@needle-tools/three 0.146.10 → 0.153.0

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