Skip to content

Instantly share code, notes, and snippets.

@ttvd
Created August 27, 2021 19:07
Show Gist options
  • Save ttvd/6bf721516f50d2dde344ce12bf0b263a to your computer and use it in GitHub Desktop.
Save ttvd/6bf721516f50d2dde344ce12bf0b263a to your computer and use it in GitHub Desktop.
red faction geomod
Howdy!
I wrote Red Faction''s Geomod engine...
It does a complete realtime subtractive boolean from the world Geometry. The "hole" that is cut out is a loaded mesh that gets randomly rotated to look different everytime. It could be any shape, we just liked how this one worked. It operates on a face basis, splitting some, deleting some, and adding in new ones. The input is a polygon mesh; the output is a polygon mesh.
The math to to the boolean takes place spread out over a few frames so that it doesn''t impact framerate much.
All of out structures in the game are dynamic to handle this... the code to actually make the whole is only a minor part of the problem. For instance, our AI paths can update to reflect the hole, the rooms and portals update so a hole between two rooms is now a portal, and the collision detection structures for the world use recursive AABB, which get dynamically updated during the Geomod. Even things like slapping bullet decals on the new faces and making sure to remove decals on faces that get Geomoded away is a mess.
The Geomod itself works on n-sided convex faces, and tesselates and splits all faces as needed. It is complex enough that it works on all input meshes, meaning it can do a lot more than punch a hole through a wall. Neither the input mesh or the geomod mesh need to be convex or even composed of just one primitive.
The Geomod code maintains all face adjacency and fixes any t-joints.
Once the Geomod has completed, the code does a search through adjacent faces and finds any chunks of the world that are separated from everything else (like a bridge that has been blasted on each end) and separates it into a new piece of geometry and either deletes it or adds physics to it, depending on the version of the engine we''re using. RF2 just deleted them, for framerate reasons.
As far as the world slowing down, it''s usually not a large problem... if you do a lot of Geomoding, the face count increases, then gets to a point where every Geomod tends to remove about as much geometry as it adds.
In RF2 we actually did a trick, where, if you Geomoded a lot and we started running low on memory, we would remove brushes that were Geomoded a lot a long time ago, rather than limiting the max number of Geomods, like we did in RF1.
John A. Slagel
Volition/THQ
PS: Here is an example of the faces created by RF2... if you used our Geomod and did four Geomods using cylinders against a 6-sided box, you''d get this:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment