@cesium/engine 2.1.0 → 2.2.0

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 (193) hide show
  1. package/Build/Workers/{AxisAlignedBoundingBox-a6f9f0e5.js → AxisAlignedBoundingBox-379015ef.js} +1 -1
  2. package/Build/Workers/{BoundingRectangle-b0a68595.js → BoundingRectangle-57f2b24f.js} +1 -1
  3. package/Build/Workers/{BoxGeometry-baedd794.js → BoxGeometry-ecabfc78.js} +1 -1
  4. package/Build/Workers/{Color-f85df1be.js → Color-14d1a36d.js} +1 -1
  5. package/Build/Workers/{CoplanarPolygonGeometryLibrary-30516950.js → CoplanarPolygonGeometryLibrary-048c3c14.js} +1 -1
  6. package/Build/Workers/{CorridorGeometryLibrary-5d5d3b3a.js → CorridorGeometryLibrary-520c8619.js} +1 -1
  7. package/Build/Workers/{CylinderGeometry-d899ae26.js → CylinderGeometry-119068b8.js} +1 -1
  8. package/Build/Workers/{EllipseGeometry-a49f8449.js → EllipseGeometry-2dfc3523.js} +1 -1
  9. package/Build/Workers/{EllipseGeometryLibrary-cba7edde.js → EllipseGeometryLibrary-0a1e0170.js} +1 -1
  10. package/Build/Workers/{EllipseOutlineGeometry-8095c8cb.js → EllipseOutlineGeometry-c5251669.js} +1 -1
  11. package/Build/Workers/{EllipsoidGeometry-ed93f571.js → EllipsoidGeometry-d10a5221.js} +1 -1
  12. package/Build/Workers/{EllipsoidOutlineGeometry-e4854854.js → EllipsoidOutlineGeometry-7039a0ae.js} +1 -1
  13. package/Build/Workers/{EllipsoidTangentPlane-7ae1aa9a.js → EllipsoidTangentPlane-857186be.js} +1 -1
  14. package/Build/Workers/{FrustumGeometry-b62db3e3.js → FrustumGeometry-400fa1b7.js} +2 -2
  15. package/Build/Workers/{GeometryAttribute-780af4fa.js → GeometryAttribute-7a2de5c6.js} +1 -1
  16. package/Build/Workers/{GeometryPipeline-36b61c99.js → GeometryPipeline-916636fa.js} +1 -1
  17. package/Build/Workers/{IntersectionTests-e889fcf0.js → IntersectionTests-b4d02d4d.js} +1 -1
  18. package/Build/Workers/{OrientedBoundingBox-43478ac8.js → OrientedBoundingBox-96fe1752.js} +5 -3
  19. package/Build/Workers/{PolygonGeometryLibrary-38a98276.js → PolygonGeometryLibrary-931f1ec6.js} +1 -1
  20. package/Build/Workers/{PolygonPipeline-d31ff61c.js → PolygonPipeline-32fc92cc.js} +1 -1
  21. package/Build/Workers/{PolylinePipeline-30e4cec9.js → PolylinePipeline-6d5c63e5.js} +1 -1
  22. package/Build/Workers/{PolylineVolumeGeometryLibrary-90551d26.js → PolylineVolumeGeometryLibrary-f068c1fb.js} +1 -1
  23. package/Build/Workers/{PrimitivePipeline-558d9cb0.js → PrimitivePipeline-879f996a.js} +1 -1
  24. package/Build/Workers/{RectangleGeometryLibrary-815c68df.js → RectangleGeometryLibrary-2d6f36f3.js} +1 -1
  25. package/Build/Workers/{TerrainEncoding-341ead52.js → TerrainEncoding-82882059.js} +1 -1
  26. package/Build/Workers/{Transforms-9e9df299.js → Transforms-9052372a.js} +6 -5
  27. package/Build/Workers/{WallGeometryLibrary-ccf90976.js → WallGeometryLibrary-db7a64fb.js} +1 -1
  28. package/Build/Workers/cesiumWorkerBootstrapper.js +1 -1
  29. package/Build/Workers/combineGeometry.js +1 -1
  30. package/Build/Workers/createBoxGeometry.js +1 -1
  31. package/Build/Workers/createBoxOutlineGeometry.js +1 -1
  32. package/Build/Workers/createCircleGeometry.js +1 -1
  33. package/Build/Workers/createCircleOutlineGeometry.js +1 -1
  34. package/Build/Workers/createCoplanarPolygonGeometry.js +1 -1
  35. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +1 -1
  36. package/Build/Workers/createCorridorGeometry.js +1 -1
  37. package/Build/Workers/createCorridorOutlineGeometry.js +1 -1
  38. package/Build/Workers/createCylinderGeometry.js +1 -1
  39. package/Build/Workers/createCylinderOutlineGeometry.js +1 -1
  40. package/Build/Workers/createEllipseGeometry.js +1 -1
  41. package/Build/Workers/createEllipseOutlineGeometry.js +1 -1
  42. package/Build/Workers/createEllipsoidGeometry.js +1 -1
  43. package/Build/Workers/createEllipsoidOutlineGeometry.js +1 -1
  44. package/Build/Workers/createFrustumGeometry.js +1 -1
  45. package/Build/Workers/createFrustumOutlineGeometry.js +1 -1
  46. package/Build/Workers/createGeometry.js +1 -1
  47. package/Build/Workers/createGroundPolylineGeometry.js +1 -1
  48. package/Build/Workers/createPlaneGeometry.js +1 -1
  49. package/Build/Workers/createPlaneOutlineGeometry.js +1 -1
  50. package/Build/Workers/createPolygonGeometry.js +1 -1
  51. package/Build/Workers/createPolygonOutlineGeometry.js +1 -1
  52. package/Build/Workers/createPolylineGeometry.js +1 -1
  53. package/Build/Workers/createPolylineVolumeGeometry.js +1 -1
  54. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +1 -1
  55. package/Build/Workers/createRectangleGeometry.js +1 -1
  56. package/Build/Workers/createRectangleOutlineGeometry.js +1 -1
  57. package/Build/Workers/createSimplePolylineGeometry.js +1 -1
  58. package/Build/Workers/createSphereGeometry.js +1 -1
  59. package/Build/Workers/createSphereOutlineGeometry.js +1 -1
  60. package/Build/Workers/createVectorTileGeometries.js +1 -1
  61. package/Build/Workers/createVectorTilePolygons.js +1 -1
  62. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +1 -1
  63. package/Build/Workers/createVerticesFromHeightmap.js +1 -1
  64. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +10 -15
  65. package/Build/Workers/createWallGeometry.js +1 -1
  66. package/Build/Workers/createWallOutlineGeometry.js +1 -1
  67. package/Build/Workers/package.js +1 -1
  68. package/Build/Workers/transferTypedArrayTest.js +1 -1
  69. package/Build/Workers/upsampleQuantizedTerrainMesh.js +1 -1
  70. package/Source/Core/ArcGISTiledElevationTerrainProvider.js +291 -191
  71. package/Source/Core/CesiumTerrainProvider.js +571 -434
  72. package/Source/Core/CustomHeightmapTerrainProvider.js +12 -0
  73. package/Source/Core/EllipsoidTerrainProvider.js +17 -10
  74. package/Source/Core/FrustumGeometry.js +1 -1
  75. package/Source/Core/GoogleEarthEnterpriseMetadata.js +86 -34
  76. package/Source/Core/GoogleEarthEnterpriseTerrainProvider.js +119 -82
  77. package/Source/Core/Ion.js +1 -1
  78. package/Source/Core/IonResource.js +14 -3
  79. package/Source/Core/OrientedBoundingBox.js +4 -2
  80. package/Source/Core/RequestScheduler.js +1 -1
  81. package/Source/Core/Resource.js +2 -2
  82. package/Source/Core/TerrainProvider.js +9 -14
  83. package/Source/Core/TileProviderError.js +8 -8
  84. package/Source/Core/VRTheWorldTerrainProvider.js +193 -124
  85. package/Source/Core/buildModuleUrl.js +4 -3
  86. package/Source/Core/createWorldTerrain.js +20 -2
  87. package/Source/Core/createWorldTerrainAsync.js +48 -0
  88. package/Source/Core/sampleTerrain.js +9 -10
  89. package/Source/Core/sampleTerrainMostDetailed.js +66 -72
  90. package/Source/DataSources/Cesium3DTilesetVisualizer.js +37 -26
  91. package/Source/DataSources/Entity.js +6 -1
  92. package/Source/DataSources/ModelVisualizer.js +99 -31
  93. package/Source/DataSources/PolygonGraphics.js +1 -1
  94. package/Source/Scene/ArcGisMapServerImageryProvider.js +552 -376
  95. package/Source/Scene/BingMapsImageryProvider.js +511 -305
  96. package/Source/Scene/BufferLoader.js +29 -34
  97. package/Source/Scene/Cesium3DTile.js +388 -251
  98. package/Source/Scene/Cesium3DTileBatchTable.js +2 -2
  99. package/Source/Scene/Cesium3DTileContent.js +16 -0
  100. package/Source/Scene/Cesium3DTileContentFactory.js +4 -4
  101. package/Source/Scene/Cesium3DTilePass.js +8 -11
  102. package/Source/Scene/Cesium3DTileStyleEngine.js +1 -1
  103. package/Source/Scene/Cesium3DTilesVoxelProvider.js +225 -117
  104. package/Source/Scene/Cesium3DTileset.js +755 -481
  105. package/Source/Scene/Cesium3DTilesetBaseTraversal.js +301 -0
  106. package/Source/Scene/Cesium3DTilesetMostDetailedTraversal.js +33 -46
  107. package/Source/Scene/Cesium3DTilesetSkipTraversal.js +421 -0
  108. package/Source/Scene/Cesium3DTilesetTraversal.js +219 -671
  109. package/Source/Scene/ClassificationPrimitive.js +7 -0
  110. package/Source/Scene/Composite3DTileContent.js +69 -26
  111. package/Source/Scene/CreditDisplay.js +20 -4
  112. package/Source/Scene/DepthPlane.js +1 -1
  113. package/Source/Scene/Empty3DTileContent.js +31 -1
  114. package/Source/Scene/Geometry3DTileContent.js +47 -7
  115. package/Source/Scene/Globe.js +5 -1
  116. package/Source/Scene/GlobeSurfaceTile.js +2 -1
  117. package/Source/Scene/GlobeSurfaceTileProvider.js +50 -27
  118. package/Source/Scene/GltfBufferViewLoader.js +47 -91
  119. package/Source/Scene/GltfDracoLoader.js +110 -112
  120. package/Source/Scene/GltfImageLoader.js +71 -78
  121. package/Source/Scene/GltfIndexBufferLoader.js +108 -121
  122. package/Source/Scene/GltfJsonLoader.js +75 -74
  123. package/Source/Scene/GltfLoader.js +392 -280
  124. package/Source/Scene/GltfStructuralMetadataLoader.js +109 -110
  125. package/Source/Scene/GltfTextureLoader.js +97 -96
  126. package/Source/Scene/GltfVertexBufferLoader.js +128 -133
  127. package/Source/Scene/GoogleEarthEnterpriseImageryProvider.js +353 -225
  128. package/Source/Scene/GoogleEarthEnterpriseMapsProvider.js +491 -331
  129. package/Source/Scene/GridImageryProvider.js +267 -104
  130. package/Source/Scene/GroundPolylinePrimitive.js +12 -1
  131. package/Source/Scene/GroundPrimitive.js +8 -1
  132. package/Source/Scene/I3SDataProvider.js +214 -113
  133. package/Source/Scene/I3SFeature.js +7 -6
  134. package/Source/Scene/I3SLayer.js +26 -37
  135. package/Source/Scene/I3SNode.js +59 -66
  136. package/Source/Scene/Imagery.js +6 -1
  137. package/Source/Scene/ImageryLayer.js +299 -48
  138. package/Source/Scene/ImageryLayerCollection.js +26 -0
  139. package/Source/Scene/ImageryProvider.js +129 -111
  140. package/Source/Scene/Implicit3DTileContent.js +72 -23
  141. package/Source/Scene/ImplicitSubtree.js +66 -45
  142. package/Source/Scene/IonImageryProvider.js +471 -264
  143. package/Source/Scene/MapboxImageryProvider.js +272 -112
  144. package/Source/Scene/MapboxStyleImageryProvider.js +270 -111
  145. package/Source/Scene/MetadataSchemaLoader.js +26 -36
  146. package/Source/Scene/Model/B3dmLoader.js +42 -46
  147. package/Source/Scene/Model/GeoJsonLoader.js +8 -32
  148. package/Source/Scene/Model/I3dmLoader.js +48 -74
  149. package/Source/Scene/Model/Model.js +470 -132
  150. package/Source/Scene/Model/Model3DTileContent.js +83 -31
  151. package/Source/Scene/Model/ModelAnimationCollection.js +3 -3
  152. package/Source/Scene/Model/ModelDrawCommand.js +15 -26
  153. package/Source/Scene/Model/ModelUtility.js +16 -16
  154. package/Source/Scene/Model/PntsLoader.js +27 -32
  155. package/Source/Scene/Multiple3DTileContent.js +134 -115
  156. package/Source/Scene/PointCloud.js +11 -19
  157. package/Source/Scene/Primitive.js +20 -0
  158. package/Source/Scene/QuadtreePrimitive.js +2 -0
  159. package/Source/Scene/QuadtreeTileProvider.js +4 -8
  160. package/Source/Scene/ResourceCache.js +47 -105
  161. package/Source/Scene/ResourceCacheStatistics.js +24 -58
  162. package/Source/Scene/ResourceLoader.js +5 -17
  163. package/Source/Scene/ResourceLoaderState.js +12 -4
  164. package/Source/Scene/Scene.js +65 -0
  165. package/Source/Scene/ScreenSpaceCameraController.js +1 -1
  166. package/Source/Scene/SingleTileImageryProvider.js +382 -209
  167. package/Source/Scene/Terrain.js +196 -0
  168. package/Source/Scene/TileCoordinatesImageryProvider.js +267 -104
  169. package/Source/Scene/TileMapServiceImageryProvider.js +177 -85
  170. package/Source/Scene/Tileset3DTileContent.js +47 -5
  171. package/Source/Scene/TimeDynamicPointCloud.js +15 -2
  172. package/Source/Scene/UrlTemplateImageryProvider.js +343 -215
  173. package/Source/Scene/Vector3DTileClampedPolylines.js +96 -84
  174. package/Source/Scene/Vector3DTileContent.js +47 -22
  175. package/Source/Scene/Vector3DTileGeometry.js +57 -52
  176. package/Source/Scene/Vector3DTilePoints.js +72 -68
  177. package/Source/Scene/Vector3DTilePolygons.js +118 -117
  178. package/Source/Scene/Vector3DTilePolylines.js +86 -82
  179. package/Source/Scene/Vector3DTilePrimitive.js +0 -1
  180. package/Source/Scene/VoxelContent.js +61 -63
  181. package/Source/Scene/VoxelPrimitive.js +39 -91
  182. package/Source/Scene/VoxelProvider.js +2 -2
  183. package/Source/Scene/WebMapServiceImageryProvider.js +272 -111
  184. package/Source/Scene/WebMapTileServiceImageryProvider.js +270 -107
  185. package/Source/Scene/computeFlyToLocationForRectangle.js +33 -37
  186. package/Source/Scene/createOsmBuildings.js +6 -0
  187. package/Source/Scene/createOsmBuildingsAsync.js +82 -0
  188. package/Source/Scene/createWorldImagery.js +14 -5
  189. package/Source/Scene/createWorldImageryAsync.js +39 -0
  190. package/Source/Widget/CesiumWidget.js +55 -27
  191. package/index.d.ts +2158 -1395
  192. package/index.js +58 -51
  193. package/package.json +1 -1
@@ -89,6 +89,8 @@ const GltfLoaderState = {
89
89
  *
90
90
  * @type {number}
91
91
  * @constant
92
+ *
93
+ * @private
92
94
  */
93
95
  LOADED: 2,
94
96
  /**
@@ -97,6 +99,8 @@ const GltfLoaderState = {
97
99
  *
98
100
  * @type {number}
99
101
  * @constant
102
+ *
103
+ * @private
100
104
  */
101
105
  PROCESSING: 3,
102
106
  /**
@@ -109,6 +113,8 @@ const GltfLoaderState = {
109
113
  *
110
114
  * @type {number}
111
115
  * @constant
116
+ *
117
+ * @private
112
118
  */
113
119
  POST_PROCESSING: 4,
114
120
  /**
@@ -118,6 +124,8 @@ const GltfLoaderState = {
118
124
  *
119
125
  * @type {number}
120
126
  * @constant
127
+ *
128
+ * @private
121
129
  */
122
130
  PROCESSED: 5,
123
131
  /**
@@ -126,6 +134,8 @@ const GltfLoaderState = {
126
134
  *
127
135
  * @type {number}
128
136
  * @constant
137
+ *
138
+ * @private
129
139
  */
130
140
  READY: 6,
131
141
  /**
@@ -133,6 +143,8 @@ const GltfLoaderState = {
133
143
  *
134
144
  * @type {number}
135
145
  * @constant
146
+ *
147
+ * @private
136
148
  */
137
149
  FAILED: 7,
138
150
  /**
@@ -140,6 +152,8 @@ const GltfLoaderState = {
140
152
  *
141
153
  * @type {number}
142
154
  * @constant
155
+ *
156
+ * @private
143
157
  */
144
158
  UNLOADED: 8,
145
159
  };
@@ -242,9 +256,8 @@ function GltfLoader(options) {
242
256
  this._state = GltfLoaderState.NOT_LOADED;
243
257
  this._textureState = GltfLoaderState.NOT_LOADED;
244
258
  this._promise = undefined;
245
- this._texturesLoadedPromise = undefined;
246
- this._process = function (loader, frameState) {};
247
- this._processTextures = function (loader, frameState) {};
259
+ this._processError = undefined;
260
+ this._textureErrors = [];
248
261
 
249
262
  // Information about whether to load primitives as typed arrays or buffers,
250
263
  // and whether post-processing is needed after loading (e.g. for
@@ -255,9 +268,14 @@ function GltfLoader(options) {
255
268
  this._loaderPromises = [];
256
269
  this._textureLoaders = [];
257
270
  this._texturesPromises = [];
271
+ this._textureCallbacks = [];
258
272
  this._bufferViewLoaders = [];
259
273
  this._geometryLoaders = [];
274
+ this._geometryCallbacks = [];
260
275
  this._structuralMetadataLoader = undefined;
276
+ this._loadResourcesPromise = undefined;
277
+ this._resourcesLoaded = false;
278
+ this._texturesLoaded = false;
261
279
 
262
280
  // In some cases where geometry post-processing is needed (like generating
263
281
  // outlines) new attributes are added that may have GPU resources attached.
@@ -275,231 +293,223 @@ if (defined(Object.create)) {
275
293
 
276
294
  Object.defineProperties(GltfLoader.prototype, {
277
295
  /**
278
- * A promise that resolves to the resource when the resource is ready, or undefined if the resource hasn't started loading.
296
+ * The cache key of the resource.
279
297
  *
280
298
  * @memberof GltfLoader.prototype
281
299
  *
282
- * @type {Promise<GltfLoader>|undefined}
300
+ * @type {string}
283
301
  * @readonly
284
302
  * @private
285
303
  */
286
- promise: {
304
+ cacheKey: {
287
305
  get: function () {
288
- return this._promise;
306
+ return undefined;
289
307
  },
290
308
  },
291
309
  /**
292
- * The cache key of the resource.
310
+ * The loaded components.
293
311
  *
294
312
  * @memberof GltfLoader.prototype
295
313
  *
296
- * @type {string}
314
+ * @type {ModelComponents.Components}
297
315
  * @readonly
298
316
  * @private
299
317
  */
300
- cacheKey: {
318
+ components: {
301
319
  get: function () {
302
- return undefined;
320
+ return this._components;
303
321
  },
304
322
  },
305
323
  /**
306
- * The loaded components.
324
+ * The loaded glTF json.
307
325
  *
308
326
  * @memberof GltfLoader.prototype
309
327
  *
310
- * @type {ModelComponents.Components}
328
+ * @type {object}
311
329
  * @readonly
312
330
  * @private
313
331
  */
314
- components: {
332
+ gltfJson: {
315
333
  get: function () {
316
- return this._components;
334
+ if (defined(this._gltfJsonLoader)) {
335
+ return this._gltfJsonLoader.gltf;
336
+ }
337
+ return this._gltfJson;
317
338
  },
318
339
  },
319
-
320
340
  /**
321
- * A promise that resolves when all textures are loaded.
322
- * When <code>incrementallyLoadTextures</code> is true this may resolve after
323
- * <code>promise</code> resolves.
341
+ * Returns true if textures are loaded separately from the other glTF resources.
324
342
  *
325
343
  * @memberof GltfLoader.prototype
326
344
  *
327
- * @type {Promise<void>}
345
+ * @type {boolean}
328
346
  * @readonly
329
347
  * @private
330
348
  */
331
- texturesLoadedPromise: {
349
+ incrementallyLoadTextures: {
332
350
  get: function () {
333
- return this._texturesLoadedPromise;
351
+ return this._incrementallyLoadTextures;
352
+ },
353
+ },
354
+ /**
355
+ * true if textures are loaded, useful when incrementallyLoadTextures is true
356
+ *
357
+ * @memberof GltfLoader.prototype
358
+ *
359
+ * @type {boolean}
360
+ * @readonly
361
+ * @private
362
+ */
363
+ texturesLoaded: {
364
+ get: function () {
365
+ return this._texturesLoaded;
334
366
  },
335
367
  },
336
368
  });
337
369
 
338
370
  /**
339
- * Loads the resource.
340
- * @returns {Promise<GltfLoader>} A promise which resolves to the loader when the resource loading is completed.
341
- * @private
371
+ * Loads the gltf object
342
372
  */
343
- GltfLoader.prototype.load = function () {
344
- const gltfJsonLoader = ResourceCache.loadGltfJson({
345
- gltfResource: this._gltfResource,
346
- baseResource: this._baseResource,
347
- typedArray: this._typedArray,
348
- gltfJson: this._gltfJson,
349
- });
350
-
351
- this._gltfJsonLoader = gltfJsonLoader;
352
- this._state = GltfLoaderState.LOADING;
353
- this._textureState = GltfLoaderState.LOADING;
373
+ async function loadGltfJson(loader) {
374
+ loader._state = GltfLoaderState.LOADING;
375
+ loader._textureState = GltfLoaderState.LOADING;
376
+
377
+ try {
378
+ const gltfJsonLoader = ResourceCache.getGltfJsonLoader({
379
+ gltfResource: loader._gltfResource,
380
+ baseResource: loader._baseResource,
381
+ typedArray: loader._typedArray,
382
+ gltfJson: loader._gltfJson,
383
+ });
384
+ loader._gltfJsonLoader = gltfJsonLoader;
385
+ await gltfJsonLoader.load();
354
386
 
355
- const that = this;
356
- let textureProcessPromise;
357
- const processPromise = new Promise(function (resolve, reject) {
358
- textureProcessPromise = new Promise(function (
359
- resolveTextures,
360
- rejectTextures
387
+ if (
388
+ loader.isDestroyed() ||
389
+ loader.isUnloaded() ||
390
+ gltfJsonLoader.isDestroyed()
361
391
  ) {
362
- that._process = function (loader, frameState) {
363
- if (!FeatureDetection.supportsWebP.initialized) {
364
- FeatureDetection.supportsWebP.initialize();
365
- return;
366
- }
367
-
368
- if (loader._state === GltfLoaderState.LOADED) {
369
- loader._state = GltfLoaderState.PROCESSING;
370
-
371
- const supportedImageFormats = new SupportedImageFormats({
372
- webp: FeatureDetection.supportsWebP(),
373
- basis: frameState.context.supportsBasis,
374
- });
375
-
376
- let gltf;
377
- if (defined(loader._gltfJsonLoader)) {
378
- gltf = loader._gltfJsonLoader.gltf;
379
- } else {
380
- gltf = loader._gltfJson;
381
- }
382
-
383
- // Parse the glTF which populates the loaders arrays. The promise will
384
- // resolve once all the loaders are ready (i.e. all external resources
385
- // have been fetched and all GPU resources have been created). Loaders that
386
- // create GPU resources need to be processed every frame until they become
387
- // ready since the JobScheduler is not able to execute all jobs in a single
388
- // frame. Also note that it's fine to call process before a loader is ready
389
- // to process; nothing will happen.
390
- parse(
391
- loader,
392
- gltf,
393
- supportedImageFormats,
394
- frameState,
395
- reject,
396
- rejectTextures
397
- );
398
-
399
- if (defined(loader._gltfJsonLoader) && loader._releaseGltfJson) {
400
- // Check that the glTF JSON loader is still defined before trying to unload it.
401
- // It may be undefined if the ready promise rejects immediately (which can happen in unit tests)
402
- ResourceCache.unload(loader._gltfJsonLoader);
403
- loader._gltfJsonLoader = undefined;
404
- }
405
- }
392
+ return;
393
+ }
406
394
 
407
- if (loader._state === GltfLoaderState.PROCESSING) {
408
- processLoaders(loader, frameState);
409
- }
395
+ const gltf = gltfJsonLoader.gltf;
396
+ const version = gltf.asset.version;
397
+ if (version !== "1.0" && version !== "2.0") {
398
+ const url = loader._gltfResource.url;
399
+ throw new RuntimeError(
400
+ `Failed to load ${url}: \nUnsupported glTF version: ${version}`
401
+ );
402
+ }
410
403
 
411
- if (loader._state === GltfLoaderState.POST_PROCESSING) {
412
- postProcessGeometry(loader, frameState.context);
413
- loader._state = GltfLoaderState.PROCESSED;
414
- }
404
+ const extensionsRequired = gltf.extensionsRequired;
405
+ if (defined(extensionsRequired)) {
406
+ ModelUtility.checkSupportedExtensions(extensionsRequired);
415
407
 
416
- if (loader._state === GltfLoaderState.PROCESSED) {
417
- // The buffer views can be unloaded once the data is copied.
418
- unloadBufferViews(loader);
408
+ // Check for the KHR_mesh_quantization extension here, it will be used later
409
+ // in loadAttribute().
410
+ loader._hasKhrMeshQuantization = extensionsRequired.includes(
411
+ "KHR_mesh_quantization"
412
+ );
413
+ }
419
414
 
420
- // Similarly, if the glTF was loaded from a typed array, release the memory
421
- loader._typedArray = undefined;
415
+ loader._state = GltfLoaderState.LOADED;
416
+ loader._textureState = GltfLoaderState.LOADED;
422
417
 
423
- loader._state = GltfLoaderState.READY;
424
- resolve(loader);
425
- }
426
- };
418
+ return loader;
419
+ } catch (error) {
420
+ if (loader.isDestroyed()) {
421
+ return;
422
+ }
427
423
 
428
- that._processTextures = function (loader, frameState) {
429
- if (loader._textureState === GltfLoaderState.LOADED) {
430
- loader._textureState = GltfLoaderState.PROCESSING;
431
- }
424
+ loader._state = GltfLoaderState.FAILED;
425
+ loader._textureState = GltfLoaderState.FAILED;
426
+ handleError(loader, error);
427
+ }
428
+ }
432
429
 
433
- if (loader._textureState === GltfLoaderState.PROCESSING) {
434
- let i;
435
- const textureLoaders = loader._textureLoaders;
436
- const textureLoadersLength = textureLoaders.length;
437
- for (i = 0; i < textureLoadersLength; ++i) {
438
- textureLoaders[i].process(frameState);
439
- }
440
- }
430
+ async function loadResources(loader, frameState) {
431
+ if (!FeatureDetection.supportsWebP.initialized) {
432
+ await FeatureDetection.supportsWebP.initialize();
433
+ }
441
434
 
442
- if (loader._textureState === GltfLoaderState.PROCESSED) {
443
- loader._textureState = GltfLoaderState.READY;
444
- resolveTextures(loader);
445
- }
446
- };
447
- });
435
+ const supportedImageFormats = new SupportedImageFormats({
436
+ webp: FeatureDetection.supportsWebP(),
437
+ basis: frameState.context.supportsBasis,
448
438
  });
449
439
 
450
- this._promise = gltfJsonLoader.promise
451
- .then(function () {
452
- if (that.isDestroyed()) {
453
- return;
454
- }
455
- that._state = GltfLoaderState.LOADED;
456
- that._textureState = GltfLoaderState.LOADED;
440
+ // Parse the glTF which populates the loaders arrays. Loading promises will be created, and will
441
+ // resolve once the loaders are ready (i.e. all external resources
442
+ // have been fetched and all GPU resources have been created). Loaders that
443
+ // create GPU resources need to be processed every frame until they become
444
+ // ready since the JobScheduler is not able to execute all jobs in a single
445
+ // frame. Any promise failures are collected, and will be handled synchronously in process(). Also note that it's fine to call process before a loader is ready
446
+ // to process or after it has failed; nothing will happen.
447
+ const gltf = loader.gltfJson;
448
+ const promise = parse(loader, gltf, supportedImageFormats, frameState);
457
449
 
458
- return processPromise;
459
- })
460
- .catch(function (error) {
461
- if (that.isDestroyed()) {
462
- return;
463
- }
464
- that._state = GltfLoaderState.FAILED;
465
- that._textureState = GltfLoaderState.FAILED;
466
- return handleError(that, error);
467
- });
450
+ // All resource loaders have been created, so we can begin processing
451
+ loader._state = GltfLoaderState.PROCESSING;
452
+ loader._textureState = GltfLoaderState.PROCESSING;
468
453
 
469
- this._texturesLoadedPromise = textureProcessPromise.catch(function (error) {
470
- if (that.isDestroyed()) {
471
- return;
472
- }
454
+ if (defined(loader._gltfJsonLoader) && loader._releaseGltfJson) {
455
+ // Check that the glTF JSON loader is still defined before trying to unload it.
456
+ // It can be unloaded if the glTF loader is destroyed.
457
+ ResourceCache.unload(loader._gltfJsonLoader);
458
+ loader._gltfJsonLoader = undefined;
459
+ }
473
460
 
474
- that._textureState = GltfLoaderState.FAILED;
475
- return handleError(that, error);
476
- });
461
+ return promise;
462
+ }
463
+
464
+ /**
465
+ * Loads the resource.
466
+ * @returns {Promise.<GltfLoader>} A promise which resolves to the loader when the resource loading is completed.
467
+ * @exception {RuntimeError} Unsupported glTF version
468
+ * @exception {RuntimeError} Unsupported glTF Extension
469
+ * @private
470
+ */
471
+ GltfLoader.prototype.load = async function () {
472
+ if (defined(this._promise)) {
473
+ return this._promise;
474
+ }
477
475
 
476
+ this._promise = loadGltfJson(this);
478
477
  return this._promise;
479
478
  };
480
479
 
481
480
  function handleError(gltfLoader, error) {
482
481
  gltfLoader.unload();
483
482
  const errorMessage = "Failed to load glTF";
484
- error = gltfLoader.getError(errorMessage, error);
485
- return Promise.reject(error);
483
+ throw gltfLoader.getError(errorMessage, error);
486
484
  }
487
485
 
488
486
  function processLoaders(loader, frameState) {
489
- const bufferViewLoaders = loader._bufferViewLoaders;
490
- const bufferViewLoadersLength = bufferViewLoaders.length;
491
- for (let i = 0; i < bufferViewLoadersLength; ++i) {
492
- bufferViewLoaders[i].process(frameState);
493
- }
494
-
487
+ let i;
488
+ let ready = true;
495
489
  const geometryLoaders = loader._geometryLoaders;
496
490
  const geometryLoadersLength = geometryLoaders.length;
497
- for (let i = 0; i < geometryLoadersLength; ++i) {
498
- geometryLoaders[i].process(frameState);
491
+ for (i = 0; i < geometryLoadersLength; ++i) {
492
+ const geometryReady = geometryLoaders[i].process(frameState);
493
+ if (geometryReady && defined(loader._geometryCallbacks[i])) {
494
+ loader._geometryCallbacks[i]();
495
+ loader._geometryCallbacks[i] = undefined;
496
+ }
497
+ ready = ready && geometryReady;
499
498
  }
500
499
 
501
- if (defined(loader._structuralMetadataLoader)) {
502
- loader._structuralMetadataLoader.process(frameState);
500
+ const structuralMetadataLoader = loader._structuralMetadataLoader;
501
+ if (defined(structuralMetadataLoader)) {
502
+ const metadataReady = structuralMetadataLoader.process(frameState);
503
+ if (metadataReady) {
504
+ loader._components.structuralMetadata =
505
+ structuralMetadataLoader.structuralMetadata;
506
+ }
507
+ ready = ready && metadataReady;
508
+ }
509
+
510
+ if (ready) {
511
+ // Geometry requires further processing
512
+ loader._state = GltfLoaderState.POST_PROCESSING;
503
513
  }
504
514
  }
505
515
 
@@ -549,6 +559,77 @@ function gatherPostProcessBuffers(loader, primitiveLoadPlan) {
549
559
  }
550
560
  }
551
561
 
562
+ /**
563
+ * Process loaders other than textures
564
+ * @private
565
+ */
566
+ GltfLoader.prototype._process = function (frameState) {
567
+ if (this._state === GltfLoaderState.READY) {
568
+ return true;
569
+ }
570
+
571
+ if (this._state === GltfLoaderState.PROCESSING) {
572
+ processLoaders(this, frameState);
573
+ }
574
+
575
+ if (
576
+ this._resourcesLoaded &&
577
+ this._state === GltfLoaderState.POST_PROCESSING
578
+ ) {
579
+ postProcessGeometry(this, frameState.context);
580
+ this._state = GltfLoaderState.PROCESSED;
581
+ }
582
+
583
+ if (this._resourcesLoaded && this._state === GltfLoaderState.PROCESSED) {
584
+ // The buffer views can be unloaded once the data is copied.
585
+ unloadBufferViewLoaders(this);
586
+
587
+ // Similarly, if the glTF was loaded from a typed array, release the memory
588
+ this._typedArray = undefined;
589
+
590
+ this._state = GltfLoaderState.READY;
591
+ return true;
592
+ }
593
+
594
+ return false;
595
+ };
596
+
597
+ /**
598
+ * Process textures other than textures
599
+ * @private
600
+ */
601
+ GltfLoader.prototype._processTextures = function (frameState) {
602
+ if (this._textureState === GltfLoaderState.READY) {
603
+ return true;
604
+ }
605
+
606
+ if (this._textureState !== GltfLoaderState.PROCESSING) {
607
+ return false;
608
+ }
609
+
610
+ let i;
611
+ let ready = true;
612
+ const textureLoaders = this._textureLoaders;
613
+ const textureLoadersLength = textureLoaders.length;
614
+ for (i = 0; i < textureLoadersLength; ++i) {
615
+ const textureReady = textureLoaders[i].process(frameState);
616
+ if (textureReady && defined(this._textureCallbacks[i])) {
617
+ this._textureCallbacks[i]();
618
+ this._textureCallbacks[i] = undefined;
619
+ }
620
+
621
+ ready = ready && textureReady;
622
+ }
623
+
624
+ if (!ready) {
625
+ return false;
626
+ }
627
+
628
+ this._textureState = GltfLoaderState.READY;
629
+ this._texturesLoaded = true;
630
+ return true;
631
+ };
632
+
552
633
  /**
553
634
  * Processes the resource until it becomes ready.
554
635
  *
@@ -560,12 +641,64 @@ GltfLoader.prototype.process = function (frameState) {
560
641
  Check.typeOf.object("frameState", frameState);
561
642
  //>>includeEnd('debug');
562
643
 
563
- this._process(this, frameState);
644
+ if (
645
+ this._state === GltfLoaderState.LOADED &&
646
+ !defined(this._loadResourcesPromise)
647
+ ) {
648
+ this._loadResourcesPromise = loadResources(this, frameState)
649
+ .then(() => {
650
+ this._resourcesLoaded = true;
651
+ })
652
+ .catch((error) => {
653
+ this._processError = error;
654
+ });
655
+ }
656
+
657
+ if (defined(this._processError)) {
658
+ this._state = GltfLoaderState.FAILED;
659
+ const error = this._processError;
660
+ this._processError = undefined;
661
+ handleError(this, error);
662
+ }
663
+
664
+ // Pop the next error of the list in case there are multiple
665
+ const textureError = this._textureErrors.pop();
666
+ if (defined(textureError)) {
667
+ // There shouldn't be the need to completely unload in this case. Just throw the error.
668
+ const error = this.getError("Failed to load glTF texture", textureError);
669
+ error.name = "TextureError";
670
+ throw error;
671
+ }
672
+
673
+ if (this._state === GltfLoaderState.FAILED) {
674
+ return false;
675
+ }
676
+
677
+ let ready = false;
678
+ try {
679
+ ready = this._process(frameState);
680
+ } catch (error) {
681
+ this._state = GltfLoaderState.FAILED;
682
+ handleError(this, error);
683
+ }
684
+
564
685
  // Since textures can be loaded independently and are handled through a separate promise, they are processed in their own function
565
- this._processTextures(this, frameState);
686
+ let texturesReady = false;
687
+ try {
688
+ texturesReady = this._processTextures(frameState);
689
+ } catch (error) {
690
+ this._textureState = GltfLoaderState.FAILED;
691
+ handleError(this, error);
692
+ }
693
+
694
+ if (this._incrementallyLoadTextures) {
695
+ return ready;
696
+ }
697
+
698
+ return ready && texturesReady;
566
699
  };
567
700
 
568
- function loadVertexBuffer(
701
+ function getVertexBufferLoader(
569
702
  loader,
570
703
  gltf,
571
704
  accessorId,
@@ -578,7 +711,7 @@ function loadVertexBuffer(
578
711
  const accessor = gltf.accessors[accessorId];
579
712
  const bufferViewId = accessor.bufferView;
580
713
 
581
- const vertexBufferLoader = ResourceCache.loadVertexBuffer({
714
+ const vertexBufferLoader = ResourceCache.getVertexBufferLoader({
582
715
  gltf: gltf,
583
716
  gltfResource: loader._gltfResource,
584
717
  baseResource: loader._baseResource,
@@ -592,12 +725,10 @@ function loadVertexBuffer(
592
725
  loadTypedArray: loadTypedArray,
593
726
  });
594
727
 
595
- loader._geometryLoaders.push(vertexBufferLoader);
596
-
597
728
  return vertexBufferLoader;
598
729
  }
599
730
 
600
- function loadIndexBuffer(
731
+ function getIndexBufferLoader(
601
732
  loader,
602
733
  gltf,
603
734
  accessorId,
@@ -606,7 +737,7 @@ function loadIndexBuffer(
606
737
  loadTypedArray,
607
738
  frameState
608
739
  ) {
609
- const indexBufferLoader = ResourceCache.loadIndexBuffer({
740
+ const indexBufferLoader = ResourceCache.getIndexBufferLoader({
610
741
  gltf: gltf,
611
742
  accessorId: accessorId,
612
743
  gltfResource: loader._gltfResource,
@@ -618,13 +749,11 @@ function loadIndexBuffer(
618
749
  loadTypedArray: loadTypedArray,
619
750
  });
620
751
 
621
- loader._geometryLoaders.push(indexBufferLoader);
622
-
623
752
  return indexBufferLoader;
624
753
  }
625
754
 
626
- function loadBufferView(loader, gltf, bufferViewId) {
627
- const bufferViewLoader = ResourceCache.loadBufferView({
755
+ function getBufferViewLoader(loader, gltf, bufferViewId) {
756
+ const bufferViewLoader = ResourceCache.getBufferViewLoader({
628
757
  gltf: gltf,
629
758
  bufferViewId: bufferViewId,
630
759
  gltfResource: loader._gltfResource,
@@ -720,6 +849,26 @@ function loadAccessorValues(accessor, typedArray, values, useQuaternion) {
720
849
  return values;
721
850
  }
722
851
 
852
+ async function loadAccessorBufferView(
853
+ loader,
854
+ bufferViewLoader,
855
+ gltf,
856
+ accessor,
857
+ useQuaternion,
858
+ values
859
+ ) {
860
+ await bufferViewLoader.load();
861
+ if (loader.isDestroyed()) {
862
+ return;
863
+ }
864
+
865
+ const bufferViewTypedArray = bufferViewLoader.typedArray;
866
+ const typedArray = getPackedTypedArray(gltf, accessor, bufferViewTypedArray);
867
+
868
+ useQuaternion = defaultValue(useQuaternion, false);
869
+ loadAccessorValues(accessor, typedArray, values, useQuaternion);
870
+ }
871
+
723
872
  function loadAccessor(loader, gltf, accessorId, useQuaternion) {
724
873
  const accessor = gltf.accessors[accessorId];
725
874
  const accessorCount = accessor.count;
@@ -727,21 +876,15 @@ function loadAccessor(loader, gltf, accessorId, useQuaternion) {
727
876
 
728
877
  const bufferViewId = accessor.bufferView;
729
878
  if (defined(bufferViewId)) {
730
- const bufferViewLoader = loadBufferView(loader, gltf, bufferViewId);
731
- const promise = bufferViewLoader.promise.then(function (bufferViewLoader) {
732
- if (loader.isDestroyed()) {
733
- return;
734
- }
735
- const bufferViewTypedArray = bufferViewLoader.typedArray;
736
- const typedArray = getPackedTypedArray(
737
- gltf,
738
- accessor,
739
- bufferViewTypedArray
740
- );
741
-
742
- useQuaternion = defaultValue(useQuaternion, false);
743
- loadAccessorValues(accessor, typedArray, values, useQuaternion);
744
- });
879
+ const bufferViewLoader = getBufferViewLoader(loader, gltf, bufferViewId);
880
+ const promise = loadAccessorBufferView(
881
+ loader,
882
+ bufferViewLoader,
883
+ gltf,
884
+ accessor,
885
+ useQuaternion,
886
+ values
887
+ );
745
888
  loader._loaderPromises.push(promise);
746
889
 
747
890
  return values;
@@ -1062,7 +1205,7 @@ function loadAttribute(
1062
1205
  return attribute;
1063
1206
  }
1064
1207
 
1065
- const vertexBufferLoader = loadVertexBuffer(
1208
+ const vertexBufferLoader = getVertexBufferLoader(
1066
1209
  loader,
1067
1210
  gltf,
1068
1211
  accessorId,
@@ -1072,13 +1215,15 @@ function loadAttribute(
1072
1215
  loadTypedArray,
1073
1216
  frameState
1074
1217
  );
1075
- const promise = vertexBufferLoader.promise.then(function (
1076
- vertexBufferLoader
1077
- ) {
1078
- if (loader.isDestroyed()) {
1079
- return;
1080
- }
1081
1218
 
1219
+ const index = loader._geometryLoaders.length;
1220
+ loader._geometryLoaders.push(vertexBufferLoader);
1221
+ const promise = vertexBufferLoader.load();
1222
+ loader._loaderPromises.push(promise);
1223
+ // This can only execute once vertexBufferLoader.process() has run and returns true
1224
+ // Save this finish callback by the loader index so it can be called
1225
+ // in process().
1226
+ loader._geometryCallbacks[index] = () => {
1082
1227
  if (
1083
1228
  defined(draco) &&
1084
1229
  defined(draco.attributes) &&
@@ -1100,9 +1245,7 @@ function loadAttribute(
1100
1245
  loadTypedArray
1101
1246
  );
1102
1247
  }
1103
- });
1104
-
1105
- loader._loaderPromises.push(promise);
1248
+ };
1106
1249
 
1107
1250
  return attribute;
1108
1251
  }
@@ -1276,7 +1419,7 @@ function loadIndices(
1276
1419
  const loadBuffer = needsPostProcessing ? false : outputBuffer;
1277
1420
  const loadTypedArray = needsPostProcessing ? true : outputTypedArray;
1278
1421
 
1279
- const indexBufferLoader = loadIndexBuffer(
1422
+ const indexBufferLoader = getIndexBufferLoader(
1280
1423
  loader,
1281
1424
  gltf,
1282
1425
  accessorId,
@@ -1286,18 +1429,18 @@ function loadIndices(
1286
1429
  frameState
1287
1430
  );
1288
1431
 
1289
- const promise = indexBufferLoader.promise.then(function (indexBufferLoader) {
1290
- if (loader.isDestroyed()) {
1291
- return;
1292
- }
1293
-
1432
+ const index = loader._geometryLoaders.length;
1433
+ loader._geometryLoaders.push(indexBufferLoader);
1434
+ const promise = indexBufferLoader.load();
1435
+ loader._loaderPromises.push(promise);
1436
+ // This can only execute once indexBufferLoader.process() has run and returns true
1437
+ // Save this finish callback by the loader index so it can be called
1438
+ // in process().
1439
+ loader._geometryCallbacks[index] = () => {
1294
1440
  indices.indexDatatype = indexBufferLoader.indexDatatype;
1295
-
1296
1441
  indices.buffer = indexBufferLoader.buffer;
1297
1442
  indices.typedArray = indexBufferLoader.typedArray;
1298
- });
1299
-
1300
- loader._loaderPromises.push(promise);
1443
+ };
1301
1444
 
1302
1445
  const indicesPlan = new PrimitiveLoadPlan.IndicesLoadPlan(indices);
1303
1446
  indicesPlan.loadBuffer = outputBuffer;
@@ -1324,7 +1467,7 @@ function loadTexture(
1324
1467
  return undefined;
1325
1468
  }
1326
1469
 
1327
- const textureLoader = ResourceCache.loadTexture({
1470
+ const textureLoader = ResourceCache.getTextureLoader({
1328
1471
  gltf: gltf,
1329
1472
  textureInfo: textureInfo,
1330
1473
  gltfResource: loader._gltfResource,
@@ -1334,23 +1477,37 @@ function loadTexture(
1334
1477
  asynchronous: loader._asynchronous,
1335
1478
  });
1336
1479
 
1337
- loader._textureLoaders.push(textureLoader);
1338
-
1339
1480
  const textureReader = GltfLoaderUtil.createModelTextureReader({
1340
1481
  textureInfo: textureInfo,
1341
1482
  });
1342
1483
 
1343
- const promise = textureLoader.promise.then(function (textureLoader) {
1344
- if (loader.isUnloaded() || loader.isDestroyed()) {
1484
+ const index = loader._textureLoaders.length;
1485
+ loader._textureLoaders.push(textureLoader);
1486
+ const promise = textureLoader.load().catch((error) => {
1487
+ if (loader.isDestroyed()) {
1345
1488
  return;
1346
1489
  }
1490
+
1491
+ if (!loader._incrementallyLoadTextures) {
1492
+ // If incrementallyLoadTextures is false, throw the error to ensure the loader state
1493
+ // immediately is set to have failed
1494
+ throw error;
1495
+ }
1496
+
1497
+ // Otherwise, save the error so it can be thrown next
1498
+ loader._textureState = GltfLoaderState.FAILED;
1499
+ loader._textureErrors.push(error);
1500
+ });
1501
+ loader._texturesPromises.push(promise);
1502
+ // This can only execute once textureLoader.process() has run and returns true
1503
+ // Save this finish callback by the loader index so it can be called
1504
+ // in process().
1505
+ loader._textureCallbacks[index] = () => {
1347
1506
  textureReader.texture = textureLoader.texture;
1348
1507
  if (defined(samplerOverride)) {
1349
1508
  textureReader.texture.sampler = samplerOverride;
1350
1509
  }
1351
- });
1352
-
1353
- loader._texturesPromises.push(promise);
1510
+ };
1354
1511
 
1355
1512
  return textureReader;
1356
1513
  }
@@ -2246,7 +2403,7 @@ function loadSkins(loader, gltf, nodes) {
2246
2403
  return skins;
2247
2404
  }
2248
2405
 
2249
- function loadStructuralMetadata(
2406
+ async function loadStructuralMetadata(
2250
2407
  loader,
2251
2408
  gltf,
2252
2409
  extension,
@@ -2264,11 +2421,8 @@ function loadStructuralMetadata(
2264
2421
  frameState: frameState,
2265
2422
  asynchronous: loader._asynchronous,
2266
2423
  });
2267
- structuralMetadataLoader.load();
2268
-
2269
2424
  loader._structuralMetadataLoader = structuralMetadataLoader;
2270
-
2271
- return structuralMetadataLoader;
2425
+ return structuralMetadataLoader.load();
2272
2426
  }
2273
2427
 
2274
2428
  function loadAnimationSampler(loader, gltf, gltfSampler) {
@@ -2442,32 +2596,7 @@ function loadScene(gltf, nodes) {
2442
2596
 
2443
2597
  const scratchCenter = new Cartesian3();
2444
2598
 
2445
- function parse(
2446
- loader,
2447
- gltf,
2448
- supportedImageFormats,
2449
- frameState,
2450
- rejectPromise,
2451
- rejectTexturesPromise
2452
- ) {
2453
- const version = gltf.asset.version;
2454
- if (version !== "1.0" && version !== "2.0") {
2455
- const url = loader._gltfResource.url;
2456
- throw new RuntimeError(
2457
- `Failed to load ${url}: \nUnsupported glTF version: ${version}`
2458
- );
2459
- }
2460
- const extensionsRequired = gltf.extensionsRequired;
2461
- if (defined(extensionsRequired)) {
2462
- ModelUtility.checkSupportedExtensions(extensionsRequired);
2463
-
2464
- // Check for the KHR_mesh_quantization extension here, it will be used later
2465
- // in loadAttribute().
2466
- loader._hasKhrMeshQuantization = extensionsRequired.includes(
2467
- "KHR_mesh_quantization"
2468
- );
2469
- }
2470
-
2599
+ function parse(loader, gltf, supportedImageFormats, frameState) {
2471
2600
  const extensions = defaultValue(gltf.extensions, defaultValue.EMPTY_OBJECT);
2472
2601
  const structuralMetadataExtension = extensions.EXT_structural_metadata;
2473
2602
  const featureMetadataExtensionLegacy = extensions.EXT_feature_metadata;
@@ -2535,7 +2664,7 @@ function parse(
2535
2664
  defined(structuralMetadataExtension) ||
2536
2665
  defined(featureMetadataExtensionLegacy)
2537
2666
  ) {
2538
- const structuralMetadataLoader = loadStructuralMetadata(
2667
+ const promise = loadStructuralMetadata(
2539
2668
  loader,
2540
2669
  gltf,
2541
2670
  structuralMetadataExtension,
@@ -2543,62 +2672,40 @@ function parse(
2543
2672
  supportedImageFormats,
2544
2673
  frameState
2545
2674
  );
2546
- const promise = structuralMetadataLoader.promise.then(function (
2547
- structuralMetadataLoader
2548
- ) {
2549
- if (loader.isDestroyed()) {
2550
- return;
2551
- }
2552
- components.structuralMetadata =
2553
- structuralMetadataLoader.structuralMetadata;
2554
- });
2555
2675
  loader._loaderPromises.push(promise);
2556
2676
  }
2557
2677
 
2558
- // Gather promises and reject if any promises fail.
2678
+ // Gather promises and handle any errors
2559
2679
  const readyPromises = [];
2560
2680
  readyPromises.push.apply(readyPromises, loader._loaderPromises);
2561
2681
 
2682
+ // When incrementallyLoadTextures is true, the errors are caught and thrown individually
2683
+ // since it doesn't affect the overall loader state
2562
2684
  if (!loader._incrementallyLoadTextures) {
2563
2685
  readyPromises.push.apply(readyPromises, loader._texturesPromises);
2564
2686
  }
2565
2687
 
2566
- Promise.all(readyPromises)
2567
- .then(function () {
2568
- if (loader.isDestroyed()) {
2569
- return;
2570
- }
2571
- loader._state = GltfLoaderState.POST_PROCESSING;
2572
- })
2573
- .catch(rejectPromise);
2574
-
2575
- // Separate promise will resolve once textures are loaded.
2576
- Promise.all(loader._texturesPromises)
2577
- .then(function () {
2578
- if (loader.isDestroyed()) {
2579
- return;
2580
- }
2581
-
2582
- // post processing only applies for geometry
2583
- loader._textureState = GltfLoaderState.PROCESSED;
2584
- })
2585
- .catch(rejectTexturesPromise);
2688
+ return Promise.all(readyPromises);
2586
2689
  }
2587
2690
 
2588
2691
  function unloadTextures(loader) {
2589
2692
  const textureLoaders = loader._textureLoaders;
2590
2693
  const textureLoadersLength = textureLoaders.length;
2591
2694
  for (let i = 0; i < textureLoadersLength; ++i) {
2592
- ResourceCache.unload(textureLoaders[i]);
2695
+ textureLoaders[i] =
2696
+ !textureLoaders[i].isDestroyed() &&
2697
+ ResourceCache.unload(textureLoaders[i]);
2593
2698
  }
2594
2699
  loader._textureLoaders.length = 0;
2595
2700
  }
2596
2701
 
2597
- function unloadBufferViews(loader) {
2702
+ function unloadBufferViewLoaders(loader) {
2598
2703
  const bufferViewLoaders = loader._bufferViewLoaders;
2599
2704
  const bufferViewLoadersLength = bufferViewLoaders.length;
2600
2705
  for (let i = 0; i < bufferViewLoadersLength; ++i) {
2601
- ResourceCache.unload(bufferViewLoaders[i]);
2706
+ bufferViewLoaders[i] =
2707
+ !bufferViewLoaders[i].isDestroyed() &&
2708
+ ResourceCache.unload(bufferViewLoaders[i]);
2602
2709
  }
2603
2710
  loader._bufferViewLoaders.length = 0;
2604
2711
  }
@@ -2607,7 +2714,9 @@ function unloadGeometry(loader) {
2607
2714
  const geometryLoaders = loader._geometryLoaders;
2608
2715
  const geometryLoadersLength = geometryLoaders.length;
2609
2716
  for (let i = 0; i < geometryLoadersLength; ++i) {
2610
- ResourceCache.unload(geometryLoaders[i]);
2717
+ geometryLoaders[i] =
2718
+ !geometryLoaders[i].isDestroyed() &&
2719
+ ResourceCache.unload(geometryLoaders[i]);
2611
2720
  }
2612
2721
  loader._geometryLoaders.length = 0;
2613
2722
  }
@@ -2625,7 +2734,10 @@ function unloadGeneratedAttributes(loader) {
2625
2734
  }
2626
2735
 
2627
2736
  function unloadStructuralMetadata(loader) {
2628
- if (defined(loader._structuralMetadataLoader)) {
2737
+ if (
2738
+ defined(loader._structuralMetadataLoader) &&
2739
+ !loader._structuralMetadataLoader.isDestroyed()
2740
+ ) {
2629
2741
  loader._structuralMetadataLoader.destroy();
2630
2742
  loader._structuralMetadataLoader = undefined;
2631
2743
  }
@@ -2644,13 +2756,13 @@ GltfLoader.prototype.isUnloaded = function () {
2644
2756
  * @private
2645
2757
  */
2646
2758
  GltfLoader.prototype.unload = function () {
2647
- if (defined(this._gltfJsonLoader)) {
2759
+ if (defined(this._gltfJsonLoader) && !this._gltfJsonLoader.isDestroyed()) {
2648
2760
  ResourceCache.unload(this._gltfJsonLoader);
2649
2761
  }
2650
2762
  this._gltfJsonLoader = undefined;
2651
2763
 
2652
2764
  unloadTextures(this);
2653
- unloadBufferViews(this);
2765
+ unloadBufferViewLoaders(this);
2654
2766
  unloadGeometry(this);
2655
2767
  unloadGeneratedAttributes(this);
2656
2768
  unloadStructuralMetadata(this);