super-three 0.141.0 → 0.147.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 (646) hide show
  1. package/README.md +9 -9
  2. package/build/three.cjs +2441 -1569
  3. package/build/three.js +2441 -1569
  4. package/build/three.min.js +1 -1
  5. package/build/three.module.js +2847 -1576
  6. package/examples/js/animation/AnimationClipCreator.js +0 -8
  7. package/examples/js/animation/CCDIKSolver.js +50 -67
  8. package/examples/js/animation/MMDAnimationHelper.js +66 -137
  9. package/examples/js/animation/MMDPhysics.js +71 -150
  10. package/examples/js/cameras/CinematicCamera.js +33 -22
  11. package/examples/js/controls/ArcballControls.js +149 -403
  12. package/examples/js/controls/DragControls.js +8 -33
  13. package/examples/js/controls/FirstPersonControls.js +32 -61
  14. package/examples/js/controls/FlyControls.js +29 -63
  15. package/examples/js/controls/OrbitControls.js +125 -103
  16. package/examples/js/controls/PointerLockControls.js +5 -22
  17. package/examples/js/controls/TrackballControls.js +33 -88
  18. package/examples/js/controls/TransformControls.js +101 -182
  19. package/examples/js/csm/CSM.js +4 -39
  20. package/examples/js/csm/CSMFrustum.js +3 -9
  21. package/examples/js/csm/CSMHelper.js +24 -4
  22. package/examples/js/csm/CSMShader.js +2 -6
  23. package/examples/js/curves/CurveExtras.js +27 -27
  24. package/examples/js/curves/NURBSCurve.js +4 -16
  25. package/examples/js/curves/NURBSSurface.js +3 -9
  26. package/examples/js/curves/NURBSUtils.js +8 -45
  27. package/examples/js/effects/AnaglyphEffect.js +6 -20
  28. package/examples/js/effects/AsciiEffect.js +32 -31
  29. package/examples/js/effects/OutlineEffect.js +30 -54
  30. package/examples/js/effects/ParallaxBarrierEffect.js +2 -15
  31. package/examples/js/effects/PeppersGhostEffect.js +14 -41
  32. package/examples/js/effects/StereoEffect.js +2 -6
  33. package/examples/js/environments/RoomEnvironment.js +32 -8
  34. package/examples/js/exporters/ColladaExporter.js +52 -78
  35. package/examples/js/exporters/DRACOExporter.js +22 -34
  36. package/examples/js/exporters/EXRExporter.js +15 -18
  37. package/examples/js/exporters/GLTFExporter.js +168 -345
  38. package/examples/js/exporters/MMDExporter.js +5 -12
  39. package/examples/js/exporters/OBJExporter.js +40 -52
  40. package/examples/js/exporters/PLYExporter.js +50 -57
  41. package/examples/js/exporters/STLExporter.js +5 -14
  42. package/examples/js/exporters/USDZExporter.js +119 -27
  43. package/examples/js/geometries/BoxLineGeometry.js +0 -1
  44. package/examples/js/geometries/ConvexGeometry.js +12 -7
  45. package/examples/js/geometries/DecalGeometry.js +53 -20
  46. package/examples/js/geometries/LightningStrike.js +54 -67
  47. package/examples/js/geometries/ParametricGeometries.js +8 -7
  48. package/examples/js/geometries/ParametricGeometry.js +23 -17
  49. package/examples/js/geometries/RoundedBoxGeometry.js +21 -19
  50. package/examples/js/geometries/TeapotGeometry.js +54 -50
  51. package/examples/js/geometries/TextGeometry.js +6 -4
  52. package/examples/js/helpers/LightProbeHelper.js +1 -2
  53. package/examples/js/helpers/OctreeHelper.js +22 -20
  54. package/examples/js/helpers/PositionalAudioHelper.js +8 -6
  55. package/examples/js/helpers/RectAreaLightHelper.js +6 -7
  56. package/examples/js/helpers/VertexNormalsHelper.js +15 -13
  57. package/examples/js/helpers/VertexTangentsHelper.js +15 -9
  58. package/examples/js/helpers/ViewHelper.js +31 -16
  59. package/examples/js/interactive/HTMLMesh.js +25 -39
  60. package/examples/js/interactive/InteractiveGroup.js +9 -14
  61. package/examples/js/interactive/SelectionBox.js +3 -70
  62. package/examples/js/interactive/SelectionHelper.js +2 -8
  63. package/examples/js/libs/ktx-parse.umd.js +1 -0
  64. package/examples/js/libs/meshopt_decoder.js +98 -32
  65. package/examples/js/lights/LightProbeGenerator.js +32 -39
  66. package/examples/js/lights/RectAreaLightUniformsLib.js +5 -1
  67. package/examples/js/lines/LineGeometry.js +3 -5
  68. package/examples/js/lines/LineMaterial.js +4 -11
  69. package/examples/js/lines/LineSegments2.js +40 -89
  70. package/examples/js/lines/LineSegmentsGeometry.js +7 -28
  71. package/examples/js/lines/Wireframe.js +2 -7
  72. package/examples/js/lines/WireframeGeometry2.js +3 -1
  73. package/examples/js/loaders/3DMLoader.js +58 -155
  74. package/examples/js/loaders/3MFLoader.js +72 -106
  75. package/examples/js/loaders/AMFLoader.js +0 -25
  76. package/examples/js/loaders/BVHLoader.js +44 -43
  77. package/examples/js/loaders/BasisTextureLoader.js +16 -46
  78. package/examples/js/loaders/ColladaLoader.js +229 -359
  79. package/examples/js/loaders/DDSLoader.js +24 -25
  80. package/examples/js/loaders/DRACOLoader.js +30 -90
  81. package/examples/js/loaders/EXRLoader.js +69 -177
  82. package/examples/js/loaders/FBXLoader.js +294 -441
  83. package/examples/js/loaders/FontLoader.js +9 -31
  84. package/examples/js/loaders/GCodeLoader.js +15 -16
  85. package/examples/js/loaders/GLTFLoader.js +458 -739
  86. package/examples/js/loaders/HDRCubeTextureLoader.js +0 -17
  87. package/examples/js/loaders/KMZLoader.js +3 -7
  88. package/examples/js/loaders/KTXLoader.js +12 -30
  89. package/examples/js/loaders/LDrawLoader.js +309 -355
  90. package/examples/js/loaders/LUT3dlLoader.js +7 -11
  91. package/examples/js/loaders/LUTCubeLoader.js +0 -8
  92. package/examples/js/loaders/LWOLoader.js +59 -124
  93. package/examples/js/loaders/LogLuvLoader.js +27 -77
  94. package/examples/js/loaders/LottieLoader.js +4 -4
  95. package/examples/js/loaders/MD2Loader.js +26 -27
  96. package/examples/js/loaders/MDDLoader.js +6 -10
  97. package/examples/js/loaders/MMDLoader.js +180 -189
  98. package/examples/js/loaders/MTLLoader.js +18 -47
  99. package/examples/js/loaders/NRRDLoader.js +44 -84
  100. package/examples/js/loaders/OBJLoader.js +56 -77
  101. package/examples/js/loaders/PCDLoader.js +92 -42
  102. package/examples/js/loaders/PDBLoader.js +17 -13
  103. package/examples/js/loaders/PLYLoader.js +65 -51
  104. package/examples/js/loaders/PRWMLoader.js +11 -22
  105. package/examples/js/loaders/PVRLoader.js +7 -16
  106. package/examples/js/loaders/RGBELoader.js +36 -61
  107. package/examples/js/loaders/RGBMLoader.js +26 -87
  108. package/examples/js/loaders/STLLoader.js +20 -27
  109. package/examples/js/loaders/SVGLoader.js +365 -236
  110. package/examples/js/loaders/TDSLoader.js +81 -118
  111. package/examples/js/loaders/TGALoader.js +39 -41
  112. package/examples/js/loaders/TIFFLoader.js +30 -0
  113. package/examples/js/loaders/TTFLoader.js +0 -8
  114. package/examples/js/loaders/TiltLoader.js +14 -15
  115. package/examples/js/loaders/VOXLoader.js +8 -16
  116. package/examples/js/loaders/VRMLLoader.js +266 -354
  117. package/examples/js/loaders/VTKLoader.js +102 -119
  118. package/examples/js/loaders/XYZLoader.js +2 -4
  119. package/examples/js/loaders/lwo/IFFParser.js +55 -136
  120. package/examples/js/loaders/lwo/LWO2Parser.js +39 -89
  121. package/examples/js/loaders/lwo/LWO3Parser.js +38 -79
  122. package/examples/js/materials/MeshGouraudMaterial.js +387 -0
  123. package/examples/js/math/Capsule.js +0 -17
  124. package/examples/js/math/ColorConverter.js +3 -53
  125. package/examples/js/math/ConvexHull.js +185 -141
  126. package/examples/js/math/ImprovedNoise.js +1 -1
  127. package/examples/js/math/Lut.js +8 -15
  128. package/examples/js/math/MeshSurfaceSampler.js +6 -28
  129. package/examples/js/math/OBB.js +90 -49
  130. package/examples/js/math/Octree.js +2 -57
  131. package/examples/js/math/SimplexNoise.js +74 -88
  132. package/examples/js/misc/ConvexObjectBreaker.js +37 -48
  133. package/examples/js/misc/GPUComputationRenderer.js +47 -14
  134. package/examples/js/misc/Gyroscope.js +5 -9
  135. package/examples/js/misc/MD2Character.js +14 -23
  136. package/examples/js/misc/MD2CharacterComplex.js +73 -54
  137. package/examples/js/misc/MorphAnimMesh.js +0 -6
  138. package/examples/js/misc/MorphBlendMesh.js +3 -30
  139. package/examples/js/misc/ProgressiveLightMap.js +47 -43
  140. package/examples/js/misc/RollerCoaster.js +17 -24
  141. package/examples/js/misc/TubePainter.js +18 -12
  142. package/examples/js/misc/Volume.js +173 -194
  143. package/examples/js/misc/VolumeSlice.js +91 -99
  144. package/examples/js/modifiers/CurveModifier.js +19 -21
  145. package/examples/js/modifiers/EdgeSplitModifier.js +0 -30
  146. package/examples/js/modifiers/SimplifyModifier.js +57 -60
  147. package/examples/js/modifiers/TessellateModifier.js +2 -9
  148. package/examples/js/objects/GroundProjectedEnv.js +181 -0
  149. package/examples/js/objects/Lensflare.js +47 -38
  150. package/examples/js/objects/LightningStorm.js +10 -13
  151. package/examples/js/objects/MarchingCubes.js +80 -59
  152. package/examples/js/objects/Reflector.js +31 -22
  153. package/examples/js/objects/ReflectorForSSRPass.js +20 -25
  154. package/examples/js/objects/Refractor.js +61 -33
  155. package/examples/js/objects/ShadowMesh.js +6 -3
  156. package/examples/js/objects/Sky.js +2 -7
  157. package/examples/js/objects/Water.js +23 -18
  158. package/examples/js/objects/Water2.js +20 -19
  159. package/examples/js/physics/AmmoPhysics.js +23 -20
  160. package/examples/js/physics/OimoPhysics.js +19 -17
  161. package/examples/js/postprocessing/AdaptiveToneMappingPass.js +13 -20
  162. package/examples/js/postprocessing/AfterimagePass.js +19 -12
  163. package/examples/js/postprocessing/BloomPass.js +38 -17
  164. package/examples/js/postprocessing/BokehPass.js +29 -12
  165. package/examples/js/postprocessing/ClearPass.js +1 -6
  166. package/examples/js/postprocessing/CubeTexturePass.js +12 -9
  167. package/examples/js/postprocessing/DotScreenPass.js +7 -5
  168. package/examples/js/postprocessing/EffectComposer.js +25 -32
  169. package/examples/js/postprocessing/FilmPass.js +7 -5
  170. package/examples/js/postprocessing/GlitchPass.js +10 -11
  171. package/examples/js/postprocessing/HalftonePass.js +9 -9
  172. package/examples/js/postprocessing/LUTPass.js +2 -15
  173. package/examples/js/postprocessing/MaskPass.js +20 -17
  174. package/examples/js/postprocessing/OutlinePass.js +49 -38
  175. package/examples/js/postprocessing/Pass.js +11 -14
  176. package/examples/js/postprocessing/RenderPass.js +3 -7
  177. package/examples/js/postprocessing/RenderPixelatedPass.js +215 -0
  178. package/examples/js/postprocessing/SAOPass.js +40 -32
  179. package/examples/js/postprocessing/SMAAPass.js +34 -17
  180. package/examples/js/postprocessing/SSAARenderPass.js +14 -14
  181. package/examples/js/postprocessing/SSAOPass.js +56 -42
  182. package/examples/js/postprocessing/SSRPass.js +78 -61
  183. package/examples/js/postprocessing/SavePass.js +14 -6
  184. package/examples/js/postprocessing/ShaderPass.js +9 -8
  185. package/examples/js/postprocessing/TAARenderPass.js +11 -9
  186. package/examples/js/postprocessing/TexturePass.js +7 -4
  187. package/examples/js/postprocessing/UnrealBloomPass.js +43 -25
  188. package/examples/js/renderers/CSS2DRenderer.js +4 -23
  189. package/examples/js/renderers/CSS3DRenderer.js +5 -26
  190. package/examples/js/renderers/Projector.js +31 -108
  191. package/examples/js/renderers/SVGRenderer.js +4 -50
  192. package/examples/js/shaders/ACESFilmicToneMappingShader.js +3 -6
  193. package/examples/js/shaders/AfterimageShader.js +3 -6
  194. package/examples/js/shaders/BasicShader.js +3 -6
  195. package/examples/js/shaders/BleachBypassShader.js +3 -6
  196. package/examples/js/shaders/BlendShader.js +3 -6
  197. package/examples/js/shaders/BokehShader.js +3 -6
  198. package/examples/js/shaders/BokehShader2.js +4 -13
  199. package/examples/js/shaders/BrightnessContrastShader.js +3 -6
  200. package/examples/js/shaders/ColorCorrectionShader.js +2 -6
  201. package/examples/js/shaders/ColorifyShader.js +2 -6
  202. package/examples/js/shaders/ConvolutionShader.js +5 -10
  203. package/examples/js/shaders/CopyShader.js +3 -6
  204. package/examples/js/shaders/DOFMipMapShader.js +3 -6
  205. package/examples/js/shaders/DepthLimitedBlurShader.js +2 -9
  206. package/examples/js/shaders/DigitalGlitch.js +3 -6
  207. package/examples/js/shaders/DotScreenShader.js +2 -6
  208. package/examples/js/shaders/FXAAShader.js +1 -3
  209. package/examples/js/shaders/FilmShader.js +3 -6
  210. package/examples/js/shaders/FocusShader.js +3 -6
  211. package/examples/js/shaders/FreiChenShader.js +2 -6
  212. package/examples/js/shaders/GammaCorrectionShader.js +3 -6
  213. package/examples/js/shaders/GodRaysShader.js +11 -24
  214. package/examples/js/shaders/HalftoneShader.js +3 -6
  215. package/examples/js/shaders/HorizontalBlurShader.js +3 -6
  216. package/examples/js/shaders/HorizontalTiltShiftShader.js +3 -6
  217. package/examples/js/shaders/HueSaturationShader.js +3 -6
  218. package/examples/js/shaders/KaleidoShader.js +3 -6
  219. package/examples/js/shaders/LuminosityHighPassShader.js +2 -6
  220. package/examples/js/shaders/LuminosityShader.js +4 -7
  221. package/examples/js/shaders/MMDToonShader.js +2 -4
  222. package/examples/js/shaders/MirrorShader.js +3 -6
  223. package/examples/js/shaders/NormalMapShader.js +2 -6
  224. package/examples/js/shaders/RGBShiftShader.js +3 -6
  225. package/examples/js/shaders/SAOShader.js +2 -6
  226. package/examples/js/shaders/SMAAShader.js +6 -18
  227. package/examples/js/shaders/SSAOShader.js +2 -6
  228. package/examples/js/shaders/SSRShader.js +6 -18
  229. package/examples/js/shaders/SepiaShader.js +3 -6
  230. package/examples/js/shaders/SobelOperatorShader.js +2 -6
  231. package/examples/js/shaders/TechnicolorShader.js +3 -6
  232. package/examples/js/shaders/ToneMapShader.js +4 -7
  233. package/examples/js/shaders/ToonShader.js +8 -24
  234. package/examples/js/shaders/TriangleBlurShader.js +2 -6
  235. package/examples/js/shaders/UnpackDepthRGBAShader.js +3 -6
  236. package/examples/js/shaders/VelocityShader.js +126 -0
  237. package/examples/js/shaders/VerticalBlurShader.js +3 -6
  238. package/examples/js/shaders/VerticalTiltShiftShader.js +3 -6
  239. package/examples/js/shaders/VignetteShader.js +3 -6
  240. package/examples/js/shaders/VolumeShader.js +2 -6
  241. package/examples/js/shaders/WaterRefractionShader.js +2 -6
  242. package/examples/js/textures/FlakesTexture.js +0 -1
  243. package/examples/js/utils/BufferGeometryUtils.js +237 -171
  244. package/examples/js/utils/CameraUtils.js +5 -20
  245. package/examples/js/utils/GPUStatsPanel.js +3 -12
  246. package/examples/js/utils/GeometryCompressionUtils.js +19 -44
  247. package/examples/js/utils/GeometryUtils.js +15 -36
  248. package/examples/js/utils/LDrawUtils.js +8 -11
  249. package/examples/js/utils/PackedPhongMaterial.js +6 -4
  250. package/examples/js/utils/SceneUtils.js +109 -14
  251. package/examples/js/utils/ShadowMapViewer.js +17 -14
  252. package/examples/js/utils/SkeletonUtils.js +13 -27
  253. package/examples/js/utils/UVsDebug.js +20 -12
  254. package/examples/js/utils/WorkerPool.js +1 -11
  255. package/examples/jsm/animation/CCDIKSolver.js +27 -3
  256. package/examples/jsm/animation/MMDPhysics.js +28 -22
  257. package/examples/jsm/capabilities/WebGPU.js +3 -1
  258. package/examples/jsm/controls/ArcballControls.js +17 -2
  259. package/examples/jsm/controls/FirstPersonControls.js +20 -27
  260. package/examples/jsm/controls/FlyControls.js +16 -24
  261. package/examples/jsm/controls/OrbitControls.js +44 -9
  262. package/examples/jsm/controls/PointerLockControls.js +0 -7
  263. package/examples/jsm/controls/TrackballControls.js +14 -5
  264. package/examples/jsm/controls/TransformControls.js +18 -16
  265. package/examples/jsm/csm/CSM.js +1 -0
  266. package/examples/jsm/csm/CSMHelper.js +30 -0
  267. package/examples/jsm/effects/AnaglyphEffect.js +2 -2
  268. package/examples/jsm/effects/OutlineEffect.js +4 -25
  269. package/examples/jsm/effects/ParallaxBarrierEffect.js +2 -2
  270. package/examples/jsm/effects/PeppersGhostEffect.js +2 -2
  271. package/examples/jsm/effects/StereoEffect.js +2 -2
  272. package/examples/jsm/environments/RoomEnvironment.js +23 -0
  273. package/examples/jsm/exporters/ColladaExporter.js +4 -13
  274. package/examples/jsm/exporters/DRACOExporter.js +0 -13
  275. package/examples/jsm/exporters/GLTFExporter.js +29 -110
  276. package/examples/jsm/exporters/KTX2Exporter.js +29 -29
  277. package/examples/jsm/exporters/OBJExporter.js +0 -18
  278. package/examples/jsm/exporters/PLYExporter.js +14 -22
  279. package/examples/jsm/exporters/STLExporter.js +1 -9
  280. package/examples/jsm/exporters/USDZExporter.js +107 -4
  281. package/examples/jsm/geometries/ConvexGeometry.js +1 -1
  282. package/examples/jsm/geometries/ParametricGeometry.js +0 -6
  283. package/examples/jsm/helpers/OctreeHelper.js +22 -8
  284. package/examples/jsm/helpers/VertexNormalsHelper.js +7 -1
  285. package/examples/jsm/helpers/VertexTangentsHelper.js +7 -0
  286. package/examples/jsm/helpers/ViewHelper.js +24 -0
  287. package/examples/jsm/interactive/HTMLMesh.js +14 -15
  288. package/examples/jsm/interactive/InteractiveGroup.js +4 -2
  289. package/examples/jsm/interactive/SelectionHelper.js +5 -3
  290. package/examples/jsm/libs/flow.module.js +610 -160
  291. package/examples/jsm/libs/lottie_canvas.module.js +14844 -0
  292. package/examples/jsm/libs/meshopt_decoder.module.js +97 -32
  293. package/examples/jsm/libs/utif.module.js +1579 -0
  294. package/examples/jsm/libs/zstddec.module.js +1 -0
  295. package/examples/jsm/lines/LineSegments2.js +4 -0
  296. package/examples/jsm/loaders/3DMLoader.js +1 -2
  297. package/examples/jsm/loaders/ColladaLoader.js +29 -0
  298. package/examples/jsm/loaders/DRACOLoader.js +2 -28
  299. package/examples/jsm/loaders/EXRLoader.js +3 -13
  300. package/examples/jsm/loaders/FBXLoader.js +26 -3
  301. package/examples/jsm/loaders/FontLoader.js +3 -16
  302. package/examples/jsm/loaders/GLTFLoader.js +321 -464
  303. package/examples/jsm/loaders/HDRCubeTextureLoader.js +0 -13
  304. package/examples/jsm/loaders/KTX2Loader.js +254 -53
  305. package/examples/jsm/loaders/LDrawLoader.js +149 -87
  306. package/examples/jsm/loaders/LottieLoader.js +4 -2
  307. package/examples/jsm/loaders/MaterialXLoader.js +728 -0
  308. package/examples/jsm/loaders/OBJLoader.js +6 -14
  309. package/examples/jsm/loaders/PCDLoader.js +60 -14
  310. package/examples/jsm/loaders/PLYLoader.js +71 -19
  311. package/examples/jsm/loaders/RGBELoader.js +1 -1
  312. package/examples/jsm/loaders/SVGLoader.js +231 -17
  313. package/examples/jsm/loaders/TIFFLoader.js +36 -0
  314. package/examples/jsm/loaders/USDZLoader.js +633 -0
  315. package/examples/jsm/loaders/VRMLLoader.js +36 -26
  316. package/examples/jsm/loaders/VTKLoader.js +1 -1
  317. package/examples/jsm/loaders/lwo/LWO2Parser.js +6 -8
  318. package/examples/jsm/loaders/lwo/LWO3Parser.js +6 -8
  319. package/examples/jsm/materials/MeshGouraudMaterial.js +423 -0
  320. package/examples/jsm/math/ColorConverter.js +1 -49
  321. package/examples/jsm/math/ConvexHull.js +4 -4
  322. package/examples/jsm/math/Octree.js +1 -1
  323. package/examples/jsm/misc/GPUComputationRenderer.js +43 -0
  324. package/examples/jsm/misc/Volume.js +169 -171
  325. package/examples/jsm/misc/VolumeSlice.js +78 -80
  326. package/examples/jsm/modifiers/SimplifyModifier.js +1 -1
  327. package/examples/jsm/node-editor/NodeEditor.js +91 -12
  328. package/examples/jsm/node-editor/accessors/MatcapUVEditor.js +1 -1
  329. package/examples/jsm/node-editor/accessors/NormalEditor.js +1 -1
  330. package/examples/jsm/node-editor/accessors/PositionEditor.js +1 -1
  331. package/examples/jsm/node-editor/accessors/UVEditor.js +1 -1
  332. package/examples/jsm/node-editor/core/BaseNode.js +10 -3
  333. package/examples/jsm/node-editor/display/BlendEditor.js +1 -1
  334. package/examples/jsm/node-editor/display/NormalMapEditor.js +1 -1
  335. package/examples/jsm/node-editor/inputs/ColorEditor.js +1 -1
  336. package/examples/jsm/node-editor/inputs/FloatEditor.js +1 -1
  337. package/examples/jsm/node-editor/inputs/SliderEditor.js +1 -1
  338. package/examples/jsm/node-editor/inputs/TextureEditor.js +1 -1
  339. package/examples/jsm/node-editor/inputs/Vector2Editor.js +1 -1
  340. package/examples/jsm/node-editor/inputs/Vector3Editor.js +1 -1
  341. package/examples/jsm/node-editor/inputs/Vector4Editor.js +1 -1
  342. package/examples/jsm/node-editor/materials/BasicMaterialEditor.js +7 -10
  343. package/examples/jsm/node-editor/materials/PointsMaterialEditor.js +1 -1
  344. package/examples/jsm/node-editor/materials/StandardMaterialEditor.js +7 -10
  345. package/examples/jsm/node-editor/math/AngleEditor.js +4 -4
  346. package/examples/jsm/node-editor/math/DotEditor.js +1 -1
  347. package/examples/jsm/node-editor/math/InvertEditor.js +3 -3
  348. package/examples/jsm/node-editor/math/LimiterEditor.js +1 -1
  349. package/examples/jsm/node-editor/math/NormalizeEditor.js +1 -1
  350. package/examples/jsm/node-editor/math/OperatorEditor.js +1 -1
  351. package/examples/jsm/node-editor/math/PowerEditor.js +1 -1
  352. package/examples/jsm/node-editor/math/TrigonometryEditor.js +1 -1
  353. package/examples/jsm/node-editor/procedural/CheckerEditor.js +1 -1
  354. package/examples/jsm/node-editor/scene/MeshEditor.js +11 -8
  355. package/examples/jsm/node-editor/utils/JoinEditor.js +1 -1
  356. package/examples/jsm/node-editor/utils/OscillatorEditor.js +1 -1
  357. package/examples/jsm/node-editor/utils/PreviewEditor.js +7 -3
  358. package/examples/jsm/node-editor/utils/SplitEditor.js +1 -1
  359. package/examples/jsm/node-editor/utils/TimerEditor.js +1 -1
  360. package/examples/jsm/nodes/Nodes.js +70 -13
  361. package/examples/jsm/nodes/accessors/BitangentNode.js +62 -0
  362. package/examples/jsm/nodes/accessors/CubeTextureNode.js +9 -5
  363. package/examples/jsm/nodes/accessors/NormalNode.js +8 -8
  364. package/examples/jsm/nodes/accessors/Object3DNode.js +1 -1
  365. package/examples/jsm/nodes/accessors/PositionNode.js +11 -5
  366. package/examples/jsm/nodes/accessors/ReferenceNode.js +1 -1
  367. package/examples/jsm/nodes/accessors/ReflectVectorNode.js +31 -0
  368. package/examples/jsm/nodes/accessors/SkinningNode.js +8 -1
  369. package/examples/jsm/nodes/accessors/TangentNode.js +95 -0
  370. package/examples/jsm/nodes/core/AttributeNode.js +32 -9
  371. package/examples/jsm/nodes/core/CodeNode.js +3 -3
  372. package/examples/jsm/nodes/core/FunctionCallNode.js +20 -5
  373. package/examples/jsm/nodes/core/FunctionNode.js +2 -2
  374. package/examples/jsm/nodes/core/Node.js +15 -13
  375. package/examples/jsm/nodes/core/NodeBuilder.js +67 -18
  376. package/examples/jsm/nodes/core/NodeFrame.js +2 -2
  377. package/examples/jsm/nodes/core/NodeUtils.js +23 -1
  378. package/examples/jsm/nodes/core/NodeVarying.js +17 -0
  379. package/examples/jsm/nodes/core/VaryingNode.js +56 -0
  380. package/examples/jsm/nodes/core/constants.js +13 -13
  381. package/examples/jsm/nodes/display/BlendModeNode.js +85 -0
  382. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +84 -0
  383. package/examples/jsm/nodes/display/NormalMapNode.js +19 -12
  384. package/examples/jsm/nodes/display/PosterizeNode.js +25 -0
  385. package/examples/jsm/nodes/display/ViewportNode.js +106 -0
  386. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +5 -5
  387. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +3 -3
  388. package/examples/jsm/nodes/functions/light/getDistanceAttenuation.js +2 -2
  389. package/examples/jsm/nodes/geometry/RangeNode.js +109 -0
  390. package/examples/jsm/nodes/gpgpu/ComputeNode.js +3 -1
  391. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +1 -1
  392. package/examples/jsm/nodes/lighting/EnvironmentNode.js +8 -7
  393. package/examples/jsm/nodes/lighting/LightingContextNode.js +4 -4
  394. package/examples/jsm/nodes/loaders/NodeLoader.js +2 -2
  395. package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +33 -0
  396. package/examples/jsm/nodes/materials/Materials.js +21 -31
  397. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +70 -0
  398. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +4 -7
  399. package/examples/jsm/nodes/materials/NodeMaterial.js +11 -3
  400. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +28 -17
  401. package/examples/jsm/nodes/materialx/DISCLAIMER.md +199 -0
  402. package/examples/jsm/nodes/materialx/MaterialXNodes.js +59 -0
  403. package/examples/jsm/nodes/materialx/lib/mx_hsv.js +56 -0
  404. package/examples/jsm/nodes/materialx/lib/mx_noise.js +617 -0
  405. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +18 -0
  406. package/examples/jsm/nodes/math/MathNode.js +7 -17
  407. package/examples/jsm/nodes/math/OperatorNode.js +16 -3
  408. package/examples/jsm/nodes/parsers/GLSLNodeFunction.js +21 -6
  409. package/examples/jsm/nodes/procedural/CheckerNode.js +2 -2
  410. package/examples/jsm/nodes/shadernode/ShaderNode.js +40 -25
  411. package/examples/jsm/nodes/shadernode/ShaderNodeBaseElements.js +95 -68
  412. package/examples/jsm/nodes/shadernode/ShaderNodeElements.js +49 -6
  413. package/examples/jsm/nodes/utils/ConvertNode.js +18 -12
  414. package/examples/jsm/nodes/utils/EquirectUVNode.js +27 -0
  415. package/examples/jsm/nodes/utils/JoinNode.js +15 -9
  416. package/examples/jsm/nodes/utils/MatcapUVNode.js +2 -4
  417. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +3 -2
  418. package/examples/jsm/nodes/utils/OscNode.js +2 -2
  419. package/examples/jsm/nodes/utils/RemapNode.js +34 -0
  420. package/examples/jsm/nodes/utils/RotateUVNode.js +32 -0
  421. package/examples/jsm/nodes/utils/SplitNode.js +21 -5
  422. package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +8 -10
  423. package/examples/jsm/nodes/utils/TimerNode.js +23 -3
  424. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +51 -0
  425. package/examples/jsm/objects/GroundProjectedEnv.js +186 -0
  426. package/examples/jsm/objects/Reflector.js +12 -5
  427. package/examples/jsm/objects/ReflectorForSSRPass.js +3 -5
  428. package/examples/jsm/objects/Refractor.js +12 -6
  429. package/examples/jsm/objects/ShadowMesh.js +8 -2
  430. package/examples/jsm/postprocessing/AfterimagePass.js +17 -4
  431. package/examples/jsm/postprocessing/BloomPass.js +22 -3
  432. package/examples/jsm/postprocessing/BokehPass.js +18 -4
  433. package/examples/jsm/postprocessing/CubeTexturePass.js +12 -5
  434. package/examples/jsm/postprocessing/DotScreenPass.js +8 -0
  435. package/examples/jsm/postprocessing/EffectComposer.js +9 -0
  436. package/examples/jsm/postprocessing/FilmPass.js +8 -0
  437. package/examples/jsm/postprocessing/GlitchPass.js +13 -1
  438. package/examples/jsm/postprocessing/HalftonePass.js +8 -0
  439. package/examples/jsm/postprocessing/OutlinePass.js +25 -3
  440. package/examples/jsm/postprocessing/Pass.js +2 -0
  441. package/examples/jsm/postprocessing/RenderPixelatedPass.js +234 -0
  442. package/examples/jsm/postprocessing/SAOPass.js +20 -0
  443. package/examples/jsm/postprocessing/SMAAPass.js +16 -0
  444. package/examples/jsm/postprocessing/SSAARenderPass.js +4 -0
  445. package/examples/jsm/postprocessing/SavePass.js +17 -1
  446. package/examples/jsm/postprocessing/ShaderPass.js +8 -0
  447. package/examples/jsm/postprocessing/TAARenderPass.js +9 -0
  448. package/examples/jsm/postprocessing/TexturePass.js +8 -0
  449. package/examples/jsm/postprocessing/UnrealBloomPass.js +16 -0
  450. package/examples/jsm/renderers/CSS2DRenderer.js +2 -2
  451. package/examples/jsm/renderers/CSS3DRenderer.js +2 -2
  452. package/examples/jsm/renderers/Projector.js +2 -24
  453. package/examples/jsm/renderers/webgl/nodes/SlotNode.js +9 -5
  454. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +363 -231
  455. package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +7 -3
  456. package/examples/jsm/renderers/webgpu/WebGPUAnimation.js +58 -0
  457. package/examples/jsm/renderers/webgpu/WebGPUAttributes.js +63 -5
  458. package/examples/jsm/renderers/webgpu/WebGPUBackground.js +68 -3
  459. package/examples/jsm/renderers/webgpu/WebGPUComputePipelines.js +6 -0
  460. package/examples/jsm/renderers/webgpu/WebGPUGeometries.js +6 -0
  461. package/examples/jsm/renderers/webgpu/WebGPUObjects.js +1 -1
  462. package/examples/jsm/renderers/webgpu/WebGPURenderPipeline.js +17 -19
  463. package/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js +16 -14
  464. package/examples/jsm/renderers/webgpu/WebGPURenderStates.js +2 -2
  465. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +113 -93
  466. package/examples/jsm/renderers/webgpu/WebGPUTextureUtils.js +5 -3
  467. package/examples/jsm/renderers/webgpu/WebGPUTextures.js +2 -2
  468. package/examples/jsm/renderers/webgpu/WebGPUUtils.js +81 -0
  469. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +63 -36
  470. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodes.js +1 -1
  471. package/examples/jsm/shaders/LuminosityShader.js +1 -1
  472. package/examples/jsm/shaders/MMDToonShader.js +2 -4
  473. package/examples/jsm/shaders/ToneMapShader.js +1 -1
  474. package/examples/jsm/shaders/VelocityShader.js +128 -0
  475. package/examples/jsm/utils/BufferGeometryUtils.js +176 -43
  476. package/examples/jsm/utils/GeometryUtils.js +17 -25
  477. package/examples/jsm/utils/PackedPhongMaterial.js +0 -1
  478. package/examples/jsm/utils/SceneUtils.js +117 -12
  479. package/examples/jsm/webxr/OculusHandModel.js +3 -2
  480. package/examples/jsm/webxr/OculusHandPointerModel.js +6 -1
  481. package/examples/jsm/webxr/VRButton.js +1 -7
  482. package/examples/jsm/webxr/XRHandMeshModel.js +8 -3
  483. package/package.json +22 -18
  484. package/src/Three.Legacy.js +262 -36
  485. package/src/Three.js +4 -2
  486. package/src/animation/AnimationAction.js +6 -5
  487. package/src/animation/AnimationClip.js +1 -1
  488. package/src/animation/AnimationMixer.js +1 -1
  489. package/src/animation/AnimationUtils.js +204 -199
  490. package/src/animation/KeyframeTrack.js +1 -1
  491. package/src/animation/PropertyBinding.js +31 -5
  492. package/src/audio/AudioContext.js +5 -5
  493. package/src/cameras/CubeCamera.js +14 -21
  494. package/src/constants.js +2 -4
  495. package/src/core/BufferAttribute.js +81 -111
  496. package/src/core/BufferGeometry.js +3 -41
  497. package/src/core/InstancedBufferAttribute.js +0 -10
  498. package/src/core/InstancedBufferGeometry.js +1 -7
  499. package/src/core/InterleavedBuffer.js +1 -1
  500. package/src/core/InterleavedBufferAttribute.js +57 -8
  501. package/src/core/Object3D.js +22 -5
  502. package/src/core/Uniform.js +0 -7
  503. package/src/core/UniformsGroup.js +92 -0
  504. package/src/extras/DataUtils.js +104 -88
  505. package/src/extras/Earcut.js +67 -67
  506. package/src/extras/core/Path.js +1 -0
  507. package/src/extras/core/ShapePath.js +1 -4
  508. package/src/extras/curves/CatmullRomCurve3.js +4 -2
  509. package/src/geometries/BoxGeometry.js +1 -1
  510. package/src/geometries/CapsuleGeometry.js +1 -1
  511. package/src/geometries/CircleGeometry.js +1 -1
  512. package/src/geometries/ConeGeometry.js +1 -1
  513. package/src/geometries/CylinderGeometry.js +2 -1
  514. package/src/geometries/DodecahedronGeometry.js +1 -1
  515. package/src/geometries/EdgesGeometry.js +5 -4
  516. package/src/geometries/ExtrudeGeometry.js +2 -11
  517. package/src/geometries/IcosahedronGeometry.js +1 -1
  518. package/src/geometries/LatheGeometry.js +2 -2
  519. package/src/geometries/OctahedronGeometry.js +1 -1
  520. package/src/geometries/PlaneGeometry.js +2 -1
  521. package/src/geometries/PolyhedronGeometry.js +2 -2
  522. package/src/geometries/RingGeometry.js +1 -1
  523. package/src/geometries/ShapeGeometry.js +3 -2
  524. package/src/geometries/SphereGeometry.js +2 -1
  525. package/src/geometries/TetrahedronGeometry.js +1 -1
  526. package/src/geometries/TorusGeometry.js +2 -1
  527. package/src/geometries/TorusKnotGeometry.js +2 -1
  528. package/src/geometries/TubeGeometry.js +2 -1
  529. package/src/geometries/WireframeGeometry.js +1 -0
  530. package/src/helpers/ArrowHelper.js +9 -0
  531. package/src/helpers/Box3Helper.js +7 -0
  532. package/src/helpers/BoxHelper.js +7 -1
  533. package/src/helpers/CameraHelper.js +97 -38
  534. package/src/helpers/DirectionalLightHelper.js +6 -1
  535. package/src/helpers/GridHelper.js +7 -0
  536. package/src/helpers/HemisphereLightHelper.js +5 -1
  537. package/src/helpers/PlaneHelper.js +15 -9
  538. package/src/helpers/PointLightHelper.js +2 -1
  539. package/src/helpers/PolarGridHelper.js +25 -14
  540. package/src/helpers/SkeletonHelper.js +7 -0
  541. package/src/helpers/SpotLightHelper.js +5 -2
  542. package/src/lights/LightShadow.js +1 -2
  543. package/src/lights/PointLight.js +2 -2
  544. package/src/lights/SpotLight.js +4 -2
  545. package/src/loaders/FileLoader.js +16 -2
  546. package/src/loaders/LoadingManager.js +1 -1
  547. package/src/loaders/MaterialLoader.js +49 -7
  548. package/src/loaders/ObjectLoader.js +9 -42
  549. package/src/materials/Material.js +2 -34
  550. package/src/materials/Materials.js +0 -27
  551. package/src/materials/MeshLambertMaterial.js +28 -1
  552. package/src/materials/MeshPhysicalMaterial.js +1 -1
  553. package/src/materials/ShaderMaterial.js +3 -7
  554. package/src/math/Color.js +8 -18
  555. package/src/math/MathUtils.js +1 -7
  556. package/src/math/Matrix3.js +54 -25
  557. package/src/math/Matrix4.js +3 -27
  558. package/src/math/Quaternion.js +1 -21
  559. package/src/math/Ray.js +2 -5
  560. package/src/math/Sphere.js +36 -21
  561. package/src/math/Vector2.js +4 -24
  562. package/src/math/Vector3.js +7 -46
  563. package/src/math/Vector4.js +4 -24
  564. package/src/objects/InstancedMesh.js +7 -0
  565. package/src/objects/LOD.js +25 -6
  566. package/src/renderers/WebGL3DRenderTarget.js +1 -1
  567. package/src/renderers/WebGLArrayRenderTarget.js +1 -1
  568. package/src/renderers/WebGLCubeRenderTarget.js +1 -1
  569. package/src/renderers/WebGLMultipleRenderTargets.js +1 -1
  570. package/src/renderers/WebGLRenderTarget.js +1 -1
  571. package/src/renderers/WebGLRenderer.js +119 -69
  572. package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +12 -12
  573. package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +3 -5
  574. package/src/renderers/shaders/ShaderChunk/common.glsl.js +6 -5
  575. package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +24 -24
  576. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +0 -4
  577. package/src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl.js +1 -1
  578. package/src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl.js +1 -1
  579. package/src/renderers/shaders/ShaderChunk/gradientmap_pars_fragment.glsl.js +2 -1
  580. package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +113 -99
  581. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +34 -13
  582. package/src/renderers/shaders/ShaderChunk/lights_lambert_fragment.glsl.js +5 -0
  583. package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +28 -0
  584. package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +0 -2
  585. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +3 -1
  586. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +13 -1
  587. package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +0 -2
  588. package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +2 -4
  589. package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +2 -4
  590. package/src/renderers/shaders/ShaderChunk/output_fragment.glsl.js +1 -1
  591. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +8 -0
  592. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +18 -7
  593. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +8 -3
  594. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +9 -6
  595. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
  596. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +14 -10
  597. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +2 -2
  598. package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +1 -1
  599. package/src/renderers/shaders/ShaderChunk.js +7 -2
  600. package/src/renderers/shaders/ShaderLib/background.glsl.js +7 -2
  601. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +62 -0
  602. package/src/renderers/shaders/ShaderLib/cube.glsl.js +4 -6
  603. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +0 -1
  604. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +22 -50
  605. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +0 -1
  606. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +0 -3
  607. package/src/renderers/shaders/ShaderLib.js +50 -36
  608. package/src/renderers/shaders/UniformsLib.js +13 -12
  609. package/src/renderers/shaders/UniformsUtils.js +29 -0
  610. package/src/renderers/webgl/WebGLAttributes.js +2 -0
  611. package/src/renderers/webgl/WebGLBackground.js +17 -9
  612. package/src/renderers/webgl/WebGLLights.js +37 -17
  613. package/src/renderers/webgl/WebGLMaterials.js +2 -1
  614. package/src/renderers/webgl/WebGLMorphtargets.js +0 -20
  615. package/src/renderers/webgl/WebGLProgram.js +6 -11
  616. package/src/renderers/webgl/WebGLPrograms.js +30 -26
  617. package/src/renderers/webgl/WebGLRenderLists.js +5 -4
  618. package/src/renderers/webgl/WebGLRenderStates.js +5 -4
  619. package/src/renderers/webgl/WebGLShaderCache.js +9 -6
  620. package/src/renderers/webgl/WebGLShadowMap.js +13 -16
  621. package/src/renderers/webgl/WebGLState.js +125 -41
  622. package/src/renderers/webgl/WebGLTextures.js +94 -39
  623. package/src/renderers/webgl/WebGLUniforms.js +156 -28
  624. package/src/renderers/webgl/WebGLUniformsGroups.js +372 -0
  625. package/src/renderers/webgl/WebGLUtils.js +3 -1
  626. package/src/renderers/webvr/WebVRManager.js +42 -9
  627. package/src/renderers/webvr/WebVRUtils.js +1 -1
  628. package/src/renderers/webxr/WebXRController.js +91 -50
  629. package/src/renderers/webxr/WebXRManager.js +127 -34
  630. package/src/scenes/Scene.js +24 -3
  631. package/src/textures/CompressedArrayTexture.js +18 -0
  632. package/src/textures/Source.js +1 -1
  633. package/src/textures/Texture.js +2 -1
  634. package/src/utils.js +1 -1
  635. package/examples/js/controls/experimental/CameraControls.js +0 -1048
  636. package/examples/js/libs/lottie_canvas.js +0 -12751
  637. package/examples/js/loaders/KTX2Loader.js +0 -558
  638. package/examples/js/shaders/PixelShader.js +0 -51
  639. package/examples/jsm/controls/experimental/CameraControls.js +0 -1248
  640. package/examples/jsm/nodes/accessors/ReflectNode.js +0 -70
  641. package/examples/jsm/nodes/core/NodeVary.js +0 -14
  642. package/examples/jsm/nodes/core/VaryNode.js +0 -54
  643. package/examples/jsm/package.json +0 -3
  644. package/examples/jsm/renderers/webgl/nodes/WebGLPhysicalContextNode.js +0 -45
  645. package/examples/jsm/shaders/PixelShader.js +0 -44
  646. package/src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl.js +0 -122
@@ -69,14 +69,17 @@
69
69
  return new GLTFMeshoptCompression( parser );
70
70
 
71
71
  } );
72
+ this.register( function ( parser ) {
72
73
 
73
- }
74
+ return new GLTFMeshGpuInstancing( parser );
75
+
76
+ } );
74
77
 
78
+ }
75
79
  load( url, onLoad, onProgress, onError ) {
76
80
 
77
81
  const scope = this;
78
82
  let resourcePath;
79
-
80
83
  if ( this.resourcePath !== '' ) {
81
84
 
82
85
  resourcePath = this.resourcePath;
@@ -89,13 +92,12 @@
89
92
 
90
93
  resourcePath = THREE.LoaderUtils.extractUrlBase( url );
91
94
 
92
- } // Tells the LoadingManager to track an extra item, which resolves after
95
+ }
96
+
97
+ // Tells the LoadingManager to track an extra item, which resolves after
93
98
  // the model is fully loaded. This means the count of items loaded will
94
99
  // be incorrect, but ensures manager.onLoad() does not fire early.
95
-
96
-
97
100
  this.manager.itemStart( url );
98
-
99
101
  const _onError = function ( e ) {
100
102
 
101
103
  if ( onError ) {
@@ -138,34 +140,29 @@
138
140
  }, onProgress, _onError );
139
141
 
140
142
  }
141
-
142
143
  setDRACOLoader( dracoLoader ) {
143
144
 
144
145
  this.dracoLoader = dracoLoader;
145
146
  return this;
146
147
 
147
148
  }
148
-
149
149
  setDDSLoader() {
150
150
 
151
151
  throw new Error( 'THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".' );
152
152
 
153
153
  }
154
-
155
154
  setKTX2Loader( ktx2Loader ) {
156
155
 
157
156
  this.ktx2Loader = ktx2Loader;
158
157
  return this;
159
158
 
160
159
  }
161
-
162
160
  setMeshoptDecoder( meshoptDecoder ) {
163
161
 
164
162
  this.meshoptDecoder = meshoptDecoder;
165
163
  return this;
166
164
 
167
165
  }
168
-
169
166
  register( callback ) {
170
167
 
171
168
  if ( this.pluginCallbacks.indexOf( callback ) === - 1 ) {
@@ -177,7 +174,6 @@
177
174
  return this;
178
175
 
179
176
  }
180
-
181
177
  unregister( callback ) {
182
178
 
183
179
  if ( this.pluginCallbacks.indexOf( callback ) !== - 1 ) {
@@ -189,21 +185,18 @@
189
185
  return this;
190
186
 
191
187
  }
192
-
193
188
  parse( data, path, onLoad, onError ) {
194
189
 
195
- let content;
190
+ let json;
196
191
  const extensions = {};
197
192
  const plugins = {};
198
-
199
193
  if ( typeof data === 'string' ) {
200
194
 
201
- content = data;
195
+ json = JSON.parse( data );
202
196
 
203
- } else {
197
+ } else if ( data instanceof ArrayBuffer ) {
204
198
 
205
199
  const magic = THREE.LoaderUtils.decodeText( new Uint8Array( data, 0, 4 ) );
206
-
207
200
  if ( magic === BINARY_EXTENSION_HEADER_MAGIC ) {
208
201
 
209
202
  try {
@@ -217,17 +210,19 @@
217
210
 
218
211
  }
219
212
 
220
- content = extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content;
213
+ json = JSON.parse( extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content );
221
214
 
222
215
  } else {
223
216
 
224
- content = THREE.LoaderUtils.decodeText( new Uint8Array( data ) );
217
+ json = JSON.parse( THREE.LoaderUtils.decodeText( new Uint8Array( data ) ) );
225
218
 
226
219
  }
227
220
 
228
- }
221
+ } else {
229
222
 
230
- const json = JSON.parse( content );
223
+ json = data;
224
+
225
+ }
231
226
 
232
227
  if ( json.asset === undefined || json.asset.version[ 0 ] < 2 ) {
233
228
 
@@ -245,15 +240,15 @@
245
240
  meshoptDecoder: this.meshoptDecoder
246
241
  } );
247
242
  parser.fileLoader.setRequestHeader( this.requestHeader );
248
-
249
243
  for ( let i = 0; i < this.pluginCallbacks.length; i ++ ) {
250
244
 
251
245
  const plugin = this.pluginCallbacks[ i ]( parser );
252
- plugins[ plugin.name ] = plugin; // Workaround to avoid determining as unknown extension
246
+ plugins[ plugin.name ] = plugin;
247
+
248
+ // Workaround to avoid determining as unknown extension
253
249
  // in addUnknownExtensionsToUserData().
254
250
  // Remove this workaround if we move all the existing
255
251
  // extension handlers to plugin system
256
-
257
252
  extensions[ plugin.name ] = true;
258
253
 
259
254
  }
@@ -264,29 +259,20 @@
264
259
 
265
260
  const extensionName = json.extensionsUsed[ i ];
266
261
  const extensionsRequired = json.extensionsRequired || [];
267
-
268
262
  switch ( extensionName ) {
269
263
 
270
264
  case EXTENSIONS.KHR_MATERIALS_UNLIT:
271
265
  extensions[ extensionName ] = new GLTFMaterialsUnlitExtension();
272
266
  break;
273
-
274
- case EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:
275
- extensions[ extensionName ] = new GLTFMaterialsPbrSpecularGlossinessExtension();
276
- break;
277
-
278
267
  case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
279
268
  extensions[ extensionName ] = new GLTFDracoMeshCompressionExtension( json, this.dracoLoader );
280
269
  break;
281
-
282
270
  case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
283
271
  extensions[ extensionName ] = new GLTFTextureTransformExtension();
284
272
  break;
285
-
286
273
  case EXTENSIONS.KHR_MESH_QUANTIZATION:
287
274
  extensions[ extensionName ] = new GLTFMeshQuantizationExtension();
288
275
  break;
289
-
290
276
  default:
291
277
  if ( extensionsRequired.indexOf( extensionName ) >= 0 && plugins[ extensionName ] === undefined ) {
292
278
 
@@ -305,7 +291,6 @@
305
291
  parser.parse( onLoad, onError );
306
292
 
307
293
  }
308
-
309
294
  parseAsync( data, path ) {
310
295
 
311
296
  const scope = this;
@@ -318,8 +303,8 @@
318
303
  }
319
304
 
320
305
  }
321
- /* GLTFREGISTRY */
322
306
 
307
+ /* GLTFREGISTRY */
323
308
 
324
309
  function GLTFRegistry() {
325
310
 
@@ -348,20 +333,17 @@
348
333
  };
349
334
 
350
335
  }
351
- /*********************************/
352
336
 
337
+ /*********************************/
353
338
  /********** EXTENSIONS ***********/
354
-
355
339
  /*********************************/
356
340
 
357
-
358
341
  const EXTENSIONS = {
359
342
  KHR_BINARY_GLTF: 'KHR_binary_glTF',
360
343
  KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
361
344
  KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
362
345
  KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
363
346
  KHR_MATERIALS_IOR: 'KHR_materials_ior',
364
- KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
365
347
  KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
366
348
  KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
367
349
  KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
@@ -373,37 +355,36 @@
373
355
  KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
374
356
  KHR_MATERIALS_EMISSIVE_STRENGTH: 'KHR_materials_emissive_strength',
375
357
  EXT_TEXTURE_WEBP: 'EXT_texture_webp',
376
- EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression'
358
+ EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression',
359
+ EXT_MESH_GPU_INSTANCING: 'EXT_mesh_gpu_instancing'
377
360
  };
361
+
378
362
  /**
379
363
  * Punctual Lights Extension
380
364
  *
381
365
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
382
366
  */
383
-
384
367
  class GLTFLightsExtension {
385
368
 
386
369
  constructor( parser ) {
387
370
 
388
371
  this.parser = parser;
389
- this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL; // THREE.Object3D instance caches
372
+ this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
390
373
 
374
+ // THREE.Object3D instance caches
391
375
  this.cache = {
392
376
  refs: {},
393
377
  uses: {}
394
378
  };
395
379
 
396
380
  }
397
-
398
381
  _markDefs() {
399
382
 
400
383
  const parser = this.parser;
401
384
  const nodeDefs = this.parser.json.nodes || [];
402
-
403
385
  for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) {
404
386
 
405
387
  const nodeDef = nodeDefs[ nodeIndex ];
406
-
407
388
  if ( nodeDef.extensions && nodeDef.extensions[ this.name ] && nodeDef.extensions[ this.name ].light !== undefined ) {
408
389
 
409
390
  parser._addNodeRef( this.cache, nodeDef.extensions[ this.name ].light );
@@ -413,7 +394,6 @@
413
394
  }
414
395
 
415
396
  }
416
-
417
397
  _loadLight( lightIndex ) {
418
398
 
419
399
  const parser = this.parser;
@@ -428,7 +408,6 @@
428
408
  const color = new THREE.Color( 0xffffff );
429
409
  if ( lightDef.color !== undefined ) color.fromArray( lightDef.color );
430
410
  const range = lightDef.range !== undefined ? lightDef.range : 0;
431
-
432
411
  switch ( lightDef.type ) {
433
412
 
434
413
  case 'directional':
@@ -436,16 +415,14 @@
436
415
  lightNode.target.position.set( 0, 0, - 1 );
437
416
  lightNode.add( lightNode.target );
438
417
  break;
439
-
440
418
  case 'point':
441
419
  lightNode = new THREE.PointLight( color );
442
420
  lightNode.distance = range;
443
421
  break;
444
-
445
422
  case 'spot':
446
423
  lightNode = new THREE.SpotLight( color );
447
- lightNode.distance = range; // Handle spotlight properties.
448
-
424
+ lightNode.distance = range;
425
+ // Handle spotlight properties.
449
426
  lightDef.spot = lightDef.spot || {};
450
427
  lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
451
428
  lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
@@ -454,16 +431,16 @@
454
431
  lightNode.target.position.set( 0, 0, - 1 );
455
432
  lightNode.add( lightNode.target );
456
433
  break;
457
-
458
434
  default:
459
435
  throw new Error( 'THREE.GLTFLoader: Unexpected light type: ' + lightDef.type );
460
436
 
461
- } // Some lights (e.g. spot) default to a position other than the origin. Reset the position
462
- // here, because node-level parsing will only override position if explicitly specified.
463
-
437
+ }
464
438
 
439
+ // Some lights (e.g. spot) default to a position other than the origin. Reset the position
440
+ // here, because node-level parsing will only override position if explicitly specified.
465
441
  lightNode.position.set( 0, 0, 0 );
466
442
  lightNode.decay = 2;
443
+ assignExtrasToUserData( lightNode, lightDef );
467
444
  if ( lightDef.intensity !== undefined ) lightNode.intensity = lightDef.intensity;
468
445
  lightNode.name = parser.createUniqueName( lightDef.name || 'light_' + lightIndex );
469
446
  dependency = Promise.resolve( lightNode );
@@ -471,7 +448,12 @@
471
448
  return dependency;
472
449
 
473
450
  }
451
+ getDependency( type, index ) {
452
+
453
+ if ( type !== 'light' ) return;
454
+ return this._loadLight( index );
474
455
 
456
+ }
475
457
  createNodeAttachment( nodeIndex ) {
476
458
 
477
459
  const self = this;
@@ -490,13 +472,12 @@
490
472
  }
491
473
 
492
474
  }
475
+
493
476
  /**
494
477
  * Unlit Materials Extension
495
478
  *
496
479
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
497
480
  */
498
-
499
-
500
481
  class GLTFMaterialsUnlitExtension {
501
482
 
502
483
  constructor() {
@@ -504,20 +485,17 @@
504
485
  this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
505
486
 
506
487
  }
507
-
508
488
  getMaterialType() {
509
489
 
510
490
  return THREE.MeshBasicMaterial;
511
491
 
512
492
  }
513
-
514
493
  extendParams( materialParams, materialDef, parser ) {
515
494
 
516
495
  const pending = [];
517
496
  materialParams.color = new THREE.Color( 1.0, 1.0, 1.0 );
518
497
  materialParams.opacity = 1.0;
519
498
  const metallicRoughness = materialDef.pbrMetallicRoughness;
520
-
521
499
  if ( metallicRoughness ) {
522
500
 
523
501
  if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
@@ -541,13 +519,12 @@
541
519
  }
542
520
 
543
521
  }
522
+
544
523
  /**
545
524
  * Materials Emissive Strength Extension
546
525
  *
547
526
  * Specification: https://github.com/KhronosGroup/glTF/blob/5768b3ce0ef32bc39cdf1bef10b948586635ead3/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md
548
527
  */
549
-
550
-
551
528
  class GLTFMaterialsEmissiveStrengthExtension {
552
529
 
553
530
  constructor( parser ) {
@@ -556,12 +533,10 @@
556
533
  this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH;
557
534
 
558
535
  }
559
-
560
536
  extendMaterialParams( materialIndex, materialParams ) {
561
537
 
562
538
  const parser = this.parser;
563
539
  const materialDef = parser.json.materials[ materialIndex ];
564
-
565
540
  if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
566
541
 
567
542
  return Promise.resolve();
@@ -569,7 +544,6 @@
569
544
  }
570
545
 
571
546
  const emissiveStrength = materialDef.extensions[ this.name ].emissiveStrength;
572
-
573
547
  if ( emissiveStrength !== undefined ) {
574
548
 
575
549
  materialParams.emissiveIntensity = emissiveStrength;
@@ -581,13 +555,12 @@
581
555
  }
582
556
 
583
557
  }
558
+
584
559
  /**
585
560
  * Clearcoat Materials Extension
586
561
  *
587
562
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat
588
563
  */
589
-
590
-
591
564
  class GLTFMaterialsClearcoatExtension {
592
565
 
593
566
  constructor( parser ) {
@@ -596,7 +569,6 @@
596
569
  this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
597
570
 
598
571
  }
599
-
600
572
  getMaterialType( materialIndex ) {
601
573
 
602
574
  const parser = this.parser;
@@ -605,12 +577,10 @@
605
577
  return THREE.MeshPhysicalMaterial;
606
578
 
607
579
  }
608
-
609
580
  extendMaterialParams( materialIndex, materialParams ) {
610
581
 
611
582
  const parser = this.parser;
612
583
  const materialDef = parser.json.materials[ materialIndex ];
613
-
614
584
  if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
615
585
 
616
586
  return Promise.resolve();
@@ -619,7 +589,6 @@
619
589
 
620
590
  const pending = [];
621
591
  const extension = materialDef.extensions[ this.name ];
622
-
623
592
  if ( extension.clearcoatFactor !== undefined ) {
624
593
 
625
594
  materialParams.clearcoat = extension.clearcoatFactor;
@@ -647,7 +616,6 @@
647
616
  if ( extension.clearcoatNormalTexture !== undefined ) {
648
617
 
649
618
  pending.push( parser.assignTexture( materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture ) );
650
-
651
619
  if ( extension.clearcoatNormalTexture.scale !== undefined ) {
652
620
 
653
621
  const scale = extension.clearcoatNormalTexture.scale;
@@ -662,13 +630,12 @@
662
630
  }
663
631
 
664
632
  }
633
+
665
634
  /**
666
635
  * Iridescence Materials Extension
667
636
  *
668
637
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_iridescence
669
638
  */
670
-
671
-
672
639
  class GLTFMaterialsIridescenceExtension {
673
640
 
674
641
  constructor( parser ) {
@@ -677,7 +644,6 @@
677
644
  this.name = EXTENSIONS.KHR_MATERIALS_IRIDESCENCE;
678
645
 
679
646
  }
680
-
681
647
  getMaterialType( materialIndex ) {
682
648
 
683
649
  const parser = this.parser;
@@ -686,12 +652,10 @@
686
652
  return THREE.MeshPhysicalMaterial;
687
653
 
688
654
  }
689
-
690
655
  extendMaterialParams( materialIndex, materialParams ) {
691
656
 
692
657
  const parser = this.parser;
693
658
  const materialDef = parser.json.materials[ materialIndex ];
694
-
695
659
  if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
696
660
 
697
661
  return Promise.resolve();
@@ -700,7 +664,6 @@
700
664
 
701
665
  const pending = [];
702
666
  const extension = materialDef.extensions[ this.name ];
703
-
704
667
  if ( extension.iridescenceFactor !== undefined ) {
705
668
 
706
669
  materialParams.iridescence = extension.iridescenceFactor;
@@ -748,13 +711,12 @@
748
711
  }
749
712
 
750
713
  }
714
+
751
715
  /**
752
716
  * Sheen Materials Extension
753
717
  *
754
718
  * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
755
719
  */
756
-
757
-
758
720
  class GLTFMaterialsSheenExtension {
759
721
 
760
722
  constructor( parser ) {
@@ -763,7 +725,6 @@
763
725
  this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
764
726
 
765
727
  }
766
-
767
728
  getMaterialType( materialIndex ) {
768
729
 
769
730
  const parser = this.parser;
@@ -772,12 +733,10 @@
772
733
  return THREE.MeshPhysicalMaterial;
773
734
 
774
735
  }
775
-
776
736
  extendMaterialParams( materialIndex, materialParams ) {
777
737
 
778
738
  const parser = this.parser;
779
739
  const materialDef = parser.json.materials[ materialIndex ];
780
-
781
740
  if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
782
741
 
783
742
  return Promise.resolve();
@@ -789,7 +748,6 @@
789
748
  materialParams.sheenRoughness = 0;
790
749
  materialParams.sheen = 1;
791
750
  const extension = materialDef.extensions[ this.name ];
792
-
793
751
  if ( extension.sheenColorFactor !== undefined ) {
794
752
 
795
753
  materialParams.sheenColor.fromArray( extension.sheenColorFactor );
@@ -819,14 +777,13 @@
819
777
  }
820
778
 
821
779
  }
780
+
822
781
  /**
823
782
  * Transmission Materials Extension
824
783
  *
825
784
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission
826
785
  * Draft: https://github.com/KhronosGroup/glTF/pull/1698
827
786
  */
828
-
829
-
830
787
  class GLTFMaterialsTransmissionExtension {
831
788
 
832
789
  constructor( parser ) {
@@ -835,7 +792,6 @@
835
792
  this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION;
836
793
 
837
794
  }
838
-
839
795
  getMaterialType( materialIndex ) {
840
796
 
841
797
  const parser = this.parser;
@@ -844,12 +800,10 @@
844
800
  return THREE.MeshPhysicalMaterial;
845
801
 
846
802
  }
847
-
848
803
  extendMaterialParams( materialIndex, materialParams ) {
849
804
 
850
805
  const parser = this.parser;
851
806
  const materialDef = parser.json.materials[ materialIndex ];
852
-
853
807
  if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
854
808
 
855
809
  return Promise.resolve();
@@ -858,7 +812,6 @@
858
812
 
859
813
  const pending = [];
860
814
  const extension = materialDef.extensions[ this.name ];
861
-
862
815
  if ( extension.transmissionFactor !== undefined ) {
863
816
 
864
817
  materialParams.transmission = extension.transmissionFactor;
@@ -876,13 +829,12 @@
876
829
  }
877
830
 
878
831
  }
832
+
879
833
  /**
880
834
  * Materials Volume Extension
881
835
  *
882
836
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume
883
837
  */
884
-
885
-
886
838
  class GLTFMaterialsVolumeExtension {
887
839
 
888
840
  constructor( parser ) {
@@ -891,7 +843,6 @@
891
843
  this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
892
844
 
893
845
  }
894
-
895
846
  getMaterialType( materialIndex ) {
896
847
 
897
848
  const parser = this.parser;
@@ -900,12 +851,10 @@
900
851
  return THREE.MeshPhysicalMaterial;
901
852
 
902
853
  }
903
-
904
854
  extendMaterialParams( materialIndex, materialParams ) {
905
855
 
906
856
  const parser = this.parser;
907
857
  const materialDef = parser.json.materials[ materialIndex ];
908
-
909
858
  if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
910
859
 
911
860
  return Promise.resolve();
@@ -915,14 +864,13 @@
915
864
  const pending = [];
916
865
  const extension = materialDef.extensions[ this.name ];
917
866
  materialParams.thickness = extension.thicknessFactor !== undefined ? extension.thicknessFactor : 0;
918
-
919
867
  if ( extension.thicknessTexture !== undefined ) {
920
868
 
921
869
  pending.push( parser.assignTexture( materialParams, 'thicknessMap', extension.thicknessTexture ) );
922
870
 
923
871
  }
924
872
 
925
- materialParams.attenuationDistance = extension.attenuationDistance || 0;
873
+ materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
926
874
  const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
927
875
  materialParams.attenuationColor = new THREE.Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
928
876
  return Promise.all( pending );
@@ -930,13 +878,12 @@
930
878
  }
931
879
 
932
880
  }
881
+
933
882
  /**
934
883
  * Materials ior Extension
935
884
  *
936
885
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior
937
886
  */
938
-
939
-
940
887
  class GLTFMaterialsIorExtension {
941
888
 
942
889
  constructor( parser ) {
@@ -945,7 +892,6 @@
945
892
  this.name = EXTENSIONS.KHR_MATERIALS_IOR;
946
893
 
947
894
  }
948
-
949
895
  getMaterialType( materialIndex ) {
950
896
 
951
897
  const parser = this.parser;
@@ -954,12 +900,10 @@
954
900
  return THREE.MeshPhysicalMaterial;
955
901
 
956
902
  }
957
-
958
903
  extendMaterialParams( materialIndex, materialParams ) {
959
904
 
960
905
  const parser = this.parser;
961
906
  const materialDef = parser.json.materials[ materialIndex ];
962
-
963
907
  if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
964
908
 
965
909
  return Promise.resolve();
@@ -973,13 +917,12 @@
973
917
  }
974
918
 
975
919
  }
920
+
976
921
  /**
977
922
  * Materials specular Extension
978
923
  *
979
924
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular
980
925
  */
981
-
982
-
983
926
  class GLTFMaterialsSpecularExtension {
984
927
 
985
928
  constructor( parser ) {
@@ -988,7 +931,6 @@
988
931
  this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
989
932
 
990
933
  }
991
-
992
934
  getMaterialType( materialIndex ) {
993
935
 
994
936
  const parser = this.parser;
@@ -997,12 +939,10 @@
997
939
  return THREE.MeshPhysicalMaterial;
998
940
 
999
941
  }
1000
-
1001
942
  extendMaterialParams( materialIndex, materialParams ) {
1002
943
 
1003
944
  const parser = this.parser;
1004
945
  const materialDef = parser.json.materials[ materialIndex ];
1005
-
1006
946
  if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
1007
947
 
1008
948
  return Promise.resolve();
@@ -1012,7 +952,6 @@
1012
952
  const pending = [];
1013
953
  const extension = materialDef.extensions[ this.name ];
1014
954
  materialParams.specularIntensity = extension.specularFactor !== undefined ? extension.specularFactor : 1.0;
1015
-
1016
955
  if ( extension.specularTexture !== undefined ) {
1017
956
 
1018
957
  pending.push( parser.assignTexture( materialParams, 'specularIntensityMap', extension.specularTexture ) );
@@ -1021,7 +960,6 @@
1021
960
 
1022
961
  const colorArray = extension.specularColorFactor || [ 1, 1, 1 ];
1023
962
  materialParams.specularColor = new THREE.Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
1024
-
1025
963
  if ( extension.specularColorTexture !== undefined ) {
1026
964
 
1027
965
  pending.push( parser.assignTexture( materialParams, 'specularColorMap', extension.specularColorTexture, THREE.sRGBEncoding ) );
@@ -1033,13 +971,12 @@
1033
971
  }
1034
972
 
1035
973
  }
974
+
1036
975
  /**
1037
976
  * BasisU THREE.Texture Extension
1038
977
  *
1039
978
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu
1040
979
  */
1041
-
1042
-
1043
980
  class GLTFTextureBasisUExtension {
1044
981
 
1045
982
  constructor( parser ) {
@@ -1048,13 +985,11 @@
1048
985
  this.name = EXTENSIONS.KHR_TEXTURE_BASISU;
1049
986
 
1050
987
  }
1051
-
1052
988
  loadTexture( textureIndex ) {
1053
989
 
1054
990
  const parser = this.parser;
1055
991
  const json = parser.json;
1056
992
  const textureDef = json.textures[ textureIndex ];
1057
-
1058
993
  if ( ! textureDef.extensions || ! textureDef.extensions[ this.name ] ) {
1059
994
 
1060
995
  return null;
@@ -1063,7 +998,6 @@
1063
998
 
1064
999
  const extension = textureDef.extensions[ this.name ];
1065
1000
  const loader = parser.options.ktx2Loader;
1066
-
1067
1001
  if ( ! loader ) {
1068
1002
 
1069
1003
  if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) {
@@ -1084,13 +1018,12 @@
1084
1018
  }
1085
1019
 
1086
1020
  }
1021
+
1087
1022
  /**
1088
1023
  * WebP THREE.Texture Extension
1089
1024
  *
1090
1025
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_webp
1091
1026
  */
1092
-
1093
-
1094
1027
  class GLTFTextureWebPExtension {
1095
1028
 
1096
1029
  constructor( parser ) {
@@ -1100,14 +1033,12 @@
1100
1033
  this.isSupported = null;
1101
1034
 
1102
1035
  }
1103
-
1104
1036
  loadTexture( textureIndex ) {
1105
1037
 
1106
1038
  const name = this.name;
1107
1039
  const parser = this.parser;
1108
1040
  const json = parser.json;
1109
1041
  const textureDef = json.textures[ textureIndex ];
1110
-
1111
1042
  if ( ! textureDef.extensions || ! textureDef.extensions[ name ] ) {
1112
1043
 
1113
1044
  return null;
@@ -1117,7 +1048,6 @@
1117
1048
  const extension = textureDef.extensions[ name ];
1118
1049
  const source = json.images[ extension.source ];
1119
1050
  let loader = parser.textureLoader;
1120
-
1121
1051
  if ( source.uri ) {
1122
1052
 
1123
1053
  const handler = parser.options.manager.getHandler( source.uri );
@@ -1128,31 +1058,29 @@
1128
1058
  return this.detectSupport().then( function ( isSupported ) {
1129
1059
 
1130
1060
  if ( isSupported ) return parser.loadTextureImage( textureIndex, extension.source, loader );
1131
-
1132
1061
  if ( json.extensionsRequired && json.extensionsRequired.indexOf( name ) >= 0 ) {
1133
1062
 
1134
1063
  throw new Error( 'THREE.GLTFLoader: WebP required by asset but unsupported.' );
1135
1064
 
1136
- } // Fall back to PNG or JPEG.
1137
-
1065
+ }
1138
1066
 
1067
+ // Fall back to PNG or JPEG.
1139
1068
  return parser.loadTexture( textureIndex );
1140
1069
 
1141
1070
  } );
1142
1071
 
1143
1072
  }
1144
-
1145
1073
  detectSupport() {
1146
1074
 
1147
1075
  if ( ! this.isSupported ) {
1148
1076
 
1149
1077
  this.isSupported = new Promise( function ( resolve ) {
1150
1078
 
1151
- const image = new Image(); // Lossy test image. Support for lossy images doesn't guarantee support for all
1152
- // WebP images, unfortunately.
1079
+ const image = new Image();
1153
1080
 
1081
+ // Lossy test image. Support for lossy images doesn't guarantee support for all
1082
+ // WebP images, unfortunately.
1154
1083
  image.src = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA';
1155
-
1156
1084
  image.onload = image.onerror = function () {
1157
1085
 
1158
1086
  resolve( image.height === 1 );
@@ -1168,13 +1096,12 @@
1168
1096
  }
1169
1097
 
1170
1098
  }
1099
+
1171
1100
  /**
1172
1101
  * meshopt BufferView Compression Extension
1173
1102
  *
1174
1103
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression
1175
1104
  */
1176
-
1177
-
1178
1105
  class GLTFMeshoptCompression {
1179
1106
 
1180
1107
  constructor( parser ) {
@@ -1183,18 +1110,15 @@
1183
1110
  this.parser = parser;
1184
1111
 
1185
1112
  }
1186
-
1187
1113
  loadBufferView( index ) {
1188
1114
 
1189
1115
  const json = this.parser.json;
1190
1116
  const bufferView = json.bufferViews[ index ];
1191
-
1192
1117
  if ( bufferView.extensions && bufferView.extensions[ this.name ] ) {
1193
1118
 
1194
1119
  const extensionDef = bufferView.extensions[ this.name ];
1195
1120
  const buffer = this.parser.getDependency( 'buffer', extensionDef.buffer );
1196
1121
  const decoder = this.parser.options.meshoptDecoder;
1197
-
1198
1122
  if ( ! decoder || ! decoder.supported ) {
1199
1123
 
1200
1124
  if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) {
@@ -1210,16 +1134,33 @@
1210
1134
 
1211
1135
  }
1212
1136
 
1213
- return Promise.all( [ buffer, decoder.ready ] ).then( function ( res ) {
1137
+ return buffer.then( function ( res ) {
1214
1138
 
1215
1139
  const byteOffset = extensionDef.byteOffset || 0;
1216
1140
  const byteLength = extensionDef.byteLength || 0;
1217
1141
  const count = extensionDef.count;
1218
1142
  const stride = extensionDef.byteStride;
1219
- const result = new ArrayBuffer( count * stride );
1220
- const source = new Uint8Array( res[ 0 ], byteOffset, byteLength );
1221
- decoder.decodeGltfBuffer( new Uint8Array( result ), count, stride, source, extensionDef.mode, extensionDef.filter );
1222
- return result;
1143
+ const source = new Uint8Array( res, byteOffset, byteLength );
1144
+ if ( decoder.decodeGltfBufferAsync ) {
1145
+
1146
+ return decoder.decodeGltfBufferAsync( count, stride, source, extensionDef.mode, extensionDef.filter ).then( function ( res ) {
1147
+
1148
+ return res.buffer;
1149
+
1150
+ } );
1151
+
1152
+ } else {
1153
+
1154
+ // Support for MeshoptDecoder 0.18 or earlier, without decodeGltfBufferAsync
1155
+ return decoder.ready.then( function () {
1156
+
1157
+ const result = new ArrayBuffer( count * stride );
1158
+ decoder.decodeGltfBuffer( new Uint8Array( result ), count, stride, source, extensionDef.mode, extensionDef.filter );
1159
+ return result;
1160
+
1161
+ } );
1162
+
1163
+ }
1223
1164
 
1224
1165
  } );
1225
1166
 
@@ -1232,16 +1173,152 @@
1232
1173
  }
1233
1174
 
1234
1175
  }
1235
- /* BINARY EXTENSION */
1236
1176
 
1177
+ /**
1178
+ * GPU Instancing Extension
1179
+ *
1180
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_mesh_gpu_instancing
1181
+ *
1182
+ */
1183
+ class GLTFMeshGpuInstancing {
1184
+
1185
+ constructor( parser ) {
1186
+
1187
+ this.name = EXTENSIONS.EXT_MESH_GPU_INSTANCING;
1188
+ this.parser = parser;
1189
+
1190
+ }
1191
+ createNodeMesh( nodeIndex ) {
1192
+
1193
+ const json = this.parser.json;
1194
+ const nodeDef = json.nodes[ nodeIndex ];
1195
+ if ( ! nodeDef.extensions || ! nodeDef.extensions[ this.name ] || nodeDef.mesh === undefined ) {
1196
+
1197
+ return null;
1198
+
1199
+ }
1200
+
1201
+ const meshDef = json.meshes[ nodeDef.mesh ];
1202
+
1203
+ // No THREE.Points or Lines + Instancing support yet
1204
+
1205
+ for ( const primitive of meshDef.primitives ) {
1206
+
1207
+ if ( primitive.mode !== WEBGL_CONSTANTS.TRIANGLES && primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP && primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN && primitive.mode !== undefined ) {
1208
+
1209
+ return null;
1210
+
1211
+ }
1212
+
1213
+ }
1214
+
1215
+ const extensionDef = nodeDef.extensions[ this.name ];
1216
+ const attributesDef = extensionDef.attributes;
1217
+
1218
+ // @TODO: Can we support THREE.InstancedMesh + THREE.SkinnedMesh?
1219
+
1220
+ const pending = [];
1221
+ const attributes = {};
1222
+ for ( const key in attributesDef ) {
1223
+
1224
+ pending.push( this.parser.getDependency( 'accessor', attributesDef[ key ] ).then( accessor => {
1225
+
1226
+ attributes[ key ] = accessor;
1227
+ return attributes[ key ];
1228
+
1229
+ } ) );
1230
+
1231
+ }
1232
+
1233
+ if ( pending.length < 1 ) {
1234
+
1235
+ return null;
1236
+
1237
+ }
1238
+
1239
+ pending.push( this.parser.createNodeMesh( nodeIndex ) );
1240
+ return Promise.all( pending ).then( results => {
1241
+
1242
+ const nodeObject = results.pop();
1243
+ const meshes = nodeObject.isGroup ? nodeObject.children : [ nodeObject ];
1244
+ const count = results[ 0 ].count; // All attribute counts should be same
1245
+ const instancedMeshes = [];
1246
+ for ( const mesh of meshes ) {
1247
+
1248
+ // Temporal variables
1249
+ const m = new THREE.Matrix4();
1250
+ const p = new THREE.Vector3();
1251
+ const q = new THREE.Quaternion();
1252
+ const s = new THREE.Vector3( 1, 1, 1 );
1253
+ const instancedMesh = new THREE.InstancedMesh( mesh.geometry, mesh.material, count );
1254
+ for ( let i = 0; i < count; i ++ ) {
1255
+
1256
+ if ( attributes.TRANSLATION ) {
1257
+
1258
+ p.fromBufferAttribute( attributes.TRANSLATION, i );
1259
+
1260
+ }
1261
+
1262
+ if ( attributes.ROTATION ) {
1263
+
1264
+ q.fromBufferAttribute( attributes.ROTATION, i );
1265
+
1266
+ }
1267
+
1268
+ if ( attributes.SCALE ) {
1269
+
1270
+ s.fromBufferAttribute( attributes.SCALE, i );
1271
+
1272
+ }
1273
+
1274
+ instancedMesh.setMatrixAt( i, m.compose( p, q, s ) );
1275
+
1276
+ }
1277
+
1278
+ // Add instance attributes to the geometry, excluding TRS.
1279
+ for ( const attributeName in attributes ) {
1280
+
1281
+ if ( attributeName !== 'TRANSLATION' && attributeName !== 'ROTATION' && attributeName !== 'SCALE' ) {
1237
1282
 
1283
+ mesh.geometry.setAttribute( attributeName, attributes[ attributeName ] );
1284
+
1285
+ }
1286
+
1287
+ }
1288
+
1289
+ // Just in case
1290
+ THREE.Object3D.prototype.copy.call( instancedMesh, mesh );
1291
+
1292
+ // https://github.com/mrdoob/three.js/issues/18334
1293
+ instancedMesh.frustumCulled = false;
1294
+ this.parser.assignFinalMaterial( instancedMesh );
1295
+ instancedMeshes.push( instancedMesh );
1296
+
1297
+ }
1298
+
1299
+ if ( nodeObject.isGroup ) {
1300
+
1301
+ nodeObject.clear();
1302
+ nodeObject.add( ...instancedMeshes );
1303
+ return nodeObject;
1304
+
1305
+ }
1306
+
1307
+ return instancedMeshes[ 0 ];
1308
+
1309
+ } );
1310
+
1311
+ }
1312
+
1313
+ }
1314
+
1315
+ /* BINARY EXTENSION */
1238
1316
  const BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
1239
1317
  const BINARY_EXTENSION_HEADER_LENGTH = 12;
1240
1318
  const BINARY_EXTENSION_CHUNK_TYPES = {
1241
1319
  JSON: 0x4E4F534A,
1242
1320
  BIN: 0x004E4942
1243
1321
  };
1244
-
1245
1322
  class GLTFBinaryExtension {
1246
1323
 
1247
1324
  constructor( data ) {
@@ -1255,7 +1332,6 @@
1255
1332
  version: headerView.getUint32( 4, true ),
1256
1333
  length: headerView.getUint32( 8, true )
1257
1334
  };
1258
-
1259
1335
  if ( this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC ) {
1260
1336
 
1261
1337
  throw new Error( 'THREE.GLTFLoader: Unsupported glTF-Binary header.' );
@@ -1269,14 +1345,12 @@
1269
1345
  const chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH;
1270
1346
  const chunkView = new DataView( data, BINARY_EXTENSION_HEADER_LENGTH );
1271
1347
  let chunkIndex = 0;
1272
-
1273
1348
  while ( chunkIndex < chunkContentsLength ) {
1274
1349
 
1275
1350
  const chunkLength = chunkView.getUint32( chunkIndex, true );
1276
1351
  chunkIndex += 4;
1277
1352
  const chunkType = chunkView.getUint32( chunkIndex, true );
1278
1353
  chunkIndex += 4;
1279
-
1280
1354
  if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON ) {
1281
1355
 
1282
1356
  const contentArray = new Uint8Array( data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength );
@@ -1287,8 +1361,9 @@
1287
1361
  const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
1288
1362
  this.body = data.slice( byteOffset, byteOffset + chunkLength );
1289
1363
 
1290
- } // Clients must ignore chunks with unknown types.
1364
+ }
1291
1365
 
1366
+ // Clients must ignore chunks with unknown types.
1292
1367
 
1293
1368
  chunkIndex += chunkLength;
1294
1369
 
@@ -1303,13 +1378,12 @@
1303
1378
  }
1304
1379
 
1305
1380
  }
1381
+
1306
1382
  /**
1307
1383
  * DRACO THREE.Mesh Compression Extension
1308
1384
  *
1309
1385
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
1310
1386
  */
1311
-
1312
-
1313
1387
  class GLTFDracoMeshCompressionExtension {
1314
1388
 
1315
1389
  constructor( json, dracoLoader ) {
@@ -1326,7 +1400,6 @@
1326
1400
  this.dracoLoader.preload();
1327
1401
 
1328
1402
  }
1329
-
1330
1403
  decodePrimitive( primitive, parser ) {
1331
1404
 
1332
1405
  const json = this.json;
@@ -1336,7 +1409,6 @@
1336
1409
  const threeAttributeMap = {};
1337
1410
  const attributeNormalizedMap = {};
1338
1411
  const attributeTypeMap = {};
1339
-
1340
1412
  for ( const attributeName in gltfAttributeMap ) {
1341
1413
 
1342
1414
  const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
@@ -1347,12 +1419,11 @@
1347
1419
  for ( const attributeName in primitive.attributes ) {
1348
1420
 
1349
1421
  const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
1350
-
1351
1422
  if ( gltfAttributeMap[ attributeName ] !== undefined ) {
1352
1423
 
1353
1424
  const accessorDef = json.accessors[ primitive.attributes[ attributeName ] ];
1354
1425
  const componentType = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
1355
- attributeTypeMap[ threeAttributeName ] = componentType;
1426
+ attributeTypeMap[ threeAttributeName ] = componentType.name;
1356
1427
  attributeNormalizedMap[ threeAttributeName ] = accessorDef.normalized === true;
1357
1428
 
1358
1429
  }
@@ -1384,13 +1455,12 @@
1384
1455
  }
1385
1456
 
1386
1457
  }
1458
+
1387
1459
  /**
1388
1460
  * THREE.Texture Transform Extension
1389
1461
  *
1390
1462
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform
1391
1463
  */
1392
-
1393
-
1394
1464
  class GLTFTextureTransformExtension {
1395
1465
 
1396
1466
  constructor() {
@@ -1398,7 +1468,6 @@
1398
1468
  this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
1399
1469
 
1400
1470
  }
1401
-
1402
1471
  extendTexture( texture, transform ) {
1403
1472
 
1404
1473
  if ( transform.texCoord !== undefined ) {
@@ -1415,7 +1484,6 @@
1415
1484
  }
1416
1485
 
1417
1486
  texture = texture.clone();
1418
-
1419
1487
  if ( transform.offset !== undefined ) {
1420
1488
 
1421
1489
  texture.offset.fromArray( transform.offset );
@@ -1440,254 +1508,12 @@
1440
1508
  }
1441
1509
 
1442
1510
  }
1443
- /**
1444
- * Specular-Glossiness Extension
1445
- *
1446
- * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness
1447
- */
1448
1511
 
1449
- /**
1450
- * A sub class of StandardMaterial with some of the functionality
1451
- * changed via the `onBeforeCompile` callback
1452
- * @pailhead
1453
- */
1454
-
1455
-
1456
- class GLTFMeshStandardSGMaterial extends THREE.MeshStandardMaterial {
1457
-
1458
- constructor( params ) {
1459
-
1460
- super();
1461
- this.isGLTFSpecularGlossinessMaterial = true; //various chunks that need replacing
1462
-
1463
- const specularMapParsFragmentChunk = [ '#ifdef USE_SPECULARMAP', ' uniform sampler2D specularMap;', '#endif' ].join( '\n' );
1464
- const glossinessMapParsFragmentChunk = [ '#ifdef USE_GLOSSINESSMAP', ' uniform sampler2D glossinessMap;', '#endif' ].join( '\n' );
1465
- const specularMapFragmentChunk = [ 'vec3 specularFactor = specular;', '#ifdef USE_SPECULARMAP', ' vec4 texelSpecular = texture2D( specularMap, vUv );', ' // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture', ' specularFactor *= texelSpecular.rgb;', '#endif' ].join( '\n' );
1466
- const glossinessMapFragmentChunk = [ 'float glossinessFactor = glossiness;', '#ifdef USE_GLOSSINESSMAP', ' vec4 texelGlossiness = texture2D( glossinessMap, vUv );', ' // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture', ' glossinessFactor *= texelGlossiness.a;', '#endif' ].join( '\n' );
1467
- const lightPhysicalFragmentChunk = [ 'PhysicalMaterial material;', 'material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );', 'vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );', 'float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );', 'material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.', 'material.roughness += geometryRoughness;', 'material.roughness = min( material.roughness, 1.0 );', 'material.specularColor = specularFactor;' ].join( '\n' );
1468
- const uniforms = {
1469
- specular: {
1470
- value: new THREE.Color().setHex( 0xffffff )
1471
- },
1472
- glossiness: {
1473
- value: 1
1474
- },
1475
- specularMap: {
1476
- value: null
1477
- },
1478
- glossinessMap: {
1479
- value: null
1480
- }
1481
- };
1482
- this._extraUniforms = uniforms;
1483
-
1484
- this.onBeforeCompile = function ( shader ) {
1485
-
1486
- for ( const uniformName in uniforms ) {
1487
-
1488
- shader.uniforms[ uniformName ] = uniforms[ uniformName ];
1489
-
1490
- }
1491
-
1492
- shader.fragmentShader = shader.fragmentShader.replace( 'uniform float roughness;', 'uniform vec3 specular;' ).replace( 'uniform float metalness;', 'uniform float glossiness;' ).replace( '#include <roughnessmap_pars_fragment>', specularMapParsFragmentChunk ).replace( '#include <metalnessmap_pars_fragment>', glossinessMapParsFragmentChunk ).replace( '#include <roughnessmap_fragment>', specularMapFragmentChunk ).replace( '#include <metalnessmap_fragment>', glossinessMapFragmentChunk ).replace( '#include <lights_physical_fragment>', lightPhysicalFragmentChunk );
1493
-
1494
- };
1495
-
1496
- Object.defineProperties( this, {
1497
- specular: {
1498
- get: function () {
1499
-
1500
- return uniforms.specular.value;
1501
-
1502
- },
1503
- set: function ( v ) {
1504
-
1505
- uniforms.specular.value = v;
1506
-
1507
- }
1508
- },
1509
- specularMap: {
1510
- get: function () {
1511
-
1512
- return uniforms.specularMap.value;
1513
-
1514
- },
1515
- set: function ( v ) {
1516
-
1517
- uniforms.specularMap.value = v;
1518
-
1519
- if ( v ) {
1520
-
1521
- this.defines.USE_SPECULARMAP = ''; // USE_UV is set by the renderer for specular maps
1522
-
1523
- } else {
1524
-
1525
- delete this.defines.USE_SPECULARMAP;
1526
-
1527
- }
1528
-
1529
- }
1530
- },
1531
- glossiness: {
1532
- get: function () {
1533
-
1534
- return uniforms.glossiness.value;
1535
-
1536
- },
1537
- set: function ( v ) {
1538
-
1539
- uniforms.glossiness.value = v;
1540
-
1541
- }
1542
- },
1543
- glossinessMap: {
1544
- get: function () {
1545
-
1546
- return uniforms.glossinessMap.value;
1547
-
1548
- },
1549
- set: function ( v ) {
1550
-
1551
- uniforms.glossinessMap.value = v;
1552
-
1553
- if ( v ) {
1554
-
1555
- this.defines.USE_GLOSSINESSMAP = '';
1556
- this.defines.USE_UV = '';
1557
-
1558
- } else {
1559
-
1560
- delete this.defines.USE_GLOSSINESSMAP;
1561
- delete this.defines.USE_UV;
1562
-
1563
- }
1564
-
1565
- }
1566
- }
1567
- } );
1568
- delete this.metalness;
1569
- delete this.roughness;
1570
- delete this.metalnessMap;
1571
- delete this.roughnessMap;
1572
- this.setValues( params );
1573
-
1574
- }
1575
-
1576
- copy( source ) {
1577
-
1578
- super.copy( source );
1579
- this.specularMap = source.specularMap;
1580
- this.specular.copy( source.specular );
1581
- this.glossinessMap = source.glossinessMap;
1582
- this.glossiness = source.glossiness;
1583
- delete this.metalness;
1584
- delete this.roughness;
1585
- delete this.metalnessMap;
1586
- delete this.roughnessMap;
1587
- return this;
1588
-
1589
- }
1590
-
1591
- }
1592
-
1593
- class GLTFMaterialsPbrSpecularGlossinessExtension {
1594
-
1595
- constructor() {
1596
-
1597
- this.name = EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS;
1598
- this.specularGlossinessParams = [ 'color', 'map', 'lightMap', 'lightMapIntensity', 'aoMap', 'aoMapIntensity', 'emissive', 'emissiveIntensity', 'emissiveMap', 'bumpMap', 'bumpScale', 'normalMap', 'normalMapType', 'displacementMap', 'displacementScale', 'displacementBias', 'specularMap', 'specular', 'glossinessMap', 'glossiness', 'alphaMap', 'envMap', 'envMapIntensity' ];
1599
-
1600
- }
1601
-
1602
- getMaterialType() {
1603
-
1604
- return GLTFMeshStandardSGMaterial;
1605
-
1606
- }
1607
-
1608
- extendParams( materialParams, materialDef, parser ) {
1609
-
1610
- const pbrSpecularGlossiness = materialDef.extensions[ this.name ];
1611
- materialParams.color = new THREE.Color( 1.0, 1.0, 1.0 );
1612
- materialParams.opacity = 1.0;
1613
- const pending = [];
1614
-
1615
- if ( Array.isArray( pbrSpecularGlossiness.diffuseFactor ) ) {
1616
-
1617
- const array = pbrSpecularGlossiness.diffuseFactor;
1618
- materialParams.color.fromArray( array );
1619
- materialParams.opacity = array[ 3 ];
1620
-
1621
- }
1622
-
1623
- if ( pbrSpecularGlossiness.diffuseTexture !== undefined ) {
1624
-
1625
- pending.push( parser.assignTexture( materialParams, 'map', pbrSpecularGlossiness.diffuseTexture, THREE.sRGBEncoding ) );
1626
-
1627
- }
1628
-
1629
- materialParams.emissive = new THREE.Color( 0.0, 0.0, 0.0 );
1630
- materialParams.glossiness = pbrSpecularGlossiness.glossinessFactor !== undefined ? pbrSpecularGlossiness.glossinessFactor : 1.0;
1631
- materialParams.specular = new THREE.Color( 1.0, 1.0, 1.0 );
1632
-
1633
- if ( Array.isArray( pbrSpecularGlossiness.specularFactor ) ) {
1634
-
1635
- materialParams.specular.fromArray( pbrSpecularGlossiness.specularFactor );
1636
-
1637
- }
1638
-
1639
- if ( pbrSpecularGlossiness.specularGlossinessTexture !== undefined ) {
1640
-
1641
- const specGlossMapDef = pbrSpecularGlossiness.specularGlossinessTexture;
1642
- pending.push( parser.assignTexture( materialParams, 'glossinessMap', specGlossMapDef ) );
1643
- pending.push( parser.assignTexture( materialParams, 'specularMap', specGlossMapDef, THREE.sRGBEncoding ) );
1644
-
1645
- }
1646
-
1647
- return Promise.all( pending );
1648
-
1649
- }
1650
-
1651
- createMaterial( materialParams ) {
1652
-
1653
- const material = new GLTFMeshStandardSGMaterial( materialParams );
1654
- material.fog = true;
1655
- material.color = materialParams.color;
1656
- material.map = materialParams.map === undefined ? null : materialParams.map;
1657
- material.lightMap = null;
1658
- material.lightMapIntensity = 1.0;
1659
- material.aoMap = materialParams.aoMap === undefined ? null : materialParams.aoMap;
1660
- material.aoMapIntensity = 1.0;
1661
- material.emissive = materialParams.emissive;
1662
- material.emissiveIntensity = materialParams.emissiveIntensity === undefined ? 1.0 : materialParams.emissiveIntensity;
1663
- material.emissiveMap = materialParams.emissiveMap === undefined ? null : materialParams.emissiveMap;
1664
- material.bumpMap = materialParams.bumpMap === undefined ? null : materialParams.bumpMap;
1665
- material.bumpScale = 1;
1666
- material.normalMap = materialParams.normalMap === undefined ? null : materialParams.normalMap;
1667
- material.normalMapType = THREE.TangentSpaceNormalMap;
1668
- if ( materialParams.normalScale ) material.normalScale = materialParams.normalScale;
1669
- material.displacementMap = null;
1670
- material.displacementScale = 1;
1671
- material.displacementBias = 0;
1672
- material.specularMap = materialParams.specularMap === undefined ? null : materialParams.specularMap;
1673
- material.specular = materialParams.specular;
1674
- material.glossinessMap = materialParams.glossinessMap === undefined ? null : materialParams.glossinessMap;
1675
- material.glossiness = materialParams.glossiness;
1676
- material.alphaMap = null;
1677
- material.envMap = materialParams.envMap === undefined ? null : materialParams.envMap;
1678
- material.envMapIntensity = 1.0;
1679
- return material;
1680
-
1681
- }
1682
-
1683
- }
1684
1512
  /**
1685
1513
  * THREE.Mesh Quantization Extension
1686
1514
  *
1687
1515
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization
1688
1516
  */
1689
-
1690
-
1691
1517
  class GLTFMeshQuantizationExtension {
1692
1518
 
1693
1519
  constructor() {
@@ -1697,15 +1523,13 @@
1697
1523
  }
1698
1524
 
1699
1525
  }
1700
- /*********************************/
1701
1526
 
1527
+ /*********************************/
1702
1528
  /********** INTERPOLATION ********/
1703
-
1704
1529
  /*********************************/
1530
+
1705
1531
  // Spline Interpolation
1706
1532
  // Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-c-spline-interpolation
1707
-
1708
-
1709
1533
  class GLTFCubicSplineInterpolant extends THREE.Interpolant {
1710
1534
 
1711
1535
  constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
@@ -1713,16 +1537,15 @@
1713
1537
  super( parameterPositions, sampleValues, sampleSize, resultBuffer );
1714
1538
 
1715
1539
  }
1716
-
1717
1540
  copySampleValue_( index ) {
1718
1541
 
1719
1542
  // Copies a sample value to the result buffer. See description of glTF
1720
1543
  // CUBICSPLINE values layout in interpolate_() function below.
1544
+
1721
1545
  const result = this.resultBuffer,
1722
1546
  values = this.sampleValues,
1723
1547
  valueSize = this.valueSize,
1724
1548
  offset = index * valueSize * 3 + valueSize;
1725
-
1726
1549
  for ( let i = 0; i !== valueSize; i ++ ) {
1727
1550
 
1728
1551
  result[ i ] = values[ offset + i ];
@@ -1732,70 +1555,61 @@
1732
1555
  return result;
1733
1556
 
1734
1557
  }
1558
+ interpolate_( i1, t0, t, t1 ) {
1735
1559
 
1736
- }
1737
-
1738
- GLTFCubicSplineInterpolant.prototype.interpolate_ = function ( i1, t0, t, t1 ) {
1739
-
1740
- const result = this.resultBuffer;
1741
- const values = this.sampleValues;
1742
- const stride = this.valueSize;
1743
- const stride2 = stride * 2;
1744
- const stride3 = stride * 3;
1745
- const td = t1 - t0;
1746
- const p = ( t - t0 ) / td;
1747
- const pp = p * p;
1748
- const ppp = pp * p;
1749
- const offset1 = i1 * stride3;
1750
- const offset0 = offset1 - stride3;
1751
- const s2 = - 2 * ppp + 3 * pp;
1752
- const s3 = ppp - pp;
1753
- const s0 = 1 - s2;
1754
- const s1 = s3 - pp + p; // Layout of keyframe output values for CUBICSPLINE animations:
1755
- // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
1756
-
1757
- for ( let i = 0; i !== stride; i ++ ) {
1560
+ const result = this.resultBuffer;
1561
+ const values = this.sampleValues;
1562
+ const stride = this.valueSize;
1563
+ const stride2 = stride * 2;
1564
+ const stride3 = stride * 3;
1565
+ const td = t1 - t0;
1566
+ const p = ( t - t0 ) / td;
1567
+ const pp = p * p;
1568
+ const ppp = pp * p;
1569
+ const offset1 = i1 * stride3;
1570
+ const offset0 = offset1 - stride3;
1571
+ const s2 = - 2 * ppp + 3 * pp;
1572
+ const s3 = ppp - pp;
1573
+ const s0 = 1 - s2;
1574
+ const s1 = s3 - pp + p;
1758
1575
 
1759
- const p0 = values[ offset0 + i + stride ]; // splineVertex_k
1576
+ // Layout of keyframe output values for CUBICSPLINE animations:
1577
+ // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
1578
+ for ( let i = 0; i !== stride; i ++ ) {
1760
1579
 
1761
- const m0 = values[ offset0 + i + stride2 ] * td; // outTangent_k * (t_k+1 - t_k)
1580
+ const p0 = values[ offset0 + i + stride ]; // splineVertex_k
1581
+ const m0 = values[ offset0 + i + stride2 ] * td; // outTangent_k * (t_k+1 - t_k)
1582
+ const p1 = values[ offset1 + i + stride ]; // splineVertex_k+1
1583
+ const m1 = values[ offset1 + i ] * td; // inTangent_k+1 * (t_k+1 - t_k)
1762
1584
 
1763
- const p1 = values[ offset1 + i + stride ]; // splineVertex_k+1
1585
+ result[ i ] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
1764
1586
 
1765
- const m1 = values[ offset1 + i ] * td; // inTangent_k+1 * (t_k+1 - t_k)
1587
+ }
1766
1588
 
1767
- result[ i ] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
1589
+ return result;
1768
1590
 
1769
1591
  }
1770
1592
 
1771
- return result;
1772
-
1773
- };
1774
-
1593
+ }
1775
1594
  const _q = new THREE.Quaternion();
1776
-
1777
1595
  class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
1778
1596
 
1779
1597
  interpolate_( i1, t0, t, t1 ) {
1780
1598
 
1781
1599
  const result = super.interpolate_( i1, t0, t, t1 );
1782
-
1783
1600
  _q.fromArray( result ).normalize().toArray( result );
1784
-
1785
1601
  return result;
1786
1602
 
1787
1603
  }
1788
1604
 
1789
1605
  }
1790
- /*********************************/
1791
1606
 
1607
+ /*********************************/
1792
1608
  /********** INTERNALS ************/
1793
-
1794
1609
  /*********************************/
1795
1610
 
1796
1611
  /* CONSTANTS */
1797
1612
 
1798
-
1799
1613
  const WEBGL_CONSTANTS = {
1800
1614
  FLOAT: 5126,
1801
1615
  //FLOAT_MAT2: 35674,
@@ -1875,10 +1689,10 @@
1875
1689
  MASK: 'MASK',
1876
1690
  BLEND: 'BLEND'
1877
1691
  };
1692
+
1878
1693
  /**
1879
1694
  * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material
1880
1695
  */
1881
-
1882
1696
  function createDefaultMaterial( cache ) {
1883
1697
 
1884
1698
  if ( cache[ 'DefaultMaterial' ] === undefined ) {
@@ -1902,6 +1716,7 @@
1902
1716
  function addUnknownExtensionsToUserData( knownExtensions, object, objectDef ) {
1903
1717
 
1904
1718
  // Add unknown glTF extensions to an object's userData.
1719
+
1905
1720
  for ( const name in objectDef.extensions ) {
1906
1721
 
1907
1722
  if ( knownExtensions[ name ] === undefined ) {
@@ -1914,12 +1729,11 @@
1914
1729
  }
1915
1730
 
1916
1731
  }
1732
+
1917
1733
  /**
1918
1734
  * @param {Object3D|Material|BufferGeometry} object
1919
1735
  * @param {GLTF.definition} gltfDef
1920
1736
  */
1921
-
1922
-
1923
1737
  function assignExtrasToUserData( object, gltfDef ) {
1924
1738
 
1925
1739
  if ( gltfDef.extras !== undefined ) {
@@ -1937,6 +1751,7 @@
1937
1751
  }
1938
1752
 
1939
1753
  }
1754
+
1940
1755
  /**
1941
1756
  * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#morph-targets
1942
1757
  *
@@ -1945,14 +1760,11 @@
1945
1760
  * @param {GLTFParser} parser
1946
1761
  * @return {Promise<BufferGeometry>}
1947
1762
  */
1948
-
1949
-
1950
1763
  function addMorphTargets( geometry, targets, parser ) {
1951
1764
 
1952
1765
  let hasMorphPosition = false;
1953
1766
  let hasMorphNormal = false;
1954
1767
  let hasMorphColor = false;
1955
-
1956
1768
  for ( let i = 0, il = targets.length; i < il; i ++ ) {
1957
1769
 
1958
1770
  const target = targets[ i ];
@@ -1967,11 +1779,9 @@
1967
1779
  const pendingPositionAccessors = [];
1968
1780
  const pendingNormalAccessors = [];
1969
1781
  const pendingColorAccessors = [];
1970
-
1971
1782
  for ( let i = 0, il = targets.length; i < il; i ++ ) {
1972
1783
 
1973
1784
  const target = targets[ i ];
1974
-
1975
1785
  if ( hasMorphPosition ) {
1976
1786
 
1977
1787
  const pendingAccessor = target.POSITION !== undefined ? parser.getDependency( 'accessor', target.POSITION ) : geometry.attributes.position;
@@ -2009,16 +1819,14 @@
2009
1819
  } );
2010
1820
 
2011
1821
  }
1822
+
2012
1823
  /**
2013
1824
  * @param {Mesh} mesh
2014
1825
  * @param {GLTF.Mesh} meshDef
2015
1826
  */
2016
-
2017
-
2018
1827
  function updateMorphTargets( mesh, meshDef ) {
2019
1828
 
2020
1829
  mesh.updateMorphTargets();
2021
-
2022
1830
  if ( meshDef.weights !== undefined ) {
2023
1831
 
2024
1832
  for ( let i = 0, il = meshDef.weights.length; i < il; i ++ ) {
@@ -2027,17 +1835,15 @@
2027
1835
 
2028
1836
  }
2029
1837
 
2030
- } // .extras has user-defined data, so check that .extras.targetNames is an array.
2031
-
1838
+ }
2032
1839
 
1840
+ // .extras has user-defined data, so check that .extras.targetNames is an array.
2033
1841
  if ( meshDef.extras && Array.isArray( meshDef.extras.targetNames ) ) {
2034
1842
 
2035
1843
  const targetNames = meshDef.extras.targetNames;
2036
-
2037
1844
  if ( mesh.morphTargetInfluences.length === targetNames.length ) {
2038
1845
 
2039
1846
  mesh.morphTargetDictionary = {};
2040
-
2041
1847
  for ( let i = 0, il = targetNames.length; i < il; i ++ ) {
2042
1848
 
2043
1849
  mesh.morphTargetDictionary[ targetNames[ i ] ] = i;
@@ -2058,7 +1864,6 @@
2058
1864
 
2059
1865
  const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ];
2060
1866
  let geometryKey;
2061
-
2062
1867
  if ( dracoExtension ) {
2063
1868
 
2064
1869
  geometryKey = 'draco:' + dracoExtension.bufferView + ':' + dracoExtension.indices + ':' + createAttributesKey( dracoExtension.attributes );
@@ -2077,7 +1882,6 @@
2077
1882
 
2078
1883
  let attributesKey = '';
2079
1884
  const keys = Object.keys( attributes ).sort();
2080
-
2081
1885
  for ( let i = 0, il = keys.length; i < il; i ++ ) {
2082
1886
 
2083
1887
  attributesKey += keys[ i ] + ':' + attributes[ keys[ i ] ] + ';';
@@ -2092,20 +1896,17 @@
2092
1896
 
2093
1897
  // Reference:
2094
1898
  // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
1899
+
2095
1900
  switch ( constructor ) {
2096
1901
 
2097
1902
  case Int8Array:
2098
1903
  return 1 / 127;
2099
-
2100
1904
  case Uint8Array:
2101
1905
  return 1 / 255;
2102
-
2103
1906
  case Int16Array:
2104
1907
  return 1 / 32767;
2105
-
2106
1908
  case Uint16Array:
2107
1909
  return 1 / 65535;
2108
-
2109
1910
  default:
2110
1911
  throw new Error( 'THREE.GLTFLoader: Unsupported normalized accessor component type.' );
2111
1912
 
@@ -2120,8 +1921,8 @@
2120
1921
  return 'image/png';
2121
1922
 
2122
1923
  }
2123
- /* GLTF PARSER */
2124
1924
 
1925
+ /* GLTF PARSER */
2125
1926
 
2126
1927
  class GLTFParser {
2127
1928
 
@@ -2130,14 +1931,18 @@
2130
1931
  this.json = json;
2131
1932
  this.extensions = {};
2132
1933
  this.plugins = {};
2133
- this.options = options; // loader object cache
1934
+ this.options = options;
2134
1935
 
2135
- this.cache = new GLTFRegistry(); // associations between Three.js objects and glTF elements
1936
+ // loader object cache
1937
+ this.cache = new GLTFRegistry();
2136
1938
 
2137
- this.associations = new Map(); // THREE.BufferGeometry caching
1939
+ // associations between Three.js objects and glTF elements
1940
+ this.associations = new Map();
2138
1941
 
2139
- this.primitiveCache = {}; // THREE.Object3D instance caches
1942
+ // THREE.BufferGeometry caching
1943
+ this.primitiveCache = {};
2140
1944
 
1945
+ // THREE.Object3D instance caches
2141
1946
  this.meshCache = {
2142
1947
  refs: {},
2143
1948
  uses: {}
@@ -2151,14 +1956,24 @@
2151
1956
  uses: {}
2152
1957
  };
2153
1958
  this.sourceCache = {};
2154
- this.textureCache = {}; // Track node names, to ensure no duplicates
1959
+ this.textureCache = {};
2155
1960
 
2156
- this.nodeNamesUsed = {}; // Use an THREE.ImageBitmapLoader if imageBitmaps are supported. Moves much of the
1961
+ // Track node names, to ensure no duplicates
1962
+ this.nodeNamesUsed = {};
1963
+
1964
+ // Use an THREE.ImageBitmapLoader if imageBitmaps are supported. Moves much of the
2157
1965
  // expensive work of uploading a texture to the GPU off the main thread.
2158
1966
 
2159
- const isSafari = /^((?!chrome|android).)*safari/i.test( navigator.userAgent ) === true;
2160
- const isFirefox = navigator.userAgent.indexOf( 'Firefox' ) > - 1;
2161
- const firefoxVersion = isFirefox ? navigator.userAgent.match( /Firefox\/([0-9]+)\./ )[ 1 ] : - 1;
1967
+ let isSafari = false;
1968
+ let isFirefox = false;
1969
+ let firefoxVersion = - 1;
1970
+ if ( typeof navigator !== 'undefined' ) {
1971
+
1972
+ isSafari = /^((?!chrome|android).)*safari/i.test( navigator.userAgent ) === true;
1973
+ isFirefox = navigator.userAgent.indexOf( 'Firefox' ) > - 1;
1974
+ firefoxVersion = isFirefox ? navigator.userAgent.match( /Firefox\/([0-9]+)\./ )[ 1 ] : - 1;
1975
+
1976
+ }
2162
1977
 
2163
1978
  if ( typeof createImageBitmap === 'undefined' || isSafari || isFirefox && firefoxVersion < 98 ) {
2164
1979
 
@@ -2174,7 +1989,6 @@
2174
1989
  this.textureLoader.setRequestHeader( this.options.requestHeader );
2175
1990
  this.fileLoader = new THREE.FileLoader( this.options.manager );
2176
1991
  this.fileLoader.setResponseType( 'arraybuffer' );
2177
-
2178
1992
  if ( this.options.crossOrigin === 'use-credentials' ) {
2179
1993
 
2180
1994
  this.fileLoader.setWithCredentials( true );
@@ -2182,33 +1996,31 @@
2182
1996
  }
2183
1997
 
2184
1998
  }
2185
-
2186
1999
  setExtensions( extensions ) {
2187
2000
 
2188
2001
  this.extensions = extensions;
2189
2002
 
2190
2003
  }
2191
-
2192
2004
  setPlugins( plugins ) {
2193
2005
 
2194
2006
  this.plugins = plugins;
2195
2007
 
2196
2008
  }
2197
-
2198
2009
  parse( onLoad, onError ) {
2199
2010
 
2200
2011
  const parser = this;
2201
2012
  const json = this.json;
2202
- const extensions = this.extensions; // Clear the loader cache
2013
+ const extensions = this.extensions;
2203
2014
 
2204
- this.cache.removeAll(); // Mark the special nodes/meshes in json for efficient parse
2015
+ // Clear the loader cache
2016
+ this.cache.removeAll();
2205
2017
 
2018
+ // Mark the special nodes/meshes in json for efficient parse
2206
2019
  this._invokeAll( function ( ext ) {
2207
2020
 
2208
2021
  return ext._markDefs && ext._markDefs();
2209
2022
 
2210
2023
  } );
2211
-
2212
2024
  Promise.all( this._invokeAll( function ( ext ) {
2213
2025
 
2214
2026
  return ext.beforeRoot && ext.beforeRoot();
@@ -2243,43 +2055,41 @@
2243
2055
  } ).catch( onError );
2244
2056
 
2245
2057
  }
2058
+
2246
2059
  /**
2247
2060
  * Marks the special nodes/meshes in json for efficient parse.
2248
2061
  */
2249
-
2250
-
2251
2062
  _markDefs() {
2252
2063
 
2253
2064
  const nodeDefs = this.json.nodes || [];
2254
2065
  const skinDefs = this.json.skins || [];
2255
- const meshDefs = this.json.meshes || []; // Nothing in the node definition indicates whether it is a THREE.Bone or an
2256
- // THREE.Object3D. Use the skins' joint references to mark bones.
2066
+ const meshDefs = this.json.meshes || [];
2257
2067
 
2068
+ // Nothing in the node definition indicates whether it is a THREE.Bone or an
2069
+ // THREE.Object3D. Use the skins' joint references to mark bones.
2258
2070
  for ( let skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex ++ ) {
2259
2071
 
2260
2072
  const joints = skinDefs[ skinIndex ].joints;
2261
-
2262
2073
  for ( let i = 0, il = joints.length; i < il; i ++ ) {
2263
2074
 
2264
2075
  nodeDefs[ joints[ i ] ].isBone = true;
2265
2076
 
2266
2077
  }
2267
2078
 
2268
- } // Iterate over all nodes, marking references to shared resources,
2269
- // as well as skeleton joints.
2270
-
2079
+ }
2271
2080
 
2081
+ // Iterate over all nodes, marking references to shared resources,
2082
+ // as well as skeleton joints.
2272
2083
  for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) {
2273
2084
 
2274
2085
  const nodeDef = nodeDefs[ nodeIndex ];
2275
-
2276
2086
  if ( nodeDef.mesh !== undefined ) {
2277
2087
 
2278
- this._addNodeRef( this.meshCache, nodeDef.mesh ); // Nothing in the mesh definition indicates whether it is
2279
- // a THREE.SkinnedMesh or THREE.Mesh. Use the node's mesh reference
2280
- // to mark THREE.SkinnedMesh if node has skin.
2281
-
2088
+ this._addNodeRef( this.meshCache, nodeDef.mesh );
2282
2089
 
2090
+ // Nothing in the mesh definition indicates whether it is
2091
+ // a THREE.SkinnedMesh or THREE.Mesh. Use the node's mesh reference
2092
+ // to mark THREE.SkinnedMesh if node has skin.
2283
2093
  if ( nodeDef.skin !== undefined ) {
2284
2094
 
2285
2095
  meshDefs[ nodeDef.mesh ].isSkinnedMesh = true;
@@ -2297,6 +2107,7 @@
2297
2107
  }
2298
2108
 
2299
2109
  }
2110
+
2300
2111
  /**
2301
2112
  * Counts references to shared node / THREE.Object3D resources. These resources
2302
2113
  * can be reused, or "instantiated", at multiple nodes in the scene
@@ -2306,12 +2117,9 @@
2306
2117
  *
2307
2118
  * Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
2308
2119
  */
2309
-
2310
-
2311
2120
  _addNodeRef( cache, index ) {
2312
2121
 
2313
2122
  if ( index === undefined ) return;
2314
-
2315
2123
  if ( cache.refs[ index ] === undefined ) {
2316
2124
 
2317
2125
  cache.refs[ index ] = cache.uses[ index ] = 0;
@@ -2321,19 +2129,18 @@
2321
2129
  cache.refs[ index ] ++;
2322
2130
 
2323
2131
  }
2324
- /** Returns a reference to a shared resource, cloning it if necessary. */
2325
-
2326
2132
 
2133
+ /** Returns a reference to a shared resource, cloning it if necessary. */
2327
2134
  _getNodeRef( cache, index, object ) {
2328
2135
 
2329
2136
  if ( cache.refs[ index ] <= 1 ) return object;
2330
- const ref = object.clone(); // Propagates mappings to the cloned object, prevents mappings on the
2331
- // original object from being lost.
2137
+ const ref = object.clone();
2332
2138
 
2139
+ // Propagates mappings to the cloned object, prevents mappings on the
2140
+ // original object from being lost.
2333
2141
  const updateMappings = ( original, clone ) => {
2334
2142
 
2335
2143
  const mappings = this.associations.get( original );
2336
-
2337
2144
  if ( mappings != null ) {
2338
2145
 
2339
2146
  this.associations.set( clone, mappings );
@@ -2353,12 +2160,10 @@
2353
2160
  return ref;
2354
2161
 
2355
2162
  }
2356
-
2357
2163
  _invokeOne( func ) {
2358
2164
 
2359
2165
  const extensions = Object.values( this.plugins );
2360
2166
  extensions.push( this );
2361
-
2362
2167
  for ( let i = 0; i < extensions.length; i ++ ) {
2363
2168
 
2364
2169
  const result = func( extensions[ i ] );
@@ -2369,13 +2174,11 @@
2369
2174
  return null;
2370
2175
 
2371
2176
  }
2372
-
2373
2177
  _invokeAll( func ) {
2374
2178
 
2375
2179
  const extensions = Object.values( this.plugins );
2376
2180
  extensions.unshift( this );
2377
2181
  const pending = [];
2378
-
2379
2182
  for ( let i = 0; i < extensions.length; i ++ ) {
2380
2183
 
2381
2184
  const result = func( extensions[ i ] );
@@ -2386,19 +2189,17 @@
2386
2189
  return pending;
2387
2190
 
2388
2191
  }
2192
+
2389
2193
  /**
2390
2194
  * Requests the specified dependency asynchronously, with caching.
2391
2195
  * @param {string} type
2392
2196
  * @param {number} index
2393
2197
  * @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
2394
2198
  */
2395
-
2396
-
2397
2199
  getDependency( type, index ) {
2398
2200
 
2399
2201
  const cacheKey = type + ':' + index;
2400
2202
  let dependency = this.cache.get( cacheKey );
2401
-
2402
2203
  if ( ! dependency ) {
2403
2204
 
2404
2205
  switch ( type ) {
@@ -2406,11 +2207,9 @@
2406
2207
  case 'scene':
2407
2208
  dependency = this.loadScene( index );
2408
2209
  break;
2409
-
2410
2210
  case 'node':
2411
2211
  dependency = this.loadNode( index );
2412
2212
  break;
2413
-
2414
2213
  case 'mesh':
2415
2214
  dependency = this._invokeOne( function ( ext ) {
2416
2215
 
@@ -2418,11 +2217,9 @@
2418
2217
 
2419
2218
  } );
2420
2219
  break;
2421
-
2422
2220
  case 'accessor':
2423
2221
  dependency = this.loadAccessor( index );
2424
2222
  break;
2425
-
2426
2223
  case 'bufferView':
2427
2224
  dependency = this._invokeOne( function ( ext ) {
2428
2225
 
@@ -2430,11 +2227,9 @@
2430
2227
 
2431
2228
  } );
2432
2229
  break;
2433
-
2434
2230
  case 'buffer':
2435
2231
  dependency = this.loadBuffer( index );
2436
2232
  break;
2437
-
2438
2233
  case 'material':
2439
2234
  dependency = this._invokeOne( function ( ext ) {
2440
2235
 
@@ -2442,7 +2237,6 @@
2442
2237
 
2443
2238
  } );
2444
2239
  break;
2445
-
2446
2240
  case 'texture':
2447
2241
  dependency = this._invokeOne( function ( ext ) {
2448
2242
 
@@ -2450,11 +2244,9 @@
2450
2244
 
2451
2245
  } );
2452
2246
  break;
2453
-
2454
2247
  case 'skin':
2455
2248
  dependency = this.loadSkin( index );
2456
2249
  break;
2457
-
2458
2250
  case 'animation':
2459
2251
  dependency = this._invokeOne( function ( ext ) {
2460
2252
 
@@ -2462,13 +2254,22 @@
2462
2254
 
2463
2255
  } );
2464
2256
  break;
2465
-
2466
2257
  case 'camera':
2467
2258
  dependency = this.loadCamera( index );
2468
2259
  break;
2469
-
2470
2260
  default:
2471
- throw new Error( 'Unknown type: ' + type );
2261
+ dependency = this._invokeOne( function ( ext ) {
2262
+
2263
+ return ext != this && ext.getDependency && ext.getDependency( type, index );
2264
+
2265
+ } );
2266
+ if ( ! dependency ) {
2267
+
2268
+ throw new Error( 'Unknown type: ' + type );
2269
+
2270
+ }
2271
+
2272
+ break;
2472
2273
 
2473
2274
  }
2474
2275
 
@@ -2479,17 +2280,15 @@
2479
2280
  return dependency;
2480
2281
 
2481
2282
  }
2283
+
2482
2284
  /**
2483
2285
  * Requests all dependencies of the specified type asynchronously, with caching.
2484
2286
  * @param {string} type
2485
2287
  * @return {Promise<Array<Object>>}
2486
2288
  */
2487
-
2488
-
2489
2289
  getDependencies( type ) {
2490
2290
 
2491
2291
  let dependencies = this.cache.get( type );
2492
-
2493
2292
  if ( ! dependencies ) {
2494
2293
 
2495
2294
  const parser = this;
@@ -2506,25 +2305,23 @@
2506
2305
  return dependencies;
2507
2306
 
2508
2307
  }
2308
+
2509
2309
  /**
2510
2310
  * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
2511
2311
  * @param {number} bufferIndex
2512
2312
  * @return {Promise<ArrayBuffer>}
2513
2313
  */
2514
-
2515
-
2516
2314
  loadBuffer( bufferIndex ) {
2517
2315
 
2518
2316
  const bufferDef = this.json.buffers[ bufferIndex ];
2519
2317
  const loader = this.fileLoader;
2520
-
2521
2318
  if ( bufferDef.type && bufferDef.type !== 'arraybuffer' ) {
2522
2319
 
2523
2320
  throw new Error( 'THREE.GLTFLoader: ' + bufferDef.type + ' buffer type is not supported.' );
2524
2321
 
2525
- } // If present, GLB container is required to be the first buffer.
2526
-
2322
+ }
2527
2323
 
2324
+ // If present, GLB container is required to be the first buffer.
2528
2325
  if ( bufferDef.uri === undefined && bufferIndex === 0 ) {
2529
2326
 
2530
2327
  return Promise.resolve( this.extensions[ EXTENSIONS.KHR_BINARY_GLTF ].body );
@@ -2543,13 +2340,12 @@
2543
2340
  } );
2544
2341
 
2545
2342
  }
2343
+
2546
2344
  /**
2547
2345
  * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
2548
2346
  * @param {number} bufferViewIndex
2549
2347
  * @return {Promise<ArrayBuffer>}
2550
2348
  */
2551
-
2552
-
2553
2349
  loadBufferView( bufferViewIndex ) {
2554
2350
 
2555
2351
  const bufferViewDef = this.json.bufferViews[ bufferViewIndex ];
@@ -2562,30 +2358,28 @@
2562
2358
  } );
2563
2359
 
2564
2360
  }
2361
+
2565
2362
  /**
2566
2363
  * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
2567
2364
  * @param {number} accessorIndex
2568
2365
  * @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
2569
2366
  */
2570
-
2571
-
2572
2367
  loadAccessor( accessorIndex ) {
2573
2368
 
2574
2369
  const parser = this;
2575
2370
  const json = this.json;
2576
2371
  const accessorDef = this.json.accessors[ accessorIndex ];
2577
-
2578
2372
  if ( accessorDef.bufferView === undefined && accessorDef.sparse === undefined ) {
2579
2373
 
2580
- // Ignore empty accessors, which may be used to declare runtime
2581
- // information about attributes coming from another source (e.g. Draco
2582
- // compression extension).
2583
- return Promise.resolve( null );
2374
+ const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ];
2375
+ const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
2376
+ const normalized = accessorDef.normalized === true;
2377
+ const array = new TypedArray( accessorDef.count * itemSize );
2378
+ return Promise.resolve( new THREE.BufferAttribute( array, itemSize, normalized ) );
2584
2379
 
2585
2380
  }
2586
2381
 
2587
2382
  const pendingBufferViews = [];
2588
-
2589
2383
  if ( accessorDef.bufferView !== undefined ) {
2590
2384
 
2591
2385
  pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.bufferView ) );
@@ -2607,15 +2401,17 @@
2607
2401
 
2608
2402
  const bufferView = bufferViews[ 0 ];
2609
2403
  const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ];
2610
- const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ]; // For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12.
2404
+ const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
2611
2405
 
2406
+ // For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12.
2612
2407
  const elementBytes = TypedArray.BYTES_PER_ELEMENT;
2613
2408
  const itemBytes = elementBytes * itemSize;
2614
2409
  const byteOffset = accessorDef.byteOffset || 0;
2615
2410
  const byteStride = accessorDef.bufferView !== undefined ? json.bufferViews[ accessorDef.bufferView ].byteStride : undefined;
2616
2411
  const normalized = accessorDef.normalized === true;
2617
- let array, bufferAttribute; // The buffer is not interleaved if the stride is the item size in bytes.
2412
+ let array, bufferAttribute;
2618
2413
 
2414
+ // The buffer is not interleaved if the stride is the item size in bytes.
2619
2415
  if ( byteStride && byteStride !== itemBytes ) {
2620
2416
 
2621
2417
  // Each "slice" of the buffer, as defined by 'count' elements of 'byteStride' bytes, gets its own THREE.InterleavedBuffer
@@ -2623,11 +2419,11 @@
2623
2419
  const ibSlice = Math.floor( byteOffset / byteStride );
2624
2420
  const ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType + ':' + ibSlice + ':' + accessorDef.count;
2625
2421
  let ib = parser.cache.get( ibCacheKey );
2626
-
2627
2422
  if ( ! ib ) {
2628
2423
 
2629
- array = new TypedArray( bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes ); // Integer parameters to IB/IBA are in array elements, not bytes.
2424
+ array = new TypedArray( bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes );
2630
2425
 
2426
+ // Integer parameters to IB/IBA are in array elements, not bytes.
2631
2427
  ib = new THREE.InterleavedBuffer( array, byteStride / elementBytes );
2632
2428
  parser.cache.add( ibCacheKey, ib );
2633
2429
 
@@ -2649,9 +2445,9 @@
2649
2445
 
2650
2446
  bufferAttribute = new THREE.BufferAttribute( array, itemSize, normalized );
2651
2447
 
2652
- } // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#sparse-accessors
2653
-
2448
+ }
2654
2449
 
2450
+ // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#sparse-accessors
2655
2451
  if ( accessorDef.sparse !== undefined ) {
2656
2452
 
2657
2453
  const itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
@@ -2660,7 +2456,6 @@
2660
2456
  const byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
2661
2457
  const sparseIndices = new TypedArrayIndices( bufferViews[ 1 ], byteOffsetIndices, accessorDef.sparse.count * itemSizeIndices );
2662
2458
  const sparseValues = new TypedArray( bufferViews[ 2 ], byteOffsetValues, accessorDef.sparse.count * itemSize );
2663
-
2664
2459
  if ( bufferView !== null ) {
2665
2460
 
2666
2461
  // Avoid modifying the original ArrayBuffer, if the bufferView wasn't initialized with zeroes.
@@ -2686,13 +2481,12 @@
2686
2481
  } );
2687
2482
 
2688
2483
  }
2484
+
2689
2485
  /**
2690
2486
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
2691
2487
  * @param {number} textureIndex
2692
- * @return {Promise<THREE.Texture>}
2488
+ * @return {Promise<THREE.Texture|null>}
2693
2489
  */
2694
-
2695
-
2696
2490
  loadTexture( textureIndex ) {
2697
2491
 
2698
2492
  const json = this.json;
@@ -2701,7 +2495,6 @@
2701
2495
  const sourceIndex = textureDef.source;
2702
2496
  const sourceDef = json.images[ sourceIndex ];
2703
2497
  let loader = this.textureLoader;
2704
-
2705
2498
  if ( sourceDef.uri ) {
2706
2499
 
2707
2500
  const handler = options.manager.getHandler( sourceDef.uri );
@@ -2712,7 +2505,6 @@
2712
2505
  return this.loadTextureImage( textureIndex, sourceIndex, loader );
2713
2506
 
2714
2507
  }
2715
-
2716
2508
  loadTextureImage( textureIndex, sourceIndex, loader ) {
2717
2509
 
2718
2510
  const parser = this;
@@ -2720,7 +2512,6 @@
2720
2512
  const textureDef = json.textures[ textureIndex ];
2721
2513
  const sourceDef = json.images[ sourceIndex ];
2722
2514
  const cacheKey = ( sourceDef.uri || sourceDef.bufferView ) + ':' + textureDef.sampler;
2723
-
2724
2515
  if ( this.textureCache[ cacheKey ] ) {
2725
2516
 
2726
2517
  // See https://github.com/mrdoob/three.js/issues/21559.
@@ -2731,7 +2522,7 @@
2731
2522
  const promise = this.loadImageSource( sourceIndex, loader ).then( function ( texture ) {
2732
2523
 
2733
2524
  texture.flipY = false;
2734
- if ( textureDef.name ) texture.name = textureDef.name;
2525
+ texture.name = textureDef.name || sourceDef.name || '';
2735
2526
  const samplers = json.samplers || {};
2736
2527
  const sampler = samplers[ textureDef.sampler ] || {};
2737
2528
  texture.magFilter = WEBGL_FILTERS[ sampler.magFilter ] || THREE.LinearFilter;
@@ -2752,13 +2543,11 @@
2752
2543
  return promise;
2753
2544
 
2754
2545
  }
2755
-
2756
2546
  loadImageSource( sourceIndex, loader ) {
2757
2547
 
2758
2548
  const parser = this;
2759
2549
  const json = this.json;
2760
2550
  const options = this.options;
2761
-
2762
2551
  if ( this.sourceCache[ sourceIndex ] !== undefined ) {
2763
2552
 
2764
2553
  return this.sourceCache[ sourceIndex ].then( texture => texture.clone() );
@@ -2769,10 +2558,10 @@
2769
2558
  const URL = self.URL || self.webkitURL;
2770
2559
  let sourceURI = sourceDef.uri || '';
2771
2560
  let isObjectURL = false;
2772
-
2773
2561
  if ( sourceDef.bufferView !== undefined ) {
2774
2562
 
2775
2563
  // Load binary image data from bufferView, if provided.
2564
+
2776
2565
  sourceURI = parser.getDependency( 'bufferView', sourceDef.bufferView ).then( function ( bufferView ) {
2777
2566
 
2778
2567
  isObjectURL = true;
@@ -2795,7 +2584,6 @@
2795
2584
  return new Promise( function ( resolve, reject ) {
2796
2585
 
2797
2586
  let onLoad = resolve;
2798
-
2799
2587
  if ( loader.isImageBitmapLoader === true ) {
2800
2588
 
2801
2589
  onLoad = function ( imageBitmap ) {
@@ -2815,6 +2603,7 @@
2815
2603
  } ).then( function ( texture ) {
2816
2604
 
2817
2605
  // Clean up resources and configure THREE.Texture.
2606
+
2818
2607
  if ( isObjectURL === true ) {
2819
2608
 
2820
2609
  URL.revokeObjectURL( sourceURI );
@@ -2834,6 +2623,7 @@
2834
2623
  return promise;
2835
2624
 
2836
2625
  }
2626
+
2837
2627
  /**
2838
2628
  * Asynchronously assigns a texture to the given material parameters.
2839
2629
  * @param {Object} materialParams
@@ -2841,13 +2631,13 @@
2841
2631
  * @param {Object} mapDef
2842
2632
  * @return {Promise<Texture>}
2843
2633
  */
2844
-
2845
-
2846
2634
  assignTexture( materialParams, mapName, mapDef, encoding ) {
2847
2635
 
2848
2636
  const parser = this;
2849
2637
  return this.getDependency( 'texture', mapDef.index ).then( function ( texture ) {
2850
2638
 
2639
+ if ( ! texture ) return null;
2640
+
2851
2641
  // Materials sample aoMap from UV set 1 and other maps from UV set 0 - this can't be configured
2852
2642
  // However, we will copy UV set 0 to UV set 1 on demand for aoMap
2853
2643
  if ( mapDef.texCoord !== undefined && mapDef.texCoord != 0 && ! ( mapName === 'aoMap' && mapDef.texCoord == 1 ) ) {
@@ -2859,7 +2649,6 @@
2859
2649
  if ( parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] ) {
2860
2650
 
2861
2651
  const transform = mapDef.extensions !== undefined ? mapDef.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] : undefined;
2862
-
2863
2652
  if ( transform ) {
2864
2653
 
2865
2654
  const gltfReference = parser.associations.get( texture );
@@ -2882,6 +2671,7 @@
2882
2671
  } );
2883
2672
 
2884
2673
  }
2674
+
2885
2675
  /**
2886
2676
  * Assigns final material to a THREE.Mesh, THREE.Line, or THREE.Points instance. The instance
2887
2677
  * already has a material (generated from the glTF material options alone)
@@ -2890,8 +2680,6 @@
2890
2680
  * be created if necessary, and reused from a cache.
2891
2681
  * @param {Object3D} mesh THREE.Mesh, THREE.Line, or THREE.Points instance.
2892
2682
  */
2893
-
2894
-
2895
2683
  assignFinalMaterial( mesh ) {
2896
2684
 
2897
2685
  const geometry = mesh.geometry;
@@ -2899,12 +2687,10 @@
2899
2687
  const useDerivativeTangents = geometry.attributes.tangent === undefined;
2900
2688
  const useVertexColors = geometry.attributes.color !== undefined;
2901
2689
  const useFlatShading = geometry.attributes.normal === undefined;
2902
-
2903
2690
  if ( mesh.isPoints ) {
2904
2691
 
2905
2692
  const cacheKey = 'PointsMaterial:' + material.uuid;
2906
2693
  let pointsMaterial = this.cache.get( cacheKey );
2907
-
2908
2694
  if ( ! pointsMaterial ) {
2909
2695
 
2910
2696
  pointsMaterial = new THREE.PointsMaterial();
@@ -2923,7 +2709,6 @@
2923
2709
 
2924
2710
  const cacheKey = 'LineBasicMaterial:' + material.uuid;
2925
2711
  let lineMaterial = this.cache.get( cacheKey );
2926
-
2927
2712
  if ( ! lineMaterial ) {
2928
2713
 
2929
2714
  lineMaterial = new THREE.LineBasicMaterial();
@@ -2935,24 +2720,21 @@
2935
2720
 
2936
2721
  material = lineMaterial;
2937
2722
 
2938
- } // Clone the material if it will be modified
2939
-
2723
+ }
2940
2724
 
2725
+ // Clone the material if it will be modified
2941
2726
  if ( useDerivativeTangents || useVertexColors || useFlatShading ) {
2942
2727
 
2943
2728
  let cacheKey = 'ClonedMaterial:' + material.uuid + ':';
2944
- if ( material.isGLTFSpecularGlossinessMaterial ) cacheKey += 'specular-glossiness:';
2945
2729
  if ( useDerivativeTangents ) cacheKey += 'derivative-tangents:';
2946
2730
  if ( useVertexColors ) cacheKey += 'vertex-colors:';
2947
2731
  if ( useFlatShading ) cacheKey += 'flat-shading:';
2948
2732
  let cachedMaterial = this.cache.get( cacheKey );
2949
-
2950
2733
  if ( ! cachedMaterial ) {
2951
2734
 
2952
2735
  cachedMaterial = material.clone();
2953
2736
  if ( useVertexColors ) cachedMaterial.vertexColors = true;
2954
2737
  if ( useFlatShading ) cachedMaterial.flatShading = true;
2955
-
2956
2738
  if ( useDerivativeTangents ) {
2957
2739
 
2958
2740
  // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
@@ -2968,8 +2750,9 @@
2968
2750
 
2969
2751
  material = cachedMaterial;
2970
2752
 
2971
- } // workarounds for mesh and geometry
2753
+ }
2972
2754
 
2755
+ // workarounds for mesh and geometry
2973
2756
 
2974
2757
  if ( material.aoMap && geometry.attributes.uv2 === undefined && geometry.attributes.uv !== undefined ) {
2975
2758
 
@@ -2980,19 +2763,17 @@
2980
2763
  mesh.material = material;
2981
2764
 
2982
2765
  }
2983
-
2984
2766
  getMaterialType() {
2985
2767
 
2986
2768
  return THREE.MeshStandardMaterial;
2987
2769
 
2988
2770
  }
2771
+
2989
2772
  /**
2990
2773
  * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
2991
2774
  * @param {number} materialIndex
2992
2775
  * @return {Promise<Material>}
2993
2776
  */
2994
-
2995
-
2996
2777
  loadMaterial( materialIndex ) {
2997
2778
 
2998
2779
  const parser = this;
@@ -3003,14 +2784,7 @@
3003
2784
  const materialParams = {};
3004
2785
  const materialExtensions = materialDef.extensions || {};
3005
2786
  const pending = [];
3006
-
3007
- if ( materialExtensions[ EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS ] ) {
3008
-
3009
- const sgExtension = extensions[ EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS ];
3010
- materialType = sgExtension.getMaterialType();
3011
- pending.push( sgExtension.extendParams( materialParams, materialDef, parser ) );
3012
-
3013
- } else if ( materialExtensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ] ) {
2787
+ if ( materialExtensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ] ) {
3014
2788
 
3015
2789
  const kmuExtension = extensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ];
3016
2790
  materialType = kmuExtension.getMaterialType();
@@ -3020,10 +2794,10 @@
3020
2794
 
3021
2795
  // Specification:
3022
2796
  // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material
2797
+
3023
2798
  const metallicRoughness = materialDef.pbrMetallicRoughness || {};
3024
2799
  materialParams.color = new THREE.Color( 1.0, 1.0, 1.0 );
3025
2800
  materialParams.opacity = 1.0;
3026
-
3027
2801
  if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
3028
2802
 
3029
2803
  const array = metallicRoughness.baseColorFactor;
@@ -3040,7 +2814,6 @@
3040
2814
 
3041
2815
  materialParams.metalness = metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0;
3042
2816
  materialParams.roughness = metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0;
3043
-
3044
2817
  if ( metallicRoughness.metallicRoughnessTexture !== undefined ) {
3045
2818
 
3046
2819
  pending.push( parser.assignTexture( materialParams, 'metalnessMap', metallicRoughness.metallicRoughnessTexture ) );
@@ -3068,17 +2841,16 @@
3068
2841
  }
3069
2842
 
3070
2843
  const alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
3071
-
3072
2844
  if ( alphaMode === ALPHA_MODES.BLEND ) {
3073
2845
 
3074
- materialParams.transparent = true; // See: https://github.com/mrdoob/three.js/issues/17706
2846
+ materialParams.transparent = true;
3075
2847
 
2848
+ // See: https://github.com/mrdoob/three.js/issues/17706
3076
2849
  materialParams.depthWrite = false;
3077
2850
 
3078
2851
  } else {
3079
2852
 
3080
2853
  materialParams.transparent = false;
3081
-
3082
2854
  if ( alphaMode === ALPHA_MODES.MASK ) {
3083
2855
 
3084
2856
  materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
@@ -3091,7 +2863,6 @@
3091
2863
 
3092
2864
  pending.push( parser.assignTexture( materialParams, 'normalMap', materialDef.normalTexture ) );
3093
2865
  materialParams.normalScale = new THREE.Vector2( 1, 1 );
3094
-
3095
2866
  if ( materialDef.normalTexture.scale !== undefined ) {
3096
2867
 
3097
2868
  const scale = materialDef.normalTexture.scale;
@@ -3104,7 +2875,6 @@
3104
2875
  if ( materialDef.occlusionTexture !== undefined && materialType !== THREE.MeshBasicMaterial ) {
3105
2876
 
3106
2877
  pending.push( parser.assignTexture( materialParams, 'aoMap', materialDef.occlusionTexture ) );
3107
-
3108
2878
  if ( materialDef.occlusionTexture.strength !== undefined ) {
3109
2879
 
3110
2880
  materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
@@ -3127,18 +2897,7 @@
3127
2897
 
3128
2898
  return Promise.all( pending ).then( function () {
3129
2899
 
3130
- let material;
3131
-
3132
- if ( materialType === GLTFMeshStandardSGMaterial ) {
3133
-
3134
- material = extensions[ EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS ].createMaterial( materialParams );
3135
-
3136
- } else {
3137
-
3138
- material = new materialType( materialParams );
3139
-
3140
- }
3141
-
2900
+ const material = new materialType( materialParams );
3142
2901
  if ( materialDef.name ) material.name = materialDef.name;
3143
2902
  assignExtrasToUserData( material, materialDef );
3144
2903
  parser.associations.set( material, {
@@ -3150,14 +2909,12 @@
3150
2909
  } );
3151
2910
 
3152
2911
  }
3153
- /** When THREE.Object3D instances are targeted by animation, they need unique names. */
3154
-
3155
2912
 
2913
+ /** When THREE.Object3D instances are targeted by animation, they need unique names. */
3156
2914
  createUniqueName( originalName ) {
3157
2915
 
3158
2916
  const sanitizedName = THREE.PropertyBinding.sanitizeNodeName( originalName || '' );
3159
2917
  let name = sanitizedName;
3160
-
3161
2918
  for ( let i = 1; this.nodeNamesUsed[ name ]; ++ i ) {
3162
2919
 
3163
2920
  name = sanitizedName + '_' + i;
@@ -3168,6 +2925,7 @@
3168
2925
  return name;
3169
2926
 
3170
2927
  }
2928
+
3171
2929
  /**
3172
2930
  * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
3173
2931
  *
@@ -3176,14 +2934,11 @@
3176
2934
  * @param {Array<GLTF.Primitive>} primitives
3177
2935
  * @return {Promise<Array<BufferGeometry>>}
3178
2936
  */
3179
-
3180
-
3181
2937
  loadGeometries( primitives ) {
3182
2938
 
3183
2939
  const parser = this;
3184
2940
  const extensions = this.extensions;
3185
2941
  const cache = this.primitiveCache;
3186
-
3187
2942
  function createDracoPrimitive( primitive ) {
3188
2943
 
3189
2944
  return extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ].decodePrimitive( primitive, parser ).then( function ( geometry ) {
@@ -3195,14 +2950,13 @@
3195
2950
  }
3196
2951
 
3197
2952
  const pending = [];
3198
-
3199
2953
  for ( let i = 0, il = primitives.length; i < il; i ++ ) {
3200
2954
 
3201
2955
  const primitive = primitives[ i ];
3202
- const cacheKey = createPrimitiveKey( primitive ); // See if we've already created this geometry
2956
+ const cacheKey = createPrimitiveKey( primitive );
3203
2957
 
2958
+ // See if we've already created this geometry
3204
2959
  const cached = cache[ cacheKey ];
3205
-
3206
2960
  if ( cached ) {
3207
2961
 
3208
2962
  // Use the cached geometry if it exists
@@ -3211,7 +2965,6 @@
3211
2965
  } else {
3212
2966
 
3213
2967
  let geometryPromise;
3214
-
3215
2968
  if ( primitive.extensions && primitive.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ] ) {
3216
2969
 
3217
2970
  // Use DRACO geometry if available
@@ -3222,9 +2975,9 @@
3222
2975
  // Otherwise create a new geometry
3223
2976
  geometryPromise = addPrimitiveAttributes( new THREE.BufferGeometry(), primitive, parser );
3224
2977
 
3225
- } // Cache this geometry
3226
-
2978
+ }
3227
2979
 
2980
+ // Cache this geometry
3228
2981
  cache[ cacheKey ] = {
3229
2982
  primitive: primitive,
3230
2983
  promise: geometryPromise
@@ -3238,13 +2991,12 @@
3238
2991
  return Promise.all( pending );
3239
2992
 
3240
2993
  }
2994
+
3241
2995
  /**
3242
2996
  * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
3243
2997
  * @param {number} meshIndex
3244
2998
  * @return {Promise<Group|Mesh|SkinnedMesh>}
3245
2999
  */
3246
-
3247
-
3248
3000
  loadMesh( meshIndex ) {
3249
3001
 
3250
3002
  const parser = this;
@@ -3253,7 +3005,6 @@
3253
3005
  const meshDef = json.meshes[ meshIndex ];
3254
3006
  const primitives = meshDef.primitives;
3255
3007
  const pending = [];
3256
-
3257
3008
  for ( let i = 0, il = primitives.length; i < il; i ++ ) {
3258
3009
 
3259
3010
  const material = primitives[ i ].material === undefined ? createDefaultMaterial( this.cache ) : this.getDependency( 'material', primitives[ i ].material );
@@ -3267,20 +3018,19 @@
3267
3018
  const materials = results.slice( 0, results.length - 1 );
3268
3019
  const geometries = results[ results.length - 1 ];
3269
3020
  const meshes = [];
3270
-
3271
3021
  for ( let i = 0, il = geometries.length; i < il; i ++ ) {
3272
3022
 
3273
3023
  const geometry = geometries[ i ];
3274
- const primitive = primitives[ i ]; // 1. create THREE.Mesh
3024
+ const primitive = primitives[ i ];
3025
+
3026
+ // 1. create THREE.Mesh
3275
3027
 
3276
3028
  let mesh;
3277
3029
  const material = materials[ i ];
3278
-
3279
3030
  if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLES || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN || primitive.mode === undefined ) {
3280
3031
 
3281
3032
  // .isSkinnedMesh isn't in glTF spec. See ._markDefs()
3282
3033
  mesh = meshDef.isSkinnedMesh === true ? new THREE.SkinnedMesh( geometry, material ) : new THREE.Mesh( geometry, material );
3283
-
3284
3034
  if ( mesh.isSkinnedMesh === true && ! mesh.geometry.attributes.skinWeight.normalized ) {
3285
3035
 
3286
3036
  // we normalize floating point skin weight array to fix malformed assets (see #15319)
@@ -3354,7 +3104,6 @@
3354
3104
  parser.associations.set( group, {
3355
3105
  meshes: meshIndex
3356
3106
  } );
3357
-
3358
3107
  for ( let i = 0, il = meshes.length; i < il; i ++ ) {
3359
3108
 
3360
3109
  group.add( meshes[ i ] );
@@ -3366,19 +3115,17 @@
3366
3115
  } );
3367
3116
 
3368
3117
  }
3118
+
3369
3119
  /**
3370
3120
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
3371
3121
  * @param {number} cameraIndex
3372
3122
  * @return {Promise<THREE.Camera>}
3373
3123
  */
3374
-
3375
-
3376
3124
  loadCamera( cameraIndex ) {
3377
3125
 
3378
3126
  let camera;
3379
3127
  const cameraDef = this.json.cameras[ cameraIndex ];
3380
3128
  const params = cameraDef[ cameraDef.type ];
3381
-
3382
3129
  if ( ! params ) {
3383
3130
 
3384
3131
  console.warn( 'THREE.GLTFLoader: Missing camera parameters.' );
@@ -3401,41 +3148,72 @@
3401
3148
  return Promise.resolve( camera );
3402
3149
 
3403
3150
  }
3151
+
3404
3152
  /**
3405
3153
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
3406
3154
  * @param {number} skinIndex
3407
- * @return {Promise<Object>}
3155
+ * @return {Promise<Skeleton>}
3408
3156
  */
3409
-
3410
-
3411
3157
  loadSkin( skinIndex ) {
3412
3158
 
3413
3159
  const skinDef = this.json.skins[ skinIndex ];
3414
- const skinEntry = {
3415
- joints: skinDef.joints
3416
- };
3160
+ const pending = [];
3161
+ for ( let i = 0, il = skinDef.joints.length; i < il; i ++ ) {
3417
3162
 
3418
- if ( skinDef.inverseBindMatrices === undefined ) {
3163
+ pending.push( this.getDependency( 'node', skinDef.joints[ i ] ) );
3419
3164
 
3420
- return Promise.resolve( skinEntry );
3165
+ }
3166
+
3167
+ if ( skinDef.inverseBindMatrices !== undefined ) {
3168
+
3169
+ pending.push( this.getDependency( 'accessor', skinDef.inverseBindMatrices ) );
3170
+
3171
+ } else {
3172
+
3173
+ pending.push( null );
3421
3174
 
3422
3175
  }
3423
3176
 
3424
- return this.getDependency( 'accessor', skinDef.inverseBindMatrices ).then( function ( accessor ) {
3177
+ return Promise.all( pending ).then( function ( results ) {
3178
+
3179
+ const inverseBindMatrices = results.pop();
3180
+ const jointNodes = results;
3181
+ const bones = [];
3182
+ const boneInverses = [];
3183
+ for ( let i = 0, il = jointNodes.length; i < il; i ++ ) {
3184
+
3185
+ const jointNode = jointNodes[ i ];
3186
+ if ( jointNode ) {
3187
+
3188
+ bones.push( jointNode );
3189
+ const mat = new THREE.Matrix4();
3190
+ if ( inverseBindMatrices !== null ) {
3191
+
3192
+ mat.fromArray( inverseBindMatrices.array, i * 16 );
3193
+
3194
+ }
3195
+
3196
+ boneInverses.push( mat );
3197
+
3198
+ } else {
3199
+
3200
+ console.warn( 'THREE.GLTFLoader: Joint "%s" could not be found.', skinDef.joints[ i ] );
3201
+
3202
+ }
3203
+
3204
+ }
3425
3205
 
3426
- skinEntry.inverseBindMatrices = accessor;
3427
- return skinEntry;
3206
+ return new THREE.Skeleton( bones, boneInverses );
3428
3207
 
3429
3208
  } );
3430
3209
 
3431
3210
  }
3211
+
3432
3212
  /**
3433
3213
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
3434
3214
  * @param {number} animationIndex
3435
3215
  * @return {Promise<AnimationClip>}
3436
3216
  */
3437
-
3438
-
3439
3217
  loadAnimation( animationIndex ) {
3440
3218
 
3441
3219
  const json = this.json;
@@ -3445,14 +3223,12 @@
3445
3223
  const pendingOutputAccessors = [];
3446
3224
  const pendingSamplers = [];
3447
3225
  const pendingTargets = [];
3448
-
3449
3226
  for ( let i = 0, il = animationDef.channels.length; i < il; i ++ ) {
3450
3227
 
3451
3228
  const channel = animationDef.channels[ i ];
3452
3229
  const sampler = animationDef.samplers[ channel.sampler ];
3453
3230
  const target = channel.target;
3454
- const name = target.node !== undefined ? target.node : target.id; // NOTE: target.id is deprecated.
3455
-
3231
+ const name = target.node;
3456
3232
  const input = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.input ] : sampler.input;
3457
3233
  const output = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.output ] : sampler.output;
3458
3234
  pendingNodes.push( this.getDependency( 'node', name ) );
@@ -3471,7 +3247,6 @@
3471
3247
  const samplers = dependencies[ 3 ];
3472
3248
  const targets = dependencies[ 4 ];
3473
3249
  const tracks = [];
3474
-
3475
3250
  for ( let i = 0, il = nodes.length; i < il; i ++ ) {
3476
3251
 
3477
3252
  const node = nodes[ i ];
@@ -3481,19 +3256,15 @@
3481
3256
  const target = targets[ i ];
3482
3257
  if ( node === undefined ) continue;
3483
3258
  node.updateMatrix();
3484
- node.matrixAutoUpdate = true;
3485
3259
  let TypedKeyframeTrack;
3486
-
3487
3260
  switch ( PATH_PROPERTIES[ target.path ] ) {
3488
3261
 
3489
3262
  case PATH_PROPERTIES.weights:
3490
3263
  TypedKeyframeTrack = THREE.NumberKeyframeTrack;
3491
3264
  break;
3492
-
3493
3265
  case PATH_PROPERTIES.rotation:
3494
3266
  TypedKeyframeTrack = THREE.QuaternionKeyframeTrack;
3495
3267
  break;
3496
-
3497
3268
  case PATH_PROPERTIES.position:
3498
3269
  case PATH_PROPERTIES.scale:
3499
3270
  default:
@@ -3505,7 +3276,6 @@
3505
3276
  const targetName = node.name ? node.name : node.uuid;
3506
3277
  const interpolation = sampler.interpolation !== undefined ? INTERPOLATION[ sampler.interpolation ] : THREE.InterpolateLinear;
3507
3278
  const targetNames = [];
3508
-
3509
3279
  if ( PATH_PROPERTIES[ target.path ] === PATH_PROPERTIES.weights ) {
3510
3280
 
3511
3281
  node.traverse( function ( object ) {
@@ -3525,12 +3295,10 @@
3525
3295
  }
3526
3296
 
3527
3297
  let outputArray = outputAccessor.array;
3528
-
3529
3298
  if ( outputAccessor.normalized ) {
3530
3299
 
3531
3300
  const scale = getNormalizedComponentScale( outputArray.constructor );
3532
3301
  const scaled = new Float32Array( outputArray.length );
3533
-
3534
3302
  for ( let j = 0, jl = outputArray.length; j < jl; j ++ ) {
3535
3303
 
3536
3304
  scaled[ j ] = outputArray[ j ] * scale;
@@ -3543,8 +3311,9 @@
3543
3311
 
3544
3312
  for ( let j = 0, jl = targetNames.length; j < jl; j ++ ) {
3545
3313
 
3546
- const track = new TypedKeyframeTrack( targetNames[ j ] + '.' + PATH_PROPERTIES[ target.path ], inputAccessor.array, outputArray, interpolation ); // Override interpolation with custom factory method.
3314
+ const track = new TypedKeyframeTrack( targetNames[ j ] + '.' + PATH_PROPERTIES[ target.path ], inputAccessor.array, outputArray, interpolation );
3547
3315
 
3316
+ // Override interpolation with custom factory method.
3548
3317
  if ( sampler.interpolation === 'CUBICSPLINE' ) {
3549
3318
 
3550
3319
  track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline( result ) {
@@ -3552,12 +3321,13 @@
3552
3321
  // A CUBICSPLINE keyframe in glTF has three output values for each input value,
3553
3322
  // representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
3554
3323
  // must be divided by three to get the interpolant's sampleSize argument.
3324
+
3555
3325
  const interpolantType = this instanceof THREE.QuaternionKeyframeTrack ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
3556
3326
  return new interpolantType( this.times, this.values, this.getValueSize() / 3, result );
3557
3327
 
3558
- }; // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
3559
-
3328
+ };
3560
3329
 
3330
+ // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
3561
3331
  track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
3562
3332
 
3563
3333
  }
@@ -3574,7 +3344,6 @@
3574
3344
  } );
3575
3345
 
3576
3346
  }
3577
-
3578
3347
  createNodeMesh( nodeIndex ) {
3579
3348
 
3580
3349
  const json = this.json;
@@ -3583,15 +3352,14 @@
3583
3352
  if ( nodeDef.mesh === undefined ) return null;
3584
3353
  return parser.getDependency( 'mesh', nodeDef.mesh ).then( function ( mesh ) {
3585
3354
 
3586
- const node = parser._getNodeRef( parser.meshCache, nodeDef.mesh, mesh ); // if weights are provided on the node, override weights on the mesh.
3587
-
3355
+ const node = parser._getNodeRef( parser.meshCache, nodeDef.mesh, mesh );
3588
3356
 
3357
+ // if weights are provided on the node, override weights on the mesh.
3589
3358
  if ( nodeDef.weights !== undefined ) {
3590
3359
 
3591
3360
  node.traverse( function ( o ) {
3592
3361
 
3593
3362
  if ( ! o.isMesh ) return;
3594
-
3595
3363
  for ( let i = 0, il = nodeDef.weights.length; i < il; i ++ ) {
3596
3364
 
3597
3365
  o.morphTargetInfluences[ i ] = nodeDef.weights[ i ];
@@ -3607,31 +3375,29 @@
3607
3375
  } );
3608
3376
 
3609
3377
  }
3378
+
3610
3379
  /**
3611
3380
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
3612
3381
  * @param {number} nodeIndex
3613
3382
  * @return {Promise<Object3D>}
3614
3383
  */
3615
-
3616
-
3617
3384
  loadNode( nodeIndex ) {
3618
3385
 
3619
3386
  const json = this.json;
3620
3387
  const extensions = this.extensions;
3621
3388
  const parser = this;
3622
- const nodeDef = json.nodes[ nodeIndex ]; // reserve node's name before its dependencies, so the root has the intended name.
3389
+ const nodeDef = json.nodes[ nodeIndex ];
3623
3390
 
3391
+ // reserve node's name before its dependencies, so the root has the intended name.
3624
3392
  const nodeName = nodeDef.name ? parser.createUniqueName( nodeDef.name ) : '';
3625
3393
  return function () {
3626
3394
 
3627
3395
  const pending = [];
3628
-
3629
3396
  const meshPromise = parser._invokeOne( function ( ext ) {
3630
3397
 
3631
3398
  return ext.createNodeMesh && ext.createNodeMesh( nodeIndex );
3632
3399
 
3633
3400
  } );
3634
-
3635
3401
  if ( meshPromise ) {
3636
3402
 
3637
3403
  pending.push( meshPromise );
@@ -3657,13 +3423,13 @@
3657
3423
  pending.push( promise );
3658
3424
 
3659
3425
  } );
3660
-
3661
3426
  return Promise.all( pending );
3662
3427
 
3663
3428
  }().then( function ( objects ) {
3664
3429
 
3665
- let node; // .isBone isn't in glTF spec. See ._markDefs
3430
+ let node;
3666
3431
 
3432
+ // .isBone isn't in glTF spec. See ._markDefs
3667
3433
  if ( nodeDef.isBone === true ) {
3668
3434
 
3669
3435
  node = new THREE.Bone();
@@ -3701,7 +3467,6 @@
3701
3467
 
3702
3468
  assignExtrasToUserData( node, nodeDef );
3703
3469
  if ( nodeDef.extensions ) addUnknownExtensionsToUserData( extensions, node, nodeDef );
3704
-
3705
3470
  if ( nodeDef.matrix !== undefined ) {
3706
3471
 
3707
3472
  const matrix = new THREE.Matrix4();
@@ -3742,28 +3507,27 @@
3742
3507
  } );
3743
3508
 
3744
3509
  }
3510
+
3745
3511
  /**
3746
3512
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
3747
3513
  * @param {number} sceneIndex
3748
3514
  * @return {Promise<Group>}
3749
3515
  */
3750
-
3751
-
3752
3516
  loadScene( sceneIndex ) {
3753
3517
 
3754
3518
  const json = this.json;
3755
3519
  const extensions = this.extensions;
3756
3520
  const sceneDef = this.json.scenes[ sceneIndex ];
3757
- const parser = this; // THREE.Loader returns THREE.Group, not Scene.
3758
- // See: https://github.com/mrdoob/three.js/issues/18342#issuecomment-578981172
3521
+ const parser = this;
3759
3522
 
3523
+ // THREE.Loader returns THREE.Group, not Scene.
3524
+ // See: https://github.com/mrdoob/three.js/issues/18342#issuecomment-578981172
3760
3525
  const scene = new THREE.Group();
3761
3526
  if ( sceneDef.name ) scene.name = parser.createUniqueName( sceneDef.name );
3762
3527
  assignExtrasToUserData( scene, sceneDef );
3763
3528
  if ( sceneDef.extensions ) addUnknownExtensionsToUserData( extensions, scene, sceneDef );
3764
3529
  const nodeIds = sceneDef.nodes || [];
3765
3530
  const pending = [];
3766
-
3767
3531
  for ( let i = 0, il = nodeIds.length; i < il; i ++ ) {
3768
3532
 
3769
3533
  pending.push( buildNodeHierarchy( nodeIds[ i ], scene, json, parser ) );
@@ -3777,7 +3541,6 @@
3777
3541
  const reduceAssociations = node => {
3778
3542
 
3779
3543
  const reducedAssociations = new Map();
3780
-
3781
3544
  for ( const [ key, value ] of parser.associations ) {
3782
3545
 
3783
3546
  if ( key instanceof THREE.Material || key instanceof THREE.Texture ) {
@@ -3791,7 +3554,6 @@
3791
3554
  node.traverse( node => {
3792
3555
 
3793
3556
  const mappings = parser.associations.get( node );
3794
-
3795
3557
  if ( mappings != null ) {
3796
3558
 
3797
3559
  reducedAssociations.set( node, mappings );
@@ -3811,62 +3573,21 @@
3811
3573
  }
3812
3574
 
3813
3575
  }
3814
-
3815
3576
  function buildNodeHierarchy( nodeId, parentObject, json, parser ) {
3816
3577
 
3817
3578
  const nodeDef = json.nodes[ nodeId ];
3818
3579
  return parser.getDependency( 'node', nodeId ).then( function ( node ) {
3819
3580
 
3820
- if ( nodeDef.skin === undefined ) return node; // build skeleton here as well
3581
+ if ( nodeDef.skin === undefined ) return node;
3821
3582
 
3822
- let skinEntry;
3823
- return parser.getDependency( 'skin', nodeDef.skin ).then( function ( skin ) {
3583
+ // build skeleton here as well
3824
3584
 
3825
- skinEntry = skin;
3826
- const pendingJoints = [];
3827
-
3828
- for ( let i = 0, il = skinEntry.joints.length; i < il; i ++ ) {
3829
-
3830
- pendingJoints.push( parser.getDependency( 'node', skinEntry.joints[ i ] ) );
3831
-
3832
- }
3833
-
3834
- return Promise.all( pendingJoints );
3835
-
3836
- } ).then( function ( jointNodes ) {
3585
+ return parser.getDependency( 'skin', nodeDef.skin ).then( function ( skeleton ) {
3837
3586
 
3838
3587
  node.traverse( function ( mesh ) {
3839
3588
 
3840
- if ( ! mesh.isMesh ) return;
3841
- const bones = [];
3842
- const boneInverses = [];
3843
-
3844
- for ( let j = 0, jl = jointNodes.length; j < jl; j ++ ) {
3845
-
3846
- const jointNode = jointNodes[ j ];
3847
-
3848
- if ( jointNode ) {
3849
-
3850
- bones.push( jointNode );
3851
- const mat = new THREE.Matrix4();
3852
-
3853
- if ( skinEntry.inverseBindMatrices !== undefined ) {
3854
-
3855
- mat.fromArray( skinEntry.inverseBindMatrices.array, j * 16 );
3856
-
3857
- }
3858
-
3859
- boneInverses.push( mat );
3860
-
3861
- } else {
3862
-
3863
- console.warn( 'THREE.GLTFLoader: Joint "%s" could not be found.', skinEntry.joints[ j ] );
3864
-
3865
- }
3866
-
3867
- }
3868
-
3869
- mesh.bind( new THREE.Skeleton( bones, boneInverses ), mesh.matrixWorld );
3589
+ if ( ! mesh.isSkinnedMesh ) return;
3590
+ mesh.bind( skeleton, mesh.matrixWorld );
3870
3591
 
3871
3592
  } );
3872
3593
  return node;
@@ -3876,13 +3597,12 @@
3876
3597
  } ).then( function ( node ) {
3877
3598
 
3878
3599
  // build node hierachy
3600
+
3879
3601
  parentObject.add( node );
3880
3602
  const pending = [];
3881
-
3882
3603
  if ( nodeDef.children ) {
3883
3604
 
3884
3605
  const children = nodeDef.children;
3885
-
3886
3606
  for ( let i = 0, il = children.length; i < il; i ++ ) {
3887
3607
 
3888
3608
  const child = children[ i ];
@@ -3897,28 +3617,27 @@
3897
3617
  } );
3898
3618
 
3899
3619
  }
3620
+
3900
3621
  /**
3901
3622
  * @param {BufferGeometry} geometry
3902
3623
  * @param {GLTF.Primitive} primitiveDef
3903
3624
  * @param {GLTFParser} parser
3904
3625
  */
3905
-
3906
-
3907
3626
  function computeBounds( geometry, primitiveDef, parser ) {
3908
3627
 
3909
3628
  const attributes = primitiveDef.attributes;
3910
3629
  const box = new THREE.Box3();
3911
-
3912
3630
  if ( attributes.POSITION !== undefined ) {
3913
3631
 
3914
3632
  const accessor = parser.json.accessors[ attributes.POSITION ];
3915
3633
  const min = accessor.min;
3916
- const max = accessor.max; // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
3634
+ const max = accessor.max;
3635
+
3636
+ // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
3917
3637
 
3918
3638
  if ( min !== undefined && max !== undefined ) {
3919
3639
 
3920
3640
  box.set( new THREE.Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ), new THREE.Vector3( max[ 0 ], max[ 1 ], max[ 2 ] ) );
3921
-
3922
3641
  if ( accessor.normalized ) {
3923
3642
 
3924
3643
  const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] );
@@ -3941,21 +3660,20 @@
3941
3660
  }
3942
3661
 
3943
3662
  const targets = primitiveDef.targets;
3944
-
3945
3663
  if ( targets !== undefined ) {
3946
3664
 
3947
3665
  const maxDisplacement = new THREE.Vector3();
3948
3666
  const vector = new THREE.Vector3();
3949
-
3950
3667
  for ( let i = 0, il = targets.length; i < il; i ++ ) {
3951
3668
 
3952
3669
  const target = targets[ i ];
3953
-
3954
3670
  if ( target.POSITION !== undefined ) {
3955
3671
 
3956
3672
  const accessor = parser.json.accessors[ target.POSITION ];
3957
3673
  const min = accessor.min;
3958
- const max = accessor.max; // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
3674
+ const max = accessor.max;
3675
+
3676
+ // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
3959
3677
 
3960
3678
  if ( min !== undefined && max !== undefined ) {
3961
3679
 
@@ -3963,18 +3681,17 @@
3963
3681
  vector.setX( Math.max( Math.abs( min[ 0 ] ), Math.abs( max[ 0 ] ) ) );
3964
3682
  vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) );
3965
3683
  vector.setZ( Math.max( Math.abs( min[ 2 ] ), Math.abs( max[ 2 ] ) ) );
3966
-
3967
3684
  if ( accessor.normalized ) {
3968
3685
 
3969
3686
  const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] );
3970
3687
  vector.multiplyScalar( boxScale );
3971
3688
 
3972
- } // Note: this assumes that the sum of all weights is at most 1. This isn't quite correct - it's more conservative
3689
+ }
3690
+
3691
+ // Note: this assumes that the sum of all weights is at most 1. This isn't quite correct - it's more conservative
3973
3692
  // to assume that each target can have a max weight of 1. However, for some use cases - notably, when morph targets
3974
3693
  // are used to implement key-frame animations and as such only two are active at a time - this results in very large
3975
3694
  // boxes. So for now we make a box that's sometimes a touch too small but is hopefully mostly of reasonable size.
3976
-
3977
-
3978
3695
  maxDisplacement.max( vector );
3979
3696
 
3980
3697
  } else {
@@ -3985,9 +3702,9 @@
3985
3702
 
3986
3703
  }
3987
3704
 
3988
- } // As per comment above this box isn't conservative, but has a reasonable size for a very large number of morph targets.
3989
-
3705
+ }
3990
3706
 
3707
+ // As per comment above this box isn't conservative, but has a reasonable size for a very large number of morph targets.
3991
3708
  box.expandByVector( maxDisplacement );
3992
3709
 
3993
3710
  }
@@ -3999,19 +3716,17 @@
3999
3716
  geometry.boundingSphere = sphere;
4000
3717
 
4001
3718
  }
3719
+
4002
3720
  /**
4003
3721
  * @param {BufferGeometry} geometry
4004
3722
  * @param {GLTF.Primitive} primitiveDef
4005
3723
  * @param {GLTFParser} parser
4006
3724
  * @return {Promise<BufferGeometry>}
4007
3725
  */
4008
-
4009
-
4010
3726
  function addPrimitiveAttributes( geometry, primitiveDef, parser ) {
4011
3727
 
4012
3728
  const attributes = primitiveDef.attributes;
4013
3729
  const pending = [];
4014
-
4015
3730
  function assignAttributeAccessor( accessorIndex, attributeName ) {
4016
3731
 
4017
3732
  return parser.getDependency( 'accessor', accessorIndex ).then( function ( accessor ) {
@@ -4024,8 +3739,9 @@
4024
3739
 
4025
3740
  for ( const gltfAttributeName in attributes ) {
4026
3741
 
4027
- const threeAttributeName = ATTRIBUTES[ gltfAttributeName ] || gltfAttributeName.toLowerCase(); // Skip attributes already provided by e.g. Draco extension.
3742
+ const threeAttributeName = ATTRIBUTES[ gltfAttributeName ] || gltfAttributeName.toLowerCase();
4028
3743
 
3744
+ // Skip attributes already provided by e.g. Draco extension.
4029
3745
  if ( threeAttributeName in geometry.attributes ) continue;
4030
3746
  pending.push( assignAttributeAccessor( attributes[ gltfAttributeName ], threeAttributeName ) );
4031
3747
 
@@ -4051,22 +3767,22 @@
4051
3767
  } );
4052
3768
 
4053
3769
  }
3770
+
4054
3771
  /**
4055
3772
  * @param {BufferGeometry} geometry
4056
3773
  * @param {Number} drawMode
4057
3774
  * @return {BufferGeometry}
4058
3775
  */
4059
-
4060
-
4061
3776
  function toTrianglesDrawMode( geometry, drawMode ) {
4062
3777
 
4063
- let index = geometry.getIndex(); // generate index if not present
3778
+ let index = geometry.getIndex();
3779
+
3780
+ // generate index if not present
4064
3781
 
4065
3782
  if ( index === null ) {
4066
3783
 
4067
3784
  const indices = [];
4068
3785
  const position = geometry.getAttribute( 'position' );
4069
-
4070
3786
  if ( position !== undefined ) {
4071
3787
 
4072
3788
  for ( let i = 0; i < position.count; i ++ ) {
@@ -4085,15 +3801,16 @@
4085
3801
 
4086
3802
  }
4087
3803
 
4088
- } //
3804
+ }
4089
3805
 
3806
+ //
4090
3807
 
4091
3808
  const numberOfTriangles = index.count - 2;
4092
3809
  const newIndices = [];
4093
-
4094
3810
  if ( drawMode === THREE.TriangleFanDrawMode ) {
4095
3811
 
4096
3812
  // gl.TRIANGLE_FAN
3813
+
4097
3814
  for ( let i = 1; i <= numberOfTriangles; i ++ ) {
4098
3815
 
4099
3816
  newIndices.push( index.getX( 0 ) );
@@ -4105,6 +3822,7 @@
4105
3822
  } else {
4106
3823
 
4107
3824
  // gl.TRIANGLE_STRIP
3825
+
4108
3826
  for ( let i = 0; i < numberOfTriangles; i ++ ) {
4109
3827
 
4110
3828
  if ( i % 2 === 0 ) {
@@ -4129,8 +3847,9 @@
4129
3847
 
4130
3848
  console.error( 'THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.' );
4131
3849
 
4132
- } // build final geometry
3850
+ }
4133
3851
 
3852
+ // build final geometry
4134
3853
 
4135
3854
  const newGeometry = geometry.clone();
4136
3855
  newGeometry.setIndex( newIndices );