This project has moved and is read-only. For the latest updates, please go here.

How to break down Geoms?

Topics: User Forum
Feb 25, 2010 at 7:23 PM

Hey everyone, this is my first post here, but first I want to say thanks to every one that has posted in these forums. I have found a lot of great info here.

First of all, here is my situation: I'm trying to create destructible terrain for a new game.  I tried multiple methods, but they all had different problems. At first, I just used a Texture2D, and deleted part of the texture when an explosion occured. This would be fine if I didn't want physics. I also tried creating an array of block objects, and filling in the original terrain Texture2D with 50X50 blocks, then filling in the rest of it with 10X10. These 10X10 blocks made the game lag terribly, so that is out of the question.

The reason I want to have physics enabled is simple: Imagine you drilled a hole all the way through a mountain... if you did the texture technique, once you made a hole all the way through the moutain, the top piece wouldn't fall down.

My first thought on this was to create a polygon from the terrain, and subtract a circle geom from it in the Explosion method. This seems like it will work, but once the polygon has a hole all the way though it, how do I create a separate Geom for the top piece?

Also, if possible, I'd like to make the polygon from a nice looking texture, with detail. When the main Geom is divided, I'd like for the second Geom to maintain its current texture.

The secondary Geoms also need to be able to be broken apart.

If this would just be too hard to do, then maybe the block idea was better? It would work perfectly if i made it correctly, I believe. I don't think there should be any reason that many bodies would create lag, but I don't know.


Thanks in advance!

Feb 25, 2010 at 8:57 PM
Edited Feb 25, 2010 at 8:58 PM

You've posted a very interesting but complex problem. The best way is to come up with a list of methods you think may work and then try each one. Try it and see! I've come up with a few creative solutions that I would like to try when I have some time to figure out how to do it.

Vertex Manipulation

If all your looking for is to remove sections of terrain why not do exactly what 3D games do when they have destructible terrain? Vertex manipulating the geometry that you want to destroy depending on what hits it. I believe you could take your geometry and create/manipulate new vertexes in the pattern that you want to collide with your object. This is a fairly complex method but it might work.

Rebuild geometry based on Texture2D

The other method I'm thinking of is to actually remove parts of the texture. Then, every time part of the texture is destroyed/removed do analysis on it and recalculate the geometry. By doing this you can create a geometry with custom vertices along the edges of the terrain and match the shape of your terrain. If you can figure out when pixels of the texture are surrounded by 255 alpha (no terrain around it) convert that into a new geometry and copy it to a new texture associated with the new geometry and now it'll act like a physics object.


Anyway it sounds pretty complex and I'm not sure if you can even create geometries of custom vertices in Farseer yet as I've only begun looking at it yesterday but when you have a complex problem just start breaking it down into possible methods.

Feb 25, 2010 at 9:21 PM

I had both of those methods working before, actually. The problem with both of them is that I dont know how to actually create a totally separate Geom when the main geom splits into two pieces.