Skip to main content

Jet Game Engine: Simple Destructible Meshes

I've been meaning for a while to mess around with destructible meshes (they're way cool!). Making physically accurate destructible meshes is hard. Instead, I've opted for a simple scheme that still has great visual results for compact objects. The technique works like this:
  1. Choose a plane to split the mesh along.
  2. Create two new meshes to hold the fragments.
  3. For each triangle in the mesh: if the triangle is entirely above the plane, add it to the first mesh.  Otherwise, add it to the second mesh.
  4. Create a new scene node/rigid body for each of the fragments.
I added some optimizations as well.  To begin, you don't have to copy the triangle data for both fragments. They share the exact same mesh data, just different halves of it.  Instead, I create a new index buffer for each fragment and then re-use the same vertex buffer. This works really well and is relatively light on the video memory. Another thing I did is to re-use the original destructible mesh object. Thus, for each fracture, only one new destructible mesh object is created.

Obviously, this technique has limitations.  You can't break a mesh into more than two pieces at once, and the hole created by the split is a) not closed and b) pretty jagged.  Jagged edges around the split is OK for wreckage.  An open mesh also looks OK, as long as both the fronts and backs of triangles are rendered (i.e., turn off back-face culling).  I have considered writing some code that will close the hole in the mesh by creating new vertices to cover the hole.  However, this modifies the triangle buffer, which might not be good for performance.

I'm sure someone else has thought of it before.  It's a pretty simple technique, but it still looks decent!


Popular posts from this blog

Lua-Style Coroutines in C++

Lua's implementation of coroutines is one of my all-time favorite features of the language. This (short) paper explains the whole reasoning behind the Lua's coroutine implementation and also a little about the history of coroutines. Sadly, coroutines are not supported out-of-the box by many modern languages, C++ included. Which brings me to the subject of this post: Lua-style coroutines in C++! For those who don't know (or were too lazy to read the paper!), Lua's coroutines support three basic operations: Create: Create a new coroutine object Resume: Run a coroutine until it yields or returns Yield: Suspend execution and return to the caller To implement these three operations, I'll use a great header file: ucontext.h. #include <vector> #include <ucontext.h> class Coroutine { public: typedef void (*Function)(void); Coroutine(Function function); void resume(); static void yield(); private: ucontext_t context_; std

Password Generator for Chrome

This week, I finally got fed up with typing in/managing passwords on a billion different sites. Since things like OpenID haven't really taken off, I decided to take matters into my own hands...and write a password generator extension for Google Chrome. There are actually a ton of such apps on the Chrome web store, but I'm paranoid about security, so I wrote my own and open-sourced it. By virtue of being open source, perhaps people will trust my version a bit more. Anyway, the extension is available here , and the source code is hosted at github . May all your online transactions be secure! UPDATE: Fixed github link.

Sparse Voxel Octrees

Terrain implementation for games is a subject with a lot of depth. At the surface, it's very easy to get rudimentary terrain working via a noise function and fixed triangle grid. As you add more features, though, the complexity builds quickly. Overhangs, caves Multiple materials Destructive terrain Collision detection Persistence Dynamic loading Regions, biomes Very large scale Smooth features Sharp features Dynamic level of detail Extremely long view distances In isolation, each of these features can make terrain difficult to implement. Taken together, it takes a lot of care and attention to make it all work. Minecraft is probably the canonical example for terrain generation in the last generation of games. In fact, I'd say Minecraft's terrain is the killer feature that makes the game so great. Minecraft does an excellent job at 1-8, but for a recent planetary renderer project I was working on, I really wanted 9-12 too. In a series of articles, I'm planning to break do