MFnMesh.setVertexNormal Huge performance issue

70 views
Skip to first unread message

justin hidair

unread,
Feb 25, 2017, 2:58:48 AM2/25/17
to Python Programming for Autodesk Maya
I made a cool script (just starting in the Python API game)
it works like intend but the problem is speed, therefor performances..

Imagine a set of faces ... why not something like 5984 polygons(=11800 tris)

now imagine you iterate over these faces and for each you get their set of vertex, and within that set you iterate through each vertex to set the normal
(With MFnMesh.setVertexNormal() )

like you can imagine that's Reeally quick with a thing like a beveled cube (26 polys)

NOW, how Maya can update its vertex normals on the fly even with huge dense objects, and I get slow, and laggy with simply setting vertex normals???, even though It's not C++
that's not fair ! there must be a way ^_^

Christopher Crouzet

unread,
Feb 25, 2017, 3:42:16 AM2/25/17
to python_in...@googlegroups.com
MFnMesh.setVertexNormals()?


--
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_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/11408607-bfc6-4faa-a852-20756b39921e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Justin Israel

unread,
Feb 25, 2017, 4:03:25 AM2/25/17
to Python Programming for Autodesk Maya
I don't have much to offer in terms of specifics to the right api calls, but I can imagine 10k python functions calls is insanely slower than 10k C++ calls. 

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

justin hidair

unread,
Feb 25, 2017, 4:10:34 AM2/25/17
to Python Programming for Autodesk Maya
Using this it'll be faster ? the problem with this one is it requires mvectorArray to be as the same size as the vertex list, while I only have one common normal to apply ... Should I duplicate it time the number of vertices within the list ?

And is there a cool way to duplicate element within a list x number of time in python ?
Also I'm so happy this group exist

justin hidair

unread,
Feb 25, 2017, 4:12:52 AM2/25/17
to Python Programming for Autodesk Maya


Le samedi 25 février 2017 01:03:25 UTC-8, Justin Israel a écrit :
I don't have much to offer in terms of specifics to the right api calls, but I can imagine 10k python functions calls is insanely slower than 10k C++ calls. 


What you just said hurt my feelings lol I don't like that

Justin Israel

unread,
Feb 25, 2017, 4:49:10 AM2/25/17
to Python Programming for Autodesk Maya
Hah. I'm sorry to be the bearer of bad news. But that benefit you gain in fast prototyping and expressiveness in the dynamic python language is always going to come at a cost. If you are comparing many of thousands of functions calls, attribute accesses, etc, of a dynamically typed interpreted language to a compiled statically typed language, you will find a wide gap. 

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

Michael Boon

unread,
Feb 26, 2017, 6:39:39 PM2/26/17
to Python Programming for Autodesk Maya
Slower than C++ for sure, but depending on your needs it might still be fine. I often set normals on meshes up to about 100k verts using Python.

To create your MVector array (in Python API 2.0), something like this will do it in less than a millisecond:
    normals = [om.MVector(0,0,1)]*100000
Creating your id list takes about a millisecond too:
    ids = range(100000)
Then, like Christopher said:
    mesh.setVertexNormals(normals, ids)

Trying it on a sphere with 40,000 normals, I can create and set all the normals in 0.03 seconds.


On Saturday, 25 February 2017 20:49:10 UTC+11, Justin Israel wrote:


On Sat, Feb 25, 2017, 10:12 PM justin hidair <justin...@gmail.com> wrote:


Le samedi 25 février 2017 01:03:25 UTC-8, Justin Israel a écrit :
I don't have much to offer in terms of specifics to the right api calls, but I can imagine 10k python functions calls is insanely slower than 10k C++ calls. 


What you just said hurt my feelings lol I don't like that

Hah. I'm sorry to be the bearer of bad news. But that benefit you gain in fast prototyping and expressiveness in the dynamic python language is always going to come at a cost. If you are comparing many of thousands of functions calls, attribute accesses, etc, of a dynamically typed interpreted language to a compiled statically typed language, you will find a wide gap. 

--
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_maya+unsub...@googlegroups.com.

justin hidair

unread,
Feb 27, 2017, 1:15:38 AM2/27/17
to Python Programming for Autodesk Maya


Le dimanche 26 février 2017 15:39:39 UTC-8, Michael Boon a écrit :
Slower than C++ for sure, but depending on your needs it might still be fine. I often set normals on meshes up to about 100k verts using Python.

To create your MVector array (in Python API 2.0), something like this will do it in less than a millisecond:
    normals = [om.MVector(0,0,1)]*100000
Creating your id list takes about a millisecond too:
    ids = range(100000)
Then, like Christopher said:
    mesh.setVertexNormals(normals, ids)

Trying it on a sphere with 40,000 normals, I can create and set all the normals in 0.03 seconds.


Woah , great ! Thank you
Reply all
Reply to author
Forward
0 new messages