def parseSelectionList(self,selectionList): ''' calculates compacted internal selection list from the MSelectionList ''' selection = [] if selectionList is None or selectionList.isEmpty(): return selection #compact selection list first mergedList = om.MSelectionList() mergedList.merge(selectionList,om.MSelectionList.kMergeNormal) for i in Utils.mIter(om.MItSelectionList(mergedList)): # read selection item path = om.MDagPath() compSelection = om.MObject() i.getDagPath(path,compSelection) if not i.hasComponents() or not compSelection.hasFn(self.componentType): continue # create selection entry and fill it with components selEntry = MeshSelectEntry(path) for c in Utils.mIter(om.MItMeshVertex(path,compSelection)): selEntry.components.append(c.index()) selection.append(selEntry) return selection
def getSelectionDagPaths(hilite): ''' similar functionality to cmds.ls, but returns transform nodes where shapes might be selected, and does not return components. ''' from maya import OpenMaya as om selection = om.MSelectionList() if hilite: om.MGlobal.getHiliteList(selection) else: om.MGlobal.getActiveSelectionList(selection) result = [] for i in Utils.mIter(om.MItSelectionList(selection)): path = om.MDagPath() i.getDagPath(path) selectionPath = path.fullPathName() # if it's a shape node, extend upwards if path.node().hasFn(om.MFn.kShape): parentPath = om.MDagPath() om.MFnDagNode( om.MFnDagNode(path).parent(0)).getPath(parentPath) selectionPath = parentPath.fullPathName() if not selectionPath in result: result.append(selectionPath) return result
def getSelectionDagPaths(hilite): """ similar functionality to cmds.ls, but returns transform nodes where shapes might be selected, and does not return components. """ from maya import OpenMaya as om selection = om.MSelectionList() if hilite: om.MGlobal.getHiliteList(selection) else: om.MGlobal.getActiveSelectionList(selection) result = [] for i in Utils.mIter(om.MItSelectionList(selection)): path = om.MDagPath() i.getDagPath(path) selectionPath = path.fullPathName() # if it's a shape node, extend upwards if path.node().hasFn(om.MFn.kShape): parentPath = om.MDagPath() om.MFnDagNode(om.MFnDagNode(path).parent(0)).getPath(parentPath) selectionPath = parentPath.fullPathName() if not selectionPath in result: result.append(selectionPath) return result
def export(self): ''' returns mesh triangles: first vertex list, then vertex ID list for each triangle; meshTransform (supplied as transform node name) is required to transform each vertex to world-space ''' # get triangles for the mesh fnMesh = om.MFnMesh(self.meshMObject) counts = om.MIntArray() vertices = om.MIntArray() fnMesh.getTriangles(counts,vertices) idList = [i for i in Utils.mIter(vertices)] # get point values points = om.MPointArray() fnMesh.getPoints(points) pointList = [] for p in Utils.mIter(points): p = p*self.transformMatrix pointList.extend((p.x,p.y,p.z)) # return point values, id values return pointList,idList
def export(self): ''' returns mesh triangles: first vertex list, then vertex ID list for each triangle; meshTransform (supplied as transform node name) is required to transform each vertex to world-space ''' # get triangles for the mesh fnMesh = om.MFnMesh(self.meshMObject) counts = om.MIntArray() vertices = om.MIntArray() fnMesh.getTriangles(counts, vertices) idList = [i for i in Utils.mIter(vertices)] # get point values points = om.MPointArray() fnMesh.getPoints(points) pointList = [] for p in Utils.mIter(points): p = p * self.transformMatrix pointList.extend((p.x, p.y, p.z)) # return point values, id values return pointList, idList