[Bf-extensions-cvs] [470e77c] blender-v2.75-release: Final step (hopefully) in unit/scale Hell.

Bastien Montagne noreply at git.blender.org
Thu Jun 18 17:45:08 CEST 2015


Commit: 470e77c2e5437d82303d2699d634a6fec8bee7d1
Author: Bastien Montagne
Date:   Mon Jun 15 21:10:06 2015 +0200
Branches: blender-v2.75-release
https://developer.blender.org/rBA470e77c2e5437d82303d2699d634a6fec8bee7d1

Final step (hopefully) in unit/scale Hell.

So, it appears some importers (at least UE4) do not use UnitScaleFactor defined by FBX,
which is assumed to be a way to say 'this FBX file uses units n times default FBX unit'
(default FBX unit being centimeter - afaik, at least I saw some FBX from Max with a
UnitScaleFactor of 2.54 - inches).

Hence, we have to add yet another stupid option to apply that 'unit scaling' to objects
instead (as part of global scaling)... Hurra.

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

M	io_scene_fbx/__init__.py
M	io_scene_fbx/export_fbx_bin.py
M	io_scene_fbx/fbx_utils.py

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

diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py
index c4bd9b7..ece5f97 100644
--- a/io_scene_fbx/__init__.py
+++ b/io_scene_fbx/__init__.py
@@ -235,6 +235,13 @@ class ExportFBX(bpy.types.Operator, ExportHelper, IOFBXOrientationHelper):
             default=1.0,
             )
     # 7.4 only
+    apply_unit_scale = BoolProperty(
+            name="Apply Unit",
+            description="Scale all data according to current Blender size, to match default FBX unit "
+                        "(centimeter, some importers do not handle UnitScaleFactor properly)",
+            default=True,
+            )
+    # 7.4 only
     bake_space_transform = BoolProperty(
             name="!EXPERIMENTAL! Apply Transform",
             description="Bake space transform into object data, avoids getting unwanted rotations to objects when "
@@ -424,6 +431,8 @@ class ExportFBX(bpy.types.Operator, ExportHelper, IOFBXOrientationHelper):
         layout.prop(self, "version")
         layout.prop(self, "use_selection")
         layout.prop(self, "global_scale")
+        if is_74bin:
+            layout.prop(self, "apply_unit_scale")
         layout.prop(self, "axis_forward")
         layout.prop(self, "axis_up")
         if is_74bin:
diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py
index e6d5f72..1e6aa38 100644
--- a/io_scene_fbx/export_fbx_bin.py
+++ b/io_scene_fbx/export_fbx_bin.py
@@ -2613,9 +2613,13 @@ def fbx_header_elements(root, scene_data, time=None):
 
     props = elem_properties(global_settings)
     up_axis, front_axis, coord_axis = RIGHT_HAND_AXES[scene_data.settings.to_axes]
-    # Currently not sure about that, but looks like default unit of FBX is cm...
-    scale_factor_org = units_blender_to_fbx_factor(scene)
-    scale_factor = scene_data.settings.global_scale * units_blender_to_fbx_factor(scene)
+    if scene_data.settings.apply_unit_scale:
+        # Unit scaling is applied to objects' scale, so our unit is effectively FBX one (centimeter).
+        scale_factor_org = 1.0
+        scale_factor = scene_data.settings.global_scale / units_blender_to_fbx_factor(scene)
+    else:
+        scale_factor_org = units_blender_to_fbx_factor(scene)
+        scale_factor = scene_data.settings.global_scale * units_blender_to_fbx_factor(scene)
     elem_props_set(props, "p_integer", b"UpAxis", up_axis[0])
     elem_props_set(props, "p_integer", b"UpAxisSign", up_axis[1])
     elem_props_set(props, "p_integer", b"FrontAxis", front_axis[0])
@@ -2799,6 +2803,7 @@ def fbx_takes_elements(root, scene_data):
 # This func can be called with just the filepath
 def save_single(operator, scene, filepath="",
                 global_matrix=Matrix(),
+                apply_unit_scale=False,
                 axis_up="Z",
                 axis_forward="Y",
                 context_objects=None,
@@ -2834,7 +2839,8 @@ def save_single(operator, scene, filepath="",
     if 'OTHER' in object_types:
         object_types |= BLENDER_OTHER_OBJECT_TYPES
 
-    #~ global_matrix = global_matrix * Matrix.Scale(units_blender_to_fbx_factor(scene), 4)
+    if apply_unit_scale:
+        global_matrix = global_matrix * Matrix.Scale(units_blender_to_fbx_factor(scene), 4)
     global_scale = global_matrix.median_scale
     global_matrix_inv = global_matrix.inverted()
     # For transforming mesh normals.
@@ -2869,7 +2875,7 @@ def save_single(operator, scene, filepath="",
     )
 
     settings = FBXExportSettings(
-        operator.report, (axis_up, axis_forward), global_matrix, global_scale,
+        operator.report, (axis_up, axis_forward), global_matrix, global_scale, apply_unit_scale,
         bake_space_transform, global_matrix_inv, global_matrix_inv_transposed,
         context_objects, object_types, use_mesh_modifiers,
         mesh_smooth_type, use_mesh_edges, use_tspace,
diff --git a/io_scene_fbx/fbx_utils.py b/io_scene_fbx/fbx_utils.py
index 0542099..f5a8e1d 100644
--- a/io_scene_fbx/fbx_utils.py
+++ b/io_scene_fbx/fbx_utils.py
@@ -1194,7 +1194,7 @@ FBXExportSettingsMedia = namedtuple("FBXExportSettingsMedia", (
 
 # Helper container gathering all exporter settings.
 FBXExportSettings = namedtuple("FBXExportSettings", (
-    "report", "to_axes", "global_matrix", "global_scale",
+    "report", "to_axes", "global_matrix", "global_scale", "apply_unit_scale",
     "bake_space_transform", "global_matrix_inv", "global_matrix_inv_transposed",
     "context_objects", "object_types", "use_mesh_modifiers",
     "mesh_smooth_type", "use_mesh_edges", "use_tspace",



More information about the Bf-extensions-cvs mailing list