Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

DAE file axis Z/Y swap

Avithohol
2013-09-08
2013-09-10
  • Avithohol
    Avithohol
    2013-09-08

    Dear All,

    let me to apologize in advance, that there are dozens of topics on this subject, and despite the fact I have read them, I still cannot put them into practice.
    If You could please hold my hand while I take the first steps,
    as I believe, there must be an easier way I do.

    What we have?

    One file:
    A DAE file where the Z axis points up (created by 3ds MAX exported by OpenCollada).

    One app:
    My app is an OpengGL one, and has the following characteristics:
    -It uses right-handed coordinate systems (+X points right, +Y is up, +Z points out of the screen)
    -It operates with column major matrices

    Lets import DAE into my app

    The following steps I take after I import the DAE file into ASSIMP structures

    Step 1.
    I see in the vertex data, that +Z is up.
    So I need swap Z Y like this (same for the normals):

    float tmp = vertexPosition.y;
    vertexPosition.y = vertexPosition.z;
    vertexPosition.z = tmp;
    vertexPosition.z *= -1.0f;
    

    Step 2.
    I wish to use aiNode.mTransformation matrix to place the meshes around in the world.
    I see that this matrix is a row-major one, so i need to transpose it to comply with my app.

    Step 3.
    In aiNode.mTransformation matrix i still need to swap the coordinates in the translation part,
    the same way i did it for the vertex data:

    float tmp = transformation[13];
    transformation[13] = transformation[14];
    transformation[14] = -tmp;
    

    Step 3.
    In aiNode.mTransformation matrix i still need to swap the rotation part, because Z axis was originally up in the modelling software.
    So 45 degree of rotation around the Z axis in the modelling app,
    means 45 degree of rotation around Y axis in my app.

    I googled this conversion matrix which would help to swap the rotation part of another rotation matrix:
    1, 0, 0, 0,
    0, 0, -1, 0,
    0, 1, 0, 0,
    0, 0, 0, 1

    Before I go on,
    the question arose:
    Is this really the intended way?

    Did I look over something?
    Maybe ASSIMP LIB can already do such swap easily with a tiny twist of its pinky.

    Note: I understood if I apply the root node transformation (which is the conversion matrix above) would give me a "ready to feed into OpenGL" results. The thing is that I wish to have the raw data in memory to be in the correct (+Y up) format.
    Should I walk through my verticies and rotate them by the matrix above?
    What about the translation part of the aiNode transformation matrix?
    They will still have +Z as up.

    Thank You again for reading my endless posts.
    A

     
    Last edit: Avithohol 2013-09-08
  • Avithohol
    Avithohol
    2013-09-08

     
    Last edit: Avithohol 2013-09-08
  • The Collada loader already converts a file to Y-UP. It does so by applying a rotation to the scene's root node transformation matrix. So you can skip step 1 to 4 as long as you make use of the root transformation.

     
  • Avithohol
    Avithohol
    2013-09-09

    Hello Thomas,
    thank you for reading.
    Yes, I see that the ASSIMP elegantly uses a conversion matrix on the root level which is
    1 0 0 0
    0 0 1 0
    0 -1 0 0
    0 0 0 1

    With the upper 3x3 matrix the axis swap is dealt with by simply rotating the basis.
    What I cannot understand how the translation part (0 0 0 1) is converted?
    I mean still there is Z Y swapped there, and the conversion matrix above simply leaves it untouched.

    Think about a mesh having no rotation and moved up by 50 in the modelling software.
    The matrix looks like this in DAE:
    Matrix.A
    1 0 0 0
    0 1 0 0
    0 0 1 50
    0 0 0 1

    but in coordinate system where +Y is up, the matrix should look like this:
    Matrix.B
    1 0 0 0
    0 1 0 50
    0 0 1 0
    0 0 0 1

    If you multiply Matrix A and B, like you would do when you traverse the nodes,
    then the translation part will still have 50 in the Z component:
    1 0 0 0
    0 0 1 0
    0 -1 0 50
    0 0 0 1

    What am I missing here?

    Cheers
    A

     
  • Everything in the scene is affected by the root node's transformation. A matrix multiplication would exactly do what you expect it to do: move the offset to the Y component. Take a sheet of paper and do the matrix multiplication for yourself to see it.

     
    • Avithohol
      Avithohol
      2013-09-10

      Thomas, I actually did and found out that either I do my complicated way, or I simply do what ASSIMP does and rotate the scene by the root note's transformation.
      Thank you for your time!
      A