Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import maya.cmds as mc
- import maya.mel as mel
- def getHierarchy(nodeName='nodeName'):
- '''
- @summary:
- from a node name get all the child objects and childrens children of that node
- @arguments:
- @returns:
- a list of node name hierarchy
- '''
- # if you need a selection you can override with this
- #nodeName = mc.ls(selection=True, long=True)
- hierarchyCheckList = [nodeName]
- hierarchyMasterList = []
- # keep looping while there is something in the checklist
- while hierarchyCheckList:
- # set the node to the first entry of the checklist
- node = hierarchyCheckList[0]
- # add the current node to the master list
- hierarchyMasterList.append(node)
- # get any children from the current node
- newChildren = mc.listRelatives(node, children=True, fullPath=True, type='transform')
- # If there are children add them to the checklist
- if newChildren:
- for index, childnode in enumerate(newChildren):
- hierarchyCheckList.insert(index, childnode)
- # remove the node from the checklist end of loop
- hierarchyCheckList.remove(node)
- # print the hierarchy list
- # print 'hierarchyMasterList:', hierarchyMasterList
- return hierarchyMasterList
- def findForwardFace(edgeList):
- '''
- @summary:
- calculates the face connected to the edge in a polystrip.
- the first edge must only have one face attached to it
- @arguments:
- edge list
- @returns:
- face list
- '''
- # pop the first edge out of the list
- firstEdge = edgeList.pop(0)
- # calculate the first face connected to the edge, there should only be one
- firstFace = mc.polyListComponentConversion(firstEdge, fromEdge=True, toFace=True)
- # create a list of faces and add the first face to the list
- faceList = [firstFace[0]]
- # Debuggin
- #print 'SelectedEdges:', edgeList
- #print 'FaceList', faceList
- # for each edge in the list loop
- for index, edge in enumerate(edgeList):
- # get the faces connected to the edge, there should be two
- newFaces = mc.polyListComponentConversion(edge, fromEdge=True, toFace=True,)
- # flatten the list of faces
- flatNewFaces = mc.ls(newFaces, flatten=True)
- # Dbuggin
- #print 'NEW FACES: ', flatNewFaces
- # get the length of the list
- #listLength = len(faceList)
- # for each face in the new faces, compare the face
- for faceCompare in flatNewFaces:
- # create a variable to test
- deadFace = 0
- # for each face in the face list compare the face
- # if it is equal then do not add the face to the list
- # if it is not equal then add it
- # the purpose is to only add a face that is not already in the list
- for face in faceList:
- if faceCompare == face:
- deadFace = 1
- if deadFace == 0:
- faceList.append(faceCompare)
- #print 'FaceLIST: ', faceList
- return faceList
- def deletePolyFaces(faceList=['poly1.f[0]','poly1.f[5]','poly1.f[2]']):
- '''
- @summary:
- nodeList=['node1','node2'], faceNumList=['f.[0]','f.[5]','f.[2]']
- @arguments:
- @returns:
- '''
- # strip the name off of the face number and store in a list
- faceNumList = []
- for face in faceList:
- faceNum = face.split('.')[1]
- faceNumList.append(faceNum)
- print 'FaceNumList:', faceNumList
- # get the master node
- rootNode = faceList[0].split('.')[0]
- #print rootNode
- # store the master node in a list
- newNodeList = [rootNode]
- # duplicate the mesh for every face in the mesh
- for index in range(len(faceList) - 1):
- newCopy = mc.duplicate(rootNode, returnRootsOnly=True)[0]
- newNodeList.append(newCopy)
- print 'NewNodes:', newNodeList
- # group all the new nodes under a new group
- foldFacesGroup = mc.group(newNodeList, world=True, name='FoldFacesGroup')
- # get the new long name list hierarchy of the new duplicated nodes
- newNodeListGroup = getHierarchy(foldFacesGroup)
- print 'newNodeListGroup', newNodeListGroup
- # remove the group name node from the list
- newNodeListGroup.pop(0)
- #print 'NewNodeListGroup:', newNodeListGroup
- # delete the extra faces on each polyobject
- #deletePolyFaces(nodeList=newNodeListGroup, faceNumList=faceNumList)
- # delete all the faces save the face in the face list
- for index, node in enumerate(newNodeList):
- # get the number of faces in the mesh
- faceCount = mc.polyEvaluate(node, face=True)
- #print 'faceCount', faceCount
- # append the new node name to the face number
- saveFace = node + '.' + faceNumList[index]
- #print index
- #print 'saveFace:', saveFace
- # select all the faces in the mesh
- mc.select('{node}.f[0:{faceCount}]'.format(node=node, faceCount=faceCount))
- # deselect the face in the face list
- mc.select(saveFace, deselect=True)
- # delete the faces
- mel.eval('doDelete;')
- def splitMeshFaces():
- '''
- @summary:
- from an ordered edge selection split off the connecting faces in order
- will create new meshes and delete faces rather than use polychip off
- @arguments:
- select edges in order then run function
- @returns:
- '''
- # This code works to retain the selected orderd
- selectedEdgeList = mc.ls(orderedSelection=True, long=True)
- #print 'EDGELIST:', selectedEdgeList
- # Create a deep copy of the list, to preserve the original
- newEdgeList = selectedEdgeList[:]
- # get a list of faces that are adjacent to the selected edges
- faceList = findForwardFace(newEdgeList)
- #print 'FACELIST:', faceList
- deletePolyFaces(faceList=faceList)
- splitMeshFaces()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement