[Bf-extensions-cvs] [0ce975d] master: Fix T42410: FBX Import: in **some** cases, se have to ignore pre/post rotation to get valid result.

Bastien Montagne noreply at git.blender.org
Sat Nov 1 15:36:28 CET 2014


Commit: 0ce975d0802e18cea5d7ec5e2f0536df886e4a2e
Author: Bastien Montagne
Date:   Sat Nov 1 15:34:20 2014 +0100
Branches: master
https://developer.blender.org/rBA0ce975d0802e18cea5d7ec5e2f0536df886e4a2e

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!

===================================================================

M	io_scene_fbx/__init__.py
M	io_scene_fbx/fbx_utils.py
M	io_scene_fbx/import_fbx.py

===================================================================

diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py
index c268ea0..238d536 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 8ab4b2a..e8837fc 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 11f76ac..e3ccd9a 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)



More information about the Bf-extensions-cvs mailing list