roamwright 0.61.18 → 0.61.20
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 +1 -2
- package/geometry/primitives.js +13 -0
- package/index.js +2 -1
- package/motion/triangle-height-field.js +177 -0
- package/package.json +1 -1
- package/examples/ruins.html +0 -61
- package/examples/ruins.js +0 -474
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 examples on the [live showcase](https://enestaylan.github.io/roamwright/).
|
|
34
34
|
|
|
35
35
|
| Live example | What the example shows | Source |
|
|
36
36
|
| --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
|
|
@@ -53,7 +53,6 @@ Browse all twenty-one examples on the [live showcase](https://enestaylan.github.
|
|
|
53
53
|
| [A baked land](https://enestaylan.github.io/roamwright/examples/land.html?seed=7) | One height sheet baked row by row with erosion, coast, river ford, banked road, cliff-faced tel, quarry and upland mere. | [land.js](examples/land.js) |
|
|
54
54
|
| [Island](https://enestaylan.github.io/roamwright/examples/island.html?seed=42) | Fractal terrain shapes a coastline, sandy coves, weathered boulders and coastal pines in turquoise shallows. | [island.js](examples/island.js) |
|
|
55
55
|
| [Pacing and measuring](https://enestaylan.github.io/roamwright/examples/pacing.html?seed=42) | Device-aware presets, ground render order, frame-pacing watch and a live performance box over a coastal valley. | [pacing.js](examples/pacing.js) |
|
|
56
|
-
| [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) |
|
|
57
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) |
|
|
58
57
|
|
|
59
58
|
### Run locally
|
package/geometry/primitives.js
CHANGED
|
@@ -203,6 +203,19 @@ export function plainUnitShapes() {
|
|
|
203
203
|
};
|
|
204
204
|
return plain;
|
|
205
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* The unit shapes a simple figure is built from, each new on every call: a torso and a skirt widening downward from their
|
|
208
|
+
* foot, a round head about its centre, and an open half-cloak hanging from its top edge, its back toward -z.
|
|
209
|
+
* @returns {{torso: THREE.BufferGeometry, skirt: THREE.BufferGeometry, head: THREE.BufferGeometry, cloak: THREE.BufferGeometry}}
|
|
210
|
+
*/
|
|
211
|
+
export function createFigureUnitShapes() {
|
|
212
|
+
return {
|
|
213
|
+
torso: new THREE.CylinderGeometry(0.5, 0.4, 1, 12).translate(0, 0.5, 0),
|
|
214
|
+
skirt: new THREE.CylinderGeometry(0.32, 0.5, 1, 12).translate(0, 0.5, 0),
|
|
215
|
+
head: new THREE.IcosahedronGeometry(0.5, 2),
|
|
216
|
+
cloak: new THREE.CylinderGeometry(0.5, 0.64, 1, 10, 3, true, Math.PI * 0.5, Math.PI).translate(0, -0.5, 0),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
206
219
|
function C(hex, jitter = 0, random) {
|
|
207
220
|
// sRGB hex -> linear [r,g,b], optionally brightness-jittered
|
|
208
221
|
colorScratch.setHex(hex);
|
package/index.js
CHANGED
|
@@ -29,10 +29,11 @@ export { createNoise } from './math/noise.js';
|
|
|
29
29
|
export { mulberry32 } from './math/random.js';
|
|
30
30
|
export { GB as GeometryBuilder, geometryOf } from './geometry/builder.js';
|
|
31
31
|
export { stillMesh } from './geometry/still-mesh.js';
|
|
32
|
-
export { createUnitShapes } from './geometry/primitives.js';
|
|
32
|
+
export { createUnitShapes, createFigureUnitShapes } from './geometry/primitives.js';
|
|
33
33
|
|
|
34
34
|
// ── Spaces & player motion ───────────────────────────────────────────────
|
|
35
35
|
export { createSpaces } from './motion/spaces.js';
|
|
36
|
+
export { createTriangleHeightField } from './motion/triangle-height-field.js';
|
|
36
37
|
export { createPlayer } from './motion/player.js';
|
|
37
38
|
|
|
38
39
|
// ── Terrain & land baking ────────────────────────────────────────────────
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A walkable height field over a triangle soup, for a solid the player can walk on and be stopped by, a moving one
|
|
3
|
+
* included (query it in the solid's own frame). Faces are sorted into floors and cliffs by how steeply they stand, kept
|
|
4
|
+
* packed ten numbers each, and listed by the cells of a square grid they cover, so a query reads only the faces near it.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const FACE = 10; // a face's corner, its two edges from it, and 1/area seen from above for a floor (0 for a wall)
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Makes an empty height field to fill with triangles.
|
|
11
|
+
* @param {object} [options]
|
|
12
|
+
* @param {number} [options.cell=8] the grid's cell size, in the soup's units
|
|
13
|
+
* @param {number} [options.firstFaces=4096] faces room is made for at first; the room doubles as it fills
|
|
14
|
+
* @param {number} [options.floorSlope=0.17] a face is a floor where its upward share of the normal is over this
|
|
15
|
+
* @param {number} [options.cliffSlope=0.62] and a cliff where it is under this (a face between the two is both)
|
|
16
|
+
* @param {number} [options.reach=0.31] how far ahead of a step a cliff stops it
|
|
17
|
+
* @param {number[]} [options.rays] the heights over the feet at which a step is tested against cliffs (knee and eye)
|
|
18
|
+
* @returns {{
|
|
19
|
+
* add(positions: ArrayLike<number>, start?: number): void,
|
|
20
|
+
* seal(): void,
|
|
21
|
+
* at(x: number, z: number, limit: number): number,
|
|
22
|
+
* blocked(x: number, feet: number, z: number, toX: number, toZ: number): boolean,
|
|
23
|
+
* }} `add` takes non-indexed triangle positions (nine numbers a face) from `start`; `seal` lets go of unused room once
|
|
24
|
+
* every face is in; `at` is the highest floor under (x, z) no higher than `limit`, or -Infinity; `blocked` says
|
|
25
|
+
* whether a step from (x, z) to (toX, toZ) with the feet at `feet` runs into a cliff facing it.
|
|
26
|
+
*/
|
|
27
|
+
export function createTriangleHeightField({
|
|
28
|
+
cell = 8,
|
|
29
|
+
firstFaces = 4096,
|
|
30
|
+
floorSlope = 0.17,
|
|
31
|
+
cliffSlope = 0.62,
|
|
32
|
+
reach = 0.31,
|
|
33
|
+
rays = [0.97, 0.97 + 0.68],
|
|
34
|
+
} = {}) {
|
|
35
|
+
const cells = new Map(),
|
|
36
|
+
cliffs = new Map(),
|
|
37
|
+
key = (x, z) => x * 65536 + z;
|
|
38
|
+
let faces = new Float32Array(firstFaces * FACE),
|
|
39
|
+
count = 0;
|
|
40
|
+
function store(map, k, face) {
|
|
41
|
+
let bucket = map.get(k);
|
|
42
|
+
if (!bucket) {
|
|
43
|
+
bucket = [];
|
|
44
|
+
map.set(k, bucket);
|
|
45
|
+
}
|
|
46
|
+
bucket.push(face);
|
|
47
|
+
}
|
|
48
|
+
function newFace(x, y, z, ux, uy, uz, vx, vy, vz, inv) {
|
|
49
|
+
if ((count + 1) * FACE > faces.length) {
|
|
50
|
+
const more = new Float32Array(faces.length * 2);
|
|
51
|
+
more.set(faces);
|
|
52
|
+
faces = more;
|
|
53
|
+
}
|
|
54
|
+
const o = count * FACE;
|
|
55
|
+
faces[o] = x;
|
|
56
|
+
faces[o + 1] = y;
|
|
57
|
+
faces[o + 2] = z;
|
|
58
|
+
faces[o + 3] = ux;
|
|
59
|
+
faces[o + 4] = uy;
|
|
60
|
+
faces[o + 5] = uz;
|
|
61
|
+
faces[o + 6] = vx;
|
|
62
|
+
faces[o + 7] = vy;
|
|
63
|
+
faces[o + 8] = vz;
|
|
64
|
+
faces[o + 9] = inv;
|
|
65
|
+
return count++;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
add(p, start = 0) {
|
|
69
|
+
for (let i = start; i < p.length; i += 9) {
|
|
70
|
+
const x = p[i],
|
|
71
|
+
y = p[i + 1],
|
|
72
|
+
z = p[i + 2];
|
|
73
|
+
const ux = p[i + 3] - x,
|
|
74
|
+
uy = p[i + 4] - y,
|
|
75
|
+
uz = p[i + 5] - z,
|
|
76
|
+
vx = p[i + 6] - x,
|
|
77
|
+
vy = p[i + 7] - y,
|
|
78
|
+
vz = p[i + 8] - z;
|
|
79
|
+
const area = uz * vx - ux * vz;
|
|
80
|
+
const normal = Math.hypot(uy * vz - uz * vy, area, ux * vy - uy * vx);
|
|
81
|
+
if (normal < 1e-5) continue;
|
|
82
|
+
const isFloor = area > normal * floorSlope,
|
|
83
|
+
isCliff = area < normal * cliffSlope;
|
|
84
|
+
if (!isFloor && !isCliff) continue;
|
|
85
|
+
const face = newFace(x, y, z, ux, uy, uz, vx, vy, vz, isFloor ? 1 / area : 0);
|
|
86
|
+
const bx = p[i + 3],
|
|
87
|
+
bz = p[i + 5],
|
|
88
|
+
cx = p[i + 6],
|
|
89
|
+
cz = p[i + 8];
|
|
90
|
+
const x0 = Math.floor(Math.min(x, bx, cx) / cell),
|
|
91
|
+
x1 = Math.floor(Math.max(x, bx, cx) / cell);
|
|
92
|
+
const z0 = Math.floor(Math.min(z, bz, cz) / cell),
|
|
93
|
+
z1 = Math.floor(Math.max(z, bz, cz) / cell);
|
|
94
|
+
for (let ix = x0; ix <= x1; ix++)
|
|
95
|
+
for (let iz = z0; iz <= z1; iz++) {
|
|
96
|
+
const k = key(ix, iz);
|
|
97
|
+
if (isFloor) store(cells, k, face);
|
|
98
|
+
if (isCliff) store(cliffs, k, face);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
seal() {
|
|
103
|
+
faces = faces.slice(0, count * FACE);
|
|
104
|
+
},
|
|
105
|
+
at(x, z, limit) {
|
|
106
|
+
const list = cells.get(key(Math.floor(x / cell), Math.floor(z / cell)));
|
|
107
|
+
let best = -Infinity;
|
|
108
|
+
if (!list) return best;
|
|
109
|
+
for (let i = 0; i < list.length; i++) {
|
|
110
|
+
const o = list[i] * FACE,
|
|
111
|
+
dx = x - faces[o],
|
|
112
|
+
dz = z - faces[o + 2],
|
|
113
|
+
ux = faces[o + 3],
|
|
114
|
+
uz = faces[o + 5],
|
|
115
|
+
vx = faces[o + 6],
|
|
116
|
+
vz = faces[o + 8],
|
|
117
|
+
inv = faces[o + 9];
|
|
118
|
+
const u = (dz * vx - dx * vz) * inv,
|
|
119
|
+
v = (uz * dx - ux * dz) * inv;
|
|
120
|
+
if (u < -1e-6 || v < -1e-6 || u + v > 1.000001) continue;
|
|
121
|
+
const y = faces[o + 1] + u * faces[o + 4] + v * faces[o + 7];
|
|
122
|
+
if (y > best && y <= limit) best = y;
|
|
123
|
+
}
|
|
124
|
+
return best;
|
|
125
|
+
},
|
|
126
|
+
blocked(x, feet, z, toX, toZ) {
|
|
127
|
+
const sx = toX - x,
|
|
128
|
+
sz = toZ - z,
|
|
129
|
+
length = Math.hypot(sx, sz);
|
|
130
|
+
if (length < 1e-5) return false;
|
|
131
|
+
const dx = sx * (1 + reach / length),
|
|
132
|
+
dz = sz * (1 + reach / length);
|
|
133
|
+
const x0 = Math.floor(Math.min(x, x + dx) / cell),
|
|
134
|
+
x1 = Math.floor(Math.max(x, x + dx) / cell);
|
|
135
|
+
const z0 = Math.floor(Math.min(z, z + dz) / cell),
|
|
136
|
+
z1 = Math.floor(Math.max(z, z + dz) / cell);
|
|
137
|
+
for (let ix = x0; ix <= x1; ix++)
|
|
138
|
+
for (let iz = z0; iz <= z1; iz++) {
|
|
139
|
+
const list = cliffs.get(key(ix, iz));
|
|
140
|
+
if (!list) continue;
|
|
141
|
+
for (let i = 0; i < list.length; i++) {
|
|
142
|
+
const o = list[i] * FACE,
|
|
143
|
+
ax = faces[o],
|
|
144
|
+
ay = faces[o + 1],
|
|
145
|
+
az = faces[o + 2],
|
|
146
|
+
ux = faces[o + 3],
|
|
147
|
+
uy = faces[o + 4],
|
|
148
|
+
uz = faces[o + 5],
|
|
149
|
+
vx = faces[o + 6],
|
|
150
|
+
vy = faces[o + 7],
|
|
151
|
+
vz = faces[o + 8];
|
|
152
|
+
// level rays at each height, culling back faces so a walker touching a wall can still step away from it
|
|
153
|
+
const hx = -dz * vy,
|
|
154
|
+
hy = dz * vx - dx * vz,
|
|
155
|
+
hz = dx * vy;
|
|
156
|
+
const det = ux * hx + uy * hy + uz * hz;
|
|
157
|
+
if (det <= 1e-6) continue;
|
|
158
|
+
const px = x - ax,
|
|
159
|
+
pz = z - az,
|
|
160
|
+
qy = pz * ux - px * uz;
|
|
161
|
+
for (let r = 0; r < rays.length; r++) {
|
|
162
|
+
const py = feet + rays[r] - ay,
|
|
163
|
+
u = (px * hx + py * hy + pz * hz) / det;
|
|
164
|
+
if (u < 0 || u > 1) continue;
|
|
165
|
+
const qx = py * uz - pz * uy,
|
|
166
|
+
qz = px * uy - py * ux;
|
|
167
|
+
const v = (dx * qx + dz * qz) / det;
|
|
168
|
+
if (v < 0 || u + v > 1) continue;
|
|
169
|
+
const t = (vx * qx + vy * qy + vz * qz) / det;
|
|
170
|
+
if (t > 0 && t <= 1) return true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "roamwright",
|
|
3
|
-
"version": "0.61.
|
|
3
|
+
"version": "0.61.20",
|
|
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",
|
package/examples/ruins.html
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
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, a stepped mesa
|
|
41
|
-
cliff, a sanctuary of dressed ashlar, fluted columns and lanterns, an impact crater 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="masonry" aria-pressed="false">Masonry & columns</button>
|
|
48
|
-
<button type="button" data-view="hill" aria-pressed="false">Hill ruin</button>
|
|
49
|
-
<button type="button" data-view="arch" aria-pressed="false">Road & arch</button>
|
|
50
|
-
<button type="button" data-view="plaza" aria-pressed="false">Paved plaza</button>
|
|
51
|
-
<button type="button" data-view="mound" aria-pressed="false">Mound & rocks</button>
|
|
52
|
-
</div>
|
|
53
|
-
<div class="views" role="group" aria-label="Plaza surface">
|
|
54
|
-
<button type="button" data-wet="0" aria-pressed="true">Dry stone</button>
|
|
55
|
-
<button type="button" data-wet="1" aria-pressed="false">After rain</button>
|
|
56
|
-
</div>
|
|
57
|
-
</div>
|
|
58
|
-
</footer>
|
|
59
|
-
<script type="module" src="./ruins.js"></script>
|
|
60
|
-
</body>
|
|
61
|
-
</html>
|
package/examples/ruins.js
DELETED
|
@@ -1,474 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import {
|
|
3
|
-
addLampStand,
|
|
4
|
-
addStillPool,
|
|
5
|
-
addWallLantern,
|
|
6
|
-
buildAshlarWall,
|
|
7
|
-
buildColumnDrum,
|
|
8
|
-
buildCraterBowl,
|
|
9
|
-
buildFlagstones,
|
|
10
|
-
buildHillRuin,
|
|
11
|
-
buildMesaCliff,
|
|
12
|
-
buildMoundRuins,
|
|
13
|
-
buildRubbleHeap,
|
|
14
|
-
buildRubbleMound,
|
|
15
|
-
buildRuinWall,
|
|
16
|
-
createDaylightSky,
|
|
17
|
-
createOrbitCamera,
|
|
18
|
-
createPavedGroundMaterial,
|
|
19
|
-
createRockShapes,
|
|
20
|
-
createShapeBatches,
|
|
21
|
-
GeometryBuilder,
|
|
22
|
-
geometryOf,
|
|
23
|
-
layPavedRoad,
|
|
24
|
-
mulberry32,
|
|
25
|
-
scatterRubble,
|
|
26
|
-
} from 'roamwright';
|
|
27
|
-
import { C, TRS } from 'roamwright/geometry/primitives.js';
|
|
28
|
-
import { sstep, TAU } from 'roamwright/math/scalar.js';
|
|
29
|
-
import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
|
|
30
|
-
import { initExample } from './stage.js';
|
|
31
|
-
|
|
32
|
-
const { canvas, renderer, camera, scene, worldGroup, seed, noise, hash, shapes } = initExample({
|
|
33
|
-
fallbackSeed: 42,
|
|
34
|
-
fov: 40,
|
|
35
|
-
});
|
|
36
|
-
const { fbm, vnoise } = noise;
|
|
37
|
-
|
|
38
|
-
const HILL = { x: -50, z: -42, r: 36, h: 11.5 };
|
|
39
|
-
const MOUND = { x: 54, z: -38, r: 36, h: 9.5 };
|
|
40
|
-
const MESA = { x: -66, z: 36, r: 22, h: 10.5 };
|
|
41
|
-
const PLAZA = { x: 0, z: 16 };
|
|
42
|
-
const COURTYARD = { x: 34, z: 22 };
|
|
43
|
-
|
|
44
|
-
// Flat-topped hill on the west, buried-town mound on the east, stepped mesa to the southwest, level highway and plaza between.
|
|
45
|
-
function plateauRise(dx, dz, r, h) {
|
|
46
|
-
const d = Math.hypot(dx, dz) / r;
|
|
47
|
-
if (d >= 1.25) return 0;
|
|
48
|
-
return h * (1 - sstep(0.68, 1.18, d));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function height(x, z) {
|
|
52
|
-
const corridor =
|
|
53
|
-
sstep(16, 44, Math.abs(x)) *
|
|
54
|
-
sstep(22, 46, Math.hypot(x - PLAZA.x, z - PLAZA.z)) *
|
|
55
|
-
sstep(12, 26, Math.hypot(x - COURTYARD.x, z - COURTYARD.z));
|
|
56
|
-
const undulation = (fbm(x * 0.015, z * 0.015, 3, 17) - 0.5) * 4.5 * corridor;
|
|
57
|
-
const hill = plateauRise(x - HILL.x, z - HILL.z, HILL.r, HILL.h);
|
|
58
|
-
const mound = plateauRise(x - MOUND.x, z - MOUND.z, MOUND.r, MOUND.h);
|
|
59
|
-
const mesa = plateauRise(x - MESA.x, z - MESA.z, MESA.r, MESA.h);
|
|
60
|
-
return 0.4 + undulation + hill + mound + mesa;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const earthTone = new THREE.Color(0xcab791);
|
|
64
|
-
const scrubTone = new THREE.Color(0x9a9168);
|
|
65
|
-
const rockTone = new THREE.Color(0xb6a382);
|
|
66
|
-
const hillTone = new THREE.Color(0xc2b296);
|
|
67
|
-
const mesaTone = new THREE.Color(0x9a6448);
|
|
68
|
-
|
|
69
|
-
const terrain = createHeightfieldMesh({
|
|
70
|
-
size: 360,
|
|
71
|
-
segs: 180,
|
|
72
|
-
heightAt: height,
|
|
73
|
-
colorAt: (x, y, z, up, out) => {
|
|
74
|
-
const n = fbm(x * 0.04, z * 0.04, 3, 29);
|
|
75
|
-
out.copy(earthTone).lerp(scrubTone, sstep(0.45, 0.78, n) * 0.55);
|
|
76
|
-
out.lerp(rockTone, 1 - sstep(0.74, 0.94, up));
|
|
77
|
-
const onHill = 1 - sstep(HILL.r * 0.75, HILL.r * 1.15, Math.hypot(x - HILL.x, z - HILL.z));
|
|
78
|
-
out.lerp(hillTone, onHill * 0.6);
|
|
79
|
-
const onMesa = 1 - sstep(MESA.r * 0.72, MESA.r * 1.05, Math.hypot(x - MESA.x, z - MESA.z));
|
|
80
|
-
out.lerp(mesaTone, onMesa * 0.82);
|
|
81
|
-
out.multiplyScalar(0.88 + 0.24 * vnoise(x * 0.2, z * 0.2, 31));
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
worldGroup.add(terrain);
|
|
85
|
-
|
|
86
|
-
// Procedural paved plaza at the highway head: concentric flagstone rings, coursed strips, cobbles and optional rain sheen.
|
|
87
|
-
const plazaGeo = new THREE.PlaneGeometry(54, 48, 24, 24).rotateX(-Math.PI / 2);
|
|
88
|
-
const plazaPos = plazaGeo.attributes.position;
|
|
89
|
-
const plazaCols = new Float32Array(plazaPos.count * 3);
|
|
90
|
-
const plazaTint = new THREE.Color();
|
|
91
|
-
for (let i = 0; i < plazaPos.count; i++) {
|
|
92
|
-
const wx = PLAZA.x + plazaPos.getX(i);
|
|
93
|
-
const wz = PLAZA.z + plazaPos.getZ(i);
|
|
94
|
-
plazaPos.setXYZ(i, wx, height(wx, wz) + 0.07, wz);
|
|
95
|
-
const g = 0.86 + 0.1 * vnoise(wx * 0.08, wz * 0.08, 43);
|
|
96
|
-
plazaTint.setRGB(0.8 * g, 0.76 * g, 0.67 * g);
|
|
97
|
-
plazaTint.toArray(plazaCols, i * 3);
|
|
98
|
-
}
|
|
99
|
-
plazaGeo.computeVertexNormals();
|
|
100
|
-
plazaGeo.setAttribute('color', new THREE.BufferAttribute(plazaCols, 3));
|
|
101
|
-
|
|
102
|
-
let wetState = 0;
|
|
103
|
-
function makePlazaMaterial(wet) {
|
|
104
|
-
const mat = createPavedGroundMaterial({
|
|
105
|
-
origin: PLAZA,
|
|
106
|
-
rings: [{ x: 0, z: 0, r: 14, ring: 1.45 }],
|
|
107
|
-
strips: [
|
|
108
|
-
{ x0: -27, z0: -4.2, x1: 27, z1: 4.2, len: 1.25, course: 0.95, along: 'x', wear: 2.2 },
|
|
109
|
-
{ x0: -5.4, z0: -24, x1: 5.4, z1: 24, len: 1.3, course: 1.05, along: 'z', wear: 2.8 },
|
|
110
|
-
],
|
|
111
|
-
cobble: 0.2,
|
|
112
|
-
earth: 0.18,
|
|
113
|
-
wet,
|
|
114
|
-
pools: [
|
|
115
|
-
[-6, 7, 5.5, 4],
|
|
116
|
-
[7, -5, 6.2, 4.2],
|
|
117
|
-
[2, 11, 4.8, 3.6],
|
|
118
|
-
[-9, -8, 5, 3.8],
|
|
119
|
-
],
|
|
120
|
-
});
|
|
121
|
-
mat.polygonOffset = true;
|
|
122
|
-
mat.polygonOffsetFactor = mat.polygonOffsetUnits = -2;
|
|
123
|
-
return mat;
|
|
124
|
-
}
|
|
125
|
-
const plazaMesh = new THREE.Mesh(plazaGeo, makePlazaMaterial(0));
|
|
126
|
-
plazaMesh.receiveShadow = true;
|
|
127
|
-
worldGroup.add(plazaMesh);
|
|
128
|
-
|
|
129
|
-
// Shared weathered stone, rock and pool materials.
|
|
130
|
-
const stoneMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.9, metalness: 0.02 });
|
|
131
|
-
const rockMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.94, flatShading: true });
|
|
132
|
-
const poolMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.16, metalness: 0.18 });
|
|
133
|
-
const mudWallMat = new THREE.MeshStandardMaterial({ color: 0xc2ab87, roughness: 0.96 });
|
|
134
|
-
|
|
135
|
-
// Hilltop ruin: tumbled blocks, leaning tower remnants, wall-stump rooms, flank masonry, scree and draped hollows.
|
|
136
|
-
const hillKit = {
|
|
137
|
-
hill: { u: HILL.x, v: -HILL.z, r: HILL.r },
|
|
138
|
-
stone: new GeometryBuilder(),
|
|
139
|
-
rock: new GeometryBuilder(),
|
|
140
|
-
orders: [],
|
|
141
|
-
Y: (u, v) => height(u, -v),
|
|
142
|
-
G: (u, v) => height(u, -v),
|
|
143
|
-
solid: () => {},
|
|
144
|
-
};
|
|
145
|
-
buildHillRuin(hillKit, mulberry32(seed * 17 + 3), {
|
|
146
|
-
shapes,
|
|
147
|
-
shape: { tumbled: 68, rooms: 9, flank: 220, scree: 900, oldWalls: 110, pools: 4, sinkholes: 3 },
|
|
148
|
-
});
|
|
149
|
-
// Fallen rubble heaps flanking the plaza edges.
|
|
150
|
-
buildRubbleHeap(hillKit.stone, mulberry32(seed * 23 + 7), {
|
|
151
|
-
x: -20,
|
|
152
|
-
z: 28,
|
|
153
|
-
radius: 4.5,
|
|
154
|
-
count: 20,
|
|
155
|
-
ground: height,
|
|
156
|
-
rock: shapes.rock,
|
|
157
|
-
});
|
|
158
|
-
scatterRubble(hillKit.rock, mulberry32(seed * 29 + 11), {
|
|
159
|
-
x: 22,
|
|
160
|
-
z: 24,
|
|
161
|
-
radius: 5.5,
|
|
162
|
-
count: 24,
|
|
163
|
-
ground: height,
|
|
164
|
-
hue: 0xc8b89a,
|
|
165
|
-
scale: 1.15,
|
|
166
|
-
rock: shapes.rock,
|
|
167
|
-
});
|
|
168
|
-
hillKit.stone.mesh(stoneMat, worldGroup);
|
|
169
|
-
hillKit.rock.mesh(rockMat, worldGroup);
|
|
170
|
-
for (const order of hillKit.orders) {
|
|
171
|
-
if (!order.mesh) continue;
|
|
172
|
-
order.mesh.mesh(order.mat === 'pool' ? poolMat : rockMat, worldGroup, Boolean(order.shadow));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Buried-town mound: eroded mud-brick wall stumps and strewn potsherds.
|
|
176
|
-
const moundBuilt = buildMoundRuins(MOUND, seed * 31 + 19, false, height, {
|
|
177
|
-
noise: vnoise,
|
|
178
|
-
shape: { sherds: 520, wallsReach: 34, standing: 0.78 },
|
|
179
|
-
});
|
|
180
|
-
if (moundBuilt.walls.index.length) {
|
|
181
|
-
const g = new THREE.BufferGeometry();
|
|
182
|
-
g.setAttribute('position', new THREE.BufferAttribute(moundBuilt.walls.position, 3));
|
|
183
|
-
g.setAttribute('normal', new THREE.BufferAttribute(moundBuilt.walls.normal, 3));
|
|
184
|
-
g.setAttribute('uv', new THREE.BufferAttribute(moundBuilt.walls.uv, 2));
|
|
185
|
-
g.setIndex(new THREE.BufferAttribute(moundBuilt.walls.index, 1));
|
|
186
|
-
const mesh = new THREE.Mesh(g, mudWallMat);
|
|
187
|
-
mesh.castShadow = mesh.receiveShadow = true;
|
|
188
|
-
worldGroup.add(mesh);
|
|
189
|
-
}
|
|
190
|
-
if (moundBuilt.sherds?.position.length) {
|
|
191
|
-
const sherdMesh = new THREE.Mesh(geometryOf(moundBuilt.sherds), rockMat);
|
|
192
|
-
sherdMesh.receiveShadow = true;
|
|
193
|
-
worldGroup.add(sherdMesh);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Paved stone highway with kerbs, milestones, spanning arch and a roadside avenue of cedars.
|
|
197
|
-
const roadBuilt = layPavedRoad({
|
|
198
|
-
road: {
|
|
199
|
-
pts: [
|
|
200
|
-
[0, 152],
|
|
201
|
-
[0, 102],
|
|
202
|
-
[0, 56],
|
|
203
|
-
[0, 34],
|
|
204
|
-
],
|
|
205
|
-
w: 9.2,
|
|
206
|
-
trees: 24,
|
|
207
|
-
},
|
|
208
|
-
ground: height,
|
|
209
|
-
parent: worldGroup,
|
|
210
|
-
random: mulberry32(seed * 37 + 5),
|
|
211
|
-
stoneMaterial: stoneMat,
|
|
212
|
-
pavingReach: { value: 180 },
|
|
213
|
-
pavingBand: 24,
|
|
214
|
-
arch: true,
|
|
215
|
-
avenueOffset: 9.2,
|
|
216
|
-
cedarSeed: seed * 41 + 9,
|
|
217
|
-
hash,
|
|
218
|
-
camera,
|
|
219
|
-
getReach: () => 140,
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
// Bedded strata outcrops and wind-worn boulders instanced with createShapeBatches around the hill, mound and verges.
|
|
223
|
-
const rockLib = createRockShapes({ noise: vnoise });
|
|
224
|
-
const outcrops = rockLib.outcropShapes();
|
|
225
|
-
const outcropBatches = createShapeBatches(outcrops, 30);
|
|
226
|
-
const stoneBatches = createShapeBatches(rockLib.stones, 70);
|
|
227
|
-
const rockPalette = [0xcfb590, 0xbfa282, 0xd8c19e, 0xb89674];
|
|
228
|
-
const rockRng = mulberry32(seed * 53 + 13);
|
|
229
|
-
let outcropPlaced = 0;
|
|
230
|
-
let stonePlaced = 0;
|
|
231
|
-
|
|
232
|
-
for (let i = 0; i < 64 && outcropPlaced < 30 * outcrops.length; i++) {
|
|
233
|
-
const x = (rockRng() - 0.5) * 200;
|
|
234
|
-
const z = (rockRng() - 0.5) * 180;
|
|
235
|
-
if (Math.abs(x) < 15 && z > 20) continue; // keep highway clear
|
|
236
|
-
if (Math.hypot(x - PLAZA.x, z - PLAZA.z) < 28) continue;
|
|
237
|
-
if (Math.hypot(x - COURTYARD.x, z - COURTYARD.z) < 18) continue;
|
|
238
|
-
if (Math.hypot(x - HILL.x, z - HILL.z) < HILL.r * 0.85) continue;
|
|
239
|
-
if (Math.hypot(x - MOUND.x, z - MOUND.z) < MOUND.r * 0.8) continue;
|
|
240
|
-
if (Math.hypot(x - MESA.x, z - MESA.z) < MESA.r * 1.15) continue;
|
|
241
|
-
const s = 1.6 + rockRng() * 2.6;
|
|
242
|
-
const col = C(rockPalette[i % rockPalette.length], 0.08, rockRng);
|
|
243
|
-
outcropBatches.put(TRS(x, height(x, z), z, s, s * (0.85 + rockRng() * 0.4), s, rockRng() * TAU), col);
|
|
244
|
-
outcropPlaced++;
|
|
245
|
-
}
|
|
246
|
-
for (let i = 0; i < 160 && stonePlaced < 70 * rockLib.stones.length; i++) {
|
|
247
|
-
const x = (rockRng() - 0.5) * 190;
|
|
248
|
-
const z = (rockRng() - 0.5) * 170;
|
|
249
|
-
if (Math.abs(x) < 11 && z > 24) continue;
|
|
250
|
-
if (Math.hypot(x - PLAZA.x, z - PLAZA.z) < 23) continue;
|
|
251
|
-
if (Math.hypot(x - COURTYARD.x, z - COURTYARD.z) < 14) continue;
|
|
252
|
-
const s = 0.45 + rockRng() * 1.1;
|
|
253
|
-
const col = C(rockPalette[i % rockPalette.length], 0.1, rockRng);
|
|
254
|
-
stoneBatches.put(TRS(x, height(x, z) + s * 0.12, z, s, s * (0.7 + rockRng() * 0.35), s, rockRng() * TAU, (rockRng() - 0.5) * 0.4), col);
|
|
255
|
-
stonePlaced++;
|
|
256
|
-
}
|
|
257
|
-
const tintedRockMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.93 });
|
|
258
|
-
outcropBatches.addTo(worldGroup, tintedRockMat, { castShadow: true, receiveShadow: true });
|
|
259
|
-
stoneBatches.addTo(worldGroup, tintedRockMat, { castShadow: false, receiveShadow: true });
|
|
260
|
-
|
|
261
|
-
// Stepped sandstone mesa cliff wrapping the southwestern plateau.
|
|
262
|
-
buildMesaCliff(MESA, height, { noise: vnoise, cliffFoot: 1.04, cliffBrow: 0.78 }).mesh(rockMat, worldGroup, true);
|
|
263
|
-
|
|
264
|
-
// Ruined sanctuary courtyard: square flagstones, ragged dressed ashlar walls, fluted standing and fallen column drums,
|
|
265
|
-
// coursed ruined wing wall, brass lamp stand, wall lantern and dark still pool.
|
|
266
|
-
const masonryRng = mulberry32(seed * 67 + 17);
|
|
267
|
-
const sanctuary = {
|
|
268
|
-
stone: new GeometryBuilder(),
|
|
269
|
-
wall: new GeometryBuilder(),
|
|
270
|
-
trim: new GeometryBuilder(),
|
|
271
|
-
cloth: new GeometryBuilder(),
|
|
272
|
-
};
|
|
273
|
-
const cx = COURTYARD.x;
|
|
274
|
-
const cz = COURTYARD.z;
|
|
275
|
-
const cy = height(cx, cz) + 0.14;
|
|
276
|
-
buildFlagstones(sanctuary.stone, {
|
|
277
|
-
x0: cx - 7,
|
|
278
|
-
z0: cz - 6,
|
|
279
|
-
x1: cx + 7,
|
|
280
|
-
z1: cz + 6,
|
|
281
|
-
y: cy,
|
|
282
|
-
size: 1.2,
|
|
283
|
-
colorHex: 0xc4b394,
|
|
284
|
-
seed: seed + 7,
|
|
285
|
-
hash,
|
|
286
|
-
});
|
|
287
|
-
buildAshlarWall(sanctuary.stone, masonryRng, {
|
|
288
|
-
x0: cx - 7,
|
|
289
|
-
z0: cz - 6,
|
|
290
|
-
x1: cx + 7,
|
|
291
|
-
z1: cz - 6,
|
|
292
|
-
y: cy - 0.5,
|
|
293
|
-
height: 4.1,
|
|
294
|
-
thickness: 0.68,
|
|
295
|
-
colorHex: 0xc2b090,
|
|
296
|
-
ragged: 0.25,
|
|
297
|
-
gap: [5.5, 8.5, 2.7],
|
|
298
|
-
seed: seed + 11,
|
|
299
|
-
hash,
|
|
300
|
-
});
|
|
301
|
-
buildAshlarWall(sanctuary.stone, masonryRng, {
|
|
302
|
-
x0: cx - 7,
|
|
303
|
-
z0: cz - 6,
|
|
304
|
-
x1: cx - 7,
|
|
305
|
-
z1: cz + 5,
|
|
306
|
-
y: cy - 0.5,
|
|
307
|
-
height: 3.3,
|
|
308
|
-
thickness: 0.65,
|
|
309
|
-
colorHex: 0xbba888,
|
|
310
|
-
ragged: 0.42,
|
|
311
|
-
seed: seed + 13,
|
|
312
|
-
hash,
|
|
313
|
-
});
|
|
314
|
-
buildColumnDrum(sanctuary.wall, masonryRng, {
|
|
315
|
-
x: cx - 3.1,
|
|
316
|
-
y: cy,
|
|
317
|
-
z: cz + 2.3,
|
|
318
|
-
radius: 0.42,
|
|
319
|
-
length: 3.0,
|
|
320
|
-
colorHex: 0xcab99a,
|
|
321
|
-
lying: false,
|
|
322
|
-
yaw: 0.2,
|
|
323
|
-
hash,
|
|
324
|
-
noise: vnoise,
|
|
325
|
-
});
|
|
326
|
-
buildColumnDrum(sanctuary.wall, masonryRng, {
|
|
327
|
-
x: cx + 3.1,
|
|
328
|
-
y: cy,
|
|
329
|
-
z: cz + 2.3,
|
|
330
|
-
radius: 0.42,
|
|
331
|
-
length: 2.2,
|
|
332
|
-
colorHex: 0xcab99a,
|
|
333
|
-
lying: false,
|
|
334
|
-
yaw: -0.4,
|
|
335
|
-
hash,
|
|
336
|
-
noise: vnoise,
|
|
337
|
-
});
|
|
338
|
-
buildColumnDrum(sanctuary.wall, masonryRng, {
|
|
339
|
-
x: cx + 0.6,
|
|
340
|
-
y: cy,
|
|
341
|
-
z: cz + 4.3,
|
|
342
|
-
radius: 0.4,
|
|
343
|
-
length: 2.1,
|
|
344
|
-
colorHex: 0xc4b394,
|
|
345
|
-
lying: true,
|
|
346
|
-
yaw: 0.55,
|
|
347
|
-
hash,
|
|
348
|
-
noise: vnoise,
|
|
349
|
-
});
|
|
350
|
-
buildRuinWall(sanctuary.stone, masonryRng, {
|
|
351
|
-
ax: cx + 7,
|
|
352
|
-
az: cz - 5,
|
|
353
|
-
bx: cx + 15,
|
|
354
|
-
bz: cz + 6,
|
|
355
|
-
tall: 2.6,
|
|
356
|
-
ground: height,
|
|
357
|
-
hue: 0xb8a380,
|
|
358
|
-
fallen: 0.55,
|
|
359
|
-
fbm,
|
|
360
|
-
rock: shapes.rock,
|
|
361
|
-
});
|
|
362
|
-
addLampStand(sanctuary, { x: cx - 2.1, y: cy, z: cz - 4.2, height: 1.3, shapes });
|
|
363
|
-
addWallLantern(sanctuary, { group: worldGroup, x: cx - 6.65, y: cy + 2.5, z: cz - 1.5, out: 0, ground: cy, poolRadius: 4.5, shapes });
|
|
364
|
-
addStillPool(worldGroup, { x: cx + 0.2, y: cy + 0.03, z: cz - 0.6, width: 3.6, depth: 2.4, yaw: 0.12 });
|
|
365
|
-
const metalMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.42, metalness: 0.6 });
|
|
366
|
-
const plasterMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.88 });
|
|
367
|
-
sanctuary.stone.mesh(stoneMat, worldGroup);
|
|
368
|
-
sanctuary.wall.mesh(plasterMat, worldGroup);
|
|
369
|
-
sanctuary.trim.mesh(metalMat, worldGroup);
|
|
370
|
-
sanctuary.cloth.mesh(metalMat, worldGroup);
|
|
371
|
-
|
|
372
|
-
// Impact crater bowl and rubble mound west of the highway.
|
|
373
|
-
const craterBuilders = {
|
|
374
|
-
earth: new GeometryBuilder(),
|
|
375
|
-
rock: new GeometryBuilder(),
|
|
376
|
-
stone: new GeometryBuilder(),
|
|
377
|
-
wood: new GeometryBuilder(),
|
|
378
|
-
};
|
|
379
|
-
const craterRng = mulberry32(seed * 73 + 29);
|
|
380
|
-
buildCraterBowl({
|
|
381
|
-
builders: craterBuilders,
|
|
382
|
-
random: craterRng,
|
|
383
|
-
ground: height,
|
|
384
|
-
x: -24,
|
|
385
|
-
z: 54,
|
|
386
|
-
crater: { x: -24, z: 54, r: 6.2, deep: 1.2 },
|
|
387
|
-
vnoise,
|
|
388
|
-
stoneShape: shapes.rock,
|
|
389
|
-
});
|
|
390
|
-
buildRubbleMound({
|
|
391
|
-
builders: craterBuilders,
|
|
392
|
-
random: craterRng,
|
|
393
|
-
ground: height,
|
|
394
|
-
x: -16,
|
|
395
|
-
z: 62,
|
|
396
|
-
radius: 3.4,
|
|
397
|
-
height: 1.2,
|
|
398
|
-
vnoise,
|
|
399
|
-
stoneShape: shapes.rock,
|
|
400
|
-
boxShape: shapes.box,
|
|
401
|
-
});
|
|
402
|
-
craterBuilders.earth.mesh(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.96 }), worldGroup, false);
|
|
403
|
-
craterBuilders.rock.mesh(rockMat, worldGroup);
|
|
404
|
-
craterBuilders.stone.mesh(stoneMat, worldGroup);
|
|
405
|
-
craterBuilders.wood.mesh(new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.94 }), worldGroup);
|
|
406
|
-
|
|
407
|
-
// Warm sunlit sky and directional shadows.
|
|
408
|
-
createDaylightSky({
|
|
409
|
-
scene,
|
|
410
|
-
renderer,
|
|
411
|
-
noise,
|
|
412
|
-
sky: {
|
|
413
|
-
zenith: [0.22, 0.46, 0.72],
|
|
414
|
-
horizon: [0.89, 0.86, 0.78],
|
|
415
|
-
sunDir: [0.68, 0.42, 0.58],
|
|
416
|
-
},
|
|
417
|
-
sunPosition: [120, 74, 102],
|
|
418
|
-
sunIntensity: 2.8,
|
|
419
|
-
sunColor: 0xfff2d8,
|
|
420
|
-
shadowRadius: 125,
|
|
421
|
-
shadowFar: 360,
|
|
422
|
-
normalBias: 0.05,
|
|
423
|
-
fogColor: 0xe2d8c5,
|
|
424
|
-
fogDensity: 0.0012,
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
const VIEWS = {
|
|
428
|
-
overview: { eye: [52, 32, 92], target: [-2, 6, -4] },
|
|
429
|
-
masonry: { eye: [23, 9.2, 41], target: [COURTYARD.x, cy + 1.4, COURTYARD.z - 1] },
|
|
430
|
-
hill: { eye: [-10, 26, -6], target: [HILL.x, HILL.h + 1, HILL.z] },
|
|
431
|
-
arch: { eye: [3, 6.5, 92], target: [0, 6, 42] },
|
|
432
|
-
plaza: { eye: [22, 13, 38], target: [PLAZA.x, 1, PLAZA.z] },
|
|
433
|
-
mound: { eye: [22, 22, 2], target: [MOUND.x, MOUND.h, MOUND.z] },
|
|
434
|
-
};
|
|
435
|
-
|
|
436
|
-
const rig = createOrbitCamera({
|
|
437
|
-
camera,
|
|
438
|
-
canvas,
|
|
439
|
-
renderer,
|
|
440
|
-
scene,
|
|
441
|
-
views: VIEWS,
|
|
442
|
-
initialView: 'overview',
|
|
443
|
-
groundAt: height,
|
|
444
|
-
minClearance: 1.5,
|
|
445
|
-
minDistance: 8,
|
|
446
|
-
maxDistance: 240,
|
|
447
|
-
onDraw: () => {},
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
// Snap cedar LODs immediately for the initial view before the first frame renders.
|
|
451
|
-
roadBuilt.hand?.(1);
|
|
452
|
-
|
|
453
|
-
for (const btn of document.querySelectorAll('[data-wet]')) {
|
|
454
|
-
btn.addEventListener('click', () => {
|
|
455
|
-
const next = Number(btn.dataset.wet);
|
|
456
|
-
if (next === wetState) return;
|
|
457
|
-
wetState = next;
|
|
458
|
-
const old = plazaMesh.material;
|
|
459
|
-
plazaMesh.material = makePlazaMaterial(wetState);
|
|
460
|
-
old.dispose();
|
|
461
|
-
for (const b of document.querySelectorAll('[data-wet]')) b.setAttribute('aria-pressed', String(Number(b.dataset.wet) === wetState));
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
const clock = new THREE.Timer();
|
|
466
|
-
function animate() {
|
|
467
|
-
clock.update();
|
|
468
|
-
const dt = Math.min(0.1, clock.getDelta());
|
|
469
|
-
rig.clampCamera();
|
|
470
|
-
roadBuilt.hand?.(dt);
|
|
471
|
-
renderer.render(scene, camera);
|
|
472
|
-
requestAnimationFrame(animate);
|
|
473
|
-
}
|
|
474
|
-
animate();
|