Inside / Outside of a Mesh

Posted By: Kartoffel

Inside / Outside of a Mesh - 06/11/12 17:46

Hi there,

in my code I want to check if a specific point
(given with it's XYZ Position-Vector)
is inside a mesh or if it's not.

Has anyone an idea what's the best - or in my case - the most efficient way to do this?
Posted By: MasterQ32

Re: Inside / Outside of a Mesh - 06/11/12 18:13

take a point from surely outside the mesh, trace to the point and collect all hitpoints with the mesh
an even number of hitpoints is outside the mish, otherwise inside
Posted By: yorisimo

Re: Inside / Outside of a Mesh - 06/11/12 18:20

I made invisible level blocks out of primitives (ellipse, cylinder, block) that were close to the shape of the mesh. I then used the "c_content" function to check whether or not a point was within empty space or a passable or unpassable block. In this way I could distinguish whether or not the specified point was inside one mesh or another, or neither. In documentation however, it says that this function is abandoned an not to be used in new projects. Also if your mesh entity moves you would have to move the level blocks along with your mesh.

@MasterQ32 - sounds like a better idea!
Posted By: EvilSOB

Re: Inside / Outside of a Mesh - 06/11/12 18:52

Simply do a c_trace from the XYZ point in question, to the XYZ co-ordinate(origin) of the mesh.
(Using USE_POLYGON of course)

If you DO get a hit, then it is outside.

If you DONT get a hit, then its inside.


Unless its a really complex mesh, then I dunno... maybe
the function "c_intersect" could be twisted into effect....


Posted By: Kartoffel

Re: Inside / Outside of a Mesh - 06/11/12 19:27

Thank you very much for the answers!!

Doing some testing now wink
Posted By: Kartoffel

Re: Inside / Outside of a Mesh - 06/11/12 20:14

OK I'm using now EvilSOB's method.
I created a model and checked a cube with 20*20*20 single traces... which works fine
but sometimes there are points outside of the mesh detected as inside of it... (pic)

Another thing is, that this c_trace-method only works it I add wait(...); functions between every trace.
Without wait()s the detection goes completely wrong.

And it would be nice if this could be checked once per frame.
But even if it would work without the wait(); functions it would be too slow. (Manual>c_trace>Speed: Slow)

Looks like this won't work with 3DGS.
Anyway, thaks a lot for your nice replys!

Kartoffel smile
Posted By: MasterQ32

Re: Inside / Outside of a Mesh - 06/11/12 20:48

EvilSOBs method only works if you got a mesh like a cube or a sphere
the basic idea is correct, but you can also have different cases of meshes:

The trace hits something (our gray funny-looking blob-mesh), but is NOT inside the mesh!
As i said you have to count all hits on this mesh. Even results (in this case 2) are outside the mesh, odd numbers are inside
this would be an accurate system to check if you are inside the mesh
and don't forget to active USE_POLYGON

For counting the hit targets you could use a contribution of me (Multiple Hit Traces)
Posted By: Kartoffel

Re: Inside / Outside of a Mesh - 06/11/12 20:56

I'm tracing from the Position which should be checked to the middle of the object.

If it hits nothing it is inside.
And as long as all normals pointing away from the center and the center is inside the mesh, too this works.

For more complex models I'd go for your solution.

But as I already said: c_trace isn't the right way to go if I want to do this once per frame.

It would be nice If it works as I want, but It doesn't matter.
It's just a kind of test-project I wanted to do, but obviously it wont work fast enough.
© 2024 lite-C Forums