@loaders.gl/tiles 4.0.0-alpha.4 → 4.0.0-alpha.6

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