Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-06-15 22:10:06 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2015-06-18 18:43:41 +0300
commit470e77c2e5437d82303d2699d634a6fec8bee7d1 (patch)
tree24349c9c8e52ee1c99082edde7521cf230d72344
parent2fcc6e45cb885cb14e78f591169d2d639383c0f2 (diff)
Final step (hopefully) in unit/scale Hell.v2.75-rc2
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.
-rw-r--r--io_scene_fbx/__init__.py9
-rw-r--r--io_scene_fbx/export_fbx_bin.py16
-rw-r--r--io_scene_fbx/fbx_utils.py2
3 files changed, 21 insertions, 6 deletions
diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py
index c4bd9b71..ece5f976 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 e6d5f720..1e6aa383 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 05420998..f5a8e1dd 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",