I am looking for a formula or a command (OpenMaya or Python or Mel) to which if I provide the vertex number, it returns me the face number of the mesh considering provided vertex number is the first vertex of a Mesh.
(I believe I will have to provide mesh name because this calculation will need mesh width and height)
Note : I have to do the calculation based on Vertex Number, I can’t use FaceVertex number.
eg. In the attached image :
vertex - 0 gives Face - 0
vertex - 1 gives Face - 1
vertex - 3 gives Face - 2
vertex - 4 gives Face - 3
Thanks
Hey Chakmangoo,
You can use the mel commands below to get what you need
Use:
polyInfo -vertexToFace
to get a list of faces that use the vert, then use
polyInfo -faceToVertex
for each face and check the first vertex in the results…
Maya returns the vert list of a face in winding order, so you will get the correct order.
If you need a hand getting the code going, drop me a line.
-Butters
Hello Butters,
Thanks for your help. I forgot to mention that I am writing the code in OpenMaya.
I came up with following function which gives me the mapping :
def mapVertexTofaceandFaceVertex(objName):
dagNode = nameToMObjectName(objName)
dagPath = mObjectNameToDagPath(dagNode)
mFnMesh = OpenMaya.MFnMesh(dagPath)
mFnDagNode = OpenMaya.MFnDagNode(dagNode)
mColorArray = OpenMaya.MColorArray()
mFnMesh.getVertexColors(mColorArray)
validVertices = []
for i in range(0, mColorArray.length()):
bBox = mFnDagNode.boundingBox()
if (i % (bBox.width() + 1)):
validVertices.append(i - 1)
''' Find number of Faces in Mesh '''
mFaceColorArray = OpenMaya.MColorArray()
mFnMesh.getFaceVertexColors(mFaceColorArray)
totalFaces = mFaceColorArray.length() / 4
faceVertexMap = []
faceNumbers = []
firstVertex = []
firstFaceVertex = []
faceVertexCounter = 0
for i in range(0, totalFaces):
faceVertexMap.append({"face":i, "firstVertex":validVertices[i], "faceVertex":faceVertexCounter})
faceNumbers.append(i)
firstVertex.append(validVertices[i])
firstFaceVertex.append(faceVertexCounter)
faceVertexCounter += 4
#faceVertexMap.append(validVertices[i])
return faceNumbers, firstVertex, firstFaceVertex
[QUOTE=Butters;16922]Hey Chakmangoo,
You can use the mel commands below to get what you need
Use:
polyInfo -vertexToFace
to get a list of faces that use the vert, then use
polyInfo -faceToVertex
for each face and check the first vertex in the results…
Maya returns the vert list of a face in winding order, so you will get the correct order.
If you need a hand getting the code going, drop me a line.
-Butters[/QUOTE]