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 17:31:12 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2015-06-18 18:43:41 +0300
commit01b3093135c2e0b29e57b4c1bc46f4a2966b8f0e (patch)
treea1fa21ef5e1131144818951a5601aa451d3d5acf
parentfe47d3d49371b03691774ba3b915c5c047876ab9 (diff)
Fix T45080: Scale of exported .fbx is wrong in 2.75.
Man... this scaling issue becomes ridiculous! Tried to fix it again also regarding (what is supposed to be) FBX scale/units handling. Since we store Blender's unit system (with 1BU == 1m in case of none) as the UnitScaleFactor element, we actually *do not* have to also scale objects themselves... In theory. Since I have to wait hours here to get my UE4 repo updated and rebuild the monster, comitting this now, we'll see later for FBXSDK behavior.
-rw-r--r--io_scene_fbx/export_fbx_bin.py15
-rw-r--r--io_scene_fbx/fbx_utils.py8
-rw-r--r--io_scene_fbx/import_fbx.py3
3 files changed, 16 insertions, 10 deletions
diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py
index 98ac6cac..e6d5f720 100644
--- a/io_scene_fbx/export_fbx_bin.py
+++ b/io_scene_fbx/export_fbx_bin.py
@@ -61,7 +61,9 @@ from .fbx_utils import (
FBX_LIGHT_TYPES, FBX_LIGHT_DECAY_TYPES,
RIGHT_HAND_AXES, FBX_FRAMERATES,
# Miscellaneous utils.
- PerfMon, units_convertor, units_convertor_iter, matrix4_to_array, similar_values, similar_values_iter,
+ PerfMon,
+ units_blender_to_fbx_factor, units_convertor, units_convertor_iter,
+ matrix4_to_array, similar_values, similar_values_iter,
# Mesh transform helpers.
vcos_transformed_gen, nors_transformed_gen,
# UUID from key.
@@ -2612,8 +2614,8 @@ 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 = 100.0 if (scene.unit_settings.system == 'NONE') else (100.0 * scene.unit_settings.scale_length)
- scale_factor = scene_data.settings.global_scale
+ 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])
@@ -2832,12 +2834,7 @@ def save_single(operator, scene, filepath="",
if 'OTHER' in object_types:
object_types |= BLENDER_OTHER_OBJECT_TYPES
- # Scale/unit mess. FBX can store the 'reference' unit of a file in its UnitScaleFactor property
- # (1.0 meaning centimeter, afaik). We use that to reflect user's default unit as set in Blender with scale_length.
- # However, we always get values in BU (i.e. meters), so we have to reverse-apply that scale in global matrix...
- # Note that when no default unit is available, we assume 'meters' (and hence scale by 100).
- scale_correction = 100.0 if (scene.unit_settings.system == 'NONE') else (100.0 * scene.unit_settings.scale_length)
- global_matrix = global_matrix * Matrix.Scale(scale_correction, 4)
+ #~ 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.
diff --git a/io_scene_fbx/fbx_utils.py b/io_scene_fbx/fbx_utils.py
index 4cf46ffb..05420998 100644
--- a/io_scene_fbx/fbx_utils.py
+++ b/io_scene_fbx/fbx_utils.py
@@ -198,6 +198,14 @@ else:
pass
+# Scale/unit mess. FBX can store the 'reference' unit of a file in its UnitScaleFactor property
+# (1.0 meaning centimeter, afaik). We use that to reflect user's default unit as set in Blender with scale_length.
+# However, we always get values in BU (i.e. meters), so we have to reverse-apply that scale in global matrix...
+# Note that when no default unit is available, we assume 'meters' (and hence scale by 100).
+def units_blender_to_fbx_factor(scene):
+ return 100.0 if (scene.unit_settings.system == 'NONE') else (100.0 * scene.unit_settings.scale_length)
+
+
# Note: this could be in a utility (math.units e.g.)...
UNITS = {
diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index 4218a4e7..7a2808db 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -42,6 +42,7 @@ from . import parse_fbx, fbx_utils
from .parse_fbx import data_types, FBXElem
from .fbx_utils import (
PerfMon,
+ units_blender_to_fbx_factor,
units_convertor_iter,
array_to_matrix4,
similar_values,
@@ -2152,7 +2153,7 @@ def load(operator, context, filepath="",
# FBX default base unit seems to be the centimeter, while raw Blender Unit is equivalent to the meter...
unit_scale = elem_props_get_number(fbx_settings_props, b'UnitScaleFactor', 1.0)
unit_scale_org = elem_props_get_number(fbx_settings_props, b'OriginalUnitScaleFactor', 1.0)
- global_scale *= unit_scale / unit_scale_org / 100.0
+ global_scale *= (unit_scale / units_blender_to_fbx_factor(context.scene))
# Compute global matrix and scale.
if not use_manual_orientation:
axis_forward = (elem_props_get_integer(fbx_settings_props, b'FrontAxis', 1),