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