• Advertisement
Sign in to follow this  

Loaded scene form COLLADA is inverted in DirectX

This topic is 1767 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, 

 

I use COLLADA to load mesh data to my engine and I use my own converter. I know that matrix from COLLADA for each mesh should be transposed for using in DirectX, I also do this, but I faced with the following problem: scene or single object that I load to my engine after conversion to binary file is inverted along Z and Y axis. I multiply one value from each mesh matrix to -1 during transposition and after that position along Y axis is correct, but not along Z axis. I don`t understand how to translate mesh matrices that all of meshes in scene display correctly. For more details please look to attach screen shots from 3ds max and my engine.  







outputMatrixValues[12] = (float)matrixValues[3] ;
outputMatrixValues[13] = (float)matrixValues[7];
outputMatrixValues[14] = (float)matrixValues[11] * (-1);
outputMatrixValues[15] = (float)matrixValues[15] ;

 

 

On screen shot you can see that scene in 3ds mas is in front position, so the position of both cameras (in my engine and 3ds) is correct. I completely confused with this problem. Help me please.

Edited by BlackJoker

Share this post


Link to post
Share on other sites
Advertisement

In 3DS, is Y your "up" axis, or is "Z" up?

You probably shouldn't be multiplying individual components of the matrix by -1, but should be scaling an entire axis of the matrix by (-1,-1,-1,-1).

 

DirectX uses whatever handedness you choose to use. You can use it with left handed or right handed matrices.

 

Transposing a matrix does not convert between handedness; it converts between column-major storage and row-major storage. D3D's HLSL and GL's GLSL both operate on column-major storage by default, though fixed-function D3D, and the D3DX helpers often use row-major storage.

 

It also converts matrices that are designed to operate on row-vectors to ones that will work on column-vectors, and vice versa.

Whether you're using row-vectors or column-vectors depends on whether you write vector * matrix, or matrix * vector in your shader code.

Edited by Hodgman

Share this post


Link to post
Share on other sites

Hodgman

 

So, if I undertand you correctly, I must multiply meshmatrix to XMFLOAT4(-1, -1, -1, -1)? Am I right?

Edited by BlackJoker

Share this post


Link to post
Share on other sites

I think this is the same as if I will multiply each value in the concrete row during transposition. Unfortunately it not works because all meshes became turned inside out and start to rotate when I move camera.

Share this post


Link to post
Share on other sites

To convert right hand coordinate system to left hand you have to only scale z axis by -1. scale vector will be Vector3(1,1,-1).

 

If in 3ds max z is up axis (i don't remember if thats the case)  you have to swap z and y values. There should be an option in 3ds max collada exporter ??

Similar option is there for x files and fbx file exporters. Otherwise you can do it at your engine side while loading.

Share this post


Link to post
Share on other sites

So simple? I cannot believe.

For Y_UP scaling works great . I want to make my engine and converter very flexible, so I want to learn them to load any variant of exported collada model or models form 3ds max/maya and blender.

 

Regards to Z_UP - there is not enough to swap y and z vertices coordinates or you mean not vertices but values in the matrix?

Edited by BlackJoker

Share this post


Link to post
Share on other sites

Hello,

Could you please explain how to swap z and y axis for mesh in my engine during loading it? With your help I understood how to load sceene with Y_UP, I also solve problem with Z_UP, but a little tricky.

XMFLOAT4X4 cm;
            cm._11 = 1;
            cm._12 = 0;
            cm._13 = 0;
            cm._14 = 0;
            cm._21 = 0;
            cm._22 = 0;
            cm._23 = 1;
            cm._24 = 0;
            cm._31 = 0;
            cm._32 = 1;
            cm._33 = 0;
            cm._34 = 0;
            cm._41 = 0;
            cm._42 = 0;
            cm._43 = 0;
            cm._44 = 1;

            XMMATRIX matr = XMLoadFloat4x4(&cm);
            
            meshInfo->meshPosition = XMMATRIX(n);
            meshInfo->meshPosition = matr * meshInfo->meshPosition* matr;

 

here i use some matrix (I don`t know what this matrix is exactly), but aftrei multiply it with mesh matrix which I got from COLLADA, in this sequence meshInfo->meshPosition = matr * meshInfo->meshPosition* matr; and then during loading swap y and z coordinates for each vertex and normal, only then scene look correct,

 

but I want to ask is there any other more simple (just using matrices without swapping y and z vertices) way to load scene correctly?

Share this post


Link to post
Share on other sites

but I want to ask is there any other more simple (just using matrices without swapping y and z vertices) way to load scene correctly?

 

A rotation matrix that rotates 90 degrees on the x-axis will flip y/z coordinates.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement