def getComponents( inObj ): ''' Creates the components GUI. ''' if inObj is not None: components_list = NodeUtility.getFrameBitSettings( inObj ) else: components_list = None # If the newly selected bit has components then update the UI to show them. # Check to see if any of the components are connected to a meta node. # We do this check so that we don't create a bunch of UI elements # unnecessarily. if components_list is not None and metaNodeCheck( inObj, components_list ): # Loop through each component on the bit. components_class_list = {} for node_name in components_list: # Check to see if the component is connected to a meta node. metaNode = NodeUtility.getNodeAttrDestination( inObj, node_name ) if metaNode: # It has a meta node. # Get the meta node properties. This returns a dict. meta_properties = NodeUtility.getFrameBitSettings( metaNode[0] ) component_class = meta_properties[ 'classType' ] # test hack!!! components_class_list[ node_name ] = component_class return components_class_list else: return None
def createSpacer(inBitName, inGroupName="newGroup", inTargetObject=None, inDoParent=False, inPrefix=None): """ Creates an empty group. Optionally, the group's transforms can be matched to another object. @param inGroupName: String. Name to give the new group. @param inTargetObject: String. Name of object to match the group's transforms to. @return: The newly created group. """ # Create empty group. if inPrefix is not None: groupName = inPrefix + "_" + inGroupName else: groupName = inGroupName newGroup = cmds.group(em=True, name=groupName) # Set its transforms. if inTargetObject is not None: # Get target objects matrix. targetMatrix = TransformUtility.getMatrix(inTargetObject, "worldMatrix") # Get groups transform. MFnTrans = OpenMaya.MFnTransform() groupDagPath = NodeUtility.getDagPath(newGroup) MFnTrans.setObject(groupDagPath) # Apply the targets translation to the group. targetTranslation = TransformUtility.getMatrixTranslation(targetMatrix, OpenMaya.MSpace.kWorld) MFnTrans.setTranslation(targetTranslation, OpenMaya.MSpace.kWorld) # Apply the targets rotation to the group. targetRotation = TransformUtility.getMatrixRotation(targetMatrix, "quat") MFnTrans.setRotation(targetRotation, OpenMaya.MSpace.kWorld) # Parent the spacer. if inDoParent: parent = cmds.listRelatives(inBitName, parent=True) if NodeUtility.attributeCheck(parent[0], "controlName"): parentControl = NodeUtility.getFrameBitSettings(parent[0])["controlName"] cmds.parent(newGroup, parentControl, absolute=True) return newGroup
def buildModule(): ''' Build function for all the rigging associated with this module. ''' # Get the frame module meta nodes in the scene. modules = NodeUtility.getMetaNodesInScene( 'frameModule' ) # Read the meta node. nodeData = NodeUtility.getFrameBitSettings( modules[0] ) prefix = nodeData['prefix'] # Get the frame module bits. frameRoot = NodeUtility.getNodeAttrSource( modules[0], 'rootBit' )[0] shoulderBit = NodeUtility.getNodeAttrSource( modules[0], 'jShoulder' )[0] elbowBit = NodeUtility.getNodeAttrSource( modules[0], 'jElbow' )[0] wristBit = NodeUtility.getNodeAttrSource( modules[0], 'jWrist' )[0] ikRootBit = NodeUtility.getNodeAttrSource( modules[0], 'ikRoot' )[0] ikEndBit = NodeUtility.getNodeAttrSource( modules[0], 'ikEnd' )[0] ikUpVecBit = NodeUtility.getNodeAttrSource( modules[0], 'ikUpVecControl' )[0] # Build shadow skeleton. jointShoulder = marigoldJoints.createJoint( nodeData['jShoulder'], shoulderBit, inPrefix=prefix ) jointElbow = marigoldJoints.createJoint( nodeData['jElbow'], elbowBit, jointShoulder, inPrefix=prefix ) jointWrist = marigoldJoints.createJoint( nodeData['jWrist'], wristBit, jointElbow, inPrefix=prefix ) # Make the FK rigging. fkControls = [ [nodeData['fkShoulderControl'], nodeData['fkShoulderControlName'], nodeData['jShoulder'], shoulderBit], [nodeData['fkElbowControl'], nodeData['fkElbowControlName'], nodeData['jElbow'],elbowBit] ] for i in fkControls: # Create the spacer. spacerName = 'j_{0}_{1}'.format( prefix, i[2] ) newSpacer = marigoldControls.makeControl().createSpacer( i[3], i[1], spacerName, True ) # Create the controller. controlSplit = i[0].split( '.' ) marigoldControls.makeControl().createController( controlSplit[0], controlSplit[1], i[1], newSpacer ) # Make the IK rigging. effSplit = nodeData['ikEffControl'].split('.') effSpacer = marigoldControls.makeControl().createSpacer( ikEndBit, nodeData['ikEffControlName'], 'j_'+prefix+'_'+nodeData['jWrist'], inDoParent=False, inPrefix=prefix ) marigoldControls.makeControl().createController( effSplit[0], effSplit[1], nodeData['ikEffControlName'], effSpacer, inPrefix=prefix ) upVecSplit = nodeData['ikUpVecControl'].split('.') upVecSpacer = marigoldControls.makeControl().createSpacer( ikUpVecBit, nodeData['ikUpVecControlName'], ikUpVecBit, inDoParent=False, inPrefix=prefix ) marigoldControls.makeControl().createController( upVecSplit[0], upVecSplit[1], nodeData['ikUpVecControlName'], upVecSpacer, inPrefix=prefix ) jointFn = OpenMayaAnim.MFnIkJoint() # IK root joint. jointShoulder = 'j_{0}_{1}'.format( prefix, nodeData['jShoulder'] ) rootJointDagPath = NodeUtility.getDagPath( jointShoulder ) # IK eff joint. jointWrist = 'j_{0}_{1}'.format( prefix, nodeData['jWrist'] ) effJointDagPath = NodeUtility.getDagPath( jointWrist ) # Do up the solver. ikHandleName = '{0}_{1}_arm'.format( nodeData['ikEffControlName'], prefix ) cmds.ikHandle( name=ikHandleName, startJoint=rootJointDagPath.fullPathName(), endEffector=effJointDagPath.fullPathName(), solver='ikRPsolver' ) effControlName = 'ct_{0}_{1}'.format( prefix, nodeData['ikEffControlName'] ) cmds.parent( ikHandleName, effControlName, absolute=True ) upVecControlName = 'ct_{0}_{1}'.format( prefix, nodeData['ikUpVecControlName'] ) cmds.poleVectorConstraint( upVecControlName, ikHandleName )