roamwright 0.61.17 → 0.61.18
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/examples/land-features.js +130 -9
- package/examples/land.html +2 -1
- package/examples/land.js +17 -2
- package/examples/ruins.html +3 -2
- package/examples/ruins.js +184 -37
- package/geometry/farm-props.js +59 -0
- package/geometry/field-map.js +147 -0
- package/geometry/instances.js +40 -0
- package/geometry/plant-tuft.js +138 -0
- package/geometry/ruins-breach.js +329 -0
- package/geometry/ruins-crater.js +269 -0
- package/geometry/ruins-masonry.js +323 -0
- package/geometry/ruins-walls.js +272 -0
- package/geometry/strata-mesa.js +114 -0
- package/geometry/strata-rocks.js +73 -2
- package/index.js +42 -1
- package/package.json +1 -1
- package/rendering/contact-shadows.js +56 -0
- package/rendering/crowd-lifecycle.js +80 -0
- package/rendering/farm-plough.js +145 -0
- package/rendering/plant-tuft.js +190 -0
- package/rendering/ruins-fittings.js +199 -0
- package/rendering/ruins-mound.js +103 -0
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import {
|
|
3
|
+
FLOWER_KINDS,
|
|
3
4
|
GeometryBuilder,
|
|
5
|
+
buildBarnDoors,
|
|
4
6
|
buildHaystacks,
|
|
5
7
|
buildStonePile,
|
|
8
|
+
createCragLibrary,
|
|
9
|
+
createFigureAssembler,
|
|
10
|
+
createFigureBuilder,
|
|
11
|
+
createLivestockCache,
|
|
12
|
+
createPloughTeam,
|
|
13
|
+
createTuftMaterial,
|
|
6
14
|
createUnitShapes,
|
|
7
15
|
drystoneStone,
|
|
16
|
+
geometryOf,
|
|
8
17
|
layRoads,
|
|
9
18
|
meshSprings,
|
|
10
19
|
meshStreamBanks,
|
|
@@ -12,13 +21,16 @@ import {
|
|
|
12
21
|
planDrystoneWall,
|
|
13
22
|
planSprings,
|
|
14
23
|
planStreamBanks,
|
|
24
|
+
tuftGeometry,
|
|
15
25
|
} from 'roamwright';
|
|
16
|
-
import { instancedMesh } from 'roamwright/geometry/instances.js';
|
|
26
|
+
import { instanceArrays, instancedMesh, putInstance } from 'roamwright/geometry/instances.js';
|
|
27
|
+
import { C, TRS } from 'roamwright/geometry/primitives.js';
|
|
17
28
|
import { SRGB2LIN } from 'roamwright/math/color.js';
|
|
18
|
-
import { lerp } from 'roamwright/math/scalar.js';
|
|
29
|
+
import { lerp, TAU } from 'roamwright/math/scalar.js';
|
|
19
30
|
|
|
20
|
-
// Roads, river springhead
|
|
21
|
-
|
|
31
|
+
// Roads, river springhead, stoned banks, crag boulders, drystone farmstead with barn doors, haystacks, stone pile,
|
|
32
|
+
// oxen plough team with ploughman, and flowering meadow tufts for examples/land.js.
|
|
33
|
+
export function buildLandFeatures({ worldGroup, camera, land, waters, groundExact, sea, shoreZ, tones, seed, fbm, vnoise }) {
|
|
22
34
|
const roadColor = (tone, mul) => ({ r: SRGB2LIN[tone[0]] * mul, g: SRGB2LIN[tone[1]] * mul, b: SRGB2LIN[tone[2]] * mul });
|
|
23
35
|
const roadSoil = roadColor(tones.debris, 0.72),
|
|
24
36
|
roadVerge = roadColor(tones.grass, 0.9);
|
|
@@ -32,6 +44,7 @@ export function buildLandFeatures({ worldGroup, land, waters, groundExact, sea,
|
|
|
32
44
|
});
|
|
33
45
|
|
|
34
46
|
const shapes = createUnitShapes(fbm);
|
|
47
|
+
const crags = createCragLibrary({ fbm, vnoise });
|
|
35
48
|
const [river] = waters.channels;
|
|
36
49
|
const riverPts = river.line.filter(([, z]) => z <= shoreZ + 10);
|
|
37
50
|
const bed = Float32Array.from(riverPts, ([x, z]) => groundExact(x, z) - 0.4);
|
|
@@ -44,7 +57,7 @@ export function buildLandFeatures({ worldGroup, land, waters, groundExact, sea,
|
|
|
44
57
|
});
|
|
45
58
|
meshStreamBanks({
|
|
46
59
|
plans,
|
|
47
|
-
stone: { geometry:
|
|
60
|
+
stone: { geometry: crags.fallenStone(1, seed * 11), material: new THREE.MeshStandardMaterial({ roughness: 0.92 }) },
|
|
48
61
|
log: { geometry: shapes.cyl, material: new THREE.MeshStandardMaterial({ roughness: 0.95 }) },
|
|
49
62
|
parent: worldGroup,
|
|
50
63
|
});
|
|
@@ -56,7 +69,7 @@ export function buildLandFeatures({ worldGroup, land, waters, groundExact, sea,
|
|
|
56
69
|
random: mulberry32(seed * 47),
|
|
57
70
|
}),
|
|
58
71
|
parent: worldGroup,
|
|
59
|
-
crag:
|
|
72
|
+
crag: fineness => crags.crag(fineness),
|
|
60
73
|
});
|
|
61
74
|
|
|
62
75
|
const wallRng = mulberry32(seed * 53);
|
|
@@ -88,15 +101,123 @@ export function buildLandFeatures({ worldGroup, land, waters, groundExact, sea,
|
|
|
88
101
|
wallMesh.castShadow = wallMesh.receiveShadow = true;
|
|
89
102
|
worldGroup.add(wallMesh);
|
|
90
103
|
|
|
91
|
-
const placeProp = (build, x, z, roughness) => {
|
|
104
|
+
const placeProp = (build, x, z, roughness, yaw = 0) => {
|
|
92
105
|
const gb = new GeometryBuilder();
|
|
93
106
|
build(gb);
|
|
94
107
|
const mesh = gb.mesh(new THREE.MeshStandardMaterial({ vertexColors: true, roughness }), worldGroup);
|
|
95
108
|
if (mesh) {
|
|
96
109
|
mesh.position.set(x, groundExact(x, z), z);
|
|
110
|
+
mesh.rotation.y = yaw;
|
|
97
111
|
mesh.updateMatrix();
|
|
98
112
|
}
|
|
99
113
|
};
|
|
100
|
-
placeProp(gb => buildHaystacks(gb, mulberry32(seed * 59), { noise: vnoise, box: shapes.box }),
|
|
101
|
-
placeProp(gb => buildStonePile(gb, mulberry32(seed * 61), { rock: shapes.rock }),
|
|
114
|
+
placeProp(gb => buildHaystacks(gb, mulberry32(seed * 59), { noise: vnoise, box: shapes.box }), 196, 84, 0.96);
|
|
115
|
+
placeProp(gb => buildStonePile(gb, mulberry32(seed * 61), { rock: shapes.rock }), 206, 78, 0.92);
|
|
116
|
+
|
|
117
|
+
// Weatherboarded timber barn with Roamwright's braced double barn doors facing the yard.
|
|
118
|
+
const barnRng = mulberry32(seed * 67);
|
|
119
|
+
placeProp(
|
|
120
|
+
gb => {
|
|
121
|
+
const w = 8.4,
|
|
122
|
+
d = 5.9,
|
|
123
|
+
h = 3.9,
|
|
124
|
+
rise = 2.0;
|
|
125
|
+
const wallCol = C(0x7c674c, 0.08, barnRng);
|
|
126
|
+
const roofCol = C(0x6e4a38, 0.1, barnRng);
|
|
127
|
+
gb.box(0, -0.5, 0, w, h + 0.5, d, wallCol);
|
|
128
|
+
// Gable end triangles built with triangular prisms along the ridge.
|
|
129
|
+
const slope = Math.hypot(d * 0.5 + 0.45, rise);
|
|
130
|
+
const pitch = Math.atan2(rise, d * 0.5 + 0.45);
|
|
131
|
+
for (const s of [-1, 1]) {
|
|
132
|
+
// Pitched timber roof deck with overhanging eaves and ridge overlap.
|
|
133
|
+
gb.box(0, h + rise * 0.5 - 0.08, s * (d * 0.25 + 0.12), w + 0.7, 0.24, slope, roofCol, 0, s * pitch);
|
|
134
|
+
// Stepped timber courses filling each gable peak cleanly behind the eaves.
|
|
135
|
+
for (let k = 0; k < 5; k++) {
|
|
136
|
+
const f = (k + 0.5) / 5;
|
|
137
|
+
gb.box(s * (w * 0.5 - 0.18), h + f * rise, 0, 0.36, rise / 5 + 0.04, d * (1 - f), wallCol);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
gb.box(0, h + rise + 0.04, 0, w + 0.76, 0.22, 0.28, C(0x523628, 0.08, barnRng));
|
|
141
|
+
buildBarnDoors(gb, barnRng, { depth: d, box: shapes.box });
|
|
142
|
+
},
|
|
143
|
+
181,
|
|
144
|
+
80,
|
|
145
|
+
0.93,
|
|
146
|
+
0.22,
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
// Yoked oxen plough team with a posed ploughman working the open strip inside the farmstead.
|
|
150
|
+
const figureKit = createFigureBuilder();
|
|
151
|
+
const figMat = () => new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.88, side: THREE.DoubleSide });
|
|
152
|
+
const { assembleFigure } = createFigureAssembler({ material: figMat, holds: figureKit.kit.holds });
|
|
153
|
+
const buildFigure = (look, figSeed) => {
|
|
154
|
+
const far = figureKit.buildBody(look, figSeed, 1);
|
|
155
|
+
return assembleFigure(look, 'human', { ...far, geo: geometryOf(far.parts) }, null);
|
|
156
|
+
};
|
|
157
|
+
const livestock = createLivestockCache();
|
|
158
|
+
const team = createPloughTeam({
|
|
159
|
+
oxen: livestock.cattleGeometry(false, false, 'ox'),
|
|
160
|
+
random: mulberry32(seed * 71),
|
|
161
|
+
camera: null,
|
|
162
|
+
seenDistance: 0,
|
|
163
|
+
buildFigure,
|
|
164
|
+
shapes,
|
|
165
|
+
layer: null,
|
|
166
|
+
});
|
|
167
|
+
const px = 198,
|
|
168
|
+
pz = 102;
|
|
169
|
+
team.position.set(px, groundExact(px, pz), pz);
|
|
170
|
+
team.rotation.set(0, -0.45, 0, 'YXZ');
|
|
171
|
+
worldGroup.add(team);
|
|
172
|
+
|
|
173
|
+
// Flowering meadow tufts (poppies, daisies, buttercups, grain ears) swaying in the wind around the farmstead.
|
|
174
|
+
const tuftRng = mulberry32(seed * 79);
|
|
175
|
+
const tuftGeo = tuftGeometry({ seed: seed * 37 + 5 });
|
|
176
|
+
const uTime = { value: 0 };
|
|
177
|
+
const uCam = { value: new THREE.Vector3(px, groundExact(px, pz), pz) };
|
|
178
|
+
const uR = { value: 90 };
|
|
179
|
+
const tuftMat = createTuftMaterial(uCam, uR, false, {
|
|
180
|
+
uTime,
|
|
181
|
+
uSunLight: { value: 1 },
|
|
182
|
+
uWind: { value: new THREE.Vector3(1.1, 0, 0.4) },
|
|
183
|
+
});
|
|
184
|
+
const flowerKinds = [0, 0, 0, FLOWER_KINDS.poppy, FLOWER_KINDS.daisy, FLOWER_KINDS.buttercup, FLOWER_KINDS.ear];
|
|
185
|
+
const tuftCount = 320;
|
|
186
|
+
const tuftArr = instanceArrays(tuftCount);
|
|
187
|
+
const flowerAttr = new Float32Array(tuftCount);
|
|
188
|
+
let placed = 0;
|
|
189
|
+
for (let i = 0; i < tuftCount; i++) {
|
|
190
|
+
const tx = 166 + tuftRng() * 54;
|
|
191
|
+
const tz = 68 + tuftRng() * 48;
|
|
192
|
+
if (Math.hypot(tx - 181, tz - 80) < 7.5 || Math.hypot(tx - px, tz - pz) < 4.5) continue;
|
|
193
|
+
const ty = groundExact(tx, tz) - 0.03;
|
|
194
|
+
const wide = 0.6 + tuftRng() * 0.45;
|
|
195
|
+
const tall = wide * (0.75 + tuftRng() * 0.55);
|
|
196
|
+
const kind = flowerKinds[(tuftRng() * flowerKinds.length) | 0];
|
|
197
|
+
putInstance(
|
|
198
|
+
tuftArr,
|
|
199
|
+
placed,
|
|
200
|
+
TRS(tx, ty, tz, wide, tall, wide, tuftRng() * TAU),
|
|
201
|
+
0.16 + tuftRng() * 0.08,
|
|
202
|
+
0.24 + tuftRng() * 0.1,
|
|
203
|
+
0.07 + tuftRng() * 0.04,
|
|
204
|
+
);
|
|
205
|
+
flowerAttr[placed] = kind ? kind * 4 + 1 + (i % 3) : 0;
|
|
206
|
+
placed++;
|
|
207
|
+
}
|
|
208
|
+
tuftGeo.setAttribute('aFlower', new THREE.InstancedBufferAttribute(flowerAttr.subarray(0, placed), 1));
|
|
209
|
+
const tufts = instancedMesh(tuftGeo, tuftMat, {
|
|
210
|
+
matrices: tuftArr.matrices.subarray(0, placed * 16),
|
|
211
|
+
colours: tuftArr.colours.subarray(0, placed * 3),
|
|
212
|
+
});
|
|
213
|
+
tufts.receiveShadow = true;
|
|
214
|
+
tufts.frustumCulled = false;
|
|
215
|
+
worldGroup.add(tufts);
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
update(elapsed) {
|
|
219
|
+
uTime.value = elapsed;
|
|
220
|
+
if (camera) uCam.value.copy(camera.position);
|
|
221
|
+
},
|
|
222
|
+
};
|
|
102
223
|
}
|
package/examples/land.html
CHANGED
|
@@ -38,12 +38,13 @@
|
|
|
38
38
|
<h1>A baked land</h1>
|
|
39
39
|
<p id="status">
|
|
40
40
|
One height sheet baked row by row: coast, eroded hills, river springhead and stoned banks, lake, draped earth road, drystone
|
|
41
|
-
|
|
41
|
+
farmstead with braced barn doors, haystacks, plough team and flowering tufts, cliff-faced tel, quarry and port pad.
|
|
42
42
|
</p>
|
|
43
43
|
</div>
|
|
44
44
|
<div class="tools">
|
|
45
45
|
<div class="views" role="group" aria-label="Camera viewpoint">
|
|
46
46
|
<button type="button" data-view="coast" aria-pressed="true">Coast & tel</button>
|
|
47
|
+
<button type="button" data-view="farmstead" aria-pressed="false">Farmstead</button>
|
|
47
48
|
<button type="button" data-view="ford" aria-pressed="false">River ford</button>
|
|
48
49
|
<button type="button" data-view="quarry" aria-pressed="false">Quarry & mere</button>
|
|
49
50
|
<button type="button" data-view="port" aria-pressed="false">Port pad</button>
|
package/examples/land.js
CHANGED
|
@@ -363,7 +363,19 @@ const groundExact = (x, z) => {
|
|
|
363
363
|
return fx + fz <= 1 ? h00 + (h10 - h00) * fx + (h01 - h00) * fz : h11 + (h01 - h11) * (1 - fx) + (h10 - h11) * (1 - fz);
|
|
364
364
|
};
|
|
365
365
|
|
|
366
|
-
buildLandFeatures({
|
|
366
|
+
const features = buildLandFeatures({
|
|
367
|
+
worldGroup,
|
|
368
|
+
camera,
|
|
369
|
+
land,
|
|
370
|
+
waters,
|
|
371
|
+
groundExact,
|
|
372
|
+
sea: SEA,
|
|
373
|
+
shoreZ: SHORE_Z,
|
|
374
|
+
tones: TONE,
|
|
375
|
+
seed,
|
|
376
|
+
fbm,
|
|
377
|
+
vnoise,
|
|
378
|
+
});
|
|
367
379
|
|
|
368
380
|
createDaylightSky({
|
|
369
381
|
scene,
|
|
@@ -384,6 +396,7 @@ status.textContent = `${STRIDE} × ${STRIDE} points (${sheet.spacing} m step): c
|
|
|
384
396
|
|
|
385
397
|
const views = {
|
|
386
398
|
coast: { eye: [365, 138, 440], target: [35, 8, -35] },
|
|
399
|
+
farmstead: { eye: [215, 17, 124], target: [190, 9, 88] },
|
|
387
400
|
ford: { eye: [228, 36, 152], target: [148, 8, 56] },
|
|
388
401
|
quarry: { eye: [-180, 125, -45], target: [-420, 14, -220] },
|
|
389
402
|
port: { eye: [-55, 78, 560], target: [-230, 5, 360] },
|
|
@@ -412,7 +425,9 @@ rig.controls.update();
|
|
|
412
425
|
const clock = new THREE.Timer();
|
|
413
426
|
renderer.setAnimationLoop(() => {
|
|
414
427
|
clock.update();
|
|
415
|
-
|
|
428
|
+
const elapsed = clock.getElapsed();
|
|
429
|
+
waterTime.value = elapsed;
|
|
430
|
+
features.update(elapsed);
|
|
416
431
|
rig.clampCamera();
|
|
417
432
|
renderer.render(scene, camera);
|
|
418
433
|
});
|
package/examples/ruins.html
CHANGED
|
@@ -37,13 +37,14 @@
|
|
|
37
37
|
<div class="caption">
|
|
38
38
|
<h1>Ruins, rocks & paved roads</h1>
|
|
39
39
|
<p>
|
|
40
|
-
A paved highway with kerbs, milestones, spanning arch and cedar avenue beside a ruined hill, a buried-town mound,
|
|
41
|
-
and a flagstone plaza.
|
|
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
42
|
</p>
|
|
43
43
|
</div>
|
|
44
44
|
<div class="tools">
|
|
45
45
|
<div class="views" role="group" aria-label="Camera viewpoint">
|
|
46
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>
|
|
47
48
|
<button type="button" data-view="hill" aria-pressed="false">Hill ruin</button>
|
|
48
49
|
<button type="button" data-view="arch" aria-pressed="false">Road & arch</button>
|
|
49
50
|
<button type="button" data-view="plaza" aria-pressed="false">Paved plaza</button>
|
package/examples/ruins.js
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import {
|
|
3
|
+
addLampStand,
|
|
4
|
+
addStillPool,
|
|
5
|
+
addWallLantern,
|
|
6
|
+
buildAshlarWall,
|
|
7
|
+
buildColumnDrum,
|
|
8
|
+
buildCraterBowl,
|
|
9
|
+
buildFlagstones,
|
|
3
10
|
buildHillRuin,
|
|
11
|
+
buildMesaCliff,
|
|
4
12
|
buildMoundRuins,
|
|
5
13
|
buildRubbleHeap,
|
|
14
|
+
buildRubbleMound,
|
|
15
|
+
buildRuinWall,
|
|
6
16
|
createDaylightSky,
|
|
7
17
|
createOrbitCamera,
|
|
8
18
|
createPavedGroundMaterial,
|
|
9
19
|
createRockShapes,
|
|
20
|
+
createShapeBatches,
|
|
10
21
|
GeometryBuilder,
|
|
11
22
|
geometryOf,
|
|
12
23
|
layPavedRoad,
|
|
13
24
|
mulberry32,
|
|
14
25
|
scatterRubble,
|
|
15
26
|
} from 'roamwright';
|
|
16
|
-
import { instanceArrays, instancedMesh, putInstance } from 'roamwright/geometry/instances.js';
|
|
17
27
|
import { C, TRS } from 'roamwright/geometry/primitives.js';
|
|
18
28
|
import { sstep, TAU } from 'roamwright/math/scalar.js';
|
|
19
29
|
import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
|
|
@@ -27,9 +37,11 @@ const { fbm, vnoise } = noise;
|
|
|
27
37
|
|
|
28
38
|
const HILL = { x: -50, z: -42, r: 36, h: 11.5 };
|
|
29
39
|
const MOUND = { x: 54, z: -38, r: 36, h: 9.5 };
|
|
40
|
+
const MESA = { x: -66, z: 36, r: 22, h: 10.5 };
|
|
30
41
|
const PLAZA = { x: 0, z: 16 };
|
|
42
|
+
const COURTYARD = { x: 34, z: 22 };
|
|
31
43
|
|
|
32
|
-
// Flat-topped hill on the west, buried-town mound on the east, level highway
|
|
44
|
+
// Flat-topped hill on the west, buried-town mound on the east, stepped mesa to the southwest, level highway and plaza between.
|
|
33
45
|
function plateauRise(dx, dz, r, h) {
|
|
34
46
|
const d = Math.hypot(dx, dz) / r;
|
|
35
47
|
if (d >= 1.25) return 0;
|
|
@@ -37,17 +49,22 @@ function plateauRise(dx, dz, r, h) {
|
|
|
37
49
|
}
|
|
38
50
|
|
|
39
51
|
function height(x, z) {
|
|
40
|
-
const corridor =
|
|
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));
|
|
41
56
|
const undulation = (fbm(x * 0.015, z * 0.015, 3, 17) - 0.5) * 4.5 * corridor;
|
|
42
57
|
const hill = plateauRise(x - HILL.x, z - HILL.z, HILL.r, HILL.h);
|
|
43
58
|
const mound = plateauRise(x - MOUND.x, z - MOUND.z, MOUND.r, MOUND.h);
|
|
44
|
-
|
|
59
|
+
const mesa = plateauRise(x - MESA.x, z - MESA.z, MESA.r, MESA.h);
|
|
60
|
+
return 0.4 + undulation + hill + mound + mesa;
|
|
45
61
|
}
|
|
46
62
|
|
|
47
63
|
const earthTone = new THREE.Color(0xcab791);
|
|
48
64
|
const scrubTone = new THREE.Color(0x9a9168);
|
|
49
65
|
const rockTone = new THREE.Color(0xb6a382);
|
|
50
66
|
const hillTone = new THREE.Color(0xc2b296);
|
|
67
|
+
const mesaTone = new THREE.Color(0x9a6448);
|
|
51
68
|
|
|
52
69
|
const terrain = createHeightfieldMesh({
|
|
53
70
|
size: 360,
|
|
@@ -59,6 +76,8 @@ const terrain = createHeightfieldMesh({
|
|
|
59
76
|
out.lerp(rockTone, 1 - sstep(0.74, 0.94, up));
|
|
60
77
|
const onHill = 1 - sstep(HILL.r * 0.75, HILL.r * 1.15, Math.hypot(x - HILL.x, z - HILL.z));
|
|
61
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);
|
|
62
81
|
out.multiplyScalar(0.88 + 0.24 * vnoise(x * 0.2, z * 0.2, 31));
|
|
63
82
|
},
|
|
64
83
|
});
|
|
@@ -200,63 +219,190 @@ const roadBuilt = layPavedRoad({
|
|
|
200
219
|
getReach: () => 140,
|
|
201
220
|
});
|
|
202
221
|
|
|
203
|
-
// Bedded strata outcrops and wind-worn boulders instanced around the hill
|
|
222
|
+
// Bedded strata outcrops and wind-worn boulders instanced with createShapeBatches around the hill, mound and verges.
|
|
204
223
|
const rockLib = createRockShapes({ noise: vnoise });
|
|
205
224
|
const outcrops = rockLib.outcropShapes();
|
|
206
|
-
const outcropBatches = outcrops
|
|
207
|
-
const stoneBatches = rockLib.stones
|
|
225
|
+
const outcropBatches = createShapeBatches(outcrops, 30);
|
|
226
|
+
const stoneBatches = createShapeBatches(rockLib.stones, 70);
|
|
208
227
|
const rockPalette = [0xcfb590, 0xbfa282, 0xd8c19e, 0xb89674];
|
|
209
228
|
const rockRng = mulberry32(seed * 53 + 13);
|
|
229
|
+
let outcropPlaced = 0;
|
|
230
|
+
let stonePlaced = 0;
|
|
210
231
|
|
|
211
|
-
for (let i = 0; i < 64; i++) {
|
|
232
|
+
for (let i = 0; i < 64 && outcropPlaced < 30 * outcrops.length; i++) {
|
|
212
233
|
const x = (rockRng() - 0.5) * 200;
|
|
213
234
|
const z = (rockRng() - 0.5) * 180;
|
|
214
235
|
if (Math.abs(x) < 15 && z > 20) continue; // keep highway clear
|
|
215
236
|
if (Math.hypot(x - PLAZA.x, z - PLAZA.z) < 28) continue;
|
|
237
|
+
if (Math.hypot(x - COURTYARD.x, z - COURTYARD.z) < 18) continue;
|
|
216
238
|
if (Math.hypot(x - HILL.x, z - HILL.z) < HILL.r * 0.85) continue;
|
|
217
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;
|
|
218
241
|
const s = 1.6 + rockRng() * 2.6;
|
|
219
242
|
const col = C(rockPalette[i % rockPalette.length], 0.08, rockRng);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
putInstance(batch.copies, batch.count++, TRS(x, height(x, z), z, s, s * (0.85 + rockRng() * 0.4), s, rockRng() * TAU), ...col);
|
|
243
|
+
outcropBatches.put(TRS(x, height(x, z), z, s, s * (0.85 + rockRng() * 0.4), s, rockRng() * TAU), col);
|
|
244
|
+
outcropPlaced++;
|
|
223
245
|
}
|
|
224
|
-
for (let i = 0; i < 160; i++) {
|
|
246
|
+
for (let i = 0; i < 160 && stonePlaced < 70 * rockLib.stones.length; i++) {
|
|
225
247
|
const x = (rockRng() - 0.5) * 190;
|
|
226
248
|
const z = (rockRng() - 0.5) * 170;
|
|
227
249
|
if (Math.abs(x) < 11 && z > 24) continue;
|
|
228
250
|
if (Math.hypot(x - PLAZA.x, z - PLAZA.z) < 23) continue;
|
|
251
|
+
if (Math.hypot(x - COURTYARD.x, z - COURTYARD.z) < 14) continue;
|
|
229
252
|
const s = 0.45 + rockRng() * 1.1;
|
|
230
253
|
const col = C(rockPalette[i % rockPalette.length], 0.1, rockRng);
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
putInstance(
|
|
234
|
-
batch.copies,
|
|
235
|
-
batch.count++,
|
|
236
|
-
TRS(x, height(x, z) + s * 0.12, z, s, s * (0.7 + rockRng() * 0.35), s, rockRng() * TAU, (rockRng() - 0.5) * 0.4),
|
|
237
|
-
...col,
|
|
238
|
-
);
|
|
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++;
|
|
239
256
|
}
|
|
240
257
|
const tintedRockMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.93 });
|
|
241
|
-
outcropBatches.
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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,
|
|
249
286
|
});
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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,
|
|
259
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);
|
|
260
406
|
|
|
261
407
|
// Warm sunlit sky and directional shadows.
|
|
262
408
|
createDaylightSky({
|
|
@@ -280,6 +426,7 @@ createDaylightSky({
|
|
|
280
426
|
|
|
281
427
|
const VIEWS = {
|
|
282
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] },
|
|
283
430
|
hill: { eye: [-10, 26, -6], target: [HILL.x, HILL.h + 1, HILL.z] },
|
|
284
431
|
arch: { eye: [3, 6.5, 92], target: [0, 6, 42] },
|
|
285
432
|
plaza: { eye: [22, 13, 38], target: [PLAZA.x, 1, PLAZA.z] },
|
package/geometry/farm-props.js
CHANGED
|
@@ -40,6 +40,29 @@ export const FARM_STONE_PILE = Object.freeze({
|
|
|
40
40
|
colorJitter: 0.24,
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Default plank count, framing dimensions (in metres) and weathered timber sRGB colours for braced
|
|
45
|
+
* double barn doors built by {@link buildBarnDoors}.
|
|
46
|
+
*/
|
|
47
|
+
export const FARM_BARN_DOORS = Object.freeze({
|
|
48
|
+
planks: 14,
|
|
49
|
+
plankStep: 0.22,
|
|
50
|
+
plankWidth: 0.215,
|
|
51
|
+
plankHeight: 2.7,
|
|
52
|
+
plankThickness: 0.13,
|
|
53
|
+
plankColor: 0x68523b,
|
|
54
|
+
plankJitter: 0.23,
|
|
55
|
+
frameColor: 0x5b4936,
|
|
56
|
+
jambOffset: 1.6,
|
|
57
|
+
jambWidth: 0.23,
|
|
58
|
+
jambHeight: 3,
|
|
59
|
+
lintelWidth: 3.42,
|
|
60
|
+
lintelHeight: 0.21,
|
|
61
|
+
lintelDepth: 0.24,
|
|
62
|
+
braceThickness: 0.1,
|
|
63
|
+
zOutset: 0.19,
|
|
64
|
+
});
|
|
65
|
+
|
|
43
66
|
/**
|
|
44
67
|
* Build one or more tall farmyard haystacks (by default a pair side by side) with weathered, bulging straw bodies and loose
|
|
45
68
|
* projecting straw wisps into a geometry builder.
|
|
@@ -105,3 +128,39 @@ export function buildStonePile(builder, random = Math.random, options = {}) {
|
|
|
105
128
|
);
|
|
106
129
|
}
|
|
107
130
|
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Build a pair of vertical-planked, diagonally braced double barn doors framed by heavy jamb posts
|
|
134
|
+
* and a lintel into a wood geometry builder.
|
|
135
|
+
*
|
|
136
|
+
* @param {Pick<import('./builder.js').GB, 'box' | 'add'>} builder - Destination wood geometry builder.
|
|
137
|
+
* @param {() => number} [random=Math.random] - Repeatable random stream in `[0, 1)`.
|
|
138
|
+
* @param {object} [options]
|
|
139
|
+
* @param {number} [options.depth=5.9] - Barn depth in metres used to position the door face when `z` is omitted.
|
|
140
|
+
* @param {number} [options.z] - Explicit local Z position of the door plane in metres (overrides `depth * 0.5 + shape.zOutset`).
|
|
141
|
+
* @param {import('three').BufferGeometry} [options.box] - Unit box geometry for diagonal timber braces (defaults to `primitives.box`).
|
|
142
|
+
* @param {Partial<typeof FARM_BARN_DOORS>} [options.shape] - Overrides for {@link FARM_BARN_DOORS}.
|
|
143
|
+
*/
|
|
144
|
+
export function buildBarnDoors(builder, random = Math.random, options = {}) {
|
|
145
|
+
const cfg = options.shape ? { ...FARM_BARN_DOORS, ...options.shape } : FARM_BARN_DOORS;
|
|
146
|
+
const braceBox = options.box ?? box;
|
|
147
|
+
const doorZ = options.z ?? (options.depth ?? 5.9) * 0.5 + cfg.zOutset;
|
|
148
|
+
const timber = C(cfg.frameColor);
|
|
149
|
+
const half = (cfg.planks - 1) * 0.5;
|
|
150
|
+
for (let j = 0; j < cfg.planks; j++) {
|
|
151
|
+
builder.box(
|
|
152
|
+
(j - half) * cfg.plankStep,
|
|
153
|
+
0.02 + (j % 3) * 0.015,
|
|
154
|
+
doorZ,
|
|
155
|
+
cfg.plankWidth,
|
|
156
|
+
cfg.plankHeight,
|
|
157
|
+
cfg.plankThickness,
|
|
158
|
+
C(cfg.plankColor, cfg.plankJitter, random),
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
for (const sign of [-1, 1]) {
|
|
162
|
+
builder.box(sign * cfg.jambOffset, -0.12, doorZ, cfg.jambWidth, cfg.jambHeight, cfg.jambWidth, timber);
|
|
163
|
+
stick(builder, [sign * 0.16, 0.28, doorZ + 0.075], [sign * 1.43, 2.38, doorZ + 0.075], cfg.braceThickness, timber, braceBox);
|
|
164
|
+
}
|
|
165
|
+
builder.box(0, cfg.plankHeight, doorZ, cfg.lintelWidth, cfg.lintelHeight, cfg.lintelDepth, timber);
|
|
166
|
+
}
|