Skip to content

Commit

Permalink
Consider pose transformation during xmot import and export
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeto committed Feb 25, 2024
1 parent ea8fe9f commit 46a16eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions g3blend/operators/io_export_xmot.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ def save_xmot(context: bpy.types.Context, filepath: str, global_scale: float, gl
else:
bone_matrix = bone_matrix

# Also consider the pose base matrix.
bone_matrix = bone_matrix @ pose_bone.matrix_basis

loc, rot, scale = bone_matrix.decompose()

motion_part = _add_chunk(chunks, Xmot.LmaChunkId.motionpart, 3, Xmot.CnkMotionPart)
Expand Down
15 changes: 11 additions & 4 deletions g3blend/operators/io_import_xmot.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ def load_xmot(context: bpy.types.Context, filepath: str, global_scale: float, gl
_to_blend_quat(chunk.content.pose_rotation),
_to_blend_vec(chunk.content.pose_scale))
last_motion_part_rest_matrix_inv = last_motion_part_rest_matrix.inverted_safe()

if last_motion_part not in arm_obj.pose.bones:
continue

pose_bone = arm_obj.pose.bones[last_motion_part]
# Set pose matrix used in xmot (relative to bone's rest matrix)
bone = pose_bone.bone
rest_matrix = bone.matrix_local
if bone.parent is not None:
rest_matrix = bone.parent.matrix_local.inverted_safe() @ rest_matrix
pose_bone.matrix_basis = rest_matrix.inverted_safe() @ last_motion_part_rest_matrix
elif isinstance(chunk.content, Xmot.CnkKeyFrame):
if last_motion_part is None:
raise ValueError('KeyFrame chunk must be preceded by a MotionPart chunk.')
Expand All @@ -94,10 +105,6 @@ def load_xmot(context: bpy.types.Context, filepath: str, global_scale: float, gl
pre_matrix = last_motion_part_rest_matrix_inv
post_matrix = Matrix()

# Apply matrix
# TODO: Necessary?
# pose_bone.matrix_basis = bone_matrix

keyframe_chunk = chunk.content
match keyframe_chunk.animation_type:
# Position
Expand Down

0 comments on commit 46a16eb

Please sign in to comment.