Starting with model hierarchy and matrices

Hi, I am implementing Collada support into my engine. I have an XML parser running, and I am able to go through the Collada nodes. I want to start by loading the model hierarchy, and matrix information, to make sure I have the model limb orientations all correct.

Please explain how. I have looked at the tutorials and if there is any useful information in there, it is extremely well-hidden. I am programming in BlitzMax, by the way.

Here is what I have so far:

Import bah.libxml

LoadDAE("duck.dae")

Global COLLADA_UpAxis

Function LoadDAE(file$)

	Local doc:TxmlDoc
	doc = TxmlDoc.parseFile(file)
	
	If Not doc
		Notify "Failed to load file.",1
		End
	EndIf
	
	Local root:TxmlNode = doc.getRootElement() 
	Notify root.GetName()
	
	For Cur_node:TxmlNode = EachIn root.Getchildren()
		Select Cur_Node.GetName()
			Case "asset" ParseAsset(doc,Cur_node)
			Case "library_materials"
			Case "library_geometries"
			Case "library_visual_scenes"
			Case "scene"
			Case "library_images"
			Case "library_cameras"	'don't care
			Case "library_lights"	'don't care
			Case "library_effects"	'don't care
			Default					'unknown
		EndSelect
	Next
	
	Function ParseAsset(doc:TxmlDoc,Cur_node:TxmlNode)
		Local ch:TxmlNode
		Local ch_list:TList
		ch_list= Cur_node.GetChildren() 
		If ch_list
			For ch=EachIn ch_list 
				Select ch.GetName().toLower() 
					Case "up_axis"
						Select ch.GetContent() 
							Case "X_UP"
								COLLADA_UpAxis=0
							Case "Y_UP"
								COLLADA_UpAxis=1
							Case "Z_UP"
								COLLADA_UpAxis=2
						EndSelect
				End Select
			Next
		EndIf
		Notify COLLADA_UpAxis
	EndFunction
	
EndFunction

I have looked at the tutorials
I’m not sure what tutorials you’re referring to, but you should be looking at the Collada spec.

In Collada, each node has a set of transforms, and you can imagine combining them into a local transform matrix.

<node id="N1">
    <translate>...</translate>
    <rotate>...</rotate>
    <scale>...</scale>
</node>

Convert the transform elements to matrices T, R, and S, and the local transform matrix will be N1 = TRS

Nodes can be nested arbitrarily deep of course.

<node id="N1">
    ...
    <node id="N2">
        ...
        <node id="N3">
            ...
            <instance_geometry url="#G">...</instance_geometry>

Here, the transform to apply to geometry G will be N1N2N3.

Here I’m assuming we’re using column vectors, as in OpenGL. For row vectors (Direct3D) you would reverse the multiplication order.

Then you have the <up_axis> setting. You want to import the model so that it matches your world’s up axis. You can do that simply by rotating the whole model into your world’s coordinate frame.

Steve

After having looked further into the way mesh data and referencing is done in this format, I have decided to make the DirectX .x file format my main file format. Sorry for the trouble.