This POST script seems to do the trick. I modified a script from another thread that @chrislesage made that aligns the IK controls to the FK hand controls. But I had to match the rotation the the wrist guide instead of the FK hand, otherwise the hand would flip 180.
Then I added a snippet that zeros out the transforms by transferring them to the offset parent matrix, instead of adding an npo node. It’d probably be better to move this function someplace else but I’m still learning this stuff.
I’m not a very good scripter but maybe it’ll help somebody out somewhere down the line.
import maya.cmds as cmds
import pymel.core as pm
import mgear.shifter.custom_step as cstp
class CustomShifterStep(cstp.customShifterMainStep):
"""Custom Step description
"""
def setup(self):
self.name = "HandIKAlign"
def run(self):
for side in 'LR':
self.fix_ik_hand_orientation(side)
def zero_OPM(self, obj):
joints = obj
aux = pm.group(em=True)
for jnt in joints:
aux.setMatrix(jnt.getMatrix(ws=True), ws=True)
pm.parent(aux, jnt.getParent())
aux.matrix >> jnt.offsetParentMatrix
pm.xform(jnt, t=[0,0,0], ro=[0,0,0], s=[1,1,1])
if pm.objectType( jnt, isType='joint' ):
jnt.jointOrient.set([0,0,0])
aux.matrix // jnt.offsetParentMatrix
pm.delete(aux)
def fix_ik_hand_orientation(self, side):
handRef = pm.PyNode('arm_{}0_wrist'.format(side))
ikCns = pm.PyNode('arm_{}0_ikcns_ctl'.format(side))
ikCtrl = pm.PyNode('arm_{}0_ik_ctl'.format(side))
handChildren = ikCtrl.getChildren(type='transform')
cmds.matchTransform(str(ikCns), str(handRef), rot=True)
cmds.matchTransform(str(ikCtrl), str(handRef), rot=True)
obj = [ikCns, ikCtrl]
self.zero_OPM(obj)
return
The downside of aligning the IK controls to the wrists and zeroing them out is that moving the IK control straight up in world Z, for example, will now drive values in all 3 axis’, which sucks. But I can’t get the rotations to mirror on an X-forward character without doing it. So the Y-forward way still gets better results.
EDIT
There IS a way to mirror the rotation on an X-forward character and it’s much simpler than all this other stuff I tried.
All I had to do was put a value of -180 in the offset parent matrix’ Z rotation of arm_R0_ik_ctrl, then re-align it back in to it’s original orientation. NOW the mirroring works without messing up the world translation values.
Phew, thanks for coming along on this trip with me.