three-stdlib 2.24.2 → 2.25.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (540) hide show
  1. package/controls/OrbitControls.d.ts +2 -0
  2. package/index.cjs +116401 -611
  3. package/index.js +116037 -263
  4. package/package.json +17 -4
  5. package/_polyfill/CapsuleGeometry.cjs +0 -22
  6. package/_polyfill/CapsuleGeometry.js +0 -22
  7. package/_polyfill/CompressedArrayTexture.cjs +0 -12
  8. package/_polyfill/CompressedArrayTexture.js +0 -12
  9. package/_polyfill/Data3DTexture.cjs +0 -17
  10. package/_polyfill/Data3DTexture.js +0 -17
  11. package/animation/AnimationClipCreator.cjs +0 -56
  12. package/animation/AnimationClipCreator.js +0 -56
  13. package/animation/CCDIKSolver.cjs +0 -269
  14. package/animation/CCDIKSolver.js +0 -269
  15. package/animation/MMDAnimationHelper.cjs +0 -688
  16. package/animation/MMDAnimationHelper.js +0 -688
  17. package/animation/MMDPhysics.cjs +0 -830
  18. package/animation/MMDPhysics.js +0 -830
  19. package/cameras/CinematicCamera.cjs +0 -131
  20. package/cameras/CinematicCamera.js +0 -131
  21. package/controls/ArcballControls.cjs +0 -2033
  22. package/controls/ArcballControls.js +0 -2033
  23. package/controls/DeviceOrientationControls.cjs +0 -85
  24. package/controls/DeviceOrientationControls.js +0 -85
  25. package/controls/DragControls.cjs +0 -182
  26. package/controls/DragControls.js +0 -182
  27. package/controls/FirstPersonControls.cjs +0 -229
  28. package/controls/FirstPersonControls.js +0 -229
  29. package/controls/FlyControls.cjs +0 -248
  30. package/controls/FlyControls.js +0 -248
  31. package/controls/OrbitControls.cjs +0 -787
  32. package/controls/OrbitControls.js +0 -787
  33. package/controls/PointerLockControls.cjs +0 -103
  34. package/controls/PointerLockControls.js +0 -103
  35. package/controls/TrackballControls.cjs +0 -502
  36. package/controls/TrackballControls.js +0 -502
  37. package/controls/TransformControls.cjs +0 -1089
  38. package/controls/TransformControls.js +0 -1089
  39. package/controls/experimental/CameraControls.cjs +0 -736
  40. package/controls/experimental/CameraControls.js +0 -736
  41. package/csm/CSM.cjs +0 -244
  42. package/csm/CSM.js +0 -244
  43. package/csm/CSMFrustum.cjs +0 -75
  44. package/csm/CSMFrustum.js +0 -75
  45. package/csm/CSMHelper.cjs +0 -114
  46. package/csm/CSMHelper.js +0 -114
  47. package/csm/CSMShader.cjs +0 -261
  48. package/csm/CSMShader.js +0 -261
  49. package/curves/CurveExtras.cjs +0 -214
  50. package/curves/CurveExtras.js +0 -214
  51. package/curves/NURBSCurve.cjs +0 -35
  52. package/curves/NURBSCurve.js +0 -35
  53. package/curves/NURBSSurface.cjs +0 -28
  54. package/curves/NURBSSurface.js +0 -28
  55. package/curves/NURBSUtils.cjs +0 -226
  56. package/curves/NURBSUtils.js +0 -226
  57. package/deprecated/Geometry.cjs +0 -971
  58. package/deprecated/Geometry.js +0 -971
  59. package/effects/AnaglyphEffect.cjs +0 -102
  60. package/effects/AnaglyphEffect.js +0 -102
  61. package/effects/AsciiEffect.cjs +0 -155
  62. package/effects/AsciiEffect.js +0 -155
  63. package/effects/OutlineEffect.cjs +0 -275
  64. package/effects/OutlineEffect.js +0 -275
  65. package/effects/ParallaxBarrierEffect.cjs +0 -65
  66. package/effects/ParallaxBarrierEffect.js +0 -65
  67. package/effects/PeppersGhostEffect.cjs +0 -88
  68. package/effects/PeppersGhostEffect.js +0 -88
  69. package/effects/StereoEffect.cjs +0 -35
  70. package/effects/StereoEffect.js +0 -35
  71. package/environments/RoomEnvironment.cjs +0 -95
  72. package/environments/RoomEnvironment.js +0 -78
  73. package/exporters/ColladaExporter.cjs +0 -331
  74. package/exporters/ColladaExporter.js +0 -331
  75. package/exporters/DRACOExporter.cjs +0 -141
  76. package/exporters/DRACOExporter.js +0 -141
  77. package/exporters/GLTFExporter.cjs +0 -1909
  78. package/exporters/GLTFExporter.js +0 -1909
  79. package/exporters/MMDExporter.cjs +0 -131
  80. package/exporters/MMDExporter.js +0 -131
  81. package/exporters/OBJExporter.cjs +0 -181
  82. package/exporters/OBJExporter.js +0 -181
  83. package/exporters/PLYExporter.cjs +0 -280
  84. package/exporters/PLYExporter.js +0 -280
  85. package/exporters/STLExporter.cjs +0 -146
  86. package/exporters/STLExporter.js +0 -146
  87. package/exporters/USDZExporter.cjs +0 -340
  88. package/exporters/USDZExporter.js +0 -340
  89. package/geometries/BoxLineGeometry.cjs +0 -45
  90. package/geometries/BoxLineGeometry.js +0 -45
  91. package/geometries/ConvexGeometry.cjs +0 -26
  92. package/geometries/ConvexGeometry.js +0 -26
  93. package/geometries/DecalGeometry.cjs +0 -184
  94. package/geometries/DecalGeometry.js +0 -184
  95. package/geometries/LightningStrike.cjs +0 -553
  96. package/geometries/LightningStrike.js +0 -553
  97. package/geometries/ParametricGeometries.cjs +0 -130
  98. package/geometries/ParametricGeometries.js +0 -130
  99. package/geometries/ParametricGeometry.cjs +0 -63
  100. package/geometries/ParametricGeometry.js +0 -63
  101. package/geometries/RoundedBoxGeometry.cjs +0 -91
  102. package/geometries/RoundedBoxGeometry.js +0 -91
  103. package/geometries/TeapotGeometry.cjs +0 -1563
  104. package/geometries/TeapotGeometry.js +0 -1563
  105. package/geometries/TextGeometry.cjs +0 -27
  106. package/geometries/TextGeometry.js +0 -27
  107. package/helpers/LightProbeHelper.cjs +0 -73
  108. package/helpers/LightProbeHelper.js +0 -73
  109. package/helpers/PositionalAudioHelper.cjs +0 -68
  110. package/helpers/PositionalAudioHelper.js +0 -68
  111. package/helpers/RectAreaLightHelper.cjs +0 -44
  112. package/helpers/RectAreaLightHelper.js +0 -44
  113. package/helpers/VertexNormalsHelper.cjs +0 -47
  114. package/helpers/VertexNormalsHelper.js +0 -47
  115. package/helpers/VertexTangentsHelper.cjs +0 -43
  116. package/helpers/VertexTangentsHelper.js +0 -43
  117. package/interactive/HTMLMesh.cjs +0 -325
  118. package/interactive/HTMLMesh.js +0 -325
  119. package/interactive/InteractiveGroup.cjs +0 -68
  120. package/interactive/InteractiveGroup.js +0 -68
  121. package/interactive/SelectionBox.cjs +0 -134
  122. package/interactive/SelectionBox.js +0 -134
  123. package/interactive/SelectionHelper.cjs +0 -51
  124. package/interactive/SelectionHelper.js +0 -51
  125. package/libs/MeshoptDecoder.cjs +0 -221
  126. package/libs/MeshoptDecoder.js +0 -221
  127. package/libs/MotionControllers.cjs +0 -325
  128. package/libs/MotionControllers.js +0 -325
  129. package/lights/LightProbeGenerator.cjs +0 -145
  130. package/lights/LightProbeGenerator.js +0 -145
  131. package/lights/RectAreaLightUniformsLib.cjs +0 -32846
  132. package/lights/RectAreaLightUniformsLib.js +0 -32846
  133. package/lines/Line2.cjs +0 -13
  134. package/lines/Line2.js +0 -13
  135. package/lines/LineGeometry.cjs +0 -44
  136. package/lines/LineGeometry.js +0 -44
  137. package/lines/LineMaterial.cjs +0 -547
  138. package/lines/LineMaterial.js +0 -547
  139. package/lines/LineSegments2.cjs +0 -203
  140. package/lines/LineSegments2.js +0 -203
  141. package/lines/LineSegmentsGeometry.cjs +0 -124
  142. package/lines/LineSegmentsGeometry.js +0 -124
  143. package/lines/Wireframe.cjs +0 -32
  144. package/lines/Wireframe.js +0 -32
  145. package/lines/WireframeGeometry2.cjs +0 -13
  146. package/lines/WireframeGeometry2.js +0 -13
  147. package/loaders/3DMLoader.cjs +0 -803
  148. package/loaders/3DMLoader.js +0 -803
  149. package/loaders/3MFLoader.cjs +0 -854
  150. package/loaders/3MFLoader.js +0 -854
  151. package/loaders/AMFLoader.cjs +0 -284
  152. package/loaders/AMFLoader.js +0 -284
  153. package/loaders/AssimpLoader.cjs +0 -1434
  154. package/loaders/AssimpLoader.js +0 -1434
  155. package/loaders/BVHLoader.cjs +0 -207
  156. package/loaders/BVHLoader.js +0 -207
  157. package/loaders/BasisTextureLoader.cjs +0 -489
  158. package/loaders/BasisTextureLoader.js +0 -489
  159. package/loaders/ColladaLoader.cjs +0 -2405
  160. package/loaders/ColladaLoader.js +0 -2405
  161. package/loaders/DDSLoader.cjs +0 -148
  162. package/loaders/DDSLoader.js +0 -148
  163. package/loaders/DRACOLoader.cjs +0 -341
  164. package/loaders/DRACOLoader.js +0 -341
  165. package/loaders/EXRLoader.cjs +0 -1356
  166. package/loaders/EXRLoader.js +0 -1356
  167. package/loaders/FBXLoader.cjs +0 -2457
  168. package/loaders/FBXLoader.js +0 -2457
  169. package/loaders/FontLoader.cjs +0 -123
  170. package/loaders/FontLoader.js +0 -123
  171. package/loaders/GCodeLoader.cjs +0 -141
  172. package/loaders/GCodeLoader.js +0 -141
  173. package/loaders/GLTFLoader.cjs +0 -2504
  174. package/loaders/GLTFLoader.js +0 -2504
  175. package/loaders/HDRCubeTextureLoader.cjs +0 -75
  176. package/loaders/HDRCubeTextureLoader.js +0 -75
  177. package/loaders/KMZLoader.cjs +0 -75
  178. package/loaders/KMZLoader.js +0 -75
  179. package/loaders/KTX2Loader.cjs +0 -480
  180. package/loaders/KTX2Loader.js +0 -480
  181. package/loaders/KTXLoader.cjs +0 -93
  182. package/loaders/KTXLoader.js +0 -93
  183. package/loaders/LDrawLoader.cjs +0 -1424
  184. package/loaders/LDrawLoader.js +0 -1424
  185. package/loaders/LUT3dlLoader.cjs +0 -103
  186. package/loaders/LUT3dlLoader.js +0 -103
  187. package/loaders/LUTCubeLoader.cjs +0 -107
  188. package/loaders/LUTCubeLoader.js +0 -107
  189. package/loaders/LWOLoader.cjs +0 -645
  190. package/loaders/LWOLoader.js +0 -645
  191. package/loaders/LottieLoader.cjs +0 -47
  192. package/loaders/LottieLoader.js +0 -47
  193. package/loaders/MD2Loader.cjs +0 -359
  194. package/loaders/MD2Loader.js +0 -359
  195. package/loaders/MDDLoader.cjs +0 -58
  196. package/loaders/MDDLoader.js +0 -58
  197. package/loaders/MMDLoader.cjs +0 -1121
  198. package/loaders/MMDLoader.js +0 -1121
  199. package/loaders/MTLLoader.cjs +0 -304
  200. package/loaders/MTLLoader.js +0 -304
  201. package/loaders/NRRDLoader.cjs +0 -401
  202. package/loaders/NRRDLoader.js +0 -401
  203. package/loaders/OBJLoader.cjs +0 -487
  204. package/loaders/OBJLoader.js +0 -487
  205. package/loaders/PCDLoader.cjs +0 -248
  206. package/loaders/PCDLoader.js +0 -248
  207. package/loaders/PDBLoader.cjs +0 -247
  208. package/loaders/PDBLoader.js +0 -247
  209. package/loaders/PLYLoader.cjs +0 -317
  210. package/loaders/PLYLoader.js +0 -317
  211. package/loaders/PRWMLoader.cjs +0 -160
  212. package/loaders/PRWMLoader.js +0 -160
  213. package/loaders/PVRLoader.cjs +0 -131
  214. package/loaders/PVRLoader.js +0 -131
  215. package/loaders/RGBELoader.cjs +0 -252
  216. package/loaders/RGBELoader.js +0 -252
  217. package/loaders/RGBMLoader.cjs +0 -1004
  218. package/loaders/RGBMLoader.js +0 -1004
  219. package/loaders/STLLoader.cjs +0 -190
  220. package/loaders/STLLoader.js +0 -190
  221. package/loaders/SVGLoader.cjs +0 -1712
  222. package/loaders/SVGLoader.js +0 -1712
  223. package/loaders/TDSLoader.cjs +0 -650
  224. package/loaders/TDSLoader.js +0 -650
  225. package/loaders/TGALoader.cjs +0 -285
  226. package/loaders/TGALoader.js +0 -285
  227. package/loaders/TTFLoader.cjs +0 -131
  228. package/loaders/TTFLoader.js +0 -131
  229. package/loaders/TiltLoader.cjs +0 -375
  230. package/loaders/TiltLoader.js +0 -375
  231. package/loaders/VOXLoader.cjs +0 -432
  232. package/loaders/VOXLoader.js +0 -432
  233. package/loaders/VRMLLoader.cjs +0 -2105
  234. package/loaders/VRMLLoader.js +0 -2105
  235. package/loaders/VRMLoader.cjs +0 -38
  236. package/loaders/VRMLoader.js +0 -38
  237. package/loaders/VTKLoader.cjs +0 -648
  238. package/loaders/VTKLoader.js +0 -648
  239. package/loaders/XLoader.cjs +0 -1258
  240. package/loaders/XLoader.js +0 -1258
  241. package/loaders/XYZLoader.cjs +0 -60
  242. package/loaders/XYZLoader.js +0 -60
  243. package/loaders/lwo/IFFParser.cjs +0 -743
  244. package/loaders/lwo/IFFParser.js +0 -743
  245. package/loaders/lwo/LWO2Parser.cjs +0 -312
  246. package/loaders/lwo/LWO2Parser.js +0 -312
  247. package/loaders/lwo/LWO3Parser.cjs +0 -282
  248. package/loaders/lwo/LWO3Parser.js +0 -282
  249. package/math/Capsule.cjs +0 -98
  250. package/math/Capsule.js +0 -98
  251. package/math/ColorConverter.cjs +0 -42
  252. package/math/ColorConverter.js +0 -42
  253. package/math/ConvexHull.cjs +0 -596
  254. package/math/ConvexHull.js +0 -596
  255. package/math/ImprovedNoise.cjs +0 -304
  256. package/math/ImprovedNoise.js +0 -304
  257. package/math/Lut.cjs +0 -137
  258. package/math/Lut.js +0 -137
  259. package/math/MeshSurfaceSampler.cjs +0 -103
  260. package/math/MeshSurfaceSampler.js +0 -103
  261. package/math/OBB.cjs +0 -242
  262. package/math/OBB.js +0 -242
  263. package/math/Octree.cjs +0 -273
  264. package/math/Octree.js +0 -273
  265. package/math/SimplexNoise.cjs +0 -440
  266. package/math/SimplexNoise.js +0 -440
  267. package/misc/ConvexObjectBreaker.cjs +0 -292
  268. package/misc/ConvexObjectBreaker.js +0 -292
  269. package/misc/GPUComputationRenderer.cjs +0 -205
  270. package/misc/GPUComputationRenderer.js +0 -205
  271. package/misc/Gyroscope.cjs +0 -33
  272. package/misc/Gyroscope.js +0 -33
  273. package/misc/MD2Character.cjs +0 -167
  274. package/misc/MD2Character.js +0 -167
  275. package/misc/MD2CharacterComplex.cjs +0 -332
  276. package/misc/MD2CharacterComplex.js +0 -332
  277. package/misc/MorphAnimMesh.cjs +0 -40
  278. package/misc/MorphAnimMesh.js +0 -40
  279. package/misc/MorphBlendMesh.cjs +0 -179
  280. package/misc/MorphBlendMesh.js +0 -179
  281. package/misc/ProgressiveLightmap.cjs +0 -186
  282. package/misc/ProgressiveLightmap.js +0 -186
  283. package/misc/RollerCoaster.cjs +0 -353
  284. package/misc/RollerCoaster.js +0 -353
  285. package/misc/Timer.cjs +0 -101
  286. package/misc/Timer.js +0 -101
  287. package/misc/TubePainter.cjs +0 -123
  288. package/misc/TubePainter.js +0 -123
  289. package/misc/Volume.cjs +0 -305
  290. package/misc/Volume.js +0 -305
  291. package/misc/VolumeSlice.cjs +0 -114
  292. package/misc/VolumeSlice.js +0 -114
  293. package/misc/WebGL.cjs +0 -74
  294. package/misc/WebGL.js +0 -74
  295. package/modifiers/CurveModifier.cjs +0 -232
  296. package/modifiers/CurveModifier.js +0 -232
  297. package/modifiers/EdgeSplitModifier.cjs +0 -167
  298. package/modifiers/EdgeSplitModifier.js +0 -168
  299. package/modifiers/SimplifyModifier.cjs +0 -301
  300. package/modifiers/SimplifyModifier.js +0 -301
  301. package/modifiers/TessellateModifier.cjs +0 -214
  302. package/modifiers/TessellateModifier.js +0 -214
  303. package/objects/GroundProjectedEnv.cjs +0 -134
  304. package/objects/GroundProjectedEnv.js +0 -134
  305. package/objects/Lensflare.cjs +0 -291
  306. package/objects/Lensflare.js +0 -291
  307. package/objects/LightningStorm.cjs +0 -110
  308. package/objects/LightningStorm.js +0 -110
  309. package/objects/MarchingCubes.cjs +0 -4809
  310. package/objects/MarchingCubes.js +0 -4809
  311. package/objects/Reflector.cjs +0 -202
  312. package/objects/Reflector.js +0 -202
  313. package/objects/ReflectorForSSRPass.cjs +0 -260
  314. package/objects/ReflectorForSSRPass.js +0 -260
  315. package/objects/ReflectorRTT.cjs +0 -10
  316. package/objects/ReflectorRTT.js +0 -10
  317. package/objects/Refractor.cjs +0 -215
  318. package/objects/Refractor.js +0 -215
  319. package/objects/ShadowMesh.cjs +0 -45
  320. package/objects/ShadowMesh.js +0 -45
  321. package/objects/Sky.cjs +0 -200
  322. package/objects/Sky.js +0 -200
  323. package/objects/Water.cjs +0 -242
  324. package/objects/Water.js +0 -242
  325. package/objects/Water2.cjs +0 -256
  326. package/objects/Water2.js +0 -256
  327. package/physics/AmmoPhysics.cjs +0 -166
  328. package/physics/AmmoPhysics.js +0 -166
  329. package/postprocessing/AdaptiveToneMappingPass.cjs +0 -218
  330. package/postprocessing/AdaptiveToneMappingPass.js +0 -218
  331. package/postprocessing/AfterimagePass.cjs +0 -68
  332. package/postprocessing/AfterimagePass.js +0 -68
  333. package/postprocessing/BloomPass.cjs +0 -109
  334. package/postprocessing/BloomPass.js +0 -109
  335. package/postprocessing/BokehPass.cjs +0 -90
  336. package/postprocessing/BokehPass.js +0 -90
  337. package/postprocessing/ClearPass.cjs +0 -36
  338. package/postprocessing/ClearPass.js +0 -36
  339. package/postprocessing/CubeTexturePass.cjs +0 -53
  340. package/postprocessing/CubeTexturePass.js +0 -53
  341. package/postprocessing/DotScreenPass.cjs +0 -49
  342. package/postprocessing/DotScreenPass.js +0 -49
  343. package/postprocessing/EffectComposer.cjs +0 -157
  344. package/postprocessing/EffectComposer.js +0 -157
  345. package/postprocessing/FilmPass.cjs +0 -51
  346. package/postprocessing/FilmPass.js +0 -51
  347. package/postprocessing/GlitchPass.cjs +0 -84
  348. package/postprocessing/GlitchPass.js +0 -84
  349. package/postprocessing/HalftonePass.cjs +0 -53
  350. package/postprocessing/HalftonePass.js +0 -53
  351. package/postprocessing/LUTPass.cjs +0 -142
  352. package/postprocessing/LUTPass.js +0 -142
  353. package/postprocessing/MaskPass.cjs +0 -69
  354. package/postprocessing/MaskPass.js +0 -69
  355. package/postprocessing/OutlinePass.cjs +0 -479
  356. package/postprocessing/OutlinePass.js +0 -479
  357. package/postprocessing/Pass.cjs +0 -48
  358. package/postprocessing/Pass.js +0 -48
  359. package/postprocessing/RenderPass.cjs +0 -59
  360. package/postprocessing/RenderPass.js +0 -59
  361. package/postprocessing/RenderPixelatedPass.cjs +0 -199
  362. package/postprocessing/RenderPixelatedPass.js +0 -199
  363. package/postprocessing/SAOPass.cjs +0 -288
  364. package/postprocessing/SAOPass.js +0 -288
  365. package/postprocessing/SMAAPass.cjs +0 -112
  366. package/postprocessing/SMAAPass.js +0 -112
  367. package/postprocessing/SSAARenderPass.cjs +0 -189
  368. package/postprocessing/SSAARenderPass.js +0 -189
  369. package/postprocessing/SSAOPass.cjs +0 -272
  370. package/postprocessing/SSAOPass.js +0 -272
  371. package/postprocessing/SSRPass.cjs +0 -411
  372. package/postprocessing/SSRPass.js +0 -411
  373. package/postprocessing/SavePass.cjs +0 -38
  374. package/postprocessing/SavePass.js +0 -38
  375. package/postprocessing/ShaderPass.cjs +0 -49
  376. package/postprocessing/ShaderPass.js +0 -49
  377. package/postprocessing/TAARenderPass.cjs +0 -174
  378. package/postprocessing/TAARenderPass.js +0 -174
  379. package/postprocessing/TexturePass.cjs +0 -42
  380. package/postprocessing/TexturePass.js +0 -42
  381. package/postprocessing/UnrealBloomPass.cjs +0 -277
  382. package/postprocessing/UnrealBloomPass.js +0 -277
  383. package/postprocessing/WaterPass.cjs +0 -72
  384. package/postprocessing/WaterPass.js +0 -72
  385. package/renderers/CSS2DRenderer.cjs +0 -122
  386. package/renderers/CSS2DRenderer.js +0 -122
  387. package/renderers/CSS3DRenderer.cjs +0 -167
  388. package/renderers/CSS3DRenderer.js +0 -167
  389. package/renderers/Projector.cjs +0 -499
  390. package/renderers/Projector.js +0 -499
  391. package/renderers/SVGRenderer.cjs +0 -311
  392. package/renderers/SVGRenderer.js +0 -311
  393. package/shaders/ACESFilmicToneMappingShader.cjs +0 -55
  394. package/shaders/ACESFilmicToneMappingShader.js +0 -55
  395. package/shaders/AfterimageShader.cjs +0 -32
  396. package/shaders/AfterimageShader.js +0 -32
  397. package/shaders/BasicShader.cjs +0 -12
  398. package/shaders/BasicShader.js +0 -12
  399. package/shaders/BleachBypassShader.cjs +0 -35
  400. package/shaders/BleachBypassShader.js +0 -35
  401. package/shaders/BlendShader.cjs +0 -30
  402. package/shaders/BlendShader.js +0 -30
  403. package/shaders/BokehShader.cjs +0 -109
  404. package/shaders/BokehShader.js +0 -109
  405. package/shaders/BokehShader2.cjs +0 -269
  406. package/shaders/BokehShader2.js +0 -269
  407. package/shaders/BrightnessContrastShader.cjs +0 -32
  408. package/shaders/BrightnessContrastShader.js +0 -32
  409. package/shaders/ColorCorrectionShader.cjs +0 -30
  410. package/shaders/ColorCorrectionShader.js +0 -30
  411. package/shaders/ColorifyShader.cjs +0 -28
  412. package/shaders/ColorifyShader.js +0 -28
  413. package/shaders/ConvolutionShader.cjs +0 -55
  414. package/shaders/ConvolutionShader.js +0 -55
  415. package/shaders/CopyShader.cjs +0 -25
  416. package/shaders/CopyShader.js +0 -25
  417. package/shaders/DOFMipMapShader.cjs +0 -32
  418. package/shaders/DOFMipMapShader.js +0 -32
  419. package/shaders/DepthLimitedBlurShader.cjs +0 -114
  420. package/shaders/DepthLimitedBlurShader.js +0 -114
  421. package/shaders/DigitalGlitch.cjs +0 -85
  422. package/shaders/DigitalGlitch.js +0 -85
  423. package/shaders/DotScreenShader.cjs +0 -39
  424. package/shaders/DotScreenShader.js +0 -39
  425. package/shaders/FXAAShader.cjs +0 -1098
  426. package/shaders/FXAAShader.js +0 -1098
  427. package/shaders/FilmShader.cjs +0 -53
  428. package/shaders/FilmShader.js +0 -53
  429. package/shaders/FocusShader.cjs +0 -55
  430. package/shaders/FocusShader.js +0 -55
  431. package/shaders/FreiChenShader.cjs +0 -64
  432. package/shaders/FreiChenShader.js +0 -64
  433. package/shaders/FresnelShader.cjs +0 -47
  434. package/shaders/FresnelShader.js +0 -47
  435. package/shaders/GammaCorrectionShader.cjs +0 -23
  436. package/shaders/GammaCorrectionShader.js +0 -23
  437. package/shaders/GodRaysShader.cjs +0 -183
  438. package/shaders/GodRaysShader.js +0 -183
  439. package/shaders/HalftoneShader.cjs +0 -228
  440. package/shaders/HalftoneShader.js +0 -228
  441. package/shaders/HorizontalBlurShader.cjs +0 -49
  442. package/shaders/HorizontalBlurShader.js +0 -49
  443. package/shaders/HorizontalTiltShiftShader.cjs +0 -37
  444. package/shaders/HorizontalTiltShiftShader.js +0 -37
  445. package/shaders/HueSaturationShader.cjs +0 -43
  446. package/shaders/HueSaturationShader.js +0 -43
  447. package/shaders/KaleidoShader.cjs +0 -34
  448. package/shaders/KaleidoShader.js +0 -34
  449. package/shaders/LuminosityHighPassShader.cjs +0 -37
  450. package/shaders/LuminosityHighPassShader.js +0 -37
  451. package/shaders/LuminosityShader.cjs +0 -25
  452. package/shaders/LuminosityShader.js +0 -25
  453. package/shaders/MirrorShader.cjs +0 -35
  454. package/shaders/MirrorShader.js +0 -35
  455. package/shaders/NormalMapShader.cjs +0 -31
  456. package/shaders/NormalMapShader.js +0 -31
  457. package/shaders/ParallaxShader.cjs +0 -133
  458. package/shaders/ParallaxShader.js +0 -133
  459. package/shaders/PixelShader.cjs +0 -28
  460. package/shaders/PixelShader.js +0 -28
  461. package/shaders/RGBShiftShader.cjs +0 -30
  462. package/shaders/RGBShiftShader.js +0 -30
  463. package/shaders/SAOShader.cjs +0 -144
  464. package/shaders/SAOShader.js +0 -144
  465. package/shaders/SMAAShader.cjs +0 -358
  466. package/shaders/SMAAShader.js +0 -358
  467. package/shaders/SSAOShader.cjs +0 -182
  468. package/shaders/SSAOShader.js +0 -182
  469. package/shaders/SSRShader.cjs +0 -342
  470. package/shaders/SSRShader.js +0 -342
  471. package/shaders/SepiaShader.cjs +0 -29
  472. package/shaders/SepiaShader.js +0 -29
  473. package/shaders/SobelOperatorShader.cjs +0 -54
  474. package/shaders/SobelOperatorShader.js +0 -54
  475. package/shaders/SubsurfaceScatteringShader.cjs +0 -98
  476. package/shaders/SubsurfaceScatteringShader.js +0 -98
  477. package/shaders/TechnicolorShader.cjs +0 -24
  478. package/shaders/TechnicolorShader.js +0 -24
  479. package/shaders/ToneMapShader.cjs +0 -51
  480. package/shaders/ToneMapShader.js +0 -51
  481. package/shaders/ToonShader.cjs +0 -188
  482. package/shaders/ToonShader.js +0 -188
  483. package/shaders/TriangleBlurShader.cjs +0 -37
  484. package/shaders/TriangleBlurShader.js +0 -37
  485. package/shaders/UnpackDepthRGBAShader.cjs +0 -26
  486. package/shaders/UnpackDepthRGBAShader.js +0 -26
  487. package/shaders/VerticalBlurShader.cjs +0 -50
  488. package/shaders/VerticalBlurShader.js +0 -50
  489. package/shaders/VerticalTiltShiftShader.cjs +0 -37
  490. package/shaders/VerticalTiltShiftShader.js +0 -37
  491. package/shaders/VignetteShader.cjs +0 -38
  492. package/shaders/VignetteShader.js +0 -38
  493. package/shaders/VolumeShader.cjs +0 -225
  494. package/shaders/VolumeShader.js +0 -225
  495. package/shaders/WaterRefractionShader.cjs +0 -59
  496. package/shaders/WaterRefractionShader.js +0 -59
  497. package/shaders/types.cjs +0 -1
  498. package/shaders/types.js +0 -1
  499. package/textures/FlakesTexture.cjs +0 -30
  500. package/textures/FlakesTexture.js +0 -30
  501. package/types/helpers.cjs +0 -4
  502. package/types/helpers.js +0 -4
  503. package/utils/BufferGeometryUtils.cjs +0 -636
  504. package/utils/BufferGeometryUtils.js +0 -636
  505. package/utils/GeometryCompressionUtils.cjs +0 -573
  506. package/utils/GeometryCompressionUtils.js +0 -573
  507. package/utils/GeometryUtils.cjs +0 -109
  508. package/utils/GeometryUtils.js +0 -109
  509. package/utils/RoughnessMipmapper.cjs +0 -223
  510. package/utils/RoughnessMipmapper.js +0 -223
  511. package/utils/SceneUtils.cjs +0 -36
  512. package/utils/SceneUtils.js +0 -36
  513. package/utils/ShadowMapViewer.cjs +0 -111
  514. package/utils/ShadowMapViewer.js +0 -111
  515. package/utils/SkeletonUtils.cjs +0 -211
  516. package/utils/SkeletonUtils.js +0 -211
  517. package/utils/UVsDebug.cjs +0 -80
  518. package/utils/UVsDebug.js +0 -80
  519. package/utils/WorkerPool.cjs +0 -62
  520. package/utils/WorkerPool.js +0 -62
  521. package/webxr/ARButton.cjs +0 -119
  522. package/webxr/ARButton.js +0 -119
  523. package/webxr/OculusHandModel.cjs +0 -82
  524. package/webxr/OculusHandModel.js +0 -82
  525. package/webxr/OculusHandPointerModel.cjs +0 -241
  526. package/webxr/OculusHandPointerModel.js +0 -224
  527. package/webxr/Text2D.cjs +0 -48
  528. package/webxr/Text2D.js +0 -31
  529. package/webxr/VRButton.cjs +0 -111
  530. package/webxr/VRButton.js +0 -111
  531. package/webxr/XRControllerModelFactory.cjs +0 -174
  532. package/webxr/XRControllerModelFactory.js +0 -174
  533. package/webxr/XREstimatedLight.cjs +0 -126
  534. package/webxr/XREstimatedLight.js +0 -126
  535. package/webxr/XRHandMeshModel.cjs +0 -82
  536. package/webxr/XRHandMeshModel.js +0 -82
  537. package/webxr/XRHandModelFactory.cjs +0 -61
  538. package/webxr/XRHandModelFactory.js +0 -61
  539. package/webxr/XRHandPrimitiveModel.cjs +0 -68
  540. package/webxr/XRHandPrimitiveModel.js +0 -68
@@ -1,2405 +0,0 @@
1
- import { Loader, LoaderUtils, FileLoader, MathUtils, Vector3, Quaternion, VectorKeyframeTrack, QuaternionKeyframeTrack, AnimationClip, Matrix4, MeshBasicMaterial, MeshLambertMaterial, MeshPhongMaterial, RepeatWrapping, ClampToEdgeWrapping, Vector2, DoubleSide, FrontSide, PerspectiveCamera, OrthographicCamera, Color, AmbientLight, SpotLight, PointLight, DirectionalLight, BufferGeometry, Float32BufferAttribute, Skeleton, Bone, Group, LineBasicMaterial, SkinnedMesh, Mesh, Line, LineSegments, Scene, TextureLoader, Euler } from "three";
2
- import { TGALoader } from "./TGALoader.js";
3
- class ColladaLoader extends Loader {
4
- constructor(manager) {
5
- super(manager);
6
- }
7
- load(url, onLoad, onProgress, onError) {
8
- const scope = this;
9
- const path = scope.path === "" ? LoaderUtils.extractUrlBase(url) : scope.path;
10
- const loader = new FileLoader(scope.manager);
11
- loader.setPath(scope.path);
12
- loader.setRequestHeader(scope.requestHeader);
13
- loader.setWithCredentials(scope.withCredentials);
14
- loader.load(
15
- url,
16
- function(text) {
17
- try {
18
- onLoad(scope.parse(text, path));
19
- } catch (e) {
20
- if (onError) {
21
- onError(e);
22
- } else {
23
- console.error(e);
24
- }
25
- scope.manager.itemError(url);
26
- }
27
- },
28
- onProgress,
29
- onError
30
- );
31
- }
32
- parse(text, path) {
33
- function getElementsByTagName(xml2, name) {
34
- const array = [];
35
- const childNodes = xml2.childNodes;
36
- for (let i = 0, l = childNodes.length; i < l; i++) {
37
- const child = childNodes[i];
38
- if (child.nodeName === name) {
39
- array.push(child);
40
- }
41
- }
42
- return array;
43
- }
44
- function parseStrings(text2) {
45
- if (text2.length === 0)
46
- return [];
47
- const parts = text2.trim().split(/\s+/);
48
- const array = new Array(parts.length);
49
- for (let i = 0, l = parts.length; i < l; i++) {
50
- array[i] = parts[i];
51
- }
52
- return array;
53
- }
54
- function parseFloats(text2) {
55
- if (text2.length === 0)
56
- return [];
57
- const parts = text2.trim().split(/\s+/);
58
- const array = new Array(parts.length);
59
- for (let i = 0, l = parts.length; i < l; i++) {
60
- array[i] = parseFloat(parts[i]);
61
- }
62
- return array;
63
- }
64
- function parseInts(text2) {
65
- if (text2.length === 0)
66
- return [];
67
- const parts = text2.trim().split(/\s+/);
68
- const array = new Array(parts.length);
69
- for (let i = 0, l = parts.length; i < l; i++) {
70
- array[i] = parseInt(parts[i]);
71
- }
72
- return array;
73
- }
74
- function parseId(text2) {
75
- return text2.substring(1);
76
- }
77
- function generateId() {
78
- return "three_default_" + count++;
79
- }
80
- function isEmpty(object) {
81
- return Object.keys(object).length === 0;
82
- }
83
- function parseAsset(xml2) {
84
- return {
85
- unit: parseAssetUnit(getElementsByTagName(xml2, "unit")[0]),
86
- upAxis: parseAssetUpAxis(getElementsByTagName(xml2, "up_axis")[0])
87
- };
88
- }
89
- function parseAssetUnit(xml2) {
90
- if (xml2 !== void 0 && xml2.hasAttribute("meter") === true) {
91
- return parseFloat(xml2.getAttribute("meter"));
92
- } else {
93
- return 1;
94
- }
95
- }
96
- function parseAssetUpAxis(xml2) {
97
- return xml2 !== void 0 ? xml2.textContent : "Y_UP";
98
- }
99
- function parseLibrary(xml2, libraryName, nodeName, parser) {
100
- const library2 = getElementsByTagName(xml2, libraryName)[0];
101
- if (library2 !== void 0) {
102
- const elements = getElementsByTagName(library2, nodeName);
103
- for (let i = 0; i < elements.length; i++) {
104
- parser(elements[i]);
105
- }
106
- }
107
- }
108
- function buildLibrary(data, builder) {
109
- for (const name in data) {
110
- const object = data[name];
111
- object.build = builder(data[name]);
112
- }
113
- }
114
- function getBuild(data, builder) {
115
- if (data.build !== void 0)
116
- return data.build;
117
- data.build = builder(data);
118
- return data.build;
119
- }
120
- function parseAnimation(xml2) {
121
- const data = {
122
- sources: {},
123
- samplers: {},
124
- channels: {}
125
- };
126
- let hasChildren = false;
127
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
128
- const child = xml2.childNodes[i];
129
- if (child.nodeType !== 1)
130
- continue;
131
- let id;
132
- switch (child.nodeName) {
133
- case "source":
134
- id = child.getAttribute("id");
135
- data.sources[id] = parseSource(child);
136
- break;
137
- case "sampler":
138
- id = child.getAttribute("id");
139
- data.samplers[id] = parseAnimationSampler(child);
140
- break;
141
- case "channel":
142
- id = child.getAttribute("target");
143
- data.channels[id] = parseAnimationChannel(child);
144
- break;
145
- case "animation":
146
- parseAnimation(child);
147
- hasChildren = true;
148
- break;
149
- default:
150
- console.log(child);
151
- }
152
- }
153
- if (hasChildren === false) {
154
- library.animations[xml2.getAttribute("id") || MathUtils.generateUUID()] = data;
155
- }
156
- }
157
- function parseAnimationSampler(xml2) {
158
- const data = {
159
- inputs: {}
160
- };
161
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
162
- const child = xml2.childNodes[i];
163
- if (child.nodeType !== 1)
164
- continue;
165
- switch (child.nodeName) {
166
- case "input":
167
- const id = parseId(child.getAttribute("source"));
168
- const semantic = child.getAttribute("semantic");
169
- data.inputs[semantic] = id;
170
- break;
171
- }
172
- }
173
- return data;
174
- }
175
- function parseAnimationChannel(xml2) {
176
- const data = {};
177
- const target = xml2.getAttribute("target");
178
- let parts = target.split("/");
179
- const id = parts.shift();
180
- let sid = parts.shift();
181
- const arraySyntax = sid.indexOf("(") !== -1;
182
- const memberSyntax = sid.indexOf(".") !== -1;
183
- if (memberSyntax) {
184
- parts = sid.split(".");
185
- sid = parts.shift();
186
- data.member = parts.shift();
187
- } else if (arraySyntax) {
188
- const indices = sid.split("(");
189
- sid = indices.shift();
190
- for (let i = 0; i < indices.length; i++) {
191
- indices[i] = parseInt(indices[i].replace(/\)/, ""));
192
- }
193
- data.indices = indices;
194
- }
195
- data.id = id;
196
- data.sid = sid;
197
- data.arraySyntax = arraySyntax;
198
- data.memberSyntax = memberSyntax;
199
- data.sampler = parseId(xml2.getAttribute("source"));
200
- return data;
201
- }
202
- function buildAnimation(data) {
203
- const tracks = [];
204
- const channels = data.channels;
205
- const samplers = data.samplers;
206
- const sources = data.sources;
207
- for (const target in channels) {
208
- if (channels.hasOwnProperty(target)) {
209
- const channel = channels[target];
210
- const sampler = samplers[channel.sampler];
211
- const inputId = sampler.inputs.INPUT;
212
- const outputId = sampler.inputs.OUTPUT;
213
- const inputSource = sources[inputId];
214
- const outputSource = sources[outputId];
215
- const animation = buildAnimationChannel(channel, inputSource, outputSource);
216
- createKeyframeTracks(animation, tracks);
217
- }
218
- }
219
- return tracks;
220
- }
221
- function getAnimation(id) {
222
- return getBuild(library.animations[id], buildAnimation);
223
- }
224
- function buildAnimationChannel(channel, inputSource, outputSource) {
225
- const node = library.nodes[channel.id];
226
- const object3D = getNode(node.id);
227
- const transform = node.transforms[channel.sid];
228
- const defaultMatrix = node.matrix.clone().transpose();
229
- let time, stride;
230
- let i, il, j, jl;
231
- const data = {};
232
- switch (transform) {
233
- case "matrix":
234
- for (i = 0, il = inputSource.array.length; i < il; i++) {
235
- time = inputSource.array[i];
236
- stride = i * outputSource.stride;
237
- if (data[time] === void 0)
238
- data[time] = {};
239
- if (channel.arraySyntax === true) {
240
- const value = outputSource.array[stride];
241
- const index = channel.indices[0] + 4 * channel.indices[1];
242
- data[time][index] = value;
243
- } else {
244
- for (j = 0, jl = outputSource.stride; j < jl; j++) {
245
- data[time][j] = outputSource.array[stride + j];
246
- }
247
- }
248
- }
249
- break;
250
- case "translate":
251
- console.warn('THREE.ColladaLoader: Animation transform type "%s" not yet implemented.', transform);
252
- break;
253
- case "rotate":
254
- console.warn('THREE.ColladaLoader: Animation transform type "%s" not yet implemented.', transform);
255
- break;
256
- case "scale":
257
- console.warn('THREE.ColladaLoader: Animation transform type "%s" not yet implemented.', transform);
258
- break;
259
- }
260
- const keyframes = prepareAnimationData(data, defaultMatrix);
261
- const animation = {
262
- name: object3D.uuid,
263
- keyframes
264
- };
265
- return animation;
266
- }
267
- function prepareAnimationData(data, defaultMatrix) {
268
- const keyframes = [];
269
- for (const time in data) {
270
- keyframes.push({ time: parseFloat(time), value: data[time] });
271
- }
272
- keyframes.sort(ascending);
273
- for (let i = 0; i < 16; i++) {
274
- transformAnimationData(keyframes, i, defaultMatrix.elements[i]);
275
- }
276
- return keyframes;
277
- function ascending(a, b) {
278
- return a.time - b.time;
279
- }
280
- }
281
- const position = new Vector3();
282
- const scale = new Vector3();
283
- const quaternion = new Quaternion();
284
- function createKeyframeTracks(animation, tracks) {
285
- const keyframes = animation.keyframes;
286
- const name = animation.name;
287
- const times = [];
288
- const positionData = [];
289
- const quaternionData = [];
290
- const scaleData = [];
291
- for (let i = 0, l = keyframes.length; i < l; i++) {
292
- const keyframe = keyframes[i];
293
- const time = keyframe.time;
294
- const value = keyframe.value;
295
- matrix.fromArray(value).transpose();
296
- matrix.decompose(position, quaternion, scale);
297
- times.push(time);
298
- positionData.push(position.x, position.y, position.z);
299
- quaternionData.push(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
300
- scaleData.push(scale.x, scale.y, scale.z);
301
- }
302
- if (positionData.length > 0)
303
- tracks.push(new VectorKeyframeTrack(name + ".position", times, positionData));
304
- if (quaternionData.length > 0) {
305
- tracks.push(new QuaternionKeyframeTrack(name + ".quaternion", times, quaternionData));
306
- }
307
- if (scaleData.length > 0)
308
- tracks.push(new VectorKeyframeTrack(name + ".scale", times, scaleData));
309
- return tracks;
310
- }
311
- function transformAnimationData(keyframes, property, defaultValue) {
312
- let keyframe;
313
- let empty = true;
314
- let i, l;
315
- for (i = 0, l = keyframes.length; i < l; i++) {
316
- keyframe = keyframes[i];
317
- if (keyframe.value[property] === void 0) {
318
- keyframe.value[property] = null;
319
- } else {
320
- empty = false;
321
- }
322
- }
323
- if (empty === true) {
324
- for (i = 0, l = keyframes.length; i < l; i++) {
325
- keyframe = keyframes[i];
326
- keyframe.value[property] = defaultValue;
327
- }
328
- } else {
329
- createMissingKeyframes(keyframes, property);
330
- }
331
- }
332
- function createMissingKeyframes(keyframes, property) {
333
- let prev, next;
334
- for (let i = 0, l = keyframes.length; i < l; i++) {
335
- const keyframe = keyframes[i];
336
- if (keyframe.value[property] === null) {
337
- prev = getPrev(keyframes, i, property);
338
- next = getNext(keyframes, i, property);
339
- if (prev === null) {
340
- keyframe.value[property] = next.value[property];
341
- continue;
342
- }
343
- if (next === null) {
344
- keyframe.value[property] = prev.value[property];
345
- continue;
346
- }
347
- interpolate(keyframe, prev, next, property);
348
- }
349
- }
350
- }
351
- function getPrev(keyframes, i, property) {
352
- while (i >= 0) {
353
- const keyframe = keyframes[i];
354
- if (keyframe.value[property] !== null)
355
- return keyframe;
356
- i--;
357
- }
358
- return null;
359
- }
360
- function getNext(keyframes, i, property) {
361
- while (i < keyframes.length) {
362
- const keyframe = keyframes[i];
363
- if (keyframe.value[property] !== null)
364
- return keyframe;
365
- i++;
366
- }
367
- return null;
368
- }
369
- function interpolate(key, prev, next, property) {
370
- if (next.time - prev.time === 0) {
371
- key.value[property] = prev.value[property];
372
- return;
373
- }
374
- key.value[property] = (key.time - prev.time) * (next.value[property] - prev.value[property]) / (next.time - prev.time) + prev.value[property];
375
- }
376
- function parseAnimationClip(xml2) {
377
- const data = {
378
- name: xml2.getAttribute("id") || "default",
379
- start: parseFloat(xml2.getAttribute("start") || 0),
380
- end: parseFloat(xml2.getAttribute("end") || 0),
381
- animations: []
382
- };
383
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
384
- const child = xml2.childNodes[i];
385
- if (child.nodeType !== 1)
386
- continue;
387
- switch (child.nodeName) {
388
- case "instance_animation":
389
- data.animations.push(parseId(child.getAttribute("url")));
390
- break;
391
- }
392
- }
393
- library.clips[xml2.getAttribute("id")] = data;
394
- }
395
- function buildAnimationClip(data) {
396
- const tracks = [];
397
- const name = data.name;
398
- const duration = data.end - data.start || -1;
399
- const animations2 = data.animations;
400
- for (let i = 0, il = animations2.length; i < il; i++) {
401
- const animationTracks = getAnimation(animations2[i]);
402
- for (let j = 0, jl = animationTracks.length; j < jl; j++) {
403
- tracks.push(animationTracks[j]);
404
- }
405
- }
406
- return new AnimationClip(name, duration, tracks);
407
- }
408
- function getAnimationClip(id) {
409
- return getBuild(library.clips[id], buildAnimationClip);
410
- }
411
- function parseController(xml2) {
412
- const data = {};
413
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
414
- const child = xml2.childNodes[i];
415
- if (child.nodeType !== 1)
416
- continue;
417
- switch (child.nodeName) {
418
- case "skin":
419
- data.id = parseId(child.getAttribute("source"));
420
- data.skin = parseSkin(child);
421
- break;
422
- case "morph":
423
- data.id = parseId(child.getAttribute("source"));
424
- console.warn("THREE.ColladaLoader: Morph target animation not supported yet.");
425
- break;
426
- }
427
- }
428
- library.controllers[xml2.getAttribute("id")] = data;
429
- }
430
- function parseSkin(xml2) {
431
- const data = {
432
- sources: {}
433
- };
434
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
435
- const child = xml2.childNodes[i];
436
- if (child.nodeType !== 1)
437
- continue;
438
- switch (child.nodeName) {
439
- case "bind_shape_matrix":
440
- data.bindShapeMatrix = parseFloats(child.textContent);
441
- break;
442
- case "source":
443
- const id = child.getAttribute("id");
444
- data.sources[id] = parseSource(child);
445
- break;
446
- case "joints":
447
- data.joints = parseJoints(child);
448
- break;
449
- case "vertex_weights":
450
- data.vertexWeights = parseVertexWeights(child);
451
- break;
452
- }
453
- }
454
- return data;
455
- }
456
- function parseJoints(xml2) {
457
- const data = {
458
- inputs: {}
459
- };
460
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
461
- const child = xml2.childNodes[i];
462
- if (child.nodeType !== 1)
463
- continue;
464
- switch (child.nodeName) {
465
- case "input":
466
- const semantic = child.getAttribute("semantic");
467
- const id = parseId(child.getAttribute("source"));
468
- data.inputs[semantic] = id;
469
- break;
470
- }
471
- }
472
- return data;
473
- }
474
- function parseVertexWeights(xml2) {
475
- const data = {
476
- inputs: {}
477
- };
478
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
479
- const child = xml2.childNodes[i];
480
- if (child.nodeType !== 1)
481
- continue;
482
- switch (child.nodeName) {
483
- case "input":
484
- const semantic = child.getAttribute("semantic");
485
- const id = parseId(child.getAttribute("source"));
486
- const offset = parseInt(child.getAttribute("offset"));
487
- data.inputs[semantic] = { id, offset };
488
- break;
489
- case "vcount":
490
- data.vcount = parseInts(child.textContent);
491
- break;
492
- case "v":
493
- data.v = parseInts(child.textContent);
494
- break;
495
- }
496
- }
497
- return data;
498
- }
499
- function buildController(data) {
500
- const build = {
501
- id: data.id
502
- };
503
- const geometry = library.geometries[build.id];
504
- if (data.skin !== void 0) {
505
- build.skin = buildSkin(data.skin);
506
- geometry.sources.skinIndices = build.skin.indices;
507
- geometry.sources.skinWeights = build.skin.weights;
508
- }
509
- return build;
510
- }
511
- function buildSkin(data) {
512
- const BONE_LIMIT = 4;
513
- const build = {
514
- joints: [],
515
- // this must be an array to preserve the joint order
516
- indices: {
517
- array: [],
518
- stride: BONE_LIMIT
519
- },
520
- weights: {
521
- array: [],
522
- stride: BONE_LIMIT
523
- }
524
- };
525
- const sources = data.sources;
526
- const vertexWeights = data.vertexWeights;
527
- const vcount = vertexWeights.vcount;
528
- const v = vertexWeights.v;
529
- const jointOffset = vertexWeights.inputs.JOINT.offset;
530
- const weightOffset = vertexWeights.inputs.WEIGHT.offset;
531
- const jointSource = data.sources[data.joints.inputs.JOINT];
532
- const inverseSource = data.sources[data.joints.inputs.INV_BIND_MATRIX];
533
- const weights = sources[vertexWeights.inputs.WEIGHT.id].array;
534
- let stride = 0;
535
- let i, j, l;
536
- for (i = 0, l = vcount.length; i < l; i++) {
537
- const jointCount = vcount[i];
538
- const vertexSkinData = [];
539
- for (j = 0; j < jointCount; j++) {
540
- const skinIndex = v[stride + jointOffset];
541
- const weightId = v[stride + weightOffset];
542
- const skinWeight = weights[weightId];
543
- vertexSkinData.push({ index: skinIndex, weight: skinWeight });
544
- stride += 2;
545
- }
546
- vertexSkinData.sort(descending);
547
- for (j = 0; j < BONE_LIMIT; j++) {
548
- const d = vertexSkinData[j];
549
- if (d !== void 0) {
550
- build.indices.array.push(d.index);
551
- build.weights.array.push(d.weight);
552
- } else {
553
- build.indices.array.push(0);
554
- build.weights.array.push(0);
555
- }
556
- }
557
- }
558
- if (data.bindShapeMatrix) {
559
- build.bindMatrix = new Matrix4().fromArray(data.bindShapeMatrix).transpose();
560
- } else {
561
- build.bindMatrix = new Matrix4().identity();
562
- }
563
- for (i = 0, l = jointSource.array.length; i < l; i++) {
564
- const name = jointSource.array[i];
565
- const boneInverse = new Matrix4().fromArray(inverseSource.array, i * inverseSource.stride).transpose();
566
- build.joints.push({ name, boneInverse });
567
- }
568
- return build;
569
- function descending(a, b) {
570
- return b.weight - a.weight;
571
- }
572
- }
573
- function getController(id) {
574
- return getBuild(library.controllers[id], buildController);
575
- }
576
- function parseImage(xml2) {
577
- const data = {
578
- init_from: getElementsByTagName(xml2, "init_from")[0].textContent
579
- };
580
- library.images[xml2.getAttribute("id")] = data;
581
- }
582
- function buildImage(data) {
583
- if (data.build !== void 0)
584
- return data.build;
585
- return data.init_from;
586
- }
587
- function getImage(id) {
588
- const data = library.images[id];
589
- if (data !== void 0) {
590
- return getBuild(data, buildImage);
591
- }
592
- console.warn("THREE.ColladaLoader: Couldn't find image with ID:", id);
593
- return null;
594
- }
595
- function parseEffect(xml2) {
596
- const data = {};
597
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
598
- const child = xml2.childNodes[i];
599
- if (child.nodeType !== 1)
600
- continue;
601
- switch (child.nodeName) {
602
- case "profile_COMMON":
603
- data.profile = parseEffectProfileCOMMON(child);
604
- break;
605
- }
606
- }
607
- library.effects[xml2.getAttribute("id")] = data;
608
- }
609
- function parseEffectProfileCOMMON(xml2) {
610
- const data = {
611
- surfaces: {},
612
- samplers: {}
613
- };
614
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
615
- const child = xml2.childNodes[i];
616
- if (child.nodeType !== 1)
617
- continue;
618
- switch (child.nodeName) {
619
- case "newparam":
620
- parseEffectNewparam(child, data);
621
- break;
622
- case "technique":
623
- data.technique = parseEffectTechnique(child);
624
- break;
625
- case "extra":
626
- data.extra = parseEffectExtra(child);
627
- break;
628
- }
629
- }
630
- return data;
631
- }
632
- function parseEffectNewparam(xml2, data) {
633
- const sid = xml2.getAttribute("sid");
634
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
635
- const child = xml2.childNodes[i];
636
- if (child.nodeType !== 1)
637
- continue;
638
- switch (child.nodeName) {
639
- case "surface":
640
- data.surfaces[sid] = parseEffectSurface(child);
641
- break;
642
- case "sampler2D":
643
- data.samplers[sid] = parseEffectSampler(child);
644
- break;
645
- }
646
- }
647
- }
648
- function parseEffectSurface(xml2) {
649
- const data = {};
650
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
651
- const child = xml2.childNodes[i];
652
- if (child.nodeType !== 1)
653
- continue;
654
- switch (child.nodeName) {
655
- case "init_from":
656
- data.init_from = child.textContent;
657
- break;
658
- }
659
- }
660
- return data;
661
- }
662
- function parseEffectSampler(xml2) {
663
- const data = {};
664
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
665
- const child = xml2.childNodes[i];
666
- if (child.nodeType !== 1)
667
- continue;
668
- switch (child.nodeName) {
669
- case "source":
670
- data.source = child.textContent;
671
- break;
672
- }
673
- }
674
- return data;
675
- }
676
- function parseEffectTechnique(xml2) {
677
- const data = {};
678
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
679
- const child = xml2.childNodes[i];
680
- if (child.nodeType !== 1)
681
- continue;
682
- switch (child.nodeName) {
683
- case "constant":
684
- case "lambert":
685
- case "blinn":
686
- case "phong":
687
- data.type = child.nodeName;
688
- data.parameters = parseEffectParameters(child);
689
- break;
690
- case "extra":
691
- data.extra = parseEffectExtra(child);
692
- break;
693
- }
694
- }
695
- return data;
696
- }
697
- function parseEffectParameters(xml2) {
698
- const data = {};
699
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
700
- const child = xml2.childNodes[i];
701
- if (child.nodeType !== 1)
702
- continue;
703
- switch (child.nodeName) {
704
- case "emission":
705
- case "diffuse":
706
- case "specular":
707
- case "bump":
708
- case "ambient":
709
- case "shininess":
710
- case "transparency":
711
- data[child.nodeName] = parseEffectParameter(child);
712
- break;
713
- case "transparent":
714
- data[child.nodeName] = {
715
- opaque: child.hasAttribute("opaque") ? child.getAttribute("opaque") : "A_ONE",
716
- data: parseEffectParameter(child)
717
- };
718
- break;
719
- }
720
- }
721
- return data;
722
- }
723
- function parseEffectParameter(xml2) {
724
- const data = {};
725
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
726
- const child = xml2.childNodes[i];
727
- if (child.nodeType !== 1)
728
- continue;
729
- switch (child.nodeName) {
730
- case "color":
731
- data[child.nodeName] = parseFloats(child.textContent);
732
- break;
733
- case "float":
734
- data[child.nodeName] = parseFloat(child.textContent);
735
- break;
736
- case "texture":
737
- data[child.nodeName] = { id: child.getAttribute("texture"), extra: parseEffectParameterTexture(child) };
738
- break;
739
- }
740
- }
741
- return data;
742
- }
743
- function parseEffectParameterTexture(xml2) {
744
- const data = {
745
- technique: {}
746
- };
747
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
748
- const child = xml2.childNodes[i];
749
- if (child.nodeType !== 1)
750
- continue;
751
- switch (child.nodeName) {
752
- case "extra":
753
- parseEffectParameterTextureExtra(child, data);
754
- break;
755
- }
756
- }
757
- return data;
758
- }
759
- function parseEffectParameterTextureExtra(xml2, data) {
760
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
761
- const child = xml2.childNodes[i];
762
- if (child.nodeType !== 1)
763
- continue;
764
- switch (child.nodeName) {
765
- case "technique":
766
- parseEffectParameterTextureExtraTechnique(child, data);
767
- break;
768
- }
769
- }
770
- }
771
- function parseEffectParameterTextureExtraTechnique(xml2, data) {
772
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
773
- const child = xml2.childNodes[i];
774
- if (child.nodeType !== 1)
775
- continue;
776
- switch (child.nodeName) {
777
- case "repeatU":
778
- case "repeatV":
779
- case "offsetU":
780
- case "offsetV":
781
- data.technique[child.nodeName] = parseFloat(child.textContent);
782
- break;
783
- case "wrapU":
784
- case "wrapV":
785
- if (child.textContent.toUpperCase() === "TRUE") {
786
- data.technique[child.nodeName] = 1;
787
- } else if (child.textContent.toUpperCase() === "FALSE") {
788
- data.technique[child.nodeName] = 0;
789
- } else {
790
- data.technique[child.nodeName] = parseInt(child.textContent);
791
- }
792
- break;
793
- case "bump":
794
- data[child.nodeName] = parseEffectExtraTechniqueBump(child);
795
- break;
796
- }
797
- }
798
- }
799
- function parseEffectExtra(xml2) {
800
- const data = {};
801
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
802
- const child = xml2.childNodes[i];
803
- if (child.nodeType !== 1)
804
- continue;
805
- switch (child.nodeName) {
806
- case "technique":
807
- data.technique = parseEffectExtraTechnique(child);
808
- break;
809
- }
810
- }
811
- return data;
812
- }
813
- function parseEffectExtraTechnique(xml2) {
814
- const data = {};
815
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
816
- const child = xml2.childNodes[i];
817
- if (child.nodeType !== 1)
818
- continue;
819
- switch (child.nodeName) {
820
- case "double_sided":
821
- data[child.nodeName] = parseInt(child.textContent);
822
- break;
823
- case "bump":
824
- data[child.nodeName] = parseEffectExtraTechniqueBump(child);
825
- break;
826
- }
827
- }
828
- return data;
829
- }
830
- function parseEffectExtraTechniqueBump(xml2) {
831
- var data = {};
832
- for (var i = 0, l = xml2.childNodes.length; i < l; i++) {
833
- var child = xml2.childNodes[i];
834
- if (child.nodeType !== 1)
835
- continue;
836
- switch (child.nodeName) {
837
- case "texture":
838
- data[child.nodeName] = {
839
- id: child.getAttribute("texture"),
840
- texcoord: child.getAttribute("texcoord"),
841
- extra: parseEffectParameterTexture(child)
842
- };
843
- break;
844
- }
845
- }
846
- return data;
847
- }
848
- function buildEffect(data) {
849
- return data;
850
- }
851
- function getEffect(id) {
852
- return getBuild(library.effects[id], buildEffect);
853
- }
854
- function parseMaterial(xml2) {
855
- const data = {
856
- name: xml2.getAttribute("name")
857
- };
858
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
859
- const child = xml2.childNodes[i];
860
- if (child.nodeType !== 1)
861
- continue;
862
- switch (child.nodeName) {
863
- case "instance_effect":
864
- data.url = parseId(child.getAttribute("url"));
865
- break;
866
- }
867
- }
868
- library.materials[xml2.getAttribute("id")] = data;
869
- }
870
- function getTextureLoader(image) {
871
- let loader;
872
- let extension = image.slice((image.lastIndexOf(".") - 1 >>> 0) + 2);
873
- extension = extension.toLowerCase();
874
- switch (extension) {
875
- case "tga":
876
- loader = tgaLoader;
877
- break;
878
- default:
879
- loader = textureLoader;
880
- }
881
- return loader;
882
- }
883
- function buildMaterial(data) {
884
- const effect = getEffect(data.url);
885
- const technique = effect.profile.technique;
886
- let material;
887
- switch (technique.type) {
888
- case "phong":
889
- case "blinn":
890
- material = new MeshPhongMaterial();
891
- break;
892
- case "lambert":
893
- material = new MeshLambertMaterial();
894
- break;
895
- default:
896
- material = new MeshBasicMaterial();
897
- break;
898
- }
899
- material.name = data.name || "";
900
- function getTexture(textureObject) {
901
- const sampler = effect.profile.samplers[textureObject.id];
902
- let image = null;
903
- if (sampler !== void 0) {
904
- const surface = effect.profile.surfaces[sampler.source];
905
- image = getImage(surface.init_from);
906
- } else {
907
- console.warn("THREE.ColladaLoader: Undefined sampler. Access image directly (see #12530).");
908
- image = getImage(textureObject.id);
909
- }
910
- if (image !== null) {
911
- const loader = getTextureLoader(image);
912
- if (loader !== void 0) {
913
- const texture = loader.load(image);
914
- const extra = textureObject.extra;
915
- if (extra !== void 0 && extra.technique !== void 0 && isEmpty(extra.technique) === false) {
916
- const technique2 = extra.technique;
917
- texture.wrapS = technique2.wrapU ? RepeatWrapping : ClampToEdgeWrapping;
918
- texture.wrapT = technique2.wrapV ? RepeatWrapping : ClampToEdgeWrapping;
919
- texture.offset.set(technique2.offsetU || 0, technique2.offsetV || 0);
920
- texture.repeat.set(technique2.repeatU || 1, technique2.repeatV || 1);
921
- } else {
922
- texture.wrapS = RepeatWrapping;
923
- texture.wrapT = RepeatWrapping;
924
- }
925
- return texture;
926
- } else {
927
- console.warn("THREE.ColladaLoader: Loader for texture %s not found.", image);
928
- return null;
929
- }
930
- } else {
931
- console.warn("THREE.ColladaLoader: Couldn't create texture with ID:", textureObject.id);
932
- return null;
933
- }
934
- }
935
- const parameters = technique.parameters;
936
- for (const key in parameters) {
937
- const parameter = parameters[key];
938
- switch (key) {
939
- case "diffuse":
940
- if (parameter.color)
941
- material.color.fromArray(parameter.color);
942
- if (parameter.texture)
943
- material.map = getTexture(parameter.texture);
944
- break;
945
- case "specular":
946
- if (parameter.color && material.specular)
947
- material.specular.fromArray(parameter.color);
948
- if (parameter.texture)
949
- material.specularMap = getTexture(parameter.texture);
950
- break;
951
- case "bump":
952
- if (parameter.texture)
953
- material.normalMap = getTexture(parameter.texture);
954
- break;
955
- case "ambient":
956
- if (parameter.texture)
957
- material.lightMap = getTexture(parameter.texture);
958
- break;
959
- case "shininess":
960
- if (parameter.float && material.shininess)
961
- material.shininess = parameter.float;
962
- break;
963
- case "emission":
964
- if (parameter.color && material.emissive)
965
- material.emissive.fromArray(parameter.color);
966
- if (parameter.texture)
967
- material.emissiveMap = getTexture(parameter.texture);
968
- break;
969
- }
970
- }
971
- let transparent = parameters["transparent"];
972
- let transparency = parameters["transparency"];
973
- if (transparency === void 0 && transparent) {
974
- transparency = {
975
- float: 1
976
- };
977
- }
978
- if (transparent === void 0 && transparency) {
979
- transparent = {
980
- opaque: "A_ONE",
981
- data: {
982
- color: [1, 1, 1, 1]
983
- }
984
- };
985
- }
986
- if (transparent && transparency) {
987
- if (transparent.data.texture) {
988
- material.transparent = true;
989
- } else {
990
- const color = transparent.data.color;
991
- switch (transparent.opaque) {
992
- case "A_ONE":
993
- material.opacity = color[3] * transparency.float;
994
- break;
995
- case "RGB_ZERO":
996
- material.opacity = 1 - color[0] * transparency.float;
997
- break;
998
- case "A_ZERO":
999
- material.opacity = 1 - color[3] * transparency.float;
1000
- break;
1001
- case "RGB_ONE":
1002
- material.opacity = color[0] * transparency.float;
1003
- break;
1004
- default:
1005
- console.warn('THREE.ColladaLoader: Invalid opaque type "%s" of transparent tag.', transparent.opaque);
1006
- }
1007
- if (material.opacity < 1)
1008
- material.transparent = true;
1009
- }
1010
- }
1011
- if (technique.extra !== void 0 && technique.extra.technique !== void 0) {
1012
- const techniques = technique.extra.technique;
1013
- for (const k in techniques) {
1014
- const v = techniques[k];
1015
- switch (k) {
1016
- case "double_sided":
1017
- material.side = v === 1 ? DoubleSide : FrontSide;
1018
- break;
1019
- case "bump":
1020
- material.normalMap = getTexture(v.texture);
1021
- material.normalScale = new Vector2(1, 1);
1022
- break;
1023
- }
1024
- }
1025
- }
1026
- return material;
1027
- }
1028
- function getMaterial(id) {
1029
- return getBuild(library.materials[id], buildMaterial);
1030
- }
1031
- function parseCamera(xml2) {
1032
- const data = {
1033
- name: xml2.getAttribute("name")
1034
- };
1035
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
1036
- const child = xml2.childNodes[i];
1037
- if (child.nodeType !== 1)
1038
- continue;
1039
- switch (child.nodeName) {
1040
- case "optics":
1041
- data.optics = parseCameraOptics(child);
1042
- break;
1043
- }
1044
- }
1045
- library.cameras[xml2.getAttribute("id")] = data;
1046
- }
1047
- function parseCameraOptics(xml2) {
1048
- for (let i = 0; i < xml2.childNodes.length; i++) {
1049
- const child = xml2.childNodes[i];
1050
- switch (child.nodeName) {
1051
- case "technique_common":
1052
- return parseCameraTechnique(child);
1053
- }
1054
- }
1055
- return {};
1056
- }
1057
- function parseCameraTechnique(xml2) {
1058
- const data = {};
1059
- for (let i = 0; i < xml2.childNodes.length; i++) {
1060
- const child = xml2.childNodes[i];
1061
- switch (child.nodeName) {
1062
- case "perspective":
1063
- case "orthographic":
1064
- data.technique = child.nodeName;
1065
- data.parameters = parseCameraParameters(child);
1066
- break;
1067
- }
1068
- }
1069
- return data;
1070
- }
1071
- function parseCameraParameters(xml2) {
1072
- const data = {};
1073
- for (let i = 0; i < xml2.childNodes.length; i++) {
1074
- const child = xml2.childNodes[i];
1075
- switch (child.nodeName) {
1076
- case "xfov":
1077
- case "yfov":
1078
- case "xmag":
1079
- case "ymag":
1080
- case "znear":
1081
- case "zfar":
1082
- case "aspect_ratio":
1083
- data[child.nodeName] = parseFloat(child.textContent);
1084
- break;
1085
- }
1086
- }
1087
- return data;
1088
- }
1089
- function buildCamera(data) {
1090
- let camera;
1091
- switch (data.optics.technique) {
1092
- case "perspective":
1093
- camera = new PerspectiveCamera(
1094
- data.optics.parameters.yfov,
1095
- data.optics.parameters.aspect_ratio,
1096
- data.optics.parameters.znear,
1097
- data.optics.parameters.zfar
1098
- );
1099
- break;
1100
- case "orthographic":
1101
- let ymag = data.optics.parameters.ymag;
1102
- let xmag = data.optics.parameters.xmag;
1103
- const aspectRatio = data.optics.parameters.aspect_ratio;
1104
- xmag = xmag === void 0 ? ymag * aspectRatio : xmag;
1105
- ymag = ymag === void 0 ? xmag / aspectRatio : ymag;
1106
- xmag *= 0.5;
1107
- ymag *= 0.5;
1108
- camera = new OrthographicCamera(
1109
- -xmag,
1110
- xmag,
1111
- ymag,
1112
- -ymag,
1113
- // left, right, top, bottom
1114
- data.optics.parameters.znear,
1115
- data.optics.parameters.zfar
1116
- );
1117
- break;
1118
- default:
1119
- camera = new PerspectiveCamera();
1120
- break;
1121
- }
1122
- camera.name = data.name || "";
1123
- return camera;
1124
- }
1125
- function getCamera(id) {
1126
- const data = library.cameras[id];
1127
- if (data !== void 0) {
1128
- return getBuild(data, buildCamera);
1129
- }
1130
- console.warn("THREE.ColladaLoader: Couldn't find camera with ID:", id);
1131
- return null;
1132
- }
1133
- function parseLight(xml2) {
1134
- let data = {};
1135
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
1136
- const child = xml2.childNodes[i];
1137
- if (child.nodeType !== 1)
1138
- continue;
1139
- switch (child.nodeName) {
1140
- case "technique_common":
1141
- data = parseLightTechnique(child);
1142
- break;
1143
- }
1144
- }
1145
- library.lights[xml2.getAttribute("id")] = data;
1146
- }
1147
- function parseLightTechnique(xml2) {
1148
- const data = {};
1149
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
1150
- const child = xml2.childNodes[i];
1151
- if (child.nodeType !== 1)
1152
- continue;
1153
- switch (child.nodeName) {
1154
- case "directional":
1155
- case "point":
1156
- case "spot":
1157
- case "ambient":
1158
- data.technique = child.nodeName;
1159
- data.parameters = parseLightParameters(child);
1160
- }
1161
- }
1162
- return data;
1163
- }
1164
- function parseLightParameters(xml2) {
1165
- const data = {};
1166
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
1167
- const child = xml2.childNodes[i];
1168
- if (child.nodeType !== 1)
1169
- continue;
1170
- switch (child.nodeName) {
1171
- case "color":
1172
- const array = parseFloats(child.textContent);
1173
- data.color = new Color().fromArray(array);
1174
- break;
1175
- case "falloff_angle":
1176
- data.falloffAngle = parseFloat(child.textContent);
1177
- break;
1178
- case "quadratic_attenuation":
1179
- const f = parseFloat(child.textContent);
1180
- data.distance = f ? Math.sqrt(1 / f) : 0;
1181
- break;
1182
- }
1183
- }
1184
- return data;
1185
- }
1186
- function buildLight(data) {
1187
- let light;
1188
- switch (data.technique) {
1189
- case "directional":
1190
- light = new DirectionalLight();
1191
- break;
1192
- case "point":
1193
- light = new PointLight();
1194
- break;
1195
- case "spot":
1196
- light = new SpotLight();
1197
- break;
1198
- case "ambient":
1199
- light = new AmbientLight();
1200
- break;
1201
- }
1202
- if (data.parameters.color)
1203
- light.color.copy(data.parameters.color);
1204
- if (data.parameters.distance)
1205
- light.distance = data.parameters.distance;
1206
- return light;
1207
- }
1208
- function getLight(id) {
1209
- const data = library.lights[id];
1210
- if (data !== void 0) {
1211
- return getBuild(data, buildLight);
1212
- }
1213
- console.warn("THREE.ColladaLoader: Couldn't find light with ID:", id);
1214
- return null;
1215
- }
1216
- function parseGeometry(xml2) {
1217
- const data = {
1218
- name: xml2.getAttribute("name"),
1219
- sources: {},
1220
- vertices: {},
1221
- primitives: []
1222
- };
1223
- const mesh = getElementsByTagName(xml2, "mesh")[0];
1224
- if (mesh === void 0)
1225
- return;
1226
- for (let i = 0; i < mesh.childNodes.length; i++) {
1227
- const child = mesh.childNodes[i];
1228
- if (child.nodeType !== 1)
1229
- continue;
1230
- const id = child.getAttribute("id");
1231
- switch (child.nodeName) {
1232
- case "source":
1233
- data.sources[id] = parseSource(child);
1234
- break;
1235
- case "vertices":
1236
- data.vertices = parseGeometryVertices(child);
1237
- break;
1238
- case "polygons":
1239
- console.warn("THREE.ColladaLoader: Unsupported primitive type: ", child.nodeName);
1240
- break;
1241
- case "lines":
1242
- case "linestrips":
1243
- case "polylist":
1244
- case "triangles":
1245
- data.primitives.push(parseGeometryPrimitive(child));
1246
- break;
1247
- default:
1248
- console.log(child);
1249
- }
1250
- }
1251
- library.geometries[xml2.getAttribute("id")] = data;
1252
- }
1253
- function parseSource(xml2) {
1254
- const data = {
1255
- array: [],
1256
- stride: 3
1257
- };
1258
- for (let i = 0; i < xml2.childNodes.length; i++) {
1259
- const child = xml2.childNodes[i];
1260
- if (child.nodeType !== 1)
1261
- continue;
1262
- switch (child.nodeName) {
1263
- case "float_array":
1264
- data.array = parseFloats(child.textContent);
1265
- break;
1266
- case "Name_array":
1267
- data.array = parseStrings(child.textContent);
1268
- break;
1269
- case "technique_common":
1270
- const accessor = getElementsByTagName(child, "accessor")[0];
1271
- if (accessor !== void 0) {
1272
- data.stride = parseInt(accessor.getAttribute("stride"));
1273
- }
1274
- break;
1275
- }
1276
- }
1277
- return data;
1278
- }
1279
- function parseGeometryVertices(xml2) {
1280
- const data = {};
1281
- for (let i = 0; i < xml2.childNodes.length; i++) {
1282
- const child = xml2.childNodes[i];
1283
- if (child.nodeType !== 1)
1284
- continue;
1285
- data[child.getAttribute("semantic")] = parseId(child.getAttribute("source"));
1286
- }
1287
- return data;
1288
- }
1289
- function parseGeometryPrimitive(xml2) {
1290
- const primitive = {
1291
- type: xml2.nodeName,
1292
- material: xml2.getAttribute("material"),
1293
- count: parseInt(xml2.getAttribute("count")),
1294
- inputs: {},
1295
- stride: 0,
1296
- hasUV: false
1297
- };
1298
- for (let i = 0, l = xml2.childNodes.length; i < l; i++) {
1299
- const child = xml2.childNodes[i];
1300
- if (child.nodeType !== 1)
1301
- continue;
1302
- switch (child.nodeName) {
1303
- case "input":
1304
- const id = parseId(child.getAttribute("source"));
1305
- const semantic = child.getAttribute("semantic");
1306
- const offset = parseInt(child.getAttribute("offset"));
1307
- const set = parseInt(child.getAttribute("set"));
1308
- const inputname = set > 0 ? semantic + set : semantic;
1309
- primitive.inputs[inputname] = { id, offset };
1310
- primitive.stride = Math.max(primitive.stride, offset + 1);
1311
- if (semantic === "TEXCOORD")
1312
- primitive.hasUV = true;
1313
- break;
1314
- case "vcount":
1315
- primitive.vcount = parseInts(child.textContent);
1316
- break;
1317
- case "p":
1318
- primitive.p = parseInts(child.textContent);
1319
- break;
1320
- }
1321
- }
1322
- return primitive;
1323
- }
1324
- function groupPrimitives(primitives) {
1325
- const build = {};
1326
- for (let i = 0; i < primitives.length; i++) {
1327
- const primitive = primitives[i];
1328
- if (build[primitive.type] === void 0)
1329
- build[primitive.type] = [];
1330
- build[primitive.type].push(primitive);
1331
- }
1332
- return build;
1333
- }
1334
- function checkUVCoordinates(primitives) {
1335
- let count2 = 0;
1336
- for (let i = 0, l = primitives.length; i < l; i++) {
1337
- const primitive = primitives[i];
1338
- if (primitive.hasUV === true) {
1339
- count2++;
1340
- }
1341
- }
1342
- if (count2 > 0 && count2 < primitives.length) {
1343
- primitives.uvsNeedsFix = true;
1344
- }
1345
- }
1346
- function buildGeometry(data) {
1347
- const build = {};
1348
- const sources = data.sources;
1349
- const vertices = data.vertices;
1350
- const primitives = data.primitives;
1351
- if (primitives.length === 0)
1352
- return {};
1353
- const groupedPrimitives = groupPrimitives(primitives);
1354
- for (const type in groupedPrimitives) {
1355
- const primitiveType = groupedPrimitives[type];
1356
- checkUVCoordinates(primitiveType);
1357
- build[type] = buildGeometryType(primitiveType, sources, vertices);
1358
- }
1359
- return build;
1360
- }
1361
- function buildGeometryType(primitives, sources, vertices) {
1362
- const build = {};
1363
- const position2 = { array: [], stride: 0 };
1364
- const normal = { array: [], stride: 0 };
1365
- const uv = { array: [], stride: 0 };
1366
- const uv2 = { array: [], stride: 0 };
1367
- const color = { array: [], stride: 0 };
1368
- const skinIndex = { array: [], stride: 4 };
1369
- const skinWeight = { array: [], stride: 4 };
1370
- const geometry = new BufferGeometry();
1371
- const materialKeys = [];
1372
- let start = 0;
1373
- for (let p = 0; p < primitives.length; p++) {
1374
- const primitive = primitives[p];
1375
- const inputs = primitive.inputs;
1376
- let count2 = 0;
1377
- switch (primitive.type) {
1378
- case "lines":
1379
- case "linestrips":
1380
- count2 = primitive.count * 2;
1381
- break;
1382
- case "triangles":
1383
- count2 = primitive.count * 3;
1384
- break;
1385
- case "polylist":
1386
- for (let g = 0; g < primitive.count; g++) {
1387
- const vc = primitive.vcount[g];
1388
- switch (vc) {
1389
- case 3:
1390
- count2 += 3;
1391
- break;
1392
- case 4:
1393
- count2 += 6;
1394
- break;
1395
- default:
1396
- count2 += (vc - 2) * 3;
1397
- break;
1398
- }
1399
- }
1400
- break;
1401
- default:
1402
- console.warn("THREE.ColladaLoader: Unknow primitive type:", primitive.type);
1403
- }
1404
- geometry.addGroup(start, count2, p);
1405
- start += count2;
1406
- if (primitive.material) {
1407
- materialKeys.push(primitive.material);
1408
- }
1409
- for (const name in inputs) {
1410
- const input = inputs[name];
1411
- switch (name) {
1412
- case "VERTEX":
1413
- for (const key in vertices) {
1414
- const id = vertices[key];
1415
- switch (key) {
1416
- case "POSITION":
1417
- const prevLength = position2.array.length;
1418
- buildGeometryData(primitive, sources[id], input.offset, position2.array);
1419
- position2.stride = sources[id].stride;
1420
- if (sources.skinWeights && sources.skinIndices) {
1421
- buildGeometryData(primitive, sources.skinIndices, input.offset, skinIndex.array);
1422
- buildGeometryData(primitive, sources.skinWeights, input.offset, skinWeight.array);
1423
- }
1424
- if (primitive.hasUV === false && primitives.uvsNeedsFix === true) {
1425
- const count3 = (position2.array.length - prevLength) / position2.stride;
1426
- for (let i = 0; i < count3; i++) {
1427
- uv.array.push(0, 0);
1428
- }
1429
- }
1430
- break;
1431
- case "NORMAL":
1432
- buildGeometryData(primitive, sources[id], input.offset, normal.array);
1433
- normal.stride = sources[id].stride;
1434
- break;
1435
- case "COLOR":
1436
- buildGeometryData(primitive, sources[id], input.offset, color.array);
1437
- color.stride = sources[id].stride;
1438
- break;
1439
- case "TEXCOORD":
1440
- buildGeometryData(primitive, sources[id], input.offset, uv.array);
1441
- uv.stride = sources[id].stride;
1442
- break;
1443
- case "TEXCOORD1":
1444
- buildGeometryData(primitive, sources[id], input.offset, uv2.array);
1445
- uv.stride = sources[id].stride;
1446
- break;
1447
- default:
1448
- console.warn('THREE.ColladaLoader: Semantic "%s" not handled in geometry build process.', key);
1449
- }
1450
- }
1451
- break;
1452
- case "NORMAL":
1453
- buildGeometryData(primitive, sources[input.id], input.offset, normal.array);
1454
- normal.stride = sources[input.id].stride;
1455
- break;
1456
- case "COLOR":
1457
- buildGeometryData(primitive, sources[input.id], input.offset, color.array);
1458
- color.stride = sources[input.id].stride;
1459
- break;
1460
- case "TEXCOORD":
1461
- buildGeometryData(primitive, sources[input.id], input.offset, uv.array);
1462
- uv.stride = sources[input.id].stride;
1463
- break;
1464
- case "TEXCOORD1":
1465
- buildGeometryData(primitive, sources[input.id], input.offset, uv2.array);
1466
- uv2.stride = sources[input.id].stride;
1467
- break;
1468
- }
1469
- }
1470
- }
1471
- if (position2.array.length > 0) {
1472
- geometry.setAttribute("position", new Float32BufferAttribute(position2.array, position2.stride));
1473
- }
1474
- if (normal.array.length > 0) {
1475
- geometry.setAttribute("normal", new Float32BufferAttribute(normal.array, normal.stride));
1476
- }
1477
- if (color.array.length > 0)
1478
- geometry.setAttribute("color", new Float32BufferAttribute(color.array, color.stride));
1479
- if (uv.array.length > 0)
1480
- geometry.setAttribute("uv", new Float32BufferAttribute(uv.array, uv.stride));
1481
- if (uv2.array.length > 0)
1482
- geometry.setAttribute("uv2", new Float32BufferAttribute(uv2.array, uv2.stride));
1483
- if (skinIndex.array.length > 0) {
1484
- geometry.setAttribute("skinIndex", new Float32BufferAttribute(skinIndex.array, skinIndex.stride));
1485
- }
1486
- if (skinWeight.array.length > 0) {
1487
- geometry.setAttribute("skinWeight", new Float32BufferAttribute(skinWeight.array, skinWeight.stride));
1488
- }
1489
- build.data = geometry;
1490
- build.type = primitives[0].type;
1491
- build.materialKeys = materialKeys;
1492
- return build;
1493
- }
1494
- function buildGeometryData(primitive, source, offset, array) {
1495
- const indices = primitive.p;
1496
- const stride = primitive.stride;
1497
- const vcount = primitive.vcount;
1498
- function pushVector(i) {
1499
- let index = indices[i + offset] * sourceStride;
1500
- const length = index + sourceStride;
1501
- for (; index < length; index++) {
1502
- array.push(sourceArray[index]);
1503
- }
1504
- }
1505
- const sourceArray = source.array;
1506
- const sourceStride = source.stride;
1507
- if (primitive.vcount !== void 0) {
1508
- let index = 0;
1509
- for (let i = 0, l = vcount.length; i < l; i++) {
1510
- const count2 = vcount[i];
1511
- if (count2 === 4) {
1512
- const a = index + stride * 0;
1513
- const b = index + stride * 1;
1514
- const c = index + stride * 2;
1515
- const d = index + stride * 3;
1516
- pushVector(a);
1517
- pushVector(b);
1518
- pushVector(d);
1519
- pushVector(b);
1520
- pushVector(c);
1521
- pushVector(d);
1522
- } else if (count2 === 3) {
1523
- const a = index + stride * 0;
1524
- const b = index + stride * 1;
1525
- const c = index + stride * 2;
1526
- pushVector(a);
1527
- pushVector(b);
1528
- pushVector(c);
1529
- } else if (count2 > 4) {
1530
- for (let k = 1, kl = count2 - 2; k <= kl; k++) {
1531
- const a = index + stride * 0;
1532
- const b = index + stride * k;
1533
- const c = index + stride * (k + 1);
1534
- pushVector(a);
1535
- pushVector(b);
1536
- pushVector(c);
1537
- }
1538
- }
1539
- index += stride * count2;
1540
- }
1541
- } else {
1542
- for (let i = 0, l = indices.length; i < l; i += stride) {
1543
- pushVector(i);
1544
- }
1545
- }
1546
- }
1547
- function getGeometry(id) {
1548
- return getBuild(library.geometries[id], buildGeometry);
1549
- }
1550
- function parseKinematicsModel(xml2) {
1551
- const data = {
1552
- name: xml2.getAttribute("name") || "",
1553
- joints: {},
1554
- links: []
1555
- };
1556
- for (let i = 0; i < xml2.childNodes.length; i++) {
1557
- const child = xml2.childNodes[i];
1558
- if (child.nodeType !== 1)
1559
- continue;
1560
- switch (child.nodeName) {
1561
- case "technique_common":
1562
- parseKinematicsTechniqueCommon(child, data);
1563
- break;
1564
- }
1565
- }
1566
- library.kinematicsModels[xml2.getAttribute("id")] = data;
1567
- }
1568
- function buildKinematicsModel(data) {
1569
- if (data.build !== void 0)
1570
- return data.build;
1571
- return data;
1572
- }
1573
- function getKinematicsModel(id) {
1574
- return getBuild(library.kinematicsModels[id], buildKinematicsModel);
1575
- }
1576
- function parseKinematicsTechniqueCommon(xml2, data) {
1577
- for (let i = 0; i < xml2.childNodes.length; i++) {
1578
- const child = xml2.childNodes[i];
1579
- if (child.nodeType !== 1)
1580
- continue;
1581
- switch (child.nodeName) {
1582
- case "joint":
1583
- data.joints[child.getAttribute("sid")] = parseKinematicsJoint(child);
1584
- break;
1585
- case "link":
1586
- data.links.push(parseKinematicsLink(child));
1587
- break;
1588
- }
1589
- }
1590
- }
1591
- function parseKinematicsJoint(xml2) {
1592
- let data;
1593
- for (let i = 0; i < xml2.childNodes.length; i++) {
1594
- const child = xml2.childNodes[i];
1595
- if (child.nodeType !== 1)
1596
- continue;
1597
- switch (child.nodeName) {
1598
- case "prismatic":
1599
- case "revolute":
1600
- data = parseKinematicsJointParameter(child);
1601
- break;
1602
- }
1603
- }
1604
- return data;
1605
- }
1606
- function parseKinematicsJointParameter(xml2) {
1607
- const data = {
1608
- sid: xml2.getAttribute("sid"),
1609
- name: xml2.getAttribute("name") || "",
1610
- axis: new Vector3(),
1611
- limits: {
1612
- min: 0,
1613
- max: 0
1614
- },
1615
- type: xml2.nodeName,
1616
- static: false,
1617
- zeroPosition: 0,
1618
- middlePosition: 0
1619
- };
1620
- for (let i = 0; i < xml2.childNodes.length; i++) {
1621
- const child = xml2.childNodes[i];
1622
- if (child.nodeType !== 1)
1623
- continue;
1624
- switch (child.nodeName) {
1625
- case "axis":
1626
- const array = parseFloats(child.textContent);
1627
- data.axis.fromArray(array);
1628
- break;
1629
- case "limits":
1630
- const max = child.getElementsByTagName("max")[0];
1631
- const min = child.getElementsByTagName("min")[0];
1632
- data.limits.max = parseFloat(max.textContent);
1633
- data.limits.min = parseFloat(min.textContent);
1634
- break;
1635
- }
1636
- }
1637
- if (data.limits.min >= data.limits.max) {
1638
- data.static = true;
1639
- }
1640
- data.middlePosition = (data.limits.min + data.limits.max) / 2;
1641
- return data;
1642
- }
1643
- function parseKinematicsLink(xml2) {
1644
- const data = {
1645
- sid: xml2.getAttribute("sid"),
1646
- name: xml2.getAttribute("name") || "",
1647
- attachments: [],
1648
- transforms: []
1649
- };
1650
- for (let i = 0; i < xml2.childNodes.length; i++) {
1651
- const child = xml2.childNodes[i];
1652
- if (child.nodeType !== 1)
1653
- continue;
1654
- switch (child.nodeName) {
1655
- case "attachment_full":
1656
- data.attachments.push(parseKinematicsAttachment(child));
1657
- break;
1658
- case "matrix":
1659
- case "translate":
1660
- case "rotate":
1661
- data.transforms.push(parseKinematicsTransform(child));
1662
- break;
1663
- }
1664
- }
1665
- return data;
1666
- }
1667
- function parseKinematicsAttachment(xml2) {
1668
- const data = {
1669
- joint: xml2.getAttribute("joint").split("/").pop(),
1670
- transforms: [],
1671
- links: []
1672
- };
1673
- for (let i = 0; i < xml2.childNodes.length; i++) {
1674
- const child = xml2.childNodes[i];
1675
- if (child.nodeType !== 1)
1676
- continue;
1677
- switch (child.nodeName) {
1678
- case "link":
1679
- data.links.push(parseKinematicsLink(child));
1680
- break;
1681
- case "matrix":
1682
- case "translate":
1683
- case "rotate":
1684
- data.transforms.push(parseKinematicsTransform(child));
1685
- break;
1686
- }
1687
- }
1688
- return data;
1689
- }
1690
- function parseKinematicsTransform(xml2) {
1691
- const data = {
1692
- type: xml2.nodeName
1693
- };
1694
- const array = parseFloats(xml2.textContent);
1695
- switch (data.type) {
1696
- case "matrix":
1697
- data.obj = new Matrix4();
1698
- data.obj.fromArray(array).transpose();
1699
- break;
1700
- case "translate":
1701
- data.obj = new Vector3();
1702
- data.obj.fromArray(array);
1703
- break;
1704
- case "rotate":
1705
- data.obj = new Vector3();
1706
- data.obj.fromArray(array);
1707
- data.angle = MathUtils.degToRad(array[3]);
1708
- break;
1709
- }
1710
- return data;
1711
- }
1712
- function parsePhysicsModel(xml2) {
1713
- const data = {
1714
- name: xml2.getAttribute("name") || "",
1715
- rigidBodies: {}
1716
- };
1717
- for (let i = 0; i < xml2.childNodes.length; i++) {
1718
- const child = xml2.childNodes[i];
1719
- if (child.nodeType !== 1)
1720
- continue;
1721
- switch (child.nodeName) {
1722
- case "rigid_body":
1723
- data.rigidBodies[child.getAttribute("name")] = {};
1724
- parsePhysicsRigidBody(child, data.rigidBodies[child.getAttribute("name")]);
1725
- break;
1726
- }
1727
- }
1728
- library.physicsModels[xml2.getAttribute("id")] = data;
1729
- }
1730
- function parsePhysicsRigidBody(xml2, data) {
1731
- for (let i = 0; i < xml2.childNodes.length; i++) {
1732
- const child = xml2.childNodes[i];
1733
- if (child.nodeType !== 1)
1734
- continue;
1735
- switch (child.nodeName) {
1736
- case "technique_common":
1737
- parsePhysicsTechniqueCommon(child, data);
1738
- break;
1739
- }
1740
- }
1741
- }
1742
- function parsePhysicsTechniqueCommon(xml2, data) {
1743
- for (let i = 0; i < xml2.childNodes.length; i++) {
1744
- const child = xml2.childNodes[i];
1745
- if (child.nodeType !== 1)
1746
- continue;
1747
- switch (child.nodeName) {
1748
- case "inertia":
1749
- data.inertia = parseFloats(child.textContent);
1750
- break;
1751
- case "mass":
1752
- data.mass = parseFloats(child.textContent)[0];
1753
- break;
1754
- }
1755
- }
1756
- }
1757
- function parseKinematicsScene(xml2) {
1758
- const data = {
1759
- bindJointAxis: []
1760
- };
1761
- for (let i = 0; i < xml2.childNodes.length; i++) {
1762
- const child = xml2.childNodes[i];
1763
- if (child.nodeType !== 1)
1764
- continue;
1765
- switch (child.nodeName) {
1766
- case "bind_joint_axis":
1767
- data.bindJointAxis.push(parseKinematicsBindJointAxis(child));
1768
- break;
1769
- }
1770
- }
1771
- library.kinematicsScenes[parseId(xml2.getAttribute("url"))] = data;
1772
- }
1773
- function parseKinematicsBindJointAxis(xml2) {
1774
- const data = {
1775
- target: xml2.getAttribute("target").split("/").pop()
1776
- };
1777
- for (let i = 0; i < xml2.childNodes.length; i++) {
1778
- const child = xml2.childNodes[i];
1779
- if (child.nodeType !== 1)
1780
- continue;
1781
- switch (child.nodeName) {
1782
- case "axis":
1783
- const param = child.getElementsByTagName("param")[0];
1784
- data.axis = param.textContent;
1785
- const tmpJointIndex = data.axis.split("inst_").pop().split("axis")[0];
1786
- data.jointIndex = tmpJointIndex.substr(0, tmpJointIndex.length - 1);
1787
- break;
1788
- }
1789
- }
1790
- return data;
1791
- }
1792
- function buildKinematicsScene(data) {
1793
- if (data.build !== void 0)
1794
- return data.build;
1795
- return data;
1796
- }
1797
- function getKinematicsScene(id) {
1798
- return getBuild(library.kinematicsScenes[id], buildKinematicsScene);
1799
- }
1800
- function setupKinematics() {
1801
- const kinematicsModelId = Object.keys(library.kinematicsModels)[0];
1802
- const kinematicsSceneId = Object.keys(library.kinematicsScenes)[0];
1803
- const visualSceneId = Object.keys(library.visualScenes)[0];
1804
- if (kinematicsModelId === void 0 || kinematicsSceneId === void 0)
1805
- return;
1806
- const kinematicsModel = getKinematicsModel(kinematicsModelId);
1807
- const kinematicsScene = getKinematicsScene(kinematicsSceneId);
1808
- const visualScene = getVisualScene(visualSceneId);
1809
- const bindJointAxis = kinematicsScene.bindJointAxis;
1810
- const jointMap = {};
1811
- for (let i = 0, l = bindJointAxis.length; i < l; i++) {
1812
- const axis = bindJointAxis[i];
1813
- const targetElement = collada.querySelector('[sid="' + axis.target + '"]');
1814
- if (targetElement) {
1815
- const parentVisualElement = targetElement.parentElement;
1816
- connect(axis.jointIndex, parentVisualElement);
1817
- }
1818
- }
1819
- function connect(jointIndex, visualElement) {
1820
- const visualElementName = visualElement.getAttribute("name");
1821
- const joint = kinematicsModel.joints[jointIndex];
1822
- visualScene.traverse(function(object) {
1823
- if (object.name === visualElementName) {
1824
- jointMap[jointIndex] = {
1825
- object,
1826
- transforms: buildTransformList(visualElement),
1827
- joint,
1828
- position: joint.zeroPosition
1829
- };
1830
- }
1831
- });
1832
- }
1833
- const m0 = new Matrix4();
1834
- kinematics = {
1835
- joints: kinematicsModel && kinematicsModel.joints,
1836
- getJointValue: function(jointIndex) {
1837
- const jointData = jointMap[jointIndex];
1838
- if (jointData) {
1839
- return jointData.position;
1840
- } else {
1841
- console.warn("THREE.ColladaLoader: Joint " + jointIndex + " doesn't exist.");
1842
- }
1843
- },
1844
- setJointValue: function(jointIndex, value) {
1845
- const jointData = jointMap[jointIndex];
1846
- if (jointData) {
1847
- const joint = jointData.joint;
1848
- if (value > joint.limits.max || value < joint.limits.min) {
1849
- console.warn(
1850
- "THREE.ColladaLoader: Joint " + jointIndex + " value " + value + " outside of limits (min: " + joint.limits.min + ", max: " + joint.limits.max + ")."
1851
- );
1852
- } else if (joint.static) {
1853
- console.warn("THREE.ColladaLoader: Joint " + jointIndex + " is static.");
1854
- } else {
1855
- const object = jointData.object;
1856
- const axis = joint.axis;
1857
- const transforms = jointData.transforms;
1858
- matrix.identity();
1859
- for (let i = 0; i < transforms.length; i++) {
1860
- const transform = transforms[i];
1861
- if (transform.sid && transform.sid.indexOf(jointIndex) !== -1) {
1862
- switch (joint.type) {
1863
- case "revolute":
1864
- matrix.multiply(m0.makeRotationAxis(axis, MathUtils.degToRad(value)));
1865
- break;
1866
- case "prismatic":
1867
- matrix.multiply(m0.makeTranslation(axis.x * value, axis.y * value, axis.z * value));
1868
- break;
1869
- default:
1870
- console.warn("THREE.ColladaLoader: Unknown joint type: " + joint.type);
1871
- break;
1872
- }
1873
- } else {
1874
- switch (transform.type) {
1875
- case "matrix":
1876
- matrix.multiply(transform.obj);
1877
- break;
1878
- case "translate":
1879
- matrix.multiply(m0.makeTranslation(transform.obj.x, transform.obj.y, transform.obj.z));
1880
- break;
1881
- case "scale":
1882
- matrix.scale(transform.obj);
1883
- break;
1884
- case "rotate":
1885
- matrix.multiply(m0.makeRotationAxis(transform.obj, transform.angle));
1886
- break;
1887
- }
1888
- }
1889
- }
1890
- object.matrix.copy(matrix);
1891
- object.matrix.decompose(object.position, object.quaternion, object.scale);
1892
- jointMap[jointIndex].position = value;
1893
- }
1894
- } else {
1895
- console.log("THREE.ColladaLoader: " + jointIndex + " does not exist.");
1896
- }
1897
- }
1898
- };
1899
- }
1900
- function buildTransformList(node) {
1901
- const transforms = [];
1902
- const xml2 = collada.querySelector('[id="' + node.id + '"]');
1903
- for (let i = 0; i < xml2.childNodes.length; i++) {
1904
- const child = xml2.childNodes[i];
1905
- if (child.nodeType !== 1)
1906
- continue;
1907
- let array, vector2;
1908
- switch (child.nodeName) {
1909
- case "matrix":
1910
- array = parseFloats(child.textContent);
1911
- const matrix2 = new Matrix4().fromArray(array).transpose();
1912
- transforms.push({
1913
- sid: child.getAttribute("sid"),
1914
- type: child.nodeName,
1915
- obj: matrix2
1916
- });
1917
- break;
1918
- case "translate":
1919
- case "scale":
1920
- array = parseFloats(child.textContent);
1921
- vector2 = new Vector3().fromArray(array);
1922
- transforms.push({
1923
- sid: child.getAttribute("sid"),
1924
- type: child.nodeName,
1925
- obj: vector2
1926
- });
1927
- break;
1928
- case "rotate":
1929
- array = parseFloats(child.textContent);
1930
- vector2 = new Vector3().fromArray(array);
1931
- const angle = MathUtils.degToRad(array[3]);
1932
- transforms.push({
1933
- sid: child.getAttribute("sid"),
1934
- type: child.nodeName,
1935
- obj: vector2,
1936
- angle
1937
- });
1938
- break;
1939
- }
1940
- }
1941
- return transforms;
1942
- }
1943
- function prepareNodes(xml2) {
1944
- const elements = xml2.getElementsByTagName("node");
1945
- for (let i = 0; i < elements.length; i++) {
1946
- const element = elements[i];
1947
- if (element.hasAttribute("id") === false) {
1948
- element.setAttribute("id", generateId());
1949
- }
1950
- }
1951
- }
1952
- const matrix = new Matrix4();
1953
- const vector = new Vector3();
1954
- function parseNode(xml2) {
1955
- const data = {
1956
- name: xml2.getAttribute("name") || "",
1957
- type: xml2.getAttribute("type"),
1958
- id: xml2.getAttribute("id"),
1959
- sid: xml2.getAttribute("sid"),
1960
- matrix: new Matrix4(),
1961
- nodes: [],
1962
- instanceCameras: [],
1963
- instanceControllers: [],
1964
- instanceLights: [],
1965
- instanceGeometries: [],
1966
- instanceNodes: [],
1967
- transforms: {}
1968
- };
1969
- for (let i = 0; i < xml2.childNodes.length; i++) {
1970
- const child = xml2.childNodes[i];
1971
- if (child.nodeType !== 1)
1972
- continue;
1973
- let array;
1974
- switch (child.nodeName) {
1975
- case "node":
1976
- data.nodes.push(child.getAttribute("id"));
1977
- parseNode(child);
1978
- break;
1979
- case "instance_camera":
1980
- data.instanceCameras.push(parseId(child.getAttribute("url")));
1981
- break;
1982
- case "instance_controller":
1983
- data.instanceControllers.push(parseNodeInstance(child));
1984
- break;
1985
- case "instance_light":
1986
- data.instanceLights.push(parseId(child.getAttribute("url")));
1987
- break;
1988
- case "instance_geometry":
1989
- data.instanceGeometries.push(parseNodeInstance(child));
1990
- break;
1991
- case "instance_node":
1992
- data.instanceNodes.push(parseId(child.getAttribute("url")));
1993
- break;
1994
- case "matrix":
1995
- array = parseFloats(child.textContent);
1996
- data.matrix.multiply(matrix.fromArray(array).transpose());
1997
- data.transforms[child.getAttribute("sid")] = child.nodeName;
1998
- break;
1999
- case "translate":
2000
- array = parseFloats(child.textContent);
2001
- vector.fromArray(array);
2002
- data.matrix.multiply(matrix.makeTranslation(vector.x, vector.y, vector.z));
2003
- data.transforms[child.getAttribute("sid")] = child.nodeName;
2004
- break;
2005
- case "rotate":
2006
- array = parseFloats(child.textContent);
2007
- const angle = MathUtils.degToRad(array[3]);
2008
- data.matrix.multiply(matrix.makeRotationAxis(vector.fromArray(array), angle));
2009
- data.transforms[child.getAttribute("sid")] = child.nodeName;
2010
- break;
2011
- case "scale":
2012
- array = parseFloats(child.textContent);
2013
- data.matrix.scale(vector.fromArray(array));
2014
- data.transforms[child.getAttribute("sid")] = child.nodeName;
2015
- break;
2016
- case "extra":
2017
- break;
2018
- default:
2019
- console.log(child);
2020
- }
2021
- }
2022
- if (hasNode(data.id)) {
2023
- console.warn(
2024
- "THREE.ColladaLoader: There is already a node with ID %s. Exclude current node from further processing.",
2025
- data.id
2026
- );
2027
- } else {
2028
- library.nodes[data.id] = data;
2029
- }
2030
- return data;
2031
- }
2032
- function parseNodeInstance(xml2) {
2033
- const data = {
2034
- id: parseId(xml2.getAttribute("url")),
2035
- materials: {},
2036
- skeletons: []
2037
- };
2038
- for (let i = 0; i < xml2.childNodes.length; i++) {
2039
- const child = xml2.childNodes[i];
2040
- switch (child.nodeName) {
2041
- case "bind_material":
2042
- const instances = child.getElementsByTagName("instance_material");
2043
- for (let j = 0; j < instances.length; j++) {
2044
- const instance = instances[j];
2045
- const symbol = instance.getAttribute("symbol");
2046
- const target = instance.getAttribute("target");
2047
- data.materials[symbol] = parseId(target);
2048
- }
2049
- break;
2050
- case "skeleton":
2051
- data.skeletons.push(parseId(child.textContent));
2052
- break;
2053
- default:
2054
- break;
2055
- }
2056
- }
2057
- return data;
2058
- }
2059
- function buildSkeleton(skeletons, joints) {
2060
- const boneData = [];
2061
- const sortedBoneData = [];
2062
- let i, j, data;
2063
- for (i = 0; i < skeletons.length; i++) {
2064
- const skeleton = skeletons[i];
2065
- let root;
2066
- if (hasNode(skeleton)) {
2067
- root = getNode(skeleton);
2068
- buildBoneHierarchy(root, joints, boneData);
2069
- } else if (hasVisualScene(skeleton)) {
2070
- const visualScene = library.visualScenes[skeleton];
2071
- const children = visualScene.children;
2072
- for (let j2 = 0; j2 < children.length; j2++) {
2073
- const child = children[j2];
2074
- if (child.type === "JOINT") {
2075
- const root2 = getNode(child.id);
2076
- buildBoneHierarchy(root2, joints, boneData);
2077
- }
2078
- }
2079
- } else {
2080
- console.error("THREE.ColladaLoader: Unable to find root bone of skeleton with ID:", skeleton);
2081
- }
2082
- }
2083
- for (i = 0; i < joints.length; i++) {
2084
- for (j = 0; j < boneData.length; j++) {
2085
- data = boneData[j];
2086
- if (data.bone.name === joints[i].name) {
2087
- sortedBoneData[i] = data;
2088
- data.processed = true;
2089
- break;
2090
- }
2091
- }
2092
- }
2093
- for (i = 0; i < boneData.length; i++) {
2094
- data = boneData[i];
2095
- if (data.processed === false) {
2096
- sortedBoneData.push(data);
2097
- data.processed = true;
2098
- }
2099
- }
2100
- const bones = [];
2101
- const boneInverses = [];
2102
- for (i = 0; i < sortedBoneData.length; i++) {
2103
- data = sortedBoneData[i];
2104
- bones.push(data.bone);
2105
- boneInverses.push(data.boneInverse);
2106
- }
2107
- return new Skeleton(bones, boneInverses);
2108
- }
2109
- function buildBoneHierarchy(root, joints, boneData) {
2110
- root.traverse(function(object) {
2111
- if (object.isBone === true) {
2112
- let boneInverse;
2113
- for (let i = 0; i < joints.length; i++) {
2114
- const joint = joints[i];
2115
- if (joint.name === object.name) {
2116
- boneInverse = joint.boneInverse;
2117
- break;
2118
- }
2119
- }
2120
- if (boneInverse === void 0) {
2121
- boneInverse = new Matrix4();
2122
- }
2123
- boneData.push({ bone: object, boneInverse, processed: false });
2124
- }
2125
- });
2126
- }
2127
- function buildNode(data) {
2128
- const objects = [];
2129
- const matrix2 = data.matrix;
2130
- const nodes = data.nodes;
2131
- const type = data.type;
2132
- const instanceCameras = data.instanceCameras;
2133
- const instanceControllers = data.instanceControllers;
2134
- const instanceLights = data.instanceLights;
2135
- const instanceGeometries = data.instanceGeometries;
2136
- const instanceNodes = data.instanceNodes;
2137
- for (let i = 0, l = nodes.length; i < l; i++) {
2138
- objects.push(getNode(nodes[i]));
2139
- }
2140
- for (let i = 0, l = instanceCameras.length; i < l; i++) {
2141
- const instanceCamera = getCamera(instanceCameras[i]);
2142
- if (instanceCamera !== null) {
2143
- objects.push(instanceCamera.clone());
2144
- }
2145
- }
2146
- for (let i = 0, l = instanceControllers.length; i < l; i++) {
2147
- const instance = instanceControllers[i];
2148
- const controller = getController(instance.id);
2149
- const geometries = getGeometry(controller.id);
2150
- const newObjects = buildObjects(geometries, instance.materials);
2151
- const skeletons = instance.skeletons;
2152
- const joints = controller.skin.joints;
2153
- const skeleton = buildSkeleton(skeletons, joints);
2154
- for (let j = 0, jl = newObjects.length; j < jl; j++) {
2155
- const object2 = newObjects[j];
2156
- if (object2.isSkinnedMesh) {
2157
- object2.bind(skeleton, controller.skin.bindMatrix);
2158
- object2.normalizeSkinWeights();
2159
- }
2160
- objects.push(object2);
2161
- }
2162
- }
2163
- for (let i = 0, l = instanceLights.length; i < l; i++) {
2164
- const instanceLight = getLight(instanceLights[i]);
2165
- if (instanceLight !== null) {
2166
- objects.push(instanceLight.clone());
2167
- }
2168
- }
2169
- for (let i = 0, l = instanceGeometries.length; i < l; i++) {
2170
- const instance = instanceGeometries[i];
2171
- const geometries = getGeometry(instance.id);
2172
- const newObjects = buildObjects(geometries, instance.materials);
2173
- for (let j = 0, jl = newObjects.length; j < jl; j++) {
2174
- objects.push(newObjects[j]);
2175
- }
2176
- }
2177
- for (let i = 0, l = instanceNodes.length; i < l; i++) {
2178
- objects.push(getNode(instanceNodes[i]).clone());
2179
- }
2180
- let object;
2181
- if (nodes.length === 0 && objects.length === 1) {
2182
- object = objects[0];
2183
- } else {
2184
- object = type === "JOINT" ? new Bone() : new Group();
2185
- for (let i = 0; i < objects.length; i++) {
2186
- object.add(objects[i]);
2187
- }
2188
- }
2189
- object.name = type === "JOINT" ? data.sid : data.name;
2190
- object.matrix.copy(matrix2);
2191
- object.matrix.decompose(object.position, object.quaternion, object.scale);
2192
- return object;
2193
- }
2194
- const fallbackMaterial = new MeshBasicMaterial({ color: 16711935 });
2195
- function resolveMaterialBinding(keys, instanceMaterials) {
2196
- const materials = [];
2197
- for (let i = 0, l = keys.length; i < l; i++) {
2198
- const id = instanceMaterials[keys[i]];
2199
- if (id === void 0) {
2200
- console.warn("THREE.ColladaLoader: Material with key %s not found. Apply fallback material.", keys[i]);
2201
- materials.push(fallbackMaterial);
2202
- } else {
2203
- materials.push(getMaterial(id));
2204
- }
2205
- }
2206
- return materials;
2207
- }
2208
- function buildObjects(geometries, instanceMaterials) {
2209
- const objects = [];
2210
- for (const type in geometries) {
2211
- const geometry = geometries[type];
2212
- const materials = resolveMaterialBinding(geometry.materialKeys, instanceMaterials);
2213
- if (materials.length === 0) {
2214
- if (type === "lines" || type === "linestrips") {
2215
- materials.push(new LineBasicMaterial());
2216
- } else {
2217
- materials.push(new MeshPhongMaterial());
2218
- }
2219
- }
2220
- const skinning = geometry.data.attributes.skinIndex !== void 0;
2221
- const material = materials.length === 1 ? materials[0] : materials;
2222
- let object;
2223
- switch (type) {
2224
- case "lines":
2225
- object = new LineSegments(geometry.data, material);
2226
- break;
2227
- case "linestrips":
2228
- object = new Line(geometry.data, material);
2229
- break;
2230
- case "triangles":
2231
- case "polylist":
2232
- if (skinning) {
2233
- object = new SkinnedMesh(geometry.data, material);
2234
- } else {
2235
- object = new Mesh(geometry.data, material);
2236
- }
2237
- break;
2238
- }
2239
- objects.push(object);
2240
- }
2241
- return objects;
2242
- }
2243
- function hasNode(id) {
2244
- return library.nodes[id] !== void 0;
2245
- }
2246
- function getNode(id) {
2247
- return getBuild(library.nodes[id], buildNode);
2248
- }
2249
- function parseVisualScene(xml2) {
2250
- const data = {
2251
- name: xml2.getAttribute("name"),
2252
- children: []
2253
- };
2254
- prepareNodes(xml2);
2255
- const elements = getElementsByTagName(xml2, "node");
2256
- for (let i = 0; i < elements.length; i++) {
2257
- data.children.push(parseNode(elements[i]));
2258
- }
2259
- library.visualScenes[xml2.getAttribute("id")] = data;
2260
- }
2261
- function buildVisualScene(data) {
2262
- const group = new Group();
2263
- group.name = data.name;
2264
- const children = data.children;
2265
- for (let i = 0; i < children.length; i++) {
2266
- const child = children[i];
2267
- group.add(getNode(child.id));
2268
- }
2269
- return group;
2270
- }
2271
- function hasVisualScene(id) {
2272
- return library.visualScenes[id] !== void 0;
2273
- }
2274
- function getVisualScene(id) {
2275
- return getBuild(library.visualScenes[id], buildVisualScene);
2276
- }
2277
- function parseScene(xml2) {
2278
- const instance = getElementsByTagName(xml2, "instance_visual_scene")[0];
2279
- return getVisualScene(parseId(instance.getAttribute("url")));
2280
- }
2281
- function setupAnimations() {
2282
- const clips = library.clips;
2283
- if (isEmpty(clips) === true) {
2284
- if (isEmpty(library.animations) === false) {
2285
- const tracks = [];
2286
- for (const id in library.animations) {
2287
- const animationTracks = getAnimation(id);
2288
- for (let i = 0, l = animationTracks.length; i < l; i++) {
2289
- tracks.push(animationTracks[i]);
2290
- }
2291
- }
2292
- animations.push(new AnimationClip("default", -1, tracks));
2293
- }
2294
- } else {
2295
- for (const id in clips) {
2296
- animations.push(getAnimationClip(id));
2297
- }
2298
- }
2299
- }
2300
- function parserErrorToText(parserError2) {
2301
- let result = "";
2302
- const stack = [parserError2];
2303
- while (stack.length) {
2304
- const node = stack.shift();
2305
- if (node.nodeType === Node.TEXT_NODE) {
2306
- result += node.textContent;
2307
- } else {
2308
- result += "\n";
2309
- stack.push.apply(stack, node.childNodes);
2310
- }
2311
- }
2312
- return result.trim();
2313
- }
2314
- if (text.length === 0) {
2315
- return { scene: new Scene() };
2316
- }
2317
- const xml = new DOMParser().parseFromString(text, "application/xml");
2318
- const collada = getElementsByTagName(xml, "COLLADA")[0];
2319
- const parserError = xml.getElementsByTagName("parsererror")[0];
2320
- if (parserError !== void 0) {
2321
- const errorElement = getElementsByTagName(parserError, "div")[0];
2322
- let errorText;
2323
- if (errorElement) {
2324
- errorText = errorElement.textContent;
2325
- } else {
2326
- errorText = parserErrorToText(parserError);
2327
- }
2328
- console.error("THREE.ColladaLoader: Failed to parse collada file.\n", errorText);
2329
- return null;
2330
- }
2331
- const version = collada.getAttribute("version");
2332
- console.log("THREE.ColladaLoader: File version", version);
2333
- const asset = parseAsset(getElementsByTagName(collada, "asset")[0]);
2334
- const textureLoader = new TextureLoader(this.manager);
2335
- textureLoader.setPath(this.resourcePath || path).setCrossOrigin(this.crossOrigin);
2336
- let tgaLoader;
2337
- if (TGALoader) {
2338
- tgaLoader = new TGALoader(this.manager);
2339
- tgaLoader.setPath(this.resourcePath || path);
2340
- }
2341
- const animations = [];
2342
- let kinematics = {};
2343
- let count = 0;
2344
- const library = {
2345
- animations: {},
2346
- clips: {},
2347
- controllers: {},
2348
- images: {},
2349
- effects: {},
2350
- materials: {},
2351
- cameras: {},
2352
- lights: {},
2353
- geometries: {},
2354
- nodes: {},
2355
- visualScenes: {},
2356
- kinematicsModels: {},
2357
- physicsModels: {},
2358
- kinematicsScenes: {}
2359
- };
2360
- parseLibrary(collada, "library_animations", "animation", parseAnimation);
2361
- parseLibrary(collada, "library_animation_clips", "animation_clip", parseAnimationClip);
2362
- parseLibrary(collada, "library_controllers", "controller", parseController);
2363
- parseLibrary(collada, "library_images", "image", parseImage);
2364
- parseLibrary(collada, "library_effects", "effect", parseEffect);
2365
- parseLibrary(collada, "library_materials", "material", parseMaterial);
2366
- parseLibrary(collada, "library_cameras", "camera", parseCamera);
2367
- parseLibrary(collada, "library_lights", "light", parseLight);
2368
- parseLibrary(collada, "library_geometries", "geometry", parseGeometry);
2369
- parseLibrary(collada, "library_nodes", "node", parseNode);
2370
- parseLibrary(collada, "library_visual_scenes", "visual_scene", parseVisualScene);
2371
- parseLibrary(collada, "library_kinematics_models", "kinematics_model", parseKinematicsModel);
2372
- parseLibrary(collada, "library_physics_models", "physics_model", parsePhysicsModel);
2373
- parseLibrary(collada, "scene", "instance_kinematics_scene", parseKinematicsScene);
2374
- buildLibrary(library.animations, buildAnimation);
2375
- buildLibrary(library.clips, buildAnimationClip);
2376
- buildLibrary(library.controllers, buildController);
2377
- buildLibrary(library.images, buildImage);
2378
- buildLibrary(library.effects, buildEffect);
2379
- buildLibrary(library.materials, buildMaterial);
2380
- buildLibrary(library.cameras, buildCamera);
2381
- buildLibrary(library.lights, buildLight);
2382
- buildLibrary(library.geometries, buildGeometry);
2383
- buildLibrary(library.visualScenes, buildVisualScene);
2384
- setupAnimations();
2385
- setupKinematics();
2386
- const scene = parseScene(getElementsByTagName(collada, "scene")[0]);
2387
- scene.animations = animations;
2388
- if (asset.upAxis === "Z_UP") {
2389
- scene.quaternion.setFromEuler(new Euler(-Math.PI / 2, 0, 0));
2390
- }
2391
- scene.scale.multiplyScalar(asset.unit);
2392
- return {
2393
- get animations() {
2394
- console.warn("THREE.ColladaLoader: Please access animations over scene.animations now.");
2395
- return animations;
2396
- },
2397
- kinematics,
2398
- library,
2399
- scene
2400
- };
2401
- }
2402
- }
2403
- export {
2404
- ColladaLoader
2405
- };