three-stdlib 2.16.0 → 2.16.2

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 (1219) hide show
  1. package/BufferGeometryUtils-1a7a235c.js +655 -0
  2. package/BufferGeometryUtils-971dfde3.js +1 -0
  3. package/Nodes-4f766d71.js +471 -0
  4. package/Nodes-9aa16d74.js +1 -0
  5. package/animation/AnimationClipCreator.cjs.js +1 -0
  6. package/animation/AnimationClipCreator.js +52 -32
  7. package/animation/CCDIKSolver.cjs.js +1 -0
  8. package/animation/CCDIKSolver.js +143 -64
  9. package/animation/MMDAnimationHelper.cjs.js +1 -0
  10. package/animation/MMDAnimationHelper.js +341 -150
  11. package/animation/MMDPhysics.cjs.js +1 -0
  12. package/animation/MMDPhysics.js +361 -154
  13. package/cameras/CinematicCamera.cjs.js +1 -0
  14. package/cameras/CinematicCamera.js +77 -67
  15. package/controls/ArcballControls.cjs.js +1 -0
  16. package/controls/ArcballControls.js +1449 -544
  17. package/controls/DeviceOrientationControls.cjs.js +1 -0
  18. package/controls/DeviceOrientationControls.js +97 -52
  19. package/controls/DragControls.cjs.js +1 -0
  20. package/controls/DragControls.js +187 -85
  21. package/controls/FirstPersonControls.cjs.js +1 -0
  22. package/controls/FirstPersonControls.js +193 -123
  23. package/controls/FlyControls.cjs.js +1 -0
  24. package/controls/FlyControls.d.ts +5 -4
  25. package/controls/FlyControls.js +160 -90
  26. package/controls/OrbitControls.cjs.js +1 -0
  27. package/controls/OrbitControls.js +481 -232
  28. package/controls/PointerLockControls.cjs.js +1 -0
  29. package/controls/PointerLockControls.js +99 -63
  30. package/controls/TrackballControls.cjs.js +1 -0
  31. package/controls/TrackballControls.js +383 -211
  32. package/controls/TransformControls.cjs.js +1 -0
  33. package/controls/TransformControls.js +782 -575
  34. package/controls/experimental/CameraControls.cjs.js +1 -0
  35. package/controls/experimental/CameraControls.js +609 -329
  36. package/csm/CSM.cjs.js +1 -0
  37. package/csm/CSM.js +108 -47
  38. package/csm/CSMFrustum.cjs.js +1 -0
  39. package/csm/CSMFrustum.js +29 -14
  40. package/csm/CSMHelper.cjs.js +1 -0
  41. package/csm/CSMHelper.js +34 -20
  42. package/csm/CSMShader.cjs.js +1 -0
  43. package/csm/CSMShader.js +11 -7
  44. package/curves/CurveExtras.cjs.js +1 -0
  45. package/curves/CurveExtras.js +115 -73
  46. package/curves/NURBSCurve.cjs.js +1 -0
  47. package/curves/NURBSCurve.js +43 -15
  48. package/curves/NURBSSurface.cjs.js +1 -0
  49. package/curves/NURBSSurface.js +27 -11
  50. package/curves/NURBSUtils.cjs.js +1 -0
  51. package/curves/NURBSUtils.js +203 -54
  52. package/custom.d.cjs.js +1 -0
  53. package/{shaders/types.mjs → custom.d.js} +0 -0
  54. package/deprecated/Geometry.cjs.js +1 -0
  55. package/deprecated/Geometry.js +486 -191
  56. package/effects/AnaglyphEffect.cjs.js +1 -0
  57. package/effects/AnaglyphEffect.js +60 -95
  58. package/effects/AsciiEffect.cjs.js +1 -0
  59. package/effects/AsciiEffect.js +110 -80
  60. package/effects/OutlineEffect.cjs.js +1 -0
  61. package/effects/OutlineEffect.js +204 -121
  62. package/effects/ParallaxBarrierEffect.cjs.js +1 -0
  63. package/effects/ParallaxBarrierEffect.js +38 -39
  64. package/effects/PeppersGhostEffect.cjs.js +1 -0
  65. package/effects/PeppersGhostEffect.js +68 -19
  66. package/effects/StereoEffect.cjs.js +1 -0
  67. package/effects/StereoEffect.js +16 -12
  68. package/environments/RoomEnvironment.cjs.js +1 -0
  69. package/environments/RoomEnvironment.js +47 -52
  70. package/exporters/ColladaExporter.cjs.js +1 -0
  71. package/exporters/ColladaExporter.js +241 -115
  72. package/exporters/DRACOExporter.cjs.js +1 -0
  73. package/exporters/DRACOExporter.js +121 -67
  74. package/exporters/GLTFExporter.cjs.js +1 -0
  75. package/exporters/GLTFExporter.js +1014 -463
  76. package/exporters/MMDExporter.cjs.js +1 -0
  77. package/exporters/MMDExporter.js +102 -44
  78. package/exporters/OBJExporter.cjs.js +1 -0
  79. package/exporters/OBJExporter.js +140 -78
  80. package/exporters/PLYExporter.cjs.js +1 -0
  81. package/exporters/PLYExporter.js +154 -93
  82. package/exporters/STLExporter.cjs.js +1 -0
  83. package/exporters/STLExporter.js +81 -30
  84. package/exporters/USDZExporter.cjs.js +1 -0
  85. package/exporters/USDZExporter.js +144 -84
  86. package/geometries/BoxLineGeometry.cjs.js +1 -0
  87. package/geometries/BoxLineGeometry.js +14 -7
  88. package/geometries/ConvexGeometry.cjs.js +1 -0
  89. package/geometries/ConvexGeometry.js +23 -14
  90. package/geometries/DecalGeometry.cjs.js +1 -0
  91. package/geometries/DecalGeometry.js +162 -108
  92. package/geometries/LightningStrike.cjs.js +1 -0
  93. package/geometries/LightningStrike.js +294 -101
  94. package/geometries/ParametricGeometries.cjs.js +1 -0
  95. package/geometries/ParametricGeometries.js +76 -26
  96. package/geometries/ParametricGeometry.cjs.js +1 -0
  97. package/geometries/ParametricGeometry.js +48 -24
  98. package/geometries/RoundedBoxGeometry.cjs.js +1 -0
  99. package/geometries/RoundedBoxGeometry.js +64 -33
  100. package/geometries/TeapotGeometry.cjs.js +1 -0
  101. package/geometries/TeapotGeometry.js +174 -1434
  102. package/geometries/TextGeometry.cjs.js +1 -0
  103. package/geometries/TextGeometry.js +17 -9
  104. package/helpers/LightProbeHelper.cjs.js +1 -0
  105. package/helpers/LightProbeHelper.js +21 -53
  106. package/helpers/PositionalAudioHelper.cjs.js +1 -0
  107. package/helpers/PositionalAudioHelper.js +30 -23
  108. package/helpers/RectAreaLightHelper.cjs.js +1 -0
  109. package/helpers/RectAreaLightHelper.js +33 -17
  110. package/helpers/VertexNormalsHelper.cjs.js +1 -0
  111. package/helpers/VertexNormalsHelper.js +41 -20
  112. package/helpers/VertexTangentsHelper.cjs.js +1 -0
  113. package/helpers/VertexTangentsHelper.js +36 -18
  114. package/index.cjs.js +1 -0
  115. package/index.js +333 -969
  116. package/interactive/InteractiveGroup.cjs.js +1 -0
  117. package/interactive/InteractiveGroup.d.ts +5 -0
  118. package/interactive/InteractiveGroup.js +87 -0
  119. package/interactive/SelectionBox.cjs.js +1 -0
  120. package/interactive/SelectionBox.js +46 -31
  121. package/interactive/SelectionHelper.cjs.js +1 -0
  122. package/interactive/SelectionHelper.js +21 -16
  123. package/libs/MeshoptDecoder.cjs.js +1 -0
  124. package/libs/MeshoptDecoder.js +58 -147
  125. package/libs/MotionControllers.cjs.js +1 -0
  126. package/libs/MotionControllers.js +208 -66
  127. package/lights/LightProbeGenerator.cjs.js +1 -0
  128. package/lights/LightProbeGenerator.js +96 -40
  129. package/lights/RectAreaLightUniformsLib.cjs.js +1 -0
  130. package/lights/RectAreaLightUniformsLib.js +9 -32842
  131. package/lines/Line2.cjs.js +1 -0
  132. package/lines/Line2.js +12 -9
  133. package/lines/LineGeometry.cjs.js +1 -0
  134. package/lines/LineGeometry.js +19 -7
  135. package/lines/LineMaterial.cjs.js +1 -0
  136. package/lines/LineMaterial.js +89 -51
  137. package/lines/LineSegments2.cjs.js +1 -0
  138. package/lines/LineSegments2.js +165 -56
  139. package/lines/LineSegmentsGeometry.cjs.js +1 -0
  140. package/lines/LineSegmentsGeometry.js +71 -29
  141. package/lines/Wireframe.cjs.js +1 -0
  142. package/lines/Wireframe.js +29 -15
  143. package/lines/WireframeGeometry2.cjs.js +1 -0
  144. package/lines/WireframeGeometry2.js +9 -8
  145. package/loaders/3DMLoader.cjs.js +1 -0
  146. package/loaders/3DMLoader.js +469 -234
  147. package/loaders/3MFLoader.cjs.js +1 -0
  148. package/loaders/3MFLoader.js +555 -340
  149. package/loaders/AMFLoader.cjs.js +1 -0
  150. package/loaders/AMFLoader.js +219 -114
  151. package/loaders/AssimpLoader.cjs.js +1 -0
  152. package/loaders/AssimpLoader.js +725 -328
  153. package/loaders/BVHLoader.cjs.js +1 -0
  154. package/loaders/BVHLoader.js +200 -94
  155. package/loaders/BasisTextureLoader.cjs.js +1 -0
  156. package/loaders/BasisTextureLoader.js +357 -229
  157. package/loaders/ColladaLoader.cjs.js +1 -0
  158. package/loaders/ColladaLoader.js +1522 -932
  159. package/loaders/DDSLoader.cjs.js +1 -0
  160. package/loaders/DDSLoader.js +108 -42
  161. package/loaders/DRACOLoader.cjs.js +1 -0
  162. package/loaders/DRACOLoader.js +210 -103
  163. package/loaders/EXRLoader.cjs.js +1 -0
  164. package/loaders/EXRLoader.js +809 -461
  165. package/loaders/FBXLoader.cjs.js +1 -0
  166. package/loaders/FBXLoader.js +1397 -842
  167. package/loaders/FontLoader.cjs.js +1 -0
  168. package/loaders/FontLoader.js +66 -33
  169. package/loaders/GCodeLoader.cjs.js +1 -0
  170. package/loaders/GCodeLoader.js +111 -63
  171. package/loaders/GLTFLoader.cjs.js +1 -0
  172. package/loaders/GLTFLoader.js +1484 -771
  173. package/loaders/HDRCubeTextureLoader.cjs.js +1 -0
  174. package/loaders/HDRCubeTextureLoader.js +50 -45
  175. package/loaders/KMZLoader.cjs.js +1 -0
  176. package/loaders/KMZLoader.js +55 -42
  177. package/loaders/KTX2Loader.cjs.js +1 -0
  178. package/loaders/KTX2Loader.js +362 -229
  179. package/loaders/KTXLoader.cjs.js +1 -0
  180. package/loaders/KTXLoader.js +99 -37
  181. package/loaders/LDrawLoader.cjs.js +1 -0
  182. package/loaders/LDrawLoader.js +746 -313
  183. package/loaders/LUT3dlLoader.cjs.js +1 -0
  184. package/loaders/LUT3dlLoader.js +62 -50
  185. package/loaders/LUTCubeLoader.cjs.js +1 -0
  186. package/loaders/LUTCubeLoader.js +56 -45
  187. package/loaders/LWOLoader.cjs.js +1 -0
  188. package/loaders/LWOLoader.js +339 -227
  189. package/loaders/LottieLoader.cjs.js +1 -0
  190. package/loaders/LottieLoader.js +38 -36
  191. package/loaders/MD2Loader.cjs.js +1 -0
  192. package/loaders/MD2Loader.js +91 -248
  193. package/loaders/MDDLoader.cjs.js +1 -0
  194. package/loaders/MDDLoader.js +45 -25
  195. package/loaders/MMDLoader.cjs.js +1 -0
  196. package/loaders/MMDLoader.js +795 -359
  197. package/loaders/MTLLoader.cjs.js +1 -0
  198. package/loaders/MTLLoader.js +201 -91
  199. package/loaders/NRRDLoader.cjs.js +1 -0
  200. package/loaders/NRRDLoader.js +263 -182
  201. package/loaders/NodeMaterialLoader.cjs.js +1 -0
  202. package/loaders/NodeMaterialLoader.js +14 -121
  203. package/loaders/OBJLoader.cjs.js +1 -0
  204. package/loaders/OBJLoader.js +283 -161
  205. package/loaders/PCDLoader.cjs.js +1 -0
  206. package/loaders/PCDLoader.js +164 -145
  207. package/loaders/PDBLoader.cjs.js +1 -0
  208. package/loaders/PDBLoader.js +63 -45
  209. package/loaders/PLYLoader.cjs.js +1 -0
  210. package/loaders/PLYLoader.js +203 -106
  211. package/loaders/PRWMLoader.cjs.js +1 -0
  212. package/loaders/PRWMLoader.js +110 -73
  213. package/loaders/PVRLoader.cjs.js +1 -0
  214. package/loaders/PVRLoader.js +93 -32
  215. package/loaders/RGBELoader.cjs.js +1 -0
  216. package/loaders/RGBELoader.js +233 -96
  217. package/loaders/RGBMLoader.cjs.js +1 -0
  218. package/loaders/RGBMLoader.js +514 -344
  219. package/loaders/STLLoader.cjs.js +1 -0
  220. package/loaders/STLLoader.js +165 -59
  221. package/loaders/SVGLoader.cjs.js +1 -0
  222. package/loaders/SVGLoader.js +851 -481
  223. package/loaders/TDSLoader.cjs.js +1 -0
  224. package/loaders/TDSLoader.js +527 -137
  225. package/loaders/TGALoader.cjs.js +1 -0
  226. package/loaders/TGALoader.js +205 -94
  227. package/loaders/TTFLoader.cjs.js +1 -0
  228. package/loaders/TTFLoader.js +79 -58
  229. package/loaders/TiltLoader.cjs.js +1 -0
  230. package/loaders/TiltLoader.js +167 -129
  231. package/loaders/VOXLoader.cjs.js +1 -0
  232. package/loaders/VOXLoader.js +84 -320
  233. package/loaders/VRMLLoader.cjs.js +1 -0
  234. package/loaders/VRMLLoader.js +1268 -786
  235. package/loaders/VRMLoader.cjs.js +1 -0
  236. package/loaders/VRMLoader.js +31 -23
  237. package/loaders/VTKLoader.cjs.js +1 -0
  238. package/loaders/VTKLoader.js +407 -219
  239. package/loaders/XLoader.cjs.js +1 -0
  240. package/loaders/XLoader.js +1259 -1083
  241. package/loaders/XYZLoader.cjs.js +1 -0
  242. package/loaders/XYZLoader.js +34 -28
  243. package/loaders/lwo/IFFParser.cjs.js +1 -0
  244. package/loaders/lwo/IFFParser.js +492 -238
  245. package/loaders/lwo/LWO2Parser.cjs.js +1 -0
  246. package/loaders/lwo/LWO2Parser.js +279 -176
  247. package/loaders/lwo/LWO3Parser.cjs.js +1 -0
  248. package/loaders/lwo/LWO3Parser.js +247 -160
  249. package/math/Capsule.cjs.js +1 -0
  250. package/math/Capsule.js +43 -56
  251. package/math/ColorConverter.cjs.js +1 -0
  252. package/math/ColorConverter.js +32 -18
  253. package/math/ConvexHull.cjs.js +1 -0
  254. package/math/ConvexHull.js +357 -97
  255. package/math/ImprovedNoise.cjs.js +1 -0
  256. package/math/ImprovedNoise.js +32 -282
  257. package/math/Lut.cjs.js +1 -0
  258. package/math/Lut.js +35 -51
  259. package/math/MeshSurfaceSampler.cjs.js +1 -0
  260. package/math/MeshSurfaceSampler.js +68 -25
  261. package/math/OBB.cjs.js +1 -0
  262. package/math/OBB.js +152 -91
  263. package/math/Octree.cjs.js +1 -0
  264. package/math/Octree.js +139 -76
  265. package/math/SimplexNoise.cjs.js +1 -0
  266. package/math/SimplexNoise.js +238 -217
  267. package/misc/ConvexObjectBreaker.cjs.js +1 -0
  268. package/misc/ConvexObjectBreaker.js +185 -79
  269. package/misc/GPUComputationRenderer.cjs.js +1 -0
  270. package/misc/GPUComputationRenderer.js +194 -69
  271. package/misc/Gyroscope.cjs.js +1 -0
  272. package/misc/Gyroscope.js +22 -16
  273. package/misc/MD2Character.cjs.js +1 -0
  274. package/misc/MD2Character.js +74 -52
  275. package/misc/MD2CharacterComplex.cjs.js +1 -0
  276. package/misc/MD2CharacterComplex.js +163 -112
  277. package/misc/MorphAnimMesh.cjs.js +1 -0
  278. package/misc/MorphAnimMesh.js +28 -20
  279. package/misc/MorphBlendMesh.cjs.js +1 -0
  280. package/misc/MorphBlendMesh.js +69 -45
  281. package/misc/ProgressiveLightmap.cjs.js +1 -0
  282. package/misc/ProgressiveLightmap.js +187 -70
  283. package/misc/RollerCoaster.cjs.js +1 -0
  284. package/misc/RollerCoaster.js +135 -106
  285. package/misc/TubePainter.cjs.js +1 -0
  286. package/misc/TubePainter.js +92 -74
  287. package/misc/Volume.cjs.js +1 -0
  288. package/misc/Volume.js +270 -108
  289. package/misc/VolumeSlice.cjs.js +1 -0
  290. package/misc/VolumeSlice.js +122 -34
  291. package/misc/WebGL.cjs.js +1 -0
  292. package/misc/WebGL.js +34 -37
  293. package/modifiers/CurveModifier.cjs.js +1 -0
  294. package/modifiers/CurveModifier.js +151 -46
  295. package/modifiers/EdgeSplitModifier.cjs.js +1 -0
  296. package/modifiers/EdgeSplitModifier.js +90 -46
  297. package/modifiers/SimplifyModifier.cjs.js +1 -0
  298. package/modifiers/SimplifyModifier.js +202 -77
  299. package/modifiers/TessellateModifier.cjs.js +1 -0
  300. package/modifiers/TessellateModifier.js +90 -65
  301. package/nodes/Nodes.cjs.js +1 -0
  302. package/nodes/Nodes.js +140 -274
  303. package/nodes/ShaderNode.cjs.js +1 -0
  304. package/nodes/ShaderNode.js +196 -296
  305. package/nodes/accessors/BufferNode.cjs.js +1 -0
  306. package/nodes/accessors/BufferNode.js +8 -4
  307. package/nodes/accessors/CameraNode.cjs.js +1 -0
  308. package/nodes/accessors/CameraNode.js +25 -20
  309. package/nodes/accessors/CubeTextureNode.cjs.js +1 -0
  310. package/nodes/accessors/CubeTextureNode.js +26 -14
  311. package/nodes/accessors/MaterialNode.cjs.js +1 -0
  312. package/nodes/accessors/MaterialNode.js +53 -43
  313. package/nodes/accessors/MaterialReferenceNode.cjs.js +1 -0
  314. package/nodes/accessors/MaterialReferenceNode.js +6 -3
  315. package/nodes/accessors/ModelNode.cjs.js +1 -0
  316. package/nodes/accessors/ModelNode.js +5 -3
  317. package/nodes/accessors/ModelViewProjectionNode.cjs.js +1 -0
  318. package/nodes/accessors/ModelViewProjectionNode.js +13 -14
  319. package/nodes/accessors/NormalNode.cjs.js +1 -0
  320. package/nodes/accessors/NormalNode.js +39 -40
  321. package/nodes/accessors/Object3DNode.cjs.js +1 -0
  322. package/nodes/accessors/Object3DNode.js +50 -40
  323. package/nodes/accessors/PointUVNode.cjs.js +1 -0
  324. package/nodes/accessors/PointUVNode.js +9 -5
  325. package/nodes/accessors/PositionNode.cjs.js +1 -0
  326. package/nodes/accessors/PositionNode.js +41 -42
  327. package/nodes/accessors/ReferenceNode.cjs.js +1 -0
  328. package/nodes/accessors/ReferenceNode.js +17 -10
  329. package/nodes/accessors/ReflectNode.cjs.js +1 -0
  330. package/nodes/accessors/ReflectNode.js +26 -23
  331. package/nodes/accessors/SkinningNode.cjs.js +1 -0
  332. package/nodes/accessors/SkinningNode.js +48 -46
  333. package/nodes/accessors/TextureNode.cjs.js +1 -0
  334. package/nodes/accessors/TextureNode.js +29 -14
  335. package/nodes/accessors/UVNode.cjs.js +1 -0
  336. package/nodes/accessors/UVNode.js +11 -5
  337. package/nodes/core/ArrayUniformNode.cjs.js +1 -0
  338. package/nodes/core/ArrayUniformNode.js +7 -3
  339. package/nodes/core/AttributeNode.cjs.js +1 -0
  340. package/nodes/core/AttributeNode.js +12 -5
  341. package/nodes/core/BypassNode.cjs.js +1 -0
  342. package/nodes/core/BypassNode.js +12 -5
  343. package/nodes/core/CodeNode.cjs.js +1 -0
  344. package/nodes/core/CodeNode.js +12 -4
  345. package/nodes/core/ConstNode.cjs.js +1 -0
  346. package/nodes/core/ConstNode.js +7 -3
  347. package/nodes/core/ContextNode.cjs.js +1 -0
  348. package/nodes/core/ContextNode.js +8 -3
  349. package/nodes/core/ExpressionNode.cjs.js +1 -0
  350. package/nodes/core/ExpressionNode.js +9 -5
  351. package/nodes/core/FunctionCallNode.cjs.js +1 -0
  352. package/nodes/core/FunctionCallNode.js +15 -6
  353. package/nodes/core/FunctionNode.cjs.js +1 -0
  354. package/nodes/core/FunctionNode.js +25 -10
  355. package/nodes/core/InputNode.cjs.js +1 -0
  356. package/nodes/core/InputNode.js +23 -12
  357. package/nodes/core/Node.cjs.js +1 -0
  358. package/nodes/core/Node.js +75 -35
  359. package/nodes/core/NodeAttribute.cjs.js +1 -0
  360. package/nodes/core/NodeAttribute.js +4 -2
  361. package/nodes/core/NodeBuilder.cjs.js +1 -0
  362. package/nodes/core/NodeBuilder.js +224 -110
  363. package/nodes/core/NodeCode.cjs.js +1 -0
  364. package/nodes/core/NodeCode.js +7 -4
  365. package/nodes/core/NodeFrame.cjs.js +1 -0
  366. package/nodes/core/NodeFrame.js +12 -9
  367. package/nodes/core/NodeFunction.cjs.js +1 -0
  368. package/nodes/core/NodeFunction.js +17 -0
  369. package/nodes/core/NodeFunctionInput.cjs.js +1 -0
  370. package/nodes/core/NodeFunctionInput.js +5 -3
  371. package/nodes/core/NodeKeywords.cjs.js +1 -0
  372. package/nodes/core/NodeKeywords.js +16 -5
  373. package/nodes/core/NodeParser.cjs.js +1 -0
  374. package/nodes/core/NodeParser.js +8 -0
  375. package/nodes/core/NodeUniform.cjs.js +1 -0
  376. package/nodes/core/NodeUniform.js +7 -3
  377. package/nodes/core/NodeUtils.cjs.js +1 -0
  378. package/nodes/core/NodeUtils.js +43 -39
  379. package/nodes/core/NodeVar.cjs.js +1 -0
  380. package/nodes/core/NodeVar.js +4 -2
  381. package/nodes/core/NodeVary.cjs.js +1 -0
  382. package/nodes/core/NodeVary.js +4 -2
  383. package/nodes/core/PropertyNode.cjs.js +1 -0
  384. package/nodes/core/PropertyNode.js +10 -4
  385. package/nodes/core/TempNode.cjs.js +1 -0
  386. package/nodes/core/TempNode.js +11 -5
  387. package/nodes/core/UniformNode.cjs.js +1 -0
  388. package/nodes/core/UniformNode.js +10 -4
  389. package/nodes/core/VarNode.cjs.js +1 -0
  390. package/nodes/core/VarNode.js +11 -3
  391. package/nodes/core/VaryNode.cjs.js +1 -0
  392. package/nodes/core/VaryNode.js +15 -6
  393. package/nodes/core/constants.cjs.js +1 -0
  394. package/nodes/core/constants.js +7 -20
  395. package/nodes/display/ColorSpaceNode.cjs.js +1 -0
  396. package/nodes/display/ColorSpaceNode.js +38 -34
  397. package/nodes/display/NormalMapNode.cjs.js +1 -0
  398. package/nodes/display/NormalMapNode.js +53 -35
  399. package/nodes/fog/FogNode.cjs.js +1 -0
  400. package/nodes/fog/FogNode.js +9 -5
  401. package/nodes/fog/FogRangeNode.cjs.js +1 -0
  402. package/nodes/fog/FogRangeNode.js +9 -5
  403. package/nodes/functions/BSDFs.cjs.js +1 -0
  404. package/nodes/functions/BSDFs.js +118 -61
  405. package/nodes/functions/PhysicalMaterialFunctions.cjs.js +1 -0
  406. package/nodes/functions/PhysicalMaterialFunctions.js +57 -0
  407. package/nodes/lights/LightContextNode.cjs.js +1 -0
  408. package/nodes/lights/LightContextNode.js +23 -14
  409. package/nodes/lights/LightNode.cjs.js +1 -0
  410. package/nodes/lights/LightNode.js +31 -27
  411. package/nodes/lights/LightsNode.cjs.js +1 -0
  412. package/nodes/lights/LightsNode.js +28 -9
  413. package/nodes/loaders/NodeLoader.cjs.js +1 -0
  414. package/nodes/loaders/NodeLoader.js +42 -27
  415. package/nodes/loaders/NodeMaterialLoader.cjs.js +1 -0
  416. package/nodes/loaders/NodeMaterialLoader.js +10 -4
  417. package/nodes/loaders/NodeObjectLoader.cjs.js +1 -0
  418. package/nodes/loaders/NodeObjectLoader.js +19 -9
  419. package/nodes/materials/LineBasicNodeMaterial.cjs.js +1 -0
  420. package/nodes/materials/LineBasicNodeMaterial.js +10 -5
  421. package/nodes/materials/Materials.cjs.js +1 -0
  422. package/nodes/materials/Materials.js +17 -14
  423. package/nodes/materials/MeshBasicNodeMaterial.cjs.js +1 -0
  424. package/nodes/materials/MeshBasicNodeMaterial.js +10 -5
  425. package/nodes/materials/MeshStandardNodeMaterial.cjs.js +1 -0
  426. package/nodes/materials/MeshStandardNodeMaterial.js +8 -5
  427. package/nodes/materials/NodeMaterial.cjs.js +1 -0
  428. package/nodes/materials/NodeMaterial.js +36 -20
  429. package/nodes/materials/PointsNodeMaterial.cjs.js +1 -0
  430. package/nodes/materials/PointsNodeMaterial.js +10 -5
  431. package/nodes/math/CondNode.cjs.js +1 -0
  432. package/nodes/math/CondNode.js +23 -11
  433. package/nodes/math/MathNode.cjs.js +1 -0
  434. package/nodes/math/MathNode.js +142 -98
  435. package/nodes/math/OperatorNode.cjs.js +1 -0
  436. package/nodes/math/OperatorNode.js +46 -24
  437. package/nodes/parsers/GLSLNodeFunction.cjs.js +1 -0
  438. package/nodes/parsers/GLSLNodeFunction.js +101 -0
  439. package/nodes/parsers/GLSLNodeParser.cjs.js +1 -0
  440. package/nodes/parsers/GLSLNodeParser.js +13 -0
  441. package/nodes/parsers/WGSLNodeFunction.cjs.js +1 -0
  442. package/nodes/parsers/WGSLNodeFunction.js +71 -0
  443. package/nodes/parsers/WGSLNodeParser.cjs.js +1 -0
  444. package/nodes/parsers/WGSLNodeParser.js +13 -0
  445. package/nodes/procedural/CheckerNode.cjs.js +1 -0
  446. package/nodes/procedural/CheckerNode.js +19 -13
  447. package/nodes/utils/ArrayElementNode.cjs.js +1 -0
  448. package/nodes/utils/ArrayElementNode.js +8 -4
  449. package/nodes/utils/ConvertNode.cjs.js +1 -0
  450. package/nodes/utils/ConvertNode.js +8 -3
  451. package/nodes/utils/JoinNode.cjs.js +1 -0
  452. package/nodes/utils/JoinNode.js +11 -7
  453. package/nodes/utils/MatcapUVNode.cjs.js +1 -0
  454. package/nodes/utils/MatcapUVNode.js +11 -8
  455. package/nodes/utils/OscNode.cjs.js +1 -0
  456. package/nodes/utils/OscNode.js +33 -27
  457. package/nodes/utils/SplitNode.cjs.js +1 -0
  458. package/nodes/utils/SplitNode.js +20 -6
  459. package/nodes/utils/SpriteSheetUVNode.cjs.js +1 -0
  460. package/nodes/utils/SpriteSheetUVNode.js +23 -23
  461. package/nodes/utils/TimerNode.cjs.js +1 -0
  462. package/nodes/utils/TimerNode.js +24 -20
  463. package/objects/GroundProjectedEnv.cjs.js +1 -0
  464. package/objects/GroundProjectedEnv.js +37 -22
  465. package/objects/Lensflare.cjs.js +1 -0
  466. package/objects/Lensflare.js +156 -86
  467. package/objects/LightningStorm.cjs.js +1 -0
  468. package/objects/LightningStorm.js +102 -38
  469. package/objects/MarchingCubes.cjs.js +1 -0
  470. package/objects/MarchingCubes.js +303 -150
  471. package/objects/Reflector.cjs.js +1 -0
  472. package/objects/Reflector.js +72 -50
  473. package/objects/ReflectorForSSRPass.cjs.js +1 -0
  474. package/objects/ReflectorForSSRPass.js +131 -80
  475. package/objects/ReflectorRTT.cjs.js +1 -0
  476. package/objects/ReflectorRTT.js +7 -6
  477. package/objects/Refractor.cjs.js +1 -0
  478. package/objects/Refractor.js +106 -64
  479. package/objects/ShadowMesh.cjs.js +1 -0
  480. package/objects/ShadowMesh.js +17 -8
  481. package/objects/Sky.cjs.js +1 -0
  482. package/objects/Sky.js +80 -119
  483. package/objects/Water.cjs.js +1 -0
  484. package/objects/Water.js +127 -83
  485. package/objects/Water2.cjs.js +1 -0
  486. package/objects/Water2.js +108 -72
  487. package/offscreen/jank.cjs.js +1 -0
  488. package/offscreen/jank.js +14 -10
  489. package/offscreen/offscreen.cjs.js +1 -0
  490. package/offscreen/offscreen.js +5 -4
  491. package/offscreen/scene.cjs.js +1 -0
  492. package/offscreen/scene.js +48 -45
  493. package/package.json +3 -3
  494. package/physics/AmmoPhysics.cjs.js +1 -0
  495. package/physics/AmmoPhysics.js +71 -30
  496. package/postprocessing/AdaptiveToneMappingPass.cjs.js +1 -0
  497. package/postprocessing/AdaptiveToneMappingPass.js +123 -97
  498. package/postprocessing/AfterimagePass.cjs.js +1 -0
  499. package/postprocessing/AfterimagePass.js +49 -28
  500. package/postprocessing/BloomPass.cjs.js +1 -0
  501. package/postprocessing/BloomPass.js +69 -43
  502. package/postprocessing/BokehPass.cjs.js +1 -0
  503. package/postprocessing/BokehPass.js +69 -39
  504. package/postprocessing/ClearPass.cjs.js +1 -0
  505. package/postprocessing/ClearPass.js +25 -10
  506. package/postprocessing/CubeTexturePass.cjs.js +1 -0
  507. package/postprocessing/CubeTexturePass.js +27 -28
  508. package/postprocessing/DotScreenPass.cjs.js +1 -0
  509. package/postprocessing/DotScreenPass.js +32 -24
  510. package/postprocessing/EffectComposer.cjs.js +1 -0
  511. package/postprocessing/EffectComposer.js +86 -39
  512. package/postprocessing/FilmPass.cjs.js +1 -0
  513. package/postprocessing/FilmPass.js +30 -25
  514. package/postprocessing/GlitchPass.cjs.js +1 -0
  515. package/postprocessing/GlitchPass.js +61 -38
  516. package/postprocessing/HalftonePass.cjs.js +1 -0
  517. package/postprocessing/HalftonePass.js +39 -19
  518. package/postprocessing/LUTPass.cjs.js +1 -0
  519. package/postprocessing/LUTPass.js +38 -13
  520. package/postprocessing/MaskPass.cjs.js +1 -0
  521. package/postprocessing/MaskPass.js +38 -19
  522. package/postprocessing/OutlinePass.cjs.js +1 -0
  523. package/postprocessing/OutlinePass.js +277 -135
  524. package/postprocessing/Pass.cjs.js +1 -0
  525. package/postprocessing/Pass.js +44 -20
  526. package/postprocessing/RenderPass.cjs.js +1 -0
  527. package/postprocessing/RenderPass.js +36 -13
  528. package/postprocessing/RenderPixelatedPass.cjs.js +1 -0
  529. package/postprocessing/RenderPixelatedPass.js +58 -44
  530. package/postprocessing/SAOPass.cjs.js +1 -0
  531. package/postprocessing/SAOPass.js +189 -154
  532. package/postprocessing/SMAAPass.cjs.js +1 -0
  533. package/postprocessing/SMAAPass.js +84 -64
  534. package/postprocessing/SSAARenderPass.cjs.js +1 -0
  535. package/postprocessing/SSAARenderPass.js +69 -121
  536. package/postprocessing/SSAOPass.cjs.js +1 -0
  537. package/postprocessing/SSAOPass.js +172 -123
  538. package/postprocessing/SSRPass.cjs.js +1 -0
  539. package/postprocessing/SSRPass.js +280 -211
  540. package/postprocessing/SavePass.cjs.js +1 -0
  541. package/postprocessing/SavePass.js +25 -20
  542. package/postprocessing/ShaderPass.cjs.js +1 -0
  543. package/postprocessing/ShaderPass.js +30 -14
  544. package/postprocessing/TAARenderPass.cjs.js +1 -0
  545. package/postprocessing/TAARenderPass.js +61 -42
  546. package/postprocessing/TexturePass.cjs.js +1 -0
  547. package/postprocessing/TexturePass.js +22 -21
  548. package/postprocessing/UnrealBloomPass.cjs.js +1 -0
  549. package/postprocessing/UnrealBloomPass.js +213 -105
  550. package/renderers/CSS2DRenderer.cjs.js +1 -0
  551. package/renderers/CSS2DRenderer.js +56 -44
  552. package/renderers/CSS3DRenderer.cjs.js +1 -0
  553. package/renderers/CSS3DRenderer.js +86 -53
  554. package/renderers/Projector.cjs.js +1 -0
  555. package/renderers/Projector.js +274 -107
  556. package/renderers/SVGRenderer.cjs.js +1 -0
  557. package/renderers/SVGRenderer.js +182 -72
  558. package/renderers/nodes/accessors/CameraNode.cjs.js +1 -0
  559. package/renderers/nodes/accessors/CameraNode.js +40 -29
  560. package/renderers/nodes/accessors/ModelNode.cjs.js +1 -0
  561. package/renderers/nodes/accessors/ModelNode.js +37 -28
  562. package/renderers/nodes/accessors/ModelViewProjectionNode.cjs.js +1 -0
  563. package/renderers/nodes/accessors/ModelViewProjectionNode.js +23 -10
  564. package/renderers/nodes/accessors/NormalNode.cjs.js +1 -0
  565. package/renderers/nodes/accessors/NormalNode.js +45 -35
  566. package/renderers/nodes/accessors/PositionNode.cjs.js +1 -0
  567. package/renderers/nodes/accessors/PositionNode.js +19 -18
  568. package/renderers/nodes/accessors/UVNode.cjs.js +1 -0
  569. package/renderers/nodes/accessors/UVNode.js +10 -5
  570. package/renderers/nodes/core/AttributeNode.cjs.js +1 -0
  571. package/renderers/nodes/core/AttributeNode.js +14 -5
  572. package/renderers/nodes/core/InputNode.cjs.js +1 -0
  573. package/renderers/nodes/core/InputNode.js +14 -4
  574. package/renderers/nodes/core/Node.cjs.js +1 -0
  575. package/renderers/nodes/core/Node.js +17 -7
  576. package/renderers/nodes/core/NodeAttribute.cjs.js +1 -0
  577. package/renderers/nodes/core/NodeAttribute.js +6 -3
  578. package/renderers/nodes/core/NodeBuilder.cjs.js +1 -0
  579. package/renderers/nodes/core/NodeBuilder.js +154 -87
  580. package/renderers/nodes/core/NodeFrame.cjs.js +1 -0
  581. package/renderers/nodes/core/NodeFrame.js +12 -9
  582. package/renderers/nodes/core/NodeSlot.cjs.js +1 -0
  583. package/renderers/nodes/core/NodeSlot.js +3 -2
  584. package/renderers/nodes/core/NodeUniform.cjs.js +1 -0
  585. package/renderers/nodes/core/NodeUniform.js +9 -4
  586. package/renderers/nodes/core/NodeVary.cjs.js +1 -0
  587. package/renderers/nodes/core/NodeVary.js +7 -4
  588. package/renderers/nodes/core/VaryNode.cjs.js +1 -0
  589. package/renderers/nodes/core/VaryNode.js +12 -6
  590. package/renderers/nodes/core/constants.cjs.js +1 -0
  591. package/renderers/nodes/core/constants.js +13 -16
  592. package/renderers/nodes/inputs/ColorNode.cjs.js +1 -0
  593. package/renderers/nodes/inputs/ColorNode.js +11 -5
  594. package/renderers/nodes/inputs/FloatNode.cjs.js +1 -0
  595. package/renderers/nodes/inputs/FloatNode.js +11 -5
  596. package/renderers/nodes/inputs/Matrix3Node.cjs.js +1 -0
  597. package/renderers/nodes/inputs/Matrix3Node.js +13 -7
  598. package/renderers/nodes/inputs/Matrix4Node.cjs.js +1 -0
  599. package/renderers/nodes/inputs/Matrix4Node.js +13 -7
  600. package/renderers/nodes/inputs/TextureNode.cjs.js +1 -0
  601. package/renderers/nodes/inputs/TextureNode.js +15 -7
  602. package/renderers/nodes/inputs/Vector2Node.cjs.js +1 -0
  603. package/renderers/nodes/inputs/Vector2Node.js +11 -5
  604. package/renderers/nodes/inputs/Vector3Node.cjs.js +1 -0
  605. package/renderers/nodes/inputs/Vector3Node.js +13 -7
  606. package/renderers/nodes/inputs/Vector4Node.cjs.js +1 -0
  607. package/renderers/nodes/inputs/Vector4Node.js +13 -7
  608. package/renderers/nodes/math/MathNode.cjs.js +1 -0
  609. package/renderers/nodes/math/MathNode.js +30 -20
  610. package/renderers/nodes/math/OperatorNode.cjs.js +1 -0
  611. package/renderers/nodes/math/OperatorNode.js +20 -4
  612. package/renderers/nodes/utils/SwitchNode.cjs.js +1 -0
  613. package/renderers/nodes/utils/SwitchNode.js +9 -4
  614. package/renderers/nodes/utils/TimerNode.cjs.js +1 -0
  615. package/renderers/nodes/utils/TimerNode.js +10 -5
  616. package/renderers/webgpu/WebGPU.cjs.js +1 -0
  617. package/renderers/webgpu/WebGPU.js +16 -14
  618. package/renderers/webgpu/WebGPUAttributes.cjs.js +1 -0
  619. package/renderers/webgpu/WebGPUAttributes.js +23 -16
  620. package/renderers/webgpu/WebGPUBackground.cjs.js +1 -0
  621. package/renderers/webgpu/WebGPUBackground.js +30 -13
  622. package/renderers/webgpu/WebGPUBinding.cjs.js +1 -0
  623. package/renderers/webgpu/WebGPUBinding.js +7 -4
  624. package/renderers/webgpu/WebGPUBindings.cjs.js +1 -0
  625. package/renderers/webgpu/WebGPUBindings.js +57 -21
  626. package/renderers/webgpu/WebGPUComputePipelines.cjs.js +1 -0
  627. package/renderers/webgpu/WebGPUComputePipelines.js +25 -14
  628. package/renderers/webgpu/WebGPUGeometries.cjs.js +1 -0
  629. package/renderers/webgpu/WebGPUGeometries.js +15 -5
  630. package/renderers/webgpu/WebGPUInfo.cjs.js +1 -0
  631. package/renderers/webgpu/WebGPUInfo.js +8 -3
  632. package/renderers/webgpu/WebGPUObjects.cjs.js +1 -0
  633. package/renderers/webgpu/WebGPUObjects.js +10 -5
  634. package/renderers/webgpu/WebGPUProperties.cjs.js +1 -0
  635. package/renderers/webgpu/WebGPUProperties.js +11 -5
  636. package/renderers/webgpu/WebGPURenderLists.cjs.js +1 -0
  637. package/renderers/webgpu/WebGPURenderLists.js +36 -20
  638. package/renderers/webgpu/WebGPURenderPipelines.cjs.js +1 -0
  639. package/renderers/webgpu/WebGPURenderPipelines.js +387 -260
  640. package/renderers/webgpu/WebGPURenderer.cjs.js +1 -0
  641. package/renderers/webgpu/WebGPURenderer.js +262 -124
  642. package/renderers/webgpu/WebGPUSampledTexture.cjs.js +1 -0
  643. package/renderers/webgpu/WebGPUSampledTexture.js +31 -18
  644. package/renderers/webgpu/WebGPUSampler.cjs.js +1 -0
  645. package/renderers/webgpu/WebGPUSampler.js +12 -7
  646. package/renderers/webgpu/WebGPUStorageBuffer.cjs.js +1 -0
  647. package/renderers/webgpu/WebGPUStorageBuffer.js +12 -7
  648. package/renderers/webgpu/WebGPUTextureRenderer.cjs.js +1 -0
  649. package/renderers/webgpu/WebGPUTextureRenderer.js +11 -5
  650. package/renderers/webgpu/WebGPUTextureUtils.cjs.js +1 -0
  651. package/renderers/webgpu/WebGPUTextureUtils.js +40 -29
  652. package/renderers/webgpu/WebGPUTextures.cjs.js +1 -0
  653. package/renderers/webgpu/WebGPUTextures.js +333 -186
  654. package/renderers/webgpu/WebGPUUniform.cjs.js +1 -0
  655. package/renderers/webgpu/WebGPUUniform.js +51 -25
  656. package/renderers/webgpu/WebGPUUniformsGroup.cjs.js +1 -0
  657. package/renderers/webgpu/WebGPUUniformsGroup.js +72 -32
  658. package/renderers/webgpu/constants.cjs.js +1 -0
  659. package/renderers/webgpu/constants.js +181 -190
  660. package/renderers/webgpu/nodes/ShaderLib.cjs.js +1 -0
  661. package/renderers/webgpu/nodes/ShaderLib.js +2 -2
  662. package/renderers/webgpu/nodes/WebGPUNodeBuilder.cjs.js +1 -0
  663. package/renderers/webgpu/nodes/WebGPUNodeBuilder.js +124 -53
  664. package/renderers/webgpu/nodes/WebGPUNodeUniform.cjs.js +1 -0
  665. package/renderers/webgpu/nodes/WebGPUNodeUniform.js +31 -17
  666. package/renderers/webgpu/nodes/WebGPUNodeUniformsGroup.cjs.js +1 -0
  667. package/renderers/webgpu/nodes/WebGPUNodeUniformsGroup.js +9 -8
  668. package/renderers/webgpu/nodes/WebGPUNodes.cjs.js +1 -0
  669. package/renderers/webgpu/nodes/WebGPUNodes.js +45 -7
  670. package/shaders/ACESFilmicToneMappingShader.cjs.js +1 -0
  671. package/shaders/ACESFilmicToneMappingShader.js +24 -44
  672. package/shaders/AfterimageShader.cjs.js +1 -0
  673. package/shaders/AfterimageShader.js +18 -28
  674. package/shaders/BasicShader.cjs.js +1 -0
  675. package/shaders/BasicShader.js +7 -9
  676. package/shaders/BleachBypassShader.cjs.js +1 -0
  677. package/shaders/BleachBypassShader.js +15 -31
  678. package/shaders/BlendShader.cjs.js +1 -0
  679. package/shaders/BlendShader.js +19 -26
  680. package/shaders/BokehShader.cjs.js +1 -0
  681. package/shaders/BokehShader.js +36 -98
  682. package/shaders/BokehShader2.cjs.js +1 -0
  683. package/shaders/BokehShader2.js +90 -261
  684. package/shaders/BrightnessContrastShader.cjs.js +1 -0
  685. package/shaders/BrightnessContrastShader.js +19 -28
  686. package/shaders/ColorCorrectionShader.cjs.js +1 -0
  687. package/shaders/ColorCorrectionShader.js +22 -26
  688. package/shaders/ColorifyShader.cjs.js +1 -0
  689. package/shaders/ColorifyShader.js +16 -24
  690. package/shaders/ConvolutionShader.cjs.js +1 -0
  691. package/shaders/ConvolutionShader.js +36 -40
  692. package/shaders/CopyShader.cjs.js +1 -0
  693. package/shaders/CopyShader.js +13 -21
  694. package/shaders/DOFMipMapShader.cjs.js +1 -0
  695. package/shaders/DOFMipMapShader.js +21 -28
  696. package/shaders/DepthLimitedBlurShader.cjs.js +1 -0
  697. package/shaders/DepthLimitedBlurShader.js +40 -85
  698. package/shaders/DigitalGlitch.cjs.js +1 -0
  699. package/shaders/DigitalGlitch.js +46 -74
  700. package/shaders/DotScreenShader.cjs.js +1 -0
  701. package/shaders/DotScreenShader.js +27 -35
  702. package/shaders/FXAAShader.cjs.js +1 -0
  703. package/shaders/FXAAShader.js +19 -1094
  704. package/shaders/FilmShader.cjs.js +1 -0
  705. package/shaders/FilmShader.js +52 -38
  706. package/shaders/FocusShader.cjs.js +1 -0
  707. package/shaders/FocusShader.js +24 -51
  708. package/shaders/FreiChenShader.cjs.js +1 -0
  709. package/shaders/FreiChenShader.js +24 -57
  710. package/shaders/FresnelShader.cjs.js +1 -0
  711. package/shaders/FresnelShader.js +22 -43
  712. package/shaders/GammaCorrectionShader.cjs.js +1 -0
  713. package/shaders/GammaCorrectionShader.js +11 -19
  714. package/shaders/GodRaysShader.cjs.js +1 -0
  715. package/shaders/GodRaysShader.js +94 -103
  716. package/shaders/HalftoneShader.cjs.js +1 -0
  717. package/shaders/HalftoneShader.js +65 -208
  718. package/shaders/HorizontalBlurShader.cjs.js +1 -0
  719. package/shaders/HorizontalBlurShader.js +23 -7
  720. package/shaders/HorizontalTiltShiftShader.cjs.js +1 -0
  721. package/shaders/HorizontalTiltShiftShader.js +21 -33
  722. package/shaders/HueSaturationShader.cjs.js +1 -0
  723. package/shaders/HueSaturationShader.js +21 -37
  724. package/shaders/KaleidoShader.cjs.js +1 -0
  725. package/shaders/KaleidoShader.js +22 -30
  726. package/shaders/LuminosityHighPassShader.cjs.js +1 -0
  727. package/shaders/LuminosityHighPassShader.js +27 -33
  728. package/shaders/LuminosityShader.cjs.js +1 -0
  729. package/shaders/LuminosityShader.js +11 -21
  730. package/shaders/MirrorShader.cjs.js +1 -0
  731. package/shaders/MirrorShader.js +16 -31
  732. package/shaders/NormalMapShader.cjs.js +1 -0
  733. package/shaders/NormalMapShader.js +23 -27
  734. package/shaders/ParallaxShader.cjs.js +1 -0
  735. package/shaders/ParallaxShader.js +48 -107
  736. package/shaders/PixelShader.cjs.js +1 -0
  737. package/shaders/PixelShader.js +16 -24
  738. package/shaders/RGBShiftShader.cjs.js +1 -0
  739. package/shaders/RGBShiftShader.js +22 -26
  740. package/shaders/SAOShader.cjs.js +1 -0
  741. package/shaders/SAOShader.js +48 -132
  742. package/shaders/SMAAShader.cjs.js +1 -0
  743. package/shaders/SMAAShader.js +135 -256
  744. package/shaders/SSAOShader.cjs.js +1 -0
  745. package/shaders/SSAOShader.js +81 -153
  746. package/shaders/SSRShader.cjs.js +1 -0
  747. package/shaders/SSRShader.js +87 -32
  748. package/shaders/SepiaShader.cjs.js +1 -0
  749. package/shaders/SepiaShader.js +15 -25
  750. package/shaders/SobelOperatorShader.cjs.js +1 -0
  751. package/shaders/SobelOperatorShader.js +29 -40
  752. package/shaders/SubsurfaceScatteringShader.cjs.js +1 -0
  753. package/shaders/SubsurfaceScatteringShader.js +39 -53
  754. package/shaders/TechnicolorShader.cjs.js +1 -0
  755. package/shaders/TechnicolorShader.js +13 -20
  756. package/shaders/ToneMapShader.cjs.js +1 -0
  757. package/shaders/ToneMapShader.js +28 -44
  758. package/shaders/ToonShader.cjs.js +1 -0
  759. package/shaders/ToonShader.js +96 -172
  760. package/shaders/TriangleBlurShader.cjs.js +1 -0
  761. package/shaders/TriangleBlurShader.js +23 -32
  762. package/shaders/UnpackDepthRGBAShader.cjs.js +1 -0
  763. package/shaders/UnpackDepthRGBAShader.js +14 -22
  764. package/shaders/VerticalBlurShader.cjs.js +1 -0
  765. package/shaders/VerticalBlurShader.js +23 -7
  766. package/shaders/VerticalTiltShiftShader.cjs.js +1 -0
  767. package/shaders/VerticalTiltShiftShader.js +21 -33
  768. package/shaders/VignetteShader.cjs.js +1 -0
  769. package/shaders/VignetteShader.js +28 -24
  770. package/shaders/VolumeShader.cjs.js +1 -0
  771. package/shaders/VolumeShader.js +77 -174
  772. package/shaders/WaterRefractionShader.cjs.js +1 -0
  773. package/shaders/WaterRefractionShader.js +6 -38
  774. package/shaders/types.cjs.js +1 -0
  775. package/shaders/types.js +1 -1
  776. package/textures/FlakesTexture.cjs.js +1 -0
  777. package/textures/FlakesTexture.js +10 -8
  778. package/types/helpers.cjs.js +1 -0
  779. package/types/helpers.js +2 -3
  780. package/types/shared.cjs.js +1 -0
  781. package/types/shared.js +1 -0
  782. package/types/utils.cjs.js +1 -0
  783. package/types/utils.js +1 -0
  784. package/utils/BufferGeometryUtils.cjs.js +1 -0
  785. package/utils/BufferGeometryUtils.js +325 -251
  786. package/utils/GeometryCompressionUtils.cjs.js +1 -0
  787. package/utils/GeometryCompressionUtils.js +239 -241
  788. package/utils/GeometryUtils.cjs.js +1 -0
  789. package/utils/GeometryUtils.js +94 -41
  790. package/utils/LDrawUtils.cjs.js +1 -0
  791. package/utils/LDrawUtils.d.ts +5 -0
  792. package/utils/LDrawUtils.js +144 -0
  793. package/utils/RoughnessMipmapper.cjs.js +1 -0
  794. package/utils/RoughnessMipmapper.js +82 -38
  795. package/utils/SceneUtils.cjs.js +1 -0
  796. package/utils/SceneUtils.js +20 -15
  797. package/utils/ShadowMapViewer.cjs.js +1 -0
  798. package/utils/ShadowMapViewer.js +95 -49
  799. package/utils/SkeletonUtils.cjs.js +1 -0
  800. package/utils/SkeletonUtils.js +165 -74
  801. package/utils/UVsDebug.cjs.js +1 -0
  802. package/utils/UVsDebug.js +62 -32
  803. package/utils/WorkerPool.cjs.js +1 -0
  804. package/utils/WorkerPool.js +33 -13
  805. package/webxr/ARButton.cjs.js +1 -0
  806. package/webxr/ARButton.js +98 -72
  807. package/webxr/OculusHandModel.cjs.js +1 -0
  808. package/webxr/OculusHandModel.js +37 -18
  809. package/webxr/OculusHandPointerModel.cjs.js +1 -0
  810. package/webxr/OculusHandPointerModel.js +80 -58
  811. package/webxr/Text2D.cjs.js +1 -0
  812. package/webxr/Text2D.js +19 -37
  813. package/webxr/VRButton.cjs.js +1 -0
  814. package/webxr/VRButton.js +90 -59
  815. package/webxr/XRControllerModelFactory.cjs.js +1 -0
  816. package/webxr/XRControllerModelFactory.js +116 -58
  817. package/webxr/XREstimatedLight.cjs.js +1 -0
  818. package/webxr/XREstimatedLight.js +66 -39
  819. package/webxr/XRHandMeshModel.cjs.js +1 -0
  820. package/webxr/XRHandMeshModel.js +29 -40
  821. package/webxr/XRHandModelFactory.cjs.js +1 -0
  822. package/webxr/XRHandModelFactory.js +31 -28
  823. package/webxr/XRHandPrimitiveModel.cjs.js +1 -0
  824. package/webxr/XRHandPrimitiveModel.js +27 -41
  825. package/animation/AnimationClipCreator.mjs +0 -57
  826. package/animation/CCDIKSolver.mjs +0 -223
  827. package/animation/MMDAnimationHelper.mjs +0 -514
  828. package/animation/MMDPhysics.mjs +0 -769
  829. package/cameras/CinematicCamera.mjs +0 -129
  830. package/controls/ArcballControls.mjs +0 -1737
  831. package/controls/DeviceOrientationControls.mjs +0 -74
  832. package/controls/DragControls.mjs +0 -172
  833. package/controls/FirstPersonControls.mjs +0 -220
  834. package/controls/FlyControls.mjs +0 -239
  835. package/controls/OrbitControls.mjs +0 -731
  836. package/controls/PointerLockControls.mjs +0 -88
  837. package/controls/TrackballControls.mjs +0 -481
  838. package/controls/TransformControls.mjs +0 -1068
  839. package/controls/experimental/CameraControls.mjs +0 -673
  840. package/csm/CSM.mjs +0 -244
  841. package/csm/CSMFrustum.mjs +0 -75
  842. package/csm/CSMHelper.mjs +0 -114
  843. package/csm/CSMShader.mjs +0 -251
  844. package/curves/CurveExtras.mjs +0 -224
  845. package/curves/NURBSCurve.mjs +0 -35
  846. package/curves/NURBSSurface.mjs +0 -28
  847. package/curves/NURBSUtils.mjs +0 -226
  848. package/deprecated/Geometry.mjs +0 -966
  849. package/effects/AnaglyphEffect.mjs +0 -120
  850. package/effects/AsciiEffect.mjs +0 -173
  851. package/effects/OutlineEffect.mjs +0 -295
  852. package/effects/ParallaxBarrierEffect.mjs +0 -64
  853. package/effects/PeppersGhostEffect.mjs +0 -85
  854. package/effects/StereoEffect.mjs +0 -32
  855. package/environments/RoomEnvironment.mjs +0 -78
  856. package/exporters/ColladaExporter.mjs +0 -299
  857. package/exporters/DRACOExporter.mjs +0 -132
  858. package/exporters/GLTFExporter.mjs +0 -1381
  859. package/exporters/MMDExporter.mjs +0 -102
  860. package/exporters/OBJExporter.mjs +0 -166
  861. package/exporters/PLYExporter.mjs +0 -278
  862. package/exporters/STLExporter.mjs +0 -129
  863. package/exporters/USDZExporter.mjs +0 -328
  864. package/geometries/BoxLineGeometry.mjs +0 -45
  865. package/geometries/ConvexGeometry.mjs +0 -29
  866. package/geometries/DecalGeometry.mjs +0 -184
  867. package/geometries/LightningStrike.mjs +0 -547
  868. package/geometries/ParametricGeometries.mjs +0 -129
  869. package/geometries/ParametricGeometry.mjs +0 -63
  870. package/geometries/RoundedBoxGeometry.mjs +0 -91
  871. package/geometries/TeapotGeometry.mjs +0 -1557
  872. package/geometries/TextGeometry.mjs +0 -23
  873. package/helpers/LightProbeHelper.mjs +0 -72
  874. package/helpers/PositionalAudioHelper.mjs +0 -68
  875. package/helpers/RectAreaLightHelper.mjs +0 -44
  876. package/helpers/VertexNormalsHelper.mjs +0 -54
  877. package/helpers/VertexTangentsHelper.mjs +0 -45
  878. package/index.mjs +0 -969
  879. package/interactive/SelectionBox.mjs +0 -137
  880. package/interactive/SelectionHelper.mjs +0 -54
  881. package/libs/MeshoptDecoder.mjs +0 -210
  882. package/libs/MotionControllers.mjs +0 -261
  883. package/lights/LightProbeGenerator.mjs +0 -145
  884. package/lights/RectAreaLightUniformsLib.mjs +0 -32842
  885. package/lines/Line2.mjs +0 -13
  886. package/lines/LineGeometry.mjs +0 -44
  887. package/lines/LineMaterial.mjs +0 -539
  888. package/lines/LineSegments2.mjs +0 -202
  889. package/lines/LineSegmentsGeometry.mjs +0 -124
  890. package/lines/Wireframe.mjs +0 -31
  891. package/lines/WireframeGeometry2.mjs +0 -13
  892. package/loaders/3DMLoader.mjs +0 -802
  893. package/loaders/3MFLoader.mjs +0 -837
  894. package/loaders/AMFLoader.mjs +0 -284
  895. package/loaders/AssimpLoader.mjs +0 -1396
  896. package/loaders/BVHLoader.mjs +0 -207
  897. package/loaders/BasisTextureLoader.mjs +0 -474
  898. package/loaders/ColladaLoader.mjs +0 -2403
  899. package/loaders/DDSLoader.mjs +0 -148
  900. package/loaders/DRACOLoader.mjs +0 -340
  901. package/loaders/EXRLoader.mjs +0 -1351
  902. package/loaders/FBXLoader.mjs +0 -2362
  903. package/loaders/FontLoader.mjs +0 -111
  904. package/loaders/GCodeLoader.mjs +0 -141
  905. package/loaders/GLTFLoader.mjs +0 -2316
  906. package/loaders/HDRCubeTextureLoader.mjs +0 -77
  907. package/loaders/KMZLoader.mjs +0 -75
  908. package/loaders/KTX2Loader.mjs +0 -427
  909. package/loaders/KTXLoader.mjs +0 -87
  910. package/loaders/LDrawLoader.mjs +0 -1409
  911. package/loaders/LUT3dlLoader.mjs +0 -100
  912. package/loaders/LUTCubeLoader.mjs +0 -104
  913. package/loaders/LWOLoader.mjs +0 -625
  914. package/loaders/LottieLoader.mjs +0 -47
  915. package/loaders/MD2Loader.mjs +0 -359
  916. package/loaders/MDDLoader.mjs +0 -58
  917. package/loaders/MMDLoader.mjs +0 -998
  918. package/loaders/MTLLoader.mjs +0 -280
  919. package/loaders/NRRDLoader.mjs +0 -401
  920. package/loaders/NodeMaterialLoader.mjs +0 -146
  921. package/loaders/OBJLoader.mjs +0 -487
  922. package/loaders/PCDLoader.mjs +0 -248
  923. package/loaders/PDBLoader.mjs +0 -246
  924. package/loaders/PLYLoader.mjs +0 -317
  925. package/loaders/PRWMLoader.mjs +0 -160
  926. package/loaders/PVRLoader.mjs +0 -131
  927. package/loaders/RGBELoader.mjs +0 -244
  928. package/loaders/RGBMLoader.mjs +0 -998
  929. package/loaders/STLLoader.mjs +0 -190
  930. package/loaders/SVGLoader.mjs +0 -1709
  931. package/loaders/TDSLoader.mjs +0 -480
  932. package/loaders/TGALoader.mjs +0 -285
  933. package/loaders/TTFLoader.mjs +0 -131
  934. package/loaders/TiltLoader.mjs +0 -373
  935. package/loaders/VOXLoader.mjs +0 -431
  936. package/loaders/VRMLLoader.mjs +0 -2093
  937. package/loaders/VRMLoader.mjs +0 -38
  938. package/loaders/VTKLoader.mjs +0 -646
  939. package/loaders/XLoader.mjs +0 -1258
  940. package/loaders/XYZLoader.mjs +0 -60
  941. package/loaders/lwo/IFFParser.mjs +0 -697
  942. package/loaders/lwo/LWO2Parser.mjs +0 -327
  943. package/loaders/lwo/LWO3Parser.mjs +0 -298
  944. package/math/Capsule.mjs +0 -100
  945. package/math/ColorConverter.mjs +0 -51
  946. package/math/ConvexHull.mjs +0 -574
  947. package/math/ImprovedNoise.mjs +0 -302
  948. package/math/Lut.mjs +0 -135
  949. package/math/MeshSurfaceSampler.mjs +0 -107
  950. package/math/OBB.mjs +0 -235
  951. package/math/Octree.mjs +0 -278
  952. package/math/SimplexNoise.mjs +0 -425
  953. package/misc/ConvexObjectBreaker.mjs +0 -292
  954. package/misc/GPUComputationRenderer.mjs +0 -171
  955. package/misc/Gyroscope.mjs +0 -35
  956. package/misc/MD2Character.mjs +0 -162
  957. package/misc/MD2CharacterComplex.mjs +0 -328
  958. package/misc/MorphAnimMesh.mjs +0 -40
  959. package/misc/MorphBlendMesh.mjs +0 -179
  960. package/misc/ProgressiveLightmap.mjs +0 -166
  961. package/misc/RollerCoaster.mjs +0 -346
  962. package/misc/TubePainter.mjs +0 -123
  963. package/misc/Volume.mjs +0 -244
  964. package/misc/VolumeSlice.mjs +0 -106
  965. package/misc/WebGL.mjs +0 -74
  966. package/modifiers/CurveModifier.mjs +0 -182
  967. package/modifiers/EdgeSplitModifier.mjs +0 -162
  968. package/modifiers/SimplifyModifier.mjs +0 -282
  969. package/modifiers/TessellateModifier.mjs +0 -206
  970. package/nodes/Nodes.mjs +0 -400
  971. package/nodes/ShaderNode.mjs +0 -408
  972. package/nodes/accessors/BufferNode.mjs +0 -15
  973. package/nodes/accessors/CameraNode.mjs +0 -44
  974. package/nodes/accessors/CubeTextureNode.mjs +0 -42
  975. package/nodes/accessors/MaterialNode.mjs +0 -71
  976. package/nodes/accessors/MaterialReferenceNode.mjs +0 -14
  977. package/nodes/accessors/ModelNode.mjs +0 -9
  978. package/nodes/accessors/ModelViewProjectionNode.mjs +0 -24
  979. package/nodes/accessors/NormalNode.mjs +0 -62
  980. package/nodes/accessors/Object3DNode.mjs +0 -76
  981. package/nodes/accessors/PointUVNode.mjs +0 -13
  982. package/nodes/accessors/PositionNode.mjs +0 -65
  983. package/nodes/accessors/ReferenceNode.mjs +0 -37
  984. package/nodes/accessors/ReflectNode.mjs +0 -43
  985. package/nodes/accessors/SkinningNode.mjs +0 -58
  986. package/nodes/accessors/TextureNode.mjs +0 -54
  987. package/nodes/accessors/UVNode.mjs +0 -23
  988. package/nodes/core/ArrayUniformNode.mjs +0 -14
  989. package/nodes/core/AttributeNode.mjs +0 -30
  990. package/nodes/core/BypassNode.mjs +0 -22
  991. package/nodes/core/CodeNode.mjs +0 -28
  992. package/nodes/core/ConstNode.mjs +0 -14
  993. package/nodes/core/ContextNode.mjs +0 -22
  994. package/nodes/core/ExpressionNode.mjs +0 -19
  995. package/nodes/core/FunctionCallNode.mjs +0 -37
  996. package/nodes/core/FunctionNode.mjs +0 -56
  997. package/nodes/core/InputNode.mjs +0 -38
  998. package/nodes/core/Node.mjs +0 -139
  999. package/nodes/core/NodeAttribute.mjs +0 -10
  1000. package/nodes/core/NodeBuilder.mjs +0 -395
  1001. package/nodes/core/NodeCode.mjs +0 -11
  1002. package/nodes/core/NodeFrame.mjs +0 -35
  1003. package/nodes/core/NodeFunctionInput.mjs +0 -13
  1004. package/nodes/core/NodeKeywords.mjs +0 -44
  1005. package/nodes/core/NodeUniform.mjs +0 -18
  1006. package/nodes/core/NodeUtils.mjs +0 -57
  1007. package/nodes/core/NodeVar.mjs +0 -10
  1008. package/nodes/core/NodeVary.mjs +0 -10
  1009. package/nodes/core/PropertyNode.mjs +0 -21
  1010. package/nodes/core/TempNode.mjs +0 -25
  1011. package/nodes/core/UniformNode.mjs +0 -23
  1012. package/nodes/core/VarNode.mjs +0 -31
  1013. package/nodes/core/VaryNode.mjs +0 -30
  1014. package/nodes/core/constants.mjs +0 -24
  1015. package/nodes/display/ColorSpaceNode.mjs +0 -63
  1016. package/nodes/display/NormalMapNode.mjs +0 -54
  1017. package/nodes/fog/FogNode.mjs +0 -15
  1018. package/nodes/fog/FogRangeNode.mjs +0 -17
  1019. package/nodes/functions/BSDFs.mjs +0 -64
  1020. package/nodes/lights/LightContextNode.mjs +0 -35
  1021. package/nodes/lights/LightNode.mjs +0 -58
  1022. package/nodes/lights/LightsNode.mjs +0 -59
  1023. package/nodes/loaders/NodeLoader.mjs +0 -66
  1024. package/nodes/loaders/NodeMaterialLoader.mjs +0 -24
  1025. package/nodes/loaders/NodeObjectLoader.mjs +0 -40
  1026. package/nodes/materials/LineBasicNodeMaterial.mjs +0 -27
  1027. package/nodes/materials/Materials.mjs +0 -28
  1028. package/nodes/materials/MeshBasicNodeMaterial.mjs +0 -28
  1029. package/nodes/materials/MeshStandardNodeMaterial.mjs +0 -41
  1030. package/nodes/materials/NodeMaterial.mjs +0 -64
  1031. package/nodes/materials/PointsNodeMaterial.mjs +0 -30
  1032. package/nodes/math/CondNode.mjs +0 -38
  1033. package/nodes/math/MathNode.mjs +0 -163
  1034. package/nodes/math/OperatorNode.mjs +0 -103
  1035. package/nodes/procedural/CheckerNode.mjs +0 -21
  1036. package/nodes/utils/ArrayElementNode.mjs +0 -19
  1037. package/nodes/utils/ConvertNode.mjs +0 -25
  1038. package/nodes/utils/JoinNode.mjs +0 -26
  1039. package/nodes/utils/MatcapUVNode.mjs +0 -16
  1040. package/nodes/utils/OscNode.mjs +0 -50
  1041. package/nodes/utils/SplitNode.mjs +0 -45
  1042. package/nodes/utils/SpriteSheetUVNode.mjs +0 -40
  1043. package/nodes/utils/TimerNode.mjs +0 -44
  1044. package/objects/GroundProjectedEnv.mjs +0 -130
  1045. package/objects/Lensflare.mjs +0 -262
  1046. package/objects/LightningStorm.mjs +0 -110
  1047. package/objects/MarchingCubes.mjs +0 -457
  1048. package/objects/Reflector.mjs +0 -166
  1049. package/objects/ReflectorForSSRPass.mjs +0 -247
  1050. package/objects/ReflectorRTT.mjs +0 -10
  1051. package/objects/Refractor.mjs +0 -178
  1052. package/objects/ShadowMesh.mjs +0 -41
  1053. package/objects/Sky.mjs +0 -124
  1054. package/objects/Water.mjs +0 -235
  1055. package/objects/Water2.mjs +0 -252
  1056. package/offscreen/jank.mjs +0 -27
  1057. package/offscreen/offscreen.mjs +0 -5
  1058. package/offscreen/scene.mjs +0 -52
  1059. package/physics/AmmoPhysics.mjs +0 -165
  1060. package/postprocessing/AdaptiveToneMappingPass.mjs +0 -221
  1061. package/postprocessing/AfterimagePass.mjs +0 -55
  1062. package/postprocessing/BloomPass.mjs +0 -90
  1063. package/postprocessing/BokehPass.mjs +0 -76
  1064. package/postprocessing/ClearPass.mjs +0 -27
  1065. package/postprocessing/CubeTexturePass.mjs +0 -49
  1066. package/postprocessing/DotScreenPass.mjs +0 -40
  1067. package/postprocessing/EffectComposer.mjs +0 -139
  1068. package/postprocessing/FilmPass.mjs +0 -42
  1069. package/postprocessing/GlitchPass.mjs +0 -75
  1070. package/postprocessing/HalftonePass.mjs +0 -44
  1071. package/postprocessing/LUTPass.mjs +0 -136
  1072. package/postprocessing/MaskPass.mjs +0 -60
  1073. package/postprocessing/OutlinePass.mjs +0 -438
  1074. package/postprocessing/Pass.mjs +0 -37
  1075. package/postprocessing/RenderPass.mjs +0 -48
  1076. package/postprocessing/RenderPixelatedPass.mjs +0 -199
  1077. package/postprocessing/SAOPass.mjs +0 -282
  1078. package/postprocessing/SMAAPass.mjs +0 -112
  1079. package/postprocessing/SSAARenderPass.mjs +0 -170
  1080. package/postprocessing/SSAOPass.mjs +0 -265
  1081. package/postprocessing/SSRPass.mjs +0 -432
  1082. package/postprocessing/SavePass.mjs +0 -37
  1083. package/postprocessing/ShaderPass.mjs +0 -39
  1084. package/postprocessing/TAARenderPass.mjs +0 -88
  1085. package/postprocessing/TexturePass.mjs +0 -39
  1086. package/postprocessing/UnrealBloomPass.mjs +0 -220
  1087. package/renderers/CSS2DRenderer.mjs +0 -112
  1088. package/renderers/CSS3DRenderer.mjs +0 -133
  1089. package/renderers/Projector.mjs +0 -511
  1090. package/renderers/SVGRenderer.mjs +0 -306
  1091. package/renderers/nodes/accessors/CameraNode.mjs +0 -63
  1092. package/renderers/nodes/accessors/ModelNode.mjs +0 -61
  1093. package/renderers/nodes/accessors/ModelViewProjectionNode.mjs +0 -21
  1094. package/renderers/nodes/accessors/NormalNode.mjs +0 -61
  1095. package/renderers/nodes/accessors/PositionNode.mjs +0 -30
  1096. package/renderers/nodes/accessors/UVNode.mjs +0 -13
  1097. package/renderers/nodes/core/AttributeNode.mjs +0 -35
  1098. package/renderers/nodes/core/InputNode.mjs +0 -31
  1099. package/renderers/nodes/core/Node.mjs +0 -34
  1100. package/renderers/nodes/core/NodeAttribute.mjs +0 -10
  1101. package/renderers/nodes/core/NodeBuilder.mjs +0 -243
  1102. package/renderers/nodes/core/NodeFrame.mjs +0 -35
  1103. package/renderers/nodes/core/NodeSlot.mjs +0 -10
  1104. package/renderers/nodes/core/NodeUniform.mjs +0 -18
  1105. package/renderers/nodes/core/NodeVary.mjs +0 -11
  1106. package/renderers/nodes/core/VaryNode.mjs +0 -22
  1107. package/renderers/nodes/core/constants.mjs +0 -22
  1108. package/renderers/nodes/inputs/ColorNode.mjs +0 -11
  1109. package/renderers/nodes/inputs/FloatNode.mjs +0 -11
  1110. package/renderers/nodes/inputs/Matrix3Node.mjs +0 -12
  1111. package/renderers/nodes/inputs/Matrix4Node.mjs +0 -12
  1112. package/renderers/nodes/inputs/TextureNode.mjs +0 -20
  1113. package/renderers/nodes/inputs/Vector2Node.mjs +0 -11
  1114. package/renderers/nodes/inputs/Vector3Node.mjs +0 -12
  1115. package/renderers/nodes/inputs/Vector4Node.mjs +0 -12
  1116. package/renderers/nodes/math/MathNode.mjs +0 -55
  1117. package/renderers/nodes/math/OperatorNode.mjs +0 -42
  1118. package/renderers/nodes/utils/SwitchNode.mjs +0 -20
  1119. package/renderers/nodes/utils/TimerNode.mjs +0 -14
  1120. package/renderers/webgpu/WebGPU.mjs +0 -24
  1121. package/renderers/webgpu/WebGPUAttributes.mjs +0 -69
  1122. package/renderers/webgpu/WebGPUBackground.mjs +0 -61
  1123. package/renderers/webgpu/WebGPUBinding.mjs +0 -14
  1124. package/renderers/webgpu/WebGPUBindings.mjs +0 -155
  1125. package/renderers/webgpu/WebGPUComputePipelines.mjs +0 -44
  1126. package/renderers/webgpu/WebGPUGeometries.mjs +0 -41
  1127. package/renderers/webgpu/WebGPUInfo.mjs +0 -46
  1128. package/renderers/webgpu/WebGPUObjects.mjs +0 -25
  1129. package/renderers/webgpu/WebGPUProperties.mjs +0 -22
  1130. package/renderers/webgpu/WebGPURenderLists.mjs +0 -119
  1131. package/renderers/webgpu/WebGPURenderPipelines.mjs +0 -545
  1132. package/renderers/webgpu/WebGPURenderer.mjs +0 -574
  1133. package/renderers/webgpu/WebGPUSampledTexture.mjs +0 -40
  1134. package/renderers/webgpu/WebGPUSampler.mjs +0 -15
  1135. package/renderers/webgpu/WebGPUStorageBuffer.mjs +0 -15
  1136. package/renderers/webgpu/WebGPUTextureRenderer.mjs +0 -23
  1137. package/renderers/webgpu/WebGPUTextureUtils.mjs +0 -98
  1138. package/renderers/webgpu/WebGPUTextures.mjs +0 -484
  1139. package/renderers/webgpu/WebGPUUniform.mjs +0 -81
  1140. package/renderers/webgpu/WebGPUUniformsGroup.mjs +0 -176
  1141. package/renderers/webgpu/constants.mjs +0 -230
  1142. package/renderers/webgpu/nodes/ShaderLib.mjs +0 -42
  1143. package/renderers/webgpu/nodes/WebGPUNodeBuilder.mjs +0 -165
  1144. package/renderers/webgpu/nodes/WebGPUNodeUniform.mjs +0 -73
  1145. package/renderers/webgpu/nodes/WebGPUNodeUniformsGroup.mjs +0 -15
  1146. package/renderers/webgpu/nodes/WebGPUNodes.mjs +0 -40
  1147. package/shaders/ACESFilmicToneMappingShader.mjs +0 -48
  1148. package/shaders/AfterimageShader.mjs +0 -32
  1149. package/shaders/BasicShader.mjs +0 -12
  1150. package/shaders/BleachBypassShader.mjs +0 -35
  1151. package/shaders/BlendShader.mjs +0 -30
  1152. package/shaders/BokehShader.mjs +0 -106
  1153. package/shaders/BokehShader2.mjs +0 -269
  1154. package/shaders/BrightnessContrastShader.mjs +0 -32
  1155. package/shaders/ColorCorrectionShader.mjs +0 -30
  1156. package/shaders/ColorifyShader.mjs +0 -28
  1157. package/shaders/ConvolutionShader.mjs +0 -55
  1158. package/shaders/CopyShader.mjs +0 -25
  1159. package/shaders/DOFMipMapShader.mjs +0 -32
  1160. package/shaders/DepthLimitedBlurShader.mjs +0 -114
  1161. package/shaders/DigitalGlitch.mjs +0 -78
  1162. package/shaders/DotScreenShader.mjs +0 -39
  1163. package/shaders/FXAAShader.mjs +0 -1098
  1164. package/shaders/FilmShader.mjs +0 -42
  1165. package/shaders/FocusShader.mjs +0 -55
  1166. package/shaders/FreiChenShader.mjs +0 -61
  1167. package/shaders/FresnelShader.mjs +0 -47
  1168. package/shaders/GammaCorrectionShader.mjs +0 -23
  1169. package/shaders/GodRaysShader.mjs +0 -146
  1170. package/shaders/HalftoneShader.mjs +0 -212
  1171. package/shaders/HorizontalBlurShader.mjs +0 -43
  1172. package/shaders/HorizontalTiltShiftShader.mjs +0 -37
  1173. package/shaders/HueSaturationShader.mjs +0 -41
  1174. package/shaders/KaleidoShader.mjs +0 -34
  1175. package/shaders/LuminosityHighPassShader.mjs +0 -37
  1176. package/shaders/LuminosityShader.mjs +0 -25
  1177. package/shaders/MirrorShader.mjs +0 -35
  1178. package/shaders/NormalMapShader.mjs +0 -31
  1179. package/shaders/ParallaxShader.mjs +0 -113
  1180. package/shaders/PixelShader.mjs +0 -28
  1181. package/shaders/RGBShiftShader.mjs +0 -30
  1182. package/shaders/SAOShader.mjs +0 -144
  1183. package/shaders/SMAAShader.mjs +0 -272
  1184. package/shaders/SSAOShader.mjs +0 -172
  1185. package/shaders/SSRShader.mjs +0 -324
  1186. package/shaders/SepiaShader.mjs +0 -29
  1187. package/shaders/SobelOperatorShader.mjs +0 -44
  1188. package/shaders/SubsurfaceScatteringShader.mjs +0 -59
  1189. package/shaders/TechnicolorShader.mjs +0 -24
  1190. package/shaders/ToneMapShader.mjs +0 -48
  1191. package/shaders/ToonShader.mjs +0 -188
  1192. package/shaders/TriangleBlurShader.mjs +0 -36
  1193. package/shaders/UnpackDepthRGBAShader.mjs +0 -26
  1194. package/shaders/VerticalBlurShader.mjs +0 -44
  1195. package/shaders/VerticalTiltShiftShader.mjs +0 -37
  1196. package/shaders/VignetteShader.mjs +0 -28
  1197. package/shaders/VolumeShader.mjs +0 -178
  1198. package/shaders/WaterRefractionShader.mjs +0 -57
  1199. package/textures/FlakesTexture.mjs +0 -30
  1200. package/types/helpers.mjs +0 -4
  1201. package/utils/BufferGeometryUtils.mjs +0 -570
  1202. package/utils/GeometryCompressionUtils.mjs +0 -547
  1203. package/utils/GeometryUtils.mjs +0 -108
  1204. package/utils/RoughnessMipmapper.mjs +0 -213
  1205. package/utils/SceneUtils.mjs +0 -36
  1206. package/utils/ShadowMapViewer.mjs +0 -114
  1207. package/utils/SkeletonUtils.mjs +0 -292
  1208. package/utils/UVsDebug.mjs +0 -85
  1209. package/utils/WorkerPool.mjs +0 -62
  1210. package/webxr/ARButton.mjs +0 -119
  1211. package/webxr/OculusHandModel.mjs +0 -71
  1212. package/webxr/OculusHandPointerModel.mjs +0 -207
  1213. package/webxr/Text2D.mjs +0 -31
  1214. package/webxr/VRButton.mjs +0 -105
  1215. package/webxr/XRControllerModelFactory.mjs +0 -146
  1216. package/webxr/XREstimatedLight.mjs +0 -126
  1217. package/webxr/XRHandMeshModel.mjs +0 -73
  1218. package/webxr/XRHandModelFactory.mjs +0 -61
  1219. package/webxr/XRHandPrimitiveModel.mjs +0 -68
@@ -1,146 +1,157 @@
1
- "use strict";
2
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const THREE = require("three");
4
- class GLTFLoader extends THREE.Loader {
1
+ import { Loader, LoaderUtils, FileLoader, Color, SpotLight, PointLight, DirectionalLight, MeshBasicMaterial, MeshPhysicalMaterial, Vector2, sRGBEncoding, TangentSpaceNormalMap, Quaternion, ImageBitmapLoader, TextureLoader, InterleavedBuffer, InterleavedBufferAttribute, BufferAttribute, LinearFilter, LinearMipmapLinearFilter, RepeatWrapping, PointsMaterial, Material, LineBasicMaterial, MeshStandardMaterial, DoubleSide, PropertyBinding, BufferGeometry, SkinnedMesh, Mesh, LineSegments, Line, LineLoop, Points, Group, PerspectiveCamera, MathUtils, OrthographicCamera, InterpolateLinear, AnimationClip, Bone, Object3D, Matrix4, Skeleton, TriangleFanDrawMode, NearestFilter, NearestMipmapNearestFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, ClampToEdgeWrapping, MirroredRepeatWrapping, InterpolateDiscrete, FrontSide, Texture, TriangleStripDrawMode, VectorKeyframeTrack, QuaternionKeyframeTrack, NumberKeyframeTrack, Box3, Vector3, Sphere, Interpolant } from 'three';
2
+
3
+ class GLTFLoader extends Loader {
5
4
  constructor(manager) {
6
5
  super(manager);
7
6
  this.dracoLoader = null;
8
7
  this.ktx2Loader = null;
9
8
  this.meshoptDecoder = null;
10
9
  this.pluginCallbacks = [];
11
- this.register(function(parser) {
10
+ this.register(function (parser) {
12
11
  return new GLTFMaterialsClearcoatExtension(parser);
13
12
  });
14
- this.register(function(parser) {
13
+ this.register(function (parser) {
15
14
  return new GLTFTextureBasisUExtension(parser);
16
15
  });
17
- this.register(function(parser) {
16
+ this.register(function (parser) {
18
17
  return new GLTFTextureWebPExtension(parser);
19
18
  });
20
- this.register(function(parser) {
19
+ this.register(function (parser) {
21
20
  return new GLTFMaterialsSheenExtension(parser);
22
21
  });
23
- this.register(function(parser) {
22
+ this.register(function (parser) {
24
23
  return new GLTFMaterialsTransmissionExtension(parser);
25
24
  });
26
- this.register(function(parser) {
25
+ this.register(function (parser) {
27
26
  return new GLTFMaterialsVolumeExtension(parser);
28
27
  });
29
- this.register(function(parser) {
28
+ this.register(function (parser) {
30
29
  return new GLTFMaterialsIorExtension(parser);
31
30
  });
32
- this.register(function(parser) {
31
+ this.register(function (parser) {
33
32
  return new GLTFMaterialsSpecularExtension(parser);
34
33
  });
35
- this.register(function(parser) {
34
+ this.register(function (parser) {
36
35
  return new GLTFLightsExtension(parser);
37
36
  });
38
- this.register(function(parser) {
37
+ this.register(function (parser) {
39
38
  return new GLTFMeshoptCompression(parser);
40
39
  });
41
40
  }
41
+
42
42
  load(url, onLoad, onProgress, onError) {
43
43
  const scope = this;
44
44
  let resourcePath;
45
- if (this.resourcePath !== "") {
45
+
46
+ if (this.resourcePath !== '') {
46
47
  resourcePath = this.resourcePath;
47
- } else if (this.path !== "") {
48
+ } else if (this.path !== '') {
48
49
  resourcePath = this.path;
49
50
  } else {
50
- resourcePath = THREE.LoaderUtils.extractUrlBase(url);
51
- }
51
+ resourcePath = LoaderUtils.extractUrlBase(url);
52
+ } // Tells the LoadingManager to track an extra item, which resolves after
53
+ // the model is fully loaded. This means the count of items loaded will
54
+ // be incorrect, but ensures manager.onLoad() does not fire early.
55
+
56
+
52
57
  this.manager.itemStart(url);
53
- const _onError = function(e) {
58
+
59
+ const _onError = function (e) {
54
60
  if (onError) {
55
61
  onError(e);
56
62
  } else {
57
63
  console.error(e);
58
64
  }
65
+
59
66
  scope.manager.itemError(url);
60
67
  scope.manager.itemEnd(url);
61
68
  };
62
- const loader = new THREE.FileLoader(this.manager);
69
+
70
+ const loader = new FileLoader(this.manager);
63
71
  loader.setPath(this.path);
64
- loader.setResponseType("arraybuffer");
72
+ loader.setResponseType('arraybuffer');
65
73
  loader.setRequestHeader(this.requestHeader);
66
74
  loader.setWithCredentials(this.withCredentials);
67
- loader.load(
68
- url,
69
- function(data) {
70
- try {
71
- scope.parse(
72
- data,
73
- resourcePath,
74
- function(gltf) {
75
- onLoad(gltf);
76
- scope.manager.itemEnd(url);
77
- },
78
- _onError
79
- );
80
- } catch (e) {
81
- _onError(e);
82
- }
83
- },
84
- onProgress,
85
- _onError
86
- );
75
+ loader.load(url, function (data) {
76
+ try {
77
+ scope.parse(data, resourcePath, function (gltf) {
78
+ onLoad(gltf);
79
+ scope.manager.itemEnd(url);
80
+ }, _onError);
81
+ } catch (e) {
82
+ _onError(e);
83
+ }
84
+ }, onProgress, _onError);
87
85
  }
86
+
88
87
  setDRACOLoader(dracoLoader) {
89
88
  this.dracoLoader = dracoLoader;
90
89
  return this;
91
90
  }
91
+
92
92
  setDDSLoader() {
93
93
  throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".');
94
94
  }
95
+
95
96
  setKTX2Loader(ktx2Loader) {
96
97
  this.ktx2Loader = ktx2Loader;
97
98
  return this;
98
99
  }
100
+
99
101
  setMeshoptDecoder(meshoptDecoder) {
100
102
  this.meshoptDecoder = meshoptDecoder;
101
103
  return this;
102
104
  }
105
+
103
106
  register(callback) {
104
107
  if (this.pluginCallbacks.indexOf(callback) === -1) {
105
108
  this.pluginCallbacks.push(callback);
106
109
  }
110
+
107
111
  return this;
108
112
  }
113
+
109
114
  unregister(callback) {
110
115
  if (this.pluginCallbacks.indexOf(callback) !== -1) {
111
116
  this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(callback), 1);
112
117
  }
118
+
113
119
  return this;
114
120
  }
121
+
115
122
  parse(data, path, onLoad, onError) {
116
123
  let content;
117
124
  const extensions = {};
118
125
  const plugins = {};
119
- if (typeof data === "string") {
126
+
127
+ if (typeof data === 'string') {
120
128
  content = data;
121
129
  } else {
122
- const magic = THREE.LoaderUtils.decodeText(new Uint8Array(data, 0, 4));
130
+ const magic = LoaderUtils.decodeText(new Uint8Array(data, 0, 4));
131
+
123
132
  if (magic === BINARY_EXTENSION_HEADER_MAGIC) {
124
133
  try {
125
134
  extensions[EXTENSIONS.KHR_BINARY_GLTF] = new GLTFBinaryExtension(data);
126
135
  } catch (error) {
127
- if (onError)
128
- onError(error);
136
+ if (onError) onError(error);
129
137
  return;
130
138
  }
139
+
131
140
  content = extensions[EXTENSIONS.KHR_BINARY_GLTF].content;
132
141
  } else {
133
- content = THREE.LoaderUtils.decodeText(new Uint8Array(data));
142
+ content = LoaderUtils.decodeText(new Uint8Array(data));
134
143
  }
135
144
  }
145
+
136
146
  const json = JSON.parse(content);
137
- if (json.asset === void 0 || json.asset.version[0] < 2) {
138
- if (onError)
139
- onError(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));
147
+
148
+ if (json.asset === undefined || json.asset.version[0] < 2) {
149
+ if (onError) onError(new Error('THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.'));
140
150
  return;
141
151
  }
152
+
142
153
  const parser = new GLTFParser(json, {
143
- path: path || this.resourcePath || "",
154
+ path: path || this.resourcePath || '',
144
155
  crossOrigin: this.crossOrigin,
145
156
  requestHeader: this.requestHeader,
146
157
  manager: this.manager,
@@ -148,474 +159,664 @@ class GLTFLoader extends THREE.Loader {
148
159
  meshoptDecoder: this.meshoptDecoder
149
160
  });
150
161
  parser.fileLoader.setRequestHeader(this.requestHeader);
162
+
151
163
  for (let i = 0; i < this.pluginCallbacks.length; i++) {
152
164
  const plugin = this.pluginCallbacks[i](parser);
153
- plugins[plugin.name] = plugin;
165
+ plugins[plugin.name] = plugin; // Workaround to avoid determining as unknown extension
166
+ // in addUnknownExtensionsToUserData().
167
+ // Remove this workaround if we move all the existing
168
+ // extension handlers to plugin system
169
+
154
170
  extensions[plugin.name] = true;
155
171
  }
172
+
156
173
  if (json.extensionsUsed) {
157
174
  for (let i = 0; i < json.extensionsUsed.length; ++i) {
158
175
  const extensionName = json.extensionsUsed[i];
159
176
  const extensionsRequired = json.extensionsRequired || [];
177
+
160
178
  switch (extensionName) {
161
179
  case EXTENSIONS.KHR_MATERIALS_UNLIT:
162
180
  extensions[extensionName] = new GLTFMaterialsUnlitExtension();
163
181
  break;
182
+
164
183
  case EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:
165
184
  extensions[extensionName] = new GLTFMaterialsPbrSpecularGlossinessExtension();
166
185
  break;
186
+
167
187
  case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
168
188
  extensions[extensionName] = new GLTFDracoMeshCompressionExtension(json, this.dracoLoader);
169
189
  break;
190
+
170
191
  case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
171
192
  extensions[extensionName] = new GLTFTextureTransformExtension();
172
193
  break;
194
+
173
195
  case EXTENSIONS.KHR_MESH_QUANTIZATION:
174
196
  extensions[extensionName] = new GLTFMeshQuantizationExtension();
175
197
  break;
198
+
176
199
  default:
177
- if (extensionsRequired.indexOf(extensionName) >= 0 && plugins[extensionName] === void 0) {
200
+ if (extensionsRequired.indexOf(extensionName) >= 0 && plugins[extensionName] === undefined) {
178
201
  console.warn('THREE.GLTFLoader: Unknown extension "' + extensionName + '".');
179
202
  }
203
+
180
204
  }
181
205
  }
182
206
  }
207
+
183
208
  parser.setExtensions(extensions);
184
209
  parser.setPlugins(plugins);
185
210
  parser.parse(onLoad, onError);
186
211
  }
212
+
187
213
  parseAsync(data, path) {
188
214
  const scope = this;
189
- return new Promise(function(resolve, reject) {
215
+ return new Promise(function (resolve, reject) {
190
216
  scope.parse(data, path, resolve, reject);
191
217
  });
192
218
  }
219
+
193
220
  }
221
+ /* GLTFREGISTRY */
222
+
223
+
194
224
  function GLTFRegistry() {
195
225
  let objects = {};
196
226
  return {
197
- get: function(key) {
227
+ get: function (key) {
198
228
  return objects[key];
199
229
  },
200
- add: function(key, object) {
230
+ add: function (key, object) {
201
231
  objects[key] = object;
202
232
  },
203
- remove: function(key) {
233
+ remove: function (key) {
204
234
  delete objects[key];
205
235
  },
206
- removeAll: function() {
236
+ removeAll: function () {
207
237
  objects = {};
208
238
  }
209
239
  };
210
240
  }
241
+ /*********************************/
242
+
243
+ /********** EXTENSIONS ***********/
244
+
245
+ /*********************************/
246
+
247
+
211
248
  const EXTENSIONS = {
212
- KHR_BINARY_GLTF: "KHR_binary_glTF",
213
- KHR_DRACO_MESH_COMPRESSION: "KHR_draco_mesh_compression",
214
- KHR_LIGHTS_PUNCTUAL: "KHR_lights_punctual",
215
- KHR_MATERIALS_CLEARCOAT: "KHR_materials_clearcoat",
216
- KHR_MATERIALS_IOR: "KHR_materials_ior",
217
- KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: "KHR_materials_pbrSpecularGlossiness",
218
- KHR_MATERIALS_SHEEN: "KHR_materials_sheen",
219
- KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
220
- KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
221
- KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
222
- KHR_MATERIALS_VOLUME: "KHR_materials_volume",
223
- KHR_TEXTURE_BASISU: "KHR_texture_basisu",
224
- KHR_TEXTURE_TRANSFORM: "KHR_texture_transform",
225
- KHR_MESH_QUANTIZATION: "KHR_mesh_quantization",
226
- EXT_TEXTURE_WEBP: "EXT_texture_webp",
227
- EXT_MESHOPT_COMPRESSION: "EXT_meshopt_compression"
249
+ KHR_BINARY_GLTF: 'KHR_binary_glTF',
250
+ KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
251
+ KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
252
+ KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
253
+ KHR_MATERIALS_IOR: 'KHR_materials_ior',
254
+ KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
255
+ KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
256
+ KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
257
+ KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
258
+ KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
259
+ KHR_MATERIALS_VOLUME: 'KHR_materials_volume',
260
+ KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
261
+ KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
262
+ KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
263
+ EXT_TEXTURE_WEBP: 'EXT_texture_webp',
264
+ EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression'
228
265
  };
266
+ /**
267
+ * Punctual Lights Extension
268
+ *
269
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
270
+ */
271
+
229
272
  class GLTFLightsExtension {
230
273
  constructor(parser) {
231
274
  this.parser = parser;
232
- this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
233
- this.cache = { refs: {}, uses: {} };
275
+ this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL; // Object3D instance caches
276
+
277
+ this.cache = {
278
+ refs: {},
279
+ uses: {}
280
+ };
234
281
  }
282
+
235
283
  _markDefs() {
236
284
  const parser = this.parser;
237
285
  const nodeDefs = this.parser.json.nodes || [];
286
+
238
287
  for (let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
239
288
  const nodeDef = nodeDefs[nodeIndex];
240
- if (nodeDef.extensions && nodeDef.extensions[this.name] && nodeDef.extensions[this.name].light !== void 0) {
289
+
290
+ if (nodeDef.extensions && nodeDef.extensions[this.name] && nodeDef.extensions[this.name].light !== undefined) {
241
291
  parser._addNodeRef(this.cache, nodeDef.extensions[this.name].light);
242
292
  }
243
293
  }
244
294
  }
295
+
245
296
  _loadLight(lightIndex) {
246
297
  const parser = this.parser;
247
- const cacheKey = "light:" + lightIndex;
298
+ const cacheKey = 'light:' + lightIndex;
248
299
  let dependency = parser.cache.get(cacheKey);
249
- if (dependency)
250
- return dependency;
300
+ if (dependency) return dependency;
251
301
  const json = parser.json;
252
302
  const extensions = json.extensions && json.extensions[this.name] || {};
253
303
  const lightDefs = extensions.lights || [];
254
304
  const lightDef = lightDefs[lightIndex];
255
305
  let lightNode;
256
- const color = new THREE.Color(16777215);
257
- if (lightDef.color !== void 0)
258
- color.fromArray(lightDef.color);
259
- const range = lightDef.range !== void 0 ? lightDef.range : 0;
306
+ const color = new Color(0xffffff);
307
+ if (lightDef.color !== undefined) color.fromArray(lightDef.color);
308
+ const range = lightDef.range !== undefined ? lightDef.range : 0;
309
+
260
310
  switch (lightDef.type) {
261
- case "directional":
262
- lightNode = new THREE.DirectionalLight(color);
311
+ case 'directional':
312
+ lightNode = new DirectionalLight(color);
263
313
  lightNode.target.position.set(0, 0, -1);
264
314
  lightNode.add(lightNode.target);
265
315
  break;
266
- case "point":
267
- lightNode = new THREE.PointLight(color);
316
+
317
+ case 'point':
318
+ lightNode = new PointLight(color);
268
319
  lightNode.distance = range;
269
320
  break;
270
- case "spot":
271
- lightNode = new THREE.SpotLight(color);
272
- lightNode.distance = range;
321
+
322
+ case 'spot':
323
+ lightNode = new SpotLight(color);
324
+ lightNode.distance = range; // Handle spotlight properties.
325
+
273
326
  lightDef.spot = lightDef.spot || {};
274
- lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== void 0 ? lightDef.spot.innerConeAngle : 0;
275
- lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== void 0 ? lightDef.spot.outerConeAngle : Math.PI / 4;
327
+ lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
328
+ lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
276
329
  lightNode.angle = lightDef.spot.outerConeAngle;
277
- lightNode.penumbra = 1 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
330
+ lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
278
331
  lightNode.target.position.set(0, 0, -1);
279
332
  lightNode.add(lightNode.target);
280
333
  break;
334
+
281
335
  default:
282
- throw new Error("THREE.GLTFLoader: Unexpected light type: " + lightDef.type);
283
- }
336
+ throw new Error('THREE.GLTFLoader: Unexpected light type: ' + lightDef.type);
337
+ } // Some lights (e.g. spot) default to a position other than the origin. Reset the position
338
+ // here, because node-level parsing will only override position if explicitly specified.
339
+
340
+
284
341
  lightNode.position.set(0, 0, 0);
285
342
  lightNode.decay = 2;
286
- if (lightDef.intensity !== void 0)
287
- lightNode.intensity = lightDef.intensity;
288
- lightNode.name = parser.createUniqueName(lightDef.name || "light_" + lightIndex);
343
+ if (lightDef.intensity !== undefined) lightNode.intensity = lightDef.intensity;
344
+ lightNode.name = parser.createUniqueName(lightDef.name || 'light_' + lightIndex);
289
345
  dependency = Promise.resolve(lightNode);
290
346
  parser.cache.add(cacheKey, dependency);
291
347
  return dependency;
292
348
  }
349
+
293
350
  createNodeAttachment(nodeIndex) {
294
- const self2 = this;
351
+ const self = this;
295
352
  const parser = this.parser;
296
353
  const json = parser.json;
297
354
  const nodeDef = json.nodes[nodeIndex];
298
355
  const lightDef = nodeDef.extensions && nodeDef.extensions[this.name] || {};
299
356
  const lightIndex = lightDef.light;
300
- if (lightIndex === void 0)
301
- return null;
302
- return this._loadLight(lightIndex).then(function(light) {
303
- return parser._getNodeRef(self2.cache, lightIndex, light);
357
+ if (lightIndex === undefined) return null;
358
+ return this._loadLight(lightIndex).then(function (light) {
359
+ return parser._getNodeRef(self.cache, lightIndex, light);
304
360
  });
305
361
  }
362
+
306
363
  }
364
+ /**
365
+ * Unlit Materials Extension
366
+ *
367
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
368
+ */
369
+
370
+
307
371
  class GLTFMaterialsUnlitExtension {
308
372
  constructor() {
309
373
  this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
310
374
  }
375
+
311
376
  getMaterialType() {
312
- return THREE.MeshBasicMaterial;
377
+ return MeshBasicMaterial;
313
378
  }
379
+
314
380
  extendParams(materialParams, materialDef, parser) {
315
381
  const pending = [];
316
- materialParams.color = new THREE.Color(1, 1, 1);
317
- materialParams.opacity = 1;
382
+ materialParams.color = new Color(1.0, 1.0, 1.0);
383
+ materialParams.opacity = 1.0;
318
384
  const metallicRoughness = materialDef.pbrMetallicRoughness;
385
+
319
386
  if (metallicRoughness) {
320
387
  if (Array.isArray(metallicRoughness.baseColorFactor)) {
321
388
  const array = metallicRoughness.baseColorFactor;
322
389
  materialParams.color.fromArray(array);
323
390
  materialParams.opacity = array[3];
324
391
  }
325
- if (metallicRoughness.baseColorTexture !== void 0) {
326
- pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture));
392
+
393
+ if (metallicRoughness.baseColorTexture !== undefined) {
394
+ pending.push(parser.assignTexture(materialParams, 'map', metallicRoughness.baseColorTexture));
327
395
  }
328
396
  }
397
+
329
398
  return Promise.all(pending);
330
399
  }
400
+
331
401
  }
402
+ /**
403
+ * Clearcoat Materials Extension
404
+ *
405
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat
406
+ */
407
+
408
+
332
409
  class GLTFMaterialsClearcoatExtension {
333
410
  constructor(parser) {
334
411
  this.parser = parser;
335
412
  this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
336
413
  }
414
+
337
415
  getMaterialType(materialIndex) {
338
416
  const parser = this.parser;
339
417
  const materialDef = parser.json.materials[materialIndex];
340
- if (!materialDef.extensions || !materialDef.extensions[this.name])
341
- return null;
342
- return THREE.MeshPhysicalMaterial;
418
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
419
+ return MeshPhysicalMaterial;
343
420
  }
421
+
344
422
  extendMaterialParams(materialIndex, materialParams) {
345
423
  const parser = this.parser;
346
424
  const materialDef = parser.json.materials[materialIndex];
425
+
347
426
  if (!materialDef.extensions || !materialDef.extensions[this.name]) {
348
427
  return Promise.resolve();
349
428
  }
429
+
350
430
  const pending = [];
351
431
  const extension = materialDef.extensions[this.name];
352
- if (extension.clearcoatFactor !== void 0) {
432
+
433
+ if (extension.clearcoatFactor !== undefined) {
353
434
  materialParams.clearcoat = extension.clearcoatFactor;
354
435
  }
355
- if (extension.clearcoatTexture !== void 0) {
356
- pending.push(parser.assignTexture(materialParams, "clearcoatMap", extension.clearcoatTexture));
436
+
437
+ if (extension.clearcoatTexture !== undefined) {
438
+ pending.push(parser.assignTexture(materialParams, 'clearcoatMap', extension.clearcoatTexture));
357
439
  }
358
- if (extension.clearcoatRoughnessFactor !== void 0) {
440
+
441
+ if (extension.clearcoatRoughnessFactor !== undefined) {
359
442
  materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor;
360
443
  }
361
- if (extension.clearcoatRoughnessTexture !== void 0) {
362
- pending.push(parser.assignTexture(materialParams, "clearcoatRoughnessMap", extension.clearcoatRoughnessTexture));
444
+
445
+ if (extension.clearcoatRoughnessTexture !== undefined) {
446
+ pending.push(parser.assignTexture(materialParams, 'clearcoatRoughnessMap', extension.clearcoatRoughnessTexture));
363
447
  }
364
- if (extension.clearcoatNormalTexture !== void 0) {
365
- pending.push(parser.assignTexture(materialParams, "clearcoatNormalMap", extension.clearcoatNormalTexture));
366
- if (extension.clearcoatNormalTexture.scale !== void 0) {
448
+
449
+ if (extension.clearcoatNormalTexture !== undefined) {
450
+ pending.push(parser.assignTexture(materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture));
451
+
452
+ if (extension.clearcoatNormalTexture.scale !== undefined) {
367
453
  const scale = extension.clearcoatNormalTexture.scale;
368
- materialParams.clearcoatNormalScale = new THREE.Vector2(scale, scale);
454
+ materialParams.clearcoatNormalScale = new Vector2(scale, scale);
369
455
  }
370
456
  }
457
+
371
458
  return Promise.all(pending);
372
459
  }
460
+
373
461
  }
462
+ /**
463
+ * Sheen Materials Extension
464
+ *
465
+ * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
466
+ */
467
+
468
+
374
469
  class GLTFMaterialsSheenExtension {
375
470
  constructor(parser) {
376
471
  this.parser = parser;
377
472
  this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
378
473
  }
474
+
379
475
  getMaterialType(materialIndex) {
380
476
  const parser = this.parser;
381
477
  const materialDef = parser.json.materials[materialIndex];
382
- if (!materialDef.extensions || !materialDef.extensions[this.name])
383
- return null;
384
- return THREE.MeshPhysicalMaterial;
478
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
479
+ return MeshPhysicalMaterial;
385
480
  }
481
+
386
482
  extendMaterialParams(materialIndex, materialParams) {
387
483
  const parser = this.parser;
388
484
  const materialDef = parser.json.materials[materialIndex];
485
+
389
486
  if (!materialDef.extensions || !materialDef.extensions[this.name]) {
390
487
  return Promise.resolve();
391
488
  }
489
+
392
490
  const pending = [];
393
- materialParams.sheenColor = new THREE.Color(0, 0, 0);
491
+ materialParams.sheenColor = new Color(0, 0, 0);
394
492
  materialParams.sheenRoughness = 0;
395
493
  materialParams.sheen = 1;
396
494
  const extension = materialDef.extensions[this.name];
397
- if (extension.sheenColorFactor !== void 0) {
495
+
496
+ if (extension.sheenColorFactor !== undefined) {
398
497
  materialParams.sheenColor.fromArray(extension.sheenColorFactor);
399
498
  }
400
- if (extension.sheenRoughnessFactor !== void 0) {
499
+
500
+ if (extension.sheenRoughnessFactor !== undefined) {
401
501
  materialParams.sheenRoughness = extension.sheenRoughnessFactor;
402
502
  }
403
- if (extension.sheenColorTexture !== void 0) {
404
- pending.push(parser.assignTexture(materialParams, "sheenColorMap", extension.sheenColorTexture));
503
+
504
+ if (extension.sheenColorTexture !== undefined) {
505
+ pending.push(parser.assignTexture(materialParams, 'sheenColorMap', extension.sheenColorTexture));
405
506
  }
406
- if (extension.sheenRoughnessTexture !== void 0) {
407
- pending.push(parser.assignTexture(materialParams, "sheenRoughnessMap", extension.sheenRoughnessTexture));
507
+
508
+ if (extension.sheenRoughnessTexture !== undefined) {
509
+ pending.push(parser.assignTexture(materialParams, 'sheenRoughnessMap', extension.sheenRoughnessTexture));
408
510
  }
511
+
409
512
  return Promise.all(pending);
410
513
  }
514
+
411
515
  }
516
+ /**
517
+ * Transmission Materials Extension
518
+ *
519
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission
520
+ * Draft: https://github.com/KhronosGroup/glTF/pull/1698
521
+ */
522
+
523
+
412
524
  class GLTFMaterialsTransmissionExtension {
413
525
  constructor(parser) {
414
526
  this.parser = parser;
415
527
  this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION;
416
528
  }
529
+
417
530
  getMaterialType(materialIndex) {
418
531
  const parser = this.parser;
419
532
  const materialDef = parser.json.materials[materialIndex];
420
- if (!materialDef.extensions || !materialDef.extensions[this.name])
421
- return null;
422
- return THREE.MeshPhysicalMaterial;
533
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
534
+ return MeshPhysicalMaterial;
423
535
  }
536
+
424
537
  extendMaterialParams(materialIndex, materialParams) {
425
538
  const parser = this.parser;
426
539
  const materialDef = parser.json.materials[materialIndex];
540
+
427
541
  if (!materialDef.extensions || !materialDef.extensions[this.name]) {
428
542
  return Promise.resolve();
429
543
  }
544
+
430
545
  const pending = [];
431
546
  const extension = materialDef.extensions[this.name];
432
- if (extension.transmissionFactor !== void 0) {
547
+
548
+ if (extension.transmissionFactor !== undefined) {
433
549
  materialParams.transmission = extension.transmissionFactor;
434
550
  }
435
- if (extension.transmissionTexture !== void 0) {
436
- pending.push(parser.assignTexture(materialParams, "transmissionMap", extension.transmissionTexture));
551
+
552
+ if (extension.transmissionTexture !== undefined) {
553
+ pending.push(parser.assignTexture(materialParams, 'transmissionMap', extension.transmissionTexture));
437
554
  }
555
+
438
556
  return Promise.all(pending);
439
557
  }
558
+
440
559
  }
560
+ /**
561
+ * Materials Volume Extension
562
+ *
563
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume
564
+ */
565
+
566
+
441
567
  class GLTFMaterialsVolumeExtension {
442
568
  constructor(parser) {
443
569
  this.parser = parser;
444
570
  this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
445
571
  }
572
+
446
573
  getMaterialType(materialIndex) {
447
574
  const parser = this.parser;
448
575
  const materialDef = parser.json.materials[materialIndex];
449
- if (!materialDef.extensions || !materialDef.extensions[this.name])
450
- return null;
451
- return THREE.MeshPhysicalMaterial;
576
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
577
+ return MeshPhysicalMaterial;
452
578
  }
579
+
453
580
  extendMaterialParams(materialIndex, materialParams) {
454
581
  const parser = this.parser;
455
582
  const materialDef = parser.json.materials[materialIndex];
583
+
456
584
  if (!materialDef.extensions || !materialDef.extensions[this.name]) {
457
585
  return Promise.resolve();
458
586
  }
587
+
459
588
  const pending = [];
460
589
  const extension = materialDef.extensions[this.name];
461
- materialParams.thickness = extension.thicknessFactor !== void 0 ? extension.thicknessFactor : 0;
462
- if (extension.thicknessTexture !== void 0) {
463
- pending.push(parser.assignTexture(materialParams, "thicknessMap", extension.thicknessTexture));
590
+ materialParams.thickness = extension.thicknessFactor !== undefined ? extension.thicknessFactor : 0;
591
+
592
+ if (extension.thicknessTexture !== undefined) {
593
+ pending.push(parser.assignTexture(materialParams, 'thicknessMap', extension.thicknessTexture));
464
594
  }
595
+
465
596
  materialParams.attenuationDistance = extension.attenuationDistance || 0;
466
597
  const colorArray = extension.attenuationColor || [1, 1, 1];
467
- materialParams.attenuationColor = new THREE.Color(colorArray[0], colorArray[1], colorArray[2]);
598
+ materialParams.attenuationColor = new Color(colorArray[0], colorArray[1], colorArray[2]);
468
599
  return Promise.all(pending);
469
600
  }
601
+
470
602
  }
603
+ /**
604
+ * Materials ior Extension
605
+ *
606
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior
607
+ */
608
+
609
+
471
610
  class GLTFMaterialsIorExtension {
472
611
  constructor(parser) {
473
612
  this.parser = parser;
474
613
  this.name = EXTENSIONS.KHR_MATERIALS_IOR;
475
614
  }
615
+
476
616
  getMaterialType(materialIndex) {
477
617
  const parser = this.parser;
478
618
  const materialDef = parser.json.materials[materialIndex];
479
- if (!materialDef.extensions || !materialDef.extensions[this.name])
480
- return null;
481
- return THREE.MeshPhysicalMaterial;
619
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
620
+ return MeshPhysicalMaterial;
482
621
  }
622
+
483
623
  extendMaterialParams(materialIndex, materialParams) {
484
624
  const parser = this.parser;
485
625
  const materialDef = parser.json.materials[materialIndex];
626
+
486
627
  if (!materialDef.extensions || !materialDef.extensions[this.name]) {
487
628
  return Promise.resolve();
488
629
  }
630
+
489
631
  const extension = materialDef.extensions[this.name];
490
- materialParams.ior = extension.ior !== void 0 ? extension.ior : 1.5;
632
+ materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5;
491
633
  return Promise.resolve();
492
634
  }
635
+
493
636
  }
637
+ /**
638
+ * Materials specular Extension
639
+ *
640
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular
641
+ */
642
+
643
+
494
644
  class GLTFMaterialsSpecularExtension {
495
645
  constructor(parser) {
496
646
  this.parser = parser;
497
647
  this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
498
648
  }
649
+
499
650
  getMaterialType(materialIndex) {
500
651
  const parser = this.parser;
501
652
  const materialDef = parser.json.materials[materialIndex];
502
- if (!materialDef.extensions || !materialDef.extensions[this.name])
503
- return null;
504
- return THREE.MeshPhysicalMaterial;
653
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
654
+ return MeshPhysicalMaterial;
505
655
  }
656
+
506
657
  extendMaterialParams(materialIndex, materialParams) {
507
658
  const parser = this.parser;
508
659
  const materialDef = parser.json.materials[materialIndex];
660
+
509
661
  if (!materialDef.extensions || !materialDef.extensions[this.name]) {
510
662
  return Promise.resolve();
511
663
  }
664
+
512
665
  const pending = [];
513
666
  const extension = materialDef.extensions[this.name];
514
- materialParams.specularIntensity = extension.specularFactor !== void 0 ? extension.specularFactor : 1;
515
- if (extension.specularTexture !== void 0) {
516
- pending.push(parser.assignTexture(materialParams, "specularIntensityMap", extension.specularTexture));
667
+ materialParams.specularIntensity = extension.specularFactor !== undefined ? extension.specularFactor : 1.0;
668
+
669
+ if (extension.specularTexture !== undefined) {
670
+ pending.push(parser.assignTexture(materialParams, 'specularIntensityMap', extension.specularTexture));
517
671
  }
672
+
518
673
  const colorArray = extension.specularColorFactor || [1, 1, 1];
519
- materialParams.specularColor = new THREE.Color(colorArray[0], colorArray[1], colorArray[2]);
520
- if (extension.specularColorTexture !== void 0) {
521
- pending.push(
522
- parser.assignTexture(materialParams, "specularColorMap", extension.specularColorTexture).then(function(texture) {
523
- texture.encoding = THREE.sRGBEncoding;
524
- })
525
- );
526
- }
674
+ materialParams.specularColor = new Color(colorArray[0], colorArray[1], colorArray[2]);
675
+
676
+ if (extension.specularColorTexture !== undefined) {
677
+ pending.push(parser.assignTexture(materialParams, 'specularColorMap', extension.specularColorTexture).then(function (texture) {
678
+ texture.encoding = sRGBEncoding;
679
+ }));
680
+ }
681
+
527
682
  return Promise.all(pending);
528
683
  }
684
+
529
685
  }
686
+ /**
687
+ * BasisU Texture Extension
688
+ *
689
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu
690
+ */
691
+
692
+
530
693
  class GLTFTextureBasisUExtension {
531
694
  constructor(parser) {
532
695
  this.parser = parser;
533
696
  this.name = EXTENSIONS.KHR_TEXTURE_BASISU;
534
697
  }
698
+
535
699
  loadTexture(textureIndex) {
536
700
  const parser = this.parser;
537
701
  const json = parser.json;
538
702
  const textureDef = json.textures[textureIndex];
703
+
539
704
  if (!textureDef.extensions || !textureDef.extensions[this.name]) {
540
705
  return null;
541
706
  }
707
+
542
708
  const extension = textureDef.extensions[this.name];
543
709
  const source = json.images[extension.source];
544
710
  const loader = parser.options.ktx2Loader;
711
+
545
712
  if (!loader) {
546
713
  if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) {
547
- throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");
714
+ throw new Error('THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures');
548
715
  } else {
716
+ // Assumes that the extension is optional and that a fallback texture is present
549
717
  return null;
550
718
  }
551
719
  }
720
+
552
721
  return parser.loadTextureImage(textureIndex, source, loader);
553
722
  }
723
+
554
724
  }
725
+ /**
726
+ * WebP Texture Extension
727
+ *
728
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_webp
729
+ */
730
+
731
+
555
732
  class GLTFTextureWebPExtension {
556
733
  constructor(parser) {
557
734
  this.parser = parser;
558
735
  this.name = EXTENSIONS.EXT_TEXTURE_WEBP;
559
736
  this.isSupported = null;
560
737
  }
738
+
561
739
  loadTexture(textureIndex) {
562
740
  const name = this.name;
563
741
  const parser = this.parser;
564
742
  const json = parser.json;
565
743
  const textureDef = json.textures[textureIndex];
744
+
566
745
  if (!textureDef.extensions || !textureDef.extensions[name]) {
567
746
  return null;
568
747
  }
748
+
569
749
  const extension = textureDef.extensions[name];
570
750
  const source = json.images[extension.source];
571
751
  let loader = parser.textureLoader;
752
+
572
753
  if (source.uri) {
573
754
  const handler = parser.options.manager.getHandler(source.uri);
574
- if (handler !== null)
575
- loader = handler;
755
+ if (handler !== null) loader = handler;
576
756
  }
577
- return this.detectSupport().then(function(isSupported) {
578
- if (isSupported)
579
- return parser.loadTextureImage(textureIndex, source, loader);
757
+
758
+ return this.detectSupport().then(function (isSupported) {
759
+ if (isSupported) return parser.loadTextureImage(textureIndex, source, loader);
760
+
580
761
  if (json.extensionsRequired && json.extensionsRequired.indexOf(name) >= 0) {
581
- throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");
582
- }
762
+ throw new Error('THREE.GLTFLoader: WebP required by asset but unsupported.');
763
+ } // Fall back to PNG or JPEG.
764
+
765
+
583
766
  return parser.loadTexture(textureIndex);
584
767
  });
585
768
  }
769
+
586
770
  detectSupport() {
587
771
  if (!this.isSupported) {
588
- this.isSupported = new Promise(function(resolve) {
589
- const image = new Image();
590
- image.src = "data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA";
591
- image.onload = image.onerror = function() {
772
+ this.isSupported = new Promise(function (resolve) {
773
+ const image = new Image(); // Lossy test image. Support for lossy images doesn't guarantee support for all
774
+ // WebP images, unfortunately.
775
+
776
+ image.src = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA';
777
+
778
+ image.onload = image.onerror = function () {
592
779
  resolve(image.height === 1);
593
780
  };
594
781
  });
595
782
  }
783
+
596
784
  return this.isSupported;
597
785
  }
786
+
598
787
  }
788
+ /**
789
+ * meshopt BufferView Compression Extension
790
+ *
791
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression
792
+ */
793
+
794
+
599
795
  class GLTFMeshoptCompression {
600
796
  constructor(parser) {
601
797
  this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION;
602
798
  this.parser = parser;
603
799
  }
800
+
604
801
  loadBufferView(index) {
605
802
  const json = this.parser.json;
606
803
  const bufferView = json.bufferViews[index];
804
+
607
805
  if (bufferView.extensions && bufferView.extensions[this.name]) {
608
806
  const extensionDef = bufferView.extensions[this.name];
609
- const buffer = this.parser.getDependency("buffer", extensionDef.buffer);
807
+ const buffer = this.parser.getDependency('buffer', extensionDef.buffer);
610
808
  const decoder = this.parser.options.meshoptDecoder;
809
+
611
810
  if (!decoder || !decoder.supported) {
612
811
  if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) {
613
- throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");
812
+ throw new Error('THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files');
614
813
  } else {
814
+ // Assumes that the extension is optional and that fallback buffer data is present
615
815
  return null;
616
816
  }
617
817
  }
618
- return Promise.all([buffer, decoder.ready]).then(function(res) {
818
+
819
+ return Promise.all([buffer, decoder.ready]).then(function (res) {
619
820
  const byteOffset = extensionDef.byteOffset || 0;
620
821
  const byteLength = extensionDef.byteLength || 0;
621
822
  const count = extensionDef.count;
@@ -629,10 +830,18 @@ class GLTFMeshoptCompression {
629
830
  return null;
630
831
  }
631
832
  }
833
+
632
834
  }
633
- const BINARY_EXTENSION_HEADER_MAGIC = "glTF";
835
+ /* BINARY EXTENSION */
836
+
837
+
838
+ const BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
634
839
  const BINARY_EXTENSION_HEADER_LENGTH = 12;
635
- const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 1313821514, BIN: 5130562 };
840
+ const BINARY_EXTENSION_CHUNK_TYPES = {
841
+ JSON: 0x4e4f534a,
842
+ BIN: 0x004e4942
843
+ };
844
+
636
845
  class GLTFBinaryExtension {
637
846
  constructor(data) {
638
847
  this.name = EXTENSIONS.KHR_BINARY_GLTF;
@@ -640,47 +849,64 @@ class GLTFBinaryExtension {
640
849
  this.body = null;
641
850
  const headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
642
851
  this.header = {
643
- magic: THREE.LoaderUtils.decodeText(new Uint8Array(data.slice(0, 4))),
852
+ magic: LoaderUtils.decodeText(new Uint8Array(data.slice(0, 4))),
644
853
  version: headerView.getUint32(4, true),
645
854
  length: headerView.getUint32(8, true)
646
855
  };
856
+
647
857
  if (this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
648
- throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");
649
- } else if (this.header.version < 2) {
650
- throw new Error("THREE.GLTFLoader: Legacy binary file detected.");
858
+ throw new Error('THREE.GLTFLoader: Unsupported glTF-Binary header.');
859
+ } else if (this.header.version < 2.0) {
860
+ throw new Error('THREE.GLTFLoader: Legacy binary file detected.');
651
861
  }
862
+
652
863
  const chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH;
653
864
  const chunkView = new DataView(data, BINARY_EXTENSION_HEADER_LENGTH);
654
865
  let chunkIndex = 0;
866
+
655
867
  while (chunkIndex < chunkContentsLength) {
656
868
  const chunkLength = chunkView.getUint32(chunkIndex, true);
657
869
  chunkIndex += 4;
658
870
  const chunkType = chunkView.getUint32(chunkIndex, true);
659
871
  chunkIndex += 4;
872
+
660
873
  if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
661
874
  const contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
662
- this.content = THREE.LoaderUtils.decodeText(contentArray);
875
+ this.content = LoaderUtils.decodeText(contentArray);
663
876
  } else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
664
877
  const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
665
878
  this.body = data.slice(byteOffset, byteOffset + chunkLength);
666
- }
879
+ } // Clients must ignore chunks with unknown types.
880
+
881
+
667
882
  chunkIndex += chunkLength;
668
883
  }
884
+
669
885
  if (this.content === null) {
670
- throw new Error("THREE.GLTFLoader: JSON content not found.");
886
+ throw new Error('THREE.GLTFLoader: JSON content not found.');
671
887
  }
672
888
  }
889
+
673
890
  }
891
+ /**
892
+ * DRACO Mesh Compression Extension
893
+ *
894
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
895
+ */
896
+
897
+
674
898
  class GLTFDracoMeshCompressionExtension {
675
899
  constructor(json, dracoLoader) {
676
900
  if (!dracoLoader) {
677
- throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
901
+ throw new Error('THREE.GLTFLoader: No DRACOLoader instance provided.');
678
902
  }
903
+
679
904
  this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
680
905
  this.json = json;
681
906
  this.dracoLoader = dracoLoader;
682
907
  this.dracoLoader.preload();
683
908
  }
909
+
684
910
  decodePrimitive(primitive, parser) {
685
911
  const json = this.json;
686
912
  const dracoLoader = this.dracoLoader;
@@ -689,154 +915,168 @@ class GLTFDracoMeshCompressionExtension {
689
915
  const threeAttributeMap = {};
690
916
  const attributeNormalizedMap = {};
691
917
  const attributeTypeMap = {};
918
+
692
919
  for (const attributeName in gltfAttributeMap) {
693
920
  const threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase();
694
921
  threeAttributeMap[threeAttributeName] = gltfAttributeMap[attributeName];
695
922
  }
923
+
696
924
  for (const attributeName in primitive.attributes) {
697
925
  const threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase();
698
- if (gltfAttributeMap[attributeName] !== void 0) {
926
+
927
+ if (gltfAttributeMap[attributeName] !== undefined) {
699
928
  const accessorDef = json.accessors[primitive.attributes[attributeName]];
700
929
  const componentType = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
701
930
  attributeTypeMap[threeAttributeName] = componentType;
702
931
  attributeNormalizedMap[threeAttributeName] = accessorDef.normalized === true;
703
932
  }
704
933
  }
705
- return parser.getDependency("bufferView", bufferViewIndex).then(function(bufferView) {
706
- return new Promise(function(resolve) {
707
- dracoLoader.decodeDracoFile(
708
- bufferView,
709
- function(geometry) {
710
- for (const attributeName in geometry.attributes) {
711
- const attribute = geometry.attributes[attributeName];
712
- const normalized = attributeNormalizedMap[attributeName];
713
- if (normalized !== void 0)
714
- attribute.normalized = normalized;
715
- }
716
- resolve(geometry);
717
- },
718
- threeAttributeMap,
719
- attributeTypeMap
720
- );
934
+
935
+ return parser.getDependency('bufferView', bufferViewIndex).then(function (bufferView) {
936
+ return new Promise(function (resolve) {
937
+ dracoLoader.decodeDracoFile(bufferView, function (geometry) {
938
+ for (const attributeName in geometry.attributes) {
939
+ const attribute = geometry.attributes[attributeName];
940
+ const normalized = attributeNormalizedMap[attributeName];
941
+ if (normalized !== undefined) attribute.normalized = normalized;
942
+ }
943
+
944
+ resolve(geometry);
945
+ }, threeAttributeMap, attributeTypeMap);
721
946
  });
722
947
  });
723
948
  }
949
+
724
950
  }
951
+ /**
952
+ * Texture Transform Extension
953
+ *
954
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform
955
+ */
956
+
957
+
725
958
  class GLTFTextureTransformExtension {
726
959
  constructor() {
727
960
  this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
728
961
  }
962
+
729
963
  extendTexture(texture, transform) {
730
- if (transform.texCoord !== void 0) {
964
+ if (transform.texCoord !== undefined) {
731
965
  console.warn('THREE.GLTFLoader: Custom UV sets in "' + this.name + '" extension not yet supported.');
732
966
  }
733
- if (transform.offset === void 0 && transform.rotation === void 0 && transform.scale === void 0) {
967
+
968
+ if (transform.offset === undefined && transform.rotation === undefined && transform.scale === undefined) {
969
+ // See https://github.com/mrdoob/three.js/issues/21819.
734
970
  return texture;
735
971
  }
972
+
736
973
  texture = texture.clone();
737
- if (transform.offset !== void 0) {
974
+
975
+ if (transform.offset !== undefined) {
738
976
  texture.offset.fromArray(transform.offset);
739
977
  }
740
- if (transform.rotation !== void 0) {
978
+
979
+ if (transform.rotation !== undefined) {
741
980
  texture.rotation = transform.rotation;
742
981
  }
743
- if (transform.scale !== void 0) {
982
+
983
+ if (transform.scale !== undefined) {
744
984
  texture.repeat.fromArray(transform.scale);
745
985
  }
986
+
746
987
  texture.needsUpdate = true;
747
988
  return texture;
748
989
  }
990
+
749
991
  }
750
- class GLTFMeshStandardSGMaterial extends THREE.MeshStandardMaterial {
992
+ /**
993
+ * Specular-Glossiness Extension
994
+ *
995
+ * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness
996
+ */
997
+
998
+ /**
999
+ * A sub class of StandardMaterial with some of the functionality
1000
+ * changed via the `onBeforeCompile` callback
1001
+ * @pailhead
1002
+ */
1003
+
1004
+
1005
+ class GLTFMeshStandardSGMaterial extends MeshStandardMaterial {
751
1006
  constructor(params) {
752
1007
  super();
753
- this.isGLTFSpecularGlossinessMaterial = true;
754
- const specularMapParsFragmentChunk = ["#ifdef USE_SPECULARMAP", " uniform sampler2D specularMap;", "#endif"].join(
755
- "\n"
756
- );
757
- const glossinessMapParsFragmentChunk = [
758
- "#ifdef USE_GLOSSINESSMAP",
759
- " uniform sampler2D glossinessMap;",
760
- "#endif"
761
- ].join("\n");
762
- const specularMapFragmentChunk = [
763
- "vec3 specularFactor = specular;",
764
- "#ifdef USE_SPECULARMAP",
765
- " vec4 texelSpecular = texture2D( specularMap, vUv );",
766
- " // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture",
767
- " specularFactor *= texelSpecular.rgb;",
768
- "#endif"
769
- ].join("\n");
770
- const glossinessMapFragmentChunk = [
771
- "float glossinessFactor = glossiness;",
772
- "#ifdef USE_GLOSSINESSMAP",
773
- " vec4 texelGlossiness = texture2D( glossinessMap, vUv );",
774
- " // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture",
775
- " glossinessFactor *= texelGlossiness.a;",
776
- "#endif"
777
- ].join("\n");
778
- const lightPhysicalFragmentChunk = [
779
- "PhysicalMaterial material;",
780
- "material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );",
781
- "vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );",
782
- "float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );",
783
- "material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.",
784
- "material.roughness += geometryRoughness;",
785
- "material.roughness = min( material.roughness, 1.0 );",
786
- "material.specularColor = specularFactor;"
787
- ].join("\n");
1008
+ this.isGLTFSpecularGlossinessMaterial = true; //various chunks that need replacing
1009
+
1010
+ const specularMapParsFragmentChunk = ['#ifdef USE_SPECULARMAP', ' uniform sampler2D specularMap;', '#endif'].join('\n');
1011
+ const glossinessMapParsFragmentChunk = ['#ifdef USE_GLOSSINESSMAP', ' uniform sampler2D glossinessMap;', '#endif'].join('\n');
1012
+ 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');
1013
+ 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');
1014
+ 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');
788
1015
  const uniforms = {
789
- specular: { value: new THREE.Color().setHex(16777215) },
790
- glossiness: { value: 1 },
791
- specularMap: { value: null },
792
- glossinessMap: { value: null }
1016
+ specular: {
1017
+ value: new Color().setHex(0xffffff)
1018
+ },
1019
+ glossiness: {
1020
+ value: 1
1021
+ },
1022
+ specularMap: {
1023
+ value: null
1024
+ },
1025
+ glossinessMap: {
1026
+ value: null
1027
+ }
793
1028
  };
794
1029
  this._extraUniforms = uniforms;
795
- this.onBeforeCompile = function(shader) {
1030
+
1031
+ this.onBeforeCompile = function (shader) {
796
1032
  for (const uniformName in uniforms) {
797
1033
  shader.uniforms[uniformName] = uniforms[uniformName];
798
1034
  }
799
- 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);
1035
+
1036
+ 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);
800
1037
  };
1038
+
801
1039
  Object.defineProperties(this, {
802
1040
  specular: {
803
- get: function() {
1041
+ get: function () {
804
1042
  return uniforms.specular.value;
805
1043
  },
806
- set: function(v) {
1044
+ set: function (v) {
807
1045
  uniforms.specular.value = v;
808
1046
  }
809
1047
  },
810
1048
  specularMap: {
811
- get: function() {
1049
+ get: function () {
812
1050
  return uniforms.specularMap.value;
813
1051
  },
814
- set: function(v) {
1052
+ set: function (v) {
815
1053
  uniforms.specularMap.value = v;
1054
+
816
1055
  if (v) {
817
- this.defines.USE_SPECULARMAP = "";
1056
+ this.defines.USE_SPECULARMAP = ''; // USE_UV is set by the renderer for specular maps
818
1057
  } else {
819
1058
  delete this.defines.USE_SPECULARMAP;
820
1059
  }
821
1060
  }
822
1061
  },
823
1062
  glossiness: {
824
- get: function() {
1063
+ get: function () {
825
1064
  return uniforms.glossiness.value;
826
1065
  },
827
- set: function(v) {
1066
+ set: function (v) {
828
1067
  uniforms.glossiness.value = v;
829
1068
  }
830
1069
  },
831
1070
  glossinessMap: {
832
- get: function() {
1071
+ get: function () {
833
1072
  return uniforms.glossinessMap.value;
834
1073
  },
835
- set: function(v) {
1074
+ set: function (v) {
836
1075
  uniforms.glossinessMap.value = v;
1076
+
837
1077
  if (v) {
838
- this.defines.USE_GLOSSINESSMAP = "";
839
- this.defines.USE_UV = "";
1078
+ this.defines.USE_GLOSSINESSMAP = '';
1079
+ this.defines.USE_UV = '';
840
1080
  } else {
841
1081
  delete this.defines.USE_GLOSSINESSMAP;
842
1082
  delete this.defines.USE_UV;
@@ -850,6 +1090,7 @@ class GLTFMeshStandardSGMaterial extends THREE.MeshStandardMaterial {
850
1090
  delete this.roughnessMap;
851
1091
  this.setValues(params);
852
1092
  }
1093
+
853
1094
  copy(source) {
854
1095
  super.copy(source);
855
1096
  this.specularMap = source.specularMap;
@@ -862,118 +1103,132 @@ class GLTFMeshStandardSGMaterial extends THREE.MeshStandardMaterial {
862
1103
  delete this.roughnessMap;
863
1104
  return this;
864
1105
  }
1106
+
865
1107
  }
1108
+
866
1109
  class GLTFMaterialsPbrSpecularGlossinessExtension {
867
1110
  constructor() {
868
1111
  this.name = EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS;
869
- this.specularGlossinessParams = [
870
- "color",
871
- "map",
872
- "lightMap",
873
- "lightMapIntensity",
874
- "aoMap",
875
- "aoMapIntensity",
876
- "emissive",
877
- "emissiveIntensity",
878
- "emissiveMap",
879
- "bumpMap",
880
- "bumpScale",
881
- "normalMap",
882
- "normalMapType",
883
- "displacementMap",
884
- "displacementScale",
885
- "displacementBias",
886
- "specularMap",
887
- "specular",
888
- "glossinessMap",
889
- "glossiness",
890
- "alphaMap",
891
- "envMap",
892
- "envMapIntensity",
893
- "refractionRatio"
894
- ];
1112
+ 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', 'refractionRatio'];
895
1113
  }
1114
+
896
1115
  getMaterialType() {
897
1116
  return GLTFMeshStandardSGMaterial;
898
1117
  }
1118
+
899
1119
  extendParams(materialParams, materialDef, parser) {
900
1120
  const pbrSpecularGlossiness = materialDef.extensions[this.name];
901
- materialParams.color = new THREE.Color(1, 1, 1);
902
- materialParams.opacity = 1;
1121
+ materialParams.color = new Color(1.0, 1.0, 1.0);
1122
+ materialParams.opacity = 1.0;
903
1123
  const pending = [];
1124
+
904
1125
  if (Array.isArray(pbrSpecularGlossiness.diffuseFactor)) {
905
1126
  const array = pbrSpecularGlossiness.diffuseFactor;
906
1127
  materialParams.color.fromArray(array);
907
1128
  materialParams.opacity = array[3];
908
1129
  }
909
- if (pbrSpecularGlossiness.diffuseTexture !== void 0) {
910
- pending.push(parser.assignTexture(materialParams, "map", pbrSpecularGlossiness.diffuseTexture));
1130
+
1131
+ if (pbrSpecularGlossiness.diffuseTexture !== undefined) {
1132
+ pending.push(parser.assignTexture(materialParams, 'map', pbrSpecularGlossiness.diffuseTexture));
911
1133
  }
912
- materialParams.emissive = new THREE.Color(0, 0, 0);
913
- materialParams.glossiness = pbrSpecularGlossiness.glossinessFactor !== void 0 ? pbrSpecularGlossiness.glossinessFactor : 1;
914
- materialParams.specular = new THREE.Color(1, 1, 1);
1134
+
1135
+ materialParams.emissive = new Color(0.0, 0.0, 0.0);
1136
+ materialParams.glossiness = pbrSpecularGlossiness.glossinessFactor !== undefined ? pbrSpecularGlossiness.glossinessFactor : 1.0;
1137
+ materialParams.specular = new Color(1.0, 1.0, 1.0);
1138
+
915
1139
  if (Array.isArray(pbrSpecularGlossiness.specularFactor)) {
916
1140
  materialParams.specular.fromArray(pbrSpecularGlossiness.specularFactor);
917
1141
  }
918
- if (pbrSpecularGlossiness.specularGlossinessTexture !== void 0) {
1142
+
1143
+ if (pbrSpecularGlossiness.specularGlossinessTexture !== undefined) {
919
1144
  const specGlossMapDef = pbrSpecularGlossiness.specularGlossinessTexture;
920
- pending.push(parser.assignTexture(materialParams, "glossinessMap", specGlossMapDef));
921
- pending.push(parser.assignTexture(materialParams, "specularMap", specGlossMapDef));
1145
+ pending.push(parser.assignTexture(materialParams, 'glossinessMap', specGlossMapDef));
1146
+ pending.push(parser.assignTexture(materialParams, 'specularMap', specGlossMapDef));
922
1147
  }
1148
+
923
1149
  return Promise.all(pending);
924
1150
  }
1151
+
925
1152
  createMaterial(materialParams) {
926
1153
  const material = new GLTFMeshStandardSGMaterial(materialParams);
927
1154
  material.fog = true;
928
1155
  material.color = materialParams.color;
929
- material.map = materialParams.map === void 0 ? null : materialParams.map;
1156
+ material.map = materialParams.map === undefined ? null : materialParams.map;
930
1157
  material.lightMap = null;
931
- material.lightMapIntensity = 1;
932
- material.aoMap = materialParams.aoMap === void 0 ? null : materialParams.aoMap;
933
- material.aoMapIntensity = 1;
1158
+ material.lightMapIntensity = 1.0;
1159
+ material.aoMap = materialParams.aoMap === undefined ? null : materialParams.aoMap;
1160
+ material.aoMapIntensity = 1.0;
934
1161
  material.emissive = materialParams.emissive;
935
- material.emissiveIntensity = 1;
936
- material.emissiveMap = materialParams.emissiveMap === void 0 ? null : materialParams.emissiveMap;
937
- material.bumpMap = materialParams.bumpMap === void 0 ? null : materialParams.bumpMap;
1162
+ material.emissiveIntensity = 1.0;
1163
+ material.emissiveMap = materialParams.emissiveMap === undefined ? null : materialParams.emissiveMap;
1164
+ material.bumpMap = materialParams.bumpMap === undefined ? null : materialParams.bumpMap;
938
1165
  material.bumpScale = 1;
939
- material.normalMap = materialParams.normalMap === void 0 ? null : materialParams.normalMap;
940
- material.normalMapType = THREE.TangentSpaceNormalMap;
941
- if (materialParams.normalScale)
942
- material.normalScale = materialParams.normalScale;
1166
+ material.normalMap = materialParams.normalMap === undefined ? null : materialParams.normalMap;
1167
+ material.normalMapType = TangentSpaceNormalMap;
1168
+ if (materialParams.normalScale) material.normalScale = materialParams.normalScale;
943
1169
  material.displacementMap = null;
944
1170
  material.displacementScale = 1;
945
1171
  material.displacementBias = 0;
946
- material.specularMap = materialParams.specularMap === void 0 ? null : materialParams.specularMap;
1172
+ material.specularMap = materialParams.specularMap === undefined ? null : materialParams.specularMap;
947
1173
  material.specular = materialParams.specular;
948
- material.glossinessMap = materialParams.glossinessMap === void 0 ? null : materialParams.glossinessMap;
1174
+ material.glossinessMap = materialParams.glossinessMap === undefined ? null : materialParams.glossinessMap;
949
1175
  material.glossiness = materialParams.glossiness;
950
1176
  material.alphaMap = null;
951
- material.envMap = materialParams.envMap === void 0 ? null : materialParams.envMap;
952
- material.envMapIntensity = 1;
1177
+ material.envMap = materialParams.envMap === undefined ? null : materialParams.envMap;
1178
+ material.envMapIntensity = 1.0;
953
1179
  material.refractionRatio = 0.98;
954
1180
  return material;
955
1181
  }
1182
+
956
1183
  }
1184
+ /**
1185
+ * Mesh Quantization Extension
1186
+ *
1187
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization
1188
+ */
1189
+
1190
+
957
1191
  class GLTFMeshQuantizationExtension {
958
1192
  constructor() {
959
1193
  this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
960
1194
  }
1195
+
961
1196
  }
962
- class GLTFCubicSplineInterpolant extends THREE.Interpolant {
1197
+ /*********************************/
1198
+
1199
+ /********** INTERPOLATION ********/
1200
+
1201
+ /*********************************/
1202
+ // Spline Interpolation
1203
+ // Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-c-spline-interpolation
1204
+
1205
+
1206
+ class GLTFCubicSplineInterpolant extends Interpolant {
963
1207
  constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) {
964
1208
  super(parameterPositions, sampleValues, sampleSize, resultBuffer);
965
1209
  }
1210
+
966
1211
  copySampleValue_(index) {
967
- const result = this.resultBuffer, values = this.sampleValues, valueSize = this.valueSize, offset = index * valueSize * 3 + valueSize;
1212
+ // Copies a sample value to the result buffer. See description of glTF
1213
+ // CUBICSPLINE values layout in interpolate_() function below.
1214
+ const result = this.resultBuffer,
1215
+ values = this.sampleValues,
1216
+ valueSize = this.valueSize,
1217
+ offset = index * valueSize * 3 + valueSize;
1218
+
968
1219
  for (let i = 0; i !== valueSize; i++) {
969
1220
  result[i] = values[offset + i];
970
1221
  }
1222
+
971
1223
  return result;
972
1224
  }
1225
+
973
1226
  }
1227
+
974
1228
  GLTFCubicSplineInterpolant.prototype.beforeStart_ = GLTFCubicSplineInterpolant.prototype.copySampleValue_;
975
1229
  GLTFCubicSplineInterpolant.prototype.afterEnd_ = GLTFCubicSplineInterpolant.prototype.copySampleValue_;
976
- GLTFCubicSplineInterpolant.prototype.interpolate_ = function(i1, t0, t, t1) {
1230
+
1231
+ GLTFCubicSplineInterpolant.prototype.interpolate_ = function (i1, t0, t, t1) {
977
1232
  const result = this.resultBuffer;
978
1233
  const values = this.sampleValues;
979
1234
  const stride = this.valueSize;
@@ -988,26 +1243,48 @@ GLTFCubicSplineInterpolant.prototype.interpolate_ = function(i1, t0, t, t1) {
988
1243
  const s2 = -2 * ppp + 3 * pp;
989
1244
  const s3 = ppp - pp;
990
1245
  const s0 = 1 - s2;
991
- const s1 = s3 - pp + p;
1246
+ const s1 = s3 - pp + p; // Layout of keyframe output values for CUBICSPLINE animations:
1247
+ // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
1248
+
992
1249
  for (let i = 0; i !== stride; i++) {
993
- const p0 = values[offset0 + i + stride];
994
- const m0 = values[offset0 + i + stride2] * td;
995
- const p1 = values[offset1 + i + stride];
996
- const m1 = values[offset1 + i] * td;
1250
+ const p0 = values[offset0 + i + stride]; // splineVertex_k
1251
+
1252
+ const m0 = values[offset0 + i + stride2] * td; // outTangent_k * (t_k+1 - t_k)
1253
+
1254
+ const p1 = values[offset1 + i + stride]; // splineVertex_k+1
1255
+
1256
+ const m1 = values[offset1 + i] * td; // inTangent_k+1 * (t_k+1 - t_k)
1257
+
997
1258
  result[i] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
998
1259
  }
1260
+
999
1261
  return result;
1000
1262
  };
1001
- const _q = new THREE.Quaternion();
1263
+
1264
+ const _q = new Quaternion();
1265
+
1002
1266
  class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
1003
1267
  interpolate_(i1, t0, t, t1) {
1004
1268
  const result = super.interpolate_(i1, t0, t, t1);
1269
+
1005
1270
  _q.fromArray(result).normalize().toArray(result);
1271
+
1006
1272
  return result;
1007
1273
  }
1274
+
1008
1275
  }
1276
+ /*********************************/
1277
+
1278
+ /********** INTERNALS ************/
1279
+
1280
+ /*********************************/
1281
+
1282
+ /* CONSTANTS */
1283
+
1284
+
1009
1285
  const WEBGL_CONSTANTS = {
1010
1286
  FLOAT: 5126,
1287
+ //FLOAT_MAT2: 35674,
1011
1288
  FLOAT_MAT3: 35675,
1012
1289
  FLOAT_MAT4: 35676,
1013
1290
  FLOAT_VEC2: 35664,
@@ -1035,17 +1312,17 @@ const WEBGL_COMPONENT_TYPES = {
1035
1312
  5126: Float32Array
1036
1313
  };
1037
1314
  const WEBGL_FILTERS = {
1038
- 9728: THREE.NearestFilter,
1039
- 9729: THREE.LinearFilter,
1040
- 9984: THREE.NearestMipmapNearestFilter,
1041
- 9985: THREE.LinearMipmapNearestFilter,
1042
- 9986: THREE.NearestMipmapLinearFilter,
1043
- 9987: THREE.LinearMipmapLinearFilter
1315
+ 9728: NearestFilter,
1316
+ 9729: LinearFilter,
1317
+ 9984: NearestMipmapNearestFilter,
1318
+ 9985: LinearMipmapNearestFilter,
1319
+ 9986: NearestMipmapLinearFilter,
1320
+ 9987: LinearMipmapLinearFilter
1044
1321
  };
1045
1322
  const WEBGL_WRAPPINGS = {
1046
- 33071: THREE.ClampToEdgeWrapping,
1047
- 33648: THREE.MirroredRepeatWrapping,
1048
- 10497: THREE.RepeatWrapping
1323
+ 33071: ClampToEdgeWrapping,
1324
+ 33648: MirroredRepeatWrapping,
1325
+ 10497: RepeatWrapping
1049
1326
  };
1050
1327
  const WEBGL_TYPE_SIZES = {
1051
1328
  SCALAR: 1,
@@ -1057,621 +1334,848 @@ const WEBGL_TYPE_SIZES = {
1057
1334
  MAT4: 16
1058
1335
  };
1059
1336
  const ATTRIBUTES = {
1060
- POSITION: "position",
1061
- NORMAL: "normal",
1062
- TANGENT: "tangent",
1063
- TEXCOORD_0: "uv",
1064
- TEXCOORD_1: "uv2",
1065
- COLOR_0: "color",
1066
- WEIGHTS_0: "skinWeight",
1067
- JOINTS_0: "skinIndex"
1337
+ POSITION: 'position',
1338
+ NORMAL: 'normal',
1339
+ TANGENT: 'tangent',
1340
+ TEXCOORD_0: 'uv',
1341
+ TEXCOORD_1: 'uv2',
1342
+ COLOR_0: 'color',
1343
+ WEIGHTS_0: 'skinWeight',
1344
+ JOINTS_0: 'skinIndex'
1068
1345
  };
1069
1346
  const PATH_PROPERTIES = {
1070
- scale: "scale",
1071
- translation: "position",
1072
- rotation: "quaternion",
1073
- weights: "morphTargetInfluences"
1347
+ scale: 'scale',
1348
+ translation: 'position',
1349
+ rotation: 'quaternion',
1350
+ weights: 'morphTargetInfluences'
1074
1351
  };
1075
1352
  const INTERPOLATION = {
1076
- CUBICSPLINE: void 0,
1077
- LINEAR: THREE.InterpolateLinear,
1078
- STEP: THREE.InterpolateDiscrete
1353
+ CUBICSPLINE: undefined,
1354
+ // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
1355
+ // keyframe track will be initialized with a default interpolation type, then modified.
1356
+ LINEAR: InterpolateLinear,
1357
+ STEP: InterpolateDiscrete
1079
1358
  };
1080
1359
  const ALPHA_MODES = {
1081
- OPAQUE: "OPAQUE",
1082
- MASK: "MASK",
1083
- BLEND: "BLEND"
1360
+ OPAQUE: 'OPAQUE',
1361
+ MASK: 'MASK',
1362
+ BLEND: 'BLEND'
1084
1363
  };
1364
+ /**
1365
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material
1366
+ */
1367
+
1085
1368
  function createDefaultMaterial(cache) {
1086
- if (cache["DefaultMaterial"] === void 0) {
1087
- cache["DefaultMaterial"] = new THREE.MeshStandardMaterial({
1088
- color: 16777215,
1089
- emissive: 0,
1369
+ if (cache['DefaultMaterial'] === undefined) {
1370
+ cache['DefaultMaterial'] = new MeshStandardMaterial({
1371
+ color: 0xffffff,
1372
+ emissive: 0x000000,
1090
1373
  metalness: 1,
1091
1374
  roughness: 1,
1092
1375
  transparent: false,
1093
1376
  depthTest: true,
1094
- side: THREE.FrontSide
1377
+ side: FrontSide
1095
1378
  });
1096
1379
  }
1097
- return cache["DefaultMaterial"];
1380
+
1381
+ return cache['DefaultMaterial'];
1098
1382
  }
1383
+
1099
1384
  function addUnknownExtensionsToUserData(knownExtensions, object, objectDef) {
1385
+ // Add unknown glTF extensions to an object's userData.
1100
1386
  for (const name in objectDef.extensions) {
1101
- if (knownExtensions[name] === void 0) {
1387
+ if (knownExtensions[name] === undefined) {
1102
1388
  object.userData.gltfExtensions = object.userData.gltfExtensions || {};
1103
1389
  object.userData.gltfExtensions[name] = objectDef.extensions[name];
1104
1390
  }
1105
1391
  }
1106
1392
  }
1393
+ /**
1394
+ * @param {Object3D|Material|BufferGeometry} object
1395
+ * @param {GLTF.definition} gltfDef
1396
+ */
1397
+
1398
+
1107
1399
  function assignExtrasToUserData(object, gltfDef) {
1108
- if (gltfDef.extras !== void 0) {
1109
- if (typeof gltfDef.extras === "object") {
1400
+ if (gltfDef.extras !== undefined) {
1401
+ if (typeof gltfDef.extras === 'object') {
1110
1402
  Object.assign(object.userData, gltfDef.extras);
1111
1403
  } else {
1112
- console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + gltfDef.extras);
1404
+ console.warn('THREE.GLTFLoader: Ignoring primitive type .extras, ' + gltfDef.extras);
1113
1405
  }
1114
1406
  }
1115
1407
  }
1408
+ /**
1409
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#morph-targets
1410
+ *
1411
+ * @param {BufferGeometry} geometry
1412
+ * @param {Array<GLTF.Target>} targets
1413
+ * @param {GLTFParser} parser
1414
+ * @return {Promise<BufferGeometry>}
1415
+ */
1416
+
1417
+
1116
1418
  function addMorphTargets(geometry, targets, parser) {
1117
1419
  let hasMorphPosition = false;
1118
1420
  let hasMorphNormal = false;
1421
+
1119
1422
  for (let i = 0, il = targets.length; i < il; i++) {
1120
1423
  const target = targets[i];
1121
- if (target.POSITION !== void 0)
1122
- hasMorphPosition = true;
1123
- if (target.NORMAL !== void 0)
1124
- hasMorphNormal = true;
1125
- if (hasMorphPosition && hasMorphNormal)
1126
- break;
1127
- }
1128
- if (!hasMorphPosition && !hasMorphNormal)
1129
- return Promise.resolve(geometry);
1424
+ if (target.POSITION !== undefined) hasMorphPosition = true;
1425
+ if (target.NORMAL !== undefined) hasMorphNormal = true;
1426
+ if (hasMorphPosition && hasMorphNormal) break;
1427
+ }
1428
+
1429
+ if (!hasMorphPosition && !hasMorphNormal) return Promise.resolve(geometry);
1130
1430
  const pendingPositionAccessors = [];
1131
1431
  const pendingNormalAccessors = [];
1432
+
1132
1433
  for (let i = 0, il = targets.length; i < il; i++) {
1133
1434
  const target = targets[i];
1435
+
1134
1436
  if (hasMorphPosition) {
1135
- const pendingAccessor = target.POSITION !== void 0 ? parser.getDependency("accessor", target.POSITION) : geometry.attributes.position;
1437
+ const pendingAccessor = target.POSITION !== undefined ? parser.getDependency('accessor', target.POSITION) : geometry.attributes.position;
1136
1438
  pendingPositionAccessors.push(pendingAccessor);
1137
1439
  }
1440
+
1138
1441
  if (hasMorphNormal) {
1139
- const pendingAccessor = target.NORMAL !== void 0 ? parser.getDependency("accessor", target.NORMAL) : geometry.attributes.normal;
1442
+ const pendingAccessor = target.NORMAL !== undefined ? parser.getDependency('accessor', target.NORMAL) : geometry.attributes.normal;
1140
1443
  pendingNormalAccessors.push(pendingAccessor);
1141
1444
  }
1142
1445
  }
1143
- return Promise.all([Promise.all(pendingPositionAccessors), Promise.all(pendingNormalAccessors)]).then(function(accessors) {
1446
+
1447
+ return Promise.all([Promise.all(pendingPositionAccessors), Promise.all(pendingNormalAccessors)]).then(function (accessors) {
1144
1448
  const morphPositions = accessors[0];
1145
1449
  const morphNormals = accessors[1];
1146
- if (hasMorphPosition)
1147
- geometry.morphAttributes.position = morphPositions;
1148
- if (hasMorphNormal)
1149
- geometry.morphAttributes.normal = morphNormals;
1450
+ if (hasMorphPosition) geometry.morphAttributes.position = morphPositions;
1451
+ if (hasMorphNormal) geometry.morphAttributes.normal = morphNormals;
1150
1452
  geometry.morphTargetsRelative = true;
1151
1453
  return geometry;
1152
1454
  });
1153
1455
  }
1456
+ /**
1457
+ * @param {Mesh} mesh
1458
+ * @param {GLTF.Mesh} meshDef
1459
+ */
1460
+
1461
+
1154
1462
  function updateMorphTargets(mesh, meshDef) {
1155
1463
  mesh.updateMorphTargets();
1156
- if (meshDef.weights !== void 0) {
1464
+
1465
+ if (meshDef.weights !== undefined) {
1157
1466
  for (let i = 0, il = meshDef.weights.length; i < il; i++) {
1158
1467
  mesh.morphTargetInfluences[i] = meshDef.weights[i];
1159
1468
  }
1160
- }
1469
+ } // .extras has user-defined data, so check that .extras.targetNames is an array.
1470
+
1471
+
1161
1472
  if (meshDef.extras && Array.isArray(meshDef.extras.targetNames)) {
1162
1473
  const targetNames = meshDef.extras.targetNames;
1474
+
1163
1475
  if (mesh.morphTargetInfluences.length === targetNames.length) {
1164
1476
  mesh.morphTargetDictionary = {};
1477
+
1165
1478
  for (let i = 0, il = targetNames.length; i < il; i++) {
1166
1479
  mesh.morphTargetDictionary[targetNames[i]] = i;
1167
1480
  }
1168
1481
  } else {
1169
- console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
1482
+ console.warn('THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.');
1170
1483
  }
1171
1484
  }
1172
1485
  }
1486
+
1173
1487
  function createPrimitiveKey(primitiveDef) {
1174
1488
  const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
1175
1489
  let geometryKey;
1490
+
1176
1491
  if (dracoExtension) {
1177
- geometryKey = "draco:" + dracoExtension.bufferView + ":" + dracoExtension.indices + ":" + createAttributesKey(dracoExtension.attributes);
1492
+ geometryKey = 'draco:' + dracoExtension.bufferView + ':' + dracoExtension.indices + ':' + createAttributesKey(dracoExtension.attributes);
1178
1493
  } else {
1179
- geometryKey = primitiveDef.indices + ":" + createAttributesKey(primitiveDef.attributes) + ":" + primitiveDef.mode;
1494
+ geometryKey = primitiveDef.indices + ':' + createAttributesKey(primitiveDef.attributes) + ':' + primitiveDef.mode;
1180
1495
  }
1496
+
1181
1497
  return geometryKey;
1182
1498
  }
1499
+
1183
1500
  function createAttributesKey(attributes) {
1184
- let attributesKey = "";
1501
+ let attributesKey = '';
1185
1502
  const keys = Object.keys(attributes).sort();
1503
+
1186
1504
  for (let i = 0, il = keys.length; i < il; i++) {
1187
- attributesKey += keys[i] + ":" + attributes[keys[i]] + ";";
1505
+ attributesKey += keys[i] + ':' + attributes[keys[i]] + ';';
1188
1506
  }
1507
+
1189
1508
  return attributesKey;
1190
1509
  }
1510
+
1191
1511
  function getNormalizedComponentScale(constructor) {
1512
+ // Reference:
1513
+ // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
1192
1514
  switch (constructor) {
1193
1515
  case Int8Array:
1194
1516
  return 1 / 127;
1517
+
1195
1518
  case Uint8Array:
1196
1519
  return 1 / 255;
1520
+
1197
1521
  case Int16Array:
1198
1522
  return 1 / 32767;
1523
+
1199
1524
  case Uint16Array:
1200
1525
  return 1 / 65535;
1526
+
1201
1527
  default:
1202
- throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.");
1528
+ throw new Error('THREE.GLTFLoader: Unsupported normalized accessor component type.');
1203
1529
  }
1204
1530
  }
1531
+ /* GLTF PARSER */
1532
+
1533
+
1205
1534
  class GLTFParser {
1206
1535
  constructor(json = {}, options = {}) {
1207
1536
  this.json = json;
1208
1537
  this.extensions = {};
1209
1538
  this.plugins = {};
1210
- this.options = options;
1211
- this.cache = new GLTFRegistry();
1212
- this.associations = /* @__PURE__ */ new Map();
1213
- this.primitiveCache = {};
1214
- this.meshCache = { refs: {}, uses: {} };
1215
- this.cameraCache = { refs: {}, uses: {} };
1216
- this.lightCache = { refs: {}, uses: {} };
1217
- this.textureCache = {};
1218
- this.nodeNamesUsed = {};
1219
- if (typeof createImageBitmap !== "undefined" && /Firefox|^((?!chrome|android).)*safari/i.test(navigator.userAgent) === false) {
1220
- this.textureLoader = new THREE.ImageBitmapLoader(this.options.manager);
1539
+ this.options = options; // loader object cache
1540
+
1541
+ this.cache = new GLTFRegistry(); // associations between Three.js objects and glTF elements
1542
+
1543
+ this.associations = new Map(); // BufferGeometry caching
1544
+
1545
+ this.primitiveCache = {}; // Object3D instance caches
1546
+
1547
+ this.meshCache = {
1548
+ refs: {},
1549
+ uses: {}
1550
+ };
1551
+ this.cameraCache = {
1552
+ refs: {},
1553
+ uses: {}
1554
+ };
1555
+ this.lightCache = {
1556
+ refs: {},
1557
+ uses: {}
1558
+ };
1559
+ this.textureCache = {}; // Track node names, to ensure no duplicates
1560
+
1561
+ this.nodeNamesUsed = {}; // Use an ImageBitmapLoader if imageBitmaps are supported. Moves much of the
1562
+ // expensive work of uploading a texture to the GPU off the main thread.
1563
+
1564
+ if (typeof createImageBitmap !== 'undefined' && /Firefox|^((?!chrome|android).)*safari/i.test(navigator.userAgent) === false) {
1565
+ this.textureLoader = new ImageBitmapLoader(this.options.manager);
1221
1566
  } else {
1222
- this.textureLoader = new THREE.TextureLoader(this.options.manager);
1567
+ this.textureLoader = new TextureLoader(this.options.manager);
1223
1568
  }
1569
+
1224
1570
  this.textureLoader.setCrossOrigin(this.options.crossOrigin);
1225
1571
  this.textureLoader.setRequestHeader(this.options.requestHeader);
1226
- this.fileLoader = new THREE.FileLoader(this.options.manager);
1227
- this.fileLoader.setResponseType("arraybuffer");
1228
- if (this.options.crossOrigin === "use-credentials") {
1572
+ this.fileLoader = new FileLoader(this.options.manager);
1573
+ this.fileLoader.setResponseType('arraybuffer');
1574
+
1575
+ if (this.options.crossOrigin === 'use-credentials') {
1229
1576
  this.fileLoader.setWithCredentials(true);
1230
1577
  }
1231
1578
  }
1579
+
1232
1580
  setExtensions(extensions) {
1233
1581
  this.extensions = extensions;
1234
1582
  }
1583
+
1235
1584
  setPlugins(plugins) {
1236
1585
  this.plugins = plugins;
1237
1586
  }
1587
+
1238
1588
  parse(onLoad, onError) {
1239
1589
  const parser = this;
1240
1590
  const json = this.json;
1241
- const extensions = this.extensions;
1242
- this.cache.removeAll();
1243
- this._invokeAll(function(ext) {
1591
+ const extensions = this.extensions; // Clear the loader cache
1592
+
1593
+ this.cache.removeAll(); // Mark the special nodes/meshes in json for efficient parse
1594
+
1595
+ this._invokeAll(function (ext) {
1244
1596
  return ext._markDefs && ext._markDefs();
1245
1597
  });
1246
- Promise.all(
1247
- this._invokeAll(function(ext) {
1248
- return ext.beforeRoot && ext.beforeRoot();
1249
- })
1250
- ).then(function() {
1251
- return Promise.all([
1252
- parser.getDependencies("scene"),
1253
- parser.getDependencies("animation"),
1254
- parser.getDependencies("camera")
1255
- ]);
1256
- }).then(function(dependencies) {
1598
+
1599
+ Promise.all(this._invokeAll(function (ext) {
1600
+ return ext.beforeRoot && ext.beforeRoot();
1601
+ })).then(function () {
1602
+ return Promise.all([parser.getDependencies('scene'), parser.getDependencies('animation'), parser.getDependencies('camera')]);
1603
+ }).then(function (dependencies) {
1257
1604
  const result = {
1258
1605
  scene: dependencies[0][json.scene || 0],
1259
1606
  scenes: dependencies[0],
1260
1607
  animations: dependencies[1],
1261
1608
  cameras: dependencies[2],
1262
1609
  asset: json.asset,
1263
- parser,
1610
+ parser: parser,
1264
1611
  userData: {}
1265
1612
  };
1266
1613
  addUnknownExtensionsToUserData(extensions, result, json);
1267
1614
  assignExtrasToUserData(result, json);
1268
- Promise.all(
1269
- parser._invokeAll(function(ext) {
1270
- return ext.afterRoot && ext.afterRoot(result);
1271
- })
1272
- ).then(function() {
1615
+ Promise.all(parser._invokeAll(function (ext) {
1616
+ return ext.afterRoot && ext.afterRoot(result);
1617
+ })).then(function () {
1273
1618
  onLoad(result);
1274
1619
  });
1275
1620
  }).catch(onError);
1276
1621
  }
1622
+ /**
1623
+ * Marks the special nodes/meshes in json for efficient parse.
1624
+ */
1625
+
1626
+
1277
1627
  _markDefs() {
1278
1628
  const nodeDefs = this.json.nodes || [];
1279
1629
  const skinDefs = this.json.skins || [];
1280
- const meshDefs = this.json.meshes || [];
1630
+ const meshDefs = this.json.meshes || []; // Nothing in the node definition indicates whether it is a Bone or an
1631
+ // Object3D. Use the skins' joint references to mark bones.
1632
+
1281
1633
  for (let skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex++) {
1282
1634
  const joints = skinDefs[skinIndex].joints;
1635
+
1283
1636
  for (let i = 0, il = joints.length; i < il; i++) {
1284
1637
  nodeDefs[joints[i]].isBone = true;
1285
1638
  }
1286
- }
1639
+ } // Iterate over all nodes, marking references to shared resources,
1640
+ // as well as skeleton joints.
1641
+
1642
+
1287
1643
  for (let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
1288
1644
  const nodeDef = nodeDefs[nodeIndex];
1289
- if (nodeDef.mesh !== void 0) {
1290
- this._addNodeRef(this.meshCache, nodeDef.mesh);
1291
- if (nodeDef.skin !== void 0) {
1645
+
1646
+ if (nodeDef.mesh !== undefined) {
1647
+ this._addNodeRef(this.meshCache, nodeDef.mesh); // Nothing in the mesh definition indicates whether it is
1648
+ // a SkinnedMesh or Mesh. Use the node's mesh reference
1649
+ // to mark SkinnedMesh if node has skin.
1650
+
1651
+
1652
+ if (nodeDef.skin !== undefined) {
1292
1653
  meshDefs[nodeDef.mesh].isSkinnedMesh = true;
1293
1654
  }
1294
1655
  }
1295
- if (nodeDef.camera !== void 0) {
1656
+
1657
+ if (nodeDef.camera !== undefined) {
1296
1658
  this._addNodeRef(this.cameraCache, nodeDef.camera);
1297
1659
  }
1298
1660
  }
1299
1661
  }
1662
+ /**
1663
+ * Counts references to shared node / Object3D resources. These resources
1664
+ * can be reused, or "instantiated", at multiple nodes in the scene
1665
+ * hierarchy. Mesh, Camera, and Light instances are instantiated and must
1666
+ * be marked. Non-scenegraph resources (like Materials, Geometries, and
1667
+ * Textures) can be reused directly and are not marked here.
1668
+ *
1669
+ * Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
1670
+ */
1671
+
1672
+
1300
1673
  _addNodeRef(cache, index) {
1301
- if (index === void 0)
1302
- return;
1303
- if (cache.refs[index] === void 0) {
1674
+ if (index === undefined) return;
1675
+
1676
+ if (cache.refs[index] === undefined) {
1304
1677
  cache.refs[index] = cache.uses[index] = 0;
1305
1678
  }
1679
+
1306
1680
  cache.refs[index]++;
1307
1681
  }
1682
+ /** Returns a reference to a shared resource, cloning it if necessary. */
1683
+
1684
+
1308
1685
  _getNodeRef(cache, index, object) {
1309
- if (cache.refs[index] <= 1)
1310
- return object;
1311
- const ref = object.clone();
1686
+ if (cache.refs[index] <= 1) return object;
1687
+ const ref = object.clone(); // Propagates mappings to the cloned object, prevents mappings on the
1688
+ // original object from being lost.
1689
+
1312
1690
  const updateMappings = (original, clone) => {
1313
1691
  const mappings = this.associations.get(original);
1692
+
1314
1693
  if (mappings != null) {
1315
1694
  this.associations.set(clone, mappings);
1316
1695
  }
1696
+
1317
1697
  for (const [i, child] of original.children.entries()) {
1318
1698
  updateMappings(child, clone.children[i]);
1319
1699
  }
1320
1700
  };
1701
+
1321
1702
  updateMappings(object, ref);
1322
- ref.name += "_instance_" + cache.uses[index]++;
1703
+ ref.name += '_instance_' + cache.uses[index]++;
1323
1704
  return ref;
1324
1705
  }
1706
+
1325
1707
  _invokeOne(func) {
1326
1708
  const extensions = Object.values(this.plugins);
1327
1709
  extensions.push(this);
1710
+
1328
1711
  for (let i = 0; i < extensions.length; i++) {
1329
1712
  const result = func(extensions[i]);
1330
- if (result)
1331
- return result;
1713
+ if (result) return result;
1332
1714
  }
1715
+
1333
1716
  return null;
1334
1717
  }
1718
+
1335
1719
  _invokeAll(func) {
1336
1720
  const extensions = Object.values(this.plugins);
1337
1721
  extensions.unshift(this);
1338
1722
  const pending = [];
1723
+
1339
1724
  for (let i = 0; i < extensions.length; i++) {
1340
1725
  const result = func(extensions[i]);
1341
- if (result)
1342
- pending.push(result);
1726
+ if (result) pending.push(result);
1343
1727
  }
1728
+
1344
1729
  return pending;
1345
1730
  }
1731
+ /**
1732
+ * Requests the specified dependency asynchronously, with caching.
1733
+ * @param {string} type
1734
+ * @param {number} index
1735
+ * @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
1736
+ */
1737
+
1738
+
1346
1739
  getDependency(type, index) {
1347
- const cacheKey = type + ":" + index;
1740
+ const cacheKey = type + ':' + index;
1348
1741
  let dependency = this.cache.get(cacheKey);
1742
+
1349
1743
  if (!dependency) {
1350
1744
  switch (type) {
1351
- case "scene":
1745
+ case 'scene':
1352
1746
  dependency = this.loadScene(index);
1353
1747
  break;
1354
- case "node":
1748
+
1749
+ case 'node':
1355
1750
  dependency = this.loadNode(index);
1356
1751
  break;
1357
- case "mesh":
1358
- dependency = this._invokeOne(function(ext) {
1752
+
1753
+ case 'mesh':
1754
+ dependency = this._invokeOne(function (ext) {
1359
1755
  return ext.loadMesh && ext.loadMesh(index);
1360
1756
  });
1361
1757
  break;
1362
- case "accessor":
1758
+
1759
+ case 'accessor':
1363
1760
  dependency = this.loadAccessor(index);
1364
1761
  break;
1365
- case "bufferView":
1366
- dependency = this._invokeOne(function(ext) {
1762
+
1763
+ case 'bufferView':
1764
+ dependency = this._invokeOne(function (ext) {
1367
1765
  return ext.loadBufferView && ext.loadBufferView(index);
1368
1766
  });
1369
1767
  break;
1370
- case "buffer":
1768
+
1769
+ case 'buffer':
1371
1770
  dependency = this.loadBuffer(index);
1372
1771
  break;
1373
- case "material":
1374
- dependency = this._invokeOne(function(ext) {
1772
+
1773
+ case 'material':
1774
+ dependency = this._invokeOne(function (ext) {
1375
1775
  return ext.loadMaterial && ext.loadMaterial(index);
1376
1776
  });
1377
1777
  break;
1378
- case "texture":
1379
- dependency = this._invokeOne(function(ext) {
1778
+
1779
+ case 'texture':
1780
+ dependency = this._invokeOne(function (ext) {
1380
1781
  return ext.loadTexture && ext.loadTexture(index);
1381
1782
  });
1382
1783
  break;
1383
- case "skin":
1784
+
1785
+ case 'skin':
1384
1786
  dependency = this.loadSkin(index);
1385
1787
  break;
1386
- case "animation":
1788
+
1789
+ case 'animation':
1387
1790
  dependency = this.loadAnimation(index);
1388
1791
  break;
1389
- case "camera":
1792
+
1793
+ case 'camera':
1390
1794
  dependency = this.loadCamera(index);
1391
1795
  break;
1796
+
1392
1797
  default:
1393
- throw new Error("Unknown type: " + type);
1798
+ throw new Error('Unknown type: ' + type);
1394
1799
  }
1800
+
1395
1801
  this.cache.add(cacheKey, dependency);
1396
1802
  }
1803
+
1397
1804
  return dependency;
1398
1805
  }
1806
+ /**
1807
+ * Requests all dependencies of the specified type asynchronously, with caching.
1808
+ * @param {string} type
1809
+ * @return {Promise<Array<Object>>}
1810
+ */
1811
+
1812
+
1399
1813
  getDependencies(type) {
1400
1814
  let dependencies = this.cache.get(type);
1815
+
1401
1816
  if (!dependencies) {
1402
1817
  const parser = this;
1403
- const defs = this.json[type + (type === "mesh" ? "es" : "s")] || [];
1404
- dependencies = Promise.all(
1405
- defs.map(function(def, index) {
1406
- return parser.getDependency(type, index);
1407
- })
1408
- );
1818
+ const defs = this.json[type + (type === 'mesh' ? 'es' : 's')] || [];
1819
+ dependencies = Promise.all(defs.map(function (def, index) {
1820
+ return parser.getDependency(type, index);
1821
+ }));
1409
1822
  this.cache.add(type, dependencies);
1410
1823
  }
1824
+
1411
1825
  return dependencies;
1412
1826
  }
1827
+ /**
1828
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
1829
+ * @param {number} bufferIndex
1830
+ * @return {Promise<ArrayBuffer>}
1831
+ */
1832
+
1833
+
1413
1834
  loadBuffer(bufferIndex) {
1414
1835
  const bufferDef = this.json.buffers[bufferIndex];
1415
1836
  const loader = this.fileLoader;
1416
- if (bufferDef.type && bufferDef.type !== "arraybuffer") {
1417
- throw new Error("THREE.GLTFLoader: " + bufferDef.type + " buffer type is not supported.");
1418
- }
1419
- if (bufferDef.uri === void 0 && bufferIndex === 0) {
1837
+
1838
+ if (bufferDef.type && bufferDef.type !== 'arraybuffer') {
1839
+ throw new Error('THREE.GLTFLoader: ' + bufferDef.type + ' buffer type is not supported.');
1840
+ } // If present, GLB container is required to be the first buffer.
1841
+
1842
+
1843
+ if (bufferDef.uri === undefined && bufferIndex === 0) {
1420
1844
  return Promise.resolve(this.extensions[EXTENSIONS.KHR_BINARY_GLTF].body);
1421
1845
  }
1846
+
1422
1847
  const options = this.options;
1423
- return new Promise(function(resolve, reject) {
1424
- loader.load(THREE.LoaderUtils.resolveURL(bufferDef.uri, options.path), resolve, void 0, function() {
1848
+ return new Promise(function (resolve, reject) {
1849
+ loader.load(LoaderUtils.resolveURL(bufferDef.uri, options.path), resolve, undefined, function () {
1425
1850
  reject(new Error('THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".'));
1426
1851
  });
1427
1852
  });
1428
1853
  }
1854
+ /**
1855
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
1856
+ * @param {number} bufferViewIndex
1857
+ * @return {Promise<ArrayBuffer>}
1858
+ */
1859
+
1860
+
1429
1861
  loadBufferView(bufferViewIndex) {
1430
1862
  const bufferViewDef = this.json.bufferViews[bufferViewIndex];
1431
- return this.getDependency("buffer", bufferViewDef.buffer).then(function(buffer) {
1863
+ return this.getDependency('buffer', bufferViewDef.buffer).then(function (buffer) {
1432
1864
  const byteLength = bufferViewDef.byteLength || 0;
1433
1865
  const byteOffset = bufferViewDef.byteOffset || 0;
1434
1866
  return buffer.slice(byteOffset, byteOffset + byteLength);
1435
1867
  });
1436
1868
  }
1869
+ /**
1870
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
1871
+ * @param {number} accessorIndex
1872
+ * @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
1873
+ */
1874
+
1875
+
1437
1876
  loadAccessor(accessorIndex) {
1438
1877
  const parser = this;
1439
1878
  const json = this.json;
1440
1879
  const accessorDef = this.json.accessors[accessorIndex];
1441
- if (accessorDef.bufferView === void 0 && accessorDef.sparse === void 0) {
1880
+
1881
+ if (accessorDef.bufferView === undefined && accessorDef.sparse === undefined) {
1882
+ // Ignore empty accessors, which may be used to declare runtime
1883
+ // information about attributes coming from another source (e.g. Draco
1884
+ // compression extension).
1442
1885
  return Promise.resolve(null);
1443
1886
  }
1887
+
1444
1888
  const pendingBufferViews = [];
1445
- if (accessorDef.bufferView !== void 0) {
1446
- pendingBufferViews.push(this.getDependency("bufferView", accessorDef.bufferView));
1889
+
1890
+ if (accessorDef.bufferView !== undefined) {
1891
+ pendingBufferViews.push(this.getDependency('bufferView', accessorDef.bufferView));
1447
1892
  } else {
1448
1893
  pendingBufferViews.push(null);
1449
1894
  }
1450
- if (accessorDef.sparse !== void 0) {
1451
- pendingBufferViews.push(this.getDependency("bufferView", accessorDef.sparse.indices.bufferView));
1452
- pendingBufferViews.push(this.getDependency("bufferView", accessorDef.sparse.values.bufferView));
1895
+
1896
+ if (accessorDef.sparse !== undefined) {
1897
+ pendingBufferViews.push(this.getDependency('bufferView', accessorDef.sparse.indices.bufferView));
1898
+ pendingBufferViews.push(this.getDependency('bufferView', accessorDef.sparse.values.bufferView));
1453
1899
  }
1454
- return Promise.all(pendingBufferViews).then(function(bufferViews) {
1900
+
1901
+ return Promise.all(pendingBufferViews).then(function (bufferViews) {
1455
1902
  const bufferView = bufferViews[0];
1456
1903
  const itemSize = WEBGL_TYPE_SIZES[accessorDef.type];
1457
- const TypedArray = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
1904
+ const TypedArray = WEBGL_COMPONENT_TYPES[accessorDef.componentType]; // For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12.
1905
+
1458
1906
  const elementBytes = TypedArray.BYTES_PER_ELEMENT;
1459
1907
  const itemBytes = elementBytes * itemSize;
1460
1908
  const byteOffset = accessorDef.byteOffset || 0;
1461
- const byteStride = accessorDef.bufferView !== void 0 ? json.bufferViews[accessorDef.bufferView].byteStride : void 0;
1909
+ const byteStride = accessorDef.bufferView !== undefined ? json.bufferViews[accessorDef.bufferView].byteStride : undefined;
1462
1910
  const normalized = accessorDef.normalized === true;
1463
- let array, bufferAttribute;
1911
+ let array, bufferAttribute; // The buffer is not interleaved if the stride is the item size in bytes.
1912
+
1464
1913
  if (byteStride && byteStride !== itemBytes) {
1914
+ // Each "slice" of the buffer, as defined by 'count' elements of 'byteStride' bytes, gets its own InterleavedBuffer
1915
+ // This makes sure that IBA.count reflects accessor.count properly
1465
1916
  const ibSlice = Math.floor(byteOffset / byteStride);
1466
- const ibCacheKey = "InterleavedBuffer:" + accessorDef.bufferView + ":" + accessorDef.componentType + ":" + ibSlice + ":" + accessorDef.count;
1917
+ const ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType + ':' + ibSlice + ':' + accessorDef.count;
1467
1918
  let ib = parser.cache.get(ibCacheKey);
1919
+
1468
1920
  if (!ib) {
1469
- array = new TypedArray(bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes);
1470
- ib = new THREE.InterleavedBuffer(array, byteStride / elementBytes);
1921
+ array = new TypedArray(bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes); // Integer parameters to IB/IBA are in array elements, not bytes.
1922
+
1923
+ ib = new InterleavedBuffer(array, byteStride / elementBytes);
1471
1924
  parser.cache.add(ibCacheKey, ib);
1472
1925
  }
1473
- bufferAttribute = new THREE.InterleavedBufferAttribute(
1474
- ib,
1475
- itemSize,
1476
- byteOffset % byteStride / elementBytes,
1477
- normalized
1478
- );
1926
+
1927
+ bufferAttribute = new InterleavedBufferAttribute(ib, itemSize, byteOffset % byteStride / elementBytes, normalized);
1479
1928
  } else {
1480
1929
  if (bufferView === null) {
1481
1930
  array = new TypedArray(accessorDef.count * itemSize);
1482
1931
  } else {
1483
1932
  array = new TypedArray(bufferView, byteOffset, accessorDef.count * itemSize);
1484
1933
  }
1485
- bufferAttribute = new THREE.BufferAttribute(array, itemSize, normalized);
1486
- }
1487
- if (accessorDef.sparse !== void 0) {
1934
+
1935
+ bufferAttribute = new BufferAttribute(array, itemSize, normalized);
1936
+ } // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#sparse-accessors
1937
+
1938
+
1939
+ if (accessorDef.sparse !== undefined) {
1488
1940
  const itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
1489
1941
  const TypedArrayIndices = WEBGL_COMPONENT_TYPES[accessorDef.sparse.indices.componentType];
1490
1942
  const byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
1491
1943
  const byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
1492
- const sparseIndices = new TypedArrayIndices(
1493
- bufferViews[1],
1494
- byteOffsetIndices,
1495
- accessorDef.sparse.count * itemSizeIndices
1496
- );
1944
+ const sparseIndices = new TypedArrayIndices(bufferViews[1], byteOffsetIndices, accessorDef.sparse.count * itemSizeIndices);
1497
1945
  const sparseValues = new TypedArray(bufferViews[2], byteOffsetValues, accessorDef.sparse.count * itemSize);
1946
+
1498
1947
  if (bufferView !== null) {
1499
- bufferAttribute = new THREE.BufferAttribute(
1500
- bufferAttribute.array.slice(),
1501
- bufferAttribute.itemSize,
1502
- bufferAttribute.normalized
1503
- );
1948
+ // Avoid modifying the original ArrayBuffer, if the bufferView wasn't initialized with zeroes.
1949
+ bufferAttribute = new BufferAttribute(bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized);
1504
1950
  }
1951
+
1505
1952
  for (let i = 0, il = sparseIndices.length; i < il; i++) {
1506
1953
  const index = sparseIndices[i];
1507
1954
  bufferAttribute.setX(index, sparseValues[i * itemSize]);
1508
- if (itemSize >= 2)
1509
- bufferAttribute.setY(index, sparseValues[i * itemSize + 1]);
1510
- if (itemSize >= 3)
1511
- bufferAttribute.setZ(index, sparseValues[i * itemSize + 2]);
1512
- if (itemSize >= 4)
1513
- bufferAttribute.setW(index, sparseValues[i * itemSize + 3]);
1514
- if (itemSize >= 5)
1515
- throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.");
1955
+ if (itemSize >= 2) bufferAttribute.setY(index, sparseValues[i * itemSize + 1]);
1956
+ if (itemSize >= 3) bufferAttribute.setZ(index, sparseValues[i * itemSize + 2]);
1957
+ if (itemSize >= 4) bufferAttribute.setW(index, sparseValues[i * itemSize + 3]);
1958
+ if (itemSize >= 5) throw new Error('THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.');
1516
1959
  }
1517
1960
  }
1961
+
1518
1962
  return bufferAttribute;
1519
1963
  });
1520
1964
  }
1965
+ /**
1966
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
1967
+ * @param {number} textureIndex
1968
+ * @return {Promise<THREE.Texture>}
1969
+ */
1970
+
1971
+
1521
1972
  loadTexture(textureIndex) {
1522
1973
  const json = this.json;
1523
1974
  const options = this.options;
1524
1975
  const textureDef = json.textures[textureIndex];
1525
1976
  const source = json.images[textureDef.source];
1526
1977
  let loader = this.textureLoader;
1978
+
1527
1979
  if (source.uri) {
1528
1980
  const handler = options.manager.getHandler(source.uri);
1529
- if (handler !== null)
1530
- loader = handler;
1981
+ if (handler !== null) loader = handler;
1531
1982
  }
1983
+
1532
1984
  return this.loadTextureImage(textureIndex, source, loader);
1533
1985
  }
1986
+
1534
1987
  loadTextureImage(textureIndex, source, loader) {
1535
1988
  const parser = this;
1536
1989
  const json = this.json;
1537
1990
  const options = this.options;
1538
1991
  const textureDef = json.textures[textureIndex];
1539
- const cacheKey = (source.uri || source.bufferView) + ":" + textureDef.sampler;
1992
+ const cacheKey = (source.uri || source.bufferView) + ':' + textureDef.sampler;
1993
+
1540
1994
  if (this.textureCache[cacheKey]) {
1995
+ // See https://github.com/mrdoob/three.js/issues/21559.
1541
1996
  return this.textureCache[cacheKey];
1542
1997
  }
1998
+
1543
1999
  const URL = self.URL || self.webkitURL;
1544
- let sourceURI = source.uri || "";
2000
+ let sourceURI = source.uri || '';
1545
2001
  let isObjectURL = false;
1546
- if (source.bufferView !== void 0) {
1547
- sourceURI = parser.getDependency("bufferView", source.bufferView).then(function(bufferView) {
2002
+
2003
+ if (source.bufferView !== undefined) {
2004
+ // Load binary image data from bufferView, if provided.
2005
+ sourceURI = parser.getDependency('bufferView', source.bufferView).then(function (bufferView) {
1548
2006
  isObjectURL = true;
1549
- const blob = new Blob([bufferView], { type: source.mimeType });
2007
+ const blob = new Blob([bufferView], {
2008
+ type: source.mimeType
2009
+ });
1550
2010
  sourceURI = URL.createObjectURL(blob);
1551
2011
  return sourceURI;
1552
2012
  });
1553
- } else if (source.uri === void 0) {
1554
- throw new Error("THREE.GLTFLoader: Image " + textureIndex + " is missing URI and bufferView");
2013
+ } else if (source.uri === undefined) {
2014
+ throw new Error('THREE.GLTFLoader: Image ' + textureIndex + ' is missing URI and bufferView');
1555
2015
  }
1556
- const promise = Promise.resolve(sourceURI).then(function(sourceURI2) {
1557
- return new Promise(function(resolve, reject) {
2016
+
2017
+ const promise = Promise.resolve(sourceURI).then(function (sourceURI) {
2018
+ return new Promise(function (resolve, reject) {
1558
2019
  let onLoad = resolve;
2020
+
1559
2021
  if (loader.isImageBitmapLoader === true) {
1560
- onLoad = function(imageBitmap) {
1561
- const texture = new THREE.Texture(imageBitmap);
2022
+ onLoad = function (imageBitmap) {
2023
+ const texture = new Texture(imageBitmap);
1562
2024
  texture.needsUpdate = true;
1563
2025
  resolve(texture);
1564
2026
  };
1565
2027
  }
1566
- loader.load(THREE.LoaderUtils.resolveURL(sourceURI2, options.path), onLoad, void 0, reject);
2028
+
2029
+ loader.load(LoaderUtils.resolveURL(sourceURI, options.path), onLoad, undefined, reject);
1567
2030
  });
1568
- }).then(function(texture) {
2031
+ }).then(function (texture) {
2032
+ // Clean up resources and configure Texture.
1569
2033
  if (isObjectURL === true) {
1570
2034
  URL.revokeObjectURL(sourceURI);
1571
2035
  }
2036
+
1572
2037
  texture.flipY = false;
1573
- if (textureDef.name)
1574
- texture.name = textureDef.name;
2038
+ if (textureDef.name) texture.name = textureDef.name;
1575
2039
  const samplers = json.samplers || {};
1576
2040
  const sampler = samplers[textureDef.sampler] || {};
1577
- texture.magFilter = WEBGL_FILTERS[sampler.magFilter] || THREE.LinearFilter;
1578
- texture.minFilter = WEBGL_FILTERS[sampler.minFilter] || THREE.LinearMipmapLinearFilter;
1579
- texture.wrapS = WEBGL_WRAPPINGS[sampler.wrapS] || THREE.RepeatWrapping;
1580
- texture.wrapT = WEBGL_WRAPPINGS[sampler.wrapT] || THREE.RepeatWrapping;
1581
- parser.associations.set(texture, { textures: textureIndex });
2041
+ texture.magFilter = WEBGL_FILTERS[sampler.magFilter] || LinearFilter;
2042
+ texture.minFilter = WEBGL_FILTERS[sampler.minFilter] || LinearMipmapLinearFilter;
2043
+ texture.wrapS = WEBGL_WRAPPINGS[sampler.wrapS] || RepeatWrapping;
2044
+ texture.wrapT = WEBGL_WRAPPINGS[sampler.wrapT] || RepeatWrapping;
2045
+ parser.associations.set(texture, {
2046
+ textures: textureIndex
2047
+ });
1582
2048
  return texture;
1583
- }).catch(function() {
2049
+ }).catch(function () {
1584
2050
  console.error("THREE.GLTFLoader: Couldn't load texture", sourceURI);
1585
2051
  return null;
1586
2052
  });
1587
2053
  this.textureCache[cacheKey] = promise;
1588
2054
  return promise;
1589
2055
  }
2056
+ /**
2057
+ * Asynchronously assigns a texture to the given material parameters.
2058
+ * @param {Object} materialParams
2059
+ * @param {string} mapName
2060
+ * @param {Object} mapDef
2061
+ * @return {Promise<Texture>}
2062
+ */
2063
+
2064
+
1590
2065
  assignTexture(materialParams, mapName, mapDef) {
1591
2066
  const parser = this;
1592
- return this.getDependency("texture", mapDef.index).then(function(texture) {
1593
- if (mapDef.texCoord !== void 0 && mapDef.texCoord != 0 && !(mapName === "aoMap" && mapDef.texCoord == 1)) {
1594
- console.warn(
1595
- "THREE.GLTFLoader: Custom UV set " + mapDef.texCoord + " for texture " + mapName + " not yet supported."
1596
- );
2067
+ return this.getDependency('texture', mapDef.index).then(function (texture) {
2068
+ // Materials sample aoMap from UV set 1 and other maps from UV set 0 - this can't be configured
2069
+ // However, we will copy UV set 0 to UV set 1 on demand for aoMap
2070
+ if (mapDef.texCoord !== undefined && mapDef.texCoord != 0 && !(mapName === 'aoMap' && mapDef.texCoord == 1)) {
2071
+ console.warn('THREE.GLTFLoader: Custom UV set ' + mapDef.texCoord + ' for texture ' + mapName + ' not yet supported.');
1597
2072
  }
2073
+
1598
2074
  if (parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM]) {
1599
- const transform = mapDef.extensions !== void 0 ? mapDef.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM] : void 0;
2075
+ const transform = mapDef.extensions !== undefined ? mapDef.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM] : undefined;
2076
+
1600
2077
  if (transform) {
1601
2078
  const gltfReference = parser.associations.get(texture);
1602
2079
  texture = parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM].extendTexture(texture, transform);
1603
2080
  parser.associations.set(texture, gltfReference);
1604
2081
  }
1605
2082
  }
2083
+
1606
2084
  materialParams[mapName] = texture;
1607
2085
  return texture;
1608
2086
  });
1609
2087
  }
2088
+ /**
2089
+ * Assigns final material to a Mesh, Line, or Points instance. The instance
2090
+ * already has a material (generated from the glTF material options alone)
2091
+ * but reuse of the same glTF material may require multiple threejs materials
2092
+ * to accommodate different primitive types, defines, etc. New materials will
2093
+ * be created if necessary, and reused from a cache.
2094
+ * @param {Object3D} mesh Mesh, Line, or Points instance.
2095
+ */
2096
+
2097
+
1610
2098
  assignFinalMaterial(mesh) {
1611
2099
  const geometry = mesh.geometry;
1612
2100
  let material = mesh.material;
1613
- const useDerivativeTangents = geometry.attributes.tangent === void 0;
1614
- const useVertexColors = geometry.attributes.color !== void 0;
1615
- const useFlatShading = geometry.attributes.normal === void 0;
2101
+ const useDerivativeTangents = geometry.attributes.tangent === undefined;
2102
+ const useVertexColors = geometry.attributes.color !== undefined;
2103
+ const useFlatShading = geometry.attributes.normal === undefined;
2104
+
1616
2105
  if (mesh.isPoints) {
1617
- const cacheKey = "PointsMaterial:" + material.uuid;
2106
+ const cacheKey = 'PointsMaterial:' + material.uuid;
1618
2107
  let pointsMaterial = this.cache.get(cacheKey);
2108
+
1619
2109
  if (!pointsMaterial) {
1620
- pointsMaterial = new THREE.PointsMaterial();
1621
- THREE.Material.prototype.copy.call(pointsMaterial, material);
2110
+ pointsMaterial = new PointsMaterial();
2111
+ Material.prototype.copy.call(pointsMaterial, material);
1622
2112
  pointsMaterial.color.copy(material.color);
1623
2113
  pointsMaterial.map = material.map;
1624
- pointsMaterial.sizeAttenuation = false;
2114
+ pointsMaterial.sizeAttenuation = false; // glTF spec says points should be 1px
2115
+
1625
2116
  this.cache.add(cacheKey, pointsMaterial);
1626
2117
  }
2118
+
1627
2119
  material = pointsMaterial;
1628
2120
  } else if (mesh.isLine) {
1629
- const cacheKey = "LineBasicMaterial:" + material.uuid;
2121
+ const cacheKey = 'LineBasicMaterial:' + material.uuid;
1630
2122
  let lineMaterial = this.cache.get(cacheKey);
2123
+
1631
2124
  if (!lineMaterial) {
1632
- lineMaterial = new THREE.LineBasicMaterial();
1633
- THREE.Material.prototype.copy.call(lineMaterial, material);
2125
+ lineMaterial = new LineBasicMaterial();
2126
+ Material.prototype.copy.call(lineMaterial, material);
1634
2127
  lineMaterial.color.copy(material.color);
1635
2128
  this.cache.add(cacheKey, lineMaterial);
1636
2129
  }
2130
+
1637
2131
  material = lineMaterial;
1638
- }
2132
+ } // Clone the material if it will be modified
2133
+
2134
+
1639
2135
  if (useDerivativeTangents || useVertexColors || useFlatShading) {
1640
- let cacheKey = "ClonedMaterial:" + material.uuid + ":";
1641
- if (material.isGLTFSpecularGlossinessMaterial)
1642
- cacheKey += "specular-glossiness:";
1643
- if (useDerivativeTangents)
1644
- cacheKey += "derivative-tangents:";
1645
- if (useVertexColors)
1646
- cacheKey += "vertex-colors:";
1647
- if (useFlatShading)
1648
- cacheKey += "flat-shading:";
2136
+ let cacheKey = 'ClonedMaterial:' + material.uuid + ':';
2137
+ if (material.isGLTFSpecularGlossinessMaterial) cacheKey += 'specular-glossiness:';
2138
+ if (useDerivativeTangents) cacheKey += 'derivative-tangents:';
2139
+ if (useVertexColors) cacheKey += 'vertex-colors:';
2140
+ if (useFlatShading) cacheKey += 'flat-shading:';
1649
2141
  let cachedMaterial = this.cache.get(cacheKey);
2142
+
1650
2143
  if (!cachedMaterial) {
1651
2144
  cachedMaterial = material.clone();
1652
- if (useVertexColors)
1653
- cachedMaterial.vertexColors = true;
1654
- if (useFlatShading)
1655
- cachedMaterial.flatShading = true;
2145
+ if (useVertexColors) cachedMaterial.vertexColors = true;
2146
+ if (useFlatShading) cachedMaterial.flatShading = true;
2147
+
1656
2148
  if (useDerivativeTangents) {
1657
- if (cachedMaterial.normalScale)
1658
- cachedMaterial.normalScale.y *= -1;
1659
- if (cachedMaterial.clearcoatNormalScale)
1660
- cachedMaterial.clearcoatNormalScale.y *= -1;
2149
+ // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
2150
+ if (cachedMaterial.normalScale) cachedMaterial.normalScale.y *= -1;
2151
+ if (cachedMaterial.clearcoatNormalScale) cachedMaterial.clearcoatNormalScale.y *= -1;
1661
2152
  }
2153
+
1662
2154
  this.cache.add(cacheKey, cachedMaterial);
1663
2155
  this.associations.set(cachedMaterial, this.associations.get(material));
1664
2156
  }
2157
+
1665
2158
  material = cachedMaterial;
2159
+ } // workarounds for mesh and geometry
2160
+
2161
+
2162
+ if (material.aoMap && geometry.attributes.uv2 === undefined && geometry.attributes.uv !== undefined) {
2163
+ geometry.setAttribute('uv2', geometry.attributes.uv);
1666
2164
  }
1667
- if (material.aoMap && geometry.attributes.uv2 === void 0 && geometry.attributes.uv !== void 0) {
1668
- geometry.setAttribute("uv2", geometry.attributes.uv);
1669
- }
2165
+
1670
2166
  mesh.material = material;
1671
2167
  }
2168
+
1672
2169
  getMaterialType() {
1673
- return THREE.MeshStandardMaterial;
1674
- }
2170
+ return MeshStandardMaterial;
2171
+ }
2172
+ /**
2173
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
2174
+ * @param {number} materialIndex
2175
+ * @return {Promise<Material>}
2176
+ */
2177
+
2178
+
1675
2179
  loadMaterial(materialIndex) {
1676
2180
  const parser = this;
1677
2181
  const json = this.json;
@@ -1681,6 +2185,7 @@ class GLTFParser {
1681
2185
  const materialParams = {};
1682
2186
  const materialExtensions = materialDef.extensions || {};
1683
2187
  const pending = [];
2188
+
1684
2189
  if (materialExtensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]) {
1685
2190
  const sgExtension = extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];
1686
2191
  materialType = sgExtension.getMaterialType();
@@ -1690,125 +2195,178 @@ class GLTFParser {
1690
2195
  materialType = kmuExtension.getMaterialType();
1691
2196
  pending.push(kmuExtension.extendParams(materialParams, materialDef, parser));
1692
2197
  } else {
2198
+ // Specification:
2199
+ // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material
1693
2200
  const metallicRoughness = materialDef.pbrMetallicRoughness || {};
1694
- materialParams.color = new THREE.Color(1, 1, 1);
1695
- materialParams.opacity = 1;
2201
+ materialParams.color = new Color(1.0, 1.0, 1.0);
2202
+ materialParams.opacity = 1.0;
2203
+
1696
2204
  if (Array.isArray(metallicRoughness.baseColorFactor)) {
1697
2205
  const array = metallicRoughness.baseColorFactor;
1698
2206
  materialParams.color.fromArray(array);
1699
2207
  materialParams.opacity = array[3];
1700
2208
  }
1701
- if (metallicRoughness.baseColorTexture !== void 0) {
1702
- pending.push(parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture));
2209
+
2210
+ if (metallicRoughness.baseColorTexture !== undefined) {
2211
+ pending.push(parser.assignTexture(materialParams, 'map', metallicRoughness.baseColorTexture));
1703
2212
  }
1704
- materialParams.metalness = metallicRoughness.metallicFactor !== void 0 ? metallicRoughness.metallicFactor : 1;
1705
- materialParams.roughness = metallicRoughness.roughnessFactor !== void 0 ? metallicRoughness.roughnessFactor : 1;
1706
- if (metallicRoughness.metallicRoughnessTexture !== void 0) {
1707
- pending.push(parser.assignTexture(materialParams, "metalnessMap", metallicRoughness.metallicRoughnessTexture));
1708
- pending.push(parser.assignTexture(materialParams, "roughnessMap", metallicRoughness.metallicRoughnessTexture));
2213
+
2214
+ materialParams.metalness = metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0;
2215
+ materialParams.roughness = metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0;
2216
+
2217
+ if (metallicRoughness.metallicRoughnessTexture !== undefined) {
2218
+ pending.push(parser.assignTexture(materialParams, 'metalnessMap', metallicRoughness.metallicRoughnessTexture));
2219
+ pending.push(parser.assignTexture(materialParams, 'roughnessMap', metallicRoughness.metallicRoughnessTexture));
1709
2220
  }
1710
- materialType = this._invokeOne(function(ext) {
2221
+
2222
+ materialType = this._invokeOne(function (ext) {
1711
2223
  return ext.getMaterialType && ext.getMaterialType(materialIndex);
1712
2224
  });
1713
- pending.push(
1714
- Promise.all(
1715
- this._invokeAll(function(ext) {
1716
- return ext.extendMaterialParams && ext.extendMaterialParams(materialIndex, materialParams);
1717
- })
1718
- )
1719
- );
2225
+ pending.push(Promise.all(this._invokeAll(function (ext) {
2226
+ return ext.extendMaterialParams && ext.extendMaterialParams(materialIndex, materialParams);
2227
+ })));
1720
2228
  }
2229
+
1721
2230
  if (materialDef.doubleSided === true) {
1722
- materialParams.side = THREE.DoubleSide;
2231
+ materialParams.side = DoubleSide;
1723
2232
  }
2233
+
1724
2234
  const alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
2235
+
1725
2236
  if (alphaMode === ALPHA_MODES.BLEND) {
1726
- materialParams.transparent = true;
2237
+ materialParams.transparent = true; // See: https://github.com/mrdoob/three.js/issues/17706
2238
+
1727
2239
  materialParams.depthWrite = false;
1728
2240
  } else {
1729
2241
  materialParams.transparent = false;
2242
+
1730
2243
  if (alphaMode === ALPHA_MODES.MASK) {
1731
- materialParams.alphaTest = materialDef.alphaCutoff !== void 0 ? materialDef.alphaCutoff : 0.5;
2244
+ materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
1732
2245
  }
1733
2246
  }
1734
- if (materialDef.normalTexture !== void 0 && materialType !== THREE.MeshBasicMaterial) {
1735
- pending.push(parser.assignTexture(materialParams, "normalMap", materialDef.normalTexture));
1736
- materialParams.normalScale = new THREE.Vector2(1, 1);
1737
- if (materialDef.normalTexture.scale !== void 0) {
2247
+
2248
+ if (materialDef.normalTexture !== undefined && materialType !== MeshBasicMaterial) {
2249
+ pending.push(parser.assignTexture(materialParams, 'normalMap', materialDef.normalTexture));
2250
+ materialParams.normalScale = new Vector2(1, 1);
2251
+
2252
+ if (materialDef.normalTexture.scale !== undefined) {
1738
2253
  const scale = materialDef.normalTexture.scale;
1739
2254
  materialParams.normalScale.set(scale, scale);
1740
2255
  }
1741
2256
  }
1742
- if (materialDef.occlusionTexture !== void 0 && materialType !== THREE.MeshBasicMaterial) {
1743
- pending.push(parser.assignTexture(materialParams, "aoMap", materialDef.occlusionTexture));
1744
- if (materialDef.occlusionTexture.strength !== void 0) {
2257
+
2258
+ if (materialDef.occlusionTexture !== undefined && materialType !== MeshBasicMaterial) {
2259
+ pending.push(parser.assignTexture(materialParams, 'aoMap', materialDef.occlusionTexture));
2260
+
2261
+ if (materialDef.occlusionTexture.strength !== undefined) {
1745
2262
  materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
1746
2263
  }
1747
2264
  }
1748
- if (materialDef.emissiveFactor !== void 0 && materialType !== THREE.MeshBasicMaterial) {
1749
- materialParams.emissive = new THREE.Color().fromArray(materialDef.emissiveFactor);
2265
+
2266
+ if (materialDef.emissiveFactor !== undefined && materialType !== MeshBasicMaterial) {
2267
+ materialParams.emissive = new Color().fromArray(materialDef.emissiveFactor);
1750
2268
  }
1751
- if (materialDef.emissiveTexture !== void 0 && materialType !== THREE.MeshBasicMaterial) {
1752
- pending.push(parser.assignTexture(materialParams, "emissiveMap", materialDef.emissiveTexture));
2269
+
2270
+ if (materialDef.emissiveTexture !== undefined && materialType !== MeshBasicMaterial) {
2271
+ pending.push(parser.assignTexture(materialParams, 'emissiveMap', materialDef.emissiveTexture));
1753
2272
  }
1754
- return Promise.all(pending).then(function() {
2273
+
2274
+ return Promise.all(pending).then(function () {
1755
2275
  let material;
2276
+
1756
2277
  if (materialType === GLTFMeshStandardSGMaterial) {
1757
2278
  material = extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(materialParams);
1758
2279
  } else {
1759
2280
  material = new materialType(materialParams);
1760
2281
  }
1761
- if (materialDef.name)
1762
- material.name = materialDef.name;
1763
- if (material.map)
1764
- material.map.encoding = THREE.sRGBEncoding;
1765
- if (material.emissiveMap)
1766
- material.emissiveMap.encoding = THREE.sRGBEncoding;
2282
+
2283
+ if (materialDef.name) material.name = materialDef.name; // baseColorTexture, emissiveTexture, and specularGlossinessTexture use sRGB encoding.
2284
+
2285
+ if (material.map) material.map.encoding = sRGBEncoding;
2286
+ if (material.emissiveMap) material.emissiveMap.encoding = sRGBEncoding;
1767
2287
  assignExtrasToUserData(material, materialDef);
1768
- parser.associations.set(material, { materials: materialIndex });
1769
- if (materialDef.extensions)
1770
- addUnknownExtensionsToUserData(extensions, material, materialDef);
2288
+ parser.associations.set(material, {
2289
+ materials: materialIndex
2290
+ });
2291
+ if (materialDef.extensions) addUnknownExtensionsToUserData(extensions, material, materialDef);
1771
2292
  return material;
1772
2293
  });
1773
2294
  }
2295
+ /** When Object3D instances are targeted by animation, they need unique names. */
2296
+
2297
+
1774
2298
  createUniqueName(originalName) {
1775
- const sanitizedName = THREE.PropertyBinding.sanitizeNodeName(originalName || "");
2299
+ const sanitizedName = PropertyBinding.sanitizeNodeName(originalName || '');
1776
2300
  let name = sanitizedName;
2301
+
1777
2302
  for (let i = 1; this.nodeNamesUsed[name]; ++i) {
1778
- name = sanitizedName + "_" + i;
2303
+ name = sanitizedName + '_' + i;
1779
2304
  }
2305
+
1780
2306
  this.nodeNamesUsed[name] = true;
1781
2307
  return name;
1782
2308
  }
2309
+ /**
2310
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
2311
+ *
2312
+ * Creates BufferGeometries from primitives.
2313
+ *
2314
+ * @param {Array<GLTF.Primitive>} primitives
2315
+ * @return {Promise<Array<BufferGeometry>>}
2316
+ */
2317
+
2318
+
1783
2319
  loadGeometries(primitives) {
1784
2320
  const parser = this;
1785
2321
  const extensions = this.extensions;
1786
2322
  const cache = this.primitiveCache;
2323
+
1787
2324
  function createDracoPrimitive(primitive) {
1788
- return extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(primitive, parser).then(function(geometry) {
2325
+ return extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(primitive, parser).then(function (geometry) {
1789
2326
  return addPrimitiveAttributes(geometry, primitive, parser);
1790
2327
  });
1791
2328
  }
2329
+
1792
2330
  const pending = [];
2331
+
1793
2332
  for (let i = 0, il = primitives.length; i < il; i++) {
1794
2333
  const primitive = primitives[i];
1795
- const cacheKey = createPrimitiveKey(primitive);
2334
+ const cacheKey = createPrimitiveKey(primitive); // See if we've already created this geometry
2335
+
1796
2336
  const cached = cache[cacheKey];
2337
+
1797
2338
  if (cached) {
2339
+ // Use the cached geometry if it exists
1798
2340
  pending.push(cached.promise);
1799
2341
  } else {
1800
2342
  let geometryPromise;
2343
+
1801
2344
  if (primitive.extensions && primitive.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION]) {
2345
+ // Use DRACO geometry if available
1802
2346
  geometryPromise = createDracoPrimitive(primitive);
1803
2347
  } else {
1804
- geometryPromise = addPrimitiveAttributes(new THREE.BufferGeometry(), primitive, parser);
1805
- }
1806
- cache[cacheKey] = { primitive, promise: geometryPromise };
2348
+ // Otherwise create a new geometry
2349
+ geometryPromise = addPrimitiveAttributes(new BufferGeometry(), primitive, parser);
2350
+ } // Cache this geometry
2351
+
2352
+
2353
+ cache[cacheKey] = {
2354
+ primitive: primitive,
2355
+ promise: geometryPromise
2356
+ };
1807
2357
  pending.push(geometryPromise);
1808
2358
  }
1809
2359
  }
2360
+
1810
2361
  return Promise.all(pending);
1811
2362
  }
2363
+ /**
2364
+ * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
2365
+ * @param {number} meshIndex
2366
+ * @return {Promise<Group|Mesh|SkinnedMesh>}
2367
+ */
2368
+
2369
+
1812
2370
  loadMesh(meshIndex) {
1813
2371
  const parser = this;
1814
2372
  const json = this.json;
@@ -1816,102 +2374,142 @@ class GLTFParser {
1816
2374
  const meshDef = json.meshes[meshIndex];
1817
2375
  const primitives = meshDef.primitives;
1818
2376
  const pending = [];
2377
+
1819
2378
  for (let i = 0, il = primitives.length; i < il; i++) {
1820
- const material = primitives[i].material === void 0 ? createDefaultMaterial(this.cache) : this.getDependency("material", primitives[i].material);
2379
+ const material = primitives[i].material === undefined ? createDefaultMaterial(this.cache) : this.getDependency('material', primitives[i].material);
1821
2380
  pending.push(material);
1822
2381
  }
2382
+
1823
2383
  pending.push(parser.loadGeometries(primitives));
1824
- return Promise.all(pending).then(function(results) {
2384
+ return Promise.all(pending).then(function (results) {
1825
2385
  const materials = results.slice(0, results.length - 1);
1826
2386
  const geometries = results[results.length - 1];
1827
2387
  const meshes = [];
2388
+
1828
2389
  for (let i = 0, il = geometries.length; i < il; i++) {
1829
2390
  const geometry = geometries[i];
1830
- const primitive = primitives[i];
2391
+ const primitive = primitives[i]; // 1. create Mesh
2392
+
1831
2393
  let mesh;
1832
2394
  const material = materials[i];
1833
- if (primitive.mode === WEBGL_CONSTANTS.TRIANGLES || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN || primitive.mode === void 0) {
1834
- mesh = meshDef.isSkinnedMesh === true ? new THREE.SkinnedMesh(geometry, material) : new THREE.Mesh(geometry, material);
2395
+
2396
+ if (primitive.mode === WEBGL_CONSTANTS.TRIANGLES || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN || primitive.mode === undefined) {
2397
+ // .isSkinnedMesh isn't in glTF spec. See ._markDefs()
2398
+ mesh = meshDef.isSkinnedMesh === true ? new SkinnedMesh(geometry, material) : new Mesh(geometry, material);
2399
+
1835
2400
  if (mesh.isSkinnedMesh === true && !mesh.geometry.attributes.skinWeight.normalized) {
2401
+ // we normalize floating point skin weight array to fix malformed assets (see #15319)
2402
+ // it's important to skip this for non-float32 data since normalizeSkinWeights assumes non-normalized inputs
1836
2403
  mesh.normalizeSkinWeights();
1837
2404
  }
2405
+
1838
2406
  if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP) {
1839
- mesh.geometry = toTrianglesDrawMode(mesh.geometry, THREE.TriangleStripDrawMode);
2407
+ mesh.geometry = toTrianglesDrawMode(mesh.geometry, TriangleStripDrawMode);
1840
2408
  } else if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN) {
1841
- mesh.geometry = toTrianglesDrawMode(mesh.geometry, THREE.TriangleFanDrawMode);
2409
+ mesh.geometry = toTrianglesDrawMode(mesh.geometry, TriangleFanDrawMode);
1842
2410
  }
1843
2411
  } else if (primitive.mode === WEBGL_CONSTANTS.LINES) {
1844
- mesh = new THREE.LineSegments(geometry, material);
2412
+ mesh = new LineSegments(geometry, material);
1845
2413
  } else if (primitive.mode === WEBGL_CONSTANTS.LINE_STRIP) {
1846
- mesh = new THREE.Line(geometry, material);
2414
+ mesh = new Line(geometry, material);
1847
2415
  } else if (primitive.mode === WEBGL_CONSTANTS.LINE_LOOP) {
1848
- mesh = new THREE.LineLoop(geometry, material);
2416
+ mesh = new LineLoop(geometry, material);
1849
2417
  } else if (primitive.mode === WEBGL_CONSTANTS.POINTS) {
1850
- mesh = new THREE.Points(geometry, material);
2418
+ mesh = new Points(geometry, material);
1851
2419
  } else {
1852
- throw new Error("THREE.GLTFLoader: Primitive mode unsupported: " + primitive.mode);
2420
+ throw new Error('THREE.GLTFLoader: Primitive mode unsupported: ' + primitive.mode);
1853
2421
  }
2422
+
1854
2423
  if (Object.keys(mesh.geometry.morphAttributes).length > 0) {
1855
2424
  updateMorphTargets(mesh, meshDef);
1856
2425
  }
1857
- mesh.name = parser.createUniqueName(meshDef.name || "mesh_" + meshIndex);
2426
+
2427
+ mesh.name = parser.createUniqueName(meshDef.name || 'mesh_' + meshIndex);
1858
2428
  assignExtrasToUserData(mesh, meshDef);
1859
- if (primitive.extensions)
1860
- addUnknownExtensionsToUserData(extensions, mesh, primitive);
2429
+ if (primitive.extensions) addUnknownExtensionsToUserData(extensions, mesh, primitive);
1861
2430
  parser.assignFinalMaterial(mesh);
1862
2431
  meshes.push(mesh);
1863
2432
  }
2433
+
1864
2434
  for (let i = 0, il = meshes.length; i < il; i++) {
1865
2435
  parser.associations.set(meshes[i], {
1866
2436
  meshes: meshIndex,
1867
2437
  primitives: i
1868
2438
  });
1869
2439
  }
2440
+
1870
2441
  if (meshes.length === 1) {
1871
2442
  return meshes[0];
1872
2443
  }
1873
- const group = new THREE.Group();
1874
- parser.associations.set(group, { meshes: meshIndex });
2444
+
2445
+ const group = new Group();
2446
+ parser.associations.set(group, {
2447
+ meshes: meshIndex
2448
+ });
2449
+
1875
2450
  for (let i = 0, il = meshes.length; i < il; i++) {
1876
2451
  group.add(meshes[i]);
1877
2452
  }
2453
+
1878
2454
  return group;
1879
2455
  });
1880
2456
  }
2457
+ /**
2458
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
2459
+ * @param {number} cameraIndex
2460
+ * @return {Promise<THREE.Camera>}
2461
+ */
2462
+
2463
+
1881
2464
  loadCamera(cameraIndex) {
1882
2465
  let camera;
1883
2466
  const cameraDef = this.json.cameras[cameraIndex];
1884
2467
  const params = cameraDef[cameraDef.type];
2468
+
1885
2469
  if (!params) {
1886
- console.warn("THREE.GLTFLoader: Missing camera parameters.");
2470
+ console.warn('THREE.GLTFLoader: Missing camera parameters.');
1887
2471
  return;
1888
2472
  }
1889
- if (cameraDef.type === "perspective") {
1890
- camera = new THREE.PerspectiveCamera(
1891
- THREE.MathUtils.radToDeg(params.yfov),
1892
- params.aspectRatio || 1,
1893
- params.znear || 1,
1894
- params.zfar || 2e6
1895
- );
1896
- } else if (cameraDef.type === "orthographic") {
1897
- camera = new THREE.OrthographicCamera(-params.xmag, params.xmag, params.ymag, -params.ymag, params.znear, params.zfar);
1898
- }
1899
- if (cameraDef.name)
1900
- camera.name = this.createUniqueName(cameraDef.name);
2473
+
2474
+ if (cameraDef.type === 'perspective') {
2475
+ camera = new PerspectiveCamera(MathUtils.radToDeg(params.yfov), params.aspectRatio || 1, params.znear || 1, params.zfar || 2e6);
2476
+ } else if (cameraDef.type === 'orthographic') {
2477
+ camera = new OrthographicCamera(-params.xmag, params.xmag, params.ymag, -params.ymag, params.znear, params.zfar);
2478
+ }
2479
+
2480
+ if (cameraDef.name) camera.name = this.createUniqueName(cameraDef.name);
1901
2481
  assignExtrasToUserData(camera, cameraDef);
1902
2482
  return Promise.resolve(camera);
1903
2483
  }
2484
+ /**
2485
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
2486
+ * @param {number} skinIndex
2487
+ * @return {Promise<Object>}
2488
+ */
2489
+
2490
+
1904
2491
  loadSkin(skinIndex) {
1905
2492
  const skinDef = this.json.skins[skinIndex];
1906
- const skinEntry = { joints: skinDef.joints };
1907
- if (skinDef.inverseBindMatrices === void 0) {
2493
+ const skinEntry = {
2494
+ joints: skinDef.joints
2495
+ };
2496
+
2497
+ if (skinDef.inverseBindMatrices === undefined) {
1908
2498
  return Promise.resolve(skinEntry);
1909
2499
  }
1910
- return this.getDependency("accessor", skinDef.inverseBindMatrices).then(function(accessor) {
2500
+
2501
+ return this.getDependency('accessor', skinDef.inverseBindMatrices).then(function (accessor) {
1911
2502
  skinEntry.inverseBindMatrices = accessor;
1912
2503
  return skinEntry;
1913
2504
  });
1914
2505
  }
2506
+ /**
2507
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
2508
+ * @param {number} animationIndex
2509
+ * @return {Promise<AnimationClip>}
2510
+ */
2511
+
2512
+
1915
2513
  loadAnimation(animationIndex) {
1916
2514
  const json = this.json;
1917
2515
  const animationDef = json.animations[animationIndex];
@@ -1920,61 +2518,63 @@ class GLTFParser {
1920
2518
  const pendingOutputAccessors = [];
1921
2519
  const pendingSamplers = [];
1922
2520
  const pendingTargets = [];
2521
+
1923
2522
  for (let i = 0, il = animationDef.channels.length; i < il; i++) {
1924
2523
  const channel = animationDef.channels[i];
1925
2524
  const sampler = animationDef.samplers[channel.sampler];
1926
2525
  const target = channel.target;
1927
- const name = target.node !== void 0 ? target.node : target.id;
1928
- const input = animationDef.parameters !== void 0 ? animationDef.parameters[sampler.input] : sampler.input;
1929
- const output = animationDef.parameters !== void 0 ? animationDef.parameters[sampler.output] : sampler.output;
1930
- pendingNodes.push(this.getDependency("node", name));
1931
- pendingInputAccessors.push(this.getDependency("accessor", input));
1932
- pendingOutputAccessors.push(this.getDependency("accessor", output));
2526
+ const name = target.node !== undefined ? target.node : target.id; // NOTE: target.id is deprecated.
2527
+
2528
+ const input = animationDef.parameters !== undefined ? animationDef.parameters[sampler.input] : sampler.input;
2529
+ const output = animationDef.parameters !== undefined ? animationDef.parameters[sampler.output] : sampler.output;
2530
+ pendingNodes.push(this.getDependency('node', name));
2531
+ pendingInputAccessors.push(this.getDependency('accessor', input));
2532
+ pendingOutputAccessors.push(this.getDependency('accessor', output));
1933
2533
  pendingSamplers.push(sampler);
1934
2534
  pendingTargets.push(target);
1935
2535
  }
1936
- return Promise.all([
1937
- Promise.all(pendingNodes),
1938
- Promise.all(pendingInputAccessors),
1939
- Promise.all(pendingOutputAccessors),
1940
- Promise.all(pendingSamplers),
1941
- Promise.all(pendingTargets)
1942
- ]).then(function(dependencies) {
2536
+
2537
+ return Promise.all([Promise.all(pendingNodes), Promise.all(pendingInputAccessors), Promise.all(pendingOutputAccessors), Promise.all(pendingSamplers), Promise.all(pendingTargets)]).then(function (dependencies) {
1943
2538
  const nodes = dependencies[0];
1944
2539
  const inputAccessors = dependencies[1];
1945
2540
  const outputAccessors = dependencies[2];
1946
2541
  const samplers = dependencies[3];
1947
2542
  const targets = dependencies[4];
1948
2543
  const tracks = [];
2544
+
1949
2545
  for (let i = 0, il = nodes.length; i < il; i++) {
1950
2546
  const node = nodes[i];
1951
2547
  const inputAccessor = inputAccessors[i];
1952
2548
  const outputAccessor = outputAccessors[i];
1953
2549
  const sampler = samplers[i];
1954
2550
  const target = targets[i];
1955
- if (node === void 0)
1956
- continue;
2551
+ if (node === undefined) continue;
1957
2552
  node.updateMatrix();
1958
2553
  node.matrixAutoUpdate = true;
1959
2554
  let TypedKeyframeTrack;
2555
+
1960
2556
  switch (PATH_PROPERTIES[target.path]) {
1961
2557
  case PATH_PROPERTIES.weights:
1962
- TypedKeyframeTrack = THREE.NumberKeyframeTrack;
2558
+ TypedKeyframeTrack = NumberKeyframeTrack;
1963
2559
  break;
2560
+
1964
2561
  case PATH_PROPERTIES.rotation:
1965
- TypedKeyframeTrack = THREE.QuaternionKeyframeTrack;
2562
+ TypedKeyframeTrack = QuaternionKeyframeTrack;
1966
2563
  break;
2564
+
1967
2565
  case PATH_PROPERTIES.position:
1968
2566
  case PATH_PROPERTIES.scale:
1969
2567
  default:
1970
- TypedKeyframeTrack = THREE.VectorKeyframeTrack;
2568
+ TypedKeyframeTrack = VectorKeyframeTrack;
1971
2569
  break;
1972
2570
  }
2571
+
1973
2572
  const targetName = node.name ? node.name : node.uuid;
1974
- const interpolation = sampler.interpolation !== void 0 ? INTERPOLATION[sampler.interpolation] : THREE.InterpolateLinear;
2573
+ const interpolation = sampler.interpolation !== undefined ? INTERPOLATION[sampler.interpolation] : InterpolateLinear;
1975
2574
  const targetNames = [];
2575
+
1976
2576
  if (PATH_PROPERTIES[target.path] === PATH_PROPERTIES.weights) {
1977
- node.traverse(function(object) {
2577
+ node.traverse(function (object) {
1978
2578
  if (object.morphTargetInfluences) {
1979
2579
  targetNames.push(object.name ? object.name : object.uuid);
1980
2580
  }
@@ -1982,318 +2582,427 @@ class GLTFParser {
1982
2582
  } else {
1983
2583
  targetNames.push(targetName);
1984
2584
  }
2585
+
1985
2586
  let outputArray = outputAccessor.array;
2587
+
1986
2588
  if (outputAccessor.normalized) {
1987
2589
  const scale = getNormalizedComponentScale(outputArray.constructor);
1988
2590
  const scaled = new Float32Array(outputArray.length);
2591
+
1989
2592
  for (let j = 0, jl = outputArray.length; j < jl; j++) {
1990
2593
  scaled[j] = outputArray[j] * scale;
1991
2594
  }
2595
+
1992
2596
  outputArray = scaled;
1993
2597
  }
2598
+
1994
2599
  for (let j = 0, jl = targetNames.length; j < jl; j++) {
1995
- const track = new TypedKeyframeTrack(
1996
- targetNames[j] + "." + PATH_PROPERTIES[target.path],
1997
- inputAccessor.array,
1998
- outputArray,
1999
- interpolation
2000
- );
2001
- if (sampler.interpolation === "CUBICSPLINE") {
2600
+ const track = new TypedKeyframeTrack(targetNames[j] + '.' + PATH_PROPERTIES[target.path], inputAccessor.array, outputArray, interpolation); // Override interpolation with custom factory method.
2601
+
2602
+ if (sampler.interpolation === 'CUBICSPLINE') {
2002
2603
  track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline(result) {
2003
- const interpolantType = this instanceof THREE.QuaternionKeyframeTrack ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
2604
+ // A CUBICSPLINE keyframe in glTF has three output values for each input value,
2605
+ // representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
2606
+ // must be divided by three to get the interpolant's sampleSize argument.
2607
+ const interpolantType = this instanceof QuaternionKeyframeTrack ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
2004
2608
  return new interpolantType(this.times, this.values, this.getValueSize() / 3, result);
2005
- };
2609
+ }; // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
2610
+
2611
+
2006
2612
  track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
2007
2613
  }
2614
+
2008
2615
  tracks.push(track);
2009
2616
  }
2010
2617
  }
2011
- const name = animationDef.name ? animationDef.name : "animation_" + animationIndex;
2012
- return new THREE.AnimationClip(name, void 0, tracks);
2618
+
2619
+ const name = animationDef.name ? animationDef.name : 'animation_' + animationIndex;
2620
+ return new AnimationClip(name, undefined, tracks);
2013
2621
  });
2014
2622
  }
2623
+
2015
2624
  createNodeMesh(nodeIndex) {
2016
2625
  const json = this.json;
2017
2626
  const parser = this;
2018
2627
  const nodeDef = json.nodes[nodeIndex];
2019
- if (nodeDef.mesh === void 0)
2020
- return null;
2021
- return parser.getDependency("mesh", nodeDef.mesh).then(function(mesh) {
2022
- const node = parser._getNodeRef(parser.meshCache, nodeDef.mesh, mesh);
2023
- if (nodeDef.weights !== void 0) {
2024
- node.traverse(function(o) {
2025
- if (!o.isMesh)
2026
- return;
2628
+ if (nodeDef.mesh === undefined) return null;
2629
+ return parser.getDependency('mesh', nodeDef.mesh).then(function (mesh) {
2630
+ const node = parser._getNodeRef(parser.meshCache, nodeDef.mesh, mesh); // if weights are provided on the node, override weights on the mesh.
2631
+
2632
+
2633
+ if (nodeDef.weights !== undefined) {
2634
+ node.traverse(function (o) {
2635
+ if (!o.isMesh) return;
2636
+
2027
2637
  for (let i = 0, il = nodeDef.weights.length; i < il; i++) {
2028
2638
  o.morphTargetInfluences[i] = nodeDef.weights[i];
2029
2639
  }
2030
2640
  });
2031
2641
  }
2642
+
2032
2643
  return node;
2033
2644
  });
2034
2645
  }
2646
+ /**
2647
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
2648
+ * @param {number} nodeIndex
2649
+ * @return {Promise<Object3D>}
2650
+ */
2651
+
2652
+
2035
2653
  loadNode(nodeIndex) {
2036
2654
  const json = this.json;
2037
2655
  const extensions = this.extensions;
2038
2656
  const parser = this;
2039
- const nodeDef = json.nodes[nodeIndex];
2040
- const nodeName = nodeDef.name ? parser.createUniqueName(nodeDef.name) : "";
2041
- return function() {
2657
+ const nodeDef = json.nodes[nodeIndex]; // reserve node's name before its dependencies, so the root has the intended name.
2658
+
2659
+ const nodeName = nodeDef.name ? parser.createUniqueName(nodeDef.name) : '';
2660
+ return function () {
2042
2661
  const pending = [];
2043
- const meshPromise = parser._invokeOne(function(ext) {
2662
+
2663
+ const meshPromise = parser._invokeOne(function (ext) {
2044
2664
  return ext.createNodeMesh && ext.createNodeMesh(nodeIndex);
2045
2665
  });
2666
+
2046
2667
  if (meshPromise) {
2047
2668
  pending.push(meshPromise);
2048
2669
  }
2049
- if (nodeDef.camera !== void 0) {
2050
- pending.push(
2051
- parser.getDependency("camera", nodeDef.camera).then(function(camera) {
2052
- return parser._getNodeRef(parser.cameraCache, nodeDef.camera, camera);
2053
- })
2054
- );
2670
+
2671
+ if (nodeDef.camera !== undefined) {
2672
+ pending.push(parser.getDependency('camera', nodeDef.camera).then(function (camera) {
2673
+ return parser._getNodeRef(parser.cameraCache, nodeDef.camera, camera);
2674
+ }));
2055
2675
  }
2056
- parser._invokeAll(function(ext) {
2676
+
2677
+ parser._invokeAll(function (ext) {
2057
2678
  return ext.createNodeAttachment && ext.createNodeAttachment(nodeIndex);
2058
- }).forEach(function(promise) {
2679
+ }).forEach(function (promise) {
2059
2680
  pending.push(promise);
2060
2681
  });
2682
+
2061
2683
  return Promise.all(pending);
2062
- }().then(function(objects) {
2063
- let node;
2684
+ }().then(function (objects) {
2685
+ let node; // .isBone isn't in glTF spec. See ._markDefs
2686
+
2064
2687
  if (nodeDef.isBone === true) {
2065
- node = new THREE.Bone();
2688
+ node = new Bone();
2066
2689
  } else if (objects.length > 1) {
2067
- node = new THREE.Group();
2690
+ node = new Group();
2068
2691
  } else if (objects.length === 1) {
2069
2692
  node = objects[0];
2070
2693
  } else {
2071
- node = new THREE.Object3D();
2694
+ node = new Object3D();
2072
2695
  }
2696
+
2073
2697
  if (node !== objects[0]) {
2074
2698
  for (let i = 0, il = objects.length; i < il; i++) {
2075
2699
  node.add(objects[i]);
2076
2700
  }
2077
2701
  }
2702
+
2078
2703
  if (nodeDef.name) {
2079
2704
  node.userData.name = nodeDef.name;
2080
2705
  node.name = nodeName;
2081
2706
  }
2707
+
2082
2708
  assignExtrasToUserData(node, nodeDef);
2083
- if (nodeDef.extensions)
2084
- addUnknownExtensionsToUserData(extensions, node, nodeDef);
2085
- if (nodeDef.matrix !== void 0) {
2086
- const matrix = new THREE.Matrix4();
2709
+ if (nodeDef.extensions) addUnknownExtensionsToUserData(extensions, node, nodeDef);
2710
+
2711
+ if (nodeDef.matrix !== undefined) {
2712
+ const matrix = new Matrix4();
2087
2713
  matrix.fromArray(nodeDef.matrix);
2088
2714
  node.applyMatrix4(matrix);
2089
2715
  } else {
2090
- if (nodeDef.translation !== void 0) {
2716
+ if (nodeDef.translation !== undefined) {
2091
2717
  node.position.fromArray(nodeDef.translation);
2092
2718
  }
2093
- if (nodeDef.rotation !== void 0) {
2719
+
2720
+ if (nodeDef.rotation !== undefined) {
2094
2721
  node.quaternion.fromArray(nodeDef.rotation);
2095
2722
  }
2096
- if (nodeDef.scale !== void 0) {
2723
+
2724
+ if (nodeDef.scale !== undefined) {
2097
2725
  node.scale.fromArray(nodeDef.scale);
2098
2726
  }
2099
2727
  }
2728
+
2100
2729
  if (!parser.associations.has(node)) {
2101
2730
  parser.associations.set(node, {});
2102
2731
  }
2732
+
2103
2733
  parser.associations.get(node).nodes = nodeIndex;
2104
2734
  return node;
2105
2735
  });
2106
2736
  }
2737
+ /**
2738
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
2739
+ * @param {number} sceneIndex
2740
+ * @return {Promise<Group>}
2741
+ */
2742
+
2743
+
2107
2744
  loadScene(sceneIndex) {
2108
2745
  const json = this.json;
2109
2746
  const extensions = this.extensions;
2110
2747
  const sceneDef = this.json.scenes[sceneIndex];
2111
- const parser = this;
2112
- const scene = new THREE.Group();
2113
- if (sceneDef.name)
2114
- scene.name = parser.createUniqueName(sceneDef.name);
2748
+ const parser = this; // Loader returns Group, not Scene.
2749
+ // See: https://github.com/mrdoob/three.js/issues/18342#issuecomment-578981172
2750
+
2751
+ const scene = new Group();
2752
+ if (sceneDef.name) scene.name = parser.createUniqueName(sceneDef.name);
2115
2753
  assignExtrasToUserData(scene, sceneDef);
2116
- if (sceneDef.extensions)
2117
- addUnknownExtensionsToUserData(extensions, scene, sceneDef);
2754
+ if (sceneDef.extensions) addUnknownExtensionsToUserData(extensions, scene, sceneDef);
2118
2755
  const nodeIds = sceneDef.nodes || [];
2119
2756
  const pending = [];
2757
+
2120
2758
  for (let i = 0, il = nodeIds.length; i < il; i++) {
2121
2759
  pending.push(buildNodeHierarchy(nodeIds[i], scene, json, parser));
2122
2760
  }
2123
- return Promise.all(pending).then(function() {
2124
- const reduceAssociations = (node) => {
2125
- const reducedAssociations = /* @__PURE__ */ new Map();
2761
+
2762
+ return Promise.all(pending).then(function () {
2763
+ // Removes dangling associations, associations that reference a node that
2764
+ // didn't make it into the scene.
2765
+ const reduceAssociations = node => {
2766
+ const reducedAssociations = new Map();
2767
+
2126
2768
  for (const [key, value] of parser.associations) {
2127
- if (key instanceof THREE.Material || key instanceof THREE.Texture) {
2769
+ if (key instanceof Material || key instanceof Texture) {
2128
2770
  reducedAssociations.set(key, value);
2129
2771
  }
2130
2772
  }
2131
- node.traverse((node2) => {
2132
- const mappings = parser.associations.get(node2);
2773
+
2774
+ node.traverse(node => {
2775
+ const mappings = parser.associations.get(node);
2776
+
2133
2777
  if (mappings != null) {
2134
- reducedAssociations.set(node2, mappings);
2778
+ reducedAssociations.set(node, mappings);
2135
2779
  }
2136
2780
  });
2137
2781
  return reducedAssociations;
2138
2782
  };
2783
+
2139
2784
  parser.associations = reduceAssociations(scene);
2140
2785
  return scene;
2141
2786
  });
2142
2787
  }
2788
+
2143
2789
  }
2790
+
2144
2791
  function buildNodeHierarchy(nodeId, parentObject, json, parser) {
2145
2792
  const nodeDef = json.nodes[nodeId];
2146
- return parser.getDependency("node", nodeId).then(function(node) {
2147
- if (nodeDef.skin === void 0)
2148
- return node;
2793
+ return parser.getDependency('node', nodeId).then(function (node) {
2794
+ if (nodeDef.skin === undefined) return node; // build skeleton here as well
2795
+
2149
2796
  let skinEntry;
2150
- return parser.getDependency("skin", nodeDef.skin).then(function(skin) {
2797
+ return parser.getDependency('skin', nodeDef.skin).then(function (skin) {
2151
2798
  skinEntry = skin;
2152
2799
  const pendingJoints = [];
2800
+
2153
2801
  for (let i = 0, il = skinEntry.joints.length; i < il; i++) {
2154
- pendingJoints.push(parser.getDependency("node", skinEntry.joints[i]));
2802
+ pendingJoints.push(parser.getDependency('node', skinEntry.joints[i]));
2155
2803
  }
2804
+
2156
2805
  return Promise.all(pendingJoints);
2157
- }).then(function(jointNodes) {
2158
- node.traverse(function(mesh) {
2159
- if (!mesh.isMesh)
2160
- return;
2806
+ }).then(function (jointNodes) {
2807
+ node.traverse(function (mesh) {
2808
+ if (!mesh.isMesh) return;
2161
2809
  const bones = [];
2162
2810
  const boneInverses = [];
2811
+
2163
2812
  for (let j = 0, jl = jointNodes.length; j < jl; j++) {
2164
2813
  const jointNode = jointNodes[j];
2814
+
2165
2815
  if (jointNode) {
2166
2816
  bones.push(jointNode);
2167
- const mat = new THREE.Matrix4();
2168
- if (skinEntry.inverseBindMatrices !== void 0) {
2817
+ const mat = new Matrix4();
2818
+
2819
+ if (skinEntry.inverseBindMatrices !== undefined) {
2169
2820
  mat.fromArray(skinEntry.inverseBindMatrices.array, j * 16);
2170
2821
  }
2822
+
2171
2823
  boneInverses.push(mat);
2172
2824
  } else {
2173
2825
  console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', skinEntry.joints[j]);
2174
2826
  }
2175
2827
  }
2176
- mesh.bind(new THREE.Skeleton(bones, boneInverses), mesh.matrixWorld);
2828
+
2829
+ mesh.bind(new Skeleton(bones, boneInverses), mesh.matrixWorld);
2177
2830
  });
2178
2831
  return node;
2179
2832
  });
2180
- }).then(function(node) {
2833
+ }).then(function (node) {
2834
+ // build node hierachy
2181
2835
  parentObject.add(node);
2182
2836
  const pending = [];
2837
+
2183
2838
  if (nodeDef.children) {
2184
2839
  const children = nodeDef.children;
2840
+
2185
2841
  for (let i = 0, il = children.length; i < il; i++) {
2186
2842
  const child = children[i];
2187
2843
  pending.push(buildNodeHierarchy(child, node, json, parser));
2188
2844
  }
2189
2845
  }
2846
+
2190
2847
  return Promise.all(pending);
2191
2848
  });
2192
2849
  }
2850
+ /**
2851
+ * @param {BufferGeometry} geometry
2852
+ * @param {GLTF.Primitive} primitiveDef
2853
+ * @param {GLTFParser} parser
2854
+ */
2855
+
2856
+
2193
2857
  function computeBounds(geometry, primitiveDef, parser) {
2194
2858
  const attributes = primitiveDef.attributes;
2195
- const box = new THREE.Box3();
2196
- if (attributes.POSITION !== void 0) {
2859
+ const box = new Box3();
2860
+
2861
+ if (attributes.POSITION !== undefined) {
2197
2862
  const accessor = parser.json.accessors[attributes.POSITION];
2198
2863
  const min = accessor.min;
2199
- const max = accessor.max;
2200
- if (min !== void 0 && max !== void 0) {
2201
- box.set(new THREE.Vector3(min[0], min[1], min[2]), new THREE.Vector3(max[0], max[1], max[2]));
2864
+ const max = accessor.max; // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
2865
+
2866
+ if (min !== undefined && max !== undefined) {
2867
+ box.set(new Vector3(min[0], min[1], min[2]), new Vector3(max[0], max[1], max[2]));
2868
+
2202
2869
  if (accessor.normalized) {
2203
2870
  const boxScale = getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[accessor.componentType]);
2204
2871
  box.min.multiplyScalar(boxScale);
2205
2872
  box.max.multiplyScalar(boxScale);
2206
2873
  }
2207
2874
  } else {
2208
- console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
2875
+ console.warn('THREE.GLTFLoader: Missing min/max properties for accessor POSITION.');
2209
2876
  return;
2210
2877
  }
2211
2878
  } else {
2212
2879
  return;
2213
2880
  }
2881
+
2214
2882
  const targets = primitiveDef.targets;
2215
- if (targets !== void 0) {
2216
- const maxDisplacement = new THREE.Vector3();
2217
- const vector = new THREE.Vector3();
2883
+
2884
+ if (targets !== undefined) {
2885
+ const maxDisplacement = new Vector3();
2886
+ const vector = new Vector3();
2887
+
2218
2888
  for (let i = 0, il = targets.length; i < il; i++) {
2219
2889
  const target = targets[i];
2220
- if (target.POSITION !== void 0) {
2890
+
2891
+ if (target.POSITION !== undefined) {
2221
2892
  const accessor = parser.json.accessors[target.POSITION];
2222
2893
  const min = accessor.min;
2223
- const max = accessor.max;
2224
- if (min !== void 0 && max !== void 0) {
2894
+ const max = accessor.max; // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
2895
+
2896
+ if (min !== undefined && max !== undefined) {
2897
+ // we need to get max of absolute components because target weight is [-1,1]
2225
2898
  vector.setX(Math.max(Math.abs(min[0]), Math.abs(max[0])));
2226
2899
  vector.setY(Math.max(Math.abs(min[1]), Math.abs(max[1])));
2227
2900
  vector.setZ(Math.max(Math.abs(min[2]), Math.abs(max[2])));
2901
+
2228
2902
  if (accessor.normalized) {
2229
2903
  const boxScale = getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[accessor.componentType]);
2230
2904
  vector.multiplyScalar(boxScale);
2231
- }
2905
+ } // Note: this assumes that the sum of all weights is at most 1. This isn't quite correct - it's more conservative
2906
+ // to assume that each target can have a max weight of 1. However, for some use cases - notably, when morph targets
2907
+ // are used to implement key-frame animations and as such only two are active at a time - this results in very large
2908
+ // boxes. So for now we make a box that's sometimes a touch too small but is hopefully mostly of reasonable size.
2909
+
2910
+
2232
2911
  maxDisplacement.max(vector);
2233
2912
  } else {
2234
- console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
2913
+ console.warn('THREE.GLTFLoader: Missing min/max properties for accessor POSITION.');
2235
2914
  }
2236
2915
  }
2237
- }
2916
+ } // As per comment above this box isn't conservative, but has a reasonable size for a very large number of morph targets.
2917
+
2918
+
2238
2919
  box.expandByVector(maxDisplacement);
2239
2920
  }
2921
+
2240
2922
  geometry.boundingBox = box;
2241
- const sphere = new THREE.Sphere();
2923
+ const sphere = new Sphere();
2242
2924
  box.getCenter(sphere.center);
2243
2925
  sphere.radius = box.min.distanceTo(box.max) / 2;
2244
2926
  geometry.boundingSphere = sphere;
2245
2927
  }
2928
+ /**
2929
+ * @param {BufferGeometry} geometry
2930
+ * @param {GLTF.Primitive} primitiveDef
2931
+ * @param {GLTFParser} parser
2932
+ * @return {Promise<BufferGeometry>}
2933
+ */
2934
+
2935
+
2246
2936
  function addPrimitiveAttributes(geometry, primitiveDef, parser) {
2247
2937
  const attributes = primitiveDef.attributes;
2248
2938
  const pending = [];
2939
+
2249
2940
  function assignAttributeAccessor(accessorIndex, attributeName) {
2250
- return parser.getDependency("accessor", accessorIndex).then(function(accessor) {
2941
+ return parser.getDependency('accessor', accessorIndex).then(function (accessor) {
2251
2942
  geometry.setAttribute(attributeName, accessor);
2252
2943
  });
2253
2944
  }
2945
+
2254
2946
  for (const gltfAttributeName in attributes) {
2255
- const threeAttributeName = ATTRIBUTES[gltfAttributeName] || gltfAttributeName.toLowerCase();
2256
- if (threeAttributeName in geometry.attributes)
2257
- continue;
2947
+ const threeAttributeName = ATTRIBUTES[gltfAttributeName] || gltfAttributeName.toLowerCase(); // Skip attributes already provided by e.g. Draco extension.
2948
+
2949
+ if (threeAttributeName in geometry.attributes) continue;
2258
2950
  pending.push(assignAttributeAccessor(attributes[gltfAttributeName], threeAttributeName));
2259
2951
  }
2260
- if (primitiveDef.indices !== void 0 && !geometry.index) {
2261
- const accessor = parser.getDependency("accessor", primitiveDef.indices).then(function(accessor2) {
2262
- geometry.setIndex(accessor2);
2952
+
2953
+ if (primitiveDef.indices !== undefined && !geometry.index) {
2954
+ const accessor = parser.getDependency('accessor', primitiveDef.indices).then(function (accessor) {
2955
+ geometry.setIndex(accessor);
2263
2956
  });
2264
2957
  pending.push(accessor);
2265
2958
  }
2959
+
2266
2960
  assignExtrasToUserData(geometry, primitiveDef);
2267
2961
  computeBounds(geometry, primitiveDef, parser);
2268
- return Promise.all(pending).then(function() {
2269
- return primitiveDef.targets !== void 0 ? addMorphTargets(geometry, primitiveDef.targets, parser) : geometry;
2962
+ return Promise.all(pending).then(function () {
2963
+ return primitiveDef.targets !== undefined ? addMorphTargets(geometry, primitiveDef.targets, parser) : geometry;
2270
2964
  });
2271
2965
  }
2966
+ /**
2967
+ * @param {BufferGeometry} geometry
2968
+ * @param {Number} drawMode
2969
+ * @return {BufferGeometry}
2970
+ */
2971
+
2972
+
2272
2973
  function toTrianglesDrawMode(geometry, drawMode) {
2273
- let index = geometry.getIndex();
2974
+ let index = geometry.getIndex(); // generate index if not present
2975
+
2274
2976
  if (index === null) {
2275
2977
  const indices = [];
2276
- const position = geometry.getAttribute("position");
2277
- if (position !== void 0) {
2978
+ const position = geometry.getAttribute('position');
2979
+
2980
+ if (position !== undefined) {
2278
2981
  for (let i = 0; i < position.count; i++) {
2279
2982
  indices.push(i);
2280
2983
  }
2984
+
2281
2985
  geometry.setIndex(indices);
2282
2986
  index = geometry.getIndex();
2283
2987
  } else {
2284
- console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.");
2988
+ console.error('THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.');
2285
2989
  return geometry;
2286
2990
  }
2287
- }
2991
+ } //
2992
+
2993
+
2288
2994
  const numberOfTriangles = index.count - 2;
2289
2995
  const newIndices = [];
2290
- if (drawMode === THREE.TriangleFanDrawMode) {
2996
+
2997
+ if (drawMode === TriangleFanDrawMode) {
2998
+ // gl.TRIANGLE_FAN
2291
2999
  for (let i = 1; i <= numberOfTriangles; i++) {
2292
3000
  newIndices.push(index.getX(0));
2293
3001
  newIndices.push(index.getX(i));
2294
3002
  newIndices.push(index.getX(i + 1));
2295
3003
  }
2296
3004
  } else {
3005
+ // gl.TRIANGLE_STRIP
2297
3006
  for (let i = 0; i < numberOfTriangles; i++) {
2298
3007
  if (i % 2 === 0) {
2299
3008
  newIndices.push(index.getX(i));
@@ -2306,11 +3015,15 @@ function toTrianglesDrawMode(geometry, drawMode) {
2306
3015
  }
2307
3016
  }
2308
3017
  }
3018
+
2309
3019
  if (newIndices.length / 3 !== numberOfTriangles) {
2310
- console.error("THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");
2311
- }
3020
+ console.error('THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.');
3021
+ } // build final geometry
3022
+
3023
+
2312
3024
  const newGeometry = geometry.clone();
2313
3025
  newGeometry.setIndex(newIndices);
2314
3026
  return newGeometry;
2315
3027
  }
2316
- exports.GLTFLoader = GLTFLoader;
3028
+
3029
+ export { GLTFLoader };