maya api - MFnMesh::allIntersections, too slow

698 views
Skip to first unread message

s...@weacceptyou.com

unread,
Aug 23, 2015, 7:36:56 AM8/23/15
to Python Programming for Autodesk Maya
Hello all,

im kind of stupid when it comes to using the api, but i needed it to check for intersections in my mesh when firing rays out from a particular point. In my script i need to be firing a hell load of rays. Probably around 500 by the end.

my program currently takes 23 seconds to process, and i have only finished about 10% of its full size in the end. About 16 seconds is taken up with the firing of the rays. It takes 0.04 seconds roughly to fire each ray. Which adds up quikly.

Does anyone know a clever way of streamlining the mFnMesh allIntersections thingy, maybe an alternative method. I just need to have something that takes a position and a vector and returns the coords of the interesection,

any help would be great,
Thanks,
Sam

e955...@gmail.com

unread,
Aug 23, 2015, 7:51:41 AM8/23/15
to Python Programming for Autodesk Maya, s...@weacceptyou.com
by the way here is a snippet of my code, the mesh.allIntersections thing is the part that is taking too long:

def returnCollisionPoints(self, point, dir):


sel = om.MSelectionList()
dag = om.MDagPath()

sel.add("BASE_MESHShape")
sel.getDagPath(0,dag)

mesh = om.MFnMesh(dag)

point = om.MFloatPoint(*point)
dir = om.MFloatVector(*dir)
hitPoints = om.MFloatPointArray()

mesh.allIntersections(
point, dir,
None, None,
False, om.MSpace.kWorld,
10000, False,
None,
True,
hitPoints,
None, None,
None, None,
None
)

return hitPoints

e955...@gmail.com

unread,
Aug 23, 2015, 10:38:20 AM8/23/15
to Python Programming for Autodesk Maya, s...@weacceptyou.com, e955...@gmail.com
ok apparently a mesh look up accelerator is needed to speed up the raytracing. God knows how to implement it though....

Janos Hunyadi

unread,
Aug 24, 2015, 4:22:23 PM8/24/15
to Python Programming for Autodesk Maya, s...@weacceptyou.com, e955...@gmail.com
mesh.allIntersections( 
                                point, dir, 
                                None, None, 
                                False, om.MSpace.kWorld, 
                                10000, False, 
                                None
                                True, 
                                hitPoints, 
                                None, None, 
                                None, None, 
                                None 
                        )      


just replace NONE with inMesh.autoUniformGridParams()

According to the maya API docs:

static MMeshIsectAccelParams uniformGridParams (int xDiv, int yDiv, int zDiv)
 Creates a MMeshIsectAccelParams configuration object to pass to the methods MFnMesh::closestIntersection()MFnMesh::anyIntersection(), or MFnMesh::allIntersections()
static MMeshIsectAccelParams autoUniformGridParams ()
 Creates a MMeshIsectAccelParams configuration object to pass to the methods MFnMesh::closestIntersection()MFnMesh::anyIntersection(), or MFnMesh::allIntersections()

Janos Hunyadi

unread,
Aug 24, 2015, 4:24:48 PM8/24/15
to Python Programming for Autodesk Maya, s...@weacceptyou.com, e955...@gmail.com
in your case inmesh.autoUniformGridParams(),  being mesh.autoUniformGridParams()

e955...@gmail.com

unread,
Aug 25, 2015, 3:52:13 AM8/25/15
to Python Programming for Autodesk Maya, s...@weacceptyou.com, e955...@gmail.com
thankyou very much Janos, alot of this api stuff is slowly starting to make sense to me.

cheers,
Sam
Reply all
Reply to author
Forward
0 new messages