easy-three-utils 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/package.json +12 -0
  2. package/src/common/index.ts +24 -0
  3. package/src/common/useLine2.ts +87 -0
  4. package/src/common/useLoader.ts +184 -0
  5. package/src/common/useLocationCalculator.ts +145 -0
  6. package/src/common/useMark.ts +42 -0
  7. package/src/common/useTween.ts +86 -0
  8. package/src/core/basic/camera.ts +28 -0
  9. package/src/core/basic/clock.ts +11 -0
  10. package/src/core/basic/control.ts +32 -0
  11. package/src/core/basic/index.ts +35 -0
  12. package/src/core/basic/labelRenderer.ts +26 -0
  13. package/src/core/basic/light.ts +63 -0
  14. package/src/core/basic/renderer.ts +37 -0
  15. package/src/core/basic/scene.ts +11 -0
  16. package/src/core/basic/stats.ts +16 -0
  17. package/src/core/event.ts +74 -0
  18. package/src/core/index.ts +11 -0
  19. package/src/core/main.ts +389 -0
  20. package/src/draco/README.md +32 -0
  21. package/src/draco/draco_decoder.js +34 -0
  22. package/src/draco/draco_decoder.wasm +0 -0
  23. package/src/draco/draco_encoder.js +33 -0
  24. package/src/draco/draco_wasm_wrapper.js +117 -0
  25. package/src/draco/gltf/draco_decoder.js +33 -0
  26. package/src/draco/gltf/draco_decoder.wasm +0 -0
  27. package/src/draco/gltf/draco_encoder.js +33 -0
  28. package/src/draco/gltf/draco_wasm_wrapper.js +116 -0
  29. package/src/tileRenderer/base/Tile.d.ts +50 -0
  30. package/src/tileRenderer/base/TileBase.d.ts +76 -0
  31. package/src/tileRenderer/base/TileInternal.d.ts +36 -0
  32. package/src/tileRenderer/base/TilesRendererBase.d.ts +35 -0
  33. package/src/tileRenderer/base/TilesRendererBase.js +847 -0
  34. package/src/tileRenderer/base/Tileset.d.ts +66 -0
  35. package/src/tileRenderer/base/constants.d.ts +6 -0
  36. package/src/tileRenderer/base/constants.js +16 -0
  37. package/src/tileRenderer/base/loaders/B3DMLoaderBase.d.ts +18 -0
  38. package/src/tileRenderer/base/loaders/B3DMLoaderBase.js +85 -0
  39. package/src/tileRenderer/base/loaders/CMPTLoaderBase.d.ts +22 -0
  40. package/src/tileRenderer/base/loaders/CMPTLoaderBase.js +61 -0
  41. package/src/tileRenderer/base/loaders/I3DMLoaderBase.d.ts +21 -0
  42. package/src/tileRenderer/base/loaders/I3DMLoaderBase.js +130 -0
  43. package/src/tileRenderer/base/loaders/LoaderBase.d.ts +10 -0
  44. package/src/tileRenderer/base/loaders/LoaderBase.js +73 -0
  45. package/src/tileRenderer/base/loaders/PNTSLoaderBase.d.ts +17 -0
  46. package/src/tileRenderer/base/loaders/PNTSLoaderBase.js +82 -0
  47. package/src/tileRenderer/base/plugins/ImplicitTilingPlugin.js +12 -0
  48. package/src/tileRenderer/base/traverseFunctions.js +468 -0
  49. package/src/tileRenderer/gltf.js +144 -0
  50. package/src/tileRenderer/index.d.ts +41 -0
  51. package/src/tileRenderer/index.js +44 -0
  52. package/src/tileRenderer/plugins/README.md +578 -0
  53. package/src/tileRenderer/plugins/base/ImplicitTilingPlugin.d.ts +2 -0
  54. package/src/tileRenderer/plugins/base/ImplicitTilingPlugin.js +84 -0
  55. package/src/tileRenderer/plugins/base/SUBTREELoader.js +876 -0
  56. package/src/tileRenderer/plugins/index.d.ts +17 -0
  57. package/src/tileRenderer/plugins/index.js +17 -0
  58. package/src/tileRenderer/plugins/three/CesiumIonAuthPlugin.d.ts +9 -0
  59. package/src/tileRenderer/plugins/three/CesiumIonAuthPlugin.js +175 -0
  60. package/src/tileRenderer/plugins/three/DebugTilesPlugin.d.ts +29 -0
  61. package/src/tileRenderer/plugins/three/DebugTilesPlugin.js +677 -0
  62. package/src/tileRenderer/plugins/three/GLTFExtensionsPlugin.d.ts +18 -0
  63. package/src/tileRenderer/plugins/three/GLTFExtensionsPlugin.js +86 -0
  64. package/src/tileRenderer/plugins/three/GoogleAttributionsManager.js +62 -0
  65. package/src/tileRenderer/plugins/three/GoogleCloudAuthPlugin.d.ts +5 -0
  66. package/src/tileRenderer/plugins/three/GoogleCloudAuthPlugin.js +200 -0
  67. package/src/tileRenderer/plugins/three/ReorientationPlugin.d.ts +12 -0
  68. package/src/tileRenderer/plugins/three/ReorientationPlugin.js +136 -0
  69. package/src/tileRenderer/plugins/three/TileCompressionPlugin.d.ts +18 -0
  70. package/src/tileRenderer/plugins/three/TileCompressionPlugin.js +223 -0
  71. package/src/tileRenderer/plugins/three/UpdateOnChangePlugin.d.ts +5 -0
  72. package/src/tileRenderer/plugins/three/UpdateOnChangePlugin.js +87 -0
  73. package/src/tileRenderer/plugins/three/fade/FadeManager.js +370 -0
  74. package/src/tileRenderer/plugins/three/fade/TilesFadePlugin.d.ts +9 -0
  75. package/src/tileRenderer/plugins/three/fade/TilesFadePlugin.js +318 -0
  76. package/src/tileRenderer/plugins/three/gltf/GLTFCesiumRTCExtension.d.ts +5 -0
  77. package/src/tileRenderer/plugins/three/gltf/GLTFCesiumRTCExtension.js +27 -0
  78. package/src/tileRenderer/plugins/three/gltf/GLTFMeshFeaturesExtension.d.ts +30 -0
  79. package/src/tileRenderer/plugins/three/gltf/GLTFMeshFeaturesExtension.js +76 -0
  80. package/src/tileRenderer/plugins/three/gltf/GLTFStructuralMetadataExtension.d.ts +49 -0
  81. package/src/tileRenderer/plugins/three/gltf/GLTFStructuralMetadataExtension.js +147 -0
  82. package/src/tileRenderer/plugins/three/gltf/metadata/classes/ClassProperty.js +149 -0
  83. package/src/tileRenderer/plugins/three/gltf/metadata/classes/MeshFeatures.js +215 -0
  84. package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertyAttributeAccessor.js +107 -0
  85. package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertySetAccessor.js +45 -0
  86. package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertyTableAccessor.js +209 -0
  87. package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertyTextureAccessor.js +244 -0
  88. package/src/tileRenderer/plugins/three/gltf/metadata/classes/StructuralMetadata.js +202 -0
  89. package/src/tileRenderer/plugins/three/gltf/metadata/math/Matrix2.js +55 -0
  90. package/src/tileRenderer/plugins/three/gltf/metadata/utilities/ClassPropertyHelpers.js +495 -0
  91. package/src/tileRenderer/plugins/three/gltf/metadata/utilities/TexCoordUtilities.js +72 -0
  92. package/src/tileRenderer/plugins/three/gltf/metadata/utilities/TextureReadUtility.js +154 -0
  93. package/src/tileRenderer/plugins/three/objects/EllipsoidRegionHelper.js +186 -0
  94. package/src/tileRenderer/plugins/three/objects/SphereHelper.js +55 -0
  95. package/src/tileRenderer/r3f/README.md +238 -0
  96. package/src/tileRenderer/r3f/components/CameraControls.jsx +132 -0
  97. package/src/tileRenderer/r3f/components/CameraTransition.jsx +177 -0
  98. package/src/tileRenderer/r3f/components/CanvasDOMOverlay.jsx +54 -0
  99. package/src/tileRenderer/r3f/components/CompassGizmo.jsx +260 -0
  100. package/src/tileRenderer/r3f/components/TilesAttributionOverlay.jsx +110 -0
  101. package/src/tileRenderer/r3f/components/TilesRenderer.jsx +239 -0
  102. package/src/tileRenderer/r3f/index.jsx +6 -0
  103. package/src/tileRenderer/r3f/utilities/useForceUpdate.jsx +8 -0
  104. package/src/tileRenderer/r3f/utilities/useObjectDep.jsx +59 -0
  105. package/src/tileRenderer/r3f/utilities/useOptions.jsx +143 -0
  106. package/src/tileRenderer/three/DebugTilesRenderer.d.ts +28 -0
  107. package/src/tileRenderer/three/DebugTilesRenderer.js +58 -0
  108. package/src/tileRenderer/three/TilesGroup.d.ts +9 -0
  109. package/src/tileRenderer/three/TilesGroup.js +91 -0
  110. package/src/tileRenderer/three/TilesRenderer.d.ts +37 -0
  111. package/src/tileRenderer/three/TilesRenderer.js +1049 -0
  112. package/src/tileRenderer/three/controls/CameraTransitionManager.js +305 -0
  113. package/src/tileRenderer/three/controls/EnvironmentControls.js +1295 -0
  114. package/src/tileRenderer/three/controls/GlobeControls.js +684 -0
  115. package/src/tileRenderer/three/controls/PivotPointMesh.js +104 -0
  116. package/src/tileRenderer/three/controls/PointerTracker.js +257 -0
  117. package/src/tileRenderer/three/controls/utils.js +113 -0
  118. package/src/tileRenderer/three/loaders/B3DMLoader.d.ts +26 -0
  119. package/src/tileRenderer/three/loaders/B3DMLoader.js +85 -0
  120. package/src/tileRenderer/three/loaders/CMPTLoader.d.ts +19 -0
  121. package/src/tileRenderer/three/loaders/CMPTLoader.js +97 -0
  122. package/src/tileRenderer/three/loaders/GLTFExtensionLoader.d.ts +11 -0
  123. package/src/tileRenderer/three/loaders/GLTFExtensionLoader.js +68 -0
  124. package/src/tileRenderer/three/loaders/I3DMLoader.d.ts +26 -0
  125. package/src/tileRenderer/three/loaders/I3DMLoader.js +256 -0
  126. package/src/tileRenderer/three/loaders/PNTSLoader.d.ts +25 -0
  127. package/src/tileRenderer/three/loaders/PNTSLoader.js +202 -0
  128. package/src/tileRenderer/three/loaders/gltf/GLTFCesiumRTCExtension.js +12 -0
  129. package/src/tileRenderer/three/loaders/gltf/GLTFMeshFeaturesExtension.js +12 -0
  130. package/src/tileRenderer/three/loaders/gltf/GLTFStructuralMetadataExtension.js +12 -0
  131. package/src/tileRenderer/three/math/Ellipsoid.d.ts +31 -0
  132. package/src/tileRenderer/three/math/Ellipsoid.js +337 -0
  133. package/src/tileRenderer/three/math/EllipsoidRegion.d.ts +23 -0
  134. package/src/tileRenderer/three/math/EllipsoidRegion.js +178 -0
  135. package/src/tileRenderer/three/math/ExtendedFrustum.js +65 -0
  136. package/src/tileRenderer/three/math/GeoConstants.d.ts +4 -0
  137. package/src/tileRenderer/three/math/GeoConstants.js +5 -0
  138. package/src/tileRenderer/three/math/GeoUtils.d.ts +9 -0
  139. package/src/tileRenderer/three/math/GeoUtils.js +106 -0
  140. package/src/tileRenderer/three/math/OBB.js +179 -0
  141. package/src/tileRenderer/three/math/TileBoundingVolume.js +272 -0
  142. package/src/tileRenderer/three/plugins/CesiumIonAuthPlugin.js +12 -0
  143. package/src/tileRenderer/three/plugins/DebugTilesPlugin.js +26 -0
  144. package/src/tileRenderer/three/plugins/GoogleCloudAuthPlugin.js +12 -0
  145. package/src/tileRenderer/three/raycastTraverse.js +178 -0
  146. package/src/tileRenderer/three/renderers/CesiumIonTilesRenderer.d.ts +14 -0
  147. package/src/tileRenderer/three/renderers/CesiumIonTilesRenderer.js +21 -0
  148. package/src/tileRenderer/three/renderers/GoogleTilesRenderer.d.ts +43 -0
  149. package/src/tileRenderer/three/renderers/GoogleTilesRenderer.js +48 -0
  150. package/src/tileRenderer/three/utilities.js +54 -0
  151. package/src/tileRenderer/utilities/BatchTable.d.ts +24 -0
  152. package/src/tileRenderer/utilities/BatchTable.js +82 -0
  153. package/src/tileRenderer/utilities/BatchTableHierarchyExtension.js +127 -0
  154. package/src/tileRenderer/utilities/FeatureTable.d.ts +30 -0
  155. package/src/tileRenderer/utilities/FeatureTable.js +159 -0
  156. package/src/tileRenderer/utilities/LRUCache.d.ts +8 -0
  157. package/src/tileRenderer/utilities/LRUCache.js +385 -0
  158. package/src/tileRenderer/utilities/PriorityQueue.d.ts +16 -0
  159. package/src/tileRenderer/utilities/PriorityQueue.js +137 -0
  160. package/src/tileRenderer/utilities/arrayToString.js +7 -0
  161. package/src/tileRenderer/utilities/readMagicBytes.js +29 -0
  162. package/src/tileRenderer/utilities/rgb565torgb.js +22 -0
  163. package/src/tileRenderer/utilities/urlExtension.js +34 -0
  164. package/tsconfig.json +42 -0
  165. package/tsconfig.node.json +11 -0
  166. package/typings/three.d.ts +27 -0
@@ -0,0 +1,468 @@
1
+ import { LOADED, FAILED } from './constants.js';
2
+
3
+ function isDownloadFinished(value) {
4
+
5
+ return value === LOADED || value === FAILED;
6
+
7
+ }
8
+
9
+ // Checks whether this tile was last used on the given frame.
10
+ function isUsedThisFrame(tile, frameCount) {
11
+
12
+ return tile.__lastFrameVisited === frameCount && tile.__used;
13
+
14
+ }
15
+
16
+ // Resets the frame frame information for the given tile
17
+ function resetFrameState(tile, renderer) {
18
+
19
+ if (tile.__lastFrameVisited !== renderer.frameCount) {
20
+
21
+ tile.__lastFrameVisited = renderer.frameCount;
22
+ tile.__used = false;
23
+ tile.__inFrustum = false;
24
+ tile.__isLeaf = false;
25
+ tile.__visible = false;
26
+ tile.__active = false;
27
+ tile.__error = Infinity;
28
+ tile.__distanceFromCamera = Infinity;
29
+ tile.__childrenWereVisible = false;
30
+ tile.__allChildrenLoaded = false;
31
+
32
+ // update tile frustum and error state
33
+ tile.__inFrustum = renderer.tileInView(tile);
34
+ renderer.calculateError(tile);
35
+
36
+ }
37
+
38
+ }
39
+
40
+ // Recursively mark tiles used down to the next tile with content
41
+ function recursivelyMarkUsed(tile, renderer) {
42
+
43
+ renderer.ensureChildrenArePreprocessed(tile);
44
+
45
+ resetFrameState(tile, renderer);
46
+ markUsed(tile, renderer);
47
+
48
+ if (!tile.__hasRenderableContent) {
49
+
50
+ const children = tile.children;
51
+ for (let i = 0, l = children.length; i < l; i++) {
52
+
53
+ recursivelyMarkUsed(children[i], renderer);
54
+
55
+ }
56
+
57
+ }
58
+
59
+ }
60
+
61
+ // Recursively traverses to the next tiles with unloaded renderable content to load them
62
+ function recursivelyLoadNextRenderableTiles(tile, renderer) {
63
+
64
+ renderer.ensureChildrenArePreprocessed(tile);
65
+
66
+ // Try to load any external tile set children if the external tile set has loaded.
67
+ const doTraverse =
68
+ isUsedThisFrame(tile, renderer.frameCount) &&
69
+ !tile.__hasRenderableContent && (
70
+ !tile.__hasContent ||
71
+ isDownloadFinished(tile.__loadingState)
72
+ );
73
+
74
+ if (doTraverse) {
75
+
76
+ const children = tile.children;
77
+ for (let i = 0, l = children.length; i < l; i++) {
78
+
79
+ // don't increment depth to rendered parent here because we should treat
80
+ // the next layer of rendered children as just a single depth away for the
81
+ // sake of sorting.
82
+ const child = children[i];
83
+ recursivelyLoadNextRenderableTiles(child, renderer);
84
+
85
+ }
86
+
87
+ } else if (isUsedThisFrame(tile, renderer.frameCount) && !renderer.lruCache.isFull()) {
88
+ renderer.queueTileForDownload(tile);
89
+
90
+ }
91
+
92
+ }
93
+
94
+ // Mark a tile as being used by current view
95
+ function markUsed(tile, renderer) {
96
+
97
+ if (tile.__used) {
98
+
99
+ return;
100
+
101
+ }
102
+
103
+ tile.__used = true;
104
+ renderer.lruCache.markUsed(tile);
105
+ renderer.stats.used++;
106
+
107
+ if (tile.__inFrustum === true) {
108
+
109
+ renderer.stats.inFrustum++;
110
+
111
+ }
112
+
113
+ }
114
+
115
+ // Returns whether the tile can be traversed to the next layer of children by checking the tile metrics
116
+ function canTraverse(tile, renderer) {
117
+
118
+ // If we've met the error requirements then don't load further
119
+ if (tile.__error <= renderer.errorTarget) {
120
+
121
+ return false;
122
+
123
+ }
124
+
125
+ // Early out if we've reached the maximum allowed depth.
126
+ if (renderer.maxDepth > 0 && tile.__depth + 1 >= renderer.maxDepth) {
127
+
128
+ return false;
129
+
130
+ }
131
+
132
+ return true;
133
+
134
+ }
135
+
136
+ // Helper function for recursively traversing a tile set. If `beforeCb` returns `true` then the
137
+ // traversal will end early.
138
+ export function traverseSet(tile, beforeCb = null, afterCb = null, parent = null, depth = 0) {
139
+
140
+ if (beforeCb && beforeCb(tile, parent, depth)) {
141
+
142
+ if (afterCb) {
143
+
144
+ afterCb(tile, parent, depth);
145
+
146
+ }
147
+
148
+ return;
149
+
150
+ }
151
+
152
+ const children = tile.children;
153
+ for (let i = 0, l = children.length; i < l; i++) {
154
+
155
+ traverseSet(children[i], beforeCb, afterCb, tile, depth + 1);
156
+
157
+ }
158
+
159
+ if (afterCb) {
160
+
161
+ afterCb(tile, parent, depth);
162
+
163
+ }
164
+
165
+ }
166
+
167
+ // Determine which tiles are used by the renderer given the current camera configuration
168
+ export function markUsedTiles(tile, renderer) {
169
+
170
+ // determine frustum set is run first so we can ensure the preprocessing of all the necessary
171
+ // child tiles has happened here.
172
+ renderer.ensureChildrenArePreprocessed(tile);
173
+
174
+ resetFrameState(tile, renderer);
175
+
176
+ if (!tile.__inFrustum) {
177
+
178
+ return;
179
+
180
+ }
181
+
182
+ if (!canTraverse(tile, renderer)) {
183
+
184
+ markUsed(tile, renderer);
185
+ return;
186
+
187
+ }
188
+
189
+ // Traverse children and see if any children are in view.
190
+ let anyChildrenUsed = false;
191
+ let anyChildrenInFrustum = false;
192
+ const children = tile.children;
193
+ for (let i = 0, l = children.length; i < l; i++) {
194
+
195
+ const c = children[i];
196
+ markUsedTiles(c, renderer);
197
+ anyChildrenUsed = anyChildrenUsed || isUsedThisFrame(c, renderer.frameCount);
198
+ anyChildrenInFrustum = anyChildrenInFrustum || c.__inFrustum;
199
+
200
+ }
201
+
202
+ // Disabled for now because this will cause otherwise unused children to be added to the lru cache
203
+ // if none of the children are in the frustum then this tile shouldn't be displayed
204
+ if (tile.refine === 'REPLACE' && !anyChildrenInFrustum && children.length !== 0 && !tile.__hasUnrenderableContent) {
205
+
206
+ // TODO: we're not checking tiles with unrenderable content here since external tile sets might look like they're in the frustum,
207
+ // load the children, then the children indicate that it's not visible, causing it to be unloaded. Then it will be loaded again.
208
+ // The impact when including external tile set roots in the check is more significant but can't be used unless we keep external tile
209
+ // sets around even when they're not needed. See issue #741.
210
+
211
+ // TODO: what if we mark the tile as not in the frustum but we _do_ mark it as used? Then we can stop frustum traversal and at least
212
+ // prevent tiles from rendering unless they're needed.
213
+ tile.__inFrustum = false;
214
+ return;
215
+
216
+ }
217
+
218
+ // wait until after the above condition to mark the traversed tile as used or not
219
+ markUsed(tile, renderer);
220
+
221
+ // If this is a tile that needs children loaded to refine then recursively load child
222
+ // tiles until error is met
223
+ if (anyChildrenUsed && tile.refine === 'REPLACE') {
224
+
225
+ for (let i = 0, l = children.length; i < l; i++) {
226
+
227
+ const c = children[i];
228
+ recursivelyMarkUsed(c, renderer);
229
+
230
+ }
231
+
232
+ }
233
+
234
+ }
235
+
236
+ // Traverse and mark the tiles that are at the leaf nodes of the "used" tree.
237
+ export function markUsedSetLeaves(tile, renderer) {
238
+
239
+ const frameCount = renderer.frameCount;
240
+ if (!isUsedThisFrame(tile, frameCount)) {
241
+
242
+ return;
243
+
244
+ }
245
+
246
+ // This tile is a leaf if none of the children had been used.
247
+ const children = tile.children;
248
+ let anyChildrenUsed = false;
249
+ for (let i = 0, l = children.length; i < l; i++) {
250
+
251
+ const c = children[i];
252
+ anyChildrenUsed = anyChildrenUsed || isUsedThisFrame(c, frameCount);
253
+
254
+ }
255
+
256
+ if (!anyChildrenUsed) {
257
+
258
+ tile.__isLeaf = true;
259
+
260
+ } else {
261
+
262
+ let childrenWereVisible = false;
263
+ let allChildrenLoaded = true;
264
+ for (let i = 0, l = children.length; i < l; i++) {
265
+
266
+ const c = children[i];
267
+ markUsedSetLeaves(c, renderer);
268
+ childrenWereVisible = childrenWereVisible || c.__wasSetVisible || c.__childrenWereVisible;
269
+
270
+ if (isUsedThisFrame(c, frameCount)) {
271
+
272
+ // consider a child to be loaded if
273
+ // - the children's children have been loaded
274
+ // - the tile content has loaded
275
+ // - the tile is completely empty - ie has no children and no content
276
+ // - the child tile set has tried to load but failed
277
+ const childLoaded =
278
+ c.__allChildrenLoaded ||
279
+ (c.__hasRenderableContent && isDownloadFinished(c.__loadingState)) ||
280
+ (!c.__hasContent && c.children.length === 0) ||
281
+ (c.__hasUnrenderableContent && c.__loadingState === FAILED);
282
+ allChildrenLoaded = allChildrenLoaded && childLoaded;
283
+
284
+ }
285
+
286
+ }
287
+
288
+ tile.__childrenWereVisible = childrenWereVisible;
289
+ tile.__allChildrenLoaded = allChildrenLoaded;
290
+
291
+ }
292
+
293
+ }
294
+
295
+ // TODO: revisit implementation
296
+ // Skip past tiles we consider unrenderable because they are outside the error threshold.
297
+ export function markVisibleTiles(tile, renderer) {
298
+
299
+ const stats = renderer.stats;
300
+
301
+ if (!isUsedThisFrame(tile, renderer.frameCount)) {
302
+
303
+ return;
304
+
305
+ }
306
+ // Request the tile contents or mark it as visible if we've found a leaf.
307
+ const lruCache = renderer.lruCache;
308
+
309
+ if (tile.__isLeaf) {
310
+
311
+ if (tile.__loadingState === LOADED) {
312
+
313
+ if (tile.__inFrustum) {
314
+
315
+ tile.__visible = true;
316
+ stats.visible++;
317
+
318
+ }
319
+ tile.__active = true;
320
+ stats.active++;
321
+
322
+
323
+
324
+ } else if (!lruCache.isFull() && tile.__hasContent) {
325
+ renderer.queueTileForDownload(tile);
326
+ }
327
+
328
+ return;
329
+
330
+ }
331
+
332
+ const children = tile.children;
333
+ const hasContent = tile.__hasContent;
334
+ const loadedContent = isDownloadFinished(tile.__loadingState) && hasContent;
335
+ const errorRequirement = (renderer.errorTarget + 1) * renderer.errorThreshold;
336
+ const meetsSSE = tile.__error <= errorRequirement;
337
+ const childrenWereVisible = tile.__childrenWereVisible;
338
+
339
+ // NOTE: We can "trickle" root tiles in by enabling these lines.
340
+ // Don't wait for all children tiles to load if this tile set has empty tiles at the root
341
+ // const emptyRootTile = tile.__depthFromRenderedParent === 0;
342
+ // const allChildrenLoaded = tile.__allChildrenLoaded || emptyRootTile;
343
+
344
+ // If we've met the SSE requirements and we can load content then fire a fetch.
345
+ const allChildrenLoaded = tile.__allChildrenLoaded;
346
+ const includeTile = meetsSSE || tile.refine === 'ADD';
347
+ // console.log(includeTile , !loadedContent , !lruCache.isFull() , hasContent);
348
+
349
+ if (includeTile && !loadedContent && !lruCache.isFull() && hasContent) {
350
+
351
+ renderer.queueTileForDownload(tile);
352
+
353
+ }
354
+
355
+ // Only mark this tile as visible if it meets the screen space error requirements, has loaded content, not
356
+ // all children have loaded yet, and if no children were visible last frame. We want to keep children visible
357
+ // that _were_ visible to avoid a pop in level of detail as the camera moves around and parent / sibling tiles
358
+ // load in.
359
+
360
+ // Skip the tile entirely if there's no content to load
361
+ if (
362
+ (meetsSSE && !allChildrenLoaded && !childrenWereVisible && loadedContent)
363
+ || (tile.refine === 'ADD' && loadedContent)
364
+ ) {
365
+
366
+ if (tile.__inFrustum) {
367
+
368
+ tile.__visible = true;
369
+ stats.visible++;
370
+
371
+ }
372
+ tile.__active = true;
373
+ stats.active++;
374
+
375
+ }
376
+
377
+ // If we're additive then don't stop the traversal here because it doesn't matter whether the children load in
378
+ // at the same rate.
379
+
380
+ if (tile.refine === 'REPLACE' && meetsSSE && !allChildrenLoaded) {
381
+
382
+ // load the child content if we've found that we've been loaded so we can move down to the next tile
383
+ // layer when the data has loaded.
384
+ for (let i = 0, l = children.length; i < l; i++) {
385
+
386
+ const c = children[i];
387
+ if (isUsedThisFrame(c, renderer.frameCount)) {
388
+
389
+ recursivelyLoadNextRenderableTiles(c, renderer);
390
+
391
+ }
392
+
393
+ }
394
+
395
+ } else {
396
+
397
+ for (let i = 0, l = children.length; i < l; i++) {
398
+
399
+ markVisibleTiles(children[i], renderer);
400
+
401
+ }
402
+
403
+ }
404
+
405
+ }
406
+
407
+ // Final traverse to toggle tile visibility.
408
+ export function toggleTiles(tile, renderer) {
409
+
410
+ const isUsed = isUsedThisFrame(tile, renderer.frameCount);
411
+ if (isUsed || tile.__usedLastFrame) {
412
+
413
+ let setActive = false;
414
+ let setVisible = false;
415
+ if (isUsed) {
416
+
417
+ // enable visibility if active due to shadows
418
+ setActive = tile.__active;
419
+ if (renderer.displayActiveTiles) {
420
+
421
+ setVisible = tile.__active || tile.__visible;
422
+
423
+ } else {
424
+
425
+ setVisible = tile.__visible;
426
+
427
+ }
428
+
429
+ } else {
430
+
431
+ // if the tile was used last frame but not this one then there's potential for the tile
432
+ // to not have been visited during the traversal, meaning it hasn't been reset and has
433
+ // stale values. This ensures the values are not stale.
434
+ resetFrameState(tile, renderer);
435
+
436
+ }
437
+
438
+ // If the active or visible state changed then call the functions.
439
+ if (tile.__hasRenderableContent && tile.__loadingState === LOADED) {
440
+
441
+ if (tile.__wasSetActive !== setActive) {
442
+
443
+ renderer.setTileActive(tile, setActive);
444
+
445
+ }
446
+
447
+ if (tile.__wasSetVisible !== setVisible) {
448
+
449
+ renderer.setTileVisible(tile, setVisible);
450
+
451
+ }
452
+
453
+ }
454
+ tile.__wasSetActive = setActive;
455
+ tile.__wasSetVisible = setVisible;
456
+ tile.__usedLastFrame = isUsed;
457
+
458
+ const children = tile.children;
459
+ for (let i = 0, l = children.length; i < l; i++) {
460
+
461
+ const c = children[i];
462
+ toggleTiles(c, renderer);
463
+
464
+ }
465
+
466
+ }
467
+
468
+ }
@@ -0,0 +1,144 @@
1
+ import { GLTFExtensionLoader } from '..';
2
+ import {
3
+ Scene,
4
+ DirectionalLight,
5
+ AmbientLight,
6
+ WebGLRenderer,
7
+ PerspectiveCamera,
8
+ PCFSoftShadowMap,
9
+ } from 'three';
10
+ import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
11
+ import { LoadingManager } from 'three';
12
+ import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
13
+ import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
14
+
15
+ let camera, controls, scene, renderer;
16
+ let dirLight;
17
+
18
+ init();
19
+ animate();
20
+
21
+ function init() {
22
+
23
+ scene = new Scene();
24
+
25
+ // primary camera view
26
+ renderer = new WebGLRenderer({ antialias: true });
27
+ renderer.setPixelRatio(window.devicePixelRatio);
28
+ renderer.setSize(window.innerWidth, window.innerHeight);
29
+ renderer.setClearColor(0x151c1f);
30
+ renderer.shadowMap.enabled = true;
31
+ renderer.shadowMap.type = PCFSoftShadowMap;
32
+
33
+ document.body.appendChild(renderer.domElement);
34
+
35
+ camera = new PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 4000);
36
+ camera.position.set(3, 10, 20);
37
+
38
+ // controls
39
+ controls = new OrbitControls(camera, renderer.domElement);
40
+ controls.screenSpacePanning = false;
41
+ controls.minDistance = 1;
42
+ controls.maxDistance = 2000;
43
+
44
+ // lights
45
+ dirLight = new DirectionalLight(0xffffff, 1.25);
46
+ dirLight.position.set(1, 2, 3).multiplyScalar(40);
47
+ dirLight.castShadow = true;
48
+ dirLight.shadow.bias = - 0.01;
49
+ dirLight.shadow.mapSize.setScalar(2048);
50
+
51
+ const shadowCam = dirLight.shadow.camera;
52
+ shadowCam.left = - 200;
53
+ shadowCam.bottom = - 200;
54
+ shadowCam.right = 200;
55
+ shadowCam.top = 200;
56
+ shadowCam.updateProjectionMatrix();
57
+ scene.add(dirLight);
58
+
59
+ const ambLight = new AmbientLight(0xffffff, 0.05);
60
+ scene.add(ambLight);
61
+
62
+ // basic gltf test files
63
+ let insertPosition = 0;
64
+ const gltfModelTests = [
65
+ 'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/CesiumMilkTruck/glTF-Binary/CesiumMilkTruck.glb',
66
+ 'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/CesiumMilkTruck/glTF-Embedded/CesiumMilkTruck.gltf',
67
+ 'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/CesiumMilkTruck/glTF/CesiumMilkTruck.gltf',
68
+ ];
69
+
70
+ for (const url of gltfModelTests) {
71
+
72
+ const loader = new GLTFExtensionLoader();
73
+ loader.workingPath = loader.workingPathForURL(url);
74
+ loader.loadAsync(url)
75
+ .then(res => {
76
+
77
+ res.scene.position.set(insertPosition += 5, 0, 0);
78
+ controls.target.set(insertPosition / 2, 0, 0);
79
+ controls.update();
80
+ console.log('default loader:', { gltf: res, url });
81
+ scene.add(res.scene);
82
+
83
+ });
84
+
85
+ }
86
+
87
+ // gltf with extensions
88
+ const delegatedLoaderTests = [
89
+ 'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/CesiumMilkTruck/glTF-Draco/CesiumMilkTruck.gltf',
90
+ 'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Box/glTF-Binary/Box.glb',
91
+ ];
92
+
93
+ const manager = new LoadingManager();
94
+ const gltfLoader = new GLTFLoader(manager);
95
+ const dracoLoader = new DRACOLoader(manager);
96
+ dracoLoader.setDecoderPath('https://unpkg.com/three@0.153.0/examples/jsm/libs/draco/gltf/');
97
+ gltfLoader.setDRACOLoader(dracoLoader);
98
+ manager.addHandler(/\.gltf$/, gltfLoader);
99
+ manager.addHandler(/\.glb$/, gltfLoader);
100
+
101
+ for (const url of delegatedLoaderTests) {
102
+
103
+ const loader = new GLTFExtensionLoader(manager);
104
+ loader.workingPath = loader.workingPathForURL(url);
105
+ loader.loadAsync(url)
106
+ .then(res => {
107
+
108
+ res.scene.position.set(insertPosition += 5, 0, 0);
109
+ controls.target.set(insertPosition / 2, 0, 0);
110
+ controls.update();
111
+ console.log('custom loader:', { gltf: res, url });
112
+ scene.add(res.scene);
113
+
114
+ });
115
+
116
+ }
117
+
118
+ onWindowResize();
119
+ window.addEventListener('resize', onWindowResize, false);
120
+
121
+ }
122
+
123
+ function onWindowResize() {
124
+
125
+ camera.aspect = window.innerWidth / window.innerHeight;
126
+ renderer.setPixelRatio(window.devicePixelRatio);
127
+ renderer.setSize(window.innerWidth, window.innerHeight);
128
+ camera.updateProjectionMatrix();
129
+
130
+ }
131
+
132
+ function animate() {
133
+
134
+ requestAnimationFrame(animate);
135
+
136
+ render();
137
+
138
+ }
139
+
140
+ function render() {
141
+
142
+ renderer.render(scene, camera);
143
+
144
+ }
@@ -0,0 +1,41 @@
1
+ // three.js
2
+ export { DebugTilesRenderer } from './three/DebugTilesRenderer';
3
+ export { TilesRenderer } from './three/TilesRenderer';
4
+ export { TilesGroup } from './three/TilesGroup';
5
+ export { B3DMLoader, B3DMScene } from './three/loaders/B3DMLoader';
6
+ export { I3DMLoader, I3DMScene } from './three/loaders/I3DMLoader';
7
+ export { PNTSLoader, PNTSScene } from './three/loaders/PNTSLoader';
8
+ export { CMPTLoader } from './three/loaders/CMPTLoader';
9
+ export { GLTFCesiumRTCExtension } from './three/loaders/gltf/GLTFCesiumRTCExtension';
10
+ export { GLTFExtensionLoader } from './three/loaders/GLTFExtensionLoader';
11
+ export { Ellipsoid } from './three/math/Ellipsoid';
12
+ export { EllipsoidRegion } from './three/math/EllipsoidRegion';
13
+ export * as GeoUtils from './three/math/GeoUtils';
14
+ export * from './three/math/GeoConstants';
15
+ export * from './three/renderers/GoogleTilesRenderer';
16
+ export * from './three/renderers/CesiumIonTilesRenderer';
17
+
18
+ // three.js plugins
19
+ export { CesiumIonAuthPlugin } from './three/plugins/CesiumIonAuthPlugin';
20
+ export { GoogleCloudAuthPlugin } from './three/plugins/GoogleCloudAuthPlugin';
21
+ export * from './three/plugins/DebugTilesPlugin';
22
+
23
+ // common plugins
24
+ export { ImplicitTilingPlugin } from './base/plugins/ImplicitTilingPlugin';
25
+
26
+ // common
27
+ export { TilesRendererBase } from './base/TilesRendererBase';
28
+ export { Tile } from './base/Tile';
29
+ export { TileBase } from './base/TileBase';
30
+ export { Tileset } from './base/Tileset';
31
+ export { B3DMLoaderBase } from './base/loaders/B3DMLoaderBase';
32
+ export { I3DMLoaderBase } from './base/loaders/I3DMLoaderBase';
33
+ export { PNTSLoaderBase } from './base/loaders/PNTSLoaderBase';
34
+ export { CMPTLoaderBase } from './base/loaders/CMPTLoaderBase';
35
+ export { LoaderBase } from './base/loaders/LoaderBase';
36
+ export * from './base/constants';
37
+
38
+ export { LRUCache } from './utilities/LRUCache';
39
+ export { PriorityQueue } from './utilities/PriorityQueue';
40
+ export { BatchTable } from './utilities/BatchTable';
41
+ export { FeatureTable } from './utilities/FeatureTable';
@@ -0,0 +1,44 @@
1
+ // three.js
2
+ export { DebugTilesRenderer } from './three/DebugTilesRenderer.js';
3
+ export { TilesRenderer } from './three/TilesRenderer.js';
4
+ export { B3DMLoader } from './three/loaders/B3DMLoader.js';
5
+ export { PNTSLoader } from './three/loaders/PNTSLoader.js';
6
+ export { I3DMLoader } from './three/loaders/I3DMLoader.js';
7
+ export { CMPTLoader } from './three/loaders/CMPTLoader.js';
8
+ export { GLTFCesiumRTCExtension } from './three/loaders/gltf/GLTFCesiumRTCExtension.js';
9
+ export { GLTFStructuralMetadataExtension } from './three/loaders/gltf/GLTFStructuralMetadataExtension.js';
10
+ export { GLTFMeshFeaturesExtension } from './three/loaders/gltf/GLTFMeshFeaturesExtension.js';
11
+ export { GLTFExtensionLoader } from './three/loaders/GLTFExtensionLoader.js';
12
+
13
+ export * from './three/math/Ellipsoid.js';
14
+ export * from './three/math/EllipsoidRegion.js';
15
+ export * as GeoUtils from './three/math/GeoUtils.js';
16
+ export * from './three/math/GeoConstants.js';
17
+ export * from './three/renderers/GoogleTilesRenderer.js';
18
+ export * from './three/renderers/CesiumIonTilesRenderer.js';
19
+
20
+ // three.js controls
21
+ export { GlobeControls } from './three/controls/GlobeControls.js';
22
+ export { EnvironmentControls } from './three/controls/EnvironmentControls.js';
23
+ export { CameraTransitionManager } from './three/controls/CameraTransitionManager.js';
24
+
25
+ // three.js plugins
26
+ export { CesiumIonAuthPlugin } from './three/plugins/CesiumIonAuthPlugin.js';
27
+ export { GoogleCloudAuthPlugin } from './three/plugins/GoogleCloudAuthPlugin.js';
28
+ export * from './three/plugins/DebugTilesPlugin.js';
29
+
30
+ // common plugins
31
+ export { ImplicitTilingPlugin } from './base/plugins/ImplicitTilingPlugin.js';
32
+
33
+ // common
34
+ export { TilesRendererBase } from './base/TilesRendererBase.js';
35
+ export { LoaderBase } from './base/loaders/LoaderBase.js';
36
+ export { B3DMLoaderBase } from './base/loaders/B3DMLoaderBase.js';
37
+ export { I3DMLoaderBase } from './base/loaders/I3DMLoaderBase.js';
38
+ export { PNTSLoaderBase } from './base/loaders/PNTSLoaderBase.js';
39
+ export { CMPTLoaderBase } from './base/loaders/CMPTLoaderBase.js';
40
+ export * from './base/constants.js';
41
+
42
+ export { LRUCache } from './utilities/LRUCache.js';
43
+ export { PriorityQueue } from './utilities/PriorityQueue.js';
44
+