diff --git a/scripts/addons/io_scene_fbx/__init__.py b/scripts/addons/io_scene_fbx/__init__.py index da23e41..7ac2724 100644 --- a/scripts/addons/io_scene_fbx/__init__.py +++ b/scripts/addons/io_scene_fbx/__init__.py @@ -161,6 +161,11 @@ class ImportFBX(bpy.types.Operator, ImportHelper): description="Try to align the major bone axis with the bone children", default=False, ) + use_bone_scale: BoolProperty( + name="Use scale to its final \"rest pose\".", + description="Try to fix the skeleton size", + default=False, + ) primary_bone_axis: EnumProperty( name="Primary Bone Axis", items=(('X', "X Axis", ""), @@ -361,6 +366,7 @@ class FBX_PT_import_armature(bpy.types.Panel): layout.prop(operator, "ignore_leaf_bones") layout.prop(operator, "force_connect_children"), + layout.prop(operator, "use_bone_scale"), layout.prop(operator, "automatic_bone_orientation"), sub = layout.column() sub.enabled = not operator.automatic_bone_orientation diff --git a/scripts/addons/io_scene_fbx/fbx_utils.py b/scripts/addons/io_scene_fbx/fbx_utils.py index 7b44e7e..ff82e9c 100644 --- a/scripts/addons/io_scene_fbx/fbx_utils.py +++ b/scripts/addons/io_scene_fbx/fbx_utils.py @@ -1248,6 +1248,6 @@ FBXImportSettings = namedtuple("FBXImportSettings", ( "use_subsurf", "use_custom_props", "use_custom_props_enum_as_string", "nodal_material_wrap_map", "image_cache", - "ignore_leaf_bones", "force_connect_children", "automatic_bone_orientation", "bone_correction_matrix", + "ignore_leaf_bones", "force_connect_children", "automatic_bone_orientation", "use_bone_scale", "bone_correction_matrix", "use_prepost_rot", "colors_type", )) diff --git a/scripts/addons/io_scene_fbx/import_fbx.py b/scripts/addons/io_scene_fbx/import_fbx.py index bc77c9f..7c54d4b 100644 --- a/scripts/addons/io_scene_fbx/import_fbx.py +++ b/scripts/addons/io_scene_fbx/import_fbx.py @@ -7,6 +7,13 @@ # Not totally pep8 compliant. # pep8 import_fbx.py --ignore=E501,E123,E702,E125 +import logging + +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) +logger.addHandler(logging.StreamHandler()) +logger.debug("this is a debug message") + if "bpy" in locals(): import importlib if "parse_fbx" in locals(): @@ -1915,6 +1922,7 @@ class FbxImportHelperNode: matrix = self.pre_matrix @ matrix if self.post_matrix: matrix = matrix @ self.post_matrix + return matrix def make_bind_pose_local(self, parent_matrix=None): @@ -1962,7 +1970,7 @@ class FbxImportHelperNode: for child in self.children: child.collect_armature_meshes() - def build_skeleton(self, arm, parent_matrix, parent_bone_size=1, force_connect_children=False): + def build_skeleton(self, arm, parent_matrix, parent_bone_size=1, force_connect_children=False, use_bone_scale=False): def child_connect(par_bone, child_bone, child_head, connect_ctx): # child_bone or child_head may be None. force_connect_children, connected = connect_ctx @@ -2028,8 +2036,8 @@ class FbxImportHelperNode: bone_tail = Vector((0.0, 1.0, 0.0)) * max(0.01, bone_size) bone.tail = bone_tail - # And rotate/move it to its final "rest pose". - bone_matrix = parent_matrix @ self.get_bind_matrix().normalized() + # And rotate/move(/scale) it to its final "rest pose". + bone_matrix = parent_matrix @ self.get_bind_matrix() if use_bone_scale else parent_matrix @ self.get_bind_matrix().normalized() bone.matrix = bone_matrix @@ -2046,7 +2054,7 @@ class FbxImportHelperNode: child_connect(bone, None, child_head, connect_ctx) elif child.is_bone and not child.ignore: child_bone = child.build_skeleton(arm, bone_matrix, bone_size, - force_connect_children=force_connect_children) + force_connect_children=force_connect_children, use_bone_scale=use_bone_scale) # Connection to parent. child_connect(bone, child_bone, None, connect_ctx) @@ -2245,7 +2253,7 @@ class FbxImportHelperNode: if child.ignore: continue if child.is_bone: - child.build_skeleton(self, Matrix(), force_connect_children=settings.force_connect_children) + child.build_skeleton(self, Matrix(), force_connect_children=settings.force_connect_children, use_bone_scale=settings.use_bone_scale) bpy.ops.object.mode_set(mode='OBJECT') @@ -2365,6 +2373,7 @@ def load(operator, context, filepath="", ignore_leaf_bones=False, force_connect_children=False, automatic_bone_orientation=False, + use_bone_scale=False, primary_bone_axis='Y', secondary_bone_axis='X', use_prepost_rot=True, @@ -2506,7 +2515,7 @@ def load(operator, context, filepath="", use_subsurf, use_custom_props, use_custom_props_enum_as_string, nodal_material_wrap_map, image_cache, - ignore_leaf_bones, force_connect_children, automatic_bone_orientation, bone_correction_matrix, + ignore_leaf_bones, force_connect_children, automatic_bone_orientation, use_bone_scale, bone_correction_matrix, use_prepost_rot, colors_type, )