roamwright 0.61.14 → 0.61.16
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 +24 -23
- package/examples/effects.js +19 -13
- package/examples/island.js +21 -14
- package/examples/ruins.js +3 -2
- package/examples/stage.js +0 -6
- package/examples/town-fittings.html +52 -0
- package/examples/town-fittings.js +464 -0
- package/geometry/harbour-kit.js +200 -0
- package/geometry/plant-garden.js +92 -0
- package/geometry/storm-wall.js +98 -0
- package/geometry/town-garden.js +343 -0
- package/index.js +8 -1
- package/package.json +1 -1
- package/rendering/lamp-maps.js +87 -0
- package/rendering/plant-garden.js +51 -0
- package/rendering/scatter-instances.js +12 -0
- package/rendering/storm-wall.js +238 -0
- package/rendering/street-lamps.js +101 -1
- package/tools/beasts-near.cjs +17 -0
- package/tools/beasts-near.test.cjs +36 -1
- package/tools/viewport-check.cjs +56 -21
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import {
|
|
3
|
+
createCityFortification,
|
|
4
|
+
createCityGlow,
|
|
5
|
+
createCityLamplight,
|
|
6
|
+
createDaylightSky,
|
|
7
|
+
createGardenPlants,
|
|
8
|
+
createHarbourKit,
|
|
9
|
+
createHouseKit,
|
|
10
|
+
createHouseKitMaterials,
|
|
11
|
+
createHouseKitMeshes,
|
|
12
|
+
createOrbitCamera,
|
|
13
|
+
createShipKit,
|
|
14
|
+
createShipMeshes,
|
|
15
|
+
createSimpleWater,
|
|
16
|
+
createSkyPanorama,
|
|
17
|
+
createStormWall,
|
|
18
|
+
createStreetLampNight,
|
|
19
|
+
createStreetLamps,
|
|
20
|
+
createTownGarden,
|
|
21
|
+
createTownHouses,
|
|
22
|
+
createTownWorks,
|
|
23
|
+
mulberry32,
|
|
24
|
+
SHIP_PRESETS,
|
|
25
|
+
} from 'roamwright';
|
|
26
|
+
import { createHeightfieldMesh } from 'roamwright/geometry/heightfield.js';
|
|
27
|
+
import { createPlantTints } from 'roamwright/geometry/plant-tints.js';
|
|
28
|
+
import { createTrees } from 'roamwright/geometry/plant-trees.js';
|
|
29
|
+
import { partsGeometry } from 'roamwright/geometry/foliage.js';
|
|
30
|
+
import { C, TRS } from 'roamwright/geometry/primitives.js';
|
|
31
|
+
import { createProps } from 'roamwright/geometry/props.js';
|
|
32
|
+
import { oneOf } from 'roamwright/geometry/ship-kit.js';
|
|
33
|
+
import { YARD_STOWED } from 'roamwright/geometry/ship-rig.js';
|
|
34
|
+
import { townFrame } from 'roamwright/geometry/land-town-ground.js';
|
|
35
|
+
import { sstep, TAU } from 'roamwright/math/scalar.js';
|
|
36
|
+
import { initExample } from './stage.js';
|
|
37
|
+
|
|
38
|
+
const { canvas, renderer, camera, scene, worldGroup, seed, random, noise, hash, shapes } = initExample({
|
|
39
|
+
fallbackSeed: 42,
|
|
40
|
+
fov: 42,
|
|
41
|
+
});
|
|
42
|
+
const params = new URL(location.href).searchParams;
|
|
43
|
+
let night = params.has('night');
|
|
44
|
+
|
|
45
|
+
// Coastal desert plain rising gently inland (-z) from a sheltered bay (+z).
|
|
46
|
+
const QUAY_Y = 2.6;
|
|
47
|
+
function groundAt(x, z) {
|
|
48
|
+
if (z > 2) return Math.max(-7, -0.14 * (z - 2) - 0.6);
|
|
49
|
+
const inland = Math.max(0, -z);
|
|
50
|
+
const shelf = 2.4 * sstep(4, -6, z);
|
|
51
|
+
const dunes = sstep(90, 260, inland) * (16 * noise.fbm(x * 0.006, z * 0.006, 4, 17) + 6 * noise.ridged(x * 0.004, z * 0.004, 3, 29));
|
|
52
|
+
return shelf + 0.006 * Math.min(inland, 120) + dunes;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const sandCol = new THREE.Color(0xcab68c);
|
|
56
|
+
const duneCol = new THREE.Color(0xb89662);
|
|
57
|
+
const stoneCol = new THREE.Color(0xb8ad96);
|
|
58
|
+
const groundMesh = createHeightfieldMesh({
|
|
59
|
+
size: 1600,
|
|
60
|
+
segs: 180,
|
|
61
|
+
heightAt: groundAt,
|
|
62
|
+
colorAt: (x, y, z, up, out) => {
|
|
63
|
+
const grain = noise.fbm(x * 0.03, z * 0.03, 3, 7);
|
|
64
|
+
const inTown = (1 - sstep(115, 145, Math.abs(x))) * sstep(6, -4, z) * (1 - sstep(95, 125, -z));
|
|
65
|
+
out.copy(sandCol).lerp(duneCol, sstep(4, 18, y) * 0.75);
|
|
66
|
+
out.lerp(stoneCol, inTown * 0.65);
|
|
67
|
+
out.multiplyScalar(0.86 + 0.24 * grain);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
worldGroup.add(groundMesh);
|
|
71
|
+
|
|
72
|
+
const { mesh: seaMesh, timeUniform: waterTime } = createSimpleWater({
|
|
73
|
+
width: 1800,
|
|
74
|
+
depth: 1800,
|
|
75
|
+
segs: 96,
|
|
76
|
+
level: 0,
|
|
77
|
+
depthAt: (x, z) => Math.max(0, -groundAt(x, z)),
|
|
78
|
+
shallowColor: 0x4b9496,
|
|
79
|
+
deepColor: 0x164a62,
|
|
80
|
+
opacity: 0.94,
|
|
81
|
+
});
|
|
82
|
+
worldGroup.add(seaMesh);
|
|
83
|
+
|
|
84
|
+
// Shared builders: house kit, props, town works, town garden, garden plants, harbour kit and ship kit.
|
|
85
|
+
const houseKit = createHouseKit({ shapes, hash });
|
|
86
|
+
const props = createProps({ houseKit, shapes, vnoise: noise.vnoise, hash, horse: () => {} });
|
|
87
|
+
const townWorks = createTownWorks({
|
|
88
|
+
shapes,
|
|
89
|
+
color: C,
|
|
90
|
+
transform: TRS,
|
|
91
|
+
archOpening: houseKit.archOpening,
|
|
92
|
+
facePut: houseKit.facePut,
|
|
93
|
+
waterJar: houseKit.waterJar,
|
|
94
|
+
kitAt: houseKit.kitAt,
|
|
95
|
+
props: {
|
|
96
|
+
bench: props.propBench,
|
|
97
|
+
crates: props.propCrates,
|
|
98
|
+
goods: props.propGoods,
|
|
99
|
+
stall: props.propStall,
|
|
100
|
+
trough: props.propTrough,
|
|
101
|
+
well: props.propWell,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
const townGarden = createTownGarden({
|
|
105
|
+
shapes,
|
|
106
|
+
color: C,
|
|
107
|
+
transform: TRS,
|
|
108
|
+
archRing: houseKit.archRing,
|
|
109
|
+
facePut: houseKit.facePut,
|
|
110
|
+
kitPush: houseKit.kitPush,
|
|
111
|
+
kitPop: houseKit.kitPop,
|
|
112
|
+
kitAt: houseKit.kitAt,
|
|
113
|
+
kitFrame: houseKit.kitFrame,
|
|
114
|
+
levelFloor: townWorks.levelFloor,
|
|
115
|
+
benchProp: props.propBench,
|
|
116
|
+
});
|
|
117
|
+
const tints = createPlantTints({ fbm: noise.fbm, vnoise: noise.vnoise, hash });
|
|
118
|
+
const gardenPlants = createGardenPlants({ crownBlob: tints.crownBlob, crownTint: tints.crownTint });
|
|
119
|
+
|
|
120
|
+
const fort = createCityFortification({ ground: groundAt, shapes, color: C, transform: TRS, houseKit });
|
|
121
|
+
const frame = townFrame({
|
|
122
|
+
x: 0,
|
|
123
|
+
z: 0,
|
|
124
|
+
plan: {
|
|
125
|
+
yaw: 0,
|
|
126
|
+
half: 130,
|
|
127
|
+
depth: 140,
|
|
128
|
+
quay: QUAY_Y,
|
|
129
|
+
quayHalf: 118,
|
|
130
|
+
wall: 0xd8cbaa,
|
|
131
|
+
yard: { from: 20, to: 112 },
|
|
132
|
+
seawall: { centre: 95, moles: [[195, 5.2, -0.18]] },
|
|
133
|
+
},
|
|
134
|
+
water: 0,
|
|
135
|
+
});
|
|
136
|
+
const sp = { id: 'harbour-town', decks: [], grid: new Map(), ground: groundAt };
|
|
137
|
+
const K = fort.cityKit(sp, frame);
|
|
138
|
+
K.town = { add: () => 0 };
|
|
139
|
+
K.quarter = { add: () => {} };
|
|
140
|
+
|
|
141
|
+
const townHouses = createTownHouses({
|
|
142
|
+
styles: {
|
|
143
|
+
harbour: { render: [0xdccfb4, 0xd1c1a0, 0xe4dac4], roof: [0x9f8d72], trim: [0x5c4734], door: [0x4c3726] },
|
|
144
|
+
estates: { render: [0xeae2cf, 0xe1d6be, 0xefe8d8], roof: [0x8b7c65], trim: [0x5c4734], door: [0x4c3726] },
|
|
145
|
+
},
|
|
146
|
+
common: {
|
|
147
|
+
dressed: [0xd9cfb4, 0xcfc4a8],
|
|
148
|
+
fired: [0x9a6a4a, 0x8e5f42],
|
|
149
|
+
domes: [0x2f6f80, 0x3a7a8a],
|
|
150
|
+
timber: [0x5a4632, 0x4a3828],
|
|
151
|
+
awning: [0xb04a32, 0x2f6a7a, 0xc9a24a],
|
|
152
|
+
clay: [0xa0603c],
|
|
153
|
+
brass: 0xb08b46,
|
|
154
|
+
earth: 0xa8916c,
|
|
155
|
+
water: 0x2a6f78,
|
|
156
|
+
},
|
|
157
|
+
form: 'courtyard',
|
|
158
|
+
defaultDistrict: 'harbour',
|
|
159
|
+
color: C,
|
|
160
|
+
addBox: () => {},
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const shipKit = createShipKit({ hash });
|
|
164
|
+
const { buildShip } = createShipMeshes({ kit: shipKit });
|
|
165
|
+
const mooredSpecs = [];
|
|
166
|
+
const harbourKit = createHarbourKit({
|
|
167
|
+
shapes,
|
|
168
|
+
color: C,
|
|
169
|
+
transform: TRS,
|
|
170
|
+
kitAt: houseKit.kitAt,
|
|
171
|
+
placeHouse: (kitObj, rng, u, v, spec) => {
|
|
172
|
+
const [x, z] = kitObj.f.world(u, v);
|
|
173
|
+
const y = kitObj.Y(u, v);
|
|
174
|
+
const col = C(0xded2b8, 0.05, rng);
|
|
175
|
+
houseKit.genHouse(kitObj.kit, {
|
|
176
|
+
x,
|
|
177
|
+
y,
|
|
178
|
+
z,
|
|
179
|
+
w: spec.w,
|
|
180
|
+
d: spec.d,
|
|
181
|
+
h: (spec.n ?? 2) * 3.1 + 1.4,
|
|
182
|
+
n: spec.n ?? 2,
|
|
183
|
+
rot: kitObj.f.yaw,
|
|
184
|
+
form: 'flat',
|
|
185
|
+
style: 'adobe',
|
|
186
|
+
col,
|
|
187
|
+
rc: C(0x9a896e, 0.04, rng),
|
|
188
|
+
seed: (rng() * 1e9) | 0,
|
|
189
|
+
shop: spec.shop,
|
|
190
|
+
awning: spec.awning,
|
|
191
|
+
found: 1.5,
|
|
192
|
+
});
|
|
193
|
+
return townHouses;
|
|
194
|
+
},
|
|
195
|
+
quayGate: fort.quayGate,
|
|
196
|
+
carvedLoad: townWorks.carvedChest,
|
|
197
|
+
moor: (spec, x, sea, z, yaw, len, rng) => mooredSpecs.push({ spec, x, sea, z, yaw, len, seed: (rng() * 1e6) | 0 }),
|
|
198
|
+
warship: SHIP_PRESETS.galley,
|
|
199
|
+
props: {
|
|
200
|
+
crates: props.propCrates,
|
|
201
|
+
goods: props.propGoods,
|
|
202
|
+
netRack: props.propNetRack,
|
|
203
|
+
standard: props.propStandard,
|
|
204
|
+
tollBooth: props.propTollBooth,
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// Stone quay apron under the stores and naval yard.
|
|
209
|
+
const quayCol = C(0xd6ccb4, 0.04, random);
|
|
210
|
+
K.stone.box(0, -3.5, -24, 240, QUAY_Y + 3.5, 52, quayCol);
|
|
211
|
+
K.stone.box(0, QUAY_Y, 1.8, 240, 0.25, 1.2, C(0xe4dcc8, 0.03, random));
|
|
212
|
+
|
|
213
|
+
const harbourPlan = {
|
|
214
|
+
town: {
|
|
215
|
+
kept: [{ id: 'garden', u: -48, v: 64, w: 68, d: 30, garden: true }],
|
|
216
|
+
stores: [
|
|
217
|
+
{ u0: -112, u1: -28, v: 36, d: 12 },
|
|
218
|
+
{ u0: -22, u1: 2, v: 32, d: 11, house: { n: 3, shop: false, awning: 0 } },
|
|
219
|
+
],
|
|
220
|
+
landing: {
|
|
221
|
+
gate: [-6, 40],
|
|
222
|
+
booth: [-14, 34],
|
|
223
|
+
standards: [
|
|
224
|
+
[-10, 26],
|
|
225
|
+
[-2, 26],
|
|
226
|
+
],
|
|
227
|
+
dryingNets: [[-88, 16]],
|
|
228
|
+
stoneLoads: [[-56, 20]],
|
|
229
|
+
palms: [
|
|
230
|
+
[-30, 22],
|
|
231
|
+
[4, 22],
|
|
232
|
+
],
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const buildRng = mulberry32(seed * 17 + 5);
|
|
238
|
+
const palms = [];
|
|
239
|
+
townGarden.townGardens(K, buildRng, harbourPlan, palms);
|
|
240
|
+
harbourKit.harbourStores(K, buildRng, harbourPlan);
|
|
241
|
+
harbourKit.harbourLanding(K, buildRng, harbourPlan, palms);
|
|
242
|
+
harbourKit.seawall(K, buildRng, 0);
|
|
243
|
+
harbourKit.navalYard(K, buildRng, 0);
|
|
244
|
+
|
|
245
|
+
// Upload masonry, timber, rock, house-kit props, water pools, garden plants, palms and ships.
|
|
246
|
+
const stoneMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.92 });
|
|
247
|
+
const woodMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.88 });
|
|
248
|
+
const rockMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.96 });
|
|
249
|
+
for (const [gb, mat] of [
|
|
250
|
+
[K.stone, stoneMat],
|
|
251
|
+
[K.wood, woodMat],
|
|
252
|
+
[K.rock, rockMat],
|
|
253
|
+
]) {
|
|
254
|
+
const m = gb.mesh(mat, worldGroup);
|
|
255
|
+
if (m) m.castShadow = m.receiveShadow = true;
|
|
256
|
+
}
|
|
257
|
+
createHouseKitMeshes({ materials: createHouseKitMaterials({ doubleSide: true }) }).kitStatic(K.kit, worldGroup);
|
|
258
|
+
|
|
259
|
+
for (const order of K.orders) {
|
|
260
|
+
if (order.glow) {
|
|
261
|
+
const { size, hex, intensity, at, ry } = order.glow;
|
|
262
|
+
const plane = new THREE.Mesh(
|
|
263
|
+
new THREE.PlaneGeometry(...size).rotateX(-Math.PI / 2),
|
|
264
|
+
new THREE.MeshBasicMaterial({ color: new THREE.Color(hex).multiplyScalar(intensity) }),
|
|
265
|
+
);
|
|
266
|
+
plane.position.set(...at);
|
|
267
|
+
plane.rotation.y = ry;
|
|
268
|
+
worldGroup.add(plane);
|
|
269
|
+
} else if (order.plants) {
|
|
270
|
+
worldGroup.add(gardenPlants.plantsMesh(order.plants));
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Procedural courtyard shade trees placed at every palm mark returned by townGardens and harbourLanding.
|
|
275
|
+
const treeKit = createTrees({
|
|
276
|
+
hash,
|
|
277
|
+
barkTint: tints.barkTint,
|
|
278
|
+
crownBlob: tints.crownBlob,
|
|
279
|
+
crownTint: tints.crownTint,
|
|
280
|
+
seed,
|
|
281
|
+
});
|
|
282
|
+
const treeGeo = partsGeometry(treeKit.acacia().near);
|
|
283
|
+
const treeMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.9 });
|
|
284
|
+
const treeMesh = new THREE.InstancedMesh(treeGeo, treeMat, palms.length);
|
|
285
|
+
palms.forEach(([u, v, scale = 1, y], i) => {
|
|
286
|
+
const [px, pz] = frame.world(u, v);
|
|
287
|
+
const py = y ?? groundAt(px, pz);
|
|
288
|
+
const s = 0.72 * scale;
|
|
289
|
+
treeMesh.setMatrixAt(i, TRS(px, py - 0.1, pz, s, s * (0.9 + buildRng() * 0.25), s, buildRng() * TAU));
|
|
290
|
+
});
|
|
291
|
+
treeMesh.castShadow = treeMesh.receiveShadow = true;
|
|
292
|
+
treeMesh.matrixAutoUpdate = false;
|
|
293
|
+
treeMesh.computeBoundingSphere();
|
|
294
|
+
worldGroup.add(treeMesh);
|
|
295
|
+
|
|
296
|
+
for (const { spec, x, sea, z, yaw, len, seed: shipSeed } of mooredSpecs) {
|
|
297
|
+
const ship = buildShip(oneOf({ ...spec, lateenYard: YARD_STOWED }, mulberry32(shipSeed)), { riding: true });
|
|
298
|
+
const scale = len / (spec.len || 30);
|
|
299
|
+
ship.group.scale.setScalar(scale);
|
|
300
|
+
ship.group.position.set(x, sea, z);
|
|
301
|
+
ship.group.rotation.y = yaw;
|
|
302
|
+
if (ship.set && ship.furl) ship.set.visible = !(ship.furl.visible = true);
|
|
303
|
+
ship.group.traverse(o => {
|
|
304
|
+
if (o.isMesh) {
|
|
305
|
+
o.castShadow = true;
|
|
306
|
+
o.receiveShadow = true;
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
worldGroup.add(ship.group);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Street lamps along the quay and garden road, distant city sky-glow, and per-city lamplight registry.
|
|
313
|
+
const lampUniforms = {
|
|
314
|
+
night: { value: night ? 1 : 0 },
|
|
315
|
+
litShare: { value: 0 },
|
|
316
|
+
time: { value: 0 },
|
|
317
|
+
sky: { value: new THREE.Color(0x223344) },
|
|
318
|
+
};
|
|
319
|
+
const lampSpots = [];
|
|
320
|
+
for (let x = -104; x <= 104; x += 26) lampSpots.push({ x, y: QUAY_Y + 3.5, z: -8 });
|
|
321
|
+
for (let x = -80; x <= -16; x += 16) lampSpots.push({ x, y: groundAt(x, -46) + 3.5, z: -46 });
|
|
322
|
+
const streetLamps = createStreetLamps({
|
|
323
|
+
lamps: lampSpots,
|
|
324
|
+
color: new THREE.Color(1, 0.72, 0.36),
|
|
325
|
+
uniforms: lampUniforms,
|
|
326
|
+
pointScale: { value: 600 },
|
|
327
|
+
shapes,
|
|
328
|
+
postMaterial: new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.6 }),
|
|
329
|
+
});
|
|
330
|
+
const cityGlow = createCityGlow({
|
|
331
|
+
color: new THREE.Color(1, 0.72, 0.36),
|
|
332
|
+
size: [260, 110],
|
|
333
|
+
position: [-10, 42, -45],
|
|
334
|
+
});
|
|
335
|
+
worldGroup.add(streetLamps.posts, streetLamps.mantles, streetLamps.panes, streetLamps.points, cityGlow);
|
|
336
|
+
|
|
337
|
+
const lampState = { ...streetLamps, glow: cityGlow };
|
|
338
|
+
const updateNightLamps = createStreetLampNight({
|
|
339
|
+
uniforms: lampUniforms,
|
|
340
|
+
camera,
|
|
341
|
+
center: { x: -10, z: -45 },
|
|
342
|
+
lamps: lampState,
|
|
343
|
+
glowFade: [90, 260],
|
|
344
|
+
nearRange: 650,
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
const cityLights = createCityLamplight({
|
|
348
|
+
camera,
|
|
349
|
+
map: { value: null },
|
|
350
|
+
rect: { value: new THREE.Vector4() },
|
|
351
|
+
night: lampUniforms.night,
|
|
352
|
+
land: () => 'harbour-town',
|
|
353
|
+
pointScale: { value: 600 },
|
|
354
|
+
pointColor: [0.95, 0.75, 0.42],
|
|
355
|
+
});
|
|
356
|
+
const flatLamps = [];
|
|
357
|
+
const distantPoints = [];
|
|
358
|
+
for (const l of lampSpots) {
|
|
359
|
+
flatLamps.push(l.x, l.z);
|
|
360
|
+
distantPoints.push(l.x, l.y, l.z);
|
|
361
|
+
}
|
|
362
|
+
cityLights.addCity({ id: 'harbour-town', group: worldGroup }, -10, -45, {
|
|
363
|
+
lamps: flatLamps,
|
|
364
|
+
lights: new Float32Array(distantPoints),
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// Towering desert storm wall sweeping across the inland horizon behind the town.
|
|
368
|
+
const stormWall = createStormWall({
|
|
369
|
+
parent: worldGroup,
|
|
370
|
+
x: -240,
|
|
371
|
+
z: -420,
|
|
372
|
+
radius: 340,
|
|
373
|
+
sweep: 0.65,
|
|
374
|
+
width: 65,
|
|
375
|
+
height: 165,
|
|
376
|
+
wind: [0.86, 0.51],
|
|
377
|
+
ground: groundAt,
|
|
378
|
+
tfbm: noise.tfbm,
|
|
379
|
+
camera,
|
|
380
|
+
layers: 4,
|
|
381
|
+
along: 90,
|
|
382
|
+
up: 8,
|
|
383
|
+
billow: 16,
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
// Daylight and night sky presets.
|
|
387
|
+
const {
|
|
388
|
+
sky: daySky,
|
|
389
|
+
sun,
|
|
390
|
+
hemi,
|
|
391
|
+
} = createDaylightSky({
|
|
392
|
+
scene,
|
|
393
|
+
renderer,
|
|
394
|
+
noise,
|
|
395
|
+
sky: { sunDir: [-0.68, 0.34, 0.65] },
|
|
396
|
+
sunPosition: [-120, 74, 105],
|
|
397
|
+
shadowRadius: 170,
|
|
398
|
+
shadowFar: 460,
|
|
399
|
+
fogColor: 0xdccfb4,
|
|
400
|
+
fogDensity: 0.0009,
|
|
401
|
+
});
|
|
402
|
+
const nightSky = createSkyPanorama(noise, {
|
|
403
|
+
zenith: [0.03, 0.06, 0.14],
|
|
404
|
+
horizon: [0.09, 0.13, 0.22],
|
|
405
|
+
ground: [0.06, 0.07, 0.1],
|
|
406
|
+
cloudColor: [0.15, 0.19, 0.28],
|
|
407
|
+
sunGlow: [0.42, 0.52, 0.76],
|
|
408
|
+
sunDir: [-0.48, 0.44, -0.76],
|
|
409
|
+
cloudCover: 0.45,
|
|
410
|
+
stars: 0.85,
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
const dayHorizon = new THREE.Color(0xdccfb4);
|
|
414
|
+
const nightHorizon = new THREE.Color(0x162038);
|
|
415
|
+
const hourBtn = document.querySelector('#hour');
|
|
416
|
+
function applyHour() {
|
|
417
|
+
scene.background = night ? nightSky : daySky;
|
|
418
|
+
scene.fog.color.setHex(night ? 0x101828 : 0xdccfb4);
|
|
419
|
+
scene.fog.density = night ? 0.0014 : 0.0009;
|
|
420
|
+
hemi.color.setHex(night ? 0x3b4d74 : 0xe8eff6);
|
|
421
|
+
hemi.groundColor.setHex(night ? 0x1b1c22 : 0x9b8766);
|
|
422
|
+
hemi.intensity = night ? 0.38 : 1.15;
|
|
423
|
+
sun.color.setHex(night ? 0x8ea6dc : 0xffe4bc);
|
|
424
|
+
sun.intensity = night ? 0.35 : 2.6;
|
|
425
|
+
hourBtn.setAttribute('aria-pressed', String(night));
|
|
426
|
+
hourBtn.textContent = night ? 'Day' : 'Night';
|
|
427
|
+
}
|
|
428
|
+
hourBtn.addEventListener('click', () => {
|
|
429
|
+
night = !night;
|
|
430
|
+
applyHour();
|
|
431
|
+
});
|
|
432
|
+
applyHour();
|
|
433
|
+
|
|
434
|
+
const views = {
|
|
435
|
+
garden: { eye: [-92, 16, -92], target: [-36, 3.5, -52] },
|
|
436
|
+
harbour: { eye: [148, 36, 128], target: [-10, 4, -10] },
|
|
437
|
+
storm: { eye: [-60, 26, -110], target: [80, 48, -380] },
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
createOrbitCamera({
|
|
441
|
+
camera,
|
|
442
|
+
canvas,
|
|
443
|
+
renderer,
|
|
444
|
+
scene,
|
|
445
|
+
views,
|
|
446
|
+
initialView: 'garden',
|
|
447
|
+
groundAt,
|
|
448
|
+
minClearance: 2,
|
|
449
|
+
minDistance: 10,
|
|
450
|
+
maxDistance: 520,
|
|
451
|
+
far: 2400,
|
|
452
|
+
onDraw: () => {},
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
function frameLoop(ms) {
|
|
456
|
+
const t = ms / 1000;
|
|
457
|
+
waterTime.value = t;
|
|
458
|
+
updateNightLamps(night ? 1 : 0, 0, night ? 21 / 24 : 15 / 24, t, night ? nightHorizon : dayHorizon);
|
|
459
|
+
cityLights.bindNearest();
|
|
460
|
+
stormWall.update(t, night ? 0 : 1, 1);
|
|
461
|
+
renderer.render(scene, camera);
|
|
462
|
+
requestAnimationFrame(frameLoop);
|
|
463
|
+
}
|
|
464
|
+
requestAnimationFrame(frameLoop);
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedural harbour works kit beside the ship kit and breakwater seawall: waterfront warehouse and shop rows with
|
|
3
|
+
* passages and landed cargo stacks (`harbourStores`), quay approach furniture including gate, toll booth, standards,
|
|
4
|
+
* drying nets, carved stone loads and palms (`harbourLanding`), fortified naval fleet dockyards with moored warships,
|
|
5
|
+
* gangways, spare-spar ricks, outer anchorage and dividing yard wall (`navalYard`), plus curving breakwater moles and
|
|
6
|
+
* beacon lighthouses (`seawall`, `mole`, `moleLight` via `createSeawall`). Worker-safe.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { dim } from '../math/color.js';
|
|
11
|
+
import { TAU } from '../math/scalar.js';
|
|
12
|
+
import { createCityFortification } from './fort-city-walls.js';
|
|
13
|
+
import { createSeawall } from './fort-seawall.js';
|
|
14
|
+
import { createHouseKit } from './house-kit.js';
|
|
15
|
+
import { C as defaultColor, createUnitShapes, TRS as defaultTransform } from './primitives.js';
|
|
16
|
+
import { SHIP_PRESETS } from './ship-presets.js';
|
|
17
|
+
import { createTownHouses } from './town-houses.js';
|
|
18
|
+
import { createTownWorks, placeInTown } from './town-works.js';
|
|
19
|
+
|
|
20
|
+
const DEFAULT_PASSAGE = 4; // width of passages through waterfront store rows to the street behind, metres
|
|
21
|
+
const noop = () => {};
|
|
22
|
+
const DEFAULT_HARBOUR_PROPS = {
|
|
23
|
+
crates: noop,
|
|
24
|
+
goods: noop,
|
|
25
|
+
netRack: noop,
|
|
26
|
+
standard: noop,
|
|
27
|
+
tollBooth: noop,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates a harbour works builder bound to unit shapes, house-kit placers, town-house builder, ship mooring hook,
|
|
32
|
+
* harbour props and seawall proportions.
|
|
33
|
+
* @param {object} [options] - Geometry, prop, ship and seawall bindings.
|
|
34
|
+
* @param {object} [options.shapes] - Unit shapes (`{ cyl6, cyl16, cone, rock }`).
|
|
35
|
+
* @param {(hex: number, jitter?: number, rng?: () => number) => number[]} [options.color] - Linear RGB colour helper.
|
|
36
|
+
* @param {Function} [options.transform] - Transform matrix helper (`TRS`).
|
|
37
|
+
* @param {Function} [options.kitAt] - House-kit prop placer `(kit, x, y, z, yaw, flip, prop, rng)`.
|
|
38
|
+
* @param {Function} [options.placeHouse] - Planned-town house placer (`createTownHouses().placeHouse`).
|
|
39
|
+
* @param {Function} [options.quayGate] - Quay approach gateway builder (`createCityFortification().quayGate`).
|
|
40
|
+
* @param {Function} [options.carvedLoad] - Carved stone load builder `(kit, rng, x, z, ry, stone)` (`createTownWorks().carvedChest`).
|
|
41
|
+
* @param {Function} [options.moor] - Vessel mooring callback `(spec, x, sea, z, yaw, len, rng)`.
|
|
42
|
+
* @param {object} [options.warship] - Ship specification passed to `moor` for naval yard berths (`SHIP_PRESETS.galley`).
|
|
43
|
+
* @param {object} [options.props] - Harbour prop builders `{ crates, goods, netRack, standard, tollBooth }`.
|
|
44
|
+
* @param {number} [options.passage=4] - Width of passages left between waterfront store rows in metres.
|
|
45
|
+
* @param {Function} [options.battlement] - Breakwater mole battlement builder forwarded to `createSeawall`.
|
|
46
|
+
* @param {Function} [options.floor] - Breakwater walkable deck builder forwarded to `createSeawall`.
|
|
47
|
+
* @param {number} [options.moleWidth=7] - Breakwater mole thickness in metres.
|
|
48
|
+
* @param {number} [options.moleMouth=46] - Breakwater mouth opening width in metres.
|
|
49
|
+
* @param {number} [options.moleReach=1.9] - Breakwater angular half-reach in radians.
|
|
50
|
+
* @param {number} [options.panelLength=9] - Target masonry chord length per mole segment in metres.
|
|
51
|
+
* @param {number} [options.bedDepth=-11] - Mole footing elevation in metres.
|
|
52
|
+
* @returns {{
|
|
53
|
+
* harbourStores: (K: object, rng: () => number, plan: object) => void,
|
|
54
|
+
* harbourLanding: (K: object, rng: () => number, plan: object, palms: Array<number[]>) => void,
|
|
55
|
+
* navalYard: (K: object, rng: () => number, sea: number) => void,
|
|
56
|
+
* seawall: (K: object, rng: () => number, sea: number) => void,
|
|
57
|
+
* mole: (K: object, rng: () => number, sea: number, centre: number, spec: [number, number, number], col: number[]) => void,
|
|
58
|
+
* moleLight: (K: object, u: number, v: number, top: number, col: number[]) => void,
|
|
59
|
+
* }} Harbour works builders.
|
|
60
|
+
*/
|
|
61
|
+
export function createHarbourKit(options = {}) {
|
|
62
|
+
const shapes = options.shapes ?? createUnitShapes();
|
|
63
|
+
const color = options.color ?? defaultColor;
|
|
64
|
+
const transform = options.transform ?? defaultTransform;
|
|
65
|
+
let kitFallback = null;
|
|
66
|
+
const getKit = () => (kitFallback ??= createHouseKit({ shapes }));
|
|
67
|
+
const kitAt = options.kitAt ?? getKit().kitAt;
|
|
68
|
+
let housesFallback = null;
|
|
69
|
+
const placeHouse = options.placeHouse ?? ((...args) => (housesFallback ??= createTownHouses({ color })).placeHouse(...args));
|
|
70
|
+
let fortFallback = null;
|
|
71
|
+
const quayGate =
|
|
72
|
+
options.quayGate ??
|
|
73
|
+
((...args) => (fortFallback ??= createCityFortification({ shapes, color, transform, houseKit: getKit() })).quayGate(...args));
|
|
74
|
+
let worksFallback = null;
|
|
75
|
+
const carvedLoad =
|
|
76
|
+
options.carvedLoad ?? ((...args) => (worksFallback ??= createTownWorks({ shapes, color, transform, kitAt })).carvedChest(...args));
|
|
77
|
+
const moor = options.moor ?? noop;
|
|
78
|
+
const warship = options.warship ?? SHIP_PRESETS.galley;
|
|
79
|
+
const props = { ...DEFAULT_HARBOUR_PROPS, ...options.props };
|
|
80
|
+
const passage = options.passage ?? DEFAULT_PASSAGE;
|
|
81
|
+
|
|
82
|
+
const { seawall, mole, moleLight } = createSeawall({
|
|
83
|
+
shapes,
|
|
84
|
+
color,
|
|
85
|
+
transform,
|
|
86
|
+
battlement: options.battlement,
|
|
87
|
+
floor: options.floor,
|
|
88
|
+
moleWidth: options.moleWidth,
|
|
89
|
+
moleMouth: options.moleMouth,
|
|
90
|
+
moleReach: options.moleReach,
|
|
91
|
+
panelLength: options.panelLength,
|
|
92
|
+
bedDepth: options.bedDepth,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const setDown = (K, rng, u, v, ry, prop, y) => placeInTown(kitAt, K, rng, u, v, ry, prop, y);
|
|
96
|
+
|
|
97
|
+
// Two- and three-storey waterfront stores along the back of a quay, with ground-floor shops under awnings, passages
|
|
98
|
+
// through to the street behind, and landed cargo stacked before their doors.
|
|
99
|
+
function harbourStores(K, rng, plan) {
|
|
100
|
+
plan.storeGoods = [];
|
|
101
|
+
for (const run of plan.town.stores ?? []) {
|
|
102
|
+
let u = run.u0;
|
|
103
|
+
while (u < run.u1 - 10) {
|
|
104
|
+
const w = run.house ? run.u1 - run.u0 : Math.min(run.u1 - u, 14 + rng() * 9);
|
|
105
|
+
placeHouse(K, rng, u + w / 2, run.v + run.d / 2, {
|
|
106
|
+
frontage: run.house ? undefined : 'loft',
|
|
107
|
+
district: run.district,
|
|
108
|
+
w,
|
|
109
|
+
d: run.d,
|
|
110
|
+
n: rng() < 0.35 ? 3 : 2,
|
|
111
|
+
shop: true,
|
|
112
|
+
awning: 0.9,
|
|
113
|
+
stair: rng() < 0.3 ? 2 : -1,
|
|
114
|
+
...run.house,
|
|
115
|
+
});
|
|
116
|
+
for (let k = 0; k < 2; k++)
|
|
117
|
+
if (rng() < 0.6) {
|
|
118
|
+
const at = u + w * (0.25 + k * 0.5);
|
|
119
|
+
const front = run.v - 2.2 - rng();
|
|
120
|
+
const ground = K.Y(at, front);
|
|
121
|
+
const floor = Math.abs(at) <= K.p.quayHalf ? Math.max(ground, K.p.quay) : ground;
|
|
122
|
+
plan.storeGoods.push({ u: at, v: front, shop: !run.house });
|
|
123
|
+
setDown(K, rng, at, front, rng() * TAU, rng() < 0.5 ? props.goods : (b, r) => props.crates(b, r, 2 + ((rng() * 3) | 0)), floor);
|
|
124
|
+
}
|
|
125
|
+
u += w + (rng() < 0.25 ? passage : 0.3);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Approach furniture on a finished quay: optional gate and toll booth, standards, drying nets, heavy carved stone loads
|
|
131
|
+
// and palms with colliders.
|
|
132
|
+
function harbourLanding(K, rng, plan, palms) {
|
|
133
|
+
const landing = plan.town.landing;
|
|
134
|
+
if (!landing) return;
|
|
135
|
+
const floor = (u, v) => Math.max(K.Y(u, v), K.p.quay);
|
|
136
|
+
function place([u, v], prop, yaw, hx, hz) {
|
|
137
|
+
setDown(K, rng, u, v, yaw, prop, floor(u, v));
|
|
138
|
+
K.solid(u, v, hx, hz, yaw);
|
|
139
|
+
}
|
|
140
|
+
if (landing.gate) {
|
|
141
|
+
const [u, v] = landing.gate;
|
|
142
|
+
quayGate(K, u, v, floor(u, v));
|
|
143
|
+
place(landing.booth, props.tollBooth, Math.PI / 2, 1.3, 1.2);
|
|
144
|
+
}
|
|
145
|
+
for (const spot of landing.standards ?? []) place(spot, props.standard, 0.45, 0.14, 0.14);
|
|
146
|
+
for (const spot of landing.dryingNets ?? []) place(spot, props.netRack, Math.PI / 2, 1.8, 0.45);
|
|
147
|
+
for (const spot of landing.stoneLoads ?? []) {
|
|
148
|
+
place(spot, (kit, rand) => carvedLoad(kit, rand, 0, 0, 0, color(K.p.wall, 0.06, rand)), 0.08, 1.3, 1);
|
|
149
|
+
}
|
|
150
|
+
for (const [u, v] of landing.palms ?? []) {
|
|
151
|
+
palms.push([u, v, 1.15, floor(u, v)]);
|
|
152
|
+
K.solid(u, v, 0.55, 0.55);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Fleet dockyard along `[from, to]` of the quay: warships moored alongside with timber gangways, apron cargo, spare
|
|
157
|
+
// spar ricks on trestles, two warships riding inside the moles, standards, and a walled gateway closing off the yard.
|
|
158
|
+
function navalYard(K, rng, sea) {
|
|
159
|
+
const { from, to } = K.p.yard;
|
|
160
|
+
const q = K.p.quay;
|
|
161
|
+
const stone = color(K.p.wall);
|
|
162
|
+
const ship = (u, v, ry, len) => {
|
|
163
|
+
const [x, z] = K.f.world(u, v);
|
|
164
|
+
moor(warship, x, sea, z, K.f.yaw + ry, len, rng);
|
|
165
|
+
};
|
|
166
|
+
const put = (u, v, ry, prop) => {
|
|
167
|
+
const [x, z] = K.f.world(u, v);
|
|
168
|
+
kitAt(K.kit, x, q, z, K.f.yaw + ry, false, prop, rng);
|
|
169
|
+
};
|
|
170
|
+
for (let u = from + 26; u < to - 14; u += 46) {
|
|
171
|
+
ship(u, -10.8, Math.PI / 2, 31 + rng() * 5);
|
|
172
|
+
K.wood.box(u - 4, q - 0.45, 3.6, 1.8, 0.14, 7.6, color(0x5a4632, 0.1, rng), 0, 0.18);
|
|
173
|
+
for (const sg of [-1, 1]) K.wood.box(u - 4 + sg * 0.9, q, 3.6, 0.06, 0.06, 7.6, color(0x4a3a2a), 0, 0.18);
|
|
174
|
+
put(u + 9, 14 + rng() * 6, rng() * TAU, rng() < 0.5 ? props.goods : (B, r) => props.crates(B, r, 4));
|
|
175
|
+
put(u - 12, 30 + rng() * 8, rng() * TAU, (B, r) => props.crates(B, r, 3));
|
|
176
|
+
const sv = 24 + rng() * 4;
|
|
177
|
+
for (let i = 0; i < 5; i++)
|
|
178
|
+
K.wood.add(
|
|
179
|
+
shapes.cyl6,
|
|
180
|
+
color(0x6e5a44, 0.12, rng),
|
|
181
|
+
transform(u + 16, q + 0.7 + (i > 2 ? 0.34 : 0), -(sv + (i % 3) * 0.4), 0.32, 13 + rng() * 3, 0.32, 0, 0, Math.PI / 2),
|
|
182
|
+
);
|
|
183
|
+
for (const sx of [-4, 4]) K.wood.box(u + 16 + sx, q, -(sv + 0.4), 0.3, 0.7, 1.8, color(0x4a3a2a));
|
|
184
|
+
}
|
|
185
|
+
ship((from + to) / 2 - 60, -74, 0.5, 34);
|
|
186
|
+
ship((from + to) / 2 + 50, -88, 2.4, 30);
|
|
187
|
+
for (let u = from + 8; u < to; u += 38) put(u, 50, 0, props.standard);
|
|
188
|
+
for (const [v0, v1] of [
|
|
189
|
+
[3, 22],
|
|
190
|
+
[29, 54],
|
|
191
|
+
]) {
|
|
192
|
+
K.stone.box(from - 5, q - 0.5, -(v0 + v1) / 2, 1.3, 4.3, v1 - v0, dim(stone, 0.94));
|
|
193
|
+
K.stone.box(from - 5, q + 3.8, -(v0 + v1) / 2, 1.7, 0.3, v1 - v0 + 0.3, dim(stone, 1.06));
|
|
194
|
+
K.solid(from - 5, (v0 + v1) / 2, 0.65, (v1 - v0) / 2);
|
|
195
|
+
}
|
|
196
|
+
for (const v of [22, 29]) K.stone.box(from - 5, q - 0.5, -v, 2.2, 5.6, 2.2, dim(stone, 1.0));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return { harbourStores, harbourLanding, navalYard, seawall, mole, moleLight };
|
|
200
|
+
}
|