Disabling root motion now correctly exports the root bone in the bind pose in animations

The description for Root Motion has also been updated to better explain how the setting works.
This commit is contained in:
Colin Basnett
2023-04-27 19:43:15 -07:00
parent 7111a536b2
commit 268d039693
2 changed files with 11 additions and 8 deletions

View File

@@ -23,12 +23,12 @@ class PsaBuildOptions:
def __init__(self): def __init__(self):
self.animation_data: Optional[AnimData] = None self.animation_data: Optional[AnimData] = None
self.sequences: List[PsaExportSequence] = [] self.sequences: List[PsaExportSequence] = []
self.bone_filter_mode = 'ALL' self.bone_filter_mode: str = 'ALL'
self.bone_group_indices: List[int] = [] self.bone_group_indices: List[int] = []
self.should_ignore_bone_name_restrictions = False self.should_ignore_bone_name_restrictions: bool = False
self.sequence_name_prefix = '' self.sequence_name_prefix: str = ''
self.sequence_name_suffix = '' self.sequence_name_suffix: str = ''
self.root_motion = False self.root_motion: bool = False
def build_psa(context: bpy.types.Context, options: PsaBuildOptions) -> Psa: def build_psa(context: bpy.types.Context, options: PsaBuildOptions) -> Psa:
@@ -145,10 +145,11 @@ def build_psa(context: bpy.types.Context, options: PsaBuildOptions) -> Psa:
pose_bone_matrix = pose_bone_parent_matrix.inverted() @ pose_bone_matrix pose_bone_matrix = pose_bone_parent_matrix.inverted() @ pose_bone_matrix
else: else:
if options.root_motion: if options.root_motion:
# Export root motion # Get the bone's pose matrix, taking the armature object's world matrix into account.
pose_bone_matrix = armature_object.matrix_world @ pose_bone.matrix pose_bone_matrix = armature_object.matrix_world @ pose_bone.matrix
else: else:
pose_bone_matrix = pose_bone.matrix # Use the bind pose matrix for the root bone.
pose_bone_matrix = armature_data.bones[pose_bone.name].matrix_local
location = pose_bone_matrix.to_translation() location = pose_bone_matrix.to_translation()
rotation = pose_bone_matrix.to_quaternion().normalized() rotation = pose_bone_matrix.to_quaternion().normalized()

View File

@@ -63,7 +63,9 @@ class PsaExportPropertyGroup(PropertyGroup):
name='Root Motion', name='Root Motion',
options=empty_set, options=empty_set,
default=False, default=False,
description='The root bone will be transformed as it appears in the scene', description='When enabled, the root bone will be transformed as it appears in the scene.\n\n'
'You might want to disable this if you are exporting an animation for an armature that is '
'attached to another object, such as a weapon or a shield',
) )
should_override_animation_data: BoolProperty( should_override_animation_data: BoolProperty(
name='Override Animation Data', name='Override Animation Data',