Skip to content

Commit

Permalink
Core: Anim_utils: IKFKmatch added support for gimbal controls if exist
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelcampos committed Jul 5, 2024
1 parent 2e0c180 commit 249093e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions release/scripts/mgear/core/anim_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,41 @@ def ikFkMatch_with_namespace(
ikRot (None, str): optional. Name of the Ik Rotation control
key (None, bool): optional. Whether we do an snap with animation
"""
# -----------------------------------------------
# NOTE: the following section is a workaround to match and reset the gimbal
# controls for legs and arms
# this workaround doesn't support custom naming.
gimbal_exist = False
try:
if "arm" in ikfk_attr or "leg" in ikfk_attr:

fks_gimbal = [pm.PyNode(x.replace("fk", "gimbal")) for x in fks]
ik_gimbal = pm.PyNode(ik.replace("ik", "gimbalIK"))

# store world transforms
fks_wtrans = [x.getMatrix(worldSpace=True) for x in fks_gimbal]
ik_wtrans = ik_gimbal.getMatrix(worldSpace=True)

# reset local transform
for x in fks_gimbal:
transform.resetTransform(x)
transform.resetTransform(ik_gimbal)

# apply transform to main control
for i, x in enumerate(fks):
pm.PyNode(x).setMatrix(fks_wtrans[i], worldSpace=True)
pm.PyNode(ik).setMatrix(ik_wtrans, worldSpace=True)

# keyframes
if key:
for x in fks_gimbal + [ik_gimbal]:
pm.setKeyframe(x, time=(cmds.currentTime(query=True) - 1.0))
gimbal_exist = True
except:
pass

# end of workaround gimbal match
# -----------------------------------------------

# returns a pymel node on the given name
def _get_node(name):
Expand Down Expand Up @@ -1087,6 +1122,9 @@ def _get_mth(name):
)
for elem in _all_controls
]
if gimbal_exist:
for x in fks_gimbal + [ik_gimbal]:
pm.setKeyframe(x, time=(cmds.currentTime(query=True)))


def ikFkMatch(model, ikfk_attr, ui_host, fks, ik, upv, ik_rot=None, key=None):
Expand Down

0 comments on commit 249093e

Please sign in to comment.