Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 959 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Inside / Outside of a Mesh #402892
06/11/12 17:46
06/11/12 17:46
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
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?


POTATO-MAN saves the day! - Random
Re: Inside / Outside of a Mesh [Re: Kartoffel] #402898
06/11/12 18:13
06/11/12 18:13
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
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


Visit my site: www.masterq32.de
Re: Inside / Outside of a Mesh [Re: Kartoffel] #402899
06/11/12 18:20
06/11/12 18:20
Joined: Mar 2007
Posts: 197
Y
yorisimo Offline
Member
yorisimo  Offline
Member
Y

Joined: Mar 2007
Posts: 197
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!

Last edited by yorisimo; 06/11/12 18:22.

Joris Lambrecht
My Contributions: Relative Rotation, Window Sizing
Re: Inside / Outside of a Mesh [Re: yorisimo] #402902
06/11/12 18:52
06/11/12 18:52
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
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....




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Inside / Outside of a Mesh [Re: EvilSOB] #402910
06/11/12 19:27
06/11/12 19:27
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Thank you very much for the answers!!

Doing some testing now wink


POTATO-MAN saves the day! - Random
Re: Inside / Outside of a Mesh [Re: Kartoffel] #402914
06/11/12 20:14
06/11/12 20:14
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
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


POTATO-MAN saves the day! - Random
Re: Inside / Outside of a Mesh [Re: Kartoffel] #402916
06/11/12 20:48
06/11/12 20:48
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
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)


Visit my site: www.masterq32.de
Re: Inside / Outside of a Mesh [Re: MasterQ32] #402917
06/11/12 20:56
06/11/12 20:56
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
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.

Last edited by Kartoffel; 06/11/12 20:59.

POTATO-MAN saves the day! - Random

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1