roamwright 0.61.27 → 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 +2 -1
- package/examples/set-pieces.html +52 -0
- package/examples/set-pieces.js +284 -0
- package/geometry/camp-layout.js +150 -0
- package/geometry/cavern-rock.js +309 -0
- package/geometry/cliff-sheets.js +457 -0
- package/geometry/creased-sheet.js +39 -0
- package/geometry/curtain-sheets.js +67 -0
- package/geometry/ice-cliff.js +339 -0
- package/geometry/ice-shards.js +247 -0
- package/geometry/index.js +34 -2
- package/geometry/instances.js +50 -1
- package/geometry/plant-roots.js +115 -0
- package/geometry/primitives.js +4 -0
- package/geometry/rock-sheets.js +259 -0
- package/geometry/strata-rocks.js +4 -3
- package/math/index.js +1 -0
- package/math/scalar.js +3 -1
- package/package.json +1 -1
- package/rendering/camp-layout.js +55 -0
- package/rendering/curtain-sheets.js +271 -0
- package/rendering/flame-sources.js +105 -0
- package/rendering/ice-material.js +143 -0
- package/rendering/index.js +24 -1
- package/rendering/rock-materials.js +27 -0
- package/rendering/ruins-fittings.js +110 -17
- package/runtime/index.js +1 -1
- package/runtime/lazy-sets.js +24 -0
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-
|
|
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
|
| --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
|
|
@@ -57,6 +57,7 @@ Browse all twenty-three examples on the [live showcase](https://enestaylan.githu
|
|
|
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
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) |
|
|
60
61
|
|
|
61
62
|
### Run locally
|
|
62
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 & 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 & 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,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Military and caravan camp layout builders: pitched tent grids with interspersed cookfires and
|
|
3
|
+
* frame-budgeted wagon lines with box colliders. Pure layout calling caller-supplied prop kits;
|
|
4
|
+
* worker-safe (no Three.js imports).
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { TAU } from '../math/scalar.js';
|
|
9
|
+
import { C as defaultColor } from './primitives.js';
|
|
10
|
+
|
|
11
|
+
/** Default spacing, gap probabilities and sun-bleached sailcloth palette for camp layouts. */
|
|
12
|
+
export const CAMP_DEFAULTS = Object.freeze({
|
|
13
|
+
canvasPalette: Object.freeze([0xb8a988, 0xa89878, 0xc4b494, 0x9a8a6c]),
|
|
14
|
+
tentSkip: 0.12,
|
|
15
|
+
fileSpacing: 6.2,
|
|
16
|
+
rowSpacing: 8.4,
|
|
17
|
+
tentCollider: Object.freeze({ hx: 1.7, hz: 2.3 }),
|
|
18
|
+
wagonCollider: Object.freeze({ hx: 1.4, hz: 2.6 }),
|
|
19
|
+
coveredChance: 0.7,
|
|
20
|
+
wagonsPerBreath: 2,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Lay out a rotated `rows` × `files` grid of pitched tents around `(x, z)` in a local spot frame,
|
|
25
|
+
* skipping occasional gaps, pushing box colliders into `solid`, and placing a cookfire beside every
|
|
26
|
+
* fourth tent.
|
|
27
|
+
*
|
|
28
|
+
* @param {object} options
|
|
29
|
+
* @param {object} options.kit - Destination kit builders passed to `placeKit`.
|
|
30
|
+
* @param {{ x0: number, z0: number, Y: (x: number, z: number) => number }} options.spot - Local spot frame (`createSpotFrame`).
|
|
31
|
+
* @param {() => number} options.random - Deterministic PRNG in `[0, 1)`.
|
|
32
|
+
* @param {number} [options.x=0] - Grid centre local X in metres.
|
|
33
|
+
* @param {number} [options.z=0] - Grid centre local Z in metres.
|
|
34
|
+
* @param {number} [options.turn=0] - Grid yaw bearing in radians.
|
|
35
|
+
* @param {number} options.rows - Number of tent rows.
|
|
36
|
+
* @param {number} options.files - Number of tent files per row.
|
|
37
|
+
* @param {Array<object> | null} [options.solid=null] - Optional collider output list.
|
|
38
|
+
* @param {(kit: object, x: number, y: number, z: number, yaw: number, plain: boolean, prop: Function, rng: () => number) => void} options.placeKit - Prop placement helper (`kitAt`).
|
|
39
|
+
* @param {(B: object, rng: () => number, canvas: number[]) => void} options.buildTent - Single tent geometry builder.
|
|
40
|
+
* @param {(B: object, rng: () => number) => void} [options.buildCookfire] - Optional cookfire geometry builder.
|
|
41
|
+
* @param {((x: number, y: number, z: number, size: number, smoke: number) => void) | null} [options.onFire=null] - Callback invoked for each placed cookfire in world coordinates.
|
|
42
|
+
* @param {readonly number[]} [options.canvasPalette=CAMP_DEFAULTS.canvasPalette] - Tent canvas sRGB hex tones.
|
|
43
|
+
* @param {Function} [options.color] - Linear RGB colour helper (`C`).
|
|
44
|
+
*/
|
|
45
|
+
export function buildTentLines({
|
|
46
|
+
kit,
|
|
47
|
+
spot,
|
|
48
|
+
random,
|
|
49
|
+
x = 0,
|
|
50
|
+
z = 0,
|
|
51
|
+
turn = 0,
|
|
52
|
+
rows,
|
|
53
|
+
files,
|
|
54
|
+
solid = null,
|
|
55
|
+
placeKit,
|
|
56
|
+
buildTent,
|
|
57
|
+
buildCookfire = null,
|
|
58
|
+
onFire = null,
|
|
59
|
+
canvasPalette = CAMP_DEFAULTS.canvasPalette,
|
|
60
|
+
color = defaultColor,
|
|
61
|
+
}) {
|
|
62
|
+
const c = Math.cos(turn);
|
|
63
|
+
const s = Math.sin(turn);
|
|
64
|
+
for (let i = 0; i < rows; i++)
|
|
65
|
+
for (let j = 0; j < files; j++) {
|
|
66
|
+
if (random() < CAMP_DEFAULTS.tentSkip) continue;
|
|
67
|
+
const dx = (j - (files - 1) / 2) * CAMP_DEFAULTS.fileSpacing + (random() - 0.5);
|
|
68
|
+
const dz = (i - (rows - 1) / 2) * CAMP_DEFAULTS.rowSpacing + (random() - 0.5);
|
|
69
|
+
const px = x + dx * c + dz * s;
|
|
70
|
+
const pz = z - dx * s + dz * c;
|
|
71
|
+
const py = spot.Y(px, pz);
|
|
72
|
+
placeKit(
|
|
73
|
+
kit,
|
|
74
|
+
spot.x0 + px,
|
|
75
|
+
py,
|
|
76
|
+
spot.z0 + pz,
|
|
77
|
+
turn + (random() - 0.5) * 0.12,
|
|
78
|
+
false,
|
|
79
|
+
(B, r) => buildTent(B, r, color(canvasPalette[(random() * canvasPalette.length) | 0], 0.06, random)),
|
|
80
|
+
random,
|
|
81
|
+
);
|
|
82
|
+
if (solid)
|
|
83
|
+
solid.push({ x: spot.x0 + px, z: spot.z0 + pz, hx: CAMP_DEFAULTS.tentCollider.hx, hz: CAMP_DEFAULTS.tentCollider.hz, rot: turn });
|
|
84
|
+
if ((i * files + j) % 4 === 1) {
|
|
85
|
+
const qx = px + 3.1 * c + 0.4 * s;
|
|
86
|
+
const qz = pz - 3.1 * s + 0.4 * c;
|
|
87
|
+
if (buildCookfire) placeKit(kit, spot.x0 + qx, spot.Y(qx, qz), spot.z0 + qz, random() * TAU, false, buildCookfire, random);
|
|
88
|
+
if (onFire) onFire(spot.x0 + qx, spot.Y(qx, qz), spot.z0 + qz, 0.3, 0.6);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Draw up a line of `count` wagons starting at `(x, z)` spaced `gap` metres apart along bearing
|
|
95
|
+
* `turn`, pushing box colliders into `solid` and optionally yielding between small batches via
|
|
96
|
+
* `breathe` so streaming frames stay smooth.
|
|
97
|
+
*
|
|
98
|
+
* @param {object} options
|
|
99
|
+
* @param {object} options.kit - Destination kit builders passed to `placeKit`.
|
|
100
|
+
* @param {{ x0: number, z0: number, Y: (x: number, z: number) => number }} options.spot - Local spot frame (`createSpotFrame`).
|
|
101
|
+
* @param {() => number} options.random - Deterministic PRNG in `[0, 1)`.
|
|
102
|
+
* @param {number} [options.x=0] - Start local X in metres.
|
|
103
|
+
* @param {number} [options.z=0] - Start local Z in metres.
|
|
104
|
+
* @param {number} [options.turn=0] - Line heading in radians.
|
|
105
|
+
* @param {number} options.count - Number of wagons to place.
|
|
106
|
+
* @param {number} options.gap - Spacing between wagons in metres.
|
|
107
|
+
* @param {Array<object> | null} [options.solid=null] - Optional collider output list.
|
|
108
|
+
* @param {(kit: object, x: number, y: number, z: number, yaw: number, plain: boolean, prop: Function, rng: () => number) => void} options.placeKit - Prop placement helper (`kitAt`).
|
|
109
|
+
* @param {(B: object, rng: () => number, covered: boolean) => void} options.buildWagon - Single wagon geometry builder.
|
|
110
|
+
* @param {(() => Promise<void>) | null} [options.breathe=null] - Optional async frame-yield callback between batches.
|
|
111
|
+
* @param {number} [options.batchSize=CAMP_DEFAULTS.wagonsPerBreath] - Wagons built before calling `breathe`.
|
|
112
|
+
* @returns {Promise<void>}
|
|
113
|
+
*/
|
|
114
|
+
export async function buildWagonLine({
|
|
115
|
+
kit,
|
|
116
|
+
spot,
|
|
117
|
+
random,
|
|
118
|
+
x = 0,
|
|
119
|
+
z = 0,
|
|
120
|
+
turn = 0,
|
|
121
|
+
count,
|
|
122
|
+
gap,
|
|
123
|
+
solid = null,
|
|
124
|
+
placeKit,
|
|
125
|
+
buildWagon,
|
|
126
|
+
breathe = null,
|
|
127
|
+
batchSize = CAMP_DEFAULTS.wagonsPerBreath,
|
|
128
|
+
}) {
|
|
129
|
+
for (let first = 0; first < count; first += batchSize) {
|
|
130
|
+
const past = Math.min(first + batchSize, count);
|
|
131
|
+
for (let i = first; i < past; i++) {
|
|
132
|
+
const px = x + Math.sin(turn) * i * gap + (random() - 0.5) * 0.8;
|
|
133
|
+
const pz = z + Math.cos(turn) * i * gap + (random() - 0.5) * 0.8;
|
|
134
|
+
const yaw = turn + (random() - 0.5) * 0.25;
|
|
135
|
+
placeKit(
|
|
136
|
+
kit,
|
|
137
|
+
spot.x0 + px,
|
|
138
|
+
spot.Y(px, pz),
|
|
139
|
+
spot.z0 + pz,
|
|
140
|
+
yaw,
|
|
141
|
+
false,
|
|
142
|
+
(B, r) => buildWagon(B, r, random() < CAMP_DEFAULTS.coveredChance),
|
|
143
|
+
random,
|
|
144
|
+
);
|
|
145
|
+
if (solid)
|
|
146
|
+
solid.push({ x: spot.x0 + px, z: spot.z0 + pz, hx: CAMP_DEFAULTS.wagonCollider.hx, hz: CAMP_DEFAULTS.wagonCollider.hz, rot: yaw });
|
|
147
|
+
}
|
|
148
|
+
if (breathe) await breathe();
|
|
149
|
+
}
|
|
150
|
+
}
|