Skip to content

Commit

Permalink
fixed some retargeting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
snow-boy committed Feb 5, 2021
1 parent b0b7f18 commit abf58c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
16 changes: 11 additions & 5 deletions neuron_mocap_live/ops/mocap_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,18 @@ def animate_armatures_indirect(ctx, source_obj):

source_pose_bone.nml_matrix_calculated = False
if not source_pose_bone.nml_matrix_calculated:
source_matrix_to_world = (source_pose_bone.bone.matrix_local.to_3x3().inverted() @
source_obj.matrix_world.to_3x3().inverted()).to_4x4()
source_matrix_world = source_pose_bone.bone.matrix_local @ source_obj.matrix_world
source_matrix_to_world = (source_pose_bone.bone.matrix_local.to_quaternion().inverted() @
source_obj.matrix_world.to_quaternion().inverted()).to_matrix().to_4x4()

source_pose_bone.nml_set_matrix_to_world(source_matrix_to_world)
source_pose_bone.nml_set_matrix_from_world(source_matrix_to_world.inverted())
scale = source_matrix_world.to_scale()

scale = source_obj.matrix_world.to_scale()
source_pose_bone.nml_scale_world = scale
translation = source_matrix_world.to_translation()

translation = source_obj.matrix_world.to_quaternion() @ source_pose_bone.bone.matrix_local.to_translation()
translation = translation + source_obj.matrix_world.to_translation()

translation.x = translation.x * scale.x
translation.y = translation.y * scale.y
translation.z = translation.z * scale.z
Expand All @@ -138,6 +141,9 @@ def animate_armatures_indirect(ctx, source_obj):
matrix_source_to_target = target_pose_bone.nml_get_matrix_to_world() @ source_pose_bone.nml_get_matrix_to_world().inverted()

target_matrix_world = matrix_source_to_target @ source_pose_bone.matrix_basis @ source_pose_bone.nml_get_matrix_to_world()
target_matrix_world[0][3] = target_matrix_world[0][3] / target_pose_bone.nml_scale_world[0]
target_matrix_world[1][3] = target_matrix_world[1][3] / target_pose_bone.nml_scale_world[1]
target_matrix_world[2][3] = target_matrix_world[2][3] / target_pose_bone.nml_scale_world[2]
target_pose_bone.matrix_basis = target_matrix_world @ target_pose_bone.nml_get_matrix_from_world() @ target_pose_bone.nml_get_matrix_basis_tpose()

factor = 1
Expand Down
13 changes: 9 additions & 4 deletions neuron_mocap_live/ops/tpose_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@ def execute(self, ctx):
matrix_world_tpose = bone.matrix @ ctx.active_object.matrix_world
bone.nml_set_matrix_world_tpose(matrix_world_tpose)

matrix_to_world = (bone.matrix.to_3x3().inverted() @ ctx.active_object.matrix_world.to_3x3().inverted()).to_4x4()
matrix_to_world = (bone.matrix.to_quaternion().inverted() @ ctx.active_object.matrix_world.to_quaternion().inverted()).to_matrix().to_4x4()
bone.nml_set_matrix_to_world(matrix_to_world)

bone.nml_set_matrix_from_world(matrix_to_world.inverted())
scale = matrix_world_tpose.to_scale()

scale = ctx.active_object.matrix_world.to_scale()
bone.nml_scale_world = scale
translation = matrix_world_tpose.to_translation()

translation = bone.bone.matrix_local.to_quaternion() @ matrix_basis_tpose.to_translation()
translation = ctx.active_object.matrix_world.to_quaternion() @ (bone.bone.matrix_local.to_translation() + translation)
translation = ctx.active_object.matrix_world.to_translation() + translation

translation.x = translation.x * scale.x
translation.y = translation.y * scale.y
translation.z = translation.z * scale.z
bone.nml_translation_world = matrix_world_tpose.to_quaternion() @ translation
bone.nml_translation_world = translation

ctx.active_object.nml_tpose_marked = True
return {'FINISHED'}
Expand Down

0 comments on commit abf58c2

Please sign in to comment.