@margoengine/scenes 0.0.0-stage → 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 (48) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +619 -2
  4. package/dist/dune-coast-info-D9yQIv8G.js +218 -0
  5. package/dist/dune-coast-info.d.ts +3 -0
  6. package/dist/dune-coast.d.ts +179 -0
  7. package/dist/dune-coast.js +778 -0
  8. package/dist/errors-fc4i1pSL.js +7 -0
  9. package/dist/fauld-blast.d.ts +165 -0
  10. package/dist/fauld-blast.js +1034 -0
  11. package/dist/fauld-countryside.d.ts +13 -0
  12. package/dist/fauld-countryside.js +10 -0
  13. package/dist/fauld-crater.d.ts +13 -0
  14. package/dist/fauld-crater.js +10 -0
  15. package/dist/fauld-dig.d.ts +89 -0
  16. package/dist/fauld-dustfall-fines-grid-MA6XPrq6.js +14 -0
  17. package/dist/fauld-dustfall-fines-grid.d.ts +11 -0
  18. package/dist/fauld-dustfall-grid-Bb4X8b-u.js +14 -0
  19. package/dist/fauld-dustfall-grid.d.ts +11 -0
  20. package/dist/fauld-explosion.d.ts +135 -0
  21. package/dist/fauld-grains.d.ts +27 -0
  22. package/dist/fauld-mud.d.ts +104 -0
  23. package/dist/fauld-surge.d.ts +71 -0
  24. package/dist/fauld-tunnels-info-8qv9X4OJ.js +70 -0
  25. package/dist/fauld-tunnels-info.d.ts +5 -0
  26. package/dist/fauld-tunnels-plan.d.ts +1069 -0
  27. package/dist/fauld-tunnels.d.ts +281 -0
  28. package/dist/fauld-tunnels.js +6801 -0
  29. package/dist/fauld-world-CNNSonJF.js +863 -0
  30. package/dist/fauld-world-info.d.ts +7 -0
  31. package/dist/fauld-world.d.ts +243 -0
  32. package/dist/index.d.ts +53 -0
  33. package/dist/index.js +160 -0
  34. package/dist/library-mesh-CjTG-mVZ.js +329 -0
  35. package/dist/library-mesh.d.ts +108 -0
  36. package/dist/library-parts.d.ts +55 -0
  37. package/dist/library.d.ts +52 -0
  38. package/dist/library.js +48 -0
  39. package/dist/look-family.d.ts +63 -0
  40. package/dist/look-family.js +57 -0
  41. package/dist/shared/settings.d.ts +89 -0
  42. package/dist/shot-settings.d.ts +40 -0
  43. package/dist/shot-settings.js +94 -0
  44. package/dist/timber-valley-info-vVI2nwDs.js +253 -0
  45. package/dist/timber-valley-info.d.ts +3 -0
  46. package/dist/timber-valley.d.ts +229 -0
  47. package/dist/timber-valley.js +424 -0
  48. package/package.json +104 -4
@@ -0,0 +1,329 @@
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;
4
+ async function n(o, s = {}) {
5
+ if (typeof o != "string") {
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");
8
+ let e = await Promise.all(o.map((e) => n(e, s)));
9
+ return e[0].map((t) => {
10
+ let n = e.map((e) => e.find((e) => e.name === t.name));
11
+ if (n.some((e) => !e)) throw TypeError(`libraryParts: material ${t.name} is missing from a level; export every level with the same materials`);
12
+ let [r, i, a] = n;
13
+ return {
14
+ ...t,
15
+ geometry: [
16
+ r.geometry,
17
+ i.geometry,
18
+ a.geometry
19
+ ],
20
+ textures: {
21
+ ...t.textures,
22
+ uvs: [
23
+ r.textures.uvs,
24
+ i.textures.uvs,
25
+ a.textures.uvs
26
+ ]
27
+ }
28
+ };
29
+ });
30
+ }
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) => {
38
+ if (t.startsWith("data:")) throw TypeError("libraryParts reads a .gltf with external buffers and images; export the model as glTF separate");
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`);
41
+ return n.arrayBuffer();
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;
44
+ if (!r || !i) throw TypeError("libraryParts: an accessor without a buffer view; use a model whose accessors all have buffer views");
45
+ if (!o || n === (r.componentType === 5126)) throw TypeError(`libraryParts: unsupported accessor component type ${r.componentType}; use float vertices and uvs and integer indices`);
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) {
52
+ let t = e.attributes;
53
+ if ((e.mode ?? 4) !== 4 || t.POSITION === void 0 || t.NORMAL === void 0 || t.TEXCOORD_0 === void 0) continue;
54
+ let n = e.material ?? -1, r = _.get(n) ?? {
55
+ positions: [],
56
+ normals: [],
57
+ uvs: [],
58
+ indices: []
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);
61
+ for (let e = 0; e < l; e++) {
62
+ let [t, n, c] = [
63
+ i[e * 3],
64
+ i[e * 3 + 1],
65
+ i[e * 3 + 2]
66
+ ], [l, u, d] = [
67
+ a[e * 3],
68
+ a[e * 3 + 1],
69
+ a[e * 3 + 2]
70
+ ];
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;
73
+ r.normals.push(f / h, p / h, m / h), r.uvs.push(s[e * 2], s[e * 2 + 1]);
74
+ }
75
+ let u = e.indices === void 0 ? Uint32Array.from({ length: l }, (e, t) => t) : g(e.indices, 1, !0);
76
+ for (let e of u) r.indices.push(c + e);
77
+ }
78
+ for (let e of a.children ?? []) v(e, o, c);
79
+ }, y = [
80
+ 1,
81
+ 0,
82
+ 0,
83
+ 0,
84
+ 0,
85
+ 1,
86
+ 0,
87
+ 0,
88
+ 0,
89
+ 0,
90
+ 1,
91
+ 0,
92
+ 0,
93
+ 0,
94
+ 0,
95
+ 1
96
+ ];
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 }), {
102
+ colorSpaceConversion: "none",
103
+ premultiplyAlpha: "none"
104
+ })), j = /* @__PURE__ */ new Map(), M = (e) => {
105
+ let t = e === void 0 ? void 0 : f.textures?.[e.index]?.source;
106
+ if (t === void 0) return;
107
+ let n = f.images?.[t];
108
+ if (!n?.uri) throw TypeError("libraryParts reads images by uri; export the model as glTF separate");
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
+ ];
146
+ }
147
+ let A = i.baseColorFactor ?? [
148
+ 1,
149
+ 1,
150
+ 1,
151
+ 1
152
+ ], [j, F, I] = [
153
+ M(i.baseColorTexture),
154
+ M(r.normalTexture),
155
+ M(i.metallicRoughnessTexture)
156
+ ];
157
+ P.push(Promise.all([
158
+ j,
159
+ F,
160
+ I
161
+ ]).then(([e, t, n]) => ({
162
+ geometry: C,
163
+ color: [
164
+ A[0],
165
+ A[1],
166
+ A[2]
167
+ ],
168
+ kind: u,
169
+ name: a,
170
+ textures: {
171
+ uvs: w,
172
+ ...e ? { baseColor: e } : {},
173
+ ...t ? { normal: t } : {},
174
+ ...n ? { occlusionRoughnessMetal: n } : {},
175
+ alphaCutoff: l && e ? r.alphaCutoff ?? .5 : 0
176
+ }
177
+ })));
178
+ }
179
+ return Promise.all(P);
180
+ }
181
+ //#endregion
182
+ //#region src/library-mesh.ts
183
+ function r(e) {
184
+ if (e.matrix) return e.matrix;
185
+ let [t, n, r, i] = e.rotation ?? [
186
+ 0,
187
+ 0,
188
+ 0,
189
+ 1
190
+ ], [a, o, s] = e.scale ?? [
191
+ 1,
192
+ 1,
193
+ 1
194
+ ], [c, l, u] = e.translation ?? [
195
+ 0,
196
+ 0,
197
+ 0
198
+ ];
199
+ return [
200
+ (1 - 2 * (n * n + r * r)) * a,
201
+ 2 * (t * n + r * i) * a,
202
+ 2 * (t * r - n * i) * a,
203
+ 0,
204
+ 2 * (t * n - r * i) * o,
205
+ (1 - 2 * (t * t + r * r)) * o,
206
+ 2 * (n * r + t * i) * o,
207
+ 0,
208
+ 2 * (t * r + n * i) * s,
209
+ 2 * (n * r - t * i) * s,
210
+ (1 - 2 * (t * t + n * n)) * s,
211
+ 0,
212
+ c,
213
+ l,
214
+ u,
215
+ 1
216
+ ];
217
+ }
218
+ var i = (e, t) => Array.from({ length: 16 }, (n, r) => {
219
+ let i = Math.floor(r / 4), a = r % 4;
220
+ return e[a] * t[i * 4] + e[4 + a] * t[i * 4 + 1] + e[8 + a] * t[i * 4 + 2] + e[12 + a] * t[i * 4 + 3];
221
+ }), a = {
222
+ 5126: [4, (e, t) => e.getFloat32(t, !0)],
223
+ 5125: [4, (e, t) => e.getUint32(t, !0)],
224
+ 5123: [2, (e, t) => e.getUint16(t, !0)],
225
+ 5121: [1, (e, t) => e.getUint8(t)]
226
+ };
227
+ async function o(t, o = {}) {
228
+ let s = o.fetch ?? globalThis.fetch, c = o.signal ? { signal: o.signal } : {}, l = await s(t, c);
229
+ if (!l.ok) throw TypeError(`libraryMesh: ${t} answered ${l.status}; check the URL and that the server is up`);
230
+ let u = await l.json(), d = t.slice(0, t.lastIndexOf("/") + 1), f = [];
231
+ if (!u.meshes?.length || !u.accessors || !u.bufferViews || !u.buffers || !u.nodes) throw TypeError(`libraryMesh: ${t} holds no meshes; pass a .gltf with meshes, accessors, buffer views, buffers and nodes`);
232
+ if (!o.color && u.materials?.some((e) => e.pbrMetallicRoughness?.baseColorTexture)) {
233
+ let r = await n(t, {
234
+ fetch: async (e, n) => e === t ? {
235
+ ok: !0,
236
+ status: 200,
237
+ json: async () => u,
238
+ arrayBuffer: async () => /* @__PURE__ */ new ArrayBuffer(0)
239
+ } : s(e, n),
240
+ signal: o.signal,
241
+ scale: o.scale,
242
+ maxTriangles: o.maxTriangles ?? 4e4,
243
+ decode: o.decode,
244
+ kind: o.kind === "bark" ? "bark" : "stone",
245
+ ...o.kind === "foliage" ? { foliage: () => !0 } : {}
246
+ });
247
+ if (r.length !== 1) throw e("unsupported", `libraryMesh: ${t} has ${r.length} textured materials and one part draws one; load it with libraryParts (one part per material), or pass color to draw it flat`);
248
+ let [i] = r;
249
+ return {
250
+ geometry: i.geometry,
251
+ color: i.color,
252
+ kind: i.kind,
253
+ textures: i.textures,
254
+ name: i.name
255
+ };
256
+ }
257
+ for (let e of u.buffers) {
258
+ if (!e.uri || e.uri.startsWith("data:")) throw TypeError("libraryMesh reads a .gltf with external buffers; export the glTF with separate .bin buffers");
259
+ let t = await s(d + e.uri, c);
260
+ if (!t.ok) throw TypeError(`libraryMesh: ${d + e.uri} answered ${t.status}; check that the buffer file sits beside the .gltf`);
261
+ f.push(await t.arrayBuffer());
262
+ }
263
+ let p = (e, t, n) => {
264
+ let r = u.accessors[e], i = r ? u.bufferViews[r.bufferView ?? -1] : void 0, o = r ? a[r.componentType] : void 0;
265
+ if (!r || !i) throw TypeError("libraryMesh: an accessor without a buffer view; export the glTF without sparse or empty accessors");
266
+ if (!o || n === (r.componentType === 5126)) throw TypeError(`libraryMesh: unsupported accessor component type ${r.componentType}; use float positions and normals and integer indices`);
267
+ let [s, c] = o, l = i.byteStride ?? s * t, d = new DataView(f[i.buffer], (i.byteOffset ?? 0) + (r.byteOffset ?? 0)), p = n ? new Uint32Array(r.count * t) : new Float32Array(r.count * t);
268
+ for (let e = 0; e < r.count; e++) for (let n = 0; n < t; n++) p[e * t + n] = c(d, e * l + n * s);
269
+ return p;
270
+ }, m = [], h = [], g = [], _ = [], v = (e, t) => {
271
+ let n = u.nodes[e], a = i(t, r(n));
272
+ if (n.mesh !== void 0) for (let e of u.meshes[n.mesh].primitives) {
273
+ if ((e.mode ?? 4) !== 4 || e.attributes.POSITION === void 0 || e.attributes.NORMAL === void 0) continue;
274
+ let t = p(e.attributes.POSITION, 3, !1), n = p(e.attributes.NORMAL, 3, !1), r = m.length / 3, i = t.length / 3;
275
+ for (let e = 0; e < i; e++) {
276
+ let r = t[e * 3], i = t[e * 3 + 1], o = t[e * 3 + 2], s = n[e * 3], c = n[e * 3 + 1], l = n[e * 3 + 2];
277
+ m.push(a[0] * r + a[4] * i + a[8] * o + a[12], a[1] * r + a[5] * i + a[9] * o + a[13], a[2] * r + a[6] * i + a[10] * o + a[14]);
278
+ let u = a[0] * s + a[4] * c + a[8] * l, d = a[1] * s + a[5] * c + a[9] * l, f = a[2] * s + a[6] * c + a[10] * l, p = Math.hypot(u, d, f) || 1;
279
+ h.push(u / p, d / p, f / p);
280
+ }
281
+ let o = e.indices === void 0 ? Uint32Array.from({ length: i }, (e, t) => t) : p(e.indices, 1, !0);
282
+ for (let e of o) g.push(r + e);
283
+ let s = u.materials?.[e.material ?? -1]?.pbrMetallicRoughness?.baseColorFactor;
284
+ s && _.push(s);
285
+ }
286
+ for (let e of n.children ?? []) v(e, a);
287
+ }, y = [
288
+ 1,
289
+ 0,
290
+ 0,
291
+ 0,
292
+ 0,
293
+ 1,
294
+ 0,
295
+ 0,
296
+ 0,
297
+ 0,
298
+ 1,
299
+ 0,
300
+ 0,
301
+ 0,
302
+ 0,
303
+ 1
304
+ ], b = u.scenes?.[u.scene ?? 0]?.nodes ?? u.nodes.map((e, t) => t);
305
+ for (let e of b) v(e, y);
306
+ let x = g.length / 3, S = o.maxTriangles ?? 4e4;
307
+ if (!x) throw TypeError(`libraryMesh: ${t} holds no triangles with positions and normals; export triangle meshes with normals`);
308
+ if (x > S) throw RangeError(`libraryMesh: ${t} has ${x} triangles, over maxTriangles ${S}; export a lighter level of it`);
309
+ let C = Infinity, w = Infinity, T = -Infinity, E = Infinity, D = -Infinity;
310
+ for (let e = 0; e < m.length; e += 3) C = Math.min(C, m[e + 1]), w = Math.min(w, m[e]), T = Math.max(T, m[e]), E = Math.min(E, m[e + 2]), D = Math.max(D, m[e + 2]);
311
+ let O = o.scale ?? 1, k = (w + T) / 2, A = (E + D) / 2, j = new Float32Array(m.length);
312
+ for (let e = 0; e < m.length; e += 3) j[e] = (m[e] - k) * O, j[e + 1] = (m[e + 1] - C) * O, j[e + 2] = (m[e + 2] - A) * O;
313
+ let M = (e) => _.length ? _.reduce((t, n) => t + n[e], 0) / _.length : .5, N = o.color ?? [
314
+ M(0),
315
+ M(1),
316
+ M(2)
317
+ ];
318
+ return {
319
+ geometry: {
320
+ positions: j,
321
+ normals: Float32Array.from(h),
322
+ indices: Uint32Array.from(g)
323
+ },
324
+ color: N,
325
+ kind: o.kind ?? "stone"
326
+ };
327
+ }
328
+ //#endregion
329
+ export { n, o as t };
@@ -0,0 +1,108 @@
1
+ import type { ScatterImage, ScatterTextures } from '@margoengine/scatter';
2
+ /** Options of {@link libraryMesh}. */
3
+ export interface LibraryMeshOptions {
4
+ /** The look the part takes in a biome scatter. Default `'stone'`. */
5
+ readonly kind?: 'bark' | 'foliage' | 'stone';
6
+ /**
7
+ * Albedo, linear RGB 0..1: the part draws this one colour and no maps. Default: a model whose material has a base
8
+ * colour map draws its maps (the part carries `textures`; a model of several textured materials needs
9
+ * `libraryParts`, one part per material); any other model draws the mean of its materials' `baseColorFactor`.
10
+ */
11
+ readonly color?: readonly [number, number, number];
12
+ /** Decodes a map's file (textured models). Default `createImageBitmap` on the fetched bytes. */
13
+ readonly decode?: (bytes: ArrayBuffer, mimeType: string) => Promise<ScatterImage>;
14
+ /** Most triangles the merged mesh may hold (it is drawn once per placed object). Default 40,000. */
15
+ readonly maxTriangles?: number;
16
+ /** Uniform scale to metres. Default 1. */
17
+ readonly scale?: number;
18
+ readonly signal?: AbortSignal;
19
+ /** The fetch to use. Default the global one. */
20
+ readonly fetch?: (url: string, init?: {
21
+ signal?: AbortSignal;
22
+ }) => Promise<{
23
+ ok: boolean;
24
+ status: number;
25
+ json(): Promise<unknown>;
26
+ arrayBuffer(): Promise<ArrayBuffer>;
27
+ }>;
28
+ }
29
+ /** A merged library mesh, ready for `BiomeViewOptions.meshes` (`{ 'procedural:rock': [part] }`). */
30
+ export interface LibraryMeshPart {
31
+ readonly geometry: {
32
+ readonly positions: Float32Array;
33
+ readonly normals: Float32Array;
34
+ readonly indices: Uint32Array;
35
+ };
36
+ /** Albedo, or the factor that multiplies the base colour map when there is one. */
37
+ readonly color: readonly [number, number, number];
38
+ readonly kind: 'bark' | 'foliage' | 'stone';
39
+ /** The model's maps and texture coordinates, when its material has a base colour map and no `color` was given. */
40
+ readonly textures?: ScatterTextures;
41
+ /** The glTF material name of a textured part. */
42
+ readonly name?: string;
43
+ }
44
+ export type Node = {
45
+ mesh?: number;
46
+ children?: number[];
47
+ matrix?: number[];
48
+ translation?: number[];
49
+ rotation?: number[];
50
+ scale?: number[];
51
+ };
52
+ export type Doc = {
53
+ buffers?: {
54
+ uri?: string;
55
+ byteLength: number;
56
+ }[];
57
+ bufferViews?: {
58
+ buffer: number;
59
+ byteOffset?: number;
60
+ byteLength: number;
61
+ byteStride?: number;
62
+ }[];
63
+ accessors?: {
64
+ bufferView?: number;
65
+ byteOffset?: number;
66
+ componentType: number;
67
+ count: number;
68
+ type: string;
69
+ }[];
70
+ meshes?: {
71
+ primitives: {
72
+ attributes: Record<string, number>;
73
+ indices?: number;
74
+ material?: number;
75
+ mode?: number;
76
+ }[];
77
+ }[];
78
+ nodes?: Node[];
79
+ scenes?: {
80
+ nodes?: number[];
81
+ }[];
82
+ scene?: number;
83
+ materials?: {
84
+ pbrMetallicRoughness?: {
85
+ baseColorFactor?: number[];
86
+ baseColorTexture?: {
87
+ index: number;
88
+ };
89
+ };
90
+ }[];
91
+ };
92
+ /** Column-major 4x4 of a node's matrix, or of its translation, rotation and scale (glTF 2.0 section 5.25). */
93
+ export declare function nodeMatrix(n: Node): number[];
94
+ export declare const mul: (a: number[], b: number[]) => number[];
95
+ /** Component types: bytes and reader. */
96
+ export declare const KINDS: Record<number, [number, (d: DataView, o: number) => number]>;
97
+ /**
98
+ * Loads a glTF model (`.gltf` with external buffers) as one merged mesh part for a biome scatter: every triangle
99
+ * primitive of the default scene under its node transforms, its base on y = 0 and centred on x = z = 0, so a placed
100
+ * object stands on the ground. A model with a base colour map (and no `color`) keeps its maps: the part carries its
101
+ * texture coordinates and its base colour, normal and occlusion-roughness-metal images, so it draws textured.
102
+ * @throws TypeError for a document with no triangles with float positions and normals; RangeError for a mesh over
103
+ * `maxTriangles`; Error for a file that does not load.
104
+ * @example
105
+ * const rock = await libraryMesh('/asset-library/big-burn-1910/rocks/rock_07/rock_07_2k.gltf', { color: [0.3, 0.29, 0.27] });
106
+ * const scene = await attach(engine, { meshes: { 'procedural:rock': [rock] } });
107
+ */
108
+ export declare function libraryMesh(url: string, options?: LibraryMeshOptions): Promise<LibraryMeshPart>;
@@ -0,0 +1,55 @@
1
+ import type { ScatterImage, ScatterTextures } from '@margoengine/scatter';
2
+ import { type LibraryMeshOptions } from './library-mesh.js';
3
+ /** Options of {@link libraryParts}. */
4
+ export interface LibraryPartsOptions extends Omit<LibraryMeshOptions, 'color' | 'kind'> {
5
+ /** The look of materials that are not foliage. Default `'bark'`. */
6
+ readonly kind?: 'bark' | 'stone';
7
+ /**
8
+ * Whether a material is foliage (sways, shades as clusters, follows the seasons). Default: alphaMode MASK or BLEND,
9
+ * or a name with twig, leaf, needle, foliage or frond in it.
10
+ */
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;
21
+ /** Decodes an image file. Default `createImageBitmap` on the fetched bytes. */
22
+ readonly decode?: (bytes: ArrayBuffer, mimeType: string) => Promise<ScatterImage>;
23
+ }
24
+ /** Vertices of one part (one level). */
25
+ export interface LibraryGeometry {
26
+ readonly positions: Float32Array;
27
+ readonly normals: Float32Array;
28
+ readonly indices: Uint32Array;
29
+ }
30
+ /** One textured part, ready for `BiomeViewOptions.meshes`. */
31
+ export interface LibraryTexturedPart {
32
+ readonly geometry: LibraryGeometry | readonly [LibraryGeometry, LibraryGeometry, LibraryGeometry];
33
+ /** The material's baseColorFactor (white for most scans): it multiplies the base colour map. */
34
+ readonly color: readonly [number, number, number];
35
+ readonly kind: 'bark' | 'foliage' | 'stone';
36
+ readonly textures: ScatterTextures;
37
+ /** The glTF material name. */
38
+ readonly name: string;
39
+ }
40
+ /**
41
+ * Loads a glTF model (`.gltf` with external buffers and images) as one textured part per material, every triangle
42
+ * primitive of the default scene under its node transforms, its base on y = 0 and centred on x = z = 0. Each part
43
+ * carries its TEXCOORD_0 (with the material's KHR_texture_transform applied) and its base colour, normal and
44
+ * metallic-roughness images; the metallic-roughness image is read as occlusion-roughness-metal (R occlusion, the
45
+ * packing of Poly Haven and most scan libraries). BLEND materials draw as MASK (a scatter has no sorted blending).
46
+ * Heavy scans need a lighter level first (`maxTriangles`, counted per part). Three URLs (near, middle, far levels of
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.
49
+ * @throws TypeError for a document with no textured triangles; RangeError for a part over `maxTriangles`; Error for a
50
+ * file that does not load.
51
+ * @example
52
+ * const fir = await libraryParts('/asset-library/big-burn-1910/plants/fir_tree_01/forest/fir_tree_01_a_near.gltf');
53
+ * const scene = await attach(engine, { meshes: { 'procedural:conifer': fir } });
54
+ */
55
+ export declare function libraryParts(url: string | readonly [near: string, middle: string, far: string], options?: LibraryPartsOptions): Promise<LibraryTexturedPart[]>;
@@ -0,0 +1,52 @@
1
+ /** What an asset is: a `model` (glTF), a `sky` (an HDR panorama) or a `texture`. */
2
+ export type AssetType = 'model' | 'sky' | 'texture';
3
+ /** One asset of the library. */
4
+ export interface LibraryAsset {
5
+ /** Unique across the library, as the source names it (`ocean_buoy`). */
6
+ readonly id: string;
7
+ /** The film or subject folder it sits in (`japan-2011-coast`). */
8
+ readonly subject: string;
9
+ /** The folder kind (`boats`, `buildings`, `plants`, `hdri` ...). */
10
+ readonly kind: string;
11
+ readonly type: AssetType;
12
+ /** Path of the file to load, relative to the library root, with forward slashes. */
13
+ readonly file: string;
14
+ /** Bytes of the file (0 when unknown). */
15
+ readonly bytes: number;
16
+ }
17
+ /** The checked index. */
18
+ export interface Library {
19
+ readonly root: string;
20
+ readonly assets: readonly LibraryAsset[];
21
+ readonly byId: ReadonlyMap<string, LibraryAsset>;
22
+ }
23
+ /** The asset types an index may hold. */
24
+ export declare const ASSET_TYPES: readonly AssetType[];
25
+ /**
26
+ * Checks an index (`{ version: 1, assets: [...] }`) and returns it with a lookup by id.
27
+ * @throws TypeError when `data` is not an index object; RangeError for a missing or repeated id, an unknown type, or a
28
+ * file path that is empty, absolute or climbs out of the root. The message names the asset.
29
+ */
30
+ export declare function parseLibrary(data: unknown, root?: string): Library;
31
+ /**
32
+ * Fetches and checks `library.json` under `root` (a URL, with or without the closing slash). The request aborts with
33
+ * `signal`.
34
+ * @throws RangeError when the request fails (the message names the URL and status); a bad index throws as {@link parseLibrary}.
35
+ */
36
+ export declare function fetchLibrary(root: string, options?: {
37
+ signal?: AbortSignal;
38
+ fetch?: typeof fetch;
39
+ }): Promise<Library>;
40
+ /**
41
+ * The URL of an asset's file under the library root.
42
+ * @throws RangeError for an id not in the library.
43
+ */
44
+ export declare function assetUrl(library: Library, id: string): string;
45
+ /** The assets of a subject and/or kind and/or type, in index order. */
46
+ export declare function findAssets(library: Library, match?: {
47
+ subject?: string;
48
+ kind?: string;
49
+ type?: AssetType;
50
+ }): LibraryAsset[];
51
+ export { libraryMesh, type LibraryMeshOptions, type LibraryMeshPart } from './library-mesh.js';
52
+ export { libraryParts, type LibraryGeometry, type LibraryPartsOptions, type LibraryTexturedPart, } from './library-parts.js';
@@ -0,0 +1,48 @@
1
+ import { n as e, t } from "./library-mesh-CjTG-mVZ.js";
2
+ //#region src/library.ts
3
+ var n = [
4
+ "model",
5
+ "sky",
6
+ "texture"
7
+ ], r = /^[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*$/, i = (e, t) => (e.endsWith("/") || e === "" ? e : e + "/") + t;
8
+ function a(e, t = "") {
9
+ let i = e;
10
+ if (typeof i != "object" || !i || i.version !== 1 || !Array.isArray(i.assets)) throw TypeError("A library index is { version: 1, assets: [...] }; build it with tools/library-index.mjs.");
11
+ let a = /* @__PURE__ */ new Map();
12
+ for (let [e, t] of i.assets.entries()) {
13
+ let i = t?.id;
14
+ if (typeof i != "string" || !i) throw RangeError(`Library asset ${e} has no id; give each asset a unique id.`);
15
+ if (a.has(i)) throw RangeError(`Library asset ${i} is listed twice; ids are unique across the library.`);
16
+ if (!n.includes(t.type)) throw RangeError(`Library asset ${i} has type ${String(t.type)}; use ${n.join(", ")}.`);
17
+ let o = t.file;
18
+ if (typeof o != "string" || !r.test(o) || o.split("/").some((e) => e === ".." || e === ".")) throw RangeError(`Library asset ${i} has file ${String(o)}; use a relative path of letters, digits, dot, dash and underscore inside the root.`);
19
+ a.set(i, {
20
+ id: i,
21
+ subject: String(t.subject ?? ""),
22
+ kind: String(t.kind ?? ""),
23
+ type: t.type,
24
+ file: o,
25
+ bytes: typeof t.bytes == "number" && t.bytes >= 0 ? t.bytes : 0
26
+ });
27
+ }
28
+ return Object.freeze({
29
+ root: t,
30
+ assets: Object.freeze([...a.values()]),
31
+ byId: a
32
+ });
33
+ }
34
+ async function o(e, t = {}) {
35
+ let n = t.fetch ?? fetch, r = i(e, "library.json"), o = await n(r, { signal: t.signal });
36
+ if (!o.ok) throw RangeError(`Could not load the asset library index ${r} (status ${o.status}); serve the library folder and run tools/library-index.mjs.`);
37
+ return a(await o.json(), e);
38
+ }
39
+ function s(e, t) {
40
+ let n = e.byId.get(t);
41
+ if (!n) throw RangeError(`Unknown library asset ${t}; use an id from library.assets.`);
42
+ return i(e.root, n.file);
43
+ }
44
+ function c(e, t = {}) {
45
+ return e.assets.filter((e) => (t.subject === void 0 || e.subject === t.subject) && (t.kind === void 0 || e.kind === t.kind) && (t.type === void 0 || e.type === t.type));
46
+ }
47
+ //#endregion
48
+ export { n as ASSET_TYPES, s as assetUrl, o as fetchLibrary, c as findAssets, t as libraryMesh, e as libraryParts, a as parseLibrary };
@@ -0,0 +1,63 @@
1
+ import { applySkySettings } from '@margoengine/sky/settings';
2
+ import { applyWaterSettings } from '@margoengine/water/settings';
3
+ import { applyTerrainSettings } from '@margoengine/terrain/settings';
4
+ import { applyWeatherSettings } from '@margoengine/weather/settings';
5
+ import { applyEnvironmentSettings } from '@margoengine/environment/settings';
6
+ import { applyFlameSettings, applySandSettings, applySmokeSettings } from '@margoengine/vfx/settings';
7
+ import { applyTonemapSettings } from '@margoengine/tonemap/settings';
8
+ import { applyPostSettings } from '@margoengine/post/settings';
9
+ import { type MaterialLook } from '@margoengine/biomes/settings';
10
+ /** The look families: `natural` is every package's own defaults, `animatedFeature` the animated-feature picture style. */
11
+ export declare const LOOK_FAMILIES: readonly ['natural', 'animatedFeature'];
12
+ /** The name of a look family in {@link LOOK_FAMILIES}. */
13
+ export type LookFamilyName = (typeof LOOK_FAMILIES)[number];
14
+ /** The parts of a scene a family can look after; each one given is written through its package's apply function. */
15
+ export interface LookFamilyTargets {
16
+ /** For `applySkySettings`: the sky, and optionally its tonemap, grade and volumetric clouds. */
17
+ readonly sky?: Parameters<typeof applySkySettings>[0];
18
+ readonly water?: Parameters<typeof applyWaterSettings>[0];
19
+ readonly terrain?: Parameters<typeof applyTerrainSettings>[0];
20
+ readonly weather?: Parameters<typeof applyWeatherSettings>[0];
21
+ readonly environment?: Parameters<typeof applyEnvironmentSettings>[0];
22
+ /** A `BlownSand` (or any target of `applySandSettings`). */
23
+ readonly sand?: Parameters<typeof applySandSettings>[0];
24
+ /** A `Smoke`, or a `FireFront` for its smoke columns (any target of `applySmokeSettings`). */
25
+ readonly smoke?: Parameters<typeof applySmokeSettings>[0];
26
+ /** A `Fire` (or any target of `applyFlameSettings`): its flames and embers. */
27
+ readonly fire?: Parameters<typeof applyFlameSettings>[0];
28
+ readonly tonemap?: Parameters<typeof applyTonemapSettings>[0];
29
+ readonly post?: Parameters<typeof applyPostSettings>[0];
30
+ /**
31
+ * The options of a `BiomeView` before `BiomeView.attach` (the ground materials are read when the view is built): its
32
+ * `materials` becomes `biomeMaterials(name)`, the built-in `MATERIALS` with the family's multipliers.
33
+ */
34
+ readonly biomes?: {
35
+ materials?: Readonly<Record<string, MaterialLook>>;
36
+ };
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;
50
+ /**
51
+ * Applies the look family `name` to every part of the scene in `targets`: each part gets that family's entry of its own
52
+ * package's LOOKS table (`natural` is every row at its default, so the part draws as it does with no settings), through
53
+ * that package's apply function. A part left out is left alone. The sky keeps the scene's time of day: its clock
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
57
+ * weather target, so give it only when nothing else (a recorded storm, a drive) owns the weather.
58
+ * @throws RangeError for a family not in {@link LOOK_FAMILIES}; whatever an apply function throws for a part that cannot
59
+ * take the family's values (a post look that turns GTAO on needs a GTAO in `post`).
60
+ * @example applyLookFamily('animatedFeature', { sky: { sky }, water, terrain: colors });
61
+ */
62
+ export declare function applyLookFamily(name: LookFamilyName, targets: LookFamilyTargets): void;
63
+ export {};