Detecting if a mesh is inside another?

Blitz3D Forums/Blitz3D Programming/Detecting if a mesh is inside another?

ICECAP(Posted 2005) [#1]
Is there any way of detecting when one mesh is inside another. I have tried mucking round with MeshesIntersect() but that just detects when they intersect not when one is inside the other.

Any thoughts?


DJWoodgate(Posted 2005) [#2]
You could try flipping the second mesh, the one you think you are inside, and then testing the assumption with a linepick from inside the first mesh to somewhere you are sure will be outside the second. That's assuming the potential containing mesh is completely closed.

Edit... thinking about it that will not work too well. You could perhaps create a duplicate of the second mesh and flip it, so you can be sure you are picking inside out and not outside in.


jfk EO-11110(Posted 2005) [#3]
I would pick from inside in 6 directions. If it all hits the outter mesh, mesh one is inside. well, maybe o_O


Picklesworth(Posted 2005) [#4]
Check X Y Z positions according to center of both objects. Check size of both objects.
If the one expected to be inside is smaller, and it is in the same position (keeping in mind a clearance found with the difference between both object's X Y Z and Width Height Depth values), it's inside.


DJWoodgate(Posted 2005) [#5]
Thing is the container mesh could be any shape and need not even be centred on it's origin. If the container has two sides, by using a flipped copy, temporarily anyway, then when you pick from inside, you will pick the inside copy. Otherwise if it is only one sided you might pick from the outside and still pick the inside.

I suspect there will be even more sophisticated approaches by building a representation of the bounding volumes or creating a BSP for the geometry. Above my head though.

I suppose you could also try using your own ray caster routine which can detect triangle intersection from either direction. I think SSwift posted something on the archives.


Floyd(Posted 2005) [#6]
This might be feasible if the meshes are extremely simple, but in general it would be very difficult.

Consider something as simple as a torus ( i.e. donut ) and a cylinder. Is the cylinder inside the torus?

It may be that all the cylinder's vertices are inside the torus, but part of the cylinder is outside, in the 'donut hole'.


PowerPC603(Posted 2005) [#7]
You could check in 6 directions (like jfk EO-11110 said), and when the test is positive (the linepick hits the outer object), you could check with MeshesIntersect.

If that returns False, then your inner mesh is really inside the outer mesh (this could work for the example Floyd mentioned, cylinder inside torus).


_PJ_(Posted 2005) [#8]
Providing you know where the Entity handles are that represent the meshes' positions and sizes, perhaps EntityDistance may actually be quite useful.

PowerPC's answer seems to be the simplest and workable solution, except that if said cylinder was slightly above the centre of the torus, then a TRUE-FALSE result would still be given, so a bit more checking would be necessary for such a scenario.


ICECAP(Posted 2005) [#9]
Cheers for your feedback, i'll give several ways a go and see which ones work better.