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!
This commit is contained in:
Bastien Montagne 2014-10-09 13:03:35 +02:00
parent ac6ed35bb1
commit 00d84a2cb5
Notes: blender-bot 2023-02-14 09:58:56 +01:00
Referenced by issue blender/blender#42135, FBX Exporter Armature not linked to mesh
2 changed files with 26 additions and 1 deletions

View File

@ -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:

View File

@ -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)