roamwright 0.61.26 → 0.61.28

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 CHANGED
@@ -30,7 +30,7 @@ npm resolves the Three.js peer in a new project. Roamwright targets Three.js **0
30
30
 
31
31
  ## Examples
32
32
 
33
- Browse all twenty-two examples on the [live showcase](https://enestaylan.github.io/roamwright/).
33
+ Browse all twenty-four examples on the [live showcase](https://enestaylan.github.io/roamwright/).
34
34
 
35
35
  | Live example | What the example shows | Source |
36
36
  | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
@@ -56,6 +56,8 @@ Browse all twenty-two examples on the [live showcase](https://enestaylan.github.
56
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
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
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 rock outcrops, branching roots, cascading fountains, fractured ice cliffs, crystal grottos and camp layouts. | [set-pieces.js](examples/set-pieces.js) |
59
61
 
60
62
  ### Run locally
61
63
 
@@ -0,0 +1,52 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <meta name="theme-color" content="#1e2b36" />
7
+ <title>Set pieces · Roamwright</title>
8
+ <link rel="stylesheet" href="./showcase.css" />
9
+ <script type="importmap">
10
+ {
11
+ "imports": {
12
+ "three": "../node_modules/three/build/three.module.js",
13
+ "three/addons/": "../node_modules/three/examples/jsm/",
14
+ "roamwright": "../index.js",
15
+ "roamwright/": "../"
16
+ }
17
+ }
18
+ </script>
19
+ </head>
20
+ <body>
21
+ <canvas
22
+ tabindex="0"
23
+ aria-label="Sandstone outcrops draped with branching roots, a cascading stone fountain, a fractured glacial ice cliff, a crystal cavern, and a field camp beside a rising dust curtain"
24
+ ></canvas>
25
+ <header>
26
+ <a class="back" href="../index.html"><span aria-hidden="true">←</span> Roamwright</a>
27
+ <div class="meta">
28
+ <a class="source" href="https://github.com/enestaylan/roamwright/blob/main/examples/set-pieces.js">Source</a>
29
+ <form method="get">
30
+ <label for="seed">Seed</label>
31
+ <input id="seed" name="seed" type="number" step="1" min="-2147483648" max="2147483647" value="42" required />
32
+ <button type="submit" title="Rebuild set pieces with this seed" aria-label="Rebuild set pieces with this seed">→</button>
33
+ </form>
34
+ </div>
35
+ </header>
36
+ <footer>
37
+ <div class="caption">
38
+ <h1>Set pieces</h1>
39
+ <p>Bedded rock outcrops, branching roots, cascading fountains, fractured glacial ice cliffs, crystal grottos and camp layouts.</p>
40
+ </div>
41
+ <div class="tools">
42
+ <div class="views" role="group" aria-label="Camera viewpoint">
43
+ <button type="button" data-view="outcrops" aria-pressed="true">Outcrops &amp; fountain</button>
44
+ <button type="button" data-view="glacier" aria-pressed="false">Ice cliff</button>
45
+ <button type="button" data-view="grotto" aria-pressed="false">Crystal grotto</button>
46
+ <button type="button" data-view="camp" aria-pressed="false">Camp &amp; storm</button>
47
+ </div>
48
+ </div>
49
+ </footer>
50
+ <script type="module" src="./set-pieces.js"></script>
51
+ </body>
52
+ </html>
@@ -0,0 +1,284 @@
1
+ import * as THREE from 'three';
2
+ import {
3
+ GeometryBuilder,
4
+ addFlame,
5
+ addStillPool,
6
+ buildCavernCrystal,
7
+ buildFallenIceBlocks,
8
+ buildIceCliffSheet,
9
+ buildIceHollow,
10
+ buildOutcrop,
11
+ buildPuddleIce,
12
+ buildRockDome,
13
+ buildTentLines,
14
+ buildWagonLine,
15
+ createCrystalMaterial,
16
+ createDaylightSky,
17
+ createDustCurtain,
18
+ createFallingWaterSheets,
19
+ createHouseKit,
20
+ createHouseKitMaterials,
21
+ createHouseKitMeshes,
22
+ createIceCliffField,
23
+ createIceMaterial,
24
+ createIceSheetTexture,
25
+ createOrbitCamera,
26
+ createSpotFrame,
27
+ growRootBranch,
28
+ mulberry32,
29
+ placeInstances,
30
+ } from 'roamwright';
31
+ import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
32
+ import { C, TRS } from 'roamwright/geometry/primitives.js';
33
+ import { createProps } from 'roamwright/geometry/props.js';
34
+ import { initExample } from './stage.js';
35
+
36
+ const { canvas, renderer, camera, scene, worldGroup, seed, noise, hash, shapes } = initExample({
37
+ fallbackSeed: 42,
38
+ fov: 42,
39
+ });
40
+ const rng = mulberry32(seed * 97 + 13);
41
+
42
+ const groundAt = (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);
43
+
44
+ // Warm canyon floor spanning all four showcase zones.
45
+ const floorLow = new THREE.Color(0xc2a882);
46
+ const floorHigh = new THREE.Color(0x9a8364);
47
+ const floorMesh = createHeightfieldMesh({
48
+ size: 560,
49
+ segs: 120,
50
+ heightAt: groundAt,
51
+ colorAt: (_x, y, _z, _up, out) => out.copy(floorLow).lerp(floorHigh, Math.min(1, Math.max(0, y * 0.8))),
52
+ roughness: 0.94,
53
+ });
54
+ worldGroup.add(floorMesh);
55
+
56
+ createDaylightSky({
57
+ scene,
58
+ horizon: '#e4d8c4',
59
+ zenith: '#4e7ca8',
60
+ fog: [120, 420],
61
+ sunPosition: [70, 52, 48],
62
+ sunIntensity: 2.8,
63
+ sunColor: '#fff1d6',
64
+ hemiIntensity: 1.05,
65
+ });
66
+
67
+ const rockMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.9, metalness: 0 });
68
+ const woodMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.88, metalness: 0 });
69
+ const stoneMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.86, metalness: 0 });
70
+
71
+ // ── 1. Opening zone (origin): wind-carved bedded outcrops, branching roots & cascading fountain ──
72
+ const rockGb = new GeometryBuilder();
73
+ const rockOpts = { noise: noise.vnoise, hash, rock: shapes.rock, color: C, transform: TRS };
74
+ buildOutcrop(rockGb, groundAt, { x: -12, z: -14, rx: 9.5, rz: 7.5, h: 13.5, beds: 4, seed: seed + 3 }, rockOpts);
75
+ buildOutcrop(rockGb, groundAt, { x: 14, z: -16, rx: 8.5, rz: 6.5, h: 11.5, beds: 4, yaw: 0.8, seed: seed + 11 }, rockOpts);
76
+ buildOutcrop(rockGb, groundAt, { x: 2, z: -26, rx: 12, rz: 7, h: 16, beds: 5, yaw: -0.4, seed: seed + 19 }, rockOpts);
77
+ rockGb.mesh(rockMat, worldGroup);
78
+
79
+ // Tapering gnarled roots spreading from the left outcrop across the terrace.
80
+ const rootGb = new GeometryBuilder();
81
+ const bark = C(0x4b3828);
82
+ for (let i = 0; i < 6; i++) {
83
+ const a = -0.7 + i * 0.48;
84
+ growRootBranch(rootGb, rng, [-6.5, groundAt(-6.5, -8) + 0.4, -8], [Math.cos(a), 0.12, Math.sin(a)], 9.5, 0.34, bark, {
85
+ step: 0.75,
86
+ curl: 0.55,
87
+ sides: 6,
88
+ branches: 3,
89
+ depth: 2,
90
+ ground: groundAt,
91
+ rise: 0.08,
92
+ });
93
+ }
94
+ rootGb.mesh(woodMat, worldGroup);
95
+
96
+ // Two-tier cascading stone fountain with still water basins, falling water curtains and lamp flames.
97
+ const fy = groundAt(2, 2);
98
+ const fGb = new GeometryBuilder();
99
+ fGb.ox = 2;
100
+ fGb.oz = 2;
101
+ fGb.add(shapes.cyl16, C(0xb8ad98), TRS(0, fy - 0.15, 0, 8.0, 0.45, 8.0));
102
+ fGb.add(shapes.cyl16, C(0xa69b86), TRS(0, fy + 0.3, 0, 7.2, 0.35, 7.2));
103
+ // Rim coping segments around the lower basin so the turquoise water pool is clearly recessed inside.
104
+ for (let i = 0; i < 16; i++) {
105
+ const a = (i / 16) * Math.PI * 2;
106
+ fGb.add(shapes.box, C(0xc6bba6), TRS(Math.cos(a) * 3.45, fy + 0.65, Math.sin(a) * 3.45, 0.38, 0.42, 1.48, -a));
107
+ }
108
+ fGb.add(shapes.cyl16, C(0xc4b9a4), TRS(0, fy + 0.5, 0, 1.35, 1.55, 1.35));
109
+ fGb.add(shapes.taper, C(0xbeb39e), TRS(0, fy + 2.05, 0, 3.2, 0.36, 3.2, 0, Math.PI));
110
+ fGb.add(shapes.cyl16, C(0xc4b9a4), TRS(0, fy + 2.05, 0, 0.46, 0.9, 0.46));
111
+ fGb.add(shapes.taper, C(0xbeb39e), TRS(0, fy + 2.98, 0, 1.62, 0.24, 1.62, 0, Math.PI));
112
+ fGb.mesh(stoneMat, worldGroup);
113
+
114
+ const poolMat = new THREE.MeshStandardMaterial({ color: 0x226870, roughness: 0.08, metalness: 0.18 });
115
+ addStillPool(worldGroup, { origin: { x: 2, z: 2 }, y: fy + 0.72, radius: 3.3, segments: 36, material: poolMat, renderOrder: 5 });
116
+ addStillPool(worldGroup, { origin: { x: 2, z: 2 }, y: fy + 2.1, radius: 1.46, segments: 32, material: poolMat, renderOrder: 5 });
117
+ addStillPool(worldGroup, { origin: { x: 2, z: 2 }, y: fy + 3.02, radius: 0.72, segments: 24, material: poolMat, renderOrder: 5 });
118
+
119
+ const waterFalls = createFallingWaterSheets(worldGroup, {
120
+ origin: { x: 2, z: 2 },
121
+ cylinders: [
122
+ { topRadius: 1.52, bottomRadius: 1.68, height: 1.36, y: fy + 1.42, segments: 40 },
123
+ { topRadius: 0.76, bottomRadius: 0.84, height: 0.9, y: fy + 2.55, segments: 28 },
124
+ ],
125
+ rings: [
126
+ { innerRadius: 1.45, outerRadius: 2.05, y: fy + 0.75, segments: 40 },
127
+ { innerRadius: 0.72, outerRadius: 1.05, y: fy + 2.12, segments: 28 },
128
+ ],
129
+ });
130
+
131
+ // Flanking stone braziers with practical flames beside the fountain.
132
+ for (const dx of [-5.2, 5.2]) {
133
+ const bx = 2 + dx;
134
+ const bz = 5.5;
135
+ const by = groundAt(bx, bz);
136
+ const stand = new GeometryBuilder();
137
+ stand.add(shapes.cyl6, C(0x4b443b), TRS(bx, by, bz, 0.5, 0.2, 0.5));
138
+ stand.add(shapes.cyl6, C(0x3a3632), TRS(bx, by + 0.18, bz, 0.34, 1.05, 0.34));
139
+ stand.add(shapes.taper, C(0x2e2a26), TRS(bx, by + 1.25, bz, 0.56, 0.22, 0.56, 0, Math.PI));
140
+ stand.mesh(stoneMat, worldGroup);
141
+ addFlame(worldGroup, { x: bx, y: by + 1.42, z: bz, size: 0.38, shapes });
142
+ }
143
+
144
+ // ── 2. Glacial ice cliff zone (far west, x = -125) ──
145
+ const iceOrigin = { x: -125, z: -20 };
146
+ const iceGround = (x, z) => groundAt(iceOrigin.x + x, iceOrigin.z + z);
147
+ const iceField = createIceCliffField({ half: 22, ends: 7, tall: 15, step: 0.7, bodies: 0, noise: noise.vnoise, hash });
148
+ const make = () => new GeometryBuilder();
149
+ const iceInto = { solid: make(), pane: make(), plug: make(), teeth: make(), deep: make(), socket: make(), veils: [make(), make()] };
150
+ buildIceCliffSheet(iceField, iceOrigin, iceGround, rng, iceInto);
151
+ buildIceHollow(iceField, iceOrigin, iceGround, iceInto);
152
+ buildFallenIceBlocks(iceField, iceInto.solid, iceOrigin, iceGround, rng, { count: 48, transform: TRS });
153
+ for (let i = 0; i < 8; i++) buildPuddleIce(iceInto.pane, iceOrigin, iceGround, rng, (rng() - 0.5) * 20, 2 + rng() * 6, 0.8 + rng() * 1.2);
154
+ const iceSheet = createIceSheetTexture({ size: 128, seed });
155
+ const iceOpaque = createIceMaterial({ sheet: iceSheet, glow: 0.14 });
156
+ const iceDeep = createIceMaterial({ sheet: iceSheet, glow: 0.45 });
157
+ const iceClear = createIceMaterial({ sheet: iceSheet, glow: 0.18, clear: true, thin: 0.32 });
158
+ const iceVeil = createIceMaterial({ sheet: iceSheet, glow: 0.2, clear: true, thin: 0.05 });
159
+ iceInto.solid.mesh(iceOpaque, worldGroup).receiveShadow = false;
160
+ iceInto.deep.mesh(iceDeep, worldGroup, false);
161
+ for (const veil of iceInto.veils) veil.mesh(iceVeil, worldGroup, false);
162
+ iceInto.pane.mesh(iceClear, worldGroup, false);
163
+ iceInto.plug.mesh(iceClear, worldGroup, false);
164
+
165
+ // ── 3. Subterranean crystal grotto zone (east, buried below ground so its dome never breaks the horizon) ──
166
+ const grottoX = 120;
167
+ const grottoZ = -35;
168
+ const grottoFloor = groundAt(grottoX, grottoZ) - 22;
169
+ const grottoGround = () => grottoFloor;
170
+ const grottoGb = new GeometryBuilder();
171
+ buildRockDome(grottoGb, grottoX, grottoZ, grottoFloor - 0.4, 15, 11.5, 3.2, 2.5, [1.35, 1.8], { noise: noise.vnoise });
172
+ // Inner dark stone cavern floor so the interior reads as a subterranean chamber.
173
+ grottoGb.add(shapes.cyl16, C(0x3a322b), TRS(grottoX, grottoFloor - 0.08, grottoZ, 29, 0.28, 29));
174
+ grottoGb.mesh(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.94, side: THREE.DoubleSide }), worldGroup);
175
+
176
+ const crystalMat = createCrystalMaterial();
177
+ const crystalGb = buildCavernCrystal(grottoX, grottoZ - 1, grottoGround, 9.5, { x: grottoX + 1.8, z: grottoZ - 4.2, h: 9.2 }, rng, {
178
+ clusters: 26,
179
+ hash,
180
+ shapes,
181
+ color: C,
182
+ transform: TRS,
183
+ });
184
+ crystalGb.mesh(crystalMat, worldGroup);
185
+ const grottoLight = new THREE.PointLight(0x98b8f8, 38, 28, 1.4);
186
+ grottoLight.position.set(grottoX, grottoFloor + 4.8, grottoZ - 1);
187
+ worldGroup.add(grottoLight);
188
+ const grottoFill = new THREE.PointLight(0xe4b888, 14, 22, 1.6);
189
+ grottoFill.position.set(grottoX - 3.5, grottoFloor + 2.8, grottoZ + 4.5);
190
+ worldGroup.add(grottoFill);
191
+
192
+ // ── 4. Field camp & rising dust curtain zone (south-east, x = 52, z = 68) ──
193
+ const houseKit = createHouseKit({ shapes, hash });
194
+ const kitMeshes = createHouseKitMeshes({ materials: createHouseKitMaterials({ doubleSide: true, stainOpacity: 0.08 }) });
195
+ const props = createProps({ houseKit, shapes, vnoise: noise.vnoise, hash, horse: () => {} });
196
+ const campSpot = createSpotFrame({ ground: groundAt, origin: { x: 52, z: 68 }, createBuilder: () => new GeometryBuilder() });
197
+ const campKit = houseKit.kitNew();
198
+ buildTentLines({
199
+ kit: campKit,
200
+ spot: campSpot,
201
+ random: rng,
202
+ x: 0,
203
+ z: 0,
204
+ turn: 0.2,
205
+ rows: 2,
206
+ files: 4,
207
+ placeKit: houseKit.kitAt,
208
+ buildTent: props.propTentS,
209
+ buildCookfire: props.propCookfire,
210
+ onFire: (fx, fy, fz) => addFlame(worldGroup, { x: fx, y: fy + 0.25, z: fz, size: 0.34, shapes }),
211
+ });
212
+ await buildWagonLine({
213
+ kit: campKit,
214
+ spot: campSpot,
215
+ random: rng,
216
+ x: -14,
217
+ z: -2,
218
+ turn: 0.18,
219
+ count: 4,
220
+ gap: 6.8,
221
+ placeKit: houseKit.kitAt,
222
+ buildWagon: props.propWagon,
223
+ });
224
+ kitMeshes.kitStatic(campKit, worldGroup);
225
+
226
+ // Instanced weathered sandstone boulders marking the camp perimeter via placeInstances.
227
+ const cairnMat = new THREE.MeshStandardMaterial({ color: 0x917b5d, roughness: 0.92, metalness: 0 });
228
+ placeInstances({
229
+ geometry: shapes.rock,
230
+ material: cairnMat,
231
+ capacity: 18,
232
+ parent: worldGroup,
233
+ place(put) {
234
+ for (let i = 0; i < 18; i++) {
235
+ const a = (i / 18) * Math.PI * 2;
236
+ const px = 52 + Math.cos(a) * 28;
237
+ const pz = 68 + Math.sin(a) * 20;
238
+ put(TRS(px, groundAt(px, pz) + 0.22, pz, 0.95, 0.65, 0.82, a));
239
+ }
240
+ },
241
+ });
242
+
243
+ const dustCurtain = createDustCurtain({
244
+ parent: worldGroup,
245
+ x: 52,
246
+ y: groundAt(52, 68),
247
+ z: 68,
248
+ rings: [30, 42],
249
+ height: 46,
250
+ around: 56,
251
+ up: 10,
252
+ });
253
+
254
+ // ── Camera viewpoints and animation loop ──
255
+ const VIEWS = {
256
+ outcrops: { eye: [14, 7.2, 20], target: [1, 3.8, -8] },
257
+ glacier: { eye: [-113, 8.5, 14], target: [-125, 6, -20] },
258
+ grotto: { eye: [120, grottoFloor + 3.2, grottoZ + 9.2], target: [120, grottoFloor + 3.2, grottoZ - 3.5] },
259
+ camp: { eye: [22, 11.5, 96], target: [52, 3.2, 66] },
260
+ };
261
+
262
+ createOrbitCamera({
263
+ camera,
264
+ canvas,
265
+ renderer,
266
+ scene,
267
+ views: VIEWS,
268
+ initialView: 'outcrops',
269
+ groundAt: (x, z) => (Math.hypot(x - grottoX, z - grottoZ) < 18 ? grottoFloor : groundAt(x, z)),
270
+ minClearance: 1.5,
271
+ minDistance: 8,
272
+ maxDistance: 220,
273
+ far: 1200,
274
+ onDraw: () => {},
275
+ });
276
+
277
+ function frameLoop(ms) {
278
+ const t = ms / 1000;
279
+ waterFalls.setTime(t);
280
+ dustCurtain.update(t, 0.85, 0.9);
281
+ renderer.render(scene, camera);
282
+ requestAnimationFrame(frameLoop);
283
+ }
284
+ requestAnimationFrame(frameLoop);
@@ -0,0 +1,56 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <meta name="theme-color" content="#1e2a26" />
7
+ <title>Troop formations · Roamwright</title>
8
+ <link rel="stylesheet" href="./showcase.css" />
9
+ <script type="importmap">
10
+ {
11
+ "imports": {
12
+ "three": "../node_modules/three/build/three.module.js",
13
+ "three/addons/": "../node_modules/three/examples/jsm/",
14
+ "roamwright": "../index.js",
15
+ "roamwright/": "../"
16
+ }
17
+ }
18
+ </script>
19
+ </head>
20
+ <body>
21
+ <canvas
22
+ tabindex="0"
23
+ aria-label="Opposing infantry formations with carried standards, mounted lancers, ox-drawn wagons, cattle herd, and arcing volleys on a sunlit plain"
24
+ ></canvas>
25
+ <header>
26
+ <a class="back" href="../index.html"><span aria-hidden="true">←</span> Roamwright</a>
27
+ <div class="meta">
28
+ <a class="source" href="https://github.com/enestaylan/roamwright/blob/main/examples/troops.js">Source</a>
29
+ <form method="get">
30
+ <label for="seed">Seed</label>
31
+ <input id="seed" name="seed" type="number" step="1" min="-2147483648" max="2147483647" value="42" required />
32
+ <button type="submit" title="Rebuild formations with this seed" aria-label="Rebuild formations with this seed">→</button>
33
+ </form>
34
+ </div>
35
+ </header>
36
+ <footer>
37
+ <div class="caption">
38
+ <h1>Troop formations</h1>
39
+ <p>Staggered infantry lines, carried standards, mounted lancers, ox-drawn supply wagons, cattle herd, and ballistic volleys.</p>
40
+ </div>
41
+ <div class="tools">
42
+ <div class="views" role="group" aria-label="Camera viewpoint">
43
+ <button type="button" data-view="line" aria-pressed="true">Line</button>
44
+ <button type="button" data-view="cavalry" aria-pressed="false">Cavalry</button>
45
+ <button type="button" data-view="train" aria-pressed="false">Supply train</button>
46
+ <button type="button" data-view="overview" aria-pressed="false">Overview</button>
47
+ </div>
48
+ <button type="button" class="action" id="march">March</button>
49
+ <button type="button" class="action" id="fight">Engage</button>
50
+ <button type="button" class="action" id="fall">Volley fall</button>
51
+ <button type="button" class="action" id="reset">Reset</button>
52
+ </div>
53
+ </footer>
54
+ <script type="module" src="./troops.js"></script>
55
+ </body>
56
+ </html>