three-stdlib 2.25.0 → 2.26.0

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