Help needed for world orientation and matrices

Hi.

I am working on a script that parses a ‘Camera’ file into Blender. The file I am parsing uses a 4 x 4 matrix to transform the world into camera space as per the camera transform in a RIB file.

eg.

filmback 24.892 18.669
frame 1
#focal length 35
fov 29.97002051
transform
0.7071067812 -0.3312945782 0.6246950476 0
-2.775557562e-17 0.8834522086 0.4685212857 0
-0.7071067812 -0.3312945782 0.6246950476 0
3560.565558 -2127.414591 3464.230949 1
frame 2
#focal length 35
fov 29.97002051
transform
0.7071067812 -0.3312945782 0.6246950476 0
-2.775557562e-17 0.8834522086 0.4685212857 0
-0.7071067812 -0.3312945782 0.6246950476 0
3560.565558 -2127.414591 3464.230949 1

=====================================

THE PROBLEM

The problem is that this camera is based on a Maya camera and world which is of course Y-Up as opposed to Blenders Z-Up.

I have managed to create a camera in Blender and bake the animation, I just need to find a way to rotate the camera so it respects Blender’s world orientation.

Help please!

R.

ps. I understand that this is something that has probably been addressed before, but I am having a hard time to find the correct solution. I found this snippet where someone had a similar problem and multiplied their matrix to re-align everything. I tried similar things, but my camera went haywire. I feel I am so close, yet so far.

===================================================

All you have to do is multiply your vector or matrix from the Z-up system with the transformation matrix which converts Z-up into Y-up:

yUp = someZupVectorOrMatrix * matrix3 [1,0,0] [0,0,1] [0,-1,0] [0,0,0]

This flips the axes by taking the +Z as +Y and the +Y as -Z and will convert rotation and scale parts correctly, too.

To convert from Y-up back to Z-up, just use the inverse() of the conversion matrix above which is
zUp = someYupVectorOrMatrix * matrix3 [1,0,0] [0,0,-1] [0,1,0] [0,0,0]

==================================================

Script examples will be appreciated :wink:

If the data is taken from maya then it’s possible that the matrices are formed differently to Blender. Blender’s matrices are column-major rather than row-major link. This means that in addition to flipping an axis to convert from right-handed to left-handed coordinate systems (or is it the other way around? :spin:) you might need to take the transpose of the matrices that you are importing.

The transpose of a matrix is a matrix that is similar, but with the rows and columns swapped around. Kinda like mirroring the matrix along the diagonal from top left to bottom right.

Assuming you are still having trouble, I think maybe performing the following might convert from Mayas right-handed xyz coordinate system to Blender’s left-handed xzy coordinate system:

blender_camera_matrix = transform1_matrix * maya_camera_matrix * transform2_matrix

where:

maya_camera_matrix is the 4x4 matrix: (using your example)
[0.7071067812,      -0.3312945782, 0.6246950476, 0]
[-2.775557562e-17,   0.8834522086, 0.4685212857, 0] 
[-0.7071067812,     -0.3312945782, 0.6246950476, 0]
[3560.565558,       -2127.414591,   3464.230949, 1]

transform1_matrix is the 4x4 matrix:
[1, 0,  0, 0]
[0, 0,  1, 0]
[0, -1, 0, 0]
[0, 0,  0, 1]

transform2_matrix is the 4x4 matrix:
[1, 0, 0, 0]
[0, 0, 1, 0]
[0, 1, 0, 0]
[0, 0, 0, 1]

Don’t have Maya to test… so maybe it works maybe it doesn’t. I’d write a little code snippet for you to run, but honestly I don’t know how to construct matrices in python :stuck_out_tongue:

The file I am parsing uses a 4 x 4 matrix to transform the world into camera space as per the camera transform in a RIB file.

I don’t know what a RIB file is, but make sure you know what your matrix represents.

Because… a camera’s world matrix transform’s a camera from local space to world space. While a matrix that transform’s the world into camera space is a totally different thing. That would be what is commonly referred to as a view matrix (the inverse of a camera’s world matrix). So make sure you know which one your dealing with or things will be off. :eyebrowlift:

Thx guys for the quick response. Will run a couple of tests tomorrow and post results.