roamwright 0.61.13 → 0.61.14
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/ruins.html +60 -0
- package/examples/ruins.js +326 -0
- package/geometry/paved-road.js +443 -0
- package/geometry/ruins-hill.js +392 -0
- package/geometry/ruins-mound.js +484 -0
- package/geometry/ruins-rubble.js +161 -0
- package/geometry/strata-rocks.js +270 -0
- package/index.js +29 -0
- package/package.json +1 -1
- package/rendering/paved-ground.js +218 -0
- package/rendering/paved-road.js +353 -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
|
|
33
|
+
Browse all nineteen examples on the [live showcase](https://enestaylan.github.io/roamwright/).
|
|
34
34
|
|
|
35
35
|
| Live example | What the example shows | Source |
|
|
36
36
|
| -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------- |
|
|
@@ -52,6 +52,7 @@ Browse all eighteen examples on the [live showcase](https://enestaylan.github.io
|
|
|
52
52
|
| [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) |
|
|
53
53
|
| [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) |
|
|
54
54
|
| [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) |
|
|
55
|
+
| [Ruins, rocks & paved roads](https://enestaylan.github.io/roamwright/examples/ruins.html?seed=42) | Hilltop ruins, buried-town mounds, bedded outcrops, a paved arch highway with cedar avenue and a flagstone plaza. | [ruins.js](examples/ruins.js) |
|
|
55
56
|
|
|
56
57
|
### Run locally
|
|
57
58
|
|
|
@@ -0,0 +1,60 @@
|
|
|
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="#152c2c" />
|
|
7
|
+
<title>Ruins, rocks & paved roads · 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="A paved stone highway and arch passing bedded outcrops, a ringed plaza, a ruined hilltop and a buried-town mound"
|
|
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/ruins.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 landscape with this seed" aria-label="Rebuild landscape with this seed">→</button>
|
|
33
|
+
</form>
|
|
34
|
+
</div>
|
|
35
|
+
</header>
|
|
36
|
+
<footer>
|
|
37
|
+
<div class="caption">
|
|
38
|
+
<h1>Ruins, rocks & paved roads</h1>
|
|
39
|
+
<p>
|
|
40
|
+
A paved highway with kerbs, milestones, spanning arch and cedar avenue beside a ruined hill, a buried-town mound, bedded outcrops
|
|
41
|
+
and a flagstone plaza.
|
|
42
|
+
</p>
|
|
43
|
+
</div>
|
|
44
|
+
<div class="tools">
|
|
45
|
+
<div class="views" role="group" aria-label="Camera viewpoint">
|
|
46
|
+
<button type="button" data-view="overview" aria-pressed="true">Overview</button>
|
|
47
|
+
<button type="button" data-view="hill" aria-pressed="false">Hill ruin</button>
|
|
48
|
+
<button type="button" data-view="arch" aria-pressed="false">Road & arch</button>
|
|
49
|
+
<button type="button" data-view="plaza" aria-pressed="false">Paved plaza</button>
|
|
50
|
+
<button type="button" data-view="mound" aria-pressed="false">Mound & rocks</button>
|
|
51
|
+
</div>
|
|
52
|
+
<div class="views" role="group" aria-label="Plaza surface">
|
|
53
|
+
<button type="button" data-wet="0" aria-pressed="true">Dry stone</button>
|
|
54
|
+
<button type="button" data-wet="1" aria-pressed="false">After rain</button>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
</footer>
|
|
58
|
+
<script type="module" src="./ruins.js"></script>
|
|
59
|
+
</body>
|
|
60
|
+
</html>
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import {
|
|
3
|
+
buildHillRuin,
|
|
4
|
+
buildMoundRuins,
|
|
5
|
+
buildRubbleHeap,
|
|
6
|
+
createDaylightSky,
|
|
7
|
+
createOrbitCamera,
|
|
8
|
+
createPavedGroundMaterial,
|
|
9
|
+
createRockShapes,
|
|
10
|
+
GeometryBuilder,
|
|
11
|
+
geometryOf,
|
|
12
|
+
layPavedRoad,
|
|
13
|
+
mulberry32,
|
|
14
|
+
scatterRubble,
|
|
15
|
+
} from 'roamwright';
|
|
16
|
+
import { instanceArrays, instancedMesh, putInstance } from 'roamwright/geometry/instances.js';
|
|
17
|
+
import { C, TRS } from 'roamwright/geometry/primitives.js';
|
|
18
|
+
import { sstep, TAU } from 'roamwright/math/scalar.js';
|
|
19
|
+
import { initExample, makeRollingGround } from './stage.js';
|
|
20
|
+
|
|
21
|
+
const { canvas, renderer, camera, scene, worldGroup, seed, noise, hash, shapes } = initExample({
|
|
22
|
+
fallbackSeed: 42,
|
|
23
|
+
fov: 40,
|
|
24
|
+
});
|
|
25
|
+
const { fbm, vnoise } = noise;
|
|
26
|
+
|
|
27
|
+
const HILL = { x: -50, z: -42, r: 36, h: 11.5 };
|
|
28
|
+
const MOUND = { x: 54, z: -38, r: 36, h: 9.5 };
|
|
29
|
+
const PLAZA = { x: 0, z: 16 };
|
|
30
|
+
|
|
31
|
+
// Flat-topped hill on the west, buried-town mound on the east, level highway corridor and plaza in between.
|
|
32
|
+
function plateauRise(dx, dz, r, h) {
|
|
33
|
+
const d = Math.hypot(dx, dz) / r;
|
|
34
|
+
if (d >= 1.25) return 0;
|
|
35
|
+
return h * (1 - sstep(0.68, 1.18, d));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function height(x, z) {
|
|
39
|
+
const corridor = sstep(16, 44, Math.abs(x)) * sstep(22, 46, Math.hypot(x - PLAZA.x, z - PLAZA.z));
|
|
40
|
+
const undulation = (fbm(x * 0.015, z * 0.015, 3, 17) - 0.5) * 4.5 * corridor;
|
|
41
|
+
const hill = plateauRise(x - HILL.x, z - HILL.z, HILL.r, HILL.h);
|
|
42
|
+
const mound = plateauRise(x - MOUND.x, z - MOUND.z, MOUND.r, MOUND.h);
|
|
43
|
+
return 0.4 + undulation + hill + mound;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const earthTone = new THREE.Color(0xcab791);
|
|
47
|
+
const scrubTone = new THREE.Color(0x9a9168);
|
|
48
|
+
const rockTone = new THREE.Color(0xb6a382);
|
|
49
|
+
const hillTone = new THREE.Color(0xc2b296);
|
|
50
|
+
|
|
51
|
+
const terrain = makeRollingGround({
|
|
52
|
+
size: 360,
|
|
53
|
+
segs: 180,
|
|
54
|
+
heightAt: height,
|
|
55
|
+
colorAt: (x, y, z, up, out) => {
|
|
56
|
+
const n = fbm(x * 0.04, z * 0.04, 3, 29);
|
|
57
|
+
out.copy(earthTone).lerp(scrubTone, sstep(0.45, 0.78, n) * 0.55);
|
|
58
|
+
out.lerp(rockTone, 1 - sstep(0.74, 0.94, up));
|
|
59
|
+
const onHill = 1 - sstep(HILL.r * 0.75, HILL.r * 1.15, Math.hypot(x - HILL.x, z - HILL.z));
|
|
60
|
+
out.lerp(hillTone, onHill * 0.6);
|
|
61
|
+
out.multiplyScalar(0.88 + 0.24 * vnoise(x * 0.2, z * 0.2, 31));
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
worldGroup.add(terrain);
|
|
65
|
+
|
|
66
|
+
// Procedural paved plaza at the highway head: concentric flagstone rings, coursed strips, cobbles and optional rain sheen.
|
|
67
|
+
const plazaGeo = new THREE.PlaneGeometry(54, 48, 24, 24).rotateX(-Math.PI / 2);
|
|
68
|
+
const plazaPos = plazaGeo.attributes.position;
|
|
69
|
+
const plazaCols = new Float32Array(plazaPos.count * 3);
|
|
70
|
+
const plazaTint = new THREE.Color();
|
|
71
|
+
for (let i = 0; i < plazaPos.count; i++) {
|
|
72
|
+
const wx = PLAZA.x + plazaPos.getX(i);
|
|
73
|
+
const wz = PLAZA.z + plazaPos.getZ(i);
|
|
74
|
+
plazaPos.setXYZ(i, wx, height(wx, wz) + 0.07, wz);
|
|
75
|
+
const g = 0.86 + 0.1 * vnoise(wx * 0.08, wz * 0.08, 43);
|
|
76
|
+
plazaTint.setRGB(0.8 * g, 0.76 * g, 0.67 * g);
|
|
77
|
+
plazaTint.toArray(plazaCols, i * 3);
|
|
78
|
+
}
|
|
79
|
+
plazaGeo.computeVertexNormals();
|
|
80
|
+
plazaGeo.setAttribute('color', new THREE.BufferAttribute(plazaCols, 3));
|
|
81
|
+
|
|
82
|
+
let wetState = 0;
|
|
83
|
+
function makePlazaMaterial(wet) {
|
|
84
|
+
const mat = createPavedGroundMaterial({
|
|
85
|
+
origin: PLAZA,
|
|
86
|
+
rings: [{ x: 0, z: 0, r: 14, ring: 1.45 }],
|
|
87
|
+
strips: [
|
|
88
|
+
{ x0: -27, z0: -4.2, x1: 27, z1: 4.2, len: 1.25, course: 0.95, along: 'x', wear: 2.2 },
|
|
89
|
+
{ x0: -5.4, z0: -24, x1: 5.4, z1: 24, len: 1.3, course: 1.05, along: 'z', wear: 2.8 },
|
|
90
|
+
],
|
|
91
|
+
cobble: 0.2,
|
|
92
|
+
earth: 0.18,
|
|
93
|
+
wet,
|
|
94
|
+
pools: [
|
|
95
|
+
[-6, 7, 5.5, 4],
|
|
96
|
+
[7, -5, 6.2, 4.2],
|
|
97
|
+
[2, 11, 4.8, 3.6],
|
|
98
|
+
[-9, -8, 5, 3.8],
|
|
99
|
+
],
|
|
100
|
+
});
|
|
101
|
+
mat.polygonOffset = true;
|
|
102
|
+
mat.polygonOffsetFactor = mat.polygonOffsetUnits = -2;
|
|
103
|
+
return mat;
|
|
104
|
+
}
|
|
105
|
+
const plazaMesh = new THREE.Mesh(plazaGeo, makePlazaMaterial(0));
|
|
106
|
+
plazaMesh.receiveShadow = true;
|
|
107
|
+
worldGroup.add(plazaMesh);
|
|
108
|
+
|
|
109
|
+
// Shared weathered stone, rock and pool materials.
|
|
110
|
+
const stoneMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.9, metalness: 0.02 });
|
|
111
|
+
const rockMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.94, flatShading: true });
|
|
112
|
+
const poolMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.16, metalness: 0.18 });
|
|
113
|
+
const mudWallMat = new THREE.MeshStandardMaterial({ color: 0xc2ab87, roughness: 0.96 });
|
|
114
|
+
|
|
115
|
+
// Hilltop ruin: tumbled blocks, leaning tower remnants, wall-stump rooms, flank masonry, scree and draped hollows.
|
|
116
|
+
const hillKit = {
|
|
117
|
+
hill: { u: HILL.x, v: -HILL.z, r: HILL.r },
|
|
118
|
+
stone: new GeometryBuilder(),
|
|
119
|
+
rock: new GeometryBuilder(),
|
|
120
|
+
orders: [],
|
|
121
|
+
Y: (u, v) => height(u, -v),
|
|
122
|
+
G: (u, v) => height(u, -v),
|
|
123
|
+
solid: () => {},
|
|
124
|
+
};
|
|
125
|
+
buildHillRuin(hillKit, mulberry32(seed * 17 + 3), {
|
|
126
|
+
shapes,
|
|
127
|
+
shape: { tumbled: 68, rooms: 9, flank: 220, scree: 900, oldWalls: 110, pools: 4, sinkholes: 3 },
|
|
128
|
+
});
|
|
129
|
+
// Fallen rubble heaps flanking the plaza edges.
|
|
130
|
+
buildRubbleHeap(hillKit.stone, mulberry32(seed * 23 + 7), {
|
|
131
|
+
x: -20,
|
|
132
|
+
z: 28,
|
|
133
|
+
radius: 4.5,
|
|
134
|
+
count: 20,
|
|
135
|
+
ground: height,
|
|
136
|
+
rock: shapes.rock,
|
|
137
|
+
});
|
|
138
|
+
scatterRubble(hillKit.rock, mulberry32(seed * 29 + 11), {
|
|
139
|
+
x: 22,
|
|
140
|
+
z: 24,
|
|
141
|
+
radius: 5.5,
|
|
142
|
+
count: 24,
|
|
143
|
+
ground: height,
|
|
144
|
+
hue: 0xc8b89a,
|
|
145
|
+
scale: 1.15,
|
|
146
|
+
rock: shapes.rock,
|
|
147
|
+
});
|
|
148
|
+
hillKit.stone.mesh(stoneMat, worldGroup);
|
|
149
|
+
hillKit.rock.mesh(rockMat, worldGroup);
|
|
150
|
+
for (const order of hillKit.orders) {
|
|
151
|
+
if (!order.mesh) continue;
|
|
152
|
+
order.mesh.mesh(order.mat === 'pool' ? poolMat : rockMat, worldGroup, Boolean(order.shadow));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Buried-town mound: eroded mud-brick wall stumps and strewn potsherds.
|
|
156
|
+
const moundBuilt = buildMoundRuins(MOUND, seed * 31 + 19, false, height, {
|
|
157
|
+
noise: vnoise,
|
|
158
|
+
shape: { sherds: 520, wallsReach: 34, standing: 0.78 },
|
|
159
|
+
});
|
|
160
|
+
if (moundBuilt.walls.index.length) {
|
|
161
|
+
const g = new THREE.BufferGeometry();
|
|
162
|
+
g.setAttribute('position', new THREE.BufferAttribute(moundBuilt.walls.position, 3));
|
|
163
|
+
g.setAttribute('normal', new THREE.BufferAttribute(moundBuilt.walls.normal, 3));
|
|
164
|
+
g.setAttribute('uv', new THREE.BufferAttribute(moundBuilt.walls.uv, 2));
|
|
165
|
+
g.setIndex(new THREE.BufferAttribute(moundBuilt.walls.index, 1));
|
|
166
|
+
const mesh = new THREE.Mesh(g, mudWallMat);
|
|
167
|
+
mesh.castShadow = mesh.receiveShadow = true;
|
|
168
|
+
worldGroup.add(mesh);
|
|
169
|
+
}
|
|
170
|
+
if (moundBuilt.sherds?.position.length) {
|
|
171
|
+
const sherdMesh = new THREE.Mesh(geometryOf(moundBuilt.sherds), rockMat);
|
|
172
|
+
sherdMesh.receiveShadow = true;
|
|
173
|
+
worldGroup.add(sherdMesh);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Paved stone highway with kerbs, milestones, spanning arch and a roadside avenue of cedars.
|
|
177
|
+
const roadBuilt = layPavedRoad({
|
|
178
|
+
road: {
|
|
179
|
+
pts: [
|
|
180
|
+
[0, 152],
|
|
181
|
+
[0, 102],
|
|
182
|
+
[0, 56],
|
|
183
|
+
[0, 34],
|
|
184
|
+
],
|
|
185
|
+
w: 9.2,
|
|
186
|
+
trees: 24,
|
|
187
|
+
},
|
|
188
|
+
ground: height,
|
|
189
|
+
parent: worldGroup,
|
|
190
|
+
random: mulberry32(seed * 37 + 5),
|
|
191
|
+
stoneMaterial: stoneMat,
|
|
192
|
+
pavingReach: { value: 180 },
|
|
193
|
+
pavingBand: 24,
|
|
194
|
+
arch: true,
|
|
195
|
+
avenueOffset: 9.2,
|
|
196
|
+
cedarSeed: seed * 41 + 9,
|
|
197
|
+
hash,
|
|
198
|
+
camera,
|
|
199
|
+
getReach: () => 140,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// Bedded strata outcrops and wind-worn boulders instanced around the hill foot, mound and road verges.
|
|
203
|
+
const rockLib = createRockShapes({ noise: vnoise });
|
|
204
|
+
const outcrops = rockLib.outcropShapes();
|
|
205
|
+
const outcropBatches = outcrops.map(() => ({ copies: instanceArrays(30), count: 0 }));
|
|
206
|
+
const stoneBatches = rockLib.stones.map(() => ({ copies: instanceArrays(70), count: 0 }));
|
|
207
|
+
const rockPalette = [0xcfb590, 0xbfa282, 0xd8c19e, 0xb89674];
|
|
208
|
+
const rockRng = mulberry32(seed * 53 + 13);
|
|
209
|
+
|
|
210
|
+
for (let i = 0; i < 64; i++) {
|
|
211
|
+
const x = (rockRng() - 0.5) * 200;
|
|
212
|
+
const z = (rockRng() - 0.5) * 180;
|
|
213
|
+
if (Math.abs(x) < 15 && z > 20) continue; // keep highway clear
|
|
214
|
+
if (Math.hypot(x - PLAZA.x, z - PLAZA.z) < 28) continue;
|
|
215
|
+
if (Math.hypot(x - HILL.x, z - HILL.z) < HILL.r * 0.85) continue;
|
|
216
|
+
if (Math.hypot(x - MOUND.x, z - MOUND.z) < MOUND.r * 0.8) continue;
|
|
217
|
+
const s = 1.6 + rockRng() * 2.6;
|
|
218
|
+
const col = C(rockPalette[i % rockPalette.length], 0.08, rockRng);
|
|
219
|
+
const batch = outcropBatches[i % outcropBatches.length];
|
|
220
|
+
if (batch.count < 30)
|
|
221
|
+
putInstance(batch.copies, batch.count++, TRS(x, height(x, z), z, s, s * (0.85 + rockRng() * 0.4), s, rockRng() * TAU), ...col);
|
|
222
|
+
}
|
|
223
|
+
for (let i = 0; i < 160; i++) {
|
|
224
|
+
const x = (rockRng() - 0.5) * 190;
|
|
225
|
+
const z = (rockRng() - 0.5) * 170;
|
|
226
|
+
if (Math.abs(x) < 11 && z > 24) continue;
|
|
227
|
+
if (Math.hypot(x - PLAZA.x, z - PLAZA.z) < 23) continue;
|
|
228
|
+
const s = 0.45 + rockRng() * 1.1;
|
|
229
|
+
const col = C(rockPalette[i % rockPalette.length], 0.1, rockRng);
|
|
230
|
+
const batch = stoneBatches[i % stoneBatches.length];
|
|
231
|
+
if (batch.count < 70)
|
|
232
|
+
putInstance(
|
|
233
|
+
batch.copies,
|
|
234
|
+
batch.count++,
|
|
235
|
+
TRS(x, height(x, z) + s * 0.12, z, s, s * (0.7 + rockRng() * 0.35), s, rockRng() * TAU, (rockRng() - 0.5) * 0.4),
|
|
236
|
+
...col,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
const tintedRockMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.93 });
|
|
240
|
+
outcropBatches.forEach(({ copies, count }, i) => {
|
|
241
|
+
if (!count) return;
|
|
242
|
+
const m = instancedMesh(outcrops[i], tintedRockMat, {
|
|
243
|
+
matrices: copies.matrices.subarray(0, count * 16),
|
|
244
|
+
colours: copies.colours.subarray(0, count * 3),
|
|
245
|
+
});
|
|
246
|
+
m.castShadow = m.receiveShadow = true;
|
|
247
|
+
worldGroup.add(m);
|
|
248
|
+
});
|
|
249
|
+
stoneBatches.forEach(({ copies, count }, i) => {
|
|
250
|
+
if (!count) return;
|
|
251
|
+
const m = instancedMesh(rockLib.stones[i], tintedRockMat, {
|
|
252
|
+
matrices: copies.matrices.subarray(0, count * 16),
|
|
253
|
+
colours: copies.colours.subarray(0, count * 3),
|
|
254
|
+
});
|
|
255
|
+
m.castShadow = false;
|
|
256
|
+
m.receiveShadow = true;
|
|
257
|
+
worldGroup.add(m);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// Warm sunlit sky and directional shadows.
|
|
261
|
+
createDaylightSky({
|
|
262
|
+
scene,
|
|
263
|
+
renderer,
|
|
264
|
+
noise,
|
|
265
|
+
sky: {
|
|
266
|
+
zenith: [0.22, 0.46, 0.72],
|
|
267
|
+
horizon: [0.89, 0.86, 0.78],
|
|
268
|
+
sunDir: [0.68, 0.42, 0.58],
|
|
269
|
+
},
|
|
270
|
+
sunPosition: [120, 74, 102],
|
|
271
|
+
sunIntensity: 2.8,
|
|
272
|
+
sunColor: 0xfff2d8,
|
|
273
|
+
shadowRadius: 125,
|
|
274
|
+
shadowFar: 360,
|
|
275
|
+
normalBias: 0.05,
|
|
276
|
+
fogColor: 0xe2d8c5,
|
|
277
|
+
fogDensity: 0.0012,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
const VIEWS = {
|
|
281
|
+
overview: { eye: [52, 32, 92], target: [-2, 6, -4] },
|
|
282
|
+
hill: { eye: [-10, 26, -6], target: [HILL.x, HILL.h + 1, HILL.z] },
|
|
283
|
+
arch: { eye: [3, 6.5, 92], target: [0, 6, 42] },
|
|
284
|
+
plaza: { eye: [22, 13, 38], target: [PLAZA.x, 1, PLAZA.z] },
|
|
285
|
+
mound: { eye: [22, 22, 2], target: [MOUND.x, MOUND.h, MOUND.z] },
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const rig = createOrbitCamera({
|
|
289
|
+
camera,
|
|
290
|
+
canvas,
|
|
291
|
+
renderer,
|
|
292
|
+
scene,
|
|
293
|
+
views: VIEWS,
|
|
294
|
+
initialView: 'overview',
|
|
295
|
+
groundAt: height,
|
|
296
|
+
minClearance: 1.5,
|
|
297
|
+
minDistance: 8,
|
|
298
|
+
maxDistance: 240,
|
|
299
|
+
onDraw: () => {},
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
// Snap cedar LODs immediately for the initial view before the first frame renders.
|
|
303
|
+
roadBuilt.hand?.(1);
|
|
304
|
+
|
|
305
|
+
for (const btn of document.querySelectorAll('[data-wet]')) {
|
|
306
|
+
btn.addEventListener('click', () => {
|
|
307
|
+
const next = Number(btn.dataset.wet);
|
|
308
|
+
if (next === wetState) return;
|
|
309
|
+
wetState = next;
|
|
310
|
+
const old = plazaMesh.material;
|
|
311
|
+
plazaMesh.material = makePlazaMaterial(wetState);
|
|
312
|
+
old.dispose();
|
|
313
|
+
for (const b of document.querySelectorAll('[data-wet]')) b.setAttribute('aria-pressed', String(Number(b.dataset.wet) === wetState));
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const clock = new THREE.Timer();
|
|
318
|
+
function animate() {
|
|
319
|
+
clock.update();
|
|
320
|
+
const dt = Math.min(0.1, clock.getDelta());
|
|
321
|
+
rig.clampCamera();
|
|
322
|
+
roadBuilt.hand?.(dt);
|
|
323
|
+
renderer.render(scene, camera);
|
|
324
|
+
requestAnimationFrame(animate);
|
|
325
|
+
}
|
|
326
|
+
animate();
|