@margoengine/tiles 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 (54) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +437 -2
  4. package/dist/bounds-CgKJT3Pg.js +161 -0
  5. package/dist/bounds.d.ts +66 -0
  6. package/dist/data-uri-DbGLVHq5.js +132 -0
  7. package/dist/data-uri.d.ts +2 -0
  8. package/dist/errors-D5_2oB8I.js +7 -0
  9. package/dist/fade.d.ts +34 -0
  10. package/dist/fade.js +129 -0
  11. package/dist/feature-texture.d.ts +19 -0
  12. package/dist/features.d.ts +78 -0
  13. package/dist/features.js +401 -0
  14. package/dist/formats-NNuOXg-1.js +390 -0
  15. package/dist/formats.d.ts +124 -0
  16. package/dist/glb-BU81jlYZ.js +25 -0
  17. package/dist/height.d.ts +20 -0
  18. package/dist/height.js +31 -0
  19. package/dist/i3dm.d.ts +16 -0
  20. package/dist/i3dm.js +85 -0
  21. package/dist/imagery.d.ts +108 -0
  22. package/dist/imagery.js +325 -0
  23. package/dist/implicit.d.ts +42 -0
  24. package/dist/index.d.ts +9 -0
  25. package/dist/index.js +849 -0
  26. package/dist/ion.d.ts +106 -0
  27. package/dist/ion.js +152 -0
  28. package/dist/json-BQoirgm5.js +4 -0
  29. package/dist/matrix-DcI5oFrD.js +89 -0
  30. package/dist/matrix.d.ts +32 -0
  31. package/dist/memory.d.ts +44 -0
  32. package/dist/metadata.d.ts +147 -0
  33. package/dist/metadata.js +285 -0
  34. package/dist/properties.d.ts +94 -0
  35. package/dist/properties.js +320 -0
  36. package/dist/queue.d.ts +37 -0
  37. package/dist/raw-accessor.d.ts +4 -0
  38. package/dist/renderer.d.ts +193 -0
  39. package/dist/s2.d.ts +37 -0
  40. package/dist/s2.js +181 -0
  41. package/dist/scene-scope-DufD_3B6.js +42 -0
  42. package/dist/screen-door-CMv5Jko4.js +11 -0
  43. package/dist/shared/screen-door.d.ts +9 -0
  44. package/dist/splats.d.ts +80 -0
  45. package/dist/splats.js +187 -0
  46. package/dist/style.d.ts +61 -0
  47. package/dist/style.js +609 -0
  48. package/dist/terrain.d.ts +96 -0
  49. package/dist/terrain.js +434 -0
  50. package/dist/tileset.d.ts +316 -0
  51. package/dist/uv-transform.d.ts +11 -0
  52. package/dist/wgs84-C5btsGGY.js +18 -0
  53. package/dist/wgs84.d.ts +24 -0
  54. package/package.json +122 -4
package/dist/s2.js ADDED
@@ -0,0 +1,181 @@
1
+ import { a as e, i as t, n, t as r } from "./wgs84-C5btsGGY.js";
2
+ import { t as i } from "./bounds-CgKJT3Pg.js";
3
+ //#region src/s2.ts
4
+ var a = 1, o = [
5
+ [
6
+ 0,
7
+ 1,
8
+ 3,
9
+ 2
10
+ ],
11
+ [
12
+ 0,
13
+ 2,
14
+ 3,
15
+ 1
16
+ ],
17
+ [
18
+ 3,
19
+ 2,
20
+ 0,
21
+ 1
22
+ ],
23
+ [
24
+ 3,
25
+ 1,
26
+ 0,
27
+ 2
28
+ ]
29
+ ], s = [
30
+ a,
31
+ 0,
32
+ 0,
33
+ 3
34
+ ], c = o.map((e) => [
35
+ 0,
36
+ 1,
37
+ 2,
38
+ 3
39
+ ].map((t) => e.indexOf(t))), l = (e, t) => /* @__PURE__ */ TypeError(`Invalid S2 token ${JSON.stringify(e)}: ${t}; give a cell's hex token such as "89c6c7"`);
40
+ function u(e) {
41
+ if (typeof e != "string" || !/^[0-9a-fA-F]{1,16}$/.test(e)) throw l(e, "not 1 to 16 hex digits");
42
+ let t = BigInt(`0x${e.padEnd(16, "0")}`);
43
+ if (t === 0n) throw l(e, "zero is not a cell");
44
+ let n = Number(t >> 61n);
45
+ if (n > 5) throw l(e, `face ${n} does not exist (0 to 5)`);
46
+ let r = 0;
47
+ for (; !(t >> BigInt(r) & 1n);) r++;
48
+ if (r % 2 || r > 60) throw l(e, "the bit after the last child is misplaced");
49
+ let i = (60 - r) / 2, c = n & a, u = 0, d = 0;
50
+ for (let e = 0; e < i; e++) {
51
+ let n = Number(t >> BigInt(59 - 2 * e) & 3n), r = o[c][n];
52
+ u = u * 2 + (r >> 1), d = d * 2 + (r & 1), c ^= s[n];
53
+ }
54
+ return {
55
+ face: n,
56
+ level: i,
57
+ i: u,
58
+ j: d
59
+ };
60
+ }
61
+ function d({ face: e, level: t, i: n, j: r }) {
62
+ let i = 2 ** t;
63
+ if (!Number.isInteger(e) || e < 0 || e > 5 || !Number.isInteger(t) || t < 0 || t > 30 || !Number.isInteger(n) || !Number.isInteger(r) || n < 0 || r < 0 || n >= i || r >= i) throw RangeError(`Invalid S2 cell ${JSON.stringify({
64
+ face: e,
65
+ level: t,
66
+ i: n,
67
+ j: r
68
+ })}; face 0-5, level 0-30, i and j on its grid`);
69
+ let o = BigInt(e) << 61n, l = e & a;
70
+ for (let e = 0; e < t; e++) {
71
+ let i = 2 ** (t - 1 - e), a = Math.floor(n / i) % 2 * 2 + Math.floor(r / i) % 2, u = c[l][a];
72
+ o |= BigInt(u) << BigInt(59 - 2 * e), l ^= s[u];
73
+ }
74
+ return o |= 1n << BigInt(60 - 2 * t), o.toString(16).padStart(16, "0").replace(/0+$/, "");
75
+ }
76
+ var f = (e) => e >= .5 ? (4 * e * e - 1) / 3 : (1 - 4 * (1 - e) * (1 - e)) / 3;
77
+ function p(e, t, n) {
78
+ switch (e) {
79
+ case 0: return [
80
+ 1,
81
+ t,
82
+ n
83
+ ];
84
+ case 1: return [
85
+ -t,
86
+ 1,
87
+ n
88
+ ];
89
+ case 2: return [
90
+ -t,
91
+ -n,
92
+ 1
93
+ ];
94
+ case 3: return [
95
+ -1,
96
+ -n,
97
+ -t
98
+ ];
99
+ case 4: return [
100
+ n,
101
+ -1,
102
+ -t
103
+ ];
104
+ default: return [
105
+ n,
106
+ t,
107
+ -1
108
+ ];
109
+ }
110
+ }
111
+ function m(e, t = .5, n = .5) {
112
+ let r = 2 ** e.level, [i, a, o] = p(e.face, f((e.i + t) / r), f((e.j + n) / r));
113
+ return [Math.atan2(a, i), Math.atan2(o, Math.hypot(i, a))];
114
+ }
115
+ var h = 16;
116
+ function g(a, o, s, c) {
117
+ if (!Number.isFinite(o) || !Number.isFinite(s) || o > s) throw RangeError(`Invalid S2 heights ${o} and ${s}; give finite metres with minimumHeight <= maximumHeight`);
118
+ let [l, u] = m(a), d = t(l, u, (o + s) / 2), f = e(d[0], d[1], d[2]), p = [
119
+ 0,
120
+ 4,
121
+ 8
122
+ ].map((e) => [
123
+ f[e],
124
+ f[e + 1],
125
+ f[e + 2]
126
+ ]), g = [
127
+ Infinity,
128
+ Infinity,
129
+ Infinity
130
+ ], _ = [
131
+ -Infinity,
132
+ -Infinity,
133
+ -Infinity
134
+ ], v = [];
135
+ for (let e = 0; e <= h; e++) for (let n = 0; n <= h; n++) {
136
+ let [r, i] = m(a, e / h, n / h);
137
+ v.push([
138
+ Math.cos(i) * Math.cos(r),
139
+ Math.cos(i) * Math.sin(r),
140
+ Math.sin(i)
141
+ ]);
142
+ for (let e of [o, s]) {
143
+ let n = t(r, i, e);
144
+ for (let e = 0; e < 3; e++) {
145
+ let t = (n[0] - d[0]) * p[e][0] + (n[1] - d[1]) * p[e][1] + (n[2] - d[2]) * p[e][2];
146
+ g[e] = Math.min(g[e], t), _[e] = Math.max(_[e], t);
147
+ }
148
+ }
149
+ }
150
+ let y = 0, b = (e, t) => v[e * 17 + t], x = (e, t) => Math.acos(Math.min(1, e[0] * t[0] + e[1] * t[1] + e[2] * t[2]));
151
+ for (let e = 0; e < h; e++) for (let t = 0; t < h; t++) y = Math.max(y, x(b(e, t), b(e + 1, t)), x(b(e, t), b(e, t + 1)), x(b(e, t), b(e + 1, t + 1)), x(b(e + 1, t), b(e, t + 1)));
152
+ let S = (r * r / n + Math.max(s, 0)) * (1 - Math.cos(y / 2)), C = [...d], w = [];
153
+ for (let e = 0; e < 3; e++) {
154
+ let t = (g[e] + _[e]) / 2, n = (_[e] - g[e]) / 2 + S;
155
+ for (let n = 0; n < 3; n++) C[n] += p[e][n] * t;
156
+ w.push(p[e][0] * n, p[e][1] * n, p[e][2] * n);
157
+ }
158
+ return new i(C, w, { split: c });
159
+ }
160
+ function _(e) {
161
+ if (!e || typeof e != "object") throw TypeError("Invalid 3DTILES_bounding_volume_S2; give { token, minimumHeight, maximumHeight }");
162
+ let t = u(e.token), { minimumHeight: n, maximumHeight: r } = e;
163
+ return g(t, n, r, (e, i, a, o, s) => {
164
+ let c = 2 ** i, l = {
165
+ face: t.face,
166
+ level: t.level + i,
167
+ i: t.i * c + a,
168
+ j: t.j * c + o
169
+ };
170
+ if (l.level > 30) throw RangeError(`Implicit S2 tile level ${l.level} is past S2's 30 levels; lower availableLevels`);
171
+ if (e !== "OCTREE") return g(l, n, r);
172
+ let u = (r - n) / c;
173
+ return g(l, n + u * s, n + u * (s + 1));
174
+ });
175
+ }
176
+ var v = {
177
+ name: "3DTILES_bounding_volume_S2",
178
+ bounds: (e) => _(e)
179
+ };
180
+ //#endregion
181
+ export { u as parseS2Token, v as s2, _ as s2Bounds, g as s2CellBounds, m as s2LonLat, d as s2Token };
@@ -0,0 +1,42 @@
1
+ // @margo/core-built 1.0.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+
4
+ //#region ../shared/scene-scope.js
5
+ var e = 0, t = (t, n) => {
6
+ let r = n + e++;
7
+ for (; t.plugins?.has(r);) r += ":";
8
+ return r;
9
+ };
10
+ function n(e) {
11
+ let n;
12
+ if (typeof e?.sceneOf == "function") {
13
+ for (let t of e.plugins?.values() ?? []) if (n = e.sceneOf(t)) break;
14
+ if (!n) {
15
+ let r = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
16
+ name: t(e, "scene-scope:"),
17
+ setup() {
18
+ n = e.sceneOf(r);
19
+ }
20
+ };
21
+ e.use(r), e.removePlugin(r.name);
22
+ }
23
+ }
24
+ return r(e, n);
25
+ }
26
+ function r(e, n) {
27
+ return {
28
+ scene: n,
29
+ run(r) {
30
+ if (!n) return r();
31
+ let i, a = {coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
32
+ name: t(e, "scene-scope:"),
33
+ setup() {
34
+ i = r();
35
+ }
36
+ };
37
+ return n.use(a), n.removePlugin(a.name), i;
38
+ }
39
+ };
40
+ }
41
+ //#endregion
42
+ export { r as n, n as t };
@@ -0,0 +1,11 @@
1
+ //#region ../shared/screen-door.js
2
+ function e(e) {
3
+ if (e.length !== 2 || !e.every(Number.isFinite) || e[0] < 0 || e[1] > 1 || e[0] > e[1]) throw RangeError("Dither fade needs 0 <= lower <= upper <= 1; correct the coverage interval");
4
+ }
5
+ function t(e, t) {
6
+ let n = Math.floor(e) & 3, r = Math.floor(t) & 3;
7
+ return 4 * (2 * (n & 1 ^ r & 1) + (r & 1)) + 2 * (n >> 1 & 1 ^ r >> 1 & 1) + (r >> 1 & 1);
8
+ }
9
+ var n = "fn margoDitherRank(p:vec2f)->u32 {\n let x=u32(p.x)&3u;let y=u32(p.y)&3u;\n return 4u*(2u*((x&1u)^(y&1u))+(y&1u))+2u*(((x>>1u)&1u)^((y>>1u)&1u))+((y>>1u)&1u);\n}";
10
+ //#endregion
11
+ export { t as n, n as r, e as t };
@@ -0,0 +1,9 @@
1
+ /** A screen-door coverage interval. Shared across replacement levels, in [0,1]. */
2
+ export type DitherRange = readonly [number, number];
3
+ /** Refuses invalid coverage intervals instead of silently clamping a transition. */
4
+ export declare function checkDitherRange(range: readonly number[]): void;
5
+ /** Ordered 4 by 4 Bayer rank, from integer drawing-buffer coordinates. */
6
+ export declare function ditherRank(x: number, y: number): number;
7
+ /** Same rank in WGSL for meshes, point discs and sorted Gaussian fragments. */
8
+ export declare const ditherWGSL =
9
+ 'fn margoDitherRank(p:vec2f)->u32 {\n let x=u32(p.x)&3u;let y=u32(p.y)&3u;\n return 4u*(2u*((x&1u)^(y&1u))+(y&1u))+2u*(((x>>1u)&1u)^((y>>1u)&1u))+((y>>1u)&1u);\n}';
@@ -0,0 +1,80 @@
1
+ import type { EngineKernel } from '@margoengine/core';
2
+ // @ts-ignore optional peer: its types apply when it is installed
3
+ import type { SplatData } from '@margoengine/splats/data';
4
+ import type { TilesContentHost, TilesModelDrawer } from './renderer.js';
5
+ /** Most splats one @margoengine/splats cloud takes; past it the visible splats start another cloud. */
6
+ export declare const SPLATS_PER_CLOUD = 3000000;
7
+ /**
8
+ * One tile's splats ready to place: covariances and harmonics already turned by the tile's linear part, positions
9
+ * relative to `anchor`, the float64 world point the tile's matrix carries its origin to.
10
+ */
11
+ export interface PlacedSplats {
12
+ readonly data: SplatData;
13
+ readonly anchor: readonly [number, number, number];
14
+ }
15
+ /**
16
+ * Turns local splats by a column-major float64 `matrix` (all but its translation) and keeps the translation apart, so
17
+ * the float32 positions stay as small as the tile and the world offset is added in float64 when clouds are built.
18
+ */
19
+ export declare function placeSplats(data: SplatData, matrix: ArrayLike<number>): Promise<PlacedSplats>;
20
+ /**
21
+ * One cloud of `parts`, each moved by its anchor minus `offset` (in float64, rounded once to float32), with harmonics
22
+ * padded to the largest degree present: zeros above a part's own bands, band 0 from its colour when it has none.
23
+ */
24
+ export declare function mergePlaced(parts: readonly PlacedSplats[], offset?: ArrayLike<number>): SplatData;
25
+ /** The part of a @margoengine/splats cloud the scene uses. */
26
+ interface Cloud {
27
+ readonly count: number;
28
+ setDitherFade?(first: number, count: number, lower: number, upper: number): unknown;
29
+ dispose(): void;
30
+ }
31
+ interface Entry {
32
+ placed: PlacedSplats;
33
+ visible: boolean;
34
+ range?: readonly [number, number];
35
+ spans?: Array<{
36
+ cloud: Cloud;
37
+ first: number;
38
+ count: number;
39
+ }>;
40
+ }
41
+ /**
42
+ * The splats of one renderer's tiles: every visible tile in one cloud (or several of at most `SPLATS_PER_CLOUD`),
43
+ * rebuilt after an update that changed which tiles show, or when the floating origin moved.
44
+ */
45
+ export declare class TileSplats {
46
+ private readonly host;
47
+ private readonly attach;
48
+ /** Most splats per cloud. */
49
+ private readonly limit;
50
+ /** The clouds drawn now. */
51
+ clouds: readonly Cloud[];
52
+ /** Times the clouds were rebuilt. */
53
+ builds: number;
54
+ private readonly entries;
55
+ private dirty;
56
+ private built;
57
+ private stop?;
58
+ constructor(host: TilesContentHost, attach: (engine: EngineKernel, data: SplatData) => Cloud,
59
+ /** Most splats per cloud. */
60
+ limit?: number);
61
+ /** Splats now visible. */
62
+ get count(): number;
63
+ add(placed: PlacedSplats): Entry;
64
+ show(entry: Entry, visible: boolean): void;
65
+ /** Sets one tile content interval without rebuilding or independently sorting its splats. */
66
+ fade(entry: Entry, lower: number, upper: number): void;
67
+ remove(entry: Entry): void;
68
+ /** Rebuilds the clouds if the visible tiles or the floating origin changed since the last build. */
69
+ flush(): void;
70
+ private release;
71
+ }
72
+ /** The splat scene of a renderer (its content host), made on its first splat tile. */
73
+ export declare function tileSplats(host: TilesContentHost): Promise<TileSplats> | undefined;
74
+ /**
75
+ * Draws glTF tile content that holds Gaussian splats: its meshes as gltf/pbr models, its splats in the renderer's one
76
+ * splat cloud, placed by `frame x tile transform x RTC x y-up to z-up x node`. Pass it as `splats` to
77
+ * `TilesRenderer.load`. The renderer's `loadModel` is not used for these tiles: gltf/pbr reads them.
78
+ */
79
+ export declare const splats: TilesModelDrawer;
80
+ export {};
package/dist/splats.js ADDED
@@ -0,0 +1,187 @@
1
+ import { s as e } from "./matrix-DcI5oFrD.js";
2
+ import { t } from "./scene-scope-DufD_3B6.js";
3
+ import { t as n } from "./screen-door-CMv5Jko4.js";
4
+ import { MargoError as r } from "@margoengine/math/errors";
5
+ //#region src/splats.ts
6
+ var i = 3e6, a = .2820947917738781;
7
+ async function o(e, t) {
8
+ let { transformSplats: n } = await import("@margoengine/splats"), r = Float64Array.from(t);
9
+ return r[12] = r[13] = r[14] = 0, {
10
+ data: n(e, r),
11
+ anchor: [
12
+ t[12],
13
+ t[13],
14
+ t[14]
15
+ ]
16
+ };
17
+ }
18
+ var s = (e) => e.sphericalHarmonics ? e.sphericalHarmonics.length / (e.positions.length / 3) / 3 : 0;
19
+ function c(e, t = [
20
+ 0,
21
+ 0,
22
+ 0
23
+ ]) {
24
+ let n = 0, r = 0;
25
+ for (let { data: t } of e) n += t.positions.length / 3, r = Math.max(r, s(t));
26
+ let i = new Float32Array(n * 3), o = new Float32Array(n * 6), c = new Float32Array(n * 4), l = r ? new Float32Array(n * r * 3) : void 0, u = 0;
27
+ for (let { data: n, anchor: d } of e) {
28
+ let e = n.positions.length / 3, f = d[0] - t[0], p = d[1] - t[1], m = d[2] - t[2];
29
+ for (let t = 0; t < e; t++) i[(u + t) * 3] = n.positions[t * 3] + f, i[(u + t) * 3 + 1] = n.positions[t * 3 + 1] + p, i[(u + t) * 3 + 2] = n.positions[t * 3 + 2] + m;
30
+ if (o.set(n.covariances, u * 6), c.set(n.colors, u * 4), l) {
31
+ let t = s(n), i = n.sphericalHarmonics;
32
+ for (let o = 0; o < e; o++) {
33
+ let e = (u + o) * r * 3;
34
+ if (i && t) l.set(i.subarray(o * t * 3, (o + 1) * t * 3), e);
35
+ else for (let t = 0; t < 3; t++) l[e + t] = (n.colors[o * 4 + t] - .5) / a;
36
+ }
37
+ }
38
+ u += e;
39
+ }
40
+ return l ? {
41
+ positions: i,
42
+ covariances: o,
43
+ colors: c,
44
+ sphericalHarmonics: l
45
+ } : {
46
+ positions: i,
47
+ covariances: o,
48
+ colors: c
49
+ };
50
+ }
51
+ var l = class {
52
+ constructor(e, t, n = i) {
53
+ this.host = e, this.attach = t, this.limit = n, this.clouds = [], this.builds = 0, this.entries = /* @__PURE__ */ new Set(), this.dirty = !1, this.built = [
54
+ 0,
55
+ 0,
56
+ 0
57
+ ], this.stop = e.onUpdate(() => this.flush());
58
+ }
59
+ get count() {
60
+ let e = 0;
61
+ for (let t of this.clouds) e += t.count;
62
+ return e;
63
+ }
64
+ add(e) {
65
+ this.stop || (this.stop = this.host.onUpdate(() => this.flush()), u.has(this.host) || (u.set(this.host, Promise.resolve(this)), d.set(this.host, this)));
66
+ let t = {
67
+ placed: e,
68
+ visible: !1
69
+ };
70
+ return this.entries.add(t), t;
71
+ }
72
+ show(e, t) {
73
+ e.visible !== t && (e.visible = t, this.dirty = !0);
74
+ }
75
+ fade(e, t, i) {
76
+ if (n([t, i]), e.range?.[0] !== t || e.range[1] !== i) {
77
+ e.range = [t, i];
78
+ for (let n of e.spans ?? []) {
79
+ if (!n.cloud.setDitherFade) throw new r("unsupported", "Splat fading needs setDitherFade in the owning splat cloud; update the custom cloud adapter");
80
+ n.cloud.setDitherFade(n.first, n.count, t, i);
81
+ }
82
+ }
83
+ }
84
+ remove(e) {
85
+ this.entries.delete(e) && (e.visible && (this.dirty = !0), this.entries.size || (this.release(), this.stop?.(), this.stop = void 0, d.get(this.host) === this && (u.delete(this.host), d.delete(this.host))));
86
+ }
87
+ flush() {
88
+ let e = this.host.offset();
89
+ if (!this.dirty && e[0] === this.built[0] && e[1] === this.built[1] && e[2] === this.built[2]) return;
90
+ this.dirty = !1, this.built = [
91
+ e[0],
92
+ e[1],
93
+ e[2]
94
+ ], this.release();
95
+ for (let e of this.entries) e.spans = [];
96
+ let t = [[]], n = 0;
97
+ for (let e of this.entries) {
98
+ if (!e.visible) continue;
99
+ let r = e.placed.data.positions.length / 3;
100
+ n && n + r > this.limit && (t.push([]), n = 0), t[t.length - 1].push(e), n += r;
101
+ }
102
+ t[0].length && (this.clouds = t.map((t) => {
103
+ let n = this.attach(this.host.engine, c(t.map((e) => e.placed), e)), i = 0;
104
+ for (let e of t) {
105
+ let t = e.placed.data.positions.length / 3;
106
+ if (e.spans.push({
107
+ cloud: n,
108
+ first: i,
109
+ count: t
110
+ }), e.range) {
111
+ if (!n.setDitherFade) throw new r("unsupported", "Splat fading needs setDitherFade in the owning splat cloud; update the custom cloud adapter");
112
+ n.setDitherFade(i, t, ...e.range);
113
+ }
114
+ i += t;
115
+ }
116
+ return n;
117
+ }), this.builds++);
118
+ }
119
+ release() {
120
+ for (let e of this.clouds) e.dispose();
121
+ this.clouds = [];
122
+ }
123
+ }, u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
124
+ function f(e) {
125
+ return u.get(e);
126
+ }
127
+ async function p(e) {
128
+ let t = u.get(e);
129
+ return t || (t = import("@margoengine/splats").then(({ Splats: t }) => {
130
+ let n = new l(e, (e, n) => t.attach(e, n));
131
+ return d.set(e, n), n;
132
+ }), u.set(e, t)), t;
133
+ }
134
+ var m = async (n, r, i, a) => {
135
+ let s = t(n.engine), [{ parseGLTFAsync: c }, { readGaussianSplats: l }] = await Promise.all([import("@margoengine/gltf/pbr"), import("@margoengine/gltf/splats")]), u = n.contentMatrix(i, r.type === "b3dm" ? r.rtcCenter : void 0, !0), d = [], f = await s.run(() => c(n.engine, r.gltf, {
136
+ signal: a,
137
+ decoders: { splats: { async attach(t, n, r, i) {
138
+ for (let { primitive: t, matrix: a } of r) d.push(l(n, t, { signal: i }).then((t) => o(t, e(u, a))));
139
+ return await Promise.all(d), [];
140
+ } } }
141
+ })), m;
142
+ try {
143
+ m = await Promise.all(d), a.throwIfAborted();
144
+ } catch (e) {
145
+ throw f.dispose(), e;
146
+ }
147
+ n.place(f.root, u), f.root.visible = !1;
148
+ let h = m.length ? await p(n) : void 0, g = h ? m.map((e) => h.add(e)) : [], _ = 0;
149
+ if (n.budget === "gpu") for (let { data: e } of m) _ += e.positions.length / 3 * 128 + (e.sphericalHarmonics?.byteLength ?? 0);
150
+ let v;
151
+ try {
152
+ v = await n.decorate?.({
153
+ kind: "splats",
154
+ model: f,
155
+ content: r,
156
+ tile: i,
157
+ signal: a,
158
+ fetch: n.fetch,
159
+ fade: (e, t) => {
160
+ for (let n of g) h.fade(n, e, t);
161
+ }
162
+ }), a.throwIfAborted();
163
+ } catch (e) {
164
+ v?.dispose();
165
+ for (let e of g) h.remove(e);
166
+ throw n.forget(f.root), f.dispose(), e;
167
+ }
168
+ return {
169
+ get bytes() {
170
+ return n.measure(f, r.byteLength) + _ + (v?.bytes ?? 0) + (n.budget === "gpu" ? g.reduce((e, t) => e + (t.range ? t.placed.data.positions.length / 3 * 4 : 0), 0) : 0);
171
+ },
172
+ get visible() {
173
+ return f.root.visible;
174
+ },
175
+ set visible(e) {
176
+ f.root.visible = e;
177
+ for (let t of g) h.show(t, e);
178
+ },
179
+ dispose: () => {
180
+ v?.dispose();
181
+ for (let e of g) h.remove(e);
182
+ n.forget(f.root), f.dispose();
183
+ }
184
+ };
185
+ };
186
+ //#endregion
187
+ export { i as SPLATS_PER_CLOUD, l as TileSplats, c as mergePlaced, o as placeSplats, m as splats, f as tileSplats };
@@ -0,0 +1,61 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ // @ts-ignore optional peer: its types apply when it is installed
3
+ import type { PBRModel, PBRPrimitive } from '@margoengine/gltf/pbr';
4
+ // @ts-ignore optional peer: its types apply when it is installed
5
+ import type { PBRInstances } from '@margoengine/gltf/pbr-instancing';
6
+ // @ts-ignore optional peer: its types apply when it is installed
7
+ import type { PointCloud } from '@margoengine/points';
8
+ import type { TilesDecorationContext, TilesContentDecoration } from './renderer.js';
9
+ /** An expression, literal, or first-matching ordered condition list. */
10
+ export type StyleExpression = string | number | boolean | {
11
+ conditions: readonly (readonly [string, string | number | boolean])[];
12
+ };
13
+ /** The visual properties of an OGC 3D Tiles style. Defaults: white, visible, 1 pixel. */
14
+ export interface TileStyleJSON {
15
+ color?: StyleExpression;
16
+ show?: StyleExpression;
17
+ pointSize?: StyleExpression;
18
+ /** Defines read feature properties directly, including properties having the same name. */
19
+ defines?: Readonly<Record<string, string>>;
20
+ meta?: Readonly<Record<string, StyleExpression>>;
21
+ }
22
+ /** One evaluated style, in sRGB RGBA; undefined means no condition matched. */
23
+ export interface FeatureStyle {
24
+ color?: readonly number[];
25
+ show?: boolean;
26
+ pointSize?: number;
27
+ meta: Readonly<Record<string, unknown>>;
28
+ }
29
+ /** Reusable live styling binding. Updating replaces the previous style; disposal restores the authored data. */
30
+ export interface TileStyleBinding extends Disposable {
31
+ update(style: TilesStyle): void;
32
+ dispose(): void;
33
+ }
34
+ /** Feature properties as an object or a property lookup (for example a BatchTable row). */
35
+ export type StyleProperties = Readonly<Record<string, unknown>> | ((name: string) => unknown);
36
+ /** Compiled, reusable OGC style with conditions, defines, vectors, math, strings and regular expressions. */
37
+ export declare class TilesStyle {
38
+ private readonly color;
39
+ private readonly show;
40
+ private readonly pointSize;
41
+ private readonly defines;
42
+ private readonly meta;
43
+ constructor(style?: TileStyleJSON);
44
+ /**
45
+ * Pass as TilesRenderer's `decorate` option. Reads b3dm batch properties, pnts BATCH_ID and point semantics,
46
+ * i3dm BATCH_ID and structural metadata attribute/implicit sets. Eviction releases every saved styling array.
47
+ */
48
+ readonly decorate: (context: TilesDecorationContext) => TilesContentDecoration;
49
+ /** Evaluates one feature; no properties yields the implicit single feature. Throws coded invalid for wrong output types. */
50
+ evaluate(properties?: StyleProperties): FeatureStyle;
51
+ /**
52
+ * Styles a loaded PBR model. Resolve properties per vertex (from a batch table, feature ID attribute or texture).
53
+ * Vertex RGB multiplies the authored colour in linear light. Hidden vertices discard in every surface pass.
54
+ * Bind before animation/deformation or shared geometry, as required by PBRModel.writeGeometry.
55
+ */
56
+ bindModel(model: PBRModel, properties: (primitive: PBRPrimitive, vertex: number) => StyleProperties): TileStyleBinding;
57
+ /** Styles points by their current cloud index. Use sourceIndex when mapping metadata of a spatially sorted cloud. */
58
+ bindPoints(cloud: PointCloud, properties: (point: number) => StyleProperties): TileStyleBinding;
59
+ /** Styles i3dm or glTF instance rows. Visibility uses a degenerate transform, retaining stable picking IDs. */
60
+ bindInstances(instances: PBRInstances, properties: (instance: number) => StyleProperties): TileStyleBinding;
61
+ }