Rigging

Rigging101 » Rigging128

split joint tool (4 posts)

About This Topic

Tags

No tags yet.

  1. greatbear

    offline
    Member
    Posted 6 years ago
    #

    Hello!

    I've been learning a bit of Python over the last few weeks and decided to knock together a script that will divide a two joint chain up into a user defined number of spans. Any comments/advice would be more than welcome, please feel free to use if it should come in handy (i'll be adding a simple interface in th enear future to make it a bit more user friendly):

    ###################################
    ## Split joint chain tool ##
    ## Created by james dunford ##
    ## 29/03/2011 ##
    ###################################

    def splitJoints(sections):
    import maya.cmds as cmds

    # put selection in a list, unparent joints, to find their world position
    #Rename the joints to avoid any potential clash within the scene
    #Store their translate attributes in variables 'JointAPos' & 'JointBPos'

    joints=cmds.ls(sl=True)
    cmds.parent(joints[1], w=True)
    cmds.rename(joints[0],'start')
    cmds.rename(joints[1], 'end')
    jointAPos = cmds.getAttr('start.translate')
    jointBPos = cmds.getAttr('end.translate')

    #Create a 1 degree curve using 'JointAPos' & 'JointBPos' as its start and end positions
    #Rebuild curve as per the number of spans specified at the start of the function

    cmds.curve(d=1, p=[(jointAPos[0]),(jointBPos[0])])
    cmds.rebuildCurve(s=sections, d=1)
    #Create and snap joints to cv's on the newly rebuilt curve, if the devision is 2, delete the
    #extra cv's
    for i in range(1,sections,1):
    if sections==2:
    cmds.delete('curve1.cv[1]')
    cmds.delete('curve1.cv[2]')
    pi= cmds.pointPosition('curve1.cv[1]')
    nJoints= cmds.joint(p=(pi), n=('temp%s' %i))
    else:
    pi = cmds.pointPosition('curve1.cv[%d]' %i)
    cmds.joint(p=(pi), n=('temp%s' %i))
    #Re-parent and orient the joints

    pJoint= sections-1
    cmds.parent('temp1', 'start')
    cmds.parent('end', 'temp%s' %pJoint)
    cmds.select('start')
    cmds.joint (e=True, oj='xyz', sao='ydown', ch=True, zso=True)
    cmds.select('end')
    cmds.joint(e=True, oj='none')

    #Delete the curve
    cmds.delete('curve1')

    ###########################################

    sorry about the lack of indentation - doesn't seem to want to publish the format.

  2. Smapdi

    offline
    Member
    Posted 6 years ago
    #

    Hi, nice stuff so far. A little note, you can avoid having to unparent the joints to get their world space position if you use the xform command on the rotate pivots...

    jointWorldspacePos = cmds.xform(q=1, ws=1, rp=1)

  3. mzahmbie

    offline
    Member
    Posted 6 years ago
    #

    Good stuff! Ive actually written a function to do the same thing a few months ago, so I thought I'd share my solution to it too, I approached it in a pretty different way. Here's what I came up with modified to work generically instead of with the studio toolset here.


    def divideBone(div):
    # Find distance each new joint will need to move relative to it's parent.
    startJoint = cmds.ls(selection=True)[0]
    endJoint = cmds.ls(selection=True)[1]
    distance = cmds.getAttr(endJoint+".tx")
    moveDist = distance/(div+1)

    for i in range(1,div+1):
    newJoint = cmds.insertJoint(startJoint)
    newJoint = cmds.rename(newJoint, "tempName"+str(i))

    cmds.move(moveDist, 0, 0, newJoint+".scalePivot", newJoint+".rotatePivot", r=True, os=True)
    startJoint = newJoint

    cmds.select(newJoint)

    Also, sorry about the indentation, it doesn't like me either.

  4. greatbear

    offline
    Member
    Posted 6 years ago
    #

    Thanks a lot for your tips and input, your advice was a great help! Mzahmbie - your script looks a lot more pragmatic and concise than mine so its back to the drawing board!

Reply

You must log in to post.

Rigging101 » Rigging128
1,099 posts in 307 topics over 110 months by 188 of 8,226 members. Latest: fashionpvp, d2q4p5z2j, gasheldonl