Benjam901
2017-11-09 16:03:12 UTC
Hello all,
So here is my struggle at the moment.
I am trying to guesstimate the "actual" in-engine vert count for a given
object in Maya so we can validate the LOD steps per object before we export.
*Proposed solution:*
The way I am trying to do this is by checking that a vertex is on a UV
border edge and adding this to the total vert count.
So for example an object with 500 verts which has a UV border straight
through the middle will end up with 1000 verts in-engine because of the UV
split.
The problem I am having is wrapping my head around the underlying data
models for verts, faces, edges and uvs.
*Solution 1:*
I have a sort of working solution that does not use the API but instead
relies on the mel command: *polySelectBorderShell 1*
import pymel.core as pm
import maya.mel as mel
sel = pm.ls(sl=True)[0] # Get object selection
# Edges must be selected here
mel.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 = 0
multiList = 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
The above solution kinda gets me there and I need to make sure its legit
and patch it up but for the most part it works.
Problem is that it is *SLOW *hence trying to use the API.
*Solution 2:*
For the API I am following along with this mode of thinking here:
*http://forums.cgsociety.org/archive/index.php?t-729364.html*
Mu current solution and where I am stuck is here. I know I need to run some
comparisons but how and on what I am deadlocked at.
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()
Any suggestions on where to go from here or how to solve this is very much
appreciated!
// Ben
So here is my struggle at the moment.
I am trying to guesstimate the "actual" in-engine vert count for a given
object in Maya so we can validate the LOD steps per object before we export.
*Proposed solution:*
The way I am trying to do this is by checking that a vertex is on a UV
border edge and adding this to the total vert count.
So for example an object with 500 verts which has a UV border straight
through the middle will end up with 1000 verts in-engine because of the UV
split.
The problem I am having is wrapping my head around the underlying data
models for verts, faces, edges and uvs.
*Solution 1:*
I have a sort of working solution that does not use the API but instead
relies on the mel command: *polySelectBorderShell 1*
import pymel.core as pm
import maya.mel as mel
sel = pm.ls(sl=True)[0] # Get object selection
# Edges must be selected here
mel.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 = 0
multiList = 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
The above solution kinda gets me there and I need to make sure its legit
and patch it up but for the most part it works.
Problem is that it is *SLOW *hence trying to use the API.
*Solution 2:*
For the API I am following along with this mode of thinking here:
*http://forums.cgsociety.org/archive/index.php?t-729364.html*
Mu current solution and where I am stuck is here. I know I need to run some
comparisons but how and on what I am deadlocked at.
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()
Any suggestions on where to go from here or how to solve this is very much
appreciated!
// Ben
--
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+***@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.
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+***@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.