Fix T42912: FBX export: Parenting to bones was broken.

This commit is contained in:
Bastien Montagne 2014-12-20 14:20:23 +01:00
parent c0e016dd83
commit 665b1a4113
Notes: blender-bot 2023-02-14 20:00:57 +01:00
Referenced by issue #42912, FBX: export/import issue
2 changed files with 10 additions and 1 deletions

View File

@ -998,9 +998,15 @@ class ObjectWrapper(metaclass=MetaObjectWrapper):
# In fact, this is wrong - since we do not store that matrix in FBX at all, we shall not use it here...
#~ matrix = self.bdata.matrix_parent_inverse * matrix
if parent._tag == 'BO':
# In bone parent case, local matrix is in ***armature*** space!!!!!!!!!!!!
# So we need to bring it back into parent bone space.
matrix = parent._ref.pose.bones[parent.name].matrix.inverted_safe() * matrix
# 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
# Actually, since we parent back to bone space above, we do not need that
# correction here it seems...
#~ 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:

View File

@ -1637,6 +1637,8 @@ class FbxImportHelperNode:
return obj
def build_skeleton_children(self, fbx_tmpl, settings, scene):
from mathutils import Matrix
if self.is_bone:
for child in self.children:
if child.ignore:
@ -1646,6 +1648,7 @@ class FbxImportHelperNode:
child_obj.parent = self.bl_obj # get the armature the bone belongs to
child_obj.parent_bone = self.bl_bone
child_obj.parent_type = 'BONE'
child_obj.matrix_parent_inverse = Matrix()
# Blender attaches to the end of a bone, while FBX attaches to the start. bone_child_matrix corrects for that.
if child.pre_matrix: