@spacexr/3d-tiles-runtime 0.0.0-stage → 0.1.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 (78) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +93 -2
  3. package/dist/chunk-AI6NWGCA.js +316 -0
  4. package/dist/chunk-AI6NWGCA.js.map +1 -0
  5. package/dist/chunk-G7YVZYMR.js +24 -0
  6. package/dist/chunk-G7YVZYMR.js.map +1 -0
  7. package/dist/chunk-PJIVVIOF.js +205 -0
  8. package/dist/chunk-PJIVVIOF.js.map +1 -0
  9. package/dist/chunk-Q2AL6LWU.js +3 -0
  10. package/dist/chunk-Q2AL6LWU.js.map +1 -0
  11. package/dist/chunk-Q35HKP5V.js +249 -0
  12. package/dist/chunk-Q35HKP5V.js.map +1 -0
  13. package/dist/chunk-URZDM4BH.js +488 -0
  14. package/dist/chunk-URZDM4BH.js.map +1 -0
  15. package/dist/implicit/index.d.ts +64 -0
  16. package/dist/implicit/index.js +4 -0
  17. package/dist/implicit/index.js.map +1 -0
  18. package/dist/index-CNnPRQZc.d.ts +350 -0
  19. package/dist/index.d.ts +713 -0
  20. package/dist/index.js +3074 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/metadata/index.d.ts +12 -0
  23. package/dist/metadata/index.js +3 -0
  24. package/dist/metadata/index.js.map +1 -0
  25. package/dist/pipeline/index.d.ts +5 -0
  26. package/dist/pipeline/index.js +3 -0
  27. package/dist/pipeline/index.js.map +1 -0
  28. package/dist/ports/index.d.ts +62 -0
  29. package/dist/ports/index.js +4 -0
  30. package/dist/ports/index.js.map +1 -0
  31. package/dist/resource-DH72MRMN.d.ts +34 -0
  32. package/dist/spatial/index.d.ts +402 -0
  33. package/dist/spatial/index.js +3 -0
  34. package/dist/spatial/index.js.map +1 -0
  35. package/dist/spatial-3IDPbyv4.d.ts +28 -0
  36. package/dist/types-Dn5i8Uqg.d.ts +78 -0
  37. package/dist/types-ri64XfSE.d.ts +237 -0
  38. package/package.json +102 -5
  39. package/src/implicit/availability.ts +55 -0
  40. package/src/implicit/coordinates.ts +193 -0
  41. package/src/implicit/dense-subtree-loader.ts +23 -0
  42. package/src/implicit/index.ts +6 -0
  43. package/src/implicit/standard-subtree-loader.ts +71 -0
  44. package/src/implicit/tile-data-source.ts +120 -0
  45. package/src/implicit/types.ts +156 -0
  46. package/src/index.ts +6 -0
  47. package/src/metadata/index.ts +2 -0
  48. package/src/metadata/metadata-resolver.ts +308 -0
  49. package/src/metadata/types.ts +91 -0
  50. package/src/pipeline/index.ts +4 -0
  51. package/src/pipeline/metadata-store.ts +44 -0
  52. package/src/pipeline/ports.ts +62 -0
  53. package/src/pipeline/states.ts +56 -0
  54. package/src/pipeline/tile-3d.ts +165 -0
  55. package/src/ports/camera.ts +12 -0
  56. package/src/ports/content.ts +71 -0
  57. package/src/ports/glyph.ts +13 -0
  58. package/src/ports/index.ts +32 -0
  59. package/src/ports/resource.ts +54 -0
  60. package/src/ports/spatial.ts +28 -0
  61. package/src/ports/telemetry.ts +44 -0
  62. package/src/runtime/cache.ts +112 -0
  63. package/src/runtime/contracts.ts +77 -0
  64. package/src/runtime/events.ts +57 -0
  65. package/src/runtime/hooks.ts +99 -0
  66. package/src/runtime/index.ts +7 -0
  67. package/src/runtime/instrumentation.ts +163 -0
  68. package/src/runtime/priority-scheduler.ts +88 -0
  69. package/src/runtime/quadtree-balance.ts +215 -0
  70. package/src/runtime/tile-runtime.ts +3508 -0
  71. package/src/spatial/bounding-volumes.ts +159 -0
  72. package/src/spatial/ecef-types.ts +110 -0
  73. package/src/spatial/ecef.ts +196 -0
  74. package/src/spatial/index.ts +6 -0
  75. package/src/spatial/utm-bounds.ts +151 -0
  76. package/src/spatial/utm-types.ts +83 -0
  77. package/src/spatial/vertical-scale.ts +125 -0
  78. package/src/spatial/view-metrics.ts +132 -0
@@ -0,0 +1,91 @@
1
+ import type {
2
+ IContent,
3
+ IMetadataClass,
4
+ IMetadataClassProperty,
5
+ IMetadataEntity,
6
+ IMetadataSchema,
7
+ ITile,
8
+ ITileset,
9
+ MetadataValue,
10
+ } from "@spacexr/3d-tiles-core";
11
+
12
+ export type MetadataDiagnosticSeverity = "info" | "warning" | "error";
13
+
14
+ export interface IMetadataDiagnostic {
15
+ code: string;
16
+ severity: MetadataDiagnosticSeverity;
17
+ message: string;
18
+ path: string;
19
+ documentUri: string;
20
+ }
21
+
22
+ export type MetadataScopeKind = "tileset" | "subtree" | "ancestor-tile" | "tile" | "group" | "content" | "feature";
23
+
24
+ export interface IRuntimeFeatureMetadata {
25
+ id?: string | number;
26
+ entity: IMetadataEntity;
27
+ schema?: IMetadataSchema;
28
+ sourceUri?: string;
29
+ }
30
+
31
+ export interface IMetadataDocumentContext {
32
+ uri: string;
33
+ tileset: ITileset;
34
+ schema?: IMetadataSchema;
35
+ schemaUri?: string;
36
+ diagnostics: readonly IMetadataDiagnostic[];
37
+ }
38
+
39
+ export interface IResolvedMetadataProperty {
40
+ id: string;
41
+ definition?: IMetadataClassProperty;
42
+ semantic?: string;
43
+ rawValue?: MetadataValue;
44
+ value?: MetadataValue;
45
+ fromDefault: boolean;
46
+ isNoData: boolean;
47
+ }
48
+
49
+ export interface IResolvedMetadataEntity {
50
+ scope: MetadataScopeKind;
51
+ ownerId: string;
52
+ documentUri: string;
53
+ featureId?: string | number;
54
+ entity: IMetadataEntity;
55
+ classId: string;
56
+ classDefinition?: IMetadataClass;
57
+ properties: Readonly<Record<string, IResolvedMetadataProperty>>;
58
+ diagnostics: readonly IMetadataDiagnostic[];
59
+ }
60
+
61
+ export interface IMetadataAncestorInput {
62
+ id: string;
63
+ tile: ITile;
64
+ document: IMetadataDocumentContext;
65
+ }
66
+
67
+ /**
68
+ * Metadata scopes are deliberately kept separate. The 3D Tiles specification
69
+ * does not define implicit inheritance between tileset, group, tile, content
70
+ * and feature metadata.
71
+ */
72
+ export interface IMetadataSnapshot {
73
+ document: IMetadataDocumentContext;
74
+ tileId: string;
75
+ tile: ITile;
76
+ content?: IContent;
77
+ scopes: readonly IResolvedMetadataEntity[];
78
+ diagnostics: readonly IMetadataDiagnostic[];
79
+ }
80
+
81
+ export interface IMetadataResolutionInput {
82
+ document: IMetadataDocumentContext;
83
+ tileId: string;
84
+ tile: ITile;
85
+ ancestors: readonly IMetadataAncestorInput[];
86
+ subtree?: { id: string; entity: IMetadataEntity; documentUri: string };
87
+ content?: IContent;
88
+ features?: readonly IRuntimeFeatureMetadata[];
89
+ }
90
+
91
+ export type MetadataScopeOrder = readonly MetadataScopeKind[];
@@ -0,0 +1,4 @@
1
+ export * from "./metadata-store";
2
+ export * from "./ports";
3
+ export * from "./states";
4
+ export * from "./tile-3d";
@@ -0,0 +1,44 @@
1
+ import type { IMetadataSnapshot } from "../metadata/types";
2
+ import { NO_METADATA, type MetadataHandle } from "./states";
3
+
4
+ export interface IMetadataStore {
5
+ readonly size: number;
6
+ register(snapshot: IMetadataSnapshot): MetadataHandle;
7
+ get(handle: MetadataHandle): IMetadataSnapshot;
8
+ tryGet(handle: MetadataHandle): IMetadataSnapshot | undefined;
9
+ release(handle: MetadataHandle): void;
10
+ clear(): void;
11
+ }
12
+
13
+ /** Compact handle store shared by tiles, contents and renderer adapters. */
14
+ export class RuntimeMetadataStore implements IMetadataStore {
15
+ private readonly snapshots: Array<IMetadataSnapshot | undefined> = [];
16
+
17
+ public get size(): number {
18
+ return this.snapshots.length;
19
+ }
20
+
21
+ public register(snapshot: IMetadataSnapshot): MetadataHandle {
22
+ const handle = this.snapshots.length;
23
+ this.snapshots.push(snapshot);
24
+ return handle;
25
+ }
26
+
27
+ public get(handle: MetadataHandle): IMetadataSnapshot {
28
+ const snapshot = this.tryGet(handle);
29
+ if (!snapshot) throw new RangeError(`Metadata handle ${handle} is not available.`);
30
+ return snapshot;
31
+ }
32
+
33
+ public tryGet(handle: MetadataHandle): IMetadataSnapshot | undefined {
34
+ return handle === NO_METADATA ? undefined : this.snapshots[handle];
35
+ }
36
+
37
+ public release(handle: MetadataHandle): void {
38
+ if (handle !== NO_METADATA && handle >= 0 && handle < this.snapshots.length) this.snapshots[handle] = undefined;
39
+ }
40
+
41
+ public clear(): void {
42
+ this.snapshots.length = 0;
43
+ }
44
+ }
@@ -0,0 +1,62 @@
1
+ import type { ContentLoadResult } from "../ports/content";
2
+ import type { IRuntimeContent } from "../runtime/contracts";
3
+ import type { IMetadataStore } from "./metadata-store";
4
+ import type { MetadataHandle } from "./states";
5
+ import type { Tile3D } from "./tile-3d";
6
+
7
+ export interface ITileReadinessPort<TRenderHandle> {
8
+ readonly tileId: string;
9
+ readonly activationId: number;
10
+ readonly signal: AbortSignal;
11
+ ready(contentId: string, result: ContentLoadResult<TRenderHandle>): Promise<boolean>;
12
+ failed(contentId: string, error: unknown): Promise<void>;
13
+ cancelled(contentId: string): Promise<void>;
14
+ }
15
+
16
+ export interface ITileActivationContext<TSpatial, TRenderHandle, TGlyphHandle> {
17
+ runtimeId: string;
18
+ tile: Tile3D<TSpatial, TRenderHandle, TGlyphHandle>;
19
+ pendingContents: readonly IRuntimeContent<TRenderHandle>[];
20
+ priority: number;
21
+ activationId: number;
22
+ signal: AbortSignal;
23
+ readiness: ITileReadinessPort<TRenderHandle>;
24
+ /**
25
+ * True when the contents are ready, possibly presented, and were invalidated by `TileRuntime.invalidate`: each
26
+ * keeps its current `handle` while it reloads. Report a new handle, which replaces the old one between two frames,
27
+ * or the same handle once the adapter refreshed it in place. An adapter that does not support refreshing reports
28
+ * the same handle at once.
29
+ */
30
+ refresh?: boolean;
31
+ }
32
+
33
+ export interface ITileDeactivationContext<TSpatial, TRenderHandle, TGlyphHandle> {
34
+ runtimeId: string;
35
+ tile: Tile3D<TSpatial, TRenderHandle, TGlyphHandle>;
36
+ activationId: number;
37
+ }
38
+
39
+ export interface ITileActivationAdapter<TSpatial, TRenderHandle, TGlyphHandle = unknown> {
40
+ activate(context: ITileActivationContext<TSpatial, TRenderHandle, TGlyphHandle>): void | Promise<void>;
41
+ deactivate(context: ITileDeactivationContext<TSpatial, TRenderHandle, TGlyphHandle>): void | Promise<void>;
42
+ }
43
+
44
+ export interface ITilePresentationResource<TRenderHandle> {
45
+ content: IRuntimeContent<TRenderHandle>;
46
+ handle: TRenderHandle;
47
+ metadataHandle: MetadataHandle;
48
+ }
49
+
50
+ export interface ITilePresentationContext<TSpatial, TRenderHandle, TGlyphHandle> {
51
+ runtimeId: string;
52
+ tile: Tile3D<TSpatial, TRenderHandle, TGlyphHandle>;
53
+ resources: readonly ITilePresentationResource<TRenderHandle>[];
54
+ tileMetadataHandle: MetadataHandle;
55
+ metadataStore: IMetadataStore;
56
+ }
57
+
58
+ export interface ITilePresentationAdapter<TSpatial, TRenderHandle, TGlyphHandle = unknown> {
59
+ present(context: ITilePresentationContext<TSpatial, TRenderHandle, TGlyphHandle>): void | Promise<void>;
60
+ hide(context: ITilePresentationContext<TSpatial, TRenderHandle, TGlyphHandle>): void | Promise<void>;
61
+ release?(context: ITilePresentationContext<TSpatial, TRenderHandle, TGlyphHandle>): void | Promise<void>;
62
+ }
@@ -0,0 +1,56 @@
1
+ /** Camera changes that can invalidate traversal or screen-space error. */
2
+ export enum CameraChangeFlags {
3
+ None = 0,
4
+ Position = 1 << 0,
5
+ Orientation = 1 << 1,
6
+ Frustum = 1 << 2,
7
+ Viewport = 1 << 3,
8
+ ClipBounds = 1 << 4,
9
+ Pose = Position | Orientation,
10
+ Projection = Frustum | Viewport,
11
+ All = Pose | Projection | ClipBounds,
12
+ }
13
+
14
+ export enum TileSelectionState {
15
+ Inactive = 0,
16
+ Active = 1,
17
+ }
18
+
19
+ export enum TileReadinessState {
20
+ Idle = 0,
21
+ Queued = 1,
22
+ Preparing = 2,
23
+ Ready = 3,
24
+ Failed = 4,
25
+ Cancelled = 5,
26
+ }
27
+
28
+ export enum TilePresentationState {
29
+ Hidden = 0,
30
+ Presenting = 1,
31
+ Visible = 2,
32
+ Hiding = 3,
33
+ }
34
+
35
+ export enum TileMetadataState {
36
+ Unresolved = 0,
37
+ Resolving = 1,
38
+ Ready = 2,
39
+ Failed = 3,
40
+ }
41
+
42
+ export enum TileContentKind {
43
+ Unknown = 0,
44
+ Renderable = 1,
45
+ ExternalTileset = 2,
46
+ Empty = 3,
47
+ }
48
+
49
+ export enum TileRefinementMode {
50
+ Add = 0,
51
+ Replace = 1,
52
+ }
53
+
54
+ export type MetadataHandle = number;
55
+
56
+ export const NO_METADATA: MetadataHandle = -1;
@@ -0,0 +1,165 @@
1
+ import type { IBoundingVolume, IContent, ITile } from "@spacexr/3d-tiles-core";
2
+
3
+ import type { IRuntimeImplicitTile } from "../implicit/types";
4
+ import type { IMetadataSnapshot, IRuntimeFeatureMetadata } from "../metadata/types";
5
+ import type { IRuntimeResourceCost } from "../runtime/cache";
6
+ import type { IRuntimeTilesetDocument } from "../runtime/contracts";
7
+ import {
8
+ NO_METADATA,
9
+ TileContentKind,
10
+ TilePresentationState,
11
+ TileReadinessState,
12
+ type MetadataHandle,
13
+ type TileMetadataState,
14
+ type TileRefinementMode,
15
+ type TileSelectionState,
16
+ } from "./states";
17
+
18
+ const SELECTION_SHIFT = 0;
19
+ const SELECTION_MASK = 0b0000_0001;
20
+ const READINESS_SHIFT = 1;
21
+ const READINESS_MASK = 0b0000_1110;
22
+ const PRESENTATION_SHIFT = 4;
23
+ const PRESENTATION_MASK = 0b0011_0000;
24
+ const METADATA_SHIFT = 6;
25
+ const METADATA_MASK = 0b1100_0000;
26
+
27
+ export class Tile3DContent<TRenderHandle> {
28
+ public status = TileReadinessState.Idle;
29
+ public kind = TileContentKind.Unknown;
30
+ public attempts = 0;
31
+ public attached = false;
32
+ public lastTouchedFrame: number;
33
+ public readyFrame = -1;
34
+ public handle?: TRenderHandle;
35
+ public featureMetadata?: readonly IRuntimeFeatureMetadata[];
36
+ public cacheKey?: string;
37
+ public cost?: IRuntimeResourceCost;
38
+ public error?: unknown;
39
+ public metadataHandle: MetadataHandle = NO_METADATA;
40
+ public featureMetadataHandle: MetadataHandle = NO_METADATA;
41
+ /**
42
+ * Invalidated by `TileRuntime.invalidate`: the handle is still presented, and is replaced once its reload is
43
+ * ready.
44
+ */
45
+ public stale = false;
46
+
47
+ public constructor(
48
+ public readonly id: string,
49
+ public readonly descriptor: IContent,
50
+ public readonly uri: string,
51
+ frame: number,
52
+ ) {
53
+ this.lastTouchedFrame = frame;
54
+ }
55
+
56
+ public get ready(): boolean {
57
+ return this.kind === TileContentKind.Renderable && this.status === TileReadinessState.Ready && this.handle !== undefined;
58
+ }
59
+ }
60
+
61
+ export interface ITile3DInitialization<TSpatial, TRenderHandle, TGlyphHandle> {
62
+ id: string;
63
+ source: ITile;
64
+ document: IRuntimeTilesetDocument;
65
+ parent?: Tile3D<TSpatial, TRenderHandle, TGlyphHandle>;
66
+ implicit?: IRuntimeImplicitTile;
67
+ depth: number;
68
+ refinementMode: TileRefinementMode;
69
+ spatial: TSpatial;
70
+ contents: Array<Tile3DContent<TRenderHandle>>;
71
+ frame: number;
72
+ }
73
+
74
+ /** Renderer-neutral runtime tile with compact numeric pipeline state. */
75
+ export class Tile3D<TSpatial, TRenderHandle = unknown, TGlyphHandle = unknown> {
76
+ public readonly id: string;
77
+ public readonly source: ITile;
78
+ public readonly document: IRuntimeTilesetDocument;
79
+ public readonly parent: Tile3D<TSpatial, TRenderHandle, TGlyphHandle> | undefined;
80
+ public readonly implicit: IRuntimeImplicitTile | undefined;
81
+ public children: Array<Tile3D<TSpatial, TRenderHandle, TGlyphHandle>> = [];
82
+ public readonly depth: number;
83
+ public readonly refinementMode: TileRefinementMode;
84
+ /** Derived spatial state. Replaced when loaded content reports a tighter tile bounding volume. */
85
+ public spatial: TSpatial;
86
+ /** True once the tile own content reported its measured bounding volume; parent refreshes no longer apply. */
87
+ public contentBoundsRefined = false;
88
+ /** The volume measured on the content, when it reported one. */
89
+ public contentBounds: (() => IBoundingVolume) | undefined = undefined;
90
+ /** Heights measured on the content, kept with its bounding volume. */
91
+ public contentHeights: (() => readonly [number, number]) | undefined = undefined;
92
+ public readonly contents: Array<Tile3DContent<TRenderHandle>>;
93
+ /** In the view of the camera. A visible tile is always active. */
94
+ public visible = false;
95
+ /** Kept by the selection: visible, in the periphery of the view, or a neighbour of a visible tile. */
96
+ public active = false;
97
+ public screenSpaceError = 0;
98
+ public priority = 0;
99
+ public activationId = 0;
100
+ public glyphHandles: Array<TGlyphHandle> = [];
101
+ public metadataSnapshots: readonly IMetadataSnapshot[] = [];
102
+ public metadataHandle: MetadataHandle = NO_METADATA;
103
+ public lastTouchedFrame: number;
104
+
105
+ private stateBits = 0;
106
+
107
+ public constructor(initialization: ITile3DInitialization<TSpatial, TRenderHandle, TGlyphHandle>) {
108
+ this.id = initialization.id;
109
+ this.source = initialization.source;
110
+ this.document = initialization.document;
111
+ this.parent = initialization.parent;
112
+ this.implicit = initialization.implicit;
113
+ this.depth = initialization.depth;
114
+ this.refinementMode = initialization.refinementMode;
115
+ this.spatial = initialization.spatial;
116
+ this.contents = initialization.contents;
117
+ this.lastTouchedFrame = initialization.frame;
118
+ }
119
+
120
+ public get selectionState(): TileSelectionState {
121
+ return ((this.stateBits & SELECTION_MASK) >> SELECTION_SHIFT) as TileSelectionState;
122
+ }
123
+
124
+ public set selectionState(state: TileSelectionState) {
125
+ this.stateBits = (this.stateBits & ~SELECTION_MASK) | (state << SELECTION_SHIFT);
126
+ }
127
+
128
+ public get readinessState(): TileReadinessState {
129
+ return ((this.stateBits & READINESS_MASK) >> READINESS_SHIFT) as TileReadinessState;
130
+ }
131
+
132
+ public set readinessState(state: TileReadinessState) {
133
+ this.stateBits = (this.stateBits & ~READINESS_MASK) | (state << READINESS_SHIFT);
134
+ }
135
+
136
+ public get presentationState(): TilePresentationState {
137
+ return ((this.stateBits & PRESENTATION_MASK) >> PRESENTATION_SHIFT) as TilePresentationState;
138
+ }
139
+
140
+ public set presentationState(state: TilePresentationState) {
141
+ this.stateBits = (this.stateBits & ~PRESENTATION_MASK) | (state << PRESENTATION_SHIFT);
142
+ }
143
+
144
+ public get metadataState(): TileMetadataState {
145
+ return ((this.stateBits & METADATA_MASK) >> METADATA_SHIFT) as TileMetadataState;
146
+ }
147
+
148
+ public set metadataState(state: TileMetadataState) {
149
+ this.stateBits = (this.stateBits & ~METADATA_MASK) | (state << METADATA_SHIFT);
150
+ }
151
+
152
+ /** Compatibility view for the currently presented cut. */
153
+ public get selected(): boolean {
154
+ return this.presentationState === TilePresentationState.Visible;
155
+ }
156
+
157
+ public set selected(selected: boolean) {
158
+ this.presentationState = selected ? TilePresentationState.Visible : TilePresentationState.Hidden;
159
+ }
160
+
161
+ public get readyToRender(): boolean {
162
+ const renderable = this.contents.filter((content) => content.kind === TileContentKind.Renderable);
163
+ return renderable.length > 0 && renderable.every((content) => content.ready);
164
+ }
165
+ }
@@ -0,0 +1,12 @@
1
+ export interface IRuntimeSubscription {
2
+ unsubscribe(): void;
3
+ }
4
+
5
+ /** Pushes camera placement changes into the runtime. */
6
+ export interface ICameraEventSource<TCamera> {
7
+ subscribe(listener: (camera: TCamera) => void): IRuntimeSubscription;
8
+ current?(): TCamera | undefined;
9
+ }
10
+
11
+ /** Preferred name for a renderer camera source producing immutable runtime frames. */
12
+ export type ICameraFrameSource<TCameraFrame> = ICameraEventSource<TCameraFrame>;
@@ -0,0 +1,71 @@
1
+ import type { IBoundingVolume, IContent, ITileset } from "@spacexr/3d-tiles-core";
2
+
3
+ import type { IMetadataSnapshot, IRuntimeFeatureMetadata } from "../metadata/types";
4
+ import type { IRuntimeResourceCost } from "../runtime/cache";
5
+ import type { ITileContext } from "../runtime/contracts";
6
+
7
+ export interface IContentLoadContext<TSpatial> extends ITileContext<TSpatial> {
8
+ contentId: string;
9
+ content: IContent;
10
+ uri: string;
11
+ }
12
+
13
+ export type ContentLoadResult<TContentHandle> =
14
+ | {
15
+ kind: "renderable";
16
+ handle: TContentHandle;
17
+ mediaType?: string;
18
+ featureMetadata?: readonly IRuntimeFeatureMetadata[];
19
+ /** Stable adapter cache identity when several tiles share a renderable resource. */
20
+ cacheKey?: string;
21
+ /** Adapter-reported footprint used by the runtime cache budgets and statistics. */
22
+ cost?: IRuntimeResourceCost;
23
+ /**
24
+ * Bounding volume of the whole tile measured from the loaded content, for example the
25
+ * height range of a DEM tile. The runtime re-derives the tile spatial state from it, so
26
+ * culling and refinement use the measured extent instead of the declared one. The
27
+ * serialized tile is not modified. A tile with several contents must report a volume
28
+ * enclosing all of them.
29
+ */
30
+ /** A volume measured on the content. A function is evaluated again when the vertical scale changes. */
31
+ tileBoundingVolume?: IBoundingVolume | (() => IBoundingVolume);
32
+ /**
33
+ * Lowest and highest heights measured on the content, such as a DEM tile, over the reference surface, in metres.
34
+ * Evaluated again when the vertical scale changes, whose factor it includes.
35
+ */
36
+ tileHeightRange?: () => readonly [number, number];
37
+ /**
38
+ * The content stands in for the content of the tile, built from data already in memory, such as the deepest
39
+ * DEM tile loaded above it. The runtime presents it and refines through it like any ready content, so that a
40
+ * descent does not wait for each level. It reloads it, through the activation adapter with `refresh` set,
41
+ * only once the tile is a leaf of the cut, and keeps it presented until the reload is ready. A tile that
42
+ * refines again stops its reload.
43
+ */
44
+ provisional?: boolean;
45
+ }
46
+ | {
47
+ kind: "external-tileset";
48
+ tileset: ITileset;
49
+ documentUri?: string;
50
+ baseUri?: string;
51
+ }
52
+ | { kind: "empty" };
53
+
54
+ export interface IContentPresentationContext<TSpatial, TContentHandle> extends IContentLoadContext<TSpatial> {
55
+ handle: TContentHandle;
56
+ metadata: IMetadataSnapshot;
57
+ }
58
+
59
+ /**
60
+ * Renderer adaptation port. A Babylon adapter may return AssetContainer, a
61
+ * Three.js adapter may return Object3D, and another adapter may publish a GPU
62
+ * resource handle. Content probing and glTF decoding stay outside the runtime.
63
+ * Implicit coordinates and spatial state are present in the load context, so
64
+ * terrain adapters may instance a shared grid and bind a DEM texture or shader.
65
+ */
66
+ export interface ITileContentAdapter<TSpatial, TContentHandle> {
67
+ load(context: IContentLoadContext<TSpatial>, signal: AbortSignal): Promise<ContentLoadResult<TContentHandle>>;
68
+ attach(context: IContentPresentationContext<TSpatial, TContentHandle>): void | Promise<void>;
69
+ detach(context: IContentPresentationContext<TSpatial, TContentHandle>): void | Promise<void>;
70
+ dispose?(context: IContentPresentationContext<TSpatial, TContentHandle>): void | Promise<void>;
71
+ }
@@ -0,0 +1,13 @@
1
+ import type { IMetadataSnapshot } from "../metadata/types";
2
+ import type { ITileContext } from "../runtime/contracts";
3
+
4
+ export interface IGlyphPublicationContext<TSpatial, TContentHandle> extends ITileContext<TSpatial> {
5
+ metadata: readonly IMetadataSnapshot[];
6
+ contentHandles: readonly TContentHandle[];
7
+ }
8
+
9
+ /** Publishes labels, anchors, symbols or domain-specific glyphs. */
10
+ export interface IGlyphPublisher<TSpatial, TContentHandle, TGlyphHandle> {
11
+ publish(context: IGlyphPublicationContext<TSpatial, TContentHandle>): readonly TGlyphHandle[] | Promise<readonly TGlyphHandle[]>;
12
+ revoke(handles: readonly TGlyphHandle[], context: IGlyphPublicationContext<TSpatial, TContentHandle>): void | Promise<void>;
13
+ }
@@ -0,0 +1,32 @@
1
+ import type { IImplicitMetadataDecoder, IImplicitSubtreeLoader, IImplicitTileResolver } from "../implicit/types";
2
+ import type { ITileActivationAdapter, ITilePresentationAdapter } from "../pipeline/ports";
3
+ import type { ICameraEventSource } from "./camera";
4
+ import type { ITileContentAdapter } from "./content";
5
+ import type { IGlyphPublisher } from "./glyph";
6
+ import type { IMetadataSchemaLoader, IRuntimeUriResolver, ITilesetLoader } from "./resource";
7
+ import type { ISpatialMetric } from "./spatial";
8
+ import type { IRuntimeTelemetry } from "./telemetry";
9
+
10
+ export * from "./camera";
11
+ export * from "./content";
12
+ export * from "./glyph";
13
+ export * from "./resource";
14
+ export * from "./spatial";
15
+ export * from "./telemetry";
16
+
17
+ export interface IRuntimeAdapter<TCamera, TSpatial, TContentHandle, TGlyphHandle> {
18
+ tilesets: ITilesetLoader;
19
+ /** Legacy combined adapter. New integrations should use activation and presentation. */
20
+ content?: ITileContentAdapter<TSpatial, TContentHandle>;
21
+ activation?: ITileActivationAdapter<TSpatial, TContentHandle, TGlyphHandle>;
22
+ presentation?: ITilePresentationAdapter<TSpatial, TContentHandle, TGlyphHandle>;
23
+ spatial: ISpatialMetric<TCamera, TSpatial>;
24
+ camera?: ICameraEventSource<TCamera>;
25
+ glyphs?: IGlyphPublisher<TSpatial, TContentHandle, TGlyphHandle>;
26
+ metadataSchemas?: IMetadataSchemaLoader;
27
+ telemetry?: IRuntimeTelemetry;
28
+ uri?: IRuntimeUriResolver;
29
+ subtrees?: IImplicitSubtreeLoader;
30
+ implicitTiles?: IImplicitTileResolver;
31
+ implicitMetadata?: IImplicitMetadataDecoder;
32
+ }
@@ -0,0 +1,54 @@
1
+ import type { IMetadataSchema, ITileset } from "@spacexr/3d-tiles-core";
2
+
3
+ export interface ITilesetLoadRequest {
4
+ uri: string;
5
+ parentDocumentUri?: string;
6
+ signal: AbortSignal;
7
+ }
8
+
9
+ export interface ILoadedTileset {
10
+ tileset: ITileset;
11
+ /** Base used to resolve references declared by this document. */
12
+ baseUri?: string;
13
+ }
14
+
15
+ export interface ITilesetLoader {
16
+ load(request: ITilesetLoadRequest): Promise<ILoadedTileset>;
17
+ }
18
+
19
+ export interface IMetadataSchemaLoadRequest {
20
+ uri: string;
21
+ documentUri: string;
22
+ signal: AbortSignal;
23
+ }
24
+
25
+ export interface IMetadataSchemaLoader {
26
+ load(request: IMetadataSchemaLoadRequest): Promise<IMetadataSchema>;
27
+ }
28
+
29
+ /** Resolves canonical resource identities, without injecting renderer state. */
30
+ export interface IRuntimeUriResolver {
31
+ resolve(reference: string, baseUri: string): string;
32
+ baseOf(uri: string): string;
33
+ }
34
+
35
+ export class StandardUriResolver implements IRuntimeUriResolver {
36
+ public resolve(reference: string, baseUri: string): string {
37
+ try {
38
+ return new URL(reference, baseUri).toString();
39
+ } catch {
40
+ if (!baseUri) return reference;
41
+ const separator = baseUri.endsWith("/") ? "" : "/";
42
+ return `${baseUri}${separator}${reference}`;
43
+ }
44
+ }
45
+
46
+ public baseOf(uri: string): string {
47
+ try {
48
+ return new URL(".", uri).toString();
49
+ } catch {
50
+ const index = Math.max(uri.lastIndexOf("/"), uri.lastIndexOf("\\"));
51
+ return index >= 0 ? uri.slice(0, index + 1) : "";
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,28 @@
1
+ import type { ITile } from "@spacexr/3d-tiles-core";
2
+
3
+ export interface ISpatialDerivationContext<TSpatial> {
4
+ tile: ITile;
5
+ parent?: TSpatial;
6
+ /** Lowest and highest heights of the terrain of the tile over the reference surface, in metres, vertical scale applied, when known. */
7
+ heightRange?: readonly [number, number];
8
+ }
9
+
10
+ export interface IScreenSpaceErrorContext<TCamera, TSpatial> {
11
+ camera: TCamera;
12
+ spatial: TSpatial;
13
+ tile: ITile;
14
+ depth: number;
15
+ }
16
+
17
+ /**
18
+ * Owns coordinate systems, placement, visibility and distance metrics. The
19
+ * traversal never assumes Babylon, Three.js, ECEF or a particular unit.
20
+ */
21
+ export interface ISpatialMetric<TCamera, TSpatial> {
22
+ derive(context: ISpatialDerivationContext<TSpatial>): TSpatial;
23
+ /** Whether the tile is in the view of the camera. */
24
+ isVisible(spatial: TSpatial, camera: TCamera): boolean;
25
+ /** Whether the tile, outside the view, is close enough to it to stay active. Without this method, no tile is. */
26
+ isInPeriphery?(spatial: TSpatial, camera: TCamera): boolean;
27
+ screenSpaceError(context: IScreenSpaceErrorContext<TCamera, TSpatial>): number;
28
+ }