@cesium/engine 9.1.0 → 10.0.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 (255) hide show
  1. package/Build/ThirdParty/Workers/pako_deflate.min.js +108 -210
  2. package/Build/ThirdParty/Workers/pako_inflate.min.js +466 -568
  3. package/Build/ThirdParty/Workers/z-worker-pako.js +54 -104
  4. package/Build/Workers/{chunk-TMMOULW3.js → chunk-2J3JKXCP.js} +5 -5
  5. package/Build/Workers/{chunk-ZDP32RQI.js → chunk-3WUV74WM.js} +95 -155
  6. package/Build/Workers/{chunk-FOZQIHZK.js → chunk-4BAE4PWO.js} +6 -6
  7. package/Build/Workers/{chunk-CYAJYEKW.js → chunk-4MSUJ4I7.js} +8 -8
  8. package/Build/Workers/{chunk-KPY4F4BW.js → chunk-4YSNMHZ4.js} +6 -6
  9. package/Build/Workers/{chunk-66E3H2KU.js → chunk-5S7OLEPK.js} +12 -12
  10. package/Build/Workers/{chunk-4AJGCQFX.js → chunk-7XGC6YB2.js} +14 -14
  11. package/Build/Workers/{chunk-BDUJXBVF.js → chunk-AA4GZKOT.js} +3 -5
  12. package/Build/Workers/{chunk-7LPEGKOF.js → chunk-AD5HBJ2F.js} +11 -8
  13. package/Build/Workers/{chunk-XHLDDE65.js → chunk-AVI4IUWC.js} +11 -11
  14. package/Build/Workers/{chunk-MWYZ64MH.js → chunk-BCL4PHHT.js} +10 -10
  15. package/Build/Workers/{chunk-PWF3YJJ5.js → chunk-BDFNKFOE.js} +13 -13
  16. package/Build/Workers/{chunk-7VZNXIKG.js → chunk-BJF5LOWE.js} +7 -7
  17. package/Build/Workers/{chunk-3S2MFY4B.js → chunk-C2CGMAIU.js} +13 -13
  18. package/Build/Workers/{chunk-UAJEGIWA.js → chunk-COYFZ5VA.js} +6 -6
  19. package/Build/Workers/{chunk-ZWPIM77Q.js → chunk-DGS5QNIO.js} +13 -13
  20. package/Build/Workers/{chunk-V7JB576Q.js → chunk-DKVHRNFY.js} +5 -5
  21. package/Build/Workers/{chunk-NI2R52QD.js → chunk-DOXCPOG4.js} +11 -9
  22. package/Build/Workers/{chunk-XWML5Y7N.js → chunk-FXIHSF7O.js} +9 -9
  23. package/Build/Workers/{chunk-LW7WGHEU.js → chunk-G3YR53LY.js} +13 -13
  24. package/Build/Workers/{chunk-34DGOKCO.js → chunk-GR3CDLCP.js} +7 -7
  25. package/Build/Workers/{chunk-AOIKO5Y7.js → chunk-GRAT5GE7.js} +5 -5
  26. package/Build/Workers/{chunk-AOFMPKUB.js → chunk-I2RC4XVN.js} +4 -4
  27. package/Build/Workers/{chunk-PK7TEP3J.js → chunk-JYAHOGGL.js} +15 -15
  28. package/Build/Workers/{chunk-4KIUON73.js → chunk-KUN2ZA5X.js} +4 -4
  29. package/Build/Workers/{chunk-POLFRINT.js → chunk-L6RTJ3RE.js} +14 -14
  30. package/Build/Workers/{chunk-LVJCR7DH.js → chunk-LCLJJ2MZ.js} +18 -18
  31. package/Build/Workers/{chunk-3RZK5NNV.js → chunk-LEABCTLP.js} +4 -4
  32. package/Build/Workers/{chunk-QKF7XXEQ.js → chunk-MDHQR3ZS.js} +10 -8
  33. package/Build/Workers/{chunk-4PHPQRSH.js → chunk-MSKXMXJI.js} +5 -6
  34. package/Build/Workers/{chunk-GIFJ77E4.js → chunk-NTXTUNEF.js} +4 -4
  35. package/Build/Workers/{chunk-I5TDPPC4.js → chunk-O3JCMSS3.js} +17 -17
  36. package/Build/Workers/{chunk-PEABJLCK.js → chunk-OOK53QUQ.js} +1 -1
  37. package/Build/Workers/{chunk-PS6AEMBR.js → chunk-OORVMGDU.js} +7 -7
  38. package/Build/Workers/{chunk-JI2445T5.js → chunk-PCP4YQST.js} +11 -11
  39. package/Build/Workers/{chunk-C5CE4OG6.js → chunk-PYHLO636.js} +42 -13
  40. package/Build/Workers/{chunk-S4XDCPKD.js → chunk-Q55ECN3Y.js} +1 -1
  41. package/Build/Workers/{chunk-WWP3I7R5.js → chunk-QD4KM3GO.js} +5 -5
  42. package/Build/Workers/{chunk-YLZTCEBJ.js → chunk-QMLTCCYG.js} +1 -1
  43. package/Build/Workers/{chunk-IBXGK4WV.js → chunk-QX5XS4LC.js} +2 -2
  44. package/Build/Workers/{chunk-RL73GOEF.js → chunk-R6B7UCQB.js} +2 -2
  45. package/Build/Workers/{chunk-RR7EOKGZ.js → chunk-RJYML24O.js} +48 -85
  46. package/Build/Workers/{chunk-U4IMCOF5.js → chunk-S3PI2KFM.js} +2 -2
  47. package/Build/Workers/{chunk-6HCAQOVK.js → chunk-STBBMQGG.js} +6 -6
  48. package/Build/Workers/{chunk-CE6GTZ4I.js → chunk-SYCPRK3D.js} +10 -10
  49. package/Build/Workers/{chunk-WFICTTOE.js → chunk-T77JILCU.js} +2 -2
  50. package/Build/Workers/{chunk-ZC4AGBZK.js → chunk-TO2PVHKI.js} +2 -2
  51. package/Build/Workers/{chunk-UCPPWV64.js → chunk-VE7BFUIX.js} +1 -1
  52. package/Build/Workers/{chunk-2CSEEWHN.js → chunk-VFBNELXB.js} +7 -7
  53. package/Build/Workers/{chunk-A6NCZSL3.js → chunk-VO3ACQB2.js} +19 -19
  54. package/Build/Workers/{chunk-WEGCQ5DY.js → chunk-X23FRWHJ.js} +6 -6
  55. package/Build/Workers/{chunk-G7CJQKKD.js → chunk-XD445VDH.js} +7 -7
  56. package/Build/Workers/combineGeometry.js +22 -22
  57. package/Build/Workers/createBoxGeometry.js +16 -16
  58. package/Build/Workers/createBoxOutlineGeometry.js +14 -14
  59. package/Build/Workers/createCircleGeometry.js +29 -25
  60. package/Build/Workers/createCircleOutlineGeometry.js +17 -17
  61. package/Build/Workers/createCoplanarPolygonGeometry.js +32 -32
  62. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -29
  63. package/Build/Workers/createCorridorGeometry.js +29 -29
  64. package/Build/Workers/createCorridorOutlineGeometry.js +27 -27
  65. package/Build/Workers/createCylinderGeometry.js +18 -18
  66. package/Build/Workers/createCylinderOutlineGeometry.js +16 -16
  67. package/Build/Workers/createEllipseGeometry.js +24 -24
  68. package/Build/Workers/createEllipseOutlineGeometry.js +17 -17
  69. package/Build/Workers/createEllipsoidGeometry.js +17 -17
  70. package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -16
  71. package/Build/Workers/createFrustumGeometry.js +16 -16
  72. package/Build/Workers/createFrustumOutlineGeometry.js +16 -16
  73. package/Build/Workers/createGeometry.js +22 -22
  74. package/Build/Workers/createGroundPolylineGeometry.js +24 -24
  75. package/Build/Workers/createPlaneGeometry.js +14 -14
  76. package/Build/Workers/createPlaneOutlineGeometry.js +13 -13
  77. package/Build/Workers/createPolygonGeometry.js +32 -32
  78. package/Build/Workers/createPolygonOutlineGeometry.js +29 -29
  79. package/Build/Workers/createPolylineGeometry.js +24 -24
  80. package/Build/Workers/createPolylineVolumeGeometry.js +30 -30
  81. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +26 -26
  82. package/Build/Workers/createRectangleGeometry.js +27 -27
  83. package/Build/Workers/createRectangleOutlineGeometry.js +19 -19
  84. package/Build/Workers/createSimplePolylineGeometry.js +22 -22
  85. package/Build/Workers/createSphereGeometry.js +17 -17
  86. package/Build/Workers/createSphereOutlineGeometry.js +16 -16
  87. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  88. package/Build/Workers/createVectorTileClampedPolylines.js +13 -13
  89. package/Build/Workers/createVectorTileGeometries.js +22 -22
  90. package/Build/Workers/createVectorTilePoints.js +12 -12
  91. package/Build/Workers/createVectorTilePolygons.js +20 -20
  92. package/Build/Workers/createVectorTilePolylines.js +13 -13
  93. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +20 -20
  94. package/Build/Workers/createVerticesFromHeightmap.js +21 -21
  95. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +17 -17
  96. package/Build/Workers/createWallGeometry.js +23 -23
  97. package/Build/Workers/createWallOutlineGeometry.js +22 -22
  98. package/Build/Workers/decodeDraco.js +11 -11
  99. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +12 -19
  100. package/Build/Workers/decodeI3S.js +10 -10
  101. package/Build/Workers/transcodeKTX2.js +43 -79
  102. package/Build/Workers/transferTypedArrayTest.js +1 -1
  103. package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -20
  104. package/Source/Core/ApproximateTerrainHeights.js +4 -4
  105. package/Source/Core/ArcGISTiledElevationTerrainProvider.js +12 -8
  106. package/Source/Core/BoundingRectangle.js +2 -0
  107. package/Source/Core/BoundingSphere.js +4 -2
  108. package/Source/Core/Cartesian3.js +13 -10
  109. package/Source/Core/Cartographic.js +11 -8
  110. package/Source/Core/CesiumTerrainProvider.js +3 -2
  111. package/Source/Core/CircleGeometry.js +6 -2
  112. package/Source/Core/CircleOutlineGeometry.js +1 -1
  113. package/Source/Core/CoplanarPolygonGeometry.js +3 -3
  114. package/Source/Core/CorridorGeometry.js +4 -4
  115. package/Source/Core/CorridorOutlineGeometry.js +2 -2
  116. package/Source/Core/Credit.js +3 -2
  117. package/Source/Core/CustomHeightmapTerrainProvider.js +17 -3
  118. package/Source/Core/EllipseGeometry.js +4 -4
  119. package/Source/Core/EllipseOutlineGeometry.js +2 -2
  120. package/Source/Core/Ellipsoid.js +34 -0
  121. package/Source/Core/EllipsoidGeodesic.js +2 -2
  122. package/Source/Core/EllipsoidRhumbLine.js +4 -4
  123. package/Source/Core/EllipsoidTangentPlane.js +3 -3
  124. package/Source/Core/EllipsoidTerrainProvider.js +3 -3
  125. package/Source/Core/GeographicProjection.js +4 -3
  126. package/Source/Core/GeographicTilingScheme.js +3 -3
  127. package/Source/Core/GeometryPipeline.js +2 -2
  128. package/Source/Core/GoogleEarthEnterpriseTerrainProvider.js +1 -1
  129. package/Source/Core/GoogleMaps.js +1 -1
  130. package/Source/Core/GroundPolylineGeometry.js +1 -1
  131. package/Source/Core/HeightmapTessellator.js +2 -2
  132. package/Source/Core/Ion.js +1 -1
  133. package/Source/Core/Math.js +0 -5
  134. package/Source/Core/Occluder.js +3 -3
  135. package/Source/Core/OrientedBoundingBox.js +2 -2
  136. package/Source/Core/PolygonGeometry.js +4 -4
  137. package/Source/Core/PolygonGeometryLibrary.js +1 -1
  138. package/Source/Core/PolygonOutlineGeometry.js +3 -3
  139. package/Source/Core/PolygonPipeline.js +2 -2
  140. package/Source/Core/PolylineGeometry.js +2 -2
  141. package/Source/Core/PolylinePipeline.js +6 -6
  142. package/Source/Core/PolylineVolumeGeometry.js +2 -2
  143. package/Source/Core/PolylineVolumeOutlineGeometry.js +2 -2
  144. package/Source/Core/Rectangle.js +6 -6
  145. package/Source/Core/RectangleGeometry.js +6 -6
  146. package/Source/Core/RectangleGeometryLibrary.js +3 -0
  147. package/Source/Core/RectangleOutlineGeometry.js +2 -2
  148. package/Source/Core/Simon1994PlanetaryPositions.js +3 -2
  149. package/Source/Core/SimplePolylineGeometry.js +2 -2
  150. package/Source/Core/Stereographic.js +2 -2
  151. package/Source/Core/TaskProcessor.js +19 -3
  152. package/Source/Core/Transforms.js +17 -17
  153. package/Source/Core/VRTheWorldTerrainProvider.js +2 -2
  154. package/Source/Core/WallGeometry.js +3 -3
  155. package/Source/Core/WallOutlineGeometry.js +3 -3
  156. package/Source/Core/WebMercatorTilingScheme.js +3 -3
  157. package/Source/Core/createWorldTerrainAsync.js +2 -0
  158. package/Source/Core/sampleTerrain.js +3 -3
  159. package/Source/DataSources/BoxGeometryUpdater.js +2 -2
  160. package/Source/DataSources/CylinderGeometryUpdater.js +2 -2
  161. package/Source/DataSources/CzmlDataSource.js +8 -8
  162. package/Source/DataSources/EllipsoidGeometryUpdater.js +3 -3
  163. package/Source/DataSources/EntityCluster.js +1 -1
  164. package/Source/DataSources/EntityView.js +2 -2
  165. package/Source/DataSources/KmlDataSource.js +4 -4
  166. package/Source/DataSources/ModelVisualizer.js +1 -2
  167. package/Source/DataSources/PolygonGeometryUpdater.js +1 -1
  168. package/Source/DataSources/PolylineGeometryUpdater.js +3 -2
  169. package/Source/DataSources/RectangleGeometryUpdater.js +1 -1
  170. package/Source/DataSources/ScaledPositionProperty.js +2 -2
  171. package/Source/DataSources/TerrainOffsetProperty.js +3 -7
  172. package/Source/DataSources/VelocityOrientationProperty.js +2 -2
  173. package/Source/DataSources/exportKml.js +2 -2
  174. package/Source/Renderer/UniformState.js +1 -1
  175. package/Source/Scene/ArcGisMapServerImageryProvider.js +2 -2
  176. package/Source/Scene/ArcGisMapService.js +1 -1
  177. package/Source/Scene/Billboard.js +8 -6
  178. package/Source/Scene/BingMapsImageryProvider.js +1 -1
  179. package/Source/Scene/Camera.js +16 -10
  180. package/Source/Scene/Cesium3DTileset.js +1 -1
  181. package/Source/Scene/ClippingPolygon.js +2 -2
  182. package/Source/Scene/ClippingPolygonCollection.js +1 -1
  183. package/Source/Scene/CreditDisplay.js +94 -104
  184. package/Source/Scene/Globe.js +16 -13
  185. package/Source/Scene/GltfLoader.js +458 -435
  186. package/Source/Scene/GltfLoaderUtil.js +5 -16
  187. package/Source/Scene/GltfPipeline/forEachTextureInMaterial.js +23 -7
  188. package/Source/Scene/GltfStructuralMetadataLoader.js +11 -9
  189. package/Source/Scene/GoogleEarthEnterpriseImageryProvider.js +1 -1
  190. package/Source/Scene/GoogleEarthEnterpriseMapsProvider.js +1 -1
  191. package/Source/Scene/GridImageryProvider.js +2 -2
  192. package/Source/Scene/ImageryLayerCollection.js +2 -2
  193. package/Source/Scene/Label.js +1 -1
  194. package/Source/Scene/MapboxImageryProvider.js +1 -1
  195. package/Source/Scene/MapboxStyleImageryProvider.js +1 -1
  196. package/Source/Scene/MetadataSemantic.js +4 -4
  197. package/Source/Scene/Model/AlphaPipelineStage.js +1 -1
  198. package/Source/Scene/Model/GeometryPipelineStage.js +15 -43
  199. package/Source/Scene/Model/ImageBasedLightingPipelineStage.js +7 -0
  200. package/Source/Scene/Model/InstancingPipelineStage.js +3 -3
  201. package/Source/Scene/Model/LightingPipelineStage.js +2 -4
  202. package/Source/Scene/Model/MaterialPipelineStage.js +395 -29
  203. package/Source/Scene/Model/Model.js +15 -7
  204. package/Source/Scene/Model/ModelSceneGraph.js +1 -1
  205. package/Source/Scene/Model/ModelUtility.js +3 -0
  206. package/Source/Scene/Model/SceneMode2DPipelineStage.js +3 -3
  207. package/Source/Scene/Model/VerticalExaggerationPipelineStage.js +4 -6
  208. package/Source/Scene/Model/pickModel.js +2 -2
  209. package/Source/Scene/ModelComponents.js +178 -1
  210. package/Source/Scene/PickDepth.js +23 -15
  211. package/Source/Scene/Picking.js +4 -13
  212. package/Source/Scene/PointPrimitive.js +5 -2
  213. package/Source/Scene/ResourceCache.js +41 -50
  214. package/Source/Scene/ResourceCacheKey.js +41 -53
  215. package/Source/Scene/Scene.js +39 -31
  216. package/Source/Scene/SceneTransforms.js +78 -20
  217. package/Source/Scene/SceneTransitioner.js +2 -2
  218. package/Source/Scene/ScreenSpaceCameraController.js +29 -19
  219. package/Source/Scene/SkyBox.js +26 -0
  220. package/Source/Scene/Sun.js +1 -1
  221. package/Source/Shaders/Builtin/CzmBuiltins.js +4 -10
  222. package/Source/Shaders/Builtin/Functions/ellipsoidTextureCoordinates.glsl +10 -0
  223. package/Source/Shaders/Builtin/Functions/{ellipsoidWgs84TextureCoordinates.js → ellipsoidTextureCoordinates.js} +3 -3
  224. package/Source/Shaders/Builtin/Functions/maximumComponent.glsl +21 -0
  225. package/Source/Shaders/Builtin/Functions/maximumComponent.js +23 -0
  226. package/Source/Shaders/Builtin/Functions/pbrLighting.glsl +108 -44
  227. package/Source/Shaders/Builtin/Functions/pbrLighting.js +108 -44
  228. package/Source/Shaders/Builtin/Structs/materialInput.glsl +1 -1
  229. package/Source/Shaders/Builtin/Structs/materialInput.js +1 -1
  230. package/Source/Shaders/Builtin/Structs/modelMaterial.glsl +16 -0
  231. package/Source/Shaders/Builtin/Structs/modelMaterial.js +16 -0
  232. package/Source/Shaders/EllipsoidFS.glsl +1 -1
  233. package/Source/Shaders/EllipsoidFS.js +1 -1
  234. package/Source/Shaders/GlobeFS.glsl +3 -3
  235. package/Source/Shaders/GlobeFS.js +3 -3
  236. package/Source/Shaders/Model/ImageBasedLightingStageFS.glsl +211 -133
  237. package/Source/Shaders/Model/ImageBasedLightingStageFS.js +212 -133
  238. package/Source/Shaders/Model/LightingStageFS.glsl +113 -48
  239. package/Source/Shaders/Model/LightingStageFS.js +113 -48
  240. package/Source/Shaders/Model/MaterialStageFS.glsl +407 -136
  241. package/Source/Shaders/Model/MaterialStageFS.js +407 -136
  242. package/Source/Widget/CesiumWidget.css +0 -5
  243. package/Source/Widget/CesiumWidget.js +29 -28
  244. package/index.d.ts +184 -116
  245. package/index.js +92 -95
  246. package/package.json +2 -2
  247. package/Source/Shaders/Builtin/Functions/defaultPbrMaterial.glsl +0 -16
  248. package/Source/Shaders/Builtin/Functions/defaultPbrMaterial.js +0 -18
  249. package/Source/Shaders/Builtin/Functions/ellipsoidWgs84TextureCoordinates.glsl +0 -10
  250. package/Source/Shaders/Builtin/Functions/pbrMetallicRoughnessMaterial.glsl +0 -37
  251. package/Source/Shaders/Builtin/Functions/pbrMetallicRoughnessMaterial.js +0 -39
  252. package/Source/Shaders/Builtin/Functions/pbrSpecularGlossinessMaterial.glsl +0 -30
  253. package/Source/Shaders/Builtin/Functions/pbrSpecularGlossinessMaterial.js +0 -32
  254. package/Source/Shaders/Builtin/Structs/pbrParameters.glsl +0 -16
  255. package/Source/Shaders/Builtin/Structs/pbrParameters.js +0 -18
@@ -30,29 +30,34 @@ import ResourceLoader from "./ResourceLoader.js";
30
30
  import SupportedImageFormats from "./SupportedImageFormats.js";
31
31
  import VertexAttributeSemantic from "./VertexAttributeSemantic.js";
32
32
 
33
- const Attribute = ModelComponents.Attribute;
34
- const Indices = ModelComponents.Indices;
35
- const FeatureIdAttribute = ModelComponents.FeatureIdAttribute;
36
- const FeatureIdTexture = ModelComponents.FeatureIdTexture;
37
- const FeatureIdImplicitRange = ModelComponents.FeatureIdImplicitRange;
38
- const MorphTarget = ModelComponents.MorphTarget;
39
- const Primitive = ModelComponents.Primitive;
40
- const Instances = ModelComponents.Instances;
41
- const Skin = ModelComponents.Skin;
42
- const Node = ModelComponents.Node;
43
- const AnimatedPropertyType = ModelComponents.AnimatedPropertyType;
44
- const AnimationSampler = ModelComponents.AnimationSampler;
45
- const AnimationTarget = ModelComponents.AnimationTarget;
46
- const AnimationChannel = ModelComponents.AnimationChannel;
47
- const Animation = ModelComponents.Animation;
48
- const ArticulationStage = ModelComponents.ArticulationStage;
49
- const Articulation = ModelComponents.Articulation;
50
- const Asset = ModelComponents.Asset;
51
- const Scene = ModelComponents.Scene;
52
- const Components = ModelComponents.Components;
53
- const MetallicRoughness = ModelComponents.MetallicRoughness;
54
- const SpecularGlossiness = ModelComponents.SpecularGlossiness;
55
- const Material = ModelComponents.Material;
33
+ const {
34
+ Attribute,
35
+ Indices,
36
+ FeatureIdAttribute,
37
+ FeatureIdTexture,
38
+ FeatureIdImplicitRange,
39
+ MorphTarget,
40
+ Primitive,
41
+ Instances,
42
+ Skin,
43
+ Node,
44
+ AnimatedPropertyType,
45
+ AnimationSampler,
46
+ AnimationTarget,
47
+ AnimationChannel,
48
+ Animation,
49
+ ArticulationStage,
50
+ Articulation,
51
+ Asset,
52
+ Scene,
53
+ Components,
54
+ MetallicRoughness,
55
+ SpecularGlossiness,
56
+ Specular,
57
+ Anisotropy,
58
+ Clearcoat,
59
+ Material,
60
+ } = ModelComponents;
56
61
 
57
62
  /**
58
63
  * States of the glTF loading process. These states also apply to
@@ -188,42 +193,28 @@ const GltfLoaderState = {
188
193
  */
189
194
  function GltfLoader(options) {
190
195
  options = defaultValue(options, defaultValue.EMPTY_OBJECT);
191
- const gltfResource = options.gltfResource;
192
- let baseResource = options.baseResource;
193
- const typedArray = options.typedArray;
194
- const releaseGltfJson = defaultValue(options.releaseGltfJson, false);
195
- const asynchronous = defaultValue(options.asynchronous, true);
196
- const incrementallyLoadTextures = defaultValue(
197
- options.incrementallyLoadTextures,
198
- true
199
- );
200
- const upAxis = defaultValue(options.upAxis, Axis.Y);
201
- const forwardAxis = defaultValue(options.forwardAxis, Axis.Z);
202
- const loadAttributesAsTypedArray = defaultValue(
203
- options.loadAttributesAsTypedArray,
204
- false
205
- );
206
- const loadAttributesFor2D = defaultValue(options.loadAttributesFor2D, false);
207
- const enablePick = defaultValue(options.enablePick);
208
- const loadIndicesForWireframe = defaultValue(
209
- options.loadIndicesForWireframe,
210
- false
211
- );
212
- const loadPrimitiveOutline = defaultValue(options.loadPrimitiveOutline, true);
213
- const loadForClassification = defaultValue(
214
- options.loadForClassification,
215
- false
216
- );
217
- const renameBatchIdSemantic = defaultValue(
218
- options.renameBatchIdSemantic,
219
- false
220
- );
196
+ const {
197
+ gltfResource,
198
+ typedArray,
199
+ releaseGltfJson = false,
200
+ asynchronous = true,
201
+ incrementallyLoadTextures = true,
202
+ upAxis = Axis.Y,
203
+ forwardAxis = Axis.Z,
204
+ loadAttributesAsTypedArray = false,
205
+ loadAttributesFor2D = false,
206
+ enablePick = false,
207
+ loadIndicesForWireframe = false,
208
+ loadPrimitiveOutline = true,
209
+ loadForClassification = false,
210
+ renameBatchIdSemantic = false,
211
+ } = options;
221
212
 
222
213
  //>>includeStart('debug', pragmas.debug);
223
214
  Check.typeOf.object("options.gltfResource", gltfResource);
224
215
  //>>includeEnd('debug');
225
216
 
226
- baseResource = defined(baseResource) ? baseResource : gltfResource.clone();
217
+ const { baseResource = gltfResource.clone() } = options;
227
218
 
228
219
  this._gltfJson = options.gltfJson;
229
220
  this._gltfResource = gltfResource;
@@ -273,6 +264,8 @@ function GltfLoader(options) {
273
264
  this._resourcesLoaded = false;
274
265
  this._texturesLoaded = false;
275
266
 
267
+ this._supportedImageFormats = undefined;
268
+
276
269
  // In some cases where geometry post-processing is needed (like generating
277
270
  // outlines) new attributes are added that may have GPU resources attached.
278
271
  // The GltfLoader will own the resources and store them here.
@@ -408,20 +401,17 @@ async function loadResources(loader, frameState) {
408
401
  await FeatureDetection.supportsWebP.initialize();
409
402
  }
410
403
 
411
- const supportedImageFormats = new SupportedImageFormats({
404
+ loader._supportedImageFormats = new SupportedImageFormats({
412
405
  webp: FeatureDetection.supportsWebP(),
413
406
  basis: frameState.context.supportsBasis,
414
407
  });
415
408
 
416
- // Parse the glTF which populates the loaders arrays. Loading promises will be created, and will
417
- // resolve once the loaders are ready (i.e. all external resources
418
- // have been fetched and all GPU resources have been created). Loaders that
419
- // create GPU resources need to be processed every frame until they become
409
+ // Loaders that create GPU resources need to be processed every frame until they become
420
410
  // ready since the JobScheduler is not able to execute all jobs in a single
421
- // 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
422
- // to process or after it has failed; nothing will happen.
423
- const gltf = loader.gltfJson;
424
- const promise = parse(loader, gltf, supportedImageFormats, frameState);
411
+ // frame. Any promise failures are collected, and will be handled synchronously in process().
412
+ // Also note that it's fine to call process before a loader is ready to process or
413
+ // after it has failed; nothing will happen.
414
+ const promise = parse(loader, frameState);
425
415
 
426
416
  // All resource loaders have been created, so we can begin processing
427
417
  loader._state = GltfLoaderState.PROCESSING;
@@ -460,11 +450,9 @@ function handleError(gltfLoader, error) {
460
450
  }
461
451
 
462
452
  function processLoaders(loader, frameState) {
463
- let i;
464
453
  let ready = true;
465
454
  const geometryLoaders = loader._geometryLoaders;
466
- const geometryLoadersLength = geometryLoaders.length;
467
- for (i = 0; i < geometryLoadersLength; ++i) {
455
+ for (let i = 0; i < geometryLoaders.length; ++i) {
468
456
  const geometryReady = geometryLoaders[i].process(frameState);
469
457
  if (geometryReady && defined(loader._geometryCallbacks[i])) {
470
458
  loader._geometryCallbacks[i]();
@@ -493,8 +481,7 @@ function postProcessGeometry(loader, context) {
493
481
  // Apply post-processing steps on geometry such as
494
482
  // updating attributes for rendering outlines.
495
483
  const loadPlans = loader._primitiveLoadPlans;
496
- const length = loadPlans.length;
497
- for (let i = 0; i < length; i++) {
484
+ for (let i = 0; i < loadPlans.length; i++) {
498
485
  const loadPlan = loadPlans[i];
499
486
  loadPlan.postProcess(context);
500
487
 
@@ -520,8 +507,7 @@ function gatherPostProcessBuffers(loader, primitiveLoadPlan) {
520
507
  // to do post-processing, all the attributes are loaded as typed arrays
521
508
  // so if a buffer exists, it was newly generated
522
509
  const attributes = primitive.attributes;
523
- const length = attributes.length;
524
- for (let i = 0; i < length; i++) {
510
+ for (let i = 0; i < attributes.length; i++) {
525
511
  const attribute = attributes[i];
526
512
  if (defined(attribute.buffer)) {
527
513
  buffers.push(attribute.buffer);
@@ -583,11 +569,9 @@ GltfLoader.prototype._processTextures = function (frameState) {
583
569
  return false;
584
570
  }
585
571
 
586
- let i;
587
572
  let ready = true;
588
573
  const textureLoaders = this._textureLoaders;
589
- const textureLoadersLength = textureLoaders.length;
590
- for (i = 0; i < textureLoadersLength; ++i) {
574
+ for (let i = 0; i < textureLoaders.length; ++i) {
591
575
  const textureReady = textureLoaders[i].process(frameState);
592
576
  if (textureReady && defined(this._textureCallbacks[i])) {
593
577
  this._textureCallbacks[i]();
@@ -676,7 +660,6 @@ GltfLoader.prototype.process = function (frameState) {
676
660
 
677
661
  function getVertexBufferLoader(
678
662
  loader,
679
- gltf,
680
663
  accessorId,
681
664
  semantic,
682
665
  draco,
@@ -684,6 +667,7 @@ function getVertexBufferLoader(
684
667
  loadTypedArray,
685
668
  frameState
686
669
  ) {
670
+ const gltf = loader.gltfJson;
687
671
  const accessor = gltf.accessors[accessorId];
688
672
  const bufferViewId = accessor.bufferView;
689
673
 
@@ -706,7 +690,6 @@ function getVertexBufferLoader(
706
690
 
707
691
  function getIndexBufferLoader(
708
692
  loader,
709
- gltf,
710
693
  accessorId,
711
694
  draco,
712
695
  loadBuffer,
@@ -714,7 +697,7 @@ function getIndexBufferLoader(
714
697
  frameState
715
698
  ) {
716
699
  const indexBufferLoader = ResourceCache.getIndexBufferLoader({
717
- gltf: gltf,
700
+ gltf: loader.gltfJson,
718
701
  accessorId: accessorId,
719
702
  gltfResource: loader._gltfResource,
720
703
  baseResource: loader._baseResource,
@@ -728,9 +711,9 @@ function getIndexBufferLoader(
728
711
  return indexBufferLoader;
729
712
  }
730
713
 
731
- function getBufferViewLoader(loader, gltf, bufferViewId) {
714
+ function getBufferViewLoader(loader, bufferViewId) {
732
715
  const bufferViewLoader = ResourceCache.getBufferViewLoader({
733
- gltf: gltf,
716
+ gltf: loader.gltfJson,
734
717
  bufferViewId: bufferViewId,
735
718
  gltfResource: loader._gltfResource,
736
719
  baseResource: loader._baseResource,
@@ -828,35 +811,37 @@ function loadAccessorValues(accessor, typedArray, values, useQuaternion) {
828
811
  async function loadAccessorBufferView(
829
812
  loader,
830
813
  bufferViewLoader,
831
- gltf,
832
814
  accessor,
833
815
  useQuaternion,
834
816
  values
835
817
  ) {
818
+ // Save a link to the gltfJson, which is removed after bufferViewLoader.load()
819
+ const { gltfJson } = loader;
820
+
836
821
  await bufferViewLoader.load();
837
822
  if (loader.isDestroyed()) {
838
823
  return;
839
824
  }
840
825
 
841
- const bufferViewTypedArray = bufferViewLoader.typedArray;
842
- const typedArray = getPackedTypedArray(gltf, accessor, bufferViewTypedArray);
826
+ const typedArray = getPackedTypedArray(
827
+ gltfJson,
828
+ accessor,
829
+ bufferViewLoader.typedArray
830
+ );
843
831
 
844
832
  useQuaternion = defaultValue(useQuaternion, false);
845
833
  loadAccessorValues(accessor, typedArray, values, useQuaternion);
846
834
  }
847
835
 
848
- function loadAccessor(loader, gltf, accessorId, useQuaternion) {
849
- const accessor = gltf.accessors[accessorId];
850
- const accessorCount = accessor.count;
851
- const values = new Array(accessorCount);
836
+ function loadAccessor(loader, accessor, useQuaternion) {
837
+ const values = new Array(accessor.count);
852
838
 
853
839
  const bufferViewId = accessor.bufferView;
854
840
  if (defined(bufferViewId)) {
855
- const bufferViewLoader = getBufferViewLoader(loader, gltf, bufferViewId);
841
+ const bufferViewLoader = getBufferViewLoader(loader, bufferViewId);
856
842
  const promise = loadAccessorBufferView(
857
843
  loader,
858
844
  bufferViewLoader,
859
- gltf,
860
845
  accessor,
861
846
  useQuaternion,
862
847
  values
@@ -1145,7 +1130,6 @@ function finalizeAttribute(
1145
1130
 
1146
1131
  function loadAttribute(
1147
1132
  loader,
1148
- gltf,
1149
1133
  accessorId,
1150
1134
  semanticInfo,
1151
1135
  draco,
@@ -1153,6 +1137,7 @@ function loadAttribute(
1153
1137
  loadTypedArray,
1154
1138
  frameState
1155
1139
  ) {
1140
+ const gltf = loader.gltfJson;
1156
1141
  const accessor = gltf.accessors[accessorId];
1157
1142
  const bufferViewId = accessor.bufferView;
1158
1143
 
@@ -1179,7 +1164,6 @@ function loadAttribute(
1179
1164
 
1180
1165
  const vertexBufferLoader = getVertexBufferLoader(
1181
1166
  loader,
1182
- gltf,
1183
1167
  accessorId,
1184
1168
  gltfSemantic,
1185
1169
  draco,
@@ -1224,7 +1208,6 @@ function loadAttribute(
1224
1208
 
1225
1209
  function loadVertexAttribute(
1226
1210
  loader,
1227
- gltf,
1228
1211
  accessorId,
1229
1212
  semanticInfo,
1230
1213
  draco,
@@ -1271,7 +1254,6 @@ function loadVertexAttribute(
1271
1254
 
1272
1255
  const attribute = loadAttribute(
1273
1256
  loader,
1274
- gltf,
1275
1257
  accessorId,
1276
1258
  semanticInfo,
1277
1259
  draco,
@@ -1289,17 +1271,17 @@ function loadVertexAttribute(
1289
1271
 
1290
1272
  function loadInstancedAttribute(
1291
1273
  loader,
1292
- gltf,
1293
1274
  accessorId,
1294
1275
  attributes,
1295
1276
  gltfSemantic,
1296
1277
  frameState
1297
1278
  ) {
1279
+ const accessors = loader.gltfJson.accessors;
1298
1280
  const hasRotation = defined(attributes.ROTATION);
1299
1281
  const hasTranslationMinMax =
1300
1282
  defined(attributes.TRANSLATION) &&
1301
- defined(gltf.accessors[attributes.TRANSLATION].min) &&
1302
- defined(gltf.accessors[attributes.TRANSLATION].max);
1283
+ defined(accessors[attributes.TRANSLATION].min) &&
1284
+ defined(accessors[attributes.TRANSLATION].max);
1303
1285
 
1304
1286
  const semanticInfo = getSemanticInfo(
1305
1287
  loader,
@@ -1344,7 +1326,6 @@ function loadInstancedAttribute(
1344
1326
  // Don't pass in draco object since instanced attributes can't be draco compressed
1345
1327
  return loadAttribute(
1346
1328
  loader,
1347
- gltf,
1348
1329
  accessorId,
1349
1330
  semanticInfo,
1350
1331
  undefined,
@@ -1356,14 +1337,13 @@ function loadInstancedAttribute(
1356
1337
 
1357
1338
  function loadIndices(
1358
1339
  loader,
1359
- gltf,
1360
1340
  accessorId,
1361
1341
  draco,
1362
1342
  hasFeatureIds,
1363
1343
  needsPostProcessing,
1364
1344
  frameState
1365
1345
  ) {
1366
- const accessor = gltf.accessors[accessorId];
1346
+ const accessor = loader.gltfJson.accessors[accessorId];
1367
1347
  const bufferViewId = accessor.bufferView;
1368
1348
 
1369
1349
  if (!defined(draco) && !defined(bufferViewId)) {
@@ -1400,7 +1380,6 @@ function loadIndices(
1400
1380
 
1401
1381
  const indexBufferLoader = getIndexBufferLoader(
1402
1382
  loader,
1403
- gltf,
1404
1383
  accessorId,
1405
1384
  draco,
1406
1385
  loadBuffer,
@@ -1428,18 +1407,12 @@ function loadIndices(
1428
1407
  return indicesPlan;
1429
1408
  }
1430
1409
 
1431
- function loadTexture(
1432
- loader,
1433
- gltf,
1434
- textureInfo,
1435
- supportedImageFormats,
1436
- frameState,
1437
- samplerOverride
1438
- ) {
1410
+ function loadTexture(loader, textureInfo, frameState, samplerOverride) {
1411
+ const gltf = loader.gltfJson;
1439
1412
  const imageId = GltfLoaderUtil.getImageIdFromTexture({
1440
1413
  gltf: gltf,
1441
1414
  textureId: textureInfo.index,
1442
- supportedImageFormats: supportedImageFormats,
1415
+ supportedImageFormats: loader._supportedImageFormats,
1443
1416
  });
1444
1417
 
1445
1418
  if (!defined(imageId)) {
@@ -1451,7 +1424,7 @@ function loadTexture(
1451
1424
  textureInfo: textureInfo,
1452
1425
  gltfResource: loader._gltfResource,
1453
1426
  baseResource: loader._baseResource,
1454
- supportedImageFormats: supportedImageFormats,
1427
+ supportedImageFormats: loader._supportedImageFormats,
1455
1428
  frameState: frameState,
1456
1429
  asynchronous: loader._asynchronous,
1457
1430
  });
@@ -1491,13 +1464,177 @@ function loadTexture(
1491
1464
  return textureReader;
1492
1465
  }
1493
1466
 
1494
- function loadMaterial(
1495
- loader,
1496
- gltf,
1497
- gltfMaterial,
1498
- supportedImageFormats,
1499
- frameState
1500
- ) {
1467
+ /**
1468
+ * Load textures and parse factors for the KHR_materials_pbrSpecularGlossiness extension
1469
+ * @param {GltfLoader} loader
1470
+ * @param {object} specularGlossinessInfo The contents of the KHR_materials_pbrSpecularGlossiness extension in the parsed glTF JSON
1471
+ * @param {FrameState} frameState
1472
+ * @returns {ModelComponents.SpecularGlossiness}
1473
+ * @private
1474
+ */
1475
+ function loadSpecularGlossiness(loader, specularGlossinessInfo, frameState) {
1476
+ const {
1477
+ diffuseTexture,
1478
+ specularGlossinessTexture,
1479
+ diffuseFactor,
1480
+ specularFactor,
1481
+ glossinessFactor,
1482
+ } = specularGlossinessInfo;
1483
+
1484
+ const specularGlossiness = new SpecularGlossiness();
1485
+ if (defined(diffuseTexture)) {
1486
+ specularGlossiness.diffuseTexture = loadTexture(
1487
+ loader,
1488
+ diffuseTexture,
1489
+ frameState
1490
+ );
1491
+ }
1492
+ if (defined(specularGlossinessTexture)) {
1493
+ specularGlossiness.specularGlossinessTexture = loadTexture(
1494
+ loader,
1495
+ specularGlossinessTexture,
1496
+ frameState
1497
+ );
1498
+ }
1499
+ specularGlossiness.diffuseFactor = fromArray(Cartesian4, diffuseFactor);
1500
+ specularGlossiness.specularFactor = fromArray(Cartesian3, specularFactor);
1501
+ specularGlossiness.glossinessFactor = glossinessFactor;
1502
+
1503
+ return specularGlossiness;
1504
+ }
1505
+
1506
+ /**
1507
+ * Load textures and parse factors for a metallic-roughness PBR model in a glTF material
1508
+ * @param {GltfLoader} loader
1509
+ * @param {object} metallicRoughnessInfo The contents of a pbrMetallicRoughness property in the parsed glTF JSON
1510
+ * @param {FrameState} frameState
1511
+ * @returns {ModelComponents.MetallicRoughness}
1512
+ * @private
1513
+ */
1514
+ function loadMetallicRoughness(loader, metallicRoughnessInfo, frameState) {
1515
+ const {
1516
+ baseColorTexture,
1517
+ metallicRoughnessTexture,
1518
+ baseColorFactor,
1519
+ metallicFactor,
1520
+ roughnessFactor,
1521
+ } = metallicRoughnessInfo;
1522
+
1523
+ const metallicRoughness = new MetallicRoughness();
1524
+ if (defined(baseColorTexture)) {
1525
+ metallicRoughness.baseColorTexture = loadTexture(
1526
+ loader,
1527
+ baseColorTexture,
1528
+ frameState
1529
+ );
1530
+ }
1531
+ if (defined(metallicRoughnessTexture)) {
1532
+ metallicRoughness.metallicRoughnessTexture = loadTexture(
1533
+ loader,
1534
+ metallicRoughnessTexture,
1535
+ frameState
1536
+ );
1537
+ }
1538
+ metallicRoughness.baseColorFactor = fromArray(Cartesian4, baseColorFactor);
1539
+ metallicRoughness.metallicFactor = metallicFactor;
1540
+ metallicRoughness.roughnessFactor = roughnessFactor;
1541
+
1542
+ return metallicRoughness;
1543
+ }
1544
+
1545
+ function loadSpecular(loader, specularInfo, frameState) {
1546
+ const {
1547
+ specularFactor,
1548
+ specularTexture,
1549
+ specularColorFactor,
1550
+ specularColorTexture,
1551
+ } = specularInfo;
1552
+
1553
+ const specular = new Specular();
1554
+ if (defined(specularTexture)) {
1555
+ specular.specularTexture = loadTexture(loader, specularTexture, frameState);
1556
+ }
1557
+ if (defined(specularColorTexture)) {
1558
+ specular.specularColorTexture = loadTexture(
1559
+ loader,
1560
+ specularColorTexture,
1561
+ frameState
1562
+ );
1563
+ }
1564
+ specular.specularFactor = specularFactor;
1565
+ specular.specularColorFactor = fromArray(Cartesian3, specularColorFactor);
1566
+
1567
+ return specular;
1568
+ }
1569
+
1570
+ function loadAnisotropy(loader, anisotropyInfo, frameState) {
1571
+ const {
1572
+ anisotropyStrength = Anisotropy.DEFAULT_ANISOTROPY_STRENGTH,
1573
+ anisotropyRotation = Anisotropy.DEFAULT_ANISOTROPY_ROTATION,
1574
+ anisotropyTexture,
1575
+ } = anisotropyInfo;
1576
+
1577
+ const anisotropy = new Anisotropy();
1578
+ if (defined(anisotropyTexture)) {
1579
+ anisotropy.anisotropyTexture = loadTexture(
1580
+ loader,
1581
+ anisotropyTexture,
1582
+ frameState
1583
+ );
1584
+ }
1585
+ anisotropy.anisotropyStrength = anisotropyStrength;
1586
+ anisotropy.anisotropyRotation = anisotropyRotation;
1587
+
1588
+ return anisotropy;
1589
+ }
1590
+
1591
+ function loadClearcoat(loader, clearcoatInfo, frameState) {
1592
+ const {
1593
+ clearcoatFactor = Clearcoat.DEFAULT_CLEARCOAT_FACTOR,
1594
+ clearcoatTexture,
1595
+ clearcoatRoughnessFactor = Clearcoat.DEFAULT_CLEARCOAT_ROUGHNESS_FACTOR,
1596
+ clearcoatRoughnessTexture,
1597
+ clearcoatNormalTexture,
1598
+ } = clearcoatInfo;
1599
+
1600
+ const clearcoat = new Clearcoat();
1601
+ if (defined(clearcoatTexture)) {
1602
+ clearcoat.clearcoatTexture = loadTexture(
1603
+ loader,
1604
+ clearcoatTexture,
1605
+ frameState
1606
+ );
1607
+ }
1608
+ if (defined(clearcoatRoughnessTexture)) {
1609
+ clearcoat.clearcoatRoughnessTexture = loadTexture(
1610
+ loader,
1611
+ clearcoatRoughnessTexture,
1612
+ frameState
1613
+ );
1614
+ }
1615
+ if (defined(clearcoatNormalTexture)) {
1616
+ clearcoat.clearcoatNormalTexture = loadTexture(
1617
+ loader,
1618
+ clearcoatNormalTexture,
1619
+ frameState
1620
+ );
1621
+ }
1622
+ clearcoat.clearcoatFactor = clearcoatFactor;
1623
+ clearcoat.clearcoatRoughnessFactor = clearcoatRoughnessFactor;
1624
+
1625
+ return clearcoat;
1626
+ }
1627
+
1628
+ /**
1629
+ * Load textures and parse factors and flags for a glTF material
1630
+ *
1631
+ * @param {GltfLoader} loader
1632
+ * @param {object} gltfMaterial An entry from the <code>.materials</code> array in the glTF JSON
1633
+ * @param {FrameState} frameState
1634
+ * @returns {ModelComponents.Material}
1635
+ * @private
1636
+ */
1637
+ function loadMaterial(loader, gltfMaterial, frameState) {
1501
1638
  const material = new Material();
1502
1639
 
1503
1640
  const extensions = defaultValue(
@@ -1505,82 +1642,43 @@ function loadMaterial(
1505
1642
  defaultValue.EMPTY_OBJECT
1506
1643
  );
1507
1644
  const pbrSpecularGlossiness = extensions.KHR_materials_pbrSpecularGlossiness;
1645
+ const pbrSpecular = extensions.KHR_materials_specular;
1646
+ const pbrAnisotropy = extensions.KHR_materials_anisotropy;
1647
+ const pbrClearcoat = extensions.KHR_materials_clearcoat;
1508
1648
  const pbrMetallicRoughness = gltfMaterial.pbrMetallicRoughness;
1509
1649
 
1510
1650
  material.unlit = defined(extensions.KHR_materials_unlit);
1511
1651
 
1512
1652
  if (defined(pbrSpecularGlossiness)) {
1513
- const specularGlossiness = new SpecularGlossiness();
1514
- material.specularGlossiness = specularGlossiness;
1515
-
1516
- if (defined(pbrSpecularGlossiness.diffuseTexture)) {
1517
- specularGlossiness.diffuseTexture = loadTexture(
1653
+ material.specularGlossiness = loadSpecularGlossiness(
1654
+ loader,
1655
+ pbrSpecularGlossiness,
1656
+ frameState
1657
+ );
1658
+ } else {
1659
+ if (defined(pbrMetallicRoughness)) {
1660
+ material.metallicRoughness = loadMetallicRoughness(
1518
1661
  loader,
1519
- gltf,
1520
- pbrSpecularGlossiness.diffuseTexture,
1521
- supportedImageFormats,
1662
+ pbrMetallicRoughness,
1522
1663
  frameState
1523
1664
  );
1524
1665
  }
1525
- if (defined(pbrSpecularGlossiness.specularGlossinessTexture)) {
1526
- if (defined(pbrSpecularGlossiness.specularGlossinessTexture)) {
1527
- specularGlossiness.specularGlossinessTexture = loadTexture(
1528
- loader,
1529
- gltf,
1530
- pbrSpecularGlossiness.specularGlossinessTexture,
1531
- supportedImageFormats,
1532
- frameState
1533
- );
1534
- }
1666
+ if (defined(pbrSpecular) && !material.unlit) {
1667
+ material.specular = loadSpecular(loader, pbrSpecular, frameState);
1535
1668
  }
1536
- specularGlossiness.diffuseFactor = fromArray(
1537
- Cartesian4,
1538
- pbrSpecularGlossiness.diffuseFactor
1539
- );
1540
- specularGlossiness.specularFactor = fromArray(
1541
- Cartesian3,
1542
- pbrSpecularGlossiness.specularFactor
1543
- );
1544
- specularGlossiness.glossinessFactor =
1545
- pbrSpecularGlossiness.glossinessFactor;
1546
- material.pbrSpecularGlossiness = pbrSpecularGlossiness;
1547
- } else if (defined(pbrMetallicRoughness)) {
1548
- const metallicRoughness = new MetallicRoughness();
1549
-
1550
- if (defined(pbrMetallicRoughness.baseColorTexture)) {
1551
- metallicRoughness.baseColorTexture = loadTexture(
1552
- loader,
1553
- gltf,
1554
- pbrMetallicRoughness.baseColorTexture,
1555
- supportedImageFormats,
1556
- frameState
1557
- );
1669
+ if (defined(pbrAnisotropy) && !material.unlit) {
1670
+ material.anisotropy = loadAnisotropy(loader, pbrAnisotropy, frameState);
1558
1671
  }
1559
- if (defined(pbrMetallicRoughness.metallicRoughnessTexture)) {
1560
- metallicRoughness.metallicRoughnessTexture = loadTexture(
1561
- loader,
1562
- gltf,
1563
- pbrMetallicRoughness.metallicRoughnessTexture,
1564
- supportedImageFormats,
1565
- frameState
1566
- );
1672
+ if (defined(pbrClearcoat) && !material.unlit) {
1673
+ material.clearcoat = loadClearcoat(loader, pbrClearcoat, frameState);
1567
1674
  }
1568
- metallicRoughness.baseColorFactor = fromArray(
1569
- Cartesian4,
1570
- pbrMetallicRoughness.baseColorFactor
1571
- );
1572
- metallicRoughness.metallicFactor = pbrMetallicRoughness.metallicFactor;
1573
- metallicRoughness.roughnessFactor = pbrMetallicRoughness.roughnessFactor;
1574
- material.metallicRoughness = metallicRoughness;
1575
1675
  }
1576
1676
 
1577
1677
  // Top level textures
1578
1678
  if (defined(gltfMaterial.emissiveTexture)) {
1579
1679
  material.emissiveTexture = loadTexture(
1580
1680
  loader,
1581
- gltf,
1582
1681
  gltfMaterial.emissiveTexture,
1583
- supportedImageFormats,
1584
1682
  frameState
1585
1683
  );
1586
1684
  }
@@ -1588,18 +1686,14 @@ function loadMaterial(
1588
1686
  if (defined(gltfMaterial.normalTexture) && !loader._loadForClassification) {
1589
1687
  material.normalTexture = loadTexture(
1590
1688
  loader,
1591
- gltf,
1592
1689
  gltfMaterial.normalTexture,
1593
- supportedImageFormats,
1594
1690
  frameState
1595
1691
  );
1596
1692
  }
1597
1693
  if (defined(gltfMaterial.occlusionTexture)) {
1598
1694
  material.occlusionTexture = loadTexture(
1599
1695
  loader,
1600
- gltf,
1601
1696
  gltfMaterial.occlusionTexture,
1602
- supportedImageFormats,
1603
1697
  frameState
1604
1698
  );
1605
1699
  }
@@ -1679,9 +1773,7 @@ function loadFeatureIdImplicitRangeLegacy(
1679
1773
  // for EXT_mesh_features
1680
1774
  function loadFeatureIdTexture(
1681
1775
  loader,
1682
- gltf,
1683
1776
  gltfFeatureIdTexture,
1684
- supportedImageFormats,
1685
1777
  frameState,
1686
1778
  positionalLabel
1687
1779
  ) {
@@ -1696,9 +1788,7 @@ function loadFeatureIdTexture(
1696
1788
  const textureInfo = gltfFeatureIdTexture.texture;
1697
1789
  featureIdTexture.textureReader = loadTexture(
1698
1790
  loader,
1699
- gltf,
1700
1791
  textureInfo,
1701
- supportedImageFormats,
1702
1792
  frameState,
1703
1793
  Sampler.NEAREST // Feature ID textures require nearest sampling
1704
1794
  );
@@ -1720,10 +1810,8 @@ function loadFeatureIdTexture(
1720
1810
  // for backwards compatibility with EXT_feature_metadata
1721
1811
  function loadFeatureIdTextureLegacy(
1722
1812
  loader,
1723
- gltf,
1724
1813
  gltfFeatureIdTexture,
1725
1814
  featureTableId,
1726
- supportedImageFormats,
1727
1815
  frameState,
1728
1816
  featureCount,
1729
1817
  positionalLabel
@@ -1735,9 +1823,7 @@ function loadFeatureIdTextureLegacy(
1735
1823
  featureIdTexture.propertyTableId = featureTableId;
1736
1824
  featureIdTexture.textureReader = loadTexture(
1737
1825
  loader,
1738
- gltf,
1739
1826
  textureInfo,
1740
- supportedImageFormats,
1741
1827
  frameState,
1742
1828
  Sampler.NEAREST // Feature ID textures require nearest sampling
1743
1829
  );
@@ -1750,7 +1836,6 @@ function loadFeatureIdTextureLegacy(
1750
1836
 
1751
1837
  function loadMorphTarget(
1752
1838
  loader,
1753
- gltf,
1754
1839
  target,
1755
1840
  needsPostProcessing,
1756
1841
  primitiveLoadPlan,
@@ -1763,44 +1848,46 @@ function loadMorphTarget(
1763
1848
  const hasInstances = false;
1764
1849
 
1765
1850
  for (const semantic in target) {
1766
- if (target.hasOwnProperty(semantic)) {
1767
- const accessorId = target[semantic];
1851
+ if (!target.hasOwnProperty(semantic)) {
1852
+ continue;
1853
+ }
1854
+ const accessorId = target[semantic];
1768
1855
 
1769
- const semanticInfo = getSemanticInfo(
1770
- loader,
1771
- VertexAttributeSemantic,
1772
- semantic
1773
- );
1856
+ const semanticInfo = getSemanticInfo(
1857
+ loader,
1858
+ VertexAttributeSemantic,
1859
+ semantic
1860
+ );
1774
1861
 
1775
- const attributePlan = loadVertexAttribute(
1776
- loader,
1777
- gltf,
1778
- accessorId,
1779
- semanticInfo,
1780
- draco,
1781
- hasInstances,
1782
- needsPostProcessing,
1783
- frameState
1784
- );
1785
- morphTarget.attributes.push(attributePlan.attribute);
1862
+ const attributePlan = loadVertexAttribute(
1863
+ loader,
1864
+ accessorId,
1865
+ semanticInfo,
1866
+ draco,
1867
+ hasInstances,
1868
+ needsPostProcessing,
1869
+ frameState
1870
+ );
1871
+ morphTarget.attributes.push(attributePlan.attribute);
1786
1872
 
1787
- // The load plan doesn't need to distinguish morph target attributes from
1788
- // regular attributes
1789
- primitiveLoadPlan.attributePlans.push(attributePlan);
1790
- }
1873
+ // The load plan doesn't need to distinguish morph target attributes from
1874
+ // regular attributes
1875
+ primitiveLoadPlan.attributePlans.push(attributePlan);
1791
1876
  }
1792
1877
 
1793
1878
  return morphTarget;
1794
1879
  }
1795
1880
 
1796
- function loadPrimitive(
1797
- loader,
1798
- gltf,
1799
- gltfPrimitive,
1800
- hasInstances,
1801
- supportedImageFormats,
1802
- frameState
1803
- ) {
1881
+ /**
1882
+ * Load resources associated with a mesh primitive for a glTF node
1883
+ * @param {GltfLoader} loader
1884
+ * @param {object} gltfPrimitive One of the primitives in a mesh
1885
+ * @param {boolean} hasInstances True if the node using this mesh has instances
1886
+ * @param {FrameState} frameState
1887
+ * @returns {ModelComponents.Primitive}
1888
+ * @private
1889
+ */
1890
+ function loadPrimitive(loader, gltfPrimitive, hasInstances, frameState) {
1804
1891
  const primitive = new Primitive();
1805
1892
  const primitivePlan = new PrimitiveLoadPlan(primitive);
1806
1893
  loader._primitiveLoadPlans.push(primitivePlan);
@@ -1809,9 +1896,7 @@ function loadPrimitive(
1809
1896
  if (defined(materialId)) {
1810
1897
  primitive.material = loadMaterial(
1811
1898
  loader,
1812
- gltf,
1813
- gltf.materials[materialId],
1814
- supportedImageFormats,
1899
+ loader.gltfJson.materials[materialId],
1815
1900
  frameState
1816
1901
  );
1817
1902
  }
@@ -1828,7 +1913,6 @@ function loadPrimitive(
1828
1913
  primitivePlan.needsOutlines = true;
1829
1914
  primitivePlan.outlineIndices = loadPrimitiveOutline(
1830
1915
  loader,
1831
- gltf,
1832
1916
  outlineExtension,
1833
1917
  primitivePlan
1834
1918
  );
@@ -1841,52 +1925,47 @@ function loadPrimitive(
1841
1925
  const attributes = gltfPrimitive.attributes;
1842
1926
  if (defined(attributes)) {
1843
1927
  for (const semantic in attributes) {
1844
- if (attributes.hasOwnProperty(semantic)) {
1845
- const accessorId = attributes[semantic];
1846
- const semanticInfo = getSemanticInfo(
1847
- loader,
1848
- VertexAttributeSemantic,
1849
- semantic
1850
- );
1928
+ if (!attributes.hasOwnProperty(semantic)) {
1929
+ continue;
1930
+ }
1931
+ const accessorId = attributes[semantic];
1932
+ const semanticInfo = getSemanticInfo(
1933
+ loader,
1934
+ VertexAttributeSemantic,
1935
+ semantic
1936
+ );
1851
1937
 
1852
- const modelSemantic = semanticInfo.modelSemantic;
1853
- if (
1854
- loadForClassification &&
1855
- !isClassificationAttribute(modelSemantic)
1856
- ) {
1857
- continue;
1858
- }
1938
+ const modelSemantic = semanticInfo.modelSemantic;
1939
+ if (loadForClassification && !isClassificationAttribute(modelSemantic)) {
1940
+ continue;
1941
+ }
1859
1942
 
1860
- if (modelSemantic === VertexAttributeSemantic.FEATURE_ID) {
1861
- hasFeatureIds = true;
1862
- }
1943
+ if (modelSemantic === VertexAttributeSemantic.FEATURE_ID) {
1944
+ hasFeatureIds = true;
1945
+ }
1863
1946
 
1864
- const attributePlan = loadVertexAttribute(
1865
- loader,
1866
- gltf,
1867
- accessorId,
1868
- semanticInfo,
1869
- draco,
1870
- hasInstances,
1871
- needsPostProcessing,
1872
- frameState
1873
- );
1947
+ const attributePlan = loadVertexAttribute(
1948
+ loader,
1949
+ accessorId,
1950
+ semanticInfo,
1951
+ draco,
1952
+ hasInstances,
1953
+ needsPostProcessing,
1954
+ frameState
1955
+ );
1874
1956
 
1875
- primitivePlan.attributePlans.push(attributePlan);
1876
- primitive.attributes.push(attributePlan.attribute);
1877
- }
1957
+ primitivePlan.attributePlans.push(attributePlan);
1958
+ primitive.attributes.push(attributePlan.attribute);
1878
1959
  }
1879
1960
  }
1880
1961
 
1881
1962
  const targets = gltfPrimitive.targets;
1882
1963
  // Morph targets are disabled for classification models.
1883
1964
  if (defined(targets) && !loadForClassification) {
1884
- const targetsLength = targets.length;
1885
- for (let i = 0; i < targetsLength; ++i) {
1965
+ for (let i = 0; i < targets.length; ++i) {
1886
1966
  primitive.morphTargets.push(
1887
1967
  loadMorphTarget(
1888
1968
  loader,
1889
- gltf,
1890
1969
  targets[i],
1891
1970
  needsPostProcessing,
1892
1971
  primitivePlan,
@@ -1900,7 +1979,6 @@ function loadPrimitive(
1900
1979
  if (defined(indices)) {
1901
1980
  const indicesPlan = loadIndices(
1902
1981
  loader,
1903
- gltf,
1904
1982
  indices,
1905
1983
  draco,
1906
1984
  hasFeatureIds,
@@ -1925,21 +2003,12 @@ function loadPrimitive(
1925
2003
 
1926
2004
  // Load feature Ids
1927
2005
  if (defined(meshFeatures)) {
1928
- loadPrimitiveFeatures(
1929
- loader,
1930
- gltf,
1931
- primitive,
1932
- meshFeatures,
1933
- supportedImageFormats,
1934
- frameState
1935
- );
2006
+ loadPrimitiveFeatures(loader, primitive, meshFeatures, frameState);
1936
2007
  } else if (hasFeatureMetadataLegacy) {
1937
2008
  loadPrimitiveFeaturesLegacy(
1938
2009
  loader,
1939
- gltf,
1940
2010
  primitive,
1941
2011
  featureMetadataLegacy,
1942
- supportedImageFormats,
1943
2012
  frameState
1944
2013
  );
1945
2014
  }
@@ -1962,19 +2031,18 @@ function loadPrimitive(
1962
2031
  return primitive;
1963
2032
  }
1964
2033
 
1965
- function loadPrimitiveOutline(loader, gltf, outlineExtension) {
2034
+ function loadPrimitiveOutline(loader, outlineExtension) {
1966
2035
  const accessorId = outlineExtension.indices;
2036
+ const accessor = loader.gltfJson.accessors[accessorId];
1967
2037
  const useQuaternion = false;
1968
- return loadAccessor(loader, gltf, accessorId, useQuaternion);
2038
+ return loadAccessor(loader, accessor, useQuaternion);
1969
2039
  }
1970
2040
 
1971
2041
  // For EXT_mesh_features
1972
2042
  function loadPrimitiveFeatures(
1973
2043
  loader,
1974
- gltf,
1975
2044
  primitive,
1976
2045
  meshFeaturesExtension,
1977
- supportedImageFormats,
1978
2046
  frameState
1979
2047
  ) {
1980
2048
  let featureIdsArray;
@@ -1995,9 +2063,7 @@ function loadPrimitiveFeatures(
1995
2063
  if (defined(featureIds.texture)) {
1996
2064
  featureIdComponent = loadFeatureIdTexture(
1997
2065
  loader,
1998
- gltf,
1999
2066
  featureIds,
2000
- supportedImageFormats,
2001
2067
  frameState,
2002
2068
  label
2003
2069
  );
@@ -2016,22 +2082,19 @@ function loadPrimitiveFeatures(
2016
2082
  // For EXT_feature_metadata
2017
2083
  function loadPrimitiveFeaturesLegacy(
2018
2084
  loader,
2019
- gltf,
2020
2085
  primitive,
2021
2086
  metadataExtension,
2022
- supportedImageFormats,
2023
2087
  frameState
2024
2088
  ) {
2025
2089
  // For looking up the featureCount for each set of feature IDs
2026
- const featureTables = gltf.extensions.EXT_feature_metadata.featureTables;
2090
+ const { featureTables } = loader.gltfJson.extensions.EXT_feature_metadata;
2027
2091
 
2028
2092
  let nextFeatureIdIndex = 0;
2029
2093
 
2030
2094
  // Feature ID Attributes
2031
2095
  const featureIdAttributes = metadataExtension.featureIdAttributes;
2032
2096
  if (defined(featureIdAttributes)) {
2033
- const featureIdAttributesLength = featureIdAttributes.length;
2034
- for (let i = 0; i < featureIdAttributesLength; ++i) {
2097
+ for (let i = 0; i < featureIdAttributes.length; ++i) {
2035
2098
  const featureIdAttribute = featureIdAttributes[i];
2036
2099
  const featureTableId = featureIdAttribute.featureTable;
2037
2100
  const propertyTableId = loader._sortedPropertyTableIds.indexOf(
@@ -2064,8 +2127,7 @@ function loadPrimitiveFeaturesLegacy(
2064
2127
  // Feature ID Textures
2065
2128
  const featureIdTextures = metadataExtension.featureIdTextures;
2066
2129
  if (defined(featureIdTextures)) {
2067
- const featureIdTexturesLength = featureIdTextures.length;
2068
- for (let i = 0; i < featureIdTexturesLength; ++i) {
2130
+ for (let i = 0; i < featureIdTextures.length; ++i) {
2069
2131
  const featureIdTexture = featureIdTextures[i];
2070
2132
  const featureTableId = featureIdTexture.featureTable;
2071
2133
  const propertyTableId = loader._sortedPropertyTableIds.indexOf(
@@ -2077,10 +2139,8 @@ function loadPrimitiveFeaturesLegacy(
2077
2139
 
2078
2140
  const featureIdComponent = loadFeatureIdTextureLegacy(
2079
2141
  loader,
2080
- gltf,
2081
2142
  featureIdTexture,
2082
2143
  propertyTableId,
2083
- supportedImageFormats,
2084
2144
  frameState,
2085
2145
  featureCount,
2086
2146
  featureIdLabel
@@ -2124,26 +2184,26 @@ function loadPrimitiveMetadataLegacy(loader, primitive, metadataExtension) {
2124
2184
  }
2125
2185
  }
2126
2186
 
2127
- function loadInstances(loader, gltf, nodeExtensions, frameState) {
2187
+ function loadInstances(loader, nodeExtensions, frameState) {
2128
2188
  const instancingExtension = nodeExtensions.EXT_mesh_gpu_instancing;
2129
2189
 
2130
2190
  const instances = new Instances();
2131
2191
  const attributes = instancingExtension.attributes;
2132
2192
  if (defined(attributes)) {
2133
2193
  for (const semantic in attributes) {
2134
- if (attributes.hasOwnProperty(semantic)) {
2135
- const accessorId = attributes[semantic];
2136
- instances.attributes.push(
2137
- loadInstancedAttribute(
2138
- loader,
2139
- gltf,
2140
- accessorId,
2141
- attributes,
2142
- semantic,
2143
- frameState
2144
- )
2145
- );
2194
+ if (!attributes.hasOwnProperty(semantic)) {
2195
+ continue;
2146
2196
  }
2197
+ const accessorId = attributes[semantic];
2198
+ instances.attributes.push(
2199
+ loadInstancedAttribute(
2200
+ loader,
2201
+ accessorId,
2202
+ attributes,
2203
+ semantic,
2204
+ frameState
2205
+ )
2206
+ );
2147
2207
  }
2148
2208
  }
2149
2209
 
@@ -2158,7 +2218,7 @@ function loadInstances(loader, gltf, nodeExtensions, frameState) {
2158
2218
  loadInstanceFeatures(instances, instanceFeatures);
2159
2219
  } else if (defined(featureMetadataLegacy)) {
2160
2220
  loadInstanceFeaturesLegacy(
2161
- gltf,
2221
+ loader.gltfJson,
2162
2222
  instances,
2163
2223
  featureMetadataLegacy,
2164
2224
  loader._sortedPropertyTableIds
@@ -2202,8 +2262,7 @@ function loadInstanceFeaturesLegacy(
2202
2262
 
2203
2263
  const featureIdAttributes = metadataExtension.featureIdAttributes;
2204
2264
  if (defined(featureIdAttributes)) {
2205
- const featureIdAttributesLength = featureIdAttributes.length;
2206
- for (let i = 0; i < featureIdAttributesLength; ++i) {
2265
+ for (let i = 0; i < featureIdAttributes.length; ++i) {
2207
2266
  const featureIdAttribute = featureIdAttributes[i];
2208
2267
  const featureTableId = featureIdAttribute.featureTable;
2209
2268
  const propertyTableId = sortedPropertyTableIds.indexOf(featureTableId);
@@ -2231,7 +2290,15 @@ function loadInstanceFeaturesLegacy(
2231
2290
  }
2232
2291
  }
2233
2292
 
2234
- function loadNode(loader, gltf, gltfNode, supportedImageFormats, frameState) {
2293
+ /**
2294
+ * Load resources associated with one node from a glTF JSON
2295
+ * @param {GltfLoader} loader
2296
+ * @param {object} gltfNode An entry from the <code>.nodes</code> array in the glTF JSON
2297
+ * @param {FrameState} frameState
2298
+ * @returns {ModelComponents.Node}
2299
+ * @private
2300
+ */
2301
+ function loadNode(loader, gltfNode, frameState) {
2235
2302
  const node = new Node();
2236
2303
 
2237
2304
  node.name = gltfNode.name;
@@ -2254,7 +2321,7 @@ function loadNode(loader, gltf, gltfNode, supportedImageFormats, frameState) {
2254
2321
  "Models with the EXT_mesh_gpu_instancing extension cannot be used for classification."
2255
2322
  );
2256
2323
  }
2257
- node.instances = loadInstances(loader, gltf, nodeExtensions, frameState);
2324
+ node.instances = loadInstances(loader, nodeExtensions, frameState);
2258
2325
  }
2259
2326
 
2260
2327
  if (defined(articulationsExtension)) {
@@ -2263,17 +2330,14 @@ function loadNode(loader, gltf, gltfNode, supportedImageFormats, frameState) {
2263
2330
 
2264
2331
  const meshId = gltfNode.mesh;
2265
2332
  if (defined(meshId)) {
2266
- const mesh = gltf.meshes[meshId];
2333
+ const mesh = loader.gltfJson.meshes[meshId];
2267
2334
  const primitives = mesh.primitives;
2268
- const primitivesLength = primitives.length;
2269
- for (let i = 0; i < primitivesLength; ++i) {
2335
+ for (let i = 0; i < primitives.length; ++i) {
2270
2336
  node.primitives.push(
2271
2337
  loadPrimitive(
2272
2338
  loader,
2273
- gltf,
2274
2339
  primitives[i],
2275
2340
  defined(node.instances),
2276
- supportedImageFormats,
2277
2341
  frameState
2278
2342
  )
2279
2343
  );
@@ -2283,120 +2347,105 @@ function loadNode(loader, gltf, gltfNode, supportedImageFormats, frameState) {
2283
2347
  // by the mesh. If both are undefined, it will default to an array of zero weights.
2284
2348
  const morphWeights = defaultValue(gltfNode.weights, mesh.weights);
2285
2349
  const targets = node.primitives[0].morphTargets;
2286
- const targetsLength = targets.length;
2287
2350
 
2288
2351
  // Since meshes are not stored as separate components, the mesh weights will still
2289
2352
  // be stored at the node level.
2290
2353
  node.morphWeights = defined(morphWeights)
2291
2354
  ? morphWeights.slice()
2292
- : new Array(targetsLength).fill(0.0);
2355
+ : new Array(targets.length).fill(0.0);
2293
2356
  }
2294
2357
 
2295
2358
  return node;
2296
2359
  }
2297
2360
 
2298
- function loadNodes(loader, gltf, supportedImageFormats, frameState) {
2299
- if (!defined(gltf.nodes)) {
2361
+ /**
2362
+ * Load resources associated with the nodes in a glTF JSON
2363
+ * @param {GltfLoader} loader
2364
+ * @param {FrameState} frameState
2365
+ * @returns {ModelComponents.Node[]}
2366
+ * @private
2367
+ */
2368
+ function loadNodes(loader, frameState) {
2369
+ const nodeJsons = loader.gltfJson.nodes;
2370
+ if (!defined(nodeJsons)) {
2300
2371
  return [];
2301
2372
  }
2302
2373
 
2303
- let i;
2304
- let j;
2305
-
2306
- const nodesLength = gltf.nodes.length;
2307
- const nodes = new Array(nodesLength);
2308
- for (i = 0; i < nodesLength; ++i) {
2309
- const node = loadNode(
2310
- loader,
2311
- gltf,
2312
- gltf.nodes[i],
2313
- supportedImageFormats,
2314
- frameState
2315
- );
2374
+ const loadedNodes = nodeJsons.map(function (nodeJson, i) {
2375
+ const node = loadNode(loader, nodeJson, frameState);
2316
2376
  node.index = i;
2317
- nodes[i] = node;
2318
- }
2377
+ return node;
2378
+ });
2319
2379
 
2320
- for (i = 0; i < nodesLength; ++i) {
2321
- const childrenNodeIds = gltf.nodes[i].children;
2380
+ for (let i = 0; i < loadedNodes.length; ++i) {
2381
+ const childrenNodeIds = nodeJsons[i].children;
2322
2382
  if (defined(childrenNodeIds)) {
2323
- const childrenLength = childrenNodeIds.length;
2324
- for (j = 0; j < childrenLength; ++j) {
2325
- nodes[i].children.push(nodes[childrenNodeIds[j]]);
2383
+ for (let j = 0; j < childrenNodeIds.length; ++j) {
2384
+ loadedNodes[i].children.push(loadedNodes[childrenNodeIds[j]]);
2326
2385
  }
2327
2386
  }
2328
2387
  }
2329
2388
 
2330
- return nodes;
2389
+ return loadedNodes;
2331
2390
  }
2332
2391
 
2333
- function loadSkin(loader, gltf, gltfSkin, nodes) {
2392
+ function loadSkin(loader, gltfSkin, nodes) {
2334
2393
  const skin = new Skin();
2335
2394
 
2336
2395
  const jointIds = gltfSkin.joints;
2337
- const jointsLength = jointIds.length;
2338
- const joints = new Array(jointsLength);
2339
- for (let i = 0; i < jointsLength; ++i) {
2340
- joints[i] = nodes[jointIds[i]];
2341
- }
2342
- skin.joints = joints;
2396
+ skin.joints = jointIds.map((jointId) => nodes[jointId]);
2343
2397
 
2344
2398
  const inverseBindMatricesAccessorId = gltfSkin.inverseBindMatrices;
2345
2399
  if (defined(inverseBindMatricesAccessorId)) {
2346
- skin.inverseBindMatrices = loadAccessor(
2347
- loader,
2348
- gltf,
2349
- inverseBindMatricesAccessorId
2350
- );
2400
+ const accessor = loader.gltfJson.accessors[inverseBindMatricesAccessorId];
2401
+ skin.inverseBindMatrices = loadAccessor(loader, accessor);
2351
2402
  } else {
2352
- skin.inverseBindMatrices = new Array(jointsLength).fill(Matrix4.IDENTITY);
2403
+ skin.inverseBindMatrices = new Array(jointIds.length).fill(
2404
+ Matrix4.IDENTITY
2405
+ );
2353
2406
  }
2354
2407
 
2355
2408
  return skin;
2356
2409
  }
2357
2410
 
2358
- function loadSkins(loader, gltf, nodes) {
2359
- const gltfSkins = gltf.skins;
2411
+ function loadSkins(loader, nodes) {
2412
+ const skinJsons = loader.gltfJson.skins;
2360
2413
 
2361
2414
  // Skins are disabled for classification models.
2362
- if (loader._loadForClassification || !defined(gltfSkins)) {
2415
+ if (loader._loadForClassification || !defined(skinJsons)) {
2363
2416
  return [];
2364
2417
  }
2365
2418
 
2366
- const skinsLength = gltf.skins.length;
2367
- const skins = new Array(skinsLength);
2368
- for (let i = 0; i < skinsLength; ++i) {
2369
- const skin = loadSkin(loader, gltf, gltf.skins[i], nodes);
2419
+ const loadedSkins = skinJsons.map(function (skinJson, i) {
2420
+ const skin = loadSkin(loader, skinJson, nodes);
2370
2421
  skin.index = i;
2371
- skins[i] = skin;
2372
- }
2422
+ return skin;
2423
+ });
2373
2424
 
2374
- const nodesLength = nodes.length;
2375
- for (let i = 0; i < nodesLength; ++i) {
2376
- const skinId = gltf.nodes[i].skin;
2425
+ const nodeJsons = loader.gltfJson.nodes;
2426
+ for (let i = 0; i < nodes.length; ++i) {
2427
+ const skinId = nodeJsons[i].skin;
2377
2428
  if (defined(skinId)) {
2378
- nodes[i].skin = skins[skinId];
2429
+ nodes[i].skin = loadedSkins[skinId];
2379
2430
  }
2380
2431
  }
2381
2432
 
2382
- return skins;
2433
+ return loadedSkins;
2383
2434
  }
2384
2435
 
2385
2436
  async function loadStructuralMetadata(
2386
2437
  loader,
2387
- gltf,
2388
2438
  extension,
2389
2439
  extensionLegacy,
2390
- supportedImageFormats,
2391
2440
  frameState
2392
2441
  ) {
2393
2442
  const structuralMetadataLoader = new GltfStructuralMetadataLoader({
2394
- gltf: gltf,
2443
+ gltf: loader.gltfJson,
2395
2444
  extension: extension,
2396
2445
  extensionLegacy: extensionLegacy,
2397
2446
  gltfResource: loader._gltfResource,
2398
2447
  baseResource: loader._baseResource,
2399
- supportedImageFormats: supportedImageFormats,
2448
+ supportedImageFormats: loader._supportedImageFormats,
2400
2449
  frameState: frameState,
2401
2450
  asynchronous: loader._asynchronous,
2402
2451
  });
@@ -2404,11 +2453,12 @@ async function loadStructuralMetadata(
2404
2453
  return structuralMetadataLoader.load();
2405
2454
  }
2406
2455
 
2407
- function loadAnimationSampler(loader, gltf, gltfSampler) {
2456
+ function loadAnimationSampler(loader, gltfSampler) {
2408
2457
  const animationSampler = new AnimationSampler();
2458
+ const accessors = loader.gltfJson.accessors;
2409
2459
 
2410
- const inputAccessorId = gltfSampler.input;
2411
- animationSampler.input = loadAccessor(loader, gltf, inputAccessorId);
2460
+ const inputAccessor = accessors[gltfSampler.input];
2461
+ animationSampler.input = loadAccessor(loader, inputAccessor);
2412
2462
 
2413
2463
  const gltfInterpolation = gltfSampler.interpolation;
2414
2464
  animationSampler.interpolation = defaultValue(
@@ -2416,8 +2466,8 @@ function loadAnimationSampler(loader, gltf, gltfSampler) {
2416
2466
  InterpolationType.LINEAR
2417
2467
  );
2418
2468
 
2419
- const outputAccessorId = gltfSampler.output;
2420
- animationSampler.output = loadAccessor(loader, gltf, outputAccessorId, true);
2469
+ const outputAccessor = accessors[gltfSampler.output];
2470
+ animationSampler.output = loadAccessor(loader, outputAccessor, true);
2421
2471
 
2422
2472
  return animationSampler;
2423
2473
  }
@@ -2450,29 +2500,19 @@ function loadAnimationChannel(gltfChannel, samplers, nodes) {
2450
2500
  return animationChannel;
2451
2501
  }
2452
2502
 
2453
- function loadAnimation(loader, gltf, gltfAnimation, nodes) {
2454
- let i;
2455
-
2503
+ function loadAnimation(loader, animationJson, nodes) {
2456
2504
  const animation = new Animation();
2457
- animation.name = gltfAnimation.name;
2505
+ animation.name = animationJson.name;
2458
2506
 
2459
- const gltfSamplers = gltfAnimation.samplers;
2460
- const samplersLength = gltfSamplers.length;
2461
-
2462
- const samplers = new Array(samplersLength);
2463
- for (i = 0; i < samplersLength; i++) {
2464
- const sampler = loadAnimationSampler(loader, gltf, gltfSamplers[i]);
2507
+ const samplers = animationJson.samplers.map(function (samplerJson, i) {
2508
+ const sampler = loadAnimationSampler(loader, samplerJson);
2465
2509
  sampler.index = i;
2466
- samplers[i] = sampler;
2467
- }
2468
-
2469
- const gltfChannels = gltfAnimation.channels;
2470
- const channelsLength = gltfChannels.length;
2510
+ return sampler;
2511
+ });
2471
2512
 
2472
- const channels = new Array(channelsLength);
2473
- for (i = 0; i < channelsLength; i++) {
2474
- channels[i] = loadAnimationChannel(gltfChannels[i], samplers, nodes);
2475
- }
2513
+ const channels = animationJson.channels.map(function (channelJson) {
2514
+ return loadAnimationChannel(channelJson, samplers, nodes);
2515
+ });
2476
2516
 
2477
2517
  animation.samplers = samplers;
2478
2518
  animation.channels = channels;
@@ -2480,21 +2520,19 @@ function loadAnimation(loader, gltf, gltfAnimation, nodes) {
2480
2520
  return animation;
2481
2521
  }
2482
2522
 
2483
- function loadAnimations(loader, gltf, nodes) {
2484
- const gltfAnimations = gltf.animations;
2523
+ function loadAnimations(loader, nodes) {
2524
+ const animationJsons = loader.gltfJson.animations;
2485
2525
 
2486
2526
  // Animations are disabled for classification models.
2487
- if (loader._loadForClassification || !defined(gltfAnimations)) {
2527
+ if (loader._loadForClassification || !defined(animationJsons)) {
2488
2528
  return [];
2489
2529
  }
2490
2530
 
2491
- const animationsLength = gltf.animations.length;
2492
- const animations = new Array(animationsLength);
2493
- for (let i = 0; i < animationsLength; ++i) {
2494
- const animation = loadAnimation(loader, gltf, gltf.animations[i], nodes);
2531
+ const animations = animationJsons.map(function (animationJson, i) {
2532
+ const animation = loadAnimation(loader, animationJson, nodes);
2495
2533
  animation.index = i;
2496
- animations[i] = animation;
2497
- }
2534
+ return animation;
2535
+ });
2498
2536
 
2499
2537
  return animations;
2500
2538
  }
@@ -2513,45 +2551,20 @@ function loadArticulationStage(gltfStage) {
2513
2551
  return stage;
2514
2552
  }
2515
2553
 
2516
- function loadArticulation(gltfArticulation) {
2554
+ function loadArticulation(articulationJson) {
2517
2555
  const articulation = new Articulation();
2518
- articulation.name = gltfArticulation.name;
2519
-
2520
- const gltfStages = gltfArticulation.stages;
2521
- const gltfStagesLength = gltfStages.length;
2522
-
2523
- const stages = new Array(gltfStagesLength);
2524
- for (let i = 0; i < gltfStagesLength; i++) {
2525
- const stage = loadArticulationStage(gltfStages[i]);
2526
- stages[i] = stage;
2527
- }
2528
-
2529
- articulation.stages = stages;
2530
-
2556
+ articulation.name = articulationJson.name;
2557
+ articulation.stages = articulationJson.stages.map(loadArticulationStage);
2531
2558
  return articulation;
2532
2559
  }
2533
2560
 
2534
2561
  function loadArticulations(gltf) {
2535
2562
  const extensions = defaultValue(gltf.extensions, defaultValue.EMPTY_OBJECT);
2536
- const articulationsExtension = extensions.AGI_articulations;
2537
-
2538
- if (!defined(articulationsExtension)) {
2563
+ const articulationJsons = extensions.AGI_articulations?.articulations;
2564
+ if (!defined(articulationJsons)) {
2539
2565
  return [];
2540
2566
  }
2541
-
2542
- const gltfArticulations = articulationsExtension.articulations;
2543
- if (!defined(gltfArticulations)) {
2544
- return [];
2545
- }
2546
-
2547
- const gltfArticulationsLength = gltfArticulations.length;
2548
- const articulations = new Array(gltfArticulationsLength);
2549
- for (let i = 0; i < gltfArticulationsLength; i++) {
2550
- const articulation = loadArticulation(gltfArticulations[i]);
2551
- articulations[i] = articulation;
2552
- }
2553
-
2554
- return articulations;
2567
+ return articulationJsons.map(loadArticulation);
2555
2568
  }
2556
2569
 
2557
2570
  function getSceneNodeIds(gltf) {
@@ -2575,7 +2588,23 @@ function loadScene(gltf, nodes) {
2575
2588
 
2576
2589
  const scratchCenter = new Cartesian3();
2577
2590
 
2578
- function parse(loader, gltf, supportedImageFormats, frameState) {
2591
+ /**
2592
+ * Parse the glTF which populates the loaders arrays. Loading promises will be created, and will
2593
+ * resolve once the loaders are ready (i.e. all external resources
2594
+ * have been fetched and all GPU resources have been created). Loaders that
2595
+ * create GPU resources need to be processed every frame until they become
2596
+ * ready since the JobScheduler is not able to execute all jobs in a single
2597
+ * frame. Any promise failures are collected, and will be handled synchronously in process().
2598
+ * Also note that it's fine to call process before a loader is ready to process or
2599
+ * after it has failed; nothing will happen.
2600
+ *
2601
+ * @param {GltfLoader} loader
2602
+ * @param {FrameState} frameState
2603
+ * @returns {Promise} A Promise that resolves when all loaders are ready
2604
+ * @private
2605
+ */
2606
+ function parse(loader, frameState) {
2607
+ const gltf = loader.gltfJson;
2579
2608
  const extensions = defaultValue(gltf.extensions, defaultValue.EMPTY_OBJECT);
2580
2609
  const structuralMetadataExtension = extensions.EXT_structural_metadata;
2581
2610
  const featureMetadataExtensionLegacy = extensions.EXT_feature_metadata;
@@ -2598,9 +2627,9 @@ function parse(loader, gltf, supportedImageFormats, frameState) {
2598
2627
  loader._sortedFeatureTextureIds = Object.keys(allFeatureTextureIds).sort();
2599
2628
  }
2600
2629
 
2601
- const nodes = loadNodes(loader, gltf, supportedImageFormats, frameState);
2602
- const skins = loadSkins(loader, gltf, nodes);
2603
- const animations = loadAnimations(loader, gltf, nodes);
2630
+ const nodes = loadNodes(loader, frameState);
2631
+ const skins = loadSkins(loader, nodes);
2632
+ const animations = loadAnimations(loader, nodes);
2604
2633
  const articulations = loadArticulations(gltf);
2605
2634
  const scene = loadScene(gltf, nodes);
2606
2635
 
@@ -2645,10 +2674,8 @@ function parse(loader, gltf, supportedImageFormats, frameState) {
2645
2674
  ) {
2646
2675
  const promise = loadStructuralMetadata(
2647
2676
  loader,
2648
- gltf,
2649
2677
  structuralMetadataExtension,
2650
2678
  featureMetadataExtensionLegacy,
2651
- supportedImageFormats,
2652
2679
  frameState
2653
2680
  );
2654
2681
  loader._loaderPromises.push(promise);
@@ -2669,8 +2696,7 @@ function parse(loader, gltf, supportedImageFormats, frameState) {
2669
2696
 
2670
2697
  function unloadTextures(loader) {
2671
2698
  const textureLoaders = loader._textureLoaders;
2672
- const textureLoadersLength = textureLoaders.length;
2673
- for (let i = 0; i < textureLoadersLength; ++i) {
2699
+ for (let i = 0; i < textureLoaders.length; ++i) {
2674
2700
  textureLoaders[i] =
2675
2701
  !textureLoaders[i].isDestroyed() &&
2676
2702
  ResourceCache.unload(textureLoaders[i]);
@@ -2680,8 +2706,7 @@ function unloadTextures(loader) {
2680
2706
 
2681
2707
  function unloadBufferViewLoaders(loader) {
2682
2708
  const bufferViewLoaders = loader._bufferViewLoaders;
2683
- const bufferViewLoadersLength = bufferViewLoaders.length;
2684
- for (let i = 0; i < bufferViewLoadersLength; ++i) {
2709
+ for (let i = 0; i < bufferViewLoaders.length; ++i) {
2685
2710
  bufferViewLoaders[i] =
2686
2711
  !bufferViewLoaders[i].isDestroyed() &&
2687
2712
  ResourceCache.unload(bufferViewLoaders[i]);
@@ -2691,8 +2716,7 @@ function unloadBufferViewLoaders(loader) {
2691
2716
 
2692
2717
  function unloadGeometry(loader) {
2693
2718
  const geometryLoaders = loader._geometryLoaders;
2694
- const geometryLoadersLength = geometryLoaders.length;
2695
- for (let i = 0; i < geometryLoadersLength; ++i) {
2719
+ for (let i = 0; i < geometryLoaders.length; ++i) {
2696
2720
  geometryLoaders[i] =
2697
2721
  !geometryLoaders[i].isDestroyed() &&
2698
2722
  ResourceCache.unload(geometryLoaders[i]);
@@ -2702,8 +2726,7 @@ function unloadGeometry(loader) {
2702
2726
 
2703
2727
  function unloadGeneratedAttributes(loader) {
2704
2728
  const buffers = loader._postProcessBuffers;
2705
- const length = buffers.length;
2706
- for (let i = 0; i < length; i++) {
2729
+ for (let i = 0; i < buffers.length; i++) {
2707
2730
  const buffer = buffers[i];
2708
2731
  if (!buffer.isDestroyed()) {
2709
2732
  buffer.destroy();