Skip to content
Lab

Playable · WebGPU

Destruction

A street of stone, wood, metal and glass that you can blow holes in with rockets or chip at with a rifle. The buildings are plain meshes, and the engine cuts the damage out of them at runtime.

  • Destruction
  • Physics
  • CSG
Destruction, a screenshot

Play in browser · 30 MB

Keyboard and mouse recommended

How it works

Each building is built in code from CSG solids. When the street loads, the engine cuts every building into cells about two meters across, each with its own mesh and its own collider. There are no pre-fractured models, and nothing in the data says where a wall can break.

When a rocket hits, the blast is subtracted from only the cells it reaches. The geometry inside the blast radius is turned into shards, each a closed solid with its own cut faces and convex hull, and the crater is left in the wall. The cost of a hit depends on the size of the blast, not the size of the building, and the hundredth hit costs about as much as the first.

After each cut, what is left of the cells is split into its connected pieces. Pieces in neighboring cells hold each other up where their faces meet, and any group of them that no longer reaches the ground becomes a single dynamic rigid body. Shoot through the base of a chimney and the top falls on its own.

What a thing is made of decides how it breaks. Stone comes away in lumps, with dust and grit. The wooden house and the crates split into long splinters along the grain. The water tower’s metal tank loses a smaller hole and a few big plates that bounce, with sparks. A pane of glass breaks all at once, from a blast further away than it takes to break stone, and most of it is blown into the room. Its biggest shards fall as solid pieces, and the rest is thrown as a spray of slivers and glints. A pane whose wall has been shot away breaks too.

Press Q to swap the rocket launcher for a rifle. A round takes a bite a few centimeters across out of stone, wood or metal. In glass it draws a small hole, with cracks running out from it, into a texture of the pane’s own, and the pane stays in its frame. After about four rounds, or two or three close together, the next one breaks the whole pane, and its shards keep their cracks.

On a desktop the cuts run on other threads. The browser build has only one, so a cut runs about three milliseconds of its steps at the start of each frame instead of all at once, and the street keeps moving while it finishes. Shards that come to rest are merged into one pile for each patch of street, which a later blast or round can pick apart again, so a street full of rubble costs about as many draws as an untouched one. On a phone or tablet the demo keeps half as many shards.

More from the lab

All demos