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.
This commit is contained in:
Bastien Montagne 2015-06-15 21:10:06 +02:00 committed by Sergey Sharybin
parent 2fcc6e45cb
commit 470e77c2e5
3 changed files with 21 additions and 6 deletions

View File

@ -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:

View File

@ -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,

View File

@ -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",