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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedural multi-lobe garden plant shapes (shrubs, clipped hedges, field crops and blossom clusters) built from
|
|
3
|
+
* displaced foliage blobs with vertex ambient shading and leaf flags. Worker-safe.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as THREE from 'three';
|
|
8
|
+
import { createNoise } from '../math/noise.js';
|
|
9
|
+
import { createHash } from '../math/random.js';
|
|
10
|
+
import { addShape, partsGeometry, shapeParts } from './foliage.js';
|
|
11
|
+
import { createPlantTints } from './plant-tints.js';
|
|
12
|
+
|
|
13
|
+
const BLOSSOMS = 6;
|
|
14
|
+
const DEFAULT_LOBE_DETAIL = 1; // icosahedron subdivided once: 80 triangles per lobe
|
|
15
|
+
const DEFAULT_BASE_COLOR = 0xffffff; // shaded in white so per-instance colours tint each plant
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Default unit-plant lobe tables standing on `y = 0`: each entry is `[x, y, z, width, height, depth]` in local metres.
|
|
19
|
+
*/
|
|
20
|
+
export const GARDEN_PLANT_LOBES = {
|
|
21
|
+
shrub: [
|
|
22
|
+
[0, 0.42, 0, 0.95, 0.82, 0.95],
|
|
23
|
+
[0.24, 0.3, 0.12, 0.62, 0.56, 0.6],
|
|
24
|
+
[-0.2, 0.3, -0.16, 0.64, 0.52, 0.6],
|
|
25
|
+
],
|
|
26
|
+
hedge: [
|
|
27
|
+
// Clipped hedge unit 1 m along z: two lobes across and three along so border segments merge cleanly.
|
|
28
|
+
...[-0.17, 0.17].flatMap(x => [-0.33, 0, 0.33].map(z => [x, 0.33, z, 0.52, 0.74, 0.56])),
|
|
29
|
+
],
|
|
30
|
+
crop: [
|
|
31
|
+
// Lighter two-lobe row-crop tuft for dense fields.
|
|
32
|
+
[0, 0.34, 0, 0.92, 0.7, 0.92],
|
|
33
|
+
[0.16, 0.24, -0.12, 0.6, 0.5, 0.6],
|
|
34
|
+
],
|
|
35
|
+
bloom: [
|
|
36
|
+
// Blossom clusters emerging from the top of a flowering shrub.
|
|
37
|
+
...Array.from({ length: BLOSSOMS }, (_, i) => {
|
|
38
|
+
const a = i * 2.4;
|
|
39
|
+
const r = 0.08 + 0.34 * Math.sqrt((i + 0.5) / BLOSSOMS);
|
|
40
|
+
return [Math.cos(a) * r, 0.86 - r * 0.62, Math.sin(a) * r, 0.3, 0.2, 0.3];
|
|
41
|
+
}),
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Creates a cached geometry factory for multi-lobe garden plants (`shrub`, `hedge`, `crop`, `bloom`, or custom kinds).
|
|
47
|
+
* @param {object} [options] - Plant tint helpers and lobe overrides.
|
|
48
|
+
* @param {(seed: number, detail?: number) => THREE.BufferGeometry} [options.crownBlob] - Displaced crown lump helper (`createPlantTints().crownBlob`).
|
|
49
|
+
* @param {(hex: number) => (x: number, y: number, z: number, out: number[]) => void} [options.crownTint] - Foliage vertex tint helper (`createPlantTints().crownTint`).
|
|
50
|
+
* @param {Record<string, number[][]>} [options.lobes] - Map of plant kind name to `[x, y, z, w, h, d]` lobe lists.
|
|
51
|
+
* @param {number} [options.detail=1] - Icosahedron subdivision detail per lobe.
|
|
52
|
+
* @param {number} [options.color=0xffffff] - Base sRGB hex colour before per-instance tinting.
|
|
53
|
+
* @returns {{
|
|
54
|
+
* plantShape: (kind: string) => THREE.BufferGeometry,
|
|
55
|
+
* geometries: WeakSet<THREE.BufferGeometry>,
|
|
56
|
+
* }} Cached geometry accessor and shared-geometry membership set.
|
|
57
|
+
*/
|
|
58
|
+
export function createGardenPlantShapes(options = {}) {
|
|
59
|
+
let tintsFallback = null;
|
|
60
|
+
const getTints = () => {
|
|
61
|
+
if (!tintsFallback) {
|
|
62
|
+
const { fbm, vnoise } = createNoise(0);
|
|
63
|
+
tintsFallback = createPlantTints({ fbm, vnoise, hash: createHash(0) });
|
|
64
|
+
}
|
|
65
|
+
return tintsFallback;
|
|
66
|
+
};
|
|
67
|
+
const crownBlob = options.crownBlob ?? getTints().crownBlob;
|
|
68
|
+
const crownTint = options.crownTint ?? getTints().crownTint;
|
|
69
|
+
const lobes = options.lobes ?? GARDEN_PLANT_LOBES;
|
|
70
|
+
const detail = options.detail ?? DEFAULT_LOBE_DETAIL;
|
|
71
|
+
const baseColor = options.color ?? DEFAULT_BASE_COLOR;
|
|
72
|
+
|
|
73
|
+
const shapes = {};
|
|
74
|
+
const geometries = new WeakSet();
|
|
75
|
+
|
|
76
|
+
function plantShape(kind) {
|
|
77
|
+
if (shapes[kind]) return shapes[kind];
|
|
78
|
+
const spec = lobes[kind];
|
|
79
|
+
if (!spec) throw new Error(`Unknown garden plant shape: ${kind}`);
|
|
80
|
+
const parts = shapeParts();
|
|
81
|
+
const m = new THREE.Matrix4();
|
|
82
|
+
spec.forEach(([x, y, z, w, h, d], i) => {
|
|
83
|
+
m.makeScale(w, h, d).setPosition(x, y, z);
|
|
84
|
+
addShape(parts, crownBlob(i * 3.7 + kind.length, detail), m, crownTint(baseColor), 1);
|
|
85
|
+
});
|
|
86
|
+
const geometry = partsGeometry(parts);
|
|
87
|
+
geometries.add(geometry);
|
|
88
|
+
return (shapes[kind] = geometry);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return { plantShape, geometries };
|
|
92
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure typed-array geometry builder for a curved multi-layer storm curtain wall (sandstorm, blizzard, or ash wall):
|
|
3
|
+
* concentric vertical strips following a circular arc with ground-conforming footings, scrolling UVs, and per-vertex
|
|
4
|
+
* arc-end and layer-depth attributes. Worker-safe and free of Three.js.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Default subdivision and layout constants for a layered storm wall mesh. */
|
|
9
|
+
export const STORM_WALL_DEFAULTS = {
|
|
10
|
+
layers: 5,
|
|
11
|
+
along: 150,
|
|
12
|
+
up: 10,
|
|
13
|
+
footSink: 8,
|
|
14
|
+
uvScale: 210,
|
|
15
|
+
layerUvOffset: 0.37,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generates vertex attribute and index typed arrays for a concentric multi-curtain storm wall arc.
|
|
20
|
+
* @param {object} options
|
|
21
|
+
* @param {number} [options.x=0] - Arc centre world X coordinate in metres.
|
|
22
|
+
* @param {number} [options.z=0] - Arc centre world Z coordinate in metres.
|
|
23
|
+
* @param {number} [options.radius=1200] - Mean arc radius in metres.
|
|
24
|
+
* @param {number} [options.sweep=1.5] - Half-angle of the arc on each side of `+x` in radians.
|
|
25
|
+
* @param {number} [options.width=150] - Radial thickness spanned across all curtain layers in metres.
|
|
26
|
+
* @param {number} [options.height=300] - Curtain wall height in metres.
|
|
27
|
+
* @param {(x: number, z: number) => number} [options.ground] - Ground height sampler `(x, z) => y` in metres (defaults to 0).
|
|
28
|
+
* @param {number} [options.layers=5] - Number of concentric curtain sheets.
|
|
29
|
+
* @param {number} [options.along=150] - Horizontal segments along the arc.
|
|
30
|
+
* @param {number} [options.up=10] - Vertical segments from foot to crest.
|
|
31
|
+
* @param {number} [options.footSink=8] - Metres the bottom edge sinks below ground so slopes never expose a gap.
|
|
32
|
+
* @param {number} [options.uvScale=210] - Arc-length metres per U repeat.
|
|
33
|
+
* @param {number} [options.layerUvOffset=0.37] - U phase shift per curtain layer so layers never align.
|
|
34
|
+
* @returns {{ position: Float32Array, uv: Float32Array, aEdge: Float32Array, index: Uint16Array | Uint32Array }} Typed mesh arrays.
|
|
35
|
+
*/
|
|
36
|
+
export function stormWallArrays({
|
|
37
|
+
x: cx = 0,
|
|
38
|
+
z: cz = 0,
|
|
39
|
+
radius = 1200,
|
|
40
|
+
sweep = 1.5,
|
|
41
|
+
width = 150,
|
|
42
|
+
height = 300,
|
|
43
|
+
ground = () => 0,
|
|
44
|
+
layers = STORM_WALL_DEFAULTS.layers,
|
|
45
|
+
along = STORM_WALL_DEFAULTS.along,
|
|
46
|
+
up = STORM_WALL_DEFAULTS.up,
|
|
47
|
+
footSink = STORM_WALL_DEFAULTS.footSink,
|
|
48
|
+
uvScale = STORM_WALL_DEFAULTS.uvScale,
|
|
49
|
+
layerUvOffset = STORM_WALL_DEFAULTS.layerUvOffset,
|
|
50
|
+
} = {}) {
|
|
51
|
+
const row = up + 1;
|
|
52
|
+
const vertsPerLayer = (along + 1) * row;
|
|
53
|
+
const totalVerts = layers * vertsPerLayer;
|
|
54
|
+
const position = new Float32Array(totalVerts * 3);
|
|
55
|
+
const uv = new Float32Array(totalVerts * 2);
|
|
56
|
+
const aEdge = new Float32Array(totalVerts * 2);
|
|
57
|
+
const index = totalVerts > 65535 ? new Uint32Array(layers * along * up * 6) : new Uint16Array(layers * along * up * 6);
|
|
58
|
+
const layerSpan = layers > 1 ? layers - 1 : 1;
|
|
59
|
+
|
|
60
|
+
let p = 0;
|
|
61
|
+
let u = 0;
|
|
62
|
+
let e = 0;
|
|
63
|
+
let idx = 0;
|
|
64
|
+
for (let layer = 0; layer < layers; layer++) {
|
|
65
|
+
const r = radius + (layers > 1 ? layer / layerSpan - 0.5 : 0) * width;
|
|
66
|
+
const base = layer * vertsPerLayer;
|
|
67
|
+
const layerShare = layers > 1 ? layer / layerSpan : 0.5;
|
|
68
|
+
for (let i = 0; i <= along; i++) {
|
|
69
|
+
const t = i / along;
|
|
70
|
+
const a = (t * 2 - 1) * sweep;
|
|
71
|
+
const x = cx + Math.cos(a) * r;
|
|
72
|
+
const z = cz + Math.sin(a) * r;
|
|
73
|
+
const foot = Math.max(ground(x, z), 0) - footSink;
|
|
74
|
+
const stU = (a * r) / uvScale + layer * layerUvOffset;
|
|
75
|
+
const edgeT = Math.min(t, 1 - t);
|
|
76
|
+
for (let j = 0; j <= up; j++) {
|
|
77
|
+
const v = j / up;
|
|
78
|
+
position[p++] = x;
|
|
79
|
+
position[p++] = foot + v * height;
|
|
80
|
+
position[p++] = z;
|
|
81
|
+
uv[u++] = stU;
|
|
82
|
+
uv[u++] = v;
|
|
83
|
+
aEdge[e++] = edgeT;
|
|
84
|
+
aEdge[e++] = layerShare;
|
|
85
|
+
if (i && j) {
|
|
86
|
+
const k = base + i * row + j;
|
|
87
|
+
index[idx++] = k - row - 1;
|
|
88
|
+
index[idx++] = k - row;
|
|
89
|
+
index[idx++] = k;
|
|
90
|
+
index[idx++] = k - row - 1;
|
|
91
|
+
index[idx++] = k;
|
|
92
|
+
index[idx++] = k - 1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return { position, uv, aEdge, index };
|
|
98
|
+
}
|