collada model and positions

Hy.
I’m still creating a collada importer in c++.
I’m at struggling with a multi mesh file.
Now the problem is that some of the meshes in the collada file appear little and the position is wrong.
I see that in collada file there are some element like this:


<node id="Cylinder12-node" name="Cylinder12" type="NODE">
<translate>0.618008 -0.674383 0.225838</translate>
<rotate>0.57735 0.57735 0.57735 -240</rotate>
<scale>0.873267 0.873267 0.873267</scale>
<instance_geometry url="#Cylinder12-mesh">
<bind_material>
<technique_common>
<instance_material symbol="ColorMaterial_B1581A00" target="#ColorMaterial_B1581A00"/>
</technique_common>
</bind_material>
</instance_geometry>
</node>

that is under the <library_visual_scenes>
is possible thath i must apply the scale rotate and translate transformation to my mesh?
How do the visual scene node?
I try to apply those tranformation , but the positions are the same , wrong.
THanks.

A <node> is COLLADA is a “place”, i.e. a local coordinate system.

You example describes a geometry that is instantiated in that place with a transformation of M=TRS.

You could apply your <translate> <rotate> <scale> to your meshes, but those elements are optional elements, not required.
Try to break your collada file into simpler case. take off your <rotate> and <scale> elements and test them one at a time.

remember that node is not directly under library_visual_scenes, it is under visual_scene.
<library_visual_scenes>
<visual_scene>
<node> … </node>
</visual_scene>
</library_visual_scenes>

You could also draw a small cube at (0,0,0) so that you can have a relative position and size to compare your objects at your transform, because your camera orientation could affect the final object’s position and size on the screen.

BTW, the <rotate> values are wrong.
It should be something like <rotate>1 0 0 -240</rotate> for rotating -240 on x-axis only.

this is a part of the xml:

<node id="F430-node" name="F430" type="NODE">
        <translate>0.642309 -0.148944 0.442514</translate>
        <rotate>0.57735 0.57735 0.57735 -240</rotate>
        <instance_geometry url="#F430-mesh">
          <bind_material>
            <technique_common>
              <instance_material symbol="body_color" target="#body_color">
                <bind_vertex_input semantic="CHANNEL1" input_semantic="TEXCOORD" input_set="1"/>
              </instance_material>
              <instance_material symbol="black_rear" target="#black_rear">
                <bind_vertex_input semantic="CHANNEL1" input_semantic="TEXCOORD" input_set="1"/>
              </instance_material>
              <instance_material symbol="difusor" target="#difusor"/>
              <instance_material symbol="glass" target="#glass"/>
            </technique_common>
          </bind_material>
        </instance_geometry>
      </node>

..
...
      <node id="B-floor-node" name="B-floor" type="NODE">
        <translate>0.234062 -1.04631 0.148801</translate>
        <rotate>0.57735 0.57735 0.57735 -240</rotate>
        <instance_geometry url="#B-floor-mesh">
          <bind_material>
            <technique_common>
              <instance_material symbol="floor" target="#floor"/>
            </technique_common>
          </bind_material>
        </instance_geometry>
      </node>


The meshes appareance is ok , but the position is wrong
I use this code (directx):



   D3DXMATRIX mxRotate;
   D3DXMATRIX mxScale;
   D3DXMATRIX mxTranslate;	
   D3DXMATRIX mxRotate1;
   D3DXMATRIX mxScale1;
   D3DXMATRIX mxTranslate1;	
//B-floor-mesh
D3DXMatrixRotationX(&mxRotate,-240);
				D3DXMatrixTranslation(&mxTranslate,0.234062,-1.04631,0.148801);
				D3DXMATRIX World1= mxTranslate  * mxRotate1 ;
				Device->SetTransform(D3DTS_WORLD, &World1);
			
				pfloormesh>DrawSubset(0);

//f430
D3DXMatrixRotationX(&mxRotate1,-240);
				D3DXMatrixTranslation(&mxTranslate1,0.642309, -0.148944 ,0.442514);
				D3DXMATRIX World2= mxTranslate1 * mxRotate1; 
				Device->SetTransform(D3DTS_WORLD, &World2);
			
				pf430mesh->DrawSubset(0);

the position are not precise.

nobody?
for rotate…
i have :<rotate>0.57735 0.57735 0.57735 -240</rotate>
the angle ok , but the 0.57735 0.57735 0.57735 are the component?
and in directx what i must transform and how for this rotation?
and… i must to apply the transformation for each poly from last to begin or i can do as in the my example code ( only 2 poly of 254 poly)?
thanks.

I am not very good in DirectX, but I will try my best to help you.

Please try this to draw it a (0, 0, 0) without rotation.
D3DXMatrixTranslation(&mxTranslate, 0.0, 0.0, 0.0);
D3DXMATRIX World1= mxTranslate;
Let’s make sure that there are nothing in the transform stack.

If that’s okay, try to draw only with the translate.
D3DXMatrixTranslation(&mxTranslate,0.234062,-1.04631,0.148801);
D3DXMATRIX World1= mxTranslate;

If that’s okay, then something might be wrong in the rotate for rotate matrix multiplication.

For the Rotation:
if you want to do x-axis rotation
D3DXMatrixRotationX(&mxRotate,-240);
your collada <rotate> element should be
<rotate>1 0 0 -240</rotate>

Thanks,
Herbert

I use vs 2005,
what is and where i can read the transform stack in vs?
Thanks

I don’t know much about DirectX, I know OpenGL.

In OpengGL:
glLoadIdentity() is the API to clear the transform stack,
You add a transformation matrix to the transform stack by some API like glTranslatef, glRotatef, and glScalef, etc.

Someone who knows about DirectX and OpenGL might be able to explain better.

Thanks,
Herbert

I don’t know much about DirectX, I know OpenGL.

And I don’t know much about either :slight_smile: But this is probably a good place to start for the DirectX answers:

http://msdn.microsoft.com/en-us/library/bb147181(VS.85.aspx

But I have a collada file with 200 meshes and i would render only 3 meshes, and i ask you if these meshes are “linked” or indipendent.
Linked if i must apply all the 200 transformation and render all 200 meshes or indipendent if i can apply only the 3 transformation of the 3 meshes nodes.
Thanks.

i post the code:
this is the render loop:
I draw only 2 meshes of the 200 meshes vector m_AllMeshes


for(itMesh = m_AllMeshes.begin();itMesh != m_AllMeshes.end();itMesh++)
		{
			Device->SetMaterial(&mtrl);
			CMeshBase* pmesh=((CMeshBase*)*itMesh);
			if(pmesh->getName().find("F430-mesh")!=string::npos )
			{
				vRotationAxis->x = 0.57735f;
				vRotationAxis->y = 0.57735f;	
				vRotationAxis->z = 0.57735f;

				matr->LoadIdentity();
				matr->RotateAxis(vRotationAxis,-240);
				matr->Translate(0.642309f,-0.1489442f,0.442514f);
				
				
				matr->Push();
				
				Device->SetTransform(D3DTS_WORLDMATRIX(0), matr->GetTop());
				pmesh->mesh->DrawSubset(0);
			}
			if(pmesh->getName().find("B-floor-mesh")!=string::npos)
			{
		
				
				matr->LoadIdentity();
				matr->RotateAxis(vRotationAxis,-240);
				matr->Translate(0.234062f, -1.04631f,0.148801f);
				
				
				matr->Push();
						
				Device->SetTransform(D3DTS_WORLDMATRIX(0), matr->GetTop());
				pmesh->mesh->DrawSubset(0);
							
			}
		}



I call loadidentity before apply the transform and the rotation result is ok ,but there is an error in the location of the 2 meshes
i already test that the values of the translate is correct.
I must use translate or translatelocal?
thanks.

I’m read somewere that in collada in directx i must invert the z coordintate of translation, from Lhc to rhc.
is true?
thanks.

COLLADA nodes are local coordinate systems that are hierarchical when representing a transformation stack. The composition of the hierarchical transforms from the root node to a given node represents the placement of geometry that is instantiated in that node’s space. In your example the geometry with id of “Cylinder12-mesh” is in that space. This composition is repeated for each instantiation.

So depending on what you mean by your question, probably I will answer “independent”.

COLLADA is 'Rhc" (like OpenGL). DirectX is normally “Lhc” but supports RH functions too (see D3DXMatrixPerspectiveRH). I think this explanation about Direct3D Coordinate Systems from Microsoft will help you understand what approach you will want to take.

1)I think that i find the error:
The vectors that collada use for the transform in the scene node must be flipped!
I’m flip the indexes 2 with 3 when import the meshes and i think that i must flip the y with the z in the vector, may be?

for example:
this are two collada position vector:

<translate>0.642309 -0.148944 0.442514</translate>
<rotate>0.57735 0.57735 0.57735 -240</rotate>
i trasform the world coord for those vectors.
how i flip the values?
I must change also the sign?

2)i must use the rh functions(D3DXMatrixPerspectiveRH ecc…)?

3)i mustip the signs in the view matrix?
i do so:


	D3DXMatrixLookAtLH(
		&V,
		&pos,
		&target,
		&up);
	
	D3DXMATRIX V1,result;
	Device->SetTransform(D3DTS_VIEW, &V);
	
	Device->GetTransform( D3DTS_VIEW ,&V1);
	V1._31=-V1._31;
	V1._32=-V1._32;
	V1._33=-V1._33;
	V1._34=-V1._34;
	Device->SetTransform( D3DTS_VIEW ,&V1);
	

is correct .
Thanks in advance