@loaders.gl/tiles 3.1.0-alpha.4 → 3.1.0-beta.3

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