@plastic-software/three 0.181.3 → 0.183.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 (437) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -4
  3. package/build/three.cjs +11330 -10017
  4. package/build/three.core.js +10011 -9493
  5. package/build/three.core.min.js +2 -2
  6. package/build/three.module.js +1414 -631
  7. package/build/three.module.min.js +2 -2
  8. package/build/three.tsl.js +21 -13
  9. package/build/three.tsl.min.js +2 -2
  10. package/build/three.webgpu.js +8007 -5427
  11. package/build/three.webgpu.min.js +2 -2
  12. package/build/three.webgpu.nodes.js +8005 -5426
  13. package/build/three.webgpu.nodes.min.js +2 -2
  14. package/examples/jsm/Addons.js +0 -3
  15. package/examples/jsm/animation/CCDIKSolver.js +2 -2
  16. package/examples/jsm/controls/ArcballControls.js +3 -3
  17. package/examples/jsm/controls/MapControls.js +55 -1
  18. package/examples/jsm/controls/OrbitControls.js +109 -6
  19. package/examples/jsm/controls/TrackballControls.js +6 -6
  20. package/examples/jsm/csm/CSM.js +2 -1
  21. package/examples/jsm/effects/AnaglyphEffect.js +102 -7
  22. package/examples/jsm/environments/ColorEnvironment.js +59 -0
  23. package/examples/jsm/environments/RoomEnvironment.js +3 -0
  24. package/examples/jsm/exporters/EXRExporter.js +1 -1
  25. package/examples/jsm/exporters/GLTFExporter.js +131 -4
  26. package/examples/jsm/exporters/USDZExporter.js +22 -3
  27. package/examples/jsm/geometries/DecalGeometry.js +1 -1
  28. package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
  29. package/examples/jsm/helpers/LightProbeHelperGPU.js +1 -1
  30. package/examples/jsm/helpers/TextureHelperGPU.js +1 -1
  31. package/examples/jsm/helpers/ViewHelper.js +67 -8
  32. package/examples/jsm/inspector/Inspector.js +74 -14
  33. package/examples/jsm/inspector/RendererInspector.js +12 -2
  34. package/examples/jsm/inspector/tabs/Console.js +41 -7
  35. package/examples/jsm/inspector/tabs/Parameters.js +18 -2
  36. package/examples/jsm/inspector/tabs/Performance.js +2 -2
  37. package/examples/jsm/inspector/tabs/Viewer.js +4 -4
  38. package/examples/jsm/inspector/ui/Profiler.js +1836 -31
  39. package/examples/jsm/inspector/ui/Style.js +973 -14
  40. package/examples/jsm/inspector/ui/Tab.js +188 -1
  41. package/examples/jsm/inspector/ui/Values.js +17 -1
  42. package/examples/jsm/libs/meshopt_decoder.module.js +6 -5
  43. package/examples/jsm/lines/LineMaterial.js +6 -0
  44. package/examples/jsm/loaders/3DMLoader.js +5 -4
  45. package/examples/jsm/loaders/3MFLoader.js +2 -2
  46. package/examples/jsm/loaders/AMFLoader.js +2 -2
  47. package/examples/jsm/loaders/ColladaLoader.js +24 -4026
  48. package/examples/jsm/loaders/DRACOLoader.js +5 -5
  49. package/examples/jsm/loaders/EXRLoader.js +5 -5
  50. package/examples/jsm/loaders/FBXLoader.js +2 -4
  51. package/examples/jsm/loaders/GCodeLoader.js +34 -8
  52. package/examples/jsm/loaders/GLTFLoader.js +122 -171
  53. package/examples/jsm/loaders/HDRLoader.js +0 -1
  54. package/examples/jsm/loaders/KMZLoader.js +5 -5
  55. package/examples/jsm/loaders/KTX2Loader.js +19 -3
  56. package/examples/jsm/loaders/LDrawLoader.js +2 -3
  57. package/examples/jsm/loaders/LWOLoader.js +7 -39
  58. package/examples/jsm/loaders/NRRDLoader.js +2 -2
  59. package/examples/jsm/loaders/PCDLoader.js +4 -2
  60. package/examples/jsm/loaders/SVGLoader.js +1 -1
  61. package/examples/jsm/loaders/TDSLoader.js +0 -2
  62. package/examples/jsm/loaders/TGALoader.js +0 -2
  63. package/examples/jsm/loaders/USDLoader.js +100 -40
  64. package/examples/jsm/loaders/UltraHDRLoader.js +285 -160
  65. package/examples/jsm/loaders/VOXLoader.js +660 -117
  66. package/examples/jsm/loaders/VRMLLoader.js +79 -2
  67. package/examples/jsm/loaders/VTKLoader.js +37 -24
  68. package/examples/jsm/loaders/collada/ColladaComposer.js +2950 -0
  69. package/examples/jsm/loaders/collada/ColladaParser.js +1962 -0
  70. package/examples/jsm/loaders/usd/USDAParser.js +447 -366
  71. package/examples/jsm/loaders/usd/USDCParser.js +1841 -6
  72. package/examples/jsm/loaders/usd/USDComposer.js +4041 -0
  73. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +2 -2
  74. package/examples/jsm/materials/WoodNodeMaterial.js +11 -11
  75. package/examples/jsm/math/Octree.js +131 -1
  76. package/examples/jsm/misc/Volume.js +0 -1
  77. package/examples/jsm/misc/VolumeSlice.js +0 -1
  78. package/examples/jsm/objects/LensflareMesh.js +1 -1
  79. package/examples/jsm/objects/Sky.js +76 -4
  80. package/examples/jsm/objects/SkyMesh.js +127 -10
  81. package/examples/jsm/objects/Water.js +4 -3
  82. package/examples/jsm/objects/Water2.js +5 -3
  83. package/examples/jsm/objects/WaterMesh.js +5 -7
  84. package/examples/jsm/physics/AmmoPhysics.js +12 -7
  85. package/examples/jsm/physics/JoltPhysics.js +10 -6
  86. package/examples/jsm/physics/RapierPhysics.js +9 -5
  87. package/examples/jsm/postprocessing/EffectComposer.js +7 -5
  88. package/examples/jsm/postprocessing/OutputPass.js +9 -0
  89. package/examples/jsm/postprocessing/RenderPass.js +10 -0
  90. package/examples/jsm/postprocessing/RenderTransitionPass.js +1 -1
  91. package/examples/jsm/postprocessing/UnrealBloomPass.js +48 -18
  92. package/examples/jsm/renderers/CSS3DRenderer.js +1 -1
  93. package/examples/jsm/renderers/Projector.js +268 -30
  94. package/examples/jsm/renderers/SVGRenderer.js +193 -60
  95. package/examples/jsm/shaders/GTAOShader.js +19 -6
  96. package/examples/jsm/shaders/HalftoneShader.js +12 -1
  97. package/examples/jsm/shaders/PoissonDenoiseShader.js +6 -2
  98. package/examples/jsm/shaders/SAOShader.js +17 -4
  99. package/examples/jsm/shaders/SSAOShader.js +11 -1
  100. package/examples/jsm/shaders/SSRShader.js +6 -5
  101. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -4
  102. package/examples/jsm/shaders/VignetteShader.js +1 -1
  103. package/examples/jsm/transpiler/AST.js +44 -0
  104. package/examples/jsm/transpiler/GLSLDecoder.js +61 -4
  105. package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -0
  106. package/examples/jsm/transpiler/TSLEncoder.js +46 -3
  107. package/examples/jsm/transpiler/TranspilerUtils.js +3 -3
  108. package/examples/jsm/transpiler/WGSLEncoder.js +27 -0
  109. package/examples/jsm/tsl/display/AfterImageNode.js +1 -1
  110. package/examples/jsm/tsl/display/AnaglyphPassNode.js +458 -16
  111. package/examples/jsm/tsl/display/AnamorphicNode.js +1 -1
  112. package/examples/jsm/tsl/display/BilateralBlurNode.js +364 -0
  113. package/examples/jsm/tsl/display/BloomNode.js +16 -6
  114. package/examples/jsm/tsl/display/CRT.js +150 -0
  115. package/examples/jsm/tsl/display/DenoiseNode.js +1 -1
  116. package/examples/jsm/tsl/display/DepthOfFieldNode.js +1 -1
  117. package/examples/jsm/tsl/display/DotScreenNode.js +1 -1
  118. package/examples/jsm/tsl/display/FXAANode.js +2 -2
  119. package/examples/jsm/tsl/display/GTAONode.js +5 -4
  120. package/examples/jsm/tsl/display/GaussianBlurNode.js +11 -2
  121. package/examples/jsm/tsl/display/GodraysNode.js +624 -0
  122. package/examples/jsm/tsl/display/LensflareNode.js +1 -1
  123. package/examples/jsm/tsl/display/Lut3DNode.js +1 -1
  124. package/examples/jsm/tsl/display/OutlineNode.js +3 -3
  125. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +2 -2
  126. package/examples/jsm/tsl/display/PixelationPassNode.js +7 -6
  127. package/examples/jsm/tsl/display/RGBShiftNode.js +2 -2
  128. package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
  129. package/examples/jsm/tsl/display/SMAANode.js +2 -2
  130. package/examples/jsm/tsl/display/SSAAPassNode.js +2 -2
  131. package/examples/jsm/tsl/display/SSGINode.js +8 -20
  132. package/examples/jsm/tsl/display/SSRNode.js +8 -8
  133. package/examples/jsm/tsl/display/SSSNode.js +6 -4
  134. package/examples/jsm/tsl/display/Shape.js +29 -0
  135. package/examples/jsm/tsl/display/SobelOperatorNode.js +2 -2
  136. package/examples/jsm/tsl/display/StereoCompositePassNode.js +8 -1
  137. package/examples/jsm/tsl/display/StereoPassNode.js +1 -2
  138. package/examples/jsm/tsl/display/TRAANode.js +273 -125
  139. package/examples/jsm/tsl/display/TransitionNode.js +1 -1
  140. package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
  141. package/examples/jsm/tsl/display/radialBlur.js +68 -0
  142. package/examples/jsm/tsl/math/Bayer.js +40 -1
  143. package/examples/jsm/utils/LDrawUtils.js +1 -1
  144. package/examples/jsm/utils/ShadowMapViewer.js +24 -10
  145. package/examples/jsm/utils/ShadowMapViewerGPU.js +1 -1
  146. package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
  147. package/package.json +20 -26
  148. package/src/Three.Core.js +2 -1
  149. package/src/Three.TSL.js +19 -11
  150. package/src/Three.WebGPU.Nodes.js +2 -0
  151. package/src/Three.WebGPU.js +3 -0
  152. package/src/Three.js +1 -0
  153. package/src/animation/AnimationAction.js +1 -1
  154. package/src/animation/AnimationClip.js +1 -1
  155. package/src/animation/AnimationMixer.js +6 -0
  156. package/src/animation/AnimationUtils.js +1 -12
  157. package/src/animation/KeyframeTrack.js +47 -8
  158. package/src/animation/PropertyMixer.js +4 -4
  159. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  160. package/src/animation/tracks/ColorKeyframeTrack.js +1 -1
  161. package/src/animation/tracks/NumberKeyframeTrack.js +1 -1
  162. package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -1
  163. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  164. package/src/animation/tracks/VectorKeyframeTrack.js +1 -1
  165. package/src/audio/Audio.js +1 -1
  166. package/src/audio/AudioListener.js +5 -3
  167. package/src/cameras/Camera.js +32 -2
  168. package/src/cameras/CubeCamera.js +20 -0
  169. package/src/constants.js +90 -5
  170. package/src/core/BufferGeometry.js +14 -2
  171. package/src/core/Clock.js +7 -0
  172. package/src/core/Object3D.js +56 -4
  173. package/src/core/Raycaster.js +2 -2
  174. package/src/core/RenderTarget.js +3 -4
  175. package/src/extras/PMREMGenerator.js +7 -18
  176. package/src/extras/TextureUtils.js +5 -1
  177. package/src/geometries/ExtrudeGeometry.js +2 -2
  178. package/src/geometries/PolyhedronGeometry.js +1 -1
  179. package/src/geometries/TorusGeometry.js +8 -3
  180. package/src/helpers/CameraHelper.js +3 -0
  181. package/src/helpers/DirectionalLightHelper.js +4 -1
  182. package/src/helpers/HemisphereLightHelper.js +3 -0
  183. package/src/helpers/PointLightHelper.js +1 -25
  184. package/src/helpers/SpotLightHelper.js +3 -0
  185. package/src/lights/DirectionalLight.js +13 -0
  186. package/src/lights/HemisphereLight.js +10 -0
  187. package/src/lights/Light.js +1 -11
  188. package/src/lights/LightProbe.js +0 -15
  189. package/src/lights/LightShadow.js +15 -6
  190. package/src/lights/PointLight.js +15 -0
  191. package/src/lights/PointLightShadow.js +0 -86
  192. package/src/lights/SpotLight.js +22 -1
  193. package/src/lights/webgpu/IESSpotLight.js +2 -1
  194. package/src/loaders/Cache.js +28 -0
  195. package/src/loaders/FileLoader.js +1 -1
  196. package/src/loaders/ImageBitmapLoader.js +8 -3
  197. package/src/loaders/Loader.js +6 -0
  198. package/src/loaders/MaterialLoader.js +2 -1
  199. package/src/loaders/ObjectLoader.js +21 -2
  200. package/src/loaders/nodes/NodeLoader.js +2 -2
  201. package/src/materials/Material.js +2 -0
  202. package/src/materials/MeshLambertMaterial.js +9 -0
  203. package/src/materials/MeshPhongMaterial.js +9 -0
  204. package/src/materials/ShaderMaterial.js +20 -1
  205. package/src/materials/nodes/Line2NodeMaterial.js +7 -7
  206. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +5 -2
  207. package/src/materials/nodes/MeshStandardNodeMaterial.js +5 -4
  208. package/src/materials/nodes/NodeMaterial.js +72 -25
  209. package/src/materials/nodes/manager/NodeMaterialObserver.js +10 -4
  210. package/src/math/Line3.js +3 -5
  211. package/src/math/MathUtils.js +10 -10
  212. package/src/math/Matrix4.js +74 -65
  213. package/src/math/Quaternion.js +3 -29
  214. package/src/math/Sphere.js +1 -1
  215. package/src/math/Vector3.js +3 -5
  216. package/src/math/interpolants/BezierInterpolant.js +108 -0
  217. package/src/nodes/Nodes.js +87 -68
  218. package/src/nodes/TSL.js +6 -6
  219. package/src/nodes/accessors/Arrays.js +1 -1
  220. package/src/nodes/accessors/BatchNode.js +10 -10
  221. package/src/nodes/accessors/Bitangent.js +5 -5
  222. package/src/nodes/accessors/BufferAttributeNode.js +98 -12
  223. package/src/nodes/accessors/BufferNode.js +29 -2
  224. package/src/nodes/accessors/Camera.js +149 -28
  225. package/src/nodes/accessors/ClippingNode.js +4 -4
  226. package/src/nodes/accessors/CubeTextureNode.js +20 -1
  227. package/src/nodes/accessors/InstanceNode.js +148 -43
  228. package/src/nodes/accessors/MaterialNode.js +9 -1
  229. package/src/nodes/accessors/MaterialReferenceNode.js +1 -2
  230. package/src/nodes/accessors/ModelNode.js +1 -1
  231. package/src/nodes/accessors/Normal.js +11 -11
  232. package/src/nodes/accessors/Position.js +34 -2
  233. package/src/nodes/accessors/ReferenceBaseNode.js +4 -4
  234. package/src/nodes/accessors/ReferenceNode.js +4 -4
  235. package/src/nodes/accessors/RendererReferenceNode.js +1 -2
  236. package/src/nodes/accessors/SceneProperties.js +53 -0
  237. package/src/nodes/accessors/SkinningNode.js +27 -26
  238. package/src/nodes/accessors/StorageBufferNode.js +4 -21
  239. package/src/nodes/accessors/StorageTextureNode.js +37 -1
  240. package/src/nodes/accessors/Tangent.js +4 -14
  241. package/src/nodes/accessors/Texture3DNode.js +32 -35
  242. package/src/nodes/accessors/TextureNode.js +58 -22
  243. package/src/nodes/accessors/UniformArrayNode.js +4 -2
  244. package/src/nodes/accessors/UserDataNode.js +1 -2
  245. package/src/nodes/accessors/VertexColorNode.js +1 -2
  246. package/src/nodes/code/FunctionNode.js +1 -2
  247. package/src/nodes/core/ArrayNode.js +20 -1
  248. package/src/nodes/core/AssignNode.js +2 -2
  249. package/src/nodes/core/AttributeNode.js +2 -2
  250. package/src/nodes/core/ContextNode.js +103 -4
  251. package/src/nodes/core/MRTNode.js +48 -2
  252. package/src/nodes/core/Node.js +29 -3
  253. package/src/nodes/core/NodeBuilder.js +170 -53
  254. package/src/nodes/core/NodeError.js +28 -0
  255. package/src/nodes/core/NodeFrame.js +12 -4
  256. package/src/nodes/core/NodeUtils.js +10 -8
  257. package/src/nodes/core/OutputStructNode.js +12 -10
  258. package/src/nodes/core/ParameterNode.js +3 -3
  259. package/src/nodes/core/PropertyNode.js +19 -3
  260. package/src/nodes/core/StackNode.js +65 -16
  261. package/src/nodes/core/StackTrace.js +139 -0
  262. package/src/nodes/core/StructNode.js +16 -2
  263. package/src/nodes/core/StructTypeNode.js +11 -17
  264. package/src/nodes/core/SubBuildNode.js +1 -1
  265. package/src/nodes/core/UniformNode.js +21 -5
  266. package/src/nodes/core/VarNode.js +47 -22
  267. package/src/nodes/core/VaryingNode.js +1 -18
  268. package/src/nodes/display/BlendModes.js +0 -64
  269. package/src/nodes/display/ColorAdjustment.js +17 -0
  270. package/src/nodes/display/ColorSpaceNode.js +3 -3
  271. package/src/nodes/display/NormalMapNode.js +39 -4
  272. package/src/nodes/display/PassNode.js +98 -9
  273. package/src/nodes/display/RenderOutputNode.js +3 -3
  274. package/src/nodes/display/ScreenNode.js +3 -1
  275. package/src/nodes/display/ToneMappingNode.js +1 -1
  276. package/src/nodes/display/ToonOutlinePassNode.js +2 -2
  277. package/src/nodes/display/ViewportDepthNode.js +52 -4
  278. package/src/nodes/display/ViewportTextureNode.js +21 -4
  279. package/src/nodes/fog/Fog.js +18 -35
  280. package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +3 -3
  281. package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
  282. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  283. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +1 -1
  284. package/src/nodes/functions/PhysicalLightingModel.js +126 -45
  285. package/src/nodes/geometry/RangeNode.js +4 -2
  286. package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -2
  287. package/src/nodes/gpgpu/ComputeNode.js +5 -4
  288. package/src/nodes/gpgpu/SubgroupFunctionNode.js +1 -1
  289. package/src/nodes/gpgpu/WorkgroupInfoNode.js +4 -4
  290. package/src/nodes/lighting/AnalyticLightNode.js +53 -0
  291. package/src/nodes/lighting/EnvironmentNode.js +28 -3
  292. package/src/nodes/lighting/LightsNode.js +2 -2
  293. package/src/nodes/lighting/PointShadowNode.js +162 -149
  294. package/src/nodes/lighting/ShadowFilterNode.js +53 -65
  295. package/src/nodes/lighting/ShadowNode.js +97 -41
  296. package/src/nodes/math/BitcountNode.js +433 -0
  297. package/src/nodes/math/ConditionalNode.js +2 -2
  298. package/src/nodes/math/MathNode.js +3 -40
  299. package/src/nodes/math/OperatorNode.js +2 -1
  300. package/src/nodes/math/PackFloatNode.js +98 -0
  301. package/src/nodes/math/UnpackFloatNode.js +96 -0
  302. package/src/nodes/pmrem/PMREMNode.js +1 -1
  303. package/src/nodes/pmrem/PMREMUtils.js +9 -15
  304. package/src/nodes/tsl/TSLCore.js +17 -14
  305. package/src/nodes/utils/ArrayElementNode.js +13 -0
  306. package/src/nodes/utils/DebugNode.js +11 -11
  307. package/src/nodes/utils/EventNode.js +1 -2
  308. package/src/nodes/utils/JoinNode.js +2 -2
  309. package/src/nodes/utils/LoopNode.js +1 -1
  310. package/src/nodes/utils/MemberNode.js +1 -1
  311. package/src/nodes/utils/Packing.js +13 -1
  312. package/src/nodes/utils/PostProcessingUtils.js +33 -1
  313. package/src/nodes/utils/RTTNode.js +1 -1
  314. package/src/nodes/utils/ReflectorNode.js +3 -4
  315. package/src/nodes/utils/SampleNode.js +1 -1
  316. package/src/nodes/utils/SpriteSheetUV.js +35 -0
  317. package/src/nodes/utils/UVUtils.js +28 -0
  318. package/src/objects/BatchedMesh.js +27 -14
  319. package/src/objects/InstancedMesh.js +11 -0
  320. package/src/objects/Line.js +1 -1
  321. package/src/objects/Mesh.js +1 -1
  322. package/src/objects/Points.js +1 -1
  323. package/src/objects/Skeleton.js +9 -0
  324. package/src/renderers/WebGLRenderer.js +178 -92
  325. package/src/renderers/common/Backend.js +29 -0
  326. package/src/renderers/common/Background.js +24 -11
  327. package/src/renderers/common/BindGroup.js +1 -9
  328. package/src/renderers/common/Binding.js +11 -0
  329. package/src/renderers/common/Bindings.js +27 -12
  330. package/src/renderers/common/BlendMode.js +143 -0
  331. package/src/renderers/common/Buffer.js +40 -0
  332. package/src/renderers/common/BundleGroup.js +1 -1
  333. package/src/renderers/common/ChainMap.js +30 -6
  334. package/src/renderers/common/CubeRenderTarget.js +50 -6
  335. package/src/renderers/common/Geometries.js +29 -3
  336. package/src/renderers/common/Lighting.js +5 -21
  337. package/src/renderers/common/Pipelines.js +4 -4
  338. package/src/renderers/common/PostProcessing.js +8 -206
  339. package/src/renderers/common/RenderBundles.js +2 -1
  340. package/src/renderers/common/RenderContext.js +16 -0
  341. package/src/renderers/common/RenderContexts.js +33 -49
  342. package/src/renderers/common/RenderLists.js +2 -1
  343. package/src/renderers/common/RenderObject.js +15 -3
  344. package/src/renderers/common/RenderObjectPipeline.js +40 -0
  345. package/src/renderers/common/RenderObjects.js +18 -2
  346. package/src/renderers/common/RenderPipeline.js +203 -17
  347. package/src/renderers/common/Renderer.js +257 -72
  348. package/src/renderers/common/Sampler.js +4 -4
  349. package/src/renderers/common/StorageBuffer.js +13 -1
  350. package/src/renderers/common/Textures.js +17 -1
  351. package/src/renderers/common/TimestampQueryPool.js +5 -3
  352. package/src/renderers/common/Uniform.js +8 -0
  353. package/src/renderers/common/UniformsGroup.js +61 -0
  354. package/src/renderers/common/XRManager.js +3 -2
  355. package/src/renderers/common/extras/PMREMGenerator.js +2 -8
  356. package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
  357. package/src/renderers/common/nodes/{Nodes.js → NodeManager.js} +18 -6
  358. package/src/renderers/common/nodes/NodeStorageBuffer.js +13 -2
  359. package/src/renderers/common/nodes/NodeUniformBuffer.js +52 -0
  360. package/src/renderers/shaders/DFGLUTData.js +19 -34
  361. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +2 -2
  362. package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +1 -5
  363. package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +1 -5
  364. package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -5
  365. package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +8 -10
  366. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +7 -11
  367. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
  368. package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
  369. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
  370. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
  371. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +112 -51
  372. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
  373. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +225 -186
  374. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
  375. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  376. package/src/renderers/shaders/ShaderChunk.js +3 -3
  377. package/src/renderers/shaders/ShaderLib/depth.glsl.js +3 -0
  378. package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
  379. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -1
  380. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
  381. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -1
  382. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
  383. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
  384. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
  385. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
  386. package/src/renderers/shaders/ShaderLib.js +7 -5
  387. package/src/renderers/shaders/UniformsLib.js +0 -3
  388. package/src/renderers/webgl/WebGLBackground.js +2 -2
  389. package/src/renderers/webgl/WebGLBindingStates.js +99 -27
  390. package/src/renderers/webgl/WebGLCapabilities.js +3 -4
  391. package/src/renderers/webgl/WebGLEnvironments.js +228 -0
  392. package/src/renderers/webgl/WebGLGeometries.js +10 -7
  393. package/src/renderers/webgl/WebGLLights.js +18 -1
  394. package/src/renderers/webgl/WebGLMaterials.js +12 -0
  395. package/src/renderers/webgl/WebGLObjects.js +3 -1
  396. package/src/renderers/webgl/WebGLOutput.js +267 -0
  397. package/src/renderers/webgl/WebGLProgram.js +45 -109
  398. package/src/renderers/webgl/WebGLPrograms.js +45 -49
  399. package/src/renderers/webgl/WebGLRenderLists.js +15 -0
  400. package/src/renderers/webgl/WebGLShadowMap.js +188 -24
  401. package/src/renderers/webgl/WebGLState.js +32 -37
  402. package/src/renderers/webgl/WebGLTextures.js +89 -28
  403. package/src/renderers/webgl/WebGLUniforms.js +40 -3
  404. package/src/renderers/webgl/WebGLUtils.js +6 -2
  405. package/src/renderers/webgl-fallback/WebGLBackend.js +148 -18
  406. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +156 -35
  407. package/src/renderers/webgl-fallback/utils/WebGLState.js +181 -5
  408. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +5 -3
  409. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -9
  410. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +6 -2
  411. package/src/renderers/webgpu/WebGPUBackend.js +119 -13
  412. package/src/renderers/webgpu/WebGPURenderer.js +2 -1
  413. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +322 -68
  414. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -17
  415. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +357 -200
  416. package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -0
  417. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +61 -23
  418. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +152 -200
  419. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +65 -42
  420. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +7 -7
  421. package/src/renderers/webgpu/utils/WebGPUUtils.js +17 -11
  422. package/src/renderers/webxr/WebXRManager.js +2 -2
  423. package/src/textures/CubeDepthTexture.js +76 -0
  424. package/src/textures/Source.js +1 -1
  425. package/src/textures/Texture.js +3 -3
  426. package/src/utils.js +258 -3
  427. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -434
  428. package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -167
  429. package/examples/jsm/shaders/GodRaysShader.js +0 -333
  430. package/src/nodes/accessors/SceneNode.js +0 -145
  431. package/src/nodes/code/ScriptableNode.js +0 -726
  432. package/src/nodes/code/ScriptableValueNode.js +0 -253
  433. package/src/nodes/display/PosterizeNode.js +0 -65
  434. package/src/nodes/functions/BSDF/DFGApprox.js +0 -71
  435. package/src/nodes/utils/SpriteSheetUVNode.js +0 -90
  436. package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
  437. package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -134
@@ -0,0 +1,2950 @@
1
+ import {
2
+ AmbientLight,
3
+ AnimationClip,
4
+ Bone,
5
+ BufferGeometry,
6
+ ClampToEdgeWrapping,
7
+ Color,
8
+ ColorManagement,
9
+ DirectionalLight,
10
+ DoubleSide,
11
+ Float32BufferAttribute,
12
+ FrontSide,
13
+ Group,
14
+ InterpolateBezier,
15
+ InterpolateDiscrete,
16
+ Line,
17
+ LineBasicMaterial,
18
+ LineSegments,
19
+ Loader,
20
+ MathUtils,
21
+ Matrix4,
22
+ Mesh,
23
+ MeshBasicMaterial,
24
+ MeshLambertMaterial,
25
+ MeshPhongMaterial,
26
+ OrthographicCamera,
27
+ PerspectiveCamera,
28
+ PointLight,
29
+ Quaternion,
30
+ QuaternionKeyframeTrack,
31
+ RepeatWrapping,
32
+ Skeleton,
33
+ SkinnedMesh,
34
+ SpotLight,
35
+ Vector2,
36
+ Vector3,
37
+ VectorKeyframeTrack,
38
+ SRGBColorSpace
39
+ } from 'three';
40
+
41
+ import { getElementsByTagName, parseFloats } from './ColladaParser.js';
42
+
43
+ /**
44
+ * ColladaComposer converts parsed library data into Three.js objects.
45
+ */
46
+ class ColladaComposer {
47
+
48
+ constructor( library, collada, textureLoader, tgaLoader ) {
49
+
50
+ this.library = library;
51
+ this.collada = collada;
52
+ this.textureLoader = textureLoader;
53
+ this.tgaLoader = tgaLoader;
54
+
55
+ this.tempColor = new Color();
56
+ this.animations = [];
57
+ this.kinematics = {};
58
+
59
+ // Reusable objects for animation
60
+ this.position = new Vector3();
61
+ this.scale = new Vector3();
62
+ this.quaternion = new Quaternion();
63
+ this.matrix = new Matrix4();
64
+
65
+ // Storage for deferred pivot animation data
66
+ // Nodes with pivot transforms need all their animation channels collected
67
+ // before building tracks, as channels may be split across animation elements
68
+ this.deferredPivotAnimations = {};
69
+
70
+ // Storage for transform node hierarchy
71
+ // Maps nodeId -> transformSid -> Object3D for animation targeting
72
+ this.transformNodes = {};
73
+
74
+ }
75
+
76
+ compose() {
77
+
78
+ const library = this.library;
79
+
80
+ this.buildLibrary( library.animations, this.buildAnimation.bind( this ) );
81
+ this.buildLibrary( library.clips, this.buildAnimationClip.bind( this ) );
82
+ this.buildLibrary( library.controllers, this.buildController.bind( this ) );
83
+ this.buildLibrary( library.images, this.buildImage.bind( this ) );
84
+ this.buildLibrary( library.effects, this.buildEffect.bind( this ) );
85
+ this.buildLibrary( library.materials, this.buildMaterial.bind( this ) );
86
+ this.buildLibrary( library.cameras, this.buildCamera.bind( this ) );
87
+ this.buildLibrary( library.lights, this.buildLight.bind( this ) );
88
+ this.buildLibrary( library.geometries, this.buildGeometry.bind( this ) );
89
+ this.buildLibrary( library.visualScenes, this.buildVisualScene.bind( this ) );
90
+
91
+ this.setupAnimations();
92
+ this.setupKinematics();
93
+
94
+ const scene = this.parseScene( getElementsByTagName( this.collada, 'scene' )[ 0 ] );
95
+ scene.animations = this.animations;
96
+
97
+ return {
98
+ scene: scene,
99
+ animations: this.animations,
100
+ kinematics: this.kinematics
101
+ };
102
+
103
+ }
104
+
105
+ buildLibrary( data, builder ) {
106
+
107
+ for ( const name in data ) {
108
+
109
+ const object = data[ name ];
110
+ object.build = builder( data[ name ] );
111
+
112
+ }
113
+
114
+ }
115
+
116
+ getBuild( data, builder ) {
117
+
118
+ if ( data.build !== undefined ) return data.build;
119
+
120
+ data.build = builder( data );
121
+
122
+ return data.build;
123
+
124
+ }
125
+
126
+ isEmpty( object ) {
127
+
128
+ return Object.keys( object ).length === 0;
129
+
130
+ }
131
+
132
+ buildAnimation( data ) {
133
+
134
+ const tracks = [];
135
+
136
+ const channels = data.channels;
137
+ const samplers = data.samplers;
138
+ const sources = data.sources;
139
+
140
+ const aggregated = this.aggregateAnimationChannels( channels, samplers, sources );
141
+
142
+ for ( const nodeId in aggregated ) {
143
+
144
+ const nodeData = this.library.nodes[ nodeId ];
145
+ if ( ! nodeData ) continue;
146
+
147
+ const nodeChannels = aggregated[ nodeId ];
148
+
149
+ if ( this.hasPivotTransforms( nodeData ) ) {
150
+
151
+ // Defer - nodes haven't been built yet
152
+ this.collectDeferredPivotAnimation( nodeId, nodeChannels );
153
+
154
+ } else {
155
+
156
+ const object3D = this.getNode( nodeId );
157
+ let rotationTrackBuilt = false;
158
+
159
+ for ( const sid in nodeChannels ) {
160
+
161
+ const transformType = nodeData.transforms[ sid ];
162
+ const transformInfo = nodeData.transformData[ sid ];
163
+ const channelData = nodeChannels[ sid ];
164
+
165
+ switch ( transformType ) {
166
+
167
+ case 'matrix':
168
+ this.buildMatrixTracks( object3D, channelData, nodeData, tracks );
169
+ break;
170
+
171
+ case 'translate':
172
+ this.buildTranslateTrack( object3D, channelData, transformInfo, tracks );
173
+ break;
174
+
175
+ case 'rotate':
176
+ if ( ! rotationTrackBuilt ) {
177
+
178
+ this.buildRotateTrack( object3D, sid, channelData, transformInfo, nodeData, tracks );
179
+ rotationTrackBuilt = true;
180
+
181
+ }
182
+
183
+ break;
184
+
185
+ case 'scale':
186
+ this.buildScaleTrack( object3D, channelData, transformInfo, tracks );
187
+ break;
188
+
189
+ }
190
+
191
+ }
192
+
193
+ }
194
+
195
+ }
196
+
197
+ return tracks;
198
+
199
+ }
200
+
201
+ collectDeferredPivotAnimation( nodeId, nodeChannels ) {
202
+
203
+ if ( ! this.deferredPivotAnimations[ nodeId ] ) {
204
+
205
+ this.deferredPivotAnimations[ nodeId ] = {};
206
+
207
+ }
208
+
209
+ const deferred = this.deferredPivotAnimations[ nodeId ];
210
+
211
+ for ( const sid in nodeChannels ) {
212
+
213
+ if ( ! deferred[ sid ] ) {
214
+
215
+ deferred[ sid ] = {};
216
+
217
+ }
218
+
219
+ for ( const member in nodeChannels[ sid ] ) {
220
+
221
+ deferred[ sid ][ member ] = nodeChannels[ sid ][ member ];
222
+
223
+ }
224
+
225
+ }
226
+
227
+ }
228
+
229
+ hasPivotTransforms( nodeData ) {
230
+
231
+ const pivotSids = [
232
+ 'rotatePivot', 'rotatePivotInverse', 'rotatePivotTranslation',
233
+ 'scalePivot', 'scalePivotInverse', 'scalePivotTranslation'
234
+ ];
235
+
236
+ for ( const sid of pivotSids ) {
237
+
238
+ if ( nodeData.transforms[ sid ] !== undefined ) {
239
+
240
+ return true;
241
+
242
+ }
243
+
244
+ }
245
+
246
+ return false;
247
+
248
+ }
249
+
250
+ getAnimation( id ) {
251
+
252
+ return this.getBuild( this.library.animations[ id ], this.buildAnimation.bind( this ) );
253
+
254
+ }
255
+
256
+ aggregateAnimationChannels( channels, samplers, sources ) {
257
+
258
+ const aggregated = {};
259
+
260
+ for ( const target in channels ) {
261
+
262
+ if ( ! channels.hasOwnProperty( target ) ) continue;
263
+
264
+ const channel = channels[ target ];
265
+ const sampler = samplers[ channel.sampler ];
266
+
267
+ const inputId = sampler.inputs.INPUT;
268
+ const outputId = sampler.inputs.OUTPUT;
269
+
270
+ const inputSource = sources[ inputId ];
271
+ const outputSource = sources[ outputId ];
272
+
273
+ const interpolationId = sampler.inputs.INTERPOLATION;
274
+ const inTangentId = sampler.inputs.IN_TANGENT;
275
+ const outTangentId = sampler.inputs.OUT_TANGENT;
276
+
277
+ const interpolationSource = interpolationId ? sources[ interpolationId ] : null;
278
+ const inTangentSource = inTangentId ? sources[ inTangentId ] : null;
279
+ const outTangentSource = outTangentId ? sources[ outTangentId ] : null;
280
+
281
+ const nodeId = channel.id;
282
+ const sid = channel.sid;
283
+ const member = channel.member || 'default';
284
+
285
+ if ( ! aggregated[ nodeId ] ) aggregated[ nodeId ] = {};
286
+ if ( ! aggregated[ nodeId ][ sid ] ) aggregated[ nodeId ][ sid ] = {};
287
+
288
+ aggregated[ nodeId ][ sid ][ member ] = {
289
+ times: inputSource.array,
290
+ values: outputSource.array,
291
+ stride: outputSource.stride,
292
+ arraySyntax: channel.arraySyntax,
293
+ indices: channel.indices,
294
+ interpolation: interpolationSource ? interpolationSource.array : null,
295
+ inTangent: inTangentSource ? inTangentSource.array : null,
296
+ outTangent: outTangentSource ? outTangentSource.array : null,
297
+ inTangentStride: inTangentSource ? inTangentSource.stride : 0,
298
+ outTangentStride: outTangentSource ? outTangentSource.stride : 0
299
+ };
300
+
301
+ }
302
+
303
+ return aggregated;
304
+
305
+ }
306
+
307
+ buildMatrixTracks( object3D, channelData, nodeData, tracks ) {
308
+
309
+ const defaultMatrix = nodeData.matrix.clone().transpose();
310
+ const data = {};
311
+
312
+ for ( const member in channelData ) {
313
+
314
+ const component = channelData[ member ];
315
+ const times = component.times;
316
+ const values = component.values;
317
+ const stride = component.stride;
318
+
319
+ for ( let i = 0, il = times.length; i < il; i ++ ) {
320
+
321
+ const time = times[ i ];
322
+ const valueOffset = i * stride;
323
+
324
+ if ( data[ time ] === undefined ) data[ time ] = {};
325
+
326
+ if ( component.arraySyntax === true ) {
327
+
328
+ const value = values[ valueOffset ];
329
+ const index = component.indices[ 0 ] + 4 * component.indices[ 1 ];
330
+ data[ time ][ index ] = value;
331
+
332
+ } else {
333
+
334
+ for ( let j = 0; j < stride; j ++ ) {
335
+
336
+ data[ time ][ j ] = values[ valueOffset + j ];
337
+
338
+ }
339
+
340
+ }
341
+
342
+ }
343
+
344
+ }
345
+
346
+ const keyframes = this.prepareAnimationData( data, defaultMatrix );
347
+ const animation = { name: object3D.uuid, keyframes: keyframes };
348
+ this.createKeyframeTracks( animation, tracks );
349
+
350
+ }
351
+
352
+ buildTranslateTrack( object3D, channelData, transformInfo, tracks ) {
353
+
354
+ if ( channelData.default && channelData.default.stride === 3 ) {
355
+
356
+ const data = channelData.default;
357
+ const times = Array.from( data.times );
358
+ const values = Array.from( data.values );
359
+
360
+ const track = new VectorKeyframeTrack(
361
+ object3D.uuid + '.position',
362
+ times,
363
+ values
364
+ );
365
+
366
+ const interpolationInfo = this.getInterpolationInfo( channelData );
367
+ this.applyInterpolation( track, interpolationInfo, channelData );
368
+ tracks.push( track );
369
+ return;
370
+
371
+ }
372
+
373
+ const times = this.getTimesForAllAxes( channelData );
374
+ if ( times.length === 0 ) return;
375
+
376
+ const values = [];
377
+ const interpolationInfo = this.getInterpolationInfo( channelData );
378
+
379
+ for ( let i = 0; i < times.length; i ++ ) {
380
+
381
+ const time = times[ i ];
382
+
383
+ const x = this.getValueAtTime( channelData.X, time, transformInfo.x );
384
+ const y = this.getValueAtTime( channelData.Y, time, transformInfo.y );
385
+ const z = this.getValueAtTime( channelData.Z, time, transformInfo.z );
386
+
387
+ values.push( x, y, z );
388
+
389
+ }
390
+
391
+ const track = new VectorKeyframeTrack(
392
+ object3D.uuid + '.position',
393
+ times,
394
+ values
395
+ );
396
+
397
+ this.applyInterpolation( track, interpolationInfo );
398
+ tracks.push( track );
399
+
400
+ }
401
+
402
+ buildRotateTrack( object3D, sid, channelData, transformInfo, nodeData, tracks ) {
403
+
404
+ const angleData = channelData.ANGLE || channelData.default;
405
+ if ( ! angleData ) return;
406
+
407
+ const times = Array.from( angleData.times );
408
+ if ( times.length === 0 ) return;
409
+
410
+ // Collect all rotations to compose them in order
411
+ const rotations = [];
412
+
413
+ for ( const transformSid of nodeData.transformOrder ) {
414
+
415
+ const transformType = nodeData.transforms[ transformSid ];
416
+
417
+ if ( transformType === 'rotate' ) {
418
+
419
+ const info = nodeData.transformData[ transformSid ];
420
+ rotations.push( {
421
+ sid: transformSid,
422
+ axis: new Vector3( info.axis[ 0 ], info.axis[ 1 ], info.axis[ 2 ] ),
423
+ defaultAngle: info.angle
424
+ } );
425
+
426
+ }
427
+
428
+ }
429
+
430
+ const quaternion = new Quaternion();
431
+ const prevQuaternion = new Quaternion();
432
+ const tempQuat = new Quaternion();
433
+ const values = [];
434
+ const interpolationInfo = this.getInterpolationInfo( channelData );
435
+
436
+ for ( let i = 0; i < times.length; i ++ ) {
437
+
438
+ const time = times[ i ];
439
+ quaternion.identity();
440
+
441
+ for ( const rotation of rotations ) {
442
+
443
+ let angleDegrees;
444
+
445
+ if ( rotation.sid === sid ) {
446
+
447
+ angleDegrees = this.getValueAtTime( angleData, time, rotation.defaultAngle );
448
+
449
+ } else {
450
+
451
+ angleDegrees = rotation.defaultAngle;
452
+
453
+ }
454
+
455
+ const angleRadians = MathUtils.degToRad( angleDegrees );
456
+ tempQuat.setFromAxisAngle( rotation.axis, angleRadians );
457
+ quaternion.multiply( tempQuat );
458
+
459
+ }
460
+
461
+ // Ensure quaternion continuity
462
+ if ( i > 0 && prevQuaternion.dot( quaternion ) < 0 ) {
463
+
464
+ quaternion.x = - quaternion.x;
465
+ quaternion.y = - quaternion.y;
466
+ quaternion.z = - quaternion.z;
467
+ quaternion.w = - quaternion.w;
468
+
469
+ }
470
+
471
+ prevQuaternion.copy( quaternion );
472
+
473
+ values.push( quaternion.x, quaternion.y, quaternion.z, quaternion.w );
474
+
475
+ }
476
+
477
+ const track = new QuaternionKeyframeTrack(
478
+ object3D.uuid + '.quaternion',
479
+ times,
480
+ values
481
+ );
482
+
483
+ this.applyInterpolation( track, interpolationInfo );
484
+ tracks.push( track );
485
+
486
+ }
487
+
488
+ buildScaleTrack( object3D, channelData, transformInfo, tracks ) {
489
+
490
+ if ( channelData.default && channelData.default.stride === 3 ) {
491
+
492
+ const data = channelData.default;
493
+ const times = Array.from( data.times );
494
+ const values = Array.from( data.values );
495
+
496
+ const track = new VectorKeyframeTrack(
497
+ object3D.uuid + '.scale',
498
+ times,
499
+ values
500
+ );
501
+
502
+ const interpolationInfo = this.getInterpolationInfo( channelData );
503
+ this.applyInterpolation( track, interpolationInfo, channelData );
504
+ tracks.push( track );
505
+ return;
506
+
507
+ }
508
+
509
+ const times = this.getTimesForAllAxes( channelData );
510
+ if ( times.length === 0 ) return;
511
+
512
+ const values = [];
513
+ const interpolationInfo = this.getInterpolationInfo( channelData );
514
+
515
+ for ( let i = 0; i < times.length; i ++ ) {
516
+
517
+ const time = times[ i ];
518
+
519
+ const x = this.getValueAtTime( channelData.X, time, transformInfo.x );
520
+ const y = this.getValueAtTime( channelData.Y, time, transformInfo.y );
521
+ const z = this.getValueAtTime( channelData.Z, time, transformInfo.z );
522
+
523
+ values.push( x, y, z );
524
+
525
+ }
526
+
527
+ const track = new VectorKeyframeTrack(
528
+ object3D.uuid + '.scale',
529
+ times,
530
+ values
531
+ );
532
+
533
+ this.applyInterpolation( track, interpolationInfo );
534
+ tracks.push( track );
535
+
536
+ }
537
+
538
+ getTimesForAllAxes( channelData ) {
539
+
540
+ let times = [];
541
+
542
+ if ( channelData.X ) times = times.concat( Array.from( channelData.X.times ) );
543
+ if ( channelData.Y ) times = times.concat( Array.from( channelData.Y.times ) );
544
+ if ( channelData.Z ) times = times.concat( Array.from( channelData.Z.times ) );
545
+ if ( channelData.ANGLE ) times = times.concat( Array.from( channelData.ANGLE.times ) );
546
+ if ( channelData.default ) times = times.concat( Array.from( channelData.default.times ) );
547
+
548
+ times = [ ...new Set( times ) ].sort( ( a, b ) => a - b );
549
+
550
+ return times;
551
+
552
+ }
553
+
554
+ getValueAtTime( componentData, time, defaultValue ) {
555
+
556
+ if ( ! componentData ) return defaultValue;
557
+
558
+ const times = componentData.times;
559
+ const values = componentData.values;
560
+ const interpolation = componentData.interpolation;
561
+
562
+ for ( let i = 0; i < times.length; i ++ ) {
563
+
564
+ if ( times[ i ] === time ) {
565
+
566
+ return values[ i ];
567
+
568
+ }
569
+
570
+ if ( times[ i ] > time ) {
571
+
572
+ if ( i === 0 ) {
573
+
574
+ return values[ 0 ];
575
+
576
+ }
577
+
578
+ const i0 = i - 1;
579
+ const i1 = i;
580
+ const t0 = times[ i0 ];
581
+ const t1 = times[ i1 ];
582
+ const v0 = values[ i0 ];
583
+ const v1 = values[ i1 ];
584
+
585
+ const interp = interpolation ? interpolation[ i0 ] : 'LINEAR';
586
+
587
+ if ( interp === 'STEP' ) {
588
+
589
+ return v0;
590
+
591
+ } else if ( interp === 'BEZIER' && componentData.inTangent && componentData.outTangent ) {
592
+
593
+ return this.evaluateBezierComponent( componentData, i0, i1, t0, t1, time );
594
+
595
+ } else {
596
+
597
+ const t = ( time - t0 ) / ( t1 - t0 );
598
+ return v0 + t * ( v1 - v0 );
599
+
600
+ }
601
+
602
+ }
603
+
604
+ }
605
+
606
+ return values[ values.length - 1 ];
607
+
608
+ }
609
+
610
+ evaluateBezierComponent( componentData, i0, i1, t0, t1, time ) {
611
+
612
+ const values = componentData.values;
613
+ const inTangent = componentData.inTangent;
614
+ const outTangent = componentData.outTangent;
615
+ const tangentStride = componentData.inTangentStride || 1;
616
+
617
+ const v0 = values[ i0 ];
618
+ const v1 = values[ i1 ];
619
+
620
+ let c0x, c0y, c1x, c1y;
621
+
622
+ if ( tangentStride === 2 ) {
623
+
624
+ c0x = outTangent[ i0 * 2 ];
625
+ c0y = outTangent[ i0 * 2 + 1 ];
626
+ c1x = inTangent[ i1 * 2 ];
627
+ c1y = inTangent[ i1 * 2 + 1 ];
628
+
629
+ } else {
630
+
631
+ c0x = t0 + ( t1 - t0 ) / 3;
632
+ c0y = outTangent[ i0 ];
633
+ c1x = t1 - ( t1 - t0 ) / 3;
634
+ c1y = inTangent[ i1 ];
635
+
636
+ }
637
+
638
+ // Newton-Raphson to solve Bx(s) = time
639
+ let s = ( time - t0 ) / ( t1 - t0 );
640
+
641
+ for ( let iter = 0; iter < 8; iter ++ ) {
642
+
643
+ const s2 = s * s;
644
+ const s3 = s2 * s;
645
+ const oneMinusS = 1 - s;
646
+ const oneMinusS2 = oneMinusS * oneMinusS;
647
+ const oneMinusS3 = oneMinusS2 * oneMinusS;
648
+
649
+ const bx = oneMinusS3 * t0 + 3 * oneMinusS2 * s * c0x + 3 * oneMinusS * s2 * c1x + s3 * t1;
650
+ const dbx = 3 * oneMinusS2 * ( c0x - t0 ) + 6 * oneMinusS * s * ( c1x - c0x ) + 3 * s2 * ( t1 - c1x );
651
+
652
+ if ( Math.abs( dbx ) < 1e-10 ) break;
653
+
654
+ const error = bx - time;
655
+ if ( Math.abs( error ) < 1e-10 ) break;
656
+
657
+ s = s - error / dbx;
658
+ s = Math.max( 0, Math.min( 1, s ) );
659
+
660
+ }
661
+
662
+ const s2 = s * s;
663
+ const s3 = s2 * s;
664
+ const oneMinusS = 1 - s;
665
+ const oneMinusS2 = oneMinusS * oneMinusS;
666
+ const oneMinusS3 = oneMinusS2 * oneMinusS;
667
+
668
+ return oneMinusS3 * v0 + 3 * oneMinusS2 * s * c0y + 3 * oneMinusS * s2 * c1y + s3 * v1;
669
+
670
+ }
671
+
672
+ getInterpolationInfo( channelData ) {
673
+
674
+ const components = [ 'X', 'Y', 'Z', 'ANGLE', 'default' ];
675
+ let interpolationType = null;
676
+ let isUniform = true;
677
+
678
+ for ( const comp of components ) {
679
+
680
+ const data = channelData[ comp ];
681
+ if ( ! data || ! data.interpolation ) continue;
682
+
683
+ const interpArray = data.interpolation;
684
+
685
+ for ( let i = 0; i < interpArray.length; i ++ ) {
686
+
687
+ const interp = interpArray[ i ];
688
+
689
+ if ( interpolationType === null ) {
690
+
691
+ interpolationType = interp;
692
+
693
+ } else if ( interp !== interpolationType ) {
694
+
695
+ isUniform = false;
696
+
697
+ }
698
+
699
+ }
700
+
701
+ }
702
+
703
+ return {
704
+ type: interpolationType || 'LINEAR',
705
+ uniform: isUniform
706
+ };
707
+
708
+ }
709
+
710
+ applyInterpolation( track, interpolationInfo, channelData = null ) {
711
+
712
+ if ( interpolationInfo.type === 'STEP' && interpolationInfo.uniform ) {
713
+
714
+ track.setInterpolation( InterpolateDiscrete );
715
+
716
+ } else if ( interpolationInfo.type === 'BEZIER' && interpolationInfo.uniform && channelData ) {
717
+
718
+ const data = channelData.default;
719
+
720
+ if ( data && data.inTangent && data.outTangent ) {
721
+
722
+ track.setInterpolation( InterpolateBezier );
723
+ track.settings = {
724
+ inTangents: new Float32Array( data.inTangent ),
725
+ outTangents: new Float32Array( data.outTangent )
726
+ };
727
+
728
+ }
729
+
730
+ }
731
+
732
+ }
733
+
734
+ prepareAnimationData( data, defaultMatrix ) {
735
+
736
+ const keyframes = [];
737
+
738
+ for ( const time in data ) {
739
+
740
+ keyframes.push( { time: parseFloat( time ), value: data[ time ] } );
741
+
742
+ }
743
+
744
+ keyframes.sort( ( a, b ) => a.time - b.time );
745
+
746
+ for ( let i = 0; i < 16; i ++ ) {
747
+
748
+ this.transformAnimationData( keyframes, i, defaultMatrix.elements[ i ] );
749
+
750
+ }
751
+
752
+ return keyframes;
753
+
754
+ }
755
+
756
+ createKeyframeTracks( animation, tracks ) {
757
+
758
+ const keyframes = animation.keyframes;
759
+ const name = animation.name;
760
+
761
+ const times = [];
762
+ const positionData = [];
763
+ const quaternionData = [];
764
+ const scaleData = [];
765
+
766
+ const position = this.position;
767
+ const quaternion = this.quaternion;
768
+ const scale = this.scale;
769
+ const matrix = this.matrix;
770
+
771
+ for ( let i = 0, l = keyframes.length; i < l; i ++ ) {
772
+
773
+ const keyframe = keyframes[ i ];
774
+
775
+ const time = keyframe.time;
776
+ const value = keyframe.value;
777
+
778
+ matrix.fromArray( value ).transpose();
779
+ matrix.decompose( position, quaternion, scale );
780
+
781
+ times.push( time );
782
+ positionData.push( position.x, position.y, position.z );
783
+ quaternionData.push( quaternion.x, quaternion.y, quaternion.z, quaternion.w );
784
+ scaleData.push( scale.x, scale.y, scale.z );
785
+
786
+ }
787
+
788
+ if ( positionData.length > 0 ) tracks.push( new VectorKeyframeTrack( name + '.position', times, positionData ) );
789
+ if ( quaternionData.length > 0 ) tracks.push( new QuaternionKeyframeTrack( name + '.quaternion', times, quaternionData ) );
790
+ if ( scaleData.length > 0 ) tracks.push( new VectorKeyframeTrack( name + '.scale', times, scaleData ) );
791
+
792
+ return tracks;
793
+
794
+ }
795
+
796
+ transformAnimationData( keyframes, property, defaultValue ) {
797
+
798
+ let keyframe;
799
+
800
+ let empty = true;
801
+ let i, l;
802
+
803
+ // check, if values of a property are missing in our keyframes
804
+
805
+ for ( i = 0, l = keyframes.length; i < l; i ++ ) {
806
+
807
+ keyframe = keyframes[ i ];
808
+
809
+ if ( keyframe.value[ property ] === undefined ) {
810
+
811
+ keyframe.value[ property ] = null; // mark as missing
812
+
813
+ } else {
814
+
815
+ empty = false;
816
+
817
+ }
818
+
819
+ }
820
+
821
+ if ( empty === true ) {
822
+
823
+ // no values at all, so we set a default value
824
+
825
+ for ( i = 0, l = keyframes.length; i < l; i ++ ) {
826
+
827
+ keyframe = keyframes[ i ];
828
+
829
+ keyframe.value[ property ] = defaultValue;
830
+
831
+ }
832
+
833
+ } else {
834
+
835
+ // filling gaps
836
+
837
+ this.createMissingKeyframes( keyframes, property );
838
+
839
+ }
840
+
841
+ }
842
+
843
+ createMissingKeyframes( keyframes, property ) {
844
+
845
+ let prev, next;
846
+
847
+ for ( let i = 0, l = keyframes.length; i < l; i ++ ) {
848
+
849
+ const keyframe = keyframes[ i ];
850
+
851
+ if ( keyframe.value[ property ] === null ) {
852
+
853
+ prev = this.getPrev( keyframes, i, property );
854
+ next = this.getNext( keyframes, i, property );
855
+
856
+ if ( prev === null ) {
857
+
858
+ keyframe.value[ property ] = next.value[ property ];
859
+ continue;
860
+
861
+ }
862
+
863
+ if ( next === null ) {
864
+
865
+ keyframe.value[ property ] = prev.value[ property ];
866
+ continue;
867
+
868
+ }
869
+
870
+ this.interpolate( keyframe, prev, next, property );
871
+
872
+ }
873
+
874
+ }
875
+
876
+ }
877
+
878
+ getPrev( keyframes, i, property ) {
879
+
880
+ while ( i >= 0 ) {
881
+
882
+ const keyframe = keyframes[ i ];
883
+
884
+ if ( keyframe.value[ property ] !== null ) return keyframe;
885
+
886
+ i --;
887
+
888
+ }
889
+
890
+ return null;
891
+
892
+ }
893
+
894
+ getNext( keyframes, i, property ) {
895
+
896
+ while ( i < keyframes.length ) {
897
+
898
+ const keyframe = keyframes[ i ];
899
+
900
+ if ( keyframe.value[ property ] !== null ) return keyframe;
901
+
902
+ i ++;
903
+
904
+ }
905
+
906
+ return null;
907
+
908
+ }
909
+
910
+ interpolate( key, prev, next, property ) {
911
+
912
+ if ( ( next.time - prev.time ) === 0 ) {
913
+
914
+ key.value[ property ] = prev.value[ property ];
915
+ return;
916
+
917
+ }
918
+
919
+ key.value[ property ] = ( ( key.time - prev.time ) * ( next.value[ property ] - prev.value[ property ] ) / ( next.time - prev.time ) ) + prev.value[ property ];
920
+
921
+ }
922
+
923
+
924
+ buildAnimationClip( data ) {
925
+
926
+ const tracks = [];
927
+
928
+ const name = data.name;
929
+ const duration = ( data.end - data.start ) || - 1;
930
+ const animations = data.animations;
931
+
932
+ for ( let i = 0, il = animations.length; i < il; i ++ ) {
933
+
934
+ const animationTracks = this.getAnimation( animations[ i ] );
935
+
936
+ for ( let j = 0, jl = animationTracks.length; j < jl; j ++ ) {
937
+
938
+ tracks.push( animationTracks[ j ] );
939
+
940
+ }
941
+
942
+ }
943
+
944
+ return new AnimationClip( name, duration, tracks );
945
+
946
+ }
947
+
948
+ getAnimationClip( id ) {
949
+
950
+ return this.getBuild( this.library.clips[ id ], this.buildAnimationClip.bind( this ) );
951
+
952
+ }
953
+
954
+
955
+ buildController( data ) {
956
+
957
+ const build = {
958
+ id: data.id
959
+ };
960
+
961
+ const geometry = this.library.geometries[ build.id ];
962
+
963
+ if ( data.skin !== undefined ) {
964
+
965
+ build.skin = this.buildSkin( data.skin );
966
+
967
+ // we enhance the 'sources' property of the corresponding geometry with our skin data
968
+
969
+ geometry.sources.skinIndices = build.skin.indices;
970
+ geometry.sources.skinWeights = build.skin.weights;
971
+
972
+ }
973
+
974
+ return build;
975
+
976
+ }
977
+
978
+ buildSkin( data ) {
979
+
980
+ const BONE_LIMIT = 4;
981
+
982
+ const build = {
983
+ joints: [], // this must be an array to preserve the joint order
984
+ indices: {
985
+ array: [],
986
+ stride: BONE_LIMIT
987
+ },
988
+ weights: {
989
+ array: [],
990
+ stride: BONE_LIMIT
991
+ }
992
+ };
993
+
994
+ const sources = data.sources;
995
+ const vertexWeights = data.vertexWeights;
996
+
997
+ const vcount = vertexWeights.vcount;
998
+ const v = vertexWeights.v;
999
+ const jointOffset = vertexWeights.inputs.JOINT.offset;
1000
+ const weightOffset = vertexWeights.inputs.WEIGHT.offset;
1001
+
1002
+ const jointSource = data.sources[ data.joints.inputs.JOINT ];
1003
+ const inverseSource = data.sources[ data.joints.inputs.INV_BIND_MATRIX ];
1004
+
1005
+ const weights = sources[ vertexWeights.inputs.WEIGHT.id ].array;
1006
+ let stride = 0;
1007
+
1008
+ let i, j, l;
1009
+
1010
+ // process skin data for each vertex
1011
+
1012
+ for ( i = 0, l = vcount.length; i < l; i ++ ) {
1013
+
1014
+ const jointCount = vcount[ i ]; // this is the amount of joints that affect a single vertex
1015
+ const vertexSkinData = [];
1016
+
1017
+ for ( j = 0; j < jointCount; j ++ ) {
1018
+
1019
+ const skinIndex = v[ stride + jointOffset ];
1020
+ const weightId = v[ stride + weightOffset ];
1021
+ const skinWeight = weights[ weightId ];
1022
+
1023
+ vertexSkinData.push( { index: skinIndex, weight: skinWeight } );
1024
+
1025
+ stride += 2;
1026
+
1027
+ }
1028
+
1029
+ // we sort the joints in descending order based on the weights.
1030
+ // this ensures, we only proceed the most important joints of the vertex
1031
+
1032
+ vertexSkinData.sort( descending );
1033
+
1034
+ // now we provide for each vertex a set of four index and weight values.
1035
+ // the order of the skin data matches the order of vertices
1036
+
1037
+ for ( j = 0; j < BONE_LIMIT; j ++ ) {
1038
+
1039
+ const d = vertexSkinData[ j ];
1040
+
1041
+ if ( d !== undefined ) {
1042
+
1043
+ build.indices.array.push( d.index );
1044
+ build.weights.array.push( d.weight );
1045
+
1046
+ } else {
1047
+
1048
+ build.indices.array.push( 0 );
1049
+ build.weights.array.push( 0 );
1050
+
1051
+ }
1052
+
1053
+ }
1054
+
1055
+ }
1056
+
1057
+ // setup bind matrix
1058
+
1059
+ if ( data.bindShapeMatrix ) {
1060
+
1061
+ build.bindMatrix = new Matrix4().fromArray( data.bindShapeMatrix ).transpose();
1062
+
1063
+ } else {
1064
+
1065
+ build.bindMatrix = new Matrix4().identity();
1066
+
1067
+ }
1068
+
1069
+ // process bones and inverse bind matrix data
1070
+
1071
+ for ( i = 0, l = jointSource.array.length; i < l; i ++ ) {
1072
+
1073
+ const name = jointSource.array[ i ];
1074
+ const boneInverse = new Matrix4().fromArray( inverseSource.array, i * inverseSource.stride ).transpose();
1075
+
1076
+ build.joints.push( { name: name, boneInverse: boneInverse } );
1077
+
1078
+ }
1079
+
1080
+ return build;
1081
+
1082
+ // array sort function
1083
+
1084
+ function descending( a, b ) {
1085
+
1086
+ return b.weight - a.weight;
1087
+
1088
+ }
1089
+
1090
+ }
1091
+
1092
+ getController( id ) {
1093
+
1094
+ return this.getBuild( this.library.controllers[ id ], this.buildController.bind( this ) );
1095
+
1096
+ }
1097
+
1098
+
1099
+ buildImage( data ) {
1100
+
1101
+ if ( data.build !== undefined ) return data.build;
1102
+
1103
+ return data.init_from;
1104
+
1105
+ }
1106
+
1107
+ getImage( id ) {
1108
+
1109
+ const data = this.library.images[ id ];
1110
+
1111
+ if ( data !== undefined ) {
1112
+
1113
+ return this.getBuild( data, this.buildImage.bind( this ) );
1114
+
1115
+ }
1116
+
1117
+ console.warn( 'THREE.ColladaLoader: Couldn\'t find image with ID:', id );
1118
+
1119
+ return null;
1120
+
1121
+ }
1122
+
1123
+
1124
+ buildEffect( data ) {
1125
+
1126
+ return data;
1127
+
1128
+ }
1129
+
1130
+ getEffect( id ) {
1131
+
1132
+ return this.getBuild( this.library.effects[ id ], this.buildEffect.bind( this ) );
1133
+
1134
+ }
1135
+
1136
+
1137
+ getTextureLoader( image ) {
1138
+
1139
+ let loader;
1140
+
1141
+ let extension = image.slice( ( image.lastIndexOf( '.' ) - 1 >>> 0 ) + 2 ); // http://www.jstips.co/en/javascript/get-file-extension/
1142
+ extension = extension.toLowerCase();
1143
+
1144
+ switch ( extension ) {
1145
+
1146
+ case 'tga':
1147
+ loader = this.tgaLoader;
1148
+ break;
1149
+
1150
+ default:
1151
+ loader = this.textureLoader;
1152
+
1153
+ }
1154
+
1155
+ return loader;
1156
+
1157
+ }
1158
+
1159
+ buildMaterial( data ) {
1160
+
1161
+ const effect = this.getEffect( data.url );
1162
+ const technique = effect.profile.technique;
1163
+
1164
+ let material;
1165
+
1166
+ switch ( technique.type ) {
1167
+
1168
+ case 'phong':
1169
+ case 'blinn':
1170
+ material = new MeshPhongMaterial();
1171
+ break;
1172
+
1173
+ case 'lambert':
1174
+ material = new MeshLambertMaterial();
1175
+ break;
1176
+
1177
+ default:
1178
+ material = new MeshBasicMaterial();
1179
+ break;
1180
+
1181
+ }
1182
+
1183
+ material.name = data.name || '';
1184
+
1185
+ const self = this;
1186
+
1187
+ function getTexture( textureObject, colorSpace = null ) {
1188
+
1189
+ const sampler = effect.profile.samplers[ textureObject.id ];
1190
+ let image = null;
1191
+
1192
+ // get image
1193
+
1194
+ if ( sampler !== undefined ) {
1195
+
1196
+ const surface = effect.profile.surfaces[ sampler.source ];
1197
+ image = self.getImage( surface.init_from );
1198
+
1199
+ } else {
1200
+
1201
+ console.warn( 'THREE.ColladaLoader: Undefined sampler. Access image directly (see #12530).' );
1202
+ image = self.getImage( textureObject.id );
1203
+
1204
+ }
1205
+
1206
+ // create texture if image is available
1207
+
1208
+ if ( image !== null ) {
1209
+
1210
+ const loader = self.getTextureLoader( image );
1211
+
1212
+ if ( loader !== undefined ) {
1213
+
1214
+ const texture = loader.load( image );
1215
+
1216
+ const extra = textureObject.extra;
1217
+
1218
+ if ( extra !== undefined && extra.technique !== undefined && self.isEmpty( extra.technique ) === false ) {
1219
+
1220
+ const technique = extra.technique;
1221
+
1222
+ texture.wrapS = technique.wrapU ? RepeatWrapping : ClampToEdgeWrapping;
1223
+ texture.wrapT = technique.wrapV ? RepeatWrapping : ClampToEdgeWrapping;
1224
+
1225
+ texture.offset.set( technique.offsetU || 0, technique.offsetV || 0 );
1226
+ texture.repeat.set( technique.repeatU || 1, technique.repeatV || 1 );
1227
+
1228
+ } else {
1229
+
1230
+ texture.wrapS = RepeatWrapping;
1231
+ texture.wrapT = RepeatWrapping;
1232
+
1233
+ }
1234
+
1235
+ if ( colorSpace !== null ) {
1236
+
1237
+ texture.colorSpace = colorSpace;
1238
+
1239
+ }
1240
+
1241
+ return texture;
1242
+
1243
+ } else {
1244
+
1245
+ console.warn( 'THREE.ColladaLoader: Loader for texture %s not found.', image );
1246
+
1247
+ return null;
1248
+
1249
+ }
1250
+
1251
+ } else {
1252
+
1253
+ console.warn( 'THREE.ColladaLoader: Couldn\'t create texture with ID:', textureObject.id );
1254
+
1255
+ return null;
1256
+
1257
+ }
1258
+
1259
+ }
1260
+
1261
+ const parameters = technique.parameters;
1262
+
1263
+ for ( const key in parameters ) {
1264
+
1265
+ const parameter = parameters[ key ];
1266
+
1267
+ switch ( key ) {
1268
+
1269
+ case 'diffuse':
1270
+ if ( parameter.color ) material.color.fromArray( parameter.color );
1271
+ if ( parameter.texture ) material.map = getTexture( parameter.texture, SRGBColorSpace );
1272
+ break;
1273
+ case 'specular':
1274
+ if ( parameter.color && material.specular ) material.specular.fromArray( parameter.color );
1275
+ if ( parameter.texture ) material.specularMap = getTexture( parameter.texture );
1276
+ break;
1277
+ case 'bump':
1278
+ if ( parameter.texture ) material.normalMap = getTexture( parameter.texture );
1279
+ break;
1280
+ case 'ambient':
1281
+ if ( parameter.texture ) material.lightMap = getTexture( parameter.texture, SRGBColorSpace );
1282
+ break;
1283
+ case 'shininess':
1284
+ if ( parameter.float && material.shininess ) material.shininess = parameter.float;
1285
+ break;
1286
+ case 'emission':
1287
+ if ( parameter.color && material.emissive ) material.emissive.fromArray( parameter.color );
1288
+ if ( parameter.texture ) material.emissiveMap = getTexture( parameter.texture, SRGBColorSpace );
1289
+ break;
1290
+
1291
+ }
1292
+
1293
+ }
1294
+
1295
+ ColorManagement.colorSpaceToWorking( material.color, SRGBColorSpace );
1296
+ if ( material.specular ) ColorManagement.colorSpaceToWorking( material.specular, SRGBColorSpace );
1297
+ if ( material.emissive ) ColorManagement.colorSpaceToWorking( material.emissive, SRGBColorSpace );
1298
+
1299
+ //
1300
+
1301
+ let transparent = parameters[ 'transparent' ];
1302
+ let transparency = parameters[ 'transparency' ];
1303
+
1304
+ // <transparency> does not exist but <transparent>
1305
+
1306
+ if ( transparency === undefined && transparent ) {
1307
+
1308
+ transparency = {
1309
+ float: 1
1310
+ };
1311
+
1312
+ }
1313
+
1314
+ // <transparent> does not exist but <transparency>
1315
+
1316
+ if ( transparent === undefined && transparency ) {
1317
+
1318
+ transparent = {
1319
+ opaque: 'A_ONE',
1320
+ data: {
1321
+ color: [ 1, 1, 1, 1 ]
1322
+ } };
1323
+
1324
+ }
1325
+
1326
+ if ( transparent && transparency ) {
1327
+
1328
+ // handle case if a texture exists but no color
1329
+
1330
+ if ( transparent.data.texture ) {
1331
+
1332
+ // we do not set an alpha map (see #13792)
1333
+
1334
+ material.transparent = true;
1335
+
1336
+ } else {
1337
+
1338
+ const color = transparent.data.color;
1339
+
1340
+ switch ( transparent.opaque ) {
1341
+
1342
+ case 'A_ONE':
1343
+ material.opacity = color[ 3 ] * transparency.float;
1344
+ break;
1345
+ case 'RGB_ZERO':
1346
+ material.opacity = 1 - ( color[ 0 ] * transparency.float );
1347
+ break;
1348
+ case 'A_ZERO':
1349
+ material.opacity = 1 - ( color[ 3 ] * transparency.float );
1350
+ break;
1351
+ case 'RGB_ONE':
1352
+ material.opacity = color[ 0 ] * transparency.float;
1353
+ break;
1354
+ default:
1355
+ console.warn( 'THREE.ColladaLoader: Invalid opaque type "%s" of transparent tag.', transparent.opaque );
1356
+
1357
+ }
1358
+
1359
+ if ( material.opacity < 1 ) material.transparent = true;
1360
+
1361
+ }
1362
+
1363
+ }
1364
+
1365
+ //
1366
+
1367
+
1368
+ if ( technique.extra !== undefined && technique.extra.technique !== undefined ) {
1369
+
1370
+ const techniques = technique.extra.technique;
1371
+
1372
+ for ( const k in techniques ) {
1373
+
1374
+ const v = techniques[ k ];
1375
+
1376
+ switch ( k ) {
1377
+
1378
+ case 'double_sided':
1379
+ material.side = ( v === 1 ? DoubleSide : FrontSide );
1380
+ break;
1381
+
1382
+ case 'bump':
1383
+ material.normalMap = getTexture( v.texture );
1384
+ material.normalScale = new Vector2( 1, 1 );
1385
+ break;
1386
+
1387
+ }
1388
+
1389
+ }
1390
+
1391
+ }
1392
+
1393
+ return material;
1394
+
1395
+ }
1396
+
1397
+ getMaterial( id ) {
1398
+
1399
+ return this.getBuild( this.library.materials[ id ], this.buildMaterial.bind( this ) );
1400
+
1401
+ }
1402
+
1403
+
1404
+ buildCamera( data ) {
1405
+
1406
+ let camera;
1407
+
1408
+ switch ( data.optics.technique ) {
1409
+
1410
+ case 'perspective':
1411
+ camera = new PerspectiveCamera(
1412
+ data.optics.parameters.yfov,
1413
+ data.optics.parameters.aspect_ratio,
1414
+ data.optics.parameters.znear,
1415
+ data.optics.parameters.zfar
1416
+ );
1417
+ break;
1418
+
1419
+ case 'orthographic':
1420
+ let ymag = data.optics.parameters.ymag;
1421
+ let xmag = data.optics.parameters.xmag;
1422
+ const aspectRatio = data.optics.parameters.aspect_ratio;
1423
+
1424
+ xmag = ( xmag === undefined ) ? ( ymag * aspectRatio ) : xmag;
1425
+ ymag = ( ymag === undefined ) ? ( xmag / aspectRatio ) : ymag;
1426
+
1427
+ xmag *= 0.5;
1428
+ ymag *= 0.5;
1429
+
1430
+ camera = new OrthographicCamera(
1431
+ - xmag, xmag, ymag, - ymag, // left, right, top, bottom
1432
+ data.optics.parameters.znear,
1433
+ data.optics.parameters.zfar
1434
+ );
1435
+ break;
1436
+
1437
+ default:
1438
+ camera = new PerspectiveCamera();
1439
+ break;
1440
+
1441
+ }
1442
+
1443
+ camera.name = data.name || '';
1444
+
1445
+ return camera;
1446
+
1447
+ }
1448
+
1449
+ getCamera( id ) {
1450
+
1451
+ const data = this.library.cameras[ id ];
1452
+
1453
+ if ( data !== undefined ) {
1454
+
1455
+ return this.getBuild( data, this.buildCamera.bind( this ) );
1456
+
1457
+ }
1458
+
1459
+ console.warn( 'THREE.ColladaLoader: Couldn\'t find camera with ID:', id );
1460
+
1461
+ return null;
1462
+
1463
+ }
1464
+
1465
+
1466
+ buildLight( data ) {
1467
+
1468
+ let light;
1469
+
1470
+ switch ( data.technique ) {
1471
+
1472
+ case 'directional':
1473
+ light = new DirectionalLight();
1474
+ break;
1475
+
1476
+ case 'point':
1477
+ light = new PointLight();
1478
+ break;
1479
+
1480
+ case 'spot':
1481
+ light = new SpotLight();
1482
+ break;
1483
+
1484
+ case 'ambient':
1485
+ light = new AmbientLight();
1486
+ break;
1487
+
1488
+ }
1489
+
1490
+ if ( data.parameters.color ) light.color.copy( data.parameters.color );
1491
+ if ( data.parameters.distance ) light.distance = data.parameters.distance;
1492
+ if ( data.parameters.falloffAngle ) light.angle = MathUtils.degToRad( data.parameters.falloffAngle );
1493
+
1494
+ return light;
1495
+
1496
+ }
1497
+
1498
+ getLight( id ) {
1499
+
1500
+ const data = this.library.lights[ id ];
1501
+
1502
+ if ( data !== undefined ) {
1503
+
1504
+ return this.getBuild( data, this.buildLight.bind( this ) );
1505
+
1506
+ }
1507
+
1508
+ console.warn( 'THREE.ColladaLoader: Couldn\'t find light with ID:', id );
1509
+
1510
+ return null;
1511
+
1512
+ }
1513
+
1514
+
1515
+ groupPrimitives( primitives ) {
1516
+
1517
+ const build = {};
1518
+
1519
+ for ( let i = 0; i < primitives.length; i ++ ) {
1520
+
1521
+ const primitive = primitives[ i ];
1522
+
1523
+ if ( build[ primitive.type ] === undefined ) build[ primitive.type ] = [];
1524
+
1525
+ build[ primitive.type ].push( primitive );
1526
+
1527
+ }
1528
+
1529
+ return build;
1530
+
1531
+ }
1532
+
1533
+ checkUVCoordinates( primitives ) {
1534
+
1535
+ let count = 0;
1536
+
1537
+ for ( let i = 0, l = primitives.length; i < l; i ++ ) {
1538
+
1539
+ const primitive = primitives[ i ];
1540
+
1541
+ if ( primitive.hasUV === true ) {
1542
+
1543
+ count ++;
1544
+
1545
+ }
1546
+
1547
+ }
1548
+
1549
+ if ( count > 0 && count < primitives.length ) {
1550
+
1551
+ primitives.uvsNeedsFix = true;
1552
+
1553
+ }
1554
+
1555
+ }
1556
+
1557
+ buildGeometry( data ) {
1558
+
1559
+ const build = {};
1560
+
1561
+ const sources = data.sources;
1562
+ const vertices = data.vertices;
1563
+ const primitives = data.primitives;
1564
+
1565
+ if ( primitives.length === 0 ) return {};
1566
+
1567
+ // our goal is to create one buffer geometry for a single type of primitives
1568
+ // first, we group all primitives by their type
1569
+
1570
+ const groupedPrimitives = this.groupPrimitives( primitives );
1571
+
1572
+ for ( const type in groupedPrimitives ) {
1573
+
1574
+ const primitiveType = groupedPrimitives[ type ];
1575
+
1576
+ // second, ensure consistent uv coordinates for each type of primitives (polylist,triangles or lines)
1577
+
1578
+ this.checkUVCoordinates( primitiveType );
1579
+
1580
+ // third, create a buffer geometry for each type of primitives
1581
+
1582
+ build[ type ] = this.buildGeometryType( primitiveType, sources, vertices );
1583
+
1584
+ }
1585
+
1586
+ return build;
1587
+
1588
+ }
1589
+
1590
+ buildGeometryType( primitives, sources, vertices ) {
1591
+
1592
+ const build = {};
1593
+
1594
+ const position = { array: [], stride: 0 };
1595
+ const normal = { array: [], stride: 0 };
1596
+ const uv = { array: [], stride: 0 };
1597
+ const uv1 = { array: [], stride: 0 };
1598
+ const color = { array: [], stride: 0 };
1599
+
1600
+ const skinIndex = { array: [], stride: 4 };
1601
+ const skinWeight = { array: [], stride: 4 };
1602
+
1603
+ const geometry = new BufferGeometry();
1604
+
1605
+ const materialKeys = [];
1606
+
1607
+ let start = 0;
1608
+
1609
+ for ( let p = 0; p < primitives.length; p ++ ) {
1610
+
1611
+ const primitive = primitives[ p ];
1612
+ const inputs = primitive.inputs;
1613
+
1614
+ // groups
1615
+
1616
+ let count = 0;
1617
+
1618
+ switch ( primitive.type ) {
1619
+
1620
+ case 'lines':
1621
+ case 'linestrips':
1622
+ count = primitive.count * 2;
1623
+ break;
1624
+
1625
+ case 'triangles':
1626
+ count = primitive.count * 3;
1627
+ break;
1628
+
1629
+ case 'polylist':
1630
+
1631
+ for ( let g = 0; g < primitive.count; g ++ ) {
1632
+
1633
+ const vc = primitive.vcount[ g ];
1634
+
1635
+ switch ( vc ) {
1636
+
1637
+ case 3:
1638
+ count += 3; // single triangle
1639
+ break;
1640
+
1641
+ case 4:
1642
+ count += 6; // quad, subdivided into two triangles
1643
+ break;
1644
+
1645
+ default:
1646
+ count += ( vc - 2 ) * 3; // polylist with more than four vertices
1647
+ break;
1648
+
1649
+ }
1650
+
1651
+ }
1652
+
1653
+ break;
1654
+
1655
+ default:
1656
+ console.warn( 'THREE.ColladaLoader: Unknown primitive type:', primitive.type );
1657
+
1658
+ }
1659
+
1660
+ geometry.addGroup( start, count, p );
1661
+ start += count;
1662
+
1663
+ // material
1664
+
1665
+ if ( primitive.material ) {
1666
+
1667
+ materialKeys.push( primitive.material );
1668
+
1669
+ }
1670
+
1671
+ // geometry data
1672
+
1673
+ for ( const name in inputs ) {
1674
+
1675
+ const input = inputs[ name ];
1676
+
1677
+ switch ( name ) {
1678
+
1679
+ case 'VERTEX':
1680
+ for ( const key in vertices ) {
1681
+
1682
+ const id = vertices[ key ];
1683
+
1684
+ switch ( key ) {
1685
+
1686
+ case 'POSITION':
1687
+ const prevLength = position.array.length;
1688
+ this.buildGeometryData( primitive, sources[ id ], input.offset, position.array );
1689
+ position.stride = sources[ id ].stride;
1690
+
1691
+ if ( sources.skinWeights && sources.skinIndices ) {
1692
+
1693
+ this.buildGeometryData( primitive, sources.skinIndices, input.offset, skinIndex.array );
1694
+ this.buildGeometryData( primitive, sources.skinWeights, input.offset, skinWeight.array );
1695
+
1696
+ }
1697
+
1698
+ // see #3803
1699
+
1700
+ if ( primitive.hasUV === false && primitives.uvsNeedsFix === true ) {
1701
+
1702
+ const count = ( position.array.length - prevLength ) / position.stride;
1703
+
1704
+ for ( let i = 0; i < count; i ++ ) {
1705
+
1706
+ // fill missing uv coordinates
1707
+
1708
+ uv.array.push( 0, 0 );
1709
+
1710
+ }
1711
+
1712
+ }
1713
+
1714
+ break;
1715
+
1716
+ case 'NORMAL':
1717
+ this.buildGeometryData( primitive, sources[ id ], input.offset, normal.array );
1718
+ normal.stride = sources[ id ].stride;
1719
+ break;
1720
+
1721
+ case 'COLOR':
1722
+ this.buildGeometryData( primitive, sources[ id ], input.offset, color.array );
1723
+ color.stride = sources[ id ].stride;
1724
+ break;
1725
+
1726
+ case 'TEXCOORD':
1727
+ this.buildGeometryData( primitive, sources[ id ], input.offset, uv.array );
1728
+ uv.stride = sources[ id ].stride;
1729
+ break;
1730
+
1731
+ case 'TEXCOORD1':
1732
+ this.buildGeometryData( primitive, sources[ id ], input.offset, uv1.array );
1733
+ uv.stride = sources[ id ].stride;
1734
+ break;
1735
+
1736
+ default:
1737
+ console.warn( 'THREE.ColladaLoader: Semantic "%s" not handled in geometry build process.', key );
1738
+
1739
+ }
1740
+
1741
+ }
1742
+
1743
+ break;
1744
+
1745
+ case 'NORMAL':
1746
+ this.buildGeometryData( primitive, sources[ input.id ], input.offset, normal.array );
1747
+ normal.stride = sources[ input.id ].stride;
1748
+ break;
1749
+
1750
+ case 'COLOR':
1751
+ this.buildGeometryData( primitive, sources[ input.id ], input.offset, color.array, true );
1752
+ color.stride = sources[ input.id ].stride;
1753
+ break;
1754
+
1755
+ case 'TEXCOORD':
1756
+ this.buildGeometryData( primitive, sources[ input.id ], input.offset, uv.array );
1757
+ uv.stride = sources[ input.id ].stride;
1758
+ break;
1759
+
1760
+ case 'TEXCOORD1':
1761
+ this.buildGeometryData( primitive, sources[ input.id ], input.offset, uv1.array );
1762
+ uv1.stride = sources[ input.id ].stride;
1763
+ break;
1764
+
1765
+ }
1766
+
1767
+ }
1768
+
1769
+ }
1770
+
1771
+ // build geometry
1772
+
1773
+ if ( position.array.length > 0 ) geometry.setAttribute( 'position', new Float32BufferAttribute( position.array, position.stride ) );
1774
+ if ( normal.array.length > 0 ) geometry.setAttribute( 'normal', new Float32BufferAttribute( normal.array, normal.stride ) );
1775
+ if ( color.array.length > 0 ) geometry.setAttribute( 'color', new Float32BufferAttribute( color.array, color.stride ) );
1776
+ if ( uv.array.length > 0 ) geometry.setAttribute( 'uv', new Float32BufferAttribute( uv.array, uv.stride ) );
1777
+ if ( uv1.array.length > 0 ) geometry.setAttribute( 'uv1', new Float32BufferAttribute( uv1.array, uv1.stride ) );
1778
+
1779
+ if ( skinIndex.array.length > 0 ) geometry.setAttribute( 'skinIndex', new Float32BufferAttribute( skinIndex.array, skinIndex.stride ) );
1780
+ if ( skinWeight.array.length > 0 ) geometry.setAttribute( 'skinWeight', new Float32BufferAttribute( skinWeight.array, skinWeight.stride ) );
1781
+
1782
+ build.data = geometry;
1783
+ build.type = primitives[ 0 ].type;
1784
+ build.materialKeys = materialKeys;
1785
+
1786
+ return build;
1787
+
1788
+ }
1789
+
1790
+ buildGeometryData( primitive, source, offset, array, isColor = false ) {
1791
+
1792
+ const indices = primitive.p;
1793
+ const stride = primitive.stride;
1794
+ const vcount = primitive.vcount;
1795
+
1796
+ const tempColor = this.tempColor;
1797
+
1798
+ function pushVector( i ) {
1799
+
1800
+ let index = indices[ i + offset ] * sourceStride;
1801
+ const length = index + sourceStride;
1802
+
1803
+ for ( ; index < length; index ++ ) {
1804
+
1805
+ array.push( sourceArray[ index ] );
1806
+
1807
+ }
1808
+
1809
+ if ( isColor ) {
1810
+
1811
+ // convert the vertex colors from srgb to linear if present
1812
+ const startIndex = array.length - sourceStride - 1;
1813
+ tempColor.setRGB(
1814
+ array[ startIndex + 0 ],
1815
+ array[ startIndex + 1 ],
1816
+ array[ startIndex + 2 ],
1817
+ SRGBColorSpace
1818
+ );
1819
+
1820
+ array[ startIndex + 0 ] = tempColor.r;
1821
+ array[ startIndex + 1 ] = tempColor.g;
1822
+ array[ startIndex + 2 ] = tempColor.b;
1823
+
1824
+ }
1825
+
1826
+ }
1827
+
1828
+ const sourceArray = source.array;
1829
+ const sourceStride = source.stride;
1830
+
1831
+ if ( primitive.vcount !== undefined ) {
1832
+
1833
+ let index = 0;
1834
+
1835
+ for ( let i = 0, l = vcount.length; i < l; i ++ ) {
1836
+
1837
+ const count = vcount[ i ];
1838
+
1839
+ if ( count === 4 ) {
1840
+
1841
+ const a = index + stride * 0;
1842
+ const b = index + stride * 1;
1843
+ const c = index + stride * 2;
1844
+ const d = index + stride * 3;
1845
+
1846
+ pushVector( a ); pushVector( b ); pushVector( d );
1847
+ pushVector( b ); pushVector( c ); pushVector( d );
1848
+
1849
+ } else if ( count === 3 ) {
1850
+
1851
+ const a = index + stride * 0;
1852
+ const b = index + stride * 1;
1853
+ const c = index + stride * 2;
1854
+
1855
+ pushVector( a ); pushVector( b ); pushVector( c );
1856
+
1857
+ } else if ( count > 4 ) {
1858
+
1859
+ for ( let k = 1, kl = ( count - 2 ); k <= kl; k ++ ) {
1860
+
1861
+ const a = index + stride * 0;
1862
+ const b = index + stride * k;
1863
+ const c = index + stride * ( k + 1 );
1864
+
1865
+ pushVector( a ); pushVector( b ); pushVector( c );
1866
+
1867
+ }
1868
+
1869
+ }
1870
+
1871
+ index += stride * count;
1872
+
1873
+ }
1874
+
1875
+ } else {
1876
+
1877
+ for ( let i = 0, l = indices.length; i < l; i += stride ) {
1878
+
1879
+ pushVector( i );
1880
+
1881
+ }
1882
+
1883
+ }
1884
+
1885
+ }
1886
+
1887
+ getGeometry( id ) {
1888
+
1889
+ return this.getBuild( this.library.geometries[ id ], this.buildGeometry.bind( this ) );
1890
+
1891
+ }
1892
+
1893
+
1894
+ buildKinematicsModel( data ) {
1895
+
1896
+ if ( data.build !== undefined ) return data.build;
1897
+
1898
+ return data;
1899
+
1900
+ }
1901
+
1902
+ getKinematicsModel( id ) {
1903
+
1904
+ return this.getBuild( this.library.kinematicsModels[ id ], this.buildKinematicsModel.bind( this ) );
1905
+
1906
+ }
1907
+
1908
+ buildKinematicsScene( data ) {
1909
+
1910
+ if ( data.build !== undefined ) return data.build;
1911
+
1912
+ return data;
1913
+
1914
+ }
1915
+
1916
+ getKinematicsScene( id ) {
1917
+
1918
+ return this.getBuild( this.library.kinematicsScenes[ id ], this.buildKinematicsScene.bind( this ) );
1919
+
1920
+ }
1921
+
1922
+ setupKinematics() {
1923
+
1924
+ const kinematicsModelId = Object.keys( this.library.kinematicsModels )[ 0 ];
1925
+ const kinematicsSceneId = Object.keys( this.library.kinematicsScenes )[ 0 ];
1926
+ const visualSceneId = Object.keys( this.library.visualScenes )[ 0 ];
1927
+
1928
+ if ( kinematicsModelId === undefined || kinematicsSceneId === undefined ) return;
1929
+
1930
+ const kinematicsModel = this.getKinematicsModel( kinematicsModelId );
1931
+ const kinematicsScene = this.getKinematicsScene( kinematicsSceneId );
1932
+ const visualScene = this.getVisualScene( visualSceneId );
1933
+
1934
+ const bindJointAxis = kinematicsScene.bindJointAxis;
1935
+ const jointMap = {};
1936
+
1937
+ const collada = this.collada;
1938
+ const self = this;
1939
+
1940
+ for ( let i = 0, l = bindJointAxis.length; i < l; i ++ ) {
1941
+
1942
+ const axis = bindJointAxis[ i ];
1943
+
1944
+ // the result of the following query is an element of type 'translate', 'rotate','scale' or 'matrix'
1945
+
1946
+ const targetElement = collada.querySelector( '[sid="' + axis.target + '"]' );
1947
+
1948
+ if ( targetElement ) {
1949
+
1950
+ // get the parent of the transform element
1951
+
1952
+ const parentVisualElement = targetElement.parentElement;
1953
+
1954
+ // connect the joint of the kinematics model with the element in the visual scene
1955
+
1956
+ connect( axis.jointIndex, parentVisualElement );
1957
+
1958
+ }
1959
+
1960
+ }
1961
+
1962
+ function connect( jointIndex, visualElement ) {
1963
+
1964
+ const visualElementName = visualElement.getAttribute( 'name' );
1965
+ const joint = kinematicsModel.joints[ jointIndex ];
1966
+ const transforms = self.buildTransformList( visualElement );
1967
+
1968
+ visualScene.traverse( function ( object ) {
1969
+
1970
+ if ( object.name === visualElementName ) {
1971
+
1972
+ jointMap[ jointIndex ] = {
1973
+ object: object,
1974
+ transforms: transforms,
1975
+ joint: joint,
1976
+ position: joint.zeroPosition
1977
+ };
1978
+
1979
+ }
1980
+
1981
+ } );
1982
+
1983
+ }
1984
+
1985
+ const m0 = new Matrix4();
1986
+ const matrix = this.matrix;
1987
+
1988
+ this.kinematics = {
1989
+
1990
+ joints: kinematicsModel && kinematicsModel.joints,
1991
+
1992
+ getJointValue: function ( jointIndex ) {
1993
+
1994
+ const jointData = jointMap[ jointIndex ];
1995
+
1996
+ if ( jointData ) {
1997
+
1998
+ return jointData.position;
1999
+
2000
+ } else {
2001
+
2002
+ console.warn( 'THREE.ColladaLoader: Joint ' + jointIndex + ' doesn\'t exist.' );
2003
+
2004
+ }
2005
+
2006
+ },
2007
+
2008
+ setJointValue: function ( jointIndex, value ) {
2009
+
2010
+ const jointData = jointMap[ jointIndex ];
2011
+
2012
+ if ( jointData ) {
2013
+
2014
+ const joint = jointData.joint;
2015
+
2016
+ if ( value > joint.limits.max || value < joint.limits.min ) {
2017
+
2018
+ console.warn( 'THREE.ColladaLoader: Joint ' + jointIndex + ' value ' + value + ' outside of limits (min: ' + joint.limits.min + ', max: ' + joint.limits.max + ').' );
2019
+
2020
+ } else if ( joint.static ) {
2021
+
2022
+ console.warn( 'THREE.ColladaLoader: Joint ' + jointIndex + ' is static.' );
2023
+
2024
+ } else {
2025
+
2026
+ const object = jointData.object;
2027
+ const axis = joint.axis;
2028
+ const transforms = jointData.transforms;
2029
+
2030
+ matrix.identity();
2031
+
2032
+ // each update, we have to apply all transforms in the correct order
2033
+
2034
+ for ( let i = 0; i < transforms.length; i ++ ) {
2035
+
2036
+ const transform = transforms[ i ];
2037
+
2038
+ // if there is a connection of the transform node with a joint, apply the joint value
2039
+
2040
+ if ( transform.sid && transform.sid.indexOf( jointIndex ) !== - 1 ) {
2041
+
2042
+ switch ( joint.type ) {
2043
+
2044
+ case 'revolute':
2045
+ matrix.multiply( m0.makeRotationAxis( axis, MathUtils.degToRad( value ) ) );
2046
+ break;
2047
+
2048
+ case 'prismatic':
2049
+ matrix.multiply( m0.makeTranslation( axis.x * value, axis.y * value, axis.z * value ) );
2050
+ break;
2051
+
2052
+ default:
2053
+ console.warn( 'THREE.ColladaLoader: Unknown joint type: ' + joint.type );
2054
+ break;
2055
+
2056
+ }
2057
+
2058
+ } else {
2059
+
2060
+ switch ( transform.type ) {
2061
+
2062
+ case 'matrix':
2063
+ matrix.multiply( transform.obj );
2064
+ break;
2065
+
2066
+ case 'translate':
2067
+ matrix.multiply( m0.makeTranslation( transform.obj.x, transform.obj.y, transform.obj.z ) );
2068
+ break;
2069
+
2070
+ case 'scale':
2071
+ matrix.scale( transform.obj );
2072
+ break;
2073
+
2074
+ case 'rotate':
2075
+ matrix.multiply( m0.makeRotationAxis( transform.obj, transform.angle ) );
2076
+ break;
2077
+
2078
+ }
2079
+
2080
+ }
2081
+
2082
+ }
2083
+
2084
+ object.matrix.copy( matrix );
2085
+ object.matrix.decompose( object.position, object.quaternion, object.scale );
2086
+
2087
+ jointMap[ jointIndex ].position = value;
2088
+
2089
+ }
2090
+
2091
+ } else {
2092
+
2093
+ console.warn( 'THREE.ColladaLoader: Joint ' + jointIndex + ' does not exist.' );
2094
+
2095
+ }
2096
+
2097
+ }
2098
+
2099
+ };
2100
+
2101
+ }
2102
+
2103
+ buildTransformList( node ) {
2104
+
2105
+ const transforms = [];
2106
+
2107
+ const xml = this.collada.querySelector( '[id="' + node.id + '"]' );
2108
+
2109
+ for ( let i = 0; i < xml.childNodes.length; i ++ ) {
2110
+
2111
+ const child = xml.childNodes[ i ];
2112
+
2113
+ if ( child.nodeType !== 1 ) continue;
2114
+
2115
+ let array, vector;
2116
+
2117
+ switch ( child.nodeName ) {
2118
+
2119
+ case 'matrix':
2120
+ array = parseFloats( child.textContent );
2121
+ const matrix = new Matrix4().fromArray( array ).transpose();
2122
+ transforms.push( {
2123
+ sid: child.getAttribute( 'sid' ),
2124
+ type: child.nodeName,
2125
+ obj: matrix
2126
+ } );
2127
+ break;
2128
+
2129
+ case 'translate':
2130
+ case 'scale':
2131
+ array = parseFloats( child.textContent );
2132
+ vector = new Vector3().fromArray( array );
2133
+ transforms.push( {
2134
+ sid: child.getAttribute( 'sid' ),
2135
+ type: child.nodeName,
2136
+ obj: vector
2137
+ } );
2138
+ break;
2139
+
2140
+ case 'rotate':
2141
+ array = parseFloats( child.textContent );
2142
+ vector = new Vector3().fromArray( array );
2143
+ const angle = MathUtils.degToRad( array[ 3 ] );
2144
+ transforms.push( {
2145
+ sid: child.getAttribute( 'sid' ),
2146
+ type: child.nodeName,
2147
+ obj: vector,
2148
+ angle: angle
2149
+ } );
2150
+ break;
2151
+
2152
+ }
2153
+
2154
+ }
2155
+
2156
+ return transforms;
2157
+
2158
+ }
2159
+
2160
+
2161
+ buildSkeleton( skeletons, joints ) {
2162
+
2163
+ const boneData = [];
2164
+ const sortedBoneData = [];
2165
+
2166
+ let i, j, data;
2167
+
2168
+ // a skeleton can have multiple root bones. collada expresses this
2169
+ // situation with multiple "skeleton" tags per controller instance
2170
+
2171
+ for ( i = 0; i < skeletons.length; i ++ ) {
2172
+
2173
+ const skeleton = skeletons[ i ];
2174
+
2175
+ let root;
2176
+
2177
+ if ( this.hasNode( skeleton ) ) {
2178
+
2179
+ root = this.getNode( skeleton );
2180
+ this.buildBoneHierarchy( root, joints, boneData );
2181
+
2182
+ } else if ( this.hasVisualScene( skeleton ) ) {
2183
+
2184
+ // handle case where the skeleton refers to the visual scene (#13335)
2185
+
2186
+ const visualScene = this.library.visualScenes[ skeleton ];
2187
+ const children = visualScene.children;
2188
+
2189
+ for ( let j = 0; j < children.length; j ++ ) {
2190
+
2191
+ const child = children[ j ];
2192
+
2193
+ if ( child.type === 'JOINT' ) {
2194
+
2195
+ const root = this.getNode( child.id );
2196
+ this.buildBoneHierarchy( root, joints, boneData );
2197
+
2198
+ }
2199
+
2200
+ }
2201
+
2202
+ } else {
2203
+
2204
+ console.error( 'THREE.ColladaLoader: Unable to find root bone of skeleton with ID:', skeleton );
2205
+
2206
+ }
2207
+
2208
+ }
2209
+
2210
+ // sort bone data (the order is defined in the corresponding controller)
2211
+
2212
+ for ( i = 0; i < joints.length; i ++ ) {
2213
+
2214
+ for ( j = 0; j < boneData.length; j ++ ) {
2215
+
2216
+ data = boneData[ j ];
2217
+
2218
+ if ( data.bone.name === joints[ i ].name ) {
2219
+
2220
+ sortedBoneData[ i ] = data;
2221
+ data.processed = true;
2222
+ break;
2223
+
2224
+ }
2225
+
2226
+ }
2227
+
2228
+ }
2229
+
2230
+ // add unprocessed bone data at the end of the list
2231
+
2232
+ for ( i = 0; i < boneData.length; i ++ ) {
2233
+
2234
+ data = boneData[ i ];
2235
+
2236
+ if ( data.processed === false ) {
2237
+
2238
+ sortedBoneData.push( data );
2239
+ data.processed = true;
2240
+
2241
+ }
2242
+
2243
+ }
2244
+
2245
+ // setup arrays for skeleton creation
2246
+
2247
+ const bones = [];
2248
+ const boneInverses = [];
2249
+
2250
+ for ( i = 0; i < sortedBoneData.length; i ++ ) {
2251
+
2252
+ data = sortedBoneData[ i ];
2253
+
2254
+ bones.push( data.bone );
2255
+ boneInverses.push( data.boneInverse );
2256
+
2257
+ }
2258
+
2259
+ return new Skeleton( bones, boneInverses );
2260
+
2261
+ }
2262
+
2263
+ buildBoneHierarchy( root, joints, boneData ) {
2264
+
2265
+ // setup bone data from visual scene
2266
+
2267
+ root.traverse( function ( object ) {
2268
+
2269
+ if ( object.isBone === true ) {
2270
+
2271
+ let boneInverse;
2272
+
2273
+ // retrieve the boneInverse from the controller data
2274
+
2275
+ for ( let i = 0; i < joints.length; i ++ ) {
2276
+
2277
+ const joint = joints[ i ];
2278
+
2279
+ if ( joint.name === object.name ) {
2280
+
2281
+ boneInverse = joint.boneInverse;
2282
+ break;
2283
+
2284
+ }
2285
+
2286
+ }
2287
+
2288
+ if ( boneInverse === undefined ) {
2289
+
2290
+ // Unfortunately, there can be joints in the visual scene that are not part of the
2291
+ // corresponding controller. In this case, we have to create a dummy boneInverse matrix
2292
+ // for the respective bone. This bone won't affect any vertices, because there are no skin indices
2293
+ // and weights defined for it. But we still have to add the bone to the sorted bone list in order to
2294
+ // ensure a correct animation of the model.
2295
+
2296
+ boneInverse = new Matrix4();
2297
+
2298
+ }
2299
+
2300
+ boneData.push( { bone: object, boneInverse: boneInverse, processed: false } );
2301
+
2302
+ }
2303
+
2304
+ } );
2305
+
2306
+ }
2307
+
2308
+ buildNode( data ) {
2309
+
2310
+ const objects = [];
2311
+
2312
+ const matrix = data.matrix;
2313
+ const nodes = data.nodes;
2314
+ const type = data.type;
2315
+ const instanceCameras = data.instanceCameras;
2316
+ const instanceControllers = data.instanceControllers;
2317
+ const instanceLights = data.instanceLights;
2318
+ const instanceGeometries = data.instanceGeometries;
2319
+ const instanceNodes = data.instanceNodes;
2320
+
2321
+ // nodes
2322
+
2323
+ for ( let i = 0, l = nodes.length; i < l; i ++ ) {
2324
+
2325
+ objects.push( this.getNode( nodes[ i ] ) );
2326
+
2327
+ }
2328
+
2329
+ // instance cameras
2330
+
2331
+ for ( let i = 0, l = instanceCameras.length; i < l; i ++ ) {
2332
+
2333
+ const instanceCamera = this.getCamera( instanceCameras[ i ] );
2334
+
2335
+ if ( instanceCamera !== null ) {
2336
+
2337
+ objects.push( instanceCamera.clone() );
2338
+
2339
+ }
2340
+
2341
+ }
2342
+
2343
+ // instance controllers
2344
+
2345
+ for ( let i = 0, l = instanceControllers.length; i < l; i ++ ) {
2346
+
2347
+ const instance = instanceControllers[ i ];
2348
+ const controller = this.getController( instance.id );
2349
+ const geometries = this.getGeometry( controller.id );
2350
+ const newObjects = this.buildObjects( geometries, instance.materials );
2351
+
2352
+ const skeletons = instance.skeletons;
2353
+ const joints = controller.skin.joints;
2354
+
2355
+ const skeleton = this.buildSkeleton( skeletons, joints );
2356
+
2357
+ for ( let j = 0, jl = newObjects.length; j < jl; j ++ ) {
2358
+
2359
+ const object = newObjects[ j ];
2360
+
2361
+ if ( object.isSkinnedMesh ) {
2362
+
2363
+ object.bind( skeleton, controller.skin.bindMatrix );
2364
+ object.normalizeSkinWeights();
2365
+
2366
+ }
2367
+
2368
+ objects.push( object );
2369
+
2370
+ }
2371
+
2372
+ }
2373
+
2374
+ // instance lights
2375
+
2376
+ for ( let i = 0, l = instanceLights.length; i < l; i ++ ) {
2377
+
2378
+ const instanceLight = this.getLight( instanceLights[ i ] );
2379
+
2380
+ if ( instanceLight !== null ) {
2381
+
2382
+ objects.push( instanceLight.clone() );
2383
+
2384
+ }
2385
+
2386
+ }
2387
+
2388
+ // instance geometries
2389
+
2390
+ for ( let i = 0, l = instanceGeometries.length; i < l; i ++ ) {
2391
+
2392
+ const instance = instanceGeometries[ i ];
2393
+
2394
+ // a single geometry instance in collada can lead to multiple object3Ds.
2395
+ // this is the case when primitives are combined like triangles and lines
2396
+
2397
+ const geometries = this.getGeometry( instance.id );
2398
+ const newObjects = this.buildObjects( geometries, instance.materials );
2399
+
2400
+ for ( let j = 0, jl = newObjects.length; j < jl; j ++ ) {
2401
+
2402
+ objects.push( newObjects[ j ] );
2403
+
2404
+ }
2405
+
2406
+ }
2407
+
2408
+ // instance nodes
2409
+
2410
+ for ( let i = 0, l = instanceNodes.length; i < l; i ++ ) {
2411
+
2412
+ objects.push( this.getNode( instanceNodes[ i ] ).clone() );
2413
+
2414
+ }
2415
+
2416
+ let object;
2417
+
2418
+ if ( nodes.length === 0 && objects.length === 1 ) {
2419
+
2420
+ object = objects[ 0 ];
2421
+
2422
+ } else {
2423
+
2424
+ object = ( type === 'JOINT' ) ? new Bone() : new Group();
2425
+
2426
+ for ( let i = 0; i < objects.length; i ++ ) {
2427
+
2428
+ object.add( objects[ i ] );
2429
+
2430
+ }
2431
+
2432
+ }
2433
+
2434
+ object.name = ( type === 'JOINT' ) ? data.sid : data.name;
2435
+
2436
+ if ( type !== 'JOINT' && this.hasPivotTransforms( data ) ) {
2437
+
2438
+ return this.wrapWithTransformHierarchy( object, data );
2439
+
2440
+ }
2441
+
2442
+ object.matrix.copy( matrix );
2443
+ object.matrix.decompose( object.position, object.quaternion, object.scale );
2444
+
2445
+ return object;
2446
+
2447
+ }
2448
+
2449
+ wrapWithTransformHierarchy( contentObject, nodeData ) {
2450
+
2451
+ const nodeId = nodeData.id;
2452
+ this.transformNodes[ nodeId ] = {};
2453
+
2454
+ const transformOrder = nodeData.transformOrder;
2455
+ const transformData = nodeData.transformData;
2456
+
2457
+ const rootNode = new Group();
2458
+ rootNode.name = nodeData.name;
2459
+
2460
+ let currentParent = rootNode;
2461
+
2462
+ for ( let i = 0; i < transformOrder.length; i ++ ) {
2463
+
2464
+ const sid = transformOrder[ i ];
2465
+ const info = transformData[ sid ];
2466
+
2467
+ const transformNode = new Group();
2468
+ transformNode.name = nodeData.name + '_' + sid;
2469
+
2470
+ switch ( info.type ) {
2471
+
2472
+ case 'translate':
2473
+ transformNode.position.set( info.x, info.y, info.z );
2474
+ break;
2475
+
2476
+ case 'rotate': {
2477
+
2478
+ const axis = new Vector3( info.axis[ 0 ], info.axis[ 1 ], info.axis[ 2 ] );
2479
+ const angle = MathUtils.degToRad( info.angle );
2480
+ transformNode.quaternion.setFromAxisAngle( axis, angle );
2481
+ transformNode.userData.rotationAxis = axis;
2482
+ break;
2483
+
2484
+ }
2485
+
2486
+ case 'scale':
2487
+ transformNode.scale.set( info.x, info.y, info.z );
2488
+ break;
2489
+
2490
+ case 'matrix': {
2491
+
2492
+ const matrix = new Matrix4().fromArray( info.array ).transpose();
2493
+ matrix.decompose( transformNode.position, transformNode.quaternion, transformNode.scale );
2494
+ break;
2495
+
2496
+ }
2497
+
2498
+ }
2499
+
2500
+ this.transformNodes[ nodeId ][ sid ] = transformNode;
2501
+
2502
+ currentParent.add( transformNode );
2503
+ currentParent = transformNode;
2504
+
2505
+ }
2506
+
2507
+ currentParent.add( contentObject );
2508
+
2509
+ return rootNode;
2510
+
2511
+ }
2512
+
2513
+ resolveMaterialBinding( keys, instanceMaterials ) {
2514
+
2515
+ const materials = [];
2516
+
2517
+ for ( let i = 0, l = keys.length; i < l; i ++ ) {
2518
+
2519
+ const id = instanceMaterials[ keys[ i ] ];
2520
+
2521
+ if ( id === undefined ) {
2522
+
2523
+ console.warn( 'THREE.ColladaLoader: Material with key %s not found. Apply fallback material.', keys[ i ] );
2524
+ materials.push( this.fallbackMaterial );
2525
+
2526
+ } else {
2527
+
2528
+ materials.push( this.getMaterial( id ) );
2529
+
2530
+ }
2531
+
2532
+ }
2533
+
2534
+ return materials;
2535
+
2536
+ }
2537
+
2538
+ get fallbackMaterial() {
2539
+
2540
+ if ( this._fallbackMaterial === undefined ) {
2541
+
2542
+ this._fallbackMaterial = new MeshBasicMaterial( {
2543
+ name: Loader.DEFAULT_MATERIAL_NAME,
2544
+ color: 0xff00ff
2545
+ } );
2546
+
2547
+ }
2548
+
2549
+ return this._fallbackMaterial;
2550
+
2551
+ }
2552
+
2553
+ buildObjects( geometries, instanceMaterials ) {
2554
+
2555
+ const objects = [];
2556
+
2557
+ for ( const type in geometries ) {
2558
+
2559
+ const geometry = geometries[ type ];
2560
+
2561
+ const materials = this.resolveMaterialBinding( geometry.materialKeys, instanceMaterials );
2562
+
2563
+ // handle case if no materials are defined
2564
+
2565
+ if ( materials.length === 0 ) {
2566
+
2567
+ if ( type === 'lines' || type === 'linestrips' ) {
2568
+
2569
+ materials.push( new LineBasicMaterial() );
2570
+
2571
+ } else {
2572
+
2573
+ materials.push( new MeshPhongMaterial() );
2574
+
2575
+ }
2576
+
2577
+ }
2578
+
2579
+ // Collada allows to use phong and lambert materials with lines. Replacing these cases with LineBasicMaterial.
2580
+
2581
+ if ( type === 'lines' || type === 'linestrips' ) {
2582
+
2583
+ for ( let i = 0, l = materials.length; i < l; i ++ ) {
2584
+
2585
+ const material = materials[ i ];
2586
+
2587
+ if ( material.isMeshPhongMaterial === true || material.isMeshLambertMaterial === true ) {
2588
+
2589
+ const lineMaterial = new LineBasicMaterial();
2590
+
2591
+ // copy compatible properties
2592
+
2593
+ lineMaterial.color.copy( material.color );
2594
+ lineMaterial.opacity = material.opacity;
2595
+ lineMaterial.transparent = material.transparent;
2596
+
2597
+ // replace material
2598
+
2599
+ materials[ i ] = lineMaterial;
2600
+
2601
+ }
2602
+
2603
+ }
2604
+
2605
+ }
2606
+
2607
+ // regard skinning
2608
+
2609
+ const skinning = ( geometry.data.attributes.skinIndex !== undefined );
2610
+
2611
+ // choose between a single or multi materials (material array)
2612
+
2613
+ const material = ( materials.length === 1 ) ? materials[ 0 ] : materials;
2614
+
2615
+ // now create a specific 3D object
2616
+
2617
+ let object;
2618
+
2619
+ switch ( type ) {
2620
+
2621
+ case 'lines':
2622
+ object = new LineSegments( geometry.data, material );
2623
+ break;
2624
+
2625
+ case 'linestrips':
2626
+ object = new Line( geometry.data, material );
2627
+ break;
2628
+
2629
+ case 'triangles':
2630
+ case 'polylist':
2631
+ if ( skinning ) {
2632
+
2633
+ object = new SkinnedMesh( geometry.data, material );
2634
+
2635
+ } else {
2636
+
2637
+ object = new Mesh( geometry.data, material );
2638
+
2639
+ }
2640
+
2641
+ break;
2642
+
2643
+ }
2644
+
2645
+ objects.push( object );
2646
+
2647
+ }
2648
+
2649
+ return objects;
2650
+
2651
+ }
2652
+
2653
+ hasNode( id ) {
2654
+
2655
+ return this.library.nodes[ id ] !== undefined;
2656
+
2657
+ }
2658
+
2659
+ getNode( id ) {
2660
+
2661
+ return this.getBuild( this.library.nodes[ id ], this.buildNode.bind( this ) );
2662
+
2663
+ }
2664
+
2665
+
2666
+ buildVisualScene( data ) {
2667
+
2668
+ const group = new Group();
2669
+ group.name = data.name;
2670
+
2671
+ const children = data.children;
2672
+
2673
+ for ( let i = 0; i < children.length; i ++ ) {
2674
+
2675
+ const child = children[ i ];
2676
+
2677
+ group.add( this.getNode( child.id ) );
2678
+
2679
+ }
2680
+
2681
+ return group;
2682
+
2683
+ }
2684
+
2685
+ hasVisualScene( id ) {
2686
+
2687
+ return this.library.visualScenes[ id ] !== undefined;
2688
+
2689
+ }
2690
+
2691
+ getVisualScene( id ) {
2692
+
2693
+ return this.getBuild( this.library.visualScenes[ id ], this.buildVisualScene.bind( this ) );
2694
+
2695
+ }
2696
+
2697
+
2698
+ parseScene( xml ) {
2699
+
2700
+ const instance = getElementsByTagName( xml, 'instance_visual_scene' )[ 0 ];
2701
+ return this.getVisualScene( this.parseId( instance.getAttribute( 'url' ) ) );
2702
+
2703
+ }
2704
+
2705
+ parseId( text ) {
2706
+
2707
+ return text.substring( 1 );
2708
+
2709
+ }
2710
+
2711
+ setupAnimations() {
2712
+
2713
+ const clips = this.library.clips;
2714
+
2715
+ if ( this.isEmpty( clips ) === true ) {
2716
+
2717
+ if ( this.isEmpty( this.library.animations ) === false ) {
2718
+
2719
+ // if there are animations but no clips, we create a default clip for playback
2720
+
2721
+ const tracks = [];
2722
+
2723
+ for ( const id in this.library.animations ) {
2724
+
2725
+ const animationTracks = this.getAnimation( id );
2726
+
2727
+ for ( let i = 0, l = animationTracks.length; i < l; i ++ ) {
2728
+
2729
+ tracks.push( animationTracks[ i ] );
2730
+
2731
+ }
2732
+
2733
+ }
2734
+
2735
+ this.buildDeferredPivotAnimationTracks( tracks );
2736
+
2737
+ this.animations.push( new AnimationClip( 'default', - 1, tracks ) );
2738
+
2739
+ }
2740
+
2741
+ } else {
2742
+
2743
+ for ( const id in clips ) {
2744
+
2745
+ this.animations.push( this.getAnimationClip( id ) );
2746
+
2747
+ }
2748
+
2749
+ }
2750
+
2751
+ }
2752
+
2753
+ buildDeferredPivotAnimationTracks( tracks ) {
2754
+
2755
+ for ( const nodeId in this.deferredPivotAnimations ) {
2756
+
2757
+ const nodeData = this.library.nodes[ nodeId ];
2758
+ if ( ! nodeData ) continue;
2759
+
2760
+ const mergedChannels = this.deferredPivotAnimations[ nodeId ];
2761
+ this.buildTransformHierarchyTracks( nodeId, mergedChannels, nodeData, tracks );
2762
+
2763
+ }
2764
+
2765
+ }
2766
+
2767
+ buildTransformHierarchyTracks( nodeId, nodeChannels, nodeData, tracks ) {
2768
+
2769
+ const transformNodes = this.transformNodes[ nodeId ];
2770
+
2771
+ if ( ! transformNodes ) {
2772
+
2773
+ console.warn( 'THREE.ColladaLoader: Transform hierarchy not found for node:', nodeId );
2774
+ return;
2775
+
2776
+ }
2777
+
2778
+ for ( const sid in nodeChannels ) {
2779
+
2780
+ const transformNode = transformNodes[ sid ];
2781
+ if ( ! transformNode ) continue;
2782
+
2783
+ const transformType = nodeData.transforms[ sid ];
2784
+ const transformInfo = nodeData.transformData[ sid ];
2785
+ const channelData = nodeChannels[ sid ];
2786
+
2787
+ switch ( transformType ) {
2788
+
2789
+ case 'translate':
2790
+ this.buildHierarchyTranslateTrack( transformNode, channelData, transformInfo, tracks );
2791
+ break;
2792
+
2793
+ case 'rotate':
2794
+ this.buildHierarchyRotateTrack( transformNode, channelData, transformInfo, tracks );
2795
+ break;
2796
+
2797
+ case 'scale':
2798
+ this.buildHierarchyScaleTrack( transformNode, channelData, transformInfo, tracks );
2799
+ break;
2800
+
2801
+ }
2802
+
2803
+ }
2804
+
2805
+ }
2806
+
2807
+ buildHierarchyTranslateTrack( transformNode, channelData, transformInfo, tracks ) {
2808
+
2809
+ if ( channelData.default && channelData.default.stride === 3 ) {
2810
+
2811
+ const data = channelData.default;
2812
+ const track = new VectorKeyframeTrack(
2813
+ transformNode.uuid + '.position',
2814
+ Array.from( data.times ),
2815
+ Array.from( data.values )
2816
+ );
2817
+
2818
+ const interpolationInfo = this.getInterpolationInfo( channelData );
2819
+ this.applyInterpolation( track, interpolationInfo, channelData );
2820
+ tracks.push( track );
2821
+ return;
2822
+
2823
+ }
2824
+
2825
+ const times = this.getTimesForAllAxes( channelData );
2826
+ if ( times.length === 0 ) return;
2827
+
2828
+ const values = [];
2829
+ const interpolationInfo = this.getInterpolationInfo( channelData );
2830
+
2831
+ for ( let i = 0; i < times.length; i ++ ) {
2832
+
2833
+ const time = times[ i ];
2834
+ const x = this.getValueAtTime( channelData.X, time, transformInfo.x );
2835
+ const y = this.getValueAtTime( channelData.Y, time, transformInfo.y );
2836
+ const z = this.getValueAtTime( channelData.Z, time, transformInfo.z );
2837
+ values.push( x, y, z );
2838
+
2839
+ }
2840
+
2841
+ const track = new VectorKeyframeTrack(
2842
+ transformNode.uuid + '.position',
2843
+ times,
2844
+ values
2845
+ );
2846
+
2847
+ this.applyInterpolation( track, interpolationInfo );
2848
+ tracks.push( track );
2849
+
2850
+ }
2851
+
2852
+ buildHierarchyRotateTrack( transformNode, channelData, transformInfo, tracks ) {
2853
+
2854
+ const angleData = channelData.ANGLE || channelData.default;
2855
+ if ( ! angleData ) return;
2856
+
2857
+ const times = Array.from( angleData.times );
2858
+ if ( times.length === 0 ) return;
2859
+
2860
+ const axis = transformNode.userData.rotationAxis ||
2861
+ new Vector3( transformInfo.axis[ 0 ], transformInfo.axis[ 1 ], transformInfo.axis[ 2 ] );
2862
+
2863
+ const quaternion = new Quaternion();
2864
+ const prevQuaternion = new Quaternion();
2865
+ const values = [];
2866
+
2867
+ const interpolationInfo = this.getInterpolationInfo( channelData );
2868
+
2869
+ for ( let i = 0; i < times.length; i ++ ) {
2870
+
2871
+ const time = times[ i ];
2872
+ const angleDegrees = this.getValueAtTime( angleData, time, transformInfo.angle );
2873
+ const angleRadians = MathUtils.degToRad( angleDegrees );
2874
+
2875
+ quaternion.setFromAxisAngle( axis, angleRadians );
2876
+
2877
+ // Ensure quaternion continuity
2878
+ if ( i > 0 && prevQuaternion.dot( quaternion ) < 0 ) {
2879
+
2880
+ quaternion.x = - quaternion.x;
2881
+ quaternion.y = - quaternion.y;
2882
+ quaternion.z = - quaternion.z;
2883
+ quaternion.w = - quaternion.w;
2884
+
2885
+ }
2886
+
2887
+ prevQuaternion.copy( quaternion );
2888
+ values.push( quaternion.x, quaternion.y, quaternion.z, quaternion.w );
2889
+
2890
+ }
2891
+
2892
+ const track = new QuaternionKeyframeTrack(
2893
+ transformNode.uuid + '.quaternion',
2894
+ times,
2895
+ values
2896
+ );
2897
+
2898
+ this.applyInterpolation( track, interpolationInfo );
2899
+ tracks.push( track );
2900
+
2901
+ }
2902
+
2903
+ buildHierarchyScaleTrack( transformNode, channelData, transformInfo, tracks ) {
2904
+
2905
+ if ( channelData.default && channelData.default.stride === 3 ) {
2906
+
2907
+ const data = channelData.default;
2908
+ const track = new VectorKeyframeTrack(
2909
+ transformNode.uuid + '.scale',
2910
+ Array.from( data.times ),
2911
+ Array.from( data.values )
2912
+ );
2913
+
2914
+ const interpolationInfo = this.getInterpolationInfo( channelData );
2915
+ this.applyInterpolation( track, interpolationInfo, channelData );
2916
+ tracks.push( track );
2917
+ return;
2918
+
2919
+ }
2920
+
2921
+ const times = this.getTimesForAllAxes( channelData );
2922
+ if ( times.length === 0 ) return;
2923
+
2924
+ const values = [];
2925
+ const interpolationInfo = this.getInterpolationInfo( channelData );
2926
+
2927
+ for ( let i = 0; i < times.length; i ++ ) {
2928
+
2929
+ const time = times[ i ];
2930
+ const x = this.getValueAtTime( channelData.X, time, transformInfo.x );
2931
+ const y = this.getValueAtTime( channelData.Y, time, transformInfo.y );
2932
+ const z = this.getValueAtTime( channelData.Z, time, transformInfo.z );
2933
+ values.push( x, y, z );
2934
+
2935
+ }
2936
+
2937
+ const track = new VectorKeyframeTrack(
2938
+ transformNode.uuid + '.scale',
2939
+ times,
2940
+ values
2941
+ );
2942
+
2943
+ this.applyInterpolation( track, interpolationInfo );
2944
+ tracks.push( track );
2945
+
2946
+ }
2947
+
2948
+ }
2949
+
2950
+ export { ColladaComposer };