super-three 0.147.1 → 0.154.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 (896) hide show
  1. package/LICENSE +1 -1
  2. package/build/three.cjs +37190 -21678
  3. package/build/three.js +37182 -21669
  4. package/build/three.min.js +4 -2
  5. package/build/three.module.js +7656 -6548
  6. package/build/three.module.min.js +7 -0
  7. package/examples/jsm/animation/AnimationClipCreator.js +5 -3
  8. package/examples/jsm/cameras/CinematicCamera.js +1 -2
  9. package/examples/jsm/capabilities/WebGPU.js +17 -5
  10. package/examples/jsm/controls/ArcballControls.js +1835 -1827
  11. package/examples/jsm/controls/FlyControls.js +25 -9
  12. package/examples/jsm/controls/MapControls.js +28 -0
  13. package/examples/jsm/controls/OrbitControls.js +25 -46
  14. package/examples/jsm/controls/PointerLockControls.js +70 -65
  15. package/examples/jsm/controls/TrackballControls.js +18 -4
  16. package/examples/jsm/controls/TransformControls.js +0 -1
  17. package/examples/jsm/csm/CSM.js +12 -6
  18. package/examples/jsm/csm/CSMShader.js +7 -6
  19. package/examples/jsm/effects/AnaglyphEffect.js +6 -20
  20. package/examples/jsm/effects/AsciiEffect.js +3 -6
  21. package/examples/jsm/effects/OutlineEffect.js +2 -16
  22. package/examples/jsm/effects/ParallaxBarrierEffect.js +3 -0
  23. package/examples/jsm/environments/RoomEnvironment.js +6 -2
  24. package/examples/jsm/exporters/DRACOExporter.js +53 -11
  25. package/examples/jsm/exporters/EXRExporter.js +3 -9
  26. package/examples/jsm/exporters/GLTFExporter.js +597 -112
  27. package/examples/jsm/exporters/KTX2Exporter.js +34 -23
  28. package/examples/jsm/exporters/MMDExporter.js +1 -1
  29. package/examples/jsm/exporters/PLYExporter.js +8 -1
  30. package/examples/jsm/exporters/STLExporter.js +8 -4
  31. package/examples/jsm/exporters/USDZExporter.js +184 -124
  32. package/examples/jsm/geometries/ConvexGeometry.js +0 -6
  33. package/examples/jsm/geometries/ParametricGeometry.js +10 -0
  34. package/examples/jsm/helpers/OctreeHelper.js +1 -0
  35. package/examples/jsm/helpers/ViewHelper.js +71 -57
  36. package/examples/jsm/interactive/HTMLMesh.js +16 -3
  37. package/examples/jsm/interactive/InteractiveGroup.js +1 -1
  38. package/examples/{js → jsm}/libs/basis/README.md +4 -4
  39. package/examples/jsm/libs/draco/draco_decoder.js +34 -0
  40. package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
  41. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -0
  42. package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -0
  43. package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
  44. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
  45. package/examples/jsm/libs/lil-gui.module.min.js +2 -2
  46. package/examples/jsm/libs/tween.module.js +803 -0
  47. package/examples/jsm/lights/IESSpotLight.js +25 -0
  48. package/examples/jsm/lights/LightProbeGenerator.js +11 -9
  49. package/examples/jsm/lines/LineMaterial.js +1 -1
  50. package/examples/jsm/lines/LineSegments2.js +12 -10
  51. package/examples/jsm/loaders/3DMLoader.js +9 -6
  52. package/examples/jsm/loaders/3MFLoader.js +17 -12
  53. package/examples/jsm/loaders/AMFLoader.js +7 -4
  54. package/examples/jsm/loaders/BVHLoader.js +2 -2
  55. package/examples/jsm/loaders/ColladaLoader.js +19 -17
  56. package/examples/jsm/loaders/DRACOLoader.js +69 -18
  57. package/examples/jsm/loaders/EXRLoader.js +23 -24
  58. package/examples/jsm/loaders/FBXLoader.js +41 -52
  59. package/examples/jsm/loaders/GCodeLoader.js +1 -2
  60. package/examples/jsm/loaders/GLTFLoader.js +452 -282
  61. package/examples/jsm/loaders/HDRCubeTextureLoader.js +4 -4
  62. package/examples/jsm/loaders/IESLoader.js +337 -0
  63. package/examples/jsm/loaders/KMZLoader.js +4 -4
  64. package/examples/jsm/loaders/KTX2Loader.js +145 -69
  65. package/examples/jsm/loaders/LDrawLoader.js +24 -25
  66. package/examples/jsm/loaders/LWOLoader.js +12 -29
  67. package/examples/jsm/loaders/LottieLoader.js +3 -1
  68. package/examples/jsm/loaders/MMDLoader.js +49 -18
  69. package/examples/jsm/loaders/MTLLoader.js +2 -2
  70. package/examples/jsm/loaders/MaterialXLoader.js +9 -3
  71. package/examples/jsm/loaders/NRRDLoader.js +33 -5
  72. package/examples/jsm/loaders/OBJLoader.js +1 -1
  73. package/examples/jsm/loaders/PCDLoader.js +26 -12
  74. package/examples/jsm/loaders/PDBLoader.js +7 -2
  75. package/examples/jsm/loaders/PLYLoader.js +261 -106
  76. package/examples/jsm/loaders/RGBELoader.js +3 -3
  77. package/examples/jsm/loaders/STLLoader.js +9 -5
  78. package/examples/jsm/loaders/SVGLoader.js +36 -27
  79. package/examples/jsm/loaders/TTFLoader.js +1 -8
  80. package/examples/jsm/loaders/TiltLoader.js +13 -7
  81. package/examples/jsm/loaders/USDZLoader.js +5 -5
  82. package/examples/jsm/loaders/VOXLoader.js +8 -2
  83. package/examples/jsm/loaders/VRMLLoader.js +60 -20
  84. package/examples/jsm/loaders/VTKLoader.js +19 -10
  85. package/examples/jsm/loaders/XYZLoader.js +9 -3
  86. package/examples/jsm/loaders/lwo/IFFParser.js +19 -19
  87. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -5
  88. package/examples/jsm/math/Lut.js +5 -4
  89. package/examples/jsm/math/MeshSurfaceSampler.js +82 -43
  90. package/examples/jsm/misc/ConvexObjectBreaker.js +2 -8
  91. package/examples/jsm/misc/GPUComputationRenderer.js +6 -5
  92. package/examples/jsm/misc/MD2Character.js +2 -2
  93. package/examples/jsm/misc/MD2CharacterComplex.js +2 -2
  94. package/examples/jsm/misc/ProgressiveLightMap.js +12 -10
  95. package/examples/jsm/misc/RollerCoaster.js +7 -1
  96. package/examples/jsm/misc/Volume.js +20 -5
  97. package/examples/jsm/misc/VolumeSlice.js +3 -1
  98. package/examples/jsm/modifiers/CurveModifier.js +1 -0
  99. package/examples/jsm/modifiers/TessellateModifier.js +19 -19
  100. package/examples/jsm/nodes/Nodes.js +149 -335
  101. package/examples/jsm/nodes/accessors/BitangentNode.js +43 -16
  102. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +99 -0
  103. package/examples/jsm/nodes/accessors/BufferNode.js +6 -0
  104. package/examples/jsm/nodes/accessors/CameraNode.js +36 -5
  105. package/examples/jsm/nodes/accessors/CubeTextureNode.js +27 -33
  106. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +64 -0
  107. package/examples/jsm/nodes/accessors/InstanceNode.js +39 -26
  108. package/examples/jsm/nodes/accessors/MaterialNode.js +164 -39
  109. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +16 -0
  110. package/examples/jsm/nodes/accessors/ModelNode.js +13 -0
  111. package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +13 -14
  112. package/examples/jsm/nodes/accessors/MorphNode.js +70 -0
  113. package/examples/jsm/nodes/accessors/NormalNode.js +36 -19
  114. package/examples/jsm/nodes/accessors/Object3DNode.js +40 -12
  115. package/examples/jsm/nodes/accessors/PointUVNode.js +6 -1
  116. package/examples/jsm/nodes/accessors/PositionNode.js +38 -23
  117. package/examples/jsm/nodes/accessors/ReferenceNode.js +21 -14
  118. package/examples/jsm/nodes/accessors/ReflectVectorNode.js +11 -7
  119. package/examples/jsm/nodes/accessors/SceneNode.js +46 -0
  120. package/examples/jsm/nodes/accessors/SkinningNode.js +55 -71
  121. package/examples/jsm/nodes/accessors/StorageBufferNode.js +6 -0
  122. package/examples/jsm/nodes/accessors/TangentNode.js +28 -20
  123. package/examples/jsm/nodes/accessors/TextureBicubicNode.js +94 -0
  124. package/examples/jsm/nodes/accessors/TextureNode.js +143 -13
  125. package/examples/jsm/nodes/accessors/TextureSizeNode.js +35 -0
  126. package/examples/jsm/nodes/accessors/UVNode.js +7 -1
  127. package/examples/jsm/nodes/accessors/UserDataNode.js +6 -0
  128. package/examples/jsm/nodes/code/CodeNode.js +78 -0
  129. package/examples/jsm/nodes/code/ExpressionNode.js +37 -0
  130. package/examples/jsm/nodes/{core → code}/FunctionCallNode.js +15 -1
  131. package/examples/jsm/nodes/{core → code}/FunctionNode.js +31 -9
  132. package/examples/jsm/nodes/code/ScriptableNode.js +488 -0
  133. package/examples/jsm/nodes/code/ScriptableValueNode.js +167 -0
  134. package/examples/jsm/nodes/core/ArrayUniformNode.js +3 -0
  135. package/examples/jsm/nodes/core/AttributeNode.js +17 -9
  136. package/examples/jsm/nodes/core/BypassNode.js +11 -4
  137. package/examples/jsm/nodes/core/CacheNode.js +46 -0
  138. package/examples/jsm/nodes/core/ConstNode.js +3 -0
  139. package/examples/jsm/nodes/core/ContextNode.js +10 -1
  140. package/examples/jsm/nodes/core/IndexNode.js +66 -0
  141. package/examples/jsm/nodes/core/InputNode.js +26 -5
  142. package/examples/jsm/nodes/core/LightingModel.js +17 -0
  143. package/examples/jsm/nodes/core/Node.js +128 -37
  144. package/examples/jsm/nodes/core/NodeAttribute.js +2 -1
  145. package/examples/jsm/nodes/core/NodeBuilder.js +287 -118
  146. package/examples/jsm/nodes/core/NodeCache.js +26 -0
  147. package/examples/jsm/nodes/core/NodeFrame.js +56 -5
  148. package/examples/jsm/nodes/core/NodeUtils.js +115 -28
  149. package/examples/jsm/nodes/core/PropertyNode.js +23 -2
  150. package/examples/jsm/nodes/core/StackNode.js +99 -0
  151. package/examples/jsm/nodes/core/TempNode.js +11 -3
  152. package/examples/jsm/nodes/core/UniformNode.js +16 -1
  153. package/examples/jsm/nodes/core/VarNode.js +19 -29
  154. package/examples/jsm/nodes/core/VaryingNode.js +15 -2
  155. package/examples/jsm/nodes/core/constants.js +6 -0
  156. package/examples/jsm/nodes/display/BlendModeNode.js +33 -19
  157. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +36 -20
  158. package/examples/jsm/nodes/display/ColorSpaceNode.js +60 -47
  159. package/examples/jsm/nodes/display/FrontFacingNode.js +7 -1
  160. package/examples/jsm/nodes/display/NormalMapNode.js +33 -20
  161. package/examples/jsm/nodes/display/PosterizeNode.js +10 -3
  162. package/examples/jsm/nodes/display/ToneMappingNode.js +101 -11
  163. package/examples/jsm/nodes/display/ViewportDepthNode.js +69 -0
  164. package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +34 -0
  165. package/examples/jsm/nodes/display/ViewportNode.js +27 -18
  166. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +31 -0
  167. package/examples/jsm/nodes/display/ViewportTextureNode.js +75 -0
  168. package/examples/jsm/nodes/fog/FogExp2Node.js +35 -0
  169. package/examples/jsm/nodes/fog/FogNode.js +12 -6
  170. package/examples/jsm/nodes/fog/FogRangeNode.js +12 -5
  171. package/examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js +30 -0
  172. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +15 -16
  173. package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +3 -3
  174. package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +43 -0
  175. package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +9 -7
  176. package/examples/jsm/nodes/functions/BSDF/D_GGX.js +5 -5
  177. package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +13 -0
  178. package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +4 -6
  179. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +8 -6
  180. package/examples/jsm/nodes/functions/PhongLightingModel.js +28 -0
  181. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +155 -45
  182. package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +5 -4
  183. package/examples/jsm/nodes/functions/material/getRoughness.js +6 -6
  184. package/examples/jsm/nodes/geometry/RangeNode.js +50 -55
  185. package/examples/jsm/nodes/gpgpu/ComputeNode.js +9 -2
  186. package/examples/jsm/nodes/lighting/AONode.js +5 -3
  187. package/examples/jsm/nodes/lighting/AmbientLightNode.js +27 -0
  188. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +114 -5
  189. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +43 -0
  190. package/examples/jsm/nodes/lighting/EnvironmentNode.js +153 -38
  191. package/examples/jsm/nodes/lighting/HemisphereLightNode.js +15 -10
  192. package/examples/jsm/nodes/lighting/IESSpotLightNode.js +39 -0
  193. package/examples/jsm/nodes/lighting/LightNode.js +57 -0
  194. package/examples/jsm/nodes/lighting/LightUtils.js +17 -0
  195. package/examples/jsm/nodes/lighting/LightingContextNode.js +41 -17
  196. package/examples/jsm/nodes/lighting/LightingNode.js +3 -1
  197. package/examples/jsm/nodes/lighting/LightsNode.js +18 -10
  198. package/examples/jsm/nodes/lighting/PointLightNode.js +71 -0
  199. package/examples/jsm/nodes/lighting/SpotLightNode.js +92 -0
  200. package/examples/jsm/nodes/loaders/NodeLoader.js +5 -4
  201. package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +4 -20
  202. package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +6 -24
  203. package/examples/jsm/nodes/materials/Materials.js +11 -55
  204. package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +5 -26
  205. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +38 -0
  206. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +65 -0
  207. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +47 -6
  208. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +22 -110
  209. package/examples/jsm/nodes/materials/NodeMaterial.js +340 -67
  210. package/examples/jsm/nodes/materials/PointsNodeMaterial.js +7 -10
  211. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +29 -32
  212. package/examples/jsm/nodes/materialx/MaterialXNodes.js +31 -22
  213. package/examples/jsm/nodes/materialx/lib/mx_hsv.js +3 -3
  214. package/examples/jsm/nodes/materialx/lib/mx_noise.js +14 -13
  215. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +4 -3
  216. package/examples/jsm/nodes/math/CondNode.js +43 -17
  217. package/examples/jsm/nodes/math/MathNode.js +184 -73
  218. package/examples/jsm/nodes/math/OperatorNode.js +53 -3
  219. package/examples/jsm/nodes/procedural/CheckerNode.js +16 -8
  220. package/examples/jsm/nodes/shadernode/ShaderNode.js +206 -63
  221. package/examples/jsm/nodes/utils/ArrayElementNode.js +4 -2
  222. package/examples/jsm/nodes/utils/ConvertNode.js +19 -1
  223. package/examples/jsm/nodes/utils/DiscardNode.js +26 -0
  224. package/examples/jsm/nodes/utils/EquirectUVNode.js +10 -4
  225. package/examples/jsm/nodes/utils/JoinNode.js +4 -1
  226. package/examples/jsm/nodes/utils/LoopNode.js +186 -0
  227. package/examples/jsm/nodes/utils/MatcapUVNode.js +11 -4
  228. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +18 -5
  229. package/examples/jsm/nodes/utils/OscNode.js +21 -14
  230. package/examples/jsm/nodes/utils/PackingNode.js +55 -0
  231. package/examples/jsm/nodes/utils/RemapNode.js +13 -5
  232. package/examples/jsm/nodes/utils/RotateUVNode.js +18 -7
  233. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +37 -0
  234. package/examples/jsm/nodes/utils/SplitNode.js +7 -5
  235. package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +15 -30
  236. package/examples/jsm/nodes/utils/TimerNode.js +16 -6
  237. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +21 -10
  238. package/examples/jsm/objects/GroundProjectedSkybox.js +172 -0
  239. package/examples/jsm/objects/Lensflare.js +3 -4
  240. package/examples/jsm/objects/MarchingCubes.js +5 -1
  241. package/examples/jsm/objects/Reflector.js +8 -5
  242. package/examples/jsm/objects/Refractor.js +5 -5
  243. package/examples/jsm/objects/ShadowMesh.js +3 -3
  244. package/examples/jsm/objects/Sky.js +1 -1
  245. package/examples/jsm/objects/Water.js +2 -1
  246. package/examples/jsm/objects/Water2.js +1 -1
  247. package/examples/jsm/offscreen/scene.js +1 -0
  248. package/examples/jsm/physics/AmmoPhysics.js +27 -28
  249. package/examples/jsm/physics/RapierPhysics.js +199 -0
  250. package/examples/jsm/postprocessing/AfterimagePass.js +3 -2
  251. package/examples/jsm/postprocessing/BloomPass.js +7 -4
  252. package/examples/jsm/postprocessing/BokehPass.js +3 -8
  253. package/examples/jsm/postprocessing/DotScreenPass.js +1 -2
  254. package/examples/jsm/postprocessing/EffectComposer.js +7 -95
  255. package/examples/jsm/postprocessing/FilmPass.js +1 -2
  256. package/examples/jsm/postprocessing/GlitchPass.js +0 -2
  257. package/examples/jsm/postprocessing/HalftonePass.js +0 -6
  258. package/examples/jsm/postprocessing/OutlinePass.js +8 -10
  259. package/examples/jsm/postprocessing/OutputPass.js +72 -0
  260. package/examples/jsm/postprocessing/Pass.js +2 -0
  261. package/examples/jsm/postprocessing/RenderPixelatedPass.js +4 -3
  262. package/examples/jsm/postprocessing/SAOPass.js +4 -26
  263. package/examples/jsm/postprocessing/SMAAPass.js +5 -8
  264. package/examples/jsm/postprocessing/SSAARenderPass.js +5 -5
  265. package/examples/jsm/postprocessing/SSAOPass.js +4 -14
  266. package/examples/jsm/postprocessing/SSRPass.js +3 -7
  267. package/examples/jsm/postprocessing/SavePass.js +5 -4
  268. package/examples/jsm/postprocessing/ShaderPass.js +1 -0
  269. package/examples/jsm/postprocessing/TAARenderPass.js +17 -4
  270. package/examples/jsm/postprocessing/TexturePass.js +2 -3
  271. package/examples/jsm/postprocessing/UnrealBloomPass.js +13 -21
  272. package/examples/jsm/renderers/CSS2DRenderer.js +6 -1
  273. package/examples/jsm/renderers/CSS3DRenderer.js +27 -5
  274. package/examples/jsm/renderers/{webgpu/WebGPUAnimation.js → common/Animation.js} +4 -4
  275. package/examples/jsm/renderers/common/Attributes.js +75 -0
  276. package/examples/jsm/renderers/common/Backend.js +162 -0
  277. package/examples/jsm/renderers/common/Background.js +134 -0
  278. package/examples/jsm/renderers/common/Binding.js +11 -0
  279. package/examples/jsm/renderers/common/Bindings.js +169 -0
  280. package/examples/jsm/renderers/common/Buffer.js +38 -0
  281. package/examples/jsm/renderers/{webgpu/WebGPUBufferUtils.js → common/BufferUtils.js} +2 -2
  282. package/examples/jsm/renderers/common/ChainMap.js +89 -0
  283. package/examples/jsm/renderers/common/ComputePipeline.js +17 -0
  284. package/examples/jsm/renderers/common/Constants.js +14 -0
  285. package/examples/jsm/renderers/common/CubeRenderTarget.js +65 -0
  286. package/examples/jsm/renderers/common/DataMap.js +54 -0
  287. package/examples/jsm/renderers/common/Geometries.js +215 -0
  288. package/examples/jsm/renderers/{webgpu/WebGPUInfo.js → common/Info.js} +2 -3
  289. package/examples/jsm/renderers/common/Pipeline.js +13 -0
  290. package/examples/jsm/renderers/common/Pipelines.js +321 -0
  291. package/examples/jsm/renderers/common/ProgrammableStage.js +18 -0
  292. package/examples/jsm/renderers/common/RenderContext.js +37 -0
  293. package/examples/jsm/renderers/common/RenderContexts.js +38 -0
  294. package/examples/jsm/renderers/{webgpu/WebGPURenderLists.js → common/RenderList.js} +26 -47
  295. package/examples/jsm/renderers/common/RenderLists.js +38 -0
  296. package/examples/jsm/renderers/common/RenderObject.js +113 -0
  297. package/examples/jsm/renderers/common/RenderObjects.js +92 -0
  298. package/examples/jsm/renderers/common/RenderPipeline.js +16 -0
  299. package/examples/jsm/renderers/common/RenderTarget.js +15 -0
  300. package/examples/jsm/renderers/common/Renderer.js +864 -0
  301. package/examples/jsm/renderers/common/SampledTexture.js +80 -0
  302. package/examples/jsm/renderers/common/Sampler.js +18 -0
  303. package/examples/jsm/renderers/common/StorageBuffer.js +17 -0
  304. package/examples/jsm/renderers/common/Textures.js +206 -0
  305. package/examples/jsm/renderers/{webgpu/WebGPUUniform.js → common/Uniform.js} +13 -9
  306. package/examples/jsm/renderers/common/UniformBuffer.js +15 -0
  307. package/examples/jsm/renderers/{webgpu/WebGPUUniformsGroup.js → common/UniformsGroup.js} +13 -13
  308. package/examples/jsm/renderers/common/nodes/NodeRender.js +302 -0
  309. package/examples/jsm/renderers/{webgpu/nodes/WebGPUNodeSampledTexture.js → common/nodes/NodeSampledTexture.js} +4 -4
  310. package/examples/jsm/renderers/{webgpu/nodes/WebGPUNodeSampler.js → common/nodes/NodeSampler.js} +3 -3
  311. package/examples/jsm/renderers/{webgpu/nodes/WebGPUNodeUniform.js → common/nodes/NodeUniform.js} +1 -1
  312. package/examples/jsm/renderers/common/nodes/Nodes.js +319 -0
  313. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +340 -0
  314. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +58 -50
  315. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +847 -0
  316. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +15 -987
  317. package/examples/jsm/renderers/webgpu/nodes/{WebGPUNodeBuilder.js → WGSLNodeBuilder.js} +139 -92
  318. package/examples/jsm/{nodes/parsers → renderers/webgpu/nodes}/WGSLNodeFunction.js +2 -2
  319. package/examples/jsm/{nodes/parsers → renderers/webgpu/nodes}/WGSLNodeParser.js +1 -1
  320. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +255 -0
  321. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +145 -0
  322. package/examples/jsm/renderers/webgpu/{constants.js → utils/WebGPUConstants.js} +73 -12
  323. package/examples/jsm/renderers/webgpu/{WebGPURenderPipeline.js → utils/WebGPUPipelineUtils.js} +141 -296
  324. package/examples/jsm/renderers/webgpu/{WebGPUTextureUtils.js → utils/WebGPUTextureMipmapUtils.js} +5 -25
  325. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +937 -0
  326. package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +92 -0
  327. package/examples/jsm/shaders/BleachBypassShader.js +2 -0
  328. package/examples/jsm/shaders/BlendShader.js +1 -2
  329. package/examples/jsm/shaders/BokehShader2.js +3 -0
  330. package/examples/jsm/shaders/ColorifyShader.js +2 -0
  331. package/examples/jsm/shaders/ConvolutionShader.js +2 -0
  332. package/examples/jsm/shaders/CopyShader.js +4 -2
  333. package/examples/jsm/shaders/DotScreenShader.js +2 -0
  334. package/examples/jsm/shaders/ExposureShader.js +44 -0
  335. package/examples/jsm/shaders/FilmShader.js +2 -0
  336. package/examples/jsm/shaders/GammaCorrectionShader.js +2 -0
  337. package/examples/jsm/shaders/HorizontalBlurShader.js +2 -0
  338. package/examples/jsm/shaders/MMDToonShader.js +15 -4
  339. package/examples/jsm/shaders/OutputShader.js +61 -0
  340. package/examples/jsm/shaders/RGBShiftShader.js +4 -2
  341. package/examples/jsm/shaders/SepiaShader.js +2 -0
  342. package/examples/jsm/shaders/ToonShader.js +13 -5
  343. package/examples/jsm/shaders/VelocityShader.js +1 -1
  344. package/examples/jsm/shaders/VerticalBlurShader.js +2 -0
  345. package/examples/jsm/shaders/VignetteShader.js +2 -0
  346. package/examples/jsm/shaders/WaterRefractionShader.js +5 -2
  347. package/examples/jsm/utils/BufferGeometryUtils.js +54 -36
  348. package/examples/jsm/utils/LDrawUtils.js +4 -4
  349. package/examples/jsm/utils/PackedPhongMaterial.js +5 -78
  350. package/examples/jsm/utils/SceneUtils.js +8 -4
  351. package/examples/jsm/utils/SkeletonUtils.js +27 -210
  352. package/examples/jsm/utils/TextureUtils.js +86 -0
  353. package/examples/jsm/webxr/OculusHandPointerModel.js +34 -13
  354. package/examples/jsm/webxr/VRButton.js +1 -2
  355. package/examples/jsm/webxr/XRButton.js +198 -0
  356. package/examples/jsm/webxr/XRHandPrimitiveModel.js +1 -0
  357. package/examples/jsm/webxr/XRPlanes.js +100 -0
  358. package/package.json +35 -87
  359. package/src/Three.Legacy.js +0 -319
  360. package/src/Three.js +4 -3
  361. package/src/animation/AnimationUtils.js +13 -1
  362. package/src/animation/PropertyBinding.js +2 -2
  363. package/src/audio/Audio.js +7 -2
  364. package/src/audio/PositionalAudio.js +8 -0
  365. package/src/cameras/Camera.js +5 -0
  366. package/src/cameras/CubeCamera.js +76 -13
  367. package/src/cameras/OrthographicCamera.js +1 -1
  368. package/src/cameras/PerspectiveCamera.js +1 -1
  369. package/src/constants.js +22 -2
  370. package/src/core/BufferAttribute.js +146 -29
  371. package/src/core/BufferGeometry.js +2 -15
  372. package/src/core/GLBufferAttribute.js +2 -0
  373. package/src/core/InterleavedBufferAttribute.js +1 -1
  374. package/src/core/Object3D.js +37 -8
  375. package/src/extras/DataUtils.js +7 -1
  376. package/src/extras/ImageUtils.js +2 -2
  377. package/src/extras/PMREMGenerator.js +5 -5
  378. package/src/extras/core/Curve.js +1 -1
  379. package/src/extras/curves/LineCurve.js +6 -4
  380. package/src/extras/curves/LineCurve3.js +13 -0
  381. package/src/geometries/BoxGeometry.js +10 -0
  382. package/src/geometries/CircleGeometry.js +11 -1
  383. package/src/geometries/ConeGeometry.js +1 -1
  384. package/src/geometries/CylinderGeometry.js +11 -1
  385. package/src/geometries/EdgesGeometry.js +10 -0
  386. package/src/geometries/ExtrudeGeometry.js +11 -1
  387. package/src/geometries/LatheGeometry.js +10 -0
  388. package/src/geometries/PlaneGeometry.js +10 -0
  389. package/src/geometries/PolyhedronGeometry.js +10 -0
  390. package/src/geometries/RingGeometry.js +11 -1
  391. package/src/geometries/ShapeGeometry.js +10 -0
  392. package/src/geometries/SphereGeometry.js +12 -2
  393. package/src/geometries/TorusGeometry.js +11 -1
  394. package/src/geometries/TorusKnotGeometry.js +10 -0
  395. package/src/geometries/TubeGeometry.js +10 -0
  396. package/src/geometries/WireframeGeometry.js +10 -0
  397. package/src/helpers/Box3Helper.js +1 -2
  398. package/src/lights/DirectionalLight.js +1 -1
  399. package/src/lights/HemisphereLight.js +1 -1
  400. package/src/lights/SpotLight.js +1 -1
  401. package/src/loaders/AudioLoader.js +14 -8
  402. package/src/loaders/CubeTextureLoader.js +2 -0
  403. package/src/loaders/DataTextureLoader.js +5 -1
  404. package/src/loaders/Loader.js +2 -0
  405. package/src/loaders/MaterialLoader.js +9 -0
  406. package/src/loaders/ObjectLoader.js +10 -2
  407. package/src/materials/LineBasicMaterial.js +4 -0
  408. package/src/materials/Material.js +19 -4
  409. package/src/materials/MeshDistanceMaterial.js +0 -9
  410. package/src/materials/MeshPhysicalMaterial.js +32 -6
  411. package/src/materials/ShaderMaterial.js +6 -1
  412. package/src/math/Box2.js +3 -2
  413. package/src/math/Box3.js +49 -64
  414. package/src/math/Color.js +88 -66
  415. package/src/math/ColorManagement.js +75 -16
  416. package/src/math/Euler.js +2 -11
  417. package/src/math/Frustum.js +29 -5
  418. package/src/math/MathUtils.js +43 -1
  419. package/src/math/Matrix3.js +26 -6
  420. package/src/math/Matrix4.js +74 -19
  421. package/src/math/Plane.js +2 -2
  422. package/src/math/Quaternion.js +6 -0
  423. package/src/math/Ray.js +7 -7
  424. package/src/math/Triangle.js +37 -7
  425. package/src/math/Vector2.js +16 -0
  426. package/src/math/Vector3.js +10 -0
  427. package/src/math/interpolants/CubicInterpolant.js +1 -2
  428. package/src/objects/InstancedMesh.js +82 -1
  429. package/src/objects/Mesh.js +108 -76
  430. package/src/objects/Skeleton.js +1 -3
  431. package/src/objects/SkinnedMesh.js +123 -8
  432. package/src/objects/Sprite.js +1 -1
  433. package/src/renderers/WebGLCubeRenderTarget.js +12 -3
  434. package/src/renderers/WebGLMultipleRenderTargets.js +4 -2
  435. package/src/renderers/WebGLRenderTarget.js +14 -2
  436. package/src/renderers/WebGLRenderer.js +1439 -1252
  437. package/src/renderers/shaders/ShaderChunk/alphahash_fragment.glsl.js +7 -0
  438. package/src/renderers/shaders/ShaderChunk/alphahash_pars_fragment.glsl.js +68 -0
  439. package/src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl.js +1 -1
  440. package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +1 -1
  441. package/src/renderers/shaders/ShaderChunk/begin_vertex.glsl.js +6 -0
  442. package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +0 -271
  443. package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +5 -5
  444. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js +2 -10
  445. package/src/renderers/shaders/ShaderChunk/clearcoat_pars_fragment.glsl.js +5 -5
  446. package/src/renderers/shaders/ShaderChunk/common.glsl.js +38 -0
  447. package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +1 -1
  448. package/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl.js +1 -1
  449. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +1 -1
  450. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +26 -3
  451. package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +1 -1
  452. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +3 -3
  453. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +10 -2
  454. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +11 -11
  455. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +39 -13
  456. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +306 -10
  457. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +1 -11
  458. package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +9 -1
  459. package/src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl.js +10 -2
  460. package/src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl.js +1 -1
  461. package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +40 -10
  462. package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +5 -13
  463. package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +7 -7
  464. package/src/renderers/shaders/ShaderChunk/{output_fragment.glsl.js → opaque_fragment.glsl.js} +1 -2
  465. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +11 -5
  466. package/src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl.js +1 -1
  467. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +4 -11
  468. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +2 -2
  469. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +39 -34
  470. package/src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl.js +1 -1
  471. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +1 -1
  472. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +5 -5
  473. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +101 -16
  474. package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +113 -1
  475. package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +135 -7
  476. package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +117 -2
  477. package/src/renderers/shaders/ShaderChunk.js +10 -12
  478. package/src/renderers/shaders/ShaderLib/background.glsl.js +1 -9
  479. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +1 -1
  480. package/src/renderers/shaders/ShaderLib/cube.glsl.js +1 -1
  481. package/src/renderers/shaders/ShaderLib/depth.glsl.js +2 -0
  482. package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +2 -0
  483. package/src/renderers/shaders/ShaderLib/equirect.glsl.js +1 -1
  484. package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +7 -2
  485. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +5 -6
  486. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +4 -5
  487. package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +4 -2
  488. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +3 -3
  489. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +4 -5
  490. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +20 -14
  491. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +4 -5
  492. package/src/renderers/shaders/ShaderLib/points.glsl.js +17 -2
  493. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +6 -1
  494. package/src/renderers/shaders/ShaderLib/sprite.glsl.js +4 -2
  495. package/src/renderers/shaders/ShaderLib.js +18 -4
  496. package/src/renderers/shaders/UniformsLib.js +27 -15
  497. package/src/renderers/shaders/UniformsUtils.js +12 -3
  498. package/src/renderers/webgl/WebGLBackground.js +23 -12
  499. package/src/renderers/webgl/WebGLBindingStates.js +13 -5
  500. package/src/renderers/webgl/WebGLCapabilities.js +1 -2
  501. package/src/renderers/webgl/WebGLClipping.js +7 -3
  502. package/src/renderers/webgl/WebGLGeometries.js +12 -0
  503. package/src/renderers/webgl/WebGLInfo.js +0 -1
  504. package/src/renderers/webgl/WebGLLights.js +2 -2
  505. package/src/renderers/webgl/WebGLMaterials.js +123 -234
  506. package/src/renderers/webgl/WebGLMorphtargets.js +1 -1
  507. package/src/renderers/webgl/WebGLObjects.js +23 -3
  508. package/src/renderers/webgl/WebGLProgram.js +154 -53
  509. package/src/renderers/webgl/WebGLPrograms.js +213 -130
  510. package/src/renderers/webgl/WebGLRenderStates.js +2 -2
  511. package/src/renderers/webgl/WebGLShadowMap.js +40 -27
  512. package/src/renderers/webgl/WebGLState.js +23 -9
  513. package/src/renderers/webgl/WebGLTextures.js +39 -19
  514. package/src/renderers/webgl/WebGLUniformsGroups.js +74 -33
  515. package/src/renderers/webgl/WebGLUtils.js +41 -29
  516. package/src/renderers/webvr/WebVRManager.js +12 -0
  517. package/src/renderers/webxr/WebXRController.js +3 -0
  518. package/src/renderers/webxr/WebXRManager.js +96 -134
  519. package/src/scenes/Scene.js +2 -18
  520. package/src/textures/CompressedTexture.js +2 -2
  521. package/src/textures/CubeTexture.js +2 -2
  522. package/src/textures/DataTexture.js +2 -2
  523. package/src/textures/DepthTexture.js +22 -0
  524. package/src/textures/FramebufferTexture.js +1 -3
  525. package/src/textures/Source.js +4 -0
  526. package/src/textures/Texture.js +42 -13
  527. package/src/utils.js +13 -1
  528. package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff +0 -0
  529. package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff2 +0 -0
  530. package/examples/fonts/open-sans/open-sans.css +0 -9
  531. package/examples/fonts/tabler-icons/fonts/tabler-icons.eot +0 -0
  532. package/examples/fonts/tabler-icons/fonts/tabler-icons.svg +0 -3966
  533. package/examples/fonts/tabler-icons/fonts/tabler-icons.ttf +0 -0
  534. package/examples/fonts/tabler-icons/fonts/tabler-icons.woff +0 -0
  535. package/examples/fonts/tabler-icons/fonts/tabler-icons.woff2 +0 -0
  536. package/examples/fonts/tabler-icons/tabler-icons.min.css +0 -4
  537. package/examples/js/animation/AnimationClipCreator.js +0 -89
  538. package/examples/js/animation/CCDIKSolver.js +0 -416
  539. package/examples/js/animation/MMDAnimationHelper.js +0 -1046
  540. package/examples/js/animation/MMDPhysics.js +0 -1174
  541. package/examples/js/cameras/CinematicCamera.js +0 -168
  542. package/examples/js/controls/ArcballControls.js +0 -2770
  543. package/examples/js/controls/DragControls.js +0 -205
  544. package/examples/js/controls/FirstPersonControls.js +0 -312
  545. package/examples/js/controls/FlyControls.js +0 -321
  546. package/examples/js/controls/OrbitControls.js +0 -1101
  547. package/examples/js/controls/PointerLockControls.js +0 -144
  548. package/examples/js/controls/TrackballControls.js +0 -729
  549. package/examples/js/controls/TransformControls.js +0 -1301
  550. package/examples/js/csm/CSM.js +0 -347
  551. package/examples/js/csm/CSMFrustum.js +0 -127
  552. package/examples/js/csm/CSMHelper.js +0 -165
  553. package/examples/js/csm/CSMShader.js +0 -253
  554. package/examples/js/curves/CurveExtras.js +0 -348
  555. package/examples/js/curves/NURBSCurve.js +0 -63
  556. package/examples/js/curves/NURBSSurface.js +0 -48
  557. package/examples/js/curves/NURBSUtils.js +0 -439
  558. package/examples/js/effects/AnaglyphEffect.js +0 -86
  559. package/examples/js/effects/AsciiEffect.js +0 -260
  560. package/examples/js/effects/OutlineEffect.js +0 -450
  561. package/examples/js/effects/ParallaxBarrierEffect.js +0 -62
  562. package/examples/js/effects/PeppersGhostEffect.js +0 -139
  563. package/examples/js/effects/StereoEffect.js +0 -46
  564. package/examples/js/environments/DebugEnvironment.js +0 -53
  565. package/examples/js/environments/RoomEnvironment.js +0 -124
  566. package/examples/js/exporters/ColladaExporter.js +0 -487
  567. package/examples/js/exporters/DRACOExporter.js +0 -212
  568. package/examples/js/exporters/EXRExporter.js +0 -455
  569. package/examples/js/exporters/GLTFExporter.js +0 -2367
  570. package/examples/js/exporters/MMDExporter.js +0 -187
  571. package/examples/js/exporters/OBJExporter.js +0 -260
  572. package/examples/js/exporters/PLYExporter.js +0 -427
  573. package/examples/js/exporters/STLExporter.js +0 -188
  574. package/examples/js/exporters/USDZExporter.js +0 -608
  575. package/examples/js/geometries/BoxLineGeometry.js +0 -59
  576. package/examples/js/geometries/ConvexGeometry.js +0 -53
  577. package/examples/js/geometries/DecalGeometry.js +0 -324
  578. package/examples/js/geometries/LightningStrike.js +0 -861
  579. package/examples/js/geometries/ParametricGeometries.js +0 -216
  580. package/examples/js/geometries/ParametricGeometry.js +0 -121
  581. package/examples/js/geometries/RoundedBoxGeometry.js +0 -142
  582. package/examples/js/geometries/TeapotGeometry.js +0 -335
  583. package/examples/js/geometries/TextGeometry.js +0 -53
  584. package/examples/js/helpers/LightProbeHelper.js +0 -48
  585. package/examples/js/helpers/OctreeHelper.js +0 -76
  586. package/examples/js/helpers/PositionalAudioHelper.js +0 -91
  587. package/examples/js/helpers/RectAreaLightHelper.js +0 -73
  588. package/examples/js/helpers/VertexNormalsHelper.js +0 -74
  589. package/examples/js/helpers/VertexTangentsHelper.js +0 -68
  590. package/examples/js/helpers/ViewHelper.js +0 -281
  591. package/examples/js/interactive/HTMLMesh.js +0 -497
  592. package/examples/js/interactive/InteractiveGroup.js +0 -95
  593. package/examples/js/interactive/SelectionBox.js +0 -195
  594. package/examples/js/interactive/SelectionHelper.js +0 -83
  595. package/examples/js/libs/chevrotain.min.js +0 -3
  596. package/examples/js/libs/draco/draco_decoder.js +0 -52
  597. package/examples/js/libs/draco/draco_decoder.wasm +0 -0
  598. package/examples/js/libs/draco/draco_wasm_wrapper.js +0 -104
  599. package/examples/js/libs/draco/gltf/draco_decoder.js +0 -48
  600. package/examples/js/libs/draco/gltf/draco_decoder.wasm +0 -0
  601. package/examples/js/libs/draco/gltf/draco_wasm_wrapper.js +0 -104
  602. package/examples/js/libs/fflate.min.js +0 -7
  603. package/examples/js/libs/ktx-parse.umd.js +0 -1
  604. package/examples/js/libs/meshopt_decoder.js +0 -188
  605. package/examples/js/libs/opentype.min.js +0 -1
  606. package/examples/js/libs/stats.min.js +0 -5
  607. package/examples/js/lights/LightProbeGenerator.js +0 -221
  608. package/examples/js/lights/RectAreaLightUniformsLib.js +0 -60
  609. package/examples/js/lines/Line2.js +0 -19
  610. package/examples/js/lines/LineGeometry.js +0 -69
  611. package/examples/js/lines/LineMaterial.js +0 -635
  612. package/examples/js/lines/LineSegments2.js +0 -313
  613. package/examples/js/lines/LineSegmentsGeometry.js +0 -198
  614. package/examples/js/lines/Wireframe.js +0 -47
  615. package/examples/js/lines/WireframeGeometry2.js +0 -20
  616. package/examples/js/loaders/3DMLoader.js +0 -1273
  617. package/examples/js/loaders/3MFLoader.js +0 -1306
  618. package/examples/js/loaders/AMFLoader.js +0 -504
  619. package/examples/js/loaders/BVHLoader.js +0 -395
  620. package/examples/js/loaders/BasisTextureLoader.js +0 -706
  621. package/examples/js/loaders/ColladaLoader.js +0 -3690
  622. package/examples/js/loaders/DDSLoader.js +0 -244
  623. package/examples/js/loaders/DRACOLoader.js +0 -511
  624. package/examples/js/loaders/EXRLoader.js +0 -2039
  625. package/examples/js/loaders/FBXLoader.js +0 -3681
  626. package/examples/js/loaders/FontLoader.js +0 -160
  627. package/examples/js/loaders/GCodeLoader.js +0 -255
  628. package/examples/js/loaders/GLTFLoader.js +0 -3862
  629. package/examples/js/loaders/HDRCubeTextureLoader.js +0 -87
  630. package/examples/js/loaders/KMZLoader.js +0 -121
  631. package/examples/js/loaders/KTXLoader.js +0 -159
  632. package/examples/js/loaders/LDrawLoader.js +0 -2263
  633. package/examples/js/loaders/LUT3dlLoader.js +0 -135
  634. package/examples/js/loaders/LUTCubeLoader.js +0 -132
  635. package/examples/js/loaders/LWOLoader.js +0 -901
  636. package/examples/js/loaders/LogLuvLoader.js +0 -715
  637. package/examples/js/loaders/LottieLoader.js +0 -62
  638. package/examples/js/loaders/MD2Loader.js +0 -248
  639. package/examples/js/loaders/MDDLoader.js +0 -91
  640. package/examples/js/loaders/MMDLoader.js +0 -1915
  641. package/examples/js/loaders/MTLLoader.js +0 -472
  642. package/examples/js/loaders/NRRDLoader.js +0 -609
  643. package/examples/js/loaders/OBJLoader.js +0 -789
  644. package/examples/js/loaders/PCDLoader.js +0 -413
  645. package/examples/js/loaders/PDBLoader.js +0 -317
  646. package/examples/js/loaders/PLYLoader.js +0 -576
  647. package/examples/js/loaders/PRWMLoader.js +0 -249
  648. package/examples/js/loaders/PVRLoader.js +0 -218
  649. package/examples/js/loaders/RGBELoader.js +0 -442
  650. package/examples/js/loaders/RGBMLoader.js +0 -1354
  651. package/examples/js/loaders/STLLoader.js +0 -364
  652. package/examples/js/loaders/SVGLoader.js +0 -2783
  653. package/examples/js/loaders/TDSLoader.js +0 -992
  654. package/examples/js/loaders/TGALoader.js +0 -484
  655. package/examples/js/loaders/TIFFLoader.js +0 -30
  656. package/examples/js/loaders/TTFLoader.js +0 -203
  657. package/examples/js/loaders/TiltLoader.js +0 -459
  658. package/examples/js/loaders/VOXLoader.js +0 -240
  659. package/examples/js/loaders/VRMLLoader.js +0 -3140
  660. package/examples/js/loaders/VTKLoader.js +0 -1078
  661. package/examples/js/loaders/XYZLoader.js +0 -89
  662. package/examples/js/loaders/lwo/IFFParser.js +0 -1067
  663. package/examples/js/loaders/lwo/LWO2Parser.js +0 -397
  664. package/examples/js/loaders/lwo/LWO3Parser.js +0 -360
  665. package/examples/js/materials/MeshGouraudMaterial.js +0 -387
  666. package/examples/js/math/Capsule.js +0 -103
  667. package/examples/js/math/ColorConverter.js +0 -33
  668. package/examples/js/math/ConvexHull.js +0 -1154
  669. package/examples/js/math/ImprovedNoise.js +0 -66
  670. package/examples/js/math/Lut.js +0 -164
  671. package/examples/js/math/MeshSurfaceSampler.js +0 -171
  672. package/examples/js/math/OBB.js +0 -382
  673. package/examples/js/math/Octree.js +0 -410
  674. package/examples/js/math/SimplexNoise.js +0 -445
  675. package/examples/js/misc/ConvexObjectBreaker.js +0 -474
  676. package/examples/js/misc/GPUComputationRenderer.js +0 -393
  677. package/examples/js/misc/Gyroscope.js +0 -56
  678. package/examples/js/misc/MD2Character.js +0 -235
  679. package/examples/js/misc/MD2CharacterComplex.js +0 -513
  680. package/examples/js/misc/MorphAnimMesh.js +0 -63
  681. package/examples/js/misc/MorphBlendMesh.js +0 -265
  682. package/examples/js/misc/ProgressiveLightMap.js +0 -335
  683. package/examples/js/misc/RollerCoaster.js +0 -430
  684. package/examples/js/misc/TubePainter.js +0 -167
  685. package/examples/js/misc/Volume.js +0 -437
  686. package/examples/js/misc/VolumeSlice.js +0 -214
  687. package/examples/js/modifiers/CurveModifier.js +0 -309
  688. package/examples/js/modifiers/EdgeSplitModifier.js +0 -228
  689. package/examples/js/modifiers/SimplifyModifier.js +0 -465
  690. package/examples/js/modifiers/TessellateModifier.js +0 -276
  691. package/examples/js/objects/GroundProjectedEnv.js +0 -181
  692. package/examples/js/objects/Lensflare.js +0 -356
  693. package/examples/js/objects/LightningStorm.js +0 -206
  694. package/examples/js/objects/MarchingCubes.js +0 -759
  695. package/examples/js/objects/Reflector.js +0 -216
  696. package/examples/js/objects/ReflectorForSSRPass.js +0 -315
  697. package/examples/js/objects/Refractor.js +0 -283
  698. package/examples/js/objects/ShadowMesh.js +0 -59
  699. package/examples/js/objects/Sky.js +0 -218
  700. package/examples/js/objects/Water.js +0 -292
  701. package/examples/js/objects/Water2.js +0 -307
  702. package/examples/js/physics/AmmoPhysics.js +0 -259
  703. package/examples/js/physics/OimoPhysics.js +0 -217
  704. package/examples/js/postprocessing/AdaptiveToneMappingPass.js +0 -335
  705. package/examples/js/postprocessing/AfterimagePass.js +0 -77
  706. package/examples/js/postprocessing/BloomPass.js +0 -135
  707. package/examples/js/postprocessing/BokehPass.js +0 -120
  708. package/examples/js/postprocessing/ClearPass.js +0 -39
  709. package/examples/js/postprocessing/CubeTexturePass.js +0 -60
  710. package/examples/js/postprocessing/DotScreenPass.js +0 -51
  711. package/examples/js/postprocessing/EffectComposer.js +0 -272
  712. package/examples/js/postprocessing/FilmPass.js +0 -52
  713. package/examples/js/postprocessing/GlitchPass.js +0 -104
  714. package/examples/js/postprocessing/HalftonePass.js +0 -75
  715. package/examples/js/postprocessing/LUTPass.js +0 -171
  716. package/examples/js/postprocessing/MaskPass.js +0 -95
  717. package/examples/js/postprocessing/OutlinePass.js +0 -598
  718. package/examples/js/postprocessing/Pass.js +0 -72
  719. package/examples/js/postprocessing/RenderPass.js +0 -70
  720. package/examples/js/postprocessing/RenderPixelatedPass.js +0 -215
  721. package/examples/js/postprocessing/SAOPass.js +0 -374
  722. package/examples/js/postprocessing/SMAAPass.js +0 -170
  723. package/examples/js/postprocessing/SSAARenderPass.js +0 -156
  724. package/examples/js/postprocessing/SSAOPass.js +0 -365
  725. package/examples/js/postprocessing/SSRPass.js +0 -567
  726. package/examples/js/postprocessing/SavePass.js +0 -59
  727. package/examples/js/postprocessing/ShaderPass.js +0 -64
  728. package/examples/js/postprocessing/TAARenderPass.js +0 -130
  729. package/examples/js/postprocessing/TexturePass.js +0 -49
  730. package/examples/js/postprocessing/UnrealBloomPass.js +0 -375
  731. package/examples/js/renderers/CSS2DRenderer.js +0 -178
  732. package/examples/js/renderers/CSS3DRenderer.js +0 -237
  733. package/examples/js/renderers/Projector.js +0 -818
  734. package/examples/js/renderers/SVGRenderer.js +0 -491
  735. package/examples/js/shaders/ACESFilmicToneMappingShader.js +0 -89
  736. package/examples/js/shaders/AfterimageShader.js +0 -60
  737. package/examples/js/shaders/BasicShader.js +0 -27
  738. package/examples/js/shaders/BleachBypassShader.js +0 -62
  739. package/examples/js/shaders/BlendShader.js +0 -54
  740. package/examples/js/shaders/BokehShader.js +0 -156
  741. package/examples/js/shaders/BokehShader2.js +0 -419
  742. package/examples/js/shaders/BrightnessContrastShader.js +0 -58
  743. package/examples/js/shaders/ColorCorrectionShader.js +0 -52
  744. package/examples/js/shaders/ColorifyShader.js +0 -47
  745. package/examples/js/shaders/ConvolutionShader.js +0 -92
  746. package/examples/js/shaders/CopyShader.js +0 -45
  747. package/examples/js/shaders/DOFMipMapShader.js +0 -60
  748. package/examples/js/shaders/DepthLimitedBlurShader.js +0 -173
  749. package/examples/js/shaders/DigitalGlitch.js +0 -127
  750. package/examples/js/shaders/DotScreenShader.js +0 -72
  751. package/examples/js/shaders/FXAAShader.js +0 -284
  752. package/examples/js/shaders/FilmShader.js +0 -110
  753. package/examples/js/shaders/FocusShader.js +0 -95
  754. package/examples/js/shaders/FreiChenShader.js +0 -93
  755. package/examples/js/shaders/GammaCorrectionShader.js +0 -41
  756. package/examples/js/shaders/GodRaysShader.js +0 -284
  757. package/examples/js/shaders/HalftoneShader.js +0 -336
  758. package/examples/js/shaders/HorizontalBlurShader.js +0 -59
  759. package/examples/js/shaders/HorizontalTiltShiftShader.js +0 -65
  760. package/examples/js/shaders/HueSaturationShader.js +0 -69
  761. package/examples/js/shaders/KaleidoShader.js +0 -60
  762. package/examples/js/shaders/LuminosityHighPassShader.js +0 -67
  763. package/examples/js/shaders/LuminosityShader.js +0 -46
  764. package/examples/js/shaders/MMDToonShader.js +0 -94
  765. package/examples/js/shaders/MirrorShader.js +0 -56
  766. package/examples/js/shaders/NormalMapShader.js +0 -55
  767. package/examples/js/shaders/RGBShiftShader.js +0 -56
  768. package/examples/js/shaders/SAOShader.js +0 -209
  769. package/examples/js/shaders/SMAAShader.js +0 -454
  770. package/examples/js/shaders/SSAOShader.js +0 -295
  771. package/examples/js/shaders/SSRShader.js +0 -381
  772. package/examples/js/shaders/SepiaShader.js +0 -52
  773. package/examples/js/shaders/SobelOperatorShader.js +0 -88
  774. package/examples/js/shaders/SubsurfaceScatteringShader.js +0 -49
  775. package/examples/js/shaders/TechnicolorShader.js +0 -43
  776. package/examples/js/shaders/ToneMapShader.js +0 -84
  777. package/examples/js/shaders/ToonShader.js +0 -335
  778. package/examples/js/shaders/TriangleBlurShader.js +0 -70
  779. package/examples/js/shaders/UnpackDepthRGBAShader.js +0 -47
  780. package/examples/js/shaders/VelocityShader.js +0 -126
  781. package/examples/js/shaders/VerticalBlurShader.js +0 -59
  782. package/examples/js/shaders/VerticalTiltShiftShader.js +0 -65
  783. package/examples/js/shaders/VignetteShader.js +0 -53
  784. package/examples/js/shaders/VolumeShader.js +0 -296
  785. package/examples/js/shaders/WaterRefractionShader.js +0 -84
  786. package/examples/js/textures/FlakesTexture.js +0 -40
  787. package/examples/js/utils/BufferGeometryUtils.js +0 -1160
  788. package/examples/js/utils/CameraUtils.js +0 -71
  789. package/examples/js/utils/GPUStatsPanel.js +0 -125
  790. package/examples/js/utils/GeometryCompressionUtils.js +0 -549
  791. package/examples/js/utils/GeometryUtils.js +0 -168
  792. package/examples/js/utils/LDrawUtils.js +0 -179
  793. package/examples/js/utils/PackedPhongMaterial.js +0 -109
  794. package/examples/js/utils/SceneUtils.js +0 -214
  795. package/examples/js/utils/ShadowMapViewer.js +0 -183
  796. package/examples/js/utils/SkeletonUtils.js +0 -493
  797. package/examples/js/utils/UVsDebug.js +0 -143
  798. package/examples/js/utils/WorkerPool.js +0 -105
  799. package/examples/jsm/exporters/ColladaExporter.js +0 -713
  800. package/examples/jsm/geometries/LightningStrike.js +0 -1017
  801. package/examples/jsm/libs/OimoPhysics/OimoPhysics.js +0 -37071
  802. package/examples/jsm/libs/OimoPhysics/index.js +0 -43
  803. package/examples/jsm/libs/flow.module.js +0 -4552
  804. package/examples/jsm/libs/tween.module.min.js +0 -3
  805. package/examples/jsm/loaders/BasisTextureLoader.js +0 -790
  806. package/examples/jsm/loaders/IFCLoader.js +0 -2431
  807. package/examples/jsm/loaders/PRWMLoader.js +0 -299
  808. package/examples/jsm/loaders/ifc/web-ifc-api.js +0 -47504
  809. package/examples/jsm/loaders/ifc/web-ifc.wasm +0 -0
  810. package/examples/jsm/node-editor/NodeEditor.js +0 -857
  811. package/examples/jsm/node-editor/accessors/MatcapUVEditor.js +0 -14
  812. package/examples/jsm/node-editor/accessors/NormalEditor.js +0 -30
  813. package/examples/jsm/node-editor/accessors/PositionEditor.js +0 -30
  814. package/examples/jsm/node-editor/accessors/UVEditor.js +0 -25
  815. package/examples/jsm/node-editor/core/BaseNode.js +0 -96
  816. package/examples/jsm/node-editor/core/DataFile.js +0 -59
  817. package/examples/jsm/node-editor/core/FileEditor.js +0 -20
  818. package/examples/jsm/node-editor/core/FileURLEditor.js +0 -29
  819. package/examples/jsm/node-editor/display/BlendEditor.js +0 -44
  820. package/examples/jsm/node-editor/display/NormalMapEditor.js +0 -49
  821. package/examples/jsm/node-editor/examples/animate-uv.json +0 -1
  822. package/examples/jsm/node-editor/examples/fake-top-light.json +0 -1
  823. package/examples/jsm/node-editor/examples/matcap.json +0 -1
  824. package/examples/jsm/node-editor/examples/oscillator-color.json +0 -1
  825. package/examples/jsm/node-editor/examples/rim.json +0 -1
  826. package/examples/jsm/node-editor/inputs/ColorEditor.js +0 -96
  827. package/examples/jsm/node-editor/inputs/FloatEditor.js +0 -23
  828. package/examples/jsm/node-editor/inputs/SliderEditor.js +0 -67
  829. package/examples/jsm/node-editor/inputs/TextureEditor.js +0 -155
  830. package/examples/jsm/node-editor/inputs/Vector2Editor.js +0 -28
  831. package/examples/jsm/node-editor/inputs/Vector3Editor.js +0 -30
  832. package/examples/jsm/node-editor/inputs/Vector4Editor.js +0 -37
  833. package/examples/jsm/node-editor/materials/BasicMaterialEditor.js +0 -84
  834. package/examples/jsm/node-editor/materials/PointsMaterialEditor.js +0 -102
  835. package/examples/jsm/node-editor/materials/StandardMaterialEditor.js +0 -118
  836. package/examples/jsm/node-editor/math/AngleEditor.js +0 -40
  837. package/examples/jsm/node-editor/math/DotEditor.js +0 -35
  838. package/examples/jsm/node-editor/math/InvertEditor.js +0 -39
  839. package/examples/jsm/node-editor/math/LimiterEditor.js +0 -62
  840. package/examples/jsm/node-editor/math/NormalizeEditor.js +0 -28
  841. package/examples/jsm/node-editor/math/OperatorEditor.js +0 -63
  842. package/examples/jsm/node-editor/math/PowerEditor.js +0 -44
  843. package/examples/jsm/node-editor/math/TrigonometryEditor.js +0 -45
  844. package/examples/jsm/node-editor/procedural/CheckerEditor.js +0 -27
  845. package/examples/jsm/node-editor/scene/MeshEditor.js +0 -102
  846. package/examples/jsm/node-editor/scene/Object3DEditor.js +0 -160
  847. package/examples/jsm/node-editor/scene/PointsEditor.js +0 -99
  848. package/examples/jsm/node-editor/utils/JoinEditor.js +0 -58
  849. package/examples/jsm/node-editor/utils/OscillatorEditor.js +0 -43
  850. package/examples/jsm/node-editor/utils/PreviewEditor.js +0 -170
  851. package/examples/jsm/node-editor/utils/SplitEditor.js +0 -39
  852. package/examples/jsm/node-editor/utils/TimerEditor.js +0 -58
  853. package/examples/jsm/nodes/core/CodeNode.js +0 -50
  854. package/examples/jsm/nodes/core/ExpressionNode.js +0 -32
  855. package/examples/jsm/nodes/core/InstanceIndexNode.js +0 -21
  856. package/examples/jsm/nodes/functions/light/getDistanceAttenuation.js +0 -22
  857. package/examples/jsm/nodes/lighting/PunctualLightNode.js +0 -68
  858. package/examples/jsm/nodes/shadernode/ShaderNodeBaseElements.js +0 -301
  859. package/examples/jsm/nodes/shadernode/ShaderNodeElements.js +0 -149
  860. package/examples/jsm/objects/GroundProjectedEnv.js +0 -186
  861. package/examples/jsm/objects/LightningStorm.js +0 -245
  862. package/examples/jsm/physics/OimoPhysics.js +0 -231
  863. package/examples/jsm/postprocessing/AdaptiveToneMappingPass.js +0 -369
  864. package/examples/jsm/renderers/webgpu/WebGPUAttributes.js +0 -187
  865. package/examples/jsm/renderers/webgpu/WebGPUBackground.js +0 -173
  866. package/examples/jsm/renderers/webgpu/WebGPUBinding.js +0 -22
  867. package/examples/jsm/renderers/webgpu/WebGPUBindings.js +0 -255
  868. package/examples/jsm/renderers/webgpu/WebGPUBuffer.js +0 -43
  869. package/examples/jsm/renderers/webgpu/WebGPUComputePipelines.js +0 -78
  870. package/examples/jsm/renderers/webgpu/WebGPUGeometries.js +0 -82
  871. package/examples/jsm/renderers/webgpu/WebGPUObjects.js +0 -36
  872. package/examples/jsm/renderers/webgpu/WebGPUProgrammableStage.js +0 -22
  873. package/examples/jsm/renderers/webgpu/WebGPUProperties.js +0 -38
  874. package/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js +0 -296
  875. package/examples/jsm/renderers/webgpu/WebGPURenderStates.js +0 -66
  876. package/examples/jsm/renderers/webgpu/WebGPUSampledTexture.js +0 -73
  877. package/examples/jsm/renderers/webgpu/WebGPUSampler.js +0 -29
  878. package/examples/jsm/renderers/webgpu/WebGPUStorageBuffer.js +0 -20
  879. package/examples/jsm/renderers/webgpu/WebGPUTextureRenderer.js +0 -40
  880. package/examples/jsm/renderers/webgpu/WebGPUTextures.js +0 -794
  881. package/examples/jsm/renderers/webgpu/WebGPUUniformBuffer.js +0 -18
  882. package/examples/jsm/renderers/webgpu/WebGPUUtils.js +0 -81
  883. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodes.js +0 -83
  884. package/examples/jsm/shaders/ToneMapShader.js +0 -73
  885. package/src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl.js +0 -7
  886. package/src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl.js +0 -10
  887. package/src/renderers/shaders/ShaderChunk/uv2_vertex.glsl.js +0 -7
  888. /package/examples/{js → jsm}/libs/ammo.wasm.js +0 -0
  889. /package/examples/{js → jsm}/libs/ammo.wasm.wasm +0 -0
  890. /package/examples/{js → jsm}/libs/basis/basis_transcoder.js +0 -0
  891. /package/examples/{js → jsm}/libs/basis/basis_transcoder.wasm +0 -0
  892. /package/examples/{js → jsm}/libs/draco/README.md +0 -0
  893. /package/examples/{js → jsm}/libs/draco/draco_encoder.js +0 -0
  894. /package/examples/{js → jsm}/libs/draco/gltf/draco_encoder.js +0 -0
  895. /package/src/renderers/shaders/ShaderChunk/{encodings_fragment.glsl.js → colorspace_fragment.glsl.js} +0 -0
  896. /package/src/renderers/shaders/ShaderChunk/{encodings_pars_fragment.glsl.js → colorspace_pars_fragment.glsl.js} +0 -0
@@ -1,3690 +0,0 @@
1
- ( function () {
2
-
3
- class ColladaLoader extends THREE.Loader {
4
-
5
- constructor( manager ) {
6
-
7
- super( manager );
8
-
9
- }
10
- load( url, onLoad, onProgress, onError ) {
11
-
12
- const scope = this;
13
- const path = scope.path === '' ? THREE.LoaderUtils.extractUrlBase( url ) : scope.path;
14
- const loader = new THREE.FileLoader( scope.manager );
15
- loader.setPath( scope.path );
16
- loader.setRequestHeader( scope.requestHeader );
17
- loader.setWithCredentials( scope.withCredentials );
18
- loader.load( url, function ( text ) {
19
-
20
- try {
21
-
22
- onLoad( scope.parse( text, path ) );
23
-
24
- } catch ( e ) {
25
-
26
- if ( onError ) {
27
-
28
- onError( e );
29
-
30
- } else {
31
-
32
- console.error( e );
33
-
34
- }
35
-
36
- scope.manager.itemError( url );
37
-
38
- }
39
-
40
- }, onProgress, onError );
41
-
42
- }
43
- parse( text, path ) {
44
-
45
- function getElementsByTagName( xml, name ) {
46
-
47
- // Non recursive xml.getElementsByTagName() ...
48
-
49
- const array = [];
50
- const childNodes = xml.childNodes;
51
- for ( let i = 0, l = childNodes.length; i < l; i ++ ) {
52
-
53
- const child = childNodes[ i ];
54
- if ( child.nodeName === name ) {
55
-
56
- array.push( child );
57
-
58
- }
59
-
60
- }
61
-
62
- return array;
63
-
64
- }
65
-
66
- function parseStrings( text ) {
67
-
68
- if ( text.length === 0 ) return [];
69
- const parts = text.trim().split( /\s+/ );
70
- const array = new Array( parts.length );
71
- for ( let i = 0, l = parts.length; i < l; i ++ ) {
72
-
73
- array[ i ] = parts[ i ];
74
-
75
- }
76
-
77
- return array;
78
-
79
- }
80
-
81
- function parseFloats( text ) {
82
-
83
- if ( text.length === 0 ) return [];
84
- const parts = text.trim().split( /\s+/ );
85
- const array = new Array( parts.length );
86
- for ( let i = 0, l = parts.length; i < l; i ++ ) {
87
-
88
- array[ i ] = parseFloat( parts[ i ] );
89
-
90
- }
91
-
92
- return array;
93
-
94
- }
95
-
96
- function parseInts( text ) {
97
-
98
- if ( text.length === 0 ) return [];
99
- const parts = text.trim().split( /\s+/ );
100
- const array = new Array( parts.length );
101
- for ( let i = 0, l = parts.length; i < l; i ++ ) {
102
-
103
- array[ i ] = parseInt( parts[ i ] );
104
-
105
- }
106
-
107
- return array;
108
-
109
- }
110
-
111
- function parseId( text ) {
112
-
113
- return text.substring( 1 );
114
-
115
- }
116
-
117
- function generateId() {
118
-
119
- return 'three_default_' + count ++;
120
-
121
- }
122
-
123
- function isEmpty( object ) {
124
-
125
- return Object.keys( object ).length === 0;
126
-
127
- }
128
-
129
- // asset
130
-
131
- function parseAsset( xml ) {
132
-
133
- return {
134
- unit: parseAssetUnit( getElementsByTagName( xml, 'unit' )[ 0 ] ),
135
- upAxis: parseAssetUpAxis( getElementsByTagName( xml, 'up_axis' )[ 0 ] )
136
- };
137
-
138
- }
139
-
140
- function parseAssetUnit( xml ) {
141
-
142
- if ( xml !== undefined && xml.hasAttribute( 'meter' ) === true ) {
143
-
144
- return parseFloat( xml.getAttribute( 'meter' ) );
145
-
146
- } else {
147
-
148
- return 1; // default 1 meter
149
-
150
- }
151
-
152
- }
153
-
154
- function parseAssetUpAxis( xml ) {
155
-
156
- return xml !== undefined ? xml.textContent : 'Y_UP';
157
-
158
- }
159
-
160
- // library
161
-
162
- function parseLibrary( xml, libraryName, nodeName, parser ) {
163
-
164
- const library = getElementsByTagName( xml, libraryName )[ 0 ];
165
- if ( library !== undefined ) {
166
-
167
- const elements = getElementsByTagName( library, nodeName );
168
- for ( let i = 0; i < elements.length; i ++ ) {
169
-
170
- parser( elements[ i ] );
171
-
172
- }
173
-
174
- }
175
-
176
- }
177
-
178
- function buildLibrary( data, builder ) {
179
-
180
- for ( const name in data ) {
181
-
182
- const object = data[ name ];
183
- object.build = builder( data[ name ] );
184
-
185
- }
186
-
187
- }
188
-
189
- // get
190
-
191
- function getBuild( data, builder ) {
192
-
193
- if ( data.build !== undefined ) return data.build;
194
- data.build = builder( data );
195
- return data.build;
196
-
197
- }
198
-
199
- // animation
200
-
201
- function parseAnimation( xml ) {
202
-
203
- const data = {
204
- sources: {},
205
- samplers: {},
206
- channels: {}
207
- };
208
- let hasChildren = false;
209
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
210
-
211
- const child = xml.childNodes[ i ];
212
- if ( child.nodeType !== 1 ) continue;
213
- let id;
214
- switch ( child.nodeName ) {
215
-
216
- case 'source':
217
- id = child.getAttribute( 'id' );
218
- data.sources[ id ] = parseSource( child );
219
- break;
220
- case 'sampler':
221
- id = child.getAttribute( 'id' );
222
- data.samplers[ id ] = parseAnimationSampler( child );
223
- break;
224
- case 'channel':
225
- id = child.getAttribute( 'target' );
226
- data.channels[ id ] = parseAnimationChannel( child );
227
- break;
228
- case 'animation':
229
- // hierarchy of related animations
230
- parseAnimation( child );
231
- hasChildren = true;
232
- break;
233
- default:
234
- console.log( child );
235
-
236
- }
237
-
238
- }
239
-
240
- if ( hasChildren === false ) {
241
-
242
- // since 'id' attributes can be optional, it's necessary to generate a UUID for unqiue assignment
243
-
244
- library.animations[ xml.getAttribute( 'id' ) || THREE.MathUtils.generateUUID() ] = data;
245
-
246
- }
247
-
248
- }
249
-
250
- function parseAnimationSampler( xml ) {
251
-
252
- const data = {
253
- inputs: {}
254
- };
255
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
256
-
257
- const child = xml.childNodes[ i ];
258
- if ( child.nodeType !== 1 ) continue;
259
- switch ( child.nodeName ) {
260
-
261
- case 'input':
262
- const id = parseId( child.getAttribute( 'source' ) );
263
- const semantic = child.getAttribute( 'semantic' );
264
- data.inputs[ semantic ] = id;
265
- break;
266
-
267
- }
268
-
269
- }
270
-
271
- return data;
272
-
273
- }
274
-
275
- function parseAnimationChannel( xml ) {
276
-
277
- const data = {};
278
- const target = xml.getAttribute( 'target' );
279
-
280
- // parsing SID Addressing Syntax
281
-
282
- let parts = target.split( '/' );
283
- const id = parts.shift();
284
- let sid = parts.shift();
285
-
286
- // check selection syntax
287
-
288
- const arraySyntax = sid.indexOf( '(' ) !== - 1;
289
- const memberSyntax = sid.indexOf( '.' ) !== - 1;
290
- if ( memberSyntax ) {
291
-
292
- // member selection access
293
-
294
- parts = sid.split( '.' );
295
- sid = parts.shift();
296
- data.member = parts.shift();
297
-
298
- } else if ( arraySyntax ) {
299
-
300
- // array-access syntax. can be used to express fields in one-dimensional vectors or two-dimensional matrices.
301
-
302
- const indices = sid.split( '(' );
303
- sid = indices.shift();
304
- for ( let i = 0; i < indices.length; i ++ ) {
305
-
306
- indices[ i ] = parseInt( indices[ i ].replace( /\)/, '' ) );
307
-
308
- }
309
-
310
- data.indices = indices;
311
-
312
- }
313
-
314
- data.id = id;
315
- data.sid = sid;
316
- data.arraySyntax = arraySyntax;
317
- data.memberSyntax = memberSyntax;
318
- data.sampler = parseId( xml.getAttribute( 'source' ) );
319
- return data;
320
-
321
- }
322
-
323
- function buildAnimation( data ) {
324
-
325
- const tracks = [];
326
- const channels = data.channels;
327
- const samplers = data.samplers;
328
- const sources = data.sources;
329
- for ( const target in channels ) {
330
-
331
- if ( channels.hasOwnProperty( target ) ) {
332
-
333
- const channel = channels[ target ];
334
- const sampler = samplers[ channel.sampler ];
335
- const inputId = sampler.inputs.INPUT;
336
- const outputId = sampler.inputs.OUTPUT;
337
- const inputSource = sources[ inputId ];
338
- const outputSource = sources[ outputId ];
339
- const animation = buildAnimationChannel( channel, inputSource, outputSource );
340
- createKeyframeTracks( animation, tracks );
341
-
342
- }
343
-
344
- }
345
-
346
- return tracks;
347
-
348
- }
349
-
350
- function getAnimation( id ) {
351
-
352
- return getBuild( library.animations[ id ], buildAnimation );
353
-
354
- }
355
-
356
- function buildAnimationChannel( channel, inputSource, outputSource ) {
357
-
358
- const node = library.nodes[ channel.id ];
359
- const object3D = getNode( node.id );
360
- const transform = node.transforms[ channel.sid ];
361
- const defaultMatrix = node.matrix.clone().transpose();
362
- let time, stride;
363
- let i, il, j, jl;
364
- const data = {};
365
-
366
- // the collada spec allows the animation of data in various ways.
367
- // depending on the transform type (matrix, translate, rotate, scale), we execute different logic
368
-
369
- switch ( transform ) {
370
-
371
- case 'matrix':
372
- for ( i = 0, il = inputSource.array.length; i < il; i ++ ) {
373
-
374
- time = inputSource.array[ i ];
375
- stride = i * outputSource.stride;
376
- if ( data[ time ] === undefined ) data[ time ] = {};
377
- if ( channel.arraySyntax === true ) {
378
-
379
- const value = outputSource.array[ stride ];
380
- const index = channel.indices[ 0 ] + 4 * channel.indices[ 1 ];
381
- data[ time ][ index ] = value;
382
-
383
- } else {
384
-
385
- for ( j = 0, jl = outputSource.stride; j < jl; j ++ ) {
386
-
387
- data[ time ][ j ] = outputSource.array[ stride + j ];
388
-
389
- }
390
-
391
- }
392
-
393
- }
394
-
395
- break;
396
- case 'translate':
397
- console.warn( 'THREE.ColladaLoader: Animation transform type "%s" not yet implemented.', transform );
398
- break;
399
- case 'rotate':
400
- console.warn( 'THREE.ColladaLoader: Animation transform type "%s" not yet implemented.', transform );
401
- break;
402
- case 'scale':
403
- console.warn( 'THREE.ColladaLoader: Animation transform type "%s" not yet implemented.', transform );
404
- break;
405
-
406
- }
407
-
408
- const keyframes = prepareAnimationData( data, defaultMatrix );
409
- const animation = {
410
- name: object3D.uuid,
411
- keyframes: keyframes
412
- };
413
- return animation;
414
-
415
- }
416
-
417
- function prepareAnimationData( data, defaultMatrix ) {
418
-
419
- const keyframes = [];
420
-
421
- // transfer data into a sortable array
422
-
423
- for ( const time in data ) {
424
-
425
- keyframes.push( {
426
- time: parseFloat( time ),
427
- value: data[ time ]
428
- } );
429
-
430
- }
431
-
432
- // ensure keyframes are sorted by time
433
-
434
- keyframes.sort( ascending );
435
-
436
- // now we clean up all animation data, so we can use them for keyframe tracks
437
-
438
- for ( let i = 0; i < 16; i ++ ) {
439
-
440
- transformAnimationData( keyframes, i, defaultMatrix.elements[ i ] );
441
-
442
- }
443
-
444
- return keyframes;
445
-
446
- // array sort function
447
-
448
- function ascending( a, b ) {
449
-
450
- return a.time - b.time;
451
-
452
- }
453
-
454
- }
455
-
456
- const position = new THREE.Vector3();
457
- const scale = new THREE.Vector3();
458
- const quaternion = new THREE.Quaternion();
459
- function createKeyframeTracks( animation, tracks ) {
460
-
461
- const keyframes = animation.keyframes;
462
- const name = animation.name;
463
- const times = [];
464
- const positionData = [];
465
- const quaternionData = [];
466
- const scaleData = [];
467
- for ( let i = 0, l = keyframes.length; i < l; i ++ ) {
468
-
469
- const keyframe = keyframes[ i ];
470
- const time = keyframe.time;
471
- const value = keyframe.value;
472
- matrix.fromArray( value ).transpose();
473
- matrix.decompose( position, quaternion, scale );
474
- times.push( time );
475
- positionData.push( position.x, position.y, position.z );
476
- quaternionData.push( quaternion.x, quaternion.y, quaternion.z, quaternion.w );
477
- scaleData.push( scale.x, scale.y, scale.z );
478
-
479
- }
480
-
481
- if ( positionData.length > 0 ) tracks.push( new THREE.VectorKeyframeTrack( name + '.position', times, positionData ) );
482
- if ( quaternionData.length > 0 ) tracks.push( new THREE.QuaternionKeyframeTrack( name + '.quaternion', times, quaternionData ) );
483
- if ( scaleData.length > 0 ) tracks.push( new THREE.VectorKeyframeTrack( name + '.scale', times, scaleData ) );
484
- return tracks;
485
-
486
- }
487
-
488
- function transformAnimationData( keyframes, property, defaultValue ) {
489
-
490
- let keyframe;
491
- let empty = true;
492
- let i, l;
493
-
494
- // check, if values of a property are missing in our keyframes
495
-
496
- for ( i = 0, l = keyframes.length; i < l; i ++ ) {
497
-
498
- keyframe = keyframes[ i ];
499
- if ( keyframe.value[ property ] === undefined ) {
500
-
501
- keyframe.value[ property ] = null; // mark as missing
502
-
503
- } else {
504
-
505
- empty = false;
506
-
507
- }
508
-
509
- }
510
-
511
- if ( empty === true ) {
512
-
513
- // no values at all, so we set a default value
514
-
515
- for ( i = 0, l = keyframes.length; i < l; i ++ ) {
516
-
517
- keyframe = keyframes[ i ];
518
- keyframe.value[ property ] = defaultValue;
519
-
520
- }
521
-
522
- } else {
523
-
524
- // filling gaps
525
-
526
- createMissingKeyframes( keyframes, property );
527
-
528
- }
529
-
530
- }
531
-
532
- function createMissingKeyframes( keyframes, property ) {
533
-
534
- let prev, next;
535
- for ( let i = 0, l = keyframes.length; i < l; i ++ ) {
536
-
537
- const keyframe = keyframes[ i ];
538
- if ( keyframe.value[ property ] === null ) {
539
-
540
- prev = getPrev( keyframes, i, property );
541
- next = getNext( keyframes, i, property );
542
- if ( prev === null ) {
543
-
544
- keyframe.value[ property ] = next.value[ property ];
545
- continue;
546
-
547
- }
548
-
549
- if ( next === null ) {
550
-
551
- keyframe.value[ property ] = prev.value[ property ];
552
- continue;
553
-
554
- }
555
-
556
- interpolate( keyframe, prev, next, property );
557
-
558
- }
559
-
560
- }
561
-
562
- }
563
-
564
- function getPrev( keyframes, i, property ) {
565
-
566
- while ( i >= 0 ) {
567
-
568
- const keyframe = keyframes[ i ];
569
- if ( keyframe.value[ property ] !== null ) return keyframe;
570
- i --;
571
-
572
- }
573
-
574
- return null;
575
-
576
- }
577
-
578
- function getNext( keyframes, i, property ) {
579
-
580
- while ( i < keyframes.length ) {
581
-
582
- const keyframe = keyframes[ i ];
583
- if ( keyframe.value[ property ] !== null ) return keyframe;
584
- i ++;
585
-
586
- }
587
-
588
- return null;
589
-
590
- }
591
-
592
- function interpolate( key, prev, next, property ) {
593
-
594
- if ( next.time - prev.time === 0 ) {
595
-
596
- key.value[ property ] = prev.value[ property ];
597
- return;
598
-
599
- }
600
-
601
- key.value[ property ] = ( key.time - prev.time ) * ( next.value[ property ] - prev.value[ property ] ) / ( next.time - prev.time ) + prev.value[ property ];
602
-
603
- }
604
-
605
- // animation clips
606
-
607
- function parseAnimationClip( xml ) {
608
-
609
- const data = {
610
- name: xml.getAttribute( 'id' ) || 'default',
611
- start: parseFloat( xml.getAttribute( 'start' ) || 0 ),
612
- end: parseFloat( xml.getAttribute( 'end' ) || 0 ),
613
- animations: []
614
- };
615
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
616
-
617
- const child = xml.childNodes[ i ];
618
- if ( child.nodeType !== 1 ) continue;
619
- switch ( child.nodeName ) {
620
-
621
- case 'instance_animation':
622
- data.animations.push( parseId( child.getAttribute( 'url' ) ) );
623
- break;
624
-
625
- }
626
-
627
- }
628
-
629
- library.clips[ xml.getAttribute( 'id' ) ] = data;
630
-
631
- }
632
-
633
- function buildAnimationClip( data ) {
634
-
635
- const tracks = [];
636
- const name = data.name;
637
- const duration = data.end - data.start || - 1;
638
- const animations = data.animations;
639
- for ( let i = 0, il = animations.length; i < il; i ++ ) {
640
-
641
- const animationTracks = getAnimation( animations[ i ] );
642
- for ( let j = 0, jl = animationTracks.length; j < jl; j ++ ) {
643
-
644
- tracks.push( animationTracks[ j ] );
645
-
646
- }
647
-
648
- }
649
-
650
- return new THREE.AnimationClip( name, duration, tracks );
651
-
652
- }
653
-
654
- function getAnimationClip( id ) {
655
-
656
- return getBuild( library.clips[ id ], buildAnimationClip );
657
-
658
- }
659
-
660
- // controller
661
-
662
- function parseController( xml ) {
663
-
664
- const data = {};
665
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
666
-
667
- const child = xml.childNodes[ i ];
668
- if ( child.nodeType !== 1 ) continue;
669
- switch ( child.nodeName ) {
670
-
671
- case 'skin':
672
- // there is exactly one skin per controller
673
- data.id = parseId( child.getAttribute( 'source' ) );
674
- data.skin = parseSkin( child );
675
- break;
676
- case 'morph':
677
- data.id = parseId( child.getAttribute( 'source' ) );
678
- console.warn( 'THREE.ColladaLoader: Morph target animation not supported yet.' );
679
- break;
680
-
681
- }
682
-
683
- }
684
-
685
- library.controllers[ xml.getAttribute( 'id' ) ] = data;
686
-
687
- }
688
-
689
- function parseSkin( xml ) {
690
-
691
- const data = {
692
- sources: {}
693
- };
694
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
695
-
696
- const child = xml.childNodes[ i ];
697
- if ( child.nodeType !== 1 ) continue;
698
- switch ( child.nodeName ) {
699
-
700
- case 'bind_shape_matrix':
701
- data.bindShapeMatrix = parseFloats( child.textContent );
702
- break;
703
- case 'source':
704
- const id = child.getAttribute( 'id' );
705
- data.sources[ id ] = parseSource( child );
706
- break;
707
- case 'joints':
708
- data.joints = parseJoints( child );
709
- break;
710
- case 'vertex_weights':
711
- data.vertexWeights = parseVertexWeights( child );
712
- break;
713
-
714
- }
715
-
716
- }
717
-
718
- return data;
719
-
720
- }
721
-
722
- function parseJoints( xml ) {
723
-
724
- const data = {
725
- inputs: {}
726
- };
727
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
728
-
729
- const child = xml.childNodes[ i ];
730
- if ( child.nodeType !== 1 ) continue;
731
- switch ( child.nodeName ) {
732
-
733
- case 'input':
734
- const semantic = child.getAttribute( 'semantic' );
735
- const id = parseId( child.getAttribute( 'source' ) );
736
- data.inputs[ semantic ] = id;
737
- break;
738
-
739
- }
740
-
741
- }
742
-
743
- return data;
744
-
745
- }
746
-
747
- function parseVertexWeights( xml ) {
748
-
749
- const data = {
750
- inputs: {}
751
- };
752
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
753
-
754
- const child = xml.childNodes[ i ];
755
- if ( child.nodeType !== 1 ) continue;
756
- switch ( child.nodeName ) {
757
-
758
- case 'input':
759
- const semantic = child.getAttribute( 'semantic' );
760
- const id = parseId( child.getAttribute( 'source' ) );
761
- const offset = parseInt( child.getAttribute( 'offset' ) );
762
- data.inputs[ semantic ] = {
763
- id: id,
764
- offset: offset
765
- };
766
- break;
767
- case 'vcount':
768
- data.vcount = parseInts( child.textContent );
769
- break;
770
- case 'v':
771
- data.v = parseInts( child.textContent );
772
- break;
773
-
774
- }
775
-
776
- }
777
-
778
- return data;
779
-
780
- }
781
-
782
- function buildController( data ) {
783
-
784
- const build = {
785
- id: data.id
786
- };
787
- const geometry = library.geometries[ build.id ];
788
- if ( data.skin !== undefined ) {
789
-
790
- build.skin = buildSkin( data.skin );
791
-
792
- // we enhance the 'sources' property of the corresponding geometry with our skin data
793
-
794
- geometry.sources.skinIndices = build.skin.indices;
795
- geometry.sources.skinWeights = build.skin.weights;
796
-
797
- }
798
-
799
- return build;
800
-
801
- }
802
-
803
- function buildSkin( data ) {
804
-
805
- const BONE_LIMIT = 4;
806
- const build = {
807
- joints: [],
808
- // this must be an array to preserve the joint order
809
- indices: {
810
- array: [],
811
- stride: BONE_LIMIT
812
- },
813
- weights: {
814
- array: [],
815
- stride: BONE_LIMIT
816
- }
817
- };
818
- const sources = data.sources;
819
- const vertexWeights = data.vertexWeights;
820
- const vcount = vertexWeights.vcount;
821
- const v = vertexWeights.v;
822
- const jointOffset = vertexWeights.inputs.JOINT.offset;
823
- const weightOffset = vertexWeights.inputs.WEIGHT.offset;
824
- const jointSource = data.sources[ data.joints.inputs.JOINT ];
825
- const inverseSource = data.sources[ data.joints.inputs.INV_BIND_MATRIX ];
826
- const weights = sources[ vertexWeights.inputs.WEIGHT.id ].array;
827
- let stride = 0;
828
- let i, j, l;
829
-
830
- // procces skin data for each vertex
831
-
832
- for ( i = 0, l = vcount.length; i < l; i ++ ) {
833
-
834
- const jointCount = vcount[ i ]; // this is the amount of joints that affect a single vertex
835
- const vertexSkinData = [];
836
- for ( j = 0; j < jointCount; j ++ ) {
837
-
838
- const skinIndex = v[ stride + jointOffset ];
839
- const weightId = v[ stride + weightOffset ];
840
- const skinWeight = weights[ weightId ];
841
- vertexSkinData.push( {
842
- index: skinIndex,
843
- weight: skinWeight
844
- } );
845
- stride += 2;
846
-
847
- }
848
-
849
- // we sort the joints in descending order based on the weights.
850
- // this ensures, we only procced the most important joints of the vertex
851
-
852
- vertexSkinData.sort( descending );
853
-
854
- // now we provide for each vertex a set of four index and weight values.
855
- // the order of the skin data matches the order of vertices
856
-
857
- for ( j = 0; j < BONE_LIMIT; j ++ ) {
858
-
859
- const d = vertexSkinData[ j ];
860
- if ( d !== undefined ) {
861
-
862
- build.indices.array.push( d.index );
863
- build.weights.array.push( d.weight );
864
-
865
- } else {
866
-
867
- build.indices.array.push( 0 );
868
- build.weights.array.push( 0 );
869
-
870
- }
871
-
872
- }
873
-
874
- }
875
-
876
- // setup bind matrix
877
-
878
- if ( data.bindShapeMatrix ) {
879
-
880
- build.bindMatrix = new THREE.Matrix4().fromArray( data.bindShapeMatrix ).transpose();
881
-
882
- } else {
883
-
884
- build.bindMatrix = new THREE.Matrix4().identity();
885
-
886
- }
887
-
888
- // process bones and inverse bind matrix data
889
-
890
- for ( i = 0, l = jointSource.array.length; i < l; i ++ ) {
891
-
892
- const name = jointSource.array[ i ];
893
- const boneInverse = new THREE.Matrix4().fromArray( inverseSource.array, i * inverseSource.stride ).transpose();
894
- build.joints.push( {
895
- name: name,
896
- boneInverse: boneInverse
897
- } );
898
-
899
- }
900
-
901
- return build;
902
-
903
- // array sort function
904
-
905
- function descending( a, b ) {
906
-
907
- return b.weight - a.weight;
908
-
909
- }
910
-
911
- }
912
-
913
- function getController( id ) {
914
-
915
- return getBuild( library.controllers[ id ], buildController );
916
-
917
- }
918
-
919
- // image
920
-
921
- function parseImage( xml ) {
922
-
923
- const data = {
924
- init_from: getElementsByTagName( xml, 'init_from' )[ 0 ].textContent
925
- };
926
- library.images[ xml.getAttribute( 'id' ) ] = data;
927
-
928
- }
929
-
930
- function buildImage( data ) {
931
-
932
- if ( data.build !== undefined ) return data.build;
933
- return data.init_from;
934
-
935
- }
936
-
937
- function getImage( id ) {
938
-
939
- const data = library.images[ id ];
940
- if ( data !== undefined ) {
941
-
942
- return getBuild( data, buildImage );
943
-
944
- }
945
-
946
- console.warn( 'THREE.ColladaLoader: Couldn\'t find image with ID:', id );
947
- return null;
948
-
949
- }
950
-
951
- // effect
952
-
953
- function parseEffect( xml ) {
954
-
955
- const data = {};
956
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
957
-
958
- const child = xml.childNodes[ i ];
959
- if ( child.nodeType !== 1 ) continue;
960
- switch ( child.nodeName ) {
961
-
962
- case 'profile_COMMON':
963
- data.profile = parseEffectProfileCOMMON( child );
964
- break;
965
-
966
- }
967
-
968
- }
969
-
970
- library.effects[ xml.getAttribute( 'id' ) ] = data;
971
-
972
- }
973
-
974
- function parseEffectProfileCOMMON( xml ) {
975
-
976
- const data = {
977
- surfaces: {},
978
- samplers: {}
979
- };
980
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
981
-
982
- const child = xml.childNodes[ i ];
983
- if ( child.nodeType !== 1 ) continue;
984
- switch ( child.nodeName ) {
985
-
986
- case 'newparam':
987
- parseEffectNewparam( child, data );
988
- break;
989
- case 'technique':
990
- data.technique = parseEffectTechnique( child );
991
- break;
992
- case 'extra':
993
- data.extra = parseEffectExtra( child );
994
- break;
995
-
996
- }
997
-
998
- }
999
-
1000
- return data;
1001
-
1002
- }
1003
-
1004
- function parseEffectNewparam( xml, data ) {
1005
-
1006
- const sid = xml.getAttribute( 'sid' );
1007
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1008
-
1009
- const child = xml.childNodes[ i ];
1010
- if ( child.nodeType !== 1 ) continue;
1011
- switch ( child.nodeName ) {
1012
-
1013
- case 'surface':
1014
- data.surfaces[ sid ] = parseEffectSurface( child );
1015
- break;
1016
- case 'sampler2D':
1017
- data.samplers[ sid ] = parseEffectSampler( child );
1018
- break;
1019
-
1020
- }
1021
-
1022
- }
1023
-
1024
- }
1025
-
1026
- function parseEffectSurface( xml ) {
1027
-
1028
- const data = {};
1029
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1030
-
1031
- const child = xml.childNodes[ i ];
1032
- if ( child.nodeType !== 1 ) continue;
1033
- switch ( child.nodeName ) {
1034
-
1035
- case 'init_from':
1036
- data.init_from = child.textContent;
1037
- break;
1038
-
1039
- }
1040
-
1041
- }
1042
-
1043
- return data;
1044
-
1045
- }
1046
-
1047
- function parseEffectSampler( xml ) {
1048
-
1049
- const data = {};
1050
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1051
-
1052
- const child = xml.childNodes[ i ];
1053
- if ( child.nodeType !== 1 ) continue;
1054
- switch ( child.nodeName ) {
1055
-
1056
- case 'source':
1057
- data.source = child.textContent;
1058
- break;
1059
-
1060
- }
1061
-
1062
- }
1063
-
1064
- return data;
1065
-
1066
- }
1067
-
1068
- function parseEffectTechnique( xml ) {
1069
-
1070
- const data = {};
1071
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1072
-
1073
- const child = xml.childNodes[ i ];
1074
- if ( child.nodeType !== 1 ) continue;
1075
- switch ( child.nodeName ) {
1076
-
1077
- case 'constant':
1078
- case 'lambert':
1079
- case 'blinn':
1080
- case 'phong':
1081
- data.type = child.nodeName;
1082
- data.parameters = parseEffectParameters( child );
1083
- break;
1084
- case 'extra':
1085
- data.extra = parseEffectExtra( child );
1086
- break;
1087
-
1088
- }
1089
-
1090
- }
1091
-
1092
- return data;
1093
-
1094
- }
1095
-
1096
- function parseEffectParameters( xml ) {
1097
-
1098
- const data = {};
1099
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1100
-
1101
- const child = xml.childNodes[ i ];
1102
- if ( child.nodeType !== 1 ) continue;
1103
- switch ( child.nodeName ) {
1104
-
1105
- case 'emission':
1106
- case 'diffuse':
1107
- case 'specular':
1108
- case 'bump':
1109
- case 'ambient':
1110
- case 'shininess':
1111
- case 'transparency':
1112
- data[ child.nodeName ] = parseEffectParameter( child );
1113
- break;
1114
- case 'transparent':
1115
- data[ child.nodeName ] = {
1116
- opaque: child.hasAttribute( 'opaque' ) ? child.getAttribute( 'opaque' ) : 'A_ONE',
1117
- data: parseEffectParameter( child )
1118
- };
1119
- break;
1120
-
1121
- }
1122
-
1123
- }
1124
-
1125
- return data;
1126
-
1127
- }
1128
-
1129
- function parseEffectParameter( xml ) {
1130
-
1131
- const data = {};
1132
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1133
-
1134
- const child = xml.childNodes[ i ];
1135
- if ( child.nodeType !== 1 ) continue;
1136
- switch ( child.nodeName ) {
1137
-
1138
- case 'color':
1139
- data[ child.nodeName ] = parseFloats( child.textContent );
1140
- break;
1141
- case 'float':
1142
- data[ child.nodeName ] = parseFloat( child.textContent );
1143
- break;
1144
- case 'texture':
1145
- data[ child.nodeName ] = {
1146
- id: child.getAttribute( 'texture' ),
1147
- extra: parseEffectParameterTexture( child )
1148
- };
1149
- break;
1150
-
1151
- }
1152
-
1153
- }
1154
-
1155
- return data;
1156
-
1157
- }
1158
-
1159
- function parseEffectParameterTexture( xml ) {
1160
-
1161
- const data = {
1162
- technique: {}
1163
- };
1164
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1165
-
1166
- const child = xml.childNodes[ i ];
1167
- if ( child.nodeType !== 1 ) continue;
1168
- switch ( child.nodeName ) {
1169
-
1170
- case 'extra':
1171
- parseEffectParameterTextureExtra( child, data );
1172
- break;
1173
-
1174
- }
1175
-
1176
- }
1177
-
1178
- return data;
1179
-
1180
- }
1181
-
1182
- function parseEffectParameterTextureExtra( xml, data ) {
1183
-
1184
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1185
-
1186
- const child = xml.childNodes[ i ];
1187
- if ( child.nodeType !== 1 ) continue;
1188
- switch ( child.nodeName ) {
1189
-
1190
- case 'technique':
1191
- parseEffectParameterTextureExtraTechnique( child, data );
1192
- break;
1193
-
1194
- }
1195
-
1196
- }
1197
-
1198
- }
1199
-
1200
- function parseEffectParameterTextureExtraTechnique( xml, data ) {
1201
-
1202
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1203
-
1204
- const child = xml.childNodes[ i ];
1205
- if ( child.nodeType !== 1 ) continue;
1206
- switch ( child.nodeName ) {
1207
-
1208
- case 'repeatU':
1209
- case 'repeatV':
1210
- case 'offsetU':
1211
- case 'offsetV':
1212
- data.technique[ child.nodeName ] = parseFloat( child.textContent );
1213
- break;
1214
- case 'wrapU':
1215
- case 'wrapV':
1216
- // some files have values for wrapU/wrapV which become NaN via parseInt
1217
-
1218
- if ( child.textContent.toUpperCase() === 'TRUE' ) {
1219
-
1220
- data.technique[ child.nodeName ] = 1;
1221
-
1222
- } else if ( child.textContent.toUpperCase() === 'FALSE' ) {
1223
-
1224
- data.technique[ child.nodeName ] = 0;
1225
-
1226
- } else {
1227
-
1228
- data.technique[ child.nodeName ] = parseInt( child.textContent );
1229
-
1230
- }
1231
-
1232
- break;
1233
- case 'bump':
1234
- data[ child.nodeName ] = parseEffectExtraTechniqueBump( child );
1235
- break;
1236
-
1237
- }
1238
-
1239
- }
1240
-
1241
- }
1242
-
1243
- function parseEffectExtra( xml ) {
1244
-
1245
- const data = {};
1246
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1247
-
1248
- const child = xml.childNodes[ i ];
1249
- if ( child.nodeType !== 1 ) continue;
1250
- switch ( child.nodeName ) {
1251
-
1252
- case 'technique':
1253
- data.technique = parseEffectExtraTechnique( child );
1254
- break;
1255
-
1256
- }
1257
-
1258
- }
1259
-
1260
- return data;
1261
-
1262
- }
1263
-
1264
- function parseEffectExtraTechnique( xml ) {
1265
-
1266
- const data = {};
1267
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1268
-
1269
- const child = xml.childNodes[ i ];
1270
- if ( child.nodeType !== 1 ) continue;
1271
- switch ( child.nodeName ) {
1272
-
1273
- case 'double_sided':
1274
- data[ child.nodeName ] = parseInt( child.textContent );
1275
- break;
1276
- case 'bump':
1277
- data[ child.nodeName ] = parseEffectExtraTechniqueBump( child );
1278
- break;
1279
-
1280
- }
1281
-
1282
- }
1283
-
1284
- return data;
1285
-
1286
- }
1287
-
1288
- function parseEffectExtraTechniqueBump( xml ) {
1289
-
1290
- const data = {};
1291
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1292
-
1293
- const child = xml.childNodes[ i ];
1294
- if ( child.nodeType !== 1 ) continue;
1295
- switch ( child.nodeName ) {
1296
-
1297
- case 'texture':
1298
- data[ child.nodeName ] = {
1299
- id: child.getAttribute( 'texture' ),
1300
- texcoord: child.getAttribute( 'texcoord' ),
1301
- extra: parseEffectParameterTexture( child )
1302
- };
1303
- break;
1304
-
1305
- }
1306
-
1307
- }
1308
-
1309
- return data;
1310
-
1311
- }
1312
-
1313
- function buildEffect( data ) {
1314
-
1315
- return data;
1316
-
1317
- }
1318
-
1319
- function getEffect( id ) {
1320
-
1321
- return getBuild( library.effects[ id ], buildEffect );
1322
-
1323
- }
1324
-
1325
- // material
1326
-
1327
- function parseMaterial( xml ) {
1328
-
1329
- const data = {
1330
- name: xml.getAttribute( 'name' )
1331
- };
1332
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1333
-
1334
- const child = xml.childNodes[ i ];
1335
- if ( child.nodeType !== 1 ) continue;
1336
- switch ( child.nodeName ) {
1337
-
1338
- case 'instance_effect':
1339
- data.url = parseId( child.getAttribute( 'url' ) );
1340
- break;
1341
-
1342
- }
1343
-
1344
- }
1345
-
1346
- library.materials[ xml.getAttribute( 'id' ) ] = data;
1347
-
1348
- }
1349
-
1350
- function getTextureLoader( image ) {
1351
-
1352
- let loader;
1353
- let extension = image.slice( ( image.lastIndexOf( '.' ) - 1 >>> 0 ) + 2 ); // http://www.jstips.co/en/javascript/get-file-extension/
1354
- extension = extension.toLowerCase();
1355
- switch ( extension ) {
1356
-
1357
- case 'tga':
1358
- loader = tgaLoader;
1359
- break;
1360
- default:
1361
- loader = textureLoader;
1362
-
1363
- }
1364
-
1365
- return loader;
1366
-
1367
- }
1368
-
1369
- function buildMaterial( data ) {
1370
-
1371
- const effect = getEffect( data.url );
1372
- const technique = effect.profile.technique;
1373
- let material;
1374
- switch ( technique.type ) {
1375
-
1376
- case 'phong':
1377
- case 'blinn':
1378
- material = new THREE.MeshPhongMaterial();
1379
- break;
1380
- case 'lambert':
1381
- material = new THREE.MeshLambertMaterial();
1382
- break;
1383
- default:
1384
- material = new THREE.MeshBasicMaterial();
1385
- break;
1386
-
1387
- }
1388
-
1389
- material.name = data.name || '';
1390
- function getTexture( textureObject, encoding = null ) {
1391
-
1392
- const sampler = effect.profile.samplers[ textureObject.id ];
1393
- let image = null;
1394
-
1395
- // get image
1396
-
1397
- if ( sampler !== undefined ) {
1398
-
1399
- const surface = effect.profile.surfaces[ sampler.source ];
1400
- image = getImage( surface.init_from );
1401
-
1402
- } else {
1403
-
1404
- console.warn( 'THREE.ColladaLoader: Undefined sampler. Access image directly (see #12530).' );
1405
- image = getImage( textureObject.id );
1406
-
1407
- }
1408
-
1409
- // create texture if image is avaiable
1410
-
1411
- if ( image !== null ) {
1412
-
1413
- const loader = getTextureLoader( image );
1414
- if ( loader !== undefined ) {
1415
-
1416
- const texture = loader.load( image );
1417
- const extra = textureObject.extra;
1418
- if ( extra !== undefined && extra.technique !== undefined && isEmpty( extra.technique ) === false ) {
1419
-
1420
- const technique = extra.technique;
1421
- texture.wrapS = technique.wrapU ? THREE.RepeatWrapping : THREE.ClampToEdgeWrapping;
1422
- texture.wrapT = technique.wrapV ? THREE.RepeatWrapping : THREE.ClampToEdgeWrapping;
1423
- texture.offset.set( technique.offsetU || 0, technique.offsetV || 0 );
1424
- texture.repeat.set( technique.repeatU || 1, technique.repeatV || 1 );
1425
-
1426
- } else {
1427
-
1428
- texture.wrapS = THREE.RepeatWrapping;
1429
- texture.wrapT = THREE.RepeatWrapping;
1430
-
1431
- }
1432
-
1433
- if ( encoding !== null ) {
1434
-
1435
- texture.encoding = encoding;
1436
-
1437
- }
1438
-
1439
- return texture;
1440
-
1441
- } else {
1442
-
1443
- console.warn( 'THREE.ColladaLoader: THREE.Loader for texture %s not found.', image );
1444
- return null;
1445
-
1446
- }
1447
-
1448
- } else {
1449
-
1450
- console.warn( 'THREE.ColladaLoader: Couldn\'t create texture with ID:', textureObject.id );
1451
- return null;
1452
-
1453
- }
1454
-
1455
- }
1456
-
1457
- const parameters = technique.parameters;
1458
- for ( const key in parameters ) {
1459
-
1460
- const parameter = parameters[ key ];
1461
- switch ( key ) {
1462
-
1463
- case 'diffuse':
1464
- if ( parameter.color ) material.color.fromArray( parameter.color );
1465
- if ( parameter.texture ) material.map = getTexture( parameter.texture, THREE.sRGBEncoding );
1466
- break;
1467
- case 'specular':
1468
- if ( parameter.color && material.specular ) material.specular.fromArray( parameter.color );
1469
- if ( parameter.texture ) material.specularMap = getTexture( parameter.texture );
1470
- break;
1471
- case 'bump':
1472
- if ( parameter.texture ) material.normalMap = getTexture( parameter.texture );
1473
- break;
1474
- case 'ambient':
1475
- if ( parameter.texture ) material.lightMap = getTexture( parameter.texture, THREE.sRGBEncoding );
1476
- break;
1477
- case 'shininess':
1478
- if ( parameter.float && material.shininess ) material.shininess = parameter.float;
1479
- break;
1480
- case 'emission':
1481
- if ( parameter.color && material.emissive ) material.emissive.fromArray( parameter.color );
1482
- if ( parameter.texture ) material.emissiveMap = getTexture( parameter.texture, THREE.sRGBEncoding );
1483
- break;
1484
-
1485
- }
1486
-
1487
- }
1488
-
1489
- material.color.convertSRGBToLinear();
1490
- if ( material.specular ) material.specular.convertSRGBToLinear();
1491
- if ( material.emissive ) material.emissive.convertSRGBToLinear();
1492
-
1493
- //
1494
-
1495
- let transparent = parameters[ 'transparent' ];
1496
- let transparency = parameters[ 'transparency' ];
1497
-
1498
- // <transparency> does not exist but <transparent>
1499
-
1500
- if ( transparency === undefined && transparent ) {
1501
-
1502
- transparency = {
1503
- float: 1
1504
- };
1505
-
1506
- }
1507
-
1508
- // <transparent> does not exist but <transparency>
1509
-
1510
- if ( transparent === undefined && transparency ) {
1511
-
1512
- transparent = {
1513
- opaque: 'A_ONE',
1514
- data: {
1515
- color: [ 1, 1, 1, 1 ]
1516
- }
1517
- };
1518
-
1519
- }
1520
-
1521
- if ( transparent && transparency ) {
1522
-
1523
- // handle case if a texture exists but no color
1524
-
1525
- if ( transparent.data.texture ) {
1526
-
1527
- // we do not set an alpha map (see #13792)
1528
-
1529
- material.transparent = true;
1530
-
1531
- } else {
1532
-
1533
- const color = transparent.data.color;
1534
- switch ( transparent.opaque ) {
1535
-
1536
- case 'A_ONE':
1537
- material.opacity = color[ 3 ] * transparency.float;
1538
- break;
1539
- case 'RGB_ZERO':
1540
- material.opacity = 1 - color[ 0 ] * transparency.float;
1541
- break;
1542
- case 'A_ZERO':
1543
- material.opacity = 1 - color[ 3 ] * transparency.float;
1544
- break;
1545
- case 'RGB_ONE':
1546
- material.opacity = color[ 0 ] * transparency.float;
1547
- break;
1548
- default:
1549
- console.warn( 'THREE.ColladaLoader: Invalid opaque type "%s" of transparent tag.', transparent.opaque );
1550
-
1551
- }
1552
-
1553
- if ( material.opacity < 1 ) material.transparent = true;
1554
-
1555
- }
1556
-
1557
- }
1558
-
1559
- //
1560
-
1561
- if ( technique.extra !== undefined && technique.extra.technique !== undefined ) {
1562
-
1563
- const techniques = technique.extra.technique;
1564
- for ( const k in techniques ) {
1565
-
1566
- const v = techniques[ k ];
1567
- switch ( k ) {
1568
-
1569
- case 'double_sided':
1570
- material.side = v === 1 ? THREE.DoubleSide : THREE.FrontSide;
1571
- break;
1572
- case 'bump':
1573
- material.normalMap = getTexture( v.texture );
1574
- material.normalScale = new THREE.Vector2( 1, 1 );
1575
- break;
1576
-
1577
- }
1578
-
1579
- }
1580
-
1581
- }
1582
-
1583
- return material;
1584
-
1585
- }
1586
-
1587
- function getMaterial( id ) {
1588
-
1589
- return getBuild( library.materials[ id ], buildMaterial );
1590
-
1591
- }
1592
-
1593
- // camera
1594
-
1595
- function parseCamera( xml ) {
1596
-
1597
- const data = {
1598
- name: xml.getAttribute( 'name' )
1599
- };
1600
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1601
-
1602
- const child = xml.childNodes[ i ];
1603
- if ( child.nodeType !== 1 ) continue;
1604
- switch ( child.nodeName ) {
1605
-
1606
- case 'optics':
1607
- data.optics = parseCameraOptics( child );
1608
- break;
1609
-
1610
- }
1611
-
1612
- }
1613
-
1614
- library.cameras[ xml.getAttribute( 'id' ) ] = data;
1615
-
1616
- }
1617
-
1618
- function parseCameraOptics( xml ) {
1619
-
1620
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
1621
-
1622
- const child = xml.childNodes[ i ];
1623
- switch ( child.nodeName ) {
1624
-
1625
- case 'technique_common':
1626
- return parseCameraTechnique( child );
1627
-
1628
- }
1629
-
1630
- }
1631
-
1632
- return {};
1633
-
1634
- }
1635
-
1636
- function parseCameraTechnique( xml ) {
1637
-
1638
- const data = {};
1639
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
1640
-
1641
- const child = xml.childNodes[ i ];
1642
- switch ( child.nodeName ) {
1643
-
1644
- case 'perspective':
1645
- case 'orthographic':
1646
- data.technique = child.nodeName;
1647
- data.parameters = parseCameraParameters( child );
1648
- break;
1649
-
1650
- }
1651
-
1652
- }
1653
-
1654
- return data;
1655
-
1656
- }
1657
-
1658
- function parseCameraParameters( xml ) {
1659
-
1660
- const data = {};
1661
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
1662
-
1663
- const child = xml.childNodes[ i ];
1664
- switch ( child.nodeName ) {
1665
-
1666
- case 'xfov':
1667
- case 'yfov':
1668
- case 'xmag':
1669
- case 'ymag':
1670
- case 'znear':
1671
- case 'zfar':
1672
- case 'aspect_ratio':
1673
- data[ child.nodeName ] = parseFloat( child.textContent );
1674
- break;
1675
-
1676
- }
1677
-
1678
- }
1679
-
1680
- return data;
1681
-
1682
- }
1683
-
1684
- function buildCamera( data ) {
1685
-
1686
- let camera;
1687
- switch ( data.optics.technique ) {
1688
-
1689
- case 'perspective':
1690
- camera = new THREE.PerspectiveCamera( data.optics.parameters.yfov, data.optics.parameters.aspect_ratio, data.optics.parameters.znear, data.optics.parameters.zfar );
1691
- break;
1692
- case 'orthographic':
1693
- let ymag = data.optics.parameters.ymag;
1694
- let xmag = data.optics.parameters.xmag;
1695
- const aspectRatio = data.optics.parameters.aspect_ratio;
1696
- xmag = xmag === undefined ? ymag * aspectRatio : xmag;
1697
- ymag = ymag === undefined ? xmag / aspectRatio : ymag;
1698
- xmag *= 0.5;
1699
- ymag *= 0.5;
1700
- camera = new THREE.OrthographicCamera( - xmag, xmag, ymag, - ymag,
1701
- // left, right, top, bottom
1702
- data.optics.parameters.znear, data.optics.parameters.zfar );
1703
- break;
1704
- default:
1705
- camera = new THREE.PerspectiveCamera();
1706
- break;
1707
-
1708
- }
1709
-
1710
- camera.name = data.name || '';
1711
- return camera;
1712
-
1713
- }
1714
-
1715
- function getCamera( id ) {
1716
-
1717
- const data = library.cameras[ id ];
1718
- if ( data !== undefined ) {
1719
-
1720
- return getBuild( data, buildCamera );
1721
-
1722
- }
1723
-
1724
- console.warn( 'THREE.ColladaLoader: Couldn\'t find camera with ID:', id );
1725
- return null;
1726
-
1727
- }
1728
-
1729
- // light
1730
-
1731
- function parseLight( xml ) {
1732
-
1733
- let data = {};
1734
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1735
-
1736
- const child = xml.childNodes[ i ];
1737
- if ( child.nodeType !== 1 ) continue;
1738
- switch ( child.nodeName ) {
1739
-
1740
- case 'technique_common':
1741
- data = parseLightTechnique( child );
1742
- break;
1743
-
1744
- }
1745
-
1746
- }
1747
-
1748
- library.lights[ xml.getAttribute( 'id' ) ] = data;
1749
-
1750
- }
1751
-
1752
- function parseLightTechnique( xml ) {
1753
-
1754
- const data = {};
1755
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1756
-
1757
- const child = xml.childNodes[ i ];
1758
- if ( child.nodeType !== 1 ) continue;
1759
- switch ( child.nodeName ) {
1760
-
1761
- case 'directional':
1762
- case 'point':
1763
- case 'spot':
1764
- case 'ambient':
1765
- data.technique = child.nodeName;
1766
- data.parameters = parseLightParameters( child );
1767
-
1768
- }
1769
-
1770
- }
1771
-
1772
- return data;
1773
-
1774
- }
1775
-
1776
- function parseLightParameters( xml ) {
1777
-
1778
- const data = {};
1779
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1780
-
1781
- const child = xml.childNodes[ i ];
1782
- if ( child.nodeType !== 1 ) continue;
1783
- switch ( child.nodeName ) {
1784
-
1785
- case 'color':
1786
- const array = parseFloats( child.textContent );
1787
- data.color = new THREE.Color().fromArray( array ).convertSRGBToLinear();
1788
- break;
1789
- case 'falloff_angle':
1790
- data.falloffAngle = parseFloat( child.textContent );
1791
- break;
1792
- case 'quadratic_attenuation':
1793
- const f = parseFloat( child.textContent );
1794
- data.distance = f ? Math.sqrt( 1 / f ) : 0;
1795
- break;
1796
-
1797
- }
1798
-
1799
- }
1800
-
1801
- return data;
1802
-
1803
- }
1804
-
1805
- function buildLight( data ) {
1806
-
1807
- let light;
1808
- switch ( data.technique ) {
1809
-
1810
- case 'directional':
1811
- light = new THREE.DirectionalLight();
1812
- break;
1813
- case 'point':
1814
- light = new THREE.PointLight();
1815
- break;
1816
- case 'spot':
1817
- light = new THREE.SpotLight();
1818
- break;
1819
- case 'ambient':
1820
- light = new THREE.AmbientLight();
1821
- break;
1822
-
1823
- }
1824
-
1825
- if ( data.parameters.color ) light.color.copy( data.parameters.color );
1826
- if ( data.parameters.distance ) light.distance = data.parameters.distance;
1827
- return light;
1828
-
1829
- }
1830
-
1831
- function getLight( id ) {
1832
-
1833
- const data = library.lights[ id ];
1834
- if ( data !== undefined ) {
1835
-
1836
- return getBuild( data, buildLight );
1837
-
1838
- }
1839
-
1840
- console.warn( 'THREE.ColladaLoader: Couldn\'t find light with ID:', id );
1841
- return null;
1842
-
1843
- }
1844
-
1845
- // geometry
1846
-
1847
- function parseGeometry( xml ) {
1848
-
1849
- const data = {
1850
- name: xml.getAttribute( 'name' ),
1851
- sources: {},
1852
- vertices: {},
1853
- primitives: []
1854
- };
1855
- const mesh = getElementsByTagName( xml, 'mesh' )[ 0 ];
1856
-
1857
- // the following tags inside geometry are not supported yet (see https://github.com/mrdoob/three.js/pull/12606): convex_mesh, spline, brep
1858
- if ( mesh === undefined ) return;
1859
- for ( let i = 0; i < mesh.childNodes.length; i ++ ) {
1860
-
1861
- const child = mesh.childNodes[ i ];
1862
- if ( child.nodeType !== 1 ) continue;
1863
- const id = child.getAttribute( 'id' );
1864
- switch ( child.nodeName ) {
1865
-
1866
- case 'source':
1867
- data.sources[ id ] = parseSource( child );
1868
- break;
1869
- case 'vertices':
1870
- // data.sources[ id ] = data.sources[ parseId( getElementsByTagName( child, 'input' )[ 0 ].getAttribute( 'source' ) ) ];
1871
- data.vertices = parseGeometryVertices( child );
1872
- break;
1873
- case 'polygons':
1874
- console.warn( 'THREE.ColladaLoader: Unsupported primitive type: ', child.nodeName );
1875
- break;
1876
- case 'lines':
1877
- case 'linestrips':
1878
- case 'polylist':
1879
- case 'triangles':
1880
- data.primitives.push( parseGeometryPrimitive( child ) );
1881
- break;
1882
- default:
1883
- console.log( child );
1884
-
1885
- }
1886
-
1887
- }
1888
-
1889
- library.geometries[ xml.getAttribute( 'id' ) ] = data;
1890
-
1891
- }
1892
-
1893
- function parseSource( xml ) {
1894
-
1895
- const data = {
1896
- array: [],
1897
- stride: 3
1898
- };
1899
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
1900
-
1901
- const child = xml.childNodes[ i ];
1902
- if ( child.nodeType !== 1 ) continue;
1903
- switch ( child.nodeName ) {
1904
-
1905
- case 'float_array':
1906
- data.array = parseFloats( child.textContent );
1907
- break;
1908
- case 'Name_array':
1909
- data.array = parseStrings( child.textContent );
1910
- break;
1911
- case 'technique_common':
1912
- const accessor = getElementsByTagName( child, 'accessor' )[ 0 ];
1913
- if ( accessor !== undefined ) {
1914
-
1915
- data.stride = parseInt( accessor.getAttribute( 'stride' ) );
1916
-
1917
- }
1918
-
1919
- break;
1920
-
1921
- }
1922
-
1923
- }
1924
-
1925
- return data;
1926
-
1927
- }
1928
-
1929
- function parseGeometryVertices( xml ) {
1930
-
1931
- const data = {};
1932
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
1933
-
1934
- const child = xml.childNodes[ i ];
1935
- if ( child.nodeType !== 1 ) continue;
1936
- data[ child.getAttribute( 'semantic' ) ] = parseId( child.getAttribute( 'source' ) );
1937
-
1938
- }
1939
-
1940
- return data;
1941
-
1942
- }
1943
-
1944
- function parseGeometryPrimitive( xml ) {
1945
-
1946
- const primitive = {
1947
- type: xml.nodeName,
1948
- material: xml.getAttribute( 'material' ),
1949
- count: parseInt( xml.getAttribute( 'count' ) ),
1950
- inputs: {},
1951
- stride: 0,
1952
- hasUV: false
1953
- };
1954
- for ( let i = 0, l = xml.childNodes.length; i < l; i ++ ) {
1955
-
1956
- const child = xml.childNodes[ i ];
1957
- if ( child.nodeType !== 1 ) continue;
1958
- switch ( child.nodeName ) {
1959
-
1960
- case 'input':
1961
- const id = parseId( child.getAttribute( 'source' ) );
1962
- const semantic = child.getAttribute( 'semantic' );
1963
- const offset = parseInt( child.getAttribute( 'offset' ) );
1964
- const set = parseInt( child.getAttribute( 'set' ) );
1965
- const inputname = set > 0 ? semantic + set : semantic;
1966
- primitive.inputs[ inputname ] = {
1967
- id: id,
1968
- offset: offset
1969
- };
1970
- primitive.stride = Math.max( primitive.stride, offset + 1 );
1971
- if ( semantic === 'TEXCOORD' ) primitive.hasUV = true;
1972
- break;
1973
- case 'vcount':
1974
- primitive.vcount = parseInts( child.textContent );
1975
- break;
1976
- case 'p':
1977
- primitive.p = parseInts( child.textContent );
1978
- break;
1979
-
1980
- }
1981
-
1982
- }
1983
-
1984
- return primitive;
1985
-
1986
- }
1987
-
1988
- function groupPrimitives( primitives ) {
1989
-
1990
- const build = {};
1991
- for ( let i = 0; i < primitives.length; i ++ ) {
1992
-
1993
- const primitive = primitives[ i ];
1994
- if ( build[ primitive.type ] === undefined ) build[ primitive.type ] = [];
1995
- build[ primitive.type ].push( primitive );
1996
-
1997
- }
1998
-
1999
- return build;
2000
-
2001
- }
2002
-
2003
- function checkUVCoordinates( primitives ) {
2004
-
2005
- let count = 0;
2006
- for ( let i = 0, l = primitives.length; i < l; i ++ ) {
2007
-
2008
- const primitive = primitives[ i ];
2009
- if ( primitive.hasUV === true ) {
2010
-
2011
- count ++;
2012
-
2013
- }
2014
-
2015
- }
2016
-
2017
- if ( count > 0 && count < primitives.length ) {
2018
-
2019
- primitives.uvsNeedsFix = true;
2020
-
2021
- }
2022
-
2023
- }
2024
-
2025
- function buildGeometry( data ) {
2026
-
2027
- const build = {};
2028
- const sources = data.sources;
2029
- const vertices = data.vertices;
2030
- const primitives = data.primitives;
2031
- if ( primitives.length === 0 ) return {};
2032
-
2033
- // our goal is to create one buffer geometry for a single type of primitives
2034
- // first, we group all primitives by their type
2035
-
2036
- const groupedPrimitives = groupPrimitives( primitives );
2037
- for ( const type in groupedPrimitives ) {
2038
-
2039
- const primitiveType = groupedPrimitives[ type ];
2040
-
2041
- // second, ensure consistent uv coordinates for each type of primitives (polylist,triangles or lines)
2042
-
2043
- checkUVCoordinates( primitiveType );
2044
-
2045
- // third, create a buffer geometry for each type of primitives
2046
-
2047
- build[ type ] = buildGeometryType( primitiveType, sources, vertices );
2048
-
2049
- }
2050
-
2051
- return build;
2052
-
2053
- }
2054
-
2055
- function buildGeometryType( primitives, sources, vertices ) {
2056
-
2057
- const build = {};
2058
- const position = {
2059
- array: [],
2060
- stride: 0
2061
- };
2062
- const normal = {
2063
- array: [],
2064
- stride: 0
2065
- };
2066
- const uv = {
2067
- array: [],
2068
- stride: 0
2069
- };
2070
- const uv2 = {
2071
- array: [],
2072
- stride: 0
2073
- };
2074
- const color = {
2075
- array: [],
2076
- stride: 0
2077
- };
2078
- const skinIndex = {
2079
- array: [],
2080
- stride: 4
2081
- };
2082
- const skinWeight = {
2083
- array: [],
2084
- stride: 4
2085
- };
2086
- const geometry = new THREE.BufferGeometry();
2087
- const materialKeys = [];
2088
- let start = 0;
2089
- for ( let p = 0; p < primitives.length; p ++ ) {
2090
-
2091
- const primitive = primitives[ p ];
2092
- const inputs = primitive.inputs;
2093
-
2094
- // groups
2095
-
2096
- let count = 0;
2097
- switch ( primitive.type ) {
2098
-
2099
- case 'lines':
2100
- case 'linestrips':
2101
- count = primitive.count * 2;
2102
- break;
2103
- case 'triangles':
2104
- count = primitive.count * 3;
2105
- break;
2106
- case 'polylist':
2107
- for ( let g = 0; g < primitive.count; g ++ ) {
2108
-
2109
- const vc = primitive.vcount[ g ];
2110
- switch ( vc ) {
2111
-
2112
- case 3:
2113
- count += 3; // single triangle
2114
- break;
2115
- case 4:
2116
- count += 6; // quad, subdivided into two triangles
2117
- break;
2118
- default:
2119
- count += ( vc - 2 ) * 3; // polylist with more than four vertices
2120
- break;
2121
-
2122
- }
2123
-
2124
- }
2125
-
2126
- break;
2127
- default:
2128
- console.warn( 'THREE.ColladaLoader: Unknow primitive type:', primitive.type );
2129
-
2130
- }
2131
-
2132
- geometry.addGroup( start, count, p );
2133
- start += count;
2134
-
2135
- // material
2136
-
2137
- if ( primitive.material ) {
2138
-
2139
- materialKeys.push( primitive.material );
2140
-
2141
- }
2142
-
2143
- // geometry data
2144
-
2145
- for ( const name in inputs ) {
2146
-
2147
- const input = inputs[ name ];
2148
- switch ( name ) {
2149
-
2150
- case 'VERTEX':
2151
- for ( const key in vertices ) {
2152
-
2153
- const id = vertices[ key ];
2154
- switch ( key ) {
2155
-
2156
- case 'POSITION':
2157
- const prevLength = position.array.length;
2158
- buildGeometryData( primitive, sources[ id ], input.offset, position.array );
2159
- position.stride = sources[ id ].stride;
2160
- if ( sources.skinWeights && sources.skinIndices ) {
2161
-
2162
- buildGeometryData( primitive, sources.skinIndices, input.offset, skinIndex.array );
2163
- buildGeometryData( primitive, sources.skinWeights, input.offset, skinWeight.array );
2164
-
2165
- }
2166
-
2167
- // see #3803
2168
-
2169
- if ( primitive.hasUV === false && primitives.uvsNeedsFix === true ) {
2170
-
2171
- const count = ( position.array.length - prevLength ) / position.stride;
2172
- for ( let i = 0; i < count; i ++ ) {
2173
-
2174
- // fill missing uv coordinates
2175
-
2176
- uv.array.push( 0, 0 );
2177
-
2178
- }
2179
-
2180
- }
2181
-
2182
- break;
2183
- case 'NORMAL':
2184
- buildGeometryData( primitive, sources[ id ], input.offset, normal.array );
2185
- normal.stride = sources[ id ].stride;
2186
- break;
2187
- case 'COLOR':
2188
- buildGeometryData( primitive, sources[ id ], input.offset, color.array );
2189
- color.stride = sources[ id ].stride;
2190
- break;
2191
- case 'TEXCOORD':
2192
- buildGeometryData( primitive, sources[ id ], input.offset, uv.array );
2193
- uv.stride = sources[ id ].stride;
2194
- break;
2195
- case 'TEXCOORD1':
2196
- buildGeometryData( primitive, sources[ id ], input.offset, uv2.array );
2197
- uv.stride = sources[ id ].stride;
2198
- break;
2199
- default:
2200
- console.warn( 'THREE.ColladaLoader: Semantic "%s" not handled in geometry build process.', key );
2201
-
2202
- }
2203
-
2204
- }
2205
-
2206
- break;
2207
- case 'NORMAL':
2208
- buildGeometryData( primitive, sources[ input.id ], input.offset, normal.array );
2209
- normal.stride = sources[ input.id ].stride;
2210
- break;
2211
- case 'COLOR':
2212
- buildGeometryData( primitive, sources[ input.id ], input.offset, color.array, true );
2213
- color.stride = sources[ input.id ].stride;
2214
- break;
2215
- case 'TEXCOORD':
2216
- buildGeometryData( primitive, sources[ input.id ], input.offset, uv.array );
2217
- uv.stride = sources[ input.id ].stride;
2218
- break;
2219
- case 'TEXCOORD1':
2220
- buildGeometryData( primitive, sources[ input.id ], input.offset, uv2.array );
2221
- uv2.stride = sources[ input.id ].stride;
2222
- break;
2223
-
2224
- }
2225
-
2226
- }
2227
-
2228
- }
2229
-
2230
- // build geometry
2231
-
2232
- if ( position.array.length > 0 ) geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( position.array, position.stride ) );
2233
- if ( normal.array.length > 0 ) geometry.setAttribute( 'normal', new THREE.Float32BufferAttribute( normal.array, normal.stride ) );
2234
- if ( color.array.length > 0 ) geometry.setAttribute( 'color', new THREE.Float32BufferAttribute( color.array, color.stride ) );
2235
- if ( uv.array.length > 0 ) geometry.setAttribute( 'uv', new THREE.Float32BufferAttribute( uv.array, uv.stride ) );
2236
- if ( uv2.array.length > 0 ) geometry.setAttribute( 'uv2', new THREE.Float32BufferAttribute( uv2.array, uv2.stride ) );
2237
- if ( skinIndex.array.length > 0 ) geometry.setAttribute( 'skinIndex', new THREE.Float32BufferAttribute( skinIndex.array, skinIndex.stride ) );
2238
- if ( skinWeight.array.length > 0 ) geometry.setAttribute( 'skinWeight', new THREE.Float32BufferAttribute( skinWeight.array, skinWeight.stride ) );
2239
- build.data = geometry;
2240
- build.type = primitives[ 0 ].type;
2241
- build.materialKeys = materialKeys;
2242
- return build;
2243
-
2244
- }
2245
-
2246
- function buildGeometryData( primitive, source, offset, array, isColor = false ) {
2247
-
2248
- const indices = primitive.p;
2249
- const stride = primitive.stride;
2250
- const vcount = primitive.vcount;
2251
- function pushVector( i ) {
2252
-
2253
- let index = indices[ i + offset ] * sourceStride;
2254
- const length = index + sourceStride;
2255
- for ( ; index < length; index ++ ) {
2256
-
2257
- array.push( sourceArray[ index ] );
2258
-
2259
- }
2260
-
2261
- if ( isColor ) {
2262
-
2263
- // convert the vertex colors from srgb to linear if present
2264
- const startIndex = array.length - sourceStride - 1;
2265
- tempColor.setRGB( array[ startIndex + 0 ], array[ startIndex + 1 ], array[ startIndex + 2 ] ).convertSRGBToLinear();
2266
- array[ startIndex + 0 ] = tempColor.r;
2267
- array[ startIndex + 1 ] = tempColor.g;
2268
- array[ startIndex + 2 ] = tempColor.b;
2269
-
2270
- }
2271
-
2272
- }
2273
-
2274
- const sourceArray = source.array;
2275
- const sourceStride = source.stride;
2276
- if ( primitive.vcount !== undefined ) {
2277
-
2278
- let index = 0;
2279
- for ( let i = 0, l = vcount.length; i < l; i ++ ) {
2280
-
2281
- const count = vcount[ i ];
2282
- if ( count === 4 ) {
2283
-
2284
- const a = index + stride * 0;
2285
- const b = index + stride * 1;
2286
- const c = index + stride * 2;
2287
- const d = index + stride * 3;
2288
- pushVector( a );
2289
- pushVector( b );
2290
- pushVector( d );
2291
- pushVector( b );
2292
- pushVector( c );
2293
- pushVector( d );
2294
-
2295
- } else if ( count === 3 ) {
2296
-
2297
- const a = index + stride * 0;
2298
- const b = index + stride * 1;
2299
- const c = index + stride * 2;
2300
- pushVector( a );
2301
- pushVector( b );
2302
- pushVector( c );
2303
-
2304
- } else if ( count > 4 ) {
2305
-
2306
- for ( let k = 1, kl = count - 2; k <= kl; k ++ ) {
2307
-
2308
- const a = index + stride * 0;
2309
- const b = index + stride * k;
2310
- const c = index + stride * ( k + 1 );
2311
- pushVector( a );
2312
- pushVector( b );
2313
- pushVector( c );
2314
-
2315
- }
2316
-
2317
- }
2318
-
2319
- index += stride * count;
2320
-
2321
- }
2322
-
2323
- } else {
2324
-
2325
- for ( let i = 0, l = indices.length; i < l; i += stride ) {
2326
-
2327
- pushVector( i );
2328
-
2329
- }
2330
-
2331
- }
2332
-
2333
- }
2334
-
2335
- function getGeometry( id ) {
2336
-
2337
- return getBuild( library.geometries[ id ], buildGeometry );
2338
-
2339
- }
2340
-
2341
- // kinematics
2342
-
2343
- function parseKinematicsModel( xml ) {
2344
-
2345
- const data = {
2346
- name: xml.getAttribute( 'name' ) || '',
2347
- joints: {},
2348
- links: []
2349
- };
2350
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
2351
-
2352
- const child = xml.childNodes[ i ];
2353
- if ( child.nodeType !== 1 ) continue;
2354
- switch ( child.nodeName ) {
2355
-
2356
- case 'technique_common':
2357
- parseKinematicsTechniqueCommon( child, data );
2358
- break;
2359
-
2360
- }
2361
-
2362
- }
2363
-
2364
- library.kinematicsModels[ xml.getAttribute( 'id' ) ] = data;
2365
-
2366
- }
2367
-
2368
- function buildKinematicsModel( data ) {
2369
-
2370
- if ( data.build !== undefined ) return data.build;
2371
- return data;
2372
-
2373
- }
2374
-
2375
- function getKinematicsModel( id ) {
2376
-
2377
- return getBuild( library.kinematicsModels[ id ], buildKinematicsModel );
2378
-
2379
- }
2380
-
2381
- function parseKinematicsTechniqueCommon( xml, data ) {
2382
-
2383
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
2384
-
2385
- const child = xml.childNodes[ i ];
2386
- if ( child.nodeType !== 1 ) continue;
2387
- switch ( child.nodeName ) {
2388
-
2389
- case 'joint':
2390
- data.joints[ child.getAttribute( 'sid' ) ] = parseKinematicsJoint( child );
2391
- break;
2392
- case 'link':
2393
- data.links.push( parseKinematicsLink( child ) );
2394
- break;
2395
-
2396
- }
2397
-
2398
- }
2399
-
2400
- }
2401
-
2402
- function parseKinematicsJoint( xml ) {
2403
-
2404
- let data;
2405
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
2406
-
2407
- const child = xml.childNodes[ i ];
2408
- if ( child.nodeType !== 1 ) continue;
2409
- switch ( child.nodeName ) {
2410
-
2411
- case 'prismatic':
2412
- case 'revolute':
2413
- data = parseKinematicsJointParameter( child );
2414
- break;
2415
-
2416
- }
2417
-
2418
- }
2419
-
2420
- return data;
2421
-
2422
- }
2423
-
2424
- function parseKinematicsJointParameter( xml ) {
2425
-
2426
- const data = {
2427
- sid: xml.getAttribute( 'sid' ),
2428
- name: xml.getAttribute( 'name' ) || '',
2429
- axis: new THREE.Vector3(),
2430
- limits: {
2431
- min: 0,
2432
- max: 0
2433
- },
2434
- type: xml.nodeName,
2435
- static: false,
2436
- zeroPosition: 0,
2437
- middlePosition: 0
2438
- };
2439
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
2440
-
2441
- const child = xml.childNodes[ i ];
2442
- if ( child.nodeType !== 1 ) continue;
2443
- switch ( child.nodeName ) {
2444
-
2445
- case 'axis':
2446
- const array = parseFloats( child.textContent );
2447
- data.axis.fromArray( array );
2448
- break;
2449
- case 'limits':
2450
- const max = child.getElementsByTagName( 'max' )[ 0 ];
2451
- const min = child.getElementsByTagName( 'min' )[ 0 ];
2452
- data.limits.max = parseFloat( max.textContent );
2453
- data.limits.min = parseFloat( min.textContent );
2454
- break;
2455
-
2456
- }
2457
-
2458
- }
2459
-
2460
- // if min is equal to or greater than max, consider the joint static
2461
-
2462
- if ( data.limits.min >= data.limits.max ) {
2463
-
2464
- data.static = true;
2465
-
2466
- }
2467
-
2468
- // calculate middle position
2469
-
2470
- data.middlePosition = ( data.limits.min + data.limits.max ) / 2.0;
2471
- return data;
2472
-
2473
- }
2474
-
2475
- function parseKinematicsLink( xml ) {
2476
-
2477
- const data = {
2478
- sid: xml.getAttribute( 'sid' ),
2479
- name: xml.getAttribute( 'name' ) || '',
2480
- attachments: [],
2481
- transforms: []
2482
- };
2483
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
2484
-
2485
- const child = xml.childNodes[ i ];
2486
- if ( child.nodeType !== 1 ) continue;
2487
- switch ( child.nodeName ) {
2488
-
2489
- case 'attachment_full':
2490
- data.attachments.push( parseKinematicsAttachment( child ) );
2491
- break;
2492
- case 'matrix':
2493
- case 'translate':
2494
- case 'rotate':
2495
- data.transforms.push( parseKinematicsTransform( child ) );
2496
- break;
2497
-
2498
- }
2499
-
2500
- }
2501
-
2502
- return data;
2503
-
2504
- }
2505
-
2506
- function parseKinematicsAttachment( xml ) {
2507
-
2508
- const data = {
2509
- joint: xml.getAttribute( 'joint' ).split( '/' ).pop(),
2510
- transforms: [],
2511
- links: []
2512
- };
2513
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
2514
-
2515
- const child = xml.childNodes[ i ];
2516
- if ( child.nodeType !== 1 ) continue;
2517
- switch ( child.nodeName ) {
2518
-
2519
- case 'link':
2520
- data.links.push( parseKinematicsLink( child ) );
2521
- break;
2522
- case 'matrix':
2523
- case 'translate':
2524
- case 'rotate':
2525
- data.transforms.push( parseKinematicsTransform( child ) );
2526
- break;
2527
-
2528
- }
2529
-
2530
- }
2531
-
2532
- return data;
2533
-
2534
- }
2535
-
2536
- function parseKinematicsTransform( xml ) {
2537
-
2538
- const data = {
2539
- type: xml.nodeName
2540
- };
2541
- const array = parseFloats( xml.textContent );
2542
- switch ( data.type ) {
2543
-
2544
- case 'matrix':
2545
- data.obj = new THREE.Matrix4();
2546
- data.obj.fromArray( array ).transpose();
2547
- break;
2548
- case 'translate':
2549
- data.obj = new THREE.Vector3();
2550
- data.obj.fromArray( array );
2551
- break;
2552
- case 'rotate':
2553
- data.obj = new THREE.Vector3();
2554
- data.obj.fromArray( array );
2555
- data.angle = THREE.MathUtils.degToRad( array[ 3 ] );
2556
- break;
2557
-
2558
- }
2559
-
2560
- return data;
2561
-
2562
- }
2563
-
2564
- // physics
2565
-
2566
- function parsePhysicsModel( xml ) {
2567
-
2568
- const data = {
2569
- name: xml.getAttribute( 'name' ) || '',
2570
- rigidBodies: {}
2571
- };
2572
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
2573
-
2574
- const child = xml.childNodes[ i ];
2575
- if ( child.nodeType !== 1 ) continue;
2576
- switch ( child.nodeName ) {
2577
-
2578
- case 'rigid_body':
2579
- data.rigidBodies[ child.getAttribute( 'name' ) ] = {};
2580
- parsePhysicsRigidBody( child, data.rigidBodies[ child.getAttribute( 'name' ) ] );
2581
- break;
2582
-
2583
- }
2584
-
2585
- }
2586
-
2587
- library.physicsModels[ xml.getAttribute( 'id' ) ] = data;
2588
-
2589
- }
2590
-
2591
- function parsePhysicsRigidBody( xml, data ) {
2592
-
2593
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
2594
-
2595
- const child = xml.childNodes[ i ];
2596
- if ( child.nodeType !== 1 ) continue;
2597
- switch ( child.nodeName ) {
2598
-
2599
- case 'technique_common':
2600
- parsePhysicsTechniqueCommon( child, data );
2601
- break;
2602
-
2603
- }
2604
-
2605
- }
2606
-
2607
- }
2608
-
2609
- function parsePhysicsTechniqueCommon( xml, data ) {
2610
-
2611
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
2612
-
2613
- const child = xml.childNodes[ i ];
2614
- if ( child.nodeType !== 1 ) continue;
2615
- switch ( child.nodeName ) {
2616
-
2617
- case 'inertia':
2618
- data.inertia = parseFloats( child.textContent );
2619
- break;
2620
- case 'mass':
2621
- data.mass = parseFloats( child.textContent )[ 0 ];
2622
- break;
2623
-
2624
- }
2625
-
2626
- }
2627
-
2628
- }
2629
-
2630
- // scene
2631
-
2632
- function parseKinematicsScene( xml ) {
2633
-
2634
- const data = {
2635
- bindJointAxis: []
2636
- };
2637
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
2638
-
2639
- const child = xml.childNodes[ i ];
2640
- if ( child.nodeType !== 1 ) continue;
2641
- switch ( child.nodeName ) {
2642
-
2643
- case 'bind_joint_axis':
2644
- data.bindJointAxis.push( parseKinematicsBindJointAxis( child ) );
2645
- break;
2646
-
2647
- }
2648
-
2649
- }
2650
-
2651
- library.kinematicsScenes[ parseId( xml.getAttribute( 'url' ) ) ] = data;
2652
-
2653
- }
2654
-
2655
- function parseKinematicsBindJointAxis( xml ) {
2656
-
2657
- const data = {
2658
- target: xml.getAttribute( 'target' ).split( '/' ).pop()
2659
- };
2660
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
2661
-
2662
- const child = xml.childNodes[ i ];
2663
- if ( child.nodeType !== 1 ) continue;
2664
- switch ( child.nodeName ) {
2665
-
2666
- case 'axis':
2667
- const param = child.getElementsByTagName( 'param' )[ 0 ];
2668
- data.axis = param.textContent;
2669
- const tmpJointIndex = data.axis.split( 'inst_' ).pop().split( 'axis' )[ 0 ];
2670
- data.jointIndex = tmpJointIndex.substring( 0, tmpJointIndex.length - 1 );
2671
- break;
2672
-
2673
- }
2674
-
2675
- }
2676
-
2677
- return data;
2678
-
2679
- }
2680
-
2681
- function buildKinematicsScene( data ) {
2682
-
2683
- if ( data.build !== undefined ) return data.build;
2684
- return data;
2685
-
2686
- }
2687
-
2688
- function getKinematicsScene( id ) {
2689
-
2690
- return getBuild( library.kinematicsScenes[ id ], buildKinematicsScene );
2691
-
2692
- }
2693
-
2694
- function setupKinematics() {
2695
-
2696
- const kinematicsModelId = Object.keys( library.kinematicsModels )[ 0 ];
2697
- const kinematicsSceneId = Object.keys( library.kinematicsScenes )[ 0 ];
2698
- const visualSceneId = Object.keys( library.visualScenes )[ 0 ];
2699
- if ( kinematicsModelId === undefined || kinematicsSceneId === undefined ) return;
2700
- const kinematicsModel = getKinematicsModel( kinematicsModelId );
2701
- const kinematicsScene = getKinematicsScene( kinematicsSceneId );
2702
- const visualScene = getVisualScene( visualSceneId );
2703
- const bindJointAxis = kinematicsScene.bindJointAxis;
2704
- const jointMap = {};
2705
- for ( let i = 0, l = bindJointAxis.length; i < l; i ++ ) {
2706
-
2707
- const axis = bindJointAxis[ i ];
2708
-
2709
- // the result of the following query is an element of type 'translate', 'rotate','scale' or 'matrix'
2710
-
2711
- const targetElement = collada.querySelector( '[sid="' + axis.target + '"]' );
2712
- if ( targetElement ) {
2713
-
2714
- // get the parent of the transform element
2715
-
2716
- const parentVisualElement = targetElement.parentElement;
2717
-
2718
- // connect the joint of the kinematics model with the element in the visual scene
2719
-
2720
- connect( axis.jointIndex, parentVisualElement );
2721
-
2722
- }
2723
-
2724
- }
2725
-
2726
- function connect( jointIndex, visualElement ) {
2727
-
2728
- const visualElementName = visualElement.getAttribute( 'name' );
2729
- const joint = kinematicsModel.joints[ jointIndex ];
2730
- visualScene.traverse( function ( object ) {
2731
-
2732
- if ( object.name === visualElementName ) {
2733
-
2734
- jointMap[ jointIndex ] = {
2735
- object: object,
2736
- transforms: buildTransformList( visualElement ),
2737
- joint: joint,
2738
- position: joint.zeroPosition
2739
- };
2740
-
2741
- }
2742
-
2743
- } );
2744
-
2745
- }
2746
-
2747
- const m0 = new THREE.Matrix4();
2748
- kinematics = {
2749
- joints: kinematicsModel && kinematicsModel.joints,
2750
- getJointValue: function ( jointIndex ) {
2751
-
2752
- const jointData = jointMap[ jointIndex ];
2753
- if ( jointData ) {
2754
-
2755
- return jointData.position;
2756
-
2757
- } else {
2758
-
2759
- console.warn( 'THREE.ColladaLoader: Joint ' + jointIndex + ' doesn\'t exist.' );
2760
-
2761
- }
2762
-
2763
- },
2764
- setJointValue: function ( jointIndex, value ) {
2765
-
2766
- const jointData = jointMap[ jointIndex ];
2767
- if ( jointData ) {
2768
-
2769
- const joint = jointData.joint;
2770
- if ( value > joint.limits.max || value < joint.limits.min ) {
2771
-
2772
- console.warn( 'THREE.ColladaLoader: Joint ' + jointIndex + ' value ' + value + ' outside of limits (min: ' + joint.limits.min + ', max: ' + joint.limits.max + ').' );
2773
-
2774
- } else if ( joint.static ) {
2775
-
2776
- console.warn( 'THREE.ColladaLoader: Joint ' + jointIndex + ' is static.' );
2777
-
2778
- } else {
2779
-
2780
- const object = jointData.object;
2781
- const axis = joint.axis;
2782
- const transforms = jointData.transforms;
2783
- matrix.identity();
2784
-
2785
- // each update, we have to apply all transforms in the correct order
2786
-
2787
- for ( let i = 0; i < transforms.length; i ++ ) {
2788
-
2789
- const transform = transforms[ i ];
2790
-
2791
- // if there is a connection of the transform node with a joint, apply the joint value
2792
-
2793
- if ( transform.sid && transform.sid.indexOf( jointIndex ) !== - 1 ) {
2794
-
2795
- switch ( joint.type ) {
2796
-
2797
- case 'revolute':
2798
- matrix.multiply( m0.makeRotationAxis( axis, THREE.MathUtils.degToRad( value ) ) );
2799
- break;
2800
- case 'prismatic':
2801
- matrix.multiply( m0.makeTranslation( axis.x * value, axis.y * value, axis.z * value ) );
2802
- break;
2803
- default:
2804
- console.warn( 'THREE.ColladaLoader: Unknown joint type: ' + joint.type );
2805
- break;
2806
-
2807
- }
2808
-
2809
- } else {
2810
-
2811
- switch ( transform.type ) {
2812
-
2813
- case 'matrix':
2814
- matrix.multiply( transform.obj );
2815
- break;
2816
- case 'translate':
2817
- matrix.multiply( m0.makeTranslation( transform.obj.x, transform.obj.y, transform.obj.z ) );
2818
- break;
2819
- case 'scale':
2820
- matrix.scale( transform.obj );
2821
- break;
2822
- case 'rotate':
2823
- matrix.multiply( m0.makeRotationAxis( transform.obj, transform.angle ) );
2824
- break;
2825
-
2826
- }
2827
-
2828
- }
2829
-
2830
- }
2831
-
2832
- object.matrix.copy( matrix );
2833
- object.matrix.decompose( object.position, object.quaternion, object.scale );
2834
- jointMap[ jointIndex ].position = value;
2835
-
2836
- }
2837
-
2838
- } else {
2839
-
2840
- console.log( 'THREE.ColladaLoader: ' + jointIndex + ' does not exist.' );
2841
-
2842
- }
2843
-
2844
- }
2845
- };
2846
-
2847
- }
2848
-
2849
- function buildTransformList( node ) {
2850
-
2851
- const transforms = [];
2852
- const xml = collada.querySelector( '[id="' + node.id + '"]' );
2853
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
2854
-
2855
- const child = xml.childNodes[ i ];
2856
- if ( child.nodeType !== 1 ) continue;
2857
- let array, vector;
2858
- switch ( child.nodeName ) {
2859
-
2860
- case 'matrix':
2861
- array = parseFloats( child.textContent );
2862
- const matrix = new THREE.Matrix4().fromArray( array ).transpose();
2863
- transforms.push( {
2864
- sid: child.getAttribute( 'sid' ),
2865
- type: child.nodeName,
2866
- obj: matrix
2867
- } );
2868
- break;
2869
- case 'translate':
2870
- case 'scale':
2871
- array = parseFloats( child.textContent );
2872
- vector = new THREE.Vector3().fromArray( array );
2873
- transforms.push( {
2874
- sid: child.getAttribute( 'sid' ),
2875
- type: child.nodeName,
2876
- obj: vector
2877
- } );
2878
- break;
2879
- case 'rotate':
2880
- array = parseFloats( child.textContent );
2881
- vector = new THREE.Vector3().fromArray( array );
2882
- const angle = THREE.MathUtils.degToRad( array[ 3 ] );
2883
- transforms.push( {
2884
- sid: child.getAttribute( 'sid' ),
2885
- type: child.nodeName,
2886
- obj: vector,
2887
- angle: angle
2888
- } );
2889
- break;
2890
-
2891
- }
2892
-
2893
- }
2894
-
2895
- return transforms;
2896
-
2897
- }
2898
-
2899
- // nodes
2900
-
2901
- function prepareNodes( xml ) {
2902
-
2903
- const elements = xml.getElementsByTagName( 'node' );
2904
-
2905
- // ensure all node elements have id attributes
2906
-
2907
- for ( let i = 0; i < elements.length; i ++ ) {
2908
-
2909
- const element = elements[ i ];
2910
- if ( element.hasAttribute( 'id' ) === false ) {
2911
-
2912
- element.setAttribute( 'id', generateId() );
2913
-
2914
- }
2915
-
2916
- }
2917
-
2918
- }
2919
-
2920
- const matrix = new THREE.Matrix4();
2921
- const vector = new THREE.Vector3();
2922
- function parseNode( xml ) {
2923
-
2924
- const data = {
2925
- name: xml.getAttribute( 'name' ) || '',
2926
- type: xml.getAttribute( 'type' ),
2927
- id: xml.getAttribute( 'id' ),
2928
- sid: xml.getAttribute( 'sid' ),
2929
- matrix: new THREE.Matrix4(),
2930
- nodes: [],
2931
- instanceCameras: [],
2932
- instanceControllers: [],
2933
- instanceLights: [],
2934
- instanceGeometries: [],
2935
- instanceNodes: [],
2936
- transforms: {}
2937
- };
2938
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
2939
-
2940
- const child = xml.childNodes[ i ];
2941
- if ( child.nodeType !== 1 ) continue;
2942
- let array;
2943
- switch ( child.nodeName ) {
2944
-
2945
- case 'node':
2946
- data.nodes.push( child.getAttribute( 'id' ) );
2947
- parseNode( child );
2948
- break;
2949
- case 'instance_camera':
2950
- data.instanceCameras.push( parseId( child.getAttribute( 'url' ) ) );
2951
- break;
2952
- case 'instance_controller':
2953
- data.instanceControllers.push( parseNodeInstance( child ) );
2954
- break;
2955
- case 'instance_light':
2956
- data.instanceLights.push( parseId( child.getAttribute( 'url' ) ) );
2957
- break;
2958
- case 'instance_geometry':
2959
- data.instanceGeometries.push( parseNodeInstance( child ) );
2960
- break;
2961
- case 'instance_node':
2962
- data.instanceNodes.push( parseId( child.getAttribute( 'url' ) ) );
2963
- break;
2964
- case 'matrix':
2965
- array = parseFloats( child.textContent );
2966
- data.matrix.multiply( matrix.fromArray( array ).transpose() );
2967
- data.transforms[ child.getAttribute( 'sid' ) ] = child.nodeName;
2968
- break;
2969
- case 'translate':
2970
- array = parseFloats( child.textContent );
2971
- vector.fromArray( array );
2972
- data.matrix.multiply( matrix.makeTranslation( vector.x, vector.y, vector.z ) );
2973
- data.transforms[ child.getAttribute( 'sid' ) ] = child.nodeName;
2974
- break;
2975
- case 'rotate':
2976
- array = parseFloats( child.textContent );
2977
- const angle = THREE.MathUtils.degToRad( array[ 3 ] );
2978
- data.matrix.multiply( matrix.makeRotationAxis( vector.fromArray( array ), angle ) );
2979
- data.transforms[ child.getAttribute( 'sid' ) ] = child.nodeName;
2980
- break;
2981
- case 'scale':
2982
- array = parseFloats( child.textContent );
2983
- data.matrix.scale( vector.fromArray( array ) );
2984
- data.transforms[ child.getAttribute( 'sid' ) ] = child.nodeName;
2985
- break;
2986
- case 'extra':
2987
- break;
2988
- default:
2989
- console.log( child );
2990
-
2991
- }
2992
-
2993
- }
2994
-
2995
- if ( hasNode( data.id ) ) {
2996
-
2997
- console.warn( 'THREE.ColladaLoader: There is already a node with ID %s. Exclude current node from further processing.', data.id );
2998
-
2999
- } else {
3000
-
3001
- library.nodes[ data.id ] = data;
3002
-
3003
- }
3004
-
3005
- return data;
3006
-
3007
- }
3008
-
3009
- function parseNodeInstance( xml ) {
3010
-
3011
- const data = {
3012
- id: parseId( xml.getAttribute( 'url' ) ),
3013
- materials: {},
3014
- skeletons: []
3015
- };
3016
- for ( let i = 0; i < xml.childNodes.length; i ++ ) {
3017
-
3018
- const child = xml.childNodes[ i ];
3019
- switch ( child.nodeName ) {
3020
-
3021
- case 'bind_material':
3022
- const instances = child.getElementsByTagName( 'instance_material' );
3023
- for ( let j = 0; j < instances.length; j ++ ) {
3024
-
3025
- const instance = instances[ j ];
3026
- const symbol = instance.getAttribute( 'symbol' );
3027
- const target = instance.getAttribute( 'target' );
3028
- data.materials[ symbol ] = parseId( target );
3029
-
3030
- }
3031
-
3032
- break;
3033
- case 'skeleton':
3034
- data.skeletons.push( parseId( child.textContent ) );
3035
- break;
3036
- default:
3037
- break;
3038
-
3039
- }
3040
-
3041
- }
3042
-
3043
- return data;
3044
-
3045
- }
3046
-
3047
- function buildSkeleton( skeletons, joints ) {
3048
-
3049
- const boneData = [];
3050
- const sortedBoneData = [];
3051
- let i, j, data;
3052
-
3053
- // a skeleton can have multiple root bones. collada expresses this
3054
- // situtation with multiple "skeleton" tags per controller instance
3055
-
3056
- for ( i = 0; i < skeletons.length; i ++ ) {
3057
-
3058
- const skeleton = skeletons[ i ];
3059
- let root;
3060
- if ( hasNode( skeleton ) ) {
3061
-
3062
- root = getNode( skeleton );
3063
- buildBoneHierarchy( root, joints, boneData );
3064
-
3065
- } else if ( hasVisualScene( skeleton ) ) {
3066
-
3067
- // handle case where the skeleton refers to the visual scene (#13335)
3068
-
3069
- const visualScene = library.visualScenes[ skeleton ];
3070
- const children = visualScene.children;
3071
- for ( let j = 0; j < children.length; j ++ ) {
3072
-
3073
- const child = children[ j ];
3074
- if ( child.type === 'JOINT' ) {
3075
-
3076
- const root = getNode( child.id );
3077
- buildBoneHierarchy( root, joints, boneData );
3078
-
3079
- }
3080
-
3081
- }
3082
-
3083
- } else {
3084
-
3085
- console.error( 'THREE.ColladaLoader: Unable to find root bone of skeleton with ID:', skeleton );
3086
-
3087
- }
3088
-
3089
- }
3090
-
3091
- // sort bone data (the order is defined in the corresponding controller)
3092
-
3093
- for ( i = 0; i < joints.length; i ++ ) {
3094
-
3095
- for ( j = 0; j < boneData.length; j ++ ) {
3096
-
3097
- data = boneData[ j ];
3098
- if ( data.bone.name === joints[ i ].name ) {
3099
-
3100
- sortedBoneData[ i ] = data;
3101
- data.processed = true;
3102
- break;
3103
-
3104
- }
3105
-
3106
- }
3107
-
3108
- }
3109
-
3110
- // add unprocessed bone data at the end of the list
3111
-
3112
- for ( i = 0; i < boneData.length; i ++ ) {
3113
-
3114
- data = boneData[ i ];
3115
- if ( data.processed === false ) {
3116
-
3117
- sortedBoneData.push( data );
3118
- data.processed = true;
3119
-
3120
- }
3121
-
3122
- }
3123
-
3124
- // setup arrays for skeleton creation
3125
-
3126
- const bones = [];
3127
- const boneInverses = [];
3128
- for ( i = 0; i < sortedBoneData.length; i ++ ) {
3129
-
3130
- data = sortedBoneData[ i ];
3131
- bones.push( data.bone );
3132
- boneInverses.push( data.boneInverse );
3133
-
3134
- }
3135
-
3136
- return new THREE.Skeleton( bones, boneInverses );
3137
-
3138
- }
3139
-
3140
- function buildBoneHierarchy( root, joints, boneData ) {
3141
-
3142
- // setup bone data from visual scene
3143
-
3144
- root.traverse( function ( object ) {
3145
-
3146
- if ( object.isBone === true ) {
3147
-
3148
- let boneInverse;
3149
-
3150
- // retrieve the boneInverse from the controller data
3151
-
3152
- for ( let i = 0; i < joints.length; i ++ ) {
3153
-
3154
- const joint = joints[ i ];
3155
- if ( joint.name === object.name ) {
3156
-
3157
- boneInverse = joint.boneInverse;
3158
- break;
3159
-
3160
- }
3161
-
3162
- }
3163
-
3164
- if ( boneInverse === undefined ) {
3165
-
3166
- // Unfortunately, there can be joints in the visual scene that are not part of the
3167
- // corresponding controller. In this case, we have to create a dummy boneInverse matrix
3168
- // for the respective bone. This bone won't affect any vertices, because there are no skin indices
3169
- // and weights defined for it. But we still have to add the bone to the sorted bone list in order to
3170
- // ensure a correct animation of the model.
3171
-
3172
- boneInverse = new THREE.Matrix4();
3173
-
3174
- }
3175
-
3176
- boneData.push( {
3177
- bone: object,
3178
- boneInverse: boneInverse,
3179
- processed: false
3180
- } );
3181
-
3182
- }
3183
-
3184
- } );
3185
-
3186
- }
3187
-
3188
- function buildNode( data ) {
3189
-
3190
- const objects = [];
3191
- const matrix = data.matrix;
3192
- const nodes = data.nodes;
3193
- const type = data.type;
3194
- const instanceCameras = data.instanceCameras;
3195
- const instanceControllers = data.instanceControllers;
3196
- const instanceLights = data.instanceLights;
3197
- const instanceGeometries = data.instanceGeometries;
3198
- const instanceNodes = data.instanceNodes;
3199
-
3200
- // nodes
3201
-
3202
- for ( let i = 0, l = nodes.length; i < l; i ++ ) {
3203
-
3204
- objects.push( getNode( nodes[ i ] ) );
3205
-
3206
- }
3207
-
3208
- // instance cameras
3209
-
3210
- for ( let i = 0, l = instanceCameras.length; i < l; i ++ ) {
3211
-
3212
- const instanceCamera = getCamera( instanceCameras[ i ] );
3213
- if ( instanceCamera !== null ) {
3214
-
3215
- objects.push( instanceCamera.clone() );
3216
-
3217
- }
3218
-
3219
- }
3220
-
3221
- // instance controllers
3222
-
3223
- for ( let i = 0, l = instanceControllers.length; i < l; i ++ ) {
3224
-
3225
- const instance = instanceControllers[ i ];
3226
- const controller = getController( instance.id );
3227
- const geometries = getGeometry( controller.id );
3228
- const newObjects = buildObjects( geometries, instance.materials );
3229
- const skeletons = instance.skeletons;
3230
- const joints = controller.skin.joints;
3231
- const skeleton = buildSkeleton( skeletons, joints );
3232
- for ( let j = 0, jl = newObjects.length; j < jl; j ++ ) {
3233
-
3234
- const object = newObjects[ j ];
3235
- if ( object.isSkinnedMesh ) {
3236
-
3237
- object.bind( skeleton, controller.skin.bindMatrix );
3238
- object.normalizeSkinWeights();
3239
-
3240
- }
3241
-
3242
- objects.push( object );
3243
-
3244
- }
3245
-
3246
- }
3247
-
3248
- // instance lights
3249
-
3250
- for ( let i = 0, l = instanceLights.length; i < l; i ++ ) {
3251
-
3252
- const instanceLight = getLight( instanceLights[ i ] );
3253
- if ( instanceLight !== null ) {
3254
-
3255
- objects.push( instanceLight.clone() );
3256
-
3257
- }
3258
-
3259
- }
3260
-
3261
- // instance geometries
3262
-
3263
- for ( let i = 0, l = instanceGeometries.length; i < l; i ++ ) {
3264
-
3265
- const instance = instanceGeometries[ i ];
3266
-
3267
- // a single geometry instance in collada can lead to multiple object3Ds.
3268
- // this is the case when primitives are combined like triangles and lines
3269
-
3270
- const geometries = getGeometry( instance.id );
3271
- const newObjects = buildObjects( geometries, instance.materials );
3272
- for ( let j = 0, jl = newObjects.length; j < jl; j ++ ) {
3273
-
3274
- objects.push( newObjects[ j ] );
3275
-
3276
- }
3277
-
3278
- }
3279
-
3280
- // instance nodes
3281
-
3282
- for ( let i = 0, l = instanceNodes.length; i < l; i ++ ) {
3283
-
3284
- objects.push( getNode( instanceNodes[ i ] ).clone() );
3285
-
3286
- }
3287
-
3288
- let object;
3289
- if ( nodes.length === 0 && objects.length === 1 ) {
3290
-
3291
- object = objects[ 0 ];
3292
-
3293
- } else {
3294
-
3295
- object = type === 'JOINT' ? new THREE.Bone() : new THREE.Group();
3296
- for ( let i = 0; i < objects.length; i ++ ) {
3297
-
3298
- object.add( objects[ i ] );
3299
-
3300
- }
3301
-
3302
- }
3303
-
3304
- object.name = type === 'JOINT' ? data.sid : data.name;
3305
- object.matrix.copy( matrix );
3306
- object.matrix.decompose( object.position, object.quaternion, object.scale );
3307
- return object;
3308
-
3309
- }
3310
-
3311
- const fallbackMaterial = new THREE.MeshBasicMaterial( {
3312
- color: 0xff00ff
3313
- } );
3314
- function resolveMaterialBinding( keys, instanceMaterials ) {
3315
-
3316
- const materials = [];
3317
- for ( let i = 0, l = keys.length; i < l; i ++ ) {
3318
-
3319
- const id = instanceMaterials[ keys[ i ] ];
3320
- if ( id === undefined ) {
3321
-
3322
- console.warn( 'THREE.ColladaLoader: Material with key %s not found. Apply fallback material.', keys[ i ] );
3323
- materials.push( fallbackMaterial );
3324
-
3325
- } else {
3326
-
3327
- materials.push( getMaterial( id ) );
3328
-
3329
- }
3330
-
3331
- }
3332
-
3333
- return materials;
3334
-
3335
- }
3336
-
3337
- function buildObjects( geometries, instanceMaterials ) {
3338
-
3339
- const objects = [];
3340
- for ( const type in geometries ) {
3341
-
3342
- const geometry = geometries[ type ];
3343
- const materials = resolveMaterialBinding( geometry.materialKeys, instanceMaterials );
3344
-
3345
- // handle case if no materials are defined
3346
-
3347
- if ( materials.length === 0 ) {
3348
-
3349
- if ( type === 'lines' || type === 'linestrips' ) {
3350
-
3351
- materials.push( new THREE.LineBasicMaterial() );
3352
-
3353
- } else {
3354
-
3355
- materials.push( new THREE.MeshPhongMaterial() );
3356
-
3357
- }
3358
-
3359
- }
3360
-
3361
- // Collada allows to use phong and lambert materials with lines. Replacing these cases with THREE.LineBasicMaterial.
3362
-
3363
- if ( type === 'lines' || type === 'linestrips' ) {
3364
-
3365
- for ( let i = 0, l = materials.length; i < l; i ++ ) {
3366
-
3367
- const material = materials[ i ];
3368
- if ( material.isMeshPhongMaterial === true || material.isMeshLambertMaterial === true ) {
3369
-
3370
- const lineMaterial = new THREE.LineBasicMaterial();
3371
-
3372
- // copy compatible properties
3373
-
3374
- lineMaterial.color.copy( material.color );
3375
- lineMaterial.opacity = material.opacity;
3376
- lineMaterial.transparent = material.transparent;
3377
-
3378
- // replace material
3379
-
3380
- materials[ i ] = lineMaterial;
3381
-
3382
- }
3383
-
3384
- }
3385
-
3386
- }
3387
-
3388
- // regard skinning
3389
-
3390
- const skinning = geometry.data.attributes.skinIndex !== undefined;
3391
-
3392
- // choose between a single or multi materials (material array)
3393
-
3394
- const material = materials.length === 1 ? materials[ 0 ] : materials;
3395
-
3396
- // now create a specific 3D object
3397
-
3398
- let object;
3399
- switch ( type ) {
3400
-
3401
- case 'lines':
3402
- object = new THREE.LineSegments( geometry.data, material );
3403
- break;
3404
- case 'linestrips':
3405
- object = new THREE.Line( geometry.data, material );
3406
- break;
3407
- case 'triangles':
3408
- case 'polylist':
3409
- if ( skinning ) {
3410
-
3411
- object = new THREE.SkinnedMesh( geometry.data, material );
3412
-
3413
- } else {
3414
-
3415
- object = new THREE.Mesh( geometry.data, material );
3416
-
3417
- }
3418
-
3419
- break;
3420
-
3421
- }
3422
-
3423
- objects.push( object );
3424
-
3425
- }
3426
-
3427
- return objects;
3428
-
3429
- }
3430
-
3431
- function hasNode( id ) {
3432
-
3433
- return library.nodes[ id ] !== undefined;
3434
-
3435
- }
3436
-
3437
- function getNode( id ) {
3438
-
3439
- return getBuild( library.nodes[ id ], buildNode );
3440
-
3441
- }
3442
-
3443
- // visual scenes
3444
-
3445
- function parseVisualScene( xml ) {
3446
-
3447
- const data = {
3448
- name: xml.getAttribute( 'name' ),
3449
- children: []
3450
- };
3451
- prepareNodes( xml );
3452
- const elements = getElementsByTagName( xml, 'node' );
3453
- for ( let i = 0; i < elements.length; i ++ ) {
3454
-
3455
- data.children.push( parseNode( elements[ i ] ) );
3456
-
3457
- }
3458
-
3459
- library.visualScenes[ xml.getAttribute( 'id' ) ] = data;
3460
-
3461
- }
3462
-
3463
- function buildVisualScene( data ) {
3464
-
3465
- const group = new THREE.Group();
3466
- group.name = data.name;
3467
- const children = data.children;
3468
- for ( let i = 0; i < children.length; i ++ ) {
3469
-
3470
- const child = children[ i ];
3471
- group.add( getNode( child.id ) );
3472
-
3473
- }
3474
-
3475
- return group;
3476
-
3477
- }
3478
-
3479
- function hasVisualScene( id ) {
3480
-
3481
- return library.visualScenes[ id ] !== undefined;
3482
-
3483
- }
3484
-
3485
- function getVisualScene( id ) {
3486
-
3487
- return getBuild( library.visualScenes[ id ], buildVisualScene );
3488
-
3489
- }
3490
-
3491
- // scenes
3492
-
3493
- function parseScene( xml ) {
3494
-
3495
- const instance = getElementsByTagName( xml, 'instance_visual_scene' )[ 0 ];
3496
- return getVisualScene( parseId( instance.getAttribute( 'url' ) ) );
3497
-
3498
- }
3499
-
3500
- function setupAnimations() {
3501
-
3502
- const clips = library.clips;
3503
- if ( isEmpty( clips ) === true ) {
3504
-
3505
- if ( isEmpty( library.animations ) === false ) {
3506
-
3507
- // if there are animations but no clips, we create a default clip for playback
3508
-
3509
- const tracks = [];
3510
- for ( const id in library.animations ) {
3511
-
3512
- const animationTracks = getAnimation( id );
3513
- for ( let i = 0, l = animationTracks.length; i < l; i ++ ) {
3514
-
3515
- tracks.push( animationTracks[ i ] );
3516
-
3517
- }
3518
-
3519
- }
3520
-
3521
- animations.push( new THREE.AnimationClip( 'default', - 1, tracks ) );
3522
-
3523
- }
3524
-
3525
- } else {
3526
-
3527
- for ( const id in clips ) {
3528
-
3529
- animations.push( getAnimationClip( id ) );
3530
-
3531
- }
3532
-
3533
- }
3534
-
3535
- }
3536
-
3537
- // convert the parser error element into text with each child elements text
3538
- // separated by new lines.
3539
-
3540
- function parserErrorToText( parserError ) {
3541
-
3542
- let result = '';
3543
- const stack = [ parserError ];
3544
- while ( stack.length ) {
3545
-
3546
- const node = stack.shift();
3547
- if ( node.nodeType === Node.TEXT_NODE ) {
3548
-
3549
- result += node.textContent;
3550
-
3551
- } else {
3552
-
3553
- result += '\n';
3554
- stack.push.apply( stack, node.childNodes );
3555
-
3556
- }
3557
-
3558
- }
3559
-
3560
- return result.trim();
3561
-
3562
- }
3563
-
3564
- if ( text.length === 0 ) {
3565
-
3566
- return {
3567
- scene: new THREE.Scene()
3568
- };
3569
-
3570
- }
3571
-
3572
- const xml = new DOMParser().parseFromString( text, 'application/xml' );
3573
- const collada = getElementsByTagName( xml, 'COLLADA' )[ 0 ];
3574
- const parserError = xml.getElementsByTagName( 'parsererror' )[ 0 ];
3575
- if ( parserError !== undefined ) {
3576
-
3577
- // Chrome will return parser error with a div in it
3578
-
3579
- const errorElement = getElementsByTagName( parserError, 'div' )[ 0 ];
3580
- let errorText;
3581
- if ( errorElement ) {
3582
-
3583
- errorText = errorElement.textContent;
3584
-
3585
- } else {
3586
-
3587
- errorText = parserErrorToText( parserError );
3588
-
3589
- }
3590
-
3591
- console.error( 'THREE.ColladaLoader: Failed to parse collada file.\n', errorText );
3592
- return null;
3593
-
3594
- }
3595
-
3596
- // metadata
3597
-
3598
- const version = collada.getAttribute( 'version' );
3599
- console.log( 'THREE.ColladaLoader: File version', version );
3600
- const asset = parseAsset( getElementsByTagName( collada, 'asset' )[ 0 ] );
3601
- const textureLoader = new THREE.TextureLoader( this.manager );
3602
- textureLoader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
3603
- let tgaLoader;
3604
- if ( THREE.TGALoader ) {
3605
-
3606
- tgaLoader = new THREE.TGALoader( this.manager );
3607
- tgaLoader.setPath( this.resourcePath || path );
3608
-
3609
- }
3610
-
3611
- //
3612
-
3613
- const tempColor = new THREE.Color();
3614
- const animations = [];
3615
- let kinematics = {};
3616
- let count = 0;
3617
-
3618
- //
3619
-
3620
- const library = {
3621
- animations: {},
3622
- clips: {},
3623
- controllers: {},
3624
- images: {},
3625
- effects: {},
3626
- materials: {},
3627
- cameras: {},
3628
- lights: {},
3629
- geometries: {},
3630
- nodes: {},
3631
- visualScenes: {},
3632
- kinematicsModels: {},
3633
- physicsModels: {},
3634
- kinematicsScenes: {}
3635
- };
3636
- parseLibrary( collada, 'library_animations', 'animation', parseAnimation );
3637
- parseLibrary( collada, 'library_animation_clips', 'animation_clip', parseAnimationClip );
3638
- parseLibrary( collada, 'library_controllers', 'controller', parseController );
3639
- parseLibrary( collada, 'library_images', 'image', parseImage );
3640
- parseLibrary( collada, 'library_effects', 'effect', parseEffect );
3641
- parseLibrary( collada, 'library_materials', 'material', parseMaterial );
3642
- parseLibrary( collada, 'library_cameras', 'camera', parseCamera );
3643
- parseLibrary( collada, 'library_lights', 'light', parseLight );
3644
- parseLibrary( collada, 'library_geometries', 'geometry', parseGeometry );
3645
- parseLibrary( collada, 'library_nodes', 'node', parseNode );
3646
- parseLibrary( collada, 'library_visual_scenes', 'visual_scene', parseVisualScene );
3647
- parseLibrary( collada, 'library_kinematics_models', 'kinematics_model', parseKinematicsModel );
3648
- parseLibrary( collada, 'library_physics_models', 'physics_model', parsePhysicsModel );
3649
- parseLibrary( collada, 'scene', 'instance_kinematics_scene', parseKinematicsScene );
3650
- buildLibrary( library.animations, buildAnimation );
3651
- buildLibrary( library.clips, buildAnimationClip );
3652
- buildLibrary( library.controllers, buildController );
3653
- buildLibrary( library.images, buildImage );
3654
- buildLibrary( library.effects, buildEffect );
3655
- buildLibrary( library.materials, buildMaterial );
3656
- buildLibrary( library.cameras, buildCamera );
3657
- buildLibrary( library.lights, buildLight );
3658
- buildLibrary( library.geometries, buildGeometry );
3659
- buildLibrary( library.visualScenes, buildVisualScene );
3660
- setupAnimations();
3661
- setupKinematics();
3662
- const scene = parseScene( getElementsByTagName( collada, 'scene' )[ 0 ] );
3663
- scene.animations = animations;
3664
- if ( asset.upAxis === 'Z_UP' ) {
3665
-
3666
- console.warn( 'THREE.ColladaLoader: You are loading an asset with a Z-UP coordinate system. The loader just rotates the asset to transform it into Y-UP. The vertex data are not converted, see #24289.' );
3667
- scene.quaternion.setFromEuler( new THREE.Euler( - Math.PI / 2, 0, 0 ) );
3668
-
3669
- }
3670
-
3671
- scene.scale.multiplyScalar( asset.unit );
3672
- return {
3673
- get animations() {
3674
-
3675
- console.warn( 'THREE.ColladaLoader: Please access animations over scene.animations now.' );
3676
- return animations;
3677
-
3678
- },
3679
- kinematics: kinematics,
3680
- library: library,
3681
- scene: scene
3682
- };
3683
-
3684
- }
3685
-
3686
- }
3687
-
3688
- THREE.ColladaLoader = ColladaLoader;
3689
-
3690
- } )();