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.
This commit is contained in:
parent
fe47d3d493
commit
01b3093135
Notes:
blender-bot
2023-02-14 19:56:27 +01:00
Referenced by issue #45080, Scale of exported .fbx is wrong in 2.75
|
@ -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.
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue