Natural IK Chain

So RiggingDojo.com shared this video series from Yutaca Sawai:

I decided to test it, and quickly made a script to generate a chain of n-segments
Essentially the left chain is the important one (bold in the video) and the rest are just a construct to propagate a single rotation to a full fletched motion.

Open Maya, run this Python script, see for yourself how one rotation and a bunch of parented joints & ikhandles can generate complex motion!

def joint(x,y,z):
    jt = cmds.joint()
    cmds.xform(jt, t=[x,y,z], ws=True)
    return cmds.ls(jt, l=True)[0]
    
def ikHandle(start, end):
    sl = cmds.ls(sl=True)
    cmds.select(start, end)
    ikh = cmds.ikHandle()[0]
    cmds.select(sl)
    return ikh

def constructBase(cycles = 10):
    cmds.select(cl=True)
    rotator = joint(1,0,0)
    
    #demonstrative animation
    cmds.currentTime(0)
    cmds.setKeyframe('%s.rz'%rotator)
    cmds.currentTime(60)
    cmds.setAttr('%s.rz'%rotator, 360)
    cmds.setKeyframe('%s.rz'%rotator)
    cmds.playbackOptions(min=0, max=60)
    
    root = joint(0,1,0)
    chain2root = joint(-2,-1,0)
    cmds.select(root)
    joint(-2,-1,0)
    anchor = joint(0,-3,0)
    cmds.group(ikHandle(root, anchor)) #group to make the ik handle fixed in place
    
    #chain 1
    cmds.select(anchor)
    ikGroups1 = []
    parents1 = []
    for i in range(cycles):
        ikGroups1.append([joint(2,-1 - i * 8,0)])
        joint(2,-5 - i * 8,0)
        ikGroups1[-1].append(joint(-2,-5 - i * 8,0))
        parents1.append(joint(-2,-9 - i * 8,0))

    #chain 2
    cmds.select(chain2root)
    ikGroups2 = []
    parents2 = []
    for i in range(cycles):
        parents2.append(joint(-2,-5 - i * 8,0))
        ikGroups2.append([joint(2,-5 - i * 8,0)])
        joint(2,-9 - i * 8,0)
        ikGroups2[-1].append(joint(-2,-9 - i * 8,0))
    for i in range(len(ikGroups2)):
        cmds.parent(ikHandle(*ikGroups2[i]), parents1[i])
        
    for i in range(len(ikGroups1)):
        cmds.parent(ikHandle(*ikGroups1[i]), parents2[i])


constructBase()

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>