FBX export: Add an option to disable global space transform.

Allow to disable the rotation matrix that is applied to the object transforms
during export.

With this option disabled only the axis system is written to the fbx file,
but the object transforms are left as-is. This leaves it up to the importer
on the other side to apply the space transform during import.

Unity has added an import option to apply space transform on import in its
latest version, but the current version of setting the axis system in the
fbx file and applying the matrix causes unexpected behaviour.

Most users will expect that Blender has a forward direction of -Y and
an up direction of +Z (Suzanne is looking in the -Y direction and the
"front" view is coming from the -Y direction). But if you set the axis
conversion to -Y and +Z the exporter will apply a 180° rotation because it
assumes a forward direction of +Y.

When done this way, using the new Unity import setting, the mesh will be
imported correctly in Unity, but the rotation of the root objects will
contain that 180° rotation. Using the +Y and +Z axes during export will
import everything without any rotations, but what the user expects to be
forward will now be pointing the other direction in Unity.

When we just write the axis system as -Y and +Z to the fbx file and leave
the rotations of the root objects untouched, we can effectively define any
foward axis and have it still be imported correctly, because every conversion
will be done on Unitys side.

Reviewed By: mont29

Differential Revision: https://developer.blender.org/D8078
This commit is contained in:
Bastien Montagne 2020-11-25 12:26:09 +01:00
parent 46590bb780
commit 1a9a9d008d
1 changed files with 11 additions and 2 deletions

View File

@ -21,7 +21,7 @@
bl_info = {
"name": "FBX format",
"author": "Campbell Barton, Bastien Montagne, Jens Restemeier",
"version": (4, 21, 3),
"version": (4, 22, 0),
"blender": (2, 90, 0),
"location": "File > Import-Export",
"description": "FBX IO meshes, UV's, vertex colors, materials, textures, cameras, lamps and actions",
@ -426,6 +426,13 @@ class ExportFBX(bpy.types.Operator, ExportHelper):
"(Blender uses FBX scale to detect units on import, "
"but many other applications do not handle the same way)",
)
use_space_transform: BoolProperty(
name="Use Space Transform",
description="Apply global space transform to the object rotations. When disabled "
"only the axis space is written to the file and all object transforms are left as-is",
default=True,
)
bake_space_transform: BoolProperty(
name="Apply Transform",
description="Bake space transform into object data, avoids getting unwanted rotations to objects when "
@ -623,7 +630,8 @@ class ExportFBX(bpy.types.Operator, ExportHelper):
global_matrix = (axis_conversion(to_forward=self.axis_forward,
to_up=self.axis_up,
).to_4x4())
).to_4x4()
if self.use_space_transform else Matrix())
keywords = self.as_keywords(ignore=("check_existing",
"filter_glob",
@ -727,6 +735,7 @@ class FBX_PT_export_transform(bpy.types.Panel):
layout.prop(operator, "axis_up")
layout.prop(operator, "apply_unit_scale")
layout.prop(operator, "use_space_transform")
row = layout.row()
row.prop(operator, "bake_space_transform")
row.label(text="", icon='ERROR')