import pymel.core as pmimport maya.mel as mel
sel = pm.ls(sl=True)[0] # Get object selection
# Edges must be selected heremel.eval("polySelectBorderShell 1")uvs = pm.polyListComponentConversion(fe=True, tuv=True)uvList = pm.ls(uvs, flatten=True)uvDict = {}for i in uvList: print i uvNum = int(i.split('[')[-1].split(']')[0]) uvDict.update({uvNum:i})
vertBorders = {} # e.g. {'map1':[1, 2, 3, 5, 71]}uvSets = pm.polyUVSet(sel, query=True, allUVSets=True)for uvSet in uvSets: vertBorders.update({uvSet:[]}) uvs = pm.polyEvaluate(sel, uvs=uvSet, uv=True) for uvNum in range(uvs): if uvNum in uvDict: vert = pm.polyListComponentConversion(uvDict[uvNum], fuv=True, tv=True)[0] vertBorders[uvSet].append(vert)
count = 0multiList = vertBorders.values()result = set(multiList[0]).intersection(*multiList[:1])count += len(result)newMultiList = []for L in multiList: newList = [i for i in L if i not in result] count += len(newList)print count
def getVertFromId(dagPath, vertID):
vertIt = OM.MItMeshVertex(dagPath)
vtxIdUtil = OM.MScriptUtil()
vtxIdUtil.createFromInt(0)
vtxIdPtr = vtxIdUtil.asIntPtr()
vertIt.setIndex(vertID, vtxIdPtr)
return vertIt
def getFaceFromId(dagPath, faceId):
faceIt = OM.MItMeshPolygon(dagPath)
faceIdUtil = OM.MScriptUtil()
faceIdUtil.createFromInt(0)
faceIdPtr = faceIdUtil.asIntPtr()
faceIt.setIndex(faceId, faceIdPtr)
return faceIt
def getVertUVInfo(vertIn):
uArr = OM.MFloatArray()
vArr = OM.MFloatArray()
fIDs = OM.MIntArray()
uvIndices = OM.MIntArray()
uvSet = 'map1'
vertIn.getUVs(uArr, vArr, fIDs, uvSet)
vertIn.getUVIndices(uvIndices, uvSet)
print uArr, vArr, fIDs, uvIndices
return fIDs, uvIndices
def stripUnecessaryFaces(currentEdgeFaces, faceIDs1, faceIDs2):
fID1 = []
fID2 = []
for fID in faceIDs1:
if fID in currentEdgeFaces:
fID1.append(fID)
for fID in faceIDs2:
if fID in currentEdgeFaces:
fID2.append(fID)
return fID1, fID2
def main():
mSelList = OM.MSelectionList()
OM.MGlobal.getActiveSelectionList(mSelList)
sel = OM.MItSelectionList(mSelList)
dagPath = OM.MDagPath()
sel.getDagPath(dagPath)
dagPath.extendToShape()
connFaces = OM.MIntArray()
edgeIter = OM.MItMeshEdge(dagPath)
while not edgeIter.isDone():
f1 = None
f2 = None
edgeIter.getConnectedFaces(connFaces)
if len(connFaces) == 1:
# open edge
print 'Open edge'
f1 = connFaces[0] # face 1
try:
f2 = connFaces[1] # face 2
except:
pass
vert1Index = edgeIter.index(0)
vert2Index = edgeIter.index(1)
MfVert1 = getVertFromId(dagPath, vert1Index)
MfVert2 = getVertFromId(dagPath, vert2Index)
fIdsvert1, uvIndicesVert1 = getVertUVInfo(MfVert1)
fIdsvert2, uvIndicesVert2 = getVertUVInfo(MfVert2)
edgeIter.next()
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1b0555d7-7ffb-4df6-9c1d-5f9883cee64b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
polyVertices = fnMesh.getVertices()polyUVIDs = fnMesh.getAssignedUVs() # with optional UV set name
vertUVIDs = [set() for _ in range(fnMesh.numVertices)]
for vID, uvID in izip(polyVertices[1], polyUVIDs[1]):
vertUVIDs[vID].add(uvID)
totalVertCount = sum(len(s) for s in vertUVIDs)
--To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2d436e81-b03e-405e-b87b-63f49173a9e7%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/5rvHKbU9ipM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2d436e81-b03e-405e-b87b-63f49173a9e7%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/5rvHKbU9ipM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAA27_yJ3-FnWM_AwkjcNV37d2a524NbCnHQb3yxKq7D%2B4CpQwA%40mail.gmail.com.
import pymel.core as pmimport maya.OpenMaya as OMfrom itertools import izip
sel = pm.ls(sl=True)[0]selName = str(sel.nodeName())
mSelList = OM.MSelectionList()OM.MGlobal.getActiveSelectionList(mSelList)sel = OM.MItSelectionList(mSelList)
path = OM.MDagPath()sel.getDagPath(path)fnMesh = OM.MFnMesh(path)
vertCount = OM.MIntArray()vertList = OM.MIntArray()
uvCounts = OM.MIntArray()uvIDs = OM.MIntArray() #uvSet='map1'
set2 = 'uvSet'tempSets = ['map1', 'uvSet']
additional = 0
#for uvSet in tempSets:fnMesh.getVertices(vertCount, vertList)#fnMesh.getAssignedUVs(uvCounts, uvIDs, uvSet)fnMesh.getAssignedUVs(uvCounts, uvIDs, set2)
vertUVIDs = [set() for _ in range(fnMesh.numVertices())]
for vID, uvID in izip(vertList, uvIDs): vertUVIDs[vID].add(uvID)
totalVertCount = sum(len(s) for s in vertUVIDs if len(s)>1)additional += totalVertCountprint additional
totes = [i for i in vertUVIDs if len(i) > 1]for i in totes: for j in i: pm.select('{0}.map[{1}]'.format(selName, j), add=True)
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/5rvHKbU9ipM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5c8e3e30-ad49-4d04-ae11-2a446fdf81dc%40googlegroups.com.
import maya.api.OpenMaya as omfrom itertools import izip, izip_longest
# Get the currently selected mesh.mSelList = om.MGlobal.getActiveSelectionList()path = mSelList.getDagPath(0)fnMesh = om.MFnMesh(path)
# So the engine splits vertices if their UVs are different.# Another way of looking at it, is that the engine stores each vertex like this:# (position, uv0, uv1)# So that's what we're going to do. We'll collect the position and the uvs of each # corner of each face, then put each of those corners into a set to find out how many # unique corners there are. That should tell us exactly how many vertices the engine # will count.# Note that we are actually storing IDs rather than real values, just because it's # easier.allFacesVertCounts = []allFacesVertIDs = []counter = []
# The first "channel" of face-vertex properties we want is the regular vertex positions.polyVertices = fnMesh.getVertices()allFacesVertCounts.append(polyVertices[0])allFacesVertIDs.append(polyVertices[1])counter.append(0)
# The next 2 channels are the UVs. This collects the first 2 UV channels but you could # change that to whatever you want.
numUVChannelsUsed = 2uvSets = fnMesh.getUVSetNames()for uvSet in uvSets[:numUVChannelsUsed]: f, ids = fnMesh.getAssignedUVs(uvSet) allFacesVertCounts.append(f) allFacesVertIDs.append(ids) counter.append(0) # If you wanted to, you could also add normals, tangents, binormals and/or colors here.
numVertProperties = len(counter)print 'Counting {} properties for {} vertex-faces...'.format( numVertProperties, len(allFacesVertIDs[0])) uniqueVerts = set()assert [len(c) == len(allFacesVertCounts[0]) for c in allFacesVertCounts]for vertCounts in izip(*allFacesVertCounts): # Inside this loop, we're looking at one face at a time. # vertCounts contains the number of verts this face has in each channel. # vertCounts[0] will be the number of actual verts. # The other channels will either have the same number (if the face is mapped) # or 0 (if the face is not mapped in this channel). assert len(vertCounts) == numVertProperties, (len(vertCounts), numVertProperties) faceVertIds = [None] * numVertProperties for i in range(numVertProperties): # Some faces don't have UVs in some channels, so they will have 0 verts in # that channel. We need to count through the UV id lists by the correct # amount for each channel. assert isinstance(vertCounts[i], int), type(vertCounts[i]) assert (vertCounts[i] == 0 or vertCounts[i] == vertCounts[0]), (vertCounts[i], vertCounts[0]) faceVertIds[i] = allFacesVertIDs[i][counter[i]:counter[i]+vertCounts[i]] counter[i] += vertCounts[i] # izip_longest lets us fill any empty faces with a default value (None in this case) for vertParams in izip_longest(*faceVertIds, fillvalue=None): # vertParams is a list of ids for this corner of the face. # The first id is the vertex id. The second is the uv id in the first uv set. # We store all these ids because if any of them are different, the game engine # will create a new vert, so we want to count it as a new vert. uniqueVerts.add(vertParams)for i in range(numVertProperties): assert counter[i] == len(allFacesVertIDs[i]), (i, counter[i], len(allFacesVertIDs[i]))
print 'Done.'print 'Number of Maya verts:', fnMesh.numVerticesprint 'Number of face-verts:', len(allFacesVertIDs[0])print 'Number of engine verts:', len(uniqueVerts)
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5c8e3e30-ad49-4d04-ae11-2a446fdf81dc%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/5rvHKbU9ipM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/23ac14f9-6484-4bbf-8e86-e2003d9666e1%40googlegroups.com.