@cesium/engine 2.1.0 → 2.3.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 (240) hide show
  1. package/Build/Workers/{AttributeCompression-8a5a065e.js → AttributeCompression-f9f6c717.js} +1 -1
  2. package/Build/Workers/{AxisAlignedBoundingBox-a6f9f0e5.js → AxisAlignedBoundingBox-31fadcf0.js} +1 -1
  3. package/Build/Workers/{BoundingRectangle-b0a68595.js → BoundingRectangle-995f0079.js} +1 -1
  4. package/Build/Workers/{BoxGeometry-baedd794.js → BoxGeometry-7eb1af60.js} +1 -1
  5. package/Build/Workers/{Color-f85df1be.js → Color-2dc49658.js} +1 -1
  6. package/Build/Workers/{CoplanarPolygonGeometryLibrary-30516950.js → CoplanarPolygonGeometryLibrary-d7d972d6.js} +1 -1
  7. package/Build/Workers/{CorridorGeometryLibrary-5d5d3b3a.js → CorridorGeometryLibrary-1f5ef7b3.js} +1 -1
  8. package/Build/Workers/{CylinderGeometry-d899ae26.js → CylinderGeometry-23c67a6c.js} +1 -1
  9. package/Build/Workers/{CylinderGeometryLibrary-135b0858.js → CylinderGeometryLibrary-7bf291b4.js} +1 -1
  10. package/Build/Workers/{EllipseGeometry-a49f8449.js → EllipseGeometry-37014da4.js} +1 -1
  11. package/Build/Workers/{EllipseGeometryLibrary-cba7edde.js → EllipseGeometryLibrary-92ab6b1e.js} +1 -1
  12. package/Build/Workers/{EllipseOutlineGeometry-8095c8cb.js → EllipseOutlineGeometry-12b6fef5.js} +1 -1
  13. package/Build/Workers/{EllipsoidGeodesic-dcff5cbd.js → EllipsoidGeodesic-5b3623dc.js} +1 -1
  14. package/Build/Workers/{EllipsoidGeometry-ed93f571.js → EllipsoidGeometry-508da15c.js} +1 -1
  15. package/Build/Workers/{EllipsoidOutlineGeometry-e4854854.js → EllipsoidOutlineGeometry-40d97455.js} +1 -1
  16. package/Build/Workers/{EllipsoidRhumbLine-b672d507.js → EllipsoidRhumbLine-ef872433.js} +1 -1
  17. package/Build/Workers/{EllipsoidTangentPlane-7ae1aa9a.js → EllipsoidTangentPlane-46d4d9c2.js} +1 -1
  18. package/Build/Workers/{EncodedCartesian3-e8bbca36.js → EncodedCartesian3-57415c8a.js} +1 -1
  19. package/Build/Workers/{FrustumGeometry-b62db3e3.js → FrustumGeometry-38605e69.js} +32 -4
  20. package/Build/Workers/{GeometryAttribute-780af4fa.js → GeometryAttribute-a466e9c7.js} +1 -1
  21. package/Build/Workers/{GeometryInstance-3fb607b7.js → GeometryInstance-34d9e21e.js} +1 -1
  22. package/Build/Workers/{GeometryPipeline-36b61c99.js → GeometryPipeline-dcf79306.js} +1 -1
  23. package/Build/Workers/{IndexDatatype-b8f3e09d.js → IndexDatatype-2643aa47.js} +1 -1
  24. package/Build/Workers/{IntersectionTests-e889fcf0.js → IntersectionTests-88c49b2e.js} +1 -1
  25. package/Build/Workers/{Math-dad82b4d.js → Math-0a2ac845.js} +12 -2
  26. package/Build/Workers/{Matrix2-1e403d0e.js → Matrix2-e1298525.js} +1 -1
  27. package/Build/Workers/{Matrix3-fa806b97.js → Matrix3-41c58dde.js} +1 -1
  28. package/Build/Workers/{OrientedBoundingBox-43478ac8.js → OrientedBoundingBox-2dd47921.js} +5 -3
  29. package/Build/Workers/{Plane-c27e1ac6.js → Plane-4c3d403b.js} +1 -1
  30. package/Build/Workers/{PolygonGeometryLibrary-38a98276.js → PolygonGeometryLibrary-59126025.js} +1 -1
  31. package/Build/Workers/PolygonPipeline-1fe328c0.js +1344 -0
  32. package/Build/Workers/{PolylinePipeline-30e4cec9.js → PolylinePipeline-896735cc.js} +1 -1
  33. package/Build/Workers/{PolylineVolumeGeometryLibrary-90551d26.js → PolylineVolumeGeometryLibrary-9c0639f7.js} +1 -1
  34. package/Build/Workers/{PrimitivePipeline-558d9cb0.js → PrimitivePipeline-fc1a47ff.js} +1 -1
  35. package/Build/Workers/{RectangleGeometryLibrary-815c68df.js → RectangleGeometryLibrary-a23c9ebe.js} +1 -1
  36. package/Build/Workers/{TerrainEncoding-341ead52.js → TerrainEncoding-51b8b33b.js} +1 -1
  37. package/Build/Workers/Transforms-bc45e707.js +14699 -0
  38. package/Build/Workers/{WallGeometryLibrary-ccf90976.js → WallGeometryLibrary-007e9883.js} +1 -1
  39. package/Build/Workers/{WebMercatorProjection-76a3fcc0.js → WebMercatorProjection-13ed1a6e.js} +1 -1
  40. package/Build/Workers/{arrayRemoveDuplicates-fac118a8.js → arrayRemoveDuplicates-d2061e85.js} +1 -1
  41. package/Build/Workers/cesiumWorkerBootstrapper.js +1 -1
  42. package/Build/Workers/combineGeometry.js +1 -1
  43. package/Build/Workers/createBoxGeometry.js +1 -1
  44. package/Build/Workers/createBoxOutlineGeometry.js +1 -1
  45. package/Build/Workers/createCircleGeometry.js +1 -1
  46. package/Build/Workers/createCircleOutlineGeometry.js +1 -1
  47. package/Build/Workers/createCoplanarPolygonGeometry.js +1 -1
  48. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +1 -1
  49. package/Build/Workers/createCorridorGeometry.js +1 -1
  50. package/Build/Workers/createCorridorOutlineGeometry.js +1 -1
  51. package/Build/Workers/createCylinderGeometry.js +1 -1
  52. package/Build/Workers/createCylinderOutlineGeometry.js +1 -1
  53. package/Build/Workers/createEllipseGeometry.js +1 -1
  54. package/Build/Workers/createEllipseOutlineGeometry.js +1 -1
  55. package/Build/Workers/createEllipsoidGeometry.js +1 -1
  56. package/Build/Workers/createEllipsoidOutlineGeometry.js +1 -1
  57. package/Build/Workers/createFrustumGeometry.js +1 -1
  58. package/Build/Workers/createFrustumOutlineGeometry.js +1 -1
  59. package/Build/Workers/createGeometry.js +1 -1
  60. package/Build/Workers/createGroundPolylineGeometry.js +1 -1
  61. package/Build/Workers/createPlaneGeometry.js +1 -1
  62. package/Build/Workers/createPlaneOutlineGeometry.js +1 -1
  63. package/Build/Workers/createPolygonGeometry.js +1 -1
  64. package/Build/Workers/createPolygonOutlineGeometry.js +1 -1
  65. package/Build/Workers/createPolylineGeometry.js +1 -1
  66. package/Build/Workers/createPolylineVolumeGeometry.js +1 -1
  67. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +1 -1
  68. package/Build/Workers/createRectangleGeometry.js +1 -1
  69. package/Build/Workers/createRectangleOutlineGeometry.js +1 -1
  70. package/Build/Workers/createSimplePolylineGeometry.js +1 -1
  71. package/Build/Workers/createSphereGeometry.js +1 -1
  72. package/Build/Workers/createSphereOutlineGeometry.js +1 -1
  73. package/Build/Workers/createVectorTileClampedPolylines.js +1 -1
  74. package/Build/Workers/createVectorTileGeometries.js +1 -1
  75. package/Build/Workers/createVectorTilePoints.js +1 -1
  76. package/Build/Workers/createVectorTilePolygons.js +1 -1
  77. package/Build/Workers/createVectorTilePolylines.js +1 -1
  78. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +1 -1
  79. package/Build/Workers/createVerticesFromHeightmap.js +5 -8
  80. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +10 -15
  81. package/Build/Workers/createWallGeometry.js +1 -1
  82. package/Build/Workers/createWallOutlineGeometry.js +1 -1
  83. package/Build/Workers/decodeDraco.js +1 -1
  84. package/Build/Workers/decodeI3S.js +1 -1
  85. package/Build/Workers/package.js +1 -1
  86. package/Build/Workers/transferTypedArrayTest.js +1 -1
  87. package/Build/Workers/upsampleQuantizedTerrainMesh.js +1 -1
  88. package/Source/Core/ArcGISTiledElevationTerrainProvider.js +291 -191
  89. package/Source/Core/BingMapsGeocoderService.js +19 -1
  90. package/Source/Core/CartographicGeocoderService.js +15 -0
  91. package/Source/Core/CesiumTerrainProvider.js +571 -434
  92. package/Source/Core/Credit.js +1 -1
  93. package/Source/Core/CustomHeightmapTerrainProvider.js +12 -0
  94. package/Source/Core/EllipsoidTerrainProvider.js +17 -10
  95. package/Source/Core/FrustumGeometry.js +4 -3
  96. package/Source/Core/GeocoderService.js +32 -1
  97. package/Source/Core/GoogleEarthEnterpriseMetadata.js +86 -34
  98. package/Source/Core/GoogleEarthEnterpriseTerrainProvider.js +119 -82
  99. package/Source/Core/Ion.js +1 -1
  100. package/Source/Core/IonGeocoderService.js +17 -2
  101. package/Source/Core/IonResource.js +14 -3
  102. package/Source/Core/OpenCageGeocoderService.js +18 -1
  103. package/Source/Core/OrientedBoundingBox.js +4 -2
  104. package/Source/Core/OrthographicFrustum.js +13 -0
  105. package/Source/Core/PeliasGeocoderService.js +14 -1
  106. package/Source/Core/PerspectiveFrustum.js +14 -0
  107. package/Source/Core/Request.js +3 -2
  108. package/Source/Core/RequestScheduler.js +10 -5
  109. package/Source/Core/Resource.js +230 -236
  110. package/Source/Core/TerrainProvider.js +9 -14
  111. package/Source/Core/TileProviderError.js +8 -8
  112. package/Source/Core/VRTheWorldTerrainProvider.js +193 -124
  113. package/Source/Core/buildModuleUrl.js +4 -3
  114. package/Source/Core/createWorldTerrain.js +20 -2
  115. package/Source/Core/createWorldTerrainAsync.js +48 -0
  116. package/Source/Core/sampleTerrain.js +9 -10
  117. package/Source/Core/sampleTerrainMostDetailed.js +66 -72
  118. package/Source/DataSources/Cesium3DTilesetVisualizer.js +37 -26
  119. package/Source/DataSources/DataSourceDisplay.js +2 -2
  120. package/Source/DataSources/Entity.js +6 -1
  121. package/Source/DataSources/EntityCluster.js +126 -128
  122. package/Source/DataSources/ModelVisualizer.js +104 -34
  123. package/Source/DataSources/PolygonGraphics.js +1 -1
  124. package/Source/Renderer/UniformState.js +3 -2
  125. package/Source/Renderer/demodernizeShader.js +5 -5
  126. package/Source/Scene/ArcGisBaseMapType.js +12 -0
  127. package/Source/Scene/ArcGisMapServerImageryProvider.js +694 -376
  128. package/Source/Scene/ArcGisMapService.js +83 -0
  129. package/Source/Scene/BingMapsImageryProvider.js +511 -305
  130. package/Source/Scene/BufferLoader.js +29 -34
  131. package/Source/Scene/Camera.js +8 -7
  132. package/Source/Scene/Cesium3DTile.js +392 -254
  133. package/Source/Scene/Cesium3DTileBatchTable.js +2 -2
  134. package/Source/Scene/Cesium3DTileContent.js +16 -0
  135. package/Source/Scene/Cesium3DTileContentFactory.js +4 -4
  136. package/Source/Scene/Cesium3DTilePass.js +8 -11
  137. package/Source/Scene/Cesium3DTileStyleEngine.js +1 -1
  138. package/Source/Scene/Cesium3DTilesVoxelProvider.js +225 -117
  139. package/Source/Scene/Cesium3DTileset.js +756 -482
  140. package/Source/Scene/Cesium3DTilesetBaseTraversal.js +301 -0
  141. package/Source/Scene/Cesium3DTilesetMostDetailedTraversal.js +33 -46
  142. package/Source/Scene/Cesium3DTilesetSkipTraversal.js +421 -0
  143. package/Source/Scene/Cesium3DTilesetTraversal.js +219 -671
  144. package/Source/Scene/ClassificationPrimitive.js +7 -0
  145. package/Source/Scene/Composite3DTileContent.js +69 -26
  146. package/Source/Scene/CreditDisplay.js +132 -20
  147. package/Source/Scene/DepthPlane.js +1 -1
  148. package/Source/Scene/Empty3DTileContent.js +31 -1
  149. package/Source/Scene/Geometry3DTileContent.js +47 -7
  150. package/Source/Scene/Globe.js +5 -1
  151. package/Source/Scene/GlobeSurfaceTile.js +2 -1
  152. package/Source/Scene/GlobeSurfaceTileProvider.js +53 -30
  153. package/Source/Scene/GltfBufferViewLoader.js +47 -91
  154. package/Source/Scene/GltfDracoLoader.js +110 -112
  155. package/Source/Scene/GltfImageLoader.js +71 -78
  156. package/Source/Scene/GltfIndexBufferLoader.js +108 -121
  157. package/Source/Scene/GltfJsonLoader.js +87 -74
  158. package/Source/Scene/GltfLoader.js +381 -300
  159. package/Source/Scene/GltfStructuralMetadataLoader.js +109 -110
  160. package/Source/Scene/GltfTextureLoader.js +97 -96
  161. package/Source/Scene/GltfVertexBufferLoader.js +128 -133
  162. package/Source/Scene/GoogleEarthEnterpriseImageryProvider.js +353 -225
  163. package/Source/Scene/GoogleEarthEnterpriseMapsProvider.js +491 -331
  164. package/Source/Scene/GridImageryProvider.js +267 -104
  165. package/Source/Scene/GroundPolylinePrimitive.js +12 -1
  166. package/Source/Scene/GroundPrimitive.js +8 -1
  167. package/Source/Scene/I3SDataProvider.js +214 -113
  168. package/Source/Scene/I3SFeature.js +7 -6
  169. package/Source/Scene/I3SLayer.js +26 -37
  170. package/Source/Scene/I3SNode.js +59 -66
  171. package/Source/Scene/Imagery.js +6 -1
  172. package/Source/Scene/ImageryLayer.js +299 -48
  173. package/Source/Scene/ImageryLayerCollection.js +26 -0
  174. package/Source/Scene/ImageryProvider.js +129 -111
  175. package/Source/Scene/Implicit3DTileContent.js +72 -23
  176. package/Source/Scene/ImplicitSubtree.js +66 -45
  177. package/Source/Scene/IonImageryProvider.js +482 -275
  178. package/Source/Scene/MapboxImageryProvider.js +272 -112
  179. package/Source/Scene/MapboxStyleImageryProvider.js +270 -111
  180. package/Source/Scene/MetadataSchemaLoader.js +26 -36
  181. package/Source/Scene/Model/B3dmLoader.js +42 -46
  182. package/Source/Scene/Model/GeoJsonLoader.js +8 -32
  183. package/Source/Scene/Model/I3dmLoader.js +48 -74
  184. package/Source/Scene/Model/MaterialPipelineStage.js +12 -12
  185. package/Source/Scene/Model/Model.js +514 -135
  186. package/Source/Scene/Model/Model3DTileContent.js +83 -31
  187. package/Source/Scene/Model/ModelAnimationCollection.js +3 -3
  188. package/Source/Scene/Model/ModelDrawCommand.js +15 -26
  189. package/Source/Scene/Model/ModelUtility.js +16 -16
  190. package/Source/Scene/Model/PntsLoader.js +27 -32
  191. package/Source/Scene/Model/UniformType.js +1 -1
  192. package/Source/Scene/Multiple3DTileContent.js +134 -115
  193. package/Source/Scene/Picking.js +3 -2
  194. package/Source/Scene/PointCloud.js +11 -19
  195. package/Source/Scene/Primitive.js +20 -0
  196. package/Source/Scene/QuadtreePrimitive.js +5 -2
  197. package/Source/Scene/QuadtreeTileProvider.js +4 -8
  198. package/Source/Scene/ResourceCache.js +47 -105
  199. package/Source/Scene/ResourceCacheStatistics.js +24 -58
  200. package/Source/Scene/ResourceLoader.js +5 -17
  201. package/Source/Scene/ResourceLoaderState.js +12 -4
  202. package/Source/Scene/Scene.js +65 -0
  203. package/Source/Scene/SceneTransforms.js +3 -2
  204. package/Source/Scene/ScreenSpaceCameraController.js +2 -2
  205. package/Source/Scene/SingleTileImageryProvider.js +382 -209
  206. package/Source/Scene/Terrain.js +196 -0
  207. package/Source/Scene/TileCoordinatesImageryProvider.js +267 -104
  208. package/Source/Scene/TileMapServiceImageryProvider.js +177 -85
  209. package/Source/Scene/Tileset3DTileContent.js +47 -5
  210. package/Source/Scene/TimeDynamicPointCloud.js +15 -2
  211. package/Source/Scene/UrlTemplateImageryProvider.js +343 -215
  212. package/Source/Scene/Vector3DTileClampedPolylines.js +96 -84
  213. package/Source/Scene/Vector3DTileContent.js +47 -22
  214. package/Source/Scene/Vector3DTileGeometry.js +57 -52
  215. package/Source/Scene/Vector3DTilePoints.js +97 -81
  216. package/Source/Scene/Vector3DTilePolygons.js +118 -117
  217. package/Source/Scene/Vector3DTilePolylines.js +86 -82
  218. package/Source/Scene/Vector3DTilePrimitive.js +0 -1
  219. package/Source/Scene/VoxelContent.js +61 -63
  220. package/Source/Scene/VoxelPrimitive.js +39 -91
  221. package/Source/Scene/VoxelProvider.js +2 -2
  222. package/Source/Scene/WebMapServiceImageryProvider.js +272 -111
  223. package/Source/Scene/WebMapTileServiceImageryProvider.js +270 -107
  224. package/Source/Scene/computeFlyToLocationForRectangle.js +33 -37
  225. package/Source/Scene/createOsmBuildings.js +6 -0
  226. package/Source/Scene/createOsmBuildingsAsync.js +82 -0
  227. package/Source/Scene/createWorldImagery.js +14 -5
  228. package/Source/Scene/createWorldImageryAsync.js +39 -0
  229. package/Source/Shaders/AtmosphereCommon.glsl +51 -8
  230. package/Source/Shaders/AtmosphereCommon.js +51 -8
  231. package/Source/Shaders/PostProcessStages/AmbientOcclusionGenerate.glsl +1 -1
  232. package/Source/Shaders/PostProcessStages/AmbientOcclusionGenerate.js +1 -1
  233. package/Source/Shaders/PostProcessStages/AmbientOcclusionModulate.glsl +3 -3
  234. package/Source/Shaders/PostProcessStages/AmbientOcclusionModulate.js +3 -3
  235. package/Source/Widget/CesiumWidget.js +67 -27
  236. package/index.d.ts +2429 -1475
  237. package/index.js +324 -315
  238. package/package.json +4 -4
  239. package/Build/Workers/PolygonPipeline-d31ff61c.js +0 -1345
  240. package/Build/Workers/Transforms-9e9df299.js +0 -14714
@@ -18,7 +18,6 @@ import getAccessorByteStride from "./GltfPipeline/getAccessorByteStride.js";
18
18
  import getComponentReader from "./GltfPipeline/getComponentReader.js";
19
19
  import numberOfComponentsForType from "./GltfPipeline/numberOfComponentsForType.js";
20
20
  import GltfStructuralMetadataLoader from "./GltfStructuralMetadataLoader.js";
21
- import ModelUtility from "./Model/ModelUtility.js";
22
21
  import AttributeType from "./AttributeType.js";
23
22
  import Axis from "./Axis.js";
24
23
  import GltfLoaderUtil from "./GltfLoaderUtil.js";
@@ -89,6 +88,8 @@ const GltfLoaderState = {
89
88
  *
90
89
  * @type {number}
91
90
  * @constant
91
+ *
92
+ * @private
92
93
  */
93
94
  LOADED: 2,
94
95
  /**
@@ -97,6 +98,8 @@ const GltfLoaderState = {
97
98
  *
98
99
  * @type {number}
99
100
  * @constant
101
+ *
102
+ * @private
100
103
  */
101
104
  PROCESSING: 3,
102
105
  /**
@@ -109,6 +112,8 @@ const GltfLoaderState = {
109
112
  *
110
113
  * @type {number}
111
114
  * @constant
115
+ *
116
+ * @private
112
117
  */
113
118
  POST_PROCESSING: 4,
114
119
  /**
@@ -118,6 +123,8 @@ const GltfLoaderState = {
118
123
  *
119
124
  * @type {number}
120
125
  * @constant
126
+ *
127
+ * @private
121
128
  */
122
129
  PROCESSED: 5,
123
130
  /**
@@ -126,6 +133,8 @@ const GltfLoaderState = {
126
133
  *
127
134
  * @type {number}
128
135
  * @constant
136
+ *
137
+ * @private
129
138
  */
130
139
  READY: 6,
131
140
  /**
@@ -133,6 +142,8 @@ const GltfLoaderState = {
133
142
  *
134
143
  * @type {number}
135
144
  * @constant
145
+ *
146
+ * @private
136
147
  */
137
148
  FAILED: 7,
138
149
  /**
@@ -140,6 +151,8 @@ const GltfLoaderState = {
140
151
  *
141
152
  * @type {number}
142
153
  * @constant
154
+ *
155
+ * @private
143
156
  */
144
157
  UNLOADED: 8,
145
158
  };
@@ -226,12 +239,6 @@ function GltfLoader(options) {
226
239
  this._loadForClassification = loadForClassification;
227
240
  this._renameBatchIdSemantic = renameBatchIdSemantic;
228
241
 
229
- // This flag will be set in parse() if the KHR_mesh_quantization extension is
230
- // present in extensionsRequired. This flag is used later when parsing
231
- // attributes. When the extension is present, attributes may be stored as
232
- // quantized integer values instead of floats.
233
- this._hasKhrMeshQuantization = false;
234
-
235
242
  // When loading EXT_feature_metadata, the feature tables and textures
236
243
  // are now stored as arrays like the newer EXT_structural_metadata extension.
237
244
  // This requires sorting the dictionary keys for a consistent ordering.
@@ -242,9 +249,8 @@ function GltfLoader(options) {
242
249
  this._state = GltfLoaderState.NOT_LOADED;
243
250
  this._textureState = GltfLoaderState.NOT_LOADED;
244
251
  this._promise = undefined;
245
- this._texturesLoadedPromise = undefined;
246
- this._process = function (loader, frameState) {};
247
- this._processTextures = function (loader, frameState) {};
252
+ this._processError = undefined;
253
+ this._textureErrors = [];
248
254
 
249
255
  // Information about whether to load primitives as typed arrays or buffers,
250
256
  // and whether post-processing is needed after loading (e.g. for
@@ -255,9 +261,14 @@ function GltfLoader(options) {
255
261
  this._loaderPromises = [];
256
262
  this._textureLoaders = [];
257
263
  this._texturesPromises = [];
264
+ this._textureCallbacks = [];
258
265
  this._bufferViewLoaders = [];
259
266
  this._geometryLoaders = [];
267
+ this._geometryCallbacks = [];
260
268
  this._structuralMetadataLoader = undefined;
269
+ this._loadResourcesPromise = undefined;
270
+ this._resourcesLoaded = false;
271
+ this._texturesLoaded = false;
261
272
 
262
273
  // In some cases where geometry post-processing is needed (like generating
263
274
  // outlines) new attributes are added that may have GPU resources attached.
@@ -275,231 +286,203 @@ if (defined(Object.create)) {
275
286
 
276
287
  Object.defineProperties(GltfLoader.prototype, {
277
288
  /**
278
- * A promise that resolves to the resource when the resource is ready, or undefined if the resource hasn't started loading.
289
+ * The cache key of the resource.
279
290
  *
280
291
  * @memberof GltfLoader.prototype
281
292
  *
282
- * @type {Promise<GltfLoader>|undefined}
293
+ * @type {string}
283
294
  * @readonly
284
295
  * @private
285
296
  */
286
- promise: {
297
+ cacheKey: {
287
298
  get: function () {
288
- return this._promise;
299
+ return undefined;
289
300
  },
290
301
  },
291
302
  /**
292
- * The cache key of the resource.
303
+ * The loaded components.
293
304
  *
294
305
  * @memberof GltfLoader.prototype
295
306
  *
296
- * @type {string}
307
+ * @type {ModelComponents.Components}
297
308
  * @readonly
298
309
  * @private
299
310
  */
300
- cacheKey: {
311
+ components: {
301
312
  get: function () {
302
- return undefined;
313
+ return this._components;
303
314
  },
304
315
  },
305
316
  /**
306
- * The loaded components.
317
+ * The loaded glTF json.
307
318
  *
308
319
  * @memberof GltfLoader.prototype
309
320
  *
310
- * @type {ModelComponents.Components}
321
+ * @type {object}
311
322
  * @readonly
312
323
  * @private
313
324
  */
314
- components: {
325
+ gltfJson: {
315
326
  get: function () {
316
- return this._components;
327
+ if (defined(this._gltfJsonLoader)) {
328
+ return this._gltfJsonLoader.gltf;
329
+ }
330
+ return this._gltfJson;
317
331
  },
318
332
  },
319
-
320
333
  /**
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.
334
+ * Returns true if textures are loaded separately from the other glTF resources.
324
335
  *
325
336
  * @memberof GltfLoader.prototype
326
337
  *
327
- * @type {Promise<void>}
338
+ * @type {boolean}
328
339
  * @readonly
329
340
  * @private
330
341
  */
331
- texturesLoadedPromise: {
342
+ incrementallyLoadTextures: {
332
343
  get: function () {
333
- return this._texturesLoadedPromise;
344
+ return this._incrementallyLoadTextures;
345
+ },
346
+ },
347
+ /**
348
+ * true if textures are loaded, useful when incrementallyLoadTextures is true
349
+ *
350
+ * @memberof GltfLoader.prototype
351
+ *
352
+ * @type {boolean}
353
+ * @readonly
354
+ * @private
355
+ */
356
+ texturesLoaded: {
357
+ get: function () {
358
+ return this._texturesLoaded;
334
359
  },
335
360
  },
336
361
  });
337
362
 
338
363
  /**
339
- * Loads the resource.
340
- * @returns {Promise<GltfLoader>} A promise which resolves to the loader when the resource loading is completed.
341
- * @private
364
+ * Loads the gltf object
342
365
  */
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;
366
+ async function loadGltfJson(loader) {
367
+ loader._state = GltfLoaderState.LOADING;
368
+ loader._textureState = GltfLoaderState.LOADING;
369
+
370
+ try {
371
+ const gltfJsonLoader = ResourceCache.getGltfJsonLoader({
372
+ gltfResource: loader._gltfResource,
373
+ baseResource: loader._baseResource,
374
+ typedArray: loader._typedArray,
375
+ gltfJson: loader._gltfJson,
376
+ });
377
+ loader._gltfJsonLoader = gltfJsonLoader;
378
+ await gltfJsonLoader.load();
354
379
 
355
- const that = this;
356
- let textureProcessPromise;
357
- const processPromise = new Promise(function (resolve, reject) {
358
- textureProcessPromise = new Promise(function (
359
- resolveTextures,
360
- rejectTextures
380
+ if (
381
+ loader.isDestroyed() ||
382
+ loader.isUnloaded() ||
383
+ gltfJsonLoader.isDestroyed()
361
384
  ) {
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
- }
406
-
407
- if (loader._state === GltfLoaderState.PROCESSING) {
408
- processLoaders(loader, frameState);
409
- }
410
-
411
- if (loader._state === GltfLoaderState.POST_PROCESSING) {
412
- postProcessGeometry(loader, frameState.context);
413
- loader._state = GltfLoaderState.PROCESSED;
414
- }
415
-
416
- if (loader._state === GltfLoaderState.PROCESSED) {
417
- // The buffer views can be unloaded once the data is copied.
418
- unloadBufferViews(loader);
385
+ return;
386
+ }
419
387
 
420
- // Similarly, if the glTF was loaded from a typed array, release the memory
421
- loader._typedArray = undefined;
388
+ loader._state = GltfLoaderState.LOADED;
389
+ loader._textureState = GltfLoaderState.LOADED;
422
390
 
423
- loader._state = GltfLoaderState.READY;
424
- resolve(loader);
425
- }
426
- };
391
+ return loader;
392
+ } catch (error) {
393
+ if (loader.isDestroyed()) {
394
+ return;
395
+ }
427
396
 
428
- that._processTextures = function (loader, frameState) {
429
- if (loader._textureState === GltfLoaderState.LOADED) {
430
- loader._textureState = GltfLoaderState.PROCESSING;
431
- }
397
+ loader._state = GltfLoaderState.FAILED;
398
+ loader._textureState = GltfLoaderState.FAILED;
399
+ handleError(loader, error);
400
+ }
401
+ }
432
402
 
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
- }
403
+ async function loadResources(loader, frameState) {
404
+ if (!FeatureDetection.supportsWebP.initialized) {
405
+ await FeatureDetection.supportsWebP.initialize();
406
+ }
441
407
 
442
- if (loader._textureState === GltfLoaderState.PROCESSED) {
443
- loader._textureState = GltfLoaderState.READY;
444
- resolveTextures(loader);
445
- }
446
- };
447
- });
408
+ const supportedImageFormats = new SupportedImageFormats({
409
+ webp: FeatureDetection.supportsWebP(),
410
+ basis: frameState.context.supportsBasis,
448
411
  });
449
412
 
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;
413
+ // Parse the glTF which populates the loaders arrays. Loading promises will be created, and will
414
+ // resolve once the loaders are ready (i.e. all external resources
415
+ // have been fetched and all GPU resources have been created). Loaders that
416
+ // create GPU resources need to be processed every frame until they become
417
+ // ready since the JobScheduler is not able to execute all jobs in a single
418
+ // 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
419
+ // to process or after it has failed; nothing will happen.
420
+ const gltf = loader.gltfJson;
421
+ const promise = parse(loader, gltf, supportedImageFormats, frameState);
457
422
 
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
- });
423
+ // All resource loaders have been created, so we can begin processing
424
+ loader._state = GltfLoaderState.PROCESSING;
425
+ loader._textureState = GltfLoaderState.PROCESSING;
468
426
 
469
- this._texturesLoadedPromise = textureProcessPromise.catch(function (error) {
470
- if (that.isDestroyed()) {
471
- return;
472
- }
427
+ if (defined(loader._gltfJsonLoader) && loader._releaseGltfJson) {
428
+ // Check that the glTF JSON loader is still defined before trying to unload it.
429
+ // It can be unloaded if the glTF loader is destroyed.
430
+ ResourceCache.unload(loader._gltfJsonLoader);
431
+ loader._gltfJsonLoader = undefined;
432
+ }
473
433
 
474
- that._textureState = GltfLoaderState.FAILED;
475
- return handleError(that, error);
476
- });
434
+ return promise;
435
+ }
477
436
 
437
+ /**
438
+ * Loads the resource.
439
+ * @returns {Promise.<GltfLoader>} A promise which resolves to the loader when the resource loading is completed.
440
+ * @exception {RuntimeError} Unsupported glTF version
441
+ * @exception {RuntimeError} Unsupported glTF Extension
442
+ * @private
443
+ */
444
+ GltfLoader.prototype.load = async function () {
445
+ if (defined(this._promise)) {
446
+ return this._promise;
447
+ }
448
+
449
+ this._promise = loadGltfJson(this);
478
450
  return this._promise;
479
451
  };
480
452
 
481
453
  function handleError(gltfLoader, error) {
482
454
  gltfLoader.unload();
483
455
  const errorMessage = "Failed to load glTF";
484
- error = gltfLoader.getError(errorMessage, error);
485
- return Promise.reject(error);
456
+ throw gltfLoader.getError(errorMessage, error);
486
457
  }
487
458
 
488
459
  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
-
460
+ let i;
461
+ let ready = true;
495
462
  const geometryLoaders = loader._geometryLoaders;
496
463
  const geometryLoadersLength = geometryLoaders.length;
497
- for (let i = 0; i < geometryLoadersLength; ++i) {
498
- geometryLoaders[i].process(frameState);
464
+ for (i = 0; i < geometryLoadersLength; ++i) {
465
+ const geometryReady = geometryLoaders[i].process(frameState);
466
+ if (geometryReady && defined(loader._geometryCallbacks[i])) {
467
+ loader._geometryCallbacks[i]();
468
+ loader._geometryCallbacks[i] = undefined;
469
+ }
470
+ ready = ready && geometryReady;
499
471
  }
500
472
 
501
- if (defined(loader._structuralMetadataLoader)) {
502
- loader._structuralMetadataLoader.process(frameState);
473
+ const structuralMetadataLoader = loader._structuralMetadataLoader;
474
+ if (defined(structuralMetadataLoader)) {
475
+ const metadataReady = structuralMetadataLoader.process(frameState);
476
+ if (metadataReady) {
477
+ loader._components.structuralMetadata =
478
+ structuralMetadataLoader.structuralMetadata;
479
+ }
480
+ ready = ready && metadataReady;
481
+ }
482
+
483
+ if (ready) {
484
+ // Geometry requires further processing
485
+ loader._state = GltfLoaderState.POST_PROCESSING;
503
486
  }
504
487
  }
505
488
 
@@ -549,6 +532,77 @@ function gatherPostProcessBuffers(loader, primitiveLoadPlan) {
549
532
  }
550
533
  }
551
534
 
535
+ /**
536
+ * Process loaders other than textures
537
+ * @private
538
+ */
539
+ GltfLoader.prototype._process = function (frameState) {
540
+ if (this._state === GltfLoaderState.READY) {
541
+ return true;
542
+ }
543
+
544
+ if (this._state === GltfLoaderState.PROCESSING) {
545
+ processLoaders(this, frameState);
546
+ }
547
+
548
+ if (
549
+ this._resourcesLoaded &&
550
+ this._state === GltfLoaderState.POST_PROCESSING
551
+ ) {
552
+ postProcessGeometry(this, frameState.context);
553
+ this._state = GltfLoaderState.PROCESSED;
554
+ }
555
+
556
+ if (this._resourcesLoaded && this._state === GltfLoaderState.PROCESSED) {
557
+ // The buffer views can be unloaded once the data is copied.
558
+ unloadBufferViewLoaders(this);
559
+
560
+ // Similarly, if the glTF was loaded from a typed array, release the memory
561
+ this._typedArray = undefined;
562
+
563
+ this._state = GltfLoaderState.READY;
564
+ return true;
565
+ }
566
+
567
+ return false;
568
+ };
569
+
570
+ /**
571
+ * Process textures other than textures
572
+ * @private
573
+ */
574
+ GltfLoader.prototype._processTextures = function (frameState) {
575
+ if (this._textureState === GltfLoaderState.READY) {
576
+ return true;
577
+ }
578
+
579
+ if (this._textureState !== GltfLoaderState.PROCESSING) {
580
+ return false;
581
+ }
582
+
583
+ let i;
584
+ let ready = true;
585
+ const textureLoaders = this._textureLoaders;
586
+ const textureLoadersLength = textureLoaders.length;
587
+ for (i = 0; i < textureLoadersLength; ++i) {
588
+ const textureReady = textureLoaders[i].process(frameState);
589
+ if (textureReady && defined(this._textureCallbacks[i])) {
590
+ this._textureCallbacks[i]();
591
+ this._textureCallbacks[i] = undefined;
592
+ }
593
+
594
+ ready = ready && textureReady;
595
+ }
596
+
597
+ if (!ready) {
598
+ return false;
599
+ }
600
+
601
+ this._textureState = GltfLoaderState.READY;
602
+ this._texturesLoaded = true;
603
+ return true;
604
+ };
605
+
552
606
  /**
553
607
  * Processes the resource until it becomes ready.
554
608
  *
@@ -560,12 +614,64 @@ GltfLoader.prototype.process = function (frameState) {
560
614
  Check.typeOf.object("frameState", frameState);
561
615
  //>>includeEnd('debug');
562
616
 
563
- this._process(this, frameState);
617
+ if (
618
+ this._state === GltfLoaderState.LOADED &&
619
+ !defined(this._loadResourcesPromise)
620
+ ) {
621
+ this._loadResourcesPromise = loadResources(this, frameState)
622
+ .then(() => {
623
+ this._resourcesLoaded = true;
624
+ })
625
+ .catch((error) => {
626
+ this._processError = error;
627
+ });
628
+ }
629
+
630
+ if (defined(this._processError)) {
631
+ this._state = GltfLoaderState.FAILED;
632
+ const error = this._processError;
633
+ this._processError = undefined;
634
+ handleError(this, error);
635
+ }
636
+
637
+ // Pop the next error of the list in case there are multiple
638
+ const textureError = this._textureErrors.pop();
639
+ if (defined(textureError)) {
640
+ // There shouldn't be the need to completely unload in this case. Just throw the error.
641
+ const error = this.getError("Failed to load glTF texture", textureError);
642
+ error.name = "TextureError";
643
+ throw error;
644
+ }
645
+
646
+ if (this._state === GltfLoaderState.FAILED) {
647
+ return false;
648
+ }
649
+
650
+ let ready = false;
651
+ try {
652
+ ready = this._process(frameState);
653
+ } catch (error) {
654
+ this._state = GltfLoaderState.FAILED;
655
+ handleError(this, error);
656
+ }
657
+
564
658
  // 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);
659
+ let texturesReady = false;
660
+ try {
661
+ texturesReady = this._processTextures(frameState);
662
+ } catch (error) {
663
+ this._textureState = GltfLoaderState.FAILED;
664
+ handleError(this, error);
665
+ }
666
+
667
+ if (this._incrementallyLoadTextures) {
668
+ return ready;
669
+ }
670
+
671
+ return ready && texturesReady;
566
672
  };
567
673
 
568
- function loadVertexBuffer(
674
+ function getVertexBufferLoader(
569
675
  loader,
570
676
  gltf,
571
677
  accessorId,
@@ -578,7 +684,7 @@ function loadVertexBuffer(
578
684
  const accessor = gltf.accessors[accessorId];
579
685
  const bufferViewId = accessor.bufferView;
580
686
 
581
- const vertexBufferLoader = ResourceCache.loadVertexBuffer({
687
+ const vertexBufferLoader = ResourceCache.getVertexBufferLoader({
582
688
  gltf: gltf,
583
689
  gltfResource: loader._gltfResource,
584
690
  baseResource: loader._baseResource,
@@ -592,12 +698,10 @@ function loadVertexBuffer(
592
698
  loadTypedArray: loadTypedArray,
593
699
  });
594
700
 
595
- loader._geometryLoaders.push(vertexBufferLoader);
596
-
597
701
  return vertexBufferLoader;
598
702
  }
599
703
 
600
- function loadIndexBuffer(
704
+ function getIndexBufferLoader(
601
705
  loader,
602
706
  gltf,
603
707
  accessorId,
@@ -606,7 +710,7 @@ function loadIndexBuffer(
606
710
  loadTypedArray,
607
711
  frameState
608
712
  ) {
609
- const indexBufferLoader = ResourceCache.loadIndexBuffer({
713
+ const indexBufferLoader = ResourceCache.getIndexBufferLoader({
610
714
  gltf: gltf,
611
715
  accessorId: accessorId,
612
716
  gltfResource: loader._gltfResource,
@@ -618,13 +722,11 @@ function loadIndexBuffer(
618
722
  loadTypedArray: loadTypedArray,
619
723
  });
620
724
 
621
- loader._geometryLoaders.push(indexBufferLoader);
622
-
623
725
  return indexBufferLoader;
624
726
  }
625
727
 
626
- function loadBufferView(loader, gltf, bufferViewId) {
627
- const bufferViewLoader = ResourceCache.loadBufferView({
728
+ function getBufferViewLoader(loader, gltf, bufferViewId) {
729
+ const bufferViewLoader = ResourceCache.getBufferViewLoader({
628
730
  gltf: gltf,
629
731
  bufferViewId: bufferViewId,
630
732
  gltfResource: loader._gltfResource,
@@ -720,6 +822,26 @@ function loadAccessorValues(accessor, typedArray, values, useQuaternion) {
720
822
  return values;
721
823
  }
722
824
 
825
+ async function loadAccessorBufferView(
826
+ loader,
827
+ bufferViewLoader,
828
+ gltf,
829
+ accessor,
830
+ useQuaternion,
831
+ values
832
+ ) {
833
+ await bufferViewLoader.load();
834
+ if (loader.isDestroyed()) {
835
+ return;
836
+ }
837
+
838
+ const bufferViewTypedArray = bufferViewLoader.typedArray;
839
+ const typedArray = getPackedTypedArray(gltf, accessor, bufferViewTypedArray);
840
+
841
+ useQuaternion = defaultValue(useQuaternion, false);
842
+ loadAccessorValues(accessor, typedArray, values, useQuaternion);
843
+ }
844
+
723
845
  function loadAccessor(loader, gltf, accessorId, useQuaternion) {
724
846
  const accessor = gltf.accessors[accessorId];
725
847
  const accessorCount = accessor.count;
@@ -727,21 +849,15 @@ function loadAccessor(loader, gltf, accessorId, useQuaternion) {
727
849
 
728
850
  const bufferViewId = accessor.bufferView;
729
851
  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
- });
852
+ const bufferViewLoader = getBufferViewLoader(loader, gltf, bufferViewId);
853
+ const promise = loadAccessorBufferView(
854
+ loader,
855
+ bufferViewLoader,
856
+ gltf,
857
+ accessor,
858
+ useQuaternion,
859
+ values
860
+ );
745
861
  loader._loaderPromises.push(promise);
746
862
 
747
863
  return values;
@@ -871,14 +987,7 @@ function setQuantizationFromWeb3dQuantizedAttributes(
871
987
  attribute.quantization = quantization;
872
988
  }
873
989
 
874
- function createAttribute(
875
- gltf,
876
- accessorId,
877
- name,
878
- semantic,
879
- setIndex,
880
- hasKhrMeshQuantization
881
- ) {
990
+ function createAttribute(gltf, accessorId, name, semantic, setIndex) {
882
991
  const accessor = gltf.accessors[accessorId];
883
992
  const MathType = AttributeType.getMathType(accessor.type);
884
993
  const normalized = defaultValue(accessor.normalized, false);
@@ -914,6 +1023,10 @@ function createAttribute(
914
1023
  // In the glTF 2.0 spec, min and max are not affected by the normalized flag.
915
1024
  // However, for KHR_mesh_quantization, min and max must be dequantized for
916
1025
  // normalized values, else the bounding sphere will be computed incorrectly.
1026
+ const hasKhrMeshQuantization = gltf.extensionsRequired?.includes(
1027
+ "KHR_mesh_quantization"
1028
+ );
1029
+
917
1030
  if (hasKhrMeshQuantization && normalized && isQuantizable) {
918
1031
  dequantizeMinMax(attribute, MathType);
919
1032
  }
@@ -1054,15 +1167,14 @@ function loadAttribute(
1054
1167
  accessorId,
1055
1168
  name,
1056
1169
  modelSemantic,
1057
- setIndex,
1058
- loader._hasKhrMeshQuantization
1170
+ setIndex
1059
1171
  );
1060
1172
 
1061
1173
  if (!defined(draco) && !defined(bufferViewId)) {
1062
1174
  return attribute;
1063
1175
  }
1064
1176
 
1065
- const vertexBufferLoader = loadVertexBuffer(
1177
+ const vertexBufferLoader = getVertexBufferLoader(
1066
1178
  loader,
1067
1179
  gltf,
1068
1180
  accessorId,
@@ -1072,13 +1184,15 @@ function loadAttribute(
1072
1184
  loadTypedArray,
1073
1185
  frameState
1074
1186
  );
1075
- const promise = vertexBufferLoader.promise.then(function (
1076
- vertexBufferLoader
1077
- ) {
1078
- if (loader.isDestroyed()) {
1079
- return;
1080
- }
1081
1187
 
1188
+ const index = loader._geometryLoaders.length;
1189
+ loader._geometryLoaders.push(vertexBufferLoader);
1190
+ const promise = vertexBufferLoader.load();
1191
+ loader._loaderPromises.push(promise);
1192
+ // This can only execute once vertexBufferLoader.process() has run and returns true
1193
+ // Save this finish callback by the loader index so it can be called
1194
+ // in process().
1195
+ loader._geometryCallbacks[index] = () => {
1082
1196
  if (
1083
1197
  defined(draco) &&
1084
1198
  defined(draco.attributes) &&
@@ -1100,9 +1214,7 @@ function loadAttribute(
1100
1214
  loadTypedArray
1101
1215
  );
1102
1216
  }
1103
- });
1104
-
1105
- loader._loaderPromises.push(promise);
1217
+ };
1106
1218
 
1107
1219
  return attribute;
1108
1220
  }
@@ -1276,7 +1388,7 @@ function loadIndices(
1276
1388
  const loadBuffer = needsPostProcessing ? false : outputBuffer;
1277
1389
  const loadTypedArray = needsPostProcessing ? true : outputTypedArray;
1278
1390
 
1279
- const indexBufferLoader = loadIndexBuffer(
1391
+ const indexBufferLoader = getIndexBufferLoader(
1280
1392
  loader,
1281
1393
  gltf,
1282
1394
  accessorId,
@@ -1286,18 +1398,18 @@ function loadIndices(
1286
1398
  frameState
1287
1399
  );
1288
1400
 
1289
- const promise = indexBufferLoader.promise.then(function (indexBufferLoader) {
1290
- if (loader.isDestroyed()) {
1291
- return;
1292
- }
1293
-
1401
+ const index = loader._geometryLoaders.length;
1402
+ loader._geometryLoaders.push(indexBufferLoader);
1403
+ const promise = indexBufferLoader.load();
1404
+ loader._loaderPromises.push(promise);
1405
+ // This can only execute once indexBufferLoader.process() has run and returns true
1406
+ // Save this finish callback by the loader index so it can be called
1407
+ // in process().
1408
+ loader._geometryCallbacks[index] = () => {
1294
1409
  indices.indexDatatype = indexBufferLoader.indexDatatype;
1295
-
1296
1410
  indices.buffer = indexBufferLoader.buffer;
1297
1411
  indices.typedArray = indexBufferLoader.typedArray;
1298
- });
1299
-
1300
- loader._loaderPromises.push(promise);
1412
+ };
1301
1413
 
1302
1414
  const indicesPlan = new PrimitiveLoadPlan.IndicesLoadPlan(indices);
1303
1415
  indicesPlan.loadBuffer = outputBuffer;
@@ -1324,7 +1436,7 @@ function loadTexture(
1324
1436
  return undefined;
1325
1437
  }
1326
1438
 
1327
- const textureLoader = ResourceCache.loadTexture({
1439
+ const textureLoader = ResourceCache.getTextureLoader({
1328
1440
  gltf: gltf,
1329
1441
  textureInfo: textureInfo,
1330
1442
  gltfResource: loader._gltfResource,
@@ -1334,23 +1446,37 @@ function loadTexture(
1334
1446
  asynchronous: loader._asynchronous,
1335
1447
  });
1336
1448
 
1337
- loader._textureLoaders.push(textureLoader);
1338
-
1339
1449
  const textureReader = GltfLoaderUtil.createModelTextureReader({
1340
1450
  textureInfo: textureInfo,
1341
1451
  });
1342
1452
 
1343
- const promise = textureLoader.promise.then(function (textureLoader) {
1344
- if (loader.isUnloaded() || loader.isDestroyed()) {
1453
+ const index = loader._textureLoaders.length;
1454
+ loader._textureLoaders.push(textureLoader);
1455
+ const promise = textureLoader.load().catch((error) => {
1456
+ if (loader.isDestroyed()) {
1345
1457
  return;
1346
1458
  }
1459
+
1460
+ if (!loader._incrementallyLoadTextures) {
1461
+ // If incrementallyLoadTextures is false, throw the error to ensure the loader state
1462
+ // immediately is set to have failed
1463
+ throw error;
1464
+ }
1465
+
1466
+ // Otherwise, save the error so it can be thrown next
1467
+ loader._textureState = GltfLoaderState.FAILED;
1468
+ loader._textureErrors.push(error);
1469
+ });
1470
+ loader._texturesPromises.push(promise);
1471
+ // This can only execute once textureLoader.process() has run and returns true
1472
+ // Save this finish callback by the loader index so it can be called
1473
+ // in process().
1474
+ loader._textureCallbacks[index] = () => {
1347
1475
  textureReader.texture = textureLoader.texture;
1348
1476
  if (defined(samplerOverride)) {
1349
1477
  textureReader.texture.sampler = samplerOverride;
1350
1478
  }
1351
- });
1352
-
1353
- loader._texturesPromises.push(promise);
1479
+ };
1354
1480
 
1355
1481
  return textureReader;
1356
1482
  }
@@ -2246,7 +2372,7 @@ function loadSkins(loader, gltf, nodes) {
2246
2372
  return skins;
2247
2373
  }
2248
2374
 
2249
- function loadStructuralMetadata(
2375
+ async function loadStructuralMetadata(
2250
2376
  loader,
2251
2377
  gltf,
2252
2378
  extension,
@@ -2264,11 +2390,8 @@ function loadStructuralMetadata(
2264
2390
  frameState: frameState,
2265
2391
  asynchronous: loader._asynchronous,
2266
2392
  });
2267
- structuralMetadataLoader.load();
2268
-
2269
2393
  loader._structuralMetadataLoader = structuralMetadataLoader;
2270
-
2271
- return structuralMetadataLoader;
2394
+ return structuralMetadataLoader.load();
2272
2395
  }
2273
2396
 
2274
2397
  function loadAnimationSampler(loader, gltf, gltfSampler) {
@@ -2442,32 +2565,7 @@ function loadScene(gltf, nodes) {
2442
2565
 
2443
2566
  const scratchCenter = new Cartesian3();
2444
2567
 
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
-
2568
+ function parse(loader, gltf, supportedImageFormats, frameState) {
2471
2569
  const extensions = defaultValue(gltf.extensions, defaultValue.EMPTY_OBJECT);
2472
2570
  const structuralMetadataExtension = extensions.EXT_structural_metadata;
2473
2571
  const featureMetadataExtensionLegacy = extensions.EXT_feature_metadata;
@@ -2535,7 +2633,7 @@ function parse(
2535
2633
  defined(structuralMetadataExtension) ||
2536
2634
  defined(featureMetadataExtensionLegacy)
2537
2635
  ) {
2538
- const structuralMetadataLoader = loadStructuralMetadata(
2636
+ const promise = loadStructuralMetadata(
2539
2637
  loader,
2540
2638
  gltf,
2541
2639
  structuralMetadataExtension,
@@ -2543,62 +2641,40 @@ function parse(
2543
2641
  supportedImageFormats,
2544
2642
  frameState
2545
2643
  );
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
2644
  loader._loaderPromises.push(promise);
2556
2645
  }
2557
2646
 
2558
- // Gather promises and reject if any promises fail.
2647
+ // Gather promises and handle any errors
2559
2648
  const readyPromises = [];
2560
2649
  readyPromises.push.apply(readyPromises, loader._loaderPromises);
2561
2650
 
2651
+ // When incrementallyLoadTextures is true, the errors are caught and thrown individually
2652
+ // since it doesn't affect the overall loader state
2562
2653
  if (!loader._incrementallyLoadTextures) {
2563
2654
  readyPromises.push.apply(readyPromises, loader._texturesPromises);
2564
2655
  }
2565
2656
 
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);
2657
+ return Promise.all(readyPromises);
2586
2658
  }
2587
2659
 
2588
2660
  function unloadTextures(loader) {
2589
2661
  const textureLoaders = loader._textureLoaders;
2590
2662
  const textureLoadersLength = textureLoaders.length;
2591
2663
  for (let i = 0; i < textureLoadersLength; ++i) {
2592
- ResourceCache.unload(textureLoaders[i]);
2664
+ textureLoaders[i] =
2665
+ !textureLoaders[i].isDestroyed() &&
2666
+ ResourceCache.unload(textureLoaders[i]);
2593
2667
  }
2594
2668
  loader._textureLoaders.length = 0;
2595
2669
  }
2596
2670
 
2597
- function unloadBufferViews(loader) {
2671
+ function unloadBufferViewLoaders(loader) {
2598
2672
  const bufferViewLoaders = loader._bufferViewLoaders;
2599
2673
  const bufferViewLoadersLength = bufferViewLoaders.length;
2600
2674
  for (let i = 0; i < bufferViewLoadersLength; ++i) {
2601
- ResourceCache.unload(bufferViewLoaders[i]);
2675
+ bufferViewLoaders[i] =
2676
+ !bufferViewLoaders[i].isDestroyed() &&
2677
+ ResourceCache.unload(bufferViewLoaders[i]);
2602
2678
  }
2603
2679
  loader._bufferViewLoaders.length = 0;
2604
2680
  }
@@ -2607,7 +2683,9 @@ function unloadGeometry(loader) {
2607
2683
  const geometryLoaders = loader._geometryLoaders;
2608
2684
  const geometryLoadersLength = geometryLoaders.length;
2609
2685
  for (let i = 0; i < geometryLoadersLength; ++i) {
2610
- ResourceCache.unload(geometryLoaders[i]);
2686
+ geometryLoaders[i] =
2687
+ !geometryLoaders[i].isDestroyed() &&
2688
+ ResourceCache.unload(geometryLoaders[i]);
2611
2689
  }
2612
2690
  loader._geometryLoaders.length = 0;
2613
2691
  }
@@ -2625,7 +2703,10 @@ function unloadGeneratedAttributes(loader) {
2625
2703
  }
2626
2704
 
2627
2705
  function unloadStructuralMetadata(loader) {
2628
- if (defined(loader._structuralMetadataLoader)) {
2706
+ if (
2707
+ defined(loader._structuralMetadataLoader) &&
2708
+ !loader._structuralMetadataLoader.isDestroyed()
2709
+ ) {
2629
2710
  loader._structuralMetadataLoader.destroy();
2630
2711
  loader._structuralMetadataLoader = undefined;
2631
2712
  }
@@ -2644,13 +2725,13 @@ GltfLoader.prototype.isUnloaded = function () {
2644
2725
  * @private
2645
2726
  */
2646
2727
  GltfLoader.prototype.unload = function () {
2647
- if (defined(this._gltfJsonLoader)) {
2728
+ if (defined(this._gltfJsonLoader) && !this._gltfJsonLoader.isDestroyed()) {
2648
2729
  ResourceCache.unload(this._gltfJsonLoader);
2649
2730
  }
2650
2731
  this._gltfJsonLoader = undefined;
2651
2732
 
2652
2733
  unloadTextures(this);
2653
- unloadBufferViews(this);
2734
+ unloadBufferViewLoaders(this);
2654
2735
  unloadGeometry(this);
2655
2736
  unloadGeneratedAttributes(this);
2656
2737
  unloadStructuralMetadata(this);