Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Bug "Bake Axis Conversion" defaults to models looking backwards

Discussion in '2020.1 Beta' started by Garrafote, Jun 11, 2020.

  1. Garrafote

    Garrafote

    Joined:
    Jun 13, 2013
    Posts:
    48
    Hi, before anything I want to say that we have been experimenting with the new "Bake Axis Conversion" feature and it looks pretty convenient so far.

    That being said we noticed that - apart from fixing the model rotation - this option is adding an extra 180 degrees on the y axis on our meshes and rigs.

    Here is what I mean:

    Without "Bake Axis Conversion" checked the mesh is imported 90 off on the X axis and this is compensated by adding a -90 degrees rotation on the game object transform. Nothing new here.
    upload_2020-6-11_16-16-40.png

    With "Bake Axis Conversion" is checked the mesh is imported in the correct direction but the prefab is generated with an extra 180 degrees on the Y axis which is causing the model to be added to the scene looking backwards.
    upload_2020-6-11_16-26-7.png

    This is not so bad for static mesh models imported with simplified hierarchy because this extra rotation is only added to the root prefab game object. But this extra rotation is also added to the root of rig hierarchies as well so for animated objects the extra rotation happens on any children transform that contains meshes and rig armatures, like so:
    upload_2020-6-11_16-33-18.png

    Fortunately, we can work around this by zeroing both Y rotations on our model instances and prefabs.

    I'm not sure if this is the intended behavior but it sounds more like a bug than a design decision given it will be source for a lot of confusion. Anyway if this is by design please let us know so I can automate the rotation zeroing on our part.

    One last thing, the fbx files shown here were exported on blender 2.83 with '-Y Forward' and 'Z Up' axis. I'm including all .fbx and .blend with the thread.
     

    Attached Files:

    Last edited: Jun 19, 2020
  2. Garrafote

    Garrafote

    Joined:
    Jun 13, 2013
    Posts:
    48
    Hello, is this the intended behavior for the Bake Axis Conversion feature?
     
  3. mordecai154

    mordecai154

    Joined:
    Oct 24, 2017
    Posts:
    4
    Hi Garrafote, I noticed the same behaviour and it seems to come from the fact that Unity uses a left-handed coordinate system, but Blender uses a right-handed one. It may also be possible that Blender does not correctly specify the coordinate system inside the fbx file. I would need to consult the fbx spec and the exporter code to verify this.
     
  4. mordecai154

    mordecai154

    Joined:
    Oct 24, 2017
    Posts:
    4
    So after looking at the fbx exporter in Blender, I did come to the conclusion that Unity does everything correctly and this is a misunderstanding about the coordinate system in Blender.

    The coordinate system in Blender is defined as right-handed with +Y forward and +Z up. This information is correctly written to the fbx file and Unity also handles the import correctly. The problem comes from the fact that Blender defines looking from the -Y axis as the "front view". Suzanne is also oriented to look in the -Y direction and every Blender file I know of is always built with the assumption that a model is looking forward in the -Y direction. But during export it is assumed that the +Y direction corresponds to forward (the way the coordinate system is defined). Blender applies the 180° rotation from +Y to -Y to all root objects, therefore you get a 180° rotation when exporting with -Y Forward and Z Up.

    I think the correct approach to this would be a patch to Blenders fbx exporter to not apply the rotation to, but only write the axis settings to the fbx file. But I imagine this will be difficult to actually get accepted because it breaks existing asset pipelines.

    I have attached a fbx file that I exported with a hacked exporter that correctly assumes the forward direction to be -Y. It imports in Unity the way you might expect.
     

    Attached Files:

  5. mordecai154

    mordecai154

    Joined:
    Oct 24, 2017
    Posts:
    4
    I will see if I can submit a patch to Blender by next week.
     
    Roshinator likes this.
  6. Garrafote

    Garrafote

    Joined:
    Jun 13, 2013
    Posts:
    48
    Thanks a lot!

    Actually, my workflow includes exporting all my fbx from a custom unity extension that calls a blender background process so I believe that I could include a similar hack on my export script.

    Can you show me the changes you made in the exporter?

    Edit:
    That would be great! Perhaps having it as an option so it doesn't break existing asset pipelines will make it more likely to be accepted.
     
    Last edited: Jun 19, 2020
  7. mordecai154

    mordecai154

    Joined:
    Oct 24, 2017
    Posts:
    4
    Sorry for the late reply, I submitted a patch but forgot to update the post here. You can see the changes here. https://developer.blender.org/D8078

    The only required change is so set the global matrix in the exporter to the identity matrix.
     
    rod_lopez, Garrafote and Peter77 like this.
  8. rod_lopez

    rod_lopez

    Joined:
    Aug 10, 2017
    Posts:
    21
    Just as a quick comment, to mention what works for us... (based on @mordecai154 's answer) and as a reference:

    Modern Blender export plug-ins have @mordecai154's patch) so that's just about getting a late'ish one.

    Create object in Blender
    Export with this (so coordinates being Blender's, "Use Space Transform" unticked)
    upload_2023-6-20_14-45-27.png

    And then on Unity's .fbx import properties
    upload_2023-6-20_14-47-17.png
    (and of course, "apply")

    Then dragging into unity will give you an object with no unwanted rotations (you can still rotate the object and that will be preserved, but it won't be due to a space-coordinate conversion thing)
    upload_2023-6-20_14-50-51.png

    (Kudos to the always awesome @hajohoetjes for digging into Python and figuring the settings to get the export right!)

    Hope it helps somebody!
     
    Bezoro and ItsMoodyDoom like this.