@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.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +437 -2
- package/dist/bounds-CgKJT3Pg.js +161 -0
- package/dist/bounds.d.ts +66 -0
- package/dist/data-uri-DbGLVHq5.js +132 -0
- package/dist/data-uri.d.ts +2 -0
- package/dist/errors-D5_2oB8I.js +7 -0
- package/dist/fade.d.ts +34 -0
- package/dist/fade.js +129 -0
- package/dist/feature-texture.d.ts +19 -0
- package/dist/features.d.ts +78 -0
- package/dist/features.js +401 -0
- package/dist/formats-NNuOXg-1.js +390 -0
- package/dist/formats.d.ts +124 -0
- package/dist/glb-BU81jlYZ.js +25 -0
- package/dist/height.d.ts +20 -0
- package/dist/height.js +31 -0
- package/dist/i3dm.d.ts +16 -0
- package/dist/i3dm.js +85 -0
- package/dist/imagery.d.ts +108 -0
- package/dist/imagery.js +325 -0
- package/dist/implicit.d.ts +42 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +849 -0
- package/dist/ion.d.ts +106 -0
- package/dist/ion.js +152 -0
- package/dist/json-BQoirgm5.js +4 -0
- package/dist/matrix-DcI5oFrD.js +89 -0
- package/dist/matrix.d.ts +32 -0
- package/dist/memory.d.ts +44 -0
- package/dist/metadata.d.ts +147 -0
- package/dist/metadata.js +285 -0
- package/dist/properties.d.ts +94 -0
- package/dist/properties.js +320 -0
- package/dist/queue.d.ts +37 -0
- package/dist/raw-accessor.d.ts +4 -0
- package/dist/renderer.d.ts +193 -0
- package/dist/s2.d.ts +37 -0
- package/dist/s2.js +181 -0
- package/dist/scene-scope-DufD_3B6.js +42 -0
- package/dist/screen-door-CMv5Jko4.js +11 -0
- package/dist/shared/screen-door.d.ts +9 -0
- package/dist/splats.d.ts +80 -0
- package/dist/splats.js +187 -0
- package/dist/style.d.ts +61 -0
- package/dist/style.js +609 -0
- package/dist/terrain.d.ts +96 -0
- package/dist/terrain.js +434 -0
- package/dist/tileset.d.ts +316 -0
- package/dist/uv-transform.d.ts +11 -0
- package/dist/wgs84-C5btsGGY.js +18 -0
- package/dist/wgs84.d.ts +24 -0
- package/package.json +122 -4
package/dist/bounds.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** A tile's `boundingVolume` as it appears in tileset JSON. */
|
|
2
|
+
export interface BoundingVolumeJSON {
|
|
3
|
+
box?: readonly number[];
|
|
4
|
+
region?: readonly number[];
|
|
5
|
+
sphere?: readonly number[];
|
|
6
|
+
extensions?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Reads a bounding volume extension, such as `s2` from `@margoengine/tiles/s2` (3DTILES_bounding_volume_S2). Pass it in
|
|
10
|
+
* `boundingVolumes` of `Tileset.load` or `TilesRenderer.load`; a volume carrying the extension is then read by it,
|
|
11
|
+
* ignoring the tile transform as such extensions specify, and the tileset may list the extension as required.
|
|
12
|
+
*/
|
|
13
|
+
export interface BoundingVolumeExtension {
|
|
14
|
+
/** The extension's name in `boundingVolume.extensions` and `extensionsRequired`. */
|
|
15
|
+
readonly name: string;
|
|
16
|
+
/** The bounds of the extension object (a box in ECEF, with `split` for implicit tiling). Throws on invalid input. */
|
|
17
|
+
bounds(volume: unknown): TileBounds;
|
|
18
|
+
}
|
|
19
|
+
/** Bounds of implicit tile (level, x, y, z) below a root volume, for a volume that subdivides its own way. */
|
|
20
|
+
export type SplitBounds = (scheme: 'QUADTREE' | 'OCTREE', level: number, x: number, y: number, z: number) => TileBounds;
|
|
21
|
+
/** An oriented box (centre, three half-axis vectors) with its bounding sphere, in tileset coordinates. */
|
|
22
|
+
export declare class TileBounds {
|
|
23
|
+
/** Centre, x y z. */
|
|
24
|
+
readonly center: Float64Array;
|
|
25
|
+
/** Half-axes: 9 numbers, axis u then v then w. */
|
|
26
|
+
readonly halfAxes: Float64Array;
|
|
27
|
+
/** Radius of the bounding sphere around `center`. */
|
|
28
|
+
readonly radius: number;
|
|
29
|
+
/** The source region in radians and metres, kept for implicit subdivision; undefined for box and sphere. */
|
|
30
|
+
readonly region?: Float64Array;
|
|
31
|
+
/** True when built from a sphere (its box is the sphere's cube; distance uses the sphere). */
|
|
32
|
+
readonly sphere: boolean;
|
|
33
|
+
/** How an extension volume (such as an S2 cell) subdivides under implicit tiling; undefined for box, region, sphere. */
|
|
34
|
+
readonly split?: SplitBounds;
|
|
35
|
+
private readonly unit;
|
|
36
|
+
private readonly lengths;
|
|
37
|
+
constructor(center: ArrayLike<number>, halfAxes: ArrayLike<number>, options?: {
|
|
38
|
+
region?: ArrayLike<number>;
|
|
39
|
+
sphere?: number;
|
|
40
|
+
split?: SplitBounds;
|
|
41
|
+
});
|
|
42
|
+
/** Distance from a point to the volume; 0 inside. */
|
|
43
|
+
distanceTo(point: ArrayLike<number>): number;
|
|
44
|
+
/** True when the point is inside (or on) the volume. */
|
|
45
|
+
contains(point: ArrayLike<number>): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* False only when the volume is entirely outside one of the frustum planes: 24 numbers, 6 planes [a, b, c, d] with
|
|
48
|
+
* a x + b y + c z + d >= 0 inside (the layout of core's `camera.planes`). All-zero planes keep everything.
|
|
49
|
+
*/
|
|
50
|
+
intersectsFrustum(planes: ArrayLike<number>): boolean;
|
|
51
|
+
/** The 8 corners of the box. */
|
|
52
|
+
corners(): [number, number, number][];
|
|
53
|
+
}
|
|
54
|
+
/** A box volume [cx, cy, cz, ux, uy, uz, vx, vy, vz, wx, wy, wz] under a transform. */
|
|
55
|
+
export declare function boxBounds(box: ArrayLike<number>, transform?: ArrayLike<number>): TileBounds;
|
|
56
|
+
/** A sphere volume [cx, cy, cz, r] under a transform (the radius grows by the largest axis scale). */
|
|
57
|
+
export declare function sphereBounds(sphere: ArrayLike<number>, transform?: ArrayLike<number>): TileBounds;
|
|
58
|
+
/**
|
|
59
|
+
* A region [west, south, east, north, minimumHeight, maximumHeight] (radians, metres above WGS84) as an oriented box
|
|
60
|
+
* in ECEF. The box is aligned with the east-north-up frame at the region's centre and holds a 9 x 9 grid of surface
|
|
61
|
+
* samples at both heights, padded by the chord sag between samples, so it always contains the curved region. Regions
|
|
62
|
+
* ignore tile transforms (3D Tiles 1.1, "Region").
|
|
63
|
+
*/
|
|
64
|
+
export declare function regionBounds(region: ArrayLike<number>): TileBounds;
|
|
65
|
+
/** Builds the bounds of a `boundingVolume` under a tile's computed transform. */
|
|
66
|
+
export declare function createBounds(volume: BoundingVolumeJSON | undefined, transform?: ArrayLike<number>, extensions?: readonly BoundingVolumeExtension[]): TileBounds;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { MargoError as e } from "@margoengine/math/errors";
|
|
2
|
+
//#region ../shared/accessor.js
|
|
3
|
+
var t = /* @__PURE__ */ Object.freeze({
|
|
4
|
+
__proto__: null,
|
|
5
|
+
SCALAR: 1,
|
|
6
|
+
VEC2: 2,
|
|
7
|
+
VEC3: 3,
|
|
8
|
+
VEC4: 4,
|
|
9
|
+
MAT2: 4,
|
|
10
|
+
MAT3: 9,
|
|
11
|
+
MAT4: 16
|
|
12
|
+
}), n = {
|
|
13
|
+
__proto__: null,
|
|
14
|
+
5120: 1,
|
|
15
|
+
5121: 1,
|
|
16
|
+
5122: 2,
|
|
17
|
+
5123: 2,
|
|
18
|
+
5125: 4,
|
|
19
|
+
5126: 4
|
|
20
|
+
};
|
|
21
|
+
function r(e, t, n) {
|
|
22
|
+
return n === 5126 ? e.getFloat32(t, !0) : n === 5125 ? e.getUint32(t, !0) : n === 5123 ? e.getUint16(t, !0) : n === 5122 ? e.getInt16(t, !0) : n === 5121 ? e.getUint8(t) : e.getInt8(t);
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/raw-accessor.ts
|
|
26
|
+
function i(i, a, o) {
|
|
27
|
+
let s = i.doc.accessors?.[a];
|
|
28
|
+
if (!s) throw TypeError("Property accessor is missing; correct the primitive attribute index");
|
|
29
|
+
let c = n[s.componentType], l = t[s.type], u = s.count;
|
|
30
|
+
if (!c || !l || !Number.isInteger(u) || u < 0) throw TypeError("Property accessor has an invalid component type, shape or count; re-export valid glTF");
|
|
31
|
+
let d = u * l * c, f = o.maximumDecodedBytes ?? i.maxBytes * 4;
|
|
32
|
+
if (!Number.isSafeInteger(d) || !Number.isFinite(f) || f < 0 || d > f) throw RangeError("Property accessor exceeds the decoded byte limit; reduce the data or raise maximumDecodedBytes");
|
|
33
|
+
let p = o.accessor?.(a);
|
|
34
|
+
if (p) {
|
|
35
|
+
if (p.length !== d) throw RangeError("Decoded property accessor byte count is wrong; supply tightly packed components");
|
|
36
|
+
return p;
|
|
37
|
+
}
|
|
38
|
+
let m = new Uint8Array(d), h = s.type.startsWith("MAT") ? Number(s.type[3]) : 0, g = h ? Math.ceil(h * c / 4) * 4 : 0, _ = h ? h * g : l * c, v = (e, t, n, r, i) => {
|
|
39
|
+
if (!Number.isInteger(t) || t < 0 || t % c || !Number.isInteger(n) || n < _ || n % c || h && t % 4 || r > 0 && t + (r - 1) * n + _ > e.length) throw RangeError("Property accessor runs past its buffer view or is unaligned; correct its offsets/count/stride");
|
|
40
|
+
for (let a = 0; a < r; a++) for (let r = 0; r < l; r++) {
|
|
41
|
+
let o = t + a * n + (h ? Math.floor(r / h) * g + r % h * c : r * c);
|
|
42
|
+
m.set(e.subarray(o, o + c), ((i?.[a] ?? a) * l + r) * c);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
if (s.bufferView !== void 0) v(i.view(s.bufferView), s.byteOffset ?? 0, i.doc.bufferViews?.[s.bufferView]?.byteStride ?? _, u);
|
|
46
|
+
else if (i.doc.meshes?.some((e) => e.primitives.some((e) => e.extensions?.KHR_draco_mesh_compression && Object.values(e.attributes ?? {}).includes(a)))) {
|
|
47
|
+
if (s.componentType === 5125) throw new e("state", "Decoded UINT32 metadata can lose integer precision in the float accessor cache; supply original packed accessor bytes");
|
|
48
|
+
let t = i.accessor(a), n = new DataView(m.buffer), r = {
|
|
49
|
+
5120: 127,
|
|
50
|
+
5121: 255,
|
|
51
|
+
5122: 32767,
|
|
52
|
+
5123: 65535,
|
|
53
|
+
5125: 4294967295
|
|
54
|
+
};
|
|
55
|
+
if (t.length !== u * l) throw RangeError("Decoded property accessor count is wrong; complete geometry decoding or provide packed accessor bytes");
|
|
56
|
+
t.forEach((t, i) => {
|
|
57
|
+
if (s.normalized) {
|
|
58
|
+
if (t === -1) throw new e("state", "Decoded signed normalized metadata has ambiguous raw sentinel bits; supply original packed accessor bytes");
|
|
59
|
+
t = Math.round(t * r[s.componentType]);
|
|
60
|
+
}
|
|
61
|
+
let a = i * c;
|
|
62
|
+
s.componentType === 5126 ? n.setFloat32(a, t, !0) : s.componentType === 5120 ? n.setInt8(a, t) : s.componentType === 5121 ? n.setUint8(a, t) : s.componentType === 5122 ? n.setInt16(a, t, !0) : s.componentType === 5123 ? n.setUint16(a, t, !0) : n.setUint32(a, t, !0);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (s.sparse) {
|
|
66
|
+
let e = s.sparse, t = e.indices, a = n[t.componentType], o = i.view(t.bufferView), c = new DataView(o.buffer, o.byteOffset, o.byteLength), l = t.byteOffset ?? 0;
|
|
67
|
+
if (![
|
|
68
|
+
5121,
|
|
69
|
+
5123,
|
|
70
|
+
5125
|
|
71
|
+
].includes(t.componentType) || !Number.isInteger(l) || l < 0 || l % a || !Number.isInteger(e.count) || e.count < 1 || l + e.count * a > o.length || e.count > u) throw RangeError("Sparse property indices are invalid; correct sparse count and index storage");
|
|
72
|
+
let d = [];
|
|
73
|
+
for (let n = 0; n < e.count; n++) {
|
|
74
|
+
let e = r(c, l + n * a, t.componentType);
|
|
75
|
+
if (e >= u || n > 0 && e <= d[n - 1]) throw RangeError("Sparse property indices must increase within the accessor count; correct the sparse indices");
|
|
76
|
+
d.push(e);
|
|
77
|
+
}
|
|
78
|
+
v(i.view(e.values.bufferView), e.values.byteOffset ?? 0, _, e.count, d);
|
|
79
|
+
}
|
|
80
|
+
return m;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/uv-transform.ts
|
|
84
|
+
function a(e, t, n) {
|
|
85
|
+
let r = Math.cos(n), i = Math.sin(n);
|
|
86
|
+
return [
|
|
87
|
+
r * e[0],
|
|
88
|
+
i * e[1],
|
|
89
|
+
t[0],
|
|
90
|
+
-i * e[0],
|
|
91
|
+
r * e[1],
|
|
92
|
+
t[1]
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
function o(e, t, n) {
|
|
96
|
+
return [e[0] * t + e[1] * n + e[2], e[3] * t + e[4] * n + e[5]];
|
|
97
|
+
}
|
|
98
|
+
function s(e, t) {
|
|
99
|
+
let n = (e) => Number.isInteger(e) ? `${e}.0` : `${e}`;
|
|
100
|
+
return `(vec2f(dot(vec2f(${n(e[0])},${n(e[1])}),${t})+${n(e[2])},dot(vec2f(${n(e[3])},${n(e[4])}),${t})+${n(e[5])}))`;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/data-uri.ts
|
|
104
|
+
function c(e, t) {
|
|
105
|
+
if (!e.startsWith("data:")) return;
|
|
106
|
+
let n = e.indexOf(",");
|
|
107
|
+
if (n < 0) throw TypeError("Metadata data URI has no comma; provide a complete encoded resource");
|
|
108
|
+
let r = e.slice(n + 1);
|
|
109
|
+
if (e.slice(0, n).includes(";base64")) {
|
|
110
|
+
let e = r.replace(/\s/g, "");
|
|
111
|
+
if (Math.floor(e.length * 3 / 4) - (e.endsWith("==") ? 2 : +!!e.endsWith("=")) > t) throw RangeError("Metadata data URI exceeds maximumBytes; reduce the embedded resource or raise its byte limit");
|
|
112
|
+
let n = atob(e);
|
|
113
|
+
return Uint8Array.from(n, (e) => e.charCodeAt(0));
|
|
114
|
+
}
|
|
115
|
+
let i = new Uint8Array(Math.min(t, r.length * 3)), a = 0;
|
|
116
|
+
for (let e = 0; e < r.length;) {
|
|
117
|
+
let t;
|
|
118
|
+
if (r[e] === "%") {
|
|
119
|
+
let n = r.slice(e + 1, e + 3);
|
|
120
|
+
if (!/^[\da-f]{2}$/i.test(n)) throw TypeError("Metadata data URI has an invalid escape; percent-encode complete bytes");
|
|
121
|
+
t = Uint8Array.of(parseInt(n, 16)), e += 3;
|
|
122
|
+
} else {
|
|
123
|
+
let n = r.codePointAt(e);
|
|
124
|
+
t = new TextEncoder().encode(String.fromCodePoint(n)), e += n > 65535 ? 2 : 1;
|
|
125
|
+
}
|
|
126
|
+
if (a + t.length > i.length) throw RangeError("Metadata data URI exceeds maximumBytes; reduce the embedded resource or raise its byte limit");
|
|
127
|
+
i.set(t, a), a += t.length;
|
|
128
|
+
}
|
|
129
|
+
return i.subarray(0, a);
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
export { i as a, s as i, o as n, t as o, a as r, c as t };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region ../shared/errors.js
|
|
2
|
+
var e = (e, t) => Object.assign(Error(t), {
|
|
3
|
+
name: "MargoError",
|
|
4
|
+
code: e
|
|
5
|
+
}), t = (e, t) => `${e}; see https://margoengine.com/errors#${t}`, n = (e, n) => TypeError(t(e, n)), r = (e, n) => RangeError(t(e, n));
|
|
6
|
+
//#endregion
|
|
7
|
+
export { r as n, n as r, e as t };
|
package/dist/fade.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { TilesRenderer, TilesContentDecorator } from './renderer.js';
|
|
3
|
+
/** Tile replacement fade options. */
|
|
4
|
+
export interface TilesFadeOptions {
|
|
5
|
+
/** Seconds for a complete replacement. Default 0.3. */
|
|
6
|
+
duration?: number;
|
|
7
|
+
/** Monotonic seconds. Default performance.now()/1000. Supply a simulation clock for replay. */
|
|
8
|
+
clock?: () => number;
|
|
9
|
+
/** Preceding style or feature decoration, owned with the same content. */
|
|
10
|
+
decorate?: TilesContentDecorator;
|
|
11
|
+
}
|
|
12
|
+
/** Hierarchical screen-door cross-fade of replacement tiles, including meshes, points and sorted splats. */
|
|
13
|
+
export declare class TilesFade implements Disposable {
|
|
14
|
+
private readonly options;
|
|
15
|
+
private readonly bindings;
|
|
16
|
+
private readonly states;
|
|
17
|
+
private stop?;
|
|
18
|
+
private renderer?;
|
|
19
|
+
private disposed;
|
|
20
|
+
private started;
|
|
21
|
+
private last;
|
|
22
|
+
private readonly duration;
|
|
23
|
+
private readonly clock;
|
|
24
|
+
constructor(options?: TilesFadeOptions);
|
|
25
|
+
/** Observes a renderer after load, before its first selection update. */
|
|
26
|
+
attach(renderer: TilesRenderer): this;
|
|
27
|
+
/** Registers content while loading. Pass this callback to TilesRenderer.load as decorate. */
|
|
28
|
+
readonly decorate: TilesContentDecorator;
|
|
29
|
+
private select;
|
|
30
|
+
/** Removes the selection observer and restores full content coverage. */
|
|
31
|
+
dispose(): void;
|
|
32
|
+
[Symbol.dispose](): void;
|
|
33
|
+
}
|
|
34
|
+
export { ditherRank } from './shared/screen-door.js';
|
package/dist/fade.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { n as e, r as t } from "./screen-door-CMv5Jko4.js";
|
|
2
|
+
import { MargoError as n } from "@margoengine/math/errors";
|
|
3
|
+
//#region src/fade.ts
|
|
4
|
+
var r = class {
|
|
5
|
+
constructor(e = {}) {
|
|
6
|
+
if (this.options = e, this.bindings = /* @__PURE__ */ new Map(), this.states = /* @__PURE__ */ new Map(), this.disposed = !1, this.started = !1, this.last = -Infinity, this.decorate = async (e) => {
|
|
7
|
+
if (this.disposed) throw new n("disposed", "TilesFade is disposed; create a new controller");
|
|
8
|
+
let r = await this.options.decorate?.(e), i = [];
|
|
9
|
+
if (this.disposed || e.signal?.aborted) throw r?.dispose(), e.signal?.throwIfAborted(), new n("disposed", "TilesFade is disposed; create a new controller");
|
|
10
|
+
if (e.kind === "model" || e.kind === "instances" || e.kind === "splats") for (let n of e.model.primitives) {
|
|
11
|
+
let e = n.extension, r = (e?.factors?.length ?? 0) / 4, a = new Float32Array((e?.factors?.length ?? 0) + 4);
|
|
12
|
+
a.set(e?.factors ?? []), a.set([
|
|
13
|
+
0,
|
|
14
|
+
1,
|
|
15
|
+
0,
|
|
16
|
+
0
|
|
17
|
+
], r * 4);
|
|
18
|
+
let o = `tileDither${r}`, s = `
|
|
19
|
+
// ${o}
|
|
20
|
+
let ${o}Value=(f32(margoDitherRank(i.clip.xy))+0.5)/16.0;
|
|
21
|
+
if(${o}Value<materialFactors[${r}].x || ${o}Value>=materialFactors[${r}].y){discard;}
|
|
22
|
+
`, c = {
|
|
23
|
+
...e,
|
|
24
|
+
factors: a,
|
|
25
|
+
declarations: (e?.declarations ?? "") + (e?.declarations?.includes("fn margoDitherRank") ? "" : t),
|
|
26
|
+
wgsl: (e?.wgsl ?? "") + s
|
|
27
|
+
};
|
|
28
|
+
n.extension = c, i.push({
|
|
29
|
+
p: n,
|
|
30
|
+
base: e,
|
|
31
|
+
extension: c,
|
|
32
|
+
offset: r,
|
|
33
|
+
marker: o
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
let a = {
|
|
37
|
+
context: e,
|
|
38
|
+
prior: r,
|
|
39
|
+
meshes: i,
|
|
40
|
+
set: (t, n) => {
|
|
41
|
+
for (let e of i) {
|
|
42
|
+
e.extension.factors?.set([t, n], e.offset * 4);
|
|
43
|
+
let r = e.p.extension;
|
|
44
|
+
r?.wgsl?.includes(e.marker) && r.factors && r.factors.set([t, n], e.offset * 4);
|
|
45
|
+
}
|
|
46
|
+
e.kind === "points" && (e.cloud.material.ditherFade = [t, n]), e.kind === "splats" && e.fade(t, n);
|
|
47
|
+
}
|
|
48
|
+
}, o = this.bindings.get(e.tile);
|
|
49
|
+
o || this.bindings.set(e.tile, o = /* @__PURE__ */ new Set()), o.add(a);
|
|
50
|
+
let s = !1;
|
|
51
|
+
return {
|
|
52
|
+
get bytes() {
|
|
53
|
+
return (r?.bytes ?? 0) + i.reduce((e, t) => e + (t.p.extension?.wgsl?.includes(t.marker) ? 16 : 0), 0);
|
|
54
|
+
},
|
|
55
|
+
dispose: () => {
|
|
56
|
+
if (!s) {
|
|
57
|
+
s = !0, a.set(0, 1);
|
|
58
|
+
for (let e of i) e.p.extension === e.extension && (e.p.extension = e.base);
|
|
59
|
+
e.kind === "points" && (e.cloud.material.ditherFade = void 0), o.delete(a), o.size || (this.bindings.delete(e.tile), this.states.delete(e.tile)), r?.dispose();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}, this.duration = e.duration ?? .3, this.clock = e.clock ?? (() => performance.now() / 1e3), !Number.isFinite(this.duration) || this.duration <= 0) throw RangeError("Tile fade duration must be finite and positive; supply seconds above zero");
|
|
64
|
+
}
|
|
65
|
+
attach(e) {
|
|
66
|
+
if (this.disposed) throw new n("disposed", "TilesFade is disposed; create a new controller");
|
|
67
|
+
if (this.renderer) throw new n("attached", "TilesFade already has a renderer; create one controller per renderer");
|
|
68
|
+
return this.renderer = e, this.stop = e.tileset.on("selection", ({ selected: e }) => this.select(e)), this;
|
|
69
|
+
}
|
|
70
|
+
select(e) {
|
|
71
|
+
if (this.disposed) return;
|
|
72
|
+
let t = this.clock();
|
|
73
|
+
if (!Number.isFinite(t) || t < this.last) throw RangeError("Tile fade clock must be finite and monotonic; supply advancing seconds");
|
|
74
|
+
this.last = t;
|
|
75
|
+
let n = new Set(e), r = /* @__PURE__ */ new Set();
|
|
76
|
+
for (let t of e) for (let e = t; e; e = e.parent) r.add(e);
|
|
77
|
+
let i = (e) => {
|
|
78
|
+
let i = this.states.get(e), a = n.has(e) ? 1 : r.has(e) ? 0 : void 0;
|
|
79
|
+
if (!i) {
|
|
80
|
+
let n = a === void 0 || this.started ? 1 : a;
|
|
81
|
+
i = {
|
|
82
|
+
value: n,
|
|
83
|
+
from: n,
|
|
84
|
+
target: a ?? n,
|
|
85
|
+
time: t
|
|
86
|
+
}, this.states.set(e, i);
|
|
87
|
+
}
|
|
88
|
+
return i.value = i.from + (i.target - i.from) * Math.min(1, (t - i.time) / this.duration), a !== void 0 && a !== i.target && (i.from = i.value, i.target = a, i.time = t), i.value;
|
|
89
|
+
}, a = (e, t, o, s = !1) => {
|
|
90
|
+
let c = r.has(e) || s && this.states.has(e), l = this.bindings.has(e), u = l && c ? i(e) : 0;
|
|
91
|
+
if (!c) {
|
|
92
|
+
e.renderable && (e.renderable.visible = !1);
|
|
93
|
+
for (let t of e.children) a(t, 0, 0, !1);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (e.refine === "ADD") {
|
|
97
|
+
let r = n.has(e);
|
|
98
|
+
for (let t of this.bindings.get(e) ?? []) t.set(0, 1);
|
|
99
|
+
e.renderable && (e.renderable.visible = r);
|
|
100
|
+
for (let r of e.children) a(r, t, o, s || n.has(e));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
let d = t + (o - t) * (1 - u), f = l && o > d && r.has(this.renderer.tileset.root);
|
|
104
|
+
for (let t of this.bindings.get(e) ?? []) t.set(d, o);
|
|
105
|
+
e.renderable && (e.renderable.visible = f);
|
|
106
|
+
for (let r of e.children) a(r, t, d, s || n.has(e));
|
|
107
|
+
};
|
|
108
|
+
a(this.renderer.tileset.root, 0, +!!r.size), this.started = !0;
|
|
109
|
+
}
|
|
110
|
+
dispose() {
|
|
111
|
+
if (!this.disposed) {
|
|
112
|
+
this.disposed = !0, this.stop?.();
|
|
113
|
+
for (let [e, t] of this.bindings) {
|
|
114
|
+
for (let e of t) {
|
|
115
|
+
e.set(0, 1);
|
|
116
|
+
for (let t of e.meshes) t.p.extension === t.extension && (t.p.extension = t.base);
|
|
117
|
+
e.context.kind === "points" && (e.context.cloud.material.ditherFade = void 0);
|
|
118
|
+
}
|
|
119
|
+
e.renderable && (e.renderable.visible = this.renderer?.last.selected.includes(e) ?? !1);
|
|
120
|
+
}
|
|
121
|
+
this.states.clear();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
[Symbol.dispose]() {
|
|
125
|
+
this.dispose();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
//#endregion
|
|
129
|
+
export { r as TilesFade, e as ditherRank };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Unmodified linear RGBA8 texels, top row first (glTF v=0). */
|
|
2
|
+
export interface FeatureImage {
|
|
3
|
+
readonly width: number;
|
|
4
|
+
readonly height: number;
|
|
5
|
+
readonly data: Uint8Array | Uint8ClampedArray;
|
|
6
|
+
}
|
|
7
|
+
/** glTF texture addressing mode: clamp, mirrored repeat or repeat (default). */
|
|
8
|
+
export type TextureWrap = 33071 | 33648 | 10497;
|
|
9
|
+
/** Validates RGBA8 storage before picking, rendering or property decoding. */
|
|
10
|
+
export declare function checkFeatureImage(image: FeatureImage): void;
|
|
11
|
+
/** Samples a nearest texel with glTF addressing and no colour conversion. */
|
|
12
|
+
export declare function metadataTexel(image: FeatureImage, uv: readonly number[], wrapS?: TextureWrap, wrapT?: TextureWrap): Uint8Array;
|
|
13
|
+
/** Decodes 1..4 selected channels as a little-endian unsigned ID, retaining all 32 bits. */
|
|
14
|
+
export declare function textureFeatureId(texel: ArrayLike<number>, channels?: readonly number[]): number;
|
|
15
|
+
/** Reads a decoded browser image without sRGB conversion or alpha premultiplication by the metadata layer. */
|
|
16
|
+
export declare function featureImage(source: {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
}): FeatureImage;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel, EnginePlugin } from '@margoengine/core';
|
|
3
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
4
|
+
import type { PBRModel, PBRPrimitive } from '@margoengine/gltf/pbr';
|
|
5
|
+
import type { TilesDecorationContext, TilesContentDecoration, TilesContentDecorator } from './renderer.js';
|
|
6
|
+
import type { TilesetTile } from './tileset.js';
|
|
7
|
+
import { type FeatureImage } from './feature-texture.js';
|
|
8
|
+
/** A model ray hit, as returned by the optional bvh package. No bvh runtime is imported here. */
|
|
9
|
+
export interface TileFeaturePick {
|
|
10
|
+
readonly model?: unknown;
|
|
11
|
+
readonly primitive?: unknown;
|
|
12
|
+
readonly primitiveIndex?: number;
|
|
13
|
+
readonly faceIndex: number;
|
|
14
|
+
readonly barycoord: readonly number[];
|
|
15
|
+
readonly instanceId?: number;
|
|
16
|
+
}
|
|
17
|
+
/** A picked feature. IDs are scoped to content and feature set, rather than being global scene IDs. */
|
|
18
|
+
export interface TileFeature {
|
|
19
|
+
readonly id: number;
|
|
20
|
+
readonly set: number;
|
|
21
|
+
readonly label?: string;
|
|
22
|
+
readonly tile: TilesetTile;
|
|
23
|
+
readonly model: PBRModel;
|
|
24
|
+
readonly primitive: PBRPrimitive;
|
|
25
|
+
readonly properties: Readonly<Record<string, unknown>>;
|
|
26
|
+
}
|
|
27
|
+
/** Feature controller options. */
|
|
28
|
+
export interface TileFeaturesOptions {
|
|
29
|
+
/** Feature set index or label. Default: first set. */
|
|
30
|
+
set?: number | string;
|
|
31
|
+
/** Original packed bytes for precision-sensitive decoded feature accessors. */
|
|
32
|
+
accessor?: (model: PBRModel, index: number) => Uint8Array | undefined;
|
|
33
|
+
/** Optional preceding decoration, such as TilesStyle.decorate. Its lifetime follows the same tile. */
|
|
34
|
+
decorate?: TilesContentDecorator;
|
|
35
|
+
/** Supply original linear RGBA8 data for a texture. Default: retained model image decoded with Canvas 2D. */
|
|
36
|
+
image?: (model: PBRModel, texture: number) => FeatureImage | Promise<FeatureImage>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Streaming feature resolution and highlight. Pass `decorate` to TilesRenderer and feed `resolve` a model ray hit.
|
|
40
|
+
* The controller owns no picking engine: bvh's existing raycasts supply the surface hit and instance row.
|
|
41
|
+
*/
|
|
42
|
+
export declare class TileFeatures implements EnginePlugin, Disposable {
|
|
43
|
+
private readonly engine;
|
|
44
|
+
private readonly options;
|
|
45
|
+
/** Creates a registered feature controller. Defaults match the constructor. */
|
|
46
|
+
static attach(engine: EngineKernel, options?: TileFeaturesOptions): TileFeatures;
|
|
47
|
+
readonly name: string;
|
|
48
|
+
private readonly entries;
|
|
49
|
+
private disposed;
|
|
50
|
+
private current?;
|
|
51
|
+
private readonly images;
|
|
52
|
+
constructor(engine: EngineKernel, options?: TileFeaturesOptions);
|
|
53
|
+
setup(engine: EngineKernel): void;
|
|
54
|
+
private check;
|
|
55
|
+
/** Registers loaded content, and removes it before eviction. Uses the existing renderer decorator hook. */
|
|
56
|
+
readonly decorate: (context: TilesDecorationContext) => Promise<TilesContentDecoration>;
|
|
57
|
+
private rawIds;
|
|
58
|
+
private selected;
|
|
59
|
+
private image;
|
|
60
|
+
private prepareImage;
|
|
61
|
+
private uv;
|
|
62
|
+
private transformed;
|
|
63
|
+
private id;
|
|
64
|
+
/** Resolves vertex/texture feature sets, b3dm batch IDs and i3dm instance IDs from a surface hit. Null IDs return undefined. */
|
|
65
|
+
resolve(hit: TileFeaturePick): TileFeature | undefined;
|
|
66
|
+
private restore;
|
|
67
|
+
/** Clears the current highlight, restoring the authored/styled surface exactly. */
|
|
68
|
+
clear(): void;
|
|
69
|
+
/** Highlights a picked feature with a linear-light multiply of the given sRGB RGBA. White restores its appearance. */
|
|
70
|
+
highlight(feature: TileFeature, color?: readonly number[]): void;
|
|
71
|
+
private highlightTexture;
|
|
72
|
+
private highlightAttribute;
|
|
73
|
+
onDeviceRestored(): void;
|
|
74
|
+
/** Releases content records and highlight resources, leaving the tiles and their prior decorator owned by the renderer. */
|
|
75
|
+
dispose(): void;
|
|
76
|
+
[Symbol.dispose](): void;
|
|
77
|
+
}
|
|
78
|
+
export { type FeatureImage, textureFeatureId, metadataTexel } from './feature-texture.js';
|