Maya API 2.0 get vertices/faces faster?

已查看 615 次
跳至第一个未读帖子

João Victor

未读,
2021年4月2日 12:23:572021/4/2
收件人 Python Programming for Autodesk Maya
Hey guys!
Could somebody help me?

What is the faster way to get vertices of a face?

Simply converting the selecion? Or there is a smarter solution?

Thanks!

Marcus Ottosson

未读,
2021年4月2日 12:29:122021/4/2
收件人 python_in...@googlegroups.com
Faster than what? What have you tried and what was the performance of it?

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/dccecf9e-b015-487a-99e0-2581af29ff98n%40googlegroups.com.

João Victor

未读,
2021年4月3日 15:58:012021/4/3
收件人 Python Programming for Autodesk Maya
Hey Marcus, thanks for replying.
I have to loop it in thousands of times.
converting with "polyListComponentConversion" takes too long.
There is some way to get it, without having to convert? Or this is the only way?
Im using API.
thanks!

João Victor

未读,
2021年4月3日 16:00:262021/4/3
收件人 Python Programming for Autodesk Maya
Marcus, explanning better my previous email:

For example, if I want to get the edges around this vertex, I would do this:

vtxToEdges = cmds.polyListComponentConversion(vtx, fromVertex=True, toEdge=True)

But it is taking too long in thousand loops. :/

Marcus Ottosson

未读,
2021年4月3日 16:22:492021/4/3
收件人 python_in...@googlegroups.com

Ok, I’m missing a lot of information haha. Let me try and fill in some gaps.

Here’s finding edges for 1 vertex amongst 100,000 vertices.

plane, _ = cmds.polyPlane(sx=1000, sy=100)
cmds.scale(10, 1, 10)

def measureMe():
    vtx = plane + ".vtx[10]"
    cmds.polyListComponentConversion(vtx, fromVertex=True, toEdge=True)

iterations = 100
result = timeit.timeit(measureMe, number=iterations)
resultMs = result * 1000
resultPerIteration = resultMs / iterations
print("%.2f ms/iteration" % resultPerIteration)
# 0.50 ms/iteration

It’s clocking in at half a millisecond. Now, is this what you mean by slow? What do you consider fast? What numbers are you hoping for?


João Victor

未读,
2021年4月3日 18:47:402021/4/3
收件人 Python Programming for Autodesk Maya
Hey Marcus! Thanks a lot for the suggestion!
As I understood in your code, you are getting the same vtx[10], right?
I was looking for something like this:

#supposing this mesh has 100.000 vertices
for vtx in list_of_all_vertices_of_the_mesh:  
    vtxToEdges = cmds.polyListComponentConversion(vtx, fromVertex=True, toEdge=True)
    vtxToEdges = cmds.ls(edgeToVtx, flatten=True)
    a = vtxToEdges

So it would get the edges around all 100.000 vertices and return 100.000 different groups of edges (each one related to each vertex).

The code above is taking 7.484 seconds, specially because I have to flatten it, otherwise would take 2.047 seconds.. :/
And I have to make it in 3 meshes, one of them needs more conversions, sometimes from faces to vertices.

So if there was a way to get it faster, instead throught conversions, would be great to shrink down this time.. :)

thanks a lot!!!

vince touache

未读,
2021年4月3日 20:06:162021/4/3
收件人 Python Programming for Autodesk Maya
if you're looking at querying many vertices per mesh, you might wanna building and caching an incidence matrix, instead of doing what you're doing now, that should save you a fair bit of redundancy

João Victor

未读,
2021年4月3日 21:00:422021/4/3
收件人 Python Programming for Autodesk Maya
thanks a lot vince!
do u have any suggestion about how I can build this incidence matrix? sorry, I have no idea.

thanks!

Jakob Kousholt

未读,
2021年4月3日 21:25:562021/4/3
收件人 python_inside_maya
You could look into MSelectionList and MItSelectionList from the Open Maya module. 

It lets you iterate over things quite fast. It is how Niels Peter and I traverse Geometry looking for issues in our model validation tool. It's probably not the fastest approach, but it is fairly straightforward to implement.

You can look at the source code here for some examples: https://github.com/JakobJK/modelChecker/blob/master/src/modelChecker.py



João Victor Ferreira

未读,
2021年4月3日 22:02:452021/4/3
收件人 python_in...@googlegroups.com
Hi Jakob!
Thank u very much for these informations!
I will take a look at your source code!
Thanks a lot! :)

Joao

Enviado do meu iPhone

Em 3 de abr. de 2021, à(s) 22:25, Jakob Kousholt <jak...@gmail.com> escreveu:



David Alvarez

未读,
2021年4月4日 03:21:522021/4/4
收件人 python_in...@googlegroups.com
Hi Joao, I don't know if is this the kind of info you are looking for https://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__files_Polygon_API_The_five_basic_polygonal_API_classes_htm
Iterators I suppose is the way to go if you have to collect info from the whole mesh. The link I provide is c++ but you could do the very same with the python API.

João Victor

未读,
2021年4月4日 05:01:002021/4/4
收件人 Python Programming for Autodesk Maya
Hey Davi, thanks a lot for replying!
I will take a look at the examples you sent me, so I get back to this thread to say if worked! :) I also think from now it is the best way to go.

thanksss a lot!



note: as my buddy Marcus suggested me an amazing idea, I am saying I also posted this question on Autodesk forums, so if artists here want to follow another thread with this subject, with possibly other constructive information , take a look there! :D

João Victor

未读,
2021年4月4日 10:16:202021/4/4
收件人 Python Programming for Autodesk Maya
Hey Vince, Jakob and Davi!
Thank you very much for your help, I received this suggestion below from an artist called tfox, I hope it is useful for you, I believe it is similar what you suggested me.
It tooks only 0.047 seconds for 100K polygons.

def buildFaceVertList(fnMesh):
    cursor, out = 0, []
    counts, idxs = fnMesh.getVertices()
    for i, count in enumerate(counts):
        out.append(idxs[cursor: cursor + count])
        cursor += count
    return out

thank you very much also to my buddy Marcus for trying to understand the question!

Cheers! :D

回复全部
回复作者
转发
0 个新帖子