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,2457 +0,0 @@
1
- import { Loader, LoaderUtils, FileLoader, TextureLoader, RepeatWrapping, ClampToEdgeWrapping, Texture, MeshPhongMaterial, MeshLambertMaterial, Color, EquirectangularReflectionMapping, Matrix4, Group, Bone, PropertyBinding, Object3D, OrthographicCamera, PerspectiveCamera, PointLight, MathUtils, SpotLight, DirectionalLight, SkinnedMesh, Mesh, LineBasicMaterial, Line, Vector3, Skeleton, AmbientLight, BufferGeometry, Float32BufferAttribute, Uint16BufferAttribute, Matrix3, Vector4, AnimationClip, Quaternion, Euler, VectorKeyframeTrack, QuaternionKeyframeTrack, NumberKeyframeTrack } from "three";
2
- import { unzlibSync } from "fflate";
3
- import { NURBSCurve } from "../curves/NURBSCurve.js";
4
- let fbxTree;
5
- let connections;
6
- let sceneGraph;
7
- class FBXLoader extends Loader {
8
- constructor(manager) {
9
- super(manager);
10
- }
11
- load(url, onLoad, onProgress, onError) {
12
- const scope = this;
13
- const path = scope.path === "" ? LoaderUtils.extractUrlBase(url) : scope.path;
14
- const loader = new FileLoader(this.manager);
15
- loader.setPath(scope.path);
16
- loader.setResponseType("arraybuffer");
17
- loader.setRequestHeader(scope.requestHeader);
18
- loader.setWithCredentials(scope.withCredentials);
19
- loader.load(
20
- url,
21
- function(buffer) {
22
- try {
23
- onLoad(scope.parse(buffer, path));
24
- } catch (e) {
25
- if (onError) {
26
- onError(e);
27
- } else {
28
- console.error(e);
29
- }
30
- scope.manager.itemError(url);
31
- }
32
- },
33
- onProgress,
34
- onError
35
- );
36
- }
37
- parse(FBXBuffer, path) {
38
- if (isFbxFormatBinary(FBXBuffer)) {
39
- fbxTree = new BinaryParser().parse(FBXBuffer);
40
- } else {
41
- const FBXText = convertArrayBufferToString(FBXBuffer);
42
- if (!isFbxFormatASCII(FBXText)) {
43
- throw new Error("THREE.FBXLoader: Unknown format.");
44
- }
45
- if (getFbxVersion(FBXText) < 7e3) {
46
- throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: " + getFbxVersion(FBXText));
47
- }
48
- fbxTree = new TextParser().parse(FBXText);
49
- }
50
- const textureLoader = new TextureLoader(this.manager).setPath(this.resourcePath || path).setCrossOrigin(this.crossOrigin);
51
- return new FBXTreeParser(textureLoader, this.manager).parse(fbxTree);
52
- }
53
- }
54
- class FBXTreeParser {
55
- constructor(textureLoader, manager) {
56
- this.textureLoader = textureLoader;
57
- this.manager = manager;
58
- }
59
- parse() {
60
- connections = this.parseConnections();
61
- const images = this.parseImages();
62
- const textures = this.parseTextures(images);
63
- const materials = this.parseMaterials(textures);
64
- const deformers = this.parseDeformers();
65
- const geometryMap = new GeometryParser().parse(deformers);
66
- this.parseScene(deformers, geometryMap, materials);
67
- return sceneGraph;
68
- }
69
- // Parses FBXTree.Connections which holds parent-child connections between objects (e.g. material -> texture, model->geometry )
70
- // and details the connection type
71
- parseConnections() {
72
- const connectionMap = /* @__PURE__ */ new Map();
73
- if ("Connections" in fbxTree) {
74
- const rawConnections = fbxTree.Connections.connections;
75
- rawConnections.forEach(function(rawConnection) {
76
- const fromID = rawConnection[0];
77
- const toID = rawConnection[1];
78
- const relationship = rawConnection[2];
79
- if (!connectionMap.has(fromID)) {
80
- connectionMap.set(fromID, {
81
- parents: [],
82
- children: []
83
- });
84
- }
85
- const parentRelationship = { ID: toID, relationship };
86
- connectionMap.get(fromID).parents.push(parentRelationship);
87
- if (!connectionMap.has(toID)) {
88
- connectionMap.set(toID, {
89
- parents: [],
90
- children: []
91
- });
92
- }
93
- const childRelationship = { ID: fromID, relationship };
94
- connectionMap.get(toID).children.push(childRelationship);
95
- });
96
- }
97
- return connectionMap;
98
- }
99
- // Parse FBXTree.Objects.Video for embedded image data
100
- // These images are connected to textures in FBXTree.Objects.Textures
101
- // via FBXTree.Connections.
102
- parseImages() {
103
- const images = {};
104
- const blobs = {};
105
- if ("Video" in fbxTree.Objects) {
106
- const videoNodes = fbxTree.Objects.Video;
107
- for (const nodeID in videoNodes) {
108
- const videoNode = videoNodes[nodeID];
109
- const id = parseInt(nodeID);
110
- images[id] = videoNode.RelativeFilename || videoNode.Filename;
111
- if ("Content" in videoNode) {
112
- const arrayBufferContent = videoNode.Content instanceof ArrayBuffer && videoNode.Content.byteLength > 0;
113
- const base64Content = typeof videoNode.Content === "string" && videoNode.Content !== "";
114
- if (arrayBufferContent || base64Content) {
115
- const image = this.parseImage(videoNodes[nodeID]);
116
- blobs[videoNode.RelativeFilename || videoNode.Filename] = image;
117
- }
118
- }
119
- }
120
- }
121
- for (const id in images) {
122
- const filename = images[id];
123
- if (blobs[filename] !== void 0)
124
- images[id] = blobs[filename];
125
- else
126
- images[id] = images[id].split("\\").pop();
127
- }
128
- return images;
129
- }
130
- // Parse embedded image data in FBXTree.Video.Content
131
- parseImage(videoNode) {
132
- const content = videoNode.Content;
133
- const fileName = videoNode.RelativeFilename || videoNode.Filename;
134
- const extension = fileName.slice(fileName.lastIndexOf(".") + 1).toLowerCase();
135
- let type;
136
- switch (extension) {
137
- case "bmp":
138
- type = "image/bmp";
139
- break;
140
- case "jpg":
141
- case "jpeg":
142
- type = "image/jpeg";
143
- break;
144
- case "png":
145
- type = "image/png";
146
- break;
147
- case "tif":
148
- type = "image/tiff";
149
- break;
150
- case "tga":
151
- if (this.manager.getHandler(".tga") === null) {
152
- console.warn("FBXLoader: TGA loader not found, skipping ", fileName);
153
- }
154
- type = "image/tga";
155
- break;
156
- default:
157
- console.warn('FBXLoader: Image type "' + extension + '" is not supported.');
158
- return;
159
- }
160
- if (typeof content === "string") {
161
- return "data:" + type + ";base64," + content;
162
- } else {
163
- const array = new Uint8Array(content);
164
- return window.URL.createObjectURL(new Blob([array], { type }));
165
- }
166
- }
167
- // Parse nodes in FBXTree.Objects.Texture
168
- // These contain details such as UV scaling, cropping, rotation etc and are connected
169
- // to images in FBXTree.Objects.Video
170
- parseTextures(images) {
171
- const textureMap = /* @__PURE__ */ new Map();
172
- if ("Texture" in fbxTree.Objects) {
173
- const textureNodes = fbxTree.Objects.Texture;
174
- for (const nodeID in textureNodes) {
175
- const texture = this.parseTexture(textureNodes[nodeID], images);
176
- textureMap.set(parseInt(nodeID), texture);
177
- }
178
- }
179
- return textureMap;
180
- }
181
- // Parse individual node in FBXTree.Objects.Texture
182
- parseTexture(textureNode, images) {
183
- const texture = this.loadTexture(textureNode, images);
184
- texture.ID = textureNode.id;
185
- texture.name = textureNode.attrName;
186
- const wrapModeU = textureNode.WrapModeU;
187
- const wrapModeV = textureNode.WrapModeV;
188
- const valueU = wrapModeU !== void 0 ? wrapModeU.value : 0;
189
- const valueV = wrapModeV !== void 0 ? wrapModeV.value : 0;
190
- texture.wrapS = valueU === 0 ? RepeatWrapping : ClampToEdgeWrapping;
191
- texture.wrapT = valueV === 0 ? RepeatWrapping : ClampToEdgeWrapping;
192
- if ("Scaling" in textureNode) {
193
- const values = textureNode.Scaling.value;
194
- texture.repeat.x = values[0];
195
- texture.repeat.y = values[1];
196
- }
197
- return texture;
198
- }
199
- // load a texture specified as a blob or data URI, or via an external URL using TextureLoader
200
- loadTexture(textureNode, images) {
201
- let fileName;
202
- const currentPath = this.textureLoader.path;
203
- const children = connections.get(textureNode.id).children;
204
- if (children !== void 0 && children.length > 0 && images[children[0].ID] !== void 0) {
205
- fileName = images[children[0].ID];
206
- if (fileName.indexOf("blob:") === 0 || fileName.indexOf("data:") === 0) {
207
- this.textureLoader.setPath(void 0);
208
- }
209
- }
210
- let texture;
211
- const extension = textureNode.FileName.slice(-3).toLowerCase();
212
- if (extension === "tga") {
213
- const loader = this.manager.getHandler(".tga");
214
- if (loader === null) {
215
- console.warn("FBXLoader: TGA loader not found, creating placeholder texture for", textureNode.RelativeFilename);
216
- texture = new Texture();
217
- } else {
218
- loader.setPath(this.textureLoader.path);
219
- texture = loader.load(fileName);
220
- }
221
- } else if (extension === "psd") {
222
- console.warn(
223
- "FBXLoader: PSD textures are not supported, creating placeholder texture for",
224
- textureNode.RelativeFilename
225
- );
226
- texture = new Texture();
227
- } else {
228
- texture = this.textureLoader.load(fileName);
229
- }
230
- this.textureLoader.setPath(currentPath);
231
- return texture;
232
- }
233
- // Parse nodes in FBXTree.Objects.Material
234
- parseMaterials(textureMap) {
235
- const materialMap = /* @__PURE__ */ new Map();
236
- if ("Material" in fbxTree.Objects) {
237
- const materialNodes = fbxTree.Objects.Material;
238
- for (const nodeID in materialNodes) {
239
- const material = this.parseMaterial(materialNodes[nodeID], textureMap);
240
- if (material !== null)
241
- materialMap.set(parseInt(nodeID), material);
242
- }
243
- }
244
- return materialMap;
245
- }
246
- // Parse single node in FBXTree.Objects.Material
247
- // Materials are connected to texture maps in FBXTree.Objects.Textures
248
- // FBX format currently only supports Lambert and Phong shading models
249
- parseMaterial(materialNode, textureMap) {
250
- const ID = materialNode.id;
251
- const name = materialNode.attrName;
252
- let type = materialNode.ShadingModel;
253
- if (typeof type === "object") {
254
- type = type.value;
255
- }
256
- if (!connections.has(ID))
257
- return null;
258
- const parameters = this.parseParameters(materialNode, textureMap, ID);
259
- let material;
260
- switch (type.toLowerCase()) {
261
- case "phong":
262
- material = new MeshPhongMaterial();
263
- break;
264
- case "lambert":
265
- material = new MeshLambertMaterial();
266
- break;
267
- default:
268
- console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.', type);
269
- material = new MeshPhongMaterial();
270
- break;
271
- }
272
- material.setValues(parameters);
273
- material.name = name;
274
- return material;
275
- }
276
- // Parse FBX material and return parameters suitable for a three.js material
277
- // Also parse the texture map and return any textures associated with the material
278
- parseParameters(materialNode, textureMap, ID) {
279
- const parameters = {};
280
- if (materialNode.BumpFactor) {
281
- parameters.bumpScale = materialNode.BumpFactor.value;
282
- }
283
- if (materialNode.Diffuse) {
284
- parameters.color = new Color().fromArray(materialNode.Diffuse.value);
285
- } else if (materialNode.DiffuseColor && (materialNode.DiffuseColor.type === "Color" || materialNode.DiffuseColor.type === "ColorRGB")) {
286
- parameters.color = new Color().fromArray(materialNode.DiffuseColor.value);
287
- }
288
- if (materialNode.DisplacementFactor) {
289
- parameters.displacementScale = materialNode.DisplacementFactor.value;
290
- }
291
- if (materialNode.Emissive) {
292
- parameters.emissive = new Color().fromArray(materialNode.Emissive.value);
293
- } else if (materialNode.EmissiveColor && (materialNode.EmissiveColor.type === "Color" || materialNode.EmissiveColor.type === "ColorRGB")) {
294
- parameters.emissive = new Color().fromArray(materialNode.EmissiveColor.value);
295
- }
296
- if (materialNode.EmissiveFactor) {
297
- parameters.emissiveIntensity = parseFloat(materialNode.EmissiveFactor.value);
298
- }
299
- if (materialNode.Opacity) {
300
- parameters.opacity = parseFloat(materialNode.Opacity.value);
301
- }
302
- if (parameters.opacity < 1) {
303
- parameters.transparent = true;
304
- }
305
- if (materialNode.ReflectionFactor) {
306
- parameters.reflectivity = materialNode.ReflectionFactor.value;
307
- }
308
- if (materialNode.Shininess) {
309
- parameters.shininess = materialNode.Shininess.value;
310
- }
311
- if (materialNode.Specular) {
312
- parameters.specular = new Color().fromArray(materialNode.Specular.value);
313
- } else if (materialNode.SpecularColor && materialNode.SpecularColor.type === "Color") {
314
- parameters.specular = new Color().fromArray(materialNode.SpecularColor.value);
315
- }
316
- const scope = this;
317
- connections.get(ID).children.forEach(function(child) {
318
- const type = child.relationship;
319
- switch (type) {
320
- case "Bump":
321
- parameters.bumpMap = scope.getTexture(textureMap, child.ID);
322
- break;
323
- case "Maya|TEX_ao_map":
324
- parameters.aoMap = scope.getTexture(textureMap, child.ID);
325
- break;
326
- case "DiffuseColor":
327
- case "Maya|TEX_color_map":
328
- parameters.map = scope.getTexture(textureMap, child.ID);
329
- if (parameters.map !== void 0) {
330
- if ("colorSpace" in parameters.map)
331
- parameters.map.colorSpace = "srgb";
332
- else
333
- parameters.map.encoding = 3001;
334
- }
335
- break;
336
- case "DisplacementColor":
337
- parameters.displacementMap = scope.getTexture(textureMap, child.ID);
338
- break;
339
- case "EmissiveColor":
340
- parameters.emissiveMap = scope.getTexture(textureMap, child.ID);
341
- if (parameters.emissiveMap !== void 0) {
342
- if ("colorSpace" in parameters.emissiveMap)
343
- parameters.emissiveMap.colorSpace = "srgb";
344
- else
345
- parameters.emissiveMap.encoding = 3001;
346
- }
347
- break;
348
- case "NormalMap":
349
- case "Maya|TEX_normal_map":
350
- parameters.normalMap = scope.getTexture(textureMap, child.ID);
351
- break;
352
- case "ReflectionColor":
353
- parameters.envMap = scope.getTexture(textureMap, child.ID);
354
- if (parameters.envMap !== void 0) {
355
- parameters.envMap.mapping = EquirectangularReflectionMapping;
356
- if ("colorSpace" in parameters.envMap)
357
- parameters.envMap.colorSpace = "srgb";
358
- else
359
- parameters.envMap.encoding = 3001;
360
- }
361
- break;
362
- case "SpecularColor":
363
- parameters.specularMap = scope.getTexture(textureMap, child.ID);
364
- if (parameters.specularMap !== void 0) {
365
- if ("colorSpace" in parameters.specularMap)
366
- parameters.specularMap.colorSpace = "srgb";
367
- else
368
- parameters.specularMap.encoding = 3001;
369
- }
370
- break;
371
- case "TransparentColor":
372
- case "TransparencyFactor":
373
- parameters.alphaMap = scope.getTexture(textureMap, child.ID);
374
- parameters.transparent = true;
375
- break;
376
- case "AmbientColor":
377
- case "ShininessExponent":
378
- case "SpecularFactor":
379
- case "VectorDisplacementColor":
380
- default:
381
- console.warn("THREE.FBXLoader: %s map is not supported in three.js, skipping texture.", type);
382
- break;
383
- }
384
- });
385
- return parameters;
386
- }
387
- // get a texture from the textureMap for use by a material.
388
- getTexture(textureMap, id) {
389
- if ("LayeredTexture" in fbxTree.Objects && id in fbxTree.Objects.LayeredTexture) {
390
- console.warn("THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer.");
391
- id = connections.get(id).children[0].ID;
392
- }
393
- return textureMap.get(id);
394
- }
395
- // Parse nodes in FBXTree.Objects.Deformer
396
- // Deformer node can contain skinning or Vertex Cache animation data, however only skinning is supported here
397
- // Generates map of Skeleton-like objects for use later when generating and binding skeletons.
398
- parseDeformers() {
399
- const skeletons = {};
400
- const morphTargets = {};
401
- if ("Deformer" in fbxTree.Objects) {
402
- const DeformerNodes = fbxTree.Objects.Deformer;
403
- for (const nodeID in DeformerNodes) {
404
- const deformerNode = DeformerNodes[nodeID];
405
- const relationships = connections.get(parseInt(nodeID));
406
- if (deformerNode.attrType === "Skin") {
407
- const skeleton = this.parseSkeleton(relationships, DeformerNodes);
408
- skeleton.ID = nodeID;
409
- if (relationships.parents.length > 1) {
410
- console.warn("THREE.FBXLoader: skeleton attached to more than one geometry is not supported.");
411
- }
412
- skeleton.geometryID = relationships.parents[0].ID;
413
- skeletons[nodeID] = skeleton;
414
- } else if (deformerNode.attrType === "BlendShape") {
415
- const morphTarget = {
416
- id: nodeID
417
- };
418
- morphTarget.rawTargets = this.parseMorphTargets(relationships, DeformerNodes);
419
- morphTarget.id = nodeID;
420
- if (relationships.parents.length > 1) {
421
- console.warn("THREE.FBXLoader: morph target attached to more than one geometry is not supported.");
422
- }
423
- morphTargets[nodeID] = morphTarget;
424
- }
425
- }
426
- }
427
- return {
428
- skeletons,
429
- morphTargets
430
- };
431
- }
432
- // Parse single nodes in FBXTree.Objects.Deformer
433
- // The top level skeleton node has type 'Skin' and sub nodes have type 'Cluster'
434
- // Each skin node represents a skeleton and each cluster node represents a bone
435
- parseSkeleton(relationships, deformerNodes) {
436
- const rawBones = [];
437
- relationships.children.forEach(function(child) {
438
- const boneNode = deformerNodes[child.ID];
439
- if (boneNode.attrType !== "Cluster")
440
- return;
441
- const rawBone = {
442
- ID: child.ID,
443
- indices: [],
444
- weights: [],
445
- transformLink: new Matrix4().fromArray(boneNode.TransformLink.a)
446
- // transform: new Matrix4().fromArray( boneNode.Transform.a ),
447
- // linkMode: boneNode.Mode,
448
- };
449
- if ("Indexes" in boneNode) {
450
- rawBone.indices = boneNode.Indexes.a;
451
- rawBone.weights = boneNode.Weights.a;
452
- }
453
- rawBones.push(rawBone);
454
- });
455
- return {
456
- rawBones,
457
- bones: []
458
- };
459
- }
460
- // The top level morph deformer node has type "BlendShape" and sub nodes have type "BlendShapeChannel"
461
- parseMorphTargets(relationships, deformerNodes) {
462
- const rawMorphTargets = [];
463
- for (let i = 0; i < relationships.children.length; i++) {
464
- const child = relationships.children[i];
465
- const morphTargetNode = deformerNodes[child.ID];
466
- const rawMorphTarget = {
467
- name: morphTargetNode.attrName,
468
- initialWeight: morphTargetNode.DeformPercent,
469
- id: morphTargetNode.id,
470
- fullWeights: morphTargetNode.FullWeights.a
471
- };
472
- if (morphTargetNode.attrType !== "BlendShapeChannel")
473
- return;
474
- rawMorphTarget.geoID = connections.get(parseInt(child.ID)).children.filter(function(child2) {
475
- return child2.relationship === void 0;
476
- })[0].ID;
477
- rawMorphTargets.push(rawMorphTarget);
478
- }
479
- return rawMorphTargets;
480
- }
481
- // create the main Group() to be returned by the loader
482
- parseScene(deformers, geometryMap, materialMap) {
483
- sceneGraph = new Group();
484
- const modelMap = this.parseModels(deformers.skeletons, geometryMap, materialMap);
485
- const modelNodes = fbxTree.Objects.Model;
486
- const scope = this;
487
- modelMap.forEach(function(model) {
488
- const modelNode = modelNodes[model.ID];
489
- scope.setLookAtProperties(model, modelNode);
490
- const parentConnections = connections.get(model.ID).parents;
491
- parentConnections.forEach(function(connection) {
492
- const parent = modelMap.get(connection.ID);
493
- if (parent !== void 0)
494
- parent.add(model);
495
- });
496
- if (model.parent === null) {
497
- sceneGraph.add(model);
498
- }
499
- });
500
- this.bindSkeleton(deformers.skeletons, geometryMap, modelMap);
501
- this.createAmbientLight();
502
- sceneGraph.traverse(function(node) {
503
- if (node.userData.transformData) {
504
- if (node.parent) {
505
- node.userData.transformData.parentMatrix = node.parent.matrix;
506
- node.userData.transformData.parentMatrixWorld = node.parent.matrixWorld;
507
- }
508
- const transform = generateTransform(node.userData.transformData);
509
- node.applyMatrix4(transform);
510
- node.updateWorldMatrix();
511
- }
512
- });
513
- const animations = new AnimationParser().parse();
514
- if (sceneGraph.children.length === 1 && sceneGraph.children[0].isGroup) {
515
- sceneGraph.children[0].animations = animations;
516
- sceneGraph = sceneGraph.children[0];
517
- }
518
- sceneGraph.animations = animations;
519
- }
520
- // parse nodes in FBXTree.Objects.Model
521
- parseModels(skeletons, geometryMap, materialMap) {
522
- const modelMap = /* @__PURE__ */ new Map();
523
- const modelNodes = fbxTree.Objects.Model;
524
- for (const nodeID in modelNodes) {
525
- const id = parseInt(nodeID);
526
- const node = modelNodes[nodeID];
527
- const relationships = connections.get(id);
528
- let model = this.buildSkeleton(relationships, skeletons, id, node.attrName);
529
- if (!model) {
530
- switch (node.attrType) {
531
- case "Camera":
532
- model = this.createCamera(relationships);
533
- break;
534
- case "Light":
535
- model = this.createLight(relationships);
536
- break;
537
- case "Mesh":
538
- model = this.createMesh(relationships, geometryMap, materialMap);
539
- break;
540
- case "NurbsCurve":
541
- model = this.createCurve(relationships, geometryMap);
542
- break;
543
- case "LimbNode":
544
- case "Root":
545
- model = new Bone();
546
- break;
547
- case "Null":
548
- default:
549
- model = new Group();
550
- break;
551
- }
552
- model.name = node.attrName ? PropertyBinding.sanitizeNodeName(node.attrName) : "";
553
- model.ID = id;
554
- }
555
- this.getTransformData(model, node);
556
- modelMap.set(id, model);
557
- }
558
- return modelMap;
559
- }
560
- buildSkeleton(relationships, skeletons, id, name) {
561
- let bone = null;
562
- relationships.parents.forEach(function(parent) {
563
- for (const ID in skeletons) {
564
- const skeleton = skeletons[ID];
565
- skeleton.rawBones.forEach(function(rawBone, i) {
566
- if (rawBone.ID === parent.ID) {
567
- const subBone = bone;
568
- bone = new Bone();
569
- bone.matrixWorld.copy(rawBone.transformLink);
570
- bone.name = name ? PropertyBinding.sanitizeNodeName(name) : "";
571
- bone.ID = id;
572
- skeleton.bones[i] = bone;
573
- if (subBone !== null) {
574
- bone.add(subBone);
575
- }
576
- }
577
- });
578
- }
579
- });
580
- return bone;
581
- }
582
- // create a PerspectiveCamera or OrthographicCamera
583
- createCamera(relationships) {
584
- let model;
585
- let cameraAttribute;
586
- relationships.children.forEach(function(child) {
587
- const attr = fbxTree.Objects.NodeAttribute[child.ID];
588
- if (attr !== void 0) {
589
- cameraAttribute = attr;
590
- }
591
- });
592
- if (cameraAttribute === void 0) {
593
- model = new Object3D();
594
- } else {
595
- let type = 0;
596
- if (cameraAttribute.CameraProjectionType !== void 0 && cameraAttribute.CameraProjectionType.value === 1) {
597
- type = 1;
598
- }
599
- let nearClippingPlane = 1;
600
- if (cameraAttribute.NearPlane !== void 0) {
601
- nearClippingPlane = cameraAttribute.NearPlane.value / 1e3;
602
- }
603
- let farClippingPlane = 1e3;
604
- if (cameraAttribute.FarPlane !== void 0) {
605
- farClippingPlane = cameraAttribute.FarPlane.value / 1e3;
606
- }
607
- let width = window.innerWidth;
608
- let height = window.innerHeight;
609
- if (cameraAttribute.AspectWidth !== void 0 && cameraAttribute.AspectHeight !== void 0) {
610
- width = cameraAttribute.AspectWidth.value;
611
- height = cameraAttribute.AspectHeight.value;
612
- }
613
- const aspect = width / height;
614
- let fov = 45;
615
- if (cameraAttribute.FieldOfView !== void 0) {
616
- fov = cameraAttribute.FieldOfView.value;
617
- }
618
- const focalLength = cameraAttribute.FocalLength ? cameraAttribute.FocalLength.value : null;
619
- switch (type) {
620
- case 0:
621
- model = new PerspectiveCamera(fov, aspect, nearClippingPlane, farClippingPlane);
622
- if (focalLength !== null)
623
- model.setFocalLength(focalLength);
624
- break;
625
- case 1:
626
- model = new OrthographicCamera(
627
- -width / 2,
628
- width / 2,
629
- height / 2,
630
- -height / 2,
631
- nearClippingPlane,
632
- farClippingPlane
633
- );
634
- break;
635
- default:
636
- console.warn("THREE.FBXLoader: Unknown camera type " + type + ".");
637
- model = new Object3D();
638
- break;
639
- }
640
- }
641
- return model;
642
- }
643
- // Create a DirectionalLight, PointLight or SpotLight
644
- createLight(relationships) {
645
- let model;
646
- let lightAttribute;
647
- relationships.children.forEach(function(child) {
648
- const attr = fbxTree.Objects.NodeAttribute[child.ID];
649
- if (attr !== void 0) {
650
- lightAttribute = attr;
651
- }
652
- });
653
- if (lightAttribute === void 0) {
654
- model = new Object3D();
655
- } else {
656
- let type;
657
- if (lightAttribute.LightType === void 0) {
658
- type = 0;
659
- } else {
660
- type = lightAttribute.LightType.value;
661
- }
662
- let color = 16777215;
663
- if (lightAttribute.Color !== void 0) {
664
- color = new Color().fromArray(lightAttribute.Color.value);
665
- }
666
- let intensity = lightAttribute.Intensity === void 0 ? 1 : lightAttribute.Intensity.value / 100;
667
- if (lightAttribute.CastLightOnObject !== void 0 && lightAttribute.CastLightOnObject.value === 0) {
668
- intensity = 0;
669
- }
670
- let distance = 0;
671
- if (lightAttribute.FarAttenuationEnd !== void 0) {
672
- if (lightAttribute.EnableFarAttenuation !== void 0 && lightAttribute.EnableFarAttenuation.value === 0) {
673
- distance = 0;
674
- } else {
675
- distance = lightAttribute.FarAttenuationEnd.value;
676
- }
677
- }
678
- const decay = 1;
679
- switch (type) {
680
- case 0:
681
- model = new PointLight(color, intensity, distance, decay);
682
- break;
683
- case 1:
684
- model = new DirectionalLight(color, intensity);
685
- break;
686
- case 2:
687
- let angle = Math.PI / 3;
688
- if (lightAttribute.InnerAngle !== void 0) {
689
- angle = MathUtils.degToRad(lightAttribute.InnerAngle.value);
690
- }
691
- let penumbra = 0;
692
- if (lightAttribute.OuterAngle !== void 0) {
693
- penumbra = MathUtils.degToRad(lightAttribute.OuterAngle.value);
694
- penumbra = Math.max(penumbra, 1);
695
- }
696
- model = new SpotLight(color, intensity, distance, angle, penumbra, decay);
697
- break;
698
- default:
699
- console.warn(
700
- "THREE.FBXLoader: Unknown light type " + lightAttribute.LightType.value + ", defaulting to a PointLight."
701
- );
702
- model = new PointLight(color, intensity);
703
- break;
704
- }
705
- if (lightAttribute.CastShadows !== void 0 && lightAttribute.CastShadows.value === 1) {
706
- model.castShadow = true;
707
- }
708
- }
709
- return model;
710
- }
711
- createMesh(relationships, geometryMap, materialMap) {
712
- let model;
713
- let geometry = null;
714
- let material = null;
715
- const materials = [];
716
- relationships.children.forEach(function(child) {
717
- if (geometryMap.has(child.ID)) {
718
- geometry = geometryMap.get(child.ID);
719
- }
720
- if (materialMap.has(child.ID)) {
721
- materials.push(materialMap.get(child.ID));
722
- }
723
- });
724
- if (materials.length > 1) {
725
- material = materials;
726
- } else if (materials.length > 0) {
727
- material = materials[0];
728
- } else {
729
- material = new MeshPhongMaterial({ color: 13421772 });
730
- materials.push(material);
731
- }
732
- if ("color" in geometry.attributes) {
733
- materials.forEach(function(material2) {
734
- material2.vertexColors = true;
735
- });
736
- }
737
- if (geometry.FBX_Deformer) {
738
- model = new SkinnedMesh(geometry, material);
739
- model.normalizeSkinWeights();
740
- } else {
741
- model = new Mesh(geometry, material);
742
- }
743
- return model;
744
- }
745
- createCurve(relationships, geometryMap) {
746
- const geometry = relationships.children.reduce(function(geo, child) {
747
- if (geometryMap.has(child.ID))
748
- geo = geometryMap.get(child.ID);
749
- return geo;
750
- }, null);
751
- const material = new LineBasicMaterial({ color: 3342591, linewidth: 1 });
752
- return new Line(geometry, material);
753
- }
754
- // parse the model node for transform data
755
- getTransformData(model, modelNode) {
756
- const transformData = {};
757
- if ("InheritType" in modelNode)
758
- transformData.inheritType = parseInt(modelNode.InheritType.value);
759
- if ("RotationOrder" in modelNode)
760
- transformData.eulerOrder = getEulerOrder(modelNode.RotationOrder.value);
761
- else
762
- transformData.eulerOrder = "ZYX";
763
- if ("Lcl_Translation" in modelNode)
764
- transformData.translation = modelNode.Lcl_Translation.value;
765
- if ("PreRotation" in modelNode)
766
- transformData.preRotation = modelNode.PreRotation.value;
767
- if ("Lcl_Rotation" in modelNode)
768
- transformData.rotation = modelNode.Lcl_Rotation.value;
769
- if ("PostRotation" in modelNode)
770
- transformData.postRotation = modelNode.PostRotation.value;
771
- if ("Lcl_Scaling" in modelNode)
772
- transformData.scale = modelNode.Lcl_Scaling.value;
773
- if ("ScalingOffset" in modelNode)
774
- transformData.scalingOffset = modelNode.ScalingOffset.value;
775
- if ("ScalingPivot" in modelNode)
776
- transformData.scalingPivot = modelNode.ScalingPivot.value;
777
- if ("RotationOffset" in modelNode)
778
- transformData.rotationOffset = modelNode.RotationOffset.value;
779
- if ("RotationPivot" in modelNode)
780
- transformData.rotationPivot = modelNode.RotationPivot.value;
781
- model.userData.transformData = transformData;
782
- }
783
- setLookAtProperties(model, modelNode) {
784
- if ("LookAtProperty" in modelNode) {
785
- const children = connections.get(model.ID).children;
786
- children.forEach(function(child) {
787
- if (child.relationship === "LookAtProperty") {
788
- const lookAtTarget = fbxTree.Objects.Model[child.ID];
789
- if ("Lcl_Translation" in lookAtTarget) {
790
- const pos = lookAtTarget.Lcl_Translation.value;
791
- if (model.target !== void 0) {
792
- model.target.position.fromArray(pos);
793
- sceneGraph.add(model.target);
794
- } else {
795
- model.lookAt(new Vector3().fromArray(pos));
796
- }
797
- }
798
- }
799
- });
800
- }
801
- }
802
- bindSkeleton(skeletons, geometryMap, modelMap) {
803
- const bindMatrices = this.parsePoseNodes();
804
- for (const ID in skeletons) {
805
- const skeleton = skeletons[ID];
806
- const parents = connections.get(parseInt(skeleton.ID)).parents;
807
- parents.forEach(function(parent) {
808
- if (geometryMap.has(parent.ID)) {
809
- const geoID = parent.ID;
810
- const geoRelationships = connections.get(geoID);
811
- geoRelationships.parents.forEach(function(geoConnParent) {
812
- if (modelMap.has(geoConnParent.ID)) {
813
- const model = modelMap.get(geoConnParent.ID);
814
- model.bind(new Skeleton(skeleton.bones), bindMatrices[geoConnParent.ID]);
815
- }
816
- });
817
- }
818
- });
819
- }
820
- }
821
- parsePoseNodes() {
822
- const bindMatrices = {};
823
- if ("Pose" in fbxTree.Objects) {
824
- const BindPoseNode = fbxTree.Objects.Pose;
825
- for (const nodeID in BindPoseNode) {
826
- if (BindPoseNode[nodeID].attrType === "BindPose" && BindPoseNode[nodeID].NbPoseNodes > 0) {
827
- const poseNodes = BindPoseNode[nodeID].PoseNode;
828
- if (Array.isArray(poseNodes)) {
829
- poseNodes.forEach(function(poseNode) {
830
- bindMatrices[poseNode.Node] = new Matrix4().fromArray(poseNode.Matrix.a);
831
- });
832
- } else {
833
- bindMatrices[poseNodes.Node] = new Matrix4().fromArray(poseNodes.Matrix.a);
834
- }
835
- }
836
- }
837
- }
838
- return bindMatrices;
839
- }
840
- // Parse ambient color in FBXTree.GlobalSettings - if it's not set to black (default), create an ambient light
841
- createAmbientLight() {
842
- if ("GlobalSettings" in fbxTree && "AmbientColor" in fbxTree.GlobalSettings) {
843
- const ambientColor = fbxTree.GlobalSettings.AmbientColor.value;
844
- const r = ambientColor[0];
845
- const g = ambientColor[1];
846
- const b = ambientColor[2];
847
- if (r !== 0 || g !== 0 || b !== 0) {
848
- const color = new Color(r, g, b);
849
- sceneGraph.add(new AmbientLight(color, 1));
850
- }
851
- }
852
- }
853
- }
854
- class GeometryParser {
855
- // Parse nodes in FBXTree.Objects.Geometry
856
- parse(deformers) {
857
- const geometryMap = /* @__PURE__ */ new Map();
858
- if ("Geometry" in fbxTree.Objects) {
859
- const geoNodes = fbxTree.Objects.Geometry;
860
- for (const nodeID in geoNodes) {
861
- const relationships = connections.get(parseInt(nodeID));
862
- const geo = this.parseGeometry(relationships, geoNodes[nodeID], deformers);
863
- geometryMap.set(parseInt(nodeID), geo);
864
- }
865
- }
866
- return geometryMap;
867
- }
868
- // Parse single node in FBXTree.Objects.Geometry
869
- parseGeometry(relationships, geoNode, deformers) {
870
- switch (geoNode.attrType) {
871
- case "Mesh":
872
- return this.parseMeshGeometry(relationships, geoNode, deformers);
873
- break;
874
- case "NurbsCurve":
875
- return this.parseNurbsGeometry(geoNode);
876
- break;
877
- }
878
- }
879
- // Parse single node mesh geometry in FBXTree.Objects.Geometry
880
- parseMeshGeometry(relationships, geoNode, deformers) {
881
- const skeletons = deformers.skeletons;
882
- const morphTargets = [];
883
- const modelNodes = relationships.parents.map(function(parent) {
884
- return fbxTree.Objects.Model[parent.ID];
885
- });
886
- if (modelNodes.length === 0)
887
- return;
888
- const skeleton = relationships.children.reduce(function(skeleton2, child) {
889
- if (skeletons[child.ID] !== void 0)
890
- skeleton2 = skeletons[child.ID];
891
- return skeleton2;
892
- }, null);
893
- relationships.children.forEach(function(child) {
894
- if (deformers.morphTargets[child.ID] !== void 0) {
895
- morphTargets.push(deformers.morphTargets[child.ID]);
896
- }
897
- });
898
- const modelNode = modelNodes[0];
899
- const transformData = {};
900
- if ("RotationOrder" in modelNode)
901
- transformData.eulerOrder = getEulerOrder(modelNode.RotationOrder.value);
902
- if ("InheritType" in modelNode)
903
- transformData.inheritType = parseInt(modelNode.InheritType.value);
904
- if ("GeometricTranslation" in modelNode)
905
- transformData.translation = modelNode.GeometricTranslation.value;
906
- if ("GeometricRotation" in modelNode)
907
- transformData.rotation = modelNode.GeometricRotation.value;
908
- if ("GeometricScaling" in modelNode)
909
- transformData.scale = modelNode.GeometricScaling.value;
910
- const transform = generateTransform(transformData);
911
- return this.genGeometry(geoNode, skeleton, morphTargets, transform);
912
- }
913
- // Generate a BufferGeometry from a node in FBXTree.Objects.Geometry
914
- genGeometry(geoNode, skeleton, morphTargets, preTransform) {
915
- const geo = new BufferGeometry();
916
- if (geoNode.attrName)
917
- geo.name = geoNode.attrName;
918
- const geoInfo = this.parseGeoNode(geoNode, skeleton);
919
- const buffers = this.genBuffers(geoInfo);
920
- const positionAttribute = new Float32BufferAttribute(buffers.vertex, 3);
921
- positionAttribute.applyMatrix4(preTransform);
922
- geo.setAttribute("position", positionAttribute);
923
- if (buffers.colors.length > 0) {
924
- geo.setAttribute("color", new Float32BufferAttribute(buffers.colors, 3));
925
- }
926
- if (skeleton) {
927
- geo.setAttribute("skinIndex", new Uint16BufferAttribute(buffers.weightsIndices, 4));
928
- geo.setAttribute("skinWeight", new Float32BufferAttribute(buffers.vertexWeights, 4));
929
- geo.FBX_Deformer = skeleton;
930
- }
931
- if (buffers.normal.length > 0) {
932
- const normalMatrix = new Matrix3().getNormalMatrix(preTransform);
933
- const normalAttribute = new Float32BufferAttribute(buffers.normal, 3);
934
- normalAttribute.applyNormalMatrix(normalMatrix);
935
- geo.setAttribute("normal", normalAttribute);
936
- }
937
- buffers.uvs.forEach(function(uvBuffer, i) {
938
- let name = "uv" + (i + 1).toString();
939
- if (i === 0) {
940
- name = "uv";
941
- }
942
- geo.setAttribute(name, new Float32BufferAttribute(buffers.uvs[i], 2));
943
- });
944
- if (geoInfo.material && geoInfo.material.mappingType !== "AllSame") {
945
- let prevMaterialIndex = buffers.materialIndex[0];
946
- let startIndex = 0;
947
- buffers.materialIndex.forEach(function(currentIndex, i) {
948
- if (currentIndex !== prevMaterialIndex) {
949
- geo.addGroup(startIndex, i - startIndex, prevMaterialIndex);
950
- prevMaterialIndex = currentIndex;
951
- startIndex = i;
952
- }
953
- });
954
- if (geo.groups.length > 0) {
955
- const lastGroup = geo.groups[geo.groups.length - 1];
956
- const lastIndex = lastGroup.start + lastGroup.count;
957
- if (lastIndex !== buffers.materialIndex.length) {
958
- geo.addGroup(lastIndex, buffers.materialIndex.length - lastIndex, prevMaterialIndex);
959
- }
960
- }
961
- if (geo.groups.length === 0) {
962
- geo.addGroup(0, buffers.materialIndex.length, buffers.materialIndex[0]);
963
- }
964
- }
965
- this.addMorphTargets(geo, geoNode, morphTargets, preTransform);
966
- return geo;
967
- }
968
- parseGeoNode(geoNode, skeleton) {
969
- const geoInfo = {};
970
- geoInfo.vertexPositions = geoNode.Vertices !== void 0 ? geoNode.Vertices.a : [];
971
- geoInfo.vertexIndices = geoNode.PolygonVertexIndex !== void 0 ? geoNode.PolygonVertexIndex.a : [];
972
- if (geoNode.LayerElementColor) {
973
- geoInfo.color = this.parseVertexColors(geoNode.LayerElementColor[0]);
974
- }
975
- if (geoNode.LayerElementMaterial) {
976
- geoInfo.material = this.parseMaterialIndices(geoNode.LayerElementMaterial[0]);
977
- }
978
- if (geoNode.LayerElementNormal) {
979
- geoInfo.normal = this.parseNormals(geoNode.LayerElementNormal[0]);
980
- }
981
- if (geoNode.LayerElementUV) {
982
- geoInfo.uv = [];
983
- let i = 0;
984
- while (geoNode.LayerElementUV[i]) {
985
- if (geoNode.LayerElementUV[i].UV) {
986
- geoInfo.uv.push(this.parseUVs(geoNode.LayerElementUV[i]));
987
- }
988
- i++;
989
- }
990
- }
991
- geoInfo.weightTable = {};
992
- if (skeleton !== null) {
993
- geoInfo.skeleton = skeleton;
994
- skeleton.rawBones.forEach(function(rawBone, i) {
995
- rawBone.indices.forEach(function(index, j) {
996
- if (geoInfo.weightTable[index] === void 0)
997
- geoInfo.weightTable[index] = [];
998
- geoInfo.weightTable[index].push({
999
- id: i,
1000
- weight: rawBone.weights[j]
1001
- });
1002
- });
1003
- });
1004
- }
1005
- return geoInfo;
1006
- }
1007
- genBuffers(geoInfo) {
1008
- const buffers = {
1009
- vertex: [],
1010
- normal: [],
1011
- colors: [],
1012
- uvs: [],
1013
- materialIndex: [],
1014
- vertexWeights: [],
1015
- weightsIndices: []
1016
- };
1017
- let polygonIndex = 0;
1018
- let faceLength = 0;
1019
- let displayedWeightsWarning = false;
1020
- let facePositionIndexes = [];
1021
- let faceNormals = [];
1022
- let faceColors = [];
1023
- let faceUVs = [];
1024
- let faceWeights = [];
1025
- let faceWeightIndices = [];
1026
- const scope = this;
1027
- geoInfo.vertexIndices.forEach(function(vertexIndex, polygonVertexIndex) {
1028
- let materialIndex;
1029
- let endOfFace = false;
1030
- if (vertexIndex < 0) {
1031
- vertexIndex = vertexIndex ^ -1;
1032
- endOfFace = true;
1033
- }
1034
- let weightIndices = [];
1035
- let weights = [];
1036
- facePositionIndexes.push(vertexIndex * 3, vertexIndex * 3 + 1, vertexIndex * 3 + 2);
1037
- if (geoInfo.color) {
1038
- const data = getData(polygonVertexIndex, polygonIndex, vertexIndex, geoInfo.color);
1039
- faceColors.push(data[0], data[1], data[2]);
1040
- }
1041
- if (geoInfo.skeleton) {
1042
- if (geoInfo.weightTable[vertexIndex] !== void 0) {
1043
- geoInfo.weightTable[vertexIndex].forEach(function(wt) {
1044
- weights.push(wt.weight);
1045
- weightIndices.push(wt.id);
1046
- });
1047
- }
1048
- if (weights.length > 4) {
1049
- if (!displayedWeightsWarning) {
1050
- console.warn(
1051
- "THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights."
1052
- );
1053
- displayedWeightsWarning = true;
1054
- }
1055
- const wIndex = [0, 0, 0, 0];
1056
- const Weight = [0, 0, 0, 0];
1057
- weights.forEach(function(weight, weightIndex) {
1058
- let currentWeight = weight;
1059
- let currentIndex = weightIndices[weightIndex];
1060
- Weight.forEach(function(comparedWeight, comparedWeightIndex, comparedWeightArray) {
1061
- if (currentWeight > comparedWeight) {
1062
- comparedWeightArray[comparedWeightIndex] = currentWeight;
1063
- currentWeight = comparedWeight;
1064
- const tmp = wIndex[comparedWeightIndex];
1065
- wIndex[comparedWeightIndex] = currentIndex;
1066
- currentIndex = tmp;
1067
- }
1068
- });
1069
- });
1070
- weightIndices = wIndex;
1071
- weights = Weight;
1072
- }
1073
- while (weights.length < 4) {
1074
- weights.push(0);
1075
- weightIndices.push(0);
1076
- }
1077
- for (let i = 0; i < 4; ++i) {
1078
- faceWeights.push(weights[i]);
1079
- faceWeightIndices.push(weightIndices[i]);
1080
- }
1081
- }
1082
- if (geoInfo.normal) {
1083
- const data = getData(polygonVertexIndex, polygonIndex, vertexIndex, geoInfo.normal);
1084
- faceNormals.push(data[0], data[1], data[2]);
1085
- }
1086
- if (geoInfo.material && geoInfo.material.mappingType !== "AllSame") {
1087
- materialIndex = getData(polygonVertexIndex, polygonIndex, vertexIndex, geoInfo.material)[0];
1088
- }
1089
- if (geoInfo.uv) {
1090
- geoInfo.uv.forEach(function(uv, i) {
1091
- const data = getData(polygonVertexIndex, polygonIndex, vertexIndex, uv);
1092
- if (faceUVs[i] === void 0) {
1093
- faceUVs[i] = [];
1094
- }
1095
- faceUVs[i].push(data[0]);
1096
- faceUVs[i].push(data[1]);
1097
- });
1098
- }
1099
- faceLength++;
1100
- if (endOfFace) {
1101
- scope.genFace(
1102
- buffers,
1103
- geoInfo,
1104
- facePositionIndexes,
1105
- materialIndex,
1106
- faceNormals,
1107
- faceColors,
1108
- faceUVs,
1109
- faceWeights,
1110
- faceWeightIndices,
1111
- faceLength
1112
- );
1113
- polygonIndex++;
1114
- faceLength = 0;
1115
- facePositionIndexes = [];
1116
- faceNormals = [];
1117
- faceColors = [];
1118
- faceUVs = [];
1119
- faceWeights = [];
1120
- faceWeightIndices = [];
1121
- }
1122
- });
1123
- return buffers;
1124
- }
1125
- // Generate data for a single face in a geometry. If the face is a quad then split it into 2 tris
1126
- genFace(buffers, geoInfo, facePositionIndexes, materialIndex, faceNormals, faceColors, faceUVs, faceWeights, faceWeightIndices, faceLength) {
1127
- for (let i = 2; i < faceLength; i++) {
1128
- buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[0]]);
1129
- buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[1]]);
1130
- buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[2]]);
1131
- buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[(i - 1) * 3]]);
1132
- buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[(i - 1) * 3 + 1]]);
1133
- buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[(i - 1) * 3 + 2]]);
1134
- buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[i * 3]]);
1135
- buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[i * 3 + 1]]);
1136
- buffers.vertex.push(geoInfo.vertexPositions[facePositionIndexes[i * 3 + 2]]);
1137
- if (geoInfo.skeleton) {
1138
- buffers.vertexWeights.push(faceWeights[0]);
1139
- buffers.vertexWeights.push(faceWeights[1]);
1140
- buffers.vertexWeights.push(faceWeights[2]);
1141
- buffers.vertexWeights.push(faceWeights[3]);
1142
- buffers.vertexWeights.push(faceWeights[(i - 1) * 4]);
1143
- buffers.vertexWeights.push(faceWeights[(i - 1) * 4 + 1]);
1144
- buffers.vertexWeights.push(faceWeights[(i - 1) * 4 + 2]);
1145
- buffers.vertexWeights.push(faceWeights[(i - 1) * 4 + 3]);
1146
- buffers.vertexWeights.push(faceWeights[i * 4]);
1147
- buffers.vertexWeights.push(faceWeights[i * 4 + 1]);
1148
- buffers.vertexWeights.push(faceWeights[i * 4 + 2]);
1149
- buffers.vertexWeights.push(faceWeights[i * 4 + 3]);
1150
- buffers.weightsIndices.push(faceWeightIndices[0]);
1151
- buffers.weightsIndices.push(faceWeightIndices[1]);
1152
- buffers.weightsIndices.push(faceWeightIndices[2]);
1153
- buffers.weightsIndices.push(faceWeightIndices[3]);
1154
- buffers.weightsIndices.push(faceWeightIndices[(i - 1) * 4]);
1155
- buffers.weightsIndices.push(faceWeightIndices[(i - 1) * 4 + 1]);
1156
- buffers.weightsIndices.push(faceWeightIndices[(i - 1) * 4 + 2]);
1157
- buffers.weightsIndices.push(faceWeightIndices[(i - 1) * 4 + 3]);
1158
- buffers.weightsIndices.push(faceWeightIndices[i * 4]);
1159
- buffers.weightsIndices.push(faceWeightIndices[i * 4 + 1]);
1160
- buffers.weightsIndices.push(faceWeightIndices[i * 4 + 2]);
1161
- buffers.weightsIndices.push(faceWeightIndices[i * 4 + 3]);
1162
- }
1163
- if (geoInfo.color) {
1164
- buffers.colors.push(faceColors[0]);
1165
- buffers.colors.push(faceColors[1]);
1166
- buffers.colors.push(faceColors[2]);
1167
- buffers.colors.push(faceColors[(i - 1) * 3]);
1168
- buffers.colors.push(faceColors[(i - 1) * 3 + 1]);
1169
- buffers.colors.push(faceColors[(i - 1) * 3 + 2]);
1170
- buffers.colors.push(faceColors[i * 3]);
1171
- buffers.colors.push(faceColors[i * 3 + 1]);
1172
- buffers.colors.push(faceColors[i * 3 + 2]);
1173
- }
1174
- if (geoInfo.material && geoInfo.material.mappingType !== "AllSame") {
1175
- buffers.materialIndex.push(materialIndex);
1176
- buffers.materialIndex.push(materialIndex);
1177
- buffers.materialIndex.push(materialIndex);
1178
- }
1179
- if (geoInfo.normal) {
1180
- buffers.normal.push(faceNormals[0]);
1181
- buffers.normal.push(faceNormals[1]);
1182
- buffers.normal.push(faceNormals[2]);
1183
- buffers.normal.push(faceNormals[(i - 1) * 3]);
1184
- buffers.normal.push(faceNormals[(i - 1) * 3 + 1]);
1185
- buffers.normal.push(faceNormals[(i - 1) * 3 + 2]);
1186
- buffers.normal.push(faceNormals[i * 3]);
1187
- buffers.normal.push(faceNormals[i * 3 + 1]);
1188
- buffers.normal.push(faceNormals[i * 3 + 2]);
1189
- }
1190
- if (geoInfo.uv) {
1191
- geoInfo.uv.forEach(function(uv, j) {
1192
- if (buffers.uvs[j] === void 0)
1193
- buffers.uvs[j] = [];
1194
- buffers.uvs[j].push(faceUVs[j][0]);
1195
- buffers.uvs[j].push(faceUVs[j][1]);
1196
- buffers.uvs[j].push(faceUVs[j][(i - 1) * 2]);
1197
- buffers.uvs[j].push(faceUVs[j][(i - 1) * 2 + 1]);
1198
- buffers.uvs[j].push(faceUVs[j][i * 2]);
1199
- buffers.uvs[j].push(faceUVs[j][i * 2 + 1]);
1200
- });
1201
- }
1202
- }
1203
- }
1204
- addMorphTargets(parentGeo, parentGeoNode, morphTargets, preTransform) {
1205
- if (morphTargets.length === 0)
1206
- return;
1207
- parentGeo.morphTargetsRelative = true;
1208
- parentGeo.morphAttributes.position = [];
1209
- const scope = this;
1210
- morphTargets.forEach(function(morphTarget) {
1211
- morphTarget.rawTargets.forEach(function(rawTarget) {
1212
- const morphGeoNode = fbxTree.Objects.Geometry[rawTarget.geoID];
1213
- if (morphGeoNode !== void 0) {
1214
- scope.genMorphGeometry(parentGeo, parentGeoNode, morphGeoNode, preTransform, rawTarget.name);
1215
- }
1216
- });
1217
- });
1218
- }
1219
- // a morph geometry node is similar to a standard node, and the node is also contained
1220
- // in FBXTree.Objects.Geometry, however it can only have attributes for position, normal
1221
- // and a special attribute Index defining which vertices of the original geometry are affected
1222
- // Normal and position attributes only have data for the vertices that are affected by the morph
1223
- genMorphGeometry(parentGeo, parentGeoNode, morphGeoNode, preTransform, name) {
1224
- const vertexIndices = parentGeoNode.PolygonVertexIndex !== void 0 ? parentGeoNode.PolygonVertexIndex.a : [];
1225
- const morphPositionsSparse = morphGeoNode.Vertices !== void 0 ? morphGeoNode.Vertices.a : [];
1226
- const indices = morphGeoNode.Indexes !== void 0 ? morphGeoNode.Indexes.a : [];
1227
- const length = parentGeo.attributes.position.count * 3;
1228
- const morphPositions = new Float32Array(length);
1229
- for (let i = 0; i < indices.length; i++) {
1230
- const morphIndex = indices[i] * 3;
1231
- morphPositions[morphIndex] = morphPositionsSparse[i * 3];
1232
- morphPositions[morphIndex + 1] = morphPositionsSparse[i * 3 + 1];
1233
- morphPositions[morphIndex + 2] = morphPositionsSparse[i * 3 + 2];
1234
- }
1235
- const morphGeoInfo = {
1236
- vertexIndices,
1237
- vertexPositions: morphPositions
1238
- };
1239
- const morphBuffers = this.genBuffers(morphGeoInfo);
1240
- const positionAttribute = new Float32BufferAttribute(morphBuffers.vertex, 3);
1241
- positionAttribute.name = name || morphGeoNode.attrName;
1242
- positionAttribute.applyMatrix4(preTransform);
1243
- parentGeo.morphAttributes.position.push(positionAttribute);
1244
- }
1245
- // Parse normal from FBXTree.Objects.Geometry.LayerElementNormal if it exists
1246
- parseNormals(NormalNode) {
1247
- const mappingType = NormalNode.MappingInformationType;
1248
- const referenceType = NormalNode.ReferenceInformationType;
1249
- const buffer = NormalNode.Normals.a;
1250
- let indexBuffer = [];
1251
- if (referenceType === "IndexToDirect") {
1252
- if ("NormalIndex" in NormalNode) {
1253
- indexBuffer = NormalNode.NormalIndex.a;
1254
- } else if ("NormalsIndex" in NormalNode) {
1255
- indexBuffer = NormalNode.NormalsIndex.a;
1256
- }
1257
- }
1258
- return {
1259
- dataSize: 3,
1260
- buffer,
1261
- indices: indexBuffer,
1262
- mappingType,
1263
- referenceType
1264
- };
1265
- }
1266
- // Parse UVs from FBXTree.Objects.Geometry.LayerElementUV if it exists
1267
- parseUVs(UVNode) {
1268
- const mappingType = UVNode.MappingInformationType;
1269
- const referenceType = UVNode.ReferenceInformationType;
1270
- const buffer = UVNode.UV.a;
1271
- let indexBuffer = [];
1272
- if (referenceType === "IndexToDirect") {
1273
- indexBuffer = UVNode.UVIndex.a;
1274
- }
1275
- return {
1276
- dataSize: 2,
1277
- buffer,
1278
- indices: indexBuffer,
1279
- mappingType,
1280
- referenceType
1281
- };
1282
- }
1283
- // Parse Vertex Colors from FBXTree.Objects.Geometry.LayerElementColor if it exists
1284
- parseVertexColors(ColorNode) {
1285
- const mappingType = ColorNode.MappingInformationType;
1286
- const referenceType = ColorNode.ReferenceInformationType;
1287
- const buffer = ColorNode.Colors.a;
1288
- let indexBuffer = [];
1289
- if (referenceType === "IndexToDirect") {
1290
- indexBuffer = ColorNode.ColorIndex.a;
1291
- }
1292
- return {
1293
- dataSize: 4,
1294
- buffer,
1295
- indices: indexBuffer,
1296
- mappingType,
1297
- referenceType
1298
- };
1299
- }
1300
- // Parse mapping and material data in FBXTree.Objects.Geometry.LayerElementMaterial if it exists
1301
- parseMaterialIndices(MaterialNode) {
1302
- const mappingType = MaterialNode.MappingInformationType;
1303
- const referenceType = MaterialNode.ReferenceInformationType;
1304
- if (mappingType === "NoMappingInformation") {
1305
- return {
1306
- dataSize: 1,
1307
- buffer: [0],
1308
- indices: [0],
1309
- mappingType: "AllSame",
1310
- referenceType
1311
- };
1312
- }
1313
- const materialIndexBuffer = MaterialNode.Materials.a;
1314
- const materialIndices = [];
1315
- for (let i = 0; i < materialIndexBuffer.length; ++i) {
1316
- materialIndices.push(i);
1317
- }
1318
- return {
1319
- dataSize: 1,
1320
- buffer: materialIndexBuffer,
1321
- indices: materialIndices,
1322
- mappingType,
1323
- referenceType
1324
- };
1325
- }
1326
- // Generate a NurbGeometry from a node in FBXTree.Objects.Geometry
1327
- parseNurbsGeometry(geoNode) {
1328
- if (NURBSCurve === void 0) {
1329
- console.error(
1330
- "THREE.FBXLoader: The loader relies on NURBSCurve for any nurbs present in the model. Nurbs will show up as empty geometry."
1331
- );
1332
- return new BufferGeometry();
1333
- }
1334
- const order = parseInt(geoNode.Order);
1335
- if (isNaN(order)) {
1336
- console.error("THREE.FBXLoader: Invalid Order %s given for geometry ID: %s", geoNode.Order, geoNode.id);
1337
- return new BufferGeometry();
1338
- }
1339
- const degree = order - 1;
1340
- const knots = geoNode.KnotVector.a;
1341
- const controlPoints = [];
1342
- const pointsValues = geoNode.Points.a;
1343
- for (let i = 0, l = pointsValues.length; i < l; i += 4) {
1344
- controlPoints.push(new Vector4().fromArray(pointsValues, i));
1345
- }
1346
- let startKnot, endKnot;
1347
- if (geoNode.Form === "Closed") {
1348
- controlPoints.push(controlPoints[0]);
1349
- } else if (geoNode.Form === "Periodic") {
1350
- startKnot = degree;
1351
- endKnot = knots.length - 1 - startKnot;
1352
- for (let i = 0; i < degree; ++i) {
1353
- controlPoints.push(controlPoints[i]);
1354
- }
1355
- }
1356
- const curve = new NURBSCurve(degree, knots, controlPoints, startKnot, endKnot);
1357
- const points = curve.getPoints(controlPoints.length * 12);
1358
- return new BufferGeometry().setFromPoints(points);
1359
- }
1360
- }
1361
- class AnimationParser {
1362
- // take raw animation clips and turn them into three.js animation clips
1363
- parse() {
1364
- const animationClips = [];
1365
- const rawClips = this.parseClips();
1366
- if (rawClips !== void 0) {
1367
- for (const key in rawClips) {
1368
- const rawClip = rawClips[key];
1369
- const clip = this.addClip(rawClip);
1370
- animationClips.push(clip);
1371
- }
1372
- }
1373
- return animationClips;
1374
- }
1375
- parseClips() {
1376
- if (fbxTree.Objects.AnimationCurve === void 0)
1377
- return void 0;
1378
- const curveNodesMap = this.parseAnimationCurveNodes();
1379
- this.parseAnimationCurves(curveNodesMap);
1380
- const layersMap = this.parseAnimationLayers(curveNodesMap);
1381
- const rawClips = this.parseAnimStacks(layersMap);
1382
- return rawClips;
1383
- }
1384
- // parse nodes in FBXTree.Objects.AnimationCurveNode
1385
- // each AnimationCurveNode holds data for an animation transform for a model (e.g. left arm rotation )
1386
- // and is referenced by an AnimationLayer
1387
- parseAnimationCurveNodes() {
1388
- const rawCurveNodes = fbxTree.Objects.AnimationCurveNode;
1389
- const curveNodesMap = /* @__PURE__ */ new Map();
1390
- for (const nodeID in rawCurveNodes) {
1391
- const rawCurveNode = rawCurveNodes[nodeID];
1392
- if (rawCurveNode.attrName.match(/S|R|T|DeformPercent/) !== null) {
1393
- const curveNode = {
1394
- id: rawCurveNode.id,
1395
- attr: rawCurveNode.attrName,
1396
- curves: {}
1397
- };
1398
- curveNodesMap.set(curveNode.id, curveNode);
1399
- }
1400
- }
1401
- return curveNodesMap;
1402
- }
1403
- // parse nodes in FBXTree.Objects.AnimationCurve and connect them up to
1404
- // previously parsed AnimationCurveNodes. Each AnimationCurve holds data for a single animated
1405
- // axis ( e.g. times and values of x rotation)
1406
- parseAnimationCurves(curveNodesMap) {
1407
- const rawCurves = fbxTree.Objects.AnimationCurve;
1408
- for (const nodeID in rawCurves) {
1409
- const animationCurve = {
1410
- id: rawCurves[nodeID].id,
1411
- times: rawCurves[nodeID].KeyTime.a.map(convertFBXTimeToSeconds),
1412
- values: rawCurves[nodeID].KeyValueFloat.a
1413
- };
1414
- const relationships = connections.get(animationCurve.id);
1415
- if (relationships !== void 0) {
1416
- const animationCurveID = relationships.parents[0].ID;
1417
- const animationCurveRelationship = relationships.parents[0].relationship;
1418
- if (animationCurveRelationship.match(/X/)) {
1419
- curveNodesMap.get(animationCurveID).curves["x"] = animationCurve;
1420
- } else if (animationCurveRelationship.match(/Y/)) {
1421
- curveNodesMap.get(animationCurveID).curves["y"] = animationCurve;
1422
- } else if (animationCurveRelationship.match(/Z/)) {
1423
- curveNodesMap.get(animationCurveID).curves["z"] = animationCurve;
1424
- } else if (animationCurveRelationship.match(/d|DeformPercent/) && curveNodesMap.has(animationCurveID)) {
1425
- curveNodesMap.get(animationCurveID).curves["morph"] = animationCurve;
1426
- }
1427
- }
1428
- }
1429
- }
1430
- // parse nodes in FBXTree.Objects.AnimationLayer. Each layers holds references
1431
- // to various AnimationCurveNodes and is referenced by an AnimationStack node
1432
- // note: theoretically a stack can have multiple layers, however in practice there always seems to be one per stack
1433
- parseAnimationLayers(curveNodesMap) {
1434
- const rawLayers = fbxTree.Objects.AnimationLayer;
1435
- const layersMap = /* @__PURE__ */ new Map();
1436
- for (const nodeID in rawLayers) {
1437
- const layerCurveNodes = [];
1438
- const connection = connections.get(parseInt(nodeID));
1439
- if (connection !== void 0) {
1440
- const children = connection.children;
1441
- children.forEach(function(child, i) {
1442
- if (curveNodesMap.has(child.ID)) {
1443
- const curveNode = curveNodesMap.get(child.ID);
1444
- if (curveNode.curves.x !== void 0 || curveNode.curves.y !== void 0 || curveNode.curves.z !== void 0) {
1445
- if (layerCurveNodes[i] === void 0) {
1446
- const modelID = connections.get(child.ID).parents.filter(function(parent) {
1447
- return parent.relationship !== void 0;
1448
- })[0].ID;
1449
- if (modelID !== void 0) {
1450
- const rawModel = fbxTree.Objects.Model[modelID.toString()];
1451
- if (rawModel === void 0) {
1452
- console.warn("THREE.FBXLoader: Encountered a unused curve.", child);
1453
- return;
1454
- }
1455
- const node = {
1456
- modelName: rawModel.attrName ? PropertyBinding.sanitizeNodeName(rawModel.attrName) : "",
1457
- ID: rawModel.id,
1458
- initialPosition: [0, 0, 0],
1459
- initialRotation: [0, 0, 0],
1460
- initialScale: [1, 1, 1]
1461
- };
1462
- sceneGraph.traverse(function(child2) {
1463
- if (child2.ID === rawModel.id) {
1464
- node.transform = child2.matrix;
1465
- if (child2.userData.transformData)
1466
- node.eulerOrder = child2.userData.transformData.eulerOrder;
1467
- }
1468
- });
1469
- if (!node.transform)
1470
- node.transform = new Matrix4();
1471
- if ("PreRotation" in rawModel)
1472
- node.preRotation = rawModel.PreRotation.value;
1473
- if ("PostRotation" in rawModel)
1474
- node.postRotation = rawModel.PostRotation.value;
1475
- layerCurveNodes[i] = node;
1476
- }
1477
- }
1478
- if (layerCurveNodes[i])
1479
- layerCurveNodes[i][curveNode.attr] = curveNode;
1480
- } else if (curveNode.curves.morph !== void 0) {
1481
- if (layerCurveNodes[i] === void 0) {
1482
- const deformerID = connections.get(child.ID).parents.filter(function(parent) {
1483
- return parent.relationship !== void 0;
1484
- })[0].ID;
1485
- const morpherID = connections.get(deformerID).parents[0].ID;
1486
- const geoID = connections.get(morpherID).parents[0].ID;
1487
- const modelID = connections.get(geoID).parents[0].ID;
1488
- const rawModel = fbxTree.Objects.Model[modelID];
1489
- const node = {
1490
- modelName: rawModel.attrName ? PropertyBinding.sanitizeNodeName(rawModel.attrName) : "",
1491
- morphName: fbxTree.Objects.Deformer[deformerID].attrName
1492
- };
1493
- layerCurveNodes[i] = node;
1494
- }
1495
- layerCurveNodes[i][curveNode.attr] = curveNode;
1496
- }
1497
- }
1498
- });
1499
- layersMap.set(parseInt(nodeID), layerCurveNodes);
1500
- }
1501
- }
1502
- return layersMap;
1503
- }
1504
- // parse nodes in FBXTree.Objects.AnimationStack. These are the top level node in the animation
1505
- // hierarchy. Each Stack node will be used to create a AnimationClip
1506
- parseAnimStacks(layersMap) {
1507
- const rawStacks = fbxTree.Objects.AnimationStack;
1508
- const rawClips = {};
1509
- for (const nodeID in rawStacks) {
1510
- const children = connections.get(parseInt(nodeID)).children;
1511
- if (children.length > 1) {
1512
- console.warn(
1513
- "THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers."
1514
- );
1515
- }
1516
- const layer = layersMap.get(children[0].ID);
1517
- rawClips[nodeID] = {
1518
- name: rawStacks[nodeID].attrName,
1519
- layer
1520
- };
1521
- }
1522
- return rawClips;
1523
- }
1524
- addClip(rawClip) {
1525
- let tracks = [];
1526
- const scope = this;
1527
- rawClip.layer.forEach(function(rawTracks) {
1528
- tracks = tracks.concat(scope.generateTracks(rawTracks));
1529
- });
1530
- return new AnimationClip(rawClip.name, -1, tracks);
1531
- }
1532
- generateTracks(rawTracks) {
1533
- const tracks = [];
1534
- let initialPosition = new Vector3();
1535
- let initialRotation = new Quaternion();
1536
- let initialScale = new Vector3();
1537
- if (rawTracks.transform)
1538
- rawTracks.transform.decompose(initialPosition, initialRotation, initialScale);
1539
- initialPosition = initialPosition.toArray();
1540
- initialRotation = new Euler().setFromQuaternion(initialRotation, rawTracks.eulerOrder).toArray();
1541
- initialScale = initialScale.toArray();
1542
- if (rawTracks.T !== void 0 && Object.keys(rawTracks.T.curves).length > 0) {
1543
- const positionTrack = this.generateVectorTrack(
1544
- rawTracks.modelName,
1545
- rawTracks.T.curves,
1546
- initialPosition,
1547
- "position"
1548
- );
1549
- if (positionTrack !== void 0)
1550
- tracks.push(positionTrack);
1551
- }
1552
- if (rawTracks.R !== void 0 && Object.keys(rawTracks.R.curves).length > 0) {
1553
- const rotationTrack = this.generateRotationTrack(
1554
- rawTracks.modelName,
1555
- rawTracks.R.curves,
1556
- initialRotation,
1557
- rawTracks.preRotation,
1558
- rawTracks.postRotation,
1559
- rawTracks.eulerOrder
1560
- );
1561
- if (rotationTrack !== void 0)
1562
- tracks.push(rotationTrack);
1563
- }
1564
- if (rawTracks.S !== void 0 && Object.keys(rawTracks.S.curves).length > 0) {
1565
- const scaleTrack = this.generateVectorTrack(rawTracks.modelName, rawTracks.S.curves, initialScale, "scale");
1566
- if (scaleTrack !== void 0)
1567
- tracks.push(scaleTrack);
1568
- }
1569
- if (rawTracks.DeformPercent !== void 0) {
1570
- const morphTrack = this.generateMorphTrack(rawTracks);
1571
- if (morphTrack !== void 0)
1572
- tracks.push(morphTrack);
1573
- }
1574
- return tracks;
1575
- }
1576
- generateVectorTrack(modelName, curves, initialValue, type) {
1577
- const times = this.getTimesForAllAxes(curves);
1578
- const values = this.getKeyframeTrackValues(times, curves, initialValue);
1579
- return new VectorKeyframeTrack(modelName + "." + type, times, values);
1580
- }
1581
- generateRotationTrack(modelName, curves, initialValue, preRotation, postRotation, eulerOrder) {
1582
- if (curves.x !== void 0) {
1583
- this.interpolateRotations(curves.x);
1584
- curves.x.values = curves.x.values.map(MathUtils.degToRad);
1585
- }
1586
- if (curves.y !== void 0) {
1587
- this.interpolateRotations(curves.y);
1588
- curves.y.values = curves.y.values.map(MathUtils.degToRad);
1589
- }
1590
- if (curves.z !== void 0) {
1591
- this.interpolateRotations(curves.z);
1592
- curves.z.values = curves.z.values.map(MathUtils.degToRad);
1593
- }
1594
- const times = this.getTimesForAllAxes(curves);
1595
- const values = this.getKeyframeTrackValues(times, curves, initialValue);
1596
- if (preRotation !== void 0) {
1597
- preRotation = preRotation.map(MathUtils.degToRad);
1598
- preRotation.push(eulerOrder);
1599
- preRotation = new Euler().fromArray(preRotation);
1600
- preRotation = new Quaternion().setFromEuler(preRotation);
1601
- }
1602
- if (postRotation !== void 0) {
1603
- postRotation = postRotation.map(MathUtils.degToRad);
1604
- postRotation.push(eulerOrder);
1605
- postRotation = new Euler().fromArray(postRotation);
1606
- postRotation = new Quaternion().setFromEuler(postRotation).invert();
1607
- }
1608
- const quaternion = new Quaternion();
1609
- const euler = new Euler();
1610
- const quaternionValues = [];
1611
- for (let i = 0; i < values.length; i += 3) {
1612
- euler.set(values[i], values[i + 1], values[i + 2], eulerOrder);
1613
- quaternion.setFromEuler(euler);
1614
- if (preRotation !== void 0)
1615
- quaternion.premultiply(preRotation);
1616
- if (postRotation !== void 0)
1617
- quaternion.multiply(postRotation);
1618
- quaternion.toArray(quaternionValues, i / 3 * 4);
1619
- }
1620
- return new QuaternionKeyframeTrack(modelName + ".quaternion", times, quaternionValues);
1621
- }
1622
- generateMorphTrack(rawTracks) {
1623
- const curves = rawTracks.DeformPercent.curves.morph;
1624
- const values = curves.values.map(function(val) {
1625
- return val / 100;
1626
- });
1627
- const morphNum = sceneGraph.getObjectByName(rawTracks.modelName).morphTargetDictionary[rawTracks.morphName];
1628
- return new NumberKeyframeTrack(
1629
- rawTracks.modelName + ".morphTargetInfluences[" + morphNum + "]",
1630
- curves.times,
1631
- values
1632
- );
1633
- }
1634
- // For all animated objects, times are defined separately for each axis
1635
- // Here we'll combine the times into one sorted array without duplicates
1636
- getTimesForAllAxes(curves) {
1637
- let times = [];
1638
- if (curves.x !== void 0)
1639
- times = times.concat(curves.x.times);
1640
- if (curves.y !== void 0)
1641
- times = times.concat(curves.y.times);
1642
- if (curves.z !== void 0)
1643
- times = times.concat(curves.z.times);
1644
- times = times.sort(function(a, b) {
1645
- return a - b;
1646
- });
1647
- if (times.length > 1) {
1648
- let targetIndex = 1;
1649
- let lastValue = times[0];
1650
- for (let i = 1; i < times.length; i++) {
1651
- const currentValue = times[i];
1652
- if (currentValue !== lastValue) {
1653
- times[targetIndex] = currentValue;
1654
- lastValue = currentValue;
1655
- targetIndex++;
1656
- }
1657
- }
1658
- times = times.slice(0, targetIndex);
1659
- }
1660
- return times;
1661
- }
1662
- getKeyframeTrackValues(times, curves, initialValue) {
1663
- const prevValue = initialValue;
1664
- const values = [];
1665
- let xIndex = -1;
1666
- let yIndex = -1;
1667
- let zIndex = -1;
1668
- times.forEach(function(time) {
1669
- if (curves.x)
1670
- xIndex = curves.x.times.indexOf(time);
1671
- if (curves.y)
1672
- yIndex = curves.y.times.indexOf(time);
1673
- if (curves.z)
1674
- zIndex = curves.z.times.indexOf(time);
1675
- if (xIndex !== -1) {
1676
- const xValue = curves.x.values[xIndex];
1677
- values.push(xValue);
1678
- prevValue[0] = xValue;
1679
- } else {
1680
- values.push(prevValue[0]);
1681
- }
1682
- if (yIndex !== -1) {
1683
- const yValue = curves.y.values[yIndex];
1684
- values.push(yValue);
1685
- prevValue[1] = yValue;
1686
- } else {
1687
- values.push(prevValue[1]);
1688
- }
1689
- if (zIndex !== -1) {
1690
- const zValue = curves.z.values[zIndex];
1691
- values.push(zValue);
1692
- prevValue[2] = zValue;
1693
- } else {
1694
- values.push(prevValue[2]);
1695
- }
1696
- });
1697
- return values;
1698
- }
1699
- // Rotations are defined as Euler angles which can have values of any size
1700
- // These will be converted to quaternions which don't support values greater than
1701
- // PI, so we'll interpolate large rotations
1702
- interpolateRotations(curve) {
1703
- for (let i = 1; i < curve.values.length; i++) {
1704
- const initialValue = curve.values[i - 1];
1705
- const valuesSpan = curve.values[i] - initialValue;
1706
- const absoluteSpan = Math.abs(valuesSpan);
1707
- if (absoluteSpan >= 180) {
1708
- const numSubIntervals = absoluteSpan / 180;
1709
- const step = valuesSpan / numSubIntervals;
1710
- let nextValue = initialValue + step;
1711
- const initialTime = curve.times[i - 1];
1712
- const timeSpan = curve.times[i] - initialTime;
1713
- const interval = timeSpan / numSubIntervals;
1714
- let nextTime = initialTime + interval;
1715
- const interpolatedTimes = [];
1716
- const interpolatedValues = [];
1717
- while (nextTime < curve.times[i]) {
1718
- interpolatedTimes.push(nextTime);
1719
- nextTime += interval;
1720
- interpolatedValues.push(nextValue);
1721
- nextValue += step;
1722
- }
1723
- curve.times = inject(curve.times, i, interpolatedTimes);
1724
- curve.values = inject(curve.values, i, interpolatedValues);
1725
- }
1726
- }
1727
- }
1728
- }
1729
- class TextParser {
1730
- getPrevNode() {
1731
- return this.nodeStack[this.currentIndent - 2];
1732
- }
1733
- getCurrentNode() {
1734
- return this.nodeStack[this.currentIndent - 1];
1735
- }
1736
- getCurrentProp() {
1737
- return this.currentProp;
1738
- }
1739
- pushStack(node) {
1740
- this.nodeStack.push(node);
1741
- this.currentIndent += 1;
1742
- }
1743
- popStack() {
1744
- this.nodeStack.pop();
1745
- this.currentIndent -= 1;
1746
- }
1747
- setCurrentProp(val, name) {
1748
- this.currentProp = val;
1749
- this.currentPropName = name;
1750
- }
1751
- parse(text) {
1752
- this.currentIndent = 0;
1753
- this.allNodes = new FBXTree();
1754
- this.nodeStack = [];
1755
- this.currentProp = [];
1756
- this.currentPropName = "";
1757
- const scope = this;
1758
- const split = text.split(/[\r\n]+/);
1759
- split.forEach(function(line, i) {
1760
- const matchComment = line.match(/^[\s\t]*;/);
1761
- const matchEmpty = line.match(/^[\s\t]*$/);
1762
- if (matchComment || matchEmpty)
1763
- return;
1764
- const matchBeginning = line.match("^\\t{" + scope.currentIndent + "}(\\w+):(.*){", "");
1765
- const matchProperty = line.match("^\\t{" + scope.currentIndent + "}(\\w+):[\\s\\t\\r\\n](.*)");
1766
- const matchEnd = line.match("^\\t{" + (scope.currentIndent - 1) + "}}");
1767
- if (matchBeginning) {
1768
- scope.parseNodeBegin(line, matchBeginning);
1769
- } else if (matchProperty) {
1770
- scope.parseNodeProperty(line, matchProperty, split[++i]);
1771
- } else if (matchEnd) {
1772
- scope.popStack();
1773
- } else if (line.match(/^[^\s\t}]/)) {
1774
- scope.parseNodePropertyContinued(line);
1775
- }
1776
- });
1777
- return this.allNodes;
1778
- }
1779
- parseNodeBegin(line, property) {
1780
- const nodeName = property[1].trim().replace(/^"/, "").replace(/"$/, "");
1781
- const nodeAttrs = property[2].split(",").map(function(attr) {
1782
- return attr.trim().replace(/^"/, "").replace(/"$/, "");
1783
- });
1784
- const node = { name: nodeName };
1785
- const attrs = this.parseNodeAttr(nodeAttrs);
1786
- const currentNode = this.getCurrentNode();
1787
- if (this.currentIndent === 0) {
1788
- this.allNodes.add(nodeName, node);
1789
- } else {
1790
- if (nodeName in currentNode) {
1791
- if (nodeName === "PoseNode") {
1792
- currentNode.PoseNode.push(node);
1793
- } else if (currentNode[nodeName].id !== void 0) {
1794
- currentNode[nodeName] = {};
1795
- currentNode[nodeName][currentNode[nodeName].id] = currentNode[nodeName];
1796
- }
1797
- if (attrs.id !== "")
1798
- currentNode[nodeName][attrs.id] = node;
1799
- } else if (typeof attrs.id === "number") {
1800
- currentNode[nodeName] = {};
1801
- currentNode[nodeName][attrs.id] = node;
1802
- } else if (nodeName !== "Properties70") {
1803
- if (nodeName === "PoseNode")
1804
- currentNode[nodeName] = [node];
1805
- else
1806
- currentNode[nodeName] = node;
1807
- }
1808
- }
1809
- if (typeof attrs.id === "number")
1810
- node.id = attrs.id;
1811
- if (attrs.name !== "")
1812
- node.attrName = attrs.name;
1813
- if (attrs.type !== "")
1814
- node.attrType = attrs.type;
1815
- this.pushStack(node);
1816
- }
1817
- parseNodeAttr(attrs) {
1818
- let id = attrs[0];
1819
- if (attrs[0] !== "") {
1820
- id = parseInt(attrs[0]);
1821
- if (isNaN(id)) {
1822
- id = attrs[0];
1823
- }
1824
- }
1825
- let name = "", type = "";
1826
- if (attrs.length > 1) {
1827
- name = attrs[1].replace(/^(\w+)::/, "");
1828
- type = attrs[2];
1829
- }
1830
- return { id, name, type };
1831
- }
1832
- parseNodeProperty(line, property, contentLine) {
1833
- let propName = property[1].replace(/^"/, "").replace(/"$/, "").trim();
1834
- let propValue = property[2].replace(/^"/, "").replace(/"$/, "").trim();
1835
- if (propName === "Content" && propValue === ",") {
1836
- propValue = contentLine.replace(/"/g, "").replace(/,$/, "").trim();
1837
- }
1838
- const currentNode = this.getCurrentNode();
1839
- const parentName = currentNode.name;
1840
- if (parentName === "Properties70") {
1841
- this.parseNodeSpecialProperty(line, propName, propValue);
1842
- return;
1843
- }
1844
- if (propName === "C") {
1845
- const connProps = propValue.split(",").slice(1);
1846
- const from = parseInt(connProps[0]);
1847
- const to = parseInt(connProps[1]);
1848
- let rest = propValue.split(",").slice(3);
1849
- rest = rest.map(function(elem) {
1850
- return elem.trim().replace(/^"/, "");
1851
- });
1852
- propName = "connections";
1853
- propValue = [from, to];
1854
- append(propValue, rest);
1855
- if (currentNode[propName] === void 0) {
1856
- currentNode[propName] = [];
1857
- }
1858
- }
1859
- if (propName === "Node")
1860
- currentNode.id = propValue;
1861
- if (propName in currentNode && Array.isArray(currentNode[propName])) {
1862
- currentNode[propName].push(propValue);
1863
- } else {
1864
- if (propName !== "a")
1865
- currentNode[propName] = propValue;
1866
- else
1867
- currentNode.a = propValue;
1868
- }
1869
- this.setCurrentProp(currentNode, propName);
1870
- if (propName === "a" && propValue.slice(-1) !== ",") {
1871
- currentNode.a = parseNumberArray(propValue);
1872
- }
1873
- }
1874
- parseNodePropertyContinued(line) {
1875
- const currentNode = this.getCurrentNode();
1876
- currentNode.a += line;
1877
- if (line.slice(-1) !== ",") {
1878
- currentNode.a = parseNumberArray(currentNode.a);
1879
- }
1880
- }
1881
- // parse "Property70"
1882
- parseNodeSpecialProperty(line, propName, propValue) {
1883
- const props = propValue.split('",').map(function(prop) {
1884
- return prop.trim().replace(/^\"/, "").replace(/\s/, "_");
1885
- });
1886
- const innerPropName = props[0];
1887
- const innerPropType1 = props[1];
1888
- const innerPropType2 = props[2];
1889
- const innerPropFlag = props[3];
1890
- let innerPropValue = props[4];
1891
- switch (innerPropType1) {
1892
- case "int":
1893
- case "enum":
1894
- case "bool":
1895
- case "ULongLong":
1896
- case "double":
1897
- case "Number":
1898
- case "FieldOfView":
1899
- innerPropValue = parseFloat(innerPropValue);
1900
- break;
1901
- case "Color":
1902
- case "ColorRGB":
1903
- case "Vector3D":
1904
- case "Lcl_Translation":
1905
- case "Lcl_Rotation":
1906
- case "Lcl_Scaling":
1907
- innerPropValue = parseNumberArray(innerPropValue);
1908
- break;
1909
- }
1910
- this.getPrevNode()[innerPropName] = {
1911
- type: innerPropType1,
1912
- type2: innerPropType2,
1913
- flag: innerPropFlag,
1914
- value: innerPropValue
1915
- };
1916
- this.setCurrentProp(this.getPrevNode(), innerPropName);
1917
- }
1918
- }
1919
- class BinaryParser {
1920
- parse(buffer) {
1921
- const reader = new BinaryReader(buffer);
1922
- reader.skip(23);
1923
- const version = reader.getUint32();
1924
- if (version < 6400) {
1925
- throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: " + version);
1926
- }
1927
- const allNodes = new FBXTree();
1928
- while (!this.endOfContent(reader)) {
1929
- const node = this.parseNode(reader, version);
1930
- if (node !== null)
1931
- allNodes.add(node.name, node);
1932
- }
1933
- return allNodes;
1934
- }
1935
- // Check if reader has reached the end of content.
1936
- endOfContent(reader) {
1937
- if (reader.size() % 16 === 0) {
1938
- return (reader.getOffset() + 160 + 16 & ~15) >= reader.size();
1939
- } else {
1940
- return reader.getOffset() + 160 + 16 >= reader.size();
1941
- }
1942
- }
1943
- // recursively parse nodes until the end of the file is reached
1944
- parseNode(reader, version) {
1945
- const node = {};
1946
- const endOffset = version >= 7500 ? reader.getUint64() : reader.getUint32();
1947
- const numProperties = version >= 7500 ? reader.getUint64() : reader.getUint32();
1948
- version >= 7500 ? reader.getUint64() : reader.getUint32();
1949
- const nameLen = reader.getUint8();
1950
- const name = reader.getString(nameLen);
1951
- if (endOffset === 0)
1952
- return null;
1953
- const propertyList = [];
1954
- for (let i = 0; i < numProperties; i++) {
1955
- propertyList.push(this.parseProperty(reader));
1956
- }
1957
- const id = propertyList.length > 0 ? propertyList[0] : "";
1958
- const attrName = propertyList.length > 1 ? propertyList[1] : "";
1959
- const attrType = propertyList.length > 2 ? propertyList[2] : "";
1960
- node.singleProperty = numProperties === 1 && reader.getOffset() === endOffset ? true : false;
1961
- while (endOffset > reader.getOffset()) {
1962
- const subNode = this.parseNode(reader, version);
1963
- if (subNode !== null)
1964
- this.parseSubNode(name, node, subNode);
1965
- }
1966
- node.propertyList = propertyList;
1967
- if (typeof id === "number")
1968
- node.id = id;
1969
- if (attrName !== "")
1970
- node.attrName = attrName;
1971
- if (attrType !== "")
1972
- node.attrType = attrType;
1973
- if (name !== "")
1974
- node.name = name;
1975
- return node;
1976
- }
1977
- parseSubNode(name, node, subNode) {
1978
- if (subNode.singleProperty === true) {
1979
- const value = subNode.propertyList[0];
1980
- if (Array.isArray(value)) {
1981
- node[subNode.name] = subNode;
1982
- subNode.a = value;
1983
- } else {
1984
- node[subNode.name] = value;
1985
- }
1986
- } else if (name === "Connections" && subNode.name === "C") {
1987
- const array = [];
1988
- subNode.propertyList.forEach(function(property, i) {
1989
- if (i !== 0)
1990
- array.push(property);
1991
- });
1992
- if (node.connections === void 0) {
1993
- node.connections = [];
1994
- }
1995
- node.connections.push(array);
1996
- } else if (subNode.name === "Properties70") {
1997
- const keys = Object.keys(subNode);
1998
- keys.forEach(function(key) {
1999
- node[key] = subNode[key];
2000
- });
2001
- } else if (name === "Properties70" && subNode.name === "P") {
2002
- let innerPropName = subNode.propertyList[0];
2003
- let innerPropType1 = subNode.propertyList[1];
2004
- const innerPropType2 = subNode.propertyList[2];
2005
- const innerPropFlag = subNode.propertyList[3];
2006
- let innerPropValue;
2007
- if (innerPropName.indexOf("Lcl ") === 0)
2008
- innerPropName = innerPropName.replace("Lcl ", "Lcl_");
2009
- if (innerPropType1.indexOf("Lcl ") === 0)
2010
- innerPropType1 = innerPropType1.replace("Lcl ", "Lcl_");
2011
- if (innerPropType1 === "Color" || innerPropType1 === "ColorRGB" || innerPropType1 === "Vector" || innerPropType1 === "Vector3D" || innerPropType1.indexOf("Lcl_") === 0) {
2012
- innerPropValue = [subNode.propertyList[4], subNode.propertyList[5], subNode.propertyList[6]];
2013
- } else {
2014
- innerPropValue = subNode.propertyList[4];
2015
- }
2016
- node[innerPropName] = {
2017
- type: innerPropType1,
2018
- type2: innerPropType2,
2019
- flag: innerPropFlag,
2020
- value: innerPropValue
2021
- };
2022
- } else if (node[subNode.name] === void 0) {
2023
- if (typeof subNode.id === "number") {
2024
- node[subNode.name] = {};
2025
- node[subNode.name][subNode.id] = subNode;
2026
- } else {
2027
- node[subNode.name] = subNode;
2028
- }
2029
- } else {
2030
- if (subNode.name === "PoseNode") {
2031
- if (!Array.isArray(node[subNode.name])) {
2032
- node[subNode.name] = [node[subNode.name]];
2033
- }
2034
- node[subNode.name].push(subNode);
2035
- } else if (node[subNode.name][subNode.id] === void 0) {
2036
- node[subNode.name][subNode.id] = subNode;
2037
- }
2038
- }
2039
- }
2040
- parseProperty(reader) {
2041
- const type = reader.getString(1);
2042
- let length;
2043
- switch (type) {
2044
- case "C":
2045
- return reader.getBoolean();
2046
- case "D":
2047
- return reader.getFloat64();
2048
- case "F":
2049
- return reader.getFloat32();
2050
- case "I":
2051
- return reader.getInt32();
2052
- case "L":
2053
- return reader.getInt64();
2054
- case "R":
2055
- length = reader.getUint32();
2056
- return reader.getArrayBuffer(length);
2057
- case "S":
2058
- length = reader.getUint32();
2059
- return reader.getString(length);
2060
- case "Y":
2061
- return reader.getInt16();
2062
- case "b":
2063
- case "c":
2064
- case "d":
2065
- case "f":
2066
- case "i":
2067
- case "l":
2068
- const arrayLength = reader.getUint32();
2069
- const encoding = reader.getUint32();
2070
- const compressedLength = reader.getUint32();
2071
- if (encoding === 0) {
2072
- switch (type) {
2073
- case "b":
2074
- case "c":
2075
- return reader.getBooleanArray(arrayLength);
2076
- case "d":
2077
- return reader.getFloat64Array(arrayLength);
2078
- case "f":
2079
- return reader.getFloat32Array(arrayLength);
2080
- case "i":
2081
- return reader.getInt32Array(arrayLength);
2082
- case "l":
2083
- return reader.getInt64Array(arrayLength);
2084
- }
2085
- }
2086
- const data = unzlibSync(new Uint8Array(reader.getArrayBuffer(compressedLength)));
2087
- const reader2 = new BinaryReader(data.buffer);
2088
- switch (type) {
2089
- case "b":
2090
- case "c":
2091
- return reader2.getBooleanArray(arrayLength);
2092
- case "d":
2093
- return reader2.getFloat64Array(arrayLength);
2094
- case "f":
2095
- return reader2.getFloat32Array(arrayLength);
2096
- case "i":
2097
- return reader2.getInt32Array(arrayLength);
2098
- case "l":
2099
- return reader2.getInt64Array(arrayLength);
2100
- }
2101
- default:
2102
- throw new Error("THREE.FBXLoader: Unknown property type " + type);
2103
- }
2104
- }
2105
- }
2106
- class BinaryReader {
2107
- constructor(buffer, littleEndian) {
2108
- this.dv = new DataView(buffer);
2109
- this.offset = 0;
2110
- this.littleEndian = littleEndian !== void 0 ? littleEndian : true;
2111
- }
2112
- getOffset() {
2113
- return this.offset;
2114
- }
2115
- size() {
2116
- return this.dv.buffer.byteLength;
2117
- }
2118
- skip(length) {
2119
- this.offset += length;
2120
- }
2121
- // seems like true/false representation depends on exporter.
2122
- // true: 1 or 'Y'(=0x59), false: 0 or 'T'(=0x54)
2123
- // then sees LSB.
2124
- getBoolean() {
2125
- return (this.getUint8() & 1) === 1;
2126
- }
2127
- getBooleanArray(size) {
2128
- const a = [];
2129
- for (let i = 0; i < size; i++) {
2130
- a.push(this.getBoolean());
2131
- }
2132
- return a;
2133
- }
2134
- getUint8() {
2135
- const value = this.dv.getUint8(this.offset);
2136
- this.offset += 1;
2137
- return value;
2138
- }
2139
- getInt16() {
2140
- const value = this.dv.getInt16(this.offset, this.littleEndian);
2141
- this.offset += 2;
2142
- return value;
2143
- }
2144
- getInt32() {
2145
- const value = this.dv.getInt32(this.offset, this.littleEndian);
2146
- this.offset += 4;
2147
- return value;
2148
- }
2149
- getInt32Array(size) {
2150
- const a = [];
2151
- for (let i = 0; i < size; i++) {
2152
- a.push(this.getInt32());
2153
- }
2154
- return a;
2155
- }
2156
- getUint32() {
2157
- const value = this.dv.getUint32(this.offset, this.littleEndian);
2158
- this.offset += 4;
2159
- return value;
2160
- }
2161
- // JavaScript doesn't support 64-bit integer so calculate this here
2162
- // 1 << 32 will return 1 so using multiply operation instead here.
2163
- // There's a possibility that this method returns wrong value if the value
2164
- // is out of the range between Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER.
2165
- // TODO: safely handle 64-bit integer
2166
- getInt64() {
2167
- let low, high;
2168
- if (this.littleEndian) {
2169
- low = this.getUint32();
2170
- high = this.getUint32();
2171
- } else {
2172
- high = this.getUint32();
2173
- low = this.getUint32();
2174
- }
2175
- if (high & 2147483648) {
2176
- high = ~high & 4294967295;
2177
- low = ~low & 4294967295;
2178
- if (low === 4294967295)
2179
- high = high + 1 & 4294967295;
2180
- low = low + 1 & 4294967295;
2181
- return -(high * 4294967296 + low);
2182
- }
2183
- return high * 4294967296 + low;
2184
- }
2185
- getInt64Array(size) {
2186
- const a = [];
2187
- for (let i = 0; i < size; i++) {
2188
- a.push(this.getInt64());
2189
- }
2190
- return a;
2191
- }
2192
- // Note: see getInt64() comment
2193
- getUint64() {
2194
- let low, high;
2195
- if (this.littleEndian) {
2196
- low = this.getUint32();
2197
- high = this.getUint32();
2198
- } else {
2199
- high = this.getUint32();
2200
- low = this.getUint32();
2201
- }
2202
- return high * 4294967296 + low;
2203
- }
2204
- getFloat32() {
2205
- const value = this.dv.getFloat32(this.offset, this.littleEndian);
2206
- this.offset += 4;
2207
- return value;
2208
- }
2209
- getFloat32Array(size) {
2210
- const a = [];
2211
- for (let i = 0; i < size; i++) {
2212
- a.push(this.getFloat32());
2213
- }
2214
- return a;
2215
- }
2216
- getFloat64() {
2217
- const value = this.dv.getFloat64(this.offset, this.littleEndian);
2218
- this.offset += 8;
2219
- return value;
2220
- }
2221
- getFloat64Array(size) {
2222
- const a = [];
2223
- for (let i = 0; i < size; i++) {
2224
- a.push(this.getFloat64());
2225
- }
2226
- return a;
2227
- }
2228
- getArrayBuffer(size) {
2229
- const value = this.dv.buffer.slice(this.offset, this.offset + size);
2230
- this.offset += size;
2231
- return value;
2232
- }
2233
- getString(size) {
2234
- let a = [];
2235
- for (let i = 0; i < size; i++) {
2236
- a[i] = this.getUint8();
2237
- }
2238
- const nullByte = a.indexOf(0);
2239
- if (nullByte >= 0)
2240
- a = a.slice(0, nullByte);
2241
- return LoaderUtils.decodeText(new Uint8Array(a));
2242
- }
2243
- }
2244
- class FBXTree {
2245
- add(key, val) {
2246
- this[key] = val;
2247
- }
2248
- }
2249
- function isFbxFormatBinary(buffer) {
2250
- const CORRECT = "Kaydara FBX Binary \0";
2251
- return buffer.byteLength >= CORRECT.length && CORRECT === convertArrayBufferToString(buffer, 0, CORRECT.length);
2252
- }
2253
- function isFbxFormatASCII(text) {
2254
- const CORRECT = [
2255
- "K",
2256
- "a",
2257
- "y",
2258
- "d",
2259
- "a",
2260
- "r",
2261
- "a",
2262
- "\\",
2263
- "F",
2264
- "B",
2265
- "X",
2266
- "\\",
2267
- "B",
2268
- "i",
2269
- "n",
2270
- "a",
2271
- "r",
2272
- "y",
2273
- "\\",
2274
- "\\"
2275
- ];
2276
- let cursor = 0;
2277
- function read(offset) {
2278
- const result = text[offset - 1];
2279
- text = text.slice(cursor + offset);
2280
- cursor++;
2281
- return result;
2282
- }
2283
- for (let i = 0; i < CORRECT.length; ++i) {
2284
- const num = read(1);
2285
- if (num === CORRECT[i]) {
2286
- return false;
2287
- }
2288
- }
2289
- return true;
2290
- }
2291
- function getFbxVersion(text) {
2292
- const versionRegExp = /FBXVersion: (\d+)/;
2293
- const match = text.match(versionRegExp);
2294
- if (match) {
2295
- const version = parseInt(match[1]);
2296
- return version;
2297
- }
2298
- throw new Error("THREE.FBXLoader: Cannot find the version number for the file given.");
2299
- }
2300
- function convertFBXTimeToSeconds(time) {
2301
- return time / 46186158e3;
2302
- }
2303
- const dataArray = [];
2304
- function getData(polygonVertexIndex, polygonIndex, vertexIndex, infoObject) {
2305
- let index;
2306
- switch (infoObject.mappingType) {
2307
- case "ByPolygonVertex":
2308
- index = polygonVertexIndex;
2309
- break;
2310
- case "ByPolygon":
2311
- index = polygonIndex;
2312
- break;
2313
- case "ByVertice":
2314
- index = vertexIndex;
2315
- break;
2316
- case "AllSame":
2317
- index = infoObject.indices[0];
2318
- break;
2319
- default:
2320
- console.warn("THREE.FBXLoader: unknown attribute mapping type " + infoObject.mappingType);
2321
- }
2322
- if (infoObject.referenceType === "IndexToDirect")
2323
- index = infoObject.indices[index];
2324
- const from = index * infoObject.dataSize;
2325
- const to = from + infoObject.dataSize;
2326
- return slice(dataArray, infoObject.buffer, from, to);
2327
- }
2328
- const tempEuler = /* @__PURE__ */ new Euler();
2329
- const tempVec = /* @__PURE__ */ new Vector3();
2330
- function generateTransform(transformData) {
2331
- const lTranslationM = new Matrix4();
2332
- const lPreRotationM = new Matrix4();
2333
- const lRotationM = new Matrix4();
2334
- const lPostRotationM = new Matrix4();
2335
- const lScalingM = new Matrix4();
2336
- const lScalingPivotM = new Matrix4();
2337
- const lScalingOffsetM = new Matrix4();
2338
- const lRotationOffsetM = new Matrix4();
2339
- const lRotationPivotM = new Matrix4();
2340
- const lParentGX = new Matrix4();
2341
- const lParentLX = new Matrix4();
2342
- const lGlobalT = new Matrix4();
2343
- const inheritType = transformData.inheritType ? transformData.inheritType : 0;
2344
- if (transformData.translation)
2345
- lTranslationM.setPosition(tempVec.fromArray(transformData.translation));
2346
- if (transformData.preRotation) {
2347
- const array = transformData.preRotation.map(MathUtils.degToRad);
2348
- array.push(transformData.eulerOrder);
2349
- lPreRotationM.makeRotationFromEuler(tempEuler.fromArray(array));
2350
- }
2351
- if (transformData.rotation) {
2352
- const array = transformData.rotation.map(MathUtils.degToRad);
2353
- array.push(transformData.eulerOrder);
2354
- lRotationM.makeRotationFromEuler(tempEuler.fromArray(array));
2355
- }
2356
- if (transformData.postRotation) {
2357
- const array = transformData.postRotation.map(MathUtils.degToRad);
2358
- array.push(transformData.eulerOrder);
2359
- lPostRotationM.makeRotationFromEuler(tempEuler.fromArray(array));
2360
- lPostRotationM.invert();
2361
- }
2362
- if (transformData.scale)
2363
- lScalingM.scale(tempVec.fromArray(transformData.scale));
2364
- if (transformData.scalingOffset)
2365
- lScalingOffsetM.setPosition(tempVec.fromArray(transformData.scalingOffset));
2366
- if (transformData.scalingPivot)
2367
- lScalingPivotM.setPosition(tempVec.fromArray(transformData.scalingPivot));
2368
- if (transformData.rotationOffset)
2369
- lRotationOffsetM.setPosition(tempVec.fromArray(transformData.rotationOffset));
2370
- if (transformData.rotationPivot)
2371
- lRotationPivotM.setPosition(tempVec.fromArray(transformData.rotationPivot));
2372
- if (transformData.parentMatrixWorld) {
2373
- lParentLX.copy(transformData.parentMatrix);
2374
- lParentGX.copy(transformData.parentMatrixWorld);
2375
- }
2376
- const lLRM = lPreRotationM.clone().multiply(lRotationM).multiply(lPostRotationM);
2377
- const lParentGRM = new Matrix4();
2378
- lParentGRM.extractRotation(lParentGX);
2379
- const lParentTM = new Matrix4();
2380
- lParentTM.copyPosition(lParentGX);
2381
- const lParentGRSM = lParentTM.clone().invert().multiply(lParentGX);
2382
- const lParentGSM = lParentGRM.clone().invert().multiply(lParentGRSM);
2383
- const lLSM = lScalingM;
2384
- const lGlobalRS = new Matrix4();
2385
- if (inheritType === 0) {
2386
- lGlobalRS.copy(lParentGRM).multiply(lLRM).multiply(lParentGSM).multiply(lLSM);
2387
- } else if (inheritType === 1) {
2388
- lGlobalRS.copy(lParentGRM).multiply(lParentGSM).multiply(lLRM).multiply(lLSM);
2389
- } else {
2390
- const lParentLSM = new Matrix4().scale(new Vector3().setFromMatrixScale(lParentLX));
2391
- const lParentLSM_inv = lParentLSM.clone().invert();
2392
- const lParentGSM_noLocal = lParentGSM.clone().multiply(lParentLSM_inv);
2393
- lGlobalRS.copy(lParentGRM).multiply(lLRM).multiply(lParentGSM_noLocal).multiply(lLSM);
2394
- }
2395
- const lRotationPivotM_inv = lRotationPivotM.clone().invert();
2396
- const lScalingPivotM_inv = lScalingPivotM.clone().invert();
2397
- let lTransform = lTranslationM.clone().multiply(lRotationOffsetM).multiply(lRotationPivotM).multiply(lPreRotationM).multiply(lRotationM).multiply(lPostRotationM).multiply(lRotationPivotM_inv).multiply(lScalingOffsetM).multiply(lScalingPivotM).multiply(lScalingM).multiply(lScalingPivotM_inv);
2398
- const lLocalTWithAllPivotAndOffsetInfo = new Matrix4().copyPosition(lTransform);
2399
- const lGlobalTranslation = lParentGX.clone().multiply(lLocalTWithAllPivotAndOffsetInfo);
2400
- lGlobalT.copyPosition(lGlobalTranslation);
2401
- lTransform = lGlobalT.clone().multiply(lGlobalRS);
2402
- lTransform.premultiply(lParentGX.invert());
2403
- return lTransform;
2404
- }
2405
- function getEulerOrder(order) {
2406
- order = order || 0;
2407
- const enums = [
2408
- "ZYX",
2409
- // -> XYZ extrinsic
2410
- "YZX",
2411
- // -> XZY extrinsic
2412
- "XZY",
2413
- // -> YZX extrinsic
2414
- "ZXY",
2415
- // -> YXZ extrinsic
2416
- "YXZ",
2417
- // -> ZXY extrinsic
2418
- "XYZ"
2419
- // -> ZYX extrinsic
2420
- //'SphericXYZ', // not possible to support
2421
- ];
2422
- if (order === 6) {
2423
- console.warn("THREE.FBXLoader: unsupported Euler Order: Spherical XYZ. Animations and rotations may be incorrect.");
2424
- return enums[0];
2425
- }
2426
- return enums[order];
2427
- }
2428
- function parseNumberArray(value) {
2429
- const array = value.split(",").map(function(val) {
2430
- return parseFloat(val);
2431
- });
2432
- return array;
2433
- }
2434
- function convertArrayBufferToString(buffer, from, to) {
2435
- if (from === void 0)
2436
- from = 0;
2437
- if (to === void 0)
2438
- to = buffer.byteLength;
2439
- return LoaderUtils.decodeText(new Uint8Array(buffer, from, to));
2440
- }
2441
- function append(a, b) {
2442
- for (let i = 0, j = a.length, l = b.length; i < l; i++, j++) {
2443
- a[j] = b[i];
2444
- }
2445
- }
2446
- function slice(a, b, from, to) {
2447
- for (let i = from, j = 0; i < to; i++, j++) {
2448
- a[j] = b[i];
2449
- }
2450
- return a;
2451
- }
2452
- function inject(a1, index, a2) {
2453
- return a1.slice(0, index).concat(a2).concat(a1.slice(index));
2454
- }
2455
- export {
2456
- FBXLoader
2457
- };