Yes, this matrix is handling the coordinate system conversion between 3D Tiles and glTF.
I now checked this again: The rotationMatrix
from the sandcastle that I posted is indeed equal to the “axis correction matrix” that is applied internally: For upAxis=Y
and forwardAxis=Z
, the matrix will be
m = Y_UP_TO_Z_UP * Z_UP_TO_X_UP
When printing this (as a flat 16-element array), then it will be
0,1,0,0,0,0,1,0,1,0,0,0,0,0,0,1
The rotationMatrix
that I defined in the sandcastle was
rotationMatrix = X_UP_TO_Y_UP * Y_UP_TO_Z_UP
but this happens to be the same as
rotationMatrix = Y_UP_TO_Z_UP * Z_UP_TO_X_UP
(i.e. the axis correction matrix)
Both of them are
0,1,0,0,0,0,1,0,1,0,0,0,0,0,0,1
Given that all these axis conversion matrices are just rotations about +/- 90 degrees, there are many cases where the multiplication of two different conversion matrices yield the same result. But as I said: I didn’t go through the math with pen and paper here.
An aside, regarding the screenshot that you posted: You probably noticed the difference:
0,0,1,0,1,0,0,0,0,1,0,0,0,0,0,1
← the matrix from the screenshot
0,1,0,0,0,0,1,0,1,0,0,0,0,0,0,1
← the axis correction matrix
But you are using that matrix in a different way: You are multiplying this with the node.transform
and the model matrix. The model matrix here contains an additional axis conversion, because it involves a HeadingPitchRoll
with a roll
of -90 degrees. And the node.transform
could contain another rotation. So it’s really difficult to understand what is actually happening there, and it’s diffucult to ensure that this works for all node.transform
matrices and all model matrices.
I think that the approach from the last sandcastle that I posted should be relatively easy, and I think that it should work in all cases. In a real application, I would probably use
rotationMatrix = Y_UP_TO_Z_UP * Z_UP_TO_X_UP
and write a short comment about the reason for this (maybe even with a link to the “axis correction matrix” code), just to avoid confusion for future readers.
Well… maybe not to avoid confusion. These axis conversions always are confusing
But maybe it helps to reduce the confusion 