roamwright 0.61.14 → 0.61.15
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/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/storm-wall.js +238 -0
- package/rendering/street-lamps.js +101 -1
package/README.md
CHANGED
|
@@ -30,29 +30,30 @@ 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
|
|
34
|
-
|
|
35
|
-
| Live example | What the example shows
|
|
36
|
-
| -------------------------------------------------------------------------------------------------- |
|
|
37
|
-
| [A small world](https://enestaylan.github.io/roamwright/examples/small-world.html?seed=42) | A coastal valley with a walled harbour town, lamps, market crowd, pasture herds, ships and a passing day/night sky.
|
|
38
|
-
| [Towns](https://enestaylan.github.io/roamwright/examples/towns.html?seed=7) | A village streaming in block by block along a winding valley road, with street lamps and windows lit after dark.
|
|
39
|
-
| [
|
|
40
|
-
| [
|
|
41
|
-
| [
|
|
42
|
-
| [
|
|
43
|
-
| [
|
|
44
|
-
| [
|
|
45
|
-
| [
|
|
46
|
-
| [
|
|
47
|
-
| [
|
|
48
|
-
| [
|
|
49
|
-
| [
|
|
50
|
-
| [
|
|
51
|
-
| [
|
|
52
|
-
| [
|
|
53
|
-
| [
|
|
54
|
-
| [
|
|
55
|
-
| [
|
|
33
|
+
Browse all twenty examples on the [live showcase](https://enestaylan.github.io/roamwright/).
|
|
34
|
+
|
|
35
|
+
| Live example | What the example shows | Source |
|
|
36
|
+
| -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
|
|
37
|
+
| [A small world](https://enestaylan.github.io/roamwright/examples/small-world.html?seed=42) | A coastal valley with a walled harbour town, lamps, market crowd, pasture herds, ships and a passing day/night sky. | [small-world.js](examples/small-world.js) |
|
|
38
|
+
| [Towns](https://enestaylan.github.io/roamwright/examples/towns.html?seed=7) | A village streaming in block by block along a winding valley road, with street lamps and windows lit after dark. | [towns.js](examples/towns.js) |
|
|
39
|
+
| [Town fittings](https://enestaylan.github.io/roamwright/examples/town-fittings.html?seed=42) | Walled courtyard gardens with instanced shrubs, harbour works and breakwater moles, street lamps and a desert storm wall. | [town-fittings.js](examples/town-fittings.js) |
|
|
40
|
+
| [Fortification](https://enestaylan.github.io/roamwright/examples/fortification.html?seed=11) | Walled coastal or inland town with towers, battlements, vaulted gatehouses, wall-walk and portal in three styles. | [fortification.js](examples/fortification.js) |
|
|
41
|
+
| [Harbour of ships](https://enestaylan.github.io/roamwright/examples/ships.html?seed=42) | Every preset of the ship kit moored stern-on to a stone harbour quay while a cog and rowing boat tack offshore. | [ships.js](examples/ships.js) |
|
|
42
|
+
| [Alpine viaduct](https://enestaylan.github.io/roamwright/examples/viaduct.html?seed=42) | Watch an electric train cross eight stone arches above a forested alpine river from valley, trackside or riverbank. | [viaduct.js](examples/viaduct.js) |
|
|
43
|
+
| [Crowds and herds](https://enestaylan.github.io/roamwright/examples/crowds.html?seed=17) | Instanced market crowd, patrolling camp walkers, street dogs, grazing cattle and poultry with crowd alarms. | [crowds.js](examples/crowds.js) |
|
|
44
|
+
| [Animal kit](https://enestaylan.github.io/roamwright/examples/animals.html?seed=42) | Horses, cattle, sheep, a pack camel, dogs and a cat animated on procedural quadruped skeletons in a fenced paddock. | [animals.js](examples/animals.js) |
|
|
45
|
+
| [Figure motion](https://enestaylan.github.io/roamwright/examples/figure-motion.html?seed=11) | Full-body procedural locomotion on uneven ground: walk, run, sit, bow, draw and sheathe a blade, and mount a horse. | [figure-motion.js](examples/figure-motion.js) |
|
|
46
|
+
| [Fliers](https://enestaylan.github.io/roamwright/examples/fliers.html?seed=7) | Moths around a lantern, animated and perched corvids on a crag, wheeling bird flocks and four-winged gliders aloft. | [fliers.js](examples/fliers.js) |
|
|
47
|
+
| [Rooms](https://enestaylan.github.io/roamwright/examples/rooms.html?seed=42) | A furnished beamed room and a domed arcaded hall with baked window, lamp and hearth light by day or night. | [rooms.js](examples/rooms.js) |
|
|
48
|
+
| [House kit](https://enestaylan.github.io/roamwright/examples/house-kit.html?seed=42) | Every built-in architectural form — gable, hip, flat, tower, round, dome and courtyard — arranged round a town square. | [house-kit.js](examples/house-kit.js) |
|
|
49
|
+
| [Props and plants](https://enestaylan.github.io/roamwright/examples/props-and-plants.html?seed=42) | Camp, market, farm and road props beside every tree, shrub, grass tussock and waterside reed in the plant kit. | [props-and-plants.js](examples/props-and-plants.js) |
|
|
50
|
+
| [Effects by day and night](https://enestaylan.github.io/roamwright/examples/effects.html?seed=3) | Budgeted campfires and light pools, drifting smoke shadows, hollow mist and particle bursts that scorch the ground. | [effects.js](examples/effects.js) |
|
|
51
|
+
| [Soundscape](https://enestaylan.github.io/roamwright/examples/soundscape.html?seed=42) | Synthesised spatial audio and surface-aware stride foley across a lakeside shore of water, mud, sand, stone and earth. | [soundscape.js](examples/soundscape.js) |
|
|
52
|
+
| [Figures](https://enestaylan.github.io/roamwright/examples/figure.html?seed=7) | Sculpted procedural characters from plain look specs — faces, hair, clothing, cloaks and custom weapons, near and far. | [figure.js](examples/figure.js) |
|
|
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
|
+
| [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
|
+
| [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) |
|
|
56
57
|
|
|
57
58
|
### Run locally
|
|
58
59
|
|
|
@@ -0,0 +1,52 @@
|
|
|
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>Town fittings · 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 walled courtyard garden beside a stone harbour with breakwater moles, moored warships, street lamps and a distant desert storm wall"
|
|
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/town-fittings.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 town fittings with this seed" aria-label="Rebuild town fittings with this seed">→</button>
|
|
33
|
+
</form>
|
|
34
|
+
</div>
|
|
35
|
+
</header>
|
|
36
|
+
<footer>
|
|
37
|
+
<div class="caption">
|
|
38
|
+
<h1>Town fittings</h1>
|
|
39
|
+
<p>Walled courtyard gardens with instanced shrubs, harbour works and breakwater moles, street lamps and a desert storm wall.</p>
|
|
40
|
+
</div>
|
|
41
|
+
<div class="tools">
|
|
42
|
+
<div class="views" role="group" aria-label="Camera viewpoint">
|
|
43
|
+
<button type="button" data-view="garden" aria-pressed="true">Garden</button>
|
|
44
|
+
<button type="button" data-view="harbour" aria-pressed="false">Harbour</button>
|
|
45
|
+
<button type="button" data-view="storm" aria-pressed="false">Storm wall</button>
|
|
46
|
+
</div>
|
|
47
|
+
<button type="button" class="action" id="hour" aria-pressed="false">Night</button>
|
|
48
|
+
</div>
|
|
49
|
+
</footer>
|
|
50
|
+
<script type="module" src="./town-fittings.js"></script>
|
|
51
|
+
</body>
|
|
52
|
+
</html>
|
|
@@ -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);
|