Series
Building on Voxel Terrain in Babylon.js
Build with blocks on the smooth voxel terrain: three sizes, painted materials, edges rounded and sloped with a chisel, and buildings that come apart when nothing holds them any more, falling as rigid bodies, landing as rubble, smashing what they hit and raising dust.
Ten parts that build on the smooth voxel terrain series. You put blocks on its hills and in its caves, in three sizes, painted in code and lit by the terrain's own light, and walk on them. A chisel rounds or slopes their edges, so the same blocks make pillars, domes, ramps and roofs. Then the blocks need something to hold them: break the last block that connects part of a building to the ground, and that part falls as one rigid body, with physics of our own, tumbles, lands as rubble you can climb and break up, smashes what it hits, and comes down with dust and a thud. Every part ends with a demo you can play right on the page, built from exactly the code it shows.
Quest line
- Part 1: Blocks on the TerrainPut blocks on the smooth voxel terrain: a grid of half-meter cells, blocks of three sizes that fill whole cells, one mesh per region with the hidden sides left out, and a tool that places and breaks them where you look.40 min
- Part 2: Painted Blocks and Their LightPaint six materials in code, from bricks to copper, and lay them on the blocks by their place in the world, so that walls read as one surface. A bar shows the materials, and blocks in caves get dark, from the light grids the workers already work out.40 min
- Part 3: Walking on BlocksMake the blocks solid for the player: the signed distance to a box, the nearest surface among the terrain and the blocks, a way out of a wall that leads into the open, and no blocks where the player stands.25 min
- Part 4: A Chisel for Rounded EdgesRound the edges of blocks with a chisel: twelve bits per block, a shape made of eight octants that are each a box, a quarter cylinder, two crossing cylinders or an eighth of a ball, its signed distance for walking, and a tool that lights up the edge, corner or side you aim at.45 min
- Part 5: Slopes and RoofsGive the chisel a second profile: an edge cut flat from side to side. A cube clipped by one plane per edge makes wedges, ridges, pyramids and hip corners; the player walks up them like ramps, and slate lies on a roof in level rows.40 min
- Part 6: What Holds a BlockDecide which blocks stand: a block holds while a chain of blocks touching by a side or an edge leads to one the ground holds. Search groups lowest block first after a break or a dig, show in orange what would fall with the block you aim at, and build a little scene to try it on.35 min
- Part 7: Falling PiecesLet loose groups fall as rigid bodies, with no physics engine: mass, middle and inertia from the blocks, a quaternion that turns, contacts at the corners of the cells against the terrain and the blocks, pushes that keep them out, friction that makes them stop, and rest when they lie still.50 min
- Part 8: RubbleTurn pieces at rest into rubble: solid for the player and for the pieces still falling, at any angle, not to build on, broken up block by block, falling apart into pieces where it splits, and falling again when what it lies on goes.35 min
- Part 9: Chain ReactionsLet falling pieces break the blocks they hit: note which block each contact touches and how fast it closes in, turn speed and weight into damage, give each material a strength, and let the support do the rest, so that one broken block can bring down a whole building.25 min
- Part 10: Dust and SoundGive the collapse weight: puffs of dust in the color of the material where pieces land and blocks break, and thuds, cracks and knocks made with the Web Audio API from noise and a falling tone, louder and deeper for heavier, harder hits, with no sound files.30 min