diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-11-01 17:34:20 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2014-11-01 17:34:20 +0300 |
commit | 0ce975d0802e18cea5d7ec5e2f0536df886e4a2e (patch) | |
tree | 16a49cb79a9e5b84430438d5110f1bfd07614f0d | |
parent | e2f0f5ddfb75e47650a80070f01e7837b7d98b81 (diff) |
Fix T42410: FBX Import: in **some** cases, se have to ignore pre/post rotation to get valid result.
Yet another big breakthrough in FBX fantastic transformation handling! And yet another
hacking parameter to get things imported better.
Anyway, many thanks to artgolf1000 (Mingfen Wang) for finding that hack!
-rw-r--r-- | io_scene_fbx/__init__.py | 8 | ||||
-rw-r--r-- | io_scene_fbx/fbx_utils.py | 2 | ||||
-rw-r--r-- | io_scene_fbx/import_fbx.py | 16 |
3 files changed, 20 insertions, 6 deletions
diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py index c268ea04..238d536e 100644 --- a/io_scene_fbx/__init__.py +++ b/io_scene_fbx/__init__.py @@ -177,6 +177,12 @@ class ImportFBX(bpy.types.Operator, ImportHelper): default='X', ) + use_prepost_rot = BoolProperty( + name="Use Pre/Post Rotation", + description="Use pre/post rotation from FBX transform (you may have to disable that in some cases)", + default=True, + ) + def draw(self, context): layout = self.layout @@ -205,6 +211,8 @@ class ImportFBX(bpy.types.Operator, ImportHelper): sub.prop(self, "primary_bone_axis") sub.prop(self, "secondary_bone_axis") + layout.prop(self, "use_prepost_rot") + def execute(self, context): keywords = self.as_keywords(ignore=("filter_glob", "directory")) keywords["use_cycles"] = (context.scene.render.engine == 'CYCLES') diff --git a/io_scene_fbx/fbx_utils.py b/io_scene_fbx/fbx_utils.py index 8ab4b2a9..e8837fc9 100644 --- a/io_scene_fbx/fbx_utils.py +++ b/io_scene_fbx/fbx_utils.py @@ -1150,5 +1150,5 @@ FBXImportSettings = namedtuple("FBXImportSettings", ( "use_alpha_decals", "decal_offset", "use_custom_props", "use_custom_props_enum_as_string", "cycles_material_wrap_map", "image_cache", - "ignore_leaf_bones", "automatic_bone_orientation", "bone_correction_matrix" + "ignore_leaf_bones", "automatic_bone_orientation", "bone_correction_matrix", "use_prepost_rot", )) diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py index 11f76ac5..e3ccd9a9 100644 --- a/io_scene_fbx/import_fbx.py +++ b/io_scene_fbx/import_fbx.py @@ -382,7 +382,7 @@ def add_vgroup_to_objects(vg_indices, vg_weights, vg_name, objects): vg.add((i,), w, 'REPLACE') -def blen_read_object_transform_preprocess(fbx_props, fbx_obj, rot_alt_mat): +def blen_read_object_transform_preprocess(fbx_props, fbx_obj, rot_alt_mat, use_prepost_rot): # This is quite involved, 'fbxRNode.cpp' from openscenegraph used as a reference const_vector_zero_3d = 0.0, 0.0, 0.0 const_vector_one_3d = 1.0, 1.0, 1.0 @@ -399,8 +399,12 @@ def blen_read_object_transform_preprocess(fbx_props, fbx_obj, rot_alt_mat): is_rot_act = elem_props_get_bool(fbx_props, b'RotationActive', False) if is_rot_act: - pre_rot = elem_props_get_vector_3d(fbx_props, b'PreRotation', const_vector_zero_3d) - pst_rot = elem_props_get_vector_3d(fbx_props, b'PostRotation', const_vector_zero_3d) + if use_prepost_rot: + pre_rot = elem_props_get_vector_3d(fbx_props, b'PreRotation', const_vector_zero_3d) + pst_rot = elem_props_get_vector_3d(fbx_props, b'PostRotation', const_vector_zero_3d) + else: + pre_rot = const_vector_zero_3d + pst_rot = const_vector_zero_3d rot_ord = { 0: 'XYZ', 1: 'XYZ', @@ -1862,7 +1866,8 @@ def load(operator, context, filepath="", ignore_leaf_bones=False, automatic_bone_orientation=False, primary_bone_axis='Y', - secondary_bone_axis='X'): + secondary_bone_axis='X', + use_prepost_rot=True): global fbx_elem_nil fbx_elem_nil = FBXElem('', (), (), ()) @@ -1975,6 +1980,7 @@ def load(operator, context, filepath="", use_custom_props, use_custom_props_enum_as_string, cycles_material_wrap_map, image_cache, ignore_leaf_bones, automatic_bone_orientation, bone_correction_matrix, + use_prepost_rot, ) # #### And now, the "real" data. @@ -2155,7 +2161,7 @@ def load(operator, context, filepath="", elem_find_first(fbx_tmpl, b'Properties70', fbx_elem_nil)) assert(fbx_props[0] is not None) - transform_data = blen_read_object_transform_preprocess(fbx_props, fbx_obj, Matrix()) + transform_data = blen_read_object_transform_preprocess(fbx_props, fbx_obj, Matrix(), use_prepost_rot) is_bone = fbx_obj.props[2] in {b'LimbNode', b'Root'} fbx_helper_nodes[a_uuid] = FbxImportHelperNode(fbx_obj, bl_data, transform_data, is_bone) |