@loaders.gl/tiles 4.0.0-alpha.8 → 4.0.0-beta.1

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 (33) hide show
  1. package/dist/dist.min.js +144 -80
  2. package/dist/es5/tileset/tileset-3d.js.map +1 -1
  3. package/dist/es5/tileset/tileset-traverser.js +1 -1
  4. package/dist/es5/tileset/tileset-traverser.js.map +1 -1
  5. package/dist/esm/tileset/tileset-3d.js.map +1 -1
  6. package/dist/esm/tileset/tileset-traverser.js +1 -1
  7. package/dist/esm/tileset/tileset-traverser.js.map +1 -1
  8. package/dist/tileset/tileset-3d.d.ts.map +1 -1
  9. package/package.json +5 -5
  10. package/src/tileset/tileset-3d.ts +1 -0
  11. package/src/tileset/tileset-traverser.ts +1 -1
  12. package/dist/bundle.js +0 -5
  13. package/dist/constants.js +0 -39
  14. package/dist/index.js +0 -26
  15. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js +0 -54
  16. package/dist/tileset/format-i3s/i3s-pending-tiles-register.js +0 -47
  17. package/dist/tileset/format-i3s/i3s-tile-manager.js +0 -80
  18. package/dist/tileset/format-i3s/i3s-tileset-traverser.js +0 -92
  19. package/dist/tileset/helpers/3d-tiles-options.js +0 -9
  20. package/dist/tileset/helpers/bounding-volume.js +0 -293
  21. package/dist/tileset/helpers/frame-state.js +0 -133
  22. package/dist/tileset/helpers/i3s-lod.js +0 -85
  23. package/dist/tileset/helpers/tiles-3d-lod.js +0 -117
  24. package/dist/tileset/helpers/transform-utils.js +0 -53
  25. package/dist/tileset/helpers/zoom.js +0 -89
  26. package/dist/tileset/tile-3d.js +0 -610
  27. package/dist/tileset/tileset-3d.js +0 -715
  28. package/dist/tileset/tileset-cache.js +0 -72
  29. package/dist/tileset/tileset-traverser.js +0 -300
  30. package/dist/types.js +0 -2
  31. package/dist/utils/doubly-linked-list-node.js +0 -18
  32. package/dist/utils/doubly-linked-list.js +0 -97
  33. package/dist/utils/managed-array.js +0 -152
@@ -1,715 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Tileset3D = void 0;
5
- // This file is derived from the Cesium code base under Apache 2 license
6
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
7
- const core_1 = require("@math.gl/core");
8
- const geospatial_1 = require("@math.gl/geospatial");
9
- const stats_1 = require("@probe.gl/stats");
10
- const loader_utils_1 = require("@loaders.gl/loader-utils");
11
- const tileset_cache_1 = require("./tileset-cache");
12
- const transform_utils_1 = require("./helpers/transform-utils");
13
- const frame_state_1 = require("./helpers/frame-state");
14
- const zoom_1 = require("./helpers/zoom");
15
- const tile_3d_1 = require("./tile-3d");
16
- const constants_1 = require("../constants");
17
- const tileset_traverser_1 = require("./tileset-traverser");
18
- // TODO - these should be moved into their respective modules
19
- const tileset_3d_traverser_1 = require("./format-3d-tiles/tileset-3d-traverser");
20
- const i3s_tileset_traverser_1 = require("./format-i3s/i3s-tileset-traverser");
21
- const DEFAULT_PROPS = {
22
- description: '',
23
- ellipsoid: geospatial_1.Ellipsoid.WGS84,
24
- modelMatrix: new core_1.Matrix4(),
25
- throttleRequests: true,
26
- maxRequests: 64,
27
- maximumMemoryUsage: 32,
28
- maximumTilesSelected: 0,
29
- debounceTime: 0,
30
- onTileLoad: () => { },
31
- onTileUnload: () => { },
32
- onTileError: () => { },
33
- onTraversalComplete: (selectedTiles) => selectedTiles,
34
- contentLoader: undefined,
35
- viewDistanceScale: 1.0,
36
- maximumScreenSpaceError: 8,
37
- loadTiles: true,
38
- updateTransforms: true,
39
- viewportTraversersMap: null,
40
- loadOptions: { fetch: {} },
41
- attributions: [],
42
- basePath: '',
43
- i3s: {}
44
- };
45
- // Tracked Stats
46
- const TILES_TOTAL = 'Tiles In Tileset(s)';
47
- const TILES_IN_MEMORY = 'Tiles In Memory';
48
- const TILES_IN_VIEW = 'Tiles In View';
49
- const TILES_RENDERABLE = 'Tiles To Render';
50
- const TILES_LOADED = 'Tiles Loaded';
51
- const TILES_LOADING = 'Tiles Loading';
52
- const TILES_UNLOADED = 'Tiles Unloaded';
53
- const TILES_LOAD_FAILED = 'Failed Tile Loads';
54
- const POINTS_COUNT = 'Points/Vertices';
55
- const TILES_GPU_MEMORY = 'Tile Memory Use';
56
- /**
57
- * The Tileset loading and rendering flow is as below,
58
- * A rendered (i.e. deck.gl `Tile3DLayer`) triggers `tileset.update()` after a `tileset` is loaded
59
- * `tileset` starts traversing the tile tree and update `requestTiles` (tiles of which content need
60
- * to be fetched) and `selectedTiles` (tiles ready for rendering under the current viewport).
61
- * `Tile3DLayer` will update rendering based on `selectedTiles`.
62
- * `Tile3DLayer` also listens to `onTileLoad` callback and trigger another round of `update and then traversal`
63
- * when new tiles are loaded.
64
-
65
- * As I3S tileset have stored `tileHeader` file (metadata) and tile content files (geometry, texture, ...) separately.
66
- * During each traversal, it issues `tilHeader` requests if that `tileHeader` is not yet fetched,
67
- * after the tile header is fulfilled, it will resume the traversal starting from the tile just fetched (not root).
68
-
69
- * Tile3DLayer
70
- * |
71
- * await load(tileset)
72
- * |
73
- * tileset.update()
74
- * | async load tileHeader
75
- * tileset.traverse() -------------------------- Queued
76
- * | resume traversal after fetched |
77
- * |----------------------------------------|
78
- * |
79
- * | async load tile content
80
- * tilset.requestedTiles ----------------------------- RequestScheduler
81
- * |
82
- * tilset.selectedTiles (ready for rendering) |
83
- * | Listen to |
84
- * Tile3DLayer ----------- onTileLoad ----------------------|
85
- * | | notify new tile is available
86
- * updateLayers |
87
- * tileset.update // trigger another round of update
88
- */
89
- class Tileset3D {
90
- /**
91
- * Create a new Tileset3D
92
- * @param json
93
- * @param props
94
- */
95
- // eslint-disable-next-line max-statements
96
- constructor(tileset, options) {
97
- this.root = null;
98
- this.roots = {};
99
- /** @todo any->unknown */
100
- this.asset = {};
101
- // Metadata for the entire tileset
102
- this.description = '';
103
- this.extras = null;
104
- this.attributions = {};
105
- this.credits = {};
106
- /** flags that contain information about data types in nested tiles */
107
- this.contentFormats = { draco: false, meshopt: false, dds: false, ktx2: false };
108
- // view props
109
- this.cartographicCenter = null;
110
- this.cartesianCenter = null;
111
- this.zoom = 1;
112
- this.boundingVolume = null;
113
- /** Updated based on the camera position and direction */
114
- this.dynamicScreenSpaceErrorComputedDensity = 0.0;
115
- // METRICS
116
- /**
117
- * The maximum amount of GPU memory (in MB) that may be used to cache tiles
118
- * Tiles not in view are unloaded to enforce private
119
- */
120
- this.maximumMemoryUsage = 32;
121
- /** The total amount of GPU memory in bytes used by the tileset. */
122
- this.gpuMemoryUsageInBytes = 0;
123
- /** Update tracker. increase in each update cycle. */
124
- this._frameNumber = 0;
125
- this._queryParams = {};
126
- this._extensionsUsed = [];
127
- this._tiles = {};
128
- /** counter for tracking tiles requests */
129
- this._pendingCount = 0;
130
- /** Hold traversal results */
131
- this.selectedTiles = [];
132
- // TRAVERSAL
133
- this.traverseCounter = 0;
134
- this.geometricError = 0;
135
- this.lastUpdatedVieports = null;
136
- this._requestedTiles = [];
137
- this._emptyTiles = [];
138
- this.frameStateData = {};
139
- this._cache = new tileset_cache_1.TilesetCache();
140
- // Promise tracking
141
- this.updatePromise = null;
142
- // PUBLIC MEMBERS
143
- this.options = { ...DEFAULT_PROPS, ...options };
144
- // raw data
145
- this.tileset = tileset;
146
- this.loader = tileset.loader;
147
- // could be 3d tiles, i3s
148
- this.type = tileset.type;
149
- // The url to a tileset JSON file.
150
- this.url = tileset.url;
151
- this.basePath = tileset.basePath || loader_utils_1.path.dirname(this.url);
152
- this.modelMatrix = this.options.modelMatrix;
153
- this.ellipsoid = this.options.ellipsoid;
154
- // Geometric error when the tree is not rendered at all
155
- this.lodMetricType = tileset.lodMetricType;
156
- this.lodMetricValue = tileset.lodMetricValue;
157
- this.refine = tileset.root.refine;
158
- this.loadOptions = this.options.loadOptions || {};
159
- // TRAVERSAL
160
- this._traverser = this._initializeTraverser();
161
- this._requestScheduler = new loader_utils_1.RequestScheduler({
162
- throttleRequests: this.options.throttleRequests,
163
- maxRequests: this.options.maxRequests
164
- });
165
- // METRICS
166
- // The total amount of GPU memory in bytes used by the tileset.
167
- this.stats = new stats_1.Stats({ id: this.url });
168
- this._initializeStats();
169
- this.tilesetInitializationPromise = this._initializeTileSet(tileset);
170
- }
171
- /** Release resources */
172
- destroy() {
173
- this._destroy();
174
- }
175
- /** Is the tileset loaded (update needs to have been called at least once) */
176
- isLoaded() {
177
- // Check that `_frameNumber !== 0` which means that update was called at least once
178
- return this._pendingCount === 0 && this._frameNumber !== 0 && this._requestedTiles.length === 0;
179
- }
180
- get tiles() {
181
- return Object.values(this._tiles);
182
- }
183
- get frameNumber() {
184
- return this._frameNumber;
185
- }
186
- get queryParams() {
187
- return new URLSearchParams(this._queryParams).toString();
188
- }
189
- setProps(props) {
190
- this.options = { ...this.options, ...props };
191
- }
192
- /** @deprecated */
193
- setOptions(options) {
194
- this.options = { ...this.options, ...options };
195
- }
196
- /**
197
- * Return a loadable tile url for a specific tile subpath
198
- * @param tilePath a tile subpath
199
- */
200
- getTileUrl(tilePath) {
201
- const isDataUrl = tilePath.startsWith('data:');
202
- if (isDataUrl) {
203
- return tilePath;
204
- }
205
- return `${tilePath}${tilePath.includes('?') ? '&' : '?'}${this.queryParams}`;
206
- }
207
- // TODO CESIUM specific
208
- hasExtension(extensionName) {
209
- return Boolean(this._extensionsUsed.indexOf(extensionName) > -1);
210
- }
211
- /**
212
- * Update visible tiles relying on a list of viewports
213
- * @param viewports - list of viewports
214
- * @deprecated
215
- */
216
- update(viewports = null) {
217
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
218
- this.tilesetInitializationPromise.then(() => {
219
- if (!viewports && this.lastUpdatedVieports) {
220
- viewports = this.lastUpdatedVieports;
221
- }
222
- else {
223
- this.lastUpdatedVieports = viewports;
224
- }
225
- if (viewports) {
226
- this.doUpdate(viewports);
227
- }
228
- });
229
- }
230
- /**
231
- * Update visible tiles relying on a list of viewports.
232
- * Do it with debounce delay to prevent update spam
233
- * @param viewports viewports
234
- * @returns Promise of new frameNumber
235
- */
236
- async selectTiles(viewports = null) {
237
- await this.tilesetInitializationPromise;
238
- if (viewports) {
239
- this.lastUpdatedVieports = viewports;
240
- }
241
- if (!this.updatePromise) {
242
- this.updatePromise = new Promise((resolve) => {
243
- setTimeout(() => {
244
- if (this.lastUpdatedVieports) {
245
- this.doUpdate(this.lastUpdatedVieports);
246
- }
247
- resolve(this._frameNumber);
248
- this.updatePromise = null;
249
- }, this.options.debounceTime);
250
- });
251
- }
252
- return this.updatePromise;
253
- }
254
- /**
255
- * Update visible tiles relying on a list of viewports
256
- * @param viewports viewports
257
- */
258
- // eslint-disable-next-line max-statements, complexity
259
- doUpdate(viewports) {
260
- if ('loadTiles' in this.options && !this.options.loadTiles) {
261
- return;
262
- }
263
- if (this.traverseCounter > 0) {
264
- return;
265
- }
266
- const preparedViewports = viewports instanceof Array ? viewports : [viewports];
267
- this._cache.reset();
268
- this._frameNumber++;
269
- this.traverseCounter = preparedViewports.length;
270
- const viewportsToTraverse = [];
271
- // First loop to decrement traverseCounter
272
- for (const viewport of preparedViewports) {
273
- const id = viewport.id;
274
- if (this._needTraverse(id)) {
275
- viewportsToTraverse.push(id);
276
- }
277
- else {
278
- this.traverseCounter--;
279
- }
280
- }
281
- // Second loop to traverse
282
- for (const viewport of preparedViewports) {
283
- const id = viewport.id;
284
- if (!this.roots[id]) {
285
- this.roots[id] = this._initializeTileHeaders(this.tileset, null);
286
- }
287
- if (!viewportsToTraverse.includes(id)) {
288
- continue; // eslint-disable-line no-continue
289
- }
290
- const frameState = (0, frame_state_1.getFrameState)(viewport, this._frameNumber);
291
- this._traverser.traverse(this.roots[id], frameState, this.options);
292
- }
293
- }
294
- /**
295
- * Check if traversal is needed for particular viewport
296
- * @param {string} viewportId - id of a viewport
297
- * @return {boolean}
298
- */
299
- _needTraverse(viewportId) {
300
- let traverserId = viewportId;
301
- if (this.options.viewportTraversersMap) {
302
- traverserId = this.options.viewportTraversersMap[viewportId];
303
- }
304
- if (traverserId !== viewportId) {
305
- return false;
306
- }
307
- return true;
308
- }
309
- /**
310
- * The callback to post-process tiles after traversal procedure
311
- * @param frameState - frame state for tile culling
312
- */
313
- _onTraversalEnd(frameState) {
314
- const id = frameState.viewport.id;
315
- if (!this.frameStateData[id]) {
316
- this.frameStateData[id] = { selectedTiles: [], _requestedTiles: [], _emptyTiles: [] };
317
- }
318
- const currentFrameStateData = this.frameStateData[id];
319
- const selectedTiles = Object.values(this._traverser.selectedTiles);
320
- const [filteredSelectedTiles, unselectedTiles] = (0, frame_state_1.limitSelectedTiles)(selectedTiles, frameState, this.options.maximumTilesSelected);
321
- currentFrameStateData.selectedTiles = filteredSelectedTiles;
322
- for (const tile of unselectedTiles) {
323
- tile.unselect();
324
- }
325
- currentFrameStateData._requestedTiles = Object.values(this._traverser.requestedTiles);
326
- currentFrameStateData._emptyTiles = Object.values(this._traverser.emptyTiles);
327
- this.traverseCounter--;
328
- if (this.traverseCounter > 0) {
329
- return;
330
- }
331
- this._updateTiles();
332
- }
333
- /**
334
- * Update tiles relying on data from all traversers
335
- */
336
- _updateTiles() {
337
- this.selectedTiles = [];
338
- this._requestedTiles = [];
339
- this._emptyTiles = [];
340
- for (const frameStateKey in this.frameStateData) {
341
- const frameStateDataValue = this.frameStateData[frameStateKey];
342
- this.selectedTiles = this.selectedTiles.concat(frameStateDataValue.selectedTiles);
343
- this._requestedTiles = this._requestedTiles.concat(frameStateDataValue._requestedTiles);
344
- this._emptyTiles = this._emptyTiles.concat(frameStateDataValue._emptyTiles);
345
- }
346
- this.selectedTiles = this.options.onTraversalComplete(this.selectedTiles);
347
- for (const tile of this.selectedTiles) {
348
- this._tiles[tile.id] = tile;
349
- }
350
- this._loadTiles();
351
- this._unloadTiles();
352
- this._updateStats();
353
- }
354
- _tilesChanged(oldSelectedTiles, selectedTiles) {
355
- if (oldSelectedTiles.length !== selectedTiles.length) {
356
- return true;
357
- }
358
- const set1 = new Set(oldSelectedTiles.map((t) => t.id));
359
- const set2 = new Set(selectedTiles.map((t) => t.id));
360
- let changed = oldSelectedTiles.filter((x) => !set2.has(x.id)).length > 0;
361
- changed = changed || selectedTiles.filter((x) => !set1.has(x.id)).length > 0;
362
- return changed;
363
- }
364
- _loadTiles() {
365
- // Sort requests by priority before making any requests.
366
- // This makes it less likely this requests will be cancelled after being issued.
367
- // requestedTiles.sort((a, b) => a._priority - b._priority);
368
- for (const tile of this._requestedTiles) {
369
- if (tile.contentUnloaded) {
370
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
371
- this._loadTile(tile);
372
- }
373
- }
374
- }
375
- _unloadTiles() {
376
- // unload tiles from cache when hit maximumMemoryUsage
377
- this._cache.unloadTiles(this, (tileset, tile) => tileset._unloadTile(tile));
378
- }
379
- _updateStats() {
380
- let tilesRenderable = 0;
381
- let pointsRenderable = 0;
382
- for (const tile of this.selectedTiles) {
383
- if (tile.contentAvailable && tile.content) {
384
- tilesRenderable++;
385
- if (tile.content.pointCount) {
386
- pointsRenderable += tile.content.pointCount;
387
- }
388
- else {
389
- // Calculate vertices for non point cloud tiles.
390
- pointsRenderable += tile.content.vertexCount;
391
- }
392
- }
393
- }
394
- this.stats.get(TILES_IN_VIEW).count = this.selectedTiles.length;
395
- this.stats.get(TILES_RENDERABLE).count = tilesRenderable;
396
- this.stats.get(POINTS_COUNT).count = pointsRenderable;
397
- }
398
- async _initializeTileSet(tilesetJson) {
399
- if (this.type === constants_1.TILESET_TYPE.I3S) {
400
- this.calculateViewPropsI3S();
401
- tilesetJson.root = await tilesetJson.root;
402
- }
403
- this.root = this._initializeTileHeaders(tilesetJson, null);
404
- if (this.type === constants_1.TILESET_TYPE.TILES3D) {
405
- this._initializeTiles3DTileset(tilesetJson);
406
- this.calculateViewPropsTiles3D();
407
- }
408
- if (this.type === constants_1.TILESET_TYPE.I3S) {
409
- this._initializeI3STileset();
410
- }
411
- }
412
- /**
413
- * Called during initialize Tileset to initialize the tileset's cartographic center (longitude, latitude) and zoom.
414
- * These metrics help apps center view on tileset
415
- * For I3S there is extent (<1.8 version) or fullExtent (>=1.8 version) to calculate view props
416
- * @returns
417
- */
418
- calculateViewPropsI3S() {
419
- // for I3S 1.8 try to calculate with fullExtent
420
- const fullExtent = this.tileset.fullExtent;
421
- if (fullExtent) {
422
- const { xmin, xmax, ymin, ymax, zmin, zmax } = fullExtent;
423
- this.cartographicCenter = new core_1.Vector3(xmin + (xmax - xmin) / 2, ymin + (ymax - ymin) / 2, zmin + (zmax - zmin) / 2);
424
- this.cartesianCenter = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(this.cartographicCenter, new core_1.Vector3());
425
- this.zoom = (0, zoom_1.getZoomFromFullExtent)(fullExtent, this.cartographicCenter, this.cartesianCenter);
426
- return;
427
- }
428
- // for I3S 1.6-1.7 try to calculate with extent
429
- const extent = this.tileset.store?.extent;
430
- if (extent) {
431
- const [xmin, ymin, xmax, ymax] = extent;
432
- this.cartographicCenter = new core_1.Vector3(xmin + (xmax - xmin) / 2, ymin + (ymax - ymin) / 2, 0);
433
- this.cartesianCenter = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(this.cartographicCenter, new core_1.Vector3());
434
- this.zoom = (0, zoom_1.getZoomFromExtent)(extent, this.cartographicCenter, this.cartesianCenter);
435
- return;
436
- }
437
- // eslint-disable-next-line no-console
438
- console.warn('Extent is not defined in the tileset header');
439
- this.cartographicCenter = new core_1.Vector3();
440
- this.zoom = 1;
441
- return;
442
- }
443
- /**
444
- * Called during initialize Tileset to initialize the tileset's cartographic center (longitude, latitude) and zoom.
445
- * These metrics help apps center view on tileset.
446
- * For 3DTiles the root tile data is used to calculate view props.
447
- * @returns
448
- */
449
- calculateViewPropsTiles3D() {
450
- const root = this.root;
451
- const { center } = root.boundingVolume;
452
- // TODO - handle all cases
453
- if (!center) {
454
- // eslint-disable-next-line no-console
455
- console.warn('center was not pre-calculated for the root tile');
456
- this.cartographicCenter = new core_1.Vector3();
457
- this.zoom = 1;
458
- return;
459
- }
460
- // cartographic coordinates are undefined at the center of the ellipsoid
461
- if (center[0] !== 0 || center[1] !== 0 || center[2] !== 0) {
462
- this.cartographicCenter = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(center, new core_1.Vector3());
463
- }
464
- else {
465
- this.cartographicCenter = new core_1.Vector3(0, 0, -geospatial_1.Ellipsoid.WGS84.radii[0]);
466
- }
467
- this.cartesianCenter = center;
468
- this.zoom = (0, zoom_1.getZoomFromBoundingVolume)(root.boundingVolume, this.cartographicCenter);
469
- }
470
- _initializeStats() {
471
- this.stats.get(TILES_TOTAL);
472
- this.stats.get(TILES_LOADING);
473
- this.stats.get(TILES_IN_MEMORY);
474
- this.stats.get(TILES_IN_VIEW);
475
- this.stats.get(TILES_RENDERABLE);
476
- this.stats.get(TILES_LOADED);
477
- this.stats.get(TILES_UNLOADED);
478
- this.stats.get(TILES_LOAD_FAILED);
479
- this.stats.get(POINTS_COUNT);
480
- this.stats.get(TILES_GPU_MEMORY, 'memory');
481
- }
482
- // Installs the main tileset JSON file or a tileset JSON file referenced from a tile.
483
- // eslint-disable-next-line max-statements
484
- _initializeTileHeaders(tilesetJson, parentTileHeader) {
485
- // A tileset JSON file referenced from a tile may exist in a different directory than the root tileset.
486
- // Get the basePath relative to the external tileset.
487
- const rootTile = new tile_3d_1.Tile3D(this, tilesetJson.root, parentTileHeader); // resource
488
- // If there is a parentTileHeader, add the root of the currently loading tileset
489
- // to parentTileHeader's children, and update its depth.
490
- if (parentTileHeader) {
491
- parentTileHeader.children.push(rootTile);
492
- rootTile.depth = parentTileHeader.depth + 1;
493
- }
494
- // 3DTiles knows the hierarchy beforehand
495
- if (this.type === constants_1.TILESET_TYPE.TILES3D) {
496
- const stack = [];
497
- stack.push(rootTile);
498
- while (stack.length > 0) {
499
- const tile = stack.pop();
500
- this.stats.get(TILES_TOTAL).incrementCount();
501
- const children = tile.header.children || [];
502
- for (const childHeader of children) {
503
- const childTile = new tile_3d_1.Tile3D(this, childHeader, tile);
504
- // Special handling for Google
505
- // A session key must be used for all tile requests
506
- if (childTile.contentUrl?.includes('?session=')) {
507
- const url = new URL(childTile.contentUrl);
508
- const session = url.searchParams.get('session');
509
- if (session) {
510
- this._queryParams.session = session;
511
- }
512
- }
513
- tile.children.push(childTile);
514
- childTile.depth = tile.depth + 1;
515
- stack.push(childTile);
516
- }
517
- }
518
- }
519
- return rootTile;
520
- }
521
- _initializeTraverser() {
522
- let TraverserClass;
523
- const type = this.type;
524
- switch (type) {
525
- case constants_1.TILESET_TYPE.TILES3D:
526
- TraverserClass = tileset_3d_traverser_1.Tileset3DTraverser;
527
- break;
528
- case constants_1.TILESET_TYPE.I3S:
529
- TraverserClass = i3s_tileset_traverser_1.I3STilesetTraverser;
530
- break;
531
- default:
532
- TraverserClass = tileset_traverser_1.TilesetTraverser;
533
- }
534
- return new TraverserClass({
535
- basePath: this.basePath,
536
- onTraversalEnd: this._onTraversalEnd.bind(this)
537
- });
538
- }
539
- _destroyTileHeaders(parentTile) {
540
- this._destroySubtree(parentTile);
541
- }
542
- async _loadTile(tile) {
543
- let loaded;
544
- try {
545
- this._onStartTileLoading();
546
- loaded = await tile.loadContent();
547
- }
548
- catch (error) {
549
- this._onTileLoadError(tile, error instanceof Error ? error : new Error('load failed'));
550
- }
551
- finally {
552
- this._onEndTileLoading();
553
- this._onTileLoad(tile, loaded);
554
- }
555
- }
556
- _onTileLoadError(tile, error) {
557
- this.stats.get(TILES_LOAD_FAILED).incrementCount();
558
- const message = error.message || error.toString();
559
- const url = tile.url;
560
- // TODO - Allow for probe log to be injected instead of console?
561
- console.error(`A 3D tile failed to load: ${tile.url} ${message}`); // eslint-disable-line
562
- this.options.onTileError(tile, message, url);
563
- }
564
- _onTileLoad(tile, loaded) {
565
- if (!loaded) {
566
- return;
567
- }
568
- if (this.type === constants_1.TILESET_TYPE.I3S) {
569
- // We can't calculate tiles total in I3S in advance so we calculate it dynamically.
570
- const nodesInNodePages = this.tileset?.nodePagesTile?.nodesInNodePages || 0;
571
- this.stats.get(TILES_TOTAL).reset();
572
- this.stats.get(TILES_TOTAL).addCount(nodesInNodePages);
573
- }
574
- // add coordinateOrigin and modelMatrix to tile
575
- if (tile && tile.content) {
576
- (0, transform_utils_1.calculateTransformProps)(tile, tile.content);
577
- }
578
- this.updateContentTypes(tile);
579
- this._addTileToCache(tile);
580
- this.options.onTileLoad(tile);
581
- }
582
- /**
583
- * Update information about data types in nested tiles
584
- * @param tile instance of a nested Tile3D
585
- */
586
- updateContentTypes(tile) {
587
- if (this.type === constants_1.TILESET_TYPE.I3S) {
588
- if (tile.header.isDracoGeometry) {
589
- this.contentFormats.draco = true;
590
- }
591
- switch (tile.header.textureFormat) {
592
- case 'dds':
593
- this.contentFormats.dds = true;
594
- break;
595
- case 'ktx2':
596
- this.contentFormats.ktx2 = true;
597
- break;
598
- default:
599
- }
600
- }
601
- else if (this.type === constants_1.TILESET_TYPE.TILES3D) {
602
- const { extensionsRemoved = [] } = tile.content?.gltf || {};
603
- if (extensionsRemoved.includes('KHR_draco_mesh_compression')) {
604
- this.contentFormats.draco = true;
605
- }
606
- if (extensionsRemoved.includes('EXT_meshopt_compression')) {
607
- this.contentFormats.meshopt = true;
608
- }
609
- if (extensionsRemoved.includes('KHR_texture_basisu')) {
610
- this.contentFormats.ktx2 = true;
611
- }
612
- }
613
- }
614
- _onStartTileLoading() {
615
- this._pendingCount++;
616
- this.stats.get(TILES_LOADING).incrementCount();
617
- }
618
- _onEndTileLoading() {
619
- this._pendingCount--;
620
- this.stats.get(TILES_LOADING).decrementCount();
621
- }
622
- _addTileToCache(tile) {
623
- this._cache.add(this, tile, (tileset) => tileset._updateCacheStats(tile));
624
- }
625
- _updateCacheStats(tile) {
626
- this.stats.get(TILES_LOADED).incrementCount();
627
- this.stats.get(TILES_IN_MEMORY).incrementCount();
628
- // Good enough? Just use the raw binary ArrayBuffer's byte length.
629
- this.gpuMemoryUsageInBytes += tile.gpuMemoryUsageInBytes || 0;
630
- this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes;
631
- }
632
- _unloadTile(tile) {
633
- this.gpuMemoryUsageInBytes -= tile.gpuMemoryUsageInBytes || 0;
634
- this.stats.get(TILES_IN_MEMORY).decrementCount();
635
- this.stats.get(TILES_UNLOADED).incrementCount();
636
- this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes;
637
- this.options.onTileUnload(tile);
638
- tile.unloadContent();
639
- }
640
- // Traverse the tree and destroy all tiles
641
- _destroy() {
642
- const stack = [];
643
- if (this.root) {
644
- stack.push(this.root);
645
- }
646
- while (stack.length > 0) {
647
- const tile = stack.pop();
648
- for (const child of tile.children) {
649
- stack.push(child);
650
- }
651
- this._destroyTile(tile);
652
- }
653
- this.root = null;
654
- }
655
- // Traverse the tree and destroy all sub tiles
656
- _destroySubtree(tile) {
657
- const root = tile;
658
- const stack = [];
659
- stack.push(root);
660
- while (stack.length > 0) {
661
- tile = stack.pop();
662
- for (const child of tile.children) {
663
- stack.push(child);
664
- }
665
- if (tile !== root) {
666
- this._destroyTile(tile);
667
- }
668
- }
669
- root.children = [];
670
- }
671
- _destroyTile(tile) {
672
- this._cache.unloadTile(this, tile);
673
- this._unloadTile(tile);
674
- tile.destroy();
675
- }
676
- _initializeTiles3DTileset(tilesetJson) {
677
- if (tilesetJson.queryString) {
678
- const searchParams = new URLSearchParams(tilesetJson.queryString);
679
- const queryParams = Object.fromEntries(searchParams.entries());
680
- this._queryParams = { ...this._queryParams, ...queryParams };
681
- }
682
- this.asset = tilesetJson.asset;
683
- if (!this.asset) {
684
- throw new Error('Tileset must have an asset property.');
685
- }
686
- if (this.asset.version !== '0.0' &&
687
- this.asset.version !== '1.0' &&
688
- this.asset.version !== '1.1') {
689
- throw new Error('The tileset must be 3D Tiles version either 0.0 or 1.0 or 1.1.');
690
- }
691
- // Note: `asset.tilesetVersion` is version of the tileset itself (not the version of the 3D TILES standard)
692
- // We add this version as a `v=1.0` query param to fetch the right version and not get an older cached version
693
- if ('tilesetVersion' in this.asset) {
694
- this._queryParams.v = this.asset.tilesetVersion;
695
- }
696
- // TODO - ion resources have a credits property we can use for additional attribution.
697
- this.credits = {
698
- attributions: this.options.attributions || []
699
- };
700
- this.description = this.options.description || '';
701
- // Gets the tileset's properties dictionary object, which contains metadata about per-feature properties.
702
- this.properties = tilesetJson.properties;
703
- this.geometricError = tilesetJson.geometricError;
704
- this._extensionsUsed = tilesetJson.extensionsUsed || [];
705
- // Returns the extras property at the top of the tileset JSON (application specific metadata).
706
- this.extras = tilesetJson.extras;
707
- }
708
- _initializeI3STileset() {
709
- // @ts-expect-error
710
- if (this.loadOptions.i3s && 'token' in this.loadOptions.i3s) {
711
- this._queryParams.token = this.loadOptions.i3s.token;
712
- }
713
- }
714
- }
715
- exports.Tileset3D = Tileset3D;