def importJointInfo(xmlFileName):
    import xml.dom.minidom
    import xml.dom

    cmds.select(clear=True)
    listJoints = []
    # open the xml file for reading
    fileObject = file(xmlFileName, 'r')
    # parse the xml file to get all of it's elements
    xmlDoc = xml.dom.minidom.parse(fileObject)
    # Get the joint elements into a list
    joints = xmlDoc.getElementsByTagName('joint')
    # iterate through all of the joint elements
    #Loads joint positions
    for joint in joints:
        # get the child elements of the joint in order to get the translation values
        children = joint.childNodes
        # loop through the child elements
        for child in children:
            # make sure the the current node type is not a text node
            if child.nodeType != child.TEXT_NODE:
                # get the name of the joint from the name attribute attached to the joint element.
                jointName = joint.getAttribute("name")
                listJoints.append(jointName)
                # create a joint named the joint name
                if not cmds.objExists(jointName):
                    cmds.joint(n=jointName)
                    cmds.select(clear=True)
    # close the file
    fileObject.close()
    return listJoints
Esempio n. 2
0
def importJointInfo(xmlFileName):
    import xml.dom.minidom
    import xml.dom
    
    cmds.select( clear=True )
    listJoints=[]
    # open the xml file for reading 
    fileObject = file(xmlFileName, 'r')
    # parse the xml file to get all of it's elements
    xmlDoc = xml.dom.minidom.parse(fileObject)
    # Get the joint elements into a list
    joints = xmlDoc.getElementsByTagName('joint')
    # iterate through all of the joint elements
    #Loads joint positions
    for joint in joints:
        # get the child elements of the joint in order to get the translation values
        children = joint.childNodes            
        # loop through the child elements
        for child in children:
            # make sure the the current node type is not a text node
            if child.nodeType != child.TEXT_NODE:
                # get the name of the joint from the name attribute attached to the joint element.
                jointName = joint.getAttribute("name")                                    
                listJoints.append(jointName)
                # create a joint named the joint name 
                if not cmds.objExists(jointName):                        
                    cmds.joint( n = jointName )                     
                    cmds.select( clear=True) 
    # close the file
    fileObject.close()
    return listJoints
def parentToBlueprint(xmlFileName, characterNameString):
    import xml.dom.minidom
    import xml.dom

    cmds.select(clear=True)

    listJoints = []
    gameParentConstraints = []
    gameScaleConstraints = []

    # open the xml file for reading
    fileObject = file(xmlFileName, 'r')
    # parse the xml file to get all of it's elements
    xmlDoc = xml.dom.minidom.parse(fileObject)
    # Get the joint elements into a list
    joints = xmlDoc.getElementsByTagName('joint')
    # iterate through all of the joint elements

    for joint in joints:
        children = joint.childNodes
        # loop through the child elements
        for child in children:
            if child.nodeType != child.TEXT_NODE:
                jointName = joint.getAttribute("name")
                listJoints.append(jointName)

                # Parent to blueprint joints. #########################################################
                if child.tagName == "bpJoint":
                    # if the node is the parentJoint node get it's children
                    # to get the parent value
                    parentAxis = child.childNodes
                    for axis in parentAxis:
                        if axis.nodeType != axis.TEXT_NODE:
                            parentValue = axis.getAttribute("value")
                            parentValue = (characterNameString + parentValue)
                            if parentValue == "World":
                                gameScaleCon = cmds.scaleConstraint(
                                    parentValue, jointName, sk=None)
                                gameScaleConstraints.append(gameScaleCon)
                            else:
                                gameParentCon = cmds.parentConstraint(
                                    parentValue, jointName, mo=True)
                                gameParentConstraints.append(gameParentCon)
                                gameScaleCon = cmds.scaleConstraint(
                                    parentValue, jointName, sk="none")
                                gameScaleConstraints.append(gameScaleCon)

    return (gameParentConstraints, gameScaleConstraints)
Esempio n. 4
0
def parentToBlueprint(xmlFileName, characterNameString):
    import xml.dom.minidom
    import xml.dom
    
    cmds.select( clear=True )
    
    listJoints=[]
    gameParentConstraints=[]
    gameScaleConstraints=[]
    
    # open the xml file for reading 
    fileObject = file(xmlFileName, 'r')
    # parse the xml file to get all of it's elements
    xmlDoc = xml.dom.minidom.parse(fileObject)
    # Get the joint elements into a list
    joints = xmlDoc.getElementsByTagName('joint')
    # iterate through all of the joint elements
    
    for joint in joints:
        children = joint.childNodes            
        # loop through the child elements
        for child in children:
            if child.nodeType != child.TEXT_NODE:
                jointName = joint.getAttribute("name")                                    
                listJoints.append(jointName) 
                            
                # Parent to blueprint joints. #########################################################
                if child.tagName == "bpJoint":
                    # if the node is the parentJoint node get it's children
                    # to get the parent value
                    parentAxis = child.childNodes
                    for axis in parentAxis:
                        if axis.nodeType != axis.TEXT_NODE:
                            parentValue = axis.getAttribute("value")
                            parentValue = (characterNameString + parentValue)
                            if parentValue == "World":
                                gameScaleCon = cmds.scaleConstraint(parentValue, jointName, sk=None) 
                                gameScaleConstraints.append(gameScaleCon)
                            else:
                                gameParentCon = cmds.parentConstraint(parentValue, jointName, mo=True )
                                gameParentConstraints.append(gameParentCon) 
                                gameScaleCon = cmds.scaleConstraint(parentValue, jointName, sk="none")
                                gameScaleConstraints.append(gameScaleCon)
                         
    return (gameParentConstraints, gameScaleConstraints) 
def setJointAttrs(xmlFileName):
    import xml.dom.minidom
    import xml.dom

    cmds.select(clear=True)
    listJoints = []
    # open the xml file for reading
    fileObject = file(xmlFileName, 'r')
    # parse the xml file to get all of it's elements
    xmlDoc = xml.dom.minidom.parse(fileObject)
    # Get the joint elements into a list
    joints = xmlDoc.getElementsByTagName('joint')
    # iterate through all of the joint elements
    #Loads joint positions
    for joint in joints:
        # get the child elements of the joint in order to get the translation values
        children = joint.childNodes
        # loop through the child elements
        for child in children:
            # make sure the the current node type is not a text node
            if child.nodeType != child.TEXT_NODE:
                # get the name of the joint from the name attribute attached to the joint element.
                jointName = joint.getAttribute("name")
                listJoints.append(jointName)

                # Deal with joint positioning. #########################################################
                # look to see if the tag name of the current child element is
                # named translation
                if child.tagName == "translation":
                    # if the node is the translation node get it's children
                    # to get the x,y,z value
                    translationAxis = child.childNodes
                    # loop through each of the axis
                    for axis in translationAxis:
                        # once again make sure that we do not have a text node element
                        if axis.nodeType != axis.TEXT_NODE:

                            # get the axis attribute value
                            axisValue = axis.getAttribute("value")
                            #print "%s:%s" % (axis.tagName, axisValue)

                            # set the attribute name by combining the joint name and the
                            # axis name
                            attribute = "%s.translate%s" % (
                                jointName, axis.tagName.upper())

                            # convert the string to a float value
                            intValue = float(axisValue)

                            # set the attribute value
                            cmds.setAttr(attribute, intValue)
                            cmds.select(clear=True)

    for joint in joints:
        children = joint.childNodes
        # loop through the child elements
        for child in children:
            if child.nodeType != child.TEXT_NODE:
                jointName = joint.getAttribute("name")
                listJoints.append(jointName)

                # Deal with rotate order. #########################################################
                if child.tagName == "rotOrder":
                    # if the node is the parentJoint node get it's children
                    # to get the parent value
                    rotAxis = child.childNodes
                    # loop through each of the axis
                    for axis in rotAxis:
                        # once again make sure that we do not have a text node element
                        if axis.nodeType != axis.TEXT_NODE:
                            # get the axis attribute value
                            axisValue = axis.getAttribute("value")
                            # set the attribute name by combining the joint name and the
                            # axis name
                            attribute = jointName + ".rotateOrder"
                            # convert the string to a float value
                            intValue = float(axisValue)
                            # set the attribute value
                            cmds.setAttr(attribute, intValue)
                            cmds.select(clear=True)

                # Deal with orientation. #########################################################
                if child.tagName == "orientation":
                    # if the node is the translation node get it's children
                    # to get the x,y,z value
                    orientAxis = child.childNodes
                    # loop through each of the axis
                    for axis in orientAxis:
                        # once again make sure that we do not have a text node element
                        if axis.nodeType != axis.TEXT_NODE:

                            # get the axis attribute value
                            axisValue = axis.getAttribute("value")

                            # set the attribute name by combining the joint name and the
                            # axis name
                            attribute = "%s.jointOrient%s" % (
                                jointName, axis.tagName.upper())

                            # convert the string to a float value
                            intValue = float(axisValue)

                            # set the attribute value
                            cmds.setAttr(attribute, intValue)
                            cmds.select(clear=True)

    for joint in joints:
        children = joint.childNodes
        # loop through the child elements
        for child in children:
            if child.nodeType != child.TEXT_NODE:
                jointName = joint.getAttribute("name")
                listJoints.append(jointName)

                # Deal with joint parent. #########################################################
                if child.tagName == "parentJoint":
                    # if the node is the parentJoint node get it's children
                    # to get the parent value
                    parentAxis = child.childNodes
                    for axis in parentAxis:
                        if axis.nodeType != axis.TEXT_NODE:
                            parentValue = axis.getAttribute("value")
                            if parentValue == "World":
                                pass
                            else:
                                try:
                                    cmds.parent(jointName, parentValue, a=True)
                                except:
                                    pass
def loadHoldLocs():
    import xml.dom.minidom
    import xml.dom
    import tsapi.core.maya.joint as joint
    reload(joint)

    # The name of the holding location
    allLocs = []

    # Use the joint class to identify the joints in the scene
    joint = joint.joint()
    bindJoints = joint.GetGameJointInfo()[0]

    if bindJoints == None:
        cmds.headsUpMessage(
            'No game joints exist in this scene.  Holding locations will not be added.'
        )
        return
    else:
        # We should create a holding loc for each game joint.
        cmds.select(clear=True)
        #listJoints=[]
        # open the xml file for reading
        fileObject = file("Z://geppetto/holdLocList.xml", 'r')
        # parse the xml file to get all of it's elements
        xmlDoc = xml.dom.minidom.parse(fileObject)
        # Get the joint elements into a list
        joints = xmlDoc.getElementsByTagName('joint')
        # iterate through all of the joint elements
        #Loads joint positions
        for joint in joints:
            # get the child elements of the joint in order to get the loc name
            children = joint.childNodes
            # loop through the child elements
            for child in children:
                # make sure the the current node type is not a text node
                if child.nodeType != child.TEXT_NODE:

                    # Deal with holding loc name. #########################################################
                    if child.tagName == "locName":
                        # if the node is locName node get it's children
                        # to get the locName
                        locAxis = child.childNodes
                        for axis in locAxis:
                            if axis.nodeType != axis.TEXT_NODE:
                                locValue = axis.getAttribute("value")

            # get the name of the joint from the name attribute attached to the joint element.
            jointName = joint.getAttribute("name")

            if cmds.objExists(jointName):
                jointPos = cmds.xform(jointName, q=True, ws=True, t=True)
                # Final name for the holding location

                locName = ("HoldingLocation_" + jointName + "_" + locValue)

                allLocs.append(locName)

                locGrp = pm.group(em=True, w=True, n=locName)
                """ Once the group is created, I get a |  at the begining of the name. WTF??? """
                locGrp = cmds.ls(sl=True)
                locGrp = (locGrp)[0]

                # Move locGrp to joints position
                cmds.xform(locGrp, t=jointPos)
                # Add an "LocationType" attr to the holding loc
                cmds.addAttr(ln="LocationType", dt="string", k=False)
                cmds.setAttr(locGrp + ".LocationType", locValue, type="string")
                # parent the holdLoc to the joint
                cmds.parent(locGrp, jointName)

        # close the file
        fileObject.close()

        return allLocs
Esempio n. 7
0
def loadHoldLocs():
    import xml.dom.minidom
    import xml.dom
    import tsapi.core.maya.joint as joint
    reload (joint)
    
    characterName = ""
    xmlDir = setupDirs(characterName, create=False)[2]
    # The name of the holding location
    allLocs=[]
    allJoints=[]
    
    # Use the joint class to identify the joints in the scene
    joint = joint.joint()
    bindJoints = joint.GetGameJointInfo()[0]
    
    if bindJoints == None:
        cmds.headsUpMessage( 'No game joints exist in this scene.  Holding locations will not be added.')
        return
    else:
        # We should create a holding loc for each game joint.    
        cmds.select( clear=True )

        # open the xml file for reading 
        holdLocFile = (xmlDir + "/holdLocList.xml")

        fileObject = file(holdLocFile, 'r')
       
        # parse the xml file to get all of it's elements
        xmlDoc = xml.dom.minidom.parse(fileObject)
        # Get the joint elements into a list
        joints = xmlDoc.getElementsByTagName('joint')
        # iterate through all of the joint elements
        #Loads joint positions
        for joint in joints:
            # get the child elements of the joint in order to get the loc name
            children = joint.childNodes            
            # loop through the child elements
            for child in children:
                # make sure the the current node type is not a text node
                if child.nodeType != child.TEXT_NODE:
                
                # Deal with holding loc name. #########################################################
                    if child.tagName == "locName":
                        # if the node is locName node get it's children
                        # to get the locName
                        locAxis = child.childNodes
                        for axis in locAxis:
                            if axis.nodeType != axis.TEXT_NODE:
                                locValue = axis.getAttribute("value")

                                
            # get the name of the joint from the name attribute attached to the joint element.
            jointName = joint.getAttribute("name")                                 

            if cmds.objExists(jointName):     
                allJoints.append(jointName)
                jointPos = cmds.xform(jointName, q=True, ws=True, t=True)
                # Final name for the holding location 
                                                        
                locName = ("HoldingLocation_" + jointName + "_" + locValue)
        
                allLocs.append(locName)

                locGrp = pm.group(em=True, w=True, n=locName)

                """ Once the group is created, I get a |  at the begining of the name. WTF??? """
                locGrp = cmds.ls(sl=True)
                locGrp = (locGrp)[0]

                # Move locGrp to joints position
                cmds.xform(locGrp, t=jointPos)
                # Add an "LocationType" attr to the holding loc
                cmds.addAttr(ln="LocationType", dt="string", k=False)
                cmds.setAttr(locGrp+".LocationType", locValue, type="string")
                # parent the holdLoc to the joint
                cmds.parent(locGrp, jointName)
              
        # close the file
        fileObject.close()
        
    # Return some info to let the user know if the holding locs were created.
    jntLen = len(allJoints)
    locLen = len(allLocs)

    return allLocs
Esempio n. 8
0
def setJointAttrs(xmlFileName):
    import xml.dom.minidom
    import xml.dom
    
    cmds.select( clear=True )
    listJoints=[]
    # open the xml file for reading 
    fileObject = file(xmlFileName, 'r')
    # parse the xml file to get all of it's elements
    xmlDoc = xml.dom.minidom.parse(fileObject)
    # Get the joint elements into a list
    joints = xmlDoc.getElementsByTagName('joint')
    # iterate through all of the joint elements
    #Loads joint positions
    for joint in joints:
        # get the child elements of the joint in order to get the translation values
        children = joint.childNodes            
        # loop through the child elements
        for child in children:
            # make sure the the current node type is not a text node
            if child.nodeType != child.TEXT_NODE:
                # get the name of the joint from the name attribute attached to the joint element.
                jointName = joint.getAttribute("name")                                    
                listJoints.append(jointName)
                
                # Deal with joint positioning. #########################################################
                # look to see if the tag name of the current child element is
                # named translation
                if child.tagName == "translation":
                    # if the node is the translation node get it's children
                    # to get the x,y,z value
                    translationAxis = child.childNodes
                    # loop through each of the axis
                    for axis in translationAxis:
                          # once again make sure that we do not have a text node element
                            if axis.nodeType != axis.TEXT_NODE:
            
                                # get the axis attribute value
                                axisValue = axis.getAttribute("value")
                                #print "%s:%s" % (axis.tagName, axisValue)
            
                                # set the attribute name by combining the joint name and the
                                # axis name
                                attribute = "%s.translate%s" % (jointName, axis.tagName.upper())
            
                                # convert the string to a float value
                                intValue = float(axisValue)
        
                                # set the attribute value
                                cmds.setAttr(attribute, intValue)
                                cmds.select( clear=True )    
                                
    

    for joint in joints:
        children = joint.childNodes            
        # loop through the child elements
        for child in children:
            if child.nodeType != child.TEXT_NODE:
                jointName = joint.getAttribute("name")                                    
                listJoints.append(jointName)
                                
                # Deal with rotate order. #########################################################  
                if child.tagName == "rotOrder":
                    # if the node is the parentJoint node get it's children
                    # to get the parent value
                    rotAxis = child.childNodes
                    # loop through each of the axis
                    for axis in rotAxis:
                        # once again make sure that we do not have a text node element
                        if axis.nodeType != axis.TEXT_NODE:
                            # get the axis attribute value
                            axisValue = axis.getAttribute("value")
                            # set the attribute name by combining the joint name and the
                            # axis name
                            attribute = jointName + ".rotateOrder"
                            # convert the string to a float value
                            intValue = float(axisValue)
                            # set the attribute value
                            cmds.setAttr(attribute, intValue)
                            cmds.select( clear=True )
                            
                # Deal with orientation. #########################################################  
                if child.tagName == "orientation":
                    # if the node is the translation node get it's children
                    # to get the x,y,z value
                    orientAxis = child.childNodes
                    # loop through each of the axis
                    for axis in orientAxis:
                          # once again make sure that we do not have a text node element
                            if axis.nodeType != axis.TEXT_NODE:
            
                                # get the axis attribute value
                                axisValue = axis.getAttribute("value")
            
                                # set the attribute name by combining the joint name and the
                                # axis name
                                attribute = "%s.jointOrient%s" % (jointName, axis.tagName.upper())
            
                                # convert the string to a float value
                                intValue = float(axisValue)
        
                                # set the attribute value
                                cmds.setAttr(attribute, intValue)
                                cmds.select( clear=True )
                                
    for joint in joints:
        children = joint.childNodes            
        # loop through the child elements
        for child in children:
            if child.nodeType != child.TEXT_NODE:
                jointName = joint.getAttribute("name")                                    
                listJoints.append(jointName) 
                            
                # Deal with joint parent. #########################################################
                if child.tagName == "parentJoint":
                    # if the node is the parentJoint node get it's children
                    # to get the parent value
                    parentAxis = child.childNodes
                    for axis in parentAxis:
                        if axis.nodeType != axis.TEXT_NODE:
                            parentValue = axis.getAttribute("value")
                            if parentValue == "World":
                                pass
                            else:
                                try:
                                    cmds.parent(jointName, parentValue, a=True )
                                except: pass