Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
I am doing some API work using the Maya Python API 2.0. Sometimes when trying to figure out a particular function, I will look at both the C++ and Python documentation. Today I was looking for more information about the functions "getFaceVertexIndex" and "getFaceAndVertexIndices" from the class "MFnMesh". But it looks like those are only listed in the Python documentation.
Does anyone know why those functions would exist only in the Python API and not in the C++ API? (Or maybe they do exist in the C++ API but the documentation is incomplete?)
Solved! Go to Solution.
Solved by lanh.hong. Go to Solution.
Hi rflannery,
Sometimes C++ doesn't map exactly to the Python API. The Python 2.0 API is written to be more "pythonic". Therefore, there are some additional or missing functions compared to C++ to make the workflow better for Python.
I look through the docs and it seems that Python use the getFaceVertexIndex() to index into the color array returned by getFaceVertexColors(). In C++, it uses the getFaceVertexColorIndex() to do the same thing.
Regards,
Lanh
Interesting. The getFaceVertexIndex() function in Python says it can be used to index into various arrays, "such as those returned by getFaceVertexBinormals(), getFaceVertexColors(), getFaceVertexNormals(), etc." After reading your comment, I thought "Oh, so maybe the Python function is a replacement for several C++ functions." But the only functions I found in the C++ were getFaceVertexColorIndex(), getTangentId(), and getFaceVertexBlindDataIndex(). After a bit more searching of the documentation, I came up with this theory about the C++ functions:
In Python, it has been simplified:
-------------------------------------------------------------
What originally led me down this rabbit hole is that I was using the Python API to work with the mesh normals. I was using getFaceAndVertexIndices() to get the face and vertex, because I already had the normal ID. It doesn't look like there is an equivalent in the C++.
Hi rflannery,
So sorry if I confused you. It was just an example to show you that Python and C++ does not always have the same function names, but can still do the same thing in their own way.
In Python, those functions can use either face-relative/local or mesh-relative/global vertex index. In C++, it's separated into different functions. The Python API wraps around the C++ API so when the Python API was written, those functions were cleaned up so it's a easier to use. However, the C++ API never applied those changes.
One of our engineers wrote the equivalent of Python's getFaceAndVertexIndices() and getFaceVertexIndex() in C++ for you. They used MFnMesh::getBlindDataFaceVertexIndices(), MFnMesh::getFaceVertexBlindDataIndex(), and MFnMesh:: getPolygonVertices().
MStatus mesh_getFaceAndVertexIndices(MFnMesh &mesh, int faceVertexIndex, int &faceIndex, int &vertexIndex, bool localVertex=true) { MStatus status = mesh.getBlindDataFaceVertexIndices(faceVertexIndex, faceIndex, vertexIndex); CHECK_MSTATUS_AND_RETURN_IT(status); if (localVertex) { MIntArray globalVertIds; status = mesh.getPolygonVertices(faceIndex, globalVertIds); CHECK_MSTATUS_AND_RETURN_IT(status); for (unsigned int i = 0; i < globalVertIds.length(); ++i) { if (globalVertIds[i] == vertexIndex) { vertexIndex = (int)i; break; } } } return status; }
MStatus mesh_getFaceVertexIndex(MFnMesh &mesh, int faceIndex, int vertexIndex, int &faceVertexIndex, bool localVertex=true) { if (localVertex) { MIntArray globalVertIds; MStatus status = mesh.getPolygonVertices(faceIndex, globalVertIds); CHECK_MSTATUS_AND_RETURN_IT(status); if (vertexIndex >= (int)globalVertIds.length()) return MS::kFailure; vertexIndex = globalVertIds[vertexIndex]; } return maya.getFaceVertexBlindDataIndex(faceIndex, vertexIndex, faceVertexIndex) }
Hope this clears things up. 🙂
Regards,
Lanh
Can't find what you're looking for? Ask the community or share your knowledge.