def match(self, *args): characterContainer = self.characterNamespaceOnly + ':character_container' blueprintContainer = self.blueprintNamespace + ':module_container' moduleContainer = self.blueprintNamespace + ':' + self.moduleNamespace + ':module_container' containers = [characterContainer, blueprintContainer, moduleContainer] for c in containers: cmds.lockNode(c, lock=False, lockUnpublished=False) joints = utils.findJointChain(self.blueprintNamespace+':' + self.moduleNamespace+':joints_grp') blueprintJoints = utils.findJointChain(self.blueprintNamespace+':blueprint_joints_grp') ikHandleControl = self.blueprintNamespace + ':' + self.moduleNamespace + ':ikHandleControl' cmds.setAttr(ikHandleControl + '.stretchiness',1) endPos = cmds.xform(blueprintJoints[len(blueprintJoints)-1], q=1, worldSpace=True, translation=True) cmds.xform(ikHandleControl, worldSpace=True, absolute=True, translation=endPos) joints.pop(0) blueprintJoints.pop(0) utils.matchTwistAngle(ikHandleControl + '.twist', joints, blueprintJoints) for c in containers: cmds.lockNode(c, lock=True, lockUnpublished=True)
def setupBasicStretchyIK(self, sJoint, eJoint, creationPose_sJoint, controlObject, moduleContainer, moduleGrp): ikNodes = utils.basic_stretchy_IK( sJoint, eJoint, container=moduleContainer, scaleCorrectionAttribute=self.blueprintNamespace + ":module_grp.hierarchicalScale", lockMinimumLength=False) ikHandle = ikNodes["ikHandle"] rootLocator = ikNodes["rootLocator"] endLocator = ikNodes["endLocator"] poleVectorLocator = ikNodes["poleVectorObject"] for loc in [rootLocator, ikHandle]: cmds.parent(loc, moduleGrp, absolute=True) cmds.parent(poleVectorLocator, creationPose_sJoint) cmds.setAttr(poleVectorLocator + ".translateX", 0) cmds.setAttr(poleVectorLocator + ".translateY", 10) cmds.setAttr(poleVectorLocator + ".translateZ", 0) utils.matchTwistAngle(ikHandle + ".twist", [ sJoint, ], [ creationPose_sJoint, ]) cmds.parent(poleVectorLocator, controlObject, absolute=True) return (rootLocator, endLocator)
def match(self, *args): # Unlock all the containers characterContainer = self.characterNamespaceOnly + ":character_container" blueprintContainer = self.blueprintNamespace + ":module_container" moduleContainer = self.blueprintNamespace + ":" + self.moduleNamespace +":module_container" containers = [characterContainer, blueprintContainer, moduleContainer] for c in containers: cmds.lockNode(c, lock=False, lockUnpublished=False) joints = utils.findJointChain(self.blueprintNamespace+":"+self.moduleNamespace+":joints_grp") blueprintJoints = utils.findJointChain(self.blueprintNamespace+":blueprint_joints_grp") ikHandleControl = self.blueprintNamespace + ":" + self.moduleNamespace + ":ikHandleControl" cmds.setAttr(ikHandleControl+".stretchiness", 1) endPos = cmds.xform(blueprintJoints[ len(blueprintJoints)-1], q=True, ws=True, t=True) cmds.xform(ikHandleControl, ws=True, a=True, t=endPos) joints.pop(0) blueprintJoints.pop(0) utils.matchTwistAngle(ikHandleControl+".twist", joints, blueprintJoints) for c in containers: cmds.lockNode(c, lock=True, lockUnpublished=True)
def match(self, *args): characterContainer = self.characterNamespaceOnly + ":character_container" blueprintContainer = self.blueprintNamespace + ":module_container" moduleContainer = self.blueprintNamespace + ":" + self.moduleNamespace +":module_container" containers = [characterContainer, blueprintContainer, moduleContainer] for c in containers: cmds.lockNode(c, lock=False, lockUnpublished=False) ikJointsAll = utils.findJointChain(self.blueprintNamespace + ":" + self.moduleNamespace + ":joints_grp") blueprintJointsAll = utils.findJointChain(self.blueprintNamespace + ":blueprint_joints_grp") ikJoints = [ikJointsAll[1], ikJointsAll[2], ikJointsAll[3]] blueprintJoints = [blueprintJointsAll[1], blueprintJointsAll[2], blueprintJointsAll[3]] ikHandleControl = self.blueprintNamespace + ":" + self.moduleNamespace + ":ikHandleControl" if cmds.objExists(ikHandleControl): cmds.setAttr(ikHandleControl+".stretchiness", 1) endPos = cmds.xform(blueprintJoints[2], q=True, worldSpace=True, translation=True) cmds.xform(ikHandleControl, worldSpace=True, absolute=True, translation=endPos) twistControl = self.blueprintNamespace + ":" + self.moduleNamespace + ":twistControl" utils.matchTwistAngle(twistControl+".rotateZ", ikJoints, blueprintJoints) for c in containers: cmds.lockNode(c, lock=True, lockUnpublished=True)
def createFKControl(self, joint, parent, moduleContainer): fkControlInfo = self.initFKControl(joint, spaceSwitchable=True) fkControl = fkControlInfo[0] rootControlParent = fkControlInfo[1] translationControl = fkControlInfo[2] cmds.parent(rootControlParent, parent, relative=True) pointConstraint = "" if translationControl: cmds.xform(fkControl, worldSpace=True, a=True, translation=cmds.xform(joint, q=True, ws=True, translation=True)) pointConstraint = cmds.pointConstraint(fkControl, joint, mo=False, n=joint+"_pointConstraint")[0] else: pointConstraint = cmds.pointConstraint(joint, rootControlParent, maintainOffset=False, n=rootControlParent+"_pointConstraint")[0] jointOrientation = cmds.xform(joint, q=True, ws=True, rotation=True) cmds.xform(fkControl, ws=True, a=True, rotation=jointOrientation) children = cmds.listRelatives(joint, children=True, type="joint") childJoint = None if children == None: childJoint = cmds.duplicate(joint, n=joint+"_child")[0] utils.addNodeToContainer(moduleContainer, childJoint) cmds.parent(childJoint, joint, a=True) cmds.setAttr(childJoint+".translateX", 1.0) else: childJoint = children[0] ikNodes = cmds.ikHandle(sj=joint, ee=childJoint, n=joint+"_ikHandle", sol="ikRPsolver") ikNodes[1] = cmds.rename(ikNodes[1], joint+"_effector") ikHandle = ikNodes[0] cmds.parent(ikHandle, fkControl, a=True) poleVectorLocator = cmds.spaceLocator(n=joint+"_poleVectorLoc")[0] cmds.parent(poleVectorLocator, joint, relative=True) cmds.setAttr(poleVectorLocator+".translateY", 3) cmds.parent(poleVectorLocator, fkControl, a=True) for node in [poleVectorLocator, ikHandle]: cmds.setAttr(node+".visibility", 0) jointName = utils.stripAllNamespaces(joint)[1] creationPoseJoint = self.blueprintNamespace + ":creationPose_" + jointName utils.matchTwistAngle(ikHandle+".twist", [joint,], [creationPoseJoint,]) containedNodes = list(ikNodes) containedNodes.append(pointConstraint) containedNodes.append(poleVectorLocator) utils.addNodeToContainer(moduleContainer, containedNodes)
def setupBasicStretchyIK(self, sJoint, eJoint, creationPose_sJoint, controlObject, moduleContainer, moduleGrp): ikNodes = utils.basic_stretchy_IK(sJoint, eJoint, container=moduleContainer, scaleCorrectionAttribute=self.blueprintNamespace+":module_grp.hierarchicalScale", lockMinimumLength=False) ikHandle = ikNodes["ikHandle"] rootLocator = ikNodes["rootLocator"] endLocator = ikNodes["endLocator"] poleVectorLocator = ikNodes["poleVectorObject"] for loc in [rootLocator, ikHandle]: cmds.parent(loc, moduleGrp, absolute=True) cmds.parent(poleVectorLocator, creationPose_sJoint) cmds.setAttr(poleVectorLocator+".translateX", 0) cmds.setAttr(poleVectorLocator+".translateY", 10) cmds.setAttr(poleVectorLocator+".translateZ", 0) utils.matchTwistAngle(ikHandle+".twist", [sJoint,], [creationPose_sJoint,]) cmds.parent(poleVectorLocator, controlObject, absolute=True) return (rootLocator, endLocator)
def match(self, *args): characterContainer = self.characterNamespaceOnly + ":character_container" blueprintContainer = self.blueprintNamespace + ":module_container" moduleContainer = self.blueprintNamespace + ":" + self.moduleNamespace + ":module_container" containers = [characterContainer, blueprintContainer, moduleContainer] for c in containers: cmds.lockNode(c, lock=False, lockUnpublished=False) ikJointsAll = utils.findJointChain(self.blueprintNamespace + ":" + self.moduleNamespace + ":joints_grp") blueprintJointsAll = utils.findJointChain(self.blueprintNamespace + ":blueprint_joints_grp") ikJoints = [ikJointsAll[1], ikJointsAll[2], ikJointsAll[3]] blueprintJoints = [ blueprintJointsAll[1], blueprintJointsAll[2], blueprintJointsAll[3] ] ikHandleControl = self.blueprintNamespace + ":" + self.moduleNamespace + ":ikHandleControl" if cmds.objExists(ikHandleControl): cmds.setAttr(ikHandleControl + ".stretchiness", 1) endPos = cmds.xform(blueprintJoints[2], q=True, worldSpace=True, translation=True) cmds.xform(ikHandleControl, worldSpace=True, absolute=True, translation=endPos) twistControl = self.blueprintNamespace + ":" + self.moduleNamespace + ":twistControl" utils.matchTwistAngle(twistControl + ".rotateZ", ikJoints, blueprintJoints) for c in containers: cmds.lockNode(c, lock=True, lockUnpublished=True)
def install_custom(self,joints,moduleGrp,moduleContainer): containedNodes = [] rootJoint = joints[1] endJoint = joints[len(joints) -1] ikNodes = utils.basic_stretchy_IK(rootJoint, endJoint, container=moduleContainer, scaleCorrectionAttribute=self.blueprintNamespace+':module_grp.hierarchicalScale') ikHandle = ikNodes['ikHandle'] rootLocator = ikNodes['rootLocator'] endLocator = ikNodes['endLocator'] poleVectorLocator = ikNodes['poleVectorObject'] stretchinessAttribute = ikNodes['stretchinessAttribute'] for node in [rootLocator, ikHandle, poleVectorLocator]: cmds.parent(node, moduleGrp, absolute=True) name = 'ikHandleControl' controlObjectInstance = controlObject.ControlObject() handleControlInfo = controlObjectInstance.create(name, 'cubeLocator.ma', self , lod=1, translation=True, rotation=True, globalScale=False, spaceSwitching=True) handleControl = handleControlInfo[0] handleRootParent = handleControlInfo[1] cmds.parent(handleRootParent, moduleGrp, relative=True) cmds.xform(handleControl, worldSpace=True, absolute=True, translation=cmds.xform(endLocator, q=True, worldSpace=True, translation=True)) cmds.parent(endLocator, handleControl, absolute=True) handleControlParent = cmds.listRelatives(handleControl, parent=True)[0] preTransform = cmds.group(empty=True, n=handleControl+'_preTransform') containedNodes.append(preTransform) cmds.parent(preTransform, handleControl, relative=True) cmds.parent(preTransform, handleControlParent, absolute=True) cmds.parent(handleControl, preTransform, absolute=True) cmds.select(handleControl) cmds.addAttr(at='float', minValue=0.0, maxValue=1.0, defaultValue=1.0, keyable=True, longName='stretchiness') cmds.addAttr(at='float', softMinValue=360.0, softMaxValue=360.0, defaultValue=0.0, keyable=True, longName='twist') cmds.connectAttr(handleControl+'.twist', ikHandle+'.twist') cmds.connectAttr(handleControl+'.stretchiness', stretchinessAttribute) self.publishNameToModuleContainer(handleControl+'.twist', 'twist', publishToOuterContainers=True) self.publishNameToModuleContainer(handleControl+'.stretchiness', 'stretchiness', publishToOuterContainers=True) jointName = utils.stripAllNamespaces(rootJoint)[1] ikJoints = utils.findJointChain(rootJoint) targetJoints = utils.findJointChain(self.blueprintNamespace+':creationPose_'+jointName) utils.matchTwistAngle(handleControl+'.twist',ikJoints,targetJoints) offsetNode = cmds.shadingNode('plusMinusAverage', asUtility=True, n=handleControl+'_twistOffset') containedNodes.append(offsetNode) cmds.setAttr(offsetNode+'.input1D[0]',cmds.getAttr(handleControl+'.twist')) cmds.connectAttr(handleControl+'.twist', offsetNode+'.input1D[1]') cmds.connectAttr(offsetNode+'.output1D', ikHandle+'.twist', force=True) cmds.setAttr(handleControl+'.twist',0.0) utils.addNodeToContainer(moduleContainer,containedNodes)
def install_custom(self, joints, moduleGrp, moduleContainer): result = cmds.confirmDialog( title="Interpolation-based Stretchy Spline", message="please specify the root control type:", button=["Translation and Rotation", "Rotation Only", "None"], defaultButton="Translation and Rotation", cancelButton="None", dismissString="None") rootControlTranslation = (result == "Translation and Rotation") createRootControl = not (result == "None") containedNodes = [] creationPoseJoints = [] for joint in joints: jointName = utils.stripAllNamespaces(joint)[1] creationPoseJoint = self.blueprintNamespace + ":creationPose_" + jointName creationPoseJoints.append(creationPoseJoint) # Create root and end controls rootControlObject = moduleGrp if createRootControl: rootControlObjectInfo = self.createRootEndControl( "rootControl", creationPoseJoints[1], creationPoseJoints[1], rootControlTranslation, containedNodes, moduleGrp) #"Return Tuple. [0] is object, [1] parent" rootControlObject = rootControlObjectInfo[0] rootControlParent = rootControlObjectInfo[1] if not rootControlTranslation: containedNodes.append( cmds.pointConstraint(moduleGrp, rootControlParent, maintainOffset=True)[0]) # Orient end joint based off second to last joint endControlObjectInfo = self.createRootEndControl( "endControl", creationPoseJoints[len(creationPoseJoints) - 2], creationPoseJoints[len(creationPoseJoints) - 1], True, containedNodes, moduleGrp) endControlObject = endControlObjectInfo[0] # Setup splineIK # Duplicate stretchyIKJoints and rename stretchyIKJoints = cmds.duplicate(joints, renameChildren=True) index = 0 for joint in stretchyIKJoints: stretchyIKJoints[index] = cmds.rename( joint, joints[index] + "_stretchyIKJoint") index += 1 containedNodes.extend(stretchyIKJoints) # Get the ws position of the root and end joints rootJoint = stretchyIKJoints[1] endJoint = stretchyIKJoints[len(stretchyIKJoints) - 1] secondJoint = stretchyIKJoints[2] secondToLastJoint = stretchyIKJoints[len(stretchyIKJoints) - 2] rootPos = cmds.xform(rootJoint, q=True, ws=True, translation=True) endPos = cmds.xform(endJoint, q=True, ws=True, translation=True) rootLocator = cmds.spaceLocator(n=stretchyIKJoints[0] + "_systemStretch_rootLocator")[0] cmds.xform(rootLocator, ws=True, absolute=True, translation=rootPos) #containedNodes.append(rootLocator) endLocator = cmds.spaceLocator(n=stretchyIKJoints[0] + "_systemStretch_endLocator")[0] cmds.xform(endLocator, ws=True, absolute=True, translation=endPos) #containedNodes.append(endLocator) # Hide locators for loc in [rootLocator, endLocator]: cmds.setAttr(loc + ".visibility", 0) #parent locators to controls cmds.parent(rootLocator, rootControlObject, absolute=True) cmds.parent(endLocator, endControlObject, absolute=True) index = 0 for joint in stretchyIKJoints: if index > 2 and index < len(stretchyIKJoints) - 1: cmds.select(stretchyIKJoints[index], replace=True) cmds.addAttr(at="float", longName="originalLength") originalLength = cmds.getAttr(stretchyIKJoints[index] + ".translateX") cmds.setAttr(stretchyIKJoints[index] + ".originalLength", originalLength) index += 1 # Setup the scale factor scaleFactorAttr = self.createDistanceCalculations( rootLocator, endLocator, containedNodes) rootScaler = self.createScalar(rootLocator, scaleFactorAttr, containedNodes) endScaler = self.createScalar(endLocator, scaleFactorAttr, containedNodes) rootIKLocators = self.setupBasicStretchyIK(rootJoint, secondJoint, creationPoseJoints[1], rootControlObject, moduleContainer, moduleGrp) rootIK_rootLocator = rootIKLocators[0] rootIK_endLocator = rootIKLocators[1] cmds.parent(rootIK_endLocator, rootScaler, absolute=True) endIKLocators = self.setupBasicStretchyIK( secondToLastJoint, endJoint, creationPoseJoints[len(creationPoseJoints) - 2], endControlObject, moduleContainer, moduleGrp) endIK_rootLocator = endIKLocators[0] endIK_endLocator = endIKLocators[1] cmds.parent(endIK_endLocator, endControlObject, absolute=True) ikNodes = cmds.ikHandle(sj=secondJoint, ee=secondToLastJoint, n=secondJoint + "_splineIKHandle", sol="ikSplineSolver", rootOnCurve=False, createCurve=True) ikNodes[1] = cmds.rename(ikNodes[1], secondJoint + "_splineIKEffector") ikNodes[2] = cmds.rename(ikNodes[2], secondJoint + "_splineIKCurve") splineIKhandle = ikNodes[0] splineIKCurve = ikNodes[2] containedNodes.extend(ikNodes) cmds.parent(splineIKhandle, moduleGrp, absolute=True) cmds.setAttr(splineIKhandle + ".visibility", 0) cmds.setAttr(splineIKCurve + ".visibility", 0) cmds.parent(splineIKCurve, world=True, absolute=True) cmds.setAttr(splineIKCurve + ".inheritsTransform", 0) cmds.parent(splineIKCurve, moduleGrp, relative=True) # Create a cluster for the CV's on the curve. cmds.select(splineIKCurve + ".cv[0:1]", replace=True) clusterNodes = cmds.cluster(n=splineIKCurve + "_rootCluster") cmds.container(moduleContainer, edit=True, addNode=clusterNodes, ihb=True, includeNetwork=True) rootClusterHandle = clusterNodes[1] cmds.select(splineIKCurve + ".cv[2:3]", replace=True) clusterNodes = cmds.cluster(n=splineIKCurve + "_endCluster") cmds.container(moduleContainer, edit=True, addNode=clusterNodes, ihb=True, includeNetwork=True) endClusterHandle = clusterNodes[1] for handle in [rootClusterHandle, endClusterHandle]: cmds.setAttr(handle + ".visibility", 0) cmds.parent(rootClusterHandle, rootScaler, absolute=True) cmds.parent(endClusterHandle, endScaler, absolute=True) containedNodes.append( cmds.parentConstraint(rootControlObject, rootJoint, maintainOffset=True)[0]) targetLocatorNodes = cmds.duplicate(endIK_rootLocator, name=endIK_rootLocator + "_duplicateTarget") targetLocator = targetLocatorNodes[0] cmds.delete(targetLocatorNodes[1]) cmds.parent(targetLocator, endScaler, absolute=True) splineScaleFactorAttr = self.createDistanceCalculations( rootIK_endLocator, targetLocator, containedNodes) # Use scaleFactor on each of the joints index = 0 for joint in stretchyIKJoints: if index > 2 and index < len(stretchyIKJoints) - 1: multNode = cmds.shadingNode("multiplyDivide", asUtility=True, n=joint + "_jointScale") containedNodes.append(multNode) cmds.connectAttr(scaleFactorAttr, multNode + ".input1X") cmds.setAttr(multNode + ".input2X", cmds.getAttr(joint + ".originalLength")) cmds.connectAttr(multNode + ".outputX", joint + ".translateX") index += 1 cmds.setAttr(splineIKhandle + ".dTwistControlEnable", 1) cmds.setAttr(splineIKhandle + ".dWorldUpType", 4) cmds.setAttr(splineIKhandle + ".dWorldUpAxis", 5) cmds.setAttr(splineIKhandle + ".dWorldUpVector", 0.0, 0.0, 1.0, type="double3") cmds.setAttr(splineIKhandle + ".dWorldUpVectorEnd", 0.0, 0.0, 1.0, type="double3") if createRootControl: cmds.connectAttr(rootControlObject + ".worldMatrix[0]", splineIKhandle + ".dWorldUpMatrix") else: dummyNode = cmds.duplicate(rootJoint, parentOnly=True, n=rootJoint + "_dummyDuplicate")[0] containedNodes.append(dummyNode) cmds.parent(dummyNode, moduleGrp, absolute=True) cmds.connectAttr(dummyNode + ".worldMatrix[0]", splineIKhandle + ".dWorldUpMatrix") cmds.connectAttr(endControlObject + ".worldMatrix[0]", splineIKhandle + ".dWorldUpMatrixEnd") # Create 2 attributes for "offsetY and offsetZ". cmds.select(moduleGrp) cmds.addAttr(at="float", defaultValue=0.0, softMinValue=-10.0, softMaxValue=10.0, keyable=True, longName="offsetY") cmds.addAttr(at="float", defaultValue=0.0, softMinValue=-10.0, softMaxValue=10.0, keyable=True, longName="offsetZ") # Publish new attrs to container self.publishNameToModuleContainer(moduleGrp + ".offsetY", "interpolator_offsetY", publishToOuterContainers=True) self.publishNameToModuleContainer(moduleGrp + ".offsetZ", "interpolator_offsetZ", publishToOuterContainers=True) # Create a node to inverse offset inverseNode = cmds.shadingNode("multiplyDivide", asUtility=True, n=moduleGrp + "_offsetInverse") containedNodes.append(inverseNode) cmds.connectAttr(moduleGrp + ".offsetY", inverseNode + ".input1Y") cmds.connectAttr(moduleGrp + ".offsetZ", inverseNode + ".input1Z") cmds.setAttr(inverseNode + ".input2Y", -1) cmds.setAttr(inverseNode + ".input2Z", -1) # Setup interpolators numStretchyIKJoints = len(stretchyIKJoints) - 1 interpolators_ikParents = [] aimChildren = [] for i in range(1, numStretchyIKJoints): if i > 1: # Create a group to follow each joint jointFollower = cmds.group(empty=True, n=stretchyIKJoints[i] + "_follower") containedNodes.append(jointFollower) # Parent the group to the joint we are following cmds.parent(jointFollower, moduleGrp, relative=True) containedNodes.append( cmds.parentConstraint(stretchyIKJoints[i], jointFollower, maintainOffset=False, n=jointFollower + "_parentConstraint")[0]) offset = cmds.group(empty=True, n=stretchyIKJoints[i] + "_interpolatorOffset") containedNodes.append(offset) # parent the offset group to the follower group cmds.parent(offset, jointFollower, relative=True) cmds.connectAttr(moduleGrp + ".offsetY", offset + ".translateY") cmds.connectAttr(moduleGrp + ".offsetZ", offset + ".translateZ") name = utils.stripAllNamespaces( joints[i])[1] + "_offsetControl" controlObjectInstance = controlObject.ControlObject() offsetControlObject = controlObjectInstance.create( name, "cubeLocator.ma", self, lod=2, translation=True, rotation=False, globalScale=False, spaceSwitching=False)[0] # parent control object under offset group cmds.parent(offsetControlObject, offset, relative=True) offsetCancelation = cmds.group(empty=True, n=stretchyIKJoints[i] + "interpolatorOffsetCancelation") containedNodes.append(offsetCancelation) cmds.parent(offsetCancelation, offsetControlObject, relative=True) cmds.connectAttr(inverseNode + ".outputY", offsetCancelation + ".translateY") cmds.connectAttr(inverseNode + ".outputZ", offsetCancelation + ".translateZ") interpolators_ikParents.append(offsetCancelation) aimChild = cmds.group(empty=True, n=stretchyIKJoints[i] + "_aimChild") containedNodes.append(aimChild) aimChildren.append(aimChild) if i > 1: cmds.parent(aimChild, offsetCancelation, relative=True) print "parent offset cancel" else: cmds.parent(aimChild, stretchyIKJoints[i], relative=True) cmds.setAttr(aimChild + ".translateY", -1) # Make use of interpolation nodes for i in range(1, numStretchyIKJoints): ikNodes = utils.basic_stretchy_IK( joints[i], joints[i + 1], container=moduleContainer, scaleCorrectionAttribute=self.blueprintNamespace + ":module_grp.hierarchicalScale", lockMinimumLength=False, poleVectorObject=aimChildren[i - 1]) ikHandle = ikNodes["ikHandle"] rootLocator = ikNodes["rootLocator"] endLocator = ikNodes["endLocator"] for loc in (ikHandle, rootLocator): cmds.parent(loc, moduleGrp, absolute=True) utils.matchTwistAngle(ikHandle + ".twist", [ joints[i], ], [ stretchyIKJoints[i], ]) if i == 1: if createRootControl: containedNodes.append( cmds.pointConstraint(rootControlObject, joints[i], maintainOffset=False, n=joints[i] + "_pointConstraint")[0]) cmds.setAttr(endLocator + ".translate", 0.0, 0.0, 0.0, type="double3") if i < numStretchyIKJoints - 1: cmds.parent(endLocator, interpolators_ikParents[i - 1], relative=True) else: cmds.parent(endLocator, endControlObject, relative=True) cmds.setAttr(moduleGrp + ".lod", 2) utils.addNodeToContainer(moduleContainer, containedNodes, ihb=True) # Publish joints to module container. for joint in stretchyIKJoints: jointName = utils.stripAllNamespaces(joint)[1] self.publishNameToModuleContainer(joint + ".rotate", jointName + "_R", publishToOuterContainers=False) self.publishNameToModuleContainer(joint + ".translate", jointName + "_T", publishToOuterContainers=False)
def install_custom(self, joints, moduleGrp, moduleContainer, createHandleControl=True, poleVectorAtRoot=True): rootJoint = joints[1] hingeJoint = joints[2] endJoint = joints[3] containedNodes = [] twistRotationAimer = cmds.group(empty=True, n=rootJoint+"_twistRotationAimer") containedNodes.append(twistRotationAimer) containedNodes.append(cmds.pointConstraint(rootJoint, twistRotationAimer, maintainOffset=False, n=twistRotationAimer+"_pointConstraint")[0]) cmds.pointConstraint(endJoint, twistRotationAimer, maintainOffset=False) upVectorTarget = cmds.group(empty=True, n=rootJoint+"_twistRotationAimer_upVectorTarget") containedNodes.append(upVectorTarget) cmds.parent(upVectorTarget, hingeJoint, relative=True) cmds.setAttr(upVectorTarget+".translateZ", cmds.getAttr(hingeJoint+".translateX")) containedNodes.append(cmds.aimConstraint(endJoint, twistRotationAimer, maintainOffset=False, n=twistRotationAimer+"_aimConstraint", aimVector=[0.0, 0.0, 1.0], upVector=[1.0, 0.0, 0.0], worldUpType="object", worldUpObject=upVectorTarget)[0]) tempLocator = cmds.spaceLocator()[0] cmds.parent(tempLocator, twistRotationAimer, relative=True) cmds.setAttr(tempLocator+".translateY", 10) twistRotationAimerPos = cmds.xform(twistRotationAimer, q=True, worldSpace=True, translation=True) tempLocatorPos = cmds.xform(tempLocator, q=True, worldSpace=True, translation=True) offsetVector = [tempLocatorPos[0] - twistRotationAimerPos[0], tempLocatorPos[1] - twistRotationAimerPos[1], tempLocatorPos[2] - twistRotationAimerPos[2]] cmds.delete(tempLocator) ikNodes = utils.basic_stretchy_IK(rootJoint, endJoint, container=moduleContainer, scaleCorrectionAttribute=self.blueprintNamespace+":module_grp.hierarchicalScale") ikHandle = ikNodes["ikHandle"] rootPosLocator = ikNodes["rootLocator"] endPosLocator = ikNodes["endLocator"] poleVectorLocator = ikNodes["poleVectorObject"] stretchinessAttribute = ikNodes["stretchinessAttribute"] for node in [ikHandle, rootPosLocator, endPosLocator, poleVectorLocator]: cmds.parent(node, moduleGrp, absolute=True) if poleVectorAtRoot: poleVectorPos = cmds.xform(rootJoint, q=True, worldSpace=True, translation=True) else: poleVectorPos = cmds.xform(endJoint, q=True, worldSpace=True, translation=True) poleVectorPos[0] += offsetVector[0] poleVectorPos[1] += offsetVector[1] poleVectorPos[2] += offsetVector[2] cmds.xform(poleVectorLocator, worldSpace=True, absolute=True, translation=poleVectorPos) if createHandleControl: name = "ikHandleControl" controlObjectInstance = controlObject.ControlObject() handleControlInfo = controlObjectInstance.create(name, "cubeLocator.ma", self, lod=1, translation=True, rotation=True, globalScale=False, spaceSwitching=True) handleControl = handleControlInfo[0] handleRootParent = handleControlInfo[1] cmds.parent(handleRootParent, moduleGrp, relative=True) cmds.xform(handleControl, worldSpace=True, absolute=True, translation=cmds.xform(endPosLocator, q=True, worldSpace=True, translation=True)) pointConstraint = cmds.pointConstraint(handleControl, endPosLocator, maintainOffset=False, n=endPosLocator+"_pointConstraint")[0] containedNodes.append(pointConstraint) cmds.select(handleControl) cmds.addAttr(at="float", minValue=0.0, maxValue=1.0, defaultValue=1.0, keyable=True, longName="stretchiness") cmds.connectAttr(handleControl+".stretchiness", stretchinessAttribute) self.publishNameToModuleContainer(handleControl+".stretchiness", "stretchiness", publishToOuterContainers=True) rotationCancellation = cmds.group(empty=True, n=self.blueprintNamespace+":"+self.moduleNamespace+":twistRotationCancellation") containedNodes.append(rotationCancellation) cmds.parent(rotationCancellation, twistRotationAimer, relative=True) twistControlOffset = cmds.group(empty=True, n=self.blueprintNamespace + ":" + self.moduleNamespace + ":twistControlOffset") containedNodes.append(twistControlOffset) cmds.parent(twistControlOffset, rotationCancellation, relative=True) twistControlObjectInstance = controlObject.ControlObject() twistControlInfo = twistControlObjectInstance.create("twistControl", "zAxisCircle.ma", self, lod=2, translation=False, rotation=[False, False, True], globalScale=False, spaceSwitching=True) twistControl = twistControlInfo[0] cmds.parent(twistControl, twistControlOffset, relative=True) cmds.connectAttr(twistControl+".rotateZ", ikHandle+".twist") pivotMultNode = cmds.shadingNode("multiplyDivide", asUtility=True, n=twistControl+"_invertOffset") containedNodes.append(pivotMultNode) cmds.connectAttr(twistControlOffset+".translateX", pivotMultNode+".input1X") cmds.setAttr(pivotMultNode+".input2X", -1) cmds.connectAttr(pivotMultNode+".output", twistControl+".rotatePivot") multNode = cmds.shadingNode("multiplyDivide", asUtility=True, n=rotationCancellation+"_invertRotateZ") containedNodes.append(multNode) cmds.connectAttr(twistControl+".rotateZ", multNode+".input1X") cmds.setAttr(multNode+".input2X", -1) cmds.connectAttr(multNode+".outputX", rotationCancellation+".rotateZ") cmds.parent(twistRotationAimer, moduleGrp, absolute=True) ikJoints = [joints[1], joints[2], joints[3]] jointName = utils.stripAllNamespaces(joints[1])[1] creationPoseRoot = self.blueprintNamespace+":creationPose_"+jointName creationPoseJoints = utils.findJointChain(creationPoseRoot) targetJoints = [creationPoseJoints[0], creationPoseJoints[1], creationPoseJoints[2]] utils.matchTwistAngle(twistControl+".rotateZ", ikJoints, targetJoints) offsetNode = cmds.shadingNode("plusMinusAverage", asUtility=True, n=twistControl+"_twistOffset") containedNodes.append(offsetNode) cmds.setAttr(offsetNode+".input1D[0]", cmds.getAttr(twistControl+".rotateZ")) cmds.connectAttr(twistControl+".rotateZ", offsetNode+".input1D[1]") cmds.connectAttr(offsetNode+".output1D", ikHandle+".twist", force=True) utils.forceSceneUpdate() cmds.setAttr(twistControl+".rotateZ", 0) utils.addNodeToContainer(moduleContainer, containedNodes) self.publishNameToModuleContainer(twistControlOffset+".translateX", "twistControlOffset", publishToOuterContainers=True) cmds.setAttr(moduleGrp+".lod", 2) return(ikNodes)
def install_custom(self, joints, moduleGrp, moduleContainer, createHandleControl=True, poleVectorAtRoot=True): rootJoint = joints[1] hingeJoint = joints[2] endJoint = joints[3] containedNodes = [] twistRotationAimer = cmds.group(empty=True, n=rootJoint + "_twistRotationAimer") containedNodes.append(twistRotationAimer) containedNodes.append( cmds.pointConstraint(rootJoint, twistRotationAimer, maintainOffset=False, n=twistRotationAimer + "_pointConstraint")[0]) cmds.pointConstraint(endJoint, twistRotationAimer, maintainOffset=False) upVectorTarget = cmds.group(empty=True, n=rootJoint + "_twistRotationAimer_upVectorTarget") containedNodes.append(upVectorTarget) cmds.parent(upVectorTarget, hingeJoint, relative=True) cmds.setAttr(upVectorTarget + ".translateZ", cmds.getAttr(hingeJoint + ".translateX")) containedNodes.append( cmds.aimConstraint(endJoint, twistRotationAimer, maintainOffset=False, n=twistRotationAimer + "_aimConstraint", aimVector=[0.0, 0.0, 1.0], upVector=[1.0, 0.0, 0.0], worldUpType="object", worldUpObject=upVectorTarget)[0]) tempLocator = cmds.spaceLocator()[0] cmds.parent(tempLocator, twistRotationAimer, relative=True) cmds.setAttr(tempLocator + ".translateY", 10) twistRotationAimerPos = cmds.xform(twistRotationAimer, q=True, worldSpace=True, translation=True) tempLocatorPos = cmds.xform(tempLocator, q=True, worldSpace=True, translation=True) offsetVector = [ tempLocatorPos[0] - twistRotationAimerPos[0], tempLocatorPos[1] - twistRotationAimerPos[1], tempLocatorPos[2] - twistRotationAimerPos[2] ] cmds.delete(tempLocator) ikNodes = utils.basic_stretchy_IK( rootJoint, endJoint, container=moduleContainer, scaleCorrectionAttribute=self.blueprintNamespace + ":module_grp.hierarchicalScale") ikHandle = ikNodes["ikHandle"] rootPosLocator = ikNodes["rootLocator"] endPosLocator = ikNodes["endLocator"] poleVectorLocator = ikNodes["poleVectorObject"] stretchinessAttribute = ikNodes["stretchinessAttribute"] for node in [ ikHandle, rootPosLocator, endPosLocator, poleVectorLocator ]: cmds.parent(node, moduleGrp, absolute=True) if poleVectorAtRoot: poleVectorPos = cmds.xform(rootJoint, q=True, worldSpace=True, translation=True) else: poleVectorPos = cmds.xform(endJoint, q=True, worldSpace=True, translation=True) poleVectorPos[0] += offsetVector[0] poleVectorPos[1] += offsetVector[1] poleVectorPos[2] += offsetVector[2] cmds.xform(poleVectorLocator, worldSpace=True, absolute=True, translation=poleVectorPos) if createHandleControl: name = "ikHandleControl" controlObjectInstance = controlObject.ControlObject() handleControlInfo = controlObjectInstance.create( name, "cubeLocator.ma", self, lod=1, translation=True, rotation=True, globalScale=False, spaceSwitching=True) handleControl = handleControlInfo[0] handleRootParent = handleControlInfo[1] cmds.parent(handleRootParent, moduleGrp, relative=True) cmds.xform(handleControl, worldSpace=True, absolute=True, translation=cmds.xform(endPosLocator, q=True, worldSpace=True, translation=True)) pointConstraint = cmds.pointConstraint(handleControl, endPosLocator, maintainOffset=False, n=endPosLocator + "_pointConstraint")[0] containedNodes.append(pointConstraint) cmds.select(handleControl) cmds.addAttr(at="float", minValue=0.0, maxValue=1.0, defaultValue=1.0, keyable=True, longName="stretchiness") cmds.connectAttr(handleControl + ".stretchiness", stretchinessAttribute) self.publishNameToModuleContainer(handleControl + ".stretchiness", "stretchiness", publishToOuterContainers=True) rotationCancellation = cmds.group(empty=True, n=self.blueprintNamespace + ":" + self.moduleNamespace + ":twistRotationCancellation") containedNodes.append(rotationCancellation) cmds.parent(rotationCancellation, twistRotationAimer, relative=True) twistControlOffset = cmds.group(empty=True, n=self.blueprintNamespace + ":" + self.moduleNamespace + ":twistControlOffset") containedNodes.append(twistControlOffset) cmds.parent(twistControlOffset, rotationCancellation, relative=True) twistControlObjectInstance = controlObject.ControlObject() twistControlInfo = twistControlObjectInstance.create( "twistControl", "zAxisCircle.ma", self, lod=2, translation=False, rotation=[False, False, True], globalScale=False, spaceSwitching=True) twistControl = twistControlInfo[0] cmds.parent(twistControl, twistControlOffset, relative=True) cmds.connectAttr(twistControl + ".rotateZ", ikHandle + ".twist") pivotMultNode = cmds.shadingNode("multiplyDivide", asUtility=True, n=twistControl + "_invertOffset") containedNodes.append(pivotMultNode) cmds.connectAttr(twistControlOffset + ".translateX", pivotMultNode + ".input1X") cmds.setAttr(pivotMultNode + ".input2X", -1) cmds.connectAttr(pivotMultNode + ".output", twistControl + ".rotatePivot") multNode = cmds.shadingNode("multiplyDivide", asUtility=True, n=rotationCancellation + "_invertRotateZ") containedNodes.append(multNode) cmds.connectAttr(twistControl + ".rotateZ", multNode + ".input1X") cmds.setAttr(multNode + ".input2X", -1) cmds.connectAttr(multNode + ".outputX", rotationCancellation + ".rotateZ") cmds.parent(twistRotationAimer, moduleGrp, absolute=True) ikJoints = [joints[1], joints[2], joints[3]] jointName = utils.stripAllNamespaces(joints[1])[1] creationPoseRoot = self.blueprintNamespace + ":creationPose_" + jointName creationPoseJoints = utils.findJointChain(creationPoseRoot) targetJoints = [ creationPoseJoints[0], creationPoseJoints[1], creationPoseJoints[2] ] utils.matchTwistAngle(twistControl + ".rotateZ", ikJoints, targetJoints) offsetNode = cmds.shadingNode("plusMinusAverage", asUtility=True, n=twistControl + "_twistOffset") containedNodes.append(offsetNode) cmds.setAttr(offsetNode + ".input1D[0]", cmds.getAttr(twistControl + ".rotateZ")) cmds.connectAttr(twistControl + ".rotateZ", offsetNode + ".input1D[1]") cmds.connectAttr(offsetNode + ".output1D", ikHandle + ".twist", force=True) utils.forceSceneUpdate() cmds.setAttr(twistControl + ".rotateZ", 0) utils.addNodeToContainer(moduleContainer, containedNodes) self.publishNameToModuleContainer(twistControlOffset + ".translateX", "twistControlOffset", publishToOuterContainers=True) cmds.setAttr(moduleGrp + ".lod", 2) return (ikNodes)
def install_custom(self,joints,moduleGrp,moduleContainer, createHandleControl=True, poleVectorAtRoot=True): rootJoint = joints[1] hingeJoint = joints[2] endJoint = joints[3] containedNodes = [] twistRotationAimer = cmds.group(empty=True,n=rootJoint+'_twistRotationAimer') containedNodes.append(twistRotationAimer) containedNodes.append(cmds.pointConstraint(rootJoint,twistRotationAimer,maintainOffset=False, n=twistRotationAimer+'_pointConstraint')[0]) cmds.pointConstraint(endJoint,twistRotationAimer,maintainOffset=False) upVectorTarget = cmds.group(empty=True, n=rootJoint+'_twistRotationAimer_upVectorTarget') containedNodes.append(upVectorTarget) cmds.parent(upVectorTarget, hingeJoint,relative=True) cmds.setAttr(upVectorTarget+'.translateZ',cmds.getAttr(hingeJoint+'.translateX')) containedNodes.append(cmds.aimConstraint(endJoint, twistRotationAimer, maintainOffset=False, n=twistRotationAimer+'_aimConstraint', aimVector=[0.0,0.0,1.0],upVector=[1.0,0.0,0.0],worldUpType='object',worldUpObject=upVectorTarget)[0]) tempLocator = cmds.spaceLocator()[0] cmds.parent(tempLocator, twistRotationAimer,relative=True) cmds.setAttr(tempLocator+'.translateY',10) twistRotationAimerPos = cmds.xform(twistRotationAimer,q=True, worldSpace=True, translation=True) tempLocatorPos = cmds.xform(tempLocator,q=True, worldSpace=True, translation=True) offsetVector = [tempLocatorPos[0] - twistRotationAimerPos[0],tempLocatorPos[1] - twistRotationAimerPos[1],tempLocatorPos[2] - twistRotationAimerPos[2]] cmds.delete(tempLocator) ikNodes = utils.basic_stretchy_IK(rootJoint,endJoint,container=moduleContainer,scaleCorrectionAttribute=self.blueprintNamespace+':module_grp.hierarchicalScale') ikHandle = ikNodes['ikHandle'] rootPosLocator = ikNodes['rootLocator'] endPosLocator = ikNodes['endLocator'] poleVectorLocator = ikNodes['poleVectorObject'] stretchinessAttribute = ikNodes['stretchinessAttribute'] for node in [ikHandle,rootPosLocator,endPosLocator,poleVectorLocator]: cmds.parent(node,moduleGrp,absolute=True) if poleVectorAtRoot: poleVectorPos = cmds.xform(rootJoint,q=True,worldSpace=True,translation=True) else: poleVectorPos = cmds.xform(endJoint,q=True,worldSpace=True,translation=True) poleVectorPos[0] += offsetVector[0] poleVectorPos[1] += offsetVector[1] poleVectorPos[2] += offsetVector[2] cmds.xform(poleVectorLocator,worldSpace=True,absolute=True,translation=poleVectorPos) if createHandleControl: name = 'ikHandleControl' controlObjectInstance = controlObject.ControlObject() handleControlInfo = controlObjectInstance.create(name,'cubeLocator.ma',self,lod=1,translation=True,rotation=False,globalScale=False,spaceSwitching=True) handleControl = handleControlInfo[0] handleRootParent = handleControlInfo[1] cmds.parent(handleRootParent,moduleGrp,relative=True) cmds.xform(handleControl,worldSpace=True,absolute=True,translation=cmds.xform(endPosLocator,q=True,worldSpace=True,translation=True)) pointConstraint = cmds.pointConstraint(handleControl,endPosLocator, maintainOffset=False,n=endPosLocator+'_pointConstraint')[0] containedNodes.append(pointConstraint) cmds.select(handleControl) cmds.addAttr(at='float',minValue=0.0, maxValue=1.0, defaultValue=1.0,keyable=True,longName='stretchiness') cmds.connectAttr(handleControl+'.stretchiness',stretchinessAttribute) self.publishNameToModuleContainer(handleControl+'.stretchiness', 'stretchiness',publishToOuterContainers=True) rotationCancellation = cmds.group(empty=True,n=self.blueprintNamespace+':'+self.moduleNamespace+':twistRotationCancellation') containedNodes.append(rotationCancellation) cmds.parent(rotationCancellation, twistRotationAimer,relative=True) twistControlOffset = cmds.group(empty=True,n=self.blueprintNamespace + ':' + self.moduleNamespace + ':twistControlOffset') containedNodes.append(twistControlOffset) cmds.parent(twistControlOffset, rotationCancellation, relative=True) twistControlObjectInstance = controlObject.ControlObject() twistControlInfo = twistControlObjectInstance.create('twistControl','zAxisCircle.ma',self, lod=2,translation=False,rotation=[False,False,True],globalScale=False, spaceSwitching=False) twistControl = twistControlInfo[0] cmds.parent(twistControl,twistControlOffset,relative=True) cmds.connectAttr(twistControl+'.rotateZ',ikHandle+'.twist') pivotMultNode = cmds.shadingNode('multiplyDivide',asUtility=True,n=twistControl+'_invertOffset') containedNodes.append(pivotMultNode) cmds.connectAttr(twistControlOffset+'.translateX',pivotMultNode+'.input1X') cmds.setAttr(pivotMultNode+'.input2X',-1) cmds.connectAttr(pivotMultNode+'.output', twistControl+'.rotatePivot') multNode = cmds.shadingNode('multiplyDivide', asUtility=True, n=rotationCancellation+'_invertRotateZ') containedNodes.append(multNode) cmds.connectAttr(twistControl+'.rotateZ',multNode+'.input1X') cmds.setAttr(multNode+'.input2X',-1) cmds.connectAttr(multNode+'.outputX',rotationCancellation+'.rotateZ') cmds.parent(twistRotationAimer,moduleGrp, absolute=True) ikJoints = [joints[1],joints[2],joints[3]] jointName = utils.stripAllNamespaces(joints[1])[1] creationPoseRoot = self.blueprintNamespace+':creationPose_'+jointName creationPoseJoints = utils.findJointChain(creationPoseRoot) targetJoints = [creationPoseJoints[0],creationPoseJoints[1],creationPoseJoints[2]] utils.matchTwistAngle(twistControl+'.rotateZ',ikJoints,targetJoints) offsetNode = cmds.shadingNode('plusMinusAverage',asUtility=True,n=twistControl+'_twistOffset') containedNodes.append(offsetNode) cmds.setAttr(offsetNode+'.input1D[0]',cmds.getAttr(twistControl+'.rotateZ')) cmds.connectAttr(twistControl+'.rotateZ',offsetNode+'.input1D[1]') cmds.connectAttr(offsetNode+'.output1D',ikHandle+'.twist',force=True) utils.forceSceneUpdate() cmds.setAttr(twistControl+'.rotateZ',0) utils.addNodeToContainer(moduleContainer,containedNodes) self.publishNameToModuleContainer(twistControlOffset+'.translateX','twistControlOffset',publishToOuterContainers=True) cmds.setAttr(moduleGrp+'.lod',2) return (ikNodes)
def install_custom(self, joints, moduleGrp, moduleContainer): result = cmds.confirmDialog(title="Interpolation-based Stretchy Spline", message="please specify the root control type:", button=["Translation and Rotation", "Rotation Only", "None"], defaultButton="Translation and Rotation", cancelButton="None", dismissString="None") rootControlTranslation = (result == "Translation and Rotation") createRootControl = not (result == "None") containedNodes = [] creationPoseJoints = [] for joint in joints: jointName = utils.stripAllNamespaces(joint)[1] creationPoseJoint = self.blueprintNamespace+":creationPose_"+jointName creationPoseJoints.append(creationPoseJoint) # Create root and end controls rootControlObject = moduleGrp if createRootControl: rootControlObjectInfo = self.createRootEndControl("rootControl", creationPoseJoints[1], creationPoseJoints[1], rootControlTranslation, containedNodes, moduleGrp) #"Return Tuple. [0] is object, [1] parent" rootControlObject = rootControlObjectInfo[0] rootControlParent = rootControlObjectInfo[1] if not rootControlTranslation: containedNodes.append(cmds.pointConstraint(moduleGrp, rootControlParent, maintainOffset=True)[0]) # Orient end joint based off second to last joint endControlObjectInfo = self.createRootEndControl("endControl", creationPoseJoints[len(creationPoseJoints)-2], creationPoseJoints[len(creationPoseJoints)-1], True, containedNodes, moduleGrp) endControlObject = endControlObjectInfo[0] # Setup splineIK # Duplicate stretchyIKJoints and rename stretchyIKJoints = cmds.duplicate(joints, renameChildren=True) index = 0 for joint in stretchyIKJoints: stretchyIKJoints[index] = cmds.rename(joint, joints[index]+"_stretchyIKJoint") index +=1 containedNodes.extend(stretchyIKJoints) # Get the ws position of the root and end joints rootJoint = stretchyIKJoints[1] endJoint = stretchyIKJoints[len(stretchyIKJoints)-1] secondJoint = stretchyIKJoints[2] secondToLastJoint = stretchyIKJoints[len(stretchyIKJoints)-2] rootPos = cmds.xform(rootJoint, q=True, ws=True, translation=True) endPos = cmds.xform(endJoint, q=True, ws=True, translation=True) rootLocator = cmds.spaceLocator(n=stretchyIKJoints[0]+"_systemStretch_rootLocator")[0] cmds.xform(rootLocator, ws=True, absolute=True, translation=rootPos) #containedNodes.append(rootLocator) endLocator = cmds.spaceLocator(n=stretchyIKJoints[0]+"_systemStretch_endLocator")[0] cmds.xform(endLocator, ws=True, absolute=True, translation=endPos) #containedNodes.append(endLocator) # Hide locators for loc in [rootLocator, endLocator]: cmds.setAttr(loc+".visibility", 0) #parent locators to controls cmds.parent(rootLocator, rootControlObject, absolute=True) cmds.parent(endLocator, endControlObject, absolute=True) index = 0 for joint in stretchyIKJoints: if index > 2 and index < len(stretchyIKJoints)-1: cmds.select(stretchyIKJoints[index], replace=True) cmds.addAttr(at="float", longName="originalLength") originalLength = cmds.getAttr(stretchyIKJoints[index]+".translateX") cmds.setAttr(stretchyIKJoints[index]+".originalLength", originalLength) index += 1 # Setup the scale factor scaleFactorAttr = self.createDistanceCalculations(rootLocator, endLocator, containedNodes) rootScaler = self.createScalar(rootLocator, scaleFactorAttr, containedNodes) endScaler = self.createScalar(endLocator, scaleFactorAttr, containedNodes) rootIKLocators = self.setupBasicStretchyIK(rootJoint, secondJoint, creationPoseJoints[1], rootControlObject, moduleContainer, moduleGrp) rootIK_rootLocator = rootIKLocators[0] rootIK_endLocator = rootIKLocators[1] cmds.parent(rootIK_endLocator, rootScaler, absolute=True) endIKLocators = self.setupBasicStretchyIK(secondToLastJoint, endJoint, creationPoseJoints[len(creationPoseJoints)-2], endControlObject, moduleContainer, moduleGrp) endIK_rootLocator = endIKLocators[0] endIK_endLocator = endIKLocators[1] cmds.parent(endIK_endLocator, endControlObject, absolute=True) ikNodes = cmds.ikHandle(sj=secondJoint, ee=secondToLastJoint, n=secondJoint+"_splineIKHandle", sol="ikSplineSolver", rootOnCurve=False, createCurve=True ) ikNodes[1] = cmds.rename(ikNodes[1], secondJoint+"_splineIKEffector") ikNodes[2] = cmds.rename(ikNodes[2], secondJoint+"_splineIKCurve") splineIKhandle = ikNodes[0] splineIKCurve = ikNodes[2] containedNodes.extend(ikNodes) cmds.parent(splineIKhandle, moduleGrp, absolute=True) cmds.setAttr(splineIKhandle+".visibility", 0) cmds.setAttr(splineIKCurve+".visibility", 0) cmds.parent(splineIKCurve, world=True, absolute=True) cmds.setAttr(splineIKCurve+".inheritsTransform", 0) cmds.parent(splineIKCurve, moduleGrp, relative=True) # Create a cluster for the CV's on the curve. cmds.select(splineIKCurve+".cv[0:1]", replace=True) clusterNodes = cmds.cluster(n=splineIKCurve+"_rootCluster") cmds.container(moduleContainer, edit=True, addNode=clusterNodes, ihb=True, includeNetwork=True) rootClusterHandle = clusterNodes[1] cmds.select(splineIKCurve+".cv[2:3]", replace=True) clusterNodes = cmds.cluster(n=splineIKCurve+"_endCluster") cmds.container(moduleContainer, edit=True, addNode=clusterNodes, ihb=True, includeNetwork=True) endClusterHandle = clusterNodes[1] for handle in [rootClusterHandle, endClusterHandle]: cmds.setAttr(handle+".visibility", 0) cmds.parent(rootClusterHandle, rootScaler, absolute=True) cmds.parent(endClusterHandle, endScaler, absolute=True) containedNodes.append(cmds.parentConstraint(rootControlObject, rootJoint, maintainOffset=True)[0]) targetLocatorNodes = cmds.duplicate(endIK_rootLocator, name=endIK_rootLocator+"_duplicateTarget") targetLocator = targetLocatorNodes[0] cmds.delete(targetLocatorNodes[1]) cmds.parent(targetLocator, endScaler, absolute=True) splineScaleFactorAttr = self.createDistanceCalculations(rootIK_endLocator, targetLocator, containedNodes) # Use scaleFactor on each of the joints index = 0 for joint in stretchyIKJoints: if index > 2 and index < len(stretchyIKJoints)-1: multNode = cmds.shadingNode("multiplyDivide", asUtility=True, n=joint+"_jointScale") containedNodes.append(multNode) cmds.connectAttr(scaleFactorAttr, multNode+".input1X") cmds.setAttr(multNode+".input2X", cmds.getAttr(joint+".originalLength")) cmds.connectAttr(multNode+".outputX", joint+".translateX") index += 1 cmds.setAttr(splineIKhandle+".dTwistControlEnable", 1) cmds.setAttr(splineIKhandle + ".dWorldUpType", 4) cmds.setAttr(splineIKhandle + ".dWorldUpAxis", 5) cmds.setAttr(splineIKhandle + ".dWorldUpVector", 0.0, 0.0, 1.0, type="double3") cmds.setAttr(splineIKhandle + ".dWorldUpVectorEnd", 0.0, 0.0, 1.0, type="double3") if createRootControl: cmds.connectAttr(rootControlObject+".worldMatrix[0]", splineIKhandle+".dWorldUpMatrix") else: dummyNode = cmds.duplicate(rootJoint, parentOnly=True, n=rootJoint+"_dummyDuplicate")[0] containedNodes.append(dummyNode) cmds.parent(dummyNode, moduleGrp, absolute=True) cmds.connectAttr(dummyNode+".worldMatrix[0]", splineIKhandle+".dWorldUpMatrix") cmds.connectAttr(endControlObject+".worldMatrix[0]", splineIKhandle+".dWorldUpMatrixEnd") # Create 2 attributes for "offsetY and offsetZ". cmds.select(moduleGrp) cmds.addAttr(at="float", defaultValue=0.0, softMinValue=-10.0, softMaxValue=10.0, keyable=True, longName="offsetY") cmds.addAttr(at="float", defaultValue=0.0, softMinValue=-10.0, softMaxValue=10.0, keyable=True, longName="offsetZ") # Publish new attrs to container self.publishNameToModuleContainer(moduleGrp+".offsetY", "interpolator_offsetY", publishToOuterContainers=True) self.publishNameToModuleContainer(moduleGrp+".offsetZ", "interpolator_offsetZ", publishToOuterContainers=True) # Create a node to inverse offset inverseNode = cmds.shadingNode("multiplyDivide", asUtility=True, n=moduleGrp+"_offsetInverse") containedNodes.append(inverseNode) cmds.connectAttr(moduleGrp+".offsetY", inverseNode+".input1Y") cmds.connectAttr(moduleGrp+".offsetZ", inverseNode+".input1Z") cmds.setAttr(inverseNode+".input2Y", -1) cmds.setAttr(inverseNode+".input2Z", -1) # Setup interpolators numStretchyIKJoints = len(stretchyIKJoints)-1 interpolators_ikParents = [] aimChildren = [] for i in range(1, numStretchyIKJoints): if i > 1: # Create a group to follow each joint jointFollower = cmds.group(empty=True, n=stretchyIKJoints[i]+"_follower") containedNodes.append(jointFollower) # Parent the group to the joint we are following cmds.parent(jointFollower, moduleGrp, relative=True) containedNodes.append(cmds.parentConstraint(stretchyIKJoints[i], jointFollower, maintainOffset=False, n=jointFollower+"_parentConstraint")[0]) offset = cmds.group(empty=True, n=stretchyIKJoints[i]+"_interpolatorOffset") containedNodes.append(offset) # parent the offset group to the follower group cmds.parent(offset, jointFollower, relative=True) cmds.connectAttr(moduleGrp+".offsetY", offset+".translateY") cmds.connectAttr(moduleGrp+".offsetZ", offset+".translateZ") name = utils.stripAllNamespaces(joints[i])[1] + "_offsetControl" controlObjectInstance = controlObject.ControlObject() offsetControlObject = controlObjectInstance.create(name, "cubeLocator.ma", self, lod=2, translation=True, rotation=False, globalScale=False, spaceSwitching=False)[0] # parent control object under offset group cmds.parent(offsetControlObject, offset, relative=True) offsetCancelation = cmds.group(empty=True, n=stretchyIKJoints[i]+"interpolatorOffsetCancelation") containedNodes.append(offsetCancelation) cmds.parent(offsetCancelation, offsetControlObject, relative=True) cmds.connectAttr(inverseNode+".outputY", offsetCancelation+".translateY") cmds.connectAttr(inverseNode+".outputZ", offsetCancelation+".translateZ") interpolators_ikParents.append(offsetCancelation) aimChild = cmds.group(empty=True, n=stretchyIKJoints[i]+"_aimChild") containedNodes.append(aimChild) aimChildren.append(aimChild) if i > 1: cmds.parent(aimChild, offsetCancelation, relative=True) print "parent offset cancel" else: cmds.parent(aimChild, stretchyIKJoints[i], relative=True) cmds.setAttr(aimChild+".translateY", -1) # Make use of interpolation nodes for i in range(1, numStretchyIKJoints): ikNodes = utils.basic_stretchy_IK(joints[i], joints[i+1], container=moduleContainer, scaleCorrectionAttribute=self.blueprintNamespace+":module_grp.hierarchicalScale", lockMinimumLength=False, poleVectorObject=aimChildren[i-1]) ikHandle = ikNodes["ikHandle"] rootLocator = ikNodes["rootLocator"] endLocator = ikNodes["endLocator"] for loc in (ikHandle, rootLocator): cmds.parent(loc, moduleGrp, absolute=True) utils.matchTwistAngle(ikHandle+".twist", [joints[i],], [stretchyIKJoints[i],]) if i == 1: if createRootControl: containedNodes.append(cmds.pointConstraint(rootControlObject, joints[i], maintainOffset=False, n=joints[i]+"_pointConstraint")[0]) cmds.setAttr(endLocator+".translate", 0.0, 0.0, 0.0, type="double3") if i < numStretchyIKJoints-1: cmds.parent(endLocator, interpolators_ikParents[i-1], relative=True) else: cmds.parent(endLocator, endControlObject, relative=True) cmds.setAttr(moduleGrp+".lod", 2) utils.addNodeToContainer(moduleContainer, containedNodes, ihb=True) # Publish joints to module container. for joint in stretchyIKJoints: jointName = utils.stripAllNamespaces(joint)[1] self.publishNameToModuleContainer(joint+".rotate", jointName+"_R", publishToOuterContainers=False) self.publishNameToModuleContainer(joint+".translate", jointName+"_T", publishToOuterContainers=False)
def install_custom(self, joints, moduleGrp, moduleContainer): containedNodes = [] rootJoint = joints[1] endJoint = joints[len(joints)-1] ikNodes = utils.basic_stretchy_IK(rootJoint, endJoint, container=moduleContainer, scaleCorrectionAttribute=self.blueprintNamespace+":module_grp.hierarchicalScale") ikHandle = ikNodes["ikHandle"] rootLocator = ikNodes["rootLocator"] endLocator = ikNodes["endLocator"] poleVectorLocator = ikNodes["poleVectorObject"] stretchinessAttribute = ikNodes["stretchinessAttribute"] # Create controls and parent ikHandles for node in [rootLocator, ikHandle, poleVectorLocator]: cmds.parent(node, moduleGrp, absolute=True) name = "ikHandleControl" # controlObject class controlObjectInstance = controlObject.ControlObject() handleControlInfo = controlObjectInstance.create(name, "cubeLocator.ma", self, lod=1, translation=True, rotation=False, globalScale=False, spaceSwitching=True) handleControl = handleControlInfo[0] handleRootParent = handleControlInfo[1] cmds.parent(handleRootParent, moduleGrp, relative=True) cmds.xform(handleControl, worldSpace=True, absolute=True, translation=cmds.xform(endLocator, q=True, worldSpace=True, translation=True)) cmds.parent(endLocator, handleControl, absolute=True) # Create a pre-transform node that sits above the control object. handleControlParent = cmds.listRelatives(handleControl, parent=True)[0] preTransform = cmds.group(empty=True, n=handleControl+"_preTransform") containedNodes.append(preTransform) cmds.parent(preTransform, handleControl, relative=True) cmds.parent(preTransform, handleControlParent, absolute=True) cmds.parent(handleControl, preTransform, absolute=True) #Add attributes to control cmds.select(handleControl) cmds.addAttr(at="float", minValue=0.0, maxValue=1.0, defaultValue=1.0, keyable=True, longName="stretchiness") cmds.addAttr(at="float", softMinValue=-360.0, softMaxValue=360.0, defaultValue=0.0, keyable=True, longName="twist") #connect attrs cmds.connectAttr(handleControl+".twist", ikHandle+".twist") cmds.connectAttr(handleControl+".stretchiness", stretchinessAttribute) # Add attrs to container self.publishNameToModuleContainer(handleControl+".twist", "twist", publishToOuterContainers=True) self.publishNameToModuleContainer(handleControl+".stretchiness", "stretchiness", publishToOuterContainers=True) # 171 > jointName = utils.stripAllNamespaces(rootJoint)[1] ikJoints = utils.findJointChain(rootJoint) targetJoints = utils.findJointChain(self.blueprintNamespace+":creationPose_"+jointName) utils.matchTwistAngle(handleControl+".twist", ikJoints, targetJoints) offsetNode = cmds.shadingNode("plusMinusAverage", asUtility=True, n=handleControl+"_twistOffset") containedNodes.append(offsetNode) cmds.setAttr(offsetNode+".input1D[0]", cmds.getAttr(handleControl+".twist")) cmds.connectAttr(handleControl+".twist", offsetNode+".input1D[1]") cmds.connectAttr(offsetNode+".output1D", ikHandle+".twist", force=True) cmds.setAttr(handleControl+".twist", 0.0) # < 171 utils.addNodeToContainer(moduleContainer, containedNodes)