def isolateOnControl(worldTarget, localTarget, transform, control, attributeName, orientation=True, position=False, useLocators=False): if isinstance(worldTarget, basestring): worldTarget = pmc.PyNode(worldTarget) if isinstance(localTarget, basestring): localTarget = pmc.PyNode(localTarget) if isinstance(transform, basestring): transform = pmc.PyNode(transform) basename = transform.shortName() worldGrp = pmc.createNode('transform', name='tgt_{0}_to_world'.format(basename)) worldGrp.setRotation(transform.getRotation('world'), 'world') worldGrp.setTranslation(transform.getTranslation('world'), 'world') localGrp = pmc.createNode('transform', name='tgt_{0}_to_local'.format(basename)) localGrp.setRotation(transform.getRotation('world'), 'world') localGrp.setTranslation(transform.getTranslation('world'), 'world') pmc.parentConstraint(worldTarget, worldGrp, maintainOffset=True) pmc.parentConstraint(localTarget, localGrp, maintainOffset=True) constraints = list() if orientation: con = pmc.orientConstraint(worldGrp, localGrp, transform, maintainOffset=False) con.interpType.set(2) constraints.append(con) if position: con = pmc.pointConstraint(worldGrp, localGrp, transform, maintainOffset=False) constraints.append(con) isolateAttr = getAttribute(control, attributeName, min=0, max=1, keyable=True) rev = pmc.createNode('reverse', name='rev_{0}_to_local'.format(basename)) for con in constraints: weightAttrs = con.getWeightAliasList() isolateAttr.connect(weightAttrs[0]) isolateAttr.connect(rev.inputX) rev.outputX.connect(weightAttrs[1]) return [worldGrp, localGrp]
def _callback(self, closeGUI): joints = map(pmc.PyNode, self._jointTsc.getAllItems()) attribute = None rawControlText = self._attrField.getText() if rawControlText: control, attrname = rawControlText.partition('.')[::2] if not attrname: pmc.warning('IKFK :: can\'t read attribute specified in IKFK switch attribute. ' 'Make sure to specify using control.attr format!') return if not pmc.objExists(control): pmc.warning('IKFK :: Controller {0} not found in scene!'.format(control)) return attribute = getAttribute(control, attrname, min=0, max=1, defaultValue=0, keyable=True) else: choice = pmc.confirmDialog(title='IKFK - No Attribute Specified', message='I noticed you didn\'t specify a controller for connecting the IKFK ' 'switch.\nDo you want to go ahead and complete the IKFK setup and ' 'you can connect a controller later?', button=['Yes', 'No'], defaultButton='Yes', cancelButton='No', dismissString='No') if choice == 'No': return stretchy = self._stretchyCheck.getValue() jointPrefix = self._basePrefixField.getText() ikJointPrefix = self._ikPrefixField.getText() fkJointPrefix = self._fkPrefixField.getText() result = makeIkFkJoints(joints, attribute, stretchy, jointPrefix, ikJointPrefix, fkJointPrefix) if not rawControlText: pmc.select(result[-1]) pmc.confirmDialog(title='IKFK Setup Complete BUT...', message='IKFK creation successful. ' 'Take a note of the selected blendColors as ' 'they\'ll need to be connected to your IKFK' 'controller.\nEnjoy!') if closeGUI: pmc.deleteUI(self.mainWindow, window=True)
def makeMultiConstraint(targets, source, controller, attrName='currentSpace', enumNames=None, addLocatorSpace=True, translation=True, rotation=True, maintainOffset=False): """ creates a constraint between all to the targets to the passed in source. """ targets = map(pmc.PyNode, targets) source = pmc.PyNode(source) controller = pmc.PyNode(controller) loc = None if enumNames is None: enumNames = map(str, targets) if addLocatorSpace: loc = pmc.spaceLocator(n='loc_follow_' + source.shortName()) alignObjects(loc, source) targets.append(loc) enumNames.append('locator') skipTranslate = 'none' if not translation: skipTranslate = ['x', 'y', 'z'] skipRotate = 'none' if not rotation: skipRotate = ['x', 'y', 'z'] constraints = list() for tgt, spaceName in izip(targets, enumNames): enumAttr = getAttribute(controller, attrName, at='enum', enumName=spaceName, keyable=True, longName=attrName) spaceEnums = enumAttr.getEnums().keys() if spaceName not in spaceEnums: spaceEnums.append(spaceName) enumAttr.setEnums(spaceEnums) index = enumAttr.getEnums().value(spaceName) if tgt is loc: tgtTransform = loc else: tgtTransform = pmc.createNode('transform', n='tgt_{0}_to_{1}'.format( source.shortName(), tgt.shortName())) alignObjects(tgtTransform, source) pmc.parentConstraint(tgt, tgtTransform, maintainOffset=maintainOffset) orient = pmc.orientConstraint(tgtTransform, source, skip=skipRotate, maintainOffset=maintainOffset) orient.interpType.set(2) constraints.append(orient) point = pmc.pointConstraint(tgtTransform, source, skip=skipTranslate, maintainOffset=maintainOffset) constraints.append(point) orientWeightList = orient.getWeightAliasList() orientWeightAttr = orientWeightList[-1] pointWeightList = point.getWeightAliasList() pointWeightAttr = pointWeightList[-1] nodeName = 'con_{0}_to_{1}_weight_{2:d}'.format( source.shortName(), tgt.shortName(), index) weightConditionNode = pmc.createNode('condition', n=nodeName) enumAttr.connect(weightConditionNode.firstTerm) weightConditionNode.secondTerm.set(index) weightConditionNode.colorIfTrueR.set(1) weightConditionNode.colorIfFalseR.set(0) weightConditionNode.outColorR.connect(pointWeightAttr) weightConditionNode.outColorR.connect(orientWeightAttr) return loc
def makeMultiConstraint(targets, source, controller, attrName='currentSpace', enumNames=None, addLocatorSpace=True, translation=True, rotation=True, maintainOffset=False): """ creates a constraint between all to the targets to the passed in source. """ targets = map(pmc.PyNode, targets) source = pmc.PyNode(source) controller = pmc.PyNode(controller) loc = None if enumNames is None: enumNames = map(str, targets) if addLocatorSpace: loc = pmc.spaceLocator(n='loc_follow_' + source.shortName()) alignObjects(loc, source) targets.append(loc) enumNames.append('locator') skipTranslate = 'none' if not translation: skipTranslate = ['x', 'y', 'z'] skipRotate = 'none' if not rotation: skipRotate = ['x', 'y', 'z'] constraints = list() for tgt, spaceName in izip(targets, enumNames): enumAttr = getAttribute(controller, attrName, at='enum', enumName=spaceName, keyable=True, longName=attrName) spaceEnums = enumAttr.getEnums().keys() if spaceName not in spaceEnums: spaceEnums.append(spaceName) enumAttr.setEnums(spaceEnums) index = enumAttr.getEnums().value(spaceName) if tgt is loc: tgtTransform = loc else: tgtTransform = pmc.createNode('transform', n='tgt_{0}_to_{1}'.format(source.shortName(), tgt.shortName())) alignObjects(tgtTransform, source) pmc.parentConstraint(tgt, tgtTransform, maintainOffset=maintainOffset) orient = pmc.orientConstraint(tgtTransform, source, skip=skipRotate, maintainOffset=maintainOffset) orient.interpType.set(2) constraints.append(orient) point = pmc.pointConstraint(tgtTransform, source, skip=skipTranslate, maintainOffset=maintainOffset) constraints.append(point) orientWeightList = orient.getWeightAliasList() orientWeightAttr = orientWeightList[-1] pointWeightList = point.getWeightAliasList() pointWeightAttr = pointWeightList[-1] nodeName = 'con_{0}_to_{1}_weight_{2:d}'.format(source.shortName(), tgt.shortName(), index) weightConditionNode = pmc.createNode('condition', n=nodeName) enumAttr.connect(weightConditionNode.firstTerm) weightConditionNode.secondTerm.set(index) weightConditionNode.colorIfTrueR.set(1) weightConditionNode.colorIfFalseR.set(0) weightConditionNode.outColorR.connect(pointWeightAttr) weightConditionNode.outColorR.connect(orientWeightAttr) return loc