diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-10-09 15:03:35 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2014-10-09 15:03:35 +0400 |
commit | 00d84a2cb55a3244027fd6609ff7f1e4bf3eec3d (patch) | |
tree | a13c83482e1d34c4c53a25445423e2126eeec300 | |
parent | ac6ed35bb1c6f25003816dbbe75793f0a972c514 (diff) |
Fix T42135: FBX Exporter Armature not linked to mesh.
This time, it was exporter that did not support bone parenting of mere objects.
Also fixes a more general bug about parenting - matrix_parent_inverse
was not taken into account at all for child objects!
-rw-r--r-- | io_scene_fbx/fbx_utils.py | 20 | ||||
-rw-r--r-- | io_scene_fbx/import_fbx.py | 7 |
2 files changed, 26 insertions, 1 deletions
diff --git a/io_scene_fbx/fbx_utils.py b/io_scene_fbx/fbx_utils.py index dc3551f3..8ab4b2a9 100644 --- a/io_scene_fbx/fbx_utils.py +++ b/io_scene_fbx/fbx_utils.py @@ -881,7 +881,17 @@ class ObjectWrapper(metaclass=MetaObjectWrapper): def get_parent(self): if self._tag == 'OB': - return ObjectWrapper(self.bdata.parent) + if (self.bdata.parent and self.bdata.parent.type == 'ARMATURE' and + self.bdata.parent_type == 'BONE' and self.bdata.parent_bone): + # Try to parent to a bone. + bo_par = self.bdata.parent.pose.bones.get(self.bdata.parent_bone, None) + if (bo_par): + return ObjectWrapper(bo_par, self.bdata.parent) + else: # Fallback to mere object parenting. + return ObjectWrapper(self.bdata.parent) + else: + # Mere object parenting. + return ObjectWrapper(self.bdata.parent) elif self._tag == 'DP': return ObjectWrapper(self.bdata.parent or self._ref) else: # self._tag == 'BO' @@ -983,6 +993,14 @@ class ObjectWrapper(metaclass=MetaObjectWrapper): elif self.bdata.type == 'CAMERA': matrix = matrix * MAT_CONVERT_CAMERA + if self._tag in {'DP', 'OB'} and parent: + # To get *real* local matrix of a child object, we also need to take into account its inverted par mat! + matrix = self.bdata.matrix_parent_inverse * matrix + if parent._tag == 'BO': + # In bone parent case, we get transformation in **bone tip** space (sigh). + # Have to bring it back into bone root, which is FBX expected value. + matrix = Matrix.Translation((0, (parent.bdata.tail - parent.bdata.head).length, 0)) * matrix + # Our matrix is in local space, time to bring it in its final desired space. if parent: if is_global: diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py index 8a1028c9..11f76ac5 100644 --- a/io_scene_fbx/import_fbx.py +++ b/io_scene_fbx/import_fbx.py @@ -1288,6 +1288,12 @@ class FbxImportHelperNode: if self._parent is not None: self._parent.children.append(self) + def __repr__(self): + if self.fbx_elem: + return self.fbx_elem.props[1].decode() + else: + return "None" + def print_info(self, indent=0): print(" " * indent + (self.fbx_name if self.fbx_name else "(Null)") + ("[root]" if self.is_root else "") @@ -1636,6 +1642,7 @@ class FbxImportHelperNode: child.pre_matrix = self.bone_child_matrix child_obj.matrix_basis = child.get_matrix() + return None else: # child is not a bone obj = self.build_node(fbx_tmpl, settings) |