roamwright 0.61.32 → 0.61.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -26
- package/examples/set-pieces-works.js +344 -0
- package/examples/set-pieces.html +8 -2
- package/examples/set-pieces.js +49 -2
- package/geometry/ground-cracks.js +90 -0
- package/geometry/harbour-kit.js +14 -1
- package/geometry/index.js +3 -0
- package/geometry/prop-mine.js +316 -0
- package/geometry/quarry-face.js +224 -0
- package/package.json +1 -1
- package/rendering/calm-dome.js +57 -0
- package/rendering/ground-cracks.js +102 -0
- package/rendering/hanging-chain.js +117 -0
- package/rendering/index.js +4 -0
- package/rendering/storm-silhouette.js +59 -0
package/README.md
CHANGED
|
@@ -32,32 +32,32 @@ npm resolves the Three.js peer in a new project. Roamwright targets Three.js **0
|
|
|
32
32
|
|
|
33
33
|
Browse all twenty-four examples on the [live showcase](https://enestaylan.github.io/roamwright/).
|
|
34
34
|
|
|
35
|
-
| Live example | What the example shows
|
|
36
|
-
| --------------------------------------------------------------------------------------------------- |
|
|
37
|
-
| [A small world](https://enestaylan.github.io/roamwright/examples/small-world.html?seed=42) | A coastal valley with a walled harbour town, lamps, market crowd, pasture herds, ships and a passing day/night sky.
|
|
38
|
-
| [Towns](https://enestaylan.github.io/roamwright/examples/towns.html?seed=7) | A village streaming in block by block along a winding valley road, with street lamps and windows lit after dark.
|
|
39
|
-
| [Town fittings](https://enestaylan.github.io/roamwright/examples/town-fittings.html?seed=42) | Walled courtyard gardens with instanced shrubs, harbour works and breakwater moles, street lamps and a desert storm wall.
|
|
40
|
-
| [Fortification](https://enestaylan.github.io/roamwright/examples/fortification.html?seed=11) | Walled coastal or inland town with towers, battlements, vaulted gatehouses, wall-walk and portal in three styles.
|
|
41
|
-
| [Harbour of ships](https://enestaylan.github.io/roamwright/examples/ships.html?seed=42) | Every preset of the ship kit moored stern-on to a stone harbour quay while a cog and rowing boat tack offshore.
|
|
42
|
-
| [Alpine viaduct](https://enestaylan.github.io/roamwright/examples/viaduct.html?seed=42) | Watch an electric train cross eight stone arches above a forested alpine river from valley, trackside or riverbank.
|
|
43
|
-
| [Crowds and herds](https://enestaylan.github.io/roamwright/examples/crowds.html?seed=17) | Instanced market crowd, patrolling camp walkers, street dogs, grazing cattle and poultry with crowd alarms.
|
|
44
|
-
| [Animal kit](https://enestaylan.github.io/roamwright/examples/animals.html?seed=42) | Horses, cattle, sheep, a pack camel, dogs and a cat animated on procedural quadruped skeletons in a fenced paddock.
|
|
45
|
-
| [Figure motion](https://enestaylan.github.io/roamwright/examples/figure-motion.html?seed=11) | Full-body procedural locomotion on uneven ground: walk, run, sit, bow, draw and sheathe a blade, and mount a horse.
|
|
46
|
-
| [Fliers](https://enestaylan.github.io/roamwright/examples/fliers.html?seed=7) | Moths around a lantern, animated and perched corvids on a crag, wheeling bird flocks and four-winged gliders aloft.
|
|
47
|
-
| [Rooms](https://enestaylan.github.io/roamwright/examples/rooms.html?seed=42) | A furnished beamed room and a domed arcaded hall with baked window, lamp and hearth light by day or night.
|
|
48
|
-
| [House kit](https://enestaylan.github.io/roamwright/examples/house-kit.html?seed=42) | Every built-in architectural form — gable, hip, flat, tower, round, dome and courtyard — arranged round a town square.
|
|
49
|
-
| [Props and plants](https://enestaylan.github.io/roamwright/examples/props-and-plants.html?seed=42) | Camp, market, farm and road props beside every tree, shrub, grass tussock and waterside reed in the plant kit.
|
|
50
|
-
| [Effects by day and night](https://enestaylan.github.io/roamwright/examples/effects.html?seed=3) | Budgeted campfires and light pools, drifting smoke shadows, hollow mist and particle bursts that scorch the ground.
|
|
51
|
-
| [Soundscape](https://enestaylan.github.io/roamwright/examples/soundscape.html?seed=42) | Synthesised spatial audio and surface-aware stride foley across a lakeside shore of water, mud, sand, stone and earth.
|
|
52
|
-
| [Figures](https://enestaylan.github.io/roamwright/examples/figure.html?seed=7) | Sculpted procedural characters from plain look specs — faces, hair, clothing, cloaks and custom weapons, near and far.
|
|
53
|
-
| [A baked land](https://enestaylan.github.io/roamwright/examples/land.html?seed=7) | One height sheet baked row by row with erosion, coast, river ford, banked road, cliff-faced tel, quarry and upland mere.
|
|
54
|
-
| [Island](https://enestaylan.github.io/roamwright/examples/island.html?seed=42) | Fractal terrain shapes a coastline, sandy coves, weathered boulders and coastal pines in turquoise shallows.
|
|
55
|
-
| [Pacing and measuring](https://enestaylan.github.io/roamwright/examples/pacing.html?seed=42) | Device-aware presets, ground render order, frame-pacing watch and a live performance box over a coastal valley.
|
|
56
|
-
| [World map and wayfinding](https://enestaylan.github.io/roamwright/examples/world-map.html?seed=42) | Shaded atlas relief, baked terrain sheets, collision-free lettering, interactive pan/zoom/tap and a live compass strip.
|
|
57
|
-
| [Scenes](https://enestaylan.github.io/roamwright/examples/scenes.html?seed=42) | Melee duels with blade trails, flying bolts, energy beams, props, instanced scene markers and automated camera cuts.
|
|
58
|
-
| [Title backdrop](https://enestaylan.github.io/roamwright/examples/title-backdrop.html?seed=42) | Procedural 2D parallax mountain ranges, snow lines, sunlit cumulus banks and freeze-on-load canvas handoff.
|
|
59
|
-
| [Troop formations](https://enestaylan.github.io/roamwright/examples/troops.html?seed=42) | Staggered infantry ranks, carried standards, mounted lancers, ox-drawn wagons, cattle herd and ballistic volleys.
|
|
60
|
-
| [Set pieces](https://enestaylan.github.io/roamwright/examples/set-pieces.html?seed=42) | Bedded
|
|
35
|
+
| Live example | What the example shows | Source |
|
|
36
|
+
| --------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
|
|
37
|
+
| [A small world](https://enestaylan.github.io/roamwright/examples/small-world.html?seed=42) | A coastal valley with a walled harbour town, lamps, market crowd, pasture herds, ships and a passing day/night sky. | [small-world.js](examples/small-world.js) |
|
|
38
|
+
| [Towns](https://enestaylan.github.io/roamwright/examples/towns.html?seed=7) | A village streaming in block by block along a winding valley road, with street lamps and windows lit after dark. | [towns.js](examples/towns.js) |
|
|
39
|
+
| [Town fittings](https://enestaylan.github.io/roamwright/examples/town-fittings.html?seed=42) | Walled courtyard gardens with instanced shrubs, harbour works and breakwater moles, street lamps and a desert storm wall. | [town-fittings.js](examples/town-fittings.js) |
|
|
40
|
+
| [Fortification](https://enestaylan.github.io/roamwright/examples/fortification.html?seed=11) | Walled coastal or inland town with towers, battlements, vaulted gatehouses, wall-walk and portal in three styles. | [fortification.js](examples/fortification.js) |
|
|
41
|
+
| [Harbour of ships](https://enestaylan.github.io/roamwright/examples/ships.html?seed=42) | Every preset of the ship kit moored stern-on to a stone harbour quay while a cog and rowing boat tack offshore. | [ships.js](examples/ships.js) |
|
|
42
|
+
| [Alpine viaduct](https://enestaylan.github.io/roamwright/examples/viaduct.html?seed=42) | Watch an electric train cross eight stone arches above a forested alpine river from valley, trackside or riverbank. | [viaduct.js](examples/viaduct.js) |
|
|
43
|
+
| [Crowds and herds](https://enestaylan.github.io/roamwright/examples/crowds.html?seed=17) | Instanced market crowd, patrolling camp walkers, street dogs, grazing cattle and poultry with crowd alarms. | [crowds.js](examples/crowds.js) |
|
|
44
|
+
| [Animal kit](https://enestaylan.github.io/roamwright/examples/animals.html?seed=42) | Horses, cattle, sheep, a pack camel, dogs and a cat animated on procedural quadruped skeletons in a fenced paddock. | [animals.js](examples/animals.js) |
|
|
45
|
+
| [Figure motion](https://enestaylan.github.io/roamwright/examples/figure-motion.html?seed=11) | Full-body procedural locomotion on uneven ground: walk, run, sit, bow, draw and sheathe a blade, and mount a horse. | [figure-motion.js](examples/figure-motion.js) |
|
|
46
|
+
| [Fliers](https://enestaylan.github.io/roamwright/examples/fliers.html?seed=7) | Moths around a lantern, animated and perched corvids on a crag, wheeling bird flocks and four-winged gliders aloft. | [fliers.js](examples/fliers.js) |
|
|
47
|
+
| [Rooms](https://enestaylan.github.io/roamwright/examples/rooms.html?seed=42) | A furnished beamed room and a domed arcaded hall with baked window, lamp and hearth light by day or night. | [rooms.js](examples/rooms.js) |
|
|
48
|
+
| [House kit](https://enestaylan.github.io/roamwright/examples/house-kit.html?seed=42) | Every built-in architectural form — gable, hip, flat, tower, round, dome and courtyard — arranged round a town square. | [house-kit.js](examples/house-kit.js) |
|
|
49
|
+
| [Props and plants](https://enestaylan.github.io/roamwright/examples/props-and-plants.html?seed=42) | Camp, market, farm and road props beside every tree, shrub, grass tussock and waterside reed in the plant kit. | [props-and-plants.js](examples/props-and-plants.js) |
|
|
50
|
+
| [Effects by day and night](https://enestaylan.github.io/roamwright/examples/effects.html?seed=3) | Budgeted campfires and light pools, drifting smoke shadows, hollow mist and particle bursts that scorch the ground. | [effects.js](examples/effects.js) |
|
|
51
|
+
| [Soundscape](https://enestaylan.github.io/roamwright/examples/soundscape.html?seed=42) | Synthesised spatial audio and surface-aware stride foley across a lakeside shore of water, mud, sand, stone and earth. | [soundscape.js](examples/soundscape.js) |
|
|
52
|
+
| [Figures](https://enestaylan.github.io/roamwright/examples/figure.html?seed=7) | Sculpted procedural characters from plain look specs — faces, hair, clothing, cloaks and custom weapons, near and far. | [figure.js](examples/figure.js) |
|
|
53
|
+
| [A baked land](https://enestaylan.github.io/roamwright/examples/land.html?seed=7) | One height sheet baked row by row with erosion, coast, river ford, banked road, cliff-faced tel, quarry and upland mere. | [land.js](examples/land.js) |
|
|
54
|
+
| [Island](https://enestaylan.github.io/roamwright/examples/island.html?seed=42) | Fractal terrain shapes a coastline, sandy coves, weathered boulders and coastal pines in turquoise shallows. | [island.js](examples/island.js) |
|
|
55
|
+
| [Pacing and measuring](https://enestaylan.github.io/roamwright/examples/pacing.html?seed=42) | Device-aware presets, ground render order, frame-pacing watch and a live performance box over a coastal valley. | [pacing.js](examples/pacing.js) |
|
|
56
|
+
| [World map and wayfinding](https://enestaylan.github.io/roamwright/examples/world-map.html?seed=42) | Shaded atlas relief, baked terrain sheets, collision-free lettering, interactive pan/zoom/tap and a live compass strip. | [world-map.js](examples/world-map.js) |
|
|
57
|
+
| [Scenes](https://enestaylan.github.io/roamwright/examples/scenes.html?seed=42) | Melee duels with blade trails, flying bolts, energy beams, props, instanced scene markers and automated camera cuts. | [scenes.js](examples/scenes.js) |
|
|
58
|
+
| [Title backdrop](https://enestaylan.github.io/roamwright/examples/title-backdrop.html?seed=42) | Procedural 2D parallax mountain ranges, snow lines, sunlit cumulus banks and freeze-on-load canvas handoff. | [title-backdrop.js](examples/title-backdrop.js) |
|
|
59
|
+
| [Troop formations](https://enestaylan.github.io/roamwright/examples/troops.html?seed=42) | Staggered infantry ranks, carried standards, mounted lancers, ox-drawn wagons, cattle herd and ballistic volleys. | [troops.js](examples/troops.js) |
|
|
60
|
+
| [Set pieces](https://enestaylan.github.io/roamwright/examples/set-pieces.html?seed=42) | Bedded outcrops, roots, fountains, ice cliffs, grottos and camps; a tiered quarry with its mine works, glowing cracks, a dome, a chain and a quay. | [set-pieces.js](examples/set-pieces.js) |
|
|
61
61
|
|
|
62
62
|
### Run locally
|
|
63
63
|
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The works zone of the set-pieces example (`examples/set-pieces.js`): a quarry mound with two tiered faces round a bowl and a
|
|
3
|
+
* timbered cut in its north-east face, where the sun rakes across it, with a rail track, ore tubs, a head-frame and a watch-tower on the bench; ground cracks running
|
|
4
|
+
* out of a spring, glowing as they run and cooling; a calm dome over a circle of stones; a chain hanging between posts; and a
|
|
5
|
+
* quay wall along a pool. Everything stands beyond the other zones, around {@link WORKS}.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import {
|
|
10
|
+
GeometryBuilder,
|
|
11
|
+
buildQuarryFace,
|
|
12
|
+
createCalmDome,
|
|
13
|
+
createGroundCracks,
|
|
14
|
+
createHarbourKit,
|
|
15
|
+
createHangingChain,
|
|
16
|
+
createMineProps,
|
|
17
|
+
createSimpleWater,
|
|
18
|
+
mulberry32,
|
|
19
|
+
placeInstances,
|
|
20
|
+
} from 'roamwright';
|
|
21
|
+
import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
|
|
22
|
+
import { C, TRS } from 'roamwright/geometry/primitives.js';
|
|
23
|
+
|
|
24
|
+
/** The quarry bowl's middle, in metres: the works stand within about eighty metres of it. */
|
|
25
|
+
export const WORKS = { x: 170, z: 110 };
|
|
26
|
+
|
|
27
|
+
const LIME = [0xd9d1b9, 0xcfc6ab, 0xe2dcc8, 0xc6bca0]; // the limestone, bed by bed
|
|
28
|
+
const BENCH = 0xcdc5ae; // the dust on a bench's top
|
|
29
|
+
const FLOOR_SAND = 0xc2a882; // warm canyon floor colour the mound's outer talus blends into
|
|
30
|
+
const BOWL = { lower: 16, upper: 22, bench: 5, top: 11, reach: 48 }; // metres: the two faces' radii, their lips' heights, the mound's foot
|
|
31
|
+
const CUT = { at: -1.33, half: 3.5 }; // the timbered cut: its bearing round the bowl (radians, 0 toward +x) and its half width in metres
|
|
32
|
+
const QUAY = { x: 10, z: 64, width: 68 }; // the quay wall, from the bowl's middle: its middle and its width in metres
|
|
33
|
+
const smooth = t => {
|
|
34
|
+
const k = Math.min(1, Math.max(0, t));
|
|
35
|
+
return k * k * (3 - 2 * k);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The height of the quarry mound at a point `x, z` counted from the bowl's middle: a floor under the bowl, a steep rise behind the
|
|
40
|
+
* lower face, the bench, a rise behind the upper face, the mound's top, and a talus down to the ground. Each rise stands well behind
|
|
41
|
+
* its face's sheet, so the sheet is all that shows of it; the mound's bench and top lie a little under the sheets that cover them.
|
|
42
|
+
* The cut is a slot through the first rise at its bearing. `groundAt` is the ground round the mound, `base` the bowl's floor.
|
|
43
|
+
*/
|
|
44
|
+
export function quarryMoundHeight(x, z, groundAt, base, fbm) {
|
|
45
|
+
const r = Math.hypot(x, z),
|
|
46
|
+
floor = base - 2.5,
|
|
47
|
+
bench = base + BOWL.bench - 0.5,
|
|
48
|
+
top = base + BOWL.top - 0.4,
|
|
49
|
+
roll = 0.1 * (fbm(x * 0.15, z * 0.15, 2, 7) - 0.5),
|
|
50
|
+
near = groundAt(WORKS.x + x, WORKS.z + z);
|
|
51
|
+
let height;
|
|
52
|
+
if (r < 19.5) height = floor;
|
|
53
|
+
else if (r < 20.5) height = floor + (bench - floor) * smooth(r - 19.5);
|
|
54
|
+
else if (r < 23.8) height = bench + roll;
|
|
55
|
+
else if (r < 24.7) height = bench + (top - bench) * smooth((r - 23.8) / 0.9);
|
|
56
|
+
else if (r < 31) height = top + roll;
|
|
57
|
+
else if (r < BOWL.reach) {
|
|
58
|
+
const fall = smooth((r - 31) / (BOWL.reach - 31));
|
|
59
|
+
height =
|
|
60
|
+
top +
|
|
61
|
+
(near - 0.3 - top) * fall +
|
|
62
|
+
(1.3 * (fbm(x * 0.05, z * 0.05, 2, 9) - 0.5) + 0.5 * (fbm(x * 0.13, z * 0.13, 2, 13) - 0.5)) * (1 - fall);
|
|
63
|
+
} else height = near - 0.45;
|
|
64
|
+
const bearing = Math.atan2(z, x),
|
|
65
|
+
across = Math.abs(Math.atan2(Math.sin(bearing - CUT.at), Math.cos(bearing - CUT.at))) * r; // metres from the cut's middle
|
|
66
|
+
if (r < 22.3 && across < CUT.half) height = Math.min(height, base - 0.3);
|
|
67
|
+
return height;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Lower the ground into a basin beyond the quay wall, so the pool lies below the coping. Returns the ground's height at `x, z`.
|
|
72
|
+
*
|
|
73
|
+
* @param {number} x - World X in metres.
|
|
74
|
+
* @param {number} z - World Z in metres.
|
|
75
|
+
* @param {number} ground - The ground's height there before the basin, in metres.
|
|
76
|
+
*/
|
|
77
|
+
export function quayBasinHeight(x, z, ground) {
|
|
78
|
+
const beyond = z - (WORKS.z + QUAY.z + 2.5),
|
|
79
|
+
within = Math.abs(x - (WORKS.x + QUAY.x)) < QUAY.width / 2 + 26;
|
|
80
|
+
return within && beyond > 0 ? ground - 3.4 * smooth(beyond / 3) : ground;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Build the works zone.
|
|
85
|
+
*
|
|
86
|
+
* @param {object} parts
|
|
87
|
+
* @param {THREE.Object3D} parts.worldGroup - The world everything is added to.
|
|
88
|
+
* @param {(x: number, z: number) => number} parts.groundAt - The ground's height round the works, in metres.
|
|
89
|
+
* @param {object} parts.shapes - The example's unit shapes.
|
|
90
|
+
* @param {object} parts.noise - The example's noise (`fbm`).
|
|
91
|
+
* @param {object} parts.hash - The example's coordinate hash.
|
|
92
|
+
* @param {number} parts.seed - The example's seed.
|
|
93
|
+
* @param {{ rock: THREE.Material, wood: THREE.Material, stone: THREE.Material }} parts.materials - The example's vertex-coloured materials.
|
|
94
|
+
* @returns {{ views: object, floorAt: (x: number, z: number) => number, update: (t: number) => void }} The zone's named viewpoints, the
|
|
95
|
+
* height a camera must keep clear of over the mound, and the zone's frame update.
|
|
96
|
+
*/
|
|
97
|
+
export function buildWorks({ worldGroup, groundAt, shapes, noise, hash, seed, materials }) {
|
|
98
|
+
const X = WORKS.x,
|
|
99
|
+
Z = WORKS.z,
|
|
100
|
+
base = groundAt(X, Z) - 0.6, // the bowl's floor: the faces stand from under the ground
|
|
101
|
+
rng = mulberry32(seed * 31 + 5);
|
|
102
|
+
const views = {};
|
|
103
|
+
const updateWater = [];
|
|
104
|
+
|
|
105
|
+
// ── The quarry mound and its two faces ──
|
|
106
|
+
const floorTone = new THREE.Color(FLOOR_SAND);
|
|
107
|
+
const mound = createHeightfieldMesh({
|
|
108
|
+
size: 2 * BOWL.reach + 8,
|
|
109
|
+
segs: 160,
|
|
110
|
+
heightAt: (x, z) => quarryMoundHeight(x, z, groundAt, base, noise.fbm),
|
|
111
|
+
colorAt: (x, y, z, up, out) => {
|
|
112
|
+
const n = noise.fbm(x * 0.2, z * 0.2, 2, 11),
|
|
113
|
+
r = Math.hypot(x, z),
|
|
114
|
+
skirt = smooth((r - 30) / (BOWL.reach - 31));
|
|
115
|
+
if (up > 0.75) out.setHex(BENCH).multiplyScalar(0.92 + 0.16 * n);
|
|
116
|
+
else out.setHex(LIME[Math.floor(n * 4) % 4]).multiplyScalar(0.85 + 0.2 * n);
|
|
117
|
+
// Blend the outer talus slope smoothly into the surrounding canyon floor so the outcrop sits naturally on the ground.
|
|
118
|
+
if (skirt > 0) out.lerp(floorTone, skirt * 0.92);
|
|
119
|
+
},
|
|
120
|
+
roughness: 0.92,
|
|
121
|
+
});
|
|
122
|
+
mound.position.set(X, 0, Z);
|
|
123
|
+
worldGroup.add(mound);
|
|
124
|
+
|
|
125
|
+
const face = new GeometryBuilder();
|
|
126
|
+
face.ox = X;
|
|
127
|
+
face.oz = Z;
|
|
128
|
+
// The points of a face round the bowl from angle `from` to `to`: its foot and lip, its top running back out of the bowl.
|
|
129
|
+
const ring = (radius, from, to, y0, top) => {
|
|
130
|
+
const points = [];
|
|
131
|
+
const count = Math.round(((to - from) / (Math.PI * 2)) * 120);
|
|
132
|
+
for (let i = 0; i <= count; i++) {
|
|
133
|
+
const a = from + ((to - from) * i) / count,
|
|
134
|
+
c = Math.cos(a),
|
|
135
|
+
s = Math.sin(a);
|
|
136
|
+
points.push({ x: c * radius, z: s * radius, nx: -c, nz: -s, y0, top, backX: c, backZ: s, dust: C(BENCH) });
|
|
137
|
+
}
|
|
138
|
+
return points;
|
|
139
|
+
};
|
|
140
|
+
const look = { bed: 2.1, tones: LIME, capTone: BENCH, noise: noise.fbm, hash, color: C };
|
|
141
|
+
const cutAngle = CUT.half / BOWL.lower;
|
|
142
|
+
buildQuarryFace(face, ring(BOWL.lower, CUT.at + cutAngle, CUT.at + Math.PI * 2 - cutAngle, base, base + BOWL.bench), {
|
|
143
|
+
...look,
|
|
144
|
+
cap: BOWL.upper - BOWL.lower - 0.3,
|
|
145
|
+
floor: base - 0.5,
|
|
146
|
+
seed: seed + 7,
|
|
147
|
+
ground: () => base + BOWL.bench,
|
|
148
|
+
});
|
|
149
|
+
// Place the upper ring's start/end seam behind the quarry camera (+2.55 rad) so no block step interrupts the skyline.
|
|
150
|
+
buildQuarryFace(face, ring(BOWL.upper, 2.55, 2.55 + Math.PI * 2, base + 2.5, base + BOWL.top), {
|
|
151
|
+
...look,
|
|
152
|
+
cap: 8,
|
|
153
|
+
floor: base - 0.5,
|
|
154
|
+
seed: seed + 17,
|
|
155
|
+
ground: () => base + BOWL.top - 0.2,
|
|
156
|
+
});
|
|
157
|
+
face.mesh(materials.rock, worldGroup);
|
|
158
|
+
// broken stone lying on the talus, so the mound's foot is a slope of rock and not a bare dome
|
|
159
|
+
const talus = [];
|
|
160
|
+
for (let k = 0; k < 220; k++) {
|
|
161
|
+
const a = rng() * Math.PI * 2,
|
|
162
|
+
r = 30.5 + rng() * rng() * 15,
|
|
163
|
+
sx = X + Math.cos(a) * r,
|
|
164
|
+
sz = Z + Math.sin(a) * r,
|
|
165
|
+
size = 0.6 + rng() * rng() * 1.8;
|
|
166
|
+
talus.push(
|
|
167
|
+
TRS(
|
|
168
|
+
sx,
|
|
169
|
+
quarryMoundHeight(sx - X, sz - Z, groundAt, base, noise.fbm) - size * 0.25,
|
|
170
|
+
sz,
|
|
171
|
+
size * 1.4,
|
|
172
|
+
size * 0.8,
|
|
173
|
+
size,
|
|
174
|
+
rng() * 6,
|
|
175
|
+
).clone(), // TRS hands back one shared matrix
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
placeInstances({
|
|
179
|
+
geometry: shapes.rock,
|
|
180
|
+
material: new THREE.MeshStandardMaterial({ roughness: 0.92 }), // its tint comes instance by instance
|
|
181
|
+
capacity: talus.length,
|
|
182
|
+
parent: worldGroup,
|
|
183
|
+
place(put) {
|
|
184
|
+
for (const matrix of talus) put(matrix, C(LIME[(rng() * 4) | 0], 0.1, rng));
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// ── The cut: timbering, a track out to the tips, ore tubs, a head-frame and its windlass, and a watch-tower on the bench ──
|
|
189
|
+
const wood = new GeometryBuilder();
|
|
190
|
+
const iron = new GeometryBuilder();
|
|
191
|
+
const ore = [];
|
|
192
|
+
const mine = createMineProps({ shapes });
|
|
193
|
+
// The cut's mouth in the face at its bearing; its way out of the hill runs toward the bowl's middle.
|
|
194
|
+
const out = [-Math.cos(CUT.at), -Math.sin(CUT.at)],
|
|
195
|
+
cut = mine.frame({ x: X + Math.cos(CUT.at) * BOWL.lower, y: base, z: Z + Math.sin(CUT.at) * BOWL.lower, ahead: out });
|
|
196
|
+
const floorAt = (u, w) =>
|
|
197
|
+
groundAt(
|
|
198
|
+
X + Math.cos(CUT.at) * (BOWL.lower - u) + Math.sin(CUT.at) * w,
|
|
199
|
+
Z + Math.sin(CUT.at) * (BOWL.lower - u) - Math.cos(CUT.at) * w,
|
|
200
|
+
) - 0.1;
|
|
201
|
+
const lift = u => floorAt(u, 0) - base;
|
|
202
|
+
// Dark rock liner tucked inside the adit slot so looking through the timbering reads as a deep mine drift into the hill.
|
|
203
|
+
const adit = new GeometryBuilder();
|
|
204
|
+
const darkRock = C(0x4a4238, 0.08, rng);
|
|
205
|
+
const deepDark = [0.012, 0.011, 0.01];
|
|
206
|
+
for (const sg of [-1, 1]) cut.put(adit, -3.2, 0, sg * (CUT.half + 0.15), 0.7, 4.7, 3.6, darkRock);
|
|
207
|
+
cut.put(adit, -3.2, 4.38, 0, CUT.half * 2 + 0.8, 0.45, 3.6, darkRock);
|
|
208
|
+
cut.put(adit, -4.9, 0, 0, CUT.half * 2 + 0.6, 4.6, 0.35, deepDark);
|
|
209
|
+
adit.mesh(materials.rock, worldGroup);
|
|
210
|
+
mine.propTimbering(wood, cut, rng, { half: CUT.half - 0.15, sets: 2 });
|
|
211
|
+
const RUN = 14;
|
|
212
|
+
mine.propTrack(iron, wood, cut, rng, { run: RUN, lift, from: -1.8 });
|
|
213
|
+
for (let k = 0; k < 3; k++) {
|
|
214
|
+
const u = RUN - 3 - k * 2.6,
|
|
215
|
+
[tx, , tz] = cut.at(u, 0, 0);
|
|
216
|
+
mine.propOreTub(wood, mine.frame({ x: tx, y: base + lift(u) + 0.16, z: tz, ahead: out, yaw: cut.yaw }), rng, {
|
|
217
|
+
heap: (x, y, z, size) => ore.push(TRS(x, y, z, size * 1.4, size * 0.9, size, rng() * 6).clone()),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
mine.propHeadFrame(iron, wood, cut, rng);
|
|
221
|
+
const towerAngle = CUT.at + 0.52;
|
|
222
|
+
mine.propWatchTower(wood, { x: X + Math.cos(towerAngle) * 27, y: base + BOWL.top - 0.45, z: Z + Math.sin(towerAngle) * 27 }, rng);
|
|
223
|
+
wood.mesh(materials.wood, worldGroup);
|
|
224
|
+
iron.mesh(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.5, metalness: 0.6 }), worldGroup);
|
|
225
|
+
// the tips: cones of broken ore beyond the end of the track, in the bowl
|
|
226
|
+
for (let tip = 0; tip < 3; tip++) {
|
|
227
|
+
const [px, , pz] = cut.at(RUN + 2.5 + tip * 2.8, 0, (tip - 1) * 5),
|
|
228
|
+
peak = 1.1 + rng() * 0.6,
|
|
229
|
+
py = groundAt(px, pz);
|
|
230
|
+
for (let k = 0; k < 70; k++) {
|
|
231
|
+
const f = Math.sqrt(rng()),
|
|
232
|
+
a = rng() * Math.PI * 2,
|
|
233
|
+
size = 0.22 + rng() * 0.3;
|
|
234
|
+
ore.push(
|
|
235
|
+
TRS(
|
|
236
|
+
px + Math.cos(a) * f * 2.4,
|
|
237
|
+
py + peak * (1 - f) - size * 0.3,
|
|
238
|
+
pz + Math.sin(a) * f * 2.4,
|
|
239
|
+
size * 1.3,
|
|
240
|
+
size * 0.8,
|
|
241
|
+
size,
|
|
242
|
+
rng() * 6,
|
|
243
|
+
).clone(),
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const oreMat = new THREE.MeshStandardMaterial({ roughness: 0.85, metalness: 0.05 });
|
|
248
|
+
placeInstances({
|
|
249
|
+
geometry: shapes.rock,
|
|
250
|
+
material: oreMat,
|
|
251
|
+
capacity: ore.length,
|
|
252
|
+
parent: worldGroup,
|
|
253
|
+
place(put) {
|
|
254
|
+
for (const matrix of ore) put(matrix, [0.52 + rng() * 0.1, 0.3 + rng() * 0.06, 0.22]);
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// ── Ground cracks running out of a spring: they split outward, glow, and cool, then the ground splits again ──
|
|
259
|
+
const spring = { x: X - 64, z: Z + 30 };
|
|
260
|
+
const cracks = createGroundCracks({ parent: worldGroup, centre: spring, ground: groundAt, random: mulberry32(seed + 23) });
|
|
261
|
+
cracks.mesh.visible = true;
|
|
262
|
+
|
|
263
|
+
// ── A calm dome over a circle of stones ──
|
|
264
|
+
const circle = { x: X - 54, z: Z + 44 };
|
|
265
|
+
const stones = new GeometryBuilder();
|
|
266
|
+
for (let k = 0; k < 9; k++) {
|
|
267
|
+
const a = (k / 9) * Math.PI * 2 + 0.3,
|
|
268
|
+
sx = circle.x + Math.cos(a) * 4.6,
|
|
269
|
+
sz = circle.z + Math.sin(a) * 3.8,
|
|
270
|
+
size = 0.5 + rng() * 0.5;
|
|
271
|
+
stones.add(shapes.rock, C(LIME[k % 4], 0.1, rng), TRS(sx, groundAt(sx, sz) - size * 0.2, sz, size * 1.4, size * 0.8, size, rng() * 6));
|
|
272
|
+
}
|
|
273
|
+
stones.mesh(materials.rock, worldGroup);
|
|
274
|
+
const dome = createCalmDome({
|
|
275
|
+
parent: worldGroup,
|
|
276
|
+
radius: 6.5,
|
|
277
|
+
at: { x: circle.x, y: groundAt(circle.x, circle.z) - 0.3, z: circle.z },
|
|
278
|
+
});
|
|
279
|
+
dome.visible = true;
|
|
280
|
+
|
|
281
|
+
// ── A chain hanging between four posts ──
|
|
282
|
+
const posts = new GeometryBuilder();
|
|
283
|
+
const chain = createHangingChain({ parent: worldGroup, spans: 3 });
|
|
284
|
+
chain.begin();
|
|
285
|
+
let last = null;
|
|
286
|
+
for (let k = 0; k < 4; k++) {
|
|
287
|
+
const px = X - 74 + Math.sin(k * 1.7) * 0.6,
|
|
288
|
+
pz = Z + 40 + k * 2.8,
|
|
289
|
+
py = groundAt(px, pz),
|
|
290
|
+
top = py + 2.2;
|
|
291
|
+
posts.add(shapes.cyl6, C(0x5a4632, 0.14, rng), TRS(px, py - 0.3, pz, 0.24, top - py + 0.3, 0.24));
|
|
292
|
+
posts.add(shapes.cyl16, C(0x2a2826), TRS(px, top - 0.12, pz, 0.3, 0.06, 0.3));
|
|
293
|
+
if (last) {
|
|
294
|
+
chain.from.set(...last);
|
|
295
|
+
chain.to.set(px, top - 0.1, pz);
|
|
296
|
+
chain.addSpan();
|
|
297
|
+
}
|
|
298
|
+
last = [px, top - 0.1, pz];
|
|
299
|
+
}
|
|
300
|
+
chain.finish();
|
|
301
|
+
posts.mesh(materials.wood, worldGroup);
|
|
302
|
+
|
|
303
|
+
// ── The quay wall along a pool ──
|
|
304
|
+
const quay = new GeometryBuilder();
|
|
305
|
+
quay.ox = X + QUAY.x;
|
|
306
|
+
quay.oz = Z + QUAY.z;
|
|
307
|
+
const quayLevel = groundAt(X + QUAY.x, Z + QUAY.z);
|
|
308
|
+
createHarbourKit({ shapes }).quayWall(quay, rng, {
|
|
309
|
+
width: QUAY.width,
|
|
310
|
+
level: () => quayLevel,
|
|
311
|
+
out: 2,
|
|
312
|
+
foot: quayLevel - 3.2,
|
|
313
|
+
stone: 0xb7ae98,
|
|
314
|
+
bollards: { half: QUAY.width / 2 - 6, at: 3.5 },
|
|
315
|
+
});
|
|
316
|
+
// the mason's joints on the wall's face: a weathered mortar course and vertical joints every few metres
|
|
317
|
+
const joint = C(0x8e8676, 0.06, rng);
|
|
318
|
+
for (let x = -QUAY.width / 2 + 1.5; x < QUAY.width / 2; x += 3.2) quay.box(x, quayLevel - 2.6, 4.11, 0.06, 2.6, 0.02, joint);
|
|
319
|
+
quay.box(0, quayLevel - 1.3, 4.11, QUAY.width, 0.06, 0.02, joint);
|
|
320
|
+
quay.mesh(materials.stone, worldGroup);
|
|
321
|
+
// the pool runs out to the haze, so no far shore shows
|
|
322
|
+
const pool = createSimpleWater({ width: QUAY.width + 64, depth: 220, segs: 44, level: quayLevel - 1.4, depthAt: () => 2 });
|
|
323
|
+
pool.mesh.position.set(X + QUAY.x, 0, Z + QUAY.z + 2 + 110 + 1);
|
|
324
|
+
worldGroup.add(pool.mesh);
|
|
325
|
+
updateWater.push(pool.update);
|
|
326
|
+
|
|
327
|
+
const mouth = cut.at(0, 0, 0);
|
|
328
|
+
views.quarry = { eye: [X - 15, base + 5.6, Z + 10.5], target: [mouth[0] + 3.2, base + 6.4, mouth[2] + 1.5] };
|
|
329
|
+
views.mine = { eye: [X - 4.5, base + 3.0, Z + 3.5], target: [mouth[0], base + 3.8, mouth[2]] };
|
|
330
|
+
views.cracks = { eye: [X - 94, base + 10.8, Z + 71], target: [X - 60, base + 1.4, Z + 40] };
|
|
331
|
+
views.quay = { eye: [X - 16, base + 3.2, Z + 64 + 22], target: [X + 14, base + 0.5, Z + 64 + 2] }; // from the water, looking east along the quay wall
|
|
332
|
+
|
|
333
|
+
const LOOP = 10; // seconds: the ground splits, the cracks run, glow for four seconds and cool, then it splits again
|
|
334
|
+
return {
|
|
335
|
+
views,
|
|
336
|
+
floorAt: (x, z) => quarryMoundHeight(x - X, z - Z, groundAt, base, noise.fbm),
|
|
337
|
+
update(t) {
|
|
338
|
+
const since = t % LOOP;
|
|
339
|
+
cracks.front.value = Math.min(since * 9, 60);
|
|
340
|
+
cracks.heat.value = 1 - smooth((since - 4) / 4);
|
|
341
|
+
for (const tick of updateWater) tick(t);
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
}
|
package/examples/set-pieces.html
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
<body>
|
|
21
21
|
<canvas
|
|
22
22
|
tabindex="0"
|
|
23
|
-
aria-label="Sandstone outcrops draped with branching roots, a cascading stone fountain, a fractured glacial ice cliff, a crystal cavern,
|
|
23
|
+
aria-label="Sandstone outcrops draped with branching roots, a cascading stone fountain, a fractured glacial ice cliff, a crystal cavern, a field camp beside a rising dust curtain, and a quarry bowl with a timbered mine cut, glowing ground cracks, a calm dome, a hanging chain and a quay wall"
|
|
24
24
|
></canvas>
|
|
25
25
|
<header>
|
|
26
26
|
<a class="back" href="../index.html"><span aria-hidden="true">←</span> Roamwright</a>
|
|
@@ -36,7 +36,9 @@
|
|
|
36
36
|
<footer>
|
|
37
37
|
<div class="caption">
|
|
38
38
|
<h1>Set pieces</h1>
|
|
39
|
-
<p>
|
|
39
|
+
<p>
|
|
40
|
+
Outcrops, roots, fountains, ice cliffs, grottos, camps, a quarry and its mine, glowing cracks, a calm dome, a chain and a quay.
|
|
41
|
+
</p>
|
|
40
42
|
</div>
|
|
41
43
|
<div class="tools">
|
|
42
44
|
<div class="views" role="group" aria-label="Camera viewpoint">
|
|
@@ -44,6 +46,10 @@
|
|
|
44
46
|
<button type="button" data-view="glacier" aria-pressed="false">Ice cliff</button>
|
|
45
47
|
<button type="button" data-view="grotto" aria-pressed="false">Crystal grotto</button>
|
|
46
48
|
<button type="button" data-view="camp" aria-pressed="false">Camp & storm</button>
|
|
49
|
+
<button type="button" data-view="quarry" aria-pressed="false">Quarry bowl</button>
|
|
50
|
+
<button type="button" data-view="mine" aria-pressed="false">Mine works</button>
|
|
51
|
+
<button type="button" data-view="cracks" aria-pressed="false">Cracks & dome</button>
|
|
52
|
+
<button type="button" data-view="quay" aria-pressed="false">Quay wall</button>
|
|
47
53
|
</div>
|
|
48
54
|
</div>
|
|
49
55
|
</footer>
|
package/examples/set-pieces.js
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
createIceSheetTexture,
|
|
25
25
|
createOrbitCamera,
|
|
26
26
|
createSpotFrame,
|
|
27
|
+
createStormSilhouetteMaterial,
|
|
27
28
|
growRootBranch,
|
|
28
29
|
mulberry32,
|
|
29
30
|
placeInstances,
|
|
@@ -31,6 +32,7 @@ import {
|
|
|
31
32
|
import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
|
|
32
33
|
import { C, TRS } from 'roamwright/geometry/primitives.js';
|
|
33
34
|
import { createProps } from 'roamwright/geometry/props.js';
|
|
35
|
+
import { buildWorks, quayBasinHeight, WORKS } from './set-pieces-works.js';
|
|
34
36
|
import { initExample } from './stage.js';
|
|
35
37
|
|
|
36
38
|
const { canvas, renderer, camera, scene, worldGroup, seed, noise, hash, shapes } = initExample({
|
|
@@ -39,7 +41,9 @@ const { canvas, renderer, camera, scene, worldGroup, seed, noise, hash, shapes }
|
|
|
39
41
|
});
|
|
40
42
|
const rng = mulberry32(seed * 97 + 13);
|
|
41
43
|
|
|
42
|
-
const
|
|
44
|
+
const openGround = (x, z) => 0.55 * noise.fbm(x * 0.014, z * 0.014, 3, 21) + 0.12 * Math.sin(x * 0.04) * Math.cos(z * 0.035);
|
|
45
|
+
// the works' pool lies in a basin beyond its quay wall
|
|
46
|
+
const groundAt = (x, z) => quayBasinHeight(x, z, openGround(x, z));
|
|
43
47
|
|
|
44
48
|
// Warm canyon floor spanning all four showcase zones.
|
|
45
49
|
const floorLow = new THREE.Color(0xc2a882);
|
|
@@ -250,6 +254,43 @@ const dustCurtain = createDustCurtain({
|
|
|
250
254
|
around: 56,
|
|
251
255
|
up: 10,
|
|
252
256
|
});
|
|
257
|
+
// A far outcrop reads through moving dust at the edge of the camp.
|
|
258
|
+
const stormRock = new GeometryBuilder();
|
|
259
|
+
const stormRockX = 71;
|
|
260
|
+
const stormRockZ = 49;
|
|
261
|
+
buildOutcrop(
|
|
262
|
+
stormRock,
|
|
263
|
+
(x, z) => groundAt(stormRockX + x, stormRockZ + z),
|
|
264
|
+
{
|
|
265
|
+
x: 0,
|
|
266
|
+
z: 0,
|
|
267
|
+
rx: 9,
|
|
268
|
+
rz: 6,
|
|
269
|
+
h: 16,
|
|
270
|
+
beds: 4,
|
|
271
|
+
seed: seed + 29,
|
|
272
|
+
},
|
|
273
|
+
rockOpts,
|
|
274
|
+
);
|
|
275
|
+
const silhouette = stormRock.mesh(
|
|
276
|
+
createStormSilhouetteMaterial({ show: dustCurtain.material.uniforms.uShow, time: dustCurtain.material.uniforms.uTime }),
|
|
277
|
+
worldGroup,
|
|
278
|
+
false,
|
|
279
|
+
);
|
|
280
|
+
silhouette.position.set(stormRockX, 0, stormRockZ);
|
|
281
|
+
silhouette.updateMatrix();
|
|
282
|
+
silhouette.renderOrder = dustCurtain.mesh.renderOrder - 1;
|
|
283
|
+
|
|
284
|
+
// ── 5. The works (east-south-east, x = 170, z = 110): a quarry bowl, a timbered cut with its mine works, cracks, a calm dome, a chain and a quay ──
|
|
285
|
+
const works = buildWorks({
|
|
286
|
+
worldGroup,
|
|
287
|
+
groundAt,
|
|
288
|
+
shapes,
|
|
289
|
+
noise,
|
|
290
|
+
hash,
|
|
291
|
+
seed,
|
|
292
|
+
materials: { rock: rockMat, wood: woodMat, stone: stoneMat },
|
|
293
|
+
});
|
|
253
294
|
|
|
254
295
|
// ── Camera viewpoints and animation loop ──
|
|
255
296
|
const VIEWS = {
|
|
@@ -257,6 +298,7 @@ const VIEWS = {
|
|
|
257
298
|
glacier: { eye: [-113, 8.5, 14], target: [-125, 6, -20] },
|
|
258
299
|
grotto: { eye: [120, grottoFloor + 3.2, grottoZ + 9.2], target: [120, grottoFloor + 3.2, grottoZ - 3.5] },
|
|
259
300
|
camp: { eye: [22, 11.5, 96], target: [52, 3.2, 66] },
|
|
301
|
+
...works.views,
|
|
260
302
|
};
|
|
261
303
|
|
|
262
304
|
createOrbitCamera({
|
|
@@ -266,7 +308,11 @@ createOrbitCamera({
|
|
|
266
308
|
scene,
|
|
267
309
|
views: VIEWS,
|
|
268
310
|
initialView: 'outcrops',
|
|
269
|
-
groundAt: (x, z) =>
|
|
311
|
+
groundAt: (x, z) => {
|
|
312
|
+
if (Math.hypot(x - grottoX, z - grottoZ) < 18) return grottoFloor;
|
|
313
|
+
if (Math.hypot(x - WORKS.x, z - WORKS.z) < 50) return works.floorAt(x, z);
|
|
314
|
+
return groundAt(x, z);
|
|
315
|
+
},
|
|
270
316
|
minClearance: 1.5,
|
|
271
317
|
minDistance: 8,
|
|
272
318
|
maxDistance: 220,
|
|
@@ -278,6 +324,7 @@ function frameLoop(ms) {
|
|
|
278
324
|
const t = ms / 1000;
|
|
279
325
|
waterFalls.setTime(t);
|
|
280
326
|
dustCurtain.update(t, 0.85, 0.9);
|
|
327
|
+
works.update(t);
|
|
281
328
|
renderer.render(scene, camera);
|
|
282
329
|
requestAnimationFrame(frameLoop);
|
|
283
330
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ground rent by cracks running out from a point (`groundCrackArrays`): each crack a walk outward that wanders and now and
|
|
3
|
+
* then forks, laid on the ground as a dark gash between two pale, lifted lips. Along each vertex run its metres from the point
|
|
4
|
+
* and its place across the crack (0 in the gash, 1 at a lip), so the material can draw the crack only as far as it has split and
|
|
5
|
+
* glow in its gash. Worker-safe.
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { lerp, TAU } from '../math/scalar.js';
|
|
10
|
+
import { mulberry32 } from '../math/random.js';
|
|
11
|
+
|
|
12
|
+
/** Default shape of a rent in the ground: how many cracks run out, how far, and the colours of its crust and gash. */
|
|
13
|
+
export const GROUND_CRACK_SHAPE = Object.freeze({
|
|
14
|
+
cracks: 16, // cracks running out from the point
|
|
15
|
+
step: 0.7, // metres to a piece of a crack
|
|
16
|
+
reach: Object.freeze([12, 34]), // metres the shortest and longest crack runs
|
|
17
|
+
lip: Object.freeze([0.42, 0.32, 0.2]), // linear RGB: the broken crust, faded into the ground round it
|
|
18
|
+
gash: Object.freeze([0.05, 0.04, 0.03]), // linear RGB: the dark of the gash
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Lay the vertices of cracks running out from `centre` on the ground.
|
|
23
|
+
*
|
|
24
|
+
* @param {object} [options]
|
|
25
|
+
* @param {{ x: number, z: number }} [options.centre={ x: 0, z: 0 }] - The point the cracks run out from, in metres.
|
|
26
|
+
* @param {(x: number, z: number) => number} [options.ground=() => 0] - The ground's height at a point, in metres.
|
|
27
|
+
* @param {() => number} [options.random=mulberry32(1)] - The random source the walks draw from.
|
|
28
|
+
* @param {number} [options.cracks=GROUND_CRACK_SHAPE.cracks] - How many cracks run out.
|
|
29
|
+
* @param {number} [options.step=GROUND_CRACK_SHAPE.step] - Metres to a piece of a crack.
|
|
30
|
+
* @param {[number, number]} [options.reach=GROUND_CRACK_SHAPE.reach] - Metres the shortest and longest crack runs.
|
|
31
|
+
* @param {number[]} [options.lip=GROUND_CRACK_SHAPE.lip] - Linear RGB of the broken crust.
|
|
32
|
+
* @param {number[]} [options.gash=GROUND_CRACK_SHAPE.gash] - Linear RGB of the gash.
|
|
33
|
+
* @returns {{ position: Float32Array, color: Float32Array, crack: Float32Array }} Three vertices a triangle (`position` and
|
|
34
|
+
* `color` with three numbers each, `crack` with two), wound to face up.
|
|
35
|
+
*/
|
|
36
|
+
export function groundCrackArrays({
|
|
37
|
+
centre = { x: 0, z: 0 },
|
|
38
|
+
ground = () => 0,
|
|
39
|
+
random = mulberry32(1),
|
|
40
|
+
cracks = GROUND_CRACK_SHAPE.cracks,
|
|
41
|
+
step = GROUND_CRACK_SHAPE.step,
|
|
42
|
+
reach = GROUND_CRACK_SHAPE.reach,
|
|
43
|
+
lip = GROUND_CRACK_SHAPE.lip,
|
|
44
|
+
gash = GROUND_CRACK_SHAPE.gash,
|
|
45
|
+
} = {}) {
|
|
46
|
+
const pos = [],
|
|
47
|
+
col = [],
|
|
48
|
+
crack = [],
|
|
49
|
+
walk = (x, z, a, from, run, wide) => {
|
|
50
|
+
for (let d = 0; d < run; d += step) {
|
|
51
|
+
a += (random() - 0.5) * 0.7;
|
|
52
|
+
const nx = x + Math.cos(a) * step,
|
|
53
|
+
nz = z + Math.sin(a) * step,
|
|
54
|
+
w0 = wide * (1 - d / run) + 0.02,
|
|
55
|
+
w1 = wide * (1 - (d + step) / run) + 0.02;
|
|
56
|
+
piece(x, z, nx, nz, from + d, from + d + step, w0, w1);
|
|
57
|
+
if (random() < 0.06 && run - d > 4)
|
|
58
|
+
walk(nx, nz, a + (random() < 0.5 ? -1 : 1) * (0.5 + random() * 0.5), from + d, (run - d) * 0.6, w1 * 0.7);
|
|
59
|
+
x = nx;
|
|
60
|
+
z = nz;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
piece = (ax, az, bx, bz, da, db, wa, wb) => {
|
|
64
|
+
const len = Math.hypot(bx - ax, bz - az) || 1,
|
|
65
|
+
sx = -(bz - az) / len,
|
|
66
|
+
sz = (bx - ax) / len,
|
|
67
|
+
// across a cross-section: lip, gash, gash, lip; the lips stand a little proud where the crust heaved
|
|
68
|
+
at = (x, z, w, d) =>
|
|
69
|
+
[-1, -0.3, 0.3, 1].map(k => {
|
|
70
|
+
const px = x + sx * w * k * 1.6,
|
|
71
|
+
pz = z + sz * w * k * 1.6;
|
|
72
|
+
return [px, ground(px, pz) + (Math.abs(k) === 1 ? 0.06 : 0.03) + w * 0.15, pz, d, Math.abs(k) === 1 ? 1 : 0];
|
|
73
|
+
}),
|
|
74
|
+
A = at(ax, az, wa, da),
|
|
75
|
+
B = at(bx, bz, wb, db);
|
|
76
|
+
for (let s = 0; s < 3; s++)
|
|
77
|
+
for (const p of [A[s], B[s + 1], B[s], A[s], A[s + 1], B[s + 1]]) {
|
|
78
|
+
// wound to face up
|
|
79
|
+
pos.push(p[0], p[1], p[2]);
|
|
80
|
+
col.push(...(p[4] ? lip : gash));
|
|
81
|
+
crack.push(p[3], p[4]);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
for (let k = 0; k < cracks; k++) {
|
|
85
|
+
const a = (k / cracks) * TAU + (random() - 0.5) * 0.3,
|
|
86
|
+
r = 3 + random();
|
|
87
|
+
walk(centre.x + Math.cos(a) * r, centre.z + Math.sin(a) * r, a, 0, lerp(reach[0], reach[1], random() ** 1.5), 0.07 + random() * 0.07);
|
|
88
|
+
}
|
|
89
|
+
return { position: new Float32Array(pos), color: new Float32Array(col), crack: new Float32Array(crack) };
|
|
90
|
+
}
|