Jump to content

  • Log In with Google      Sign In   
  • Create Account


Loaded scene form COLLADA is inverted in DirectX


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 BlackJoker   Members   -  Reputation: 493

Like
1Likes
Like

Posted 17 March 2013 - 04:19 AM

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.

Attached Thumbnails

  • comparison.png

Edited by BlackJoker, 17 March 2013 - 04:48 AM.


Sponsor:

#2 Doug Rogers   Members   -  Reputation: 173

Like
0Likes
Like

Posted 17 March 2013 - 09:02 PM

DirectX uses a left handed coordinate system.  



#3 BlackJoker   Members   -  Reputation: 493

Like
0Likes
Like

Posted 17 March 2013 - 11:35 PM

Yes, I know it, Thats why I transpose each mesh matrix before loading the model.



#4 Hodgman   Moderators   -  Reputation: 29488

Like
2Likes
Like

Posted 17 March 2013 - 11:44 PM

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, 17 March 2013 - 11:46 PM.


#5 BlackJoker   Members   -  Reputation: 493

Like
0Likes
Like

Posted 17 March 2013 - 11:52 PM

Hodgman

 

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


Edited by BlackJoker, 17 March 2013 - 11:52 PM.


#6 Hodgman   Moderators   -  Reputation: 29488

Like
0Likes
Like

Posted 17 March 2013 - 11:58 PM

Not the whole matrix, just the axis you want to flip.

e.g. if the Y axis is stored in matrix row #1, then multiply all the cells in row #1 by -1.



#7 BlackJoker   Members   -  Reputation: 493

Like
0Likes
Like

Posted 18 March 2013 - 01:56 AM

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.



#8 BlackJoker   Members   -  Reputation: 493

Like
0Likes
Like

Posted 18 March 2013 - 03:47 PM

Does someone know how to flip axis and coordinate system from 3ds max to DirectX? I think this is the root of the problem



#9 chetanjags   Members   -  Reputation: 173

Like
1Likes
Like

Posted 18 March 2013 - 04:03 PM

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.


My Game Development Blog : chetanjags.wordpress.com


#10 BlackJoker   Members   -  Reputation: 493

Like
0Likes
Like

Posted 18 March 2013 - 05:01 PM

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, 18 March 2013 - 05:02 PM.


#11 BlackJoker   Members   -  Reputation: 493

Like
0Likes
Like

Posted 18 March 2013 - 11:46 PM

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?



#12 stalef   Members   -  Reputation: 482

Like
0Likes
Like

Posted 19 March 2013 - 12:23 PM

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.



#13 BlackJoker   Members   -  Reputation: 493

Like
0Likes
Like

Posted 22 March 2013 - 09:10 AM

I think there is no correct way to do this only with matrices, but I could be wrong



#14 GuardianX   Crossbones+   -  Reputation: 1492

Like
0Likes
Like

Posted 22 March 2013 - 10:13 AM

Swap y and z coordinates of each point in the model.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS