Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MFnMesh: getFaceVertexIndex and getFaceAndVertexIndices

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
rflannery
1249 Views, 4 Replies

MFnMesh: getFaceVertexIndex and getFaceAndVertexIndices

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?)

4 REPLIES 4
Message 2 of 5
lanh.hong
in reply to: rflannery

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


Lanh Hong
Developer Technical Services
Autodesk Developer Network



Message 3 of 5
rflannery
in reply to: lanh.hong

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:

  • I think that the ID into any face-vertex array should be the same for a given faceIndex and vertexIndex.  So you don't need separate functions to get the ID for any data stored per face-vertex, like color, binormal, etc.
  • getFaceVertexColorIndex() can be used when you have a face-relative (local) vertex ID.
  • getTangentId() can be used when you have an object-relative (global) vertex ID.

In Python, it has been simplified:

  • getFaceVertexIndex() can be used with either face-relative or object-relative vertex IDs.

-------------------------------------------------------------

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++.

Message 4 of 5
lanh.hong
in reply to: rflannery

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

 

 

 


Lanh Hong
Developer Technical Services
Autodesk Developer Network



Message 5 of 5
rflannery
in reply to: lanh.hong

Awesome, thanks!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report