Skip to content

Commit

Permalink
Anim_util: Change the logic to calculate the upv position on IK/FK ma…
Browse files Browse the repository at this point in the history
…tch.

Now using a simple match to the match reference node .
Added a note to research in the future #445
  • Loading branch information
miquelcampos committed Feb 7, 2025
1 parent 2e71a07 commit 85f1df3
Showing 1 changed file with 42 additions and 37 deletions.
79 changes: 42 additions & 37 deletions release/scripts/mgear/core/anim_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,46 +1067,51 @@ def _get_mth(name):
transform.matchWorldTransform(ik_target, ik_ctrl)
if ik_rot:
transform.matchWorldTransform(ik_rot_target, ik_rot_node)

transform.matchWorldTransform(fk_targets[1], upv_ctrl)
# calculates new pole vector position
start_end = fk_targets[-1].getTranslation(space="world") - fk_targets[
0
].getTranslation(space="world")
start_mid = fk_targets[1].getTranslation(space="world") - fk_targets[
0
].getTranslation(space="world")

dot_p = start_mid * start_end
proj = float(dot_p) / float(start_end.length())
proj_vector = start_end.normal() * proj
arrow_vector = start_mid - proj_vector
arrow_vector *= start_end.normal().length()

thre = 1e-4
# handle the case where three points lie on a line.
if (
abs(arrow_vector.x) < thre
and abs(arrow_vector.y) < thre
and abs(arrow_vector.z) < thre
):
# can make roll and move up ctrl
upv_ctrl_target = _get_mth(upv)
transform.matchWorldTransform(upv_ctrl_target, upv_ctrl)
else:
# ensure that the pole vector distance is a minimun of 1 unit
# while arrow_vector.length() < 1.0:
while arrow_vector.length() < start_mid.length():
arrow_vector *= 2.0

final_vector = arrow_vector + fk_targets[1].getTranslation(
space="world"
)
upv_ctrl.setTranslation(final_vector, space="world")
# NOTE: Simple match replacing the previous logic.
# Added TODO to researh in the future
upv_ctrl_target = _get_mth(upv)
transform.matchWorldTransform(upv_ctrl_target, upv_ctrl)

# TODO: The following logic is failing with some components. Apparently
# the control orientation for normal and binormal axis is affecting
# transform.matchWorldTransform(fk_targets[1], upv_ctrl)
# # calculates new pole vector position
# start_end = fk_targets[-1].getTranslation(space="world") - fk_targets[
# 0
# ].getTranslation(space="world")
# start_mid = fk_targets[1].getTranslation(space="world") - fk_targets[
# 0
# ].getTranslation(space="world")

# dot_p = start_mid * start_end
# proj = float(dot_p) / float(start_end.length())
# proj_vector = start_end.normal() * proj
# arrow_vector = start_mid - proj_vector
# arrow_vector *= start_end.normal().length()

# thre = 1e-4
# # handle the case where three points lie on a line.
# if (
# abs(arrow_vector.x) < thre
# and abs(arrow_vector.y) < thre
# and abs(arrow_vector.z) < thre
# ):
# # can make roll and move up ctrl
# upv_ctrl_target = _get_mth(upv)
# transform.matchWorldTransform(upv_ctrl_target, upv_ctrl)
# else:
# # ensure that the pole vector distance is a minimun of 1 unit
# # while arrow_vector.length() < 1.0:
# while arrow_vector.length() < start_mid.length():
# arrow_vector *= 2.0

# final_vector = arrow_vector + fk_targets[1].getTranslation(
# space="world"
# )
# upv_ctrl.setTranslation(final_vector, space="world")

# sets blend attribute new value
pm.setAttr(o_attr, ik_val)
# print(o_attr.get())

# handle the upvector roll
roll_att_name = ikfk_attr.replace("blend", "roll")
Expand Down

0 comments on commit 85f1df3

Please sign in to comment.