@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.
- package/LICENSE +201 -0
- package/README.md +93 -2
- package/dist/chunk-AI6NWGCA.js +316 -0
- package/dist/chunk-AI6NWGCA.js.map +1 -0
- package/dist/chunk-G7YVZYMR.js +24 -0
- package/dist/chunk-G7YVZYMR.js.map +1 -0
- package/dist/chunk-PJIVVIOF.js +205 -0
- package/dist/chunk-PJIVVIOF.js.map +1 -0
- package/dist/chunk-Q2AL6LWU.js +3 -0
- package/dist/chunk-Q2AL6LWU.js.map +1 -0
- package/dist/chunk-Q35HKP5V.js +249 -0
- package/dist/chunk-Q35HKP5V.js.map +1 -0
- package/dist/chunk-URZDM4BH.js +488 -0
- package/dist/chunk-URZDM4BH.js.map +1 -0
- package/dist/implicit/index.d.ts +64 -0
- package/dist/implicit/index.js +4 -0
- package/dist/implicit/index.js.map +1 -0
- package/dist/index-CNnPRQZc.d.ts +350 -0
- package/dist/index.d.ts +713 -0
- package/dist/index.js +3074 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata/index.d.ts +12 -0
- package/dist/metadata/index.js +3 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/pipeline/index.d.ts +5 -0
- package/dist/pipeline/index.js +3 -0
- package/dist/pipeline/index.js.map +1 -0
- package/dist/ports/index.d.ts +62 -0
- package/dist/ports/index.js +4 -0
- package/dist/ports/index.js.map +1 -0
- package/dist/resource-DH72MRMN.d.ts +34 -0
- package/dist/spatial/index.d.ts +402 -0
- package/dist/spatial/index.js +3 -0
- package/dist/spatial/index.js.map +1 -0
- package/dist/spatial-3IDPbyv4.d.ts +28 -0
- package/dist/types-Dn5i8Uqg.d.ts +78 -0
- package/dist/types-ri64XfSE.d.ts +237 -0
- package/package.json +102 -5
- package/src/implicit/availability.ts +55 -0
- package/src/implicit/coordinates.ts +193 -0
- package/src/implicit/dense-subtree-loader.ts +23 -0
- package/src/implicit/index.ts +6 -0
- package/src/implicit/standard-subtree-loader.ts +71 -0
- package/src/implicit/tile-data-source.ts +120 -0
- package/src/implicit/types.ts +156 -0
- package/src/index.ts +6 -0
- package/src/metadata/index.ts +2 -0
- package/src/metadata/metadata-resolver.ts +308 -0
- package/src/metadata/types.ts +91 -0
- package/src/pipeline/index.ts +4 -0
- package/src/pipeline/metadata-store.ts +44 -0
- package/src/pipeline/ports.ts +62 -0
- package/src/pipeline/states.ts +56 -0
- package/src/pipeline/tile-3d.ts +165 -0
- package/src/ports/camera.ts +12 -0
- package/src/ports/content.ts +71 -0
- package/src/ports/glyph.ts +13 -0
- package/src/ports/index.ts +32 -0
- package/src/ports/resource.ts +54 -0
- package/src/ports/spatial.ts +28 -0
- package/src/ports/telemetry.ts +44 -0
- package/src/runtime/cache.ts +112 -0
- package/src/runtime/contracts.ts +77 -0
- package/src/runtime/events.ts +57 -0
- package/src/runtime/hooks.ts +99 -0
- package/src/runtime/index.ts +7 -0
- package/src/runtime/instrumentation.ts +163 -0
- package/src/runtime/priority-scheduler.ts +88 -0
- package/src/runtime/quadtree-balance.ts +215 -0
- package/src/runtime/tile-runtime.ts +3508 -0
- package/src/spatial/bounding-volumes.ts +159 -0
- package/src/spatial/ecef-types.ts +110 -0
- package/src/spatial/ecef.ts +196 -0
- package/src/spatial/index.ts +6 -0
- package/src/spatial/utm-bounds.ts +151 -0
- package/src/spatial/utm-types.ts +83 -0
- package/src/spatial/vertical-scale.ts +125 -0
- package/src/spatial/view-metrics.ts +132 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { IContent, IBoundingVolume, IMetadataEntity, ITileset, IImplicitTiling, ISubtree, IMetadataSchema, ITile } from '@spacexr/3d-tiles-core';
|
|
2
|
+
import { ITileMetrics } from '@spacexr/tiles';
|
|
3
|
+
|
|
4
|
+
/** Camera changes that can invalidate traversal or screen-space error. */
|
|
5
|
+
declare enum CameraChangeFlags {
|
|
6
|
+
None = 0,
|
|
7
|
+
Position = 1,
|
|
8
|
+
Orientation = 2,
|
|
9
|
+
Frustum = 4,
|
|
10
|
+
Viewport = 8,
|
|
11
|
+
ClipBounds = 16,
|
|
12
|
+
Pose = 3,
|
|
13
|
+
Projection = 12,
|
|
14
|
+
All = 31
|
|
15
|
+
}
|
|
16
|
+
declare enum TileSelectionState {
|
|
17
|
+
Inactive = 0,
|
|
18
|
+
Active = 1
|
|
19
|
+
}
|
|
20
|
+
declare enum TileReadinessState {
|
|
21
|
+
Idle = 0,
|
|
22
|
+
Queued = 1,
|
|
23
|
+
Preparing = 2,
|
|
24
|
+
Ready = 3,
|
|
25
|
+
Failed = 4,
|
|
26
|
+
Cancelled = 5
|
|
27
|
+
}
|
|
28
|
+
declare enum TilePresentationState {
|
|
29
|
+
Hidden = 0,
|
|
30
|
+
Presenting = 1,
|
|
31
|
+
Visible = 2,
|
|
32
|
+
Hiding = 3
|
|
33
|
+
}
|
|
34
|
+
declare enum TileMetadataState {
|
|
35
|
+
Unresolved = 0,
|
|
36
|
+
Resolving = 1,
|
|
37
|
+
Ready = 2,
|
|
38
|
+
Failed = 3
|
|
39
|
+
}
|
|
40
|
+
declare enum TileContentKind {
|
|
41
|
+
Unknown = 0,
|
|
42
|
+
Renderable = 1,
|
|
43
|
+
ExternalTileset = 2,
|
|
44
|
+
Empty = 3
|
|
45
|
+
}
|
|
46
|
+
declare enum TileRefinementMode {
|
|
47
|
+
Add = 0,
|
|
48
|
+
Replace = 1
|
|
49
|
+
}
|
|
50
|
+
type MetadataHandle = number;
|
|
51
|
+
declare const NO_METADATA: MetadataHandle;
|
|
52
|
+
|
|
53
|
+
interface ITileAddress {
|
|
54
|
+
/** Root of the address on a pyramid of several roots, such as a multi-root pyramid; omitted for face 0. */
|
|
55
|
+
face?: number;
|
|
56
|
+
lod: number;
|
|
57
|
+
x: number;
|
|
58
|
+
y: number;
|
|
59
|
+
z?: number;
|
|
60
|
+
}
|
|
61
|
+
interface ITileDataSourceTile {
|
|
62
|
+
address: ITileAddress;
|
|
63
|
+
boundingVolume: IBoundingVolume;
|
|
64
|
+
geometricError: number;
|
|
65
|
+
contents: readonly IContent[];
|
|
66
|
+
metadata?: IMetadataEntity;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Owns the physical pyramid definition consumed by a tileset decorator.
|
|
70
|
+
*
|
|
71
|
+
* Metrics, addressing and URL templates belong to the data source. The 3D
|
|
72
|
+
* Tiles implicit representation is only one possible view over this source.
|
|
73
|
+
*/
|
|
74
|
+
interface ITileDataSource {
|
|
75
|
+
readonly id: string;
|
|
76
|
+
readonly metrics: Pick<ITileMetrics, "minLOD" | "maxLOD">;
|
|
77
|
+
readonly rootAddress: ITileAddress;
|
|
78
|
+
readonly urlTemplates: readonly string[];
|
|
79
|
+
addressOf(coordinates: IImplicitCoordinates): ITileAddress;
|
|
80
|
+
resolve(coordinates: IImplicitCoordinates, computedContents?: readonly IContent[]): ITileDataSourceTile;
|
|
81
|
+
}
|
|
82
|
+
interface IImplicitTilesetDecoratorOptions {
|
|
83
|
+
subtreeLevels?: number;
|
|
84
|
+
refine?: "ADD" | "REPLACE";
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Presents an `ITileDataSource` as a standard implicit 3D Tiles tileset.
|
|
88
|
+
*
|
|
89
|
+
* The decorator owns no pyramid metric or URL policy. `availableLevels` is
|
|
90
|
+
* derived from the source metrics and resolution delegates back to the source.
|
|
91
|
+
*/
|
|
92
|
+
declare class ImplicitTilesetDecorator implements IImplicitTileResolver {
|
|
93
|
+
readonly dataSource: ITileDataSource;
|
|
94
|
+
readonly tileset: ITileset;
|
|
95
|
+
constructor(dataSource: ITileDataSource, options?: IImplicitTilesetDecoratorOptions);
|
|
96
|
+
/** Address of the tile in the source pyramid, shared by every decorator of the same pyramid. */
|
|
97
|
+
addressOf(context: IImplicitTileAddressContext): ITileAddress;
|
|
98
|
+
resolve(context: IImplicitTileResolveContext): IImplicitTileOverride;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
interface IImplicitCoordinates {
|
|
102
|
+
level: number;
|
|
103
|
+
x: number;
|
|
104
|
+
y: number;
|
|
105
|
+
z?: number;
|
|
106
|
+
}
|
|
107
|
+
interface ILoadedImplicitSubtree {
|
|
108
|
+
subtree: ISubtree;
|
|
109
|
+
/** Buffer payloads indexed exactly like subtree.buffers. */
|
|
110
|
+
buffers?: readonly Uint8Array[];
|
|
111
|
+
}
|
|
112
|
+
interface IImplicitSubtreeLoadRequest {
|
|
113
|
+
uri: string;
|
|
114
|
+
documentUri: string;
|
|
115
|
+
coordinates: IImplicitCoordinates;
|
|
116
|
+
implicitTiling: IImplicitTiling;
|
|
117
|
+
contentCount: number;
|
|
118
|
+
signal: AbortSignal;
|
|
119
|
+
}
|
|
120
|
+
interface IImplicitSubtreeLoader {
|
|
121
|
+
load(request: IImplicitSubtreeLoadRequest): Promise<ILoadedImplicitSubtree>;
|
|
122
|
+
}
|
|
123
|
+
interface IImplicitTileResolveContext {
|
|
124
|
+
documentUri: string;
|
|
125
|
+
rootTile: ITile;
|
|
126
|
+
implicitTiling: IImplicitTiling;
|
|
127
|
+
coordinates: IImplicitCoordinates;
|
|
128
|
+
computedBoundingVolume: IBoundingVolume;
|
|
129
|
+
computedGeometricError: number;
|
|
130
|
+
computedContents: readonly IContent[];
|
|
131
|
+
}
|
|
132
|
+
interface IImplicitTileOverride {
|
|
133
|
+
boundingVolume?: IBoundingVolume;
|
|
134
|
+
geometricError?: number;
|
|
135
|
+
contents?: readonly IContent[];
|
|
136
|
+
metadata?: IMetadataEntity;
|
|
137
|
+
/** Heights of the terrain of the tile when they are known before its content, prepared by its parent for example. */
|
|
138
|
+
heightRange?: readonly [number, number];
|
|
139
|
+
}
|
|
140
|
+
interface IImplicitTileAddressContext {
|
|
141
|
+
documentUri: string;
|
|
142
|
+
rootTile: ITile;
|
|
143
|
+
implicitTiling: IImplicitTiling;
|
|
144
|
+
coordinates: IImplicitCoordinates;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Optional runtime override for sources whose physical pyramid differs from
|
|
148
|
+
* the regular 3D Tiles subdivision, for example XYZ Web Mercator services.
|
|
149
|
+
*/
|
|
150
|
+
interface IImplicitTileResolver {
|
|
151
|
+
resolve(context: IImplicitTileResolveContext): IImplicitTileOverride | undefined;
|
|
152
|
+
/**
|
|
153
|
+
* Address of an implicit tile in a pyramid shared by several implicit
|
|
154
|
+
* tilesets, in the XYZ convention. Quadtree balancing uses it to find
|
|
155
|
+
* neighbours across implicit roots; without it, neighbours are searched
|
|
156
|
+
* within each implicit tileset only.
|
|
157
|
+
*/
|
|
158
|
+
addressOf?(context: IImplicitTileAddressContext): ITileAddress | undefined;
|
|
159
|
+
/**
|
|
160
|
+
* Implicit subtree registered at an implicit tile, whose rules apply from
|
|
161
|
+
* that tile down; `undefined` keeps the rules of the tileset. Called for
|
|
162
|
+
* each tile the tileset makes available, before the tile is created.
|
|
163
|
+
*/
|
|
164
|
+
subtreeAt?(context: IImplicitTileAddressContext): IImplicitSubtreeGraft | undefined;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* An implicit subtree registered at a tile of an implicit tileset, with its own rules.
|
|
168
|
+
*
|
|
169
|
+
* From the registered tile down, the subtree replaces the rules of the tileset: its implicit tiling, hence its own
|
|
170
|
+
* levels and availability, its content templates, its resolver and its subtree loader. Its root tile takes the place
|
|
171
|
+
* of the registered tile, contents included. A subtree may stop the refinement early, make tiles unavailable, supply
|
|
172
|
+
* other contents, or go deeper than the tileset. Subtrees may register subtrees of their own.
|
|
173
|
+
*/
|
|
174
|
+
interface IImplicitSubtreeGraft {
|
|
175
|
+
/** Root tile of the subtree: an implicit root tile, with `implicitTiling` and the content templates of the subtree. */
|
|
176
|
+
tile: ITile;
|
|
177
|
+
/** Resolves the tiles of the subtree, and the subtrees registered inside it. Defaults to the resolver of the tileset. */
|
|
178
|
+
resolver?: IImplicitTileResolver;
|
|
179
|
+
/** Loads the availability subtrees of the subtree. Defaults to the subtree loader of the adapter. */
|
|
180
|
+
subtrees?: IImplicitSubtreeLoader;
|
|
181
|
+
}
|
|
182
|
+
interface IImplicitMetadataDecodeRequest {
|
|
183
|
+
loaded: ILoadedImplicitSubtree;
|
|
184
|
+
availability: ISubtreeAvailability;
|
|
185
|
+
schema?: IMetadataSchema;
|
|
186
|
+
implicitTiling: IImplicitTiling;
|
|
187
|
+
coordinates: IImplicitCoordinates;
|
|
188
|
+
localCoordinates: IImplicitCoordinates;
|
|
189
|
+
contentCount: number;
|
|
190
|
+
}
|
|
191
|
+
interface IImplicitMetadataDecodeResult {
|
|
192
|
+
tileMetadata?: IMetadataEntity;
|
|
193
|
+
contentMetadata?: readonly (IMetadataEntity | undefined)[];
|
|
194
|
+
}
|
|
195
|
+
/** Decodes binary property tables after a standard subtree has been loaded. */
|
|
196
|
+
interface IImplicitMetadataDecoder {
|
|
197
|
+
decode(request: IImplicitMetadataDecodeRequest): IImplicitMetadataDecodeResult;
|
|
198
|
+
}
|
|
199
|
+
type ImplicitSubtreeStatus = TileReadinessState;
|
|
200
|
+
interface IRuntimeImplicitContext {
|
|
201
|
+
id: string;
|
|
202
|
+
rootTile: ITile;
|
|
203
|
+
implicitTiling: IImplicitTiling;
|
|
204
|
+
contentTemplates: readonly IContent[];
|
|
205
|
+
/** Resolver of a registered subtree, in place of the resolver of the adapter. */
|
|
206
|
+
resolver?: IImplicitTileResolver;
|
|
207
|
+
/** Subtree loader of a registered subtree, in place of the loader of the adapter. */
|
|
208
|
+
subtrees?: IImplicitSubtreeLoader;
|
|
209
|
+
}
|
|
210
|
+
interface IRuntimeImplicitSubtree {
|
|
211
|
+
uri: string;
|
|
212
|
+
coordinates: IImplicitCoordinates;
|
|
213
|
+
status: ImplicitSubtreeStatus;
|
|
214
|
+
attempts: number;
|
|
215
|
+
loaded?: ILoadedImplicitSubtree;
|
|
216
|
+
availability?: ISubtreeAvailability;
|
|
217
|
+
error?: unknown;
|
|
218
|
+
estimatedBytes: number;
|
|
219
|
+
lastTouchedFrame: number;
|
|
220
|
+
}
|
|
221
|
+
interface IRuntimeImplicitTile {
|
|
222
|
+
context: IRuntimeImplicitContext;
|
|
223
|
+
coordinates: IImplicitCoordinates;
|
|
224
|
+
localCoordinates: IImplicitCoordinates;
|
|
225
|
+
subtree: IRuntimeImplicitSubtree;
|
|
226
|
+
childrenMaterialized: boolean;
|
|
227
|
+
metadataApplied: boolean;
|
|
228
|
+
/** Heights given by the resolver the last time it resolved the tile. */
|
|
229
|
+
heightRange?: readonly [number, number];
|
|
230
|
+
}
|
|
231
|
+
interface ISubtreeAvailability {
|
|
232
|
+
isTileAvailable(coordinates: IImplicitCoordinates): boolean;
|
|
233
|
+
isContentAvailable(contentIndex: number, coordinates: IImplicitCoordinates): boolean;
|
|
234
|
+
isChildSubtreeAvailable(coordinates: IImplicitCoordinates): boolean;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export { CameraChangeFlags as C, type IImplicitSubtreeLoader as I, type MetadataHandle as M, NO_METADATA as N, TileContentKind as T, type IImplicitTileResolver as a, type IImplicitMetadataDecoder as b, type IRuntimeImplicitSubtree as c, type ILoadedImplicitSubtree as d, type ITileAddress as e, type IImplicitCoordinates as f, type IImplicitMetadataDecodeRequest as g, type IImplicitMetadataDecodeResult as h, type IImplicitSubtreeGraft as i, type IImplicitSubtreeLoadRequest as j, type IImplicitTileAddressContext as k, type IImplicitTileOverride as l, type IImplicitTileResolveContext as m, type IImplicitTilesetDecoratorOptions as n, type IRuntimeImplicitContext as o, type IRuntimeImplicitTile as p, type ISubtreeAvailability as q, type ITileDataSource as r, type ITileDataSourceTile as s, type ImplicitSubtreeStatus as t, ImplicitTilesetDecorator as u, TileMetadataState as v, TilePresentationState as w, TileReadinessState as x, TileRefinementMode as y, TileSelectionState as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,103 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@spacexr/3d-tiles-runtime",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Renderer-neutral 3D Tiles traversal, content lifecycle and metadata runtime.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "Guillaume Pelletier (SpaceXR)",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/pandaGaume/3d-tiles-core.git",
|
|
11
|
+
"directory": "node/packages/runtime"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/pandaGaume/3d-tiles-core#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/pandaGaume/3d-tiles-core/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"3d-tiles",
|
|
19
|
+
"runtime",
|
|
20
|
+
"gltf",
|
|
21
|
+
"geospatial",
|
|
22
|
+
"metadata",
|
|
23
|
+
"spacexr"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=20.11.0"
|
|
27
|
+
},
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"src",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"main": "./dist/index.js",
|
|
36
|
+
"module": "./dist/index.js",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"import": "./dist/index.js",
|
|
42
|
+
"default": "./dist/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./implicit": {
|
|
45
|
+
"types": "./dist/implicit/index.d.ts",
|
|
46
|
+
"import": "./dist/implicit/index.js",
|
|
47
|
+
"default": "./dist/implicit/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./ports": {
|
|
50
|
+
"types": "./dist/ports/index.d.ts",
|
|
51
|
+
"import": "./dist/ports/index.js",
|
|
52
|
+
"default": "./dist/ports/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./metadata": {
|
|
55
|
+
"types": "./dist/metadata/index.d.ts",
|
|
56
|
+
"import": "./dist/metadata/index.js",
|
|
57
|
+
"default": "./dist/metadata/index.js"
|
|
58
|
+
},
|
|
59
|
+
"./pipeline": {
|
|
60
|
+
"types": "./dist/pipeline/index.d.ts",
|
|
61
|
+
"import": "./dist/pipeline/index.js",
|
|
62
|
+
"default": "./dist/pipeline/index.js"
|
|
63
|
+
},
|
|
64
|
+
"./spatial": {
|
|
65
|
+
"types": "./dist/spatial/index.d.ts",
|
|
66
|
+
"import": "./dist/spatial/index.js",
|
|
67
|
+
"default": "./dist/spatial/index.js"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"scripts": {
|
|
71
|
+
"build": "tsup",
|
|
72
|
+
"clean": "rimraf dist coverage",
|
|
73
|
+
"watch": "tsup --watch",
|
|
74
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
75
|
+
"test": "vitest run --coverage.enabled=false",
|
|
76
|
+
"test:watch": "vitest",
|
|
77
|
+
"lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
78
|
+
"lint:fix": "eslint \"src/**/*.ts\" \"tests/**/*.ts\" --fix",
|
|
79
|
+
"format": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
80
|
+
"format:fix": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
81
|
+
"prepublishOnly": "npm run lint && npm run typecheck && npm run test && npm run build"
|
|
82
|
+
},
|
|
83
|
+
"dependencies": {
|
|
84
|
+
"@spacexr/3d-tiles-core": "0.1.0",
|
|
85
|
+
"@spacexr/geodesy": "0.4.0",
|
|
86
|
+
"@spacexr/geometry": "0.2.0",
|
|
87
|
+
"@spacexr/tiles": "0.1.0"
|
|
88
|
+
},
|
|
89
|
+
"devDependencies": {
|
|
90
|
+
"@types/node": "^20.11.0",
|
|
91
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
92
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
93
|
+
"eslint": "^8.57.0",
|
|
94
|
+
"eslint-config-prettier": "^9.1.0",
|
|
95
|
+
"eslint-plugin-prettier": "^5.5.7",
|
|
96
|
+
"prettier": "^3.10.1",
|
|
97
|
+
"rimraf": "~6.1.4",
|
|
98
|
+
"tslib": "^2.9.1",
|
|
99
|
+
"tsup": "^8.5.1",
|
|
100
|
+
"typescript": "^5.4.0",
|
|
101
|
+
"vitest": "4.1.12"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { IAvailability, IImplicitTiling, ISubtreeBufferView } from "@spacexr/3d-tiles-core";
|
|
2
|
+
|
|
3
|
+
import { implicitAvailabilityIndex, implicitMortonIndex } from "./coordinates";
|
|
4
|
+
import type { IImplicitCoordinates, ILoadedImplicitSubtree, ISubtreeAvailability } from "./types";
|
|
5
|
+
|
|
6
|
+
export class SubtreeAvailabilityError extends Error {
|
|
7
|
+
public constructor(message: string) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "SubtreeAvailabilityError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getBit(bytes: Uint8Array, index: number): boolean {
|
|
14
|
+
const byte = bytes[Math.floor(index / 8)];
|
|
15
|
+
if (byte === undefined) throw new SubtreeAvailabilityError(`Availability bit ${index} is outside the referenced buffer view.`);
|
|
16
|
+
return ((byte >> (index % 8)) & 1) === 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class LoadedSubtreeAvailability implements ISubtreeAvailability {
|
|
20
|
+
public constructor(
|
|
21
|
+
private readonly loaded: ILoadedImplicitSubtree,
|
|
22
|
+
private readonly tiling: IImplicitTiling,
|
|
23
|
+
) {}
|
|
24
|
+
|
|
25
|
+
public isTileAvailable(coordinates: IImplicitCoordinates): boolean {
|
|
26
|
+
return this.read(this.loaded.subtree.tileAvailability, implicitAvailabilityIndex(coordinates, this.tiling));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public isContentAvailable(contentIndex: number, coordinates: IImplicitCoordinates): boolean {
|
|
30
|
+
const availability = this.loaded.subtree.contentAvailability?.[contentIndex];
|
|
31
|
+
return availability ? this.read(availability, implicitAvailabilityIndex(coordinates, this.tiling)) : false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public isChildSubtreeAvailable(coordinates: IImplicitCoordinates): boolean {
|
|
35
|
+
return this.read(this.loaded.subtree.childSubtreeAvailability, implicitMortonIndex(coordinates, this.tiling.subdivisionScheme));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private read(availability: IAvailability, index: number): boolean {
|
|
39
|
+
if (availability.constant !== undefined) return availability.constant === 1;
|
|
40
|
+
if (availability.bitstream === undefined)
|
|
41
|
+
throw new SubtreeAvailabilityError("Availability must define either constant or bitstream.");
|
|
42
|
+
const view = this.loaded.subtree.bufferViews?.[availability.bitstream];
|
|
43
|
+
if (!view) throw new SubtreeAvailabilityError(`Availability references missing buffer view ${availability.bitstream}.`);
|
|
44
|
+
return getBit(this.bufferView(view), index);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private bufferView(view: ISubtreeBufferView): Uint8Array {
|
|
48
|
+
const buffer = this.loaded.buffers?.[view.buffer];
|
|
49
|
+
if (!buffer) throw new SubtreeAvailabilityError(`Buffer view references unloaded buffer ${view.buffer}.`);
|
|
50
|
+
const start = view.byteOffset ?? 0;
|
|
51
|
+
const end = start + view.byteLength;
|
|
52
|
+
if (start < 0 || end > buffer.byteLength) throw new SubtreeAvailabilityError("Buffer view exceeds its loaded buffer.");
|
|
53
|
+
return buffer.subarray(start, end);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createUtmBoundingVolume,
|
|
3
|
+
getUtmBoundingVolume,
|
|
4
|
+
type IBoundingVolume,
|
|
5
|
+
type IContent,
|
|
6
|
+
type IImplicitTiling,
|
|
7
|
+
type ITile,
|
|
8
|
+
type IUtmBoundingVolume,
|
|
9
|
+
} from "@spacexr/3d-tiles-core";
|
|
10
|
+
|
|
11
|
+
import type { IImplicitCoordinates } from "./types";
|
|
12
|
+
|
|
13
|
+
function coordinateScale(level: number): number {
|
|
14
|
+
const scale = 2 ** level;
|
|
15
|
+
if (!Number.isSafeInteger(scale)) throw new RangeError(`Implicit level ${level} exceeds the safe coordinate range.`);
|
|
16
|
+
return scale;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function normalizeLongitude(value: number): number {
|
|
20
|
+
if (value === Math.PI) return value;
|
|
21
|
+
const tau = Math.PI * 2;
|
|
22
|
+
return ((((value + Math.PI) % tau) + tau) % tau) - Math.PI;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function implicitBranchingFactor(tiling: IImplicitTiling): 4 | 8 {
|
|
26
|
+
return tiling.subdivisionScheme === "OCTREE" ? 8 : 4;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function implicitMortonIndex(coordinates: IImplicitCoordinates, scheme: IImplicitTiling["subdivisionScheme"]): number {
|
|
30
|
+
const dimensions = scheme === "OCTREE" ? 3 : 2;
|
|
31
|
+
let result = 0;
|
|
32
|
+
for (let bit = 0; bit < coordinates.level; bit++) {
|
|
33
|
+
const divisor = 2 ** bit;
|
|
34
|
+
const x = Math.floor(coordinates.x / divisor) % 2;
|
|
35
|
+
const y = Math.floor(coordinates.y / divisor) % 2;
|
|
36
|
+
const z = scheme === "OCTREE" ? Math.floor((coordinates.z ?? 0) / divisor) % 2 : 0;
|
|
37
|
+
result += x * 2 ** (dimensions * bit) + y * 2 ** (dimensions * bit + 1);
|
|
38
|
+
if (dimensions === 3) result += z * 2 ** (dimensions * bit + 2);
|
|
39
|
+
}
|
|
40
|
+
if (!Number.isSafeInteger(result)) throw new RangeError("The Morton index exceeds the JavaScript safe integer range.");
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function implicitLevelOffset(level: number, branchingFactor: 4 | 8): number {
|
|
45
|
+
const result = (branchingFactor ** level - 1) / (branchingFactor - 1);
|
|
46
|
+
if (!Number.isSafeInteger(result)) throw new RangeError("The availability level offset exceeds the JavaScript safe integer range.");
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function implicitAvailabilityIndex(coordinates: IImplicitCoordinates, tiling: IImplicitTiling): number {
|
|
51
|
+
return (
|
|
52
|
+
implicitLevelOffset(coordinates.level, implicitBranchingFactor(tiling)) + implicitMortonIndex(coordinates, tiling.subdivisionScheme)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function expandImplicitTemplate(template: string, coordinates: IImplicitCoordinates): string {
|
|
57
|
+
return template
|
|
58
|
+
.replaceAll("{level}", String(coordinates.level))
|
|
59
|
+
.replaceAll("{x}", String(coordinates.x))
|
|
60
|
+
.replaceAll("{y}", String(coordinates.y))
|
|
61
|
+
.replaceAll("{z}", String(coordinates.z ?? 0));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function implicitChildCoordinates(
|
|
65
|
+
parent: IImplicitCoordinates,
|
|
66
|
+
childIndex: number,
|
|
67
|
+
scheme: IImplicitTiling["subdivisionScheme"],
|
|
68
|
+
): IImplicitCoordinates {
|
|
69
|
+
const result: IImplicitCoordinates = {
|
|
70
|
+
level: parent.level + 1,
|
|
71
|
+
x: parent.x * 2 + (childIndex & 1),
|
|
72
|
+
y: parent.y * 2 + ((childIndex >> 1) & 1),
|
|
73
|
+
};
|
|
74
|
+
if (scheme === "OCTREE") result.z = (parent.z ?? 0) * 2 + ((childIndex >> 2) & 1);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function implicitLocalCoordinates(global: IImplicitCoordinates, subtreeRoot: IImplicitCoordinates): IImplicitCoordinates {
|
|
79
|
+
const level = global.level - subtreeRoot.level;
|
|
80
|
+
const scale = coordinateScale(level);
|
|
81
|
+
const result: IImplicitCoordinates = {
|
|
82
|
+
level,
|
|
83
|
+
x: global.x - subtreeRoot.x * scale,
|
|
84
|
+
y: global.y - subtreeRoot.y * scale,
|
|
85
|
+
};
|
|
86
|
+
if (global.z !== undefined || subtreeRoot.z !== undefined) result.z = (global.z ?? 0) - (subtreeRoot.z ?? 0) * scale;
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function subdivideUtmExtent(
|
|
91
|
+
root: IUtmBoundingVolume,
|
|
92
|
+
scheme: IImplicitTiling["subdivisionScheme"],
|
|
93
|
+
coordinates: IImplicitCoordinates,
|
|
94
|
+
scale: number,
|
|
95
|
+
): IUtmBoundingVolume {
|
|
96
|
+
const eastingSize = (root.maxEasting - root.minEasting) / scale;
|
|
97
|
+
const northingSize = (root.maxNorthing - root.minNorthing) / scale;
|
|
98
|
+
const minEasting = root.minEasting + eastingSize * coordinates.x;
|
|
99
|
+
const minNorthing = root.minNorthing + northingSize * coordinates.y;
|
|
100
|
+
let vertical = root.vertical;
|
|
101
|
+
if (scheme === "OCTREE") {
|
|
102
|
+
// The z coordinate grows upward, so depths measured downward are split from their maximum.
|
|
103
|
+
const verticalSize = (root.vertical.maximum - root.vertical.minimum) / scale;
|
|
104
|
+
const offset = verticalSize * (coordinates.z ?? 0);
|
|
105
|
+
vertical =
|
|
106
|
+
root.vertical.direction === "DOWN"
|
|
107
|
+
? { ...root.vertical, minimum: root.vertical.maximum - offset - verticalSize, maximum: root.vertical.maximum - offset }
|
|
108
|
+
: { ...root.vertical, minimum: root.vertical.minimum + offset, maximum: root.vertical.minimum + offset + verticalSize };
|
|
109
|
+
}
|
|
110
|
+
return { ...root, minEasting, minNorthing, maxEasting: minEasting + eastingSize, maxNorthing: minNorthing + northingSize, vertical };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function subdivideImplicitBoundingVolume(
|
|
114
|
+
root: IBoundingVolume,
|
|
115
|
+
scheme: IImplicitTiling["subdivisionScheme"],
|
|
116
|
+
coordinates: IImplicitCoordinates,
|
|
117
|
+
): IBoundingVolume {
|
|
118
|
+
const scale = coordinateScale(coordinates.level);
|
|
119
|
+
const utm = getUtmBoundingVolume(root);
|
|
120
|
+
if (utm) return createUtmBoundingVolume(subdivideUtmExtent(utm, scheme, coordinates, scale));
|
|
121
|
+
if (root.region) {
|
|
122
|
+
const [west, south, east, north, minimumHeight, maximumHeight] = root.region;
|
|
123
|
+
const unwrappedEast = east < west ? east + Math.PI * 2 : east;
|
|
124
|
+
const longitudeSize = (unwrappedEast - west) / scale;
|
|
125
|
+
const latitudeSize = (north - south) / scale;
|
|
126
|
+
const childWest = west + longitudeSize * coordinates.x;
|
|
127
|
+
const childEast = childWest + longitudeSize;
|
|
128
|
+
let childMinimumHeight = minimumHeight;
|
|
129
|
+
let childMaximumHeight = maximumHeight;
|
|
130
|
+
if (scheme === "OCTREE") {
|
|
131
|
+
const heightSize = (maximumHeight - minimumHeight) / scale;
|
|
132
|
+
childMinimumHeight = minimumHeight + heightSize * (coordinates.z ?? 0);
|
|
133
|
+
childMaximumHeight = childMinimumHeight + heightSize;
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
region: [
|
|
137
|
+
normalizeLongitude(childWest),
|
|
138
|
+
south + latitudeSize * coordinates.y,
|
|
139
|
+
normalizeLongitude(childEast),
|
|
140
|
+
south + latitudeSize * (coordinates.y + 1),
|
|
141
|
+
childMinimumHeight,
|
|
142
|
+
childMaximumHeight,
|
|
143
|
+
],
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
if (root.box) {
|
|
147
|
+
const [cx, cy, cz, ...axes] = root.box;
|
|
148
|
+
const xAxis = axes.slice(0, 3);
|
|
149
|
+
const yAxis = axes.slice(3, 6);
|
|
150
|
+
const zAxis = axes.slice(6, 9);
|
|
151
|
+
const xCoefficient = -1 + (2 * coordinates.x + 1) / scale;
|
|
152
|
+
const yCoefficient = -1 + (2 * coordinates.y + 1) / scale;
|
|
153
|
+
const zCoefficient = scheme === "OCTREE" ? -1 + (2 * (coordinates.z ?? 0) + 1) / scale : 0;
|
|
154
|
+
const center = [
|
|
155
|
+
cx + xAxis[0]! * xCoefficient + yAxis[0]! * yCoefficient + zAxis[0]! * zCoefficient,
|
|
156
|
+
cy + xAxis[1]! * xCoefficient + yAxis[1]! * yCoefficient + zAxis[1]! * zCoefficient,
|
|
157
|
+
cz + xAxis[2]! * xCoefficient + yAxis[2]! * yCoefficient + zAxis[2]! * zCoefficient,
|
|
158
|
+
];
|
|
159
|
+
const zScale = scheme === "OCTREE" ? scale : 1;
|
|
160
|
+
return {
|
|
161
|
+
box: [
|
|
162
|
+
center[0]!,
|
|
163
|
+
center[1]!,
|
|
164
|
+
center[2]!,
|
|
165
|
+
xAxis[0]! / scale,
|
|
166
|
+
xAxis[1]! / scale,
|
|
167
|
+
xAxis[2]! / scale,
|
|
168
|
+
yAxis[0]! / scale,
|
|
169
|
+
yAxis[1]! / scale,
|
|
170
|
+
yAxis[2]! / scale,
|
|
171
|
+
zAxis[0]! / zScale,
|
|
172
|
+
zAxis[1]! / zScale,
|
|
173
|
+
zAxis[2]! / zScale,
|
|
174
|
+
],
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
throw new Error("Implicit tiling requires a box, region or SPACEXR_bounding_volume_utm bounding volume.");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function computeImplicitTile(
|
|
181
|
+
rootTile: ITile,
|
|
182
|
+
tiling: IImplicitTiling,
|
|
183
|
+
coordinates: IImplicitCoordinates,
|
|
184
|
+
): Pick<ITile, "boundingVolume" | "geometricError"> & {
|
|
185
|
+
contents: readonly IContent[];
|
|
186
|
+
} {
|
|
187
|
+
const templates = rootTile.contents ? [...rootTile.contents] : rootTile.content ? [rootTile.content] : [];
|
|
188
|
+
return {
|
|
189
|
+
boundingVolume: subdivideImplicitBoundingVolume(rootTile.boundingVolume, tiling.subdivisionScheme, coordinates),
|
|
190
|
+
geometricError: rootTile.geometricError / coordinateScale(coordinates.level),
|
|
191
|
+
contents: templates.map((content) => ({ ...content, uri: expandImplicitTemplate(content.uri, coordinates) })),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ISubtree } from "@spacexr/3d-tiles-core";
|
|
2
|
+
|
|
3
|
+
import type { IImplicitSubtreeLoader, IImplicitSubtreeLoadRequest, ILoadedImplicitSubtree } from "./types";
|
|
4
|
+
|
|
5
|
+
/** Virtual dense availability for regular Web Map and DEM pyramids. */
|
|
6
|
+
export class DenseImplicitSubtreeLoader implements IImplicitSubtreeLoader {
|
|
7
|
+
public async load(request: IImplicitSubtreeLoadRequest): Promise<ILoadedImplicitSubtree> {
|
|
8
|
+
if (request.signal.aborted) throw request.signal.reason;
|
|
9
|
+
const hasChildSubtrees = request.coordinates.level + request.implicitTiling.subtreeLevels < request.implicitTiling.availableLevels;
|
|
10
|
+
const subtree: ISubtree = {
|
|
11
|
+
tileAvailability: { constant: 1 },
|
|
12
|
+
...(request.contentCount > 0
|
|
13
|
+
? {
|
|
14
|
+
contentAvailability: Array.from({ length: request.contentCount }, () => ({ constant: 1 as const })) as [
|
|
15
|
+
{ constant: 1 },
|
|
16
|
+
],
|
|
17
|
+
}
|
|
18
|
+
: {}),
|
|
19
|
+
childSubtreeAvailability: { constant: hasChildSubtrees ? 1 : 0 },
|
|
20
|
+
};
|
|
21
|
+
return { subtree };
|
|
22
|
+
}
|
|
23
|
+
}
|