vc-spaces365-threejs 0.180.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 (1120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -0
  3. package/build/three.cjs +77750 -0
  4. package/build/three.core.js +58846 -0
  5. package/build/three.core.min.js +6 -0
  6. package/build/three.module.js +18484 -0
  7. package/build/three.module.min.js +6 -0
  8. package/build/three.tsl.js +636 -0
  9. package/build/three.tsl.min.js +6 -0
  10. package/build/three.webgpu.js +77332 -0
  11. package/build/three.webgpu.min.js +6 -0
  12. package/build/three.webgpu.nodes.js +77103 -0
  13. package/build/three.webgpu.nodes.min.js +6 -0
  14. package/examples/fonts/LICENSE +13 -0
  15. package/examples/fonts/README.md +11 -0
  16. package/examples/fonts/droid/NOTICE +190 -0
  17. package/examples/fonts/droid/README.txt +18 -0
  18. package/examples/fonts/droid/droid_sans_bold.typeface.json +1 -0
  19. package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +1 -0
  20. package/examples/fonts/droid/droid_sans_regular.typeface.json +1 -0
  21. package/examples/fonts/droid/droid_serif_bold.typeface.json +1 -0
  22. package/examples/fonts/droid/droid_serif_regular.typeface.json +1 -0
  23. package/examples/fonts/gentilis_bold.typeface.json +1 -0
  24. package/examples/fonts/gentilis_regular.typeface.json +1 -0
  25. package/examples/fonts/helvetiker_bold.typeface.json +1 -0
  26. package/examples/fonts/helvetiker_regular.typeface.json +1 -0
  27. package/examples/fonts/optimer_bold.typeface.json +1 -0
  28. package/examples/fonts/optimer_regular.typeface.json +1 -0
  29. package/examples/fonts/ttf/README.md +9 -0
  30. package/examples/fonts/ttf/kenpixel.ttf +0 -0
  31. package/examples/jsm/Addons.js +285 -0
  32. package/examples/jsm/animation/AnimationClipCreator.js +168 -0
  33. package/examples/jsm/animation/CCDIKSolver.js +591 -0
  34. package/examples/jsm/capabilities/WebGL.js +113 -0
  35. package/examples/jsm/capabilities/WebGPU.js +59 -0
  36. package/examples/jsm/controls/ArcballControls.js +3536 -0
  37. package/examples/jsm/controls/DragControls.js +452 -0
  38. package/examples/jsm/controls/FirstPersonControls.js +447 -0
  39. package/examples/jsm/controls/FlyControls.js +380 -0
  40. package/examples/jsm/controls/MapControls.js +62 -0
  41. package/examples/jsm/controls/OrbitControls.js +1860 -0
  42. package/examples/jsm/controls/PointerLockControls.js +264 -0
  43. package/examples/jsm/controls/TrackballControls.js +1001 -0
  44. package/examples/jsm/controls/TransformControls.js +1918 -0
  45. package/examples/jsm/csm/CSM.js +597 -0
  46. package/examples/jsm/csm/CSMFrustum.js +209 -0
  47. package/examples/jsm/csm/CSMHelper.js +243 -0
  48. package/examples/jsm/csm/CSMShader.js +307 -0
  49. package/examples/jsm/csm/CSMShadowNode.js +599 -0
  50. package/examples/jsm/curves/CurveExtras.js +694 -0
  51. package/examples/jsm/curves/NURBSCurve.js +155 -0
  52. package/examples/jsm/curves/NURBSSurface.js +98 -0
  53. package/examples/jsm/curves/NURBSUtils.js +532 -0
  54. package/examples/jsm/curves/NURBSVolume.js +82 -0
  55. package/examples/jsm/effects/AnaglyphEffect.js +179 -0
  56. package/examples/jsm/effects/AsciiEffect.js +310 -0
  57. package/examples/jsm/effects/OutlineEffect.js +489 -0
  58. package/examples/jsm/effects/ParallaxBarrierEffect.js +155 -0
  59. package/examples/jsm/effects/StereoEffect.js +91 -0
  60. package/examples/jsm/environments/DebugEnvironment.js +102 -0
  61. package/examples/jsm/environments/RoomEnvironment.js +182 -0
  62. package/examples/jsm/exporters/DRACOExporter.js +311 -0
  63. package/examples/jsm/exporters/EXRExporter.js +618 -0
  64. package/examples/jsm/exporters/GLTFExporter.js +3595 -0
  65. package/examples/jsm/exporters/KTX2Exporter.js +347 -0
  66. package/examples/jsm/exporters/OBJExporter.js +308 -0
  67. package/examples/jsm/exporters/PLYExporter.js +562 -0
  68. package/examples/jsm/exporters/STLExporter.js +221 -0
  69. package/examples/jsm/exporters/USDZExporter.js +1228 -0
  70. package/examples/jsm/geometries/BoxLineGeometry.js +92 -0
  71. package/examples/jsm/geometries/ConvexGeometry.js +72 -0
  72. package/examples/jsm/geometries/DecalGeometry.js +420 -0
  73. package/examples/jsm/geometries/ParametricFunctions.js +100 -0
  74. package/examples/jsm/geometries/ParametricGeometry.js +172 -0
  75. package/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  76. package/examples/jsm/geometries/TeapotGeometry.js +689 -0
  77. package/examples/jsm/geometries/TextGeometry.js +83 -0
  78. package/examples/jsm/helpers/LightProbeHelper.js +165 -0
  79. package/examples/jsm/helpers/LightProbeHelperGPU.js +102 -0
  80. package/examples/jsm/helpers/OctreeHelper.js +109 -0
  81. package/examples/jsm/helpers/PositionalAudioHelper.js +169 -0
  82. package/examples/jsm/helpers/RapierHelper.js +59 -0
  83. package/examples/jsm/helpers/RectAreaLightHelper.js +118 -0
  84. package/examples/jsm/helpers/TextureHelper.js +265 -0
  85. package/examples/jsm/helpers/TextureHelperGPU.js +214 -0
  86. package/examples/jsm/helpers/VertexNormalsHelper.js +155 -0
  87. package/examples/jsm/helpers/VertexTangentsHelper.js +133 -0
  88. package/examples/jsm/helpers/ViewHelper.js +422 -0
  89. package/examples/jsm/interactive/HTMLMesh.js +605 -0
  90. package/examples/jsm/interactive/InteractiveGroup.js +224 -0
  91. package/examples/jsm/interactive/SelectionBox.js +294 -0
  92. package/examples/jsm/interactive/SelectionHelper.js +150 -0
  93. package/examples/jsm/libs/ammo.wasm.js +822 -0
  94. package/examples/jsm/libs/ammo.wasm.wasm +0 -0
  95. package/examples/jsm/libs/basis/README.md +46 -0
  96. package/examples/jsm/libs/basis/basis_transcoder.js +19 -0
  97. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  98. package/examples/jsm/libs/chevrotain.module.min.js +141 -0
  99. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  100. package/examples/jsm/libs/draco/README.md +32 -0
  101. package/examples/jsm/libs/draco/draco_decoder.js +34 -0
  102. package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
  103. package/examples/jsm/libs/draco/draco_encoder.js +33 -0
  104. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -0
  105. package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -0
  106. package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
  107. package/examples/jsm/libs/draco/gltf/draco_encoder.js +33 -0
  108. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
  109. package/examples/jsm/libs/ecsy.module.js +1792 -0
  110. package/examples/jsm/libs/fflate.module.js +2672 -0
  111. package/examples/jsm/libs/ktx-parse.module.js +1 -0
  112. package/examples/jsm/libs/lil-gui.module.min.js +8 -0
  113. package/examples/jsm/libs/lottie_canvas.module.js +14849 -0
  114. package/examples/jsm/libs/meshopt_decoder.module.js +195 -0
  115. package/examples/jsm/libs/mikktspace.module.js +128 -0
  116. package/examples/jsm/libs/motion-controllers.module.js +397 -0
  117. package/examples/jsm/libs/opentype.module.js +14506 -0
  118. package/examples/jsm/libs/potpack.module.js +125 -0
  119. package/examples/jsm/libs/rhino3dm/rhino3dm.js +21 -0
  120. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +16 -0
  121. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  122. package/examples/jsm/libs/stats.module.js +167 -0
  123. package/examples/jsm/libs/surfaceNet.js +201 -0
  124. package/examples/jsm/libs/tween.module.js +876 -0
  125. package/examples/jsm/libs/utif.module.js +1665 -0
  126. package/examples/jsm/libs/zstddec.module.js +1 -0
  127. package/examples/jsm/lighting/TiledLighting.js +42 -0
  128. package/examples/jsm/lights/LightProbeGenerator.js +337 -0
  129. package/examples/jsm/lights/RectAreaLightTexturesLib.js +127 -0
  130. package/examples/jsm/lights/RectAreaLightUniformsLib.js +40 -0
  131. package/examples/jsm/lines/Line2.js +56 -0
  132. package/examples/jsm/lines/LineGeometry.js +157 -0
  133. package/examples/jsm/lines/LineMaterial.js +697 -0
  134. package/examples/jsm/lines/LineSegments2.js +426 -0
  135. package/examples/jsm/lines/LineSegmentsGeometry.js +298 -0
  136. package/examples/jsm/lines/Wireframe.js +108 -0
  137. package/examples/jsm/lines/WireframeGeometry2.js +49 -0
  138. package/examples/jsm/lines/webgpu/Line2.js +46 -0
  139. package/examples/jsm/lines/webgpu/LineSegments2.js +411 -0
  140. package/examples/jsm/lines/webgpu/Wireframe.js +86 -0
  141. package/examples/jsm/loaders/3DMLoader.js +1835 -0
  142. package/examples/jsm/loaders/3MFLoader.js +1621 -0
  143. package/examples/jsm/loaders/AMFLoader.js +541 -0
  144. package/examples/jsm/loaders/BVHLoader.js +484 -0
  145. package/examples/jsm/loaders/ColladaLoader.js +4155 -0
  146. package/examples/jsm/loaders/DDSLoader.js +385 -0
  147. package/examples/jsm/loaders/DRACOLoader.js +688 -0
  148. package/examples/jsm/loaders/EXRLoader.js +2784 -0
  149. package/examples/jsm/loaders/FBXLoader.js +4382 -0
  150. package/examples/jsm/loaders/FontLoader.js +242 -0
  151. package/examples/jsm/loaders/GCodeLoader.js +292 -0
  152. package/examples/jsm/loaders/GLTFLoader.js +4890 -0
  153. package/examples/jsm/loaders/HDRCubeTextureLoader.js +164 -0
  154. package/examples/jsm/loaders/HDRLoader.js +486 -0
  155. package/examples/jsm/loaders/IESLoader.js +379 -0
  156. package/examples/jsm/loaders/KMZLoader.js +163 -0
  157. package/examples/jsm/loaders/KTX2Loader.js +1228 -0
  158. package/examples/jsm/loaders/KTXLoader.js +197 -0
  159. package/examples/jsm/loaders/LDrawLoader.js +2519 -0
  160. package/examples/jsm/loaders/LUT3dlLoader.js +205 -0
  161. package/examples/jsm/loaders/LUTCubeLoader.js +190 -0
  162. package/examples/jsm/loaders/LUTImageLoader.js +190 -0
  163. package/examples/jsm/loaders/LWOLoader.js +1079 -0
  164. package/examples/jsm/loaders/LottieLoader.js +130 -0
  165. package/examples/jsm/loaders/MD2Loader.js +435 -0
  166. package/examples/jsm/loaders/MDDLoader.js +147 -0
  167. package/examples/jsm/loaders/MTLLoader.js +593 -0
  168. package/examples/jsm/loaders/MaterialXLoader.js +1087 -0
  169. package/examples/jsm/loaders/NRRDLoader.js +718 -0
  170. package/examples/jsm/loaders/OBJLoader.js +955 -0
  171. package/examples/jsm/loaders/PCDLoader.js +618 -0
  172. package/examples/jsm/loaders/PDBLoader.js +272 -0
  173. package/examples/jsm/loaders/PLYLoader.js +805 -0
  174. package/examples/jsm/loaders/PVRLoader.js +270 -0
  175. package/examples/jsm/loaders/RGBELoader.js +18 -0
  176. package/examples/jsm/loaders/STLLoader.js +421 -0
  177. package/examples/jsm/loaders/SVGLoader.js +3267 -0
  178. package/examples/jsm/loaders/TDSLoader.js +1144 -0
  179. package/examples/jsm/loaders/TGALoader.js +540 -0
  180. package/examples/jsm/loaders/TIFFLoader.js +59 -0
  181. package/examples/jsm/loaders/TTFLoader.js +261 -0
  182. package/examples/jsm/loaders/USDLoader.js +219 -0
  183. package/examples/jsm/loaders/USDZLoader.js +16 -0
  184. package/examples/jsm/loaders/UltraHDRLoader.js +630 -0
  185. package/examples/jsm/loaders/VOXLoader.js +376 -0
  186. package/examples/jsm/loaders/VRMLLoader.js +3569 -0
  187. package/examples/jsm/loaders/VTKLoader.js +1276 -0
  188. package/examples/jsm/loaders/XYZLoader.js +143 -0
  189. package/examples/jsm/loaders/lwo/IFFParser.js +1217 -0
  190. package/examples/jsm/loaders/lwo/LWO2Parser.js +414 -0
  191. package/examples/jsm/loaders/lwo/LWO3Parser.js +373 -0
  192. package/examples/jsm/loaders/usd/USDAParser.js +741 -0
  193. package/examples/jsm/loaders/usd/USDCParser.js +17 -0
  194. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +183 -0
  195. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +154 -0
  196. package/examples/jsm/materials/MeshGouraudMaterial.js +434 -0
  197. package/examples/jsm/materials/MeshPostProcessingMaterial.js +167 -0
  198. package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
  199. package/examples/jsm/math/Capsule.js +159 -0
  200. package/examples/jsm/math/ColorConverter.js +58 -0
  201. package/examples/jsm/math/ColorSpaces.js +147 -0
  202. package/examples/jsm/math/ConvexHull.js +1695 -0
  203. package/examples/jsm/math/ImprovedNoise.js +88 -0
  204. package/examples/jsm/math/Lut.js +317 -0
  205. package/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  206. package/examples/jsm/math/OBB.js +535 -0
  207. package/examples/jsm/math/Octree.js +692 -0
  208. package/examples/jsm/math/SimplexNoise.js +470 -0
  209. package/examples/jsm/misc/ConvexObjectBreaker.js +539 -0
  210. package/examples/jsm/misc/GPUComputationRenderer.js +506 -0
  211. package/examples/jsm/misc/Gyroscope.js +78 -0
  212. package/examples/jsm/misc/MD2Character.js +391 -0
  213. package/examples/jsm/misc/MD2CharacterComplex.js +740 -0
  214. package/examples/jsm/misc/MorphAnimMesh.js +119 -0
  215. package/examples/jsm/misc/MorphBlendMesh.js +425 -0
  216. package/examples/jsm/misc/ProgressiveLightMap.js +370 -0
  217. package/examples/jsm/misc/ProgressiveLightMapGPU.js +322 -0
  218. package/examples/jsm/misc/RollerCoaster.js +623 -0
  219. package/examples/jsm/misc/TubePainter.js +256 -0
  220. package/examples/jsm/misc/Volume.js +521 -0
  221. package/examples/jsm/misc/VolumeSlice.js +276 -0
  222. package/examples/jsm/modifiers/CurveModifier.js +374 -0
  223. package/examples/jsm/modifiers/CurveModifierGPU.js +256 -0
  224. package/examples/jsm/modifiers/EdgeSplitModifier.js +299 -0
  225. package/examples/jsm/modifiers/SimplifyModifier.js +632 -0
  226. package/examples/jsm/modifiers/TessellateModifier.js +340 -0
  227. package/examples/jsm/objects/GroundedSkybox.js +69 -0
  228. package/examples/jsm/objects/Lensflare.js +489 -0
  229. package/examples/jsm/objects/LensflareMesh.js +376 -0
  230. package/examples/jsm/objects/MarchingCubes.js +1261 -0
  231. package/examples/jsm/objects/Reflector.js +338 -0
  232. package/examples/jsm/objects/ReflectorForSSRPass.js +393 -0
  233. package/examples/jsm/objects/Refractor.js +389 -0
  234. package/examples/jsm/objects/ShadowMesh.js +130 -0
  235. package/examples/jsm/objects/Sky.js +237 -0
  236. package/examples/jsm/objects/SkyMesh.js +243 -0
  237. package/examples/jsm/objects/Water.js +373 -0
  238. package/examples/jsm/objects/Water2.js +401 -0
  239. package/examples/jsm/objects/Water2Mesh.js +199 -0
  240. package/examples/jsm/objects/WaterMesh.js +196 -0
  241. package/examples/jsm/offscreen/jank.js +45 -0
  242. package/examples/jsm/offscreen/offscreen.js +8 -0
  243. package/examples/jsm/offscreen/scene.js +86 -0
  244. package/examples/jsm/physics/AmmoPhysics.js +354 -0
  245. package/examples/jsm/physics/JoltPhysics.js +330 -0
  246. package/examples/jsm/physics/RapierPhysics.js +432 -0
  247. package/examples/jsm/postprocessing/AfterimagePass.js +185 -0
  248. package/examples/jsm/postprocessing/BloomPass.js +274 -0
  249. package/examples/jsm/postprocessing/BokehPass.js +218 -0
  250. package/examples/jsm/postprocessing/ClearPass.js +97 -0
  251. package/examples/jsm/postprocessing/CubeTexturePass.js +146 -0
  252. package/examples/jsm/postprocessing/DotScreenPass.js +114 -0
  253. package/examples/jsm/postprocessing/EffectComposer.js +363 -0
  254. package/examples/jsm/postprocessing/FXAAPass.js +40 -0
  255. package/examples/jsm/postprocessing/FilmPass.js +113 -0
  256. package/examples/jsm/postprocessing/GTAOPass.js +727 -0
  257. package/examples/jsm/postprocessing/GlitchPass.js +177 -0
  258. package/examples/jsm/postprocessing/HalftonePass.js +134 -0
  259. package/examples/jsm/postprocessing/LUTPass.js +138 -0
  260. package/examples/jsm/postprocessing/MaskPass.js +195 -0
  261. package/examples/jsm/postprocessing/OutlinePass.js +776 -0
  262. package/examples/jsm/postprocessing/OutputPass.js +139 -0
  263. package/examples/jsm/postprocessing/Pass.js +191 -0
  264. package/examples/jsm/postprocessing/RenderPass.js +183 -0
  265. package/examples/jsm/postprocessing/RenderPixelatedPass.js +314 -0
  266. package/examples/jsm/postprocessing/RenderTransitionPass.js +267 -0
  267. package/examples/jsm/postprocessing/SAOPass.js +407 -0
  268. package/examples/jsm/postprocessing/SMAAPass.js +230 -0
  269. package/examples/jsm/postprocessing/SSAARenderPass.js +313 -0
  270. package/examples/jsm/postprocessing/SSAOPass.js +527 -0
  271. package/examples/jsm/postprocessing/SSRPass.js +856 -0
  272. package/examples/jsm/postprocessing/SavePass.js +132 -0
  273. package/examples/jsm/postprocessing/ShaderPass.js +135 -0
  274. package/examples/jsm/postprocessing/TAARenderPass.js +243 -0
  275. package/examples/jsm/postprocessing/TexturePass.js +131 -0
  276. package/examples/jsm/postprocessing/UnrealBloomPass.js +492 -0
  277. package/examples/jsm/renderers/CSS2DRenderer.js +317 -0
  278. package/examples/jsm/renderers/CSS3DRenderer.js +453 -0
  279. package/examples/jsm/renderers/Projector.js +936 -0
  280. package/examples/jsm/renderers/SVGRenderer.js +685 -0
  281. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +96 -0
  282. package/examples/jsm/shaders/AfterimageShader.js +63 -0
  283. package/examples/jsm/shaders/BasicShader.js +36 -0
  284. package/examples/jsm/shaders/BleachBypassShader.js +68 -0
  285. package/examples/jsm/shaders/BlendShader.js +56 -0
  286. package/examples/jsm/shaders/BokehShader.js +151 -0
  287. package/examples/jsm/shaders/BokehShader2.js +404 -0
  288. package/examples/jsm/shaders/BrightnessContrastShader.js +62 -0
  289. package/examples/jsm/shaders/ColorCorrectionShader.js +59 -0
  290. package/examples/jsm/shaders/ColorifyShader.js +57 -0
  291. package/examples/jsm/shaders/ConvolutionShader.js +74 -0
  292. package/examples/jsm/shaders/CopyShader.js +52 -0
  293. package/examples/jsm/shaders/DOFMipMapShader.js +63 -0
  294. package/examples/jsm/shaders/DepthLimitedBlurShader.js +180 -0
  295. package/examples/jsm/shaders/DigitalGlitch.js +104 -0
  296. package/examples/jsm/shaders/DotScreenShader.js +75 -0
  297. package/examples/jsm/shaders/ExposureShader.js +51 -0
  298. package/examples/jsm/shaders/FXAAShader.js +298 -0
  299. package/examples/jsm/shaders/FilmShader.js +72 -0
  300. package/examples/jsm/shaders/FocusShader.js +94 -0
  301. package/examples/jsm/shaders/FreiChenShader.js +103 -0
  302. package/examples/jsm/shaders/GTAOShader.js +421 -0
  303. package/examples/jsm/shaders/GammaCorrectionShader.js +52 -0
  304. package/examples/jsm/shaders/GodRaysShader.js +333 -0
  305. package/examples/jsm/shaders/HalftoneShader.js +321 -0
  306. package/examples/jsm/shaders/HorizontalBlurShader.js +68 -0
  307. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +70 -0
  308. package/examples/jsm/shaders/HueSaturationShader.js +74 -0
  309. package/examples/jsm/shaders/KaleidoShader.js +65 -0
  310. package/examples/jsm/shaders/LuminosityHighPassShader.js +68 -0
  311. package/examples/jsm/shaders/LuminosityShader.js +54 -0
  312. package/examples/jsm/shaders/MirrorShader.js +62 -0
  313. package/examples/jsm/shaders/NormalMapShader.js +60 -0
  314. package/examples/jsm/shaders/OutputShader.js +103 -0
  315. package/examples/jsm/shaders/PoissonDenoiseShader.js +235 -0
  316. package/examples/jsm/shaders/RGBShiftShader.js +61 -0
  317. package/examples/jsm/shaders/SAOShader.js +188 -0
  318. package/examples/jsm/shaders/SMAAShader.js +489 -0
  319. package/examples/jsm/shaders/SSAOShader.js +321 -0
  320. package/examples/jsm/shaders/SSRShader.js +395 -0
  321. package/examples/jsm/shaders/SepiaShader.js +57 -0
  322. package/examples/jsm/shaders/SobelOperatorShader.js +98 -0
  323. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +95 -0
  324. package/examples/jsm/shaders/TechnicolorShader.js +51 -0
  325. package/examples/jsm/shaders/ToonShader.js +349 -0
  326. package/examples/jsm/shaders/TriangleBlurShader.js +79 -0
  327. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +62 -0
  328. package/examples/jsm/shaders/VelocityShader.js +137 -0
  329. package/examples/jsm/shaders/VerticalBlurShader.js +66 -0
  330. package/examples/jsm/shaders/VerticalTiltShiftShader.js +70 -0
  331. package/examples/jsm/shaders/VignetteShader.js +56 -0
  332. package/examples/jsm/shaders/VolumeShader.js +298 -0
  333. package/examples/jsm/shaders/WaterRefractionShader.js +106 -0
  334. package/examples/jsm/textures/FlakesTexture.js +54 -0
  335. package/examples/jsm/textures/IESTexture.js +101 -0
  336. package/examples/jsm/transpiler/AST.js +631 -0
  337. package/examples/jsm/transpiler/GLSLDecoder.js +1171 -0
  338. package/examples/jsm/transpiler/Linker.js +327 -0
  339. package/examples/jsm/transpiler/ShaderToyDecoder.js +49 -0
  340. package/examples/jsm/transpiler/TSLEncoder.js +933 -0
  341. package/examples/jsm/transpiler/Transpiler.js +67 -0
  342. package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
  343. package/examples/jsm/transpiler/WGSLEncoder.js +812 -0
  344. package/examples/jsm/tsl/display/AfterImageNode.js +242 -0
  345. package/examples/jsm/tsl/display/AnaglyphPassNode.js +107 -0
  346. package/examples/jsm/tsl/display/AnamorphicNode.js +281 -0
  347. package/examples/jsm/tsl/display/BleachBypass.js +33 -0
  348. package/examples/jsm/tsl/display/BloomNode.js +520 -0
  349. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +207 -0
  350. package/examples/jsm/tsl/display/DenoiseNode.js +332 -0
  351. package/examples/jsm/tsl/display/DepthOfFieldNode.js +547 -0
  352. package/examples/jsm/tsl/display/DotScreenNode.js +104 -0
  353. package/examples/jsm/tsl/display/FXAANode.js +365 -0
  354. package/examples/jsm/tsl/display/FilmNode.js +101 -0
  355. package/examples/jsm/tsl/display/GTAONode.js +530 -0
  356. package/examples/jsm/tsl/display/GaussianBlurNode.js +378 -0
  357. package/examples/jsm/tsl/display/LensflareNode.js +279 -0
  358. package/examples/jsm/tsl/display/Lut3DNode.js +109 -0
  359. package/examples/jsm/tsl/display/MotionBlur.js +33 -0
  360. package/examples/jsm/tsl/display/OutlineNode.js +751 -0
  361. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +89 -0
  362. package/examples/jsm/tsl/display/PixelationPassNode.js +334 -0
  363. package/examples/jsm/tsl/display/RGBShiftNode.js +96 -0
  364. package/examples/jsm/tsl/display/SMAANode.js +768 -0
  365. package/examples/jsm/tsl/display/SSAAPassNode.js +358 -0
  366. package/examples/jsm/tsl/display/SSGINode.js +650 -0
  367. package/examples/jsm/tsl/display/SSRNode.js +654 -0
  368. package/examples/jsm/tsl/display/Sepia.js +24 -0
  369. package/examples/jsm/tsl/display/SobelOperatorNode.js +168 -0
  370. package/examples/jsm/tsl/display/StereoCompositePassNode.js +185 -0
  371. package/examples/jsm/tsl/display/StereoPassNode.js +120 -0
  372. package/examples/jsm/tsl/display/TRAANode.js +461 -0
  373. package/examples/jsm/tsl/display/TransitionNode.js +141 -0
  374. package/examples/jsm/tsl/display/boxBlur.js +64 -0
  375. package/examples/jsm/tsl/display/hashBlur.js +53 -0
  376. package/examples/jsm/tsl/lighting/TiledLightsNode.js +422 -0
  377. package/examples/jsm/tsl/math/Bayer.js +34 -0
  378. package/examples/jsm/tsl/shadows/TileShadowNode.js +456 -0
  379. package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +212 -0
  380. package/examples/jsm/tsl/utils/Raymarching.js +70 -0
  381. package/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
  382. package/examples/jsm/utils/CameraUtils.js +82 -0
  383. package/examples/jsm/utils/GeometryCompressionUtils.js +547 -0
  384. package/examples/jsm/utils/GeometryUtils.js +226 -0
  385. package/examples/jsm/utils/LDrawUtils.js +211 -0
  386. package/examples/jsm/utils/SceneOptimizer.js +458 -0
  387. package/examples/jsm/utils/SceneUtils.js +363 -0
  388. package/examples/jsm/utils/ShadowMapViewer.js +230 -0
  389. package/examples/jsm/utils/ShadowMapViewerGPU.js +233 -0
  390. package/examples/jsm/utils/SkeletonUtils.js +490 -0
  391. package/examples/jsm/utils/SortUtils.js +175 -0
  392. package/examples/jsm/utils/UVsDebug.js +173 -0
  393. package/examples/jsm/utils/WebGLTextureUtils.js +115 -0
  394. package/examples/jsm/utils/WebGPUTextureUtils.js +81 -0
  395. package/examples/jsm/utils/WorkerPool.js +167 -0
  396. package/examples/jsm/webxr/ARButton.js +251 -0
  397. package/examples/jsm/webxr/OculusHandModel.js +194 -0
  398. package/examples/jsm/webxr/OculusHandPointerModel.js +539 -0
  399. package/examples/jsm/webxr/Text2D.js +52 -0
  400. package/examples/jsm/webxr/VRButton.js +264 -0
  401. package/examples/jsm/webxr/XRButton.js +246 -0
  402. package/examples/jsm/webxr/XRControllerModelFactory.js +403 -0
  403. package/examples/jsm/webxr/XREstimatedLight.js +254 -0
  404. package/examples/jsm/webxr/XRHandMeshModel.js +151 -0
  405. package/examples/jsm/webxr/XRHandModelFactory.js +197 -0
  406. package/examples/jsm/webxr/XRHandPrimitiveModel.js +147 -0
  407. package/examples/jsm/webxr/XRPlanes.js +118 -0
  408. package/package.json +134 -0
  409. package/src/Three.Core.js +185 -0
  410. package/src/Three.Legacy.js +0 -0
  411. package/src/Three.TSL.js +629 -0
  412. package/src/Three.WebGPU.Nodes.js +24 -0
  413. package/src/Three.WebGPU.js +26 -0
  414. package/src/Three.js +9 -0
  415. package/src/animation/AnimationAction.js +932 -0
  416. package/src/animation/AnimationClip.js +628 -0
  417. package/src/animation/AnimationMixer.js +854 -0
  418. package/src/animation/AnimationObjectGroup.js +411 -0
  419. package/src/animation/AnimationUtils.js +506 -0
  420. package/src/animation/KeyframeTrack.js +597 -0
  421. package/src/animation/PropertyBinding.js +794 -0
  422. package/src/animation/PropertyMixer.js +385 -0
  423. package/src/animation/tracks/BooleanKeyframeTrack.js +55 -0
  424. package/src/animation/tracks/ColorKeyframeTrack.js +36 -0
  425. package/src/animation/tracks/NumberKeyframeTrack.js +36 -0
  426. package/src/animation/tracks/QuaternionKeyframeTrack.js +51 -0
  427. package/src/animation/tracks/StringKeyframeTrack.js +55 -0
  428. package/src/animation/tracks/VectorKeyframeTrack.js +36 -0
  429. package/src/audio/Audio.js +778 -0
  430. package/src/audio/AudioAnalyser.js +97 -0
  431. package/src/audio/AudioContext.js +40 -0
  432. package/src/audio/AudioListener.js +216 -0
  433. package/src/audio/PositionalAudio.js +253 -0
  434. package/src/cameras/ArrayCamera.js +54 -0
  435. package/src/cameras/Camera.js +130 -0
  436. package/src/cameras/CubeCamera.js +239 -0
  437. package/src/cameras/OrthographicCamera.js +245 -0
  438. package/src/cameras/PerspectiveCamera.js +407 -0
  439. package/src/cameras/StereoCamera.js +146 -0
  440. package/src/constants.js +1675 -0
  441. package/src/core/BufferAttribute.js +1044 -0
  442. package/src/core/BufferGeometry.js +1446 -0
  443. package/src/core/Clock.js +128 -0
  444. package/src/core/EventDispatcher.js +131 -0
  445. package/src/core/GLBufferAttribute.js +171 -0
  446. package/src/core/InstancedBufferAttribute.js +68 -0
  447. package/src/core/InstancedBufferGeometry.js +60 -0
  448. package/src/core/InstancedInterleavedBuffer.js +74 -0
  449. package/src/core/InterleavedBuffer.js +291 -0
  450. package/src/core/InterleavedBufferAttribute.js +549 -0
  451. package/src/core/Layers.js +121 -0
  452. package/src/core/Object3D.js +1619 -0
  453. package/src/core/Raycaster.js +262 -0
  454. package/src/core/RenderTarget.js +392 -0
  455. package/src/core/RenderTarget3D.js +48 -0
  456. package/src/core/Timer.js +184 -0
  457. package/src/core/Uniform.js +46 -0
  458. package/src/core/UniformsGroup.js +180 -0
  459. package/src/extras/Controls.js +120 -0
  460. package/src/extras/DataUtils.js +217 -0
  461. package/src/extras/Earcut.js +22 -0
  462. package/src/extras/ImageUtils.js +137 -0
  463. package/src/extras/PMREMGenerator.js +966 -0
  464. package/src/extras/ShapeUtils.js +114 -0
  465. package/src/extras/TextureUtils.js +293 -0
  466. package/src/extras/core/Curve.js +517 -0
  467. package/src/extras/core/CurvePath.js +296 -0
  468. package/src/extras/core/Interpolations.js +105 -0
  469. package/src/extras/core/Path.js +329 -0
  470. package/src/extras/core/Shape.js +165 -0
  471. package/src/extras/core/ShapePath.js +367 -0
  472. package/src/extras/curves/ArcCurve.js +39 -0
  473. package/src/extras/curves/CatmullRomCurve3.js +326 -0
  474. package/src/extras/curves/CubicBezierCurve.js +145 -0
  475. package/src/extras/curves/CubicBezierCurve3.js +129 -0
  476. package/src/extras/curves/Curves.js +10 -0
  477. package/src/extras/curves/EllipseCurve.js +258 -0
  478. package/src/extras/curves/LineCurve.js +128 -0
  479. package/src/extras/curves/LineCurve3.js +128 -0
  480. package/src/extras/curves/QuadraticBezierCurve.js +133 -0
  481. package/src/extras/curves/QuadraticBezierCurve3.js +118 -0
  482. package/src/extras/curves/SplineCurve.js +145 -0
  483. package/src/extras/lib/earcut.js +685 -0
  484. package/src/geometries/BoxGeometry.js +218 -0
  485. package/src/geometries/CapsuleGeometry.js +217 -0
  486. package/src/geometries/CircleGeometry.js +141 -0
  487. package/src/geometries/ConeGeometry.js +69 -0
  488. package/src/geometries/CylinderGeometry.js +332 -0
  489. package/src/geometries/DodecahedronGeometry.js +98 -0
  490. package/src/geometries/EdgesGeometry.js +180 -0
  491. package/src/geometries/ExtrudeGeometry.js +909 -0
  492. package/src/geometries/Geometries.js +21 -0
  493. package/src/geometries/IcosahedronGeometry.js +74 -0
  494. package/src/geometries/LatheGeometry.js +229 -0
  495. package/src/geometries/OctahedronGeometry.js +69 -0
  496. package/src/geometries/PlaneGeometry.js +132 -0
  497. package/src/geometries/PolyhedronGeometry.js +348 -0
  498. package/src/geometries/RingGeometry.js +164 -0
  499. package/src/geometries/ShapeGeometry.js +232 -0
  500. package/src/geometries/SphereGeometry.js +174 -0
  501. package/src/geometries/TetrahedronGeometry.js +66 -0
  502. package/src/geometries/TorusGeometry.js +155 -0
  503. package/src/geometries/TorusKnotGeometry.js +205 -0
  504. package/src/geometries/TubeGeometry.js +252 -0
  505. package/src/geometries/WireframeGeometry.js +179 -0
  506. package/src/helpers/ArrowHelper.js +171 -0
  507. package/src/helpers/AxesHelper.js +96 -0
  508. package/src/helpers/Box3Helper.js +83 -0
  509. package/src/helpers/BoxHelper.js +149 -0
  510. package/src/helpers/CameraHelper.js +342 -0
  511. package/src/helpers/DirectionalLightHelper.js +145 -0
  512. package/src/helpers/GridHelper.js +82 -0
  513. package/src/helpers/HemisphereLightHelper.js +127 -0
  514. package/src/helpers/PlaneHelper.js +96 -0
  515. package/src/helpers/PointLightHelper.js +135 -0
  516. package/src/helpers/PolarGridHelper.js +126 -0
  517. package/src/helpers/SkeletonHelper.js +194 -0
  518. package/src/helpers/SpotLightHelper.js +151 -0
  519. package/src/lights/AmbientLight.js +42 -0
  520. package/src/lights/DirectionalLight.js +100 -0
  521. package/src/lights/DirectionalLightShadow.js +31 -0
  522. package/src/lights/HemisphereLight.js +66 -0
  523. package/src/lights/Light.js +95 -0
  524. package/src/lights/LightProbe.js +90 -0
  525. package/src/lights/LightShadow.js +338 -0
  526. package/src/lights/PointLight.js +116 -0
  527. package/src/lights/PointLightShadow.js +117 -0
  528. package/src/lights/RectAreaLight.js +115 -0
  529. package/src/lights/SpotLight.js +173 -0
  530. package/src/lights/SpotLightShadow.js +80 -0
  531. package/src/lights/webgpu/IESSpotLight.js +46 -0
  532. package/src/lights/webgpu/ProjectorLight.js +46 -0
  533. package/src/loaders/AnimationLoader.js +98 -0
  534. package/src/loaders/AudioLoader.js +98 -0
  535. package/src/loaders/BufferGeometryLoader.js +242 -0
  536. package/src/loaders/Cache.js +87 -0
  537. package/src/loaders/CompressedTextureLoader.js +167 -0
  538. package/src/loaders/CubeTextureLoader.js +103 -0
  539. package/src/loaders/DataTextureLoader.js +172 -0
  540. package/src/loaders/FileLoader.js +368 -0
  541. package/src/loaders/IESLoader.js +327 -0
  542. package/src/loaders/ImageBitmapLoader.js +220 -0
  543. package/src/loaders/ImageLoader.js +168 -0
  544. package/src/loaders/Loader.js +216 -0
  545. package/src/loaders/LoaderUtils.js +59 -0
  546. package/src/loaders/LoadingManager.js +307 -0
  547. package/src/loaders/MaterialLoader.js +438 -0
  548. package/src/loaders/ObjectLoader.js +1264 -0
  549. package/src/loaders/TextureLoader.js +74 -0
  550. package/src/loaders/nodes/NodeLoader.js +194 -0
  551. package/src/loaders/nodes/NodeMaterialLoader.js +108 -0
  552. package/src/loaders/nodes/NodeObjectLoader.js +151 -0
  553. package/src/materials/LineBasicMaterial.js +122 -0
  554. package/src/materials/LineDashedMaterial.js +86 -0
  555. package/src/materials/Material.js +1015 -0
  556. package/src/materials/Materials.js +39 -0
  557. package/src/materials/MeshBasicMaterial.js +249 -0
  558. package/src/materials/MeshDepthMaterial.js +147 -0
  559. package/src/materials/MeshDistanceMaterial.js +119 -0
  560. package/src/materials/MeshLambertMaterial.js +392 -0
  561. package/src/materials/MeshMatcapMaterial.js +223 -0
  562. package/src/materials/MeshNormalMaterial.js +174 -0
  563. package/src/materials/MeshPhongMaterial.js +411 -0
  564. package/src/materials/MeshPhysicalMaterial.js +535 -0
  565. package/src/materials/MeshStandardMaterial.js +424 -0
  566. package/src/materials/MeshToonMaterial.js +320 -0
  567. package/src/materials/PointsMaterial.js +139 -0
  568. package/src/materials/RawShaderMaterial.js +42 -0
  569. package/src/materials/ShaderMaterial.js +394 -0
  570. package/src/materials/ShadowMaterial.js +91 -0
  571. package/src/materials/SpriteMaterial.js +136 -0
  572. package/src/materials/nodes/Line2NodeMaterial.js +542 -0
  573. package/src/materials/nodes/LineBasicNodeMaterial.js +46 -0
  574. package/src/materials/nodes/LineDashedNodeMaterial.js +132 -0
  575. package/src/materials/nodes/MeshBasicNodeMaterial.js +134 -0
  576. package/src/materials/nodes/MeshLambertNodeMaterial.js +82 -0
  577. package/src/materials/nodes/MeshMatcapNodeMaterial.js +77 -0
  578. package/src/materials/nodes/MeshNormalNodeMaterial.js +67 -0
  579. package/src/materials/nodes/MeshPhongNodeMaterial.js +141 -0
  580. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +518 -0
  581. package/src/materials/nodes/MeshSSSNodeMaterial.js +175 -0
  582. package/src/materials/nodes/MeshStandardNodeMaterial.js +186 -0
  583. package/src/materials/nodes/MeshToonNodeMaterial.js +66 -0
  584. package/src/materials/nodes/NodeMaterial.js +1271 -0
  585. package/src/materials/nodes/NodeMaterials.js +21 -0
  586. package/src/materials/nodes/PointsNodeMaterial.js +211 -0
  587. package/src/materials/nodes/ShadowNodeMaterial.js +76 -0
  588. package/src/materials/nodes/SpriteNodeMaterial.js +186 -0
  589. package/src/materials/nodes/VolumeNodeMaterial.js +81 -0
  590. package/src/materials/nodes/manager/NodeMaterialObserver.js +612 -0
  591. package/src/math/Box2.js +381 -0
  592. package/src/math/Box3.js +805 -0
  593. package/src/math/Color.js +967 -0
  594. package/src/math/ColorManagement.js +215 -0
  595. package/src/math/Cylindrical.js +120 -0
  596. package/src/math/Euler.js +449 -0
  597. package/src/math/Frustum.js +285 -0
  598. package/src/math/FrustumArray.js +258 -0
  599. package/src/math/Interpolant.js +320 -0
  600. package/src/math/Line3.js +336 -0
  601. package/src/math/MathUtils.js +751 -0
  602. package/src/math/Matrix2.js +124 -0
  603. package/src/math/Matrix3.js +613 -0
  604. package/src/math/Matrix4.js +1301 -0
  605. package/src/math/Plane.js +367 -0
  606. package/src/math/Quaternion.js +943 -0
  607. package/src/math/Ray.js +655 -0
  608. package/src/math/Sphere.js +420 -0
  609. package/src/math/Spherical.js +147 -0
  610. package/src/math/SphericalHarmonics3.js +341 -0
  611. package/src/math/Triangle.js +539 -0
  612. package/src/math/Vector2.js +866 -0
  613. package/src/math/Vector3.js +1261 -0
  614. package/src/math/Vector4.js +1063 -0
  615. package/src/math/interpolants/CubicInterpolant.js +159 -0
  616. package/src/math/interpolants/DiscreteInterpolant.js +34 -0
  617. package/src/math/interpolants/LinearInterpolant.js +51 -0
  618. package/src/math/interpolants/QuaternionLinearInterpolant.js +48 -0
  619. package/src/nodes/Nodes.js +148 -0
  620. package/src/nodes/TSL.js +173 -0
  621. package/src/nodes/accessors/AccessorsUtils.js +53 -0
  622. package/src/nodes/accessors/Arrays.js +68 -0
  623. package/src/nodes/accessors/BatchNode.js +163 -0
  624. package/src/nodes/accessors/Bitangent.js +82 -0
  625. package/src/nodes/accessors/BufferAttributeNode.js +340 -0
  626. package/src/nodes/accessors/BufferNode.js +101 -0
  627. package/src/nodes/accessors/BuiltinNode.js +63 -0
  628. package/src/nodes/accessors/Camera.js +282 -0
  629. package/src/nodes/accessors/ClippingNode.js +255 -0
  630. package/src/nodes/accessors/CubeTextureNode.js +190 -0
  631. package/src/nodes/accessors/InstanceNode.js +244 -0
  632. package/src/nodes/accessors/InstancedMeshNode.js +50 -0
  633. package/src/nodes/accessors/Lights.js +129 -0
  634. package/src/nodes/accessors/MaterialNode.js +775 -0
  635. package/src/nodes/accessors/MaterialProperties.js +59 -0
  636. package/src/nodes/accessors/MaterialReferenceNode.js +85 -0
  637. package/src/nodes/accessors/ModelNode.js +184 -0
  638. package/src/nodes/accessors/ModelViewProjectionNode.js +13 -0
  639. package/src/nodes/accessors/MorphNode.js +310 -0
  640. package/src/nodes/accessors/Normal.js +243 -0
  641. package/src/nodes/accessors/Object3DNode.js +268 -0
  642. package/src/nodes/accessors/PointUVNode.js +55 -0
  643. package/src/nodes/accessors/Position.js +74 -0
  644. package/src/nodes/accessors/ReferenceBaseNode.js +357 -0
  645. package/src/nodes/accessors/ReferenceNode.js +424 -0
  646. package/src/nodes/accessors/ReflectVector.js +36 -0
  647. package/src/nodes/accessors/RendererReferenceNode.js +79 -0
  648. package/src/nodes/accessors/SceneNode.js +145 -0
  649. package/src/nodes/accessors/SkinningNode.js +327 -0
  650. package/src/nodes/accessors/StorageBufferNode.js +416 -0
  651. package/src/nodes/accessors/StorageTextureNode.js +242 -0
  652. package/src/nodes/accessors/Tangent.js +70 -0
  653. package/src/nodes/accessors/TangentUtils.js +46 -0
  654. package/src/nodes/accessors/Texture3DNode.js +199 -0
  655. package/src/nodes/accessors/TextureBicubic.js +92 -0
  656. package/src/nodes/accessors/TextureNode.js +894 -0
  657. package/src/nodes/accessors/TextureSizeNode.js +77 -0
  658. package/src/nodes/accessors/UV.js +11 -0
  659. package/src/nodes/accessors/UniformArrayNode.js +348 -0
  660. package/src/nodes/accessors/UserDataNode.js +77 -0
  661. package/src/nodes/accessors/VelocityNode.js +224 -0
  662. package/src/nodes/accessors/VertexColorNode.js +110 -0
  663. package/src/nodes/code/CodeNode.js +181 -0
  664. package/src/nodes/code/ExpressionNode.js +68 -0
  665. package/src/nodes/code/FunctionCallNode.js +187 -0
  666. package/src/nodes/code/FunctionNode.js +183 -0
  667. package/src/nodes/code/ScriptableNode.js +726 -0
  668. package/src/nodes/code/ScriptableValueNode.js +253 -0
  669. package/src/nodes/core/ArrayNode.js +154 -0
  670. package/src/nodes/core/AssignNode.js +202 -0
  671. package/src/nodes/core/AttributeNode.js +168 -0
  672. package/src/nodes/core/BypassNode.js +93 -0
  673. package/src/nodes/core/CacheNode.js +100 -0
  674. package/src/nodes/core/ConstNode.js +67 -0
  675. package/src/nodes/core/ContextNode.js +190 -0
  676. package/src/nodes/core/IndexNode.js +164 -0
  677. package/src/nodes/core/InputNode.js +136 -0
  678. package/src/nodes/core/LightingModel.js +77 -0
  679. package/src/nodes/core/MRTNode.js +150 -0
  680. package/src/nodes/core/Node.js +959 -0
  681. package/src/nodes/core/NodeAttribute.js +53 -0
  682. package/src/nodes/core/NodeBuilder.js +2968 -0
  683. package/src/nodes/core/NodeCache.js +75 -0
  684. package/src/nodes/core/NodeCode.js +46 -0
  685. package/src/nodes/core/NodeFrame.js +306 -0
  686. package/src/nodes/core/NodeFunction.js +69 -0
  687. package/src/nodes/core/NodeFunctionInput.js +61 -0
  688. package/src/nodes/core/NodeParser.js +23 -0
  689. package/src/nodes/core/NodeUniform.js +91 -0
  690. package/src/nodes/core/NodeUtils.js +480 -0
  691. package/src/nodes/core/NodeVar.js +60 -0
  692. package/src/nodes/core/NodeVarying.js +63 -0
  693. package/src/nodes/core/OutputStructNode.js +103 -0
  694. package/src/nodes/core/ParameterNode.js +94 -0
  695. package/src/nodes/core/PropertyNode.js +344 -0
  696. package/src/nodes/core/StackNode.js +376 -0
  697. package/src/nodes/core/StructNode.js +120 -0
  698. package/src/nodes/core/StructType.js +13 -0
  699. package/src/nodes/core/StructTypeNode.js +154 -0
  700. package/src/nodes/core/SubBuildNode.js +89 -0
  701. package/src/nodes/core/TempNode.js +88 -0
  702. package/src/nodes/core/UniformGroupNode.js +137 -0
  703. package/src/nodes/core/UniformNode.js +243 -0
  704. package/src/nodes/core/VarNode.js +284 -0
  705. package/src/nodes/core/VaryingNode.js +227 -0
  706. package/src/nodes/core/constants.js +68 -0
  707. package/src/nodes/display/BlendModes.js +235 -0
  708. package/src/nodes/display/BumpMapNode.js +117 -0
  709. package/src/nodes/display/ColorAdjustment.js +141 -0
  710. package/src/nodes/display/ColorSpaceFunctions.js +54 -0
  711. package/src/nodes/display/ColorSpaceNode.js +164 -0
  712. package/src/nodes/display/FrontFacingNode.js +102 -0
  713. package/src/nodes/display/NormalMapNode.js +118 -0
  714. package/src/nodes/display/PassNode.js +905 -0
  715. package/src/nodes/display/PosterizeNode.js +65 -0
  716. package/src/nodes/display/RenderOutputNode.js +124 -0
  717. package/src/nodes/display/ScreenNode.js +290 -0
  718. package/src/nodes/display/ToneMappingFunctions.js +242 -0
  719. package/src/nodes/display/ToneMappingNode.js +121 -0
  720. package/src/nodes/display/ToonOutlinePassNode.js +183 -0
  721. package/src/nodes/display/ViewportDepthNode.js +294 -0
  722. package/src/nodes/display/ViewportDepthTextureNode.js +67 -0
  723. package/src/nodes/display/ViewportSharedTextureNode.js +73 -0
  724. package/src/nodes/display/ViewportTextureNode.js +228 -0
  725. package/src/nodes/fog/Fog.js +114 -0
  726. package/src/nodes/functions/BSDF/BRDF_GGX.js +55 -0
  727. package/src/nodes/functions/BSDF/BRDF_Lambert.js +9 -0
  728. package/src/nodes/functions/BSDF/BRDF_Sheen.js +57 -0
  729. package/src/nodes/functions/BSDF/DFGApprox.js +30 -0
  730. package/src/nodes/functions/BSDF/D_GGX.js +23 -0
  731. package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +28 -0
  732. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +13 -0
  733. package/src/nodes/functions/BSDF/F_Schlick.js +16 -0
  734. package/src/nodes/functions/BSDF/LTC.js +175 -0
  735. package/src/nodes/functions/BSDF/Schlick_to_F0.js +21 -0
  736. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +26 -0
  737. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +29 -0
  738. package/src/nodes/functions/BasicLightingModel.js +100 -0
  739. package/src/nodes/functions/PhongLightingModel.js +99 -0
  740. package/src/nodes/functions/PhysicalLightingModel.js +796 -0
  741. package/src/nodes/functions/ShadowMaskModel.js +58 -0
  742. package/src/nodes/functions/ToonLightingModel.js +70 -0
  743. package/src/nodes/functions/VolumetricLightingModel.js +183 -0
  744. package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
  745. package/src/nodes/functions/material/getGeometryRoughness.js +19 -0
  746. package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
  747. package/src/nodes/functions/material/getRoughness.js +18 -0
  748. package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
  749. package/src/nodes/geometry/RangeNode.js +172 -0
  750. package/src/nodes/gpgpu/AtomicFunctionNode.js +274 -0
  751. package/src/nodes/gpgpu/BarrierNode.js +89 -0
  752. package/src/nodes/gpgpu/ComputeBuiltinNode.js +228 -0
  753. package/src/nodes/gpgpu/ComputeNode.js +273 -0
  754. package/src/nodes/gpgpu/SubgroupFunctionNode.js +430 -0
  755. package/src/nodes/gpgpu/WorkgroupInfoNode.js +234 -0
  756. package/src/nodes/lighting/AONode.js +45 -0
  757. package/src/nodes/lighting/AmbientLightNode.js +35 -0
  758. package/src/nodes/lighting/AnalyticLightNode.js +256 -0
  759. package/src/nodes/lighting/BasicEnvironmentNode.js +49 -0
  760. package/src/nodes/lighting/BasicLightMapNode.js +49 -0
  761. package/src/nodes/lighting/DirectionalLightNode.js +39 -0
  762. package/src/nodes/lighting/EnvironmentNode.js +153 -0
  763. package/src/nodes/lighting/HemisphereLightNode.js +87 -0
  764. package/src/nodes/lighting/IESSpotLightNode.js +49 -0
  765. package/src/nodes/lighting/IrradianceNode.js +44 -0
  766. package/src/nodes/lighting/LightProbeNode.js +73 -0
  767. package/src/nodes/lighting/LightUtils.js +25 -0
  768. package/src/nodes/lighting/LightingContextNode.js +115 -0
  769. package/src/nodes/lighting/LightingNode.js +36 -0
  770. package/src/nodes/lighting/LightsNode.js +455 -0
  771. package/src/nodes/lighting/PointLightNode.js +102 -0
  772. package/src/nodes/lighting/PointShadowNode.js +306 -0
  773. package/src/nodes/lighting/ProjectorLightNode.js +91 -0
  774. package/src/nodes/lighting/RectAreaLightNode.js +133 -0
  775. package/src/nodes/lighting/ShadowBaseNode.js +81 -0
  776. package/src/nodes/lighting/ShadowFilterNode.js +274 -0
  777. package/src/nodes/lighting/ShadowNode.js +745 -0
  778. package/src/nodes/lighting/SpotLightNode.js +168 -0
  779. package/src/nodes/materialx/DISCLAIMER.md +199 -0
  780. package/src/nodes/materialx/MaterialXNodes.js +197 -0
  781. package/src/nodes/materialx/lib/mx_hsv.js +127 -0
  782. package/src/nodes/materialx/lib/mx_noise.js +1491 -0
  783. package/src/nodes/materialx/lib/mx_transform_color.js +23 -0
  784. package/src/nodes/math/BitcastNode.js +156 -0
  785. package/src/nodes/math/ConditionalNode.js +245 -0
  786. package/src/nodes/math/Hash.js +21 -0
  787. package/src/nodes/math/MathNode.js +1167 -0
  788. package/src/nodes/math/MathUtils.js +54 -0
  789. package/src/nodes/math/OperatorNode.js +751 -0
  790. package/src/nodes/math/TriNoise3D.js +71 -0
  791. package/src/nodes/parsers/GLSLNodeFunction.js +168 -0
  792. package/src/nodes/parsers/GLSLNodeParser.js +25 -0
  793. package/src/nodes/pmrem/PMREMNode.js +397 -0
  794. package/src/nodes/pmrem/PMREMUtils.js +288 -0
  795. package/src/nodes/procedural/Checker.js +22 -0
  796. package/src/nodes/shapes/Shapes.js +33 -0
  797. package/src/nodes/tsl/TSLBase.js +35 -0
  798. package/src/nodes/tsl/TSLCore.js +1209 -0
  799. package/src/nodes/utils/ArrayElementNode.js +77 -0
  800. package/src/nodes/utils/ConvertNode.js +100 -0
  801. package/src/nodes/utils/CubeMapNode.js +237 -0
  802. package/src/nodes/utils/DebugNode.js +83 -0
  803. package/src/nodes/utils/Discard.js +24 -0
  804. package/src/nodes/utils/EquirectUV.js +27 -0
  805. package/src/nodes/utils/EventNode.js +83 -0
  806. package/src/nodes/utils/FlipNode.js +106 -0
  807. package/src/nodes/utils/FunctionOverloadingNode.js +152 -0
  808. package/src/nodes/utils/JoinNode.js +117 -0
  809. package/src/nodes/utils/LoopNode.js +354 -0
  810. package/src/nodes/utils/MatcapUV.js +22 -0
  811. package/src/nodes/utils/MaxMipLevelNode.js +103 -0
  812. package/src/nodes/utils/MemberNode.js +120 -0
  813. package/src/nodes/utils/Oscillators.js +41 -0
  814. package/src/nodes/utils/Packing.js +21 -0
  815. package/src/nodes/utils/PostProcessingUtils.js +95 -0
  816. package/src/nodes/utils/RTTNode.js +279 -0
  817. package/src/nodes/utils/ReflectorNode.js +623 -0
  818. package/src/nodes/utils/RemapNode.js +125 -0
  819. package/src/nodes/utils/RotateNode.js +103 -0
  820. package/src/nodes/utils/SampleNode.js +91 -0
  821. package/src/nodes/utils/SetNode.js +108 -0
  822. package/src/nodes/utils/SplitNode.js +179 -0
  823. package/src/nodes/utils/SpriteSheetUVNode.js +90 -0
  824. package/src/nodes/utils/SpriteUtils.js +63 -0
  825. package/src/nodes/utils/StorageArrayElementNode.js +143 -0
  826. package/src/nodes/utils/Timer.js +26 -0
  827. package/src/nodes/utils/TriplanarTextures.js +65 -0
  828. package/src/nodes/utils/UVUtils.js +39 -0
  829. package/src/nodes/utils/ViewportUtils.js +26 -0
  830. package/src/objects/BatchedMesh.js +1654 -0
  831. package/src/objects/Bone.js +41 -0
  832. package/src/objects/ClippingGroup.js +68 -0
  833. package/src/objects/Group.js +41 -0
  834. package/src/objects/InstancedMesh.js +395 -0
  835. package/src/objects/LOD.js +329 -0
  836. package/src/objects/Line.js +329 -0
  837. package/src/objects/LineLoop.js +37 -0
  838. package/src/objects/LineSegments.js +74 -0
  839. package/src/objects/Mesh.js +496 -0
  840. package/src/objects/Points.js +228 -0
  841. package/src/objects/Skeleton.js +383 -0
  842. package/src/objects/SkinnedMesh.js +352 -0
  843. package/src/objects/Sprite.js +245 -0
  844. package/src/renderers/WebGL3DRenderTarget.js +48 -0
  845. package/src/renderers/WebGLArrayRenderTarget.js +48 -0
  846. package/src/renderers/WebGLCubeRenderTarget.js +182 -0
  847. package/src/renderers/WebGLRenderTarget.js +34 -0
  848. package/src/renderers/WebGLRenderer.js +3508 -0
  849. package/src/renderers/common/Animation.js +147 -0
  850. package/src/renderers/common/Attributes.js +118 -0
  851. package/src/renderers/common/Backend.js +685 -0
  852. package/src/renderers/common/Background.js +212 -0
  853. package/src/renderers/common/BindGroup.js +61 -0
  854. package/src/renderers/common/Binding.js +60 -0
  855. package/src/renderers/common/Bindings.js +343 -0
  856. package/src/renderers/common/Buffer.js +87 -0
  857. package/src/renderers/common/BufferUtils.js +58 -0
  858. package/src/renderers/common/BundleGroup.js +83 -0
  859. package/src/renderers/common/ChainMap.js +98 -0
  860. package/src/renderers/common/ClippingContext.js +262 -0
  861. package/src/renderers/common/Color4.js +77 -0
  862. package/src/renderers/common/ComputePipeline.js +41 -0
  863. package/src/renderers/common/Constants.js +15 -0
  864. package/src/renderers/common/CubeRenderTarget.js +103 -0
  865. package/src/renderers/common/DataMap.js +90 -0
  866. package/src/renderers/common/Geometries.js +344 -0
  867. package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
  868. package/src/renderers/common/Info.js +172 -0
  869. package/src/renderers/common/Lighting.js +73 -0
  870. package/src/renderers/common/Pipeline.js +35 -0
  871. package/src/renderers/common/Pipelines.js +465 -0
  872. package/src/renderers/common/PostProcessing.js +245 -0
  873. package/src/renderers/common/ProgrammableStage.js +78 -0
  874. package/src/renderers/common/QuadMesh.js +106 -0
  875. package/src/renderers/common/RenderBundle.js +24 -0
  876. package/src/renderers/common/RenderBundles.js +67 -0
  877. package/src/renderers/common/RenderContext.js +265 -0
  878. package/src/renderers/common/RenderContexts.js +116 -0
  879. package/src/renderers/common/RenderList.js +400 -0
  880. package/src/renderers/common/RenderLists.js +77 -0
  881. package/src/renderers/common/RenderObject.js +901 -0
  882. package/src/renderers/common/RenderObjects.js +202 -0
  883. package/src/renderers/common/RenderPipeline.js +40 -0
  884. package/src/renderers/common/Renderer.js +3125 -0
  885. package/src/renderers/common/RendererUtils.js +191 -0
  886. package/src/renderers/common/SampledTexture.js +144 -0
  887. package/src/renderers/common/Sampler.js +139 -0
  888. package/src/renderers/common/Storage3DTexture.js +100 -0
  889. package/src/renderers/common/StorageArrayTexture.js +84 -0
  890. package/src/renderers/common/StorageBuffer.js +41 -0
  891. package/src/renderers/common/StorageBufferAttribute.js +46 -0
  892. package/src/renderers/common/StorageInstancedBufferAttribute.js +46 -0
  893. package/src/renderers/common/StorageTexture.js +78 -0
  894. package/src/renderers/common/Textures.js +491 -0
  895. package/src/renderers/common/TimestampQueryPool.js +99 -0
  896. package/src/renderers/common/Uniform.js +367 -0
  897. package/src/renderers/common/UniformBuffer.js +34 -0
  898. package/src/renderers/common/UniformsGroup.js +487 -0
  899. package/src/renderers/common/XRManager.js +1676 -0
  900. package/src/renderers/common/XRRenderTarget.js +91 -0
  901. package/src/renderers/common/extras/PMREMGenerator.js +946 -0
  902. package/src/renderers/common/nodes/NodeBuilderState.js +152 -0
  903. package/src/renderers/common/nodes/NodeLibrary.js +196 -0
  904. package/src/renderers/common/nodes/NodeSampledTexture.js +140 -0
  905. package/src/renderers/common/nodes/NodeSampler.js +50 -0
  906. package/src/renderers/common/nodes/NodeStorageBuffer.js +61 -0
  907. package/src/renderers/common/nodes/NodeUniform.js +418 -0
  908. package/src/renderers/common/nodes/NodeUniformBuffer.js +53 -0
  909. package/src/renderers/common/nodes/NodeUniformsGroup.js +51 -0
  910. package/src/renderers/common/nodes/Nodes.js +819 -0
  911. package/src/renderers/shaders/ShaderChunk/alphahash_fragment.glsl.js +7 -0
  912. package/src/renderers/shaders/ShaderChunk/alphahash_pars_fragment.glsl.js +68 -0
  913. package/src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl.js +7 -0
  914. package/src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl.js +7 -0
  915. package/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js +16 -0
  916. package/src/renderers/shaders/ShaderChunk/alphatest_pars_fragment.glsl.js +5 -0
  917. package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +26 -0
  918. package/src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl.js +8 -0
  919. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +49 -0
  920. package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +5 -0
  921. package/src/renderers/shaders/ShaderChunk/begin_vertex.glsl.js +9 -0
  922. package/src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl.js +9 -0
  923. package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +33 -0
  924. package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +43 -0
  925. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_begin.glsl.js +7 -0
  926. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js +10 -0
  927. package/src/renderers/shaders/ShaderChunk/clearcoat_pars_fragment.glsl.js +21 -0
  928. package/src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl.js +78 -0
  929. package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_fragment.glsl.js +9 -0
  930. package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_vertex.glsl.js +7 -0
  931. package/src/renderers/shaders/ShaderChunk/clipping_planes_vertex.glsl.js +7 -0
  932. package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +11 -0
  933. package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +11 -0
  934. package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +11 -0
  935. package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +31 -0
  936. package/src/renderers/shaders/ShaderChunk/colorspace_fragment.glsl.js +3 -0
  937. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +15 -0
  938. package/src/renderers/shaders/ShaderChunk/common.glsl.js +137 -0
  939. package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +186 -0
  940. package/src/renderers/shaders/ShaderChunk/default_fragment.glsl.js +5 -0
  941. package/src/renderers/shaders/ShaderChunk/default_vertex.glsl.js +5 -0
  942. package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +63 -0
  943. package/src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl.js +9 -0
  944. package/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl.js +7 -0
  945. package/src/renderers/shaders/ShaderChunk/dithering_fragment.glsl.js +7 -0
  946. package/src/renderers/shaders/ShaderChunk/dithering_pars_fragment.glsl.js +20 -0
  947. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +17 -0
  948. package/src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl.js +7 -0
  949. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +15 -0
  950. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +62 -0
  951. package/src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl.js +21 -0
  952. package/src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl.js +22 -0
  953. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +69 -0
  954. package/src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js +37 -0
  955. package/src/renderers/shaders/ShaderChunk/fog_fragment.glsl.js +17 -0
  956. package/src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl.js +19 -0
  957. package/src/renderers/shaders/ShaderChunk/fog_pars_vertex.glsl.js +7 -0
  958. package/src/renderers/shaders/ShaderChunk/fog_vertex.glsl.js +7 -0
  959. package/src/renderers/shaders/ShaderChunk/gradientmap_pars_fragment.glsl.js +27 -0
  960. package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +120 -0
  961. package/src/renderers/shaders/ShaderChunk/iridescence_pars_fragment.glsl.js +14 -0
  962. package/src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl.js +8 -0
  963. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +209 -0
  964. package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +13 -0
  965. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +40 -0
  966. package/src/renderers/shaders/ShaderChunk/lights_lambert_fragment.glsl.js +5 -0
  967. package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +28 -0
  968. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +254 -0
  969. package/src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl.js +7 -0
  970. package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +32 -0
  971. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +157 -0
  972. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +563 -0
  973. package/src/renderers/shaders/ShaderChunk/lights_toon_fragment.glsl.js +4 -0
  974. package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +26 -0
  975. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +9 -0
  976. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +9 -0
  977. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +8 -0
  978. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +8 -0
  979. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +17 -0
  980. package/src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl.js +7 -0
  981. package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +27 -0
  982. package/src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl.js +27 -0
  983. package/src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl.js +12 -0
  984. package/src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl.js +7 -0
  985. package/src/renderers/shaders/ShaderChunk/morphcolor_vertex.glsl.js +24 -0
  986. package/src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js +14 -0
  987. package/src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl.js +16 -0
  988. package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +26 -0
  989. package/src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl.js +16 -0
  990. package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +76 -0
  991. package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +33 -0
  992. package/src/renderers/shaders/ShaderChunk/normal_pars_fragment.glsl.js +14 -0
  993. package/src/renderers/shaders/ShaderChunk/normal_pars_vertex.glsl.js +14 -0
  994. package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +14 -0
  995. package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +43 -0
  996. package/src/renderers/shaders/ShaderChunk/opaque_fragment.glsl.js +11 -0
  997. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +100 -0
  998. package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +8 -0
  999. package/src/renderers/shaders/ShaderChunk/project_vertex.glsl.js +19 -0
  1000. package/src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl.js +12 -0
  1001. package/src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl.js +7 -0
  1002. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +337 -0
  1003. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +71 -0
  1004. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +68 -0
  1005. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +66 -0
  1006. package/src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl.js +10 -0
  1007. package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +25 -0
  1008. package/src/renderers/shaders/ShaderChunk/skinning_vertex.glsl.js +15 -0
  1009. package/src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl.js +20 -0
  1010. package/src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl.js +14 -0
  1011. package/src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl.js +7 -0
  1012. package/src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl.js +7 -0
  1013. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +200 -0
  1014. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +36 -0
  1015. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +235 -0
  1016. package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +119 -0
  1017. package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +145 -0
  1018. package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +122 -0
  1019. package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +21 -0
  1020. package/src/renderers/shaders/ShaderChunk.js +270 -0
  1021. package/src/renderers/shaders/ShaderLib/background.glsl.js +40 -0
  1022. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +63 -0
  1023. package/src/renderers/shaders/ShaderLib/cube.glsl.js +36 -0
  1024. package/src/renderers/shaders/ShaderLib/depth.glsl.js +114 -0
  1025. package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +78 -0
  1026. package/src/renderers/shaders/ShaderLib/equirect.glsl.js +35 -0
  1027. package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +76 -0
  1028. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +116 -0
  1029. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +125 -0
  1030. package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +112 -0
  1031. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +87 -0
  1032. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +127 -0
  1033. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +229 -0
  1034. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +119 -0
  1035. package/src/renderers/shaders/ShaderLib/points.glsl.js +87 -0
  1036. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +58 -0
  1037. package/src/renderers/shaders/ShaderLib/sprite.glsl.js +79 -0
  1038. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +53 -0
  1039. package/src/renderers/shaders/ShaderLib.js +361 -0
  1040. package/src/renderers/shaders/UniformsLib.js +235 -0
  1041. package/src/renderers/shaders/UniformsUtils.js +112 -0
  1042. package/src/renderers/webgl/WebGLAnimation.js +53 -0
  1043. package/src/renderers/webgl/WebGLAttributes.js +237 -0
  1044. package/src/renderers/webgl/WebGLBackground.js +303 -0
  1045. package/src/renderers/webgl/WebGLBindingStates.js +594 -0
  1046. package/src/renderers/webgl/WebGLBufferRenderer.js +89 -0
  1047. package/src/renderers/webgl/WebGLCapabilities.js +145 -0
  1048. package/src/renderers/webgl/WebGLClipping.js +171 -0
  1049. package/src/renderers/webgl/WebGLCubeMaps.js +99 -0
  1050. package/src/renderers/webgl/WebGLCubeUVMaps.js +134 -0
  1051. package/src/renderers/webgl/WebGLExtensions.js +84 -0
  1052. package/src/renderers/webgl/WebGLGeometries.js +183 -0
  1053. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +100 -0
  1054. package/src/renderers/webgl/WebGLInfo.js +73 -0
  1055. package/src/renderers/webgl/WebGLLights.js +571 -0
  1056. package/src/renderers/webgl/WebGLMaterials.js +591 -0
  1057. package/src/renderers/webgl/WebGLMorphtargets.js +168 -0
  1058. package/src/renderers/webgl/WebGLObjects.js +92 -0
  1059. package/src/renderers/webgl/WebGLProgram.js +1091 -0
  1060. package/src/renderers/webgl/WebGLPrograms.js +667 -0
  1061. package/src/renderers/webgl/WebGLProperties.js +55 -0
  1062. package/src/renderers/webgl/WebGLRenderLists.js +238 -0
  1063. package/src/renderers/webgl/WebGLRenderStates.js +116 -0
  1064. package/src/renderers/webgl/WebGLShader.js +12 -0
  1065. package/src/renderers/webgl/WebGLShaderCache.js +124 -0
  1066. package/src/renderers/webgl/WebGLShadowMap.js +436 -0
  1067. package/src/renderers/webgl/WebGLState.js +1332 -0
  1068. package/src/renderers/webgl/WebGLTextures.js +2342 -0
  1069. package/src/renderers/webgl/WebGLUniforms.js +1166 -0
  1070. package/src/renderers/webgl/WebGLUniformsGroups.js +394 -0
  1071. package/src/renderers/webgl/WebGLUtils.js +213 -0
  1072. package/src/renderers/webgl-fallback/WebGLBackend.js +2633 -0
  1073. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +140 -0
  1074. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +1517 -0
  1075. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +325 -0
  1076. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +64 -0
  1077. package/src/renderers/webgl-fallback/utils/WebGLConstants.js +14 -0
  1078. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +83 -0
  1079. package/src/renderers/webgl-fallback/utils/WebGLState.js +1144 -0
  1080. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +1304 -0
  1081. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +366 -0
  1082. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +313 -0
  1083. package/src/renderers/webgpu/WebGPUBackend.js +2456 -0
  1084. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +69 -0
  1085. package/src/renderers/webgpu/WebGPURenderer.js +106 -0
  1086. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +66 -0
  1087. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +100 -0
  1088. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +2248 -0
  1089. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +187 -0
  1090. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +25 -0
  1091. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +449 -0
  1092. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +484 -0
  1093. package/src/renderers/webgpu/utils/WebGPUConstants.js +339 -0
  1094. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +781 -0
  1095. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +439 -0
  1096. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +1505 -0
  1097. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +287 -0
  1098. package/src/renderers/webgpu/utils/WebGPUUtils.js +227 -0
  1099. package/src/renderers/webxr/WebXRController.js +428 -0
  1100. package/src/renderers/webxr/WebXRDepthSensing.js +155 -0
  1101. package/src/renderers/webxr/WebXRManager.js +1103 -0
  1102. package/src/scenes/Fog.js +98 -0
  1103. package/src/scenes/FogExp2.js +86 -0
  1104. package/src/scenes/Scene.js +165 -0
  1105. package/src/textures/CanvasTexture.js +45 -0
  1106. package/src/textures/CompressedArrayTexture.js +89 -0
  1107. package/src/textures/CompressedCubeTexture.js +48 -0
  1108. package/src/textures/CompressedTexture.js +86 -0
  1109. package/src/textures/CubeTexture.js +81 -0
  1110. package/src/textures/Data3DTexture.js +112 -0
  1111. package/src/textures/DataArrayTexture.js +134 -0
  1112. package/src/textures/DataTexture.js +87 -0
  1113. package/src/textures/DepthTexture.js +104 -0
  1114. package/src/textures/ExternalTexture.js +56 -0
  1115. package/src/textures/FramebufferTexture.js +85 -0
  1116. package/src/textures/Source.js +230 -0
  1117. package/src/textures/Texture.js +801 -0
  1118. package/src/textures/VideoFrameTexture.js +72 -0
  1119. package/src/textures/VideoTexture.js +125 -0
  1120. package/src/utils.js +216 -0
@@ -0,0 +1,4890 @@
1
+ import {
2
+ AnimationClip,
3
+ Bone,
4
+ Box3,
5
+ BufferAttribute,
6
+ BufferGeometry,
7
+ ClampToEdgeWrapping,
8
+ Color,
9
+ ColorManagement,
10
+ DirectionalLight,
11
+ DoubleSide,
12
+ FileLoader,
13
+ FrontSide,
14
+ Group,
15
+ ImageBitmapLoader,
16
+ InstancedMesh,
17
+ InterleavedBuffer,
18
+ InterleavedBufferAttribute,
19
+ Interpolant,
20
+ InterpolateDiscrete,
21
+ InterpolateLinear,
22
+ Line,
23
+ LineBasicMaterial,
24
+ LineLoop,
25
+ LineSegments,
26
+ LinearFilter,
27
+ LinearMipmapLinearFilter,
28
+ LinearMipmapNearestFilter,
29
+ LinearSRGBColorSpace,
30
+ Loader,
31
+ LoaderUtils,
32
+ Material,
33
+ MathUtils,
34
+ Matrix4,
35
+ Mesh,
36
+ MeshBasicMaterial,
37
+ MeshPhysicalMaterial,
38
+ MeshStandardMaterial,
39
+ MirroredRepeatWrapping,
40
+ NearestFilter,
41
+ NearestMipmapLinearFilter,
42
+ NearestMipmapNearestFilter,
43
+ NumberKeyframeTrack,
44
+ Object3D,
45
+ OrthographicCamera,
46
+ PerspectiveCamera,
47
+ PointLight,
48
+ Points,
49
+ PointsMaterial,
50
+ PropertyBinding,
51
+ Quaternion,
52
+ QuaternionKeyframeTrack,
53
+ RepeatWrapping,
54
+ Skeleton,
55
+ SkinnedMesh,
56
+ Sphere,
57
+ SpotLight,
58
+ Texture,
59
+ TextureLoader,
60
+ TriangleFanDrawMode,
61
+ TriangleStripDrawMode,
62
+ Vector2,
63
+ Vector3,
64
+ VectorKeyframeTrack,
65
+ SRGBColorSpace,
66
+ InstancedBufferAttribute
67
+ } from 'three';
68
+ import { toTrianglesDrawMode } from '../utils/BufferGeometryUtils.js';
69
+
70
+ /**
71
+ * A loader for the glTF 2.0 format.
72
+ *
73
+ * [glTF]{@link https://www.khronos.org/gltf/} (GL Transmission Format) is an [open format specification]{@link https://github.com/KhronosGroup/glTF/tree/main/specification/2.0}
74
+ * for efficient delivery and loading of 3D content. Assets may be provided either in JSON (.gltf) or binary (.glb)
75
+ * format. External files store textures (.jpg, .png) and additional binary data (.bin). A glTF asset may deliver
76
+ * one or more scenes, including meshes, materials, textures, skins, skeletons, morph targets, animations, lights,
77
+ * and/or cameras.
78
+ *
79
+ * `GLTFLoader` uses {@link ImageBitmapLoader} whenever possible. Be advised that image bitmaps are not
80
+ * automatically GC-collected when they are no longer referenced, and they require special handling during
81
+ * the disposal process.
82
+ *
83
+ * `GLTFLoader` supports the following glTF 2.0 extensions:
84
+ * - KHR_draco_mesh_compression
85
+ * - KHR_materials_clearcoat
86
+ * - KHR_materials_dispersion
87
+ * - KHR_materials_ior
88
+ * - KHR_materials_specular
89
+ * - KHR_materials_transmission
90
+ * - KHR_materials_iridescence
91
+ * - KHR_materials_unlit
92
+ * - KHR_materials_volume
93
+ * - KHR_mesh_quantization
94
+ * - KHR_lights_punctual
95
+ * - KHR_texture_basisu
96
+ * - KHR_texture_transform
97
+ * - EXT_texture_webp
98
+ * - EXT_meshopt_compression
99
+ * - EXT_mesh_gpu_instancing
100
+ *
101
+ * The following glTF 2.0 extension is supported by an external user plugin:
102
+ * - [KHR_materials_variants]{@link https://github.com/takahirox/three-gltf-extensions}
103
+ * - [MSFT_texture_dds]{@link https://github.com/takahirox/three-gltf-extensions}
104
+ *
105
+ * ```js
106
+ * const loader = new GLTFLoader();
107
+ *
108
+ * // Optional: Provide a DRACOLoader instance to decode compressed mesh data
109
+ * const dracoLoader = new DRACOLoader();
110
+ * dracoLoader.setDecoderPath( '/examples/jsm/libs/draco/' );
111
+ * loader.setDRACOLoader( dracoLoader );
112
+ *
113
+ * const gltf = await loader.loadAsync( 'models/gltf/duck/duck.gltf' );
114
+ * scene.add( gltf.scene );
115
+ * ```
116
+ *
117
+ * @augments Loader
118
+ * @three_import import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
119
+ */
120
+ class GLTFLoader extends Loader {
121
+
122
+ /**
123
+ * Constructs a new glTF loader.
124
+ *
125
+ * @param {LoadingManager} [manager] - The loading manager.
126
+ */
127
+ constructor( manager ) {
128
+
129
+ super( manager );
130
+
131
+ this.dracoLoader = null;
132
+ this.ktx2Loader = null;
133
+ this.meshoptDecoder = null;
134
+
135
+ this.pluginCallbacks = [];
136
+
137
+ this.register( function ( parser ) {
138
+
139
+ return new GLTFMaterialsClearcoatExtension( parser );
140
+
141
+ } );
142
+
143
+ this.register( function ( parser ) {
144
+
145
+ return new GLTFMaterialsDispersionExtension( parser );
146
+
147
+ } );
148
+
149
+ this.register( function ( parser ) {
150
+
151
+ return new GLTFTextureBasisUExtension( parser );
152
+
153
+ } );
154
+
155
+ this.register( function ( parser ) {
156
+
157
+ return new GLTFTextureWebPExtension( parser );
158
+
159
+ } );
160
+
161
+ this.register( function ( parser ) {
162
+
163
+ return new GLTFTextureAVIFExtension( parser );
164
+
165
+ } );
166
+
167
+ this.register( function ( parser ) {
168
+
169
+ return new GLTFMaterialsSheenExtension( parser );
170
+
171
+ } );
172
+
173
+ this.register( function ( parser ) {
174
+
175
+ return new GLTFMaterialsTransmissionExtension( parser );
176
+
177
+ } );
178
+
179
+ this.register( function ( parser ) {
180
+
181
+ return new GLTFMaterialsVolumeExtension( parser );
182
+
183
+ } );
184
+
185
+ this.register( function ( parser ) {
186
+
187
+ return new GLTFMaterialsIorExtension( parser );
188
+
189
+ } );
190
+
191
+ this.register( function ( parser ) {
192
+
193
+ return new GLTFMaterialsEmissiveStrengthExtension( parser );
194
+
195
+ } );
196
+
197
+ this.register( function ( parser ) {
198
+
199
+ return new GLTFMaterialsSpecularExtension( parser );
200
+
201
+ } );
202
+
203
+ this.register( function ( parser ) {
204
+
205
+ return new GLTFMaterialsIridescenceExtension( parser );
206
+
207
+ } );
208
+
209
+ this.register( function ( parser ) {
210
+
211
+ return new GLTFMaterialsAnisotropyExtension( parser );
212
+
213
+ } );
214
+
215
+ this.register( function ( parser ) {
216
+
217
+ return new GLTFMaterialsBumpExtension( parser );
218
+
219
+ } );
220
+
221
+ this.register( function ( parser ) {
222
+
223
+ return new GLTFLightsExtension( parser );
224
+
225
+ } );
226
+
227
+ this.register( function ( parser ) {
228
+
229
+ return new GLTFMeshoptCompression( parser );
230
+
231
+ } );
232
+
233
+ this.register( function ( parser ) {
234
+
235
+ return new GLTFMeshGpuInstancing( parser );
236
+
237
+ } );
238
+
239
+ }
240
+
241
+ /**
242
+ * Starts loading from the given URL and passes the loaded glTF asset
243
+ * to the `onLoad()` callback.
244
+ *
245
+ * @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
246
+ * @param {function(GLTFLoader~LoadObject)} onLoad - Executed when the loading process has been finished.
247
+ * @param {onProgressCallback} onProgress - Executed while the loading is in progress.
248
+ * @param {onErrorCallback} onError - Executed when errors occur.
249
+ */
250
+ load( url, onLoad, onProgress, onError ) {
251
+
252
+ const scope = this;
253
+
254
+ let resourcePath;
255
+
256
+ if ( this.resourcePath !== '' ) {
257
+
258
+ resourcePath = this.resourcePath;
259
+
260
+ } else if ( this.path !== '' ) {
261
+
262
+ // If a base path is set, resources will be relative paths from that plus the relative path of the gltf file
263
+ // Example path = 'https://my-cnd-server.com/', url = 'assets/models/model.gltf'
264
+ // resourcePath = 'https://my-cnd-server.com/assets/models/'
265
+ // referenced resource 'model.bin' will be loaded from 'https://my-cnd-server.com/assets/models/model.bin'
266
+ // referenced resource '../textures/texture.png' will be loaded from 'https://my-cnd-server.com/assets/textures/texture.png'
267
+ const relativeUrl = LoaderUtils.extractUrlBase( url );
268
+ resourcePath = LoaderUtils.resolveURL( relativeUrl, this.path );
269
+
270
+ } else {
271
+
272
+ resourcePath = LoaderUtils.extractUrlBase( url );
273
+
274
+ }
275
+
276
+ // Tells the LoadingManager to track an extra item, which resolves after
277
+ // the model is fully loaded. This means the count of items loaded will
278
+ // be incorrect, but ensures manager.onLoad() does not fire early.
279
+ this.manager.itemStart( url );
280
+
281
+ const _onError = function ( e ) {
282
+
283
+ if ( onError ) {
284
+
285
+ onError( e );
286
+
287
+ } else {
288
+
289
+ console.error( e );
290
+
291
+ }
292
+
293
+ scope.manager.itemError( url );
294
+ scope.manager.itemEnd( url );
295
+
296
+ };
297
+
298
+ const loader = new FileLoader( this.manager );
299
+
300
+ loader.setPath( this.path );
301
+ loader.setResponseType( 'arraybuffer' );
302
+ loader.setRequestHeader( this.requestHeader );
303
+ loader.setWithCredentials( this.withCredentials );
304
+
305
+ loader.load( url, function ( data ) {
306
+
307
+ try {
308
+
309
+ scope.parse( data, resourcePath, function ( gltf ) {
310
+
311
+ onLoad( gltf );
312
+
313
+ scope.manager.itemEnd( url );
314
+
315
+ }, _onError );
316
+
317
+ } catch ( e ) {
318
+
319
+ _onError( e );
320
+
321
+ }
322
+
323
+ }, onProgress, _onError );
324
+
325
+ }
326
+
327
+ /**
328
+ * Sets the given Draco loader to this loader. Required for decoding assets
329
+ * compressed with the `KHR_draco_mesh_compression` extension.
330
+ *
331
+ * @param {DRACOLoader} dracoLoader - The Draco loader to set.
332
+ * @return {GLTFLoader} A reference to this loader.
333
+ */
334
+ setDRACOLoader( dracoLoader ) {
335
+
336
+ this.dracoLoader = dracoLoader;
337
+ return this;
338
+
339
+ }
340
+
341
+ /**
342
+ * Sets the given KTX2 loader to this loader. Required for loading KTX2
343
+ * compressed textures.
344
+ *
345
+ * @param {KTX2Loader} ktx2Loader - The KTX2 loader to set.
346
+ * @return {GLTFLoader} A reference to this loader.
347
+ */
348
+ setKTX2Loader( ktx2Loader ) {
349
+
350
+ this.ktx2Loader = ktx2Loader;
351
+ return this;
352
+
353
+ }
354
+
355
+ /**
356
+ * Sets the given meshopt decoder. Required for decoding assets
357
+ * compressed with the `EXT_meshopt_compression` extension.
358
+ *
359
+ * @param {Object} meshoptDecoder - The meshopt decoder to set.
360
+ * @return {GLTFLoader} A reference to this loader.
361
+ */
362
+ setMeshoptDecoder( meshoptDecoder ) {
363
+
364
+ this.meshoptDecoder = meshoptDecoder;
365
+ return this;
366
+
367
+ }
368
+
369
+ /**
370
+ * Registers a plugin callback. This API is internally used to implement the various
371
+ * glTF extensions but can also used by third-party code to add additional logic
372
+ * to the loader.
373
+ *
374
+ * @param {function(parser:GLTFParser)} callback - The callback function to register.
375
+ * @return {GLTFLoader} A reference to this loader.
376
+ */
377
+ register( callback ) {
378
+
379
+ if ( this.pluginCallbacks.indexOf( callback ) === - 1 ) {
380
+
381
+ this.pluginCallbacks.push( callback );
382
+
383
+ }
384
+
385
+ return this;
386
+
387
+ }
388
+
389
+ /**
390
+ * Unregisters a plugin callback.
391
+ *
392
+ * @param {Function} callback - The callback function to unregister.
393
+ * @return {GLTFLoader} A reference to this loader.
394
+ */
395
+ unregister( callback ) {
396
+
397
+ if ( this.pluginCallbacks.indexOf( callback ) !== - 1 ) {
398
+
399
+ this.pluginCallbacks.splice( this.pluginCallbacks.indexOf( callback ), 1 );
400
+
401
+ }
402
+
403
+ return this;
404
+
405
+ }
406
+
407
+ /**
408
+ * Parses the given FBX data and returns the resulting group.
409
+ *
410
+ * @param {string|ArrayBuffer} data - The raw glTF data.
411
+ * @param {string} path - The URL base path.
412
+ * @param {function(GLTFLoader~LoadObject)} onLoad - Executed when the loading process has been finished.
413
+ * @param {onErrorCallback} onError - Executed when errors occur.
414
+ */
415
+ parse( data, path, onLoad, onError ) {
416
+
417
+ let json;
418
+ const extensions = {};
419
+ const plugins = {};
420
+ const textDecoder = new TextDecoder();
421
+
422
+ if ( typeof data === 'string' ) {
423
+
424
+ json = JSON.parse( data );
425
+
426
+ } else if ( data instanceof ArrayBuffer ) {
427
+
428
+ const magic = textDecoder.decode( new Uint8Array( data, 0, 4 ) );
429
+
430
+ if ( magic === BINARY_EXTENSION_HEADER_MAGIC ) {
431
+
432
+ try {
433
+
434
+ extensions[ EXTENSIONS.KHR_BINARY_GLTF ] = new GLTFBinaryExtension( data );
435
+
436
+ } catch ( error ) {
437
+
438
+ if ( onError ) onError( error );
439
+ return;
440
+
441
+ }
442
+
443
+ json = JSON.parse( extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content );
444
+
445
+ } else {
446
+
447
+ json = JSON.parse( textDecoder.decode( data ) );
448
+
449
+ }
450
+
451
+ } else {
452
+
453
+ json = data;
454
+
455
+ }
456
+
457
+ if ( json.asset === undefined || json.asset.version[ 0 ] < 2 ) {
458
+
459
+ if ( onError ) onError( new Error( 'THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.' ) );
460
+ return;
461
+
462
+ }
463
+
464
+ const parser = new GLTFParser( json, {
465
+
466
+ path: path || this.resourcePath || '',
467
+ crossOrigin: this.crossOrigin,
468
+ requestHeader: this.requestHeader,
469
+ manager: this.manager,
470
+ ktx2Loader: this.ktx2Loader,
471
+ meshoptDecoder: this.meshoptDecoder
472
+
473
+ } );
474
+
475
+ parser.fileLoader.setRequestHeader( this.requestHeader );
476
+
477
+ for ( let i = 0; i < this.pluginCallbacks.length; i ++ ) {
478
+
479
+ const plugin = this.pluginCallbacks[ i ]( parser );
480
+
481
+ if ( ! plugin.name ) console.error( 'THREE.GLTFLoader: Invalid plugin found: missing name' );
482
+
483
+ plugins[ plugin.name ] = plugin;
484
+
485
+ // Workaround to avoid determining as unknown extension
486
+ // in addUnknownExtensionsToUserData().
487
+ // Remove this workaround if we move all the existing
488
+ // extension handlers to plugin system
489
+ extensions[ plugin.name ] = true;
490
+
491
+ }
492
+
493
+ if ( json.extensionsUsed ) {
494
+
495
+ for ( let i = 0; i < json.extensionsUsed.length; ++ i ) {
496
+
497
+ const extensionName = json.extensionsUsed[ i ];
498
+ const extensionsRequired = json.extensionsRequired || [];
499
+
500
+ switch ( extensionName ) {
501
+
502
+ case EXTENSIONS.KHR_MATERIALS_UNLIT:
503
+ extensions[ extensionName ] = new GLTFMaterialsUnlitExtension();
504
+ break;
505
+
506
+ case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
507
+ extensions[ extensionName ] = new GLTFDracoMeshCompressionExtension( json, this.dracoLoader );
508
+ break;
509
+
510
+ case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
511
+ extensions[ extensionName ] = new GLTFTextureTransformExtension();
512
+ break;
513
+
514
+ case EXTENSIONS.KHR_MESH_QUANTIZATION:
515
+ extensions[ extensionName ] = new GLTFMeshQuantizationExtension();
516
+ break;
517
+
518
+ default:
519
+
520
+ if ( extensionsRequired.indexOf( extensionName ) >= 0 && plugins[ extensionName ] === undefined ) {
521
+
522
+ console.warn( 'THREE.GLTFLoader: Unknown extension "' + extensionName + '".' );
523
+
524
+ }
525
+
526
+ }
527
+
528
+ }
529
+
530
+ }
531
+
532
+ parser.setExtensions( extensions );
533
+ parser.setPlugins( plugins );
534
+ parser.parse( onLoad, onError );
535
+
536
+ }
537
+
538
+ /**
539
+ * Async version of {@link GLTFLoader#parse}.
540
+ *
541
+ * @async
542
+ * @param {string|ArrayBuffer} data - The raw glTF data.
543
+ * @param {string} path - The URL base path.
544
+ * @return {Promise<GLTFLoader~LoadObject>} A Promise that resolves with the loaded glTF when the parsing has been finished.
545
+ */
546
+ parseAsync( data, path ) {
547
+
548
+ const scope = this;
549
+
550
+ return new Promise( function ( resolve, reject ) {
551
+
552
+ scope.parse( data, path, resolve, reject );
553
+
554
+ } );
555
+
556
+ }
557
+
558
+ }
559
+
560
+ /* GLTFREGISTRY */
561
+
562
+ function GLTFRegistry() {
563
+
564
+ let objects = {};
565
+
566
+ return {
567
+
568
+ get: function ( key ) {
569
+
570
+ return objects[ key ];
571
+
572
+ },
573
+
574
+ add: function ( key, object ) {
575
+
576
+ objects[ key ] = object;
577
+
578
+ },
579
+
580
+ remove: function ( key ) {
581
+
582
+ delete objects[ key ];
583
+
584
+ },
585
+
586
+ removeAll: function () {
587
+
588
+ objects = {};
589
+
590
+ }
591
+
592
+ };
593
+
594
+ }
595
+
596
+ /*********************************/
597
+ /********** EXTENSIONS ***********/
598
+ /*********************************/
599
+
600
+ const EXTENSIONS = {
601
+ KHR_BINARY_GLTF: 'KHR_binary_glTF',
602
+ KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
603
+ KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
604
+ KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
605
+ KHR_MATERIALS_DISPERSION: 'KHR_materials_dispersion',
606
+ KHR_MATERIALS_IOR: 'KHR_materials_ior',
607
+ KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
608
+ KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
609
+ KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
610
+ KHR_MATERIALS_IRIDESCENCE: 'KHR_materials_iridescence',
611
+ KHR_MATERIALS_ANISOTROPY: 'KHR_materials_anisotropy',
612
+ KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
613
+ KHR_MATERIALS_VOLUME: 'KHR_materials_volume',
614
+ KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
615
+ KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
616
+ KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
617
+ KHR_MATERIALS_EMISSIVE_STRENGTH: 'KHR_materials_emissive_strength',
618
+ EXT_MATERIALS_BUMP: 'EXT_materials_bump',
619
+ EXT_TEXTURE_WEBP: 'EXT_texture_webp',
620
+ EXT_TEXTURE_AVIF: 'EXT_texture_avif',
621
+ EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression',
622
+ EXT_MESH_GPU_INSTANCING: 'EXT_mesh_gpu_instancing'
623
+ };
624
+
625
+ /**
626
+ * Punctual Lights Extension
627
+ *
628
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
629
+ *
630
+ * @private
631
+ */
632
+ class GLTFLightsExtension {
633
+
634
+ constructor( parser ) {
635
+
636
+ this.parser = parser;
637
+ this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
638
+
639
+ // Object3D instance caches
640
+ this.cache = { refs: {}, uses: {} };
641
+
642
+ }
643
+
644
+ _markDefs() {
645
+
646
+ const parser = this.parser;
647
+ const nodeDefs = this.parser.json.nodes || [];
648
+
649
+ for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) {
650
+
651
+ const nodeDef = nodeDefs[ nodeIndex ];
652
+
653
+ if ( nodeDef.extensions
654
+ && nodeDef.extensions[ this.name ]
655
+ && nodeDef.extensions[ this.name ].light !== undefined ) {
656
+
657
+ parser._addNodeRef( this.cache, nodeDef.extensions[ this.name ].light );
658
+
659
+ }
660
+
661
+ }
662
+
663
+ }
664
+
665
+ _loadLight( lightIndex ) {
666
+
667
+ const parser = this.parser;
668
+ const cacheKey = 'light:' + lightIndex;
669
+ let dependency = parser.cache.get( cacheKey );
670
+
671
+ if ( dependency ) return dependency;
672
+
673
+ const json = parser.json;
674
+ const extensions = ( json.extensions && json.extensions[ this.name ] ) || {};
675
+ const lightDefs = extensions.lights || [];
676
+ const lightDef = lightDefs[ lightIndex ];
677
+ let lightNode;
678
+
679
+ const color = new Color( 0xffffff );
680
+
681
+ if ( lightDef.color !== undefined ) color.setRGB( lightDef.color[ 0 ], lightDef.color[ 1 ], lightDef.color[ 2 ], LinearSRGBColorSpace );
682
+
683
+ const range = lightDef.range !== undefined ? lightDef.range : 0;
684
+
685
+ switch ( lightDef.type ) {
686
+
687
+ case 'directional':
688
+ lightNode = new DirectionalLight( color );
689
+ lightNode.target.position.set( 0, 0, - 1 );
690
+ lightNode.add( lightNode.target );
691
+ break;
692
+
693
+ case 'point':
694
+ lightNode = new PointLight( color );
695
+ lightNode.distance = range;
696
+ break;
697
+
698
+ case 'spot':
699
+ lightNode = new SpotLight( color );
700
+ lightNode.distance = range;
701
+ // Handle spotlight properties.
702
+ lightDef.spot = lightDef.spot || {};
703
+ lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
704
+ lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
705
+ lightNode.angle = lightDef.spot.outerConeAngle;
706
+ lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
707
+ lightNode.target.position.set( 0, 0, - 1 );
708
+ lightNode.add( lightNode.target );
709
+ break;
710
+
711
+ default:
712
+ throw new Error( 'THREE.GLTFLoader: Unexpected light type: ' + lightDef.type );
713
+
714
+ }
715
+
716
+ // Some lights (e.g. spot) default to a position other than the origin. Reset the position
717
+ // here, because node-level parsing will only override position if explicitly specified.
718
+ lightNode.position.set( 0, 0, 0 );
719
+
720
+ assignExtrasToUserData( lightNode, lightDef );
721
+
722
+ if ( lightDef.intensity !== undefined ) lightNode.intensity = lightDef.intensity;
723
+
724
+ lightNode.name = parser.createUniqueName( lightDef.name || ( 'light_' + lightIndex ) );
725
+
726
+ dependency = Promise.resolve( lightNode );
727
+
728
+ parser.cache.add( cacheKey, dependency );
729
+
730
+ return dependency;
731
+
732
+ }
733
+
734
+ getDependency( type, index ) {
735
+
736
+ if ( type !== 'light' ) return;
737
+
738
+ return this._loadLight( index );
739
+
740
+ }
741
+
742
+ createNodeAttachment( nodeIndex ) {
743
+
744
+ const self = this;
745
+ const parser = this.parser;
746
+ const json = parser.json;
747
+ const nodeDef = json.nodes[ nodeIndex ];
748
+ const lightDef = ( nodeDef.extensions && nodeDef.extensions[ this.name ] ) || {};
749
+ const lightIndex = lightDef.light;
750
+
751
+ if ( lightIndex === undefined ) return null;
752
+
753
+ return this._loadLight( lightIndex ).then( function ( light ) {
754
+
755
+ return parser._getNodeRef( self.cache, lightIndex, light );
756
+
757
+ } );
758
+
759
+ }
760
+
761
+ }
762
+
763
+ /**
764
+ * Unlit Materials Extension
765
+ *
766
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
767
+ *
768
+ * @private
769
+ */
770
+ class GLTFMaterialsUnlitExtension {
771
+
772
+ constructor() {
773
+
774
+ this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
775
+
776
+ }
777
+
778
+ getMaterialType() {
779
+
780
+ return MeshBasicMaterial;
781
+
782
+ }
783
+
784
+ extendParams( materialParams, materialDef, parser ) {
785
+
786
+ const pending = [];
787
+
788
+ materialParams.color = new Color( 1.0, 1.0, 1.0 );
789
+ materialParams.opacity = 1.0;
790
+
791
+ const metallicRoughness = materialDef.pbrMetallicRoughness;
792
+
793
+ if ( metallicRoughness ) {
794
+
795
+ if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
796
+
797
+ const array = metallicRoughness.baseColorFactor;
798
+
799
+ materialParams.color.setRGB( array[ 0 ], array[ 1 ], array[ 2 ], LinearSRGBColorSpace );
800
+ materialParams.opacity = array[ 3 ];
801
+
802
+ }
803
+
804
+ if ( metallicRoughness.baseColorTexture !== undefined ) {
805
+
806
+ pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, SRGBColorSpace ) );
807
+
808
+ }
809
+
810
+ }
811
+
812
+ return Promise.all( pending );
813
+
814
+ }
815
+
816
+ }
817
+
818
+ /**
819
+ * Materials Emissive Strength Extension
820
+ *
821
+ * Specification: https://github.com/KhronosGroup/glTF/blob/5768b3ce0ef32bc39cdf1bef10b948586635ead3/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md
822
+ *
823
+ * @private
824
+ */
825
+ class GLTFMaterialsEmissiveStrengthExtension {
826
+
827
+ constructor( parser ) {
828
+
829
+ this.parser = parser;
830
+ this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH;
831
+
832
+ }
833
+
834
+ extendMaterialParams( materialIndex, materialParams ) {
835
+
836
+ const parser = this.parser;
837
+ const materialDef = parser.json.materials[ materialIndex ];
838
+
839
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
840
+
841
+ return Promise.resolve();
842
+
843
+ }
844
+
845
+ const emissiveStrength = materialDef.extensions[ this.name ].emissiveStrength;
846
+
847
+ if ( emissiveStrength !== undefined ) {
848
+
849
+ materialParams.emissiveIntensity = emissiveStrength;
850
+
851
+ }
852
+
853
+ return Promise.resolve();
854
+
855
+ }
856
+
857
+ }
858
+
859
+ /**
860
+ * Clearcoat Materials Extension
861
+ *
862
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat
863
+ *
864
+ * @private
865
+ */
866
+ class GLTFMaterialsClearcoatExtension {
867
+
868
+ constructor( parser ) {
869
+
870
+ this.parser = parser;
871
+ this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
872
+
873
+ }
874
+
875
+ getMaterialType( materialIndex ) {
876
+
877
+ const parser = this.parser;
878
+ const materialDef = parser.json.materials[ materialIndex ];
879
+
880
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
881
+
882
+ return MeshPhysicalMaterial;
883
+
884
+ }
885
+
886
+ extendMaterialParams( materialIndex, materialParams ) {
887
+
888
+ const parser = this.parser;
889
+ const materialDef = parser.json.materials[ materialIndex ];
890
+
891
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
892
+
893
+ return Promise.resolve();
894
+
895
+ }
896
+
897
+ const pending = [];
898
+
899
+ const extension = materialDef.extensions[ this.name ];
900
+
901
+ if ( extension.clearcoatFactor !== undefined ) {
902
+
903
+ materialParams.clearcoat = extension.clearcoatFactor;
904
+
905
+ }
906
+
907
+ if ( extension.clearcoatTexture !== undefined ) {
908
+
909
+ pending.push( parser.assignTexture( materialParams, 'clearcoatMap', extension.clearcoatTexture ) );
910
+
911
+ }
912
+
913
+ if ( extension.clearcoatRoughnessFactor !== undefined ) {
914
+
915
+ materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor;
916
+
917
+ }
918
+
919
+ if ( extension.clearcoatRoughnessTexture !== undefined ) {
920
+
921
+ pending.push( parser.assignTexture( materialParams, 'clearcoatRoughnessMap', extension.clearcoatRoughnessTexture ) );
922
+
923
+ }
924
+
925
+ if ( extension.clearcoatNormalTexture !== undefined ) {
926
+
927
+ pending.push( parser.assignTexture( materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture ) );
928
+
929
+ if ( extension.clearcoatNormalTexture.scale !== undefined ) {
930
+
931
+ const scale = extension.clearcoatNormalTexture.scale;
932
+
933
+ materialParams.clearcoatNormalScale = new Vector2( scale, scale );
934
+
935
+ }
936
+
937
+ }
938
+
939
+ return Promise.all( pending );
940
+
941
+ }
942
+
943
+ }
944
+
945
+ /**
946
+ * Materials dispersion Extension
947
+ *
948
+ * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_dispersion
949
+ *
950
+ * @private
951
+ */
952
+ class GLTFMaterialsDispersionExtension {
953
+
954
+ constructor( parser ) {
955
+
956
+ this.parser = parser;
957
+ this.name = EXTENSIONS.KHR_MATERIALS_DISPERSION;
958
+
959
+ }
960
+
961
+ getMaterialType( materialIndex ) {
962
+
963
+ const parser = this.parser;
964
+ const materialDef = parser.json.materials[ materialIndex ];
965
+
966
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
967
+
968
+ return MeshPhysicalMaterial;
969
+
970
+ }
971
+
972
+ extendMaterialParams( materialIndex, materialParams ) {
973
+
974
+ const parser = this.parser;
975
+ const materialDef = parser.json.materials[ materialIndex ];
976
+
977
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
978
+
979
+ return Promise.resolve();
980
+
981
+ }
982
+
983
+ const extension = materialDef.extensions[ this.name ];
984
+
985
+ materialParams.dispersion = extension.dispersion !== undefined ? extension.dispersion : 0;
986
+
987
+ return Promise.resolve();
988
+
989
+ }
990
+
991
+ }
992
+
993
+ /**
994
+ * Iridescence Materials Extension
995
+ *
996
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_iridescence
997
+ *
998
+ * @private
999
+ */
1000
+ class GLTFMaterialsIridescenceExtension {
1001
+
1002
+ constructor( parser ) {
1003
+
1004
+ this.parser = parser;
1005
+ this.name = EXTENSIONS.KHR_MATERIALS_IRIDESCENCE;
1006
+
1007
+ }
1008
+
1009
+ getMaterialType( materialIndex ) {
1010
+
1011
+ const parser = this.parser;
1012
+ const materialDef = parser.json.materials[ materialIndex ];
1013
+
1014
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
1015
+
1016
+ return MeshPhysicalMaterial;
1017
+
1018
+ }
1019
+
1020
+ extendMaterialParams( materialIndex, materialParams ) {
1021
+
1022
+ const parser = this.parser;
1023
+ const materialDef = parser.json.materials[ materialIndex ];
1024
+
1025
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
1026
+
1027
+ return Promise.resolve();
1028
+
1029
+ }
1030
+
1031
+ const pending = [];
1032
+
1033
+ const extension = materialDef.extensions[ this.name ];
1034
+
1035
+ if ( extension.iridescenceFactor !== undefined ) {
1036
+
1037
+ materialParams.iridescence = extension.iridescenceFactor;
1038
+
1039
+ }
1040
+
1041
+ if ( extension.iridescenceTexture !== undefined ) {
1042
+
1043
+ pending.push( parser.assignTexture( materialParams, 'iridescenceMap', extension.iridescenceTexture ) );
1044
+
1045
+ }
1046
+
1047
+ if ( extension.iridescenceIor !== undefined ) {
1048
+
1049
+ materialParams.iridescenceIOR = extension.iridescenceIor;
1050
+
1051
+ }
1052
+
1053
+ if ( materialParams.iridescenceThicknessRange === undefined ) {
1054
+
1055
+ materialParams.iridescenceThicknessRange = [ 100, 400 ];
1056
+
1057
+ }
1058
+
1059
+ if ( extension.iridescenceThicknessMinimum !== undefined ) {
1060
+
1061
+ materialParams.iridescenceThicknessRange[ 0 ] = extension.iridescenceThicknessMinimum;
1062
+
1063
+ }
1064
+
1065
+ if ( extension.iridescenceThicknessMaximum !== undefined ) {
1066
+
1067
+ materialParams.iridescenceThicknessRange[ 1 ] = extension.iridescenceThicknessMaximum;
1068
+
1069
+ }
1070
+
1071
+ if ( extension.iridescenceThicknessTexture !== undefined ) {
1072
+
1073
+ pending.push( parser.assignTexture( materialParams, 'iridescenceThicknessMap', extension.iridescenceThicknessTexture ) );
1074
+
1075
+ }
1076
+
1077
+ return Promise.all( pending );
1078
+
1079
+ }
1080
+
1081
+ }
1082
+
1083
+ /**
1084
+ * Sheen Materials Extension
1085
+ *
1086
+ * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
1087
+ *
1088
+ * @private
1089
+ */
1090
+ class GLTFMaterialsSheenExtension {
1091
+
1092
+ constructor( parser ) {
1093
+
1094
+ this.parser = parser;
1095
+ this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
1096
+
1097
+ }
1098
+
1099
+ getMaterialType( materialIndex ) {
1100
+
1101
+ const parser = this.parser;
1102
+ const materialDef = parser.json.materials[ materialIndex ];
1103
+
1104
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
1105
+
1106
+ return MeshPhysicalMaterial;
1107
+
1108
+ }
1109
+
1110
+ extendMaterialParams( materialIndex, materialParams ) {
1111
+
1112
+ const parser = this.parser;
1113
+ const materialDef = parser.json.materials[ materialIndex ];
1114
+
1115
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
1116
+
1117
+ return Promise.resolve();
1118
+
1119
+ }
1120
+
1121
+ const pending = [];
1122
+
1123
+ materialParams.sheenColor = new Color( 0, 0, 0 );
1124
+ materialParams.sheenRoughness = 0;
1125
+ materialParams.sheen = 1;
1126
+
1127
+ const extension = materialDef.extensions[ this.name ];
1128
+
1129
+ if ( extension.sheenColorFactor !== undefined ) {
1130
+
1131
+ const colorFactor = extension.sheenColorFactor;
1132
+ materialParams.sheenColor.setRGB( colorFactor[ 0 ], colorFactor[ 1 ], colorFactor[ 2 ], LinearSRGBColorSpace );
1133
+
1134
+ }
1135
+
1136
+ if ( extension.sheenRoughnessFactor !== undefined ) {
1137
+
1138
+ materialParams.sheenRoughness = extension.sheenRoughnessFactor;
1139
+
1140
+ }
1141
+
1142
+ if ( extension.sheenColorTexture !== undefined ) {
1143
+
1144
+ pending.push( parser.assignTexture( materialParams, 'sheenColorMap', extension.sheenColorTexture, SRGBColorSpace ) );
1145
+
1146
+ }
1147
+
1148
+ if ( extension.sheenRoughnessTexture !== undefined ) {
1149
+
1150
+ pending.push( parser.assignTexture( materialParams, 'sheenRoughnessMap', extension.sheenRoughnessTexture ) );
1151
+
1152
+ }
1153
+
1154
+ return Promise.all( pending );
1155
+
1156
+ }
1157
+
1158
+ }
1159
+
1160
+ /**
1161
+ * Transmission Materials Extension
1162
+ *
1163
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission
1164
+ * Draft: https://github.com/KhronosGroup/glTF/pull/1698
1165
+ *
1166
+ * @private
1167
+ */
1168
+ class GLTFMaterialsTransmissionExtension {
1169
+
1170
+ constructor( parser ) {
1171
+
1172
+ this.parser = parser;
1173
+ this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION;
1174
+
1175
+ }
1176
+
1177
+ getMaterialType( materialIndex ) {
1178
+
1179
+ const parser = this.parser;
1180
+ const materialDef = parser.json.materials[ materialIndex ];
1181
+
1182
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
1183
+
1184
+ return MeshPhysicalMaterial;
1185
+
1186
+ }
1187
+
1188
+ extendMaterialParams( materialIndex, materialParams ) {
1189
+
1190
+ const parser = this.parser;
1191
+ const materialDef = parser.json.materials[ materialIndex ];
1192
+
1193
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
1194
+
1195
+ return Promise.resolve();
1196
+
1197
+ }
1198
+
1199
+ const pending = [];
1200
+
1201
+ const extension = materialDef.extensions[ this.name ];
1202
+
1203
+ if ( extension.transmissionFactor !== undefined ) {
1204
+
1205
+ materialParams.transmission = extension.transmissionFactor;
1206
+
1207
+ }
1208
+
1209
+ if ( extension.transmissionTexture !== undefined ) {
1210
+
1211
+ pending.push( parser.assignTexture( materialParams, 'transmissionMap', extension.transmissionTexture ) );
1212
+
1213
+ }
1214
+
1215
+ return Promise.all( pending );
1216
+
1217
+ }
1218
+
1219
+ }
1220
+
1221
+ /**
1222
+ * Materials Volume Extension
1223
+ *
1224
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume
1225
+ *
1226
+ * @private
1227
+ */
1228
+ class GLTFMaterialsVolumeExtension {
1229
+
1230
+ constructor( parser ) {
1231
+
1232
+ this.parser = parser;
1233
+ this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
1234
+
1235
+ }
1236
+
1237
+ getMaterialType( materialIndex ) {
1238
+
1239
+ const parser = this.parser;
1240
+ const materialDef = parser.json.materials[ materialIndex ];
1241
+
1242
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
1243
+
1244
+ return MeshPhysicalMaterial;
1245
+
1246
+ }
1247
+
1248
+ extendMaterialParams( materialIndex, materialParams ) {
1249
+
1250
+ const parser = this.parser;
1251
+ const materialDef = parser.json.materials[ materialIndex ];
1252
+
1253
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
1254
+
1255
+ return Promise.resolve();
1256
+
1257
+ }
1258
+
1259
+ const pending = [];
1260
+
1261
+ const extension = materialDef.extensions[ this.name ];
1262
+
1263
+ materialParams.thickness = extension.thicknessFactor !== undefined ? extension.thicknessFactor : 0;
1264
+
1265
+ if ( extension.thicknessTexture !== undefined ) {
1266
+
1267
+ pending.push( parser.assignTexture( materialParams, 'thicknessMap', extension.thicknessTexture ) );
1268
+
1269
+ }
1270
+
1271
+ materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
1272
+
1273
+ const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
1274
+ materialParams.attenuationColor = new Color().setRGB( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ], LinearSRGBColorSpace );
1275
+
1276
+ return Promise.all( pending );
1277
+
1278
+ }
1279
+
1280
+ }
1281
+
1282
+ /**
1283
+ * Materials ior Extension
1284
+ *
1285
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior
1286
+ *
1287
+ * @private
1288
+ */
1289
+ class GLTFMaterialsIorExtension {
1290
+
1291
+ constructor( parser ) {
1292
+
1293
+ this.parser = parser;
1294
+ this.name = EXTENSIONS.KHR_MATERIALS_IOR;
1295
+
1296
+ }
1297
+
1298
+ getMaterialType( materialIndex ) {
1299
+
1300
+ const parser = this.parser;
1301
+ const materialDef = parser.json.materials[ materialIndex ];
1302
+
1303
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
1304
+
1305
+ return MeshPhysicalMaterial;
1306
+
1307
+ }
1308
+
1309
+ extendMaterialParams( materialIndex, materialParams ) {
1310
+
1311
+ const parser = this.parser;
1312
+ const materialDef = parser.json.materials[ materialIndex ];
1313
+
1314
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
1315
+
1316
+ return Promise.resolve();
1317
+
1318
+ }
1319
+
1320
+ const extension = materialDef.extensions[ this.name ];
1321
+
1322
+ materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5;
1323
+
1324
+ return Promise.resolve();
1325
+
1326
+ }
1327
+
1328
+ }
1329
+
1330
+ /**
1331
+ * Materials specular Extension
1332
+ *
1333
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular
1334
+ *
1335
+ * @private
1336
+ */
1337
+ class GLTFMaterialsSpecularExtension {
1338
+
1339
+ constructor( parser ) {
1340
+
1341
+ this.parser = parser;
1342
+ this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
1343
+
1344
+ }
1345
+
1346
+ getMaterialType( materialIndex ) {
1347
+
1348
+ const parser = this.parser;
1349
+ const materialDef = parser.json.materials[ materialIndex ];
1350
+
1351
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
1352
+
1353
+ return MeshPhysicalMaterial;
1354
+
1355
+ }
1356
+
1357
+ extendMaterialParams( materialIndex, materialParams ) {
1358
+
1359
+ const parser = this.parser;
1360
+ const materialDef = parser.json.materials[ materialIndex ];
1361
+
1362
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
1363
+
1364
+ return Promise.resolve();
1365
+
1366
+ }
1367
+
1368
+ const pending = [];
1369
+
1370
+ const extension = materialDef.extensions[ this.name ];
1371
+
1372
+ materialParams.specularIntensity = extension.specularFactor !== undefined ? extension.specularFactor : 1.0;
1373
+
1374
+ if ( extension.specularTexture !== undefined ) {
1375
+
1376
+ pending.push( parser.assignTexture( materialParams, 'specularIntensityMap', extension.specularTexture ) );
1377
+
1378
+ }
1379
+
1380
+ const colorArray = extension.specularColorFactor || [ 1, 1, 1 ];
1381
+ materialParams.specularColor = new Color().setRGB( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ], LinearSRGBColorSpace );
1382
+
1383
+ if ( extension.specularColorTexture !== undefined ) {
1384
+
1385
+ pending.push( parser.assignTexture( materialParams, 'specularColorMap', extension.specularColorTexture, SRGBColorSpace ) );
1386
+
1387
+ }
1388
+
1389
+ return Promise.all( pending );
1390
+
1391
+ }
1392
+
1393
+ }
1394
+
1395
+
1396
+ /**
1397
+ * Materials bump Extension
1398
+ *
1399
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_materials_bump
1400
+ *
1401
+ * @private
1402
+ */
1403
+ class GLTFMaterialsBumpExtension {
1404
+
1405
+ constructor( parser ) {
1406
+
1407
+ this.parser = parser;
1408
+ this.name = EXTENSIONS.EXT_MATERIALS_BUMP;
1409
+
1410
+ }
1411
+
1412
+ getMaterialType( materialIndex ) {
1413
+
1414
+ const parser = this.parser;
1415
+ const materialDef = parser.json.materials[ materialIndex ];
1416
+
1417
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
1418
+
1419
+ return MeshPhysicalMaterial;
1420
+
1421
+ }
1422
+
1423
+ extendMaterialParams( materialIndex, materialParams ) {
1424
+
1425
+ const parser = this.parser;
1426
+ const materialDef = parser.json.materials[ materialIndex ];
1427
+
1428
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
1429
+
1430
+ return Promise.resolve();
1431
+
1432
+ }
1433
+
1434
+ const pending = [];
1435
+
1436
+ const extension = materialDef.extensions[ this.name ];
1437
+
1438
+ materialParams.bumpScale = extension.bumpFactor !== undefined ? extension.bumpFactor : 1.0;
1439
+
1440
+ if ( extension.bumpTexture !== undefined ) {
1441
+
1442
+ pending.push( parser.assignTexture( materialParams, 'bumpMap', extension.bumpTexture ) );
1443
+
1444
+ }
1445
+
1446
+ return Promise.all( pending );
1447
+
1448
+ }
1449
+
1450
+ }
1451
+
1452
+ /**
1453
+ * Materials anisotropy Extension
1454
+ *
1455
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_anisotropy
1456
+ *
1457
+ * @private
1458
+ */
1459
+ class GLTFMaterialsAnisotropyExtension {
1460
+
1461
+ constructor( parser ) {
1462
+
1463
+ this.parser = parser;
1464
+ this.name = EXTENSIONS.KHR_MATERIALS_ANISOTROPY;
1465
+
1466
+ }
1467
+
1468
+ getMaterialType( materialIndex ) {
1469
+
1470
+ const parser = this.parser;
1471
+ const materialDef = parser.json.materials[ materialIndex ];
1472
+
1473
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
1474
+
1475
+ return MeshPhysicalMaterial;
1476
+
1477
+ }
1478
+
1479
+ extendMaterialParams( materialIndex, materialParams ) {
1480
+
1481
+ const parser = this.parser;
1482
+ const materialDef = parser.json.materials[ materialIndex ];
1483
+
1484
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
1485
+
1486
+ return Promise.resolve();
1487
+
1488
+ }
1489
+
1490
+ const pending = [];
1491
+
1492
+ const extension = materialDef.extensions[ this.name ];
1493
+
1494
+ if ( extension.anisotropyStrength !== undefined ) {
1495
+
1496
+ materialParams.anisotropy = extension.anisotropyStrength;
1497
+
1498
+ }
1499
+
1500
+ if ( extension.anisotropyRotation !== undefined ) {
1501
+
1502
+ materialParams.anisotropyRotation = extension.anisotropyRotation;
1503
+
1504
+ }
1505
+
1506
+ if ( extension.anisotropyTexture !== undefined ) {
1507
+
1508
+ pending.push( parser.assignTexture( materialParams, 'anisotropyMap', extension.anisotropyTexture ) );
1509
+
1510
+ }
1511
+
1512
+ return Promise.all( pending );
1513
+
1514
+ }
1515
+
1516
+ }
1517
+
1518
+ /**
1519
+ * BasisU Texture Extension
1520
+ *
1521
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu
1522
+ *
1523
+ * @private
1524
+ */
1525
+ class GLTFTextureBasisUExtension {
1526
+
1527
+ constructor( parser ) {
1528
+
1529
+ this.parser = parser;
1530
+ this.name = EXTENSIONS.KHR_TEXTURE_BASISU;
1531
+
1532
+ }
1533
+
1534
+ loadTexture( textureIndex ) {
1535
+
1536
+ const parser = this.parser;
1537
+ const json = parser.json;
1538
+
1539
+ const textureDef = json.textures[ textureIndex ];
1540
+
1541
+ if ( ! textureDef.extensions || ! textureDef.extensions[ this.name ] ) {
1542
+
1543
+ return null;
1544
+
1545
+ }
1546
+
1547
+ const extension = textureDef.extensions[ this.name ];
1548
+ const loader = parser.options.ktx2Loader;
1549
+
1550
+ if ( ! loader ) {
1551
+
1552
+ if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) {
1553
+
1554
+ throw new Error( 'THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures' );
1555
+
1556
+ } else {
1557
+
1558
+ // Assumes that the extension is optional and that a fallback texture is present
1559
+ return null;
1560
+
1561
+ }
1562
+
1563
+ }
1564
+
1565
+ return parser.loadTextureImage( textureIndex, extension.source, loader );
1566
+
1567
+ }
1568
+
1569
+ }
1570
+
1571
+ /**
1572
+ * WebP Texture Extension
1573
+ *
1574
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_webp
1575
+ *
1576
+ * @private
1577
+ */
1578
+ class GLTFTextureWebPExtension {
1579
+
1580
+ constructor( parser ) {
1581
+
1582
+ this.parser = parser;
1583
+ this.name = EXTENSIONS.EXT_TEXTURE_WEBP;
1584
+
1585
+ }
1586
+
1587
+ loadTexture( textureIndex ) {
1588
+
1589
+ const name = this.name;
1590
+ const parser = this.parser;
1591
+ const json = parser.json;
1592
+
1593
+ const textureDef = json.textures[ textureIndex ];
1594
+
1595
+ if ( ! textureDef.extensions || ! textureDef.extensions[ name ] ) {
1596
+
1597
+ return null;
1598
+
1599
+ }
1600
+
1601
+ const extension = textureDef.extensions[ name ];
1602
+ const source = json.images[ extension.source ];
1603
+
1604
+ let loader = parser.textureLoader;
1605
+ if ( source.uri ) {
1606
+
1607
+ const handler = parser.options.manager.getHandler( source.uri );
1608
+ if ( handler !== null ) loader = handler;
1609
+
1610
+ }
1611
+
1612
+ return parser.loadTextureImage( textureIndex, extension.source, loader );
1613
+
1614
+ }
1615
+
1616
+ }
1617
+
1618
+ /**
1619
+ * AVIF Texture Extension
1620
+ *
1621
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_avif
1622
+ *
1623
+ * @private
1624
+ */
1625
+ class GLTFTextureAVIFExtension {
1626
+
1627
+ constructor( parser ) {
1628
+
1629
+ this.parser = parser;
1630
+ this.name = EXTENSIONS.EXT_TEXTURE_AVIF;
1631
+
1632
+ }
1633
+
1634
+ loadTexture( textureIndex ) {
1635
+
1636
+ const name = this.name;
1637
+ const parser = this.parser;
1638
+ const json = parser.json;
1639
+
1640
+ const textureDef = json.textures[ textureIndex ];
1641
+
1642
+ if ( ! textureDef.extensions || ! textureDef.extensions[ name ] ) {
1643
+
1644
+ return null;
1645
+
1646
+ }
1647
+
1648
+ const extension = textureDef.extensions[ name ];
1649
+ const source = json.images[ extension.source ];
1650
+
1651
+ let loader = parser.textureLoader;
1652
+ if ( source.uri ) {
1653
+
1654
+ const handler = parser.options.manager.getHandler( source.uri );
1655
+ if ( handler !== null ) loader = handler;
1656
+
1657
+ }
1658
+
1659
+ return parser.loadTextureImage( textureIndex, extension.source, loader );
1660
+
1661
+ }
1662
+
1663
+ }
1664
+
1665
+ /**
1666
+ * meshopt BufferView Compression Extension
1667
+ *
1668
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression
1669
+ *
1670
+ * @private
1671
+ */
1672
+ class GLTFMeshoptCompression {
1673
+
1674
+ constructor( parser ) {
1675
+
1676
+ this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION;
1677
+ this.parser = parser;
1678
+
1679
+ }
1680
+
1681
+ loadBufferView( index ) {
1682
+
1683
+ const json = this.parser.json;
1684
+ const bufferView = json.bufferViews[ index ];
1685
+
1686
+ if ( bufferView.extensions && bufferView.extensions[ this.name ] ) {
1687
+
1688
+ const extensionDef = bufferView.extensions[ this.name ];
1689
+
1690
+ const buffer = this.parser.getDependency( 'buffer', extensionDef.buffer );
1691
+ const decoder = this.parser.options.meshoptDecoder;
1692
+
1693
+ if ( ! decoder || ! decoder.supported ) {
1694
+
1695
+ if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) {
1696
+
1697
+ throw new Error( 'THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files' );
1698
+
1699
+ } else {
1700
+
1701
+ // Assumes that the extension is optional and that fallback buffer data is present
1702
+ return null;
1703
+
1704
+ }
1705
+
1706
+ }
1707
+
1708
+ return buffer.then( function ( res ) {
1709
+
1710
+ const byteOffset = extensionDef.byteOffset || 0;
1711
+ const byteLength = extensionDef.byteLength || 0;
1712
+
1713
+ const count = extensionDef.count;
1714
+ const stride = extensionDef.byteStride;
1715
+
1716
+ const source = new Uint8Array( res, byteOffset, byteLength );
1717
+
1718
+ if ( decoder.decodeGltfBufferAsync ) {
1719
+
1720
+ return decoder.decodeGltfBufferAsync( count, stride, source, extensionDef.mode, extensionDef.filter ).then( function ( res ) {
1721
+
1722
+ return res.buffer;
1723
+
1724
+ } );
1725
+
1726
+ } else {
1727
+
1728
+ // Support for MeshoptDecoder 0.18 or earlier, without decodeGltfBufferAsync
1729
+ return decoder.ready.then( function () {
1730
+
1731
+ const result = new ArrayBuffer( count * stride );
1732
+ decoder.decodeGltfBuffer( new Uint8Array( result ), count, stride, source, extensionDef.mode, extensionDef.filter );
1733
+ return result;
1734
+
1735
+ } );
1736
+
1737
+ }
1738
+
1739
+ } );
1740
+
1741
+ } else {
1742
+
1743
+ return null;
1744
+
1745
+ }
1746
+
1747
+ }
1748
+
1749
+ }
1750
+
1751
+ /**
1752
+ * GPU Instancing Extension
1753
+ *
1754
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_mesh_gpu_instancing
1755
+ *
1756
+ * @private
1757
+ */
1758
+ class GLTFMeshGpuInstancing {
1759
+
1760
+ constructor( parser ) {
1761
+
1762
+ this.name = EXTENSIONS.EXT_MESH_GPU_INSTANCING;
1763
+ this.parser = parser;
1764
+
1765
+ }
1766
+
1767
+ createNodeMesh( nodeIndex ) {
1768
+
1769
+ const json = this.parser.json;
1770
+ const nodeDef = json.nodes[ nodeIndex ];
1771
+
1772
+ if ( ! nodeDef.extensions || ! nodeDef.extensions[ this.name ] ||
1773
+ nodeDef.mesh === undefined ) {
1774
+
1775
+ return null;
1776
+
1777
+ }
1778
+
1779
+ const meshDef = json.meshes[ nodeDef.mesh ];
1780
+
1781
+ // No Points or Lines + Instancing support yet
1782
+
1783
+ for ( const primitive of meshDef.primitives ) {
1784
+
1785
+ if ( primitive.mode !== WEBGL_CONSTANTS.TRIANGLES &&
1786
+ primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP &&
1787
+ primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN &&
1788
+ primitive.mode !== undefined ) {
1789
+
1790
+ return null;
1791
+
1792
+ }
1793
+
1794
+ }
1795
+
1796
+ const extensionDef = nodeDef.extensions[ this.name ];
1797
+ const attributesDef = extensionDef.attributes;
1798
+
1799
+ // @TODO: Can we support InstancedMesh + SkinnedMesh?
1800
+
1801
+ const pending = [];
1802
+ const attributes = {};
1803
+
1804
+ for ( const key in attributesDef ) {
1805
+
1806
+ pending.push( this.parser.getDependency( 'accessor', attributesDef[ key ] ).then( accessor => {
1807
+
1808
+ attributes[ key ] = accessor;
1809
+ return attributes[ key ];
1810
+
1811
+ } ) );
1812
+
1813
+ }
1814
+
1815
+ if ( pending.length < 1 ) {
1816
+
1817
+ return null;
1818
+
1819
+ }
1820
+
1821
+ pending.push( this.parser.createNodeMesh( nodeIndex ) );
1822
+
1823
+ return Promise.all( pending ).then( results => {
1824
+
1825
+ const nodeObject = results.pop();
1826
+ const meshes = nodeObject.isGroup ? nodeObject.children : [ nodeObject ];
1827
+ const count = results[ 0 ].count; // All attribute counts should be same
1828
+ const instancedMeshes = [];
1829
+
1830
+ for ( const mesh of meshes ) {
1831
+
1832
+ // Temporal variables
1833
+ const m = new Matrix4();
1834
+ const p = new Vector3();
1835
+ const q = new Quaternion();
1836
+ const s = new Vector3( 1, 1, 1 );
1837
+
1838
+ const instancedMesh = new InstancedMesh( mesh.geometry, mesh.material, count );
1839
+
1840
+ for ( let i = 0; i < count; i ++ ) {
1841
+
1842
+ if ( attributes.TRANSLATION ) {
1843
+
1844
+ p.fromBufferAttribute( attributes.TRANSLATION, i );
1845
+
1846
+ }
1847
+
1848
+ if ( attributes.ROTATION ) {
1849
+
1850
+ q.fromBufferAttribute( attributes.ROTATION, i );
1851
+
1852
+ }
1853
+
1854
+ if ( attributes.SCALE ) {
1855
+
1856
+ s.fromBufferAttribute( attributes.SCALE, i );
1857
+
1858
+ }
1859
+
1860
+ instancedMesh.setMatrixAt( i, m.compose( p, q, s ) );
1861
+
1862
+ }
1863
+
1864
+ // Add instance attributes to the geometry, excluding TRS.
1865
+ for ( const attributeName in attributes ) {
1866
+
1867
+ if ( attributeName === '_COLOR_0' ) {
1868
+
1869
+ const attr = attributes[ attributeName ];
1870
+ instancedMesh.instanceColor = new InstancedBufferAttribute( attr.array, attr.itemSize, attr.normalized );
1871
+
1872
+ } else if ( attributeName !== 'TRANSLATION' &&
1873
+ attributeName !== 'ROTATION' &&
1874
+ attributeName !== 'SCALE' ) {
1875
+
1876
+ mesh.geometry.setAttribute( attributeName, attributes[ attributeName ] );
1877
+
1878
+ }
1879
+
1880
+ }
1881
+
1882
+ // Just in case
1883
+ Object3D.prototype.copy.call( instancedMesh, mesh );
1884
+
1885
+ this.parser.assignFinalMaterial( instancedMesh );
1886
+
1887
+ instancedMeshes.push( instancedMesh );
1888
+
1889
+ }
1890
+
1891
+ if ( nodeObject.isGroup ) {
1892
+
1893
+ nodeObject.clear();
1894
+
1895
+ nodeObject.add( ... instancedMeshes );
1896
+
1897
+ return nodeObject;
1898
+
1899
+ }
1900
+
1901
+ return instancedMeshes[ 0 ];
1902
+
1903
+ } );
1904
+
1905
+ }
1906
+
1907
+ }
1908
+
1909
+ /* BINARY EXTENSION */
1910
+ const BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
1911
+ const BINARY_EXTENSION_HEADER_LENGTH = 12;
1912
+ const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4E4F534A, BIN: 0x004E4942 };
1913
+
1914
+ class GLTFBinaryExtension {
1915
+
1916
+ constructor( data ) {
1917
+
1918
+ this.name = EXTENSIONS.KHR_BINARY_GLTF;
1919
+ this.content = null;
1920
+ this.body = null;
1921
+
1922
+ const headerView = new DataView( data, 0, BINARY_EXTENSION_HEADER_LENGTH );
1923
+ const textDecoder = new TextDecoder();
1924
+
1925
+ this.header = {
1926
+ magic: textDecoder.decode( new Uint8Array( data.slice( 0, 4 ) ) ),
1927
+ version: headerView.getUint32( 4, true ),
1928
+ length: headerView.getUint32( 8, true )
1929
+ };
1930
+
1931
+ if ( this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC ) {
1932
+
1933
+ throw new Error( 'THREE.GLTFLoader: Unsupported glTF-Binary header.' );
1934
+
1935
+ } else if ( this.header.version < 2.0 ) {
1936
+
1937
+ throw new Error( 'THREE.GLTFLoader: Legacy binary file detected.' );
1938
+
1939
+ }
1940
+
1941
+ const chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH;
1942
+ const chunkView = new DataView( data, BINARY_EXTENSION_HEADER_LENGTH );
1943
+ let chunkIndex = 0;
1944
+
1945
+ while ( chunkIndex < chunkContentsLength ) {
1946
+
1947
+ const chunkLength = chunkView.getUint32( chunkIndex, true );
1948
+ chunkIndex += 4;
1949
+
1950
+ const chunkType = chunkView.getUint32( chunkIndex, true );
1951
+ chunkIndex += 4;
1952
+
1953
+ if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON ) {
1954
+
1955
+ const contentArray = new Uint8Array( data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength );
1956
+ this.content = textDecoder.decode( contentArray );
1957
+
1958
+ } else if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN ) {
1959
+
1960
+ const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
1961
+ this.body = data.slice( byteOffset, byteOffset + chunkLength );
1962
+
1963
+ }
1964
+
1965
+ // Clients must ignore chunks with unknown types.
1966
+
1967
+ chunkIndex += chunkLength;
1968
+
1969
+ }
1970
+
1971
+ if ( this.content === null ) {
1972
+
1973
+ throw new Error( 'THREE.GLTFLoader: JSON content not found.' );
1974
+
1975
+ }
1976
+
1977
+ }
1978
+
1979
+ }
1980
+
1981
+ /**
1982
+ * DRACO Mesh Compression Extension
1983
+ *
1984
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
1985
+ *
1986
+ * @private
1987
+ */
1988
+ class GLTFDracoMeshCompressionExtension {
1989
+
1990
+ constructor( json, dracoLoader ) {
1991
+
1992
+ if ( ! dracoLoader ) {
1993
+
1994
+ throw new Error( 'THREE.GLTFLoader: No DRACOLoader instance provided.' );
1995
+
1996
+ }
1997
+
1998
+ this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
1999
+ this.json = json;
2000
+ this.dracoLoader = dracoLoader;
2001
+ this.dracoLoader.preload();
2002
+
2003
+ }
2004
+
2005
+ decodePrimitive( primitive, parser ) {
2006
+
2007
+ const json = this.json;
2008
+ const dracoLoader = this.dracoLoader;
2009
+ const bufferViewIndex = primitive.extensions[ this.name ].bufferView;
2010
+ const gltfAttributeMap = primitive.extensions[ this.name ].attributes;
2011
+ const threeAttributeMap = {};
2012
+ const attributeNormalizedMap = {};
2013
+ const attributeTypeMap = {};
2014
+
2015
+ for ( const attributeName in gltfAttributeMap ) {
2016
+
2017
+ const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
2018
+
2019
+ threeAttributeMap[ threeAttributeName ] = gltfAttributeMap[ attributeName ];
2020
+
2021
+ }
2022
+
2023
+ for ( const attributeName in primitive.attributes ) {
2024
+
2025
+ const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
2026
+
2027
+ if ( gltfAttributeMap[ attributeName ] !== undefined ) {
2028
+
2029
+ const accessorDef = json.accessors[ primitive.attributes[ attributeName ] ];
2030
+ const componentType = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
2031
+
2032
+ attributeTypeMap[ threeAttributeName ] = componentType.name;
2033
+ attributeNormalizedMap[ threeAttributeName ] = accessorDef.normalized === true;
2034
+
2035
+ }
2036
+
2037
+ }
2038
+
2039
+ return parser.getDependency( 'bufferView', bufferViewIndex ).then( function ( bufferView ) {
2040
+
2041
+ return new Promise( function ( resolve, reject ) {
2042
+
2043
+ dracoLoader.decodeDracoFile( bufferView, function ( geometry ) {
2044
+
2045
+ for ( const attributeName in geometry.attributes ) {
2046
+
2047
+ const attribute = geometry.attributes[ attributeName ];
2048
+ const normalized = attributeNormalizedMap[ attributeName ];
2049
+
2050
+ if ( normalized !== undefined ) attribute.normalized = normalized;
2051
+
2052
+ }
2053
+
2054
+ resolve( geometry );
2055
+
2056
+ }, threeAttributeMap, attributeTypeMap, LinearSRGBColorSpace, reject );
2057
+
2058
+ } );
2059
+
2060
+ } );
2061
+
2062
+ }
2063
+
2064
+ }
2065
+
2066
+ /**
2067
+ * Texture Transform Extension
2068
+ *
2069
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform
2070
+ *
2071
+ * @private
2072
+ */
2073
+ class GLTFTextureTransformExtension {
2074
+
2075
+ constructor() {
2076
+
2077
+ this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
2078
+
2079
+ }
2080
+
2081
+ extendTexture( texture, transform ) {
2082
+
2083
+ if ( ( transform.texCoord === undefined || transform.texCoord === texture.channel )
2084
+ && transform.offset === undefined
2085
+ && transform.rotation === undefined
2086
+ && transform.scale === undefined ) {
2087
+
2088
+ // See https://github.com/mrdoob/three.js/issues/21819.
2089
+ return texture;
2090
+
2091
+ }
2092
+
2093
+ texture = texture.clone();
2094
+
2095
+ if ( transform.texCoord !== undefined ) {
2096
+
2097
+ texture.channel = transform.texCoord;
2098
+
2099
+ }
2100
+
2101
+ if ( transform.offset !== undefined ) {
2102
+
2103
+ texture.offset.fromArray( transform.offset );
2104
+
2105
+ }
2106
+
2107
+ if ( transform.rotation !== undefined ) {
2108
+
2109
+ texture.rotation = transform.rotation;
2110
+
2111
+ }
2112
+
2113
+ if ( transform.scale !== undefined ) {
2114
+
2115
+ texture.repeat.fromArray( transform.scale );
2116
+
2117
+ }
2118
+
2119
+ texture.needsUpdate = true;
2120
+
2121
+ return texture;
2122
+
2123
+ }
2124
+
2125
+ }
2126
+
2127
+ /**
2128
+ * Mesh Quantization Extension
2129
+ *
2130
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization
2131
+ *
2132
+ * @private
2133
+ */
2134
+ class GLTFMeshQuantizationExtension {
2135
+
2136
+ constructor() {
2137
+
2138
+ this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
2139
+
2140
+ }
2141
+
2142
+ }
2143
+
2144
+ /*********************************/
2145
+ /********** INTERPOLATION ********/
2146
+ /*********************************/
2147
+
2148
+ // Spline Interpolation
2149
+ // Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-c-spline-interpolation
2150
+ class GLTFCubicSplineInterpolant extends Interpolant {
2151
+
2152
+ constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
2153
+
2154
+ super( parameterPositions, sampleValues, sampleSize, resultBuffer );
2155
+
2156
+ }
2157
+
2158
+ copySampleValue_( index ) {
2159
+
2160
+ // Copies a sample value to the result buffer. See description of glTF
2161
+ // CUBICSPLINE values layout in interpolate_() function below.
2162
+
2163
+ const result = this.resultBuffer,
2164
+ values = this.sampleValues,
2165
+ valueSize = this.valueSize,
2166
+ offset = index * valueSize * 3 + valueSize;
2167
+
2168
+ for ( let i = 0; i !== valueSize; i ++ ) {
2169
+
2170
+ result[ i ] = values[ offset + i ];
2171
+
2172
+ }
2173
+
2174
+ return result;
2175
+
2176
+ }
2177
+
2178
+ interpolate_( i1, t0, t, t1 ) {
2179
+
2180
+ const result = this.resultBuffer;
2181
+ const values = this.sampleValues;
2182
+ const stride = this.valueSize;
2183
+
2184
+ const stride2 = stride * 2;
2185
+ const stride3 = stride * 3;
2186
+
2187
+ const td = t1 - t0;
2188
+
2189
+ const p = ( t - t0 ) / td;
2190
+ const pp = p * p;
2191
+ const ppp = pp * p;
2192
+
2193
+ const offset1 = i1 * stride3;
2194
+ const offset0 = offset1 - stride3;
2195
+
2196
+ const s2 = - 2 * ppp + 3 * pp;
2197
+ const s3 = ppp - pp;
2198
+ const s0 = 1 - s2;
2199
+ const s1 = s3 - pp + p;
2200
+
2201
+ // Layout of keyframe output values for CUBICSPLINE animations:
2202
+ // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
2203
+ for ( let i = 0; i !== stride; i ++ ) {
2204
+
2205
+ const p0 = values[ offset0 + i + stride ]; // splineVertex_k
2206
+ const m0 = values[ offset0 + i + stride2 ] * td; // outTangent_k * (t_k+1 - t_k)
2207
+ const p1 = values[ offset1 + i + stride ]; // splineVertex_k+1
2208
+ const m1 = values[ offset1 + i ] * td; // inTangent_k+1 * (t_k+1 - t_k)
2209
+
2210
+ result[ i ] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
2211
+
2212
+ }
2213
+
2214
+ return result;
2215
+
2216
+ }
2217
+
2218
+ }
2219
+
2220
+ const _quaternion = new Quaternion();
2221
+
2222
+ class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
2223
+
2224
+ interpolate_( i1, t0, t, t1 ) {
2225
+
2226
+ const result = super.interpolate_( i1, t0, t, t1 );
2227
+
2228
+ _quaternion.fromArray( result ).normalize().toArray( result );
2229
+
2230
+ return result;
2231
+
2232
+ }
2233
+
2234
+ }
2235
+
2236
+
2237
+ /*********************************/
2238
+ /********** INTERNALS ************/
2239
+ /*********************************/
2240
+
2241
+ /* CONSTANTS */
2242
+
2243
+ const WEBGL_CONSTANTS = {
2244
+ FLOAT: 5126,
2245
+ //FLOAT_MAT2: 35674,
2246
+ FLOAT_MAT3: 35675,
2247
+ FLOAT_MAT4: 35676,
2248
+ FLOAT_VEC2: 35664,
2249
+ FLOAT_VEC3: 35665,
2250
+ FLOAT_VEC4: 35666,
2251
+ LINEAR: 9729,
2252
+ REPEAT: 10497,
2253
+ SAMPLER_2D: 35678,
2254
+ POINTS: 0,
2255
+ LINES: 1,
2256
+ LINE_LOOP: 2,
2257
+ LINE_STRIP: 3,
2258
+ TRIANGLES: 4,
2259
+ TRIANGLE_STRIP: 5,
2260
+ TRIANGLE_FAN: 6,
2261
+ UNSIGNED_BYTE: 5121,
2262
+ UNSIGNED_SHORT: 5123
2263
+ };
2264
+
2265
+ const WEBGL_COMPONENT_TYPES = {
2266
+ 5120: Int8Array,
2267
+ 5121: Uint8Array,
2268
+ 5122: Int16Array,
2269
+ 5123: Uint16Array,
2270
+ 5125: Uint32Array,
2271
+ 5126: Float32Array
2272
+ };
2273
+
2274
+ const WEBGL_FILTERS = {
2275
+ 9728: NearestFilter,
2276
+ 9729: LinearFilter,
2277
+ 9984: NearestMipmapNearestFilter,
2278
+ 9985: LinearMipmapNearestFilter,
2279
+ 9986: NearestMipmapLinearFilter,
2280
+ 9987: LinearMipmapLinearFilter
2281
+ };
2282
+
2283
+ const WEBGL_WRAPPINGS = {
2284
+ 33071: ClampToEdgeWrapping,
2285
+ 33648: MirroredRepeatWrapping,
2286
+ 10497: RepeatWrapping
2287
+ };
2288
+
2289
+ const WEBGL_TYPE_SIZES = {
2290
+ 'SCALAR': 1,
2291
+ 'VEC2': 2,
2292
+ 'VEC3': 3,
2293
+ 'VEC4': 4,
2294
+ 'MAT2': 4,
2295
+ 'MAT3': 9,
2296
+ 'MAT4': 16
2297
+ };
2298
+
2299
+ const ATTRIBUTES = {
2300
+ POSITION: 'position',
2301
+ NORMAL: 'normal',
2302
+ TANGENT: 'tangent',
2303
+ TEXCOORD_0: 'uv',
2304
+ TEXCOORD_1: 'uv1',
2305
+ TEXCOORD_2: 'uv2',
2306
+ TEXCOORD_3: 'uv3',
2307
+ COLOR_0: 'color',
2308
+ WEIGHTS_0: 'skinWeight',
2309
+ JOINTS_0: 'skinIndex',
2310
+ };
2311
+
2312
+ const PATH_PROPERTIES = {
2313
+ scale: 'scale',
2314
+ translation: 'position',
2315
+ rotation: 'quaternion',
2316
+ weights: 'morphTargetInfluences'
2317
+ };
2318
+
2319
+ const INTERPOLATION = {
2320
+ CUBICSPLINE: undefined, // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
2321
+ // keyframe track will be initialized with a default interpolation type, then modified.
2322
+ LINEAR: InterpolateLinear,
2323
+ STEP: InterpolateDiscrete
2324
+ };
2325
+
2326
+ const ALPHA_MODES = {
2327
+ OPAQUE: 'OPAQUE',
2328
+ MASK: 'MASK',
2329
+ BLEND: 'BLEND'
2330
+ };
2331
+
2332
+ /**
2333
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material
2334
+ *
2335
+ * @private
2336
+ * @param {Object<string, Material>} cache
2337
+ * @return {Material}
2338
+ */
2339
+ function createDefaultMaterial( cache ) {
2340
+
2341
+ if ( cache[ 'DefaultMaterial' ] === undefined ) {
2342
+
2343
+ cache[ 'DefaultMaterial' ] = new MeshStandardMaterial( {
2344
+ color: 0xFFFFFF,
2345
+ emissive: 0x000000,
2346
+ metalness: 1,
2347
+ roughness: 1,
2348
+ transparent: false,
2349
+ depthTest: true,
2350
+ side: FrontSide
2351
+ } );
2352
+
2353
+ }
2354
+
2355
+ return cache[ 'DefaultMaterial' ];
2356
+
2357
+ }
2358
+
2359
+ function addUnknownExtensionsToUserData( knownExtensions, object, objectDef ) {
2360
+
2361
+ // Add unknown glTF extensions to an object's userData.
2362
+
2363
+ for ( const name in objectDef.extensions ) {
2364
+
2365
+ if ( knownExtensions[ name ] === undefined ) {
2366
+
2367
+ object.userData.gltfExtensions = object.userData.gltfExtensions || {};
2368
+ object.userData.gltfExtensions[ name ] = objectDef.extensions[ name ];
2369
+
2370
+ }
2371
+
2372
+ }
2373
+
2374
+ }
2375
+
2376
+ /**
2377
+ *
2378
+ * @private
2379
+ * @param {Object3D|Material|BufferGeometry|Object|AnimationClip} object
2380
+ * @param {GLTF.definition} gltfDef
2381
+ */
2382
+ function assignExtrasToUserData( object, gltfDef ) {
2383
+
2384
+ if ( gltfDef.extras !== undefined ) {
2385
+
2386
+ if ( typeof gltfDef.extras === 'object' ) {
2387
+
2388
+ Object.assign( object.userData, gltfDef.extras );
2389
+
2390
+ } else {
2391
+
2392
+ console.warn( 'THREE.GLTFLoader: Ignoring primitive type .extras, ' + gltfDef.extras );
2393
+
2394
+ }
2395
+
2396
+ }
2397
+
2398
+ }
2399
+
2400
+ /**
2401
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#morph-targets
2402
+ *
2403
+ * @private
2404
+ * @param {BufferGeometry} geometry
2405
+ * @param {Array<GLTF.Target>} targets
2406
+ * @param {GLTFParser} parser
2407
+ * @return {Promise<BufferGeometry>}
2408
+ */
2409
+ function addMorphTargets( geometry, targets, parser ) {
2410
+
2411
+ let hasMorphPosition = false;
2412
+ let hasMorphNormal = false;
2413
+ let hasMorphColor = false;
2414
+
2415
+ for ( let i = 0, il = targets.length; i < il; i ++ ) {
2416
+
2417
+ const target = targets[ i ];
2418
+
2419
+ if ( target.POSITION !== undefined ) hasMorphPosition = true;
2420
+ if ( target.NORMAL !== undefined ) hasMorphNormal = true;
2421
+ if ( target.COLOR_0 !== undefined ) hasMorphColor = true;
2422
+
2423
+ if ( hasMorphPosition && hasMorphNormal && hasMorphColor ) break;
2424
+
2425
+ }
2426
+
2427
+ if ( ! hasMorphPosition && ! hasMorphNormal && ! hasMorphColor ) return Promise.resolve( geometry );
2428
+
2429
+ const pendingPositionAccessors = [];
2430
+ const pendingNormalAccessors = [];
2431
+ const pendingColorAccessors = [];
2432
+
2433
+ for ( let i = 0, il = targets.length; i < il; i ++ ) {
2434
+
2435
+ const target = targets[ i ];
2436
+
2437
+ if ( hasMorphPosition ) {
2438
+
2439
+ const pendingAccessor = target.POSITION !== undefined
2440
+ ? parser.getDependency( 'accessor', target.POSITION )
2441
+ : geometry.attributes.position;
2442
+
2443
+ pendingPositionAccessors.push( pendingAccessor );
2444
+
2445
+ }
2446
+
2447
+ if ( hasMorphNormal ) {
2448
+
2449
+ const pendingAccessor = target.NORMAL !== undefined
2450
+ ? parser.getDependency( 'accessor', target.NORMAL )
2451
+ : geometry.attributes.normal;
2452
+
2453
+ pendingNormalAccessors.push( pendingAccessor );
2454
+
2455
+ }
2456
+
2457
+ if ( hasMorphColor ) {
2458
+
2459
+ const pendingAccessor = target.COLOR_0 !== undefined
2460
+ ? parser.getDependency( 'accessor', target.COLOR_0 )
2461
+ : geometry.attributes.color;
2462
+
2463
+ pendingColorAccessors.push( pendingAccessor );
2464
+
2465
+ }
2466
+
2467
+ }
2468
+
2469
+ return Promise.all( [
2470
+ Promise.all( pendingPositionAccessors ),
2471
+ Promise.all( pendingNormalAccessors ),
2472
+ Promise.all( pendingColorAccessors )
2473
+ ] ).then( function ( accessors ) {
2474
+
2475
+ const morphPositions = accessors[ 0 ];
2476
+ const morphNormals = accessors[ 1 ];
2477
+ const morphColors = accessors[ 2 ];
2478
+
2479
+ if ( hasMorphPosition ) geometry.morphAttributes.position = morphPositions;
2480
+ if ( hasMorphNormal ) geometry.morphAttributes.normal = morphNormals;
2481
+ if ( hasMorphColor ) geometry.morphAttributes.color = morphColors;
2482
+ geometry.morphTargetsRelative = true;
2483
+
2484
+ return geometry;
2485
+
2486
+ } );
2487
+
2488
+ }
2489
+
2490
+ /**
2491
+ *
2492
+ * @private
2493
+ * @param {Mesh} mesh
2494
+ * @param {GLTF.Mesh} meshDef
2495
+ */
2496
+ function updateMorphTargets( mesh, meshDef ) {
2497
+
2498
+ mesh.updateMorphTargets();
2499
+
2500
+ if ( meshDef.weights !== undefined ) {
2501
+
2502
+ for ( let i = 0, il = meshDef.weights.length; i < il; i ++ ) {
2503
+
2504
+ mesh.morphTargetInfluences[ i ] = meshDef.weights[ i ];
2505
+
2506
+ }
2507
+
2508
+ }
2509
+
2510
+ // .extras has user-defined data, so check that .extras.targetNames is an array.
2511
+ if ( meshDef.extras && Array.isArray( meshDef.extras.targetNames ) ) {
2512
+
2513
+ const targetNames = meshDef.extras.targetNames;
2514
+
2515
+ if ( mesh.morphTargetInfluences.length === targetNames.length ) {
2516
+
2517
+ mesh.morphTargetDictionary = {};
2518
+
2519
+ for ( let i = 0, il = targetNames.length; i < il; i ++ ) {
2520
+
2521
+ mesh.morphTargetDictionary[ targetNames[ i ] ] = i;
2522
+
2523
+ }
2524
+
2525
+ } else {
2526
+
2527
+ console.warn( 'THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.' );
2528
+
2529
+ }
2530
+
2531
+ }
2532
+
2533
+ }
2534
+
2535
+ function createPrimitiveKey( primitiveDef ) {
2536
+
2537
+ let geometryKey;
2538
+
2539
+ const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ];
2540
+
2541
+ if ( dracoExtension ) {
2542
+
2543
+ geometryKey = 'draco:' + dracoExtension.bufferView
2544
+ + ':' + dracoExtension.indices
2545
+ + ':' + createAttributesKey( dracoExtension.attributes );
2546
+
2547
+ } else {
2548
+
2549
+ geometryKey = primitiveDef.indices + ':' + createAttributesKey( primitiveDef.attributes ) + ':' + primitiveDef.mode;
2550
+
2551
+ }
2552
+
2553
+ if ( primitiveDef.targets !== undefined ) {
2554
+
2555
+ for ( let i = 0, il = primitiveDef.targets.length; i < il; i ++ ) {
2556
+
2557
+ geometryKey += ':' + createAttributesKey( primitiveDef.targets[ i ] );
2558
+
2559
+ }
2560
+
2561
+ }
2562
+
2563
+ return geometryKey;
2564
+
2565
+ }
2566
+
2567
+ function createAttributesKey( attributes ) {
2568
+
2569
+ let attributesKey = '';
2570
+
2571
+ const keys = Object.keys( attributes ).sort();
2572
+
2573
+ for ( let i = 0, il = keys.length; i < il; i ++ ) {
2574
+
2575
+ attributesKey += keys[ i ] + ':' + attributes[ keys[ i ] ] + ';';
2576
+
2577
+ }
2578
+
2579
+ return attributesKey;
2580
+
2581
+ }
2582
+
2583
+ function getNormalizedComponentScale( constructor ) {
2584
+
2585
+ // Reference:
2586
+ // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
2587
+
2588
+ switch ( constructor ) {
2589
+
2590
+ case Int8Array:
2591
+ return 1 / 127;
2592
+
2593
+ case Uint8Array:
2594
+ return 1 / 255;
2595
+
2596
+ case Int16Array:
2597
+ return 1 / 32767;
2598
+
2599
+ case Uint16Array:
2600
+ return 1 / 65535;
2601
+
2602
+ default:
2603
+ throw new Error( 'THREE.GLTFLoader: Unsupported normalized accessor component type.' );
2604
+
2605
+ }
2606
+
2607
+ }
2608
+
2609
+ function getImageURIMimeType( uri ) {
2610
+
2611
+ if ( uri.search( /\.jpe?g($|\?)/i ) > 0 || uri.search( /^data\:image\/jpeg/ ) === 0 ) return 'image/jpeg';
2612
+ if ( uri.search( /\.webp($|\?)/i ) > 0 || uri.search( /^data\:image\/webp/ ) === 0 ) return 'image/webp';
2613
+ if ( uri.search( /\.ktx2($|\?)/i ) > 0 || uri.search( /^data\:image\/ktx2/ ) === 0 ) return 'image/ktx2';
2614
+
2615
+ return 'image/png';
2616
+
2617
+ }
2618
+
2619
+ const _identityMatrix = new Matrix4();
2620
+
2621
+ /* GLTF PARSER */
2622
+
2623
+ class GLTFParser {
2624
+
2625
+ constructor( json = {}, options = {} ) {
2626
+
2627
+ this.json = json;
2628
+ this.extensions = {};
2629
+ this.plugins = {};
2630
+ this.options = options;
2631
+
2632
+ // loader object cache
2633
+ this.cache = new GLTFRegistry();
2634
+
2635
+ // associations between Three.js objects and glTF elements
2636
+ this.associations = new Map();
2637
+
2638
+ // BufferGeometry caching
2639
+ this.primitiveCache = {};
2640
+
2641
+ // Node cache
2642
+ this.nodeCache = {};
2643
+
2644
+ // Object3D instance caches
2645
+ this.meshCache = { refs: {}, uses: {} };
2646
+ this.cameraCache = { refs: {}, uses: {} };
2647
+ this.lightCache = { refs: {}, uses: {} };
2648
+
2649
+ this.sourceCache = {};
2650
+ this.textureCache = {};
2651
+
2652
+ // Track node names, to ensure no duplicates
2653
+ this.nodeNamesUsed = {};
2654
+
2655
+ // Use an ImageBitmapLoader if imageBitmaps are supported. Moves much of the
2656
+ // expensive work of uploading a texture to the GPU off the main thread.
2657
+
2658
+ let isSafari = false;
2659
+ let safariVersion = - 1;
2660
+ let isFirefox = false;
2661
+ let firefoxVersion = - 1;
2662
+
2663
+ if ( typeof navigator !== 'undefined' ) {
2664
+
2665
+ const userAgent = navigator.userAgent;
2666
+
2667
+ isSafari = /^((?!chrome|android).)*safari/i.test( userAgent ) === true;
2668
+ const safariMatch = userAgent.match( /Version\/(\d+)/ );
2669
+ safariVersion = isSafari && safariMatch ? parseInt( safariMatch[ 1 ], 10 ) : - 1;
2670
+
2671
+ isFirefox = userAgent.indexOf( 'Firefox' ) > - 1;
2672
+ firefoxVersion = isFirefox ? userAgent.match( /Firefox\/([0-9]+)\./ )[ 1 ] : - 1;
2673
+
2674
+ }
2675
+
2676
+ if ( typeof createImageBitmap === 'undefined' || ( isSafari && safariVersion < 17 ) || ( isFirefox && firefoxVersion < 98 ) ) {
2677
+
2678
+ this.textureLoader = new TextureLoader( this.options.manager );
2679
+
2680
+ } else {
2681
+
2682
+ this.textureLoader = new ImageBitmapLoader( this.options.manager );
2683
+
2684
+ }
2685
+
2686
+ this.textureLoader.setCrossOrigin( this.options.crossOrigin );
2687
+ this.textureLoader.setRequestHeader( this.options.requestHeader );
2688
+
2689
+ this.fileLoader = new FileLoader( this.options.manager );
2690
+ this.fileLoader.setResponseType( 'arraybuffer' );
2691
+
2692
+ if ( this.options.crossOrigin === 'use-credentials' ) {
2693
+
2694
+ this.fileLoader.setWithCredentials( true );
2695
+
2696
+ }
2697
+
2698
+ }
2699
+
2700
+ setExtensions( extensions ) {
2701
+
2702
+ this.extensions = extensions;
2703
+
2704
+ }
2705
+
2706
+ setPlugins( plugins ) {
2707
+
2708
+ this.plugins = plugins;
2709
+
2710
+ }
2711
+
2712
+ parse( onLoad, onError ) {
2713
+
2714
+ const parser = this;
2715
+ const json = this.json;
2716
+ const extensions = this.extensions;
2717
+
2718
+ // Clear the loader cache
2719
+ this.cache.removeAll();
2720
+ this.nodeCache = {};
2721
+
2722
+ // Mark the special nodes/meshes in json for efficient parse
2723
+ this._invokeAll( function ( ext ) {
2724
+
2725
+ return ext._markDefs && ext._markDefs();
2726
+
2727
+ } );
2728
+
2729
+ Promise.all( this._invokeAll( function ( ext ) {
2730
+
2731
+ return ext.beforeRoot && ext.beforeRoot();
2732
+
2733
+ } ) ).then( function () {
2734
+
2735
+ return Promise.all( [
2736
+
2737
+ parser.getDependencies( 'scene' ),
2738
+ parser.getDependencies( 'animation' ),
2739
+ parser.getDependencies( 'camera' ),
2740
+
2741
+ ] );
2742
+
2743
+ } ).then( function ( dependencies ) {
2744
+
2745
+ const result = {
2746
+ scene: dependencies[ 0 ][ json.scene || 0 ],
2747
+ scenes: dependencies[ 0 ],
2748
+ animations: dependencies[ 1 ],
2749
+ cameras: dependencies[ 2 ],
2750
+ asset: json.asset,
2751
+ parser: parser,
2752
+ userData: {}
2753
+ };
2754
+
2755
+ addUnknownExtensionsToUserData( extensions, result, json );
2756
+
2757
+ assignExtrasToUserData( result, json );
2758
+
2759
+ return Promise.all( parser._invokeAll( function ( ext ) {
2760
+
2761
+ return ext.afterRoot && ext.afterRoot( result );
2762
+
2763
+ } ) ).then( function () {
2764
+
2765
+ for ( const scene of result.scenes ) {
2766
+
2767
+ scene.updateMatrixWorld();
2768
+
2769
+ }
2770
+
2771
+ onLoad( result );
2772
+
2773
+ } );
2774
+
2775
+ } ).catch( onError );
2776
+
2777
+ }
2778
+
2779
+ /**
2780
+ * Marks the special nodes/meshes in json for efficient parse.
2781
+ *
2782
+ * @private
2783
+ */
2784
+ _markDefs() {
2785
+
2786
+ const nodeDefs = this.json.nodes || [];
2787
+ const skinDefs = this.json.skins || [];
2788
+ const meshDefs = this.json.meshes || [];
2789
+
2790
+ // Nothing in the node definition indicates whether it is a Bone or an
2791
+ // Object3D. Use the skins' joint references to mark bones.
2792
+ for ( let skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex ++ ) {
2793
+
2794
+ const joints = skinDefs[ skinIndex ].joints;
2795
+
2796
+ for ( let i = 0, il = joints.length; i < il; i ++ ) {
2797
+
2798
+ nodeDefs[ joints[ i ] ].isBone = true;
2799
+
2800
+ }
2801
+
2802
+ }
2803
+
2804
+ // Iterate over all nodes, marking references to shared resources,
2805
+ // as well as skeleton joints.
2806
+ for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) {
2807
+
2808
+ const nodeDef = nodeDefs[ nodeIndex ];
2809
+
2810
+ if ( nodeDef.mesh !== undefined ) {
2811
+
2812
+ this._addNodeRef( this.meshCache, nodeDef.mesh );
2813
+
2814
+ // Nothing in the mesh definition indicates whether it is
2815
+ // a SkinnedMesh or Mesh. Use the node's mesh reference
2816
+ // to mark SkinnedMesh if node has skin.
2817
+ if ( nodeDef.skin !== undefined ) {
2818
+
2819
+ meshDefs[ nodeDef.mesh ].isSkinnedMesh = true;
2820
+
2821
+ }
2822
+
2823
+ }
2824
+
2825
+ if ( nodeDef.camera !== undefined ) {
2826
+
2827
+ this._addNodeRef( this.cameraCache, nodeDef.camera );
2828
+
2829
+ }
2830
+
2831
+ }
2832
+
2833
+ }
2834
+
2835
+ /**
2836
+ * Counts references to shared node / Object3D resources. These resources
2837
+ * can be reused, or "instantiated", at multiple nodes in the scene
2838
+ * hierarchy. Mesh, Camera, and Light instances are instantiated and must
2839
+ * be marked. Non-scenegraph resources (like Materials, Geometries, and
2840
+ * Textures) can be reused directly and are not marked here.
2841
+ *
2842
+ * Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
2843
+ *
2844
+ * @private
2845
+ * @param {Object} cache
2846
+ * @param {Object3D} index
2847
+ */
2848
+ _addNodeRef( cache, index ) {
2849
+
2850
+ if ( index === undefined ) return;
2851
+
2852
+ if ( cache.refs[ index ] === undefined ) {
2853
+
2854
+ cache.refs[ index ] = cache.uses[ index ] = 0;
2855
+
2856
+ }
2857
+
2858
+ cache.refs[ index ] ++;
2859
+
2860
+ }
2861
+
2862
+ /**
2863
+ * Returns a reference to a shared resource, cloning it if necessary.
2864
+ *
2865
+ * @private
2866
+ * @param {Object} cache
2867
+ * @param {number} index
2868
+ * @param {Object} object
2869
+ * @return {Object}
2870
+ */
2871
+ _getNodeRef( cache, index, object ) {
2872
+
2873
+ if ( cache.refs[ index ] <= 1 ) return object;
2874
+
2875
+ const ref = object.clone();
2876
+
2877
+ // Propagates mappings to the cloned object, prevents mappings on the
2878
+ // original object from being lost.
2879
+ const updateMappings = ( original, clone ) => {
2880
+
2881
+ const mappings = this.associations.get( original );
2882
+ if ( mappings != null ) {
2883
+
2884
+ this.associations.set( clone, mappings );
2885
+
2886
+ }
2887
+
2888
+ for ( const [ i, child ] of original.children.entries() ) {
2889
+
2890
+ updateMappings( child, clone.children[ i ] );
2891
+
2892
+ }
2893
+
2894
+ };
2895
+
2896
+ updateMappings( object, ref );
2897
+
2898
+ ref.name += '_instance_' + ( cache.uses[ index ] ++ );
2899
+
2900
+ return ref;
2901
+
2902
+ }
2903
+
2904
+ _invokeOne( func ) {
2905
+
2906
+ const extensions = Object.values( this.plugins );
2907
+ extensions.push( this );
2908
+
2909
+ for ( let i = 0; i < extensions.length; i ++ ) {
2910
+
2911
+ const result = func( extensions[ i ] );
2912
+
2913
+ if ( result ) return result;
2914
+
2915
+ }
2916
+
2917
+ return null;
2918
+
2919
+ }
2920
+
2921
+ _invokeAll( func ) {
2922
+
2923
+ const extensions = Object.values( this.plugins );
2924
+ extensions.unshift( this );
2925
+
2926
+ const pending = [];
2927
+
2928
+ for ( let i = 0; i < extensions.length; i ++ ) {
2929
+
2930
+ const result = func( extensions[ i ] );
2931
+
2932
+ if ( result ) pending.push( result );
2933
+
2934
+ }
2935
+
2936
+ return pending;
2937
+
2938
+ }
2939
+
2940
+ /**
2941
+ * Requests the specified dependency asynchronously, with caching.
2942
+ *
2943
+ * @private
2944
+ * @param {string} type
2945
+ * @param {number} index
2946
+ * @return {Promise<Object3D|Material|Texture|AnimationClip|ArrayBuffer|Object>}
2947
+ */
2948
+ getDependency( type, index ) {
2949
+
2950
+ const cacheKey = type + ':' + index;
2951
+ let dependency = this.cache.get( cacheKey );
2952
+
2953
+ if ( ! dependency ) {
2954
+
2955
+ switch ( type ) {
2956
+
2957
+ case 'scene':
2958
+ dependency = this.loadScene( index );
2959
+ break;
2960
+
2961
+ case 'node':
2962
+ dependency = this._invokeOne( function ( ext ) {
2963
+
2964
+ return ext.loadNode && ext.loadNode( index );
2965
+
2966
+ } );
2967
+ break;
2968
+
2969
+ case 'mesh':
2970
+ dependency = this._invokeOne( function ( ext ) {
2971
+
2972
+ return ext.loadMesh && ext.loadMesh( index );
2973
+
2974
+ } );
2975
+ break;
2976
+
2977
+ case 'accessor':
2978
+ dependency = this.loadAccessor( index );
2979
+ break;
2980
+
2981
+ case 'bufferView':
2982
+ dependency = this._invokeOne( function ( ext ) {
2983
+
2984
+ return ext.loadBufferView && ext.loadBufferView( index );
2985
+
2986
+ } );
2987
+ break;
2988
+
2989
+ case 'buffer':
2990
+ dependency = this.loadBuffer( index );
2991
+ break;
2992
+
2993
+ case 'material':
2994
+ dependency = this._invokeOne( function ( ext ) {
2995
+
2996
+ return ext.loadMaterial && ext.loadMaterial( index );
2997
+
2998
+ } );
2999
+ break;
3000
+
3001
+ case 'texture':
3002
+ dependency = this._invokeOne( function ( ext ) {
3003
+
3004
+ return ext.loadTexture && ext.loadTexture( index );
3005
+
3006
+ } );
3007
+ break;
3008
+
3009
+ case 'skin':
3010
+ dependency = this.loadSkin( index );
3011
+ break;
3012
+
3013
+ case 'animation':
3014
+ dependency = this._invokeOne( function ( ext ) {
3015
+
3016
+ return ext.loadAnimation && ext.loadAnimation( index );
3017
+
3018
+ } );
3019
+ break;
3020
+
3021
+ case 'camera':
3022
+ dependency = this.loadCamera( index );
3023
+ break;
3024
+
3025
+ default:
3026
+ dependency = this._invokeOne( function ( ext ) {
3027
+
3028
+ return ext != this && ext.getDependency && ext.getDependency( type, index );
3029
+
3030
+ } );
3031
+
3032
+ if ( ! dependency ) {
3033
+
3034
+ throw new Error( 'Unknown type: ' + type );
3035
+
3036
+ }
3037
+
3038
+ break;
3039
+
3040
+ }
3041
+
3042
+ this.cache.add( cacheKey, dependency );
3043
+
3044
+ }
3045
+
3046
+ return dependency;
3047
+
3048
+ }
3049
+
3050
+ /**
3051
+ * Requests all dependencies of the specified type asynchronously, with caching.
3052
+ *
3053
+ * @private
3054
+ * @param {string} type
3055
+ * @return {Promise<Array<Object>>}
3056
+ */
3057
+ getDependencies( type ) {
3058
+
3059
+ let dependencies = this.cache.get( type );
3060
+
3061
+ if ( ! dependencies ) {
3062
+
3063
+ const parser = this;
3064
+ const defs = this.json[ type + ( type === 'mesh' ? 'es' : 's' ) ] || [];
3065
+
3066
+ dependencies = Promise.all( defs.map( function ( def, index ) {
3067
+
3068
+ return parser.getDependency( type, index );
3069
+
3070
+ } ) );
3071
+
3072
+ this.cache.add( type, dependencies );
3073
+
3074
+ }
3075
+
3076
+ return dependencies;
3077
+
3078
+ }
3079
+
3080
+ /**
3081
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
3082
+ *
3083
+ * @private
3084
+ * @param {number} bufferIndex
3085
+ * @return {Promise<ArrayBuffer>}
3086
+ */
3087
+ loadBuffer( bufferIndex ) {
3088
+
3089
+ const bufferDef = this.json.buffers[ bufferIndex ];
3090
+ const loader = this.fileLoader;
3091
+
3092
+ if ( bufferDef.type && bufferDef.type !== 'arraybuffer' ) {
3093
+
3094
+ throw new Error( 'THREE.GLTFLoader: ' + bufferDef.type + ' buffer type is not supported.' );
3095
+
3096
+ }
3097
+
3098
+ // If present, GLB container is required to be the first buffer.
3099
+ if ( bufferDef.uri === undefined && bufferIndex === 0 ) {
3100
+
3101
+ return Promise.resolve( this.extensions[ EXTENSIONS.KHR_BINARY_GLTF ].body );
3102
+
3103
+ }
3104
+
3105
+ const options = this.options;
3106
+
3107
+ return new Promise( function ( resolve, reject ) {
3108
+
3109
+ loader.load( LoaderUtils.resolveURL( bufferDef.uri, options.path ), resolve, undefined, function () {
3110
+
3111
+ reject( new Error( 'THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".' ) );
3112
+
3113
+ } );
3114
+
3115
+ } );
3116
+
3117
+ }
3118
+
3119
+ /**
3120
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
3121
+ *
3122
+ * @private
3123
+ * @param {number} bufferViewIndex
3124
+ * @return {Promise<ArrayBuffer>}
3125
+ */
3126
+ loadBufferView( bufferViewIndex ) {
3127
+
3128
+ const bufferViewDef = this.json.bufferViews[ bufferViewIndex ];
3129
+
3130
+ return this.getDependency( 'buffer', bufferViewDef.buffer ).then( function ( buffer ) {
3131
+
3132
+ const byteLength = bufferViewDef.byteLength || 0;
3133
+ const byteOffset = bufferViewDef.byteOffset || 0;
3134
+ return buffer.slice( byteOffset, byteOffset + byteLength );
3135
+
3136
+ } );
3137
+
3138
+ }
3139
+
3140
+ /**
3141
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
3142
+ *
3143
+ * @private
3144
+ * @param {number} accessorIndex
3145
+ * @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
3146
+ */
3147
+ loadAccessor( accessorIndex ) {
3148
+
3149
+ const parser = this;
3150
+ const json = this.json;
3151
+
3152
+ const accessorDef = this.json.accessors[ accessorIndex ];
3153
+
3154
+ if ( accessorDef.bufferView === undefined && accessorDef.sparse === undefined ) {
3155
+
3156
+ const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ];
3157
+ const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
3158
+ const normalized = accessorDef.normalized === true;
3159
+
3160
+ const array = new TypedArray( accessorDef.count * itemSize );
3161
+ return Promise.resolve( new BufferAttribute( array, itemSize, normalized ) );
3162
+
3163
+ }
3164
+
3165
+ const pendingBufferViews = [];
3166
+
3167
+ if ( accessorDef.bufferView !== undefined ) {
3168
+
3169
+ pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.bufferView ) );
3170
+
3171
+ } else {
3172
+
3173
+ pendingBufferViews.push( null );
3174
+
3175
+ }
3176
+
3177
+ if ( accessorDef.sparse !== undefined ) {
3178
+
3179
+ pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.sparse.indices.bufferView ) );
3180
+ pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.sparse.values.bufferView ) );
3181
+
3182
+ }
3183
+
3184
+ return Promise.all( pendingBufferViews ).then( function ( bufferViews ) {
3185
+
3186
+ const bufferView = bufferViews[ 0 ];
3187
+
3188
+ const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ];
3189
+ const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
3190
+
3191
+ // For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12.
3192
+ const elementBytes = TypedArray.BYTES_PER_ELEMENT;
3193
+ const itemBytes = elementBytes * itemSize;
3194
+ const byteOffset = accessorDef.byteOffset || 0;
3195
+ const byteStride = accessorDef.bufferView !== undefined ? json.bufferViews[ accessorDef.bufferView ].byteStride : undefined;
3196
+ const normalized = accessorDef.normalized === true;
3197
+ let array, bufferAttribute;
3198
+
3199
+ // The buffer is not interleaved if the stride is the item size in bytes.
3200
+ if ( byteStride && byteStride !== itemBytes ) {
3201
+
3202
+ // Each "slice" of the buffer, as defined by 'count' elements of 'byteStride' bytes, gets its own InterleavedBuffer
3203
+ // This makes sure that IBA.count reflects accessor.count properly
3204
+ const ibSlice = Math.floor( byteOffset / byteStride );
3205
+ const ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType + ':' + ibSlice + ':' + accessorDef.count;
3206
+ let ib = parser.cache.get( ibCacheKey );
3207
+
3208
+ if ( ! ib ) {
3209
+
3210
+ array = new TypedArray( bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes );
3211
+
3212
+ // Integer parameters to IB/IBA are in array elements, not bytes.
3213
+ ib = new InterleavedBuffer( array, byteStride / elementBytes );
3214
+
3215
+ parser.cache.add( ibCacheKey, ib );
3216
+
3217
+ }
3218
+
3219
+ bufferAttribute = new InterleavedBufferAttribute( ib, itemSize, ( byteOffset % byteStride ) / elementBytes, normalized );
3220
+
3221
+ } else {
3222
+
3223
+ if ( bufferView === null ) {
3224
+
3225
+ array = new TypedArray( accessorDef.count * itemSize );
3226
+
3227
+ } else {
3228
+
3229
+ array = new TypedArray( bufferView, byteOffset, accessorDef.count * itemSize );
3230
+
3231
+ }
3232
+
3233
+ bufferAttribute = new BufferAttribute( array, itemSize, normalized );
3234
+
3235
+ }
3236
+
3237
+ // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#sparse-accessors
3238
+ if ( accessorDef.sparse !== undefined ) {
3239
+
3240
+ const itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
3241
+ const TypedArrayIndices = WEBGL_COMPONENT_TYPES[ accessorDef.sparse.indices.componentType ];
3242
+
3243
+ const byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
3244
+ const byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
3245
+
3246
+ const sparseIndices = new TypedArrayIndices( bufferViews[ 1 ], byteOffsetIndices, accessorDef.sparse.count * itemSizeIndices );
3247
+ const sparseValues = new TypedArray( bufferViews[ 2 ], byteOffsetValues, accessorDef.sparse.count * itemSize );
3248
+
3249
+ if ( bufferView !== null ) {
3250
+
3251
+ // Avoid modifying the original ArrayBuffer, if the bufferView wasn't initialized with zeroes.
3252
+ bufferAttribute = new BufferAttribute( bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized );
3253
+
3254
+ }
3255
+
3256
+ // Ignore normalized since we copy from sparse
3257
+ bufferAttribute.normalized = false;
3258
+
3259
+ for ( let i = 0, il = sparseIndices.length; i < il; i ++ ) {
3260
+
3261
+ const index = sparseIndices[ i ];
3262
+
3263
+ bufferAttribute.setX( index, sparseValues[ i * itemSize ] );
3264
+ if ( itemSize >= 2 ) bufferAttribute.setY( index, sparseValues[ i * itemSize + 1 ] );
3265
+ if ( itemSize >= 3 ) bufferAttribute.setZ( index, sparseValues[ i * itemSize + 2 ] );
3266
+ if ( itemSize >= 4 ) bufferAttribute.setW( index, sparseValues[ i * itemSize + 3 ] );
3267
+ if ( itemSize >= 5 ) throw new Error( 'THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.' );
3268
+
3269
+ }
3270
+
3271
+ bufferAttribute.normalized = normalized;
3272
+
3273
+ }
3274
+
3275
+ return bufferAttribute;
3276
+
3277
+ } );
3278
+
3279
+ }
3280
+
3281
+ /**
3282
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
3283
+ *
3284
+ * @private
3285
+ * @param {number} textureIndex
3286
+ * @return {Promise<?Texture>}
3287
+ */
3288
+ loadTexture( textureIndex ) {
3289
+
3290
+ const json = this.json;
3291
+ const options = this.options;
3292
+ const textureDef = json.textures[ textureIndex ];
3293
+ const sourceIndex = textureDef.source;
3294
+ const sourceDef = json.images[ sourceIndex ];
3295
+
3296
+ let loader = this.textureLoader;
3297
+
3298
+ if ( sourceDef.uri ) {
3299
+
3300
+ const handler = options.manager.getHandler( sourceDef.uri );
3301
+ if ( handler !== null ) loader = handler;
3302
+
3303
+ }
3304
+
3305
+ return this.loadTextureImage( textureIndex, sourceIndex, loader );
3306
+
3307
+ }
3308
+
3309
+ loadTextureImage( textureIndex, sourceIndex, loader ) {
3310
+
3311
+ const parser = this;
3312
+ const json = this.json;
3313
+
3314
+ const textureDef = json.textures[ textureIndex ];
3315
+ const sourceDef = json.images[ sourceIndex ];
3316
+
3317
+ const cacheKey = ( sourceDef.uri || sourceDef.bufferView ) + ':' + textureDef.sampler;
3318
+
3319
+ if ( this.textureCache[ cacheKey ] ) {
3320
+
3321
+ // See https://github.com/mrdoob/three.js/issues/21559.
3322
+ return this.textureCache[ cacheKey ];
3323
+
3324
+ }
3325
+
3326
+ const promise = this.loadImageSource( sourceIndex, loader ).then( function ( texture ) {
3327
+
3328
+ texture.flipY = false;
3329
+
3330
+ texture.name = textureDef.name || sourceDef.name || '';
3331
+
3332
+ if ( texture.name === '' && typeof sourceDef.uri === 'string' && sourceDef.uri.startsWith( 'data:image/' ) === false ) {
3333
+
3334
+ texture.name = sourceDef.uri;
3335
+
3336
+ }
3337
+
3338
+ const samplers = json.samplers || {};
3339
+ const sampler = samplers[ textureDef.sampler ] || {};
3340
+
3341
+ texture.magFilter = WEBGL_FILTERS[ sampler.magFilter ] || LinearFilter;
3342
+ texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || LinearMipmapLinearFilter;
3343
+ texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || RepeatWrapping;
3344
+ texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || RepeatWrapping;
3345
+ texture.generateMipmaps = ! texture.isCompressedTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
3346
+
3347
+ parser.associations.set( texture, { textures: textureIndex } );
3348
+
3349
+ return texture;
3350
+
3351
+ } ).catch( function () {
3352
+
3353
+ return null;
3354
+
3355
+ } );
3356
+
3357
+ this.textureCache[ cacheKey ] = promise;
3358
+
3359
+ return promise;
3360
+
3361
+ }
3362
+
3363
+ loadImageSource( sourceIndex, loader ) {
3364
+
3365
+ const parser = this;
3366
+ const json = this.json;
3367
+ const options = this.options;
3368
+
3369
+ if ( this.sourceCache[ sourceIndex ] !== undefined ) {
3370
+
3371
+ return this.sourceCache[ sourceIndex ].then( ( texture ) => texture.clone() );
3372
+
3373
+ }
3374
+
3375
+ const sourceDef = json.images[ sourceIndex ];
3376
+
3377
+ const URL = self.URL || self.webkitURL;
3378
+
3379
+ let sourceURI = sourceDef.uri || '';
3380
+ let isObjectURL = false;
3381
+
3382
+ if ( sourceDef.bufferView !== undefined ) {
3383
+
3384
+ // Load binary image data from bufferView, if provided.
3385
+
3386
+ sourceURI = parser.getDependency( 'bufferView', sourceDef.bufferView ).then( function ( bufferView ) {
3387
+
3388
+ isObjectURL = true;
3389
+ const blob = new Blob( [ bufferView ], { type: sourceDef.mimeType } );
3390
+ sourceURI = URL.createObjectURL( blob );
3391
+ return sourceURI;
3392
+
3393
+ } );
3394
+
3395
+ } else if ( sourceDef.uri === undefined ) {
3396
+
3397
+ throw new Error( 'THREE.GLTFLoader: Image ' + sourceIndex + ' is missing URI and bufferView' );
3398
+
3399
+ }
3400
+
3401
+ const promise = Promise.resolve( sourceURI ).then( function ( sourceURI ) {
3402
+
3403
+ return new Promise( function ( resolve, reject ) {
3404
+
3405
+ let onLoad = resolve;
3406
+
3407
+ if ( loader.isImageBitmapLoader === true ) {
3408
+
3409
+ onLoad = function ( imageBitmap ) {
3410
+
3411
+ const texture = new Texture( imageBitmap );
3412
+ texture.needsUpdate = true;
3413
+
3414
+ resolve( texture );
3415
+
3416
+ };
3417
+
3418
+ }
3419
+
3420
+ loader.load( LoaderUtils.resolveURL( sourceURI, options.path ), onLoad, undefined, reject );
3421
+
3422
+ } );
3423
+
3424
+ } ).then( function ( texture ) {
3425
+
3426
+ // Clean up resources and configure Texture.
3427
+
3428
+ if ( isObjectURL === true ) {
3429
+
3430
+ URL.revokeObjectURL( sourceURI );
3431
+
3432
+ }
3433
+
3434
+ assignExtrasToUserData( texture, sourceDef );
3435
+
3436
+ texture.userData.mimeType = sourceDef.mimeType || getImageURIMimeType( sourceDef.uri );
3437
+
3438
+ return texture;
3439
+
3440
+ } ).catch( function ( error ) {
3441
+
3442
+ console.error( 'THREE.GLTFLoader: Couldn\'t load texture', sourceURI );
3443
+ throw error;
3444
+
3445
+ } );
3446
+
3447
+ this.sourceCache[ sourceIndex ] = promise;
3448
+ return promise;
3449
+
3450
+ }
3451
+
3452
+ /**
3453
+ * Asynchronously assigns a texture to the given material parameters.
3454
+ *
3455
+ * @private
3456
+ * @param {Object} materialParams
3457
+ * @param {string} mapName
3458
+ * @param {Object} mapDef
3459
+ * @param {string} [colorSpace]
3460
+ * @return {Promise<Texture>}
3461
+ */
3462
+ assignTexture( materialParams, mapName, mapDef, colorSpace ) {
3463
+
3464
+ const parser = this;
3465
+
3466
+ return this.getDependency( 'texture', mapDef.index ).then( function ( texture ) {
3467
+
3468
+ if ( ! texture ) return null;
3469
+
3470
+ if ( mapDef.texCoord !== undefined && mapDef.texCoord > 0 ) {
3471
+
3472
+ texture = texture.clone();
3473
+ texture.channel = mapDef.texCoord;
3474
+
3475
+ }
3476
+
3477
+ if ( parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] ) {
3478
+
3479
+ const transform = mapDef.extensions !== undefined ? mapDef.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] : undefined;
3480
+
3481
+ if ( transform ) {
3482
+
3483
+ const gltfReference = parser.associations.get( texture );
3484
+ texture = parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ].extendTexture( texture, transform );
3485
+ parser.associations.set( texture, gltfReference );
3486
+
3487
+ }
3488
+
3489
+ }
3490
+
3491
+ if ( colorSpace !== undefined ) {
3492
+
3493
+ texture.colorSpace = colorSpace;
3494
+
3495
+ }
3496
+
3497
+ materialParams[ mapName ] = texture;
3498
+
3499
+ return texture;
3500
+
3501
+ } );
3502
+
3503
+ }
3504
+
3505
+ /**
3506
+ * Assigns final material to a Mesh, Line, or Points instance. The instance
3507
+ * already has a material (generated from the glTF material options alone)
3508
+ * but reuse of the same glTF material may require multiple threejs materials
3509
+ * to accommodate different primitive types, defines, etc. New materials will
3510
+ * be created if necessary, and reused from a cache.
3511
+ *
3512
+ * @private
3513
+ * @param {Object3D} mesh Mesh, Line, or Points instance.
3514
+ */
3515
+ assignFinalMaterial( mesh ) {
3516
+
3517
+ const geometry = mesh.geometry;
3518
+ let material = mesh.material;
3519
+
3520
+ const useDerivativeTangents = geometry.attributes.tangent === undefined;
3521
+ const useVertexColors = geometry.attributes.color !== undefined;
3522
+ const useFlatShading = geometry.attributes.normal === undefined;
3523
+
3524
+ if ( mesh.isPoints ) {
3525
+
3526
+ const cacheKey = 'PointsMaterial:' + material.uuid;
3527
+
3528
+ let pointsMaterial = this.cache.get( cacheKey );
3529
+
3530
+ if ( ! pointsMaterial ) {
3531
+
3532
+ pointsMaterial = new PointsMaterial();
3533
+ Material.prototype.copy.call( pointsMaterial, material );
3534
+ pointsMaterial.color.copy( material.color );
3535
+ pointsMaterial.map = material.map;
3536
+ pointsMaterial.sizeAttenuation = false; // glTF spec says points should be 1px
3537
+
3538
+ this.cache.add( cacheKey, pointsMaterial );
3539
+
3540
+ }
3541
+
3542
+ material = pointsMaterial;
3543
+
3544
+ } else if ( mesh.isLine ) {
3545
+
3546
+ const cacheKey = 'LineBasicMaterial:' + material.uuid;
3547
+
3548
+ let lineMaterial = this.cache.get( cacheKey );
3549
+
3550
+ if ( ! lineMaterial ) {
3551
+
3552
+ lineMaterial = new LineBasicMaterial();
3553
+ Material.prototype.copy.call( lineMaterial, material );
3554
+ lineMaterial.color.copy( material.color );
3555
+ lineMaterial.map = material.map;
3556
+
3557
+ this.cache.add( cacheKey, lineMaterial );
3558
+
3559
+ }
3560
+
3561
+ material = lineMaterial;
3562
+
3563
+ }
3564
+
3565
+ // Clone the material if it will be modified
3566
+ if ( useDerivativeTangents || useVertexColors || useFlatShading ) {
3567
+
3568
+ let cacheKey = 'ClonedMaterial:' + material.uuid + ':';
3569
+
3570
+ if ( useDerivativeTangents ) cacheKey += 'derivative-tangents:';
3571
+ if ( useVertexColors ) cacheKey += 'vertex-colors:';
3572
+ if ( useFlatShading ) cacheKey += 'flat-shading:';
3573
+
3574
+ let cachedMaterial = this.cache.get( cacheKey );
3575
+
3576
+ if ( ! cachedMaterial ) {
3577
+
3578
+ cachedMaterial = material.clone();
3579
+
3580
+ if ( useVertexColors ) cachedMaterial.vertexColors = true;
3581
+ if ( useFlatShading ) cachedMaterial.flatShading = true;
3582
+
3583
+ if ( useDerivativeTangents ) {
3584
+
3585
+ // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
3586
+ if ( cachedMaterial.normalScale ) cachedMaterial.normalScale.y *= - 1;
3587
+ if ( cachedMaterial.clearcoatNormalScale ) cachedMaterial.clearcoatNormalScale.y *= - 1;
3588
+
3589
+ }
3590
+
3591
+ this.cache.add( cacheKey, cachedMaterial );
3592
+
3593
+ this.associations.set( cachedMaterial, this.associations.get( material ) );
3594
+
3595
+ }
3596
+
3597
+ material = cachedMaterial;
3598
+
3599
+ }
3600
+
3601
+ mesh.material = material;
3602
+
3603
+ }
3604
+
3605
+ getMaterialType( /* materialIndex */ ) {
3606
+
3607
+ return MeshStandardMaterial;
3608
+
3609
+ }
3610
+
3611
+ /**
3612
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
3613
+ *
3614
+ * @private
3615
+ * @param {number} materialIndex
3616
+ * @return {Promise<Material>}
3617
+ */
3618
+ loadMaterial( materialIndex ) {
3619
+
3620
+ const parser = this;
3621
+ const json = this.json;
3622
+ const extensions = this.extensions;
3623
+ const materialDef = json.materials[ materialIndex ];
3624
+
3625
+ let materialType;
3626
+ const materialParams = {};
3627
+ const materialExtensions = materialDef.extensions || {};
3628
+
3629
+ const pending = [];
3630
+
3631
+ if ( materialExtensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ] ) {
3632
+
3633
+ const kmuExtension = extensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ];
3634
+ materialType = kmuExtension.getMaterialType();
3635
+ pending.push( kmuExtension.extendParams( materialParams, materialDef, parser ) );
3636
+
3637
+ } else {
3638
+
3639
+ // Specification:
3640
+ // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material
3641
+
3642
+ const metallicRoughness = materialDef.pbrMetallicRoughness || {};
3643
+
3644
+ materialParams.color = new Color( 1.0, 1.0, 1.0 );
3645
+ materialParams.opacity = 1.0;
3646
+
3647
+ if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
3648
+
3649
+ const array = metallicRoughness.baseColorFactor;
3650
+
3651
+ materialParams.color.setRGB( array[ 0 ], array[ 1 ], array[ 2 ], LinearSRGBColorSpace );
3652
+ materialParams.opacity = array[ 3 ];
3653
+
3654
+ }
3655
+
3656
+ if ( metallicRoughness.baseColorTexture !== undefined ) {
3657
+
3658
+ pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, SRGBColorSpace ) );
3659
+
3660
+ }
3661
+
3662
+ materialParams.metalness = metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0;
3663
+ materialParams.roughness = metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0;
3664
+
3665
+ if ( metallicRoughness.metallicRoughnessTexture !== undefined ) {
3666
+
3667
+ pending.push( parser.assignTexture( materialParams, 'metalnessMap', metallicRoughness.metallicRoughnessTexture ) );
3668
+ pending.push( parser.assignTexture( materialParams, 'roughnessMap', metallicRoughness.metallicRoughnessTexture ) );
3669
+
3670
+ }
3671
+
3672
+ materialType = this._invokeOne( function ( ext ) {
3673
+
3674
+ return ext.getMaterialType && ext.getMaterialType( materialIndex );
3675
+
3676
+ } );
3677
+
3678
+ pending.push( Promise.all( this._invokeAll( function ( ext ) {
3679
+
3680
+ return ext.extendMaterialParams && ext.extendMaterialParams( materialIndex, materialParams );
3681
+
3682
+ } ) ) );
3683
+
3684
+ }
3685
+
3686
+ if ( materialDef.doubleSided === true ) {
3687
+
3688
+ materialParams.side = DoubleSide;
3689
+
3690
+ }
3691
+
3692
+ const alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
3693
+
3694
+ if ( alphaMode === ALPHA_MODES.BLEND ) {
3695
+
3696
+ materialParams.transparent = true;
3697
+
3698
+ // See: https://github.com/mrdoob/three.js/issues/17706
3699
+ materialParams.depthWrite = false;
3700
+
3701
+ } else {
3702
+
3703
+ materialParams.transparent = false;
3704
+
3705
+ if ( alphaMode === ALPHA_MODES.MASK ) {
3706
+
3707
+ materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
3708
+
3709
+ }
3710
+
3711
+ }
3712
+
3713
+ if ( materialDef.normalTexture !== undefined && materialType !== MeshBasicMaterial ) {
3714
+
3715
+ pending.push( parser.assignTexture( materialParams, 'normalMap', materialDef.normalTexture ) );
3716
+
3717
+ materialParams.normalScale = new Vector2( 1, 1 );
3718
+
3719
+ if ( materialDef.normalTexture.scale !== undefined ) {
3720
+
3721
+ const scale = materialDef.normalTexture.scale;
3722
+
3723
+ materialParams.normalScale.set( scale, scale );
3724
+
3725
+ }
3726
+
3727
+ }
3728
+
3729
+ if ( materialDef.occlusionTexture !== undefined && materialType !== MeshBasicMaterial ) {
3730
+
3731
+ pending.push( parser.assignTexture( materialParams, 'aoMap', materialDef.occlusionTexture ) );
3732
+
3733
+ if ( materialDef.occlusionTexture.strength !== undefined ) {
3734
+
3735
+ materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
3736
+
3737
+ }
3738
+
3739
+ }
3740
+
3741
+ if ( materialDef.emissiveFactor !== undefined && materialType !== MeshBasicMaterial ) {
3742
+
3743
+ const emissiveFactor = materialDef.emissiveFactor;
3744
+ materialParams.emissive = new Color().setRGB( emissiveFactor[ 0 ], emissiveFactor[ 1 ], emissiveFactor[ 2 ], LinearSRGBColorSpace );
3745
+
3746
+ }
3747
+
3748
+ if ( materialDef.emissiveTexture !== undefined && materialType !== MeshBasicMaterial ) {
3749
+
3750
+ pending.push( parser.assignTexture( materialParams, 'emissiveMap', materialDef.emissiveTexture, SRGBColorSpace ) );
3751
+
3752
+ }
3753
+
3754
+ return Promise.all( pending ).then( function () {
3755
+
3756
+ const material = new materialType( materialParams );
3757
+
3758
+ if ( materialDef.name ) material.name = materialDef.name;
3759
+
3760
+ assignExtrasToUserData( material, materialDef );
3761
+
3762
+ parser.associations.set( material, { materials: materialIndex } );
3763
+
3764
+ if ( materialDef.extensions ) addUnknownExtensionsToUserData( extensions, material, materialDef );
3765
+
3766
+ return material;
3767
+
3768
+ } );
3769
+
3770
+ }
3771
+
3772
+ /**
3773
+ * When Object3D instances are targeted by animation, they need unique names.
3774
+ *
3775
+ * @private
3776
+ * @param {string} originalName
3777
+ * @return {string}
3778
+ */
3779
+ createUniqueName( originalName ) {
3780
+
3781
+ const sanitizedName = PropertyBinding.sanitizeNodeName( originalName || '' );
3782
+
3783
+ if ( sanitizedName in this.nodeNamesUsed ) {
3784
+
3785
+ return sanitizedName + '_' + ( ++ this.nodeNamesUsed[ sanitizedName ] );
3786
+
3787
+ } else {
3788
+
3789
+ this.nodeNamesUsed[ sanitizedName ] = 0;
3790
+
3791
+ return sanitizedName;
3792
+
3793
+ }
3794
+
3795
+ }
3796
+
3797
+ /**
3798
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
3799
+ *
3800
+ * Creates BufferGeometries from primitives.
3801
+ *
3802
+ * @private
3803
+ * @param {Array<GLTF.Primitive>} primitives
3804
+ * @return {Promise<Array<BufferGeometry>>}
3805
+ */
3806
+ loadGeometries( primitives ) {
3807
+
3808
+ const parser = this;
3809
+ const extensions = this.extensions;
3810
+ const cache = this.primitiveCache;
3811
+
3812
+ function createDracoPrimitive( primitive ) {
3813
+
3814
+ return extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ]
3815
+ .decodePrimitive( primitive, parser )
3816
+ .then( function ( geometry ) {
3817
+
3818
+ return addPrimitiveAttributes( geometry, primitive, parser );
3819
+
3820
+ } );
3821
+
3822
+ }
3823
+
3824
+ const pending = [];
3825
+
3826
+ for ( let i = 0, il = primitives.length; i < il; i ++ ) {
3827
+
3828
+ const primitive = primitives[ i ];
3829
+ const cacheKey = createPrimitiveKey( primitive );
3830
+
3831
+ // See if we've already created this geometry
3832
+ const cached = cache[ cacheKey ];
3833
+
3834
+ if ( cached ) {
3835
+
3836
+ // Use the cached geometry if it exists
3837
+ pending.push( cached.promise );
3838
+
3839
+ } else {
3840
+
3841
+ let geometryPromise;
3842
+
3843
+ if ( primitive.extensions && primitive.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ] ) {
3844
+
3845
+ // Use DRACO geometry if available
3846
+ geometryPromise = createDracoPrimitive( primitive );
3847
+
3848
+ } else {
3849
+
3850
+ // Otherwise create a new geometry
3851
+ geometryPromise = addPrimitiveAttributes( new BufferGeometry(), primitive, parser );
3852
+
3853
+ }
3854
+
3855
+ // Cache this geometry
3856
+ cache[ cacheKey ] = { primitive: primitive, promise: geometryPromise };
3857
+
3858
+ pending.push( geometryPromise );
3859
+
3860
+ }
3861
+
3862
+ }
3863
+
3864
+ return Promise.all( pending );
3865
+
3866
+ }
3867
+
3868
+ /**
3869
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
3870
+ *
3871
+ * @private
3872
+ * @param {number} meshIndex
3873
+ * @return {Promise<Group|Mesh|SkinnedMesh|Line|Points>}
3874
+ */
3875
+ loadMesh( meshIndex ) {
3876
+
3877
+ const parser = this;
3878
+ const json = this.json;
3879
+ const extensions = this.extensions;
3880
+
3881
+ const meshDef = json.meshes[ meshIndex ];
3882
+ const primitives = meshDef.primitives;
3883
+
3884
+ const pending = [];
3885
+
3886
+ for ( let i = 0, il = primitives.length; i < il; i ++ ) {
3887
+
3888
+ const material = primitives[ i ].material === undefined
3889
+ ? createDefaultMaterial( this.cache )
3890
+ : this.getDependency( 'material', primitives[ i ].material );
3891
+
3892
+ pending.push( material );
3893
+
3894
+ }
3895
+
3896
+ pending.push( parser.loadGeometries( primitives ) );
3897
+
3898
+ return Promise.all( pending ).then( function ( results ) {
3899
+
3900
+ const materials = results.slice( 0, results.length - 1 );
3901
+ const geometries = results[ results.length - 1 ];
3902
+
3903
+ const meshes = [];
3904
+
3905
+ for ( let i = 0, il = geometries.length; i < il; i ++ ) {
3906
+
3907
+ const geometry = geometries[ i ];
3908
+ const primitive = primitives[ i ];
3909
+
3910
+ // 1. create Mesh
3911
+
3912
+ let mesh;
3913
+
3914
+ const material = materials[ i ];
3915
+
3916
+ if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLES ||
3917
+ primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ||
3918
+ primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ||
3919
+ primitive.mode === undefined ) {
3920
+
3921
+ // .isSkinnedMesh isn't in glTF spec. See ._markDefs()
3922
+ mesh = meshDef.isSkinnedMesh === true
3923
+ ? new SkinnedMesh( geometry, material )
3924
+ : new Mesh( geometry, material );
3925
+
3926
+ if ( mesh.isSkinnedMesh === true ) {
3927
+
3928
+ // normalize skin weights to fix malformed assets (see #15319)
3929
+ mesh.normalizeSkinWeights();
3930
+
3931
+ }
3932
+
3933
+ if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ) {
3934
+
3935
+ mesh.geometry = toTrianglesDrawMode( mesh.geometry, TriangleStripDrawMode );
3936
+
3937
+ } else if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ) {
3938
+
3939
+ mesh.geometry = toTrianglesDrawMode( mesh.geometry, TriangleFanDrawMode );
3940
+
3941
+ }
3942
+
3943
+ } else if ( primitive.mode === WEBGL_CONSTANTS.LINES ) {
3944
+
3945
+ mesh = new LineSegments( geometry, material );
3946
+
3947
+ } else if ( primitive.mode === WEBGL_CONSTANTS.LINE_STRIP ) {
3948
+
3949
+ mesh = new Line( geometry, material );
3950
+
3951
+ } else if ( primitive.mode === WEBGL_CONSTANTS.LINE_LOOP ) {
3952
+
3953
+ mesh = new LineLoop( geometry, material );
3954
+
3955
+ } else if ( primitive.mode === WEBGL_CONSTANTS.POINTS ) {
3956
+
3957
+ mesh = new Points( geometry, material );
3958
+
3959
+ } else {
3960
+
3961
+ throw new Error( 'THREE.GLTFLoader: Primitive mode unsupported: ' + primitive.mode );
3962
+
3963
+ }
3964
+
3965
+ if ( Object.keys( mesh.geometry.morphAttributes ).length > 0 ) {
3966
+
3967
+ updateMorphTargets( mesh, meshDef );
3968
+
3969
+ }
3970
+
3971
+ mesh.name = parser.createUniqueName( meshDef.name || ( 'mesh_' + meshIndex ) );
3972
+
3973
+ assignExtrasToUserData( mesh, meshDef );
3974
+
3975
+ if ( primitive.extensions ) addUnknownExtensionsToUserData( extensions, mesh, primitive );
3976
+
3977
+ parser.assignFinalMaterial( mesh );
3978
+
3979
+ meshes.push( mesh );
3980
+
3981
+ }
3982
+
3983
+ for ( let i = 0, il = meshes.length; i < il; i ++ ) {
3984
+
3985
+ parser.associations.set( meshes[ i ], {
3986
+ meshes: meshIndex,
3987
+ primitives: i
3988
+ } );
3989
+
3990
+ }
3991
+
3992
+ if ( meshes.length === 1 ) {
3993
+
3994
+ if ( meshDef.extensions ) addUnknownExtensionsToUserData( extensions, meshes[ 0 ], meshDef );
3995
+
3996
+ return meshes[ 0 ];
3997
+
3998
+ }
3999
+
4000
+ const group = new Group();
4001
+
4002
+ if ( meshDef.extensions ) addUnknownExtensionsToUserData( extensions, group, meshDef );
4003
+
4004
+ parser.associations.set( group, { meshes: meshIndex } );
4005
+
4006
+ for ( let i = 0, il = meshes.length; i < il; i ++ ) {
4007
+
4008
+ group.add( meshes[ i ] );
4009
+
4010
+ }
4011
+
4012
+ return group;
4013
+
4014
+ } );
4015
+
4016
+ }
4017
+
4018
+ /**
4019
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
4020
+ *
4021
+ * @private
4022
+ * @param {number} cameraIndex
4023
+ * @return {Promise<Camera>|undefined}
4024
+ */
4025
+ loadCamera( cameraIndex ) {
4026
+
4027
+ let camera;
4028
+ const cameraDef = this.json.cameras[ cameraIndex ];
4029
+ const params = cameraDef[ cameraDef.type ];
4030
+
4031
+ if ( ! params ) {
4032
+
4033
+ console.warn( 'THREE.GLTFLoader: Missing camera parameters.' );
4034
+ return;
4035
+
4036
+ }
4037
+
4038
+ if ( cameraDef.type === 'perspective' ) {
4039
+
4040
+ camera = new PerspectiveCamera( MathUtils.radToDeg( params.yfov ), params.aspectRatio || 1, params.znear || 1, params.zfar || 2e6 );
4041
+
4042
+ } else if ( cameraDef.type === 'orthographic' ) {
4043
+
4044
+ camera = new OrthographicCamera( - params.xmag, params.xmag, params.ymag, - params.ymag, params.znear, params.zfar );
4045
+
4046
+ }
4047
+
4048
+ if ( cameraDef.name ) camera.name = this.createUniqueName( cameraDef.name );
4049
+
4050
+ assignExtrasToUserData( camera, cameraDef );
4051
+
4052
+ return Promise.resolve( camera );
4053
+
4054
+ }
4055
+
4056
+ /**
4057
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
4058
+ *
4059
+ * @private
4060
+ * @param {number} skinIndex
4061
+ * @return {Promise<Skeleton>}
4062
+ */
4063
+ loadSkin( skinIndex ) {
4064
+
4065
+ const skinDef = this.json.skins[ skinIndex ];
4066
+
4067
+ const pending = [];
4068
+
4069
+ for ( let i = 0, il = skinDef.joints.length; i < il; i ++ ) {
4070
+
4071
+ pending.push( this._loadNodeShallow( skinDef.joints[ i ] ) );
4072
+
4073
+ }
4074
+
4075
+ if ( skinDef.inverseBindMatrices !== undefined ) {
4076
+
4077
+ pending.push( this.getDependency( 'accessor', skinDef.inverseBindMatrices ) );
4078
+
4079
+ } else {
4080
+
4081
+ pending.push( null );
4082
+
4083
+ }
4084
+
4085
+ return Promise.all( pending ).then( function ( results ) {
4086
+
4087
+ const inverseBindMatrices = results.pop();
4088
+ const jointNodes = results;
4089
+
4090
+ // Note that bones (joint nodes) may or may not be in the
4091
+ // scene graph at this time.
4092
+
4093
+ const bones = [];
4094
+ const boneInverses = [];
4095
+
4096
+ for ( let i = 0, il = jointNodes.length; i < il; i ++ ) {
4097
+
4098
+ const jointNode = jointNodes[ i ];
4099
+
4100
+ if ( jointNode ) {
4101
+
4102
+ bones.push( jointNode );
4103
+
4104
+ const mat = new Matrix4();
4105
+
4106
+ if ( inverseBindMatrices !== null ) {
4107
+
4108
+ mat.fromArray( inverseBindMatrices.array, i * 16 );
4109
+
4110
+ }
4111
+
4112
+ boneInverses.push( mat );
4113
+
4114
+ } else {
4115
+
4116
+ console.warn( 'THREE.GLTFLoader: Joint "%s" could not be found.', skinDef.joints[ i ] );
4117
+
4118
+ }
4119
+
4120
+ }
4121
+
4122
+ return new Skeleton( bones, boneInverses );
4123
+
4124
+ } );
4125
+
4126
+ }
4127
+
4128
+ /**
4129
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
4130
+ *
4131
+ * @private
4132
+ * @param {number} animationIndex
4133
+ * @return {Promise<AnimationClip>}
4134
+ */
4135
+ loadAnimation( animationIndex ) {
4136
+
4137
+ const json = this.json;
4138
+ const parser = this;
4139
+
4140
+ const animationDef = json.animations[ animationIndex ];
4141
+ const animationName = animationDef.name ? animationDef.name : 'animation_' + animationIndex;
4142
+
4143
+ const pendingNodes = [];
4144
+ const pendingInputAccessors = [];
4145
+ const pendingOutputAccessors = [];
4146
+ const pendingSamplers = [];
4147
+ const pendingTargets = [];
4148
+
4149
+ for ( let i = 0, il = animationDef.channels.length; i < il; i ++ ) {
4150
+
4151
+ const channel = animationDef.channels[ i ];
4152
+ const sampler = animationDef.samplers[ channel.sampler ];
4153
+ const target = channel.target;
4154
+ const name = target.node;
4155
+ const input = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.input ] : sampler.input;
4156
+ const output = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.output ] : sampler.output;
4157
+
4158
+ if ( target.node === undefined ) continue;
4159
+
4160
+ pendingNodes.push( this.getDependency( 'node', name ) );
4161
+ pendingInputAccessors.push( this.getDependency( 'accessor', input ) );
4162
+ pendingOutputAccessors.push( this.getDependency( 'accessor', output ) );
4163
+ pendingSamplers.push( sampler );
4164
+ pendingTargets.push( target );
4165
+
4166
+ }
4167
+
4168
+ return Promise.all( [
4169
+
4170
+ Promise.all( pendingNodes ),
4171
+ Promise.all( pendingInputAccessors ),
4172
+ Promise.all( pendingOutputAccessors ),
4173
+ Promise.all( pendingSamplers ),
4174
+ Promise.all( pendingTargets )
4175
+
4176
+ ] ).then( function ( dependencies ) {
4177
+
4178
+ const nodes = dependencies[ 0 ];
4179
+ const inputAccessors = dependencies[ 1 ];
4180
+ const outputAccessors = dependencies[ 2 ];
4181
+ const samplers = dependencies[ 3 ];
4182
+ const targets = dependencies[ 4 ];
4183
+
4184
+ const tracks = [];
4185
+
4186
+ for ( let i = 0, il = nodes.length; i < il; i ++ ) {
4187
+
4188
+ const node = nodes[ i ];
4189
+ const inputAccessor = inputAccessors[ i ];
4190
+ const outputAccessor = outputAccessors[ i ];
4191
+ const sampler = samplers[ i ];
4192
+ const target = targets[ i ];
4193
+
4194
+ if ( node === undefined ) continue;
4195
+
4196
+ if ( node.updateMatrix ) {
4197
+
4198
+ node.updateMatrix();
4199
+
4200
+ }
4201
+
4202
+ const createdTracks = parser._createAnimationTracks( node, inputAccessor, outputAccessor, sampler, target );
4203
+
4204
+ if ( createdTracks ) {
4205
+
4206
+ for ( let k = 0; k < createdTracks.length; k ++ ) {
4207
+
4208
+ tracks.push( createdTracks[ k ] );
4209
+
4210
+ }
4211
+
4212
+ }
4213
+
4214
+ }
4215
+
4216
+ const animation = new AnimationClip( animationName, undefined, tracks );
4217
+
4218
+ assignExtrasToUserData( animation, animationDef );
4219
+
4220
+ return animation;
4221
+
4222
+ } );
4223
+
4224
+ }
4225
+
4226
+ createNodeMesh( nodeIndex ) {
4227
+
4228
+ const json = this.json;
4229
+ const parser = this;
4230
+ const nodeDef = json.nodes[ nodeIndex ];
4231
+
4232
+ if ( nodeDef.mesh === undefined ) return null;
4233
+
4234
+ return parser.getDependency( 'mesh', nodeDef.mesh ).then( function ( mesh ) {
4235
+
4236
+ const node = parser._getNodeRef( parser.meshCache, nodeDef.mesh, mesh );
4237
+
4238
+ // if weights are provided on the node, override weights on the mesh.
4239
+ if ( nodeDef.weights !== undefined ) {
4240
+
4241
+ node.traverse( function ( o ) {
4242
+
4243
+ if ( ! o.isMesh ) return;
4244
+
4245
+ for ( let i = 0, il = nodeDef.weights.length; i < il; i ++ ) {
4246
+
4247
+ o.morphTargetInfluences[ i ] = nodeDef.weights[ i ];
4248
+
4249
+ }
4250
+
4251
+ } );
4252
+
4253
+ }
4254
+
4255
+ return node;
4256
+
4257
+ } );
4258
+
4259
+ }
4260
+
4261
+ /**
4262
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
4263
+ *
4264
+ * @private
4265
+ * @param {number} nodeIndex
4266
+ * @return {Promise<Object3D>}
4267
+ */
4268
+ loadNode( nodeIndex ) {
4269
+
4270
+ const json = this.json;
4271
+ const parser = this;
4272
+
4273
+ const nodeDef = json.nodes[ nodeIndex ];
4274
+
4275
+ const nodePending = parser._loadNodeShallow( nodeIndex );
4276
+
4277
+ const childPending = [];
4278
+ const childrenDef = nodeDef.children || [];
4279
+
4280
+ for ( let i = 0, il = childrenDef.length; i < il; i ++ ) {
4281
+
4282
+ childPending.push( parser.getDependency( 'node', childrenDef[ i ] ) );
4283
+
4284
+ }
4285
+
4286
+ const skeletonPending = nodeDef.skin === undefined
4287
+ ? Promise.resolve( null )
4288
+ : parser.getDependency( 'skin', nodeDef.skin );
4289
+
4290
+ return Promise.all( [
4291
+ nodePending,
4292
+ Promise.all( childPending ),
4293
+ skeletonPending
4294
+ ] ).then( function ( results ) {
4295
+
4296
+ const node = results[ 0 ];
4297
+ const children = results[ 1 ];
4298
+ const skeleton = results[ 2 ];
4299
+
4300
+ if ( skeleton !== null ) {
4301
+
4302
+ // This full traverse should be fine because
4303
+ // child glTF nodes have not been added to this node yet.
4304
+ node.traverse( function ( mesh ) {
4305
+
4306
+ if ( ! mesh.isSkinnedMesh ) return;
4307
+
4308
+ mesh.bind( skeleton, _identityMatrix );
4309
+
4310
+ } );
4311
+
4312
+ }
4313
+
4314
+ for ( let i = 0, il = children.length; i < il; i ++ ) {
4315
+
4316
+ node.add( children[ i ] );
4317
+
4318
+ }
4319
+
4320
+ return node;
4321
+
4322
+ } );
4323
+
4324
+ }
4325
+
4326
+ // ._loadNodeShallow() parses a single node.
4327
+ // skin and child nodes are created and added in .loadNode() (no '_' prefix).
4328
+ _loadNodeShallow( nodeIndex ) {
4329
+
4330
+ const json = this.json;
4331
+ const extensions = this.extensions;
4332
+ const parser = this;
4333
+
4334
+ // This method is called from .loadNode() and .loadSkin().
4335
+ // Cache a node to avoid duplication.
4336
+
4337
+ if ( this.nodeCache[ nodeIndex ] !== undefined ) {
4338
+
4339
+ return this.nodeCache[ nodeIndex ];
4340
+
4341
+ }
4342
+
4343
+ const nodeDef = json.nodes[ nodeIndex ];
4344
+
4345
+ // reserve node's name before its dependencies, so the root has the intended name.
4346
+ const nodeName = nodeDef.name ? parser.createUniqueName( nodeDef.name ) : '';
4347
+
4348
+ const pending = [];
4349
+
4350
+ const meshPromise = parser._invokeOne( function ( ext ) {
4351
+
4352
+ return ext.createNodeMesh && ext.createNodeMesh( nodeIndex );
4353
+
4354
+ } );
4355
+
4356
+ if ( meshPromise ) {
4357
+
4358
+ pending.push( meshPromise );
4359
+
4360
+ }
4361
+
4362
+ if ( nodeDef.camera !== undefined ) {
4363
+
4364
+ pending.push( parser.getDependency( 'camera', nodeDef.camera ).then( function ( camera ) {
4365
+
4366
+ return parser._getNodeRef( parser.cameraCache, nodeDef.camera, camera );
4367
+
4368
+ } ) );
4369
+
4370
+ }
4371
+
4372
+ parser._invokeAll( function ( ext ) {
4373
+
4374
+ return ext.createNodeAttachment && ext.createNodeAttachment( nodeIndex );
4375
+
4376
+ } ).forEach( function ( promise ) {
4377
+
4378
+ pending.push( promise );
4379
+
4380
+ } );
4381
+
4382
+ this.nodeCache[ nodeIndex ] = Promise.all( pending ).then( function ( objects ) {
4383
+
4384
+ let node;
4385
+
4386
+ // .isBone isn't in glTF spec. See ._markDefs
4387
+ if ( nodeDef.isBone === true ) {
4388
+
4389
+ node = new Bone();
4390
+
4391
+ } else if ( objects.length > 1 ) {
4392
+
4393
+ node = new Group();
4394
+
4395
+ } else if ( objects.length === 1 ) {
4396
+
4397
+ node = objects[ 0 ];
4398
+
4399
+ } else {
4400
+
4401
+ node = new Object3D();
4402
+
4403
+ }
4404
+
4405
+ if ( node !== objects[ 0 ] ) {
4406
+
4407
+ for ( let i = 0, il = objects.length; i < il; i ++ ) {
4408
+
4409
+ node.add( objects[ i ] );
4410
+
4411
+ }
4412
+
4413
+ }
4414
+
4415
+ if ( nodeDef.name ) {
4416
+
4417
+ node.userData.name = nodeDef.name;
4418
+ node.name = nodeName;
4419
+
4420
+ }
4421
+
4422
+ assignExtrasToUserData( node, nodeDef );
4423
+
4424
+ if ( nodeDef.extensions ) addUnknownExtensionsToUserData( extensions, node, nodeDef );
4425
+
4426
+ if ( nodeDef.matrix !== undefined ) {
4427
+
4428
+ const matrix = new Matrix4();
4429
+ matrix.fromArray( nodeDef.matrix );
4430
+ node.applyMatrix4( matrix );
4431
+
4432
+ } else {
4433
+
4434
+ if ( nodeDef.translation !== undefined ) {
4435
+
4436
+ node.position.fromArray( nodeDef.translation );
4437
+
4438
+ }
4439
+
4440
+ if ( nodeDef.rotation !== undefined ) {
4441
+
4442
+ node.quaternion.fromArray( nodeDef.rotation );
4443
+
4444
+ }
4445
+
4446
+ if ( nodeDef.scale !== undefined ) {
4447
+
4448
+ node.scale.fromArray( nodeDef.scale );
4449
+
4450
+ }
4451
+
4452
+ }
4453
+
4454
+ if ( ! parser.associations.has( node ) ) {
4455
+
4456
+ parser.associations.set( node, {} );
4457
+
4458
+ } else if ( nodeDef.mesh !== undefined && parser.meshCache.refs[ nodeDef.mesh ] > 1 ) {
4459
+
4460
+ const mapping = parser.associations.get( node );
4461
+ parser.associations.set( node, { ...mapping } );
4462
+
4463
+ }
4464
+
4465
+ parser.associations.get( node ).nodes = nodeIndex;
4466
+
4467
+ return node;
4468
+
4469
+ } );
4470
+
4471
+ return this.nodeCache[ nodeIndex ];
4472
+
4473
+ }
4474
+
4475
+ /**
4476
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
4477
+ *
4478
+ * @private
4479
+ * @param {number} sceneIndex
4480
+ * @return {Promise<Group>}
4481
+ */
4482
+ loadScene( sceneIndex ) {
4483
+
4484
+ const extensions = this.extensions;
4485
+ const sceneDef = this.json.scenes[ sceneIndex ];
4486
+ const parser = this;
4487
+
4488
+ // Loader returns Group, not Scene.
4489
+ // See: https://github.com/mrdoob/three.js/issues/18342#issuecomment-578981172
4490
+ const scene = new Group();
4491
+ if ( sceneDef.name ) scene.name = parser.createUniqueName( sceneDef.name );
4492
+
4493
+ assignExtrasToUserData( scene, sceneDef );
4494
+
4495
+ if ( sceneDef.extensions ) addUnknownExtensionsToUserData( extensions, scene, sceneDef );
4496
+
4497
+ const nodeIds = sceneDef.nodes || [];
4498
+
4499
+ const pending = [];
4500
+
4501
+ for ( let i = 0, il = nodeIds.length; i < il; i ++ ) {
4502
+
4503
+ pending.push( parser.getDependency( 'node', nodeIds[ i ] ) );
4504
+
4505
+ }
4506
+
4507
+ return Promise.all( pending ).then( function ( nodes ) {
4508
+
4509
+ for ( let i = 0, il = nodes.length; i < il; i ++ ) {
4510
+
4511
+ scene.add( nodes[ i ] );
4512
+
4513
+ }
4514
+
4515
+ // Removes dangling associations, associations that reference a node that
4516
+ // didn't make it into the scene.
4517
+ const reduceAssociations = ( node ) => {
4518
+
4519
+ const reducedAssociations = new Map();
4520
+
4521
+ for ( const [ key, value ] of parser.associations ) {
4522
+
4523
+ if ( key instanceof Material || key instanceof Texture ) {
4524
+
4525
+ reducedAssociations.set( key, value );
4526
+
4527
+ }
4528
+
4529
+ }
4530
+
4531
+ node.traverse( ( node ) => {
4532
+
4533
+ const mappings = parser.associations.get( node );
4534
+
4535
+ if ( mappings != null ) {
4536
+
4537
+ reducedAssociations.set( node, mappings );
4538
+
4539
+ }
4540
+
4541
+ } );
4542
+
4543
+ return reducedAssociations;
4544
+
4545
+ };
4546
+
4547
+ parser.associations = reduceAssociations( scene );
4548
+
4549
+ return scene;
4550
+
4551
+ } );
4552
+
4553
+ }
4554
+
4555
+ _createAnimationTracks( node, inputAccessor, outputAccessor, sampler, target ) {
4556
+
4557
+ const tracks = [];
4558
+
4559
+ const targetName = node.name ? node.name : node.uuid;
4560
+ const targetNames = [];
4561
+
4562
+ if ( PATH_PROPERTIES[ target.path ] === PATH_PROPERTIES.weights ) {
4563
+
4564
+ node.traverse( function ( object ) {
4565
+
4566
+ if ( object.morphTargetInfluences ) {
4567
+
4568
+ targetNames.push( object.name ? object.name : object.uuid );
4569
+
4570
+ }
4571
+
4572
+ } );
4573
+
4574
+ } else {
4575
+
4576
+ targetNames.push( targetName );
4577
+
4578
+ }
4579
+
4580
+ let TypedKeyframeTrack;
4581
+
4582
+ switch ( PATH_PROPERTIES[ target.path ] ) {
4583
+
4584
+ case PATH_PROPERTIES.weights:
4585
+
4586
+ TypedKeyframeTrack = NumberKeyframeTrack;
4587
+ break;
4588
+
4589
+ case PATH_PROPERTIES.rotation:
4590
+
4591
+ TypedKeyframeTrack = QuaternionKeyframeTrack;
4592
+ break;
4593
+
4594
+ case PATH_PROPERTIES.translation:
4595
+ case PATH_PROPERTIES.scale:
4596
+
4597
+ TypedKeyframeTrack = VectorKeyframeTrack;
4598
+ break;
4599
+
4600
+ default:
4601
+
4602
+ switch ( outputAccessor.itemSize ) {
4603
+
4604
+ case 1:
4605
+ TypedKeyframeTrack = NumberKeyframeTrack;
4606
+ break;
4607
+ case 2:
4608
+ case 3:
4609
+ default:
4610
+ TypedKeyframeTrack = VectorKeyframeTrack;
4611
+ break;
4612
+
4613
+ }
4614
+
4615
+ break;
4616
+
4617
+ }
4618
+
4619
+ const interpolation = sampler.interpolation !== undefined ? INTERPOLATION[ sampler.interpolation ] : InterpolateLinear;
4620
+
4621
+
4622
+ const outputArray = this._getArrayFromAccessor( outputAccessor );
4623
+
4624
+ for ( let j = 0, jl = targetNames.length; j < jl; j ++ ) {
4625
+
4626
+ const track = new TypedKeyframeTrack(
4627
+ targetNames[ j ] + '.' + PATH_PROPERTIES[ target.path ],
4628
+ inputAccessor.array,
4629
+ outputArray,
4630
+ interpolation
4631
+ );
4632
+
4633
+ // Override interpolation with custom factory method.
4634
+ if ( sampler.interpolation === 'CUBICSPLINE' ) {
4635
+
4636
+ this._createCubicSplineTrackInterpolant( track );
4637
+
4638
+ }
4639
+
4640
+ tracks.push( track );
4641
+
4642
+ }
4643
+
4644
+ return tracks;
4645
+
4646
+ }
4647
+
4648
+ _getArrayFromAccessor( accessor ) {
4649
+
4650
+ let outputArray = accessor.array;
4651
+
4652
+ if ( accessor.normalized ) {
4653
+
4654
+ const scale = getNormalizedComponentScale( outputArray.constructor );
4655
+ const scaled = new Float32Array( outputArray.length );
4656
+
4657
+ for ( let j = 0, jl = outputArray.length; j < jl; j ++ ) {
4658
+
4659
+ scaled[ j ] = outputArray[ j ] * scale;
4660
+
4661
+ }
4662
+
4663
+ outputArray = scaled;
4664
+
4665
+ }
4666
+
4667
+ return outputArray;
4668
+
4669
+ }
4670
+
4671
+ _createCubicSplineTrackInterpolant( track ) {
4672
+
4673
+ track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline( result ) {
4674
+
4675
+ // A CUBICSPLINE keyframe in glTF has three output values for each input value,
4676
+ // representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
4677
+ // must be divided by three to get the interpolant's sampleSize argument.
4678
+
4679
+ const interpolantType = ( this instanceof QuaternionKeyframeTrack ) ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
4680
+
4681
+ return new interpolantType( this.times, this.values, this.getValueSize() / 3, result );
4682
+
4683
+ };
4684
+
4685
+ // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
4686
+ track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
4687
+
4688
+ }
4689
+
4690
+ }
4691
+
4692
+ /**
4693
+ *
4694
+ * @private
4695
+ * @param {BufferGeometry} geometry
4696
+ * @param {GLTF.Primitive} primitiveDef
4697
+ * @param {GLTFParser} parser
4698
+ */
4699
+ function computeBounds( geometry, primitiveDef, parser ) {
4700
+
4701
+ const attributes = primitiveDef.attributes;
4702
+
4703
+ const box = new Box3();
4704
+
4705
+ if ( attributes.POSITION !== undefined ) {
4706
+
4707
+ const accessor = parser.json.accessors[ attributes.POSITION ];
4708
+
4709
+ const min = accessor.min;
4710
+ const max = accessor.max;
4711
+
4712
+ // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
4713
+
4714
+ if ( min !== undefined && max !== undefined ) {
4715
+
4716
+ box.set(
4717
+ new Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ),
4718
+ new Vector3( max[ 0 ], max[ 1 ], max[ 2 ] )
4719
+ );
4720
+
4721
+ if ( accessor.normalized ) {
4722
+
4723
+ const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] );
4724
+ box.min.multiplyScalar( boxScale );
4725
+ box.max.multiplyScalar( boxScale );
4726
+
4727
+ }
4728
+
4729
+ } else {
4730
+
4731
+ console.warn( 'THREE.GLTFLoader: Missing min/max properties for accessor POSITION.' );
4732
+
4733
+ return;
4734
+
4735
+ }
4736
+
4737
+ } else {
4738
+
4739
+ return;
4740
+
4741
+ }
4742
+
4743
+ const targets = primitiveDef.targets;
4744
+
4745
+ if ( targets !== undefined ) {
4746
+
4747
+ const maxDisplacement = new Vector3();
4748
+ const vector = new Vector3();
4749
+
4750
+ for ( let i = 0, il = targets.length; i < il; i ++ ) {
4751
+
4752
+ const target = targets[ i ];
4753
+
4754
+ if ( target.POSITION !== undefined ) {
4755
+
4756
+ const accessor = parser.json.accessors[ target.POSITION ];
4757
+ const min = accessor.min;
4758
+ const max = accessor.max;
4759
+
4760
+ // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
4761
+
4762
+ if ( min !== undefined && max !== undefined ) {
4763
+
4764
+ // we need to get max of absolute components because target weight is [-1,1]
4765
+ vector.setX( Math.max( Math.abs( min[ 0 ] ), Math.abs( max[ 0 ] ) ) );
4766
+ vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) );
4767
+ vector.setZ( Math.max( Math.abs( min[ 2 ] ), Math.abs( max[ 2 ] ) ) );
4768
+
4769
+
4770
+ if ( accessor.normalized ) {
4771
+
4772
+ const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] );
4773
+ vector.multiplyScalar( boxScale );
4774
+
4775
+ }
4776
+
4777
+ // Note: this assumes that the sum of all weights is at most 1. This isn't quite correct - it's more conservative
4778
+ // to assume that each target can have a max weight of 1. However, for some use cases - notably, when morph targets
4779
+ // are used to implement key-frame animations and as such only two are active at a time - this results in very large
4780
+ // boxes. So for now we make a box that's sometimes a touch too small but is hopefully mostly of reasonable size.
4781
+ maxDisplacement.max( vector );
4782
+
4783
+ } else {
4784
+
4785
+ console.warn( 'THREE.GLTFLoader: Missing min/max properties for accessor POSITION.' );
4786
+
4787
+ }
4788
+
4789
+ }
4790
+
4791
+ }
4792
+
4793
+ // As per comment above this box isn't conservative, but has a reasonable size for a very large number of morph targets.
4794
+ box.expandByVector( maxDisplacement );
4795
+
4796
+ }
4797
+
4798
+ geometry.boundingBox = box;
4799
+
4800
+ const sphere = new Sphere();
4801
+
4802
+ box.getCenter( sphere.center );
4803
+ sphere.radius = box.min.distanceTo( box.max ) / 2;
4804
+
4805
+ geometry.boundingSphere = sphere;
4806
+
4807
+ }
4808
+
4809
+ /**
4810
+ *
4811
+ * @private
4812
+ * @param {BufferGeometry} geometry
4813
+ * @param {GLTF.Primitive} primitiveDef
4814
+ * @param {GLTFParser} parser
4815
+ * @return {Promise<BufferGeometry>}
4816
+ */
4817
+ function addPrimitiveAttributes( geometry, primitiveDef, parser ) {
4818
+
4819
+ const attributes = primitiveDef.attributes;
4820
+
4821
+ const pending = [];
4822
+
4823
+ function assignAttributeAccessor( accessorIndex, attributeName ) {
4824
+
4825
+ return parser.getDependency( 'accessor', accessorIndex )
4826
+ .then( function ( accessor ) {
4827
+
4828
+ geometry.setAttribute( attributeName, accessor );
4829
+
4830
+ } );
4831
+
4832
+ }
4833
+
4834
+ for ( const gltfAttributeName in attributes ) {
4835
+
4836
+ const threeAttributeName = ATTRIBUTES[ gltfAttributeName ] || gltfAttributeName.toLowerCase();
4837
+
4838
+ // Skip attributes already provided by e.g. Draco extension.
4839
+ if ( threeAttributeName in geometry.attributes ) continue;
4840
+
4841
+ pending.push( assignAttributeAccessor( attributes[ gltfAttributeName ], threeAttributeName ) );
4842
+
4843
+ }
4844
+
4845
+ if ( primitiveDef.indices !== undefined && ! geometry.index ) {
4846
+
4847
+ const accessor = parser.getDependency( 'accessor', primitiveDef.indices ).then( function ( accessor ) {
4848
+
4849
+ geometry.setIndex( accessor );
4850
+
4851
+ } );
4852
+
4853
+ pending.push( accessor );
4854
+
4855
+ }
4856
+
4857
+ if ( ColorManagement.workingColorSpace !== LinearSRGBColorSpace && 'COLOR_0' in attributes ) {
4858
+
4859
+ console.warn( `THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${ColorManagement.workingColorSpace}" not supported.` );
4860
+
4861
+ }
4862
+
4863
+ assignExtrasToUserData( geometry, primitiveDef );
4864
+
4865
+ computeBounds( geometry, primitiveDef, parser );
4866
+
4867
+ return Promise.all( pending ).then( function () {
4868
+
4869
+ return primitiveDef.targets !== undefined
4870
+ ? addMorphTargets( geometry, primitiveDef.targets, parser )
4871
+ : geometry;
4872
+
4873
+ } );
4874
+
4875
+ }
4876
+
4877
+ /**
4878
+ * Loader result of `GLTFLoader`.
4879
+ *
4880
+ * @typedef {Object} GLTFLoader~LoadObject
4881
+ * @property {Array<AnimationClip>} animations - An array of animation clips.
4882
+ * @property {Object} asset - Meta data about the loaded asset.
4883
+ * @property {Array<Camera>} cameras - An array of cameras.
4884
+ * @property {GLTFParser} parser - A reference to the internal parser.
4885
+ * @property {Group} scene - The default scene.
4886
+ * @property {Array<Group>} scenes - glTF assets might define multiple scenes.
4887
+ * @property {Object} userData - Additional data.
4888
+ **/
4889
+
4890
+ export { GLTFLoader };