def verifyValues(outNum, scNode, expRao, expSha, expShf, expSpa, expSpf): """Print test results""" print '%s (test %i):'%(scNode, outNum) print'\trao: %s'%(expRao == cmds.am_shoulderConstraint(scNode, q=True, rao=True)) print'\tsha: %s'%(expSha == cmds.am_shoulderConstraint(scNode, q=True, sha=True)) print'\tshf: %s'%(expShf == cmds.am_shoulderConstraint(scNode, q=True, shf=True)) print'\tspa: %s'%(expSpa == cmds.am_shoulderConstraint(scNode, q=True, spa=True)) print'\tspf: %s'%(expSpf == cmds.am_shoulderConstraint(scNode, q=True, spf=True))
def doOptions(input_spine, input_raisedAngleOffset, input_shoulderAimAxis, input_shoulderFrontAxis, input_spineAimAxis, input_spineFrontAxis): """Specifies the function called when the apply or create button is clicked""" try: # validate selection selection = utils.dg.validateSelection(type='transform', msg='Please select your shoulder object and then the twist object to constrain.', exact=2) # validate spine spine = cmds.textFieldGrp(input_spine, q=True, tx=True) utils.dg.verifyNode(spine) # create the shoulder constraint cmds.am_shoulderConstraint( selection[1], spineObject = spine, shoulderObject = selection[0], rao=cmds.floatSliderGrp(input_raisedAngleOffset, q=True, v=True), sha=cmds.floatFieldGrp(input_shoulderAimAxis, q=True, v=True), shf=cmds.floatFieldGrp(input_shoulderFrontAxis, q=True, v=True), spa=cmds.floatFieldGrp(input_spineAimAxis, q=True, v=True), spf=cmds.floatFieldGrp(input_spineFrontAxis, q=True, v=True)) except: raise
def verifyObjects(outNum, scNode, expSpine, expShoulder, expTwist): """Print test results""" print '%s (test %i):'%(scNode, outNum) print'\tspine: %s'%(expSpine == cmds.am_shoulderConstraint(scNode, q=True, sp=True)) print'\tshldr: %s'%(expShoulder == cmds.am_shoulderConstraint(scNode, q=True, sh=True)) print'\ttwist: %s'%(expTwist == cmds.listConnections('%s.rotate'%scNode, scn=True)[0])
def unitTest(): """A simple unit test for the am_shoulderConstraint command""" # make joints jr = 0.1 spine = cmds.joint(n='spine', p=[0,0,0], rad=jr) neck = cmds.joint(n='neck', p=[0,1,0], rad=jr) cmds.joint(spine, e=True, oj='xzy', sao='zup') cmds.joint(neck, e=True, o=[0,0,0]) cmds.select(spine) collar = cmds.joint(n='collar', p=[0.2,1,0.1], rad=jr) cmds.joint(collar, e=True, o=[0,0,-90]) shoulder = cmds.joint(n='shoulder', p=[0.4,1,0], rad=jr) elbow = cmds.joint(n='elbow', p=[0.5,0.5,-0.1], rad=jr) cmds.joint(shoulder, e=True, oj='xzy', sao='zup') hand = cmds.joint(n='hand', p=[0.6,0,0], rad=jr) cmds.joint(elbow, e=True, oj='xzy', sao='zup') cmds.joint(hand, e=True, o=[0,0,0]) cmds.select(shoulder) twist = cmds.joint(n='twist', rad=jr*2) # test create mode print '---TESTING CREATE---' def verifyObjects(outNum, scNode, expSpine, expShoulder, expTwist): """Print test results""" print '%s (test %i):'%(scNode, outNum) print'\tspine: %s'%(expSpine == cmds.am_shoulderConstraint(scNode, q=True, sp=True)) print'\tshldr: %s'%(expShoulder == cmds.am_shoulderConstraint(scNode, q=True, sh=True)) print'\ttwist: %s'%(expTwist == cmds.listConnections('%s.rotate'%scNode, scn=True)[0]) sc = cmds.am_shoulderConstraint([spine,shoulder,twist]) verifyObjects(0, sc, spine, shoulder, twist) cmds.delete(sc) sc = cmds.am_shoulderConstraint([shoulder,twist], spineObject=spine) verifyObjects(1, sc, spine, shoulder, twist) cmds.delete(sc) sc = cmds.am_shoulderConstraint([spine,twist], shoulderObject=shoulder) verifyObjects(2, sc, spine, shoulder, twist) # test edit mode def compareVectors(listVec, tupleVec): """Return test result comparing vectors""" return listVec[0]==tupleVec[0] and listVec[1]==tupleVec[1] and listVec[2]==tupleVec[2] def verifyValues(outNum, scNode, expRao, expSha, expShf, expSpa, expSpf): """Print test results""" print '%s (test %i):'%(scNode, outNum) print'\trao: %s'%(expRao == cmds.am_shoulderConstraint(scNode, q=True, rao=True)) print'\tsha: %s'%(expSha == cmds.am_shoulderConstraint(scNode, q=True, sha=True)) print'\tshf: %s'%(expShf == cmds.am_shoulderConstraint(scNode, q=True, shf=True)) print'\tspa: %s'%(expSpa == cmds.am_shoulderConstraint(scNode, q=True, spa=True)) print'\tspf: %s'%(expSpf == cmds.am_shoulderConstraint(scNode, q=True, spf=True)) print '---TESTING EDIT---' cmds.am_shoulderConstraint(sc, e=True, sp=collar) verifyObjects(0, sc, collar, shoulder, twist) cmds.am_shoulderConstraint(sc, e=True, sh=elbow) verifyObjects(1, sc, collar, elbow, twist) cmds.am_shoulderConstraint(sc, e=True, sh=shoulder, sp=spine) verifyObjects(2, sc, spine, shoulder, twist) rao = 90.0 sha = [2,0,0] shf = [0,0,2] spa = [1.5,0,0] spf = [1.2,0,0] cmds.am_shoulderConstraint(sc, e=True, rao=rao, sha=sha, shf=shf, spa=spa, spf=spf) verifyValues(0, sc, rao, sha, shf, spa, spf) # test query mode print '---TESTING QUERY---' print 'shldr: %s'%(cmds.am_shoulderConstraint(sc, q=True, sh=True) == cmds.listConnections('%s.shoulder'%sc)[0]) print 'spine: %s'%(cmds.am_shoulderConstraint(sc, q=True, sp=True) == cmds.listConnections('%s.spine'%sc)[0]) print 'offst: %s'%(cmds.am_shoulderConstraint(sc, q=True, rao=True) == cmds.getAttr('%s.raisedOffset'%sc)) print 'shAim: %s'%compareVectors(cmds.am_shoulderConstraint(sc, q=True, sha=True), cmds.getAttr('%s.shoulderAim'%sc)[0]) print 'shFor: %s'%compareVectors(cmds.am_shoulderConstraint(sc, q=True, shf=True), cmds.getAttr('%s.shoulderFront'%sc)[0]) print 'spAim: %s'%compareVectors(cmds.am_shoulderConstraint(sc, q=True, spa=True), cmds.getAttr('%s.spineAim'%sc)[0]) print 'spFor: %s'%compareVectors(cmds.am_shoulderConstraint(sc, q=True, spf=True), cmds.getAttr('%s.spineFront'%sc)[0]) cmds.select(spine)
def doSetup(baseName, numberTwistJoints, elbow, shoulder, spine, raisedAngleOffset, shoulderAimAxis, shoulderFrontAxis, spineAimAxis, spineFrontAxis): """This function creates the new twist joints and returns a list of their names.""" try: # validate baseName utils.dg.validateNodeName(baseName) # validate incoming object names utils.dg.verifyNode(elbow) utils.dg.verifyNode(shoulder) utils.dg.verifyNode(spine) # get the translation value for the elbow elbowTranslate = cmds.getAttr('%s.translate'%elbow)[0] # see if there is a side label bodySide = cmds.getAttr('%s.side'%shoulder) # find out what rotate order the shoulder is using rotateOrder = cmds.getAttr('%s.rotateOrder'%shoulder) # create the twist joints twistJoints = [] for i in range(numberTwistJoints): cmds.select(cl=True) newJoint = cmds.joint(name='%s%s'%(baseName, i + 1)) # set up the first joint if i == 0: newJoint = cmds.parent(newJoint, shoulder)[0] jointRadius = 1.0 jointOrient = [] if cmds.objectType(shoulder, isType='joint'): jointRadius = cmds.getAttr('%s.radius'%shoulder) * 0.5 cmds.setAttr('%s.radius'%newJoint, jointRadius) cmds.setAttr('%s.jointOrient'%newJoint, 0,0,0) cmds.setAttr('%s.translate'%newJoint, 0,0,0) # create the shoulder constraint cmds.am_shoulderConstraint( newJoint, spineObject=spine, shoulderObject=shoulder, rao=raisedAngleOffset, sha=shoulderAimAxis, shf=shoulderFrontAxis, spa=spineAimAxis, spf=spineFrontAxis) # set up the rest of the joints else: newJoint = cmds.parent(newJoint, shoulder)[0] cmds.setAttr('%s.radius'%newJoint, jointRadius) cmds.setAttr('%s.jointOrient'%newJoint, 0,0,0) pct = float(i)/float(numberTwistJoints) cmds.setAttr('%s.translate'%newJoint, elbowTranslate[0]*pct, elbowTranslate[1]*pct, elbowTranslate[2]*pct) # create the orient constraint orientConstraint = cmds.orientConstraint([twistJoints[0], shoulder, newJoint]) targetWeights = cmds.orientConstraint(q=True, weightAliasList=True) cmds.setAttr('%s.%s'%(orientConstraint[0], targetWeights[0]), numberTwistJoints - i) cmds.setAttr('%s.%s'%(orientConstraint[0], targetWeights[1]), i) cmds.setAttr('%s.interpType'%orientConstraint[0], 1) # set label and rotate order cmds.setAttr('%s.side'%newJoint, bodySide) cmds.setAttr('%s.type'%newJoint, 18) cmds.setAttr('%s.otherType'%newJoint, 'Shoulder Twist %s'%(i + 1), type='string') cmds.setAttr('%s.rotateOrder'%newJoint, rotateOrder) # add the new joint to the list to return twistJoints.append(newJoint) return twistJoints; except: raise
def doSetup(baseName, numberTwistJoints, elbow, shoulder, spine, raisedAngleOffset, shoulderAimAxis, shoulderFrontAxis, spineAimAxis, spineFrontAxis): """This function creates the new twist joints and returns a list of their names.""" try: # validate baseName utils.dg.validateNodeName(baseName) # validate incoming object names utils.dg.verifyNode(elbow) utils.dg.verifyNode(shoulder) utils.dg.verifyNode(spine) # get the translation value for the elbow elbowTranslate = cmds.getAttr('%s.translate' % elbow)[0] # see if there is a side label bodySide = cmds.getAttr('%s.side' % shoulder) # find out what rotate order the shoulder is using rotateOrder = cmds.getAttr('%s.rotateOrder' % shoulder) # create the twist joints twistJoints = [] for i in range(numberTwistJoints): cmds.select(cl=True) newJoint = cmds.joint(name='%s%s' % (baseName, i + 1)) # set up the first joint if i == 0: newJoint = cmds.parent(newJoint, shoulder)[0] jointRadius = 1.0 jointOrient = [] if cmds.objectType(shoulder, isType='joint'): jointRadius = cmds.getAttr('%s.radius' % shoulder) * 0.5 cmds.setAttr('%s.radius' % newJoint, jointRadius) cmds.setAttr('%s.jointOrient' % newJoint, 0, 0, 0) cmds.setAttr('%s.translate' % newJoint, 0, 0, 0) # create the shoulder constraint cmds.am_shoulderConstraint(newJoint, spineObject=spine, shoulderObject=shoulder, rao=raisedAngleOffset, sha=shoulderAimAxis, shf=shoulderFrontAxis, spa=spineAimAxis, spf=spineFrontAxis) # set up the rest of the joints else: newJoint = cmds.parent(newJoint, shoulder)[0] cmds.setAttr('%s.radius' % newJoint, jointRadius) cmds.setAttr('%s.jointOrient' % newJoint, 0, 0, 0) pct = float(i) / float(numberTwistJoints) cmds.setAttr('%s.translate' % newJoint, elbowTranslate[0] * pct, elbowTranslate[1] * pct, elbowTranslate[2] * pct) # create the orient constraint orientConstraint = cmds.orientConstraint( [twistJoints[0], shoulder, newJoint]) targetWeights = cmds.orientConstraint(q=True, weightAliasList=True) cmds.setAttr('%s.%s' % (orientConstraint[0], targetWeights[0]), numberTwistJoints - i) cmds.setAttr('%s.%s' % (orientConstraint[0], targetWeights[1]), i) cmds.setAttr('%s.interpType' % orientConstraint[0], 1) # set label and rotate order cmds.setAttr('%s.side' % newJoint, bodySide) cmds.setAttr('%s.type' % newJoint, 18) cmds.setAttr('%s.otherType' % newJoint, 'Shoulder Twist %s' % (i + 1), type='string') cmds.setAttr('%s.rotateOrder' % newJoint, rotateOrder) # add the new joint to the list to return twistJoints.append(newJoint) return twistJoints except: raise