Best way to poke holes in terrain?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Akonyl
Posts: 4
Joined: Fri Sep 19, 2014 12:27 am

Best way to poke holes in terrain?

Post by Akonyl »

I just started using BEPU terrains in my project, and recently I've been thinking of how best to poke holes in the terrain so that they can be fallen through, like if I want a cave in a mountainside, I can insert a cave model under the mountain and cut a hole in the terrain for the mouth.

My current way of achieving this is by putting NaNs in the height map where I want a hole to appear, which seems to work. This feels a bit hack-y though, and also seems like it depends on the "grain" of the terrain, because only triangles using that vertex are nulled out, so if one vertex is NaN-d, two opposite quads will be completely gone, and on the other two, the triangles furthest from the NaN will still be there. Preferably, I would like cutting out a vertex to uniformly remove all the adjacent quads, rather than it being dependent on the terrain's orientation + grain.

So my question is, is there a better way to do this? The only other way I could think of would be to subdivide the terrain around the desired holes, but though that's easy enough for one hole, adding more would make things increasingly complex.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Best way to poke holes in terrain?

Post by Norbo »

I would recommend changing the TerrainShape.GetOverlaps function. It is used by collision detection to select which triangles are potentially in collision with another object.

Right now, it selects every triangle in a bounding box. Some additional condition could be inserted to filter out certain triangles to allow caves. I wouldn't recommend using NaNs to flag it, though; there is some complexity surrounding the performance of NaN in different usages and hardware. I'm not entirely sure where things stand these days. A simple large negative value or supplementary data structure would do the trick, though.
Akonyl
Posts: 4
Joined: Fri Sep 19, 2014 12:27 am

Re: Best way to poke holes in terrain?

Post by Akonyl »

I didn't know that about NaNs, good to know.

I took a look at GetOverlaps and tweaked it & my code to look for sufficiently negative values, and it seems like that does the trick, thanks! I guess the only downside to this method is that all my holes will be at least 2x2, but if that ever becomes an issue I can just use another structure to solve that rather than ultra-negative values, as you said.
Post Reply