roamwright 0.61.18 → 0.61.19
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/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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "roamwright",
|
|
3
|
-
"version": "0.61.
|
|
3
|
+
"version": "0.61.19",
|
|
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();
|