Biomes and Vegetation on Voxel Terrain in Babylon.js · Part 12 of 12 in the series
Part 12: Felling trees
Give the player an axe. A tree that takes four blows leaves the forest and falls as a rigid body, smashes the blocks it hits, lands, sheds its leaves and lies as a solid log that the axe chops up. Trees whose ground is dug away fall too.
Biomes and Vegetation on Voxel Terrain in Babylon.jsPart 12 of 12
On this page
Quest objectives
- Aim at a trunk with a ray against cylinders, without picking meshes
- Take single trees out of a forest that a rule plants
- Build a rigid body for a tree from its trunk and its crown
- Draw only the wood of a tree by drawing fewer indices
- Make a lying log solid, and chop it up
- Fell the trees whose ground is dug away
The forest stands, sways and reaches the horizon, and nothing you do changes it. This last part gives you an axe. Four blows fell a tree: it tips over away from you, falls as a rigid body, the same kind that the walls of the building series fall as, breaks the blocks it lands on, sheds its leaves and lies as a log. The log is solid, you can stand on it, and the axe chops it up. And a tree needs ground: dig it away, and the tree comes down too.
Wood and leaves apart
A log is a tree without leaves. There is no need for a second mesh for it: meshTree() makes all the tubes first and all the cards after them, so the first indices of the mesh are the wood and the rest are the leaves. A mesh that is drawn with only the first so many of its indices is the bare tree of part 7. The model has to remember where the wood ends. In src/trees.ts, TreeModel gets a field, and meshTree() notes the count just before it makes the sprays:
/** How many of the mesh's indices are its wood: they come first, the leaves after them. */
wood: number;
const wood = indices.length;In the object that meshTree() returns, add wood, before girth.
Trees that are gone
The forest doesn't keep a list of trees that could have one taken out. Its trees come from a rule: a tile that is dropped and planted again comes back with every tree the rule gives it. So felling can't delete anything. Instead, the forest keeps a list of the trees that are gone, and leaves those out wherever it deals with trees.
For that a tree needs a name that is the same every time its tile is planted. The rule of part 9 allows one tree per cell of 6 m, so the cell a tree stands in names it, and the cell follows from the tree's place: the worker doesn't have to send anything new. In src/forest.ts, import TREE_CELL from ./treeRule.ts too, and add after tileKey:
/** A tree that stands: its numbers from the list, and a key that no other tree has. */
export interface StandingTree {
x: number;
y: number;
z: number;
size: number;
turn: number;
model: number;
key: number;
}
/** A tree's key: the number of its cell, which holds no other tree. */
const keyOf = (x: number, z: number) => (Math.floor(x / TREE_CELL) + 32768) * 65536 + Math.floor(z / TREE_CELL) + 32768;
function standing(trees: Float32Array, t: number): StandingTree {
return { x: trees[t], y: trees[t + 1], z: trees[t + 2], size: trees[t + 3], turn: trees[t + 4], model: trees[t + 6], key: keyOf(trees[t], trees[t + 2]) };
}StandingTree is a tree as the rest of the game sees it: a row of the tile's list, with names for its numbers. The class Forest gets the list of the felled, as a field: private readonly gone = new Set<number>();. The cards of part 10 can leave trees out already. Replace card():
/** Makes a tile's cards, anew if it had some. */
private card(tile: Tile): void {
tile.cards?.dispose();
tile.cards = null;
const { trees } = tile;
if (!trees || !this.cardMaterial) return;
tile.cards = createCards(this.scene, trees, this.models, this.cardMaterial, (t) => this.gone.has(keyOf(trees[t], trees[t + 2])));
}After it, add three methods:
/** Takes a tree out of the forest: it is drawn no more, and its trunk is not solid. */
fell(tree: StandingTree): void {
this.gone.add(tree.key);
this.sorted = null;
const tile = this.tiles.get(tileKey(Math.floor(tree.x / TILE), Math.floor(tree.z / TILE)));
if (tile) this.card(tile);
}
/** The trees that stand around a point, within `reach` meters along the ground. */
around(x: number, z: number, reach: number): StandingTree[] {
const found: StandingTree[] = [];
for (let cellZ = z - reach; cellZ < z + reach + GRID; cellZ += GRID) {
for (let cellX = x - reach; cellX < x + reach + GRID; cellX += GRID) {
const tile = this.tiles.get(tileKey(Math.floor(cellX / TILE), Math.floor(cellZ / TILE)));
if (!tile?.trees) continue;
const { trees } = tile;
tile.grid ??= gridOf(trees);
for (const t of tile.grid.get(gridKey(cellX, cellZ)) ?? []) {
if (Math.hypot(trees[t] - x, trees[t + 2] - z) <= reach && !this.gone.has(keyOf(trees[t], trees[t + 2]))) found.push(standing(trees, t));
}
}
}
return found;
}
/** The tree whose trunk a ray hits first, and how far along the ray. */
pick(origin: Vector3, direction: Vector3, reach: number): { tree: StandingTree; distance: number } | null {
let nearest: { tree: StandingTree; distance: number } | null = null;
for (const tree of this.around(origin.x, origin.z, reach + 1)) {
const model = this.models[tree.model];
const radius = model.girth * tree.size;
// Seen from above, the trunk is a circle and the ray a line: where the line enters the circle.
const [dx, dz] = [direction.x, direction.z];
const [ox, oz] = [origin.x - tree.x, origin.z - tree.z];
const a = dx * dx + dz * dz;
const b = ox * dx + oz * dz;
const inside = b * b - a * (ox * ox + oz * oz - radius * radius);
if (a === 0 || inside < 0) continue;
const distance = (-b - Math.sqrt(inside)) / a;
// And there the ray has to be at the trunk's height.
const height = origin.y + direction.y * distance - tree.y;
if (distance < 0 || distance > reach || height < 0 || height > model.height * tree.size * TRUNK) continue;
if (!nearest || distance < nearest.distance) nearest = { tree, distance };
}
return nearest;
}fell()puts a tree on the list, has the meshes sorted out again at the next update, and makes the cards of the tree's tile anew, without the tree.around()finds the trees near a point, through the grid that part 9 built for the trunks. Digging and aiming both ask it.pick()finds the trunk a ray hits. Babylon.js can't do that: it picks meshes, and the forest has one mesh per model, drawn in a thousand places that only the graphics card knows. But a trunk is a standing cylinder, and a ray against a cylinder is school geometry. Seen from above, the trunk is a circle and the ray a line. Where the line enters the circle is the smaller solution of a quadratic equation, and if the ray is between the tree's foot and its crown at that distance, it hits the trunk.
Two places are left that deal with trees. In sort(), after the line that skips trees out of range, and in nearest(), after the line that checks the height, add: if (this.gone.has(keyOf(trees[t], trees[t + 2]))) continue;. A felled tree is not drawn any more, and its trunk is not solid.
A falling tree
What falls is a Body, the rigid body of part 7 of the building series. It wants two things: parts, each with a mass, a middle and an inertia, and points to touch the world with. For a piece of wall those came from its blocks. For a tree they come from its measures:
The trunk is cut into six slices. Each is a part, as heavy as a cylinder of green wood of its size, and each has four points around its lower end. Six small parts in a row have nearly the inertia of one long rod, which is what makes the tree hard to turn about its foot and easy to spin about its trunk.
The crown is one more part: light, three tenths of the trunk's weight, but far up. Six points around it, well inside its reach, keep the tree from lying flat on its trunk: it comes to rest on its limbs, as trees do.
The body's own frame has its origin at the tree's foot, with the trunk straight up. To make the tree tip over, the body starts with a spin about the level axis that lies across the way it should fall. The points around its foot grip the ground by friction, the trunk turns over them, and once the tree's weight is past its foot, gravity does the rest. Create src/felled.ts:
import { Quaternion, TransformNode, Vector3, type Buffer, type Mesh, type Scene, type ShaderMaterial } from '@babylonjs/core/pure';
import type { Block } from './blocks.ts';
import { Body, type BodyPart } from './body.ts';
import { instanceBuffer } from './chunkPlants.ts';
import type { StandingTree } from './forest.ts';
import type { Solid, Solids, Surface } from './solids.ts';
import { createTreeMesh } from './treeMaterial.ts';
import type { TreeModel } from './trees.ts';
/** Kilograms per cubic meter of green wood. */
const WOOD = 700;
/** The trunk counts as this many parts of the body, and has a ring of points at the end of each. */
const PARTS = 6;
/** How fast a felled tree starts to tip over, in radians per second. */
const TIP = 0.6;
/** Below this height, a falling tree is gone for good. */
const BOTTOM = -500;
/**
* A felled tree: a rigid body with the tree's mesh. While it falls it is a tree; once it
* lies still it sheds its leaves and is a log, solid like a trunk that stands.
*/
export class FelledTree implements Solid {
readonly body: Body;
readonly model: TreeModel;
/** The trunk in the body's own frame: from the foot at (0, 0, 0) straight up, this long and thick. */
readonly length: number;
readonly radius: number;
isLog = false;
private readonly node: TransformNode;
private readonly mesh: Mesh;
private readonly buffer: Buffer;
constructor(scene: Scene, material: ShaderMaterial, model: TreeModel, tree: StandingTree, toward: Vector3) {
this.model = model;
const height = model.height * tree.size;
this.length = height * (model.species.leader ? 0.95 : 0.7);
this.radius = model.girth * tree.size * 0.75;
// The trunk in slices, each a part with its weight, and four points around the end
// of each to touch the world with. The crown is a part too: light, but far up.
const parts: BodyPart[] = [];
const points: Vector3[] = [];
const slice = this.length / PARTS;
for (let p = 0; p < PARTS; p += 1) {
const mass = WOOD * Math.PI * this.radius ** 2 * slice;
const inertia = (mass * slice * slice) / 6;
parts.push({ mass, center: new Vector3(0, (p + 0.5) * slice, 0), inertia: [inertia, 0, 0, 0, inertia, 0, 0, 0, inertia] });
for (const [x, z] of [[1, 0], [0, 1], [-1, 0], [0, -1]]) points.push(new Vector3(x * this.radius, p * slice, z * this.radius));
}
if (model.species.leaves) {
const crown = height * (model.species.bare + 1) * 0.5;
const reach = model.reach * tree.size * 0.6;
const mass = parts.length * parts[0].mass * 0.3;
const inertia = mass * reach * reach * 0.4;
parts.push({ mass, center: new Vector3(0, crown, 0), inertia: [inertia, 0, 0, 0, inertia, 0, 0, 0, inertia] });
// The crown touches the world with six points: it keeps the tree from lying flat.
for (const [x, y, z] of [[1, 0, 0], [-1, 0, 0], [0, 0, 1], [0, 0, -1], [0, 1, 0], [0, -0.6, 0]]) {
points.push(new Vector3(x * reach, crown + y * reach, z * reach));
}
}
this.body = new Body(parts, points);
// The body's own frame has its origin at the tree's foot.
this.body.position.addInPlace(new Vector3(tree.x, tree.y, tree.z));
// It tips over about the axis that lies across the way it falls.
this.body.spin.copyFrom(Vector3.Cross(Vector3.Up(), toward).scaleInPlace(TIP));
// The tree's own mesh, once: turned and sized as the tree was, at the origin of a
// node that follows the body, as the pieces of part 7 of the building series do.
this.mesh = createTreeMesh(scene, model, material);
this.buffer = instanceBuffer(this.mesh, new Float32Array([0, 0, 0, tree.size, tree.turn, 0, 0, tree.x * 0.37]));
this.node = new TransformNode('felled tree', scene);
this.mesh.parent = this.node;
this.mesh.position = this.body.center.negate();
this.node.rotationQuaternion = Quaternion.Identity();
this.follow();
}
/** Puts the node where the body is. */
follow(): void {
this.node.position.copyFrom(this.body.position);
this.node.rotationQuaternion!.copyFrom(this.body.orientation);
}
/** At rest it sheds its leaves: only the wood is drawn from now on. */
rest(): void {
this.isLog = true;
this.mesh.subMeshes[0].indexCount = this.model.wood;
}
/** A point of the world in the body's own frame. */
toLocal(point: Vector3): Vector3 {
return point.subtract(this.body.position).applyRotationQuaternion(this.body.orientation.conjugate()).addInPlace(this.body.center);
}
/** The nearest point of the trunk's surface to a point of the world, if within reach: the trunk is a rod with round ends. */
nearest(x: number, y: number, z: number, reach: number): Surface | null {
const point = new Vector3(x, y, z);
if (Vector3.Distance(point, this.body.position) > this.length + reach) return null;
const local = this.toLocal(point);
const onAxis = new Vector3(0, Math.min(Math.max(local.y, 0), this.length), 0);
const out = local.subtract(onAxis);
const distance = out.length() - this.radius;
if (distance >= reach) return null;
const normal = out.normalize().applyRotationQuaternion(this.body.orientation);
return { distance, normal: normal.asArray() as Surface['normal'] };
}
/** How far along a ray the trunk is hit, or null if the ray misses it. */
hit(origin: Vector3, direction: Vector3, reach: number): number | null {
for (let distance = 0; distance <= reach; distance += 0.1) {
const point = origin.add(direction.scale(distance));
if (this.nearest(point.x, point.y, point.z, 0.2)) return distance;
}
return null;
}
dispose(): void {
this.node.dispose();
this.buffer.dispose();
}
}
/** The trees that were felled: falling, or lying as logs. */
export class FelledTrees {
readonly all: FelledTree[] = [];
/** The logs, as of the last update: they are solid. */
logs: FelledTree[] = [];
/** Called with every block a falling tree hit, how fast, and the tree's mass. */
onHit: (block: Block, speed: number, mass: number) => void = () => {};
/** Called when a falling tree hits something hard: where, and how fast. */
onImpact: (point: Vector3, speed: number, tree: FelledTree) => void = () => {};
/** Called when a tree comes to rest and sheds its leaves. */
onRest: (tree: FelledTree) => void = () => {};
private readonly scene: Scene;
private readonly material: ShaderMaterial;
private readonly models: TreeModel[];
private readonly solids: Solids;
constructor(scene: Scene, material: ShaderMaterial, models: TreeModel[], solids: Solids) {
this.scene = scene;
this.material = material;
this.models = models;
this.solids = solids;
}
/** A tree that stood starts to fall `toward` a direction along the ground. */
fell(tree: StandingTree, toward: Vector3): void {
this.all.push(new FelledTree(this.scene, this.material, this.models[tree.model], tree, toward));
}
/** The log a ray hits first, and how far along the ray. */
pick(origin: Vector3, direction: Vector3, reach: number): { log: FelledTree; distance: number } | null {
let nearest: { log: FelledTree; distance: number } | null = null;
for (const log of this.logs) {
const distance = log.hit(origin, direction, reach);
if (distance !== null && (!nearest || distance < nearest.distance)) nearest = { log, distance };
}
return nearest;
}
/** Takes a log away. */
remove(tree: FelledTree): void {
tree.dispose();
this.all.splice(this.all.indexOf(tree), 1);
this.logs = this.logs.filter((other) => other !== tree);
}
/** Sets the logs near a box of the world rolling again: the ground under them may be gone. */
wakeNear(low: Vector3, high: Vector3): void {
for (const log of this.logs) {
const nearest = Vector3.Clamp(log.body.position, low, high);
if (Vector3.Distance(log.body.position, nearest) <= log.length) log.body.wake();
}
}
/** Once a frame: moves the trees that fall. */
update(dt: number): void {
for (const tree of [...this.all]) {
if (tree.body.resting) continue;
tree.body.update(dt, this.solids);
for (const [block, speed] of tree.body.hits) this.onHit(block, speed, tree.body.mass);
tree.body.hits.clear();
if (tree.body.impact) this.onImpact(tree.body.impact.point, tree.body.impact.speed, tree);
tree.body.impact = null;
tree.follow();
if (tree.body.resting && !tree.isLog) {
tree.rest();
this.onRest(tree);
}
if (tree.body.position.y < BOTTOM) this.remove(tree);
}
this.logs = this.all.filter((tree) => tree.body.resting);
}
}The mesh is the model's, made once more, with a single instance at the origin that has the tree's size and turn. It hangs under a node that follows the body, as a
Piecedoes. The trees' shader multiplies withworld, which was the identity until now: here it is the node's matrix, and the tree turns over with it.rest()makes the tree a log: it sets the number of indices that the mesh's only submesh draws to the model'swood.nearest()is the solid's question, for a log. In the body's frame the trunk is a straight rod with round ends: the nearest point of its axis, and from there out by the radius. The limbs are not solid. That is a simplification you can feel if you look for it, and it keeps the question cheap.hit()walks along a ray in steps of 10 cm and asksnearest(). The axe's reach is short, so that is a few dozen questions.FelledTreesis to felled trees whatPiecesis to pieces: it moves the bodies, hands on what they hit, turns trees at rest into logs, and wakes logs when the ground near them changes.
A felled tree is drawn by the trees' material, with its range: further than 95 m from the camera it is not drawn, and it has no card. That fits a game in which you fell trees where you stand.
The axe
The axe is the fourth tool. Each frame it works out what it is aimed at: the nearest trunk or log within its reach, unless the ground or a block is in the way, which the scene's own ray tells. A click is kept until the next frame, as the other tools do it. A blow on a tree counts up; the fourth fells it, away from the camera. A blow on a log chops it up. Create src/axe.ts:
import type { Camera, Scene, Vector3 } from '@babylonjs/core/pure';
import type { FelledTree, FelledTrees } from './felled.ts';
import type { Forest, StandingTree } from './forest.ts';
/** How far the axe reaches, in meters. */
const REACH = 4.5;
/** Blows a tree takes before it falls. */
const BLOWS = 4;
/** Fells the tree the camera looks at, blow by blow, and chops up logs. */
export class AxeTool {
/** What the axe is aimed at: a tree that stands, a log, or nothing. */
target: { tree: StandingTree } | { log: FelledTree } | null = null;
/** Blows the tree in aim still takes. */
left = BLOWS;
/** How many logs were chopped up. */
logs = 0;
/** Called with every blow, and where it lands. */
onBlow: (point: Vector3) => void = () => {};
/** Called when a tree falls, with the way it falls, and when a log is chopped up. */
onFell: (tree: StandingTree, toward: Vector3) => void = () => {};
onChop: (log: FelledTree) => void = () => {};
private swing = false;
/** The blows each tree has taken so far, by its key. */
private readonly blows = new Map<number, number>();
private readonly scene: Scene;
private readonly camera: Camera;
private readonly forest: Forest;
private readonly felled: FelledTrees;
constructor(scene: Scene, camera: Camera, forest: Forest, felled: FelledTrees) {
this.scene = scene;
this.camera = camera;
this.forest = forest;
this.felled = felled;
}
/** A click: the next update swings the axe. */
start(): void {
this.swing = true;
}
hide(): void {
this.target = null;
this.swing = false;
}
update(): void {
// What the camera looks at first: a trunk, a log, or the ground and the blocks in front of them.
const ray = this.camera.getForwardRay(REACH);
const solid = this.scene.pickWithRay(ray)?.distance || Infinity;
const tree = this.forest.pick(ray.origin, ray.direction, REACH);
const log = this.felled.pick(ray.origin, ray.direction, REACH);
const nearest = Math.min(tree?.distance ?? Infinity, log?.distance ?? Infinity);
this.target = nearest > solid ? null : tree && tree.distance === nearest ? { tree: tree.tree } : log ? { log: log.log } : null;
const swing = this.swing;
this.swing = false;
if (!this.target) return;
if ('tree' in this.target) this.left = BLOWS - (this.blows.get(this.target.tree.key) ?? 0);
if (!swing) return;
this.onBlow(ray.origin.add(ray.direction.scale(nearest)));
if ('log' in this.target) {
this.logs += 1;
this.onChop(this.target.log);
this.felled.remove(this.target.log);
return;
}
const { tree: standing } = this.target;
const blows = (this.blows.get(standing.key) ?? 0) + 1;
this.blows.set(standing.key, blows);
if (blows < BLOWS) return;
// It falls away from the one who felled it.
this.blows.delete(standing.key);
const toward = ray.direction.clone();
toward.y = 0;
this.forest.fell(standing);
this.onFell(standing, toward.normalize());
}
}The tool only decides. What a blow sounds like and what happens to a felled tree is told to it from outside, through onBlow, onFell and onChop.
Putting it together
In src/main.ts, import AxeTool from ./axe.ts and FelledTrees from ./felled.ts. The felled trees are made right after the pieces, and their logs join the solids. Replace the assignment to solids.others:
// Felled trees fall as bodies of their own, and are solid once they lie as logs.
const felled = new FelledTrees(scene, treeMaterial, treeModels, solids);
solids.others = function* () {
yield* pieces.rubble;
yield forest;
yield* felled.logs;
};A tree that falls onto something built should do to it what a falling wall does: the damage of part 9 of the building series takes a speed and a mass, and doesn't care what they belong to. Replace the block that makes the damage and sets pieces.onHit:
// Falling pieces and falling trees break the blocks they hit hard enough, which may let more fall.
const damage = new Damage();
let broken = 0;
pieces.onHit = felled.onHit = (block, speed, mass) => {
if (!damage.hit(block, speed, mass)) return;
blocks.store.remove(block);
crumble(middleOf(block), block, 0.8);
broken += 1;
};
// A tree lands with a thud and a puff of the ground's dust, and sheds its leaves when it lies still.
const LEAF_GREEN = '#5c8f33';
felled.onImpact = (point, speed, tree) => {
const strength = Math.min((speed - 2) / 8, 1);
dust.puff(point, '#8a7250', strength * 0.6);
sounds.thud(point, strength, Math.min(Math.max(110 / Math.cbrt(tree.body.mass / 1000), 40), 140));
};
felled.onRest = (tree) => {
if (!tree.model.species.leaves) return;
const crown = tree.body.toWorld(new Vector3(0, tree.length, 0));
dust.puff(crown, LEAF_GREEN, 1);
sounds.crack(crown, 0.5);
};A landing tree thuds, deeper the heavier it is, and raises the ground's dust. When it lies still and its leaves go, a green puff at its top and a crack cover the moment.
Digging takes a tree's ground away. After every edit, the trees around the edit's box are asked whether their foot is still in the ground: the density a little above the foot is below 0 if it is not. Such a tree falls the way it happens to be turned. Replace world.onEdit:
world.onEdit = (box) => {
field.forget();
support.groundChanged(box);
const [low, high] = [Vector3.FromArray(box.low), Vector3.FromArray(box.high)];
pieces.wakeNear(low, high);
felled.wakeNear(low, high);
// A tree whose foot is in the air now has lost its ground, and falls.
const middle = Vector3.Center(low, high);
for (const tree of forest.around(middle.x, middle.z, Vector3.Distance(low, high) / 2)) {
if (field.probe(tree.x, tree.y + 0.3, tree.z).density >= 0) continue;
forest.fell(tree);
felled.fell(tree, new Vector3(Math.cos(tree.turn), 0, Math.sin(tree.turn)));
}
};The logs are woken there too: a log over a hole rolls into it. Now the tool itself. Replace the line that declares tool:
// And a fourth: the axe fells trees and chops up the logs they leave.
const axeTool = new AxeTool(scene, camera, forest, felled);
axeTool.onBlow = (point) => {
dust.puff(point, '#b98a52', 0.15);
sounds.knock(point, 320);
};
axeTool.onFell = (tree, toward) => {
felled.fell(tree, toward);
sounds.crack(new Vector3(tree.x, tree.y + 1, tree.z), 1);
};
axeTool.onChop = (log) => dust.puff(log.body.position, '#b98a52', 0.8);
let tool: 'terrain' | 'blocks' | 'chisel' | 'axe' = 'blocks';The axe only has a left button. Replace the listener for pointerdown:
canvas.addEventListener('pointerdown', (event) => {
sounds.start();
if (document.pointerLockElement !== canvas) {
canvas.requestPointerLock();
return;
}
if (tool === 'terrain') {
if (event.button === 0) digTool.start('dig');
if (event.button === 2) digTool.start('build');
} else if (tool === 'blocks') {
if (event.button === 0) blockTool.start('break');
if (event.button === 2) blockTool.start('place');
} else if (tool === 'chisel') {
if (event.button === 0) chiselTool.start('cut');
if (event.button === 2) chiselTool.start('sharpen');
} else if (event.button === 0) {
axeTool.start();
}
});In the listener for keydown, add the key: if (event.code === 'KeyX') tool = 'axe';. In the frame's function, after the two lines of the chisel, add:
if (tool === 'axe') axeTool.update();
else axeTool.hide();And after pieces.update(dt);, add felled.update(dt);. The HUD gets a line for the axe, in toolLine, after the chisel's:
axe:
`Axe: ${axeTool.logs} logs chopped` +
(axeTool.target && 'tree' in axeTool.target
? `\n${treeModels[axeTool.target.tree.model].species.name}: ${axeTool.left} more blows`
: axeTool.target
? '\nA log: left click chops it up'
: ''),The help line names the new key. Replace index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel biomes</title>
</head>
<body>
<canvas id="game"></canvas>
<div id="crosshair"></div>
<div id="hud"></div>
<div id="bar"></div>
<div id="help">
Click to look around · WASD walk, Shift run, Space jump · F fly (Q/E down/up) · B blocks:
left break, right place, wheel or 1–6 material, , . size · C chisel: left cut, right sharp, R round or slope ·
T terrain: left dig, right build, wheel size · X axe: left chop · M mesher · G map of the biomes · N fly to the next biome
</div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>Try it
Press X, walk up to one of the oaks on the meadow and look at its trunk: the HUD names the tree and counts the blows it still takes. Left-click four times. The tree tips away from you, comes down, and a moment after it lies still its leaves are gone. Climb onto the log, then chop it up. Press B and build a wall next to a tree, then fell the tree onto it. Press T and dig the ground away under another one. And press N for the conifer forest, where a spruce that falls has other trunks in its way.
Where to go from here
That is the series. Over twelve parts the terrain of the two earlier series got a climate and six biomes with their own ground and their own shapes, a sea with shores, grass and small plants that grow by rules and make way for what you dig and build, trees grown from a handful of numbers, forests that reach the horizon, wind, and an axe. Everything is still made in code, and all of it follows from a seed.
Some things it leaves for you. Felled trees could grow back, as saplings whose size rises with time. The species could turn with seasons: the tint that every tree carries and no shader reads yet is waiting for autumn. More species and more kinds of small plants are rows in two tables. And the water stands where the land was made low: water that flows into what you dig is a series of its own.
Comments
The comments are GitHub Discussions: sign in with GitHub to write one.
The comments come from GitHub, through giscus. Loading them sends your IP address to giscus.app and GitHub.
