@margoengine/scenes 0.1.0 → 1.0.0

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.
Files changed (38) hide show
  1. package/LICENSE +201 -201
  2. package/NOTICE +4 -4
  3. package/README.md +620 -387
  4. package/dist/{dune-coast-info-e8eDZXBu.js → dune-coast-info-D9yQIv8G.js} +13 -3
  5. package/dist/dune-coast.d.ts +20 -1
  6. package/dist/dune-coast.js +374 -187
  7. package/dist/errors-fc4i1pSL.js +7 -0
  8. package/dist/fauld-blast.d.ts +119 -21
  9. package/dist/fauld-blast.js +957 -206
  10. package/dist/fauld-countryside.d.ts +1 -1
  11. package/dist/fauld-countryside.js +4 -4
  12. package/dist/fauld-crater.d.ts +1 -1
  13. package/dist/fauld-crater.js +4 -4
  14. package/dist/fauld-dig.d.ts +89 -0
  15. package/dist/fauld-dustfall-fines-grid-MA6XPrq6.js +14 -0
  16. package/dist/fauld-dustfall-fines-grid.d.ts +11 -0
  17. package/dist/fauld-dustfall-grid-Bb4X8b-u.js +14 -0
  18. package/dist/fauld-dustfall-grid.d.ts +11 -0
  19. package/dist/fauld-explosion.d.ts +135 -0
  20. package/dist/fauld-grains.d.ts +27 -0
  21. package/dist/fauld-mud.d.ts +104 -0
  22. package/dist/fauld-surge.d.ts +71 -0
  23. package/dist/fauld-tunnels.d.ts +76 -3
  24. package/dist/fauld-tunnels.js +518 -193
  25. package/dist/fauld-world-CNNSonJF.js +863 -0
  26. package/dist/fauld-world.d.ts +86 -3
  27. package/dist/index.js +2 -2
  28. package/dist/{library-mesh-BRk4Ycnn.js → library-mesh-CjTG-mVZ.js} +97 -74
  29. package/dist/library-parts.d.ts +11 -1
  30. package/dist/library.js +1 -1
  31. package/dist/look-family.d.ts +16 -1
  32. package/dist/look-family.js +35 -12
  33. package/dist/shared/settings.d.ts +89 -89
  34. package/dist/{timber-valley-info-BB6GvcsL.js → timber-valley-info-vVI2nwDs.js} +11 -0
  35. package/dist/timber-valley.d.ts +69 -3
  36. package/dist/timber-valley.js +198 -136
  37. package/package.json +106 -104
  38. package/dist/fauld-world-85dg03jo.js +0 -582
@@ -1,6 +1,7 @@
1
1
  /// <reference lib="esnext.disposable" preserve="true" />
2
2
  import type { EngineKernel, Mesh, Vec3 } from '@margoengine/core';
3
3
  import { BiomeWorld } from '@margoengine/biomes';
4
+ import type { Exclusion } from '@margoengine/biomes/placement';
4
5
  import '@margoengine/biomes/splines';
5
6
  import { type Farmland } from '@margoengine/biomes/farmland';
6
7
  import { BiomeView } from '@margoengine/biomes/view';
@@ -26,8 +27,8 @@ export declare const FAULD_PLACES: Readonly<{
26
27
  hanbury: readonly [-1225, -175];
27
28
  church: readonly [-1190, -190];
28
29
  inn: readonly [-1120, -120];
29
- works: readonly [120, -780];
30
- reservoir: readonly [210, -430];
30
+ works: readonly [43, -582];
31
+ reservoir: readonly [-61, -278];
31
32
  dove: readonly [-300, -2600];
32
33
  tutbury: readonly [3100, -1300];
33
34
  }>;
@@ -63,7 +64,7 @@ export declare const FAULD_SLOTS: Readonly<{
63
64
  eras: string[];
64
65
  };
65
66
  kilnWorks: {
66
- at: readonly [120, -780];
67
+ at: readonly [43, -582];
67
68
  turn: number;
68
69
  model: string;
69
70
  eras: string[];
@@ -145,6 +146,8 @@ export interface FauldWorld extends Disposable {
145
146
  settle(): Promise<void>;
146
147
  dispose(): void;
147
148
  }
149
+ /** How fast the winter haze thins with height over the Fauld ground, metres per e-fold (the sky fog's `scaleHeight`). */
150
+ export declare const FAULD_HAZE_SCALE_HEIGHT = 500;
148
151
  /**
149
152
  * The overcast deck of a grey November day, metres above the ground: a stratocumulus sheet, the common winter overcast
150
153
  * over the English Midlands, with its base at 1,000 m and tops at 1,600 m (WMO International Cloud Atlas 2017,
@@ -156,5 +159,85 @@ export declare const FAULD_CLOUD_DECK: Readonly<{
156
159
  bottom: 1000;
157
160
  top: 1600;
158
161
  }>;
162
+ /**
163
+ * The hedge shrubs and trees by plant mesh name (`library:<key>`): their model files under `margo-library/fauld/`,
164
+ * without `.gltf`.
165
+ */
166
+ export declare const FAULD_PLANT_MODELS: Readonly<Record<string, string>>;
167
+ /** Ground scans (Poly Haven, CC0) under `margo-library/fauld/ground/`, the repeat in metres and the winter colour. */
168
+ /**
169
+ * November ground at field capacity (English soils return to it in autumn and hold it to spring) keeps 0.62 of its dry
170
+ * albedo: wet grains lose albedo by internal reflection in the water film (Lekner and Dorf 1988; Twomey, Bohren and
171
+ * Mergenthaler 1986), most of the drop coming with the first moisture (Lobell and Asner 2002): the terrain's share
172
+ * (1 - e^-3m) / (1 - e^-3) of its 0.6 at saturation, at m = 0.75.
173
+ */
174
+ export declare const FAULD_WET_SOIL: number;
175
+ /** The earth a blast throws over the fields, linear RGB: the Mercia Mudstone's reddish soil (red sand), wet. */
176
+ export declare const FAULD_THROWN_SOIL: readonly [number, number, number];
177
+ /**
178
+ * The fields' looks: each scan's mean brought to a measured albedo (@margoengine/materials' ECOSTRESS surfaces, linear
179
+ * RGB): the pasture green grass, the stubble dry grass, the rough meadow half each (a model choice: its share of dead
180
+ * stems was not measured), the plough and the mud the reddish soil of the Mercia Mudstone (red sand) wetted to
181
+ * FAULD_WET_SOIL. They were set by eye at about twice the measured albedo, so the ground at eye height read pale.
182
+ */
183
+ export declare const FAULD_GROUND_LOOKS: Readonly<Record<string, {
184
+ file: string;
185
+ repeat: number;
186
+ color: readonly [number, number, number];
187
+ bump?: number;
188
+ }>>;
189
+ /** The size and corner of a height grid, as the `.json` beside it says. */
190
+ export interface FauldDemMeta {
191
+ readonly width: number;
192
+ readonly depth: number;
193
+ readonly cellsize_m: number;
194
+ readonly xll_easting: number;
195
+ readonly ytop_northing: number;
196
+ }
197
+ /**
198
+ * The OS Terrain 50 grid (float32 metres, row 0 the northmost) as the height at OS (easting, northing), bilinear between
199
+ * sample centres.
200
+ * @throws RangeError for a grid whose length is not width x depth.
201
+ * @example
202
+ * const meta = await (await fetch('/dem/fauld.json')).json();
203
+ * const dem = fauldDem(meta, new Float32Array(await (await fetch('/dem/fauld.f32')).arrayBuffer()));
204
+ * const metres = dem(FAULD_CENTRE.easting, FAULD_CENTRE.northing);
205
+ */
206
+ export declare function fauldDem(meta: FauldDemMeta, data: Float32Array): (easting: number, northing: number) => number;
207
+ /** What {@link layFauldGround} builds from. */
208
+ export interface FauldGroundOptions {
209
+ /** Default `'before'`. */
210
+ readonly era?: FauldEra;
211
+ /** Default 1944. */
212
+ readonly seed?: number;
213
+ /** Height at OS (easting, northing): {@link fauldDem} of the OS Terrain 50 grid. */
214
+ readonly dem: (easting: number, northing: number) => number;
215
+ /** The era's crater model, of which only the heights are read. Default none (the ground before 1944). */
216
+ readonly crater?: {
217
+ readonly geometry: {
218
+ readonly positions: ArrayLike<number>;
219
+ };
220
+ };
221
+ readonly signal?: AbortSignal;
222
+ }
223
+ /** The place without an engine: its biome world, farm, planting exclusions and ground height. */
224
+ export interface FauldGround extends Disposable {
225
+ readonly world: BiomeWorld;
226
+ readonly farm: Farmland;
227
+ /** Where nothing is planted: what the view and `BiomePlacement` take, so both place the same trees and hedges. */
228
+ readonly exclusions: readonly Exclusion[];
229
+ height(x: number, z: number): number;
230
+ dispose(): void;
231
+ }
232
+ /**
233
+ * The ground of {@link attachFauldWorld} on the CPU alone, for tools that must know where the hills, hedges and trees
234
+ * stand without rendering them (such as keeping shot cameras clear with `@margoengine/cameras/clearance`).
235
+ * @throws RangeError for an unknown era; rejects with the signal's reason when aborted.
236
+ * @example
237
+ * using ground = await layFauldGround({ dem, era: 'before' });
238
+ * const placement = BiomePlacement.attach(ground.world, { exclusions: ground.exclusions });
239
+ * const trees = await placement.tile(12, 12);
240
+ */
241
+ export declare function layFauldGround(options: FauldGroundOptions): Promise<FauldGround>;
159
242
  /** Builds the shared Fauld ground, farmland, sky and weather into `engine`. */
160
243
  export declare function attachFauldWorld(engine: EngineKernel, settings?: FauldWorldSettings): Promise<FauldWorld>;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { t as e } from "./dune-coast-info-e8eDZXBu.js";
2
- import { t } from "./timber-valley-info-BB6GvcsL.js";
1
+ import { t as e } from "./dune-coast-info-D9yQIv8G.js";
2
+ import { t } from "./timber-valley-info-vVI2nwDs.js";
3
3
  import { n } from "./fauld-tunnels-info-8qv9X4OJ.js";
4
4
  //#region src/fauld-world-info.ts
5
5
  var r = {
@@ -1,11 +1,10 @@
1
- //#region ../shared/errors.js
2
- var e = (e, t) => Object.assign(Error(t), {
3
- name: "MargoError",
4
- code: e
5
- }), t = /twig|leaf|leaves|needle|foliage|frond/i;
1
+ import { t as e } from "./errors-fc4i1pSL.js";
2
+ //#region src/library-parts.ts
3
+ var t = /twig|leaf|leaves|needle|foliage|frond/i;
6
4
  async function n(o, s = {}) {
7
5
  if (typeof o != "string") {
8
6
  if (!Array.isArray(o) || o.length !== 3) throw TypeError("libraryParts takes one URL or three; pass a string or [near, middle, far]");
7
+ if (s.foliageTriangles) throw TypeError("libraryParts foliageTriangles makes the levels from one model; pass one URL, not three");
9
8
  let e = await Promise.all(o.map((e) => n(e, s)));
10
9
  return e[0].map((t) => {
11
10
  let n = e.map((e) => e.find((e) => e.name === t.name));
@@ -29,53 +28,55 @@ async function n(o, s = {}) {
29
28
  };
30
29
  });
31
30
  }
32
- let c = s.fetch ?? globalThis.fetch, l = s.signal ? { signal: s.signal } : {}, u = await c(o, l);
33
- if (!u.ok) throw e("failed", `libraryParts: ${o} answered ${u.status}; check the URL and that the server serves the file`);
34
- let d = await u.json(), f = o.slice(0, o.lastIndexOf("/") + 1);
35
- if (!d.meshes?.length || !d.accessors || !d.bufferViews || !d.buffers || !d.nodes) throw TypeError(`libraryParts: ${o} holds no meshes; pass a .gltf with meshes, nodes and buffers`);
36
- let p = async (t) => {
31
+ let c = s.foliageTriangles;
32
+ if (c !== void 0 && (!Array.isArray(c) || c.length !== 3)) throw TypeError("libraryParts foliageTriangles must hold three triangle budgets: [near, middle, far]");
33
+ let l = s.fetch ?? globalThis.fetch, u = s.signal ? { signal: s.signal } : {}, d = await l(o, u);
34
+ if (!d.ok) throw e("failed", `libraryParts: ${o} answered ${d.status}; check the URL and that the server serves the file`);
35
+ let f = await d.json(), p = o.slice(0, o.lastIndexOf("/") + 1);
36
+ if (!f.meshes?.length || !f.accessors || !f.bufferViews || !f.buffers || !f.nodes) throw TypeError(`libraryParts: ${o} holds no meshes; pass a .gltf with meshes, nodes and buffers`);
37
+ let m = async (t) => {
37
38
  if (t.startsWith("data:")) throw TypeError("libraryParts reads a .gltf with external buffers and images; export the model as glTF separate");
38
- let n = await c(f + t, l);
39
- if (!n.ok) throw e("failed", `libraryParts: ${f + t} answered ${n.status}; check that the file sits beside the .gltf`);
39
+ let n = await l(p + t, u);
40
+ if (!n.ok) throw e("failed", `libraryParts: ${p + t} answered ${n.status}; check that the file sits beside the .gltf`);
40
41
  return n.arrayBuffer();
41
- }, m = await Promise.all(d.buffers.map((e) => p(e.uri ?? "data:"))), h = (e, t, n) => {
42
- let r = d.accessors[e], i = r ? d.bufferViews[r.bufferView ?? -1] : void 0, o = r ? a[r.componentType] : void 0;
42
+ }, h = await Promise.all(f.buffers.map((e) => m(e.uri ?? "data:"))), g = (e, t, n) => {
43
+ let r = f.accessors[e], i = r ? f.bufferViews[r.bufferView ?? -1] : void 0, o = r ? a[r.componentType] : void 0;
43
44
  if (!r || !i) throw TypeError("libraryParts: an accessor without a buffer view; use a model whose accessors all have buffer views");
44
45
  if (!o || n === (r.componentType === 5126)) throw TypeError(`libraryParts: unsupported accessor component type ${r.componentType}; use float vertices and uvs and integer indices`);
45
- let [s, c] = o, l = i.byteStride ?? s * t, u = new DataView(m[i.buffer], (i.byteOffset ?? 0) + (r.byteOffset ?? 0)), f = n ? new Uint32Array(r.count * t) : new Float32Array(r.count * t);
46
- for (let e = 0; e < r.count; e++) for (let n = 0; n < t; n++) f[e * t + n] = c(u, e * l + n * s);
47
- return f;
48
- }, g = /* @__PURE__ */ new Map(), _ = (e, t) => {
49
- let n = d.nodes[e], a = i(t, r(n));
50
- if (n.mesh !== void 0) for (let e of d.meshes[n.mesh].primitives) {
46
+ let [s, c] = o, l = i.byteStride ?? s * t, u = new DataView(h[i.buffer], (i.byteOffset ?? 0) + (r.byteOffset ?? 0)), d = n ? new Uint32Array(r.count * t) : new Float32Array(r.count * t);
47
+ for (let e = 0; e < r.count; e++) for (let n = 0; n < t; n++) d[e * t + n] = c(u, e * l + n * s);
48
+ return d;
49
+ }, _ = /* @__PURE__ */ new Map(), v = (e, t, n) => {
50
+ let a = f.nodes[e], o = i(t, r(a)), c = n || a.name === s.node;
51
+ if (c && a.mesh !== void 0) for (let e of f.meshes[a.mesh].primitives) {
51
52
  let t = e.attributes;
52
53
  if ((e.mode ?? 4) !== 4 || t.POSITION === void 0 || t.NORMAL === void 0 || t.TEXCOORD_0 === void 0) continue;
53
- let n = e.material ?? -1, r = g.get(n) ?? {
54
+ let n = e.material ?? -1, r = _.get(n) ?? {
54
55
  positions: [],
55
56
  normals: [],
56
57
  uvs: [],
57
58
  indices: []
58
- }, i = h(t.POSITION, 3, !1), o = h(t.NORMAL, 3, !1), s = h(t.TEXCOORD_0, 2, !1), c = r.positions.length / 3, l = i.length / 3;
59
- g.set(n, r);
59
+ }, i = g(t.POSITION, 3, !1), a = g(t.NORMAL, 3, !1), s = g(t.TEXCOORD_0, 2, !1), c = r.positions.length / 3, l = i.length / 3;
60
+ _.set(n, r);
60
61
  for (let e = 0; e < l; e++) {
61
62
  let [t, n, c] = [
62
63
  i[e * 3],
63
64
  i[e * 3 + 1],
64
65
  i[e * 3 + 2]
65
66
  ], [l, u, d] = [
66
- o[e * 3],
67
- o[e * 3 + 1],
68
- o[e * 3 + 2]
67
+ a[e * 3],
68
+ a[e * 3 + 1],
69
+ a[e * 3 + 2]
69
70
  ];
70
- r.positions.push(a[0] * t + a[4] * n + a[8] * c + a[12], a[1] * t + a[5] * n + a[9] * c + a[13], a[2] * t + a[6] * n + a[10] * c + a[14]);
71
- let f = a[0] * l + a[4] * u + a[8] * d, p = a[1] * l + a[5] * u + a[9] * d, m = a[2] * l + a[6] * u + a[10] * d, h = Math.hypot(f, p, m) || 1;
71
+ r.positions.push(o[0] * t + o[4] * n + o[8] * c + o[12], o[1] * t + o[5] * n + o[9] * c + o[13], o[2] * t + o[6] * n + o[10] * c + o[14]);
72
+ let f = o[0] * l + o[4] * u + o[8] * d, p = o[1] * l + o[5] * u + o[9] * d, m = o[2] * l + o[6] * u + o[10] * d, h = Math.hypot(f, p, m) || 1;
72
73
  r.normals.push(f / h, p / h, m / h), r.uvs.push(s[e * 2], s[e * 2 + 1]);
73
74
  }
74
- let u = e.indices === void 0 ? Uint32Array.from({ length: l }, (e, t) => t) : h(e.indices, 1, !0);
75
+ let u = e.indices === void 0 ? Uint32Array.from({ length: l }, (e, t) => t) : g(e.indices, 1, !0);
75
76
  for (let e of u) r.indices.push(c + e);
76
77
  }
77
- for (let e of n.children ?? []) _(e, a);
78
- }, v = [
78
+ for (let e of a.children ?? []) v(e, o, c);
79
+ }, y = [
79
80
  1,
80
81
  0,
81
82
  0,
@@ -93,67 +94,89 @@ async function n(o, s = {}) {
93
94
  0,
94
95
  1
95
96
  ];
96
- for (let e of d.scenes?.[d.scene ?? 0]?.nodes ?? d.nodes.map((e, t) => t)) _(e, v);
97
- if (!g.size) throw TypeError(`libraryParts: ${o} holds no triangles with positions, normals and uvs; export the model with normals and TEXCOORD_0`);
98
- let y = Infinity, b = Infinity, x = -Infinity, S = Infinity, C = -Infinity;
99
- for (let e of g.values()) for (let t = 0; t < e.positions.length; t += 3) y = Math.min(y, e.positions[t + 1]), b = Math.min(b, e.positions[t]), x = Math.max(x, e.positions[t]), S = Math.min(S, e.positions[t + 2]), C = Math.max(C, e.positions[t + 2]);
100
- let w = s.scale ?? 1, T = (b + x) / 2, E = (S + C) / 2, D = s.maxTriangles ?? 12e4, O = s.foliage ?? ((e) => t.test(e)), k = s.decode ?? (async (e, t) => createImageBitmap(new Blob([e], { type: t }), {
97
+ for (let e of f.scenes?.[f.scene ?? 0]?.nodes ?? f.nodes.map((e, t) => t)) v(e, y, s.node === void 0);
98
+ if (!_.size) throw TypeError(s.node === void 0 ? `libraryParts: ${o} holds no triangles with positions, normals and uvs; export the model with normals and TEXCOORD_0` : `libraryParts: ${o} has no node named ${s.node} with textured triangles; pass the name of a node in the file`);
99
+ let b = Infinity, x = Infinity, S = -Infinity, C = Infinity, w = -Infinity;
100
+ for (let e of _.values()) for (let t = 0; t < e.positions.length; t += 3) b = Math.min(b, e.positions[t + 1]), x = Math.min(x, e.positions[t]), S = Math.max(S, e.positions[t]), C = Math.min(C, e.positions[t + 2]), w = Math.max(w, e.positions[t + 2]);
101
+ let T = s.scale ?? 1, E = (x + S) / 2, D = (C + w) / 2, O = s.maxTriangles ?? 12e4, k = s.foliage ?? ((e) => t.test(e)), A = s.decode ?? (async (e, t) => createImageBitmap(new Blob([e], { type: t }), {
101
102
  colorSpaceConversion: "none",
102
103
  premultiplyAlpha: "none"
103
- })), A = /* @__PURE__ */ new Map(), j = (e) => {
104
- let t = e === void 0 ? void 0 : d.textures?.[e.index]?.source;
104
+ })), j = /* @__PURE__ */ new Map(), M = (e) => {
105
+ let t = e === void 0 ? void 0 : f.textures?.[e.index]?.source;
105
106
  if (t === void 0) return;
106
- let n = d.images?.[t];
107
+ let n = f.images?.[t];
107
108
  if (!n?.uri) throw TypeError("libraryParts reads images by uri; export the model as glTF separate");
108
- return A.has(t) || A.set(t, p(n.uri).then((e) => k(e, n.mimeType ?? (n.uri.endsWith(".png") ? "image/png" : "image/jpeg")))), A.get(t);
109
- }, M = [];
110
- for (let [e, t] of g) {
111
- let n = t.indices.length / 3;
112
- if (n > D) throw RangeError(`libraryParts: ${o} has ${n} triangles in one part, over maxTriangles ${D}; export a lighter level of it`);
113
- let r = d.materials?.[e] ?? {}, i = r.pbrMetallicRoughness ?? {}, a = r.name ?? `material ${e}`, c = new Float32Array(t.positions.length);
114
- for (let e = 0; e < c.length; e += 3) c[e] = (t.positions[e] - T) * w, c[e + 1] = (t.positions[e + 1] - y) * w, c[e + 2] = (t.positions[e + 2] - E) * w;
115
- let l = i.baseColorTexture?.extensions?.KHR_texture_transform, [u, f] = l?.offset ?? [0, 0], [p, m] = l?.scale ?? [1, 1], h = Math.cos(l?.rotation ?? 0), g = Math.sin(l?.rotation ?? 0), _ = new Float32Array(t.uvs.length);
116
- for (let e = 0; e < _.length; e += 2) {
117
- let n = t.uvs[e] * p, r = t.uvs[e + 1] * m;
118
- _[e] = h * n + g * r + u, _[e + 1] = -g * n + h * r + f;
109
+ return j.has(t) || j.set(t, m(n.uri).then((e) => A(e, n.mimeType ?? (n.uri.endsWith(".png") ? "image/png" : "image/jpeg")))), j.get(t);
110
+ }, N = c ? (await import("@margoengine/scatter/foliage")).foliageLODs : void 0;
111
+ s.signal?.throwIfAborted();
112
+ let P = [];
113
+ for (let [e, t] of _) {
114
+ let n = t.indices.length / 3, r = f.materials?.[e] ?? {}, i = r.pbrMetallicRoughness ?? {}, a = r.name ?? `material ${e}`, l = r.alphaMode === "MASK" || r.alphaMode === "BLEND", u = l || k(a) ? "foliage" : s.kind ?? "bark", d = u === "foliage" ? N : void 0;
115
+ if (!d && n > O) throw RangeError(`libraryParts: ${o} has ${n} triangles in one part, over maxTriangles ${O}; export a lighter level of it (foliage parts: pass foliageTriangles)`);
116
+ let p = new Float32Array(t.positions.length);
117
+ for (let e = 0; e < p.length; e += 3) p[e] = (t.positions[e] - E) * T, p[e + 1] = (t.positions[e + 1] - b) * T, p[e + 2] = (t.positions[e + 2] - D) * T;
118
+ let m = i.baseColorTexture?.extensions?.KHR_texture_transform, [h, g] = m?.offset ?? [0, 0], [_, v] = m?.scale ?? [1, 1], y = Math.cos(m?.rotation ?? 0), x = Math.sin(m?.rotation ?? 0), S = new Float32Array(t.uvs.length);
119
+ for (let e = 0; e < S.length; e += 2) {
120
+ let n = t.uvs[e] * _, r = t.uvs[e + 1] * v;
121
+ S[e] = y * n + x * r + h, S[e + 1] = -x * n + y * r + g;
122
+ }
123
+ let C = {
124
+ positions: p,
125
+ normals: Float32Array.from(t.normals),
126
+ indices: Uint32Array.from(t.indices)
127
+ }, w = S;
128
+ if (d) {
129
+ let e = d({
130
+ ...C,
131
+ uvs: S
132
+ }, { triangles: c }), [t, n, r] = e.map((e) => ({
133
+ positions: e.positions,
134
+ normals: e.normals,
135
+ indices: e.indices
136
+ }));
137
+ C = [
138
+ t,
139
+ n,
140
+ r
141
+ ], w = [
142
+ e[0].uvs,
143
+ e[1].uvs,
144
+ e[2].uvs
145
+ ];
119
146
  }
120
- let v = r.alphaMode === "MASK" || r.alphaMode === "BLEND", b = i.baseColorFactor ?? [
147
+ let A = i.baseColorFactor ?? [
121
148
  1,
122
149
  1,
123
150
  1,
124
151
  1
125
- ], [x, S, C] = [
126
- j(i.baseColorTexture),
127
- j(r.normalTexture),
128
- j(i.metallicRoughnessTexture)
152
+ ], [j, F, I] = [
153
+ M(i.baseColorTexture),
154
+ M(r.normalTexture),
155
+ M(i.metallicRoughnessTexture)
129
156
  ];
130
- M.push(Promise.all([
131
- x,
132
- S,
133
- C
134
- ]).then(([e, n, i]) => ({
135
- geometry: {
136
- positions: c,
137
- normals: Float32Array.from(t.normals),
138
- indices: Uint32Array.from(t.indices)
139
- },
157
+ P.push(Promise.all([
158
+ j,
159
+ F,
160
+ I
161
+ ]).then(([e, t, n]) => ({
162
+ geometry: C,
140
163
  color: [
141
- b[0],
142
- b[1],
143
- b[2]
164
+ A[0],
165
+ A[1],
166
+ A[2]
144
167
  ],
145
- kind: v || O(a) ? "foliage" : s.kind ?? "bark",
168
+ kind: u,
146
169
  name: a,
147
170
  textures: {
148
- uvs: _,
171
+ uvs: w,
149
172
  ...e ? { baseColor: e } : {},
150
- ...n ? { normal: n } : {},
151
- ...i ? { occlusionRoughnessMetal: i } : {},
152
- alphaCutoff: v && e ? r.alphaCutoff ?? .5 : 0
173
+ ...t ? { normal: t } : {},
174
+ ...n ? { occlusionRoughnessMetal: n } : {},
175
+ alphaCutoff: l && e ? r.alphaCutoff ?? .5 : 0
153
176
  }
154
177
  })));
155
178
  }
156
- return Promise.all(M);
179
+ return Promise.all(P);
157
180
  }
158
181
  //#endregion
159
182
  //#region src/library-mesh.ts
@@ -9,6 +9,15 @@ export interface LibraryPartsOptions extends Omit<LibraryMeshOptions, 'color' |
9
9
  * or a name with twig, leaf, needle, foliage or frond in it.
10
10
  */
11
11
  readonly foliage?: (name: string) => boolean;
12
+ /**
13
+ * Triangles of each foliage part's near, middle and far levels, made from one model with `foliageLODs` of
14
+ * `@margoengine/scatter/foliage`: whole needles or leaves are removed and the rest grow until each level covers what
15
+ * the model covers, where an exported decimation thins the crown. Takes one URL; `maxTriangles` then bounds the
16
+ * other parts only. Default: foliage draws as the file holds it.
17
+ */
18
+ readonly foliageTriangles?: readonly [near: number, middle: number, far: number];
19
+ /** Reads only the node of this name and its children, as one model of a file holding several. Default: the scene. */
20
+ readonly node?: string;
12
21
  /** Decodes an image file. Default `createImageBitmap` on the fetched bytes. */
13
22
  readonly decode?: (bytes: ArrayBuffer, mimeType: string) => Promise<ScatterImage>;
14
23
  }
@@ -35,7 +44,8 @@ export interface LibraryTexturedPart {
35
44
  * metallic-roughness images; the metallic-roughness image is read as occlusion-roughness-metal (R occlusion, the
36
45
  * packing of Poly Haven and most scan libraries). BLEND materials draw as MASK (a scatter has no sorted blending).
37
46
  * Heavy scans need a lighter level first (`maxTriangles`, counted per part). Three URLs (near, middle, far levels of
38
- * one model, such as decimations of a scan) give each part one geometry per LOD ring, matched by material name.
47
+ * one model, such as decimations of a scan) give each part one geometry per LOD ring, matched by material name. With
48
+ * `foliageTriangles` one URL gives each foliage part three levels that keep its crown.
39
49
  * @throws TypeError for a document with no textured triangles; RangeError for a part over `maxTriangles`; Error for a
40
50
  * file that does not load.
41
51
  * @example
package/dist/library.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as e, t } from "./library-mesh-BRk4Ycnn.js";
1
+ import { n as e, t } from "./library-mesh-CjTG-mVZ.js";
2
2
  //#region src/library.ts
3
3
  var n = [
4
4
  "model",
@@ -35,14 +35,29 @@ export interface LookFamilyTargets {
35
35
  materials?: Readonly<Record<string, MaterialLook>>;
36
36
  };
37
37
  }
38
+ type SkyTarget = Parameters<typeof applySkySettings>[0];
39
+ /**
40
+ * Writes a shot's sky rows over the look family `name`: the family's sky values with `rows` on top, through
41
+ * `applySkySettings`, so rows left out keep the family's value (its warm key, saturation and air), not the row default.
42
+ * As in {@link applyLookFamily} the sky keeps the scene's clock and sun unless `rows` name a clock or sun row, the clouds
43
+ * keep the layer the scene placed unless `rows` name it, and the display keeps the scene's exposure unless `rows` give
44
+ * `tonemap.exposure`. Until 2026-11-29 a scene wrote shot rows over the row defaults, so one row moved the sun to the
45
+ * clock's noon and undid the family (KB-SCENES-SHOTROWS1).
46
+ * @throws RangeError for a family not in {@link LOOK_FAMILIES}; whatever `applySkySettings` throws for the rows.
47
+ * @example applyFamilySky('animatedFeature', { sky, clouds, tonemap, grade }, { 'tonemap.curve': 'linear' });
48
+ */
49
+ export declare function applyFamilySky(name: LookFamilyName, target: SkyTarget, rows?: Readonly<Record<string, unknown>>): void;
38
50
  /**
39
51
  * Applies the look family `name` to every part of the scene in `targets`: each part gets that family's entry of its own
40
52
  * package's LOOKS table (`natural` is every row at its default, so the part draws as it does with no settings), through
41
53
  * that package's apply function. A part left out is left alone. The sky keeps the scene's time of day: its clock
42
- * (`hours`, `timeScale`) and sun direction stay as the scene set them, so a family never moves the sun. The weather part writes the family's state onto the
54
+ * (`hours`, `timeScale`) and sun direction stay as the scene set them, so a family never moves the sun, the display keeps
55
+ * the scene's exposure (a family that sets `tonemap.exposure` itself excepted), and the
56
+ * `clouds` keep the layer's `type`, `coverage`, `bottom`, `top` and `density`. The weather part writes the family's state onto the
43
57
  * weather target, so give it only when nothing else (a recorded storm, a drive) owns the weather.
44
58
  * @throws RangeError for a family not in {@link LOOK_FAMILIES}; whatever an apply function throws for a part that cannot
45
59
  * take the family's values (a post look that turns GTAO on needs a GTAO in `post`).
46
60
  * @example applyLookFamily('animatedFeature', { sky: { sky }, water, terrain: colors });
47
61
  */
48
62
  export declare function applyLookFamily(name: LookFamilyName, targets: LookFamilyTargets): void;
63
+ export {};
@@ -18,17 +18,40 @@ var x = ["natural", "animatedFeature"], S = x, C = [
18
18
  "hours",
19
19
  "timeScale",
20
20
  "sunDirection"
21
- ];
22
- function T(T, E) {
23
- if (!S.includes(T)) throw RangeError(`Unknown look family ${String(T)}; use one of ${x.join(", ")}.`);
24
- let D = (e) => e[T];
25
- if (E.sky) {
26
- let n = E.sky.sky.options, r = w.map((e) => [e, n[e]]), i = { ...D(e) };
27
- for (let e of C) delete i[e];
28
- t(E.sky, i);
29
- for (let [e, t] of r) t === void 0 ? delete n[e] : n[e] = Array.isArray(t) ? [...t] : t;
30
- }
31
- E.water && r(E.water, D(n)), E.terrain && a(E.terrain, D(i)), E.weather && s(E.weather, D(o)), E.environment && l(E.environment, D(c)), E.sand && m(E.sand, D(d)), E.smoke && h(E.smoke, D(f)), E.fire && p(E.fire, D(u)), E.tonemap && _(E.tonemap, D(g)), E.post && y(E.post, D(v)), E.biomes && (E.biomes.materials = b(T));
21
+ ], T = [
22
+ "type",
23
+ "coverage",
24
+ "bottom",
25
+ "top",
26
+ "density"
27
+ ], E = (e) => {
28
+ if (!S.includes(e)) throw RangeError(`Unknown look family ${String(e)}; use one of ${x.join(", ")}.`);
29
+ };
30
+ function D(n, r, i) {
31
+ let a = r.sky.options, o = { ...e[n] };
32
+ for (let e of C) delete o[e];
33
+ let s = {
34
+ ...o,
35
+ ...i
36
+ }, c = C.some((e) => e in i) ? [] : w.map((e) => [e, a[e]]), l = r.clouds?.options, u = (l ? T.filter((e) => !(`volumetric.${e}` in s) && l[e] !== void 0) : []).map((e) => [e, l[e]]);
37
+ t(r, s);
38
+ for (let [e, t] of u) l[e] = t;
39
+ for (let [e, t] of c) t === void 0 ? delete a[e] : a[e] = Array.isArray(t) ? [...t] : t;
40
+ }
41
+ function O(e, t, n) {
42
+ let r = e.filter((e) => typeof e?.options == "object" && e.options !== null).map((e) => [e.options, e.options.exposure]);
43
+ if (n(), !t) for (let [e, t] of r) t === void 0 ? delete e.exposure : e.exposure = t;
44
+ }
45
+ var k = (t, n) => n in e[t] || n in g[t];
46
+ function A(e, t, n = {}) {
47
+ E(e), O([t.tonemap], "tonemap.exposure" in n || k(e, "tonemap.exposure"), () => D(e, t, n));
48
+ }
49
+ function j(e, t) {
50
+ E(e), O([t.sky?.tonemap, t.tonemap?.tonemap], k(e, "tonemap.exposure"), () => M(e, t));
51
+ }
52
+ function M(e, t) {
53
+ let x = (t) => t[e];
54
+ t.sky && D(e, t.sky, {}), t.water && r(t.water, x(n)), t.terrain && a(t.terrain, x(i)), t.weather && s(t.weather, x(o)), t.environment && l(t.environment, x(c)), t.sand && m(t.sand, x(d)), t.smoke && h(t.smoke, x(f)), t.fire && p(t.fire, x(u)), t.tonemap && _(t.tonemap, x(g)), t.post && y(t.post, x(v)), t.biomes && (t.biomes.materials = b(e));
32
55
  }
33
56
  //#endregion
34
- export { x as LOOK_FAMILIES, T as applyLookFamily };
57
+ export { x as LOOK_FAMILIES, A as applyFamilySky, j as applyLookFamily };