Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

OpenMaya MItMeshFaceVertex getUV parameters, expect float2

OpenMaya MItMeshFaceVertex getUV parameters, expect float2

MarcoGirard
Explorer Explorer
831 Views
2 Replies
Message 1 of 3

OpenMaya MItMeshFaceVertex getUV parameters, expect float2

MarcoGirard
Explorer
Explorer

Hi there, I use MItMeshFaceVertex iterator to get access to vertex info in a selection of faces. I try to use the "getUV" function which according to doc have this signature :

getUV(uvSet='') -> (float, float)

I tried different call most looking like this :

uv = itr.getUV('map1')

uv = itr.getUV()

 Yet I got the following error :

# TypeError: in method 'MItMeshFaceVertex_getUV', argument 2 of type 'float2 &'

I saw in the C++ API that the same function in C++ have a float2 as first parameter, which is probably provided by the python wrapper.

 

What did I not get please?

 

the whole code snippet look like this :

    sel = om.MSelectionList()
    om.MGlobal.getActiveSelectionList(sel)
    dag = om.MDagPath()
    comp = om.MObject()
    sel.getDagPath(0, dag, comp)
    
    itr = om.MItMeshFaceVertex(dag, comp)

        

    faces = []
    vertices = []
    poly_info = {}
    positions = om.MPointArray()
    uvs_u = om.MFloatArray()
    uvs_v = om.MFloatArray()

    # print '| %-15s| %-15s| %-15s' % ('Face ID', 'Object VertID', 'Face-relative VertId')
    while not itr.isDone():
        # print '| %-15s| %-15s| %-15s' % (itr.faceId(), itr.vertId(), itr.faceVertId())
        if itr.vertId() not in vertices:
            vertices.append(itr.vertId())
            positions.append(itr.position(om.MSpace.kWorld))
            if itr.hasUVs():
                uv = itr.getUV('map1')
                uvs_u.append(uv[0])
                uvs_v.append(uv[1])

        if itr.faceId() not in poly_info.keys():
            poly_info[itr.faceId()] = [itr.vertId()]
        else:
            poly_info[itr.faceId()].append(itr.vertId())

        itr.next()

    mesh_fn = om.MFnMesh()
    
    # in poly_info, each key is a polygon index from the original selection
    # and its value is a list of indices of each vertex that makes the polygon.the
    # The length of this list if the amount of vertices that will make the new polygon.
    polygon_counts = om.MIntArray()
    for v in poly_info.values():
        polygon_counts.append(len(v))

    # vertex in list "vertices" and the MPoint in "positions" indices correspond to each other
    polygon_connects = om.MIntArray()
    for v in poly_info.values(): # our list of list of vertex indices
        for i in v:
            polygon_connects.append(vertices.index(i)) # will get corresponding position

    placeHolderU = om.MIntArray()
    placeHolderV = om.MIntArray()
    dummy**** = om.MObject()
    new_mesh = mesh_fn.create(len(vertices), len(poly_info.keys()), positions, polygon_counts, polygon_connects)

    if uvs_u.length() and uvs_u.length() == uvs_v.length():
        mesh_fn.setUVs(uvs_u, uvs_v)

Thank you for your help! 🙂

     

0 Likes
Accepted solutions (1)
832 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Accepted solution

Hey,

 

I don't exactly have an answer to this question as even I don't know how to declare float2.

 

Having said that, you are mixing Python 1 Api and Python 2 Api.

What is om? maya.OpenMaya or Maya.api.OpenMaya ?

om.MGlobal.getActiveSelectionList(sel) is Python 1 Api style because python 2 Api signature returns sel via return type ie sel = om.MGlobal.getActiveSelectionList().

 

itr.getUV('map1') is again Python 2 Api style not Python 1 Api. Python 1 Api style is itr.getUV(float2 &).

 

So for what it's worth, I have imported om as maya.api.OpenMaya slightly changed all the methods as per Python 2 Api docs and itr.getUV('map1') works like charm :).

Message 3 of 3

MarcoGirard
Explorer
Explorer

Yes om is maya.OpenMaya so I figure now it's the API 1 I've been using. It's of course not what I should use. That explain why I've been so confused with the doc.

 

thank you so much!

0 Likes