big problem with MFnMesh::allIntersections

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Display Modes
  12 December 2008
Angry big problem: MFnMesh::allIntersections collapses intersections

Hey there again!
I've got a big problem :(

I based my whole plugin on the assumption, that MFnMesh:: allIntersections() will give me all intersections of a ray with a mesh. Now I noticed that the function collapses intersections that happen at the same location in 3D space.
Now - in my case there can be multiple intersections in the same place, but with different polygons (because the polygons intersect each other or may even lie in the same plane) - but it's extremely important for me to get those intersections too, because for me not the intersectionPoint, but the hitFace and the barycentric coordinates matter.

I already tried to set the tolerance of MFnMesh:: allIntersections to 0 or to extremely small value - but still the same issue.

That's really important for me - how can I make this function return me all intersections and not throwing away any intersections even if they happen at the same location?

Thank you!

Last edited by MatthiasBuehlmann : 12 December 2008 at 05:38 PM. Reason: more accurate title
  12 December 2008
Sounds like you're dealing with a pretty bad geometry there :P Can't imagine any production scene being the case of such.

But anyway you can use the old intersect method: MFnMesh::intersect() instead.
It is slower since it is not using any grid structures to optimize stuff but I have found it being more reliable in many cases.
Diffusion Curves


  12 December 2008
hey GennadiyKorol, thanks again for your help!

yeah - this mesh is not going to be conventionally rendered . it's kind of a helper that combines different scenedata and relations in one geometric structure. I know that the function was not intended to be used for something like that, but I really hope that i don't have to write my own accelerated intersection routine, since it most probably will be much slower :(

thanks for the suggestion of the old intersect function. Unfortunately this function does not return hitTriangle ID's and Barycentric coordinates, which is the data i'm interested in :(

my current attempt is to use a while loop and call the allIntersections function multiple times, each time excluding the polygons from the last hit.
But of course that's making the whole thing much slower (performance already was an issue before).

Also, maybe do u know whether the accelerationStructur is actually used by the algorithm? i don't notice any performance benefit from using one (tried with different creation parameters). It's like 100 times slower than the rayintersection algorithm used by the software renderer...

Thank you!
  12 December 2008
Yes, grid accelerator is used and acceleratedIntersect calls are usually much faster than non accelerated calls for large number of triangles.

My guess is that the algorithm uses the basic uniform grid approach.
A better solution would be to use BSP tree or Octree.

But there is little need in implementing them on your own. There are plenty of libraries that already implement mesh to mesh, mesh to ray intersections. I don't remember exactly the name of the library but you can sure google it up.

For barycentric coordinates - just compute them on your own.
x1, x2 and x3 of vertex p in triangle t {p1, p2, p3} could be computed by relative areas of triangles defined by the intersection point and other 2 vertcies.

x1 = A({p2, p, p3}) / A(t)
x2 = A({p1, p, p3}) / A(t)
x3 = A({p1, p, p2}) / A(t)

Area of the triangle is twice the length of the cross product between any 2 vectors of the triangle.

Maya has all the methods to compute barycentric coordinates on your own given the intersection point p and the triangle id.

So if the intersect() method is fast enough and gives you the correct results it would be the fastest way to the goal
Diffusion Curves


  12 December 2008
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 12:46 AM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.