@loaders.gl/tiles 4.0.0-alpha.9 → 4.0.0-beta.2

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 (35) hide show
  1. package/dist/dist.min.js +149 -81
  2. package/dist/es5/tileset/tileset-3d.js +5 -1
  3. package/dist/es5/tileset/tileset-3d.js.map +1 -1
  4. package/dist/es5/tileset/tileset-traverser.js +1 -1
  5. package/dist/es5/tileset/tileset-traverser.js.map +1 -1
  6. package/dist/esm/tileset/tileset-3d.js +5 -1
  7. package/dist/esm/tileset/tileset-3d.js.map +1 -1
  8. package/dist/esm/tileset/tileset-traverser.js +1 -1
  9. package/dist/esm/tileset/tileset-traverser.js.map +1 -1
  10. package/dist/tileset/tileset-3d.d.ts.map +1 -1
  11. package/package.json +4 -4
  12. package/src/tileset/tileset-3d.ts +7 -1
  13. package/src/tileset/tileset-traverser.ts +1 -1
  14. package/dist/bundle.js +0 -5
  15. package/dist/constants.js +0 -39
  16. package/dist/index.js +0 -26
  17. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js +0 -54
  18. package/dist/tileset/format-i3s/i3s-pending-tiles-register.js +0 -47
  19. package/dist/tileset/format-i3s/i3s-tile-manager.js +0 -80
  20. package/dist/tileset/format-i3s/i3s-tileset-traverser.js +0 -92
  21. package/dist/tileset/helpers/3d-tiles-options.js +0 -9
  22. package/dist/tileset/helpers/bounding-volume.js +0 -293
  23. package/dist/tileset/helpers/frame-state.js +0 -133
  24. package/dist/tileset/helpers/i3s-lod.js +0 -85
  25. package/dist/tileset/helpers/tiles-3d-lod.js +0 -117
  26. package/dist/tileset/helpers/transform-utils.js +0 -53
  27. package/dist/tileset/helpers/zoom.js +0 -89
  28. package/dist/tileset/tile-3d.js +0 -610
  29. package/dist/tileset/tileset-3d.js +0 -715
  30. package/dist/tileset/tileset-cache.js +0 -72
  31. package/dist/tileset/tileset-traverser.js +0 -300
  32. package/dist/types.js +0 -2
  33. package/dist/utils/doubly-linked-list-node.js +0 -18
  34. package/dist/utils/doubly-linked-list.js +0 -97
  35. package/dist/utils/managed-array.js +0 -152
@@ -1,610 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Tile3D = 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 culling_1 = require("@math.gl/culling");
9
- const core_2 = require("@loaders.gl/core");
10
- const constants_1 = require("../constants");
11
- const bounding_volume_1 = require("./helpers/bounding-volume");
12
- const tiles_3d_lod_1 = require("./helpers/tiles-3d-lod");
13
- const i3s_lod_1 = require("./helpers/i3s-lod");
14
- const _3d_tiles_options_1 = require("./helpers/3d-tiles-options");
15
- const tileset_traverser_1 = require("./tileset-traverser");
16
- const scratchVector = new core_1.Vector3();
17
- function defined(x) {
18
- return x !== undefined && x !== null;
19
- }
20
- /**
21
- * A Tile3DHeader represents a tile as Tileset3D. When a tile is first created, its content is not loaded;
22
- * the content is loaded on-demand when needed based on the view.
23
- * Do not construct this directly, instead access tiles through {@link Tileset3D#tileVisible}.
24
- */
25
- class Tile3D {
26
- /**
27
- * @constructs
28
- * Create a Tile3D instance
29
- * @param tileset - Tileset3D instance
30
- * @param header - tile header - JSON loaded from a dataset
31
- * @param parentHeader - parent Tile3D instance
32
- * @param extendedId - optional ID to separate copies of a tile for different viewports.
33
- * const extendedId = `${tile.id}-${frameState.viewport.id}`;
34
- */
35
- // eslint-disable-next-line max-statements
36
- constructor(tileset, header, parentHeader, extendedId = '') {
37
- /** Different refinement algorithms used by I3S and 3D tiles */
38
- this.lodMetricType = 'geometricError';
39
- /** The error, in meters, introduced if this tile is rendered and its children are not. */
40
- this.lodMetricValue = 0;
41
- /** @todo math.gl is not exporting BoundingVolume base type? */
42
- this.boundingVolume = null;
43
- /**
44
- * The tile's content. This represents the actual tile's payload,
45
- * not the content's metadata in the tileset JSON file.
46
- */
47
- this.content = null;
48
- this.contentState = constants_1.TILE_CONTENT_STATE.UNLOADED;
49
- this.gpuMemoryUsageInBytes = 0;
50
- /** The tile's children - an array of Tile3D objects. */
51
- this.children = [];
52
- this.depth = 0;
53
- this.viewportIds = [];
54
- this.transform = new core_1.Matrix4();
55
- this.extensions = null;
56
- /** TODO Cesium 3d tiles specific */
57
- this.implicitTiling = null;
58
- /** Container to store application specific data */
59
- this.userData = {};
60
- this.hasEmptyContent = false;
61
- this.hasTilesetContent = false;
62
- this.traverser = new tileset_traverser_1.TilesetTraverser({});
63
- /** Used by TilesetCache */
64
- this._cacheNode = null;
65
- this._frameNumber = null;
66
- // TODO Cesium 3d tiles specific
67
- this._expireDate = null;
68
- this._expiredContent = null;
69
- /** updated every frame for tree traversal and rendering optimizations: */
70
- this._distanceToCamera = 0;
71
- this._screenSpaceError = 0;
72
- this._visible = undefined;
73
- this._initialTransform = new core_1.Matrix4();
74
- // Used by traverser, cannot be marked private
75
- this._priority = 0;
76
- this._selectedFrame = 0;
77
- this._requestedFrame = 0;
78
- this._selectionDepth = 0;
79
- this._touchedFrame = 0;
80
- this._centerZDepth = 0;
81
- this._shouldRefine = false;
82
- this._stackLength = 0;
83
- this._visitedFrame = 0;
84
- this._inRequestVolume = false;
85
- this._lodJudge = null; // TODO i3s specific, needs to remove
86
- // PUBLIC MEMBERS
87
- // original tile data
88
- this.header = header;
89
- // The tileset containing this tile.
90
- this.tileset = tileset;
91
- this.id = extendedId || header.id;
92
- this.url = header.url;
93
- // This tile's parent or `undefined` if this tile is the root.
94
- // @ts-ignore
95
- this.parent = parentHeader;
96
- this.refine = this._getRefine(header.refine);
97
- this.type = header.type;
98
- this.contentUrl = header.contentUrl;
99
- this._initializeLodMetric(header);
100
- this._initializeTransforms(header);
101
- this._initializeBoundingVolumes(header);
102
- this._initializeContent(header);
103
- this._initializeRenderingState(header);
104
- Object.seal(this);
105
- }
106
- destroy() {
107
- this.header = null;
108
- }
109
- isDestroyed() {
110
- return this.header === null;
111
- }
112
- get selected() {
113
- return this._selectedFrame === this.tileset._frameNumber;
114
- }
115
- get isVisible() {
116
- return this._visible;
117
- }
118
- get isVisibleAndInRequestVolume() {
119
- return this._visible && this._inRequestVolume;
120
- }
121
- /** Returns true if tile is not an empty tile and not an external tileset */
122
- get hasRenderContent() {
123
- return !this.hasEmptyContent && !this.hasTilesetContent;
124
- }
125
- /** Returns true if tile has children */
126
- get hasChildren() {
127
- return this.children.length > 0 || (this.header.children && this.header.children.length > 0);
128
- }
129
- /**
130
- * Determines if the tile's content is ready. This is automatically `true` for
131
- * tiles with empty content.
132
- */
133
- get contentReady() {
134
- return this.contentState === constants_1.TILE_CONTENT_STATE.READY || this.hasEmptyContent;
135
- }
136
- /**
137
- * Determines if the tile has available content to render. `true` if the tile's
138
- * content is ready or if it has expired content this renders while new content loads; otherwise,
139
- */
140
- get contentAvailable() {
141
- return Boolean((this.contentReady && this.hasRenderContent) || (this._expiredContent && !this.contentFailed));
142
- }
143
- /** Returns true if tile has renderable content but it's unloaded */
144
- get hasUnloadedContent() {
145
- return this.hasRenderContent && this.contentUnloaded;
146
- }
147
- /**
148
- * Determines if the tile's content has not be requested. `true` if tile's
149
- * content has not be requested; otherwise, `false`.
150
- */
151
- get contentUnloaded() {
152
- return this.contentState === constants_1.TILE_CONTENT_STATE.UNLOADED;
153
- }
154
- /**
155
- * Determines if the tile's content is expired. `true` if tile's
156
- * content is expired; otherwise, `false`.
157
- */
158
- get contentExpired() {
159
- return this.contentState === constants_1.TILE_CONTENT_STATE.EXPIRED;
160
- }
161
- // Determines if the tile's content failed to load. `true` if the tile's
162
- // content failed to load; otherwise, `false`.
163
- get contentFailed() {
164
- return this.contentState === constants_1.TILE_CONTENT_STATE.FAILED;
165
- }
166
- /**
167
- * Distance from the tile's bounding volume center to the camera
168
- */
169
- get distanceToCamera() {
170
- return this._distanceToCamera;
171
- }
172
- /**
173
- * Screen space error for LOD selection
174
- */
175
- get screenSpaceError() {
176
- return this._screenSpaceError;
177
- }
178
- /**
179
- * Get bounding box in cartographic coordinates
180
- * @returns [min, max] each in [longitude, latitude, altitude]
181
- */
182
- get boundingBox() {
183
- if (!this._boundingBox) {
184
- this._boundingBox = (0, bounding_volume_1.getCartographicBounds)(this.header.boundingVolume, this.boundingVolume);
185
- }
186
- return this._boundingBox;
187
- }
188
- /** Get the tile's screen space error. */
189
- getScreenSpaceError(frameState, useParentLodMetric) {
190
- switch (this.tileset.type) {
191
- case constants_1.TILESET_TYPE.I3S:
192
- return (0, i3s_lod_1.getProjectedRadius)(this, frameState);
193
- case constants_1.TILESET_TYPE.TILES3D:
194
- return (0, tiles_3d_lod_1.getTiles3DScreenSpaceError)(this, frameState, useParentLodMetric);
195
- default:
196
- // eslint-disable-next-line
197
- throw new Error('Unsupported tileset type');
198
- }
199
- }
200
- /**
201
- * Make tile unselected than means it won't be shown
202
- * but it can be still loaded in memory
203
- */
204
- unselect() {
205
- this._selectedFrame = 0;
206
- }
207
- /**
208
- * Memory usage of tile on GPU
209
- */
210
- _getGpuMemoryUsageInBytes() {
211
- return this.content.gpuMemoryUsageInBytes || this.content.byteLength || 0;
212
- }
213
- /*
214
- * If skipLevelOfDetail is off try to load child tiles as soon as possible so that their parent can refine sooner.
215
- * Tiles are prioritized by screen space error.
216
- */
217
- // eslint-disable-next-line complexity
218
- _getPriority() {
219
- const traverser = this.tileset._traverser;
220
- const { skipLevelOfDetail } = traverser.options;
221
- /*
222
- * Tiles that are outside of the camera's frustum could be skipped if we are in 'ADD' mode
223
- * or if we are using 'Skip Traversal' in 'REPLACE' mode.
224
- * Otherewise, all 'touched' child tiles have to be loaded and displayed,
225
- * this may include tiles that are outide of the camera frustum (so that we can hide the parent tile).
226
- */
227
- const maySkipTile = this.refine === constants_1.TILE_REFINEMENT.ADD || skipLevelOfDetail;
228
- // Check if any reason to abort
229
- if (maySkipTile && !this.isVisible && this._visible !== undefined) {
230
- return -1;
231
- }
232
- // Condition used in `cancelOutOfViewRequests` function in CesiumJS/Cesium3DTileset.js
233
- if (this.tileset._frameNumber - this._touchedFrame >= 1) {
234
- return -1;
235
- }
236
- if (this.contentState === constants_1.TILE_CONTENT_STATE.UNLOADED) {
237
- return -1;
238
- }
239
- // Based on the priority function `getPriorityReverseScreenSpaceError` in CesiumJS. Scheduling priority is based on the parent's screen space error when possible.
240
- const parent = this.parent;
241
- const useParentScreenSpaceError = parent && (!maySkipTile || this._screenSpaceError === 0.0 || parent.hasTilesetContent);
242
- const screenSpaceError = useParentScreenSpaceError
243
- ? parent._screenSpaceError
244
- : this._screenSpaceError;
245
- const rootScreenSpaceError = traverser.root ? traverser.root._screenSpaceError : 0.0;
246
- // Map higher SSE to lower values (e.g. root tile is highest priority)
247
- return Math.max(rootScreenSpaceError - screenSpaceError, 0);
248
- }
249
- /**
250
- * Requests the tile's content.
251
- * The request may not be made if the Request Scheduler can't prioritize it.
252
- */
253
- // eslint-disable-next-line max-statements, complexity
254
- async loadContent() {
255
- if (this.hasEmptyContent) {
256
- return false;
257
- }
258
- if (this.content) {
259
- return true;
260
- }
261
- const expired = this.contentExpired;
262
- if (expired) {
263
- this._expireDate = null;
264
- }
265
- this.contentState = constants_1.TILE_CONTENT_STATE.LOADING;
266
- const requestToken = await this.tileset._requestScheduler.scheduleRequest(this.id, this._getPriority.bind(this));
267
- if (!requestToken) {
268
- // cancelled
269
- this.contentState = constants_1.TILE_CONTENT_STATE.UNLOADED;
270
- return false;
271
- }
272
- try {
273
- const contentUrl = this.tileset.getTileUrl(this.contentUrl);
274
- // The content can be a binary tile ot a JSON tileset
275
- const loader = this.tileset.loader;
276
- const options = {
277
- ...this.tileset.loadOptions,
278
- [loader.id]: {
279
- // @ts-expect-error
280
- ...this.tileset.loadOptions[loader.id],
281
- isTileset: this.type === 'json',
282
- ...this._getLoaderSpecificOptions(loader.id)
283
- }
284
- };
285
- this.content = await (0, core_2.load)(contentUrl, loader, options);
286
- if (this.tileset.options.contentLoader) {
287
- await this.tileset.options.contentLoader(this);
288
- }
289
- if (this._isTileset()) {
290
- // Add tile headers for the nested tilset's subtree
291
- // Async update of the tree should be fine since there would never be edits to the same node
292
- // TODO - we need to capture the child tileset's URL
293
- this.tileset._initializeTileHeaders(this.content, this);
294
- }
295
- this.contentState = constants_1.TILE_CONTENT_STATE.READY;
296
- this._onContentLoaded();
297
- return true;
298
- }
299
- catch (error) {
300
- // Tile is unloaded before the content finishes loading
301
- this.contentState = constants_1.TILE_CONTENT_STATE.FAILED;
302
- throw error;
303
- }
304
- finally {
305
- requestToken.done();
306
- }
307
- }
308
- // Unloads the tile's content.
309
- unloadContent() {
310
- if (this.content && this.content.destroy) {
311
- this.content.destroy();
312
- }
313
- this.content = null;
314
- if (this.header.content && this.header.content.destroy) {
315
- this.header.content.destroy();
316
- }
317
- this.header.content = null;
318
- this.contentState = constants_1.TILE_CONTENT_STATE.UNLOADED;
319
- return true;
320
- }
321
- /**
322
- * Update the tile's visibility
323
- * @param {Object} frameState - frame state for tile culling
324
- * @param {string[]} viewportIds - a list of viewport ids that show this tile
325
- * @return {void}
326
- */
327
- updateVisibility(frameState, viewportIds) {
328
- if (this._frameNumber === frameState.frameNumber) {
329
- // Return early if visibility has already been checked during the traversal.
330
- // The visibility may have already been checked if the cullWithChildrenBounds optimization is used.
331
- return;
332
- }
333
- const parent = this.parent;
334
- const parentVisibilityPlaneMask = parent
335
- ? parent._visibilityPlaneMask
336
- : culling_1.CullingVolume.MASK_INDETERMINATE;
337
- if (this.tileset._traverser.options.updateTransforms) {
338
- const parentTransform = parent ? parent.computedTransform : this.tileset.modelMatrix;
339
- this._updateTransform(parentTransform);
340
- }
341
- this._distanceToCamera = this.distanceToTile(frameState);
342
- this._screenSpaceError = this.getScreenSpaceError(frameState, false);
343
- this._visibilityPlaneMask = this.visibility(frameState, parentVisibilityPlaneMask); // Use parent's plane mask to speed up visibility test
344
- this._visible = this._visibilityPlaneMask !== culling_1.CullingVolume.MASK_OUTSIDE;
345
- this._inRequestVolume = this.insideViewerRequestVolume(frameState);
346
- this._frameNumber = frameState.frameNumber;
347
- this.viewportIds = viewportIds;
348
- }
349
- // Determines whether the tile's bounding volume intersects the culling volume.
350
- // @param {FrameState} frameState The frame state.
351
- // @param {Number} parentVisibilityPlaneMask The parent's plane mask to speed up the visibility check.
352
- // @returns {Number} A plane mask as described above in {@link CullingVolume#computeVisibilityWithPlaneMask}.
353
- visibility(frameState, parentVisibilityPlaneMask) {
354
- const { cullingVolume } = frameState;
355
- const { boundingVolume } = this;
356
- // TODO Cesium specific - restore clippingPlanes
357
- // const {clippingPlanes, clippingPlanesOriginMatrix} = tileset;
358
- // if (clippingPlanes && clippingPlanes.enabled) {
359
- // const intersection = clippingPlanes.computeIntersectionWithBoundingVolume(
360
- // boundingVolume,
361
- // clippingPlanesOriginMatrix
362
- // );
363
- // this._isClipped = intersection !== Intersect.INSIDE;
364
- // if (intersection === Intersect.OUTSIDE) {
365
- // return CullingVolume.MASK_OUTSIDE;
366
- // }
367
- // }
368
- // return cullingVolume.computeVisibilityWithPlaneMask(boundingVolume, parentVisibilityPlaneMask);
369
- return cullingVolume.computeVisibilityWithPlaneMask(boundingVolume, parentVisibilityPlaneMask);
370
- }
371
- // Assuming the tile's bounding volume intersects the culling volume, determines
372
- // whether the tile's content's bounding volume intersects the culling volume.
373
- // @param {FrameState} frameState The frame state.
374
- // @returns {Intersect} The result of the intersection: the tile's content is completely outside, completely inside, or intersecting the culling volume.
375
- contentVisibility() {
376
- return true;
377
- // TODO restore
378
- /*
379
- // Assumes the tile's bounding volume intersects the culling volume already, so
380
- // just return Intersect.INSIDE if there is no content bounding volume.
381
- if (!defined(this.contentBoundingVolume)) {
382
- return Intersect.INSIDE;
383
- }
384
-
385
- if (this._visibilityPlaneMask === CullingVolume.MASK_INSIDE) {
386
- // The tile's bounding volume is completely inside the culling volume so
387
- // the content bounding volume must also be inside.
388
- return Intersect.INSIDE;
389
- }
390
-
391
- // PERFORMANCE_IDEA: is it possible to burn less CPU on this test since we know the
392
- // tile's (not the content's) bounding volume intersects the culling volume?
393
- const cullingVolume = frameState.cullingVolume;
394
- const boundingVolume = tile.contentBoundingVolume;
395
-
396
- const tileset = this.tileset;
397
- const clippingPlanes = tileset.clippingPlanes;
398
- if (defined(clippingPlanes) && clippingPlanes.enabled) {
399
- const intersection = clippingPlanes.computeIntersectionWithBoundingVolume(
400
- boundingVolume,
401
- tileset.clippingPlanesOriginMatrix
402
- );
403
- this._isClipped = intersection !== Intersect.INSIDE;
404
- if (intersection === Intersect.OUTSIDE) {
405
- return Intersect.OUTSIDE;
406
- }
407
- }
408
-
409
- return cullingVolume.computeVisibility(boundingVolume);
410
- */
411
- }
412
- /**
413
- * Computes the (potentially approximate) distance from the closest point of the tile's bounding volume to the camera.
414
- * @param frameState The frame state.
415
- * @returns {Number} The distance, in meters, or zero if the camera is inside the bounding volume.
416
- */
417
- distanceToTile(frameState) {
418
- const boundingVolume = this.boundingVolume;
419
- return Math.sqrt(Math.max(boundingVolume.distanceSquaredTo(frameState.camera.position), 0));
420
- }
421
- /**
422
- * Computes the tile's camera-space z-depth.
423
- * @param frameState The frame state.
424
- * @returns The distance, in meters.
425
- */
426
- cameraSpaceZDepth({ camera }) {
427
- const boundingVolume = this.boundingVolume; // Gets the underlying OrientedBoundingBox or BoundingSphere
428
- scratchVector.subVectors(boundingVolume.center, camera.position);
429
- return camera.direction.dot(scratchVector);
430
- }
431
- /**
432
- * Checks if the camera is inside the viewer request volume.
433
- * @param {FrameState} frameState The frame state.
434
- * @returns {Boolean} Whether the camera is inside the volume.
435
- */
436
- insideViewerRequestVolume(frameState) {
437
- const viewerRequestVolume = this._viewerRequestVolume;
438
- return (!viewerRequestVolume || viewerRequestVolume.distanceSquaredTo(frameState.camera.position) <= 0);
439
- }
440
- // TODO Cesium specific
441
- // Update whether the tile has expired.
442
- updateExpiration() {
443
- if (defined(this._expireDate) && this.contentReady && !this.hasEmptyContent) {
444
- const now = Date.now();
445
- // @ts-ignore Date.lessThan - replace with ms compare?
446
- if (Date.lessThan(this._expireDate, now)) {
447
- this.contentState = constants_1.TILE_CONTENT_STATE.EXPIRED;
448
- this._expiredContent = this.content;
449
- }
450
- }
451
- }
452
- get extras() {
453
- return this.header.extras;
454
- }
455
- // INTERNAL METHODS
456
- _initializeLodMetric(header) {
457
- if ('lodMetricType' in header) {
458
- this.lodMetricType = header.lodMetricType;
459
- }
460
- else {
461
- this.lodMetricType = (this.parent && this.parent.lodMetricType) || this.tileset.lodMetricType;
462
- // eslint-disable-next-line
463
- console.warn(`3D Tile: Required prop lodMetricType is undefined. Using parent lodMetricType`);
464
- }
465
- // This is used to compute screen space error, i.e., the error measured in pixels.
466
- if ('lodMetricValue' in header) {
467
- this.lodMetricValue = header.lodMetricValue;
468
- }
469
- else {
470
- this.lodMetricValue =
471
- (this.parent && this.parent.lodMetricValue) || this.tileset.lodMetricValue;
472
- // eslint-disable-next-line
473
- console.warn('3D Tile: Required prop lodMetricValue is undefined. Using parent lodMetricValue');
474
- }
475
- }
476
- _initializeTransforms(tileHeader) {
477
- // The local transform of this tile.
478
- this.transform = tileHeader.transform ? new core_1.Matrix4(tileHeader.transform) : new core_1.Matrix4();
479
- const parent = this.parent;
480
- const tileset = this.tileset;
481
- const parentTransform = parent && parent.computedTransform
482
- ? parent.computedTransform.clone()
483
- : tileset.modelMatrix.clone();
484
- this.computedTransform = new core_1.Matrix4(parentTransform).multiplyRight(this.transform);
485
- const parentInitialTransform = parent && parent._initialTransform ? parent._initialTransform.clone() : new core_1.Matrix4();
486
- this._initialTransform = new core_1.Matrix4(parentInitialTransform).multiplyRight(this.transform);
487
- }
488
- _initializeBoundingVolumes(tileHeader) {
489
- this._contentBoundingVolume = null;
490
- this._viewerRequestVolume = null;
491
- this._updateBoundingVolume(tileHeader);
492
- }
493
- _initializeContent(tileHeader) {
494
- // Empty tile by default
495
- this.content = { _tileset: this.tileset, _tile: this };
496
- this.hasEmptyContent = true;
497
- this.contentState = constants_1.TILE_CONTENT_STATE.UNLOADED;
498
- // When `true`, the tile's content points to an external tileset.
499
- // This is `false` until the tile's content is loaded.
500
- this.hasTilesetContent = false;
501
- if (tileHeader.contentUrl) {
502
- this.content = null;
503
- this.hasEmptyContent = false;
504
- }
505
- }
506
- // TODO - remove anything not related to basic visibility detection
507
- _initializeRenderingState(header) {
508
- this.depth = header.level || (this.parent ? this.parent.depth + 1 : 0);
509
- this._shouldRefine = false;
510
- // Members this are updated every frame for tree traversal and rendering optimizations:
511
- this._distanceToCamera = 0;
512
- this._centerZDepth = 0;
513
- this._screenSpaceError = 0;
514
- this._visibilityPlaneMask = culling_1.CullingVolume.MASK_INDETERMINATE;
515
- this._visible = undefined;
516
- this._inRequestVolume = false;
517
- this._stackLength = 0;
518
- this._selectionDepth = 0;
519
- this._frameNumber = 0;
520
- this._touchedFrame = 0;
521
- this._visitedFrame = 0;
522
- this._selectedFrame = 0;
523
- this._requestedFrame = 0;
524
- this._priority = 0.0;
525
- }
526
- _getRefine(refine) {
527
- // Inherit from parent tile if omitted.
528
- return refine || (this.parent && this.parent.refine) || constants_1.TILE_REFINEMENT.REPLACE;
529
- }
530
- _isTileset() {
531
- return this.contentUrl.indexOf('.json') !== -1;
532
- }
533
- _onContentLoaded() {
534
- // Vector and Geometry tile rendering do not support the skip LOD optimization.
535
- switch (this.content && this.content.type) {
536
- case 'vctr':
537
- case 'geom':
538
- // @ts-ignore
539
- this.tileset._traverser.disableSkipLevelOfDetail = true;
540
- break;
541
- default:
542
- }
543
- // The content may be tileset json
544
- if (this._isTileset()) {
545
- this.hasTilesetContent = true;
546
- }
547
- else {
548
- this.gpuMemoryUsageInBytes = this._getGpuMemoryUsageInBytes();
549
- }
550
- }
551
- _updateBoundingVolume(header) {
552
- // Update the bounding volumes
553
- this.boundingVolume = (0, bounding_volume_1.createBoundingVolume)(header.boundingVolume, this.computedTransform, this.boundingVolume);
554
- const content = header.content;
555
- if (!content) {
556
- return;
557
- }
558
- // TODO Cesium specific
559
- // Non-leaf tiles may have a content bounding-volume, which is a tight-fit bounding volume
560
- // around only the features in the tile. This box is useful for culling for rendering,
561
- // but not for culling for traversing the tree since it does not guarantee spatial coherence, i.e.,
562
- // since it only bounds features in the tile, not the entire tile, children may be
563
- // outside of this box.
564
- if (content.boundingVolume) {
565
- this._contentBoundingVolume = (0, bounding_volume_1.createBoundingVolume)(content.boundingVolume, this.computedTransform, this._contentBoundingVolume);
566
- }
567
- if (header.viewerRequestVolume) {
568
- this._viewerRequestVolume = (0, bounding_volume_1.createBoundingVolume)(header.viewerRequestVolume, this.computedTransform, this._viewerRequestVolume);
569
- }
570
- }
571
- // Update the tile's transform. The transform is applied to the tile's bounding volumes.
572
- _updateTransform(parentTransform = new core_1.Matrix4()) {
573
- const computedTransform = parentTransform.clone().multiplyRight(this.transform);
574
- const didTransformChange = !computedTransform.equals(this.computedTransform);
575
- if (!didTransformChange) {
576
- return;
577
- }
578
- this.computedTransform = computedTransform;
579
- this._updateBoundingVolume(this.header);
580
- }
581
- // Get options which are applicable only for the particular loader
582
- _getLoaderSpecificOptions(loaderId) {
583
- switch (loaderId) {
584
- case 'i3s':
585
- return {
586
- ...this.tileset.options.i3s,
587
- _tileOptions: {
588
- attributeUrls: this.header.attributeUrls,
589
- textureUrl: this.header.textureUrl,
590
- textureFormat: this.header.textureFormat,
591
- textureLoaderOptions: this.header.textureLoaderOptions,
592
- materialDefinition: this.header.materialDefinition,
593
- isDracoGeometry: this.header.isDracoGeometry,
594
- mbs: this.header.mbs
595
- },
596
- _tilesetOptions: {
597
- store: this.tileset.tileset.store,
598
- attributeStorageInfo: this.tileset.tileset.attributeStorageInfo,
599
- fields: this.tileset.tileset.fields
600
- },
601
- isTileHeader: false
602
- };
603
- case '3d-tiles':
604
- case 'cesium-ion':
605
- default:
606
- return (0, _3d_tiles_options_1.get3dTilesOptions)(this.tileset.tileset);
607
- }
608
- }
609
- }
610
- exports.Tile3D = Tile3D;