0
\$\begingroup\$

I have a few cameras in Blender to export to Unity3D. They're exported as empty GameObjects, and that's what is expected. The idea is to have the main camera be a child of one of the camera empty GameObjects.

In Blender, for the world, +Y is forward, +Z is up. But the camera is -Z is forward, +Y is up. In Blender, I have to set the camera's rotation to (90, 0, 0) just to have the camera not face down. But it the camera doesn't face the same direction as the camera in Blender.

I tried rotating the camera game objects by Y+180 so that the camera faces +Z, parent the camera GameObject, then zero out its position and rotation.

How can I have a 1:1 export from Blender to Unity3D for camera objects?

Edit: I am exporting FBX binary 7.4 files.

Edit: Here is a table:

 Blender RotXYZ     Unity global RotXYZ    Expected rotation
( 0,  0,  0)        (  0, -90,  90)        ( 90,   0,   0)
(90,  0,  0)        (  0, -90,   0)        (  0,   0,   0)
( 0, 90,  0)        ( 90, 180,   0)        (  0, -90, -90)
( 0,  0, 90)        (  0, 180,  90)        ( 90, -90,   0)

If I input any of the Blender RotXYZ values into Blender's camera rotation, export the FBX, I get the corresponding value in the Unity global RotXYZ column. But Expected rotation is what it should be.

Edit: Here is a poorly drawn image of what I'm seeing when I export from Blender to Unity.

Edit: I'm seeing inside fbx_utils.py (FBX exporter) that the camera gets rotated to have +X be the camera's forward direction.

\$\endgroup\$
2
\$\begingroup\$

Blender is a right handed coordinate system but you can export .obj and .fbx with whatever "up" vector you want. Selecting Y+ as your Up vector when you export your .fbx files should result in the orientation you're looking for.

enter image description here

Link to a more detailed post about the blender coordinate system on the blender stack exchange

\$\endgroup\$
  • \$\begingroup\$ I failed to mention that I am already setting Up=Y and Forward=Z. I still don't get the right orientation. \$\endgroup\$ – mrkotfw Jan 5 '17 at 18:26
0
\$\begingroup\$

Okay! I figured it out.

In Blender's FBX exporter, set options Up=Z, Forward=Y.

M = Matrix.Rotation(math.pi / 2.0, 4, 'Y')
R = Matrix.Rotation(math.pi, 4, 'Z')
obj.matrix_local = (R * obj.matrix_local) * M.inverted()

Rotate the camera around the Z-axis by 180 degrees (matrix R). Since Blender's FBX exporter rotates the camera so that +X is the camera's forward direction, we need to apply the inverse of that rotation (matrix M) so that it's canceled out on export.

On Unity's side, rotate the empty game object by -90 degrees on the X-axis, then 180 degrees on the Y axis.

The only problem I'm having now is Blender not taking into account the changes made to matrix_local before exporting.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.