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.

Maya crashed by calling <MItMeshVertex>.getNormal().

Maya crashed by calling <MItMeshVertex>.getNormal().

Anonymous
Not applicable
903 Views
7 Replies
Message 1 of 8

Maya crashed by calling <MItMeshVertex>.getNormal().

Anonymous
Not applicable

Hello,

I was trying to get normal from the vertices that I select. but this code crashes maya.

I'm using maya 2019 in linux. if I use vert_itr.getNormals instead of vert_itr.getNormal, maya does not crash and returns proper vectors. but it returns the normals  of the current vertex for all faces. 

I want to use getNormal  to get average normal for the vertex. but maya crashes with the function.

 

import maya.api.OpenMaya as OM2

sel = OM2.MGlobal.getActiveSelectionList()
dag, component = sel.getComponent(0)
if not component.isNull():
    # There were components selected
    vert_itr = OM2.MItMeshVertex(dag, component)
    while not vert_itr.isDone():
        rayDirection = vert_itr.getNormal(OM2.MSpace.kWorld)
        vert_itr.next()

 

904 Views
7 Replies
Replies (7)
Message 2 of 8

stuzzz
Collaborator
Collaborator

Do you have the same problem with MItMeshVertex::getNormals()?

It would be way faster and better (if that avoid crashes).

0 Likes
Message 3 of 8

Anonymous
Not applicable

thanks for reply @stuzzz 

but if I use getNormals, I need to calculate average Normal again.

this worked fine in api 1.0. and I was translating this from api 1.0 to api 2.0. and I'm having issue with this.

so I'm wondering if I used this function wrong or if there is another issue.

 

 

 

0 Likes
Message 4 of 8

Anonymous
Not applicable
I just tested this code in maya 2020 on window machine.
and maya crashes as well.
anyone can take a look at this?
0 Likes
Message 5 of 8

stuzzz
Collaborator
Collaborator

Sorry I haven't read carefuly (sic!)

 

If you do something like this, it should work (it does on Maya2018).

I guess that something got wrong with the MSelectionList::getComponent()

you should use the MSelectionList::getDagPath instead

The component is stored in the MObject obj  which can be then passed to the MItMeshVertex constructor

 

 

sel = MSelectionList()
MGlobal.getActiveSelectionList(sel)
src=MDagPath();obj=MObject()
sel.getDagPath(0,src, obj)

it = MItMeshVertex(src, obj)
while not it.isDone():
	norm = MVector()
	it.getNormal(norm, MSpace.kWorld)
	it.next()

 

 

 

0 Likes
Message 6 of 8

Anonymous
Not applicable

I have similar code in api 1.0 like you and it works fine, but if I translate it into api 2.0 and does not work.

0 Likes
Message 7 of 8

stuzzz
Collaborator
Collaborator

it seems like you have your answer...

0 Likes
Message 8 of 8

michael.trainor
Explorer
Explorer

Just hit this myself. This was my solution. I use the indices with the index array I get from getTriangles().

indicies = list(mesh_polygon_iter.getVertices())
normals = list(mesh_polygon_iter.getNormals())
packed_normals = {v: list(n) for v, n in zip(indicies, normals)}

 

Good luck out there!

0 Likes