Dynamic destructible environment in BGE?

Hello,

I’m looking for something that’s possibly a bit tall order for my small project…

Basically, I want an explosive projectile to be able to leave a crater in level geometry. The crater geometry would ideally be semi-randomized or procedural, but calling in from a selection of prebuilt props would be sufficient, at least as a rough draft. The important point is that this needs to be done during run-time -not prebaked- as the point of impact is a variable that cannot be known beforehand, i.e. it needs to be “Dynamic”.

If there is not already a package that can do this, then I would like to discus implementing it ourselves, as I feel this is a very desirable game-play feature.

Note:
(1) I am aware of the performance implications of having gameplay actively create potentially unbound amounts of geometry.

(2) I am aware that texturing is most likely going to brake if not done very carefully.

(3) Very old AAA games (Red Faction, with its “GeoMod”), and several indie titles (Terraria, Minecraft, Starbound) have at least something similar, so it’s not at all impossible.

If the blocky nature is acceptable I have plenty of examples.
From simple low performance to more complex ones.

http://i.imgur.com/SwHHMRD.gif

The routine is,

  1. have read all vertex/face positions into a dictionary,
  2. in game ,in affected area move - reuse faces.
    You can’t create new faces in a mesh in game engine, but you can move and reuse them.

If you woud like more of the kind like smooth ground denting and realistic buildings crumble, then I am of no help.

Oh!, thanks for the posts everyone. (I was apparently not getting emails about this, I will manually subscribe.)

adriansnetlis has called out about what I’m looking for here…

I guess you are making something that should work to Worms system, right?

Indeed. I want a sandbox environment if at all possible. I want the player to be able to potentially blast holes in a nearby wall when he can’t get through a door, or when there simply isn’t one. I want an unintended explosion to cut off routs, potentially requiring the player to rethink their path.

I can make a fun game without this, but it’s one of the things on my short list of got-to-have game-play elements.

@Vert shifting
This unfortunately isn’t applicable. Moving a vertex over and over again will only stretch the mesh, it won’t create new vertexes/edges/faces, and it can’t destroy them either. I need the system to allow creating a tunnel through a destructable object to the other side. If a vert was pushed to the other side of an object, it would simply clip through the face and keep going.

@Voxel options
From a computer science perspective, I do like voxel based systems. However, since the introduction (and huge $uccess) of Minecraft there have been so many of them popping up that I’m thoroughly jaded. I don’t mean to rebel against popular opinion, but voxel games are becoming so increasingly cliché that I feel it wise to avoid them for new projects.

@scorpion81
voronoi-based fracture at run-time would be great, possibly preferred to what was swimming around in my head. It certainly looks good. I have tried prefractured assets a bit already (I think with cell fracture) but getting what I wanted proved to be unreasonably tedious. I have a great deal of stuff I want to make destructible, and I want it to break in parts/layers. I want to be able to bore a hole into a destructible material, not unlike what’s going on in VegetableJuiceF’s voxel video. This nature makes the problem so dynamic that it’s not feasible to precalculate all the fractures. So I really have to just avoid prefractured assets if at all possible.

Very interested in the real-time aspects of what you’ve presented though. I’ll probably have to take a look at it.

@VegetableJuiceF

You can’t create new faces in a mesh in game engine…

That is disappointing news.

I do have to ask though, is this a certain fact? Is it hard-coded into the blender game engine or something? Is there no way for the game engine to add mesh elements?

I was expecting that the objective might be doable about like so…
(1) Get the projectile’s point of impact (simple bullet call[back]?)
(2) Spawn a “positive crater mesh” at this point. (preferably procedurally generated geometry)
(3) Use the positive to create a negative (a simple bool clip?) in the affected geometry.

This would only ever need to be done once for each impact, so there shouldn’t be much, if any, performance hit. But if what you’re saying is strictly true, then high performance algo or not, it simply can’t be done.

Maybe we should bug a dev to adjust the BGE API? Or do it ourselves? It could be useful for many things other than this.

We basically just need to be able to use the Boolean modifiers in BGE. I would assume it could also possibly be done with a geometry shader.

Well, a long time ago (2011 or 2012) i experimented with triggering boolean cuts from bge though, BUT… this involves calling the bpy API which has 4 disadvantages:

  1. It will require the full blender to run your game (not just the blender player)
  2. it will modify also the original geometry in the viewport (which would be dynamically reloaded then to have an effect in the BGE though).
  3. Failing boolean cuts will mess up your original geometry then as well and boolean isnt exactly the fastest algorithm (with complex geometry and / or many shards atleast, for simple geometry with smaller amounts it is acceptable)
  4. you might need instance based physics meshes for dynamic fracture (i once (2014) had a patch for it, but it wasnt accepted due to being too hacky) else you would need to preallocate individual objects in blender, whose meshes you could replace by the generated shards, as you have then only 1 instance of each object, you would have “individual” physics meshes this way.

So i just mention it here for completeness. Somebody should really wrap the boolean (or even the fracture modifier, a project of mine :slight_smile: ) inside some fracture actuator, working on some temporary intermediate mesh, which is dynamically reloaded OR directly with the BGE Meshes (think the latter might be harder)

Well, Charies_S, voxel isn’t always looking like a cubeworld. It just uses cubeworld calculations to improve performance of sandbox worlds. As far as I know, all worm series games use either 2D or 3D voxel based world. Yeah - voxels can blend nicely aswell as have non-cubic collision for rigid bodies.

@Vert shifting
This unfortunately isn’t applicable. Moving a vertex over and over again will only stretch the mesh, it won’t create new vertexes/edges/faces, and it can’t destroy them either. I need the system to allow creating a tunnel through a destructable object to the other side. If a vert was pushed to the other side of an object, it would simply clip through the face and keep going.

So so wrong :slight_smile:

I have a donor mesh at worldPosition.z = -10000, and by moving it’s vertices I can fake new geometry.
If something, like a block, is destroyed the vertices are moved back to z=-10000 and reused later if necessary.
If you run out of vertices, you spawn a new donor to help.
As the vertices(fake cubes) belong to one object (per chunk) it reduces draw calls to a minimum.

Now, if you had slope blocks:

you could do this:
http://i1041.photobucket.com/albums/b412/Lakmeer/Sculpt_02.png

I do have to ask though, is this a certain fact? Is it hard-coded into the blender game engine or something? Is there no way for the game engine to add mesh elements?

Not hard coded, lol. More like not coded, there is no such functionality.
What can be done, is using blender ( the modelling software part) trough a socket connection to remotely create meshes and then libload them in to the game.

Is it better to have it not hardcoded or hardcoded?

Well, a long time ago (2011 or 2012) i experimented with triggering boolean cuts from bge though, BUT… this involves calling the bpy API which has 4 disadvantages:

Yeah, I feared as much. I looked at the python in the tool tip for the Boolean modifiers, saw the bpy prefix, and realized that was going to have to be imported. Too bad :frowning:

… boolean isnt exactly the fastest algorithm (with complex geometry and / or many shards atleast, for simple geometry with smaller amounts it is acceptable)

The geometry doesn’t need to be all that complex it appears. I can get about the effect I’m looking for by making the “positive” object out of just 4 cubes superimposed within each-other. I place the positive on the surface, apply a Boolean difference modifier on the destroyable surface, and select the target as the positive mask. Other than maybe texturing, the results are quite workable.

Now that I’ve seen it in blender, I’m 80% sure this is what they are using in Redfaction’s Geomod, actually.

Here is an image…


And here is the blend… (though I think it borked)
Destruct.blend (4.05 MB)

… Somebody should really wrap the boolean (or even the fracture modifier, a project of mine :slight_smile: ) inside some fracture actuator, working on some temporary intermediate mesh, which is dynamically reloaded OR directly with the BGE Meshes (think the latter might be harder)

Agreed. I can easily work with the above, which uses the boolean.

Well, Charies_S, voxel isn’t always looking like a cubeworld. It just uses cubeworld calculations to improve performance of sandbox worlds. As far as I know, all worm series games use either 2D or 3D voxel based world. Yeah - voxels can blend nicely aswell as have non-cubic collision for rigid bodies.

Agreed, terraria doesn’t look bad. There was some 3D space RTS that did a very nice job too, name escapes me though.

It would be nice, but it sounds rather involved.

(1) Create or port a voxel framework into BGE.
(2) Create a blending method that makes it look and play nice in an arbitrary mesh environment.

The first thing is a project all on its own, and the second is trying to smash a square peg (voxels) into a round hole (mesh world)

Reviewing what I’m proposing, using boolean clipping is only a few basic operations. The realization may have performance problems, agreed, but the process appears simple, sans BGE support.

So so wrong :slight_smile: …[snip example]…

Fair enough, though maybe we are talking about different things?

Here is what happens when I tried sculpt with a strong subtract brush on a default cube subdivided twice…


Note that after the object had crushed enough for the insides to begin to touch, the verts begin to clip through and just keep on going. If this were done to, say, a wall between two rooms, it would never make a hole you could go through, it would just keep stretching and stretching. Also it tends to show the back side of faces, which is highly undesirable.

This is what I mean when I say moving verts in a mesh (by itself, mind you!) isn’t applicable.

I suspect you are talking about something else though.

…[snip]… I have a donor mesh at worldPosition.z = -10000, and by moving it’s vertices I can fake new geometry.
If something, like a block, is destroyed the vertices are moved back to z=-10000 and reused later if necessary.
If you run out of vertices, you spawn a new donor to help.
As the vertices(fake cubes) belong to one object (per chunk) it reduces draw calls to a minimum.

Think you could elaborate on that last bit some? Or maybe some code or something? Forgive me if this sounds like doubt, that’s not the case, I’m just having trouble understanding what you’re actually doing.

Are you talking about basically… you have a fabric/net mesh, that starts at z-10000, and is incrementally warped. Basically, somewhat how sculpt mode in blender modeling works?

Well to begin with, i don’t get what you are doing.
Blender and bge are two different things.
Why are you bringing up sculpting, when talking about Dynamic (in game) destruction?
You can’t sculp in game… Or use blender boolean modifiers…

The first thing blender sculpting meshes and bge meshes are different.
In blender, when you move a vertex or face, most of the time they are joined to other faces. When you move one, the neighbour faces deform also. Meaning stretching.

In bge, the faces are all split, moving one face, doesn’t affect other.

What I do is re-arrange the mesh faces.
Its the same when you get a lego castle, smash it pieces and re-use the pieces to build a tank.

z-=10 000 means that the unused faces are just out of view, till i take them “out of the lego box” to be visible.

Look at this, I can’t make it more obvious:

http://i.imgur.com/5DdMnQH.gif

The bottom object is the donor mesh.
The upper one is the faked object.

The donor mesh has about 3 cube worth of faces (3 * 6 = 18).
I can simulate any shape that has equal/less faces than 18.
If I need more faces, I spawn a bigger donor mesh or more donor meshes.

Normally you would hide the donor mesh from view as they are distracting.

import bge



cont = bge.logic.getCurrentController()
own = cont.owner


mesh        =   own.meshes[0]


matID       =   0  


mesh_length =   mesh.getVertexArrayLength(matID)


exampleLogicalCube = [
(-4.0, -4.0, 17.0) ,
(-4.0, 4.0, 17.0) ,
(-4.0, 4.0, 8.0) ,
(-4.0, -4.0, 8.0) ,
(-4.0, 4.0, 17.0) ,
(4.0, 4.0, 17.0) ,
(4.0, 4.0, 8.0) ,
(-4.0, 4.0, 8.0) ,
(4.0, 4.0, 17.0) ,
(4.0, -4.0, 17.0) ,
(4.0, -4.0, 8.0) ,
(4.0, 4.0, 8.0) ,
(4.0, -4.0, 17.0) ,
(-4.0, -4.0, 17.0) ,
(-4.0, -4.0, 8.0) ,
(4.0, -4.0, 8.0) ,
(-4.0, -4.0, 8.0) ,
(-4.0, 4.0, 8.0) ,
(4.0, 4.0, 8.0) ,
(4.0, -4.0, 8.0) ,
(4.0, -4.0, 17.0) ,
(4.0, 4.0, 17.0) ,
(-4.0, 4.0, 17.0) ,
(-4.0, -4.0, 17.0) 
]




if not "array_index" in own:
    own["array_index"] = 0
    
array_index = own["array_index"]




if own["array_index"] < mesh_length:
    own["array_index"] += 1
    
mesh_vert = mesh.getVertex(matID,array_index) 


newPos = exampleLogicalCube[array_index%24]
mesh_vert.setXYZ(newPos)    

Edit: extra gif
http://i.imgur.com/qBCypaI.gif

Well to begin with, i don’t get what you are doing.

Nothing wrong with that. We’ll hopefully get there.

The first picture in post #10 says it all.

The square-ish object would be some destructible material. All the holes in it are “craters” caused by “explosions.” The craters are added later at runtime from the extra geometry; the floating object seen on the mid right. -ALL- of the holes in that image were created from the floating object, they were done with the boolean modifier in BME (blender modeling engine).

My hope/presumption is that this could be done in BGE. Or more correctly, that BGE could handle doing it, if it were allowed.

But the end goal remains the same, missile hits object, craters in the mesh appear. Add enough craters and a hole appears. Add more craters still and the whole object would be gone.

Aside from the physic and texturing unknowns, and the fact that BGE maybe doesn’t have the right tools, I think its totally practical.

Blender and bge are two different things.

If by “different things” you meant they are “different engines” then… yes … I am aware of this.

Why are you bringing up sculpting, when talking about Dynamic (in game) destruction?

I was talking about the sculpting mechanic, not the BME implementation of it. I was expecting that this mechanic is what you were doing. I see by your latest post though that I was clearly mistaken. My bad.

The first thing blender sculpting meshes and bge meshes are different.
In blender, when you move a vertex or face, most of the time they are joined to other faces. When you move one, the neighbour faces deform also. Meaning stretching.

In bge, the faces are all split, moving one face, doesn’t affect other.

Oh!? I didn’t know this about BGE; it’s not a strict requirement of OpenGL. In fact, I believe it’s quite the opposite.

From what I remember, it’s standard OpenGL practice to load complex geometry into a vertex buffer object as a list of (shared) vertices. An example of a primitive operation that does this would be GL_TRIANGLE_STRIP, where each vertex will share a face with two others.

The behavior of such an object is exactly as it is for blender modeling; if you move a vertex, it pulls stuff with it.

I see by your demo though that this is not the case for BGE. I guess the API accessible side of the geometry is in a different state than you would normally expect it to be for OpenGL. Or more likely at a different stage.

@ Post #12
VERY interesting, and quite impressive. I do indeed like this a lot more than I was thinking I was going to.

For this, I would do what you’re doing in your animations, but in reverse.
(1) Start the object out as borrowed faces.
(2) When a collision is detected, move a vert.
< Branch >
(3a) Face shrank below a certain limit, remove it and merge edges.
(3b) Face expanded above a certain limit, replace it with two more, half the size.

The above process is a little naive, and it’s not as easy to manage as the other one. But it looks to have the advantage of already being doable in BGE. I don’t know about physics, but I honestly don’t know for sure how we would do physics for the boolean method either.

Edit: BTW, @Lostscience

Is it better to have it not hardcoded or hardcoded?

I don’t really know how exactly to respond to this.

There are pros and cons to both, but usually hardcoding anything is discouraged as it causes problems later on down the road… but it’s a full topic all on it’s own really.

Maybe ask on c-board or stack exchange if you really want a good answer?

Amazing work V_J

The donor mesh idea looks pretty good, but how would you handle making each one unique in cases where large numbers of them are needed, what about smooth shading and changing UV’s, different textures, conversion to a new physics object?

Truth be told, the BGE may have (by a decent margin) the weakest API of any free or low cost engine that is out there in terms of direct mesh manipulation and the creation of entirely new data (bpy doesn’t count as it will not work in executables). You have to really hack things together to get something that even resembles true, procedural, creation.

The BGE may simply not be the right engine for this, because even if you hack the system together, you still have to find a way to make it run at 60 FPS (and Python’s not the fastest language around).

That is what is great about the bge.Someone could possible come up with a new solution.I know you are going to say don’t hold my breath.But who knows i might be right.

Ugh, apologies for the great wall of text.

Okay, you seems to know you stuff and are just unfamiliar with this game engine.

Don’t give me too much credit. :slight_smile: Honestly, seeing the level of your effort was very discouraging for me; I feel pretty outclassed.

Physics can be updated, but it is a hasle. I think it was something along the lines " edit the hidden layer object and then addObject/replacemesh_with that"

Makes sense.

If it matters, my geometry for physics and the graphical representation are one in the same. I don’t have a separate simplified collision mesh, as the graphical mesh is very modest.

Also note that my game is 2.5D. All the physics objects are constrained to the same ZY plane (soon to be XY plane for other reasons). So far this has simplified many things, and promises to keep good performance. The background mesh doesn’t even have physics applied for example.

If you need your map to be fully random, you would have to build it in game first which takes time.You could also premake your map and keep a dictionary file of the fake objects initially present.

My terrain is actually prebaked from a height map + displacement modifier on a highly subdivided plane. I also have a low-polly version with a baked normal map. The latter kinda looks like crap; I’m planing on reworking it. Pretty conventional stuff though.

This terrain is totally static, and only determines aesthetics, major paths, and major obstacles for the game. The physics layer is just in front of this, and is effectively two dimensional.

My map making process is simple enough that I’m sure it could be easily automated. Doing it in just BGE, placing enemies/assets, and placing a matching low poly physics layer are problems though.

As for dictionary files, I have yet to play with them. I’ve been putting it off to focus on other aspects. Though I definitely need to figure it out soon as I want some game save and inventory functionality, of course.

I’ll listen to recommendations regarding this. It’s probably the very next thing I’m going to do.

You probably could smooth the terrain as said with slope blocks or, more fancy marching cube algo.

Speaking of marching cube algo, I’m actually thinking that, if I went the voxel route, the marching square algo would be sufficient for my game.

The only environment the player object can interact with is confined to one plane. If the collision mesh for the plane were made voxel like, there would never be a change in the data above and below a certain depth, as nothing the player does would ever reach. Knowing this, the collision mesh reduces to 2D, so the marching square algo would apply.

This would make for a more simple implementation, and higher performance… I might play with this.

Good luck

Thanks, you to.

The donor mesh idea looks pretty good, but how would you handle making each one unique in cases where large numbers of them are needed,

If you check out one of VJ’s demos in post #14, there are a whole bunch of identical planes on the visible layer. Looks like thousands and thousands. Also looks like VJ is culling a lot that’s not being seen, greatly reducing the number of donors he needs at one time.

[W]hat about smooth shading and changing UV’s, different textures, conversion to a new physics object?

Indeed. These are difficult problems that arise doing this, and big concerns for me as well.

To be fair, I don’t think my idea (or any other for that matter) is in any batter standing.

Truth be told, the BGE may have (by a decent margin) the weakest API of any free or low cost engine that is out there in terms of direct mesh manipulation and the creation of entirely new data (bpy doesn’t count as it will not work in executables). You have to really hack things together to get something that even resembles true, procedural, creation.

I’m starting to see this, and it’s really unfortunate. The wave of the future for video games is dynamic “sand box” environments. IMHO that is the thing that really sold Mincraft, not it’s “goofy but endearing blockyness” like a lot of people believe. It’s the fact that you could build/destroy anything that made it an instant hit. I’m not a big fan of Minecraft, but I feel no shame promoting this aspect of the game.

I think BGE suffers greatly by not having tools for this.

The BGE may simply not be the right engine for this, because even if you hack the system together, you still have to find a way to make it run at 60 FPS (and Python’s not the fastest language around).

Agreed for the most part.

That being said, both of VJ’s blends ran on my lesser dev computer at full 60 frames when everything was eventually loaded. That’s on a 3Ghz Phenom II x2 555 BE + 4GB RAM + Radeon HD3800 series card. I presume it to be a pretty decent baseline.

Even so, I’m rapidly coming more inline with the quoted viewpoint as time goes on.

I think a voxel terrain using a marching squares/cubes algo is pretty workable. The mutating donor geometry is also plausible. But I’m also thinking about the work/effort necessary (including talking in this thread) and it’s looking pretty prohibitive.

Just note that; even if I do ultimately give up on having this in my game, it’s still something that BGE should strive to acquire.

That is what is great about the bge.Someone could possible come up with a new solution.I know you are going to say don’t hold my breath.But who knows i might be right.

From what I’ve read, development on BGE has more or less stagnated. There was a lot of talk about making it more an integrated visualizer for game prototyping than an independent engine. There was even scare that it BGE was getting dropped altogether. It turned out to be more about lack of enthusiasm for continued development, and that there are no plans to remove it.

For the record, the inbuilt game engine is my sole interest in blender. If it was gone, I would leave with it. I feel this is probably true for a lot of people.

I’m starting to see this, and it’s really unfortunate. The wave of the future for video games is dynamic “sand box” environments. IMHO that is the thing that really sold Mincraft

The BGE would be able to do Minecraft if it had some optimizations like object batching, the entire game is basically placing and destroying block objects that have the exact same UVmap.

As for truly dynamic stuff (ie. direct mesh manipulation), all the BGE really has is a handful of functions to get the vertex, change its location, and change its color (but you don’t really have to deal with it so much with pre-made meshes).

Be careful, neigbouring face vertices aren’t always split by face

You can only change the vertex properties of a mesh object, not the mesh topology.
To use mesh objects effectively, you should know a bit about how the game engine handles them.

  • Mesh Objects are converted from Blender at scene load.
  • The Converter groups polygons by Material. This means they can be sent to the renderer efficiently. A material holds:
    [LIST=1]
  • The texture.
  • The Blender material.
  • The Tile properties
  • The face properties - (From the “Texture Face” panel)
  • Transparency & z sorting
  • Light layer
  • Polygon shape (triangle/quad)
  • Game Object
  • Verticies will be split by face if necessary. Verticies can only be shared between faces if:

  • They are at the same position

  • UV coordinates are the same

  • Their normals are the same (both polygons are “Set Smooth”)

  • They are the same colour

[/LIST]

Is Sort-based draw call bucketing possible in the blender game engine?

Such a thing would have to be developed as a new feature for the BGE (ie. written in C++), as the custom GLSL functions available to users do not include such low-level things as draw calls.