Find vertex index from uv value

722 views
Skip to first unread message

Rémi Deletrain

unread,
Jun 1, 2016, 12:29:55 PM6/1/16
to Python Programming for Autodesk Maya
Hello everyone,

I have a question just being stupid.
Is it possible to retrieve the index of a vertex with u and v values.

Or find the index of a uv with u and v values to then find the index of the vertex.

The objectif is to make a symmetry with the points by uv.

Rémi Deletrain

unread,
Jun 2, 2016, 12:07:19 PM6/2/16
to Python Programming for Autodesk Maya
I have a solution but it is very long in python. Easy to reproduce in cpp but I would like as much as possible try to make a quick trick in python ...


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

#    Get All UVs
u_values = OpenMaya.MFloatArray()
v_values = OpenMaya.MFloatArray()
mfn_mesh.getUVs(u_values, v_values, "SKIN")

#    Sort UVs left / right
r_list = {}
l_list = {}

for idx, (u, v) in enumerate(zip(u_values, v_values)):

    if u < 0.5:
        r_list[str(idx)] = [u, v]
    if u > 0.5:
        l_list[str(idx)] = [u, v]

#    Get UVs sym map
sym_map = {}
for rk, rv in r_list.items():

    sym_uv = pmc.dt.Vector(1 - rv[0], rv[1], 0)

    tmp_length = None
    for lk, lv in  l_list.items():

        l_uv = pmc.dt.Vector(lv[0], lv[1], 0)
        distance = sym_uv.distanceTo(sym_uv)

        if tmp_length is None or distance < tmp_length:
            tmp_length = distance
            sym_map[rk] = lk
            del l_list[lk]

#    R vertices
r_vertices = []
for idx in sym_map.keys():
    uv_name = mesh_node.name() + ".map[" + str(idx) + "]"
    v = pmc.polyListComponentConversion(uv_name, fromUV=True, toVertex=True)
    r_vertices.extend(v)

pmc.select(vertices)

#    L vertices
l_vertices = []
for idx in sym_map.values():
    uv_name = mesh_node.name() + ".map[" + str(idx) + "]"
    v = pmc.polyListComponentConversion(uv_name, fromUV=True, toVertex=True)
    l_vertices.extend(v)

pmc.select(r_vertices)
pmc.select(l_vertices)

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

Rémi Deletrain

unread,
Jun 6, 2016, 7:23:53 AM6/6/16
to Python Programming for Autodesk Maya
Hello everyone,

I found a solution to optimize a little time calcul.
I split UVs to reduce the search field.

I share with you the python script.

It's possible you have small problem when you launch script, I have split fwe function of my scripts

Doktor Weeny

unread,
Jun 7, 2016, 3:38:03 PM6/7/16
to Python Programming for Autodesk Maya
You could have use cmds.polyListComponentConversion  (even if it is a quite slow command)

Rémi Deletrain

unread,
Jun 7, 2016, 5:02:15 PM6/7/16
to Python Programming for Autodesk Maya
This command convert element index to another element index. Not found symetric index of an element.

And this command is very slow. I think it's possible to recreate this command for convert uv index to vertex index in api.
Today i try to convert this code to cpp and the result is very interesting.
Tomorrow i try to create command for convert uv index to vertex.

Reply all
Reply to author
Forward
0 new messages