@loaders.gl/tiles 3.1.0-alpha.5 → 3.1.0-beta.5

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 (84) hide show
  1. package/dist/bundle.d.ts +1 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +8136 -0
  4. package/dist/constants.d.ts +1 -0
  5. package/dist/constants.d.ts.map +1 -0
  6. package/dist/constants.js +35 -0
  7. package/dist/es5/tileset/helpers/i3s-lod.js.map +1 -1
  8. package/dist/es5/tileset/tileset-cache.js.map +1 -1
  9. package/dist/es5/utils/doubly-linked-list-node.js +7 -0
  10. package/dist/es5/utils/doubly-linked-list-node.js.map +1 -1
  11. package/dist/es5/utils/doubly-linked-list.js +5 -3
  12. package/dist/es5/utils/doubly-linked-list.js.map +1 -1
  13. package/dist/es5/utils/managed-array.js +7 -1
  14. package/dist/es5/utils/managed-array.js.map +1 -1
  15. package/dist/esm/tileset/helpers/i3s-lod.js.map +1 -1
  16. package/dist/esm/tileset/tileset-cache.js.map +1 -1
  17. package/dist/esm/utils/doubly-linked-list-node.js +7 -0
  18. package/dist/esm/utils/doubly-linked-list-node.js.map +1 -1
  19. package/dist/esm/utils/doubly-linked-list.js +6 -3
  20. package/dist/esm/utils/doubly-linked-list.js.map +1 -1
  21. package/dist/esm/utils/managed-array.js +7 -1
  22. package/dist/esm/utils/managed-array.js.map +1 -1
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +28 -0
  26. package/dist/tileset/helpers/3d-tiles-options.d.ts +1 -0
  27. package/dist/tileset/helpers/3d-tiles-options.d.ts.map +1 -0
  28. package/dist/tileset/helpers/3d-tiles-options.js +9 -0
  29. package/dist/tileset/helpers/bounding-volume.d.ts +1 -0
  30. package/dist/tileset/helpers/bounding-volume.d.ts.map +1 -0
  31. package/dist/tileset/helpers/bounding-volume.js +177 -0
  32. package/dist/tileset/helpers/frame-state.d.ts +1 -0
  33. package/dist/tileset/helpers/frame-state.d.ts.map +1 -0
  34. package/dist/tileset/helpers/frame-state.js +70 -0
  35. package/dist/tileset/helpers/i3s-lod.d.ts +2 -1
  36. package/dist/tileset/helpers/i3s-lod.d.ts.map +1 -0
  37. package/dist/tileset/helpers/i3s-lod.js +83 -0
  38. package/dist/tileset/helpers/tiles-3d-lod.d.ts +1 -0
  39. package/dist/tileset/helpers/tiles-3d-lod.d.ts.map +1 -0
  40. package/dist/tileset/helpers/tiles-3d-lod.js +116 -0
  41. package/dist/tileset/helpers/transform-utils.d.ts +1 -0
  42. package/dist/tileset/helpers/transform-utils.d.ts.map +1 -0
  43. package/dist/tileset/helpers/transform-utils.js +52 -0
  44. package/dist/tileset/helpers/zoom.d.ts +1 -0
  45. package/dist/tileset/helpers/zoom.d.ts.map +1 -0
  46. package/dist/tileset/helpers/zoom.js +42 -0
  47. package/dist/tileset/tile-3d.d.ts +1 -0
  48. package/dist/tileset/tile-3d.d.ts.map +1 -0
  49. package/dist/tileset/tile-3d.js +554 -0
  50. package/dist/tileset/tileset-3d.d.ts +1 -0
  51. package/dist/tileset/tileset-3d.d.ts.map +1 -0
  52. package/dist/tileset/tileset-3d.js +601 -0
  53. package/dist/tileset/tileset-cache.d.ts +1 -0
  54. package/dist/tileset/tileset-cache.d.ts.map +1 -0
  55. package/dist/tileset/tileset-cache.js +79 -0
  56. package/dist/tileset/traversers/i3s-tile-manager.d.ts +1 -0
  57. package/dist/tileset/traversers/i3s-tile-manager.d.ts.map +1 -0
  58. package/dist/tileset/traversers/i3s-tile-manager.js +36 -0
  59. package/dist/tileset/traversers/i3s-tileset-traverser.d.ts +1 -0
  60. package/dist/tileset/traversers/i3s-tileset-traverser.d.ts.map +1 -0
  61. package/dist/tileset/traversers/i3s-tileset-traverser.js +85 -0
  62. package/dist/tileset/traversers/tileset-3d-traverser.d.ts +1 -0
  63. package/dist/tileset/traversers/tileset-3d-traverser.d.ts.map +1 -0
  64. package/dist/tileset/traversers/tileset-3d-traverser.js +55 -0
  65. package/dist/tileset/traversers/tileset-traverser.d.ts +1 -0
  66. package/dist/tileset/traversers/tileset-traverser.d.ts.map +1 -0
  67. package/dist/tileset/traversers/tileset-traverser.js +294 -0
  68. package/dist/utils/doubly-linked-list-node.d.ts +2 -1
  69. package/dist/utils/doubly-linked-list-node.d.ts.map +1 -0
  70. package/dist/utils/doubly-linked-list-node.js +17 -0
  71. package/dist/utils/doubly-linked-list.d.ts +7 -6
  72. package/dist/utils/doubly-linked-list.d.ts.map +1 -0
  73. package/dist/utils/doubly-linked-list.js +100 -0
  74. package/dist/utils/managed-array.d.ts +10 -9
  75. package/dist/utils/managed-array.d.ts.map +1 -0
  76. package/dist/utils/managed-array.js +151 -0
  77. package/package.json +6 -7
  78. package/src/tileset/helpers/i3s-lod.ts +1 -1
  79. package/src/tileset/tileset-cache.ts +2 -0
  80. package/src/utils/{doubly-linked-list-node.js → doubly-linked-list-node.ts} +4 -0
  81. package/src/utils/{doubly-linked-list.js → doubly-linked-list.ts} +3 -5
  82. package/src/utils/{managed-array.js → managed-array.ts} +4 -1
  83. package/dist/dist.min.js +0 -2
  84. package/dist/dist.min.js.map +0 -1
@@ -0,0 +1,601 @@
1
+ "use strict";
2
+ // This file is derived from the Cesium code base under Apache 2 license
3
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ /*
9
+
10
+ The Tileset loading and rendering flow is as below,
11
+ A rendered (i.e. deck.gl `Tile3DLayer`) triggers `tileset.update()` after a `tileset` is loaded
12
+ `tileset` starts traversing the tile tree and update `requestTiles` (tiles of which content need
13
+ to be fetched) and `selectedTiles` (tiles ready for rendering under the current viewport).
14
+ `Tile3DLayer` will update rendering based on `selectedTiles`.
15
+ `Tile3DLayer` also listens to `onTileLoad` callback and trigger another round of `update and then traversal`
16
+ when new tiles are loaded.
17
+
18
+ As I3S tileset have stored `tileHeader` file (metadata) and tile content files (geometry, texture, ...) separately.
19
+ During each traversal, it issues `tilHeader` requests if that `tileHeader` is not yet fetched,
20
+ after the tile header is fulfilled, it will resume the traversal starting from the tile just fetched (not root).
21
+
22
+ Tile3DLayer
23
+ |
24
+ await load(tileset)
25
+ |
26
+ tileset.update()
27
+ | async load tileHeader
28
+ tileset.traverse() -------------------------- Queued
29
+ | resume traversal after fetched |
30
+ |----------------------------------------|
31
+ |
32
+ | async load tile content
33
+ tilset.requestedTiles ----------------------------- RequestScheduler
34
+ |
35
+ tilset.selectedTiles (ready for rendering) |
36
+ | Listen to |
37
+ Tile3DLayer ----------- onTileLoad ----------------------|
38
+ | | notify new tile is available
39
+ updateLayers |
40
+ tileset.update // trigger another round of update
41
+ */
42
+ const core_1 = require("@math.gl/core");
43
+ const geospatial_1 = require("@math.gl/geospatial");
44
+ const stats_1 = require("@probe.gl/stats");
45
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
46
+ const tileset_cache_1 = __importDefault(require("./tileset-cache"));
47
+ const transform_utils_1 = require("./helpers/transform-utils");
48
+ const frame_state_1 = require("./helpers/frame-state");
49
+ const zoom_1 = require("./helpers/zoom");
50
+ const tile_3d_1 = __importDefault(require("./tile-3d"));
51
+ const tileset_3d_traverser_1 = __importDefault(require("./traversers/tileset-3d-traverser"));
52
+ const tileset_traverser_1 = __importDefault(require("./traversers/tileset-traverser"));
53
+ const i3s_tileset_traverser_1 = __importDefault(require("./traversers/i3s-tileset-traverser"));
54
+ const constants_1 = require("../constants");
55
+ const DEFAULT_PROPS = {
56
+ description: '',
57
+ ellipsoid: geospatial_1.Ellipsoid.WGS84,
58
+ // A 4x4 transformation matrix this transforms the entire tileset.
59
+ modelMatrix: new core_1.Matrix4(),
60
+ // Set to false to disable network request throttling
61
+ throttleRequests: true,
62
+ // Number of simultaneous requsts, if throttleRequests is true
63
+ maxRequests: 64,
64
+ maximumMemoryUsage: 32,
65
+ /**
66
+ * Callback. Indicates this a tile's content was loaded
67
+ * @param tile {TileHeader}
68
+ */
69
+ onTileLoad: () => { },
70
+ /**
71
+ * Callback. Indicates this a tile's content was unloaded
72
+ * @param tile {TileHeader}
73
+ */
74
+ onTileUnload: () => { },
75
+ onTileError: () => { },
76
+ /**
77
+ * Callback. Allows post-process selectedTiles right after traversal.
78
+ * @param selectedTiles {TileHeader[]}
79
+ * @returns TileHeader[] - output array of tiles to return to deck.gl
80
+ */
81
+ onTraversalComplete: (selectedTiles) => selectedTiles,
82
+ // Optional async tile content loader
83
+ contentLoader: undefined,
84
+ // View distance scale modifier
85
+ viewDistanceScale: 1.0,
86
+ // TODO CESIUM
87
+ // The maximum screen space error used to drive level of detail refinement.
88
+ maximumScreenSpaceError: 8,
89
+ loadTiles: true,
90
+ updateTransforms: true,
91
+ viewportTraversersMap: null,
92
+ loadOptions: { fetch: {} },
93
+ attributions: [],
94
+ basePath: '',
95
+ i3s: {}
96
+ };
97
+ // Tracked Stats
98
+ const TILES_TOTAL = 'Tiles In Tileset(s)';
99
+ const TILES_IN_MEMORY = 'Tiles In Memory';
100
+ const TILES_IN_VIEW = 'Tiles In View';
101
+ const TILES_RENDERABLE = 'Tiles To Render';
102
+ const TILES_LOADED = 'Tiles Loaded';
103
+ const TILES_LOADING = 'Tiles Loading';
104
+ const TILES_UNLOADED = 'Tiles Unloaded';
105
+ const TILES_LOAD_FAILED = 'Failed Tile Loads';
106
+ const POINTS_COUNT = 'Points';
107
+ const TILES_GPU_MEMORY = 'Tile Memory Use';
108
+ class Tileset3D {
109
+ /**
110
+ * Create a new Tileset3D
111
+ * @param json
112
+ * @param props
113
+ */
114
+ // eslint-disable-next-line max-statements
115
+ constructor(json, options) {
116
+ (0, loader_utils_1.assert)(json);
117
+ // PUBLIC MEMBERS
118
+ this.options = { ...DEFAULT_PROPS, ...options };
119
+ // raw data
120
+ this.tileset = json;
121
+ this.loader = json.loader;
122
+ // could be 3d tiles, i3s
123
+ this.type = json.type;
124
+ // The url to a tileset JSON file.
125
+ this.url = json.url;
126
+ this.basePath = json.basePath || loader_utils_1.path.dirname(this.url);
127
+ this.modelMatrix = this.options.modelMatrix;
128
+ this.ellipsoid = this.options.ellipsoid;
129
+ // Geometric error when the tree is not rendered at all
130
+ this.lodMetricType = json.lodMetricType;
131
+ this.lodMetricValue = json.lodMetricValue;
132
+ this.refine = json.root.refine;
133
+ this.loadOptions = this.options.loadOptions || {};
134
+ this.root = null;
135
+ this.roots = {};
136
+ // view props
137
+ this.cartographicCenter = null;
138
+ this.cartesianCenter = null;
139
+ this.zoom = 1;
140
+ this.boundingVolume = null;
141
+ // TRAVERSAL
142
+ this.traverseCounter = 0;
143
+ this.geometricError = 0;
144
+ this._traverser = this._initializeTraverser();
145
+ this._cache = new tileset_cache_1.default();
146
+ this._requestScheduler = new loader_utils_1.RequestScheduler({
147
+ throttleRequests: this.options.throttleRequests,
148
+ maxRequests: this.options.maxRequests
149
+ });
150
+ // update tracker
151
+ // increase in each update cycle
152
+ this._frameNumber = 0;
153
+ // counter for tracking tiles requests
154
+ this._pendingCount = 0;
155
+ // HOLD TRAVERSAL RESULTS
156
+ this._tiles = {};
157
+ this.selectedTiles = [];
158
+ this._emptyTiles = [];
159
+ this._requestedTiles = [];
160
+ this.frameStateData = {};
161
+ this.lastUpdatedVieports = null;
162
+ this._queryParams = {};
163
+ this._queryParamsString = '';
164
+ // METRICS
165
+ // The maximum amount of GPU memory (in MB) that may be used to cache tiles.
166
+ // Tiles not in view are unloaded to enforce this.
167
+ this.maximumMemoryUsage = this.options.maximumMemoryUsage || 32;
168
+ // The total amount of GPU memory in bytes used by the tileset.
169
+ this.gpuMemoryUsageInBytes = 0;
170
+ this.stats = new stats_1.Stats({ id: this.url });
171
+ this._initializeStats();
172
+ // EXTRACTED FROM TILESET
173
+ this._extensionsUsed = undefined;
174
+ this.dynamicScreenSpaceErrorComputedDensity = 0.0; // Updated based on the camera position and direction
175
+ // Metadata for the entire tileset
176
+ this.extras = null;
177
+ this.asset = {};
178
+ this.credits = {};
179
+ this.description = this.options.description || '';
180
+ this._initializeTileSet(json);
181
+ }
182
+ /** Release resources */
183
+ destroy() {
184
+ this._destroy();
185
+ }
186
+ /** Is the tileset loaded (update needs to have been called at least once) */
187
+ isLoaded() {
188
+ // Check that `_frameNumber !== 0` which means that update was called at least once
189
+ return this._pendingCount === 0 && this._frameNumber !== 0;
190
+ }
191
+ get tiles() {
192
+ return Object.values(this._tiles);
193
+ }
194
+ get frameNumber() {
195
+ return this._frameNumber;
196
+ }
197
+ get queryParams() {
198
+ if (!this._queryParamsString) {
199
+ this._queryParamsString = getQueryParamString(this._queryParams);
200
+ }
201
+ return this._queryParamsString;
202
+ }
203
+ setProps(props) {
204
+ this.options = { ...this.options, ...props };
205
+ }
206
+ /** @deprecated */
207
+ setOptions(options) {
208
+ this.options = { ...this.options, ...options };
209
+ }
210
+ /**
211
+ * Return a loadable tile url for a specific tile subpath
212
+ * @param tilePath a tile subpath
213
+ */
214
+ getTileUrl(tilePath) {
215
+ const isDataUrl = tilePath.startsWith('data:');
216
+ if (isDataUrl) {
217
+ return tilePath;
218
+ }
219
+ return `${tilePath}${this.queryParams}`;
220
+ }
221
+ // TODO CESIUM specific
222
+ hasExtension(extensionName) {
223
+ return Boolean(this._extensionsUsed && this._extensionsUsed.indexOf(extensionName) > -1);
224
+ }
225
+ /**
226
+ * Update visible tiles relying on a list of viewports
227
+ * @param viewports - list of viewports
228
+ */
229
+ // eslint-disable-next-line max-statements, complexity
230
+ update(viewports) {
231
+ if ('loadTiles' in this.options && !this.options.loadTiles) {
232
+ return;
233
+ }
234
+ if (this.traverseCounter > 0) {
235
+ return;
236
+ }
237
+ if (!viewports && this.lastUpdatedVieports) {
238
+ viewports = this.lastUpdatedVieports;
239
+ }
240
+ else {
241
+ this.lastUpdatedVieports = viewports;
242
+ }
243
+ if (!(viewports instanceof Array)) {
244
+ viewports = [viewports];
245
+ }
246
+ this._cache.reset();
247
+ this._frameNumber++;
248
+ this.traverseCounter = viewports.length;
249
+ const viewportsToTraverse = [];
250
+ // First loop to decrement traverseCounter
251
+ for (const viewport of viewports) {
252
+ const id = viewport.id;
253
+ if (this._needTraverse(id)) {
254
+ viewportsToTraverse.push(id);
255
+ }
256
+ else {
257
+ this.traverseCounter--;
258
+ }
259
+ }
260
+ // Second loop to traverse
261
+ for (const viewport of viewports) {
262
+ const id = viewport.id;
263
+ if (!this.roots[id]) {
264
+ this.roots[id] = this._initializeTileHeaders(this.tileset, null);
265
+ }
266
+ if (!viewportsToTraverse.includes(id)) {
267
+ continue; // eslint-disable-line no-continue
268
+ }
269
+ const frameState = (0, frame_state_1.getFrameState)(viewport, this._frameNumber);
270
+ this._traverser.traverse(this.roots[id], frameState, this.options);
271
+ }
272
+ }
273
+ /**
274
+ * Check if traversal is needed for particular viewport
275
+ * @param {string} viewportId - id of a viewport
276
+ * @return {boolean}
277
+ */
278
+ _needTraverse(viewportId) {
279
+ let traverserId = viewportId;
280
+ if (this.options.viewportTraversersMap) {
281
+ traverserId = this.options.viewportTraversersMap[viewportId];
282
+ }
283
+ if (traverserId !== viewportId) {
284
+ return false;
285
+ }
286
+ return true;
287
+ }
288
+ /**
289
+ * The callback to post-process tiles after traversal procedure
290
+ * @param frameState - frame state for tile culling
291
+ */
292
+ _onTraversalEnd(frameState) {
293
+ const id = frameState.viewport.id;
294
+ if (!this.frameStateData[id]) {
295
+ this.frameStateData[id] = { selectedTiles: [], _requestedTiles: [], _emptyTiles: [] };
296
+ }
297
+ const currentFrameStateData = this.frameStateData[id];
298
+ const selectedTiles = Object.values(this._traverser.selectedTiles);
299
+ currentFrameStateData.selectedTiles = selectedTiles;
300
+ currentFrameStateData._requestedTiles = Object.values(this._traverser.requestedTiles);
301
+ currentFrameStateData._emptyTiles = Object.values(this._traverser.emptyTiles);
302
+ this.traverseCounter--;
303
+ if (this.traverseCounter > 0) {
304
+ return;
305
+ }
306
+ this._updateTiles();
307
+ }
308
+ /**
309
+ * Update tiles relying on data from all traversers
310
+ */
311
+ _updateTiles() {
312
+ this.selectedTiles = [];
313
+ this._requestedTiles = [];
314
+ this._emptyTiles = [];
315
+ for (const frameStateKey in this.frameStateData) {
316
+ const frameStateDataValue = this.frameStateData[frameStateKey];
317
+ this.selectedTiles = this.selectedTiles.concat(frameStateDataValue.selectedTiles);
318
+ this._requestedTiles = this._requestedTiles.concat(frameStateDataValue._requestedTiles);
319
+ this._emptyTiles = this._emptyTiles.concat(frameStateDataValue._emptyTiles);
320
+ }
321
+ this.selectedTiles = this.options.onTraversalComplete(this.selectedTiles);
322
+ for (const tile of this.selectedTiles) {
323
+ this._tiles[tile.id] = tile;
324
+ }
325
+ this._loadTiles();
326
+ this._unloadTiles();
327
+ this._updateStats();
328
+ }
329
+ _tilesChanged(oldSelectedTiles, selectedTiles) {
330
+ if (oldSelectedTiles.length !== selectedTiles.length) {
331
+ return true;
332
+ }
333
+ const set1 = new Set(oldSelectedTiles.map((t) => t.id));
334
+ const set2 = new Set(selectedTiles.map((t) => t.id));
335
+ let changed = oldSelectedTiles.filter((x) => !set2.has(x.id)).length > 0;
336
+ changed = changed || selectedTiles.filter((x) => !set1.has(x.id)).length > 0;
337
+ return changed;
338
+ }
339
+ _loadTiles() {
340
+ // Sort requests by priority before making any requests.
341
+ // This makes it less likely this requests will be cancelled after being issued.
342
+ // requestedTiles.sort((a, b) => a._priority - b._priority);
343
+ for (const tile of this._requestedTiles) {
344
+ if (tile.contentUnloaded) {
345
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
346
+ this._loadTile(tile);
347
+ }
348
+ }
349
+ }
350
+ _unloadTiles() {
351
+ // unload tiles from cache when hit maximumMemoryUsage
352
+ this._cache.unloadTiles(this, (tileset, tile) => tileset._unloadTile(tile));
353
+ }
354
+ _updateStats() {
355
+ let tilesRenderable = 0;
356
+ let pointsRenderable = 0;
357
+ for (const tile of this.selectedTiles) {
358
+ if (tile.contentAvailable && tile.content) {
359
+ tilesRenderable++;
360
+ if (tile.content.pointCount) {
361
+ pointsRenderable += tile.content.pointCount;
362
+ }
363
+ }
364
+ }
365
+ this.stats.get(TILES_IN_VIEW).count = this.selectedTiles.length;
366
+ this.stats.get(TILES_RENDERABLE).count = tilesRenderable;
367
+ this.stats.get(POINTS_COUNT).count = pointsRenderable;
368
+ }
369
+ _initializeTileSet(tilesetJson) {
370
+ this.root = this._initializeTileHeaders(tilesetJson, null);
371
+ // TODO CESIUM Specific
372
+ if (this.type === constants_1.TILESET_TYPE.TILES3D) {
373
+ this._initializeCesiumTileset(tilesetJson);
374
+ }
375
+ if (this.type === constants_1.TILESET_TYPE.I3S) {
376
+ this._initializeI3STileset();
377
+ }
378
+ // Calculate cartographicCenter & zoom props to help apps center view on tileset
379
+ this._calculateViewProps();
380
+ }
381
+ // Called during initialize Tileset to initialize the tileset's cartographic center (longitude, latitude) and zoom.
382
+ _calculateViewProps() {
383
+ const root = this.root;
384
+ (0, loader_utils_1.assert)(root);
385
+ const { center } = root.boundingVolume;
386
+ // TODO - handle all cases
387
+ if (!center) {
388
+ // eslint-disable-next-line
389
+ console.warn('center was not pre-calculated for the root tile');
390
+ this.cartographicCenter = new core_1.Vector3();
391
+ this.zoom = 1;
392
+ return;
393
+ }
394
+ this.cartographicCenter = geospatial_1.Ellipsoid.WGS84.cartesianToCartographic(center, new core_1.Vector3());
395
+ this.cartesianCenter = center;
396
+ this.zoom = (0, zoom_1.getZoomFromBoundingVolume)(root.boundingVolume);
397
+ }
398
+ _initializeStats() {
399
+ this.stats.get(TILES_TOTAL);
400
+ this.stats.get(TILES_LOADING);
401
+ this.stats.get(TILES_IN_MEMORY);
402
+ this.stats.get(TILES_IN_VIEW);
403
+ this.stats.get(TILES_RENDERABLE);
404
+ this.stats.get(TILES_LOADED);
405
+ this.stats.get(TILES_UNLOADED);
406
+ this.stats.get(TILES_LOAD_FAILED);
407
+ this.stats.get(POINTS_COUNT, 'memory');
408
+ this.stats.get(TILES_GPU_MEMORY, 'memory');
409
+ }
410
+ // Installs the main tileset JSON file or a tileset JSON file referenced from a tile.
411
+ // eslint-disable-next-line max-statements
412
+ _initializeTileHeaders(tilesetJson, parentTileHeader) {
413
+ // A tileset JSON file referenced from a tile may exist in a different directory than the root tileset.
414
+ // Get the basePath relative to the external tileset.
415
+ const rootTile = new tile_3d_1.default(this, tilesetJson.root, parentTileHeader); // resource
416
+ // If there is a parentTileHeader, add the root of the currently loading tileset
417
+ // to parentTileHeader's children, and update its depth.
418
+ if (parentTileHeader) {
419
+ parentTileHeader.children.push(rootTile);
420
+ rootTile.depth = parentTileHeader.depth + 1;
421
+ }
422
+ // Cesium 3d tiles knows the hierarchy beforehand
423
+ if (this.type === constants_1.TILESET_TYPE.TILES3D) {
424
+ const stack = [];
425
+ stack.push(rootTile);
426
+ while (stack.length > 0) {
427
+ const tile = stack.pop();
428
+ this.stats.get(TILES_TOTAL).incrementCount();
429
+ const children = tile.header.children || [];
430
+ for (const childHeader of children) {
431
+ const childTile = new tile_3d_1.default(this, childHeader, tile);
432
+ tile.children.push(childTile);
433
+ childTile.depth = tile.depth + 1;
434
+ stack.push(childTile);
435
+ }
436
+ }
437
+ }
438
+ return rootTile;
439
+ }
440
+ _initializeTraverser() {
441
+ let TraverserClass;
442
+ const type = this.type;
443
+ switch (type) {
444
+ case constants_1.TILESET_TYPE.TILES3D:
445
+ TraverserClass = tileset_3d_traverser_1.default;
446
+ break;
447
+ case constants_1.TILESET_TYPE.I3S:
448
+ TraverserClass = i3s_tileset_traverser_1.default;
449
+ break;
450
+ default:
451
+ TraverserClass = tileset_traverser_1.default;
452
+ }
453
+ return new TraverserClass({
454
+ basePath: this.basePath,
455
+ onTraversalEnd: this._onTraversalEnd.bind(this)
456
+ });
457
+ }
458
+ _destroyTileHeaders(parentTile) {
459
+ this._destroySubtree(parentTile);
460
+ }
461
+ async _loadTile(tile) {
462
+ let loaded;
463
+ try {
464
+ this._onStartTileLoading();
465
+ loaded = await tile.loadContent();
466
+ }
467
+ catch (error) {
468
+ this._onTileLoadError(tile, error);
469
+ }
470
+ finally {
471
+ this._onEndTileLoading();
472
+ this._onTileLoad(tile, loaded);
473
+ }
474
+ }
475
+ _onTileLoadError(tile, error) {
476
+ this.stats.get(TILES_LOAD_FAILED).incrementCount();
477
+ const message = error.message || error.toString();
478
+ const url = tile.url;
479
+ // TODO - Allow for probe log to be injected instead of console?
480
+ console.error(`A 3D tile failed to load: ${tile.url} ${message}`); // eslint-disable-line
481
+ this.options.onTileError(tile, message, url);
482
+ }
483
+ _onTileLoad(tile, loaded) {
484
+ if (!loaded) {
485
+ return;
486
+ }
487
+ // add coordinateOrigin and modelMatrix to tile
488
+ if (tile && tile.content) {
489
+ (0, transform_utils_1.calculateTransformProps)(tile, tile.content);
490
+ }
491
+ this._addTileToCache(tile);
492
+ this.options.onTileLoad(tile);
493
+ }
494
+ _onStartTileLoading() {
495
+ this._pendingCount++;
496
+ this.stats.get(TILES_LOADING).incrementCount();
497
+ }
498
+ _onEndTileLoading() {
499
+ this._pendingCount--;
500
+ this.stats.get(TILES_LOADING).decrementCount();
501
+ }
502
+ _addTileToCache(tile) {
503
+ this._cache.add(this, tile, (tileset) => tileset._updateCacheStats(tile));
504
+ }
505
+ _updateCacheStats(tile) {
506
+ this.stats.get(TILES_LOADED).incrementCount();
507
+ this.stats.get(TILES_IN_MEMORY).incrementCount();
508
+ // Good enough? Just use the raw binary ArrayBuffer's byte length.
509
+ this.gpuMemoryUsageInBytes += tile.content.byteLength || 0;
510
+ this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes;
511
+ }
512
+ _unloadTile(tile) {
513
+ this.gpuMemoryUsageInBytes -= (tile.content && tile.content.byteLength) || 0;
514
+ this.stats.get(TILES_IN_MEMORY).decrementCount();
515
+ this.stats.get(TILES_UNLOADED).incrementCount();
516
+ this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes;
517
+ this.options.onTileUnload(tile);
518
+ tile.unloadContent();
519
+ }
520
+ // Traverse the tree and destroy all tiles
521
+ _destroy() {
522
+ const stack = [];
523
+ if (this.root) {
524
+ stack.push(this.root);
525
+ }
526
+ while (stack.length > 0) {
527
+ const tile = stack.pop();
528
+ for (const child of tile.children) {
529
+ stack.push(child);
530
+ }
531
+ this._destroyTile(tile);
532
+ }
533
+ this.root = null;
534
+ }
535
+ // Traverse the tree and destroy all sub tiles
536
+ _destroySubtree(tile) {
537
+ const root = tile;
538
+ const stack = [];
539
+ stack.push(root);
540
+ while (stack.length > 0) {
541
+ tile = stack.pop();
542
+ for (const child of tile.children) {
543
+ stack.push(child);
544
+ }
545
+ if (tile !== root) {
546
+ this._destroyTile(tile);
547
+ }
548
+ }
549
+ root.children = [];
550
+ }
551
+ _destroyTile(tile) {
552
+ this._cache.unloadTile(this, tile);
553
+ this._unloadTile(tile);
554
+ tile.destroy();
555
+ }
556
+ _initializeCesiumTileset(tilesetJson) {
557
+ this.asset = tilesetJson.asset;
558
+ if (!this.asset) {
559
+ throw new Error('Tileset must have an asset property.');
560
+ }
561
+ if (this.asset.version !== '0.0' && this.asset.version !== '1.0') {
562
+ throw new Error('The tileset must be 3D Tiles version 0.0 or 1.0.');
563
+ }
564
+ // Note: `asset.tilesetVersion` is version of the tileset itself (not the version of the 3D TILES standard)
565
+ // We add this version as a `v=1.0` query param to fetch the right version and not get an older cached version
566
+ if ('tilesetVersion' in this.asset) {
567
+ this._queryParams.v = this.asset.tilesetVersion;
568
+ }
569
+ // TODO - ion resources have a credits property we can use for additional attribution.
570
+ this.credits = {
571
+ attributions: this.options.attributions || []
572
+ };
573
+ this.description = this.options.description || '';
574
+ // Gets the tileset's properties dictionary object, which contains metadata about per-feature properties.
575
+ this.properties = tilesetJson.properties;
576
+ this.geometricError = tilesetJson.geometricError;
577
+ this._extensionsUsed = tilesetJson.extensionsUsed;
578
+ // Returns the extras property at the top of the tileset JSON (application specific metadata).
579
+ this.extras = tilesetJson.extras;
580
+ }
581
+ _initializeI3STileset() {
582
+ if (this.loadOptions.i3s && 'token' in this.loadOptions.i3s) {
583
+ this._queryParams.token = this.loadOptions.i3s.token;
584
+ }
585
+ }
586
+ }
587
+ exports.default = Tileset3D;
588
+ function getQueryParamString(queryParams) {
589
+ const queryParamStrings = [];
590
+ for (const key of Object.keys(queryParams)) {
591
+ queryParamStrings.push(`${key}=${queryParams[key]}`);
592
+ }
593
+ switch (queryParamStrings.length) {
594
+ case 0:
595
+ return '';
596
+ case 1:
597
+ return `?${queryParamStrings[0]}`;
598
+ default:
599
+ return `?${queryParamStrings.join('&')}`;
600
+ }
601
+ }
@@ -15,3 +15,4 @@ export default class TilesetCache {
15
15
  unloadTiles(tileset: any, unloadCallback: any): void;
16
16
  trim(): void;
17
17
  }
18
+ //# sourceMappingURL=tileset-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tileset-cache.d.ts","sourceRoot":"","sources":["../../src/tileset/tileset-cache.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B,OAAO,CAAC,KAAK,CAAmB;IAChC,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,UAAU,CAAU;;IAU5B,KAAK;IAOL,KAAK,CAAC,IAAI,KAAA;IAOV,GAAG,CAAC,OAAO,KAAA,EAAE,IAAI,KAAA,EAAE,WAAW,KAAA;IAU9B,UAAU,CAAC,OAAO,KAAA,EAAE,IAAI,KAAA,EAAE,cAAc,CAAC,KAAA;IAazC,WAAW,CAAC,OAAO,KAAA,EAAE,cAAc,KAAA;IA0BnC,IAAI;CAGL"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ // This file is derived from the Cesium code base under Apache 2 license
3
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const doubly_linked_list_1 = __importDefault(require("../utils/doubly-linked-list"));
9
+ function defined(x) {
10
+ return x !== undefined && x !== null;
11
+ }
12
+ /**
13
+ * Stores tiles with content loaded.
14
+ *
15
+ * @private
16
+ */
17
+ class TilesetCache {
18
+ constructor() {
19
+ // [head, sentinel) -> tiles that weren't selected this frame and may be removed from the cache
20
+ // (sentinel, tail] -> tiles that were selected this frame
21
+ this._list = new doubly_linked_list_1.default();
22
+ this._sentinel = this._list.add('sentinel');
23
+ this._trimTiles = false;
24
+ }
25
+ reset() {
26
+ // Move sentinel node to the tail so, at the start of the frame, all tiles
27
+ // may be potentially replaced. Tiles are moved to the right of the sentinel
28
+ // when they are selected so they will not be replaced.
29
+ this._list.splice(this._list.tail, this._sentinel);
30
+ }
31
+ touch(tile) {
32
+ const node = tile._cacheNode;
33
+ if (defined(node)) {
34
+ this._list.splice(this._sentinel, node);
35
+ }
36
+ }
37
+ add(tileset, tile, addCallback) {
38
+ if (!defined(tile._cacheNode)) {
39
+ tile._cacheNode = this._list.add(tile);
40
+ if (addCallback) {
41
+ addCallback(tileset, tile);
42
+ }
43
+ }
44
+ }
45
+ unloadTile(tileset, tile, unloadCallback) {
46
+ const node = tile._cacheNode;
47
+ if (!defined(node)) {
48
+ return;
49
+ }
50
+ this._list.remove(node);
51
+ tile._cacheNode = undefined;
52
+ if (unloadCallback) {
53
+ unloadCallback(tileset, tile);
54
+ }
55
+ }
56
+ unloadTiles(tileset, unloadCallback) {
57
+ const trimTiles = this._trimTiles;
58
+ this._trimTiles = false;
59
+ const list = this._list;
60
+ const maximumMemoryUsageInBytes = tileset.maximumMemoryUsage * 1024 * 1024;
61
+ // Traverse the list only to the sentinel since tiles/nodes to the
62
+ // right of the sentinel were used this frame.
63
+ // The sub-list to the left of the sentinel is ordered from LRU to MRU.
64
+ const sentinel = this._sentinel;
65
+ let node = list.head;
66
+ while (node !== sentinel &&
67
+ (tileset.gpuMemoryUsageInBytes > maximumMemoryUsageInBytes || trimTiles)) {
68
+ // @ts-expect-error
69
+ const tile = node.item;
70
+ // @ts-expect-error
71
+ node = node.next;
72
+ this.unloadTile(tileset, tile, unloadCallback);
73
+ }
74
+ }
75
+ trim() {
76
+ this._trimTiles = true;
77
+ }
78
+ }
79
+ exports.default = TilesetCache;
@@ -5,3 +5,4 @@ export default class I3STileManager {
5
5
  update(key: any, frameState: any): void;
6
6
  find(key: any): any;
7
7
  }
8
+ //# sourceMappingURL=i3s-tile-manager.d.ts.map