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