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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Procedural harbour works kit beside the ship kit and breakwater seawall: stone quayside aprons, coping, bollards,
3
- * mooring rings and water stairs (`quayside`), walkable quay decks (`quayDeck`), timber piers on piles (`pier`), working
3
+ * mooring rings and water stairs (`quayside`), straight waterfront walls with bollards (`quayWall`), walkable quay decks (`quayDeck`), timber piers on piles (`pier`), working
4
4
  * harbour gear with cranes, cargo, drying nets and moored/anchored craft (`harbourGear`), waterfront warehouse and shop
5
5
  * rows with passages and landed cargo stacks (`harbourStores`), quay approach furniture including gate, toll booth,
6
6
  * standards, drying nets, carved stone loads and palms (`harbourLanding`), fortified naval fleet dockyards with moored
@@ -122,6 +122,7 @@ export function quayDeck(frame, half, top, apron = HARBOUR_WATERFRONT.apron) {
122
122
  * craneX: (x: number, half: number) => number,
123
123
  * quayside: (gb: object, rng: () => number, half: number, top: number, stone: number, stairX: number) => void,
124
124
  * quayDeck: (frame: object, half: number, top: number) => object,
125
+ * quayWall: (gb: object, rng: () => number, spec: { width: number, level: (x: number) => number, stone: number, out?: number, foot?: number, depth?: number, over?: number, bollards?: { half?: number, step?: number, at?: number, size?: number, height?: number, tone?: number } }) => void,
125
126
  * pier: (wd: object, rng: () => number, frame: object, x: number, len: number, top: number) => object,
126
127
  * harbourGear: (kit: object, rng: () => number, frame: object, x0: number, x1: number, top: number, sea: number, opts: object) => Array<object>,
127
128
  * harbourStores: (K: object, rng: () => number, plan: object) => void,
@@ -215,6 +216,17 @@ export function createHarbourKit(options = {}) {
215
216
  return { x: cx, z: cz, hx: pierWidth / 2, hz: (len - 2.2) / 2 + 0.6, c: Math.cos(frame.yaw), s: Math.sin(frame.yaw), y: top - 0.07 };
216
217
  }
217
218
 
219
+ // A straight waterfront wall with bollards along its coping, in a port's frame (x along the quay, +z out over the water): the
220
+ // wall from its foot up to `over` past the level at its middle, and a bollard every `step` metres with its foot on the level where
221
+ // it stands, so the row follows the ground as it falls to the water. The wall's stone is drawn first, then a bollard's, in turn.
222
+ function quayWall(gb, rng, { width, level, out = 2, foot = -3, depth = 4.2, over = 0.05, stone, bollards = {} }) {
223
+ const { half = width / 2 - bollardFrom, step = 9, at = 0, size = 0.5, height = 0.6, tone = 0.7 } = bollards;
224
+ const lift = over - foot; // the wall's height: from its foot to its coping
225
+ gb.box(0, foot, out, width, level(0) + lift, depth, dim(color(stone, 0.06, rng), 0.8));
226
+ for (let x = -half; x <= half; x += step)
227
+ gb.add(shapes.cyl6, dim(color(stone, 0.06, rng), tone), transform(x, level(x), at, size, height, size));
228
+ }
229
+
218
230
  // Working gear along a quay between `x0` and `x1`: cranes between bollards, apron cargo and drying nets, plus fishing boats
219
231
  // moored alongside and vessels riding at anchor offshore.
220
232
  function harbourGear(kit, rng, frame, x0, x1, top, sea, { half, spare = () => false, stairX, anchorage = [70, 150] }) {
@@ -358,6 +370,7 @@ export function createHarbourKit(options = {}) {
358
370
  craneX: snapCraneX,
359
371
  quayside,
360
372
  quayDeck: deckForQuay,
373
+ quayWall,
361
374
  pier,
362
375
  harbourGear,
363
376
  harbourStores,
package/geometry/index.js CHANGED
@@ -30,6 +30,8 @@ export {
30
30
  domeReach,
31
31
  } from './cavern-rock.js';
32
32
  export { BEDDED_BUTTE_DEFAULTS, ESCARPMENT_CLIFF_DEFAULTS, createBeddedButte, createEscarpmentCliff } from './cliff-sheets.js';
33
+ export { QUARRY_FACE_DEFAULTS, buildQuarryFace, defaultQuarryNoise } from './quarry-face.js';
34
+ export { MINE_PROPS_DEFAULTS, createMineProps } from './prop-mine.js';
33
35
  export {
34
36
  ICE_CLIFF_DEFAULTS,
35
37
  buildIceCliffSheet,
@@ -204,6 +206,7 @@ export { farCrowdFigure } from './crowd-far.js';
204
206
  // ── Effects, audio, pacing & runtime ─────────────────────────────────────
205
207
  export { STORM_WALL_DEFAULTS, stormWallArrays } from './storm-wall.js';
206
208
  export { DUST_CURTAIN_SHAPE, dustCurtainArrays } from './curtain-sheets.js';
209
+ export { GROUND_CRACK_SHAPE, groundCrackArrays } from './ground-cracks.js';
207
210
  export { CAMP_DEFAULTS, buildTentLines, buildWagonLine } from './camp-layout.js';
208
211
 
209
212
  // ── Scene playback, melee, projectiles, beams, props & markers ───────────
@@ -0,0 +1,316 @@
1
+ /**
2
+ * The works of a mine (`createMineProps`), bound to a world's unit shapes: the frame its works stand in (`frame`: a drift's mouth,
3
+ * `u` metres out of it toward the tip, `v` over its floor, `w` across it); the timbering down a drift (`propTimbering`: sets of two
4
+ * legs and a cap, each a little out of true, with lagging boards overhead); the rail track out to the tip (`propTrack`: sleepers and
5
+ * two iron straps, laid on the ground as it lies); an ore tub on four iron wheels, heaped through the world's own ore
6
+ * (`propOreTub`); a head-frame over a shaft's mouth with its winding wheel, rope and windlass (`propHeadFrame`); and a timber
7
+ * watch-tower (`propWatchTower`). Every dimension is in metres in {@link MINE_PROPS_DEFAULTS}, so a world reads and changes them
8
+ * by name. Worker-safe.
9
+ * @module
10
+ */
11
+
12
+ import * as THREE from 'three';
13
+ import { dim } from '../math/color.js';
14
+ import { C, TRS, defaultUnitShapes, stick } from './primitives.js';
15
+
16
+ /** Default proportions and materials of a mine's works (metres, sRGB hex, linear RGB and radians). */
17
+ export const MINE_PROPS_DEFAULTS = Object.freeze({
18
+ timber: 0x4a3828, // sRGB hex of the mine's wet, dark timber
19
+ timberJitter: 0.14, // how much each beam's tone varies
20
+ plank: 0x5a4632, // sRGB hex of an ore tub's planks
21
+ iron: Object.freeze([0.05, 0.045, 0.04]), // linear RGB of the straps, the wheels and the winding wheel
22
+ rope: 0x8a7a5a, // sRGB hex of a winding rope
23
+ timbering: Object.freeze({
24
+ sets: 5, // sets of props down a drift
25
+ first: -0.4, // metres from the mouth to the first set (inside the drift)
26
+ step: 2.3, // metres between the sets
27
+ legInset: 0.9, // metres each leg stands in from the drift's wall
28
+ leg: 0.36, // a leg's section
29
+ legHeight: 4.1, // a set's legs
30
+ lean: 0.05, // radians each leg leans, out of true
31
+ capRise: 3.95, // metres over the floor the cap lies
32
+ cap: 0.4, // the cap's section
33
+ capShort: 1, // metres a cap falls short of the drift's full width
34
+ capSkew: 0.03, // radians a cap is turned, out of true
35
+ laggingBack: 1.1, // metres further in the lagging boards lie
36
+ laggingRise: 4.3, // metres over the floor they lie
37
+ laggingAcross: 1.7, // metres either side of the middle, a board's middle
38
+ board: Object.freeze([3.2, 0.07, 2.3]), // a lagging board's length, thickness and reach across
39
+ boardShade: 0.8, // how much a board's tone is dimmed
40
+ }),
41
+ track: Object.freeze({
42
+ from: -8, // metres from the mouth the track begins (inside the drift)
43
+ sleeper: 1.1, // metres from one sleeper to the next
44
+ sleeperSize: Object.freeze([1.7, 0.1, 0.24]), // a sleeper's length across, thickness and width along
45
+ sleeperLift: 0.02, // metres a sleeper lies over the ground
46
+ sleeperSkew: 0.08, // radians a sleeper is turned, out of true
47
+ sleeperShade: 0.7, // how much a sleeper's tone is dimmed
48
+ railLength: 4.4, // metres: each iron strap's length
49
+ rail: 0.07, // a strap's section
50
+ railRise: 0.11, // metres a strap lies over its sleepers
51
+ gauge: 0.5, // metres from the track's middle to a strap
52
+ railOver: 0.02, // metres a strap runs past its sleepers
53
+ }),
54
+ tub: Object.freeze({
55
+ floor: Object.freeze([0.22, 1.2, 0.1, 1.9]), // the floor's rise over the rails, width, thickness and length
56
+ side: Object.freeze([0.3, 0.56, 0.07, 0.72, 1.9, 0.14]), // a side's rise, offset, thickness, height, length and lean
57
+ end: Object.freeze([0.93, 0.3, 1.16, 0.72, 0.07, 0.1]), // an end's offset, rise, width, height, thickness and lean
58
+ wheel: Object.freeze([0.6, 0.24, 0.5, 0.44, 0.07, 0.44]), // a wheel's place along and across, its rise, radius and width
59
+ axle: Object.freeze([0.93, 0.3, 0.56, 0.1, 0.74, 0.05]), // an axle box's place and size
60
+ heapAlong: 0.32, // metres between the lumps of the load along the tub
61
+ heapAcross: 0.27, // metres between them across
62
+ heapRise: 1.04, // metres the load stands over the rails at its middle
63
+ heapFall: 0.045, // metres it falls per place from the middle
64
+ heapScatter: 0.1, // metres a lump wanders from its place
65
+ lump: Object.freeze([0.17, 0.09]), // a lump's size and how much it varies
66
+ }),
67
+ headFrame: Object.freeze({
68
+ crown: Object.freeze([2.2, 9.2, 1.2]), // the crown's place out of the mouth, its height and half width
69
+ leg: Object.freeze([7, 0, 3.6]), // a raking leg's foot: out of the mouth, over the floor, half width apart
70
+ legRadius: 0.2,
71
+ back: Object.freeze([-0.6, 4.4, 3.4]), // a back stay's foot
72
+ backRadius: 0.18,
73
+ brace: Object.freeze([5, 3.6, 2.7, 0.6, 6.2, 2.6]), // a brace's foot and head
74
+ braceRadius: 0.12,
75
+ beam: Object.freeze([2.2, 9.1, 0, 3.2, 0.32, 0.32]), // the crown beam
76
+ wheel: Object.freeze([2.2, 8.2]), // the winding wheel's place: out of the mouth, its height
77
+ wheelSize: Object.freeze([0.9, 0.09]), // its ring and rim
78
+ spokes: 6,
79
+ spokeStep: 1.047, // radians between the spokes, a sixth of a turn as the wheel was drawn
80
+ rope: Object.freeze([1.3, 3.1]), // where the rope leaves the wheel, down the drift and out to the windlass
81
+ ropeRadius: 0.035,
82
+ ropeDown: Object.freeze([-7, 2.2, 0]), // the rope's end down the drift
83
+ ropeOut: Object.freeze([11, 0.9, 4.5]), // the rope's end at the windlass
84
+ windlass: Object.freeze([11, 0, 4.5, 0.9, 0.3, 1.2]), // the windlass's trestles: out of the mouth, over the floor, across, apart, section, height
85
+ drum: Object.freeze([11, 0.65, 5.4, 0.5, 1.8]), // its drum: out, over, across to the starting trestle, diameter, length
86
+ }),
87
+ tower: Object.freeze({
88
+ timber: 0x54402c, // sRGB hex of a watch-tower's timber
89
+ height: 7.5, // metres: its platform over the ground
90
+ foot: Object.freeze([1.9, 0.3]), // metres out from the middle each leg stands at the ground, and how far it is buried
91
+ head: Object.freeze([1.25, 2.3]), // metres out from the middle each leg reaches the roof, and the roof's rise over the platform
92
+ legRadius: 0.14,
93
+ brace: Object.freeze([1.8, 0.6, 1.5, 3.8, 1.55]), // a brace's foot (out, rise) and head (out, rise, across)
94
+ braceRadius: 0.07,
95
+ railRise: 0.9, // metres the platform's rail stands over it
96
+ railInset: 1.3, // metres in from the middle each rail lies
97
+ rail: Object.freeze([0.08, 0.1, 2.7]), // a rail's section and length
98
+ platform: Object.freeze([3.1, 0.14]), // the platform's width and thickness
99
+ roof: Object.freeze([3.9, 0.1, 0.14]), // the roof's width, thickness and tilt
100
+ roofShade: 0.8, // how much the roof's tone is dimmed
101
+ ladder: Object.freeze([0.28, 2.5, 1.6]), // its rails' half spacing, foot out from the middle, head in from it
102
+ ladderRadius: 0.045,
103
+ rung: Object.freeze([0.5, 0.06, 0.6, 0.05]), // rungs every so far, each leaning in a little, with its width and section
104
+ rungs: 14, // rungs up the ladder
105
+ }),
106
+ });
107
+
108
+ let sharedWheel = null;
109
+ // The winding wheel's ring, made once and shared by every head-frame on a page.
110
+ const wheelGeometry = () =>
111
+ (sharedWheel ??= new THREE.TorusGeometry(MINE_PROPS_DEFAULTS.headFrame.wheelSize[0], MINE_PROPS_DEFAULTS.headFrame.wheelSize[1], 6, 18));
112
+
113
+ /**
114
+ * Create a mine's prop builders, bound to a world's shapes, colour and transform.
115
+ *
116
+ * @param {object} [options]
117
+ * @param {object} [options.shapes] - The unit shapes (`createUnitShapes`: `box`, `cyl16` and, through `stick`, `cyl6`).
118
+ * @param {(hex: number, jitter?: number, rng?: () => number) => number[]} [options.color] - Linear RGB colour helper.
119
+ * @param {Function} [options.transform] - Transform matrix helper (`TRS`).
120
+ * @returns {{ frame: Function, propTimbering: Function, propTrack: Function, propOreTub: Function, propHeadFrame: Function, propWatchTower: Function }}
121
+ * The mine's prop builders, each documented at its definition.
122
+ */
123
+ export function createMineProps({ shapes = defaultUnitShapes(), color = C, transform = TRS } = {}) {
124
+ const D = MINE_PROPS_DEFAULTS,
125
+ iron = D.iron;
126
+
127
+ /**
128
+ * A drift's mouth and the frame its works stand in.
129
+ *
130
+ * @param {{ x: number, y: number, z: number, ahead: [number, number], yaw?: number }} mouth - The mouth's place (its floor at
131
+ * `y`), `ahead` the way out of it toward the tip (a unit vector), and `yaw` the frame's turn where it is not the way's own.
132
+ * @returns {{ at: (u: number, v: number, w: number) => [number, number, number], put: (b: object, u: number, v: number, w: number, sx: number, sy: number, sz: number, col: number[], ry?: number, rz?: number) => void, yaw: number }}
133
+ * `at(u, v, w)`: a point `u` metres out of the mouth, `v` over its floor, `w` across it; `put`: a box of that size and colour
134
+ * there, turned `ry` and `rz` from the frame; `yaw`: the frame's turn.
135
+ */
136
+ function frame({ x, y, z, ahead, yaw }) {
137
+ const [fx, fz] = ahead,
138
+ turned = yaw ?? Math.atan2(fx, fz);
139
+ const at = (u, v, w) => [x + fx * u + fz * w, y + v, z + fz * u - fx * w];
140
+ const put = (b, u, v, w, sx, sy, sz, col, ry = 0, rz = 0) =>
141
+ b.add(shapes.box, col, transform(...at(u, v, w), sx, sy, sz, turned + ry, 0, rz));
142
+ return { at, put, yaw: turned };
143
+ }
144
+
145
+ /**
146
+ * The timbering down a drift: sets of two legs and a cap, each a little out of true, with lagging boards overhead. Each beam's
147
+ * tone is drawn from `random` as it is set, so a world's other draws keep their order.
148
+ *
149
+ * @param {object} wd - The timber builder.
150
+ * @param {{ put: Function }} drift - The drift's frame (`frame`).
151
+ * @param {() => number} random - The random source the tones draw from.
152
+ * @param {{ half: number, sets?: number }} options - The drift's half width in metres, and how many sets stand down it.
153
+ * @returns {void}
154
+ */
155
+ function propTimbering(wd, { put }, random, { half, sets = D.timbering.sets }) {
156
+ const T = D.timbering,
157
+ beam = () => color(D.timber, D.timberJitter, random);
158
+ for (let k = 0; k < sets; k++) {
159
+ const u = T.first - k * T.step;
160
+ for (const sg of [-1, 1]) put(wd, u, 0, sg * (half - T.legInset), T.leg, T.legHeight, T.leg, beam(), 0, sg * -T.lean);
161
+ put(wd, u, T.capRise, 0, 2 * half - T.capShort, T.cap, T.cap, beam(), 0, (random() - 0.5) * T.capSkew);
162
+ for (const sg of [-1, 1])
163
+ put(wd, u - T.laggingBack, T.laggingRise, sg * T.laggingAcross, T.board[0], T.board[1], T.board[2], dim(beam(), T.boardShade));
164
+ }
165
+ }
166
+
167
+ /**
168
+ * The rail track out of a drift: sleepers every so often, two iron straps on them, laid on the ground as it lies.
169
+ *
170
+ * @param {object} gb - The iron builder.
171
+ * @param {object} wd - The timber builder.
172
+ * @param {{ at: Function, put: Function }} drift - The drift's frame (`frame`).
173
+ * @param {() => number} random - The random source the sleepers' tones draw from.
174
+ * @param {{ run: number, lift: (u: number) => number, from?: number, turn?: number }} options - How far out the track runs (metres),
175
+ * the ground's height over the floor at `u` metres out, where the track begins, and how far a sleeper is turned from across the
176
+ * track (radians; a sleeper lies across it, under both straps).
177
+ * @returns {void}
178
+ */
179
+ function propTrack(gb, wd, { put }, random, { run, lift, from = D.track.from, turn = 0 }) {
180
+ const K = D.track,
181
+ beam = () => color(D.timber, D.timberJitter, random);
182
+ for (let u = from; u < run; u += K.sleeper)
183
+ put(
184
+ wd,
185
+ u,
186
+ lift(u) + K.sleeperLift,
187
+ 0,
188
+ K.sleeperSize[0],
189
+ K.sleeperSize[1],
190
+ K.sleeperSize[2],
191
+ dim(beam(), K.sleeperShade),
192
+ turn + (random() - 0.5) * K.sleeperSkew,
193
+ );
194
+ for (let u = from; u < run; u += K.railLength) {
195
+ const v = (lift(u) + lift(u + K.railLength)) / 2; // a strap lies level on its sleepers: the floor rises a few centimetres along one
196
+ for (const sg of [-1, 1])
197
+ put(gb, u + K.railLength / 2, v + K.railRise, sg * K.gauge, K.rail, K.rail, K.railLength + K.railOver, iron);
198
+ }
199
+ }
200
+
201
+ /**
202
+ * An ore tub on its four iron wheels, heaped with ore: it stands at the frame's origin, its length along the frame's way.
203
+ *
204
+ * @param {object} wd - The timber builder (its planks and axle boxes).
205
+ * @param {{ at: Function, yaw: number }} place - The tub's frame (`frame` at the tub's place on the rails).
206
+ * @param {() => number} random - The random source the planks' tones and the load draw from.
207
+ * @param {{ heap: (x: number, y: number, z: number, size: number, random: () => number) => void }} options - How the world lays a
208
+ * lump of its own ore at a point of the given size.
209
+ * @returns {void}
210
+ */
211
+ function propOreTub(wd, { at, yaw }, random, { heap }) {
212
+ const B = D.tub,
213
+ plank = () => color(D.plank, D.timberJitter, random);
214
+ wd.box(...at(0, B.floor[0], 0), B.floor[1], B.floor[2], B.floor[3], plank(), yaw);
215
+ for (const sg of [-1, 1]) {
216
+ wd.add(shapes.box, plank(), transform(...at(0, B.side[0], sg * B.side[1]), B.side[2], B.side[3], B.side[4], yaw, 0, sg * -B.side[5]));
217
+ wd.add(shapes.box, plank(), transform(...at(sg * B.end[0], B.end[1], 0), B.end[2], B.end[3], B.end[4], yaw, sg * B.end[5]));
218
+ for (const e of [-1, 1]) {
219
+ wd.add(
220
+ shapes.cyl16,
221
+ iron,
222
+ transform(...at(e * B.wheel[0], B.wheel[1], sg * B.wheel[2]), B.wheel[3], B.wheel[4], B.wheel[3], yaw, 0, Math.PI / 2),
223
+ );
224
+ wd.box(...at(e * B.axle[0], B.axle[1], sg * B.axle[2]), B.axle[3], B.axle[4], B.axle[5], iron, yaw);
225
+ }
226
+ }
227
+ for (let u = -2; u <= 2; u++)
228
+ for (let w = -1; w <= 1; w++) {
229
+ const fill = B.heapRise - B.heapFall * (Math.abs(u) + Math.abs(w));
230
+ heap(...at(u * B.heapAlong + (random() - 0.5) * B.heapScatter, fill, w * B.heapAcross), B.lump[0] + random() * B.lump[1], random);
231
+ }
232
+ }
233
+
234
+ /**
235
+ * The head-frame over a shaft's mouth: two raking legs each side, a crown beam, the winding wheel and its rope down the drift and
236
+ * out to a windlass on two trestles.
237
+ *
238
+ * @param {object} gb - The iron builder (the wheel, its spokes).
239
+ * @param {object} wd - The timber builder (the frame, the windlass) and the rope.
240
+ * @param {{ at: Function, put: Function, yaw: number }} drift - The shaft's frame (`frame`).
241
+ * @param {() => number} random - The random source the beams' tones draw from.
242
+ * @param {{ drumAcross?: number }} [options] - Where the drum starts across the drift, in metres. It extends toward the track.
243
+ * @returns {void}
244
+ */
245
+ function propHeadFrame(gb, wd, { at, put, yaw }, random, { drumAcross = D.headFrame.drum[2] } = {}) {
246
+ const F = D.headFrame,
247
+ beam = () => color(D.timber, D.timberJitter, random),
248
+ rope = color(D.rope);
249
+ const crown = sg => at(F.crown[0], F.crown[1], sg * F.crown[2]);
250
+ for (const sg of [-1, 1]) {
251
+ stick(wd, at(F.leg[0], F.leg[1], sg * F.leg[2]), crown(sg), F.legRadius, beam());
252
+ stick(wd, at(F.back[0], F.back[1], sg * F.back[2]), crown(sg), F.backRadius, beam());
253
+ stick(wd, at(F.brace[0], F.brace[1], sg * F.brace[2]), at(F.brace[3], F.brace[4], sg * F.brace[5]), F.braceRadius, beam());
254
+ }
255
+ put(wd, F.beam[0], F.beam[1], F.beam[2], F.beam[3], F.beam[4], F.beam[5], beam());
256
+ gb.add(wheelGeometry(), iron, transform(...at(F.wheel[0], F.wheel[1], 0), 1, 1, 1, yaw + Math.PI / 2));
257
+ for (let k = 0; k < F.spokes; k++)
258
+ stick(
259
+ gb,
260
+ at(F.wheel[0], F.wheel[1], 0),
261
+ at(F.wheel[0] + Math.cos(k * F.spokeStep) * F.wheelSize[0], F.wheel[1] + Math.sin(k * F.spokeStep) * F.wheelSize[0], 0),
262
+ 0.03,
263
+ iron,
264
+ );
265
+ stick(wd, at(F.rope[0], F.wheel[1], 0), at(...F.ropeDown), F.ropeRadius, rope);
266
+ stick(wd, at(F.rope[1], F.wheel[1], 0), at(...F.ropeOut), F.ropeRadius, rope); // and down to the windlass
267
+ for (const sg of [-1, 1])
268
+ put(wd, F.windlass[0], F.windlass[1], F.windlass[2] + sg * F.windlass[3], F.windlass[4], F.windlass[5], F.windlass[4], beam());
269
+ wd.add(shapes.cyl16, beam(), transform(...at(F.drum[0], F.drum[1], drumAcross), F.drum[3], F.drum[4], F.drum[3], yaw, 0, Math.PI / 2));
270
+ }
271
+
272
+ /**
273
+ * A timber watch-tower: four raking legs, braces, a railed platform under a plank roof, and its ladder.
274
+ *
275
+ * @param {object} wd - The timber builder.
276
+ * @param {{ x: number, y: number, z: number }} at - The middle of the tower's foot, on the ground.
277
+ * @param {() => number} random - The random source the beams' tones draw from.
278
+ * @param {{ height?: number }} [options] - The platform's height over the ground in metres.
279
+ * @returns {void}
280
+ */
281
+ function propWatchTower(wd, { x, y, z }, random, { height: H = D.tower.height } = {}) {
282
+ const W = D.tower,
283
+ beam = () => color(W.timber, D.timberJitter, random);
284
+ for (const [sx, sz] of [
285
+ [-1, -1],
286
+ [1, -1],
287
+ [1, 1],
288
+ [-1, 1],
289
+ ]) {
290
+ stick(
291
+ wd,
292
+ [x + sx * W.foot[0], y - W.foot[1], z + sz * W.foot[0]],
293
+ [x + sx * W.head[0], y + H + W.head[1], z + sz * W.head[0]],
294
+ W.legRadius,
295
+ beam(),
296
+ );
297
+ stick(
298
+ wd,
299
+ [x + sx * W.brace[0], y + W.brace[1], z + sz * W.brace[0]],
300
+ [x - sx * W.brace[2], y + W.brace[3], z + sz * W.brace[4]],
301
+ W.braceRadius,
302
+ beam(),
303
+ );
304
+ wd.box(x + sx * W.railInset, y + H + W.railRise, z, W.rail[0], W.rail[1], W.rail[2], beam());
305
+ wd.box(x, y + H + W.railRise, z + sz * W.railInset, W.rail[2], W.rail[1], W.rail[0], beam());
306
+ }
307
+ wd.box(x, y + H, z, W.platform[0], W.platform[1], W.platform[0], beam());
308
+ wd.add(shapes.box, dim(beam(), W.roofShade), transform(x, y + H + W.head[1], z, W.roof[0], W.roof[1], W.roof[0], 0, 0, W.roof[2]));
309
+ for (const sg of [-1, 1])
310
+ stick(wd, [x + sg * W.ladder[0], y, z + W.ladder[1]], [x + sg * W.ladder[0], y + H + 0.2, z + W.ladder[2]], W.ladderRadius, beam());
311
+ for (let k = 1; k <= W.rungs; k++)
312
+ wd.box(x, y + k * W.rung[0], z + W.ladder[1] - k * W.rung[1], W.rung[2], W.rung[3], W.rung[3], beam());
313
+ }
314
+
315
+ return { frame, propTimbering, propTrack, propOreTub, propHeadFrame, propWatchTower };
316
+ }
@@ -0,0 +1,224 @@
1
+ /**
2
+ * A face of quarried rock (`buildQuarryFace`): one sheet of rows and columns along a line of points, every vertex pushed out of
3
+ * or back into the rock by the bed it lies in, the block of that bed it belongs to, and the roughness of a broken face. Beds are
4
+ * counted from a level, so they run straight along a whole wall; each bed is split along its length by joints into blocks, each
5
+ * standing a little proud of or behind its neighbours; a seam is weathered back at the foot of every bed, the face leans back as
6
+ * it rises, and its top rounds over and runs back into the rock to meet the ground behind it. Worker-safe.
7
+ * @module
8
+ */
9
+
10
+ import { createNoise } from '../math/noise.js';
11
+ import { clamp, lerp, sstep } from '../math/scalar.js';
12
+ import { defaultRockHash as defaultHash } from './creased-sheet.js';
13
+ import { C as defaultColor } from './primitives.js';
14
+
15
+ let fallbackNoise = null;
16
+ /** Lazily created default 2D fBm sampler for a quarry face: `(x, z, octaves, seed) => number` in `[0, 1]`. */
17
+ export const defaultQuarryNoise = () => (fallbackNoise ??= createNoise().fbm);
18
+
19
+ /** Default proportions of a quarry face, in metres and in shares of a bed. */
20
+ export const QUARRY_FACE_DEFAULTS = Object.freeze({
21
+ block: 6.5, // metres: a block's length along its bed, on average
22
+ joint: 0.14, // the share of a block's length over which the face steps to its neighbour's
23
+ rows: Object.freeze([0, 0.09, 0.55]), // where the rows lie in a bed, as shares of its height
24
+ capRows: Object.freeze([Object.freeze([0.3, 0.2]), Object.freeze([1.2, 0.3]), Object.freeze([0.5, 0.2]), Object.freeze([1, -0.7])]), // the rows over the top: [metres back from the face's last row (the last two as shares of the cap's depth), metres up]
25
+ capLump: 0.9, // metres up and down the spoil on a bench's top lies, at most
26
+ });
27
+
28
+ /**
29
+ * Build a quarried face along `points` into the builder `face`: from each point's foot up to its top, bed over bed, and over the
30
+ * top and back into the rock.
31
+ *
32
+ * Each point stands in the builder's own frame: `{ x, z }` on the face's foot, `{ nx, nz }` out of the rock, `y0` its foot, `top`
33
+ * its lip, `dust` the colour of the ground its top runs back into, and optionally `cap` (metres its own top runs back),
34
+ * `backX`/`backZ` (the way its top runs back, where that is not the reverse of its normal) and `soffit` (`[x, y, z]`: where a cut's
35
+ * ceiling behind this point joins the face, so a quad closes the gap under the brow).
36
+ *
37
+ * @param {object} face - The geometry builder the sheet is written into (its `raw` and `triangles`, at its origin).
38
+ * @param {Array<object>} points - The face's points in order along it; fewer than two build nothing.
39
+ * @param {object} options
40
+ * @param {number} options.floor - Metres: the level beds are counted from.
41
+ * @param {number} options.bed - Metres: a bed's height.
42
+ * @param {number} options.cap - Metres the top runs back (a point's own `cap` where it has one); `0` leaves the lip as the last row.
43
+ * @param {number[]} options.tones - Each bed's colour (sRGB hex), taken in order round the list.
44
+ * @param {number} options.capTone - The sRGB hex colour of the ground the top runs back into.
45
+ * @param {number} options.seed - The face's seed: every hash and noise sample is salted with it.
46
+ * @param {(x: number, z: number) => number} [options.ground] - The ground's height in the builder's frame; where given, the last
47
+ * row of the top is kept a little under it, so the sheet meets the ground it runs into.
48
+ * @param {number[]} [options.rows=QUARRY_FACE_DEFAULTS.rows] - Where a bed's rows lie, as shares of its height (fewer for a face seen
49
+ * only from afar).
50
+ * @param {Array<[number, number]>} [options.capRows=QUARRY_FACE_DEFAULTS.capRows] - The rows over the top.
51
+ * @param {number} [options.block=QUARRY_FACE_DEFAULTS.block] - Metres: a block's length along its bed, on average.
52
+ * @param {number} [options.joint=QUARRY_FACE_DEFAULTS.joint] - The share of a block's length over which the face steps to its neighbour's.
53
+ * @param {number} [options.capLump=QUARRY_FACE_DEFAULTS.capLump] - Metres the spoil on a bench's top lies up and down, at most.
54
+ * @param {(x: number, z: number, octaves: number, seed: number) => number} [options.noise] - A 2D fBm sampler.
55
+ * @param {(x: number, y: number, salt: number) => number} [options.hash] - A 2D coordinate hash.
56
+ * @param {(hex: number) => number[]} [options.color] - sRGB hex to linear RGB.
57
+ * @returns {void}
58
+ */
59
+ export function buildQuarryFace(
60
+ face,
61
+ points,
62
+ {
63
+ floor,
64
+ bed,
65
+ cap,
66
+ tones,
67
+ capTone,
68
+ seed,
69
+ ground = null,
70
+ rows = QUARRY_FACE_DEFAULTS.rows,
71
+ capRows = QUARRY_FACE_DEFAULTS.capRows,
72
+ block = QUARRY_FACE_DEFAULTS.block,
73
+ joint = QUARRY_FACE_DEFAULTS.joint,
74
+ capLump = QUARRY_FACE_DEFAULTS.capLump,
75
+ noise = defaultQuarryNoise(),
76
+ hash = defaultHash(),
77
+ color = defaultColor,
78
+ } = {},
79
+ ) {
80
+ const n = points.length;
81
+ if (n < 2) return;
82
+ let yMin = 1e9,
83
+ yMax = -1e9;
84
+ const s = new Float32Array(n);
85
+ for (let i = 0; i < n; i++) {
86
+ const p = points[i];
87
+ if (i) s[i] = s[i - 1] + Math.hypot(p.x - points[i - 1].x, p.z - points[i - 1].z);
88
+ yMin = Math.min(yMin, p.y0);
89
+ yMax = Math.max(yMax, p.top);
90
+ }
91
+ // the rows: at fixed heights within the beds, so seams run level; each column's own foot and top clamp them
92
+ const levels = [yMin];
93
+ for (let k = Math.floor((yMin - floor) / bed); floor + k * bed < yMax; k++)
94
+ for (const f of rows) {
95
+ const y = floor + (k + f) * bed;
96
+ if (y > yMin + 0.05 && y < yMax - 0.3) levels.push(y);
97
+ }
98
+ levels.push(yMax);
99
+ const nr = levels.length + (cap > 0 ? capRows.length : 0),
100
+ P = new Float32Array(n * nr * 3),
101
+ K = new Float32Array(n * nr * 3),
102
+ out = (blk, k) => (hash(blk, k, seed) - 0.5) * 1.4,
103
+ capCol = color(capTone);
104
+ for (let i = 0; i < n; i++) {
105
+ const p = points[i];
106
+ for (let j = 0; j < nr; j++) {
107
+ const at = (i * nr + j) * 3;
108
+ if (j >= levels.length) {
109
+ const [back, up] = capRows[j - levels.length],
110
+ b = j - levels.length < 2 ? back : Math.max(1.25, back * (p.cap ?? cap)),
111
+ last = (i * nr + levels.length - 1) * 3;
112
+ P[at] = P[last] + (p.backX ?? -p.nx) * b;
113
+ P[at + 2] = P[last + 2] + (p.backZ ?? -p.nz) * b;
114
+ // the bench's top is spoil and dust, never a smooth sheet: lumped where it lies back from the brow, and mottled in drifts
115
+ const lump = j - levels.length === 2 ? (noise(P[at] * 0.21, P[at + 2] * 0.21, 2, seed + 6) - 0.5) * capLump : 0,
116
+ k = 0.8 + 0.16 * noise(P[at] * 0.05, P[at + 2] * 0.05, 2, seed + 5) + 0.12 * noise(P[at] * 0.4, P[at + 2] * 0.4, 2, seed + 7);
117
+ P[at + 1] = ground && j === nr - 1 ? Math.min(p.top + up, ground(P[at], P[at + 2]) - 0.35) : p.top + up + lump;
118
+ const dust = 0.55 + (0.42 * (j - levels.length)) / (capRows.length - 1);
119
+ for (let c = 0; c < 3; c++) K[at + c] = lerp(capCol[c], p.dust[c], dust) * k;
120
+ continue;
121
+ }
122
+ const y = clamp(levels[j], p.y0, p.top),
123
+ k = Math.floor((y - floor) / bed),
124
+ within = y - floor - k * bed,
125
+ along = s[i] / block + hash(k, 7, seed) * 7,
126
+ blk = Math.floor(along),
127
+ f = along - blk;
128
+ let d = out(blk, k);
129
+ if (f < joint) d = lerp(out(blk - 1, k), d, 0.5 + 0.5 * sstep(-joint, joint, f));
130
+ else if (f > 1 - joint) d = lerp(d, out(blk + 1, k), 0.5 * sstep(1 - joint, 1 + joint, f));
131
+ const rise = (y - p.y0) / Math.max(1, p.top - p.y0),
132
+ rough = (noise(s[i] * 0.3 + seed, y * 0.35, 2, seed + 1) - 0.5) * 1.1 + (noise(s[i] * 1.1, y * 1.2, 2, seed + 2) - 0.5) * 0.3,
133
+ seam = -0.38 * (1 - sstep(0, 0.32, within)),
134
+ lip = -0.9 * sstep(p.top - 1.4, p.top, y) ** 2;
135
+ d += rough + seam + lip - rise * 0.9;
136
+ P[at] = p.x + p.nx * d;
137
+ P[at + 1] = y;
138
+ P[at + 2] = p.z + p.nz * d;
139
+ // each bed its own tone, each block a little lighter or darker, dark in hollows and seams, stained where rain runs down
140
+ const tone = color(tones[((k % tones.length) + tones.length) % tones.length]),
141
+ shade =
142
+ (0.86 + 0.2 * hash(blk, k, seed + 3)) *
143
+ (0.74 + 0.3 * sstep(-0.55, 0.35, rough + seam)) *
144
+ (1 - 0.14 * sstep(0.5, 0.75, noise(s[i] * 0.12, 3, 2, seed + 4)) * rise);
145
+ K[at] = tone[0] * shade;
146
+ K[at + 1] = tone[1] * shade;
147
+ K[at + 2] = tone[2] * shade;
148
+ }
149
+ }
150
+ // normals from the neighbours on the sheet, turned to face out of the rock
151
+ const N = new Float32Array(n * nr * 3),
152
+ v = (i, j, c) => P[(clamp(i, 0, n - 1) * nr + clamp(j, 0, nr - 1)) * 3 + c];
153
+ for (let i = 0; i < n; i++)
154
+ for (let j = 0; j < nr; j++) {
155
+ const ax = v(i, j + 1, 0) - v(i, j - 1, 0),
156
+ ay = v(i, j + 1, 1) - v(i, j - 1, 1),
157
+ az = v(i, j + 1, 2) - v(i, j - 1, 2),
158
+ bx = v(i + 1, j, 0) - v(i - 1, j, 0),
159
+ by = v(i + 1, j, 1) - v(i - 1, j, 1),
160
+ bz = v(i + 1, j, 2) - v(i - 1, j, 2);
161
+ let nx = ay * bz - az * by,
162
+ ny = az * bx - ax * bz,
163
+ nz = ax * by - ay * bx;
164
+ const l = Math.hypot(nx, ny, nz) || 1,
165
+ sign = j < levels.length ? Math.sign(nx * points[i].nx + nz * points[i].nz) || 1 : Math.sign(ny) || 1;
166
+ nx = (nx / l) * sign;
167
+ ny = (ny / l) * sign;
168
+ nz = (nz / l) * sign;
169
+ const at = (i * nr + j) * 3;
170
+ N[at] = nx;
171
+ N[at + 1] = ny;
172
+ N[at + 2] = nz;
173
+ }
174
+ // every point of the sheet once, and two triangles a cell over them, wound to face the way their normals do
175
+ const { ox, oy, oz } = face,
176
+ first = face.count / 3,
177
+ corners = [];
178
+ for (let q = 0; q < n * nr * 3; q += 3)
179
+ face.raw(P[q] + ox, P[q + 1] + oy, P[q + 2] + oz, N[q], N[q + 1], N[q + 2], K[q], K[q + 1], K[q + 2]);
180
+ for (let i = 0; i + 1 < n; i++)
181
+ for (let j = 0; j + 1 < nr; j++) {
182
+ const a = i * nr + j,
183
+ b = (i + 1) * nr + j,
184
+ c = b + 1,
185
+ d = a + 1,
186
+ ex = P[b * 3] - P[a * 3],
187
+ ey = P[b * 3 + 1] - P[a * 3 + 1],
188
+ ez = P[b * 3 + 2] - P[a * 3 + 2],
189
+ fx = P[d * 3] - P[a * 3],
190
+ fy = P[d * 3 + 1] - P[a * 3 + 1],
191
+ fz = P[d * 3 + 2] - P[a * 3 + 2],
192
+ facing = (ey * fz - ez * fy) * N[a * 3] + (ez * fx - ex * fz) * N[a * 3 + 1] + (ex * fy - ey * fx) * N[a * 3 + 2];
193
+ if (facing > 0) corners.push(a, b, c, a, c, d);
194
+ else corners.push(a, c, b, a, d, c);
195
+ }
196
+ // Under a cut's brow the last few metres of its ceiling join the irregular face to the roof of the drift behind it.
197
+ for (let i = 1; i < n; i++) {
198
+ const left = points[i - 1].soffit,
199
+ right = points[i].soffit;
200
+ if (!left || !right) continue;
201
+ const a = (i - 1) * nr * 3,
202
+ b = i * nr * 3,
203
+ v = face.count / 3 - first,
204
+ dx = P[b] - P[a],
205
+ dy = P[b + 1] - P[a + 1],
206
+ dz = P[b + 2] - P[a + 2],
207
+ bx = left[0] - P[a],
208
+ by = left[1] - P[a + 1],
209
+ bz = left[2] - P[a + 2],
210
+ nx = dz * by - dy * bz,
211
+ ny = dx * bz - dz * bx,
212
+ nz = dy * bx - dx * by,
213
+ length = Math.hypot(nx, ny, nz) || 1;
214
+ for (const [x, y, z, k] of [
215
+ [P[a], P[a + 1], P[a + 2], 0.8],
216
+ [P[b], P[b + 1], P[b + 2], 0.8],
217
+ [...right, 0.4],
218
+ [...left, 0.4],
219
+ ])
220
+ face.raw(x + ox, y + oy, z + oz, nx / length, ny / length, nz / length, k * K[a], k * K[a + 1], k * K[a + 2]);
221
+ corners.push(v, v + 2, v + 1, v, v + 3, v + 2);
222
+ }
223
+ face.triangles(first, corners);
224
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roamwright",
3
- "version": "0.61.32",
3
+ "version": "0.61.33",
4
4
  "description": "A procedural worldbuilding engine built on top of Three.js. Generate landscapes with rivers and changing weather, animate crowds, and explore on foot or in flight.",
5
5
  "keywords": [
6
6
  "threejs",
@@ -0,0 +1,57 @@
1
+ /**
2
+ * A dome of still air (`createCalmDome`): a translucent half sphere over a circle of ground, added to the picture so that it
3
+ * brightens what lies behind it rather than hiding it: a spell's circle of calm, a shield's shell, the glass of a conservatory.
4
+ * Hidden when made; its keeper shows it.
5
+ * @module
6
+ */
7
+
8
+ import * as THREE from 'three';
9
+ import { TAU } from '../math/scalar.js';
10
+
11
+ /** Default size and look of a calm dome. */
12
+ export const CALM_DOME_DEFAULTS = Object.freeze({
13
+ radius: 13, // metres
14
+ segments: Object.freeze([40, 16]), // the half sphere's width and height segments
15
+ color: 0xcfe0ee, // sRGB hex: the air's tint
16
+ opacity: 0.07, // how much of it is added to the picture
17
+ });
18
+
19
+ /**
20
+ * Create a translucent dome of still air: a half sphere standing on its foot at `at`, drawn from both sides without depth, its
21
+ * colour added to what lies behind it.
22
+ *
23
+ * @param {object} [options]
24
+ * @param {number} [options.radius=CALM_DOME_DEFAULTS.radius] - The dome's radius in metres.
25
+ * @param {[number, number]} [options.segments=CALM_DOME_DEFAULTS.segments] - The half sphere's width and height segments.
26
+ * @param {number} [options.color=CALM_DOME_DEFAULTS.color] - The air's tint, sRGB hex.
27
+ * @param {number} [options.opacity=CALM_DOME_DEFAULTS.opacity] - How much of it is added to the picture.
28
+ * @param {boolean} [options.fogFades=false] - Attach `{ FOG_FADES: '' }` for worlds with custom haze fading, so the dome fades in
29
+ * haze rather than glowing through it.
30
+ * @param {THREE.Object3D | null} [options.parent=null] - A group to add the dome to.
31
+ * @param {{ x: number, y: number, z: number }} [options.at={ x: 0, y: 0, z: 0 }] - Where its foot stands, in metres.
32
+ * @returns {THREE.Mesh} The dome, hidden until shown.
33
+ */
34
+ export function createCalmDome({
35
+ radius = CALM_DOME_DEFAULTS.radius,
36
+ segments = CALM_DOME_DEFAULTS.segments,
37
+ color = CALM_DOME_DEFAULTS.color,
38
+ opacity = CALM_DOME_DEFAULTS.opacity,
39
+ fogFades = false,
40
+ parent = null,
41
+ at = { x: 0, y: 0, z: 0 },
42
+ } = {}) {
43
+ const material = new THREE.MeshBasicMaterial({
44
+ color,
45
+ transparent: true,
46
+ opacity,
47
+ blending: THREE.AdditiveBlending,
48
+ depthWrite: false,
49
+ side: THREE.DoubleSide,
50
+ });
51
+ if (fogFades) material.defines = { FOG_FADES: '' };
52
+ const dome = new THREE.Mesh(new THREE.SphereGeometry(radius, segments[0], segments[1], 0, TAU, 0, Math.PI / 2), material);
53
+ dome.position.set(at.x, at.y, at.z);
54
+ dome.visible = false; // its keeper shows it
55
+ if (parent) parent.add(dome);
56
+ return dome;
57
+ }