Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(society): the island gets its game - real waves, six more biomes, the mine, and the lights

rubenluetke10-beep4d94406a71c1
diff --git a/docs/agent-society/world-art-direction.md b/docs/agent-society/world-art-direction.md
index f046d94ce8..dfe9d62cfb 100644
--- a/docs/agent-society/world-art-direction.md
+++ b/docs/agent-society/world-art-direction.md
@@ -48,6 +48,12 @@ W dark FOREST (workshop)—[ MARKET PLATEAU ]—(lighthouse on the rocky CAPE)
S harbor BAY, dock, breakwater
```
+**Biomes, as tile kinds:** sand · grass · meadow · forest · alpine · heath (heather drifts over
+the high moor) · dry (savanna on the eastern lowland) · farm (crop rows, south-west) · marsh
+(pools and reeds on the south-western coast) · scree (gravel on the mountain's flanks) · rock ·
+snow · quarry (the mine's forecourt). Plain grass is kept to the village plateau and the
+lowland around it; everything further out belongs to a named biome.
+
**Terrain:** a continuous height field (`islandLayout.heightAt`) — a radial fall-off plus one
designed bump or dip per biome (`REGIONS`) plus a little noise — quantised into ten levels
(`LEVEL_Y`, 0.35 m at the beach to 12.6 m at the peak). Every slope becomes a terrace, every
@@ -90,10 +96,20 @@ harbor and the gardens low at 2, the solar field on the mountain's foot terrace
| — | lighthouse (east cape, on the rock) | striped tower with rotating lamp, keeper's hut |
| — | gardens (south-east, the cove's low terrace) | six glass greenhouses on garden tiles |
| — | solar field (north-west, the mountain's foot terrace) | 35 tilted panels on posts |
+| — | the mine (the mountain's south-eastern flank, off the north road) | timber portal in a cliff, lanterns, rails, ore cart, headframe, foreman's hut |
Idle agents (`idle`) wander inside the square with the rest-biased model (`wander.ts`);
paused agents stand still.
+**Light and life:** lamps along the spokes, around the square's rim, along the ring road, the
+dock and the mine's road — every lamp throws an additive pool of light on the ground; festoon
+strings over the square from eight poles; the lighthouse's two sweeping beams; lanterns on the
+mine's portal; a campfire on the cove's beach; lights on the buoys; the hub's halo beacon.
+
+**Sea:** a subdivided plane with real waves — three swells plus breakers that build as the
+bottom rises (from the shore-distance field), lit by the sun with a glint, whitecaps on the
+crests, a breathing foam line, and a wash sheet that runs up the beach and drains back.
+
**Vegetation per biome** (`treeChoice`): round trees on grass and meadow (dense and taller in the
forest), pines on the alpine meadows and the high slopes, palms on the cove's sand — thickest
around the lagoon; boulders on the high ground, at the foot of cliffs and on the beaches.
diff --git a/jarvis/ui/web/frontend/src/components/society/world/Landmarks.tsx b/jarvis/ui/web/frontend/src/components/society/world/Landmarks.tsx
index 4403497a9b..53ae57680b 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/Landmarks.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/world/Landmarks.tsx
@@ -100,7 +100,9 @@ function Harbor({ kit, paused }: { kit: Kit; paused: boolean }) {
[-14, 48],
[4, 58],
].map(([bx, bz]) => (
- <mesh key={`${bx},${bz}`} geometry={kit.g.sphere} material={kit.m.lit(PAL.buoy)} position={[bx, 0.25, bz]} scale={[1.1, 1.3, 1.1]} />
+ <mesh key={`${bx},${bz}`} geometry={kit.g.sphere} material={kit.m.lit(PAL.buoy)} position={[bx, 0.25, bz]} scale={[1.1, 1.3, 1.1]}>
+ <mesh geometry={kit.g.sphere} material={kit.m.glow(PAL.lampLight)} position={[0, 0.75, 0]} scale={[0.35, 0.3, 0.35]} />
+ </mesh>
))}
</group>
</group>
@@ -110,9 +112,12 @@ function Harbor({ kit, paused }: { kit: Kit; paused: boolean }) {
function Lighthouse({ kit, paused }: { kit: Kit; paused: boolean }) {
const [x, y, z] = placeWorld("lighthouse");
const lamp = useRef<Mesh>(null);
+ const beam = useRef<Group>(null);
useFrame(({ clock }) => {
- if (!lamp.current || paused) return;
- lamp.current.rotation.y = clock.getElapsedTime() * 1.4;
+ if (paused) return;
+ const t = clock.getElapsedTime() * 1.4;
+ if (lamp.current) lamp.current.rotation.y = t;
+ if (beam.current) beam.current.rotation.y = t;
});
return (
<group position={[x, y, z]} scale={[1.3, 1.3, 1.3]}>
@@ -124,6 +129,20 @@ function Lighthouse({ kit, paused }: { kit: Kit; paused: boolean }) {
<mesh geometry={kit.g.cylinder} material={kit.m.glow(PAL.hubGlass)} position={[0, 12.3, 0]} scale={[2.6, 1.8, 2.6]} />
<mesh ref={lamp} geometry={kit.g.box} material={kit.m.glow(PAL.beaconCore)} position={[0, 12.3, 0]} scale={[3.2, 0.9, 0.7]} />
<mesh geometry={kit.g.dome} material={kit.m.lit(PAL.lighthouseStripe)} position={[0, 13.2, 0]} scale={[4.2, 2.2, 4.2]} />
+ {/* the beam: two translucent cones sweeping with the lamp, one each way */}
+ <group ref={beam} position={[0, 12.3, 0]}>
+ {[1, -1].map((dir) => (
+ <mesh
+ key={dir}
+ geometry={kit.g.cone}
+ material={kit.m.halo(PAL.beacon, 0.16)}
+ position={[dir * 24, 0, 0]}
+ rotation={[0, 0, (-dir * Math.PI) / 2]}
+ scale={[7, 48, 7]}
+ />
+ ))}
+ </group>
+ <mesh geometry={kit.g.disc} material={kit.m.halo(PAL.lampGlow, 0.2)} position={[0, 0.55, 0]} scale={[7, 1, 7]} />
{/* keeper's hut */}
<Block kit={kit} at={[-5, 1.3, 3]} size={[4, 2.6, 3.4]} color={PAL.wallShade} />
<Block kit={kit} at={[-5, 2.75, 3]} size={[4.6, 0.3, 4]} color={PAL.solar} />
@@ -131,6 +150,125 @@ function Lighthouse({ kit, paused }: { kit: Kit; paused: boolean }) {
);
}
+/**
+ * The mine: a timber portal cut into the cliff north of the quarry's forecourt,
+ * lanterns on its posts, rails running out of the dark to a cart of ore, a
+ * headframe with its wheel, crates, and the foreman's hut.
+ */
+function Mine({ kit, paused }: { kit: Kit; paused: boolean }) {
+ const [x, y, z] = placeWorld("mine");
+ const wheel = useRef<Mesh>(null);
+ useFrame(({ clock }) => {
+ if (!wheel.current || paused) return;
+ wheel.current.rotation.x = clock.getElapsedTime() * 0.8;
+ });
+ const face = -6.8; // the cliff's south face, relative z
+ return (
+ <group position={[x, y, z]}>
+ {/* the tunnel: a dark mouth set into the cliff */}
+ <Block kit={kit} at={[0, 2.2, face - 0.5]} size={[5.2, 4.4, 1.6]} color={PAL.mineDark} glow />
+ {/* timber frame */}
+ <Block kit={kit} at={[-2.9, 2.4, face + 0.2]} size={[0.7, 4.8, 0.7]} color={PAL.woodDark} />
+ <Block kit={kit} at={[2.9, 2.4, face + 0.2]} size={[0.7, 4.8, 0.7]} color={PAL.woodDark} />
+ <Block kit={kit} at={[0, 4.9, face + 0.2]} size={[6.8, 0.7, 0.8]} color={PAL.woodDark} />
+ <Block kit={kit} at={[0, 3.6, face - 0.3]} size={[5.4, 0.4, 0.5]} color={PAL.wood} />
+ {/* the sign over the lintel and the lanterns on the posts */}
+ <Block kit={kit} at={[0, 5.9, face + 0.25]} size={[3.6, 1.0, 0.16]} color={PAL.wall} />
+ <Block kit={kit} at={[0, 5.9, face + 0.36]} size={[2.6, 0.22, 0.04]} color={PAL.woodDark} />
+ {[-2.9, 2.9].map((px) => (
+ <group key={px} position={[px, 3.9, face + 0.75]}>
+ <mesh geometry={kit.g.box} material={kit.m.glow(PAL.lampLight)} scale={[0.42, 0.5, 0.42]} />
+ <mesh geometry={kit.g.box} material={kit.m.lit(PAL.metal)} position={[0, 0.34, 0]} scale={[0.5, 0.12, 0.5]} />
+ <mesh geometry={kit.g.disc} material={kit.m.halo(PAL.lampGlow, 0.3)} position={[0, -3.85, 0.6]} scale={[2.6, 1, 2.6]} />
+ </group>
+ ))}
+ {/* rails out of the tunnel across the forecourt */}
+ {[-0.75, 0.75].map((px) => (
+ <Block key={px} kit={kit} at={[px, 0.08, face + 8]} size={[0.14, 0.14, 16.5]} color={PAL.rail} />
+ ))}
+ {Array.from({ length: 9 }, (_, k) => (
+ <Block key={k} kit={kit} at={[0, 0.04, face + 1 + k * 1.8]} size={[2.2, 0.08, 0.36]} color={PAL.woodDark} />
+ ))}
+ {/* the ore cart on the rails */}
+ <group position={[0, 0, face + 6.5]}>
+ <Block kit={kit} at={[0, 0.85, 0]} size={[1.7, 1.0, 2.3]} color={PAL.woodDark} />
+ <Block kit={kit} at={[0, 0.85, 0]} size={[1.5, 1.05, 2.1]} color={PAL.metal} />
+ {[
+ [-0.85, -0.7],
+ [0.85, -0.7],
+ [-0.85, 0.7],
+ [0.85, 0.7],
+ ].map(([wx, wz]) => (
+ <mesh key={`${wx},${wz}`} geometry={kit.g.cylinder} material={kit.m.lit(PAL.rail)} position={[wx, 0.3, wz]} rotation={[0, 0, Math.PI / 2]} scale={[0.6, 0.16, 0.6]} />
+ ))}
+ <mesh geometry={kit.g.blob} material={kit.m.glow(PAL.ore)} position={[0.2, 1.5, 0.3]} scale={0.8} />
+ <mesh geometry={kit.g.blob} material={kit.m.glow(PAL.ore)} position={[-0.4, 1.45, -0.4]} scale={0.7} />
+ <mesh geometry={kit.g.blob} material={kit.m.lit(PAL.boulderB)} position={[0.35, 1.4, -0.5]} scale={0.6} />
+ </group>
+ {/* the headframe: an A-frame with the winding wheel, and the foreman's hut */}
+ <group position={[6.5, 0, face + 3]}>
+ <Block kit={kit} at={[-1.1, 3.0, 0]} size={[0.35, 6.4, 0.35]} color={PAL.woodDark} rotation={[0, 0, 0.18]} />
+ <Block kit={kit} at={[1.1, 3.0, 0]} size={[0.35, 6.4, 0.35]} color={PAL.woodDark} rotation={[0, 0, -0.18]} />
+ <Block kit={kit} at={[0, 0.3, -1.4]} size={[0.35, 0.6, 3.2]} color={PAL.woodDark} />
+ <Block kit={kit} at={[0, 3.6, 0]} size={[2.4, 0.3, 0.3]} color={PAL.wood} />
+ <mesh ref={wheel} geometry={kit.g.ring} material={kit.m.lit(PAL.rail)} position={[0, 6.1, 0]} rotation={[0, Math.PI / 2, 0]} scale={[2.2, 2.2, 2.2]} />
+ <Block kit={kit} at={[0, 6.1, 0]} size={[0.16, 0.16, 0.6]} color={PAL.metal} />
+ <Block kit={kit} at={[0, 3.3, 0]} size={[0.06, 5.6, 0.06]} color={PAL.rail} />
+ </group>
+ <group position={[-6.2, 0, face + 3.5]}>
+ <Block kit={kit} at={[0, 1.4, 0]} size={[3.6, 2.8, 3.2]} color={PAL.wallShade} />
+ <Block kit={kit} at={[0, 2.95, 0]} size={[4.2, 0.3, 3.8]} color={PAL.solar} />
+ <Block kit={kit} at={[0, 1.5, 1.66]} size={[1.6, 1.0, 0.12]} color={PAL.glass} glow />
+ <Block kit={kit} at={[1.2, 1.0, 1.66]} size={[0.8, 2.0, 0.12]} color={PAL.door} />
+ </group>
+ {/* crates and a lantern post at the forecourt's edge */}
+ <Block kit={kit} at={[-4.5, 0.5, face + 8]} size={[1.0, 1.0, 1.0]} color={PAL.wood} />
+ <Block kit={kit} at={[-5.6, 0.45, face + 8.4]} size={[0.9, 0.9, 0.9]} color={PAL.woodDark} />
+ <Block kit={kit} at={[-5.0, 1.45, face + 8.1]} size={[0.9, 0.9, 0.9]} color={PAL.wood} rotation={[0, 0.5, 0]} />
+ </group>
+ );
+}
+
+/** The campfire on the cove's beach: a ring of stones, logs, a flame that breathes. */
+function Campfire({ kit, paused }: { kit: Kit; paused: boolean }) {
+ const { campfire } = buildIsland().content;
+ const flames = useRef<Group>(null);
+ const glow = useRef<Mesh>(null);
+ useFrame(({ clock }) => {
+ if (paused) return;
+ const t = clock.getElapsedTime();
+ if (flames.current) {
+ flames.current.children.forEach((f, i) => {
+ const s = 0.85 + 0.25 * Math.sin(t * (5 + i) + i * 1.7);
+ f.scale.set(s, s * (1.1 + 0.3 * Math.sin(t * 7 + i)), s);
+ f.position.y = 0.55 + i * 0.35 + 0.1 * Math.sin(t * 6 + i);
+ });
+ }
+ if (glow.current) glow.current.scale.setScalar(4.2 + 0.5 * Math.sin(t * 4.3));
+ });
+ return (
+ <group position={[campfire.x, campfire.y, campfire.z]}>
+ {Array.from({ length: 7 }, (_, k) => {
+ const a = (k / 7) * Math.PI * 2;
+ return (
+ <mesh key={k} geometry={kit.g.blob} material={kit.m.lit(k % 2 ? PAL.boulderA : PAL.boulderB)} position={[Math.cos(a) * 1.3, 0.2, Math.sin(a) * 1.3]} scale={[0.55, 0.4, 0.5]} rotation={[0, a, 0]} />
+ );
+ })}
+ <Block kit={kit} at={[0, 0.25, 0]} size={[0.35, 0.35, 1.8]} color={PAL.woodDark} rotation={[0, 0.5, 0]} />
+ <Block kit={kit} at={[0, 0.25, 0]} size={[0.35, 0.35, 1.8]} color={PAL.woodDark} rotation={[0, -0.7, 0]} />
+ <group ref={flames}>
+ <mesh geometry={kit.g.blob} material={kit.m.glow(PAL.fire)} position={[0, 0.6, 0]} scale={0.9} />
+ <mesh geometry={kit.g.blob} material={kit.m.glow(PAL.fireCore)} position={[0.1, 0.9, 0]} scale={0.6} />
+ <mesh geometry={kit.g.blob} material={kit.m.glow(PAL.ember)} position={[-0.15, 1.2, 0.1]} scale={0.35} />
+ </group>
+ <mesh ref={glow} geometry={kit.g.disc} material={kit.m.halo(PAL.fire, 0.3)} position={[0, 0.06, 0]} scale={4.2} />
+ {/* two driftwood benches */}
+ <Block kit={kit} at={[0, 0.3, 3.2]} size={[3.2, 0.5, 0.6]} color={PAL.wood} rotation={[0, 0.15, 0]} />
+ <Block kit={kit} at={[-3.0, 0.3, -1.2]} size={[3.0, 0.5, 0.6]} color={PAL.woodDark} rotation={[0, 1.2, 0]} />
+ </group>
+ );
+}
+
/** Instanced greenhouses: glass barrels on wooden sills. */
function Greenhouses({ kit, posts }: { kit: Kit; posts: Post[] }) {
const dummy = useMemo(() => new Object3D(), []);
@@ -211,6 +349,8 @@ export function Landmarks({
<MemoryHouse paused={paused} busy={atMemory ?? 0} onClick={onHubClick} selected={memoryOpen} />
<Harbor kit={kit} paused={paused} />
<Lighthouse kit={kit} paused={paused} />
+ <Mine kit={kit} paused={paused} />
+ <Campfire kit={kit} paused={paused} />
<Greenhouses kit={kit} posts={content.greenhouses} />
<SolarField kit={kit} posts={content.panels} />
</group>
diff --git a/jarvis/ui/web/frontend/src/components/society/world/PlaceLabels.tsx b/jarvis/ui/web/frontend/src/components/society/world/PlaceLabels.tsx
index cbfa13bbdf..f88796dca9 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/PlaceLabels.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/world/PlaceLabels.tsx
@@ -18,6 +18,7 @@ const LABEL_Y: Record<PlaceId, number> = {
lighthouse: 20,
gardens: 6,
solar: 5,
+ mine: 10,
plugins: 13,
foundry: 18,
skills: 9,
diff --git a/jarvis/ui/web/frontend/src/components/society/world/Terrain.tsx b/jarvis/ui/web/frontend/src/components/society/world/Terrain.tsx
index 8336c1cc9c..e86189da23 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/Terrain.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/world/Terrain.tsx
@@ -1,10 +1,17 @@
/**
* The ground and the sea. The terrain is one merged, vertex-coloured mesh
- * (`terrainGeometry.ts`) that receives the sun's shadows. The sea is a single
- * plane with a shader driven by a shore-distance texture baked from the tile
- * map: turquoise shallows deepening to the open sea, long swells, caustic
- * shimmer in the shallows, wave crests rolling toward every coast and
- * breaking into a foam line, sparkle further out — world-masterplan-v2.md §3.6.
+ * (`terrainGeometry.ts`) that receives the sun's shadows.
+ *
+ * The sea is a subdivided plane whose vertex shader raises real waves — three
+ * open-sea swells plus breakers that build up as the bottom rises (a shore-
+ * distance field baked from the tile map says where the coast is) — and hands
+ * the fragment shader the wave normal and the crest phase. The fragment shader
+ * lights the water with the sun (dark troughs, bright faces, a glint on the
+ * steep side), tints it by depth from the turquoise shallows to the abyss,
+ * shimmers the shallows, breaks the crests into whitecaps and lays a
+ * breathing foam line along the coast. A second, transparent plane just above
+ * the beach is the wash: foam that runs up the sand and drains back.
+ * world-masterplan-v2.md §3.6.
*/
import { useEffect, useMemo } from "react";
import { useFrame } from "@react-three/fiber";
@@ -18,11 +25,13 @@ import {
PlaneGeometry,
RedFormat,
ShaderMaterial,
+ Vector3,
} from "three";
-import { ISLAND_HALF_M, TILE_M, TileKind, buildIsland, type IslandMap } from "./islandLayout";
+import { ISLAND_HALF_M, LEVEL_Y, TILE_M, TileKind, buildIsland, type IslandMap } from "./islandLayout";
import { buildTerrainGeometry } from "./terrainGeometry";
-import { WATER } from "./worldPalette";
+import { SKY, WATER } from "./worldPalette";
+import { cameraOffset } from "./worldCamera";
export function Terrain() {
const geometry = useMemo(() => buildTerrainGeometry(buildIsland().map), []);
@@ -41,11 +50,15 @@ export function Terrain() {
}
/** The sea plane — far larger than the island so its edge is never in view. */
-const SEA_SIZE_M = 2400;
+const SEA_SIZE_M = 1400;
+/** Vertices per side: 5 m cells, fine enough for 9 m breakers. */
+const SEA_SEGMENTS = 280;
/** How many tiles out from the coast the shore texture measures distance. */
export const SHORE_REACH_TILES = 16;
/** The same reach in metres — the shader's distance scale. */
const SHORE_REACH_M = SHORE_REACH_TILES * TILE_M;
+/** How many tiles inland the wash texture reaches over the beach. */
+const WASH_REACH_TILES = 2;
/**
* Shore distance per tile: 1 on land and at the coast, fading to 0 sixteen
@@ -53,11 +66,49 @@ const SHORE_REACH_M = SHORE_REACH_TILES * TILE_M;
* water. Linear filtering turns the per-tile values into a smooth field.
*/
export function buildShoreTexture(map: IslandMap): DataTexture {
+ const dist = distanceField(map, (k) => k !== TileKind.water, (k) => k === TileKind.water, SHORE_REACH_TILES);
+ const n = map.size * map.size;
+ const data = new Uint8Array(n);
+ for (let i = 0; i < n; i++) {
+ if (map.kind[i] !== TileKind.water) {
+ data[i] = 255;
+ continue;
+ }
+ const d = dist[i];
+ data[i] = d < 0 ? 0 : Math.max(0, Math.round(255 * (1 - (d - 0.5) / SHORE_REACH_TILES)));
+ }
+ return makeTexture(data, map.size);
+}
+
+/**
+ * The beach as seen from the water: 1 on sand right at the waterline, 0.5 one
+ * tile further up, 0 elsewhere — the field the wash climbs.
+ */
+export function buildWashTexture(map: IslandMap): DataTexture {
+ const dist = distanceField(map, (k) => k === TileKind.water, (k) => k === TileKind.sand, WASH_REACH_TILES);
+ const n = map.size * map.size;
+ const data = new Uint8Array(n);
+ for (let i = 0; i < n; i++) {
+ const d = dist[i];
+ // Only the low beach: sand one step above the water.
+ if (map.kind[i] !== TileKind.sand || map.level[i] !== 1 || d <= 0) continue;
+ data[i] = Math.round(255 * (1 - (d - 1) / WASH_REACH_TILES));
+ }
+ return makeTexture(data, map.size);
+}
+
+/** Breadth-first distance from every `source` tile over `through` tiles, up to `reach`. */
+function distanceField(
+ map: IslandMap,
+ source: (kind: number) => boolean,
+ through: (kind: number) => boolean,
+ reach: number,
+): Int16Array {
const n = map.size * map.size;
const dist = new Int16Array(n).fill(-1);
const queue: number[] = [];
for (let i = 0; i < n; i++) {
- if (map.kind[i] !== TileKind.water) {
+ if (source(map.kind[i])) {
dist[i] = 0;
queue.push(i);
}
@@ -66,7 +117,7 @@ export function buildShoreTexture(map: IslandMap): DataTexture {
while (head < queue.length) {
const cur = queue[head++];
const d = dist[cur];
- if (d >= SHORE_REACH_TILES) continue;
+ if (d >= reach) continue;
const cx = cur % map.size;
const cz = Math.floor(cur / map.size);
for (const [dx, dz] of [
@@ -79,21 +130,16 @@ export function buildShoreTexture(map: IslandMap): DataTexture {
const nz = cz + dz;
if (nx < 0 || nz < 0 || nx >= map.size || nz >= map.size) continue;
const ni = nz * map.size + nx;
- if (dist[ni] !== -1) continue;
+ if (dist[ni] !== -1 || !through(map.kind[ni])) continue;
dist[ni] = d + 1;
queue.push(ni);
}
}
- const data = new Uint8Array(n);
- for (let i = 0; i < n; i++) {
- if (map.kind[i] !== TileKind.water) {
- data[i] = 255;
- continue;
- }
- const d = dist[i];
- data[i] = d < 0 ? 0 : Math.max(0, Math.round(255 * (1 - (d - 0.5) / SHORE_REACH_TILES)));
- }
- const tex = new DataTexture(data, map.size, map.size, RedFormat);
+ return dist;
+}
+
+function makeTexture(data: Uint8Array, size: number): DataTexture {
+ const tex = new DataTexture(data, size, size, RedFormat);
tex.minFilter = LinearFilter;
tex.magFilter = LinearFilter;
tex.wrapS = ClampToEdgeWrapping;
@@ -102,92 +148,197 @@ export function buildShoreTexture(map: IslandMap): DataTexture {
return tex;
}
+const NOISE_GLSL = /* glsl */ `
+ float hashn(vec2 p) {
+ return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
+ }
+ float noise(vec2 p) {
+ vec2 i = floor(p);
+ vec2 f = fract(p);
+ f = f * f * (3.0 - 2.0 * f);
+ float a = hashn(i);
+ float b = hashn(i + vec2(1.0, 0.0));
+ float c = hashn(i + vec2(0.0, 1.0));
+ float d = hashn(i + vec2(1.0, 1.0));
+ return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
+ }
+`;
+
const WATER_VERTEX = /* glsl */ `
+ uniform sampler2D shoreTex;
+ uniform float time;
+ uniform float halfSize;
+ uniform float reachM;
varying vec3 vWorld;
+ varying vec3 vNormal;
+ varying float vDist;
+ varying float vCrest;
+ ${NOISE_GLSL}
+
+ float shoreDist(vec2 xz) {
+ vec2 uv = xz / (2.0 * halfSize) + 0.5;
+ return (1.0 - texture2D(shoreTex, uv).r) * reachM;
+ }
+
void main() {
- vec4 world = modelMatrix * vec4(position, 1.0);
- vWorld = world.xyz;
- gl_Position = projectionMatrix * viewMatrix * world;
+ vec3 world = (modelMatrix * vec4(position, 1.0)).xyz;
+ vec2 p = world.xz;
+ float dist = shoreDist(p);
+ // Where the coast lies, from the field's gradient: the breakers run that way.
+ float e = 2.0;
+ vec2 grad = vec2(shoreDist(p + vec2(e, 0.0)) - shoreDist(p - vec2(e, 0.0)),
+ shoreDist(p + vec2(0.0, e)) - shoreDist(p - vec2(0.0, e))) / (2.0 * e);
+
+ float h = 0.0;
+ vec2 slope = vec2(0.0);
+ // Three open-sea swells: long, medium, short.
+ vec2 d1 = normalize(vec2(0.8, 0.6));
+ vec2 d2 = normalize(vec2(-0.5, 0.87));
+ vec2 d3 = normalize(vec2(0.3, -0.95));
+ float k1 = 6.2832 / 34.0, k2 = 6.2832 / 19.0, k3 = 6.2832 / 9.5;
+ float a1 = 0.26, a2 = 0.16, a3 = 0.08;
+ float p1 = dot(p, d1) * k1 - time * 0.9;
+ float p2 = dot(p, d2) * k2 - time * 1.25;
+ float p3 = dot(p, d3) * k3 - time * 1.9;
+ h += a1 * sin(p1) + a2 * sin(p2) + a3 * sin(p3);
+ slope += a1 * k1 * cos(p1) * d1 + a2 * k2 * cos(p2) * d2 + a3 * k3 * cos(p3) * d3;
+
+ // Breakers: as the bottom rises the wave steepens, peaks a few metres off
+ // the beach and collapses into foam on the sand.
+ float shoal = smoothstep(1.5, 6.0, dist) * (1.0 - smoothstep(9.0, 30.0, dist));
+ float wobble = noise(p * 0.12 + vec2(3.7, 1.3)) * 2.5;
+ float phase = dist * 0.72 - time * 1.35 + wobble;
+ float crest = sin(phase);
+ // Sharpen the front face: a wave that is about to break leans forward.
+ float steep = crest + 0.35 * sin(2.0 * phase + 1.2);
+ float ab = 0.42 * shoal;
+ h += ab * steep;
+ // Its slope points along the shore gradient (toward the coast).
+ slope += ab * 0.72 * cos(phase) * grad;
+
+ vec3 displaced = world + vec3(0.0, h, 0.0);
+ vWorld = displaced;
+ vNormal = normalize(vec3(-slope.x, 1.0, -slope.y));
+ vDist = dist;
+ vCrest = steep * shoal;
+ gl_Position = projectionMatrix * viewMatrix * vec4(displaced, 1.0);
}
`;
const WATER_FRAGMENT = /* glsl */ `
- uniform sampler2D shoreTex;
uniform float time;
- uniform float halfSize;
uniform float reachM;
+ uniform vec3 sunDir;
+ uniform vec3 viewDir;
uniform vec3 abyss;
uniform vec3 deep;
uniform vec3 surface;
uniform vec3 shallow;
uniform vec3 ripple;
uniform vec3 foam;
+ uniform vec3 glintColor;
varying vec3 vWorld;
-
- float hashn(vec2 p) {
- return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
- }
- float noise(vec2 p) {
- vec2 i = floor(p);
- vec2 f = fract(p);
- f = f * f * (3.0 - 2.0 * f);
- float a = hashn(i);
- float b = hashn(i + vec2(1.0, 0.0));
- float c = hashn(i + vec2(0.0, 1.0));
- float d = hashn(i + vec2(1.0, 1.0));
- return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
- }
+ varying vec3 vNormal;
+ varying float vDist;
+ varying float vCrest;
+ ${NOISE_GLSL}
void main() {
- vec2 uv = vWorld.xz / (2.0 * halfSize) + 0.5;
- float shore = texture2D(shoreTex, uv).r;
- // Metres from the nearest coast, 0 at the shore, reachM on the open sea.
- float dist = (1.0 - shore) * reachM;
+ float dist = vDist;
+ vec3 n = normalize(vNormal);
// Depth: turquoise over the sand, the surface blue, then deep, then the abyss.
vec3 col = mix(shallow, surface, smoothstep(0.0, 9.0, dist));
col = mix(col, deep, smoothstep(8.0, 22.0, dist));
col = mix(col, abyss, smoothstep(24.0, reachM, dist));
- // Long swells: two slow bands crossing the whole sea.
- float swell = sin(dot(vWorld.xz, vec2(0.045, 0.028)) - time * 0.55) * 0.5 + 0.5;
- float swell2 = sin(dot(vWorld.xz, vec2(-0.03, 0.05)) + time * 0.4) * 0.5 + 0.5;
- col *= 0.94 + 0.05 * swell + 0.04 * swell2;
+ // The sun on the waves: faces toward it brighten, troughs and backs darken.
+ float ndl = max(dot(n, sunDir), 0.0);
+ col *= 0.72 + 0.4 * ndl;
+ // The glint: the sun's reflection toward the camera on the steep faces.
+ vec3 r = reflect(-sunDir, n);
+ float spec = pow(max(dot(r, viewDir), 0.0), 90.0);
+ col += glintColor * spec * 0.55;
// Caustic shimmer where the bottom is close.
float n1 = noise(vWorld.xz * 0.8 + vec2(time * 0.35, -time * 0.22));
float n2 = noise(vWorld.xz * 1.15 - vec2(time * 0.28, time * 0.31));
float caustic = smoothstep(0.66, 0.92, n1 * 0.5 + n2 * 0.5) * (1.0 - smoothstep(2.0, 12.0, dist));
- col = mix(col, ripple, caustic * 0.32);
+ col = mix(col, ripple, caustic * 0.3);
- // Breakers: crests rolling in toward the coast, wavelength ~9 m, bent by noise.
- float wobble = noise(vWorld.xz * 0.12 + vec2(3.7, 1.3)) * 2.5;
- float crest = sin(dist * 0.7 - time * 1.35 + wobble);
- float crestMask = (1.0 - smoothstep(3.0, 16.0, dist)) * smoothstep(0.6, 3.0, dist);
+ // Whitecaps: the crest of a breaker, torn by noise, streaming behind it.
float lace = noise(vWorld.xz * 0.9 + vec2(-time * 0.6, time * 0.45));
- float waves = smoothstep(0.84, 0.97, crest) * crestMask * smoothstep(0.25, 0.75, lace);
+ float lace2 = noise(vWorld.xz * 2.2 + vec2(time * 0.9, -time * 0.7));
+ float cap = smoothstep(0.55, 0.95, vCrest) * smoothstep(0.2, 0.7, lace * 0.6 + lace2 * 0.4);
+ float streak = smoothstep(0.25, 0.6, vCrest) * smoothstep(0.55, 0.85, lace2) * 0.5;
// The foam line hugging the coast, breathing with the waves.
- float breathe = 0.35 * sin(time * 1.35 + wobble);
- float band = 1.0 - smoothstep(1.0 + breathe, 2.8 + breathe, dist);
- float foamAmt = max(band * (0.7 + 0.3 * lace), waves * 0.9);
+ float wobble = noise(vWorld.xz * 0.12 + vec2(3.7, 1.3)) * 2.5;
+ float breathe = 0.45 * sin(time * 1.35 + wobble);
+ float band = 1.0 - smoothstep(0.9 + breathe, 3.0 + breathe, dist);
+ float foamAmt = max(band * (0.65 + 0.35 * lace), max(cap * 0.95, streak));
col = mix(col, foam, foamAmt);
- // Sparkle on the open water.
+ // Sparkle on the open water, in drifting patches.
float g1 = sin(vWorld.x * 0.42 + vWorld.z * 0.18 + time * 0.9);
float g2 = sin(vWorld.z * 0.37 - vWorld.x * 0.21 - time * 0.7);
float glintPatch = smoothstep(0.42, 0.72, noise(vWorld.xz * 0.06 + vec2(time * 0.05, -time * 0.03)));
float glint = smoothstep(0.9, 1.0, g1 * g2) * smoothstep(4.0, 12.0, dist) * glintPatch;
- col = mix(col, ripple, glint * 0.45);
+ col = mix(col, ripple, glint * 0.4);
gl_FragColor = vec4(col, 1.0);
#include <colorspace_fragment>
}
`;
+const WASH_VERTEX = /* glsl */ `
+ varying vec2 vXz;
+ void main() {
+ vec4 world = modelMatrix * vec4(position, 1.0);
+ vXz = world.xz;
+ gl_Position = projectionMatrix * viewMatrix * world;
+ }
+`;
+
+const WASH_FRAGMENT = /* glsl */ `
+ uniform sampler2D washTex;
+ uniform float time;
+ uniform float halfSize;
+ uniform vec3 foam;
+ varying vec2 vXz;
+ ${NOISE_GLSL}
+
+ void main() {
+ vec2 uv = vXz / (2.0 * halfSize) + 0.5;
+ // 1 at the waterline, 0.5 a tile up the beach, 0 beyond: how far a wash can climb.
+ float beach = texture2D(washTex, uv).r;
+ if (beach <= 0.001) discard;
+ float wobble = noise(vXz * 0.12 + vec2(3.7, 1.3)) * 2.5;
+ // The same rhythm as the breakers: the wash follows each one up the sand.
+ float surge = 0.5 + 0.5 * sin(time * 1.35 + wobble + 1.3);
+ float reach = 0.35 + 0.65 * surge;
+ float edge = smoothstep(reach - 0.35, reach, beach);
+ float lace = noise(vXz * 1.4 + vec2(-time * 0.5, time * 0.4));
+ // The sheet is thickest at its leading edge and lacy behind it.
+ float alpha = edge * (0.35 + 0.45 * smoothstep(0.3, 0.8, lace)) * (0.6 + 0.4 * surge);
+ gl_FragColor = vec4(foam, alpha);
+ #include <colorspace_fragment>
+ }
+`;
+
+const SUN_DIR = new Vector3(SKY.sunFrom[0], SKY.sunFrom[1], SKY.sunFrom[2]).normalize();
+const VIEW_DIR = (() => {
+ const [x, y, z] = cameraOffset();
+ return new Vector3(x, y, z).normalize();
+})();
+
export function Water({ paused }: { paused: boolean }) {
- const geometry = useMemo(() => new PlaneGeometry(SEA_SIZE_M, SEA_SIZE_M), []);
- const shore = useMemo(() => buildShoreTexture(buildIsland().map), []);
+ const geometry = useMemo(() => new PlaneGeometry(SEA_SIZE_M, SEA_SIZE_M, SEA_SEGMENTS, SEA_SEGMENTS), []);
+ const washGeometry = useMemo(() => new PlaneGeometry(SEA_SIZE_M, SEA_SIZE_M), []);
+ const { shore, wash } = useMemo(() => {
+ const { map } = buildIsland();
+ return { shore: buildShoreTexture(map), wash: buildWashTexture(map) };
+ }, []);
const material = useMemo(
() =>
new ShaderMaterial({
@@ -196,31 +347,67 @@ export function Water({ paused }: { paused: boolean }) {
time: { value: 0 },
halfSize: { value: ISLAND_HALF_M },
reachM: { value: SHORE_REACH_M },
+ sunDir: { value: SUN_DIR },
+ viewDir: { value: VIEW_DIR },
abyss: { value: new Color(WATER.abyss) },
deep: { value: new Color(WATER.deep) },
surface: { value: new Color(WATER.surface) },
shallow: { value: new Color(WATER.shallow) },
ripple: { value: new Color(WATER.ripple) },
foam: { value: new Color(WATER.foam) },
+ glintColor: { value: new Color(SKY.seaGlint) },
},
vertexShader: WATER_VERTEX,
fragmentShader: WATER_FRAGMENT,
}),
[shore],
);
+ const washMaterial = useMemo(
+ () =>
+ new ShaderMaterial({
+ uniforms: {
+ washTex: { value: wash },
+ time: { value: 0 },
+ halfSize: { value: ISLAND_HALF_M },
+ foam: { value: new Color(WATER.foam) },
+ },
+ vertexShader: WASH_VERTEX,
+ fragmentShader: WASH_FRAGMENT,
+ transparent: true,
+ depthWrite: false,
+ }),
+ [wash],
+ );
useEffect(
() => () => {
geometry.dispose();
+ washGeometry.dispose();
material.dispose();
+ washMaterial.dispose();
shore.dispose();
+ wash.dispose();
},
- [geometry, material, shore],
+ [geometry, washGeometry, material, washMaterial, shore, wash],
);
useFrame(({ clock }) => {
if (paused) return;
- material.uniforms.time.value = clock.getElapsedTime();
+ const t = clock.getElapsedTime();
+ material.uniforms.time.value = t;
+ washMaterial.uniforms.time.value = t;
});
- return <mesh geometry={geometry} material={material} rotation={[-Math.PI / 2, 0, 0]} />;
+ return (
+ <group>
+ <mesh geometry={geometry} material={material} rotation={[-Math.PI / 2, 0, 0]} />
+ {/* the wash: a sheet just above the beach's sand */}
+ <mesh
+ geometry={washGeometry}
+ material={washMaterial}
+ rotation={[-Math.PI / 2, 0, 0]}
+ position={[0, LEVEL_Y[1] + 0.03, 0]}
+ renderOrder={2}
+ />
+ </group>
+ );
}
diff --git a/jarvis/ui/web/frontend/src/components/society/world/Trees.tsx b/jarvis/ui/web/frontend/src/components/society/world/Trees.tsx
index 670065352f..40b98c8993 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/Trees.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/world/Trees.tsx
@@ -8,7 +8,7 @@
import { useMemo } from "react";
import { Color, InstancedMesh, Object3D } from "three";
-import { buildIsland, type Boulder, type TreeSpot } from "./islandLayout";
+import { buildIsland, type Boulder, type Post, type TreeSpot } from "./islandLayout";
import { NATURE } from "./worldPalette";
import { useKit } from "./WorldKit";
@@ -196,8 +196,49 @@ function Boulders({ rocks }: { rocks: Boulder[] }) {
return <instancedMesh ref={setup} args={[g.blob, m.lit("#ffffff"), rocks.length]} />;
}
+/** Reeds in the marsh: leaning stalks with a brown head, two instanced meshes. */
+function Reeds({ reeds }: { reeds: Post[] }) {
+ const { g, m } = useKit();
+ const dummy = useMemo(() => new Object3D(), []);
+ const stalks: Setup = (mesh) => {
+ if (!mesh) return;
+ reeds.forEach((r, i) => {
+ const h = 1.5 + (r.rotation % 1) * 0.9;
+ dummy.position.set(r.x, r.y, r.z);
+ dummy.rotation.set(0, r.rotation, 0);
+ dummy.rotateX(0.12);
+ dummy.scale.set(0.12, h, 0.12);
+ dummy.translateY(h / 2);
+ dummy.updateMatrix();
+ mesh.setMatrixAt(i, dummy.matrix);
+ });
+ mesh.instanceMatrix.needsUpdate = true;
+ };
+ const heads: Setup = (mesh) => {
+ if (!mesh) return;
+ reeds.forEach((r, i) => {
+ const h = 1.5 + (r.rotation % 1) * 0.9;
+ dummy.position.set(r.x, r.y, r.z);
+ dummy.rotation.set(0, r.rotation, 0);
+ dummy.rotateX(0.12);
+ dummy.scale.set(0.2, 0.45, 0.2);
+ dummy.translateY(h / 0.45 - 0.3);
+ dummy.updateMatrix();
+ mesh.setMatrixAt(i, dummy.matrix);
+ });
+ mesh.instanceMatrix.needsUpdate = true;
+ };
+ if (reeds.length === 0) return null;
+ return (
+ <group>
+ <instancedMesh ref={stalks} args={[g.slab, m.lit(NATURE.reed), reeds.length]} />
+ <instancedMesh ref={heads} args={[g.cylinder, m.lit(NATURE.reedHead), reeds.length]} />
+ </group>
+ );
+}
+
export function Trees() {
- const { trees, boulders } = buildIsland().content;
+ const { trees, boulders, reeds } = buildIsland().content;
const byKind = useMemo(
() => ({
round: trees.filter((t) => t.kind === "round"),
@@ -212,6 +253,7 @@ export function Trees() {
<Pines spots={byKind.pine} />
<Palms spots={byKind.palm} />
<Boulders rocks={boulders} />
+ <Reeds reeds={reeds} />
</group>
);
}
diff --git a/jarvis/ui/web/frontend/src/components/society/world/Village.tsx b/jarvis/ui/web/frontend/src/components/society/world/Village.tsx
index 1a5ab7ab37..2565c67569 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/Village.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/world/Village.tsx
@@ -9,7 +9,7 @@
*/
import { useMemo, useRef } from "react";
import { useFrame } from "@react-three/fiber";
-import { Color, InstancedMesh, Mesh, Object3D } from "three";
+import { Color, InstancedMesh, Mesh, Object3D, Vector3 } from "three";
import { LEVEL_Y, PLATEAU_LEVEL, buildIsland, groundY, type HousePlot, type Post } from "./islandLayout";
import { QuestMonument } from "./QuestMonument";
@@ -233,7 +233,11 @@ function Hedges({ kit, posts }: { kit: Kit; posts: Post[] }) {
);
}
-/** Lamps along the spokes: a post and a glowing head. */
+/**
+ * Lamps along the spokes, around the square, the ring road and the dock: a
+ * post, a glowing head, and the warm pool of light it throws on the ground —
+ * an additive disc, the cheapest lighting effect there is.
+ */
function Lamps({ kit, posts }: { kit: Kit; posts: Post[] }) {
const dummy = useMemo(() => new Object3D(), []);
const setup = (mesh: InstancedMesh | null, yOffset: number, scale: [number, number, number]) => {
@@ -251,10 +255,95 @@ function Lamps({ kit, posts }: { kit: Kit; posts: Post[] }) {
<>
<instancedMesh ref={(m) => setup(m, 1.6, [0.18, 3.2, 0.18])} args={[kit.g.cylinder, kit.m.lit(PAL.lampPost), posts.length]} />
<instancedMesh ref={(m) => setup(m, 3.35, [0.55, 0.45, 0.55])} args={[kit.g.box, kit.m.glow(PAL.lampLight), posts.length]} />
+ <instancedMesh ref={(m) => setup(m, 0.05, [3.4, 1, 3.4])} args={[kit.g.disc, kit.m.halo(PAL.lampGlow, 0.28), posts.length]} />
</>
);
}
+/** Bulbs per string between two neighbouring poles. */
+const FESTOON_BULBS = 13;
+/** How far the string sags in the middle, metres. */
+const FESTOON_SAG = 1.4;
+/** Height of the string's ends on the pole. */
+const FESTOON_Y = 5.2;
+
+/**
+ * Festoon lights over the square: strings of bulbs sagging from pole to pole
+ * around the rim, and one from every pole in toward the centre — the roof of
+ * light a market has on a summer evening. Bulbs and wire segments are two
+ * instanced meshes.
+ */
+function Festoon({ kit, poles }: { kit: Kit; poles: Post[] }) {
+ const dummy = useMemo(() => new Object3D(), []);
+ const segments = useMemo(() => {
+ const out: Array<{ a: Vector3; b: Vector3 }> = [];
+ const anchor = (p: Post) => new Vector3(p.x, p.y + FESTOON_Y, p.z);
+ for (let i = 0; i < poles.length; i++) {
+ out.push({ a: anchor(poles[i]), b: anchor(poles[(i + 1) % poles.length]) });
+ }
+ return out;
+ }, [poles]);
+ const points = useMemo(() => {
+ const pts: Vector3[] = [];
+ for (const { a, b } of segments) {
+ for (let k = 0; k <= FESTOON_BULBS; k++) {
+ const t = k / FESTOON_BULBS;
+ const p = a.clone().lerp(b, t);
+ p.y -= FESTOON_SAG * 4 * t * (1 - t);
+ pts.push(p);
+ }
+ }
+ return pts;
+ }, [segments]);
+ const bulbCount = segments.length * (FESTOON_BULBS - 1);
+ const wireCount = segments.length * FESTOON_BULBS;
+
+ const bulbs = (mesh: InstancedMesh | null) => {
+ if (!mesh) return;
+ let i = 0;
+ for (let s = 0; s < segments.length; s++) {
+ for (let k = 1; k < FESTOON_BULBS; k++) {
+ const p = points[s * (FESTOON_BULBS + 1) + k];
+ dummy.position.set(p.x, p.y - 0.12, p.z);
+ dummy.rotation.set(0, 0, 0);
+ dummy.scale.setScalar(0.3);
+ dummy.updateMatrix();
+ mesh.setMatrixAt(i++, dummy.matrix);
+ }
+ }
+ mesh.instanceMatrix.needsUpdate = true;
+ };
+ const wires = (mesh: InstancedMesh | null) => {
+ if (!mesh) return;
+ let i = 0;
+ for (let s = 0; s < segments.length; s++) {
+ for (let k = 0; k < FESTOON_BULBS; k++) {
+ const p = points[s * (FESTOON_BULBS + 1) + k];
+ const q = points[s * (FESTOON_BULBS + 1) + k + 1];
+ dummy.position.copy(p).lerp(q, 0.5);
+ dummy.lookAt(q);
+ dummy.scale.set(0.05, 0.05, p.distanceTo(q));
+ dummy.updateMatrix();
+ mesh.setMatrixAt(i++, dummy.matrix);
+ }
+ }
+ mesh.instanceMatrix.needsUpdate = true;
+ };
+
+ return (
+ <group>
+ {poles.map((p, i) => (
+ <group key={i} position={[p.x, p.y, p.z]}>
+ <mesh geometry={kit.g.cylinder} material={kit.m.lit(PAL.lampPost)} position={[0, FESTOON_Y / 2, 0]} scale={[0.22, FESTOON_Y, 0.22]} />
+ <mesh geometry={kit.g.box} material={kit.m.lit(PAL.trim)} position={[0, 0.2, 0]} scale={[0.8, 0.4, 0.8]} />
+ </group>
+ ))}
+ <instancedMesh ref={wires} args={[kit.g.slab, kit.m.lit(PAL.lampPost), wireCount]} />
+ <instancedMesh ref={bulbs} args={[kit.g.sphere, kit.m.glow(PAL.bulb), bulbCount]} />
+ </group>
+ );
+}
+
export function Village({
paused,
onQuestClick,
@@ -276,6 +365,7 @@ export function Village({
<SquareCentre kit={kit} paused={paused} onQuestClick={onQuestClick} questOpen={questOpen} />
<Hedges kit={kit} posts={content.hedges} />
<Lamps kit={kit} posts={content.lamps} />
+ <Festoon kit={kit} poles={content.festoonPoles} />
</group>
);
}
diff --git a/jarvis/ui/web/frontend/src/components/society/world/islandLayout.test.ts b/jarvis/ui/web/frontend/src/components/society/world/islandLayout.test.ts
index d93ec6b796..ec821a83e0 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/islandLayout.test.ts
+++ b/jarvis/ui/web/frontend/src/components/society/world/islandLayout.test.ts
@@ -262,7 +262,7 @@ describe("islandLayout", () => {
kinds[t.kind]++;
const [tx, tz] = worldToTile(t.x, t.z);
const k = map.kind[tileIndex(map, tx, tz)];
- expect([TileKind.grass, TileKind.meadow, TileKind.forest, TileKind.alpine, TileKind.sand]).toContain(k);
+ expect([TileKind.grass, TileKind.meadow, TileKind.forest, TileKind.alpine, TileKind.sand, TileKind.heath, TileKind.dry]).toContain(k);
if (k === TileKind.sand) expect(t.kind).toBe("palm");
if (t.kind === "palm") expect(k).toBe(TileKind.sand);
expect(Math.hypot(tx + 0.5 - CENTER_TILE, tz + 0.5 - CENTER_TILE)).toBeGreaterThan(
@@ -274,6 +274,22 @@ describe("islandLayout", () => {
expect(kinds.palm).toBeGreaterThan(20);
});
+ it("cuts the mine into a cliff at the end of its own road, and lights the village", () => {
+ const { map, content } = island;
+ const [mx, mz] = content.places.mine.tile;
+ // The forecourt is quarry floor; the cliff behind it stands three steps higher, as rock.
+ expect(map.kind[tileIndex(map, mx, mz)]).toBe(TileKind.quarry);
+ expect(map.kind[tileIndex(map, mx, mz - 8)]).toBe(TileKind.rock);
+ expect(map.level[tileIndex(map, mx, mz - 8)] - map.level[tileIndex(map, mx, mz)]).toBeGreaterThanOrEqual(3);
+ // The branch road reaches the forecourt from the north spoke.
+ expect(map.kind[tileIndex(map, mx + 12, mz)]).toBe(TileKind.path);
+ expect(content.festoonPoles.length).toBe(8);
+ expect(content.lamps.length).toBeGreaterThan(50);
+ expect(content.reeds.length).toBeGreaterThan(40);
+ const [cx, cz] = worldToTile(content.campfire.x, content.campfire.z);
+ expect(map.kind[tileIndex(map, cx, cz)]).toBe(TileKind.sand);
+ });
+
it("scatters boulders over the high ground, never on pavement", () => {
const { map, content } = island;
expect(content.boulders.length).toBeGreaterThan(100);
diff --git a/jarvis/ui/web/frontend/src/components/society/world/islandLayout.ts b/jarvis/ui/web/frontend/src/components/society/world/islandLayout.ts
index f6c8910acb..5b6e92b0b5 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/islandLayout.ts
+++ b/jarvis/ui/web/frontend/src/components/society/world/islandLayout.ts
@@ -26,7 +26,11 @@
* alpine meadows roll over the north-east, the lighthouse stands on a
* rocky cape in the east, the tropical cove with its lagoon and palms fills
* the low south-east foreground, the harbor bay bites into the south, the
- * orchard meadows cover the south-west and the dark forest the west.
+ * orchard meadows and farmland cover the south-west, a marsh with pools
+ * and reeds the south-western coast, dry savanna the eastern lowland, the
+ * dark forest the west; heather drifts over the high moor, gravel over the
+ * mountain's flanks, and a mine is cut into a cliff on its south-eastern
+ * side, reached by a branch off the north road.
* - The terrain is a continuous height field quantised into steps: every
* slope becomes a terrace, every steep place a cliff. Roads are GRADED —
* never more than one step per tile — so every place stays reachable on
@@ -85,6 +89,18 @@ export const TileKind = {
alpine: 10,
/** The mountain's snow cap. */
snow: 11,
+ /** Heather over the high moor, north-east. */
+ heath: 12,
+ /** Sun-dried savanna grass on the eastern lowland. */
+ dry: 13,
+ /** Crop rows of the south-western farmland. */
+ farm: 14,
+ /** Wetland with pools and reeds on the south-western coast. */
+ marsh: 15,
+ /** Loose gravel on the mountain's flanks. */
+ scree: 16,
+ /** The quarry floor around the mine. */
+ quarry: 17,
} as const;
export type TileKind = (typeof TileKind)[keyof typeof TileKind];
@@ -130,6 +146,7 @@ export type PlaceId =
| "lighthouse"
| "gardens"
| "solar"
+ | "mine"
| "plugins"
| "foundry"
| "skills"
@@ -201,6 +218,12 @@ export interface IslandContent {
trees: TreeSpot[];
/** Rocks scattered over the highland, the cliffs and the beaches. */
boulders: Boulder[];
+ /** Reeds standing in the marsh. */
+ reeds: Post[];
+ /** Poles around the square that carry the festoon lights. */
+ festoonPoles: Post[];
+ /** The campfire on the cove's beach. */
+ campfire: Post;
/** Hedge segments forming the village ring, with gaps at the four gates. */
hedges: Post[];
/** Light posts along the ring and the spokes. */
@@ -411,6 +434,8 @@ const PLACE_TILES: Record<PlaceId, [number, number]> = {
lighthouse: [CENTER_TILE + 84, CENTER_TILE],
gardens: [CENTER_TILE + 44, CENTER_TILE + 48],
solar: [CENTER_TILE - 40, CENTER_TILE - 40],
+ // The mine: a portal in a cliff on the mountain's south-eastern flank.
+ mine: [CENTER_TILE - 32, CENTER_TILE - 60],
// Kit buildings stand in the house ring (RING_KIT_SLOTS); the tile is the ring pose's.
plugins: ringTile("plugins"),
foundry: ringTile("foundry"),
@@ -464,6 +489,7 @@ const PLOT_HALF: Record<PlaceId, [number, number]> = {
lighthouse: [4, 4],
gardens: [9, 7],
solar: [8, 7],
+ mine: [5, 4],
plugins: [0, 0], // no flat plot of its own: it sits on the village plateau
foundry: [0, 0],
skills: [0, 0],
@@ -481,6 +507,7 @@ const PLOT_LEVEL: Record<PlaceId, number> = {
lighthouse: 6,
gardens: 2,
solar: 4,
+ mine: 4,
plugins: PLATEAU_LEVEL,
foundry: PLATEAU_LEVEL,
skills: PLATEAU_LEVEL,
@@ -496,6 +523,11 @@ const BUILDING_HALF: Partial<Record<PlaceId, [number, number]>> = {
lighthouse: [1, 1],
};
+/** The cliff the mine's portal is cut into: a rock block north of the forecourt. */
+const MINE_CLIFF = { dz: -8, hw: 8, hd: 3, level: 7 } as const;
+/** The mine's branch road leaves the north spoke here and runs west to the forecourt. */
+const MINE_ROAD = { fromX: CENTER_TILE - 1, z: CENTER_TILE - 60, length: 27 } as const;
+
/** Where the dock reaches into the bay: from the harbor plot southward. */
export const DOCK_TILES = { from: CENTER_TILE + 66, to: CENTER_TILE + 80, halfWidth: 1 } as const;
@@ -522,6 +554,10 @@ export const REGIONS = {
orchard: { x: -0.45, z: 0.5, r: 0.3 },
/** The dark forest, west. */
forest: { x: -0.6, z: 0.02, r: 0.34 },
+ /** Dry savanna on the eastern lowland, between the highland and the cove. */
+ savanna: { x: 0.64, z: 0.2, r: 0.3 },
+ /** The wetland on the south-western coast. */
+ marsh: { x: -0.62, z: 0.46, r: 0.2 },
} as const;
export type RegionId = keyof typeof REGIONS;
@@ -647,21 +683,39 @@ function biomeKind(nx: number, nz: number, level: number): TileKind {
const inHighland = regionT(nx, nz, REGIONS.highland) < 1;
const inCove = regionT(nx, nz, REGIONS.cove) < 0.8;
const inForest = regionT(nx, nz, REGIONS.forest) < 0.92;
+ const inSavanna = regionT(nx, nz, REGIONS.savanna) < 1;
+ const inMarsh = regionT(nx, nz, REGIONS.marsh) < 1;
+ const inOrchard = regionT(nx, nz, REGIONS.orchard) < 0.85;
const grain = fbm(nx * 6 + 31, nz * 6 + 17, ISLAND_SEED + 3);
- if (level === 6) return inMountain || inCape ? TileKind.rock : TileKind.alpine;
+ // A second, coarser grain decides the patchwork biomes: heather drifts, fields, gravel.
+ const patchwork = fbm(nx * 4.2 + 5, nz * 4.2 + 9, ISLAND_SEED + 31);
+ if (level === 6) {
+ if (inMountain || inCape) return grain > 0.42 ? TileKind.rock : TileKind.scree;
+ return patchwork > 0.5 ? TileKind.heath : TileKind.alpine;
+ }
if (level === 5) {
- if ((inMountain || inCape) && grain > 0.55) return TileKind.rock;
- return inMountain || inHighland || inCape ? TileKind.alpine : TileKind.meadow;
+ if (inMountain || inCape) return grain > 0.55 ? TileKind.rock : grain > 0.3 ? TileKind.scree : TileKind.alpine;
+ if (inHighland) return patchwork > 0.52 ? TileKind.heath : TileKind.alpine;
+ return TileKind.meadow;
}
- if (level === 1) return TileKind.sand;
+ if (level === 1) return inMarsh ? TileKind.marsh : TileKind.sand;
if (level === 2) {
if (inCove) return TileKind.sand;
+ if (inMarsh) return TileKind.marsh;
+ if (inSavanna) return TileKind.dry;
+ if (inOrchard) return patchwork > 0.45 ? TileKind.farm : TileKind.meadow;
return grain > 0.6 ? TileKind.meadow : TileKind.grass;
}
// Levels 3 and 4: the rolling middle ground.
if (inForest && grain > 0.3) return TileKind.forest;
- if (level === 4) return inHighland && grain > 0.5 ? TileKind.alpine : TileKind.meadow;
- return grain > 0.66 ? TileKind.meadow : TileKind.grass;
+ if (inSavanna && level === 3) return grain > 0.7 ? TileKind.meadow : TileKind.dry;
+ if (inOrchard && level === 3) return patchwork > 0.42 ? TileKind.farm : TileKind.meadow;
+ if (inMountain && level === 4 && grain > 0.6) return TileKind.scree;
+ if (level === 4) {
+ if (inHighland) return patchwork > 0.55 ? TileKind.heath : grain > 0.5 ? TileKind.alpine : TileKind.meadow;
+ return grain > 0.45 ? TileKind.meadow : TileKind.grass;
+ }
+ return grain > 0.58 ? TileKind.meadow : TileKind.grass;
}
/**
@@ -693,6 +747,29 @@ function buildTerrain(map: IslandMap): void {
}
}
+ // Pools in the marsh: sea-level water inside the wetland, ringed by reeds.
+ for (let tz = 0; tz < map.size; tz++) {
+ for (let tx = 0; tx < map.size; tx++) {
+ const i = tileIndex(map, tx, tz);
+ if (map.kind[i] !== TileKind.marsh) continue;
+ const nx = (tx + 0.5 - C) / C;
+ const nz = (tz + 0.5 - C) / C;
+ if (fbm(nx * 16 + 2, nz * 16 + 6, ISLAND_SEED + 21) > 0.64) paintWater(map, i);
+ }
+ }
+
+ // The quarry: a gravel apron around the mine and the cliff its portal is cut into.
+ const [mx, mz] = PLACE_TILES.mine;
+ paintDisc(map, mx, mz, 0, 11, (i) => {
+ if (map.kind[i] === TileKind.water || map.kind[i] === TileKind.snow) return;
+ if (map.level[i] >= 7) return;
+ paintLand(map, i, map.level[i] >= 4 ? TileKind.scree : TileKind.quarry, map.level[i]);
+ });
+ fillRect(map, mx, mz + MINE_CLIFF.dz, MINE_CLIFF.hw, MINE_CLIFF.hd, (i) => {
+ if (map.kind[i] === TileKind.water) return;
+ paintLand(map, i, TileKind.rock, MINE_CLIFF.level);
+ });
+
// Sandbar around the lagoon: a bright rim of beach, one step above the water.
const lag = REGIONS.lagoon;
paintDisc(map, C + lag.x * C, C + lag.z * C, 0, lag.r * C + 4.5, (i) => {
@@ -742,7 +819,9 @@ function buildPlots(map: IslandMap): void {
? TileKind.meadow
: id === "lighthouse"
? TileKind.rock
- : TileKind.plaza;
+ : id === "mine"
+ ? TileKind.quarry
+ : TileKind.plaza;
fillRect(map, px, pz, hw, hd, (i) => {
if (map.kind[i] === TileKind.water) return;
paintLand(map, i, kind, PLOT_LEVEL[id]);
@@ -757,12 +836,17 @@ function buildPlots(map: IslandMap): void {
* come along, so the road never runs in a trench. This is what keeps every
* place reachable on foot whatever the terrain does.
*/
-function gradeSpoke(map: IslandMap, dir: [number, number], fromTiles: number, toTiles: number): void {
- const C = CENTER_TILE;
- let prev = PLATEAU_LEVEL;
- for (let s = fromTiles; s <= toTiles; s++) {
- const cx = C + dir[0] * s;
- const cz = C + dir[1] * s;
+function gradeRoad(
+ map: IslandMap,
+ start: [number, number],
+ dir: [number, number],
+ length: number,
+ startLevel: number,
+): void {
+ let prev = startLevel;
+ for (let s = 0; s <= length; s++) {
+ const cx = start[0] + dir[0] * s;
+ const cz = start[1] + dir[1] * s;
if (!inBounds(map, cx, cz)) break;
const ci = tileIndex(map, cx, cz);
const desired = map.kind[ci] === TileKind.water ? prev : map.level[ci];
@@ -804,7 +888,13 @@ function buildVillage(map: IslandMap): void {
});
// Spokes from the square out to the quarters (width 3), graded.
- for (const spoke of SPOKES) gradeSpoke(map, spoke.dir, PLAZA_RADIUS_TILES - 1, spoke.toTiles);
+ for (const spoke of SPOKES) {
+ const from = PLAZA_RADIUS_TILES - 1;
+ gradeRoad(map, [C + spoke.dir[0] * from, C + spoke.dir[1] * from], spoke.dir, spoke.toTiles - from, PLATEAU_LEVEL);
+ }
+ // The mine's branch: off the north spoke, west to the quarry, at the spoke's level there.
+ const junction = map.level[tileIndex(map, MINE_ROAD.fromX + 1, MINE_ROAD.z)];
+ gradeRoad(map, [MINE_ROAD.fromX, MINE_ROAD.z], [-1, 0], MINE_ROAD.length, junction);
// Buildings block walking; their tiles keep the plot level.
for (const id of Object.keys(BUILDING_HALF) as PlaceId[]) {
@@ -817,6 +907,10 @@ function buildVillage(map: IslandMap): void {
});
}
+ // The mine's portal and its rail head block walking; the forecourt stays open.
+ const [mx, mz] = PLACE_TILES.mine;
+ fillRect(map, mx, mz - 3, 3, 1, (i) => (map.blocked[i] = 1));
+
// The dock runs from the harbor plot into the bay, one step above the water
// so a walker can step onto the planks from the beach.
for (let tz = DOCK_TILES.from; tz <= DOCK_TILES.to; tz++) {
@@ -923,9 +1017,105 @@ function placeRingFurniture(map: IslandMap): { hedges: Post[]; lamps: Post[] } {
}
}
}
+ // Lamps around the square's rim and along the ring road, between the gates.
+ const ringLamps = (radiusTiles: number, count: number, offset: number) => {
+ for (let k = 0; k < count; k++) {
+ const angle = ((k + offset) / count) * Math.PI * 2;
+ // Never in a gate or on a spoke.
+ const toCardinal = Math.abs(((angle + Math.PI / 4) % (Math.PI / 2)) - Math.PI / 4);
+ if (toCardinal < 0.12) continue;
+ const x = Math.sin(angle) * radiusTiles * TILE_M;
+ const z = -Math.cos(angle) * radiusTiles * TILE_M;
+ const [tx, tz] = worldToTile(x, z);
+ if (!inBounds(map, tx, tz) || map.blocked[tileIndex(map, tx, tz)]) continue;
+ lamps.push({ x, z, y: groundY(map, x, z), rotation: 0 });
+ }
+ };
+ ringLamps(PLAZA_RADIUS_TILES + 2.2, 16, 0.5);
+ ringLamps(RING_ROAD_TILES + 1.8, 16, 0.5);
+ // Lanterns along the dock and the mine's road.
+ for (let tz = DOCK_TILES.from + 2; tz <= DOCK_TILES.to; tz += 4) {
+ const [x, z] = tileToWorld(CENTER_TILE + DOCK_TILES.halfWidth, tz);
+ lamps.push({ x: x + 0.7, z, y: DOCK_Y, rotation: 0 });
+ }
+ for (let s = 4; s < MINE_ROAD.length; s += 8) {
+ const [x, z] = tileToWorld(MINE_ROAD.fromX - s, MINE_ROAD.z + 2);
+ lamps.push({ x, z, y: groundY(map, x, z), rotation: 0 });
+ }
return { hedges, lamps };
}
+/** Eight poles around the square that carry the festoon lights over it. */
+function placeFestoonPoles(map: IslandMap): Post[] {
+ const poles: Post[] = [];
+ const r = (PLAZA_RADIUS_TILES - 1.5) * TILE_M;
+ for (let k = 0; k < 8; k++) {
+ const angle = ((k + 0.5) / 8) * Math.PI * 2;
+ const x = Math.sin(angle) * r;
+ const z = -Math.cos(angle) * r;
+ poles.push({ x, z, y: groundY(map, x, z), rotation: angle });
+ const [tx, tz] = worldToTile(x, z);
+ if (inBounds(map, tx, tz)) map.blocked[tileIndex(map, tx, tz)] = 1;
+ }
+ return poles;
+}
+
+/** The campfire: the first free sand tile near the lagoon's western shore. */
+function placeCampfire(map: IslandMap): Post {
+ const C = CENTER_TILE;
+ const cx = Math.round(C + REGIONS.lagoon.x * C - REGIONS.lagoon.r * C - 9);
+ const cz = Math.round(C + REGIONS.lagoon.z * C + 4);
+ for (let r = 0; r < 12; r++) {
+ for (let dz = -r; dz <= r; dz++) {
+ for (let dx = -r; dx <= r; dx++) {
+ const tx = cx + dx;
+ const tz = cz + dz;
+ if (!inBounds(map, tx, tz)) continue;
+ let ok = true;
+ fillRect(map, tx, tz, 1, 1, (i) => {
+ if (map.kind[i] !== TileKind.sand || map.blocked[i]) ok = false;
+ });
+ if (!ok) continue;
+ fillRect(map, tx, tz, 1, 1, (i) => (map.blocked[i] = 1));
+ const [x, z] = tileToWorld(tx, tz);
+ return { x, z, y: groundY(map, x, z), rotation: 0 };
+ }
+ }
+ }
+ const [x, z] = tileToWorld(cx, cz);
+ return { x, z, y: groundY(map, x, z), rotation: 0 };
+}
+
+/** Reeds on the marsh, thickest at the pools' edges. */
+function placeReeds(map: IslandMap): Post[] {
+ const reeds: Post[] = [];
+ for (let tz = 1; tz < map.size - 1; tz++) {
+ for (let tx = 1; tx < map.size - 1; tx++) {
+ const i = tileIndex(map, tx, tz);
+ if (map.kind[i] !== TileKind.marsh || map.blocked[i]) continue;
+ let pool = false;
+ for (const [dx, dz] of [
+ [1, 0],
+ [-1, 0],
+ [0, 1],
+ [0, -1],
+ ] as const) {
+ if (map.kind[tileIndex(map, tx + dx, tz + dz)] === TileKind.water) pool = true;
+ }
+ const density = pool ? 0.8 : 0.28;
+ if (hash2(tx, tz, ISLAND_SEED + 61) > density) continue;
+ const [x, z] = tileToWorld(tx, tz);
+ reeds.push({
+ x: x + (hash2(tx, tz, 62) - 0.5) * 1.4,
+ z: z + (hash2(tx, tz, 63) - 0.5) * 1.4,
+ y: LEVEL_Y[map.level[i]],
+ rotation: hash2(tx, tz, 64) * Math.PI * 2,
+ });
+ }
+ }
+ return reeds;
+}
+
/** Solar panel rows and greenhouses — the solarpunk furniture of two quarters. */
function placeQuarterFurniture(map: IslandMap): { panels: Post[]; greenhouses: Post[] } {
const panels: Post[] = [];
@@ -971,6 +1161,8 @@ function treeChoice(map: IslandMap, tx: number, tz: number): { kind: TreeKind; d
return { kind: "palm", density: lagoon < 1.9 ? 0.11 : 0.045 };
}
if (k === TileKind.meadow) return { kind: level >= 5 ? "pine" : "round", density: 0.09 };
+ if (k === TileKind.heath) return { kind: "pine", density: 0.025 };
+ if (k === TileKind.dry) return { kind: "round", density: 0.018 };
if (k === TileKind.grass) {
// Islets carry a tree or two; the mainland's grass stays open.
const offshore = Math.hypot(nx, nz) > 0.8;
@@ -1040,7 +1232,9 @@ function placeBoulders(map: IslandMap): Boulder[] {
if (Math.hypot(tx + 0.5 - C, tz + 0.5 - C) < HEDGE_RING_TILES + 4) continue;
let density: number;
if (k === TileKind.rock || k === TileKind.snow) density = 0.05;
- else if (k === TileKind.alpine) density = 0.035;
+ else if (k === TileKind.quarry) density = 0.09;
+ else if (k === TileKind.scree) density = 0.06;
+ else if (k === TileKind.alpine || k === TileKind.heath) density = 0.035;
else if (k === TileKind.sand) density = 0.012;
else density = 0.008;
// Rocks gather at the foot of cliffs: a higher neighbour raises the odds.
@@ -1097,6 +1291,8 @@ function buildPlaces(map: IslandMap): Record<PlaceId, Place> {
lighthouse: place("lighthouse", [PLACE_TILES.lighthouse[0] - 4, C], Math.PI / 2),
gardens: place("gardens", [PLACE_TILES.gardens[0], PLACE_TILES.gardens[1]], 0),
solar: place("solar", [PLACE_TILES.solar[0] + 1, PLACE_TILES.solar[1] + 9], Math.PI),
+ // On the mine's road at the edge of the forecourt, facing the portal (west).
+ mine: place("mine", [PLACE_TILES.mine[0] + 7, PLACE_TILES.mine[1]], -Math.PI / 2),
// In front of the docks' bays (7.5 m toward the square), facing the building.
plugins: kitPlace("plugins", 7.5),
// At the foot of the foundry's conveyor ramp, facing the portal.
@@ -1180,12 +1376,28 @@ export function buildIsland(): Island {
blockSquareFurniture(map);
const { hedges, lamps } = placeRingFurniture(map);
const { panels, greenhouses } = placeQuarterFurniture(map);
+ const festoonPoles = placeFestoonPoles(map);
+ const campfire = placeCampfire(map);
const trees = placeTrees(map);
const boulders = placeBoulders(map);
+ const reeds = placeReeds(map);
const places = buildPlaces(map);
cached = {
map,
- content: { places, houses, trees, boulders, hedges, lamps, panels, greenhouses, kitPoses },
+ content: {
+ places,
+ houses,
+ trees,
+ boulders,
+ reeds,
+ festoonPoles,
+ campfire,
+ hedges,
+ lamps,
+ panels,
+ greenhouses,
+ kitPoses,
+ },
};
return cached;
}
diff --git a/jarvis/ui/web/frontend/src/components/society/world/terrainGeometry.ts b/jarvis/ui/web/frontend/src/components/society/world/terrainGeometry.ts
index 10d0030ad7..1e64b6306e 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/terrainGeometry.ts
+++ b/jarvis/ui/web/frontend/src/components/society/world/terrainGeometry.ts
@@ -140,7 +140,9 @@ export function buildTerrainGeometry(map: IslandMap): BufferGeometry {
const shades = TILE_COLORS[kind];
const shade = hash2(tx, tz, 91) < 0.5 ? 0 : 1;
// Garden beds: the second shade is the flower colour, sprinkled sparsely.
- const topIdx = kind === TileKind.garden ? (hash2(tx, tz, 92) < 0.3 ? 1 : 0) : shade;
+ // Farmland: the two shades alternate by row — soil and crop, ploughed lines.
+ const topIdx =
+ kind === TileKind.garden ? (hash2(tx, tz, 92) < 0.3 ? 1 : 0) : kind === TileKind.farm ? tz % 2 : shade;
// Analytic ambient occlusion (world-masterplan-v2.md §3.3): ground next
// to a higher step or a building darkens a little, the way every corner
// of a stylised village is shaded.
diff --git a/jarvis/ui/web/frontend/src/components/society/world/worldMaterials.ts b/jarvis/ui/web/frontend/src/components/society/world/worldMaterials.ts
index 9d4ba91918..85231556f3 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/worldMaterials.ts
+++ b/jarvis/ui/web/frontend/src/components/society/world/worldMaterials.ts
@@ -6,7 +6,9 @@
*/
import { useEffect, useMemo } from "react";
import {
+ AdditiveBlending,
BoxGeometry,
+ CircleGeometry,
Color,
CylinderGeometry,
DataTexture,
@@ -48,6 +50,8 @@ export function createToonRamp(): DataTexture {
export interface WorldMaterials {
lit: (hex: string) => MeshToonMaterial;
glow: (hex: string) => MeshBasicMaterial;
+ /** Additive, translucent: light pools, beams, halos — the cheap "lighting effect". */
+ halo: (hex: string, opacity?: number) => MeshBasicMaterial;
dispose: () => void;
}
@@ -55,8 +59,24 @@ export interface WorldMaterials {
export function createWorldMaterials(): WorldMaterials {
const lit = new Map<string, MeshToonMaterial>();
const glow = new Map<string, MeshBasicMaterial>();
+ const halo = new Map<string, MeshBasicMaterial>();
const ramp = createToonRamp();
return {
+ halo: (hex, opacity = 0.35) => {
+ const key = `${hex}@${opacity}`;
+ let m = halo.get(key);
+ if (!m) {
+ m = new MeshBasicMaterial({
+ color: new Color(hex),
+ transparent: true,
+ opacity,
+ blending: AdditiveBlending,
+ depthWrite: false,
+ });
+ halo.set(key, m);
+ }
+ return m;
+ },
lit: (hex) => {
let m = lit.get(hex);
if (!m) {
@@ -76,9 +96,11 @@ export function createWorldMaterials(): WorldMaterials {
dispose: () => {
for (const m of lit.values()) m.dispose();
for (const m of glow.values()) m.dispose();
+ for (const m of halo.values()) m.dispose();
ramp.dispose();
lit.clear();
glow.clear();
+ halo.clear();
},
};
}
@@ -106,6 +128,8 @@ export interface WorldGeometries {
pine: BufferGeometry;
/** A palm crown: six drooping fronds around the trunk top, unit radius. */
palmCrown: BufferGeometry;
+ /** A flat unit disc facing +y, for light pools on the ground. */
+ disc: CircleGeometry;
dispose: () => void;
}
@@ -144,7 +168,8 @@ export function createWorldGeometries(): WorldGeometries {
const ring = new TorusGeometry(0.5, 0.06, 6, 24);
const pine = makePine();
const palmCrown = makePalmCrown();
- const all = [box, slab, cylinder, halfCylinder, cone, blob, sphere, dome, ring, pine, palmCrown];
+ const disc = new CircleGeometry(1, 20).rotateX(-Math.PI / 2);
+ const all = [box, slab, cylinder, halfCylinder, cone, blob, sphere, dome, ring, pine, palmCrown, disc];
return {
box,
slab,
@@ -157,6 +182,7 @@ export function createWorldGeometries(): WorldGeometries {
ring,
pine,
palmCrown,
+ disc,
dispose: () => all.forEach((g) => g.dispose()),
};
}
diff --git a/jarvis/ui/web/frontend/src/components/society/world/worldPalette.ts b/jarvis/ui/web/frontend/src/components/society/world/worldPalette.ts
index 62ca63aa14..5b2b4a7100 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/worldPalette.ts
+++ b/jarvis/ui/web/frontend/src/components/society/world/worldPalette.ts
@@ -34,6 +34,12 @@ export const TILE_COLORS: Record<TileKind, TileShades> = {
[TileKind.forest]: { top: ["#4f9e47", "#47923f"], side: "#6d5236" },
[TileKind.alpine]: { top: ["#bcd97c", "#aecf6f"], side: "#7c6a4c" },
[TileKind.snow]: { top: ["#f6f9fc", "#e9eff6"], side: "#8f92a3" },
+ [TileKind.heath]: { top: ["#b48ec6", "#a583b8"], side: "#7c6a4c" },
+ [TileKind.dry]: { top: ["#dcd07e", "#cfc370"], side: "#a08a55" },
+ [TileKind.farm]: { top: ["#c9a35a", "#8fbf55"], side: "#8e6a44" },
+ [TileKind.marsh]: { top: ["#5f9e70", "#4f8c62"], side: "#4c5e3c" },
+ [TileKind.scree]: { top: ["#918e88", "#85827b"], side: "#6f6e7c" },
+ [TileKind.quarry]: { top: ["#a2988a", "#948a7c"], side: "#6f6e7c" },
};
/** Water: the animated surface, from the turquoise shallows to the open sea. */
@@ -49,6 +55,8 @@ export const WATER = {
/** Sky and light. NoToneMapping keeps these exact. */
export const SKY = {
clear: "#a5dbff",
+ /** The sea's own highlight: the sun's colour on a wave face. */
+ seaGlint: "#fff6df",
hemiSky: "#d6ecff",
hemiGround: "#7f9c5a",
sun: "#fff1d6",
@@ -89,6 +97,10 @@ export const BUILDING = {
lighthouseStripe: "#e05a5a",
metal: "#8b8f9c",
buoy: "#e8563f",
+ /** The mine: the dark of the tunnel, the ore in the cart, the rails. */
+ mineDark: "#10131a",
+ ore: "#e8bd4c",
+ rail: "#6d6f78",
};
export const NATURE = {
@@ -114,6 +126,14 @@ export const NATURE = {
flower: "#ef8fb6",
lampPost: "#5c5f6a",
lampLight: "#ffe9b0",
+ /** The warm pool a lamp throws on the ground, and the festoon bulbs over the square. */
+ lampGlow: "#ffd68a",
+ bulb: "#fff3c8",
+ reed: "#7aa95e",
+ reedHead: "#a8834b",
+ fire: "#ff8f3a",
+ fireCore: "#ffe37a",
+ ember: "#ff5a2c",
tableWood: "#c58d4f",
bench: "#a9723a",
};
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/society/de.json b/jarvis/ui/web/frontend/src/i18n/locales/society/de.json
index 9f316c28a8..663323f85e 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/society/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/society/de.json
@@ -117,7 +117,8 @@
"place_harbor": "Hafentor",
"place_lighthouse": "Leuchtturm",
"place_gardens": "Gärten",
- "place_solar": "Solarfeld"
+ "place_solar": "Solarfeld",
+ "place_mine": "Die Mine"
}
}
}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/society/en.json b/jarvis/ui/web/frontend/src/i18n/locales/society/en.json
index eb02dfc418..bfe890bc1c 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/society/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/society/en.json
@@ -117,7 +117,8 @@
"place_harbor": "Harbor Gate",
"place_lighthouse": "Lighthouse",
"place_gardens": "Gardens",
- "place_solar": "Solar Field"
+ "place_solar": "Solar Field",
+ "place_mine": "The Mine"
}
}
}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/society/es.json b/jarvis/ui/web/frontend/src/i18n/locales/society/es.json
index af9019f2df..3ff7ccd649 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/society/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/society/es.json
@@ -117,7 +117,8 @@
"place_harbor": "Puerta del Puerto",
"place_lighthouse": "Faro",
"place_gardens": "Jardines",
- "place_solar": "Campo Solar"
+ "place_solar": "Campo Solar",
+ "place_mine": "La Mina"
}
}
}