@gnsx/three 0.184.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 (1182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +85 -0
  3. package/build/three.cjs +79695 -0
  4. package/build/three.core.js +59732 -0
  5. package/build/three.core.min.js +6 -0
  6. package/build/three.module.js +19552 -0
  7. package/build/three.module.min.js +6 -0
  8. package/build/three.tsl.js +654 -0
  9. package/build/three.tsl.min.js +6 -0
  10. package/build/three.webgpu.js +83969 -0
  11. package/build/three.webgpu.min.js +6 -0
  12. package/build/three.webgpu.nodes.js +83702 -0
  13. package/build/three.webgpu.nodes.min.js +6 -0
  14. package/examples/fonts/LICENSE +13 -0
  15. package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
  16. package/examples/fonts/MPLUSRounded1c/OFL.txt +91 -0
  17. package/examples/fonts/README.md +11 -0
  18. package/examples/fonts/droid/NOTICE +190 -0
  19. package/examples/fonts/droid/README.txt +18 -0
  20. package/examples/fonts/droid/droid_sans_bold.typeface.json +1 -0
  21. package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +1 -0
  22. package/examples/fonts/droid/droid_sans_regular.typeface.json +1 -0
  23. package/examples/fonts/droid/droid_serif_bold.typeface.json +1 -0
  24. package/examples/fonts/droid/droid_serif_regular.typeface.json +1 -0
  25. package/examples/fonts/gentilis_bold.typeface.json +1 -0
  26. package/examples/fonts/gentilis_regular.typeface.json +1 -0
  27. package/examples/fonts/helvetiker_bold.typeface.json +1 -0
  28. package/examples/fonts/helvetiker_regular.typeface.json +1 -0
  29. package/examples/fonts/optimer_bold.typeface.json +1 -0
  30. package/examples/fonts/optimer_regular.typeface.json +1 -0
  31. package/examples/fonts/ttf/README.md +9 -0
  32. package/examples/fonts/ttf/kenpixel.ttf +0 -0
  33. package/examples/jsm/Addons.js +293 -0
  34. package/examples/jsm/animation/AnimationClipCreator.js +168 -0
  35. package/examples/jsm/animation/CCDIKSolver.js +595 -0
  36. package/examples/jsm/capabilities/WebGL.js +113 -0
  37. package/examples/jsm/capabilities/WebGPU.js +59 -0
  38. package/examples/jsm/controls/ArcballControls.js +3539 -0
  39. package/examples/jsm/controls/DragControls.js +452 -0
  40. package/examples/jsm/controls/FirstPersonControls.js +451 -0
  41. package/examples/jsm/controls/FlyControls.js +384 -0
  42. package/examples/jsm/controls/MapControls.js +116 -0
  43. package/examples/jsm/controls/OrbitControls.js +1963 -0
  44. package/examples/jsm/controls/PointerLockControls.js +264 -0
  45. package/examples/jsm/controls/TrackballControls.js +1001 -0
  46. package/examples/jsm/controls/TransformControls.js +1950 -0
  47. package/examples/jsm/csm/CSM.js +598 -0
  48. package/examples/jsm/csm/CSMFrustum.js +209 -0
  49. package/examples/jsm/csm/CSMHelper.js +243 -0
  50. package/examples/jsm/csm/CSMShader.js +307 -0
  51. package/examples/jsm/csm/CSMShadowNode.js +603 -0
  52. package/examples/jsm/curves/CurveExtras.js +694 -0
  53. package/examples/jsm/curves/NURBSCurve.js +155 -0
  54. package/examples/jsm/curves/NURBSSurface.js +98 -0
  55. package/examples/jsm/curves/NURBSUtils.js +532 -0
  56. package/examples/jsm/curves/NURBSVolume.js +82 -0
  57. package/examples/jsm/effects/AnaglyphEffect.js +274 -0
  58. package/examples/jsm/effects/AsciiEffect.js +310 -0
  59. package/examples/jsm/effects/OutlineEffect.js +489 -0
  60. package/examples/jsm/effects/ParallaxBarrierEffect.js +155 -0
  61. package/examples/jsm/effects/StereoEffect.js +91 -0
  62. package/examples/jsm/environments/ColorEnvironment.js +59 -0
  63. package/examples/jsm/environments/DebugEnvironment.js +102 -0
  64. package/examples/jsm/environments/RoomEnvironment.js +185 -0
  65. package/examples/jsm/exporters/DRACOExporter.js +311 -0
  66. package/examples/jsm/exporters/EXRExporter.js +618 -0
  67. package/examples/jsm/exporters/GLTFExporter.js +3738 -0
  68. package/examples/jsm/exporters/KTX2Exporter.js +347 -0
  69. package/examples/jsm/exporters/OBJExporter.js +308 -0
  70. package/examples/jsm/exporters/PLYExporter.js +562 -0
  71. package/examples/jsm/exporters/STLExporter.js +221 -0
  72. package/examples/jsm/exporters/USDZExporter.js +1254 -0
  73. package/examples/jsm/geometries/BoxLineGeometry.js +92 -0
  74. package/examples/jsm/geometries/ConvexGeometry.js +72 -0
  75. package/examples/jsm/geometries/DecalGeometry.js +420 -0
  76. package/examples/jsm/geometries/ParametricFunctions.js +100 -0
  77. package/examples/jsm/geometries/ParametricGeometry.js +172 -0
  78. package/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  79. package/examples/jsm/geometries/TeapotGeometry.js +689 -0
  80. package/examples/jsm/geometries/TextGeometry.js +102 -0
  81. package/examples/jsm/gpgpu/BitonicSort.js +715 -0
  82. package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
  83. package/examples/jsm/helpers/LightProbeGridHelper.js +221 -0
  84. package/examples/jsm/helpers/LightProbeHelper.js +165 -0
  85. package/examples/jsm/helpers/LightProbeHelperGPU.js +102 -0
  86. package/examples/jsm/helpers/OctreeHelper.js +109 -0
  87. package/examples/jsm/helpers/PositionalAudioHelper.js +169 -0
  88. package/examples/jsm/helpers/RapierHelper.js +59 -0
  89. package/examples/jsm/helpers/RectAreaLightHelper.js +118 -0
  90. package/examples/jsm/helpers/TextureHelper.js +265 -0
  91. package/examples/jsm/helpers/TextureHelperGPU.js +214 -0
  92. package/examples/jsm/helpers/VertexNormalsHelper.js +155 -0
  93. package/examples/jsm/helpers/VertexTangentsHelper.js +133 -0
  94. package/examples/jsm/helpers/ViewHelper.js +519 -0
  95. package/examples/jsm/inspector/Extension.js +13 -0
  96. package/examples/jsm/inspector/Inspector.js +542 -0
  97. package/examples/jsm/inspector/RendererInspector.js +425 -0
  98. package/examples/jsm/inspector/extensions/extensions.json +6 -0
  99. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +916 -0
  100. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +281 -0
  101. package/examples/jsm/inspector/tabs/Console.js +238 -0
  102. package/examples/jsm/inspector/tabs/Memory.js +128 -0
  103. package/examples/jsm/inspector/tabs/Parameters.js +380 -0
  104. package/examples/jsm/inspector/tabs/Performance.js +268 -0
  105. package/examples/jsm/inspector/tabs/Settings.js +264 -0
  106. package/examples/jsm/inspector/tabs/Timeline.js +1611 -0
  107. package/examples/jsm/inspector/tabs/Viewer.js +268 -0
  108. package/examples/jsm/inspector/ui/Graph.js +95 -0
  109. package/examples/jsm/inspector/ui/Item.js +170 -0
  110. package/examples/jsm/inspector/ui/List.js +75 -0
  111. package/examples/jsm/inspector/ui/Profiler.js +2072 -0
  112. package/examples/jsm/inspector/ui/Style.js +1667 -0
  113. package/examples/jsm/inspector/ui/Tab.js +265 -0
  114. package/examples/jsm/inspector/ui/Values.js +476 -0
  115. package/examples/jsm/inspector/ui/utils.js +69 -0
  116. package/examples/jsm/interaction/InteractionManager.js +226 -0
  117. package/examples/jsm/interactive/HTMLMesh.js +601 -0
  118. package/examples/jsm/interactive/InteractiveGroup.js +224 -0
  119. package/examples/jsm/interactive/SelectionBox.js +324 -0
  120. package/examples/jsm/interactive/SelectionHelper.js +150 -0
  121. package/examples/jsm/libs/ammo.wasm.js +822 -0
  122. package/examples/jsm/libs/ammo.wasm.wasm +0 -0
  123. package/examples/jsm/libs/basis/README.md +46 -0
  124. package/examples/jsm/libs/basis/basis_transcoder.js +19 -0
  125. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  126. package/examples/jsm/libs/chevrotain.module.min.js +141 -0
  127. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  128. package/examples/jsm/libs/draco/README.md +32 -0
  129. package/examples/jsm/libs/draco/draco_decoder.js +34 -0
  130. package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
  131. package/examples/jsm/libs/draco/draco_encoder.js +33 -0
  132. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -0
  133. package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -0
  134. package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
  135. package/examples/jsm/libs/draco/gltf/draco_encoder.js +33 -0
  136. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
  137. package/examples/jsm/libs/ecsy.module.js +1792 -0
  138. package/examples/jsm/libs/fflate.module.js +2672 -0
  139. package/examples/jsm/libs/ktx-parse.module.js +1 -0
  140. package/examples/jsm/libs/lil-gui.module.min.js +8 -0
  141. package/examples/jsm/libs/lottie_canvas.module.js +14849 -0
  142. package/examples/jsm/libs/meshopt_decoder.module.js +196 -0
  143. package/examples/jsm/libs/mikktspace.module.js +128 -0
  144. package/examples/jsm/libs/motion-controllers.module.js +397 -0
  145. package/examples/jsm/libs/opentype.module.js +14506 -0
  146. package/examples/jsm/libs/potpack.module.js +125 -0
  147. package/examples/jsm/libs/rhino3dm/rhino3dm.js +21 -0
  148. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +16 -0
  149. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  150. package/examples/jsm/libs/stats.module.js +167 -0
  151. package/examples/jsm/libs/surfaceNet.js +201 -0
  152. package/examples/jsm/libs/tween.module.js +876 -0
  153. package/examples/jsm/libs/utif.module.js +1665 -0
  154. package/examples/jsm/libs/zstddec.module.js +1 -0
  155. package/examples/jsm/lighting/DynamicLighting.js +82 -0
  156. package/examples/jsm/lighting/LightProbeGrid.js +651 -0
  157. package/examples/jsm/lighting/TiledLighting.js +42 -0
  158. package/examples/jsm/lights/LightProbeGenerator.js +337 -0
  159. package/examples/jsm/lights/RectAreaLightTexturesLib.js +127 -0
  160. package/examples/jsm/lights/RectAreaLightUniformsLib.js +40 -0
  161. package/examples/jsm/lines/Line2.js +56 -0
  162. package/examples/jsm/lines/LineGeometry.js +157 -0
  163. package/examples/jsm/lines/LineMaterial.js +703 -0
  164. package/examples/jsm/lines/LineSegments2.js +426 -0
  165. package/examples/jsm/lines/LineSegmentsGeometry.js +298 -0
  166. package/examples/jsm/lines/Wireframe.js +108 -0
  167. package/examples/jsm/lines/WireframeGeometry2.js +49 -0
  168. package/examples/jsm/lines/webgpu/Line2.js +46 -0
  169. package/examples/jsm/lines/webgpu/LineSegments2.js +411 -0
  170. package/examples/jsm/lines/webgpu/Wireframe.js +86 -0
  171. package/examples/jsm/loaders/3DMLoader.js +1836 -0
  172. package/examples/jsm/loaders/3MFLoader.js +1621 -0
  173. package/examples/jsm/loaders/AMFLoader.js +541 -0
  174. package/examples/jsm/loaders/BVHLoader.js +484 -0
  175. package/examples/jsm/loaders/ColladaLoader.js +153 -0
  176. package/examples/jsm/loaders/DDSLoader.js +385 -0
  177. package/examples/jsm/loaders/DRACOLoader.js +739 -0
  178. package/examples/jsm/loaders/EXRLoader.js +3423 -0
  179. package/examples/jsm/loaders/FBXLoader.js +4580 -0
  180. package/examples/jsm/loaders/FontLoader.js +260 -0
  181. package/examples/jsm/loaders/GCodeLoader.js +318 -0
  182. package/examples/jsm/loaders/GLTFLoader.js +4860 -0
  183. package/examples/jsm/loaders/HDRCubeTextureLoader.js +164 -0
  184. package/examples/jsm/loaders/HDRLoader.js +485 -0
  185. package/examples/jsm/loaders/IESLoader.js +379 -0
  186. package/examples/jsm/loaders/KMZLoader.js +163 -0
  187. package/examples/jsm/loaders/KTX2Loader.js +1257 -0
  188. package/examples/jsm/loaders/KTXLoader.js +197 -0
  189. package/examples/jsm/loaders/LDrawLoader.js +2510 -0
  190. package/examples/jsm/loaders/LUT3dlLoader.js +205 -0
  191. package/examples/jsm/loaders/LUTCubeLoader.js +190 -0
  192. package/examples/jsm/loaders/LUTImageLoader.js +190 -0
  193. package/examples/jsm/loaders/LWOLoader.js +1047 -0
  194. package/examples/jsm/loaders/LottieLoader.js +130 -0
  195. package/examples/jsm/loaders/MD2Loader.js +435 -0
  196. package/examples/jsm/loaders/MDDLoader.js +147 -0
  197. package/examples/jsm/loaders/MTLLoader.js +593 -0
  198. package/examples/jsm/loaders/MaterialXLoader.js +1104 -0
  199. package/examples/jsm/loaders/NRRDLoader.js +718 -0
  200. package/examples/jsm/loaders/OBJLoader.js +955 -0
  201. package/examples/jsm/loaders/PCDLoader.js +620 -0
  202. package/examples/jsm/loaders/PDBLoader.js +272 -0
  203. package/examples/jsm/loaders/PLYLoader.js +805 -0
  204. package/examples/jsm/loaders/PVRLoader.js +270 -0
  205. package/examples/jsm/loaders/RGBELoader.js +18 -0
  206. package/examples/jsm/loaders/STLLoader.js +421 -0
  207. package/examples/jsm/loaders/SVGLoader.js +3267 -0
  208. package/examples/jsm/loaders/TDSLoader.js +1142 -0
  209. package/examples/jsm/loaders/TGALoader.js +538 -0
  210. package/examples/jsm/loaders/TIFFLoader.js +59 -0
  211. package/examples/jsm/loaders/TTFLoader.js +261 -0
  212. package/examples/jsm/loaders/USDLoader.js +279 -0
  213. package/examples/jsm/loaders/USDZLoader.js +16 -0
  214. package/examples/jsm/loaders/UltraHDRLoader.js +755 -0
  215. package/examples/jsm/loaders/VOXLoader.js +919 -0
  216. package/examples/jsm/loaders/VRMLLoader.js +3646 -0
  217. package/examples/jsm/loaders/VTKLoader.js +1293 -0
  218. package/examples/jsm/loaders/XYZLoader.js +143 -0
  219. package/examples/jsm/loaders/collada/ColladaComposer.js +3044 -0
  220. package/examples/jsm/loaders/collada/ColladaParser.js +1977 -0
  221. package/examples/jsm/loaders/lwo/IFFParser.js +1217 -0
  222. package/examples/jsm/loaders/lwo/LWO2Parser.js +414 -0
  223. package/examples/jsm/loaders/lwo/LWO3Parser.js +373 -0
  224. package/examples/jsm/loaders/usd/USDAParser.js +828 -0
  225. package/examples/jsm/loaders/usd/USDCParser.js +1878 -0
  226. package/examples/jsm/loaders/usd/USDComposer.js +4594 -0
  227. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +183 -0
  228. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +154 -0
  229. package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
  230. package/examples/jsm/math/Capsule.js +159 -0
  231. package/examples/jsm/math/ColorConverter.js +58 -0
  232. package/examples/jsm/math/ColorSpaces.js +147 -0
  233. package/examples/jsm/math/ConvexHull.js +1695 -0
  234. package/examples/jsm/math/ImprovedNoise.js +88 -0
  235. package/examples/jsm/math/Lut.js +317 -0
  236. package/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  237. package/examples/jsm/math/OBB.js +535 -0
  238. package/examples/jsm/math/Octree.js +822 -0
  239. package/examples/jsm/math/SimplexNoise.js +470 -0
  240. package/examples/jsm/misc/ConvexObjectBreaker.js +539 -0
  241. package/examples/jsm/misc/GPUComputationRenderer.js +508 -0
  242. package/examples/jsm/misc/Gyroscope.js +78 -0
  243. package/examples/jsm/misc/MD2Character.js +391 -0
  244. package/examples/jsm/misc/MD2CharacterComplex.js +740 -0
  245. package/examples/jsm/misc/MorphAnimMesh.js +119 -0
  246. package/examples/jsm/misc/MorphBlendMesh.js +425 -0
  247. package/examples/jsm/misc/ProgressiveLightMap.js +370 -0
  248. package/examples/jsm/misc/ProgressiveLightMapGPU.js +322 -0
  249. package/examples/jsm/misc/RollerCoaster.js +661 -0
  250. package/examples/jsm/misc/TubePainter.js +599 -0
  251. package/examples/jsm/misc/Volume.js +520 -0
  252. package/examples/jsm/misc/VolumeSlice.js +275 -0
  253. package/examples/jsm/modifiers/CurveModifier.js +374 -0
  254. package/examples/jsm/modifiers/CurveModifierGPU.js +256 -0
  255. package/examples/jsm/modifiers/EdgeSplitModifier.js +299 -0
  256. package/examples/jsm/modifiers/SimplifyModifier.js +632 -0
  257. package/examples/jsm/modifiers/TessellateModifier.js +340 -0
  258. package/examples/jsm/objects/GroundedSkybox.js +69 -0
  259. package/examples/jsm/objects/Lensflare.js +489 -0
  260. package/examples/jsm/objects/LensflareMesh.js +376 -0
  261. package/examples/jsm/objects/MarchingCubes.js +1261 -0
  262. package/examples/jsm/objects/Reflector.js +386 -0
  263. package/examples/jsm/objects/ReflectorForSSRPass.js +393 -0
  264. package/examples/jsm/objects/Refractor.js +389 -0
  265. package/examples/jsm/objects/ShadowMesh.js +130 -0
  266. package/examples/jsm/objects/Sky.js +321 -0
  267. package/examples/jsm/objects/SkyMesh.js +377 -0
  268. package/examples/jsm/objects/Water.js +374 -0
  269. package/examples/jsm/objects/Water2.js +403 -0
  270. package/examples/jsm/objects/Water2Mesh.js +199 -0
  271. package/examples/jsm/objects/WaterMesh.js +194 -0
  272. package/examples/jsm/offscreen/jank.js +45 -0
  273. package/examples/jsm/offscreen/offscreen.js +8 -0
  274. package/examples/jsm/offscreen/scene.js +86 -0
  275. package/examples/jsm/physics/AmmoPhysics.js +359 -0
  276. package/examples/jsm/physics/JoltPhysics.js +334 -0
  277. package/examples/jsm/physics/RapierPhysics.js +436 -0
  278. package/examples/jsm/postprocessing/AfterimagePass.js +185 -0
  279. package/examples/jsm/postprocessing/BloomPass.js +274 -0
  280. package/examples/jsm/postprocessing/BokehPass.js +218 -0
  281. package/examples/jsm/postprocessing/ClearPass.js +97 -0
  282. package/examples/jsm/postprocessing/CubeTexturePass.js +146 -0
  283. package/examples/jsm/postprocessing/DotScreenPass.js +114 -0
  284. package/examples/jsm/postprocessing/EffectComposer.js +365 -0
  285. package/examples/jsm/postprocessing/FXAAPass.js +40 -0
  286. package/examples/jsm/postprocessing/FilmPass.js +113 -0
  287. package/examples/jsm/postprocessing/GTAOPass.js +727 -0
  288. package/examples/jsm/postprocessing/GlitchPass.js +177 -0
  289. package/examples/jsm/postprocessing/HalftonePass.js +134 -0
  290. package/examples/jsm/postprocessing/LUTPass.js +138 -0
  291. package/examples/jsm/postprocessing/MaskPass.js +195 -0
  292. package/examples/jsm/postprocessing/OutlinePass.js +776 -0
  293. package/examples/jsm/postprocessing/OutputPass.js +148 -0
  294. package/examples/jsm/postprocessing/Pass.js +191 -0
  295. package/examples/jsm/postprocessing/RenderPass.js +193 -0
  296. package/examples/jsm/postprocessing/RenderPixelatedPass.js +314 -0
  297. package/examples/jsm/postprocessing/RenderTransitionPass.js +267 -0
  298. package/examples/jsm/postprocessing/SAOPass.js +407 -0
  299. package/examples/jsm/postprocessing/SMAAPass.js +230 -0
  300. package/examples/jsm/postprocessing/SSAARenderPass.js +313 -0
  301. package/examples/jsm/postprocessing/SSAOPass.js +527 -0
  302. package/examples/jsm/postprocessing/SSRPass.js +856 -0
  303. package/examples/jsm/postprocessing/SavePass.js +132 -0
  304. package/examples/jsm/postprocessing/ShaderPass.js +135 -0
  305. package/examples/jsm/postprocessing/TAARenderPass.js +243 -0
  306. package/examples/jsm/postprocessing/TexturePass.js +131 -0
  307. package/examples/jsm/postprocessing/UnrealBloomPass.js +524 -0
  308. package/examples/jsm/renderers/CSS2DRenderer.js +328 -0
  309. package/examples/jsm/renderers/CSS3DRenderer.js +454 -0
  310. package/examples/jsm/renderers/Projector.js +1154 -0
  311. package/examples/jsm/renderers/SVGRenderer.js +799 -0
  312. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +96 -0
  313. package/examples/jsm/shaders/AfterimageShader.js +63 -0
  314. package/examples/jsm/shaders/BasicShader.js +36 -0
  315. package/examples/jsm/shaders/BleachBypassShader.js +68 -0
  316. package/examples/jsm/shaders/BlendShader.js +56 -0
  317. package/examples/jsm/shaders/BokehShader.js +151 -0
  318. package/examples/jsm/shaders/BokehShader2.js +404 -0
  319. package/examples/jsm/shaders/BrightnessContrastShader.js +62 -0
  320. package/examples/jsm/shaders/ColorCorrectionShader.js +59 -0
  321. package/examples/jsm/shaders/ColorifyShader.js +57 -0
  322. package/examples/jsm/shaders/ConvolutionShader.js +74 -0
  323. package/examples/jsm/shaders/CopyShader.js +52 -0
  324. package/examples/jsm/shaders/DOFMipMapShader.js +63 -0
  325. package/examples/jsm/shaders/DepthLimitedBlurShader.js +180 -0
  326. package/examples/jsm/shaders/DigitalGlitch.js +104 -0
  327. package/examples/jsm/shaders/DotScreenShader.js +75 -0
  328. package/examples/jsm/shaders/ExposureShader.js +51 -0
  329. package/examples/jsm/shaders/FXAAShader.js +298 -0
  330. package/examples/jsm/shaders/FilmShader.js +72 -0
  331. package/examples/jsm/shaders/FocusShader.js +94 -0
  332. package/examples/jsm/shaders/FreiChenShader.js +103 -0
  333. package/examples/jsm/shaders/GTAOShader.js +434 -0
  334. package/examples/jsm/shaders/GammaCorrectionShader.js +52 -0
  335. package/examples/jsm/shaders/HalftoneShader.js +332 -0
  336. package/examples/jsm/shaders/HorizontalBlurShader.js +68 -0
  337. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +70 -0
  338. package/examples/jsm/shaders/HueSaturationShader.js +74 -0
  339. package/examples/jsm/shaders/KaleidoShader.js +65 -0
  340. package/examples/jsm/shaders/LuminosityHighPassShader.js +68 -0
  341. package/examples/jsm/shaders/LuminosityShader.js +54 -0
  342. package/examples/jsm/shaders/MirrorShader.js +62 -0
  343. package/examples/jsm/shaders/NormalMapShader.js +60 -0
  344. package/examples/jsm/shaders/OutputShader.js +103 -0
  345. package/examples/jsm/shaders/PoissonDenoiseShader.js +239 -0
  346. package/examples/jsm/shaders/RGBShiftShader.js +61 -0
  347. package/examples/jsm/shaders/SAOShader.js +201 -0
  348. package/examples/jsm/shaders/SMAAShader.js +489 -0
  349. package/examples/jsm/shaders/SSAOShader.js +331 -0
  350. package/examples/jsm/shaders/SSRShader.js +396 -0
  351. package/examples/jsm/shaders/SepiaShader.js +57 -0
  352. package/examples/jsm/shaders/SobelOperatorShader.js +98 -0
  353. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +95 -0
  354. package/examples/jsm/shaders/TechnicolorShader.js +51 -0
  355. package/examples/jsm/shaders/ToonShader.js +349 -0
  356. package/examples/jsm/shaders/TriangleBlurShader.js +79 -0
  357. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +60 -0
  358. package/examples/jsm/shaders/VelocityShader.js +137 -0
  359. package/examples/jsm/shaders/VerticalBlurShader.js +66 -0
  360. package/examples/jsm/shaders/VerticalTiltShiftShader.js +70 -0
  361. package/examples/jsm/shaders/VignetteShader.js +56 -0
  362. package/examples/jsm/shaders/VolumeShader.js +298 -0
  363. package/examples/jsm/shaders/WaterRefractionShader.js +106 -0
  364. package/examples/jsm/textures/FlakesTexture.js +54 -0
  365. package/examples/jsm/transpiler/AST.js +675 -0
  366. package/examples/jsm/transpiler/GLSLDecoder.js +1228 -0
  367. package/examples/jsm/transpiler/Linker.js +327 -0
  368. package/examples/jsm/transpiler/ShaderToyDecoder.js +51 -0
  369. package/examples/jsm/transpiler/TSLEncoder.js +983 -0
  370. package/examples/jsm/transpiler/Transpiler.js +67 -0
  371. package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
  372. package/examples/jsm/transpiler/WGSLEncoder.js +839 -0
  373. package/examples/jsm/tsl/WebGLNodesHandler.js +605 -0
  374. package/examples/jsm/tsl/display/AfterImageNode.js +254 -0
  375. package/examples/jsm/tsl/display/AnaglyphPassNode.js +549 -0
  376. package/examples/jsm/tsl/display/AnamorphicNode.js +293 -0
  377. package/examples/jsm/tsl/display/BilateralBlurNode.js +374 -0
  378. package/examples/jsm/tsl/display/BleachBypass.js +33 -0
  379. package/examples/jsm/tsl/display/BloomNode.js +534 -0
  380. package/examples/jsm/tsl/display/CRT.js +150 -0
  381. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +174 -0
  382. package/examples/jsm/tsl/display/DenoiseNode.js +334 -0
  383. package/examples/jsm/tsl/display/DepthOfFieldNode.js +554 -0
  384. package/examples/jsm/tsl/display/DotScreenNode.js +104 -0
  385. package/examples/jsm/tsl/display/FSR1Node.js +477 -0
  386. package/examples/jsm/tsl/display/FXAANode.js +365 -0
  387. package/examples/jsm/tsl/display/FilmNode.js +101 -0
  388. package/examples/jsm/tsl/display/GTAONode.js +572 -0
  389. package/examples/jsm/tsl/display/GaussianBlurNode.js +399 -0
  390. package/examples/jsm/tsl/display/GodraysNode.js +615 -0
  391. package/examples/jsm/tsl/display/LensflareNode.js +279 -0
  392. package/examples/jsm/tsl/display/Lut3DNode.js +109 -0
  393. package/examples/jsm/tsl/display/MotionBlur.js +33 -0
  394. package/examples/jsm/tsl/display/OutlineNode.js +812 -0
  395. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +89 -0
  396. package/examples/jsm/tsl/display/PixelationPassNode.js +335 -0
  397. package/examples/jsm/tsl/display/RGBShiftNode.js +96 -0
  398. package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
  399. package/examples/jsm/tsl/display/SMAANode.js +768 -0
  400. package/examples/jsm/tsl/display/SSAAPassNode.js +358 -0
  401. package/examples/jsm/tsl/display/SSGINode.js +638 -0
  402. package/examples/jsm/tsl/display/SSRNode.js +656 -0
  403. package/examples/jsm/tsl/display/SSSNode.js +490 -0
  404. package/examples/jsm/tsl/display/Sepia.js +24 -0
  405. package/examples/jsm/tsl/display/Shape.js +29 -0
  406. package/examples/jsm/tsl/display/SharpenNode.js +283 -0
  407. package/examples/jsm/tsl/display/SobelOperatorNode.js +168 -0
  408. package/examples/jsm/tsl/display/StereoCompositePassNode.js +192 -0
  409. package/examples/jsm/tsl/display/StereoPassNode.js +119 -0
  410. package/examples/jsm/tsl/display/TAAUNode.js +835 -0
  411. package/examples/jsm/tsl/display/TRAANode.js +767 -0
  412. package/examples/jsm/tsl/display/TransitionNode.js +141 -0
  413. package/examples/jsm/tsl/display/boxBlur.js +65 -0
  414. package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
  415. package/examples/jsm/tsl/display/hashBlur.js +54 -0
  416. package/examples/jsm/tsl/display/radialBlur.js +68 -0
  417. package/examples/jsm/tsl/lighting/DynamicLightsNode.js +300 -0
  418. package/examples/jsm/tsl/lighting/TiledLightsNode.js +442 -0
  419. package/examples/jsm/tsl/lighting/data/AmbientLightDataNode.js +61 -0
  420. package/examples/jsm/tsl/lighting/data/DirectionalLightDataNode.js +111 -0
  421. package/examples/jsm/tsl/lighting/data/HemisphereLightDataNode.js +99 -0
  422. package/examples/jsm/tsl/lighting/data/PointLightDataNode.js +134 -0
  423. package/examples/jsm/tsl/lighting/data/SpotLightDataNode.js +161 -0
  424. package/examples/jsm/tsl/math/Bayer.js +84 -0
  425. package/examples/jsm/tsl/shadows/TileShadowNode.js +456 -0
  426. package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +212 -0
  427. package/examples/jsm/tsl/utils/Raymarching.js +70 -0
  428. package/examples/jsm/utils/BufferGeometryUtils.js +1434 -0
  429. package/examples/jsm/utils/CameraUtils.js +82 -0
  430. package/examples/jsm/utils/ColorUtils.js +76 -0
  431. package/examples/jsm/utils/GeometryCompressionUtils.js +547 -0
  432. package/examples/jsm/utils/GeometryUtils.js +226 -0
  433. package/examples/jsm/utils/LDrawUtils.js +211 -0
  434. package/examples/jsm/utils/SceneOptimizer.js +458 -0
  435. package/examples/jsm/utils/SceneUtils.js +363 -0
  436. package/examples/jsm/utils/ShadowMapViewer.js +244 -0
  437. package/examples/jsm/utils/ShadowMapViewerGPU.js +233 -0
  438. package/examples/jsm/utils/SkeletonUtils.js +496 -0
  439. package/examples/jsm/utils/SortUtils.js +175 -0
  440. package/examples/jsm/utils/UVsDebug.js +173 -0
  441. package/examples/jsm/utils/WebGLTextureUtils.js +115 -0
  442. package/examples/jsm/utils/WebGPUTextureUtils.js +81 -0
  443. package/examples/jsm/utils/WorkerPool.js +167 -0
  444. package/examples/jsm/webxr/ARButton.js +251 -0
  445. package/examples/jsm/webxr/OculusHandModel.js +194 -0
  446. package/examples/jsm/webxr/OculusHandPointerModel.js +539 -0
  447. package/examples/jsm/webxr/Text2D.js +52 -0
  448. package/examples/jsm/webxr/VRButton.js +264 -0
  449. package/examples/jsm/webxr/XRButton.js +246 -0
  450. package/examples/jsm/webxr/XRControllerModelFactory.js +403 -0
  451. package/examples/jsm/webxr/XREstimatedLight.js +254 -0
  452. package/examples/jsm/webxr/XRHandMeshModel.js +177 -0
  453. package/examples/jsm/webxr/XRHandModelFactory.js +198 -0
  454. package/examples/jsm/webxr/XRHandPrimitiveModel.js +147 -0
  455. package/examples/jsm/webxr/XRPlanes.js +118 -0
  456. package/package.json +123 -0
  457. package/src/Three.Core.js +187 -0
  458. package/src/Three.Legacy.js +0 -0
  459. package/src/Three.TSL.js +647 -0
  460. package/src/Three.WebGPU.Nodes.js +31 -0
  461. package/src/Three.WebGPU.js +37 -0
  462. package/src/Three.js +10 -0
  463. package/src/animation/AnimationAction.js +942 -0
  464. package/src/animation/AnimationClip.js +628 -0
  465. package/src/animation/AnimationMixer.js +860 -0
  466. package/src/animation/AnimationObjectGroup.js +411 -0
  467. package/src/animation/AnimationUtils.js +495 -0
  468. package/src/animation/KeyframeTrack.js +636 -0
  469. package/src/animation/PropertyBinding.js +794 -0
  470. package/src/animation/PropertyMixer.js +385 -0
  471. package/src/animation/tracks/BooleanKeyframeTrack.js +55 -0
  472. package/src/animation/tracks/ColorKeyframeTrack.js +36 -0
  473. package/src/animation/tracks/NumberKeyframeTrack.js +36 -0
  474. package/src/animation/tracks/QuaternionKeyframeTrack.js +51 -0
  475. package/src/animation/tracks/StringKeyframeTrack.js +55 -0
  476. package/src/animation/tracks/VectorKeyframeTrack.js +36 -0
  477. package/src/audio/Audio.js +778 -0
  478. package/src/audio/AudioAnalyser.js +97 -0
  479. package/src/audio/AudioContext.js +40 -0
  480. package/src/audio/AudioListener.js +218 -0
  481. package/src/audio/PositionalAudio.js +253 -0
  482. package/src/cameras/ArrayCamera.js +54 -0
  483. package/src/cameras/Camera.js +160 -0
  484. package/src/cameras/CubeCamera.js +259 -0
  485. package/src/cameras/OrthographicCamera.js +245 -0
  486. package/src/cameras/PerspectiveCamera.js +407 -0
  487. package/src/cameras/StereoCamera.js +146 -0
  488. package/src/constants.js +1760 -0
  489. package/src/core/BufferAttribute.js +1056 -0
  490. package/src/core/BufferGeometry.js +1458 -0
  491. package/src/core/Clock.js +135 -0
  492. package/src/core/EventDispatcher.js +131 -0
  493. package/src/core/GLBufferAttribute.js +171 -0
  494. package/src/core/InstancedBufferAttribute.js +68 -0
  495. package/src/core/InstancedBufferGeometry.js +60 -0
  496. package/src/core/InstancedInterleavedBuffer.js +74 -0
  497. package/src/core/InterleavedBuffer.js +291 -0
  498. package/src/core/InterleavedBufferAttribute.js +549 -0
  499. package/src/core/Layers.js +121 -0
  500. package/src/core/Object3D.js +1667 -0
  501. package/src/core/Raycaster.js +262 -0
  502. package/src/core/RenderTarget.js +392 -0
  503. package/src/core/RenderTarget3D.js +48 -0
  504. package/src/core/Timer.js +184 -0
  505. package/src/core/Uniform.js +46 -0
  506. package/src/core/UniformsGroup.js +180 -0
  507. package/src/extras/Controls.js +120 -0
  508. package/src/extras/DataUtils.js +217 -0
  509. package/src/extras/Earcut.js +28 -0
  510. package/src/extras/ImageUtils.js +137 -0
  511. package/src/extras/PMREMGenerator.js +1167 -0
  512. package/src/extras/ShapeUtils.js +114 -0
  513. package/src/extras/TextureUtils.js +297 -0
  514. package/src/extras/core/Curve.js +517 -0
  515. package/src/extras/core/CurvePath.js +296 -0
  516. package/src/extras/core/Interpolations.js +111 -0
  517. package/src/extras/core/Path.js +329 -0
  518. package/src/extras/core/Shape.js +165 -0
  519. package/src/extras/core/ShapePath.js +367 -0
  520. package/src/extras/curves/ArcCurve.js +39 -0
  521. package/src/extras/curves/CatmullRomCurve3.js +327 -0
  522. package/src/extras/curves/CubicBezierCurve.js +145 -0
  523. package/src/extras/curves/CubicBezierCurve3.js +129 -0
  524. package/src/extras/curves/Curves.js +10 -0
  525. package/src/extras/curves/EllipseCurve.js +258 -0
  526. package/src/extras/curves/LineCurve.js +128 -0
  527. package/src/extras/curves/LineCurve3.js +128 -0
  528. package/src/extras/curves/QuadraticBezierCurve.js +133 -0
  529. package/src/extras/curves/QuadraticBezierCurve3.js +118 -0
  530. package/src/extras/curves/SplineCurve.js +145 -0
  531. package/src/extras/lib/earcut.js +685 -0
  532. package/src/geometries/BoxGeometry.js +219 -0
  533. package/src/geometries/CapsuleGeometry.js +218 -0
  534. package/src/geometries/CircleGeometry.js +142 -0
  535. package/src/geometries/ConeGeometry.js +70 -0
  536. package/src/geometries/CylinderGeometry.js +333 -0
  537. package/src/geometries/DodecahedronGeometry.js +99 -0
  538. package/src/geometries/EdgesGeometry.js +180 -0
  539. package/src/geometries/ExtrudeGeometry.js +910 -0
  540. package/src/geometries/Geometries.js +21 -0
  541. package/src/geometries/IcosahedronGeometry.js +75 -0
  542. package/src/geometries/LatheGeometry.js +230 -0
  543. package/src/geometries/OctahedronGeometry.js +70 -0
  544. package/src/geometries/PlaneGeometry.js +133 -0
  545. package/src/geometries/PolyhedronGeometry.js +348 -0
  546. package/src/geometries/RingGeometry.js +165 -0
  547. package/src/geometries/ShapeGeometry.js +233 -0
  548. package/src/geometries/SphereGeometry.js +175 -0
  549. package/src/geometries/TetrahedronGeometry.js +67 -0
  550. package/src/geometries/TorusGeometry.js +161 -0
  551. package/src/geometries/TorusKnotGeometry.js +206 -0
  552. package/src/geometries/TubeGeometry.js +253 -0
  553. package/src/geometries/WireframeGeometry.js +179 -0
  554. package/src/helpers/ArrowHelper.js +171 -0
  555. package/src/helpers/AxesHelper.js +96 -0
  556. package/src/helpers/Box3Helper.js +83 -0
  557. package/src/helpers/BoxHelper.js +149 -0
  558. package/src/helpers/CameraHelper.js +345 -0
  559. package/src/helpers/DirectionalLightHelper.js +148 -0
  560. package/src/helpers/GridHelper.js +82 -0
  561. package/src/helpers/HemisphereLightHelper.js +130 -0
  562. package/src/helpers/PlaneHelper.js +96 -0
  563. package/src/helpers/PointLightHelper.js +111 -0
  564. package/src/helpers/PolarGridHelper.js +126 -0
  565. package/src/helpers/SkeletonHelper.js +194 -0
  566. package/src/helpers/SpotLightHelper.js +154 -0
  567. package/src/lights/AmbientLight.js +42 -0
  568. package/src/lights/DirectionalLight.js +113 -0
  569. package/src/lights/DirectionalLightShadow.js +31 -0
  570. package/src/lights/HemisphereLight.js +76 -0
  571. package/src/lights/Light.js +85 -0
  572. package/src/lights/LightProbe.js +75 -0
  573. package/src/lights/LightShadow.js +347 -0
  574. package/src/lights/PointLight.js +131 -0
  575. package/src/lights/PointLightShadow.js +31 -0
  576. package/src/lights/RectAreaLight.js +115 -0
  577. package/src/lights/SpotLight.js +194 -0
  578. package/src/lights/SpotLightShadow.js +80 -0
  579. package/src/lights/webgpu/IESSpotLight.js +47 -0
  580. package/src/lights/webgpu/ProjectorLight.js +46 -0
  581. package/src/loaders/AnimationLoader.js +98 -0
  582. package/src/loaders/AudioLoader.js +108 -0
  583. package/src/loaders/BufferGeometryLoader.js +242 -0
  584. package/src/loaders/Cache.js +115 -0
  585. package/src/loaders/CompressedTextureLoader.js +167 -0
  586. package/src/loaders/CubeTextureLoader.js +103 -0
  587. package/src/loaders/DataTextureLoader.js +174 -0
  588. package/src/loaders/FileLoader.js +367 -0
  589. package/src/loaders/ImageBitmapLoader.js +223 -0
  590. package/src/loaders/ImageLoader.js +168 -0
  591. package/src/loaders/Loader.js +222 -0
  592. package/src/loaders/LoaderUtils.js +59 -0
  593. package/src/loaders/LoadingManager.js +329 -0
  594. package/src/loaders/MaterialLoader.js +439 -0
  595. package/src/loaders/ObjectLoader.js +1304 -0
  596. package/src/loaders/TextureLoader.js +74 -0
  597. package/src/loaders/nodes/NodeLoader.js +194 -0
  598. package/src/loaders/nodes/NodeMaterialLoader.js +108 -0
  599. package/src/loaders/nodes/NodeObjectLoader.js +169 -0
  600. package/src/materials/LineBasicMaterial.js +122 -0
  601. package/src/materials/LineDashedMaterial.js +86 -0
  602. package/src/materials/Material.js +1017 -0
  603. package/src/materials/Materials.js +39 -0
  604. package/src/materials/MeshBasicMaterial.js +250 -0
  605. package/src/materials/MeshDepthMaterial.js +148 -0
  606. package/src/materials/MeshDistanceMaterial.js +119 -0
  607. package/src/materials/MeshLambertMaterial.js +402 -0
  608. package/src/materials/MeshMatcapMaterial.js +245 -0
  609. package/src/materials/MeshNormalMaterial.js +175 -0
  610. package/src/materials/MeshPhongMaterial.js +421 -0
  611. package/src/materials/MeshPhysicalMaterial.js +536 -0
  612. package/src/materials/MeshStandardMaterial.js +425 -0
  613. package/src/materials/MeshToonMaterial.js +321 -0
  614. package/src/materials/PointsMaterial.js +139 -0
  615. package/src/materials/RawShaderMaterial.js +42 -0
  616. package/src/materials/ShaderMaterial.js +413 -0
  617. package/src/materials/ShadowMaterial.js +91 -0
  618. package/src/materials/SpriteMaterial.js +136 -0
  619. package/src/materials/nodes/Line2NodeMaterial.js +569 -0
  620. package/src/materials/nodes/LineBasicNodeMaterial.js +46 -0
  621. package/src/materials/nodes/LineDashedNodeMaterial.js +132 -0
  622. package/src/materials/nodes/MeshBasicNodeMaterial.js +134 -0
  623. package/src/materials/nodes/MeshLambertNodeMaterial.js +82 -0
  624. package/src/materials/nodes/MeshMatcapNodeMaterial.js +77 -0
  625. package/src/materials/nodes/MeshNormalNodeMaterial.js +67 -0
  626. package/src/materials/nodes/MeshPhongNodeMaterial.js +141 -0
  627. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +521 -0
  628. package/src/materials/nodes/MeshSSSNodeMaterial.js +175 -0
  629. package/src/materials/nodes/MeshStandardNodeMaterial.js +187 -0
  630. package/src/materials/nodes/MeshToonNodeMaterial.js +66 -0
  631. package/src/materials/nodes/NodeMaterial.js +1330 -0
  632. package/src/materials/nodes/NodeMaterials.js +21 -0
  633. package/src/materials/nodes/PointsNodeMaterial.js +211 -0
  634. package/src/materials/nodes/ShadowNodeMaterial.js +76 -0
  635. package/src/materials/nodes/SpriteNodeMaterial.js +186 -0
  636. package/src/materials/nodes/VolumeNodeMaterial.js +81 -0
  637. package/src/materials/nodes/manager/NodeMaterialObserver.js +718 -0
  638. package/src/math/Box2.js +381 -0
  639. package/src/math/Box3.js +805 -0
  640. package/src/math/Color.js +967 -0
  641. package/src/math/ColorManagement.js +215 -0
  642. package/src/math/Cylindrical.js +120 -0
  643. package/src/math/Euler.js +449 -0
  644. package/src/math/Frustum.js +285 -0
  645. package/src/math/FrustumArray.js +258 -0
  646. package/src/math/Interpolant.js +320 -0
  647. package/src/math/Line3.js +337 -0
  648. package/src/math/MathUtils.js +751 -0
  649. package/src/math/Matrix2.js +128 -0
  650. package/src/math/Matrix3.js +617 -0
  651. package/src/math/Matrix4.js +1314 -0
  652. package/src/math/Plane.js +368 -0
  653. package/src/math/Quaternion.js +918 -0
  654. package/src/math/Ray.js +655 -0
  655. package/src/math/Sphere.js +420 -0
  656. package/src/math/Spherical.js +147 -0
  657. package/src/math/SphericalHarmonics3.js +341 -0
  658. package/src/math/Triangle.js +539 -0
  659. package/src/math/Vector2.js +870 -0
  660. package/src/math/Vector3.js +1263 -0
  661. package/src/math/Vector4.js +1067 -0
  662. package/src/math/interpolants/BezierInterpolant.js +108 -0
  663. package/src/math/interpolants/CubicInterpolant.js +159 -0
  664. package/src/math/interpolants/DiscreteInterpolant.js +34 -0
  665. package/src/math/interpolants/LinearInterpolant.js +51 -0
  666. package/src/math/interpolants/QuaternionLinearInterpolant.js +48 -0
  667. package/src/nodes/Nodes.js +166 -0
  668. package/src/nodes/TSL.js +173 -0
  669. package/src/nodes/accessors/AccessorsUtils.js +53 -0
  670. package/src/nodes/accessors/Arrays.js +68 -0
  671. package/src/nodes/accessors/BatchNode.js +163 -0
  672. package/src/nodes/accessors/Bitangent.js +82 -0
  673. package/src/nodes/accessors/BufferAttributeNode.js +432 -0
  674. package/src/nodes/accessors/BufferNode.js +128 -0
  675. package/src/nodes/accessors/BuiltinNode.js +63 -0
  676. package/src/nodes/accessors/Camera.js +403 -0
  677. package/src/nodes/accessors/ClippingNode.js +255 -0
  678. package/src/nodes/accessors/CubeTextureNode.js +215 -0
  679. package/src/nodes/accessors/InstanceNode.js +349 -0
  680. package/src/nodes/accessors/InstancedMeshNode.js +50 -0
  681. package/src/nodes/accessors/Lights.js +139 -0
  682. package/src/nodes/accessors/MaterialNode.js +783 -0
  683. package/src/nodes/accessors/MaterialProperties.js +56 -0
  684. package/src/nodes/accessors/MaterialReferenceNode.js +84 -0
  685. package/src/nodes/accessors/ModelNode.js +184 -0
  686. package/src/nodes/accessors/ModelViewProjectionNode.js +13 -0
  687. package/src/nodes/accessors/MorphNode.js +310 -0
  688. package/src/nodes/accessors/Normal.js +243 -0
  689. package/src/nodes/accessors/Object3DNode.js +268 -0
  690. package/src/nodes/accessors/PointUVNode.js +55 -0
  691. package/src/nodes/accessors/Position.js +122 -0
  692. package/src/nodes/accessors/ReferenceBaseNode.js +357 -0
  693. package/src/nodes/accessors/ReferenceNode.js +424 -0
  694. package/src/nodes/accessors/ReflectVector.js +36 -0
  695. package/src/nodes/accessors/RendererReferenceNode.js +78 -0
  696. package/src/nodes/accessors/SceneProperties.js +47 -0
  697. package/src/nodes/accessors/SkinningNode.js +328 -0
  698. package/src/nodes/accessors/StorageBufferNode.js +405 -0
  699. package/src/nodes/accessors/StorageTextureNode.js +295 -0
  700. package/src/nodes/accessors/Tangent.js +60 -0
  701. package/src/nodes/accessors/TangentUtils.js +46 -0
  702. package/src/nodes/accessors/Texture3DNode.js +196 -0
  703. package/src/nodes/accessors/TextureBicubic.js +92 -0
  704. package/src/nodes/accessors/TextureNode.js +971 -0
  705. package/src/nodes/accessors/TextureSizeNode.js +77 -0
  706. package/src/nodes/accessors/UV.js +11 -0
  707. package/src/nodes/accessors/UniformArrayNode.js +350 -0
  708. package/src/nodes/accessors/UserDataNode.js +76 -0
  709. package/src/nodes/accessors/VelocityNode.js +224 -0
  710. package/src/nodes/accessors/VertexColorNode.js +109 -0
  711. package/src/nodes/code/CodeNode.js +181 -0
  712. package/src/nodes/code/ExpressionNode.js +68 -0
  713. package/src/nodes/code/FunctionCallNode.js +187 -0
  714. package/src/nodes/code/FunctionNode.js +182 -0
  715. package/src/nodes/core/ArrayNode.js +174 -0
  716. package/src/nodes/core/AssignNode.js +202 -0
  717. package/src/nodes/core/AttributeNode.js +168 -0
  718. package/src/nodes/core/BypassNode.js +93 -0
  719. package/src/nodes/core/ConstNode.js +67 -0
  720. package/src/nodes/core/ContextNode.js +283 -0
  721. package/src/nodes/core/IndexNode.js +165 -0
  722. package/src/nodes/core/InputNode.js +136 -0
  723. package/src/nodes/core/InspectorNode.js +128 -0
  724. package/src/nodes/core/IsolateNode.js +133 -0
  725. package/src/nodes/core/LightingModel.js +77 -0
  726. package/src/nodes/core/MRTNode.js +196 -0
  727. package/src/nodes/core/Node.js +1180 -0
  728. package/src/nodes/core/NodeAttribute.js +53 -0
  729. package/src/nodes/core/NodeBuilder.js +3299 -0
  730. package/src/nodes/core/NodeCache.js +75 -0
  731. package/src/nodes/core/NodeCode.js +46 -0
  732. package/src/nodes/core/NodeError.js +28 -0
  733. package/src/nodes/core/NodeFrame.js +314 -0
  734. package/src/nodes/core/NodeFunction.js +69 -0
  735. package/src/nodes/core/NodeFunctionInput.js +61 -0
  736. package/src/nodes/core/NodeParser.js +23 -0
  737. package/src/nodes/core/NodeUniform.js +91 -0
  738. package/src/nodes/core/NodeUtils.js +408 -0
  739. package/src/nodes/core/NodeVar.js +60 -0
  740. package/src/nodes/core/NodeVarying.js +63 -0
  741. package/src/nodes/core/OutputStructNode.js +105 -0
  742. package/src/nodes/core/ParameterNode.js +94 -0
  743. package/src/nodes/core/PropertyNode.js +367 -0
  744. package/src/nodes/core/StackNode.js +426 -0
  745. package/src/nodes/core/StackTrace.js +139 -0
  746. package/src/nodes/core/StructNode.js +134 -0
  747. package/src/nodes/core/StructType.js +13 -0
  748. package/src/nodes/core/StructTypeNode.js +148 -0
  749. package/src/nodes/core/SubBuildNode.js +89 -0
  750. package/src/nodes/core/TempNode.js +88 -0
  751. package/src/nodes/core/UniformGroupNode.js +167 -0
  752. package/src/nodes/core/UniformNode.js +259 -0
  753. package/src/nodes/core/VarNode.js +367 -0
  754. package/src/nodes/core/VaryingNode.js +210 -0
  755. package/src/nodes/core/constants.js +68 -0
  756. package/src/nodes/display/BlendModes.js +171 -0
  757. package/src/nodes/display/BumpMapNode.js +117 -0
  758. package/src/nodes/display/ColorAdjustment.js +158 -0
  759. package/src/nodes/display/ColorSpaceFunctions.js +54 -0
  760. package/src/nodes/display/ColorSpaceNode.js +164 -0
  761. package/src/nodes/display/FrontFacingNode.js +102 -0
  762. package/src/nodes/display/NormalMapNode.js +153 -0
  763. package/src/nodes/display/PassNode.js +1055 -0
  764. package/src/nodes/display/RenderOutputNode.js +150 -0
  765. package/src/nodes/display/ScreenNode.js +292 -0
  766. package/src/nodes/display/ToneMappingFunctions.js +242 -0
  767. package/src/nodes/display/ToneMappingNode.js +147 -0
  768. package/src/nodes/display/ToonOutlinePassNode.js +191 -0
  769. package/src/nodes/display/ViewportDepthNode.js +342 -0
  770. package/src/nodes/display/ViewportDepthTextureNode.js +63 -0
  771. package/src/nodes/display/ViewportSharedTextureNode.js +73 -0
  772. package/src/nodes/display/ViewportTextureNode.js +256 -0
  773. package/src/nodes/fog/Fog.js +97 -0
  774. package/src/nodes/functions/BSDF/BRDF_GGX.js +55 -0
  775. package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +52 -0
  776. package/src/nodes/functions/BSDF/BRDF_Lambert.js +9 -0
  777. package/src/nodes/functions/BSDF/BRDF_Sheen.js +57 -0
  778. package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
  779. package/src/nodes/functions/BSDF/D_GGX.js +23 -0
  780. package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +28 -0
  781. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +13 -0
  782. package/src/nodes/functions/BSDF/F_Schlick.js +16 -0
  783. package/src/nodes/functions/BSDF/LTC.js +175 -0
  784. package/src/nodes/functions/BSDF/Schlick_to_F0.js +21 -0
  785. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +26 -0
  786. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +29 -0
  787. package/src/nodes/functions/BasicLightingModel.js +100 -0
  788. package/src/nodes/functions/PhongLightingModel.js +99 -0
  789. package/src/nodes/functions/PhysicalLightingModel.js +878 -0
  790. package/src/nodes/functions/ShadowMaskModel.js +58 -0
  791. package/src/nodes/functions/ToonLightingModel.js +70 -0
  792. package/src/nodes/functions/VolumetricLightingModel.js +183 -0
  793. package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
  794. package/src/nodes/functions/material/getGeometryRoughness.js +19 -0
  795. package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
  796. package/src/nodes/functions/material/getRoughness.js +18 -0
  797. package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
  798. package/src/nodes/geometry/RangeNode.js +210 -0
  799. package/src/nodes/gpgpu/AtomicFunctionNode.js +274 -0
  800. package/src/nodes/gpgpu/BarrierNode.js +98 -0
  801. package/src/nodes/gpgpu/ComputeBuiltinNode.js +227 -0
  802. package/src/nodes/gpgpu/ComputeNode.js +310 -0
  803. package/src/nodes/gpgpu/SubgroupFunctionNode.js +455 -0
  804. package/src/nodes/gpgpu/WorkgroupInfoNode.js +234 -0
  805. package/src/nodes/lighting/AONode.js +45 -0
  806. package/src/nodes/lighting/AmbientLightNode.js +35 -0
  807. package/src/nodes/lighting/AnalyticLightNode.js +309 -0
  808. package/src/nodes/lighting/BasicEnvironmentNode.js +49 -0
  809. package/src/nodes/lighting/BasicLightMapNode.js +49 -0
  810. package/src/nodes/lighting/DirectionalLightNode.js +39 -0
  811. package/src/nodes/lighting/EnvironmentNode.js +178 -0
  812. package/src/nodes/lighting/HemisphereLightNode.js +87 -0
  813. package/src/nodes/lighting/IESSpotLightNode.js +49 -0
  814. package/src/nodes/lighting/IrradianceNode.js +44 -0
  815. package/src/nodes/lighting/LightProbeNode.js +73 -0
  816. package/src/nodes/lighting/LightUtils.js +25 -0
  817. package/src/nodes/lighting/LightingContextNode.js +115 -0
  818. package/src/nodes/lighting/LightingNode.js +36 -0
  819. package/src/nodes/lighting/LightsNode.js +432 -0
  820. package/src/nodes/lighting/PointLightNode.js +102 -0
  821. package/src/nodes/lighting/PointShadowNode.js +325 -0
  822. package/src/nodes/lighting/ProjectorLightNode.js +91 -0
  823. package/src/nodes/lighting/RectAreaLightNode.js +133 -0
  824. package/src/nodes/lighting/ShadowBaseNode.js +81 -0
  825. package/src/nodes/lighting/ShadowFilterNode.js +264 -0
  826. package/src/nodes/lighting/ShadowNode.js +889 -0
  827. package/src/nodes/lighting/SpotLightNode.js +168 -0
  828. package/src/nodes/materialx/DISCLAIMER.md +199 -0
  829. package/src/nodes/materialx/MaterialXNodes.js +197 -0
  830. package/src/nodes/materialx/lib/mx_hsv.js +127 -0
  831. package/src/nodes/materialx/lib/mx_noise.js +1491 -0
  832. package/src/nodes/materialx/lib/mx_transform_color.js +23 -0
  833. package/src/nodes/math/BitcastNode.js +156 -0
  834. package/src/nodes/math/BitcountNode.js +433 -0
  835. package/src/nodes/math/ConditionalNode.js +245 -0
  836. package/src/nodes/math/Hash.js +21 -0
  837. package/src/nodes/math/MathNode.js +1202 -0
  838. package/src/nodes/math/MathUtils.js +54 -0
  839. package/src/nodes/math/OperatorNode.js +752 -0
  840. package/src/nodes/math/PackFloatNode.js +98 -0
  841. package/src/nodes/math/TriNoise3D.js +71 -0
  842. package/src/nodes/math/UnpackFloatNode.js +96 -0
  843. package/src/nodes/parsers/GLSLNodeFunction.js +168 -0
  844. package/src/nodes/parsers/GLSLNodeParser.js +25 -0
  845. package/src/nodes/pmrem/PMREMNode.js +397 -0
  846. package/src/nodes/pmrem/PMREMUtils.js +397 -0
  847. package/src/nodes/procedural/Checker.js +22 -0
  848. package/src/nodes/shapes/Shapes.js +33 -0
  849. package/src/nodes/tsl/TSLBase.js +36 -0
  850. package/src/nodes/tsl/TSLCore.js +1250 -0
  851. package/src/nodes/utils/ArrayElementNode.js +90 -0
  852. package/src/nodes/utils/ConvertNode.js +100 -0
  853. package/src/nodes/utils/CubeMapNode.js +237 -0
  854. package/src/nodes/utils/DebugNode.js +83 -0
  855. package/src/nodes/utils/Discard.js +24 -0
  856. package/src/nodes/utils/EquirectUV.js +27 -0
  857. package/src/nodes/utils/EventNode.js +148 -0
  858. package/src/nodes/utils/FlipNode.js +106 -0
  859. package/src/nodes/utils/FunctionOverloadingNode.js +170 -0
  860. package/src/nodes/utils/JoinNode.js +117 -0
  861. package/src/nodes/utils/LoopNode.js +349 -0
  862. package/src/nodes/utils/MatcapUV.js +22 -0
  863. package/src/nodes/utils/MaxMipLevelNode.js +103 -0
  864. package/src/nodes/utils/MemberNode.js +120 -0
  865. package/src/nodes/utils/Oscillators.js +41 -0
  866. package/src/nodes/utils/Packing.js +33 -0
  867. package/src/nodes/utils/PostProcessingUtils.js +154 -0
  868. package/src/nodes/utils/RTTNode.js +289 -0
  869. package/src/nodes/utils/ReflectorNode.js +629 -0
  870. package/src/nodes/utils/Remap.js +48 -0
  871. package/src/nodes/utils/RotateNode.js +103 -0
  872. package/src/nodes/utils/SampleNode.js +91 -0
  873. package/src/nodes/utils/SetNode.js +108 -0
  874. package/src/nodes/utils/SplitNode.js +179 -0
  875. package/src/nodes/utils/SpriteSheetUV.js +35 -0
  876. package/src/nodes/utils/SpriteUtils.js +63 -0
  877. package/src/nodes/utils/StorageArrayElementNode.js +143 -0
  878. package/src/nodes/utils/Timer.js +26 -0
  879. package/src/nodes/utils/TriplanarTextures.js +65 -0
  880. package/src/nodes/utils/UVUtils.js +67 -0
  881. package/src/nodes/utils/ViewportUtils.js +26 -0
  882. package/src/objects/BatchedMesh.js +1682 -0
  883. package/src/objects/Bone.js +41 -0
  884. package/src/objects/ClippingGroup.js +68 -0
  885. package/src/objects/Group.js +41 -0
  886. package/src/objects/InstancedMesh.js +422 -0
  887. package/src/objects/LOD.js +329 -0
  888. package/src/objects/Line.js +329 -0
  889. package/src/objects/LineLoop.js +37 -0
  890. package/src/objects/LineSegments.js +74 -0
  891. package/src/objects/Mesh.js +496 -0
  892. package/src/objects/Points.js +228 -0
  893. package/src/objects/Skeleton.js +392 -0
  894. package/src/objects/SkinnedMesh.js +370 -0
  895. package/src/objects/Sprite.js +245 -0
  896. package/src/renderers/WebGL3DRenderTarget.js +48 -0
  897. package/src/renderers/WebGLArrayRenderTarget.js +48 -0
  898. package/src/renderers/WebGLCubeRenderTarget.js +182 -0
  899. package/src/renderers/WebGLRenderTarget.js +34 -0
  900. package/src/renderers/WebGLRenderer.js +3699 -0
  901. package/src/renderers/common/Animation.js +159 -0
  902. package/src/renderers/common/Attributes.js +132 -0
  903. package/src/renderers/common/Backend.js +769 -0
  904. package/src/renderers/common/Background.js +225 -0
  905. package/src/renderers/common/BindGroup.js +46 -0
  906. package/src/renderers/common/Binding.js +71 -0
  907. package/src/renderers/common/Bindings.js +394 -0
  908. package/src/renderers/common/BlendMode.js +143 -0
  909. package/src/renderers/common/Buffer.js +127 -0
  910. package/src/renderers/common/BufferUtils.js +58 -0
  911. package/src/renderers/common/BundleGroup.js +83 -0
  912. package/src/renderers/common/CanvasTarget.js +341 -0
  913. package/src/renderers/common/ChainMap.js +122 -0
  914. package/src/renderers/common/ClippingContext.js +262 -0
  915. package/src/renderers/common/Color4.js +77 -0
  916. package/src/renderers/common/ComputePipeline.js +41 -0
  917. package/src/renderers/common/Constants.js +15 -0
  918. package/src/renderers/common/CubeRenderTarget.js +147 -0
  919. package/src/renderers/common/DataMap.js +90 -0
  920. package/src/renderers/common/Geometries.js +396 -0
  921. package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
  922. package/src/renderers/common/Info.js +501 -0
  923. package/src/renderers/common/InspectorBase.js +151 -0
  924. package/src/renderers/common/Lighting.js +57 -0
  925. package/src/renderers/common/Pipeline.js +35 -0
  926. package/src/renderers/common/Pipelines.js +498 -0
  927. package/src/renderers/common/PostProcessing.js +28 -0
  928. package/src/renderers/common/ProgrammableStage.js +78 -0
  929. package/src/renderers/common/QuadMesh.js +112 -0
  930. package/src/renderers/common/ReadbackBuffer.js +78 -0
  931. package/src/renderers/common/RenderBundle.js +26 -0
  932. package/src/renderers/common/RenderBundles.js +71 -0
  933. package/src/renderers/common/RenderContext.js +281 -0
  934. package/src/renderers/common/RenderContexts.js +100 -0
  935. package/src/renderers/common/RenderList.js +404 -0
  936. package/src/renderers/common/RenderLists.js +78 -0
  937. package/src/renderers/common/RenderObject.js +915 -0
  938. package/src/renderers/common/RenderObjectPipeline.js +40 -0
  939. package/src/renderers/common/RenderObjects.js +218 -0
  940. package/src/renderers/common/RenderPipeline.js +255 -0
  941. package/src/renderers/common/Renderer.js +3654 -0
  942. package/src/renderers/common/RendererUtils.js +200 -0
  943. package/src/renderers/common/SampledTexture.js +152 -0
  944. package/src/renderers/common/Sampler.js +165 -0
  945. package/src/renderers/common/Storage3DTexture.js +100 -0
  946. package/src/renderers/common/StorageArrayTexture.js +84 -0
  947. package/src/renderers/common/StorageBuffer.js +53 -0
  948. package/src/renderers/common/StorageBufferAttribute.js +46 -0
  949. package/src/renderers/common/StorageInstancedBufferAttribute.js +46 -0
  950. package/src/renderers/common/StorageTexture.js +86 -0
  951. package/src/renderers/common/Textures.js +629 -0
  952. package/src/renderers/common/TimestampQueryPool.js +163 -0
  953. package/src/renderers/common/Uniform.js +375 -0
  954. package/src/renderers/common/UniformBuffer.js +34 -0
  955. package/src/renderers/common/UniformsGroup.js +548 -0
  956. package/src/renderers/common/XRManager.js +1684 -0
  957. package/src/renderers/common/XRRenderTarget.js +91 -0
  958. package/src/renderers/common/extras/PMREMGenerator.js +1042 -0
  959. package/src/renderers/common/nodes/NodeBuilderState.js +152 -0
  960. package/src/renderers/common/nodes/NodeLibrary.js +196 -0
  961. package/src/renderers/common/nodes/NodeManager.js +983 -0
  962. package/src/renderers/common/nodes/NodeSampledTexture.js +140 -0
  963. package/src/renderers/common/nodes/NodeSampler.js +62 -0
  964. package/src/renderers/common/nodes/NodeStorageBuffer.js +72 -0
  965. package/src/renderers/common/nodes/NodeUniform.js +418 -0
  966. package/src/renderers/common/nodes/NodeUniformBuffer.js +105 -0
  967. package/src/renderers/common/nodes/NodeUniformsGroup.js +51 -0
  968. package/src/renderers/shaders/DFGLUTData.js +49 -0
  969. package/src/renderers/shaders/ShaderChunk/alphahash_fragment.glsl.js +7 -0
  970. package/src/renderers/shaders/ShaderChunk/alphahash_pars_fragment.glsl.js +68 -0
  971. package/src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl.js +7 -0
  972. package/src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl.js +7 -0
  973. package/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js +16 -0
  974. package/src/renderers/shaders/ShaderChunk/alphatest_pars_fragment.glsl.js +5 -0
  975. package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +26 -0
  976. package/src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl.js +8 -0
  977. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +49 -0
  978. package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +5 -0
  979. package/src/renderers/shaders/ShaderChunk/begin_vertex.glsl.js +9 -0
  980. package/src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl.js +9 -0
  981. package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +33 -0
  982. package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +43 -0
  983. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_begin.glsl.js +7 -0
  984. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js +10 -0
  985. package/src/renderers/shaders/ShaderChunk/clearcoat_pars_fragment.glsl.js +21 -0
  986. package/src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl.js +78 -0
  987. package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_fragment.glsl.js +9 -0
  988. package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_vertex.glsl.js +7 -0
  989. package/src/renderers/shaders/ShaderChunk/clipping_planes_vertex.glsl.js +7 -0
  990. package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +7 -0
  991. package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +7 -0
  992. package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +7 -0
  993. package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +29 -0
  994. package/src/renderers/shaders/ShaderChunk/colorspace_fragment.glsl.js +3 -0
  995. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +15 -0
  996. package/src/renderers/shaders/ShaderChunk/common.glsl.js +125 -0
  997. package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +186 -0
  998. package/src/renderers/shaders/ShaderChunk/default_fragment.glsl.js +5 -0
  999. package/src/renderers/shaders/ShaderChunk/default_vertex.glsl.js +5 -0
  1000. package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +63 -0
  1001. package/src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl.js +9 -0
  1002. package/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl.js +7 -0
  1003. package/src/renderers/shaders/ShaderChunk/dithering_fragment.glsl.js +7 -0
  1004. package/src/renderers/shaders/ShaderChunk/dithering_pars_fragment.glsl.js +20 -0
  1005. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +17 -0
  1006. package/src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl.js +7 -0
  1007. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +14 -0
  1008. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +58 -0
  1009. package/src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl.js +21 -0
  1010. package/src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl.js +22 -0
  1011. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +69 -0
  1012. package/src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js +37 -0
  1013. package/src/renderers/shaders/ShaderChunk/fog_fragment.glsl.js +17 -0
  1014. package/src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl.js +19 -0
  1015. package/src/renderers/shaders/ShaderChunk/fog_pars_vertex.glsl.js +7 -0
  1016. package/src/renderers/shaders/ShaderChunk/fog_vertex.glsl.js +7 -0
  1017. package/src/renderers/shaders/ShaderChunk/gradientmap_pars_fragment.glsl.js +27 -0
  1018. package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +120 -0
  1019. package/src/renderers/shaders/ShaderChunk/iridescence_pars_fragment.glsl.js +14 -0
  1020. package/src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl.js +8 -0
  1021. package/src/renderers/shaders/ShaderChunk/lightprobes_pars_fragment.glsl.js +80 -0
  1022. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +213 -0
  1023. package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +19 -0
  1024. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +44 -0
  1025. package/src/renderers/shaders/ShaderChunk/lights_lambert_fragment.glsl.js +5 -0
  1026. package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +28 -0
  1027. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +216 -0
  1028. package/src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl.js +7 -0
  1029. package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +32 -0
  1030. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +161 -0
  1031. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +656 -0
  1032. package/src/renderers/shaders/ShaderChunk/lights_toon_fragment.glsl.js +4 -0
  1033. package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +26 -0
  1034. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +9 -0
  1035. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +9 -0
  1036. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +8 -0
  1037. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +8 -0
  1038. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +17 -0
  1039. package/src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl.js +7 -0
  1040. package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +27 -0
  1041. package/src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl.js +27 -0
  1042. package/src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl.js +12 -0
  1043. package/src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl.js +7 -0
  1044. package/src/renderers/shaders/ShaderChunk/morphcolor_vertex.glsl.js +24 -0
  1045. package/src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js +14 -0
  1046. package/src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl.js +16 -0
  1047. package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +26 -0
  1048. package/src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl.js +16 -0
  1049. package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +76 -0
  1050. package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +40 -0
  1051. package/src/renderers/shaders/ShaderChunk/normal_pars_fragment.glsl.js +14 -0
  1052. package/src/renderers/shaders/ShaderChunk/normal_pars_vertex.glsl.js +14 -0
  1053. package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +14 -0
  1054. package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +43 -0
  1055. package/src/renderers/shaders/ShaderChunk/opaque_fragment.glsl.js +11 -0
  1056. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +116 -0
  1057. package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +7 -0
  1058. package/src/renderers/shaders/ShaderChunk/project_vertex.glsl.js +19 -0
  1059. package/src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl.js +12 -0
  1060. package/src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl.js +7 -0
  1061. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +376 -0
  1062. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +71 -0
  1063. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +78 -0
  1064. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +66 -0
  1065. package/src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl.js +10 -0
  1066. package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +25 -0
  1067. package/src/renderers/shaders/ShaderChunk/skinning_vertex.glsl.js +15 -0
  1068. package/src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl.js +20 -0
  1069. package/src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl.js +14 -0
  1070. package/src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl.js +7 -0
  1071. package/src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl.js +7 -0
  1072. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +200 -0
  1073. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +36 -0
  1074. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +235 -0
  1075. package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +119 -0
  1076. package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +145 -0
  1077. package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +122 -0
  1078. package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +21 -0
  1079. package/src/renderers/shaders/ShaderChunk.js +272 -0
  1080. package/src/renderers/shaders/ShaderLib/background.glsl.js +40 -0
  1081. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +62 -0
  1082. package/src/renderers/shaders/ShaderLib/cube.glsl.js +36 -0
  1083. package/src/renderers/shaders/ShaderLib/depth.glsl.js +117 -0
  1084. package/src/renderers/shaders/ShaderLib/distance.glsl.js +77 -0
  1085. package/src/renderers/shaders/ShaderLib/equirect.glsl.js +35 -0
  1086. package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +76 -0
  1087. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +116 -0
  1088. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +126 -0
  1089. package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +112 -0
  1090. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +86 -0
  1091. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +128 -0
  1092. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +224 -0
  1093. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +118 -0
  1094. package/src/renderers/shaders/ShaderLib/points.glsl.js +87 -0
  1095. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +58 -0
  1096. package/src/renderers/shaders/ShaderLib/sprite.glsl.js +79 -0
  1097. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +51 -0
  1098. package/src/renderers/shaders/ShaderLib.js +362 -0
  1099. package/src/renderers/shaders/UniformsLib.js +234 -0
  1100. package/src/renderers/shaders/UniformsUtils.js +154 -0
  1101. package/src/renderers/webgl/WebGLAnimation.js +54 -0
  1102. package/src/renderers/webgl/WebGLAttributes.js +237 -0
  1103. package/src/renderers/webgl/WebGLBackground.js +303 -0
  1104. package/src/renderers/webgl/WebGLBindingStates.js +666 -0
  1105. package/src/renderers/webgl/WebGLBufferRenderer.js +57 -0
  1106. package/src/renderers/webgl/WebGLCapabilities.js +150 -0
  1107. package/src/renderers/webgl/WebGLClipping.js +171 -0
  1108. package/src/renderers/webgl/WebGLEnvironments.js +228 -0
  1109. package/src/renderers/webgl/WebGLExtensions.js +61 -0
  1110. package/src/renderers/webgl/WebGLGeometries.js +186 -0
  1111. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +68 -0
  1112. package/src/renderers/webgl/WebGLInfo.js +73 -0
  1113. package/src/renderers/webgl/WebGLLights.js +584 -0
  1114. package/src/renderers/webgl/WebGLMaterials.js +602 -0
  1115. package/src/renderers/webgl/WebGLMorphtargets.js +168 -0
  1116. package/src/renderers/webgl/WebGLObjects.js +94 -0
  1117. package/src/renderers/webgl/WebGLOutput.js +270 -0
  1118. package/src/renderers/webgl/WebGLProgram.js +1031 -0
  1119. package/src/renderers/webgl/WebGLPrograms.js +679 -0
  1120. package/src/renderers/webgl/WebGLProperties.js +55 -0
  1121. package/src/renderers/webgl/WebGLRenderLists.js +253 -0
  1122. package/src/renderers/webgl/WebGLRenderStates.js +124 -0
  1123. package/src/renderers/webgl/WebGLShader.js +12 -0
  1124. package/src/renderers/webgl/WebGLShaderCache.js +124 -0
  1125. package/src/renderers/webgl/WebGLShadowMap.js +600 -0
  1126. package/src/renderers/webgl/WebGLState.js +1370 -0
  1127. package/src/renderers/webgl/WebGLTextures.js +2506 -0
  1128. package/src/renderers/webgl/WebGLUniforms.js +1203 -0
  1129. package/src/renderers/webgl/WebGLUniformsGroups.js +413 -0
  1130. package/src/renderers/webgl/WebGLUtils.js +217 -0
  1131. package/src/renderers/webgl-fallback/WebGLBackend.js +2783 -0
  1132. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +99 -0
  1133. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +1676 -0
  1134. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +359 -0
  1135. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +89 -0
  1136. package/src/renderers/webgl-fallback/utils/WebGLConstants.js +13 -0
  1137. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +83 -0
  1138. package/src/renderers/webgl-fallback/utils/WebGLState.js +1361 -0
  1139. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +1324 -0
  1140. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +396 -0
  1141. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +317 -0
  1142. package/src/renderers/webgpu/WebGPUBackend.js +2602 -0
  1143. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +69 -0
  1144. package/src/renderers/webgpu/WebGPURenderer.js +107 -0
  1145. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +66 -0
  1146. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +100 -0
  1147. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +2523 -0
  1148. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +187 -0
  1149. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +25 -0
  1150. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +522 -0
  1151. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +642 -0
  1152. package/src/renderers/webgpu/utils/WebGPUCapabilities.js +48 -0
  1153. package/src/renderers/webgpu/utils/WebGPUConstants.js +354 -0
  1154. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +846 -0
  1155. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +389 -0
  1156. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +1673 -0
  1157. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +310 -0
  1158. package/src/renderers/webgpu/utils/WebGPUUtils.js +269 -0
  1159. package/src/renderers/webxr/WebXRController.js +440 -0
  1160. package/src/renderers/webxr/WebXRDepthSensing.js +155 -0
  1161. package/src/renderers/webxr/WebXRManager.js +1103 -0
  1162. package/src/scenes/Fog.js +98 -0
  1163. package/src/scenes/FogExp2.js +86 -0
  1164. package/src/scenes/Scene.js +165 -0
  1165. package/src/textures/CanvasTexture.js +45 -0
  1166. package/src/textures/CompressedArrayTexture.js +89 -0
  1167. package/src/textures/CompressedCubeTexture.js +48 -0
  1168. package/src/textures/CompressedTexture.js +86 -0
  1169. package/src/textures/CubeDepthTexture.js +76 -0
  1170. package/src/textures/CubeTexture.js +81 -0
  1171. package/src/textures/Data3DTexture.js +112 -0
  1172. package/src/textures/DataArrayTexture.js +134 -0
  1173. package/src/textures/DataTexture.js +87 -0
  1174. package/src/textures/DepthTexture.js +104 -0
  1175. package/src/textures/ExternalTexture.js +56 -0
  1176. package/src/textures/FramebufferTexture.js +85 -0
  1177. package/src/textures/HTMLTexture.js +74 -0
  1178. package/src/textures/Source.js +230 -0
  1179. package/src/textures/Texture.js +812 -0
  1180. package/src/textures/VideoFrameTexture.js +72 -0
  1181. package/src/textures/VideoTexture.js +127 -0
  1182. package/src/utils.js +493 -0
@@ -0,0 +1,4580 @@
1
+ import {
2
+ AmbientLight,
3
+ AnimationClip,
4
+ Bone,
5
+ BufferGeometry,
6
+ ClampToEdgeWrapping,
7
+ Color,
8
+ ColorManagement,
9
+ DirectionalLight,
10
+ EquirectangularReflectionMapping,
11
+ Euler,
12
+ FileLoader,
13
+ Float32BufferAttribute,
14
+ Group,
15
+ Line,
16
+ LineBasicMaterial,
17
+ Loader,
18
+ LoaderUtils,
19
+ MathUtils,
20
+ Matrix3,
21
+ Matrix4,
22
+ Mesh,
23
+ MeshLambertMaterial,
24
+ MeshPhongMaterial,
25
+ NumberKeyframeTrack,
26
+ Object3D,
27
+ PerspectiveCamera,
28
+ PointLight,
29
+ PropertyBinding,
30
+ Quaternion,
31
+ QuaternionKeyframeTrack,
32
+ RepeatWrapping,
33
+ SRGBColorSpace,
34
+ ShapeUtils,
35
+ Skeleton,
36
+ SkinnedMesh,
37
+ SpotLight,
38
+ Texture,
39
+ TextureLoader,
40
+ Uint16BufferAttribute,
41
+ Vector2,
42
+ Vector3,
43
+ Vector4,
44
+ VectorKeyframeTrack
45
+ } from 'three';
46
+
47
+ import { unzlibSync } from '../libs/fflate.module.js';
48
+ import { NURBSCurve } from '../curves/NURBSCurve.js';
49
+
50
+ let fbxTree;
51
+ let connections;
52
+ let sceneGraph;
53
+
54
+ /**
55
+ * A loader for the FBX format.
56
+ *
57
+ * Requires FBX file to be >= 7.0 and in ASCII or >= 6400 in Binary format.
58
+ * Versions lower than this may load but will probably have errors.
59
+ *
60
+ * Needs Support:
61
+ * - Morph normals / blend shape normals
62
+ *
63
+ * FBX format references:
64
+ * - [C++ SDK reference](https://help.autodesk.com/view/FBX/2017/ENU/?guid=__cpp_ref_index_html)
65
+ *
66
+ * Binary format specification:
67
+ * - [FBX binary file format specification](https://code.blender.org/2013/08/fbx-binary-file-format-specification/)
68
+ *
69
+ * ```js
70
+ * const loader = new FBXLoader();
71
+ * const object = await loader.loadAsync( 'models/fbx/stanford-bunny.fbx' );
72
+ * scene.add( object );
73
+ * ```
74
+ *
75
+ * @augments Loader
76
+ * @three_import import { FBXLoader } from 'three/addons/loaders/FBXLoader.js';
77
+ */
78
+ class FBXLoader extends Loader {
79
+
80
+ /**
81
+ * Constructs a new FBX loader.
82
+ *
83
+ * @param {LoadingManager} [manager] - The loading manager.
84
+ */
85
+ constructor( manager ) {
86
+
87
+ super( manager );
88
+
89
+ }
90
+
91
+ /**
92
+ * Starts loading from the given URL and passes the loaded FBX asset
93
+ * to the `onLoad()` callback.
94
+ *
95
+ * @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
96
+ * @param {function(Group)} onLoad - Executed when the loading process has been finished.
97
+ * @param {onProgressCallback} onProgress - Executed while the loading is in progress.
98
+ * @param {onErrorCallback} onError - Executed when errors occur.
99
+ */
100
+ load( url, onLoad, onProgress, onError ) {
101
+
102
+ const scope = this;
103
+
104
+ const path = ( scope.path === '' ) ? LoaderUtils.extractUrlBase( url ) : scope.path;
105
+
106
+ const loader = new FileLoader( this.manager );
107
+ loader.setPath( scope.path );
108
+ loader.setResponseType( 'arraybuffer' );
109
+ loader.setRequestHeader( scope.requestHeader );
110
+ loader.setWithCredentials( scope.withCredentials );
111
+
112
+ loader.load( url, function ( buffer ) {
113
+
114
+ try {
115
+
116
+ onLoad( scope.parse( buffer, path ) );
117
+
118
+ } catch ( e ) {
119
+
120
+ if ( onError ) {
121
+
122
+ onError( e );
123
+
124
+ } else {
125
+
126
+ console.error( e );
127
+
128
+ }
129
+
130
+ scope.manager.itemError( url );
131
+
132
+ }
133
+
134
+ }, onProgress, onError );
135
+
136
+ }
137
+
138
+ /**
139
+ * Parses the given FBX data and returns the resulting group.
140
+ *
141
+ * @param {ArrayBuffer} FBXBuffer - The raw FBX data as an array buffer.
142
+ * @param {string} path - The URL base path.
143
+ * @return {Group} An object representing the parsed asset.
144
+ */
145
+ parse( FBXBuffer, path ) {
146
+
147
+ if ( isFbxFormatBinary( FBXBuffer ) ) {
148
+
149
+ fbxTree = new BinaryParser().parse( FBXBuffer );
150
+
151
+ } else {
152
+
153
+ const FBXText = convertArrayBufferToString( FBXBuffer );
154
+
155
+ if ( ! isFbxFormatASCII( FBXText ) ) {
156
+
157
+ throw new Error( 'THREE.FBXLoader: Unknown format.' );
158
+
159
+ }
160
+
161
+ if ( getFbxVersion( FBXText ) < 7000 ) {
162
+
163
+ throw new Error( 'THREE.FBXLoader: FBX version not supported, FileVersion: ' + getFbxVersion( FBXText ) );
164
+
165
+ }
166
+
167
+ fbxTree = new TextParser().parse( FBXText );
168
+
169
+ }
170
+
171
+ // console.log( fbxTree );
172
+
173
+ const textureLoader = new TextureLoader( this.manager ).setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
174
+
175
+ return new FBXTreeParser( textureLoader, this.manager ).parse( fbxTree );
176
+
177
+ }
178
+
179
+ }
180
+
181
+ // Parse the FBXTree object returned by the BinaryParser or TextParser and return a Group
182
+ class FBXTreeParser {
183
+
184
+ constructor( textureLoader, manager ) {
185
+
186
+ this.textureLoader = textureLoader;
187
+ this.manager = manager;
188
+
189
+ }
190
+
191
+ parse() {
192
+
193
+ connections = this.parseConnections();
194
+
195
+ const images = this.parseImages();
196
+ const textures = this.parseTextures( images );
197
+ const materials = this.parseMaterials( textures );
198
+ const deformers = this.parseDeformers();
199
+ const geometryMap = new GeometryParser().parse( deformers );
200
+
201
+ this.parseScene( deformers, geometryMap, materials );
202
+
203
+ return sceneGraph;
204
+
205
+ }
206
+
207
+ // Parses FBXTree.Connections which holds parent-child connections between objects (e.g. material -> texture, model->geometry )
208
+ // and details the connection type
209
+ parseConnections() {
210
+
211
+ const connectionMap = new Map();
212
+
213
+ if ( 'Connections' in fbxTree ) {
214
+
215
+ const rawConnections = fbxTree.Connections.connections;
216
+
217
+ rawConnections.forEach( function ( rawConnection ) {
218
+
219
+ const fromID = rawConnection[ 0 ];
220
+ const toID = rawConnection[ 1 ];
221
+ const relationship = rawConnection[ 2 ];
222
+
223
+ if ( ! connectionMap.has( fromID ) ) {
224
+
225
+ connectionMap.set( fromID, {
226
+ parents: [],
227
+ children: []
228
+ } );
229
+
230
+ }
231
+
232
+ const parentRelationship = { ID: toID, relationship: relationship };
233
+ connectionMap.get( fromID ).parents.push( parentRelationship );
234
+
235
+ if ( ! connectionMap.has( toID ) ) {
236
+
237
+ connectionMap.set( toID, {
238
+ parents: [],
239
+ children: []
240
+ } );
241
+
242
+ }
243
+
244
+ const childRelationship = { ID: fromID, relationship: relationship };
245
+ connectionMap.get( toID ).children.push( childRelationship );
246
+
247
+ } );
248
+
249
+ }
250
+
251
+ return connectionMap;
252
+
253
+ }
254
+
255
+ // Parse FBXTree.Objects.Video for embedded image data
256
+ // These images are connected to textures in FBXTree.Objects.Textures
257
+ // via FBXTree.Connections.
258
+ parseImages() {
259
+
260
+ const images = {};
261
+ const blobs = {};
262
+
263
+ if ( 'Video' in fbxTree.Objects ) {
264
+
265
+ const videoNodes = fbxTree.Objects.Video;
266
+
267
+ for ( const nodeID in videoNodes ) {
268
+
269
+ const videoNode = videoNodes[ nodeID ];
270
+
271
+ const id = parseInt( nodeID );
272
+
273
+ images[ id ] = videoNode.RelativeFilename || videoNode.Filename;
274
+
275
+ // raw image data is in videoNode.Content
276
+ if ( 'Content' in videoNode ) {
277
+
278
+ const arrayBufferContent = ( videoNode.Content instanceof ArrayBuffer ) && ( videoNode.Content.byteLength > 0 );
279
+ const base64Content = ( typeof videoNode.Content === 'string' ) && ( videoNode.Content !== '' );
280
+
281
+ if ( arrayBufferContent || base64Content ) {
282
+
283
+ const image = this.parseImage( videoNodes[ nodeID ] );
284
+
285
+ blobs[ videoNode.RelativeFilename || videoNode.Filename ] = image;
286
+
287
+ }
288
+
289
+ }
290
+
291
+ }
292
+
293
+ }
294
+
295
+ for ( const id in images ) {
296
+
297
+ const filename = images[ id ];
298
+
299
+ if ( blobs[ filename ] !== undefined ) images[ id ] = blobs[ filename ];
300
+ else images[ id ] = images[ id ].split( '\\' ).pop();
301
+
302
+ }
303
+
304
+ return images;
305
+
306
+ }
307
+
308
+ // Parse embedded image data in FBXTree.Video.Content
309
+ parseImage( videoNode ) {
310
+
311
+ const content = videoNode.Content;
312
+ const fileName = videoNode.RelativeFilename || videoNode.Filename;
313
+ const extension = fileName.slice( fileName.lastIndexOf( '.' ) + 1 ).toLowerCase();
314
+
315
+ let type;
316
+
317
+ switch ( extension ) {
318
+
319
+ case 'bmp':
320
+
321
+ type = 'image/bmp';
322
+ break;
323
+
324
+ case 'jpg':
325
+ case 'jpeg':
326
+
327
+ type = 'image/jpeg';
328
+ break;
329
+
330
+ case 'png':
331
+
332
+ type = 'image/png';
333
+ break;
334
+
335
+ case 'tif':
336
+
337
+ type = 'image/tiff';
338
+ break;
339
+
340
+ case 'tga':
341
+
342
+ if ( this.manager.getHandler( '.tga' ) === null ) {
343
+
344
+ console.warn( 'FBXLoader: TGA loader not found, skipping ', fileName );
345
+
346
+ }
347
+
348
+ type = 'image/tga';
349
+ break;
350
+
351
+ case 'webp':
352
+
353
+ type = 'image/webp';
354
+ break;
355
+
356
+ default:
357
+
358
+ console.warn( 'FBXLoader: Image type "' + extension + '" is not supported.' );
359
+ return;
360
+
361
+ }
362
+
363
+ if ( typeof content === 'string' ) { // ASCII format
364
+
365
+ return 'data:' + type + ';base64,' + content;
366
+
367
+ } else { // Binary Format
368
+
369
+ const array = new Uint8Array( content );
370
+ return window.URL.createObjectURL( new Blob( [ array ], { type: type } ) );
371
+
372
+ }
373
+
374
+ }
375
+
376
+ // Parse nodes in FBXTree.Objects.Texture
377
+ // These contain details such as UV scaling, cropping, rotation etc and are connected
378
+ // to images in FBXTree.Objects.Video
379
+ parseTextures( images ) {
380
+
381
+ const textureMap = new Map();
382
+
383
+ if ( 'Texture' in fbxTree.Objects ) {
384
+
385
+ const textureNodes = fbxTree.Objects.Texture;
386
+ for ( const nodeID in textureNodes ) {
387
+
388
+ const texture = this.parseTexture( textureNodes[ nodeID ], images );
389
+ textureMap.set( parseInt( nodeID ), texture );
390
+
391
+ }
392
+
393
+ }
394
+
395
+ return textureMap;
396
+
397
+ }
398
+
399
+ // Parse individual node in FBXTree.Objects.Texture
400
+ parseTexture( textureNode, images ) {
401
+
402
+ const texture = this.loadTexture( textureNode, images );
403
+
404
+ texture.ID = textureNode.id;
405
+
406
+ texture.name = textureNode.attrName;
407
+
408
+ const wrapModeU = textureNode.WrapModeU;
409
+ const wrapModeV = textureNode.WrapModeV;
410
+
411
+ const valueU = wrapModeU !== undefined ? wrapModeU.value : 0;
412
+ const valueV = wrapModeV !== undefined ? wrapModeV.value : 0;
413
+
414
+ // http://download.autodesk.com/us/fbx/SDKdocs/FBX_SDK_Help/files/fbxsdkref/class_k_fbx_texture.html#889640e63e2e681259ea81061b85143a
415
+ // 0: repeat(default), 1: clamp
416
+
417
+ texture.wrapS = valueU === 0 ? RepeatWrapping : ClampToEdgeWrapping;
418
+ texture.wrapT = valueV === 0 ? RepeatWrapping : ClampToEdgeWrapping;
419
+
420
+ if ( 'Scaling' in textureNode ) {
421
+
422
+ const values = textureNode.Scaling.value;
423
+
424
+ texture.repeat.x = values[ 0 ];
425
+ texture.repeat.y = values[ 1 ];
426
+
427
+ }
428
+
429
+ if ( 'Translation' in textureNode ) {
430
+
431
+ const values = textureNode.Translation.value;
432
+
433
+ texture.offset.x = values[ 0 ];
434
+ texture.offset.y = values[ 1 ];
435
+
436
+ }
437
+
438
+ return texture;
439
+
440
+ }
441
+
442
+ // load a texture specified as a blob or data URI, or via an external URL using TextureLoader
443
+ loadTexture( textureNode, images ) {
444
+
445
+ const extension = textureNode.FileName.split( '.' ).pop().toLowerCase();
446
+
447
+ let loader = this.manager.getHandler( `.${extension}` );
448
+ if ( loader === null ) loader = this.textureLoader;
449
+
450
+ const loaderPath = loader.path;
451
+
452
+ if ( ! loaderPath ) {
453
+
454
+ loader.setPath( this.textureLoader.path );
455
+
456
+ }
457
+
458
+ const children = connections.get( textureNode.id ).children;
459
+
460
+ let fileName;
461
+
462
+ if ( children !== undefined && children.length > 0 && images[ children[ 0 ].ID ] !== undefined ) {
463
+
464
+ fileName = images[ children[ 0 ].ID ];
465
+
466
+ if ( fileName.indexOf( 'blob:' ) === 0 || fileName.indexOf( 'data:' ) === 0 ) {
467
+
468
+ loader.setPath( undefined );
469
+
470
+ }
471
+
472
+ }
473
+
474
+ if ( fileName === undefined ) {
475
+
476
+ console.warn( 'FBXLoader: Undefined filename, creating placeholder texture.' );
477
+ return new Texture();
478
+
479
+ }
480
+
481
+ const texture = loader.load( fileName );
482
+
483
+ // revert to initial path
484
+ loader.setPath( loaderPath );
485
+
486
+ return texture;
487
+
488
+ }
489
+
490
+ // Parse nodes in FBXTree.Objects.Material
491
+ parseMaterials( textureMap ) {
492
+
493
+ const materialMap = new Map();
494
+
495
+ if ( 'Material' in fbxTree.Objects ) {
496
+
497
+ const materialNodes = fbxTree.Objects.Material;
498
+
499
+ for ( const nodeID in materialNodes ) {
500
+
501
+ const material = this.parseMaterial( materialNodes[ nodeID ], textureMap );
502
+
503
+ if ( material !== null ) materialMap.set( parseInt( nodeID ), material );
504
+
505
+ }
506
+
507
+ }
508
+
509
+ return materialMap;
510
+
511
+ }
512
+
513
+ // Parse single node in FBXTree.Objects.Material
514
+ // Materials are connected to texture maps in FBXTree.Objects.Textures
515
+ // FBX format currently only supports Lambert and Phong shading models
516
+ parseMaterial( materialNode, textureMap ) {
517
+
518
+ const ID = materialNode.id;
519
+ const name = materialNode.attrName;
520
+ let type = materialNode.ShadingModel;
521
+
522
+ // Case where FBX wraps shading model in property object.
523
+ if ( typeof type === 'object' ) {
524
+
525
+ type = type.value;
526
+
527
+ }
528
+
529
+ // Ignore unused materials which don't have any connections.
530
+ if ( ! connections.has( ID ) ) return null;
531
+
532
+ const parameters = this.parseParameters( materialNode, textureMap, ID );
533
+
534
+ let material;
535
+
536
+ switch ( type.toLowerCase() ) {
537
+
538
+ case 'phong':
539
+ material = new MeshPhongMaterial();
540
+ break;
541
+ case 'lambert':
542
+ material = new MeshLambertMaterial();
543
+ break;
544
+ default:
545
+ console.warn( 'THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.', type );
546
+ material = new MeshPhongMaterial();
547
+ break;
548
+
549
+ }
550
+
551
+ material.setValues( parameters );
552
+ material.name = name;
553
+
554
+ return material;
555
+
556
+ }
557
+
558
+ // Parse FBX material and return parameters suitable for a three.js material
559
+ // Also parse the texture map and return any textures associated with the material
560
+ parseParameters( materialNode, textureMap, ID ) {
561
+
562
+ const parameters = {};
563
+
564
+ if ( materialNode.BumpFactor ) {
565
+
566
+ parameters.bumpScale = materialNode.BumpFactor.value;
567
+
568
+ }
569
+
570
+ if ( materialNode.Diffuse ) {
571
+
572
+ parameters.color = ColorManagement.colorSpaceToWorking( new Color().fromArray( materialNode.Diffuse.value ), SRGBColorSpace );
573
+
574
+ } else if ( materialNode.DiffuseColor && ( materialNode.DiffuseColor.type === 'Color' || materialNode.DiffuseColor.type === 'ColorRGB' ) ) {
575
+
576
+ // The blender exporter exports diffuse here instead of in materialNode.Diffuse
577
+ parameters.color = ColorManagement.colorSpaceToWorking( new Color().fromArray( materialNode.DiffuseColor.value ), SRGBColorSpace );
578
+
579
+ }
580
+
581
+ if ( materialNode.DisplacementFactor ) {
582
+
583
+ parameters.displacementScale = materialNode.DisplacementFactor.value;
584
+
585
+ }
586
+
587
+ if ( materialNode.Emissive ) {
588
+
589
+ parameters.emissive = ColorManagement.colorSpaceToWorking( new Color().fromArray( materialNode.Emissive.value ), SRGBColorSpace );
590
+
591
+ } else if ( materialNode.EmissiveColor && ( materialNode.EmissiveColor.type === 'Color' || materialNode.EmissiveColor.type === 'ColorRGB' ) ) {
592
+
593
+ // The blender exporter exports emissive color here instead of in materialNode.Emissive
594
+ parameters.emissive = ColorManagement.colorSpaceToWorking( new Color().fromArray( materialNode.EmissiveColor.value ), SRGBColorSpace );
595
+
596
+ }
597
+
598
+ if ( materialNode.EmissiveFactor ) {
599
+
600
+ parameters.emissiveIntensity = parseFloat( materialNode.EmissiveFactor.value );
601
+
602
+ }
603
+
604
+ // the transparency handling is implemented based on Blender's approach:
605
+ // https://github.com/blender/blender/blob/main/scripts/addons_core/io_scene_fbx/import_fbx.py
606
+
607
+ parameters.opacity = 1 - ( materialNode.TransparencyFactor ? parseFloat( materialNode.TransparencyFactor.value ) : 0 );
608
+
609
+ if ( parameters.opacity === 1 || parameters.opacity === 0 ) {
610
+
611
+ parameters.opacity = ( materialNode.Opacity ? parseFloat( materialNode.Opacity.value ) : null );
612
+
613
+ if ( parameters.opacity === null ) {
614
+
615
+ // Default to opaque. Some exporters (e.g. 3ds Max) define TransparentColor
616
+ // as white (1,1,1) without intending transparency, which makes the Unity-style
617
+ // fallback of `1 - TransparentColor.r` produce incorrect zero opacity.
618
+ parameters.opacity = 1;
619
+
620
+ }
621
+
622
+ }
623
+
624
+ if ( parameters.opacity < 1.0 ) {
625
+
626
+ parameters.transparent = true;
627
+
628
+ }
629
+
630
+ if ( materialNode.ReflectionFactor ) {
631
+
632
+ parameters.reflectivity = materialNode.ReflectionFactor.value;
633
+
634
+ }
635
+
636
+ if ( materialNode.Shininess ) {
637
+
638
+ parameters.shininess = materialNode.Shininess.value;
639
+
640
+ }
641
+
642
+ if ( materialNode.Specular ) {
643
+
644
+ parameters.specular = ColorManagement.colorSpaceToWorking( new Color().fromArray( materialNode.Specular.value ), SRGBColorSpace );
645
+
646
+ } else if ( materialNode.SpecularColor && materialNode.SpecularColor.type === 'Color' ) {
647
+
648
+ // The blender exporter exports specular color here instead of in materialNode.Specular
649
+ parameters.specular = ColorManagement.colorSpaceToWorking( new Color().fromArray( materialNode.SpecularColor.value ), SRGBColorSpace );
650
+
651
+ }
652
+
653
+ const scope = this;
654
+ connections.get( ID ).children.forEach( function ( child ) {
655
+
656
+ const type = child.relationship;
657
+
658
+ switch ( type ) {
659
+
660
+ case 'Bump':
661
+ parameters.bumpMap = scope.getTexture( textureMap, child.ID );
662
+ break;
663
+
664
+ case 'Maya|TEX_ao_map':
665
+ parameters.aoMap = scope.getTexture( textureMap, child.ID );
666
+ break;
667
+
668
+ case 'DiffuseColor':
669
+ case 'Maya|TEX_color_map':
670
+ parameters.map = scope.getTexture( textureMap, child.ID );
671
+ if ( parameters.map !== undefined ) {
672
+
673
+ parameters.map.colorSpace = SRGBColorSpace;
674
+
675
+ }
676
+
677
+ break;
678
+
679
+ case 'DisplacementColor':
680
+ parameters.displacementMap = scope.getTexture( textureMap, child.ID );
681
+ break;
682
+
683
+ case 'EmissiveColor':
684
+ parameters.emissiveMap = scope.getTexture( textureMap, child.ID );
685
+ if ( parameters.emissiveMap !== undefined ) {
686
+
687
+ parameters.emissiveMap.colorSpace = SRGBColorSpace;
688
+
689
+ }
690
+
691
+ break;
692
+
693
+ case 'NormalMap':
694
+ case 'Maya|TEX_normal_map':
695
+ parameters.normalMap = scope.getTexture( textureMap, child.ID );
696
+ break;
697
+
698
+ case 'ReflectionColor':
699
+ parameters.envMap = scope.getTexture( textureMap, child.ID );
700
+ if ( parameters.envMap !== undefined ) {
701
+
702
+ parameters.envMap.mapping = EquirectangularReflectionMapping;
703
+ parameters.envMap.colorSpace = SRGBColorSpace;
704
+
705
+ }
706
+
707
+ break;
708
+
709
+ case 'SpecularColor':
710
+ parameters.specularMap = scope.getTexture( textureMap, child.ID );
711
+ if ( parameters.specularMap !== undefined ) {
712
+
713
+ parameters.specularMap.colorSpace = SRGBColorSpace;
714
+
715
+ }
716
+
717
+ break;
718
+
719
+ case 'TransparentColor':
720
+ case 'TransparencyFactor':
721
+ parameters.alphaMap = scope.getTexture( textureMap, child.ID );
722
+ parameters.transparent = true;
723
+ break;
724
+
725
+ case 'AmbientColor':
726
+ case 'ShininessExponent': // AKA glossiness map
727
+ case 'SpecularFactor': // AKA specularLevel
728
+ case 'VectorDisplacementColor': // NOTE: Seems to be a copy of DisplacementColor
729
+ default:
730
+ console.warn( 'THREE.FBXLoader: %s map is not supported in three.js, skipping texture.', type );
731
+ break;
732
+
733
+ }
734
+
735
+ } );
736
+
737
+ return parameters;
738
+
739
+ }
740
+
741
+ // get a texture from the textureMap for use by a material.
742
+ getTexture( textureMap, id ) {
743
+
744
+ // if the texture is a layered texture, just use the first layer and issue a warning
745
+ if ( 'LayeredTexture' in fbxTree.Objects && id in fbxTree.Objects.LayeredTexture ) {
746
+
747
+ console.warn( 'THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer.' );
748
+ id = connections.get( id ).children[ 0 ].ID;
749
+
750
+ }
751
+
752
+ return textureMap.get( id );
753
+
754
+ }
755
+
756
+ // Parse nodes in FBXTree.Objects.Deformer
757
+ // Deformer node can contain skinning or Vertex Cache animation data, however only skinning is supported here
758
+ // Generates map of Skeleton-like objects for use later when generating and binding skeletons.
759
+ parseDeformers() {
760
+
761
+ const skeletons = {};
762
+ const morphTargets = {};
763
+
764
+ if ( 'Deformer' in fbxTree.Objects ) {
765
+
766
+ const DeformerNodes = fbxTree.Objects.Deformer;
767
+
768
+ for ( const nodeID in DeformerNodes ) {
769
+
770
+ const deformerNode = DeformerNodes[ nodeID ];
771
+
772
+ const relationships = connections.get( parseInt( nodeID ) );
773
+
774
+ if ( deformerNode.attrType === 'Skin' ) {
775
+
776
+ const skeleton = this.parseSkeleton( relationships, DeformerNodes );
777
+ skeleton.ID = nodeID;
778
+
779
+ if ( relationships.parents.length > 1 ) console.warn( 'THREE.FBXLoader: skeleton attached to more than one geometry is not supported.' );
780
+ skeleton.geometryID = relationships.parents[ 0 ].ID;
781
+
782
+ skeletons[ nodeID ] = skeleton;
783
+
784
+ } else if ( deformerNode.attrType === 'BlendShape' ) {
785
+
786
+ const morphTarget = {
787
+ id: nodeID,
788
+ };
789
+
790
+ morphTarget.rawTargets = this.parseMorphTargets( relationships, DeformerNodes );
791
+ morphTarget.id = nodeID;
792
+
793
+ if ( relationships.parents.length > 1 ) console.warn( 'THREE.FBXLoader: morph target attached to more than one geometry is not supported.' );
794
+
795
+ morphTargets[ nodeID ] = morphTarget;
796
+
797
+ }
798
+
799
+ }
800
+
801
+ }
802
+
803
+ return {
804
+
805
+ skeletons: skeletons,
806
+ morphTargets: morphTargets,
807
+
808
+ };
809
+
810
+ }
811
+
812
+ // Parse single nodes in FBXTree.Objects.Deformer
813
+ // The top level skeleton node has type 'Skin' and sub nodes have type 'Cluster'
814
+ // Each skin node represents a skeleton and each cluster node represents a bone
815
+ parseSkeleton( relationships, deformerNodes ) {
816
+
817
+ const rawBones = [];
818
+
819
+ relationships.children.forEach( function ( child ) {
820
+
821
+ const boneNode = deformerNodes[ child.ID ];
822
+
823
+ if ( boneNode.attrType !== 'Cluster' ) return;
824
+
825
+ const rawBone = {
826
+
827
+ ID: child.ID,
828
+ indices: [],
829
+ weights: [],
830
+ transformLink: new Matrix4().fromArray( boneNode.TransformLink.a ),
831
+
832
+ };
833
+
834
+ if ( 'Indexes' in boneNode ) {
835
+
836
+ rawBone.indices = boneNode.Indexes.a;
837
+ rawBone.weights = boneNode.Weights.a;
838
+
839
+ }
840
+
841
+ rawBones.push( rawBone );
842
+
843
+ } );
844
+
845
+ return {
846
+
847
+ rawBones: rawBones,
848
+ bones: []
849
+
850
+ };
851
+
852
+ }
853
+
854
+ // The top level morph deformer node has type "BlendShape" and sub nodes have type "BlendShapeChannel"
855
+ parseMorphTargets( relationships, deformerNodes ) {
856
+
857
+ const rawMorphTargets = [];
858
+
859
+ for ( let i = 0; i < relationships.children.length; i ++ ) {
860
+
861
+ const child = relationships.children[ i ];
862
+
863
+ const morphTargetNode = deformerNodes[ child.ID ];
864
+
865
+ const rawMorphTarget = {
866
+
867
+ name: morphTargetNode.attrName,
868
+ initialWeight: morphTargetNode.DeformPercent,
869
+ id: morphTargetNode.id,
870
+ fullWeights: morphTargetNode.FullWeights.a
871
+
872
+ };
873
+
874
+ if ( morphTargetNode.attrType !== 'BlendShapeChannel' ) return;
875
+
876
+ rawMorphTarget.geoID = connections.get( parseInt( child.ID ) ).children.filter( function ( child ) {
877
+
878
+ return child.relationship === undefined;
879
+
880
+ } )[ 0 ].ID;
881
+
882
+ rawMorphTargets.push( rawMorphTarget );
883
+
884
+ }
885
+
886
+ return rawMorphTargets;
887
+
888
+ }
889
+
890
+ // create the main Group() to be returned by the loader
891
+ parseScene( deformers, geometryMap, materialMap ) {
892
+
893
+ sceneGraph = new Group();
894
+
895
+ const modelMap = this.parseModels( deformers.skeletons, geometryMap, materialMap );
896
+
897
+ const modelNodes = fbxTree.Objects.Model;
898
+
899
+ const scope = this;
900
+ modelMap.forEach( function ( model ) {
901
+
902
+ const modelNode = modelNodes[ model.ID ];
903
+ scope.setLookAtProperties( model, modelNode );
904
+
905
+ const parentConnections = connections.get( model.ID ).parents;
906
+
907
+ parentConnections.forEach( function ( connection ) {
908
+
909
+ const parent = modelMap.get( connection.ID );
910
+ if ( parent !== undefined ) parent.add( model );
911
+
912
+ } );
913
+
914
+ if ( model.parent === null ) {
915
+
916
+ sceneGraph.add( model );
917
+
918
+ }
919
+
920
+
921
+ } );
922
+
923
+ this.addGlobalSceneSettings();
924
+
925
+ sceneGraph.traverse( function ( node ) {
926
+
927
+ if ( node.userData.transformData ) {
928
+
929
+ if ( node.parent ) {
930
+
931
+ node.userData.transformData.parentMatrix = node.parent.matrix;
932
+ node.userData.transformData.parentMatrixWorld = node.parent.matrixWorld;
933
+
934
+ }
935
+
936
+ const transform = generateTransform( node.userData.transformData );
937
+
938
+ node.applyMatrix4( transform );
939
+ node.updateWorldMatrix();
940
+
941
+ }
942
+
943
+ } );
944
+
945
+ // Like Blender's FBX importer, use the BindPose section to set the
946
+ // rest pose for bones that are not part of a skin cluster. The BindPose
947
+ // provides a more authoritative rest pose than the Lcl properties which
948
+ // may represent an animation frame rather than the true rest state.
949
+ // Bones WITH clusters will get their bind pose from TransformLink
950
+ // (set via bindSkeleton below), which takes priority.
951
+ const bindPoseMatrices = this.parsePoseNodes();
952
+ const clusterBoneIDs = new Set();
953
+
954
+ for ( const ID in deformers.skeletons ) {
955
+
956
+ deformers.skeletons[ ID ].rawBones.forEach( function ( _, i ) {
957
+
958
+ const bone = deformers.skeletons[ ID ].bones[ i ];
959
+ if ( bone ) clusterBoneIDs.add( bone.ID );
960
+
961
+ } );
962
+
963
+ }
964
+
965
+ const tempMatrix = new Matrix4();
966
+
967
+ sceneGraph.traverse( function ( node ) {
968
+
969
+ if ( node.isBone && node.ID !== undefined && ! clusterBoneIDs.has( node.ID ) ) {
970
+
971
+ const bindPose = bindPoseMatrices[ node.ID ];
972
+
973
+ if ( bindPose !== undefined ) {
974
+
975
+ if ( node.parent ) {
976
+
977
+ tempMatrix.copy( node.parent.matrixWorld ).invert();
978
+ tempMatrix.multiply( bindPose );
979
+
980
+ } else {
981
+
982
+ tempMatrix.copy( bindPose );
983
+
984
+ }
985
+
986
+ tempMatrix.decompose( node.position, node.quaternion, node.scale );
987
+ node.updateMatrix();
988
+ node.matrixWorld.copy( bindPose );
989
+
990
+ }
991
+
992
+ }
993
+
994
+ } );
995
+
996
+ // Bind skeletons after transforms are applied so that bind matrices
997
+ // are computed from the final scene state. This ensures the rest pose
998
+ // is correct even when the FBX file's Cluster TransformLink matrices
999
+ // differ from the reconstructed bone transforms (common in files
1000
+ // without a BindPose section).
1001
+ this.bindSkeleton( deformers.skeletons, geometryMap, modelMap );
1002
+
1003
+ const animations = new AnimationParser().parse();
1004
+
1005
+ // if all the models where already combined in a single group, just return that
1006
+ if ( sceneGraph.children.length === 1 && sceneGraph.children[ 0 ].isGroup ) {
1007
+
1008
+ sceneGraph.children[ 0 ].animations = animations;
1009
+ sceneGraph = sceneGraph.children[ 0 ];
1010
+
1011
+ }
1012
+
1013
+ sceneGraph.animations = animations;
1014
+
1015
+ // Apply coordinate system correction. FBX files can use different
1016
+ // up-axis conventions (Y-up or Z-up). Three.js uses Y-up, so rotate
1017
+ // the scene when the file uses Z-up (UpAxis === 2).
1018
+
1019
+ if ( 'GlobalSettings' in fbxTree && 'UpAxis' in fbxTree.GlobalSettings ) {
1020
+
1021
+ const upAxis = fbxTree.GlobalSettings.UpAxis.value;
1022
+
1023
+ if ( upAxis === 2 ) {
1024
+
1025
+ console.warn( 'THREE.FBXLoader: You are loading an asset with a Z-UP coordinate system. The loader just rotates the asset to transform it into Y-UP. The vertex data are not converted.' );
1026
+
1027
+ sceneGraph.rotation.set( - Math.PI / 2, 0, 0 );
1028
+
1029
+ }
1030
+
1031
+ }
1032
+
1033
+ }
1034
+
1035
+ // parse nodes in FBXTree.Objects.Model
1036
+ parseModels( skeletons, geometryMap, materialMap ) {
1037
+
1038
+ const modelMap = new Map();
1039
+ const modelNodes = fbxTree.Objects.Model;
1040
+
1041
+ for ( const nodeID in modelNodes ) {
1042
+
1043
+ const id = parseInt( nodeID );
1044
+ const node = modelNodes[ nodeID ];
1045
+ const relationships = connections.get( id );
1046
+
1047
+ let model = this.buildSkeleton( relationships, skeletons, id, node.attrName );
1048
+
1049
+ if ( ! model ) {
1050
+
1051
+ switch ( node.attrType ) {
1052
+
1053
+ case 'Camera':
1054
+ model = this.createCamera( relationships );
1055
+ break;
1056
+ case 'Light':
1057
+ model = this.createLight( relationships );
1058
+ break;
1059
+ case 'Mesh':
1060
+ model = this.createMesh( relationships, geometryMap, materialMap );
1061
+ break;
1062
+ case 'NurbsCurve':
1063
+ model = this.createCurve( relationships, geometryMap );
1064
+ break;
1065
+ case 'LimbNode':
1066
+ case 'Root':
1067
+ model = new Bone();
1068
+ break;
1069
+ case 'Null':
1070
+ default:
1071
+ model = new Group();
1072
+ break;
1073
+
1074
+ }
1075
+
1076
+ model.name = node.attrName ? PropertyBinding.sanitizeNodeName( node.attrName ) : '';
1077
+ model.userData.originalName = node.attrName;
1078
+
1079
+ model.ID = id;
1080
+
1081
+ }
1082
+
1083
+ this.getTransformData( model, node );
1084
+ modelMap.set( id, model );
1085
+
1086
+ }
1087
+
1088
+ return modelMap;
1089
+
1090
+ }
1091
+
1092
+ buildSkeleton( relationships, skeletons, id, name ) {
1093
+
1094
+ let bone = null;
1095
+
1096
+ relationships.parents.forEach( function ( parent ) {
1097
+
1098
+ for ( const ID in skeletons ) {
1099
+
1100
+ const skeleton = skeletons[ ID ];
1101
+
1102
+ skeleton.rawBones.forEach( function ( rawBone, i ) {
1103
+
1104
+ if ( rawBone.ID === parent.ID ) {
1105
+
1106
+ const subBone = bone;
1107
+ bone = new Bone();
1108
+
1109
+ bone.matrixWorld.copy( rawBone.transformLink );
1110
+
1111
+ // set name and id here - otherwise in cases where "subBone" is created it will not have a name / id
1112
+
1113
+ bone.name = name ? PropertyBinding.sanitizeNodeName( name ) : '';
1114
+ bone.userData.originalName = name;
1115
+ bone.ID = id;
1116
+
1117
+ skeleton.bones[ i ] = bone;
1118
+
1119
+ // In cases where a bone is shared between multiple meshes
1120
+ // duplicate the bone here and add it as a child of the first bone
1121
+ if ( subBone !== null ) {
1122
+
1123
+ bone.add( subBone );
1124
+
1125
+ }
1126
+
1127
+ }
1128
+
1129
+ } );
1130
+
1131
+ }
1132
+
1133
+ } );
1134
+
1135
+ return bone;
1136
+
1137
+ }
1138
+
1139
+ // create a PerspectiveCamera or OrthographicCamera
1140
+ createCamera( relationships ) {
1141
+
1142
+ let model;
1143
+ let cameraAttribute;
1144
+
1145
+ relationships.children.forEach( function ( child ) {
1146
+
1147
+ const attr = fbxTree.Objects.NodeAttribute[ child.ID ];
1148
+
1149
+ if ( attr !== undefined ) {
1150
+
1151
+ cameraAttribute = attr;
1152
+
1153
+ }
1154
+
1155
+ } );
1156
+
1157
+ if ( cameraAttribute === undefined ) {
1158
+
1159
+ model = new Object3D();
1160
+
1161
+ } else {
1162
+
1163
+ let type = 0;
1164
+ if ( cameraAttribute.CameraProjectionType !== undefined && cameraAttribute.CameraProjectionType.value === 1 ) {
1165
+
1166
+ type = 1;
1167
+
1168
+ }
1169
+
1170
+ let nearClippingPlane = 1;
1171
+ if ( cameraAttribute.NearPlane !== undefined ) {
1172
+
1173
+ nearClippingPlane = cameraAttribute.NearPlane.value / 1000;
1174
+
1175
+ }
1176
+
1177
+ let farClippingPlane = 1000;
1178
+ if ( cameraAttribute.FarPlane !== undefined ) {
1179
+
1180
+ farClippingPlane = cameraAttribute.FarPlane.value / 1000;
1181
+
1182
+ }
1183
+
1184
+
1185
+ let width = window.innerWidth;
1186
+ let height = window.innerHeight;
1187
+
1188
+ if ( cameraAttribute.AspectWidth !== undefined && cameraAttribute.AspectHeight !== undefined ) {
1189
+
1190
+ width = cameraAttribute.AspectWidth.value;
1191
+ height = cameraAttribute.AspectHeight.value;
1192
+
1193
+ }
1194
+
1195
+ const aspect = width / height;
1196
+
1197
+ let fov = 45;
1198
+ if ( cameraAttribute.FieldOfView !== undefined ) {
1199
+
1200
+ fov = cameraAttribute.FieldOfView.value;
1201
+
1202
+ }
1203
+
1204
+ const focalLength = cameraAttribute.FocalLength ? cameraAttribute.FocalLength.value : null;
1205
+
1206
+ switch ( type ) {
1207
+
1208
+ case 0: // Perspective
1209
+ model = new PerspectiveCamera( fov, aspect, nearClippingPlane, farClippingPlane );
1210
+ if ( focalLength !== null ) model.setFocalLength( focalLength );
1211
+ break;
1212
+
1213
+ case 1: // Orthographic
1214
+ console.warn( 'THREE.FBXLoader: Orthographic cameras not supported yet.' );
1215
+ model = new Object3D();
1216
+ break;
1217
+
1218
+ default:
1219
+ console.warn( 'THREE.FBXLoader: Unknown camera type ' + type + '.' );
1220
+ model = new Object3D();
1221
+ break;
1222
+
1223
+ }
1224
+
1225
+ }
1226
+
1227
+ return model;
1228
+
1229
+ }
1230
+
1231
+ // Create a DirectionalLight, PointLight or SpotLight
1232
+ createLight( relationships ) {
1233
+
1234
+ let model;
1235
+ let lightAttribute;
1236
+
1237
+ relationships.children.forEach( function ( child ) {
1238
+
1239
+ const attr = fbxTree.Objects.NodeAttribute[ child.ID ];
1240
+
1241
+ if ( attr !== undefined ) {
1242
+
1243
+ lightAttribute = attr;
1244
+
1245
+ }
1246
+
1247
+ } );
1248
+
1249
+ if ( lightAttribute === undefined ) {
1250
+
1251
+ model = new Object3D();
1252
+
1253
+ } else {
1254
+
1255
+ let type;
1256
+
1257
+ // LightType can be undefined for Point lights
1258
+ if ( lightAttribute.LightType === undefined ) {
1259
+
1260
+ type = 0;
1261
+
1262
+ } else {
1263
+
1264
+ type = lightAttribute.LightType.value;
1265
+
1266
+ }
1267
+
1268
+ let color = 0xffffff;
1269
+
1270
+ if ( lightAttribute.Color !== undefined ) {
1271
+
1272
+ color = ColorManagement.colorSpaceToWorking( new Color().fromArray( lightAttribute.Color.value ), SRGBColorSpace );
1273
+
1274
+ }
1275
+
1276
+ let intensity = ( lightAttribute.Intensity === undefined ) ? 1 : lightAttribute.Intensity.value / 100;
1277
+
1278
+ // light disabled
1279
+ if ( lightAttribute.CastLightOnObject !== undefined && lightAttribute.CastLightOnObject.value === 0 ) {
1280
+
1281
+ intensity = 0;
1282
+
1283
+ }
1284
+
1285
+ let distance = 0;
1286
+ if ( lightAttribute.FarAttenuationEnd !== undefined ) {
1287
+
1288
+ if ( lightAttribute.EnableFarAttenuation !== undefined && lightAttribute.EnableFarAttenuation.value === 0 ) {
1289
+
1290
+ distance = 0;
1291
+
1292
+ } else {
1293
+
1294
+ distance = lightAttribute.FarAttenuationEnd.value;
1295
+
1296
+ }
1297
+
1298
+ }
1299
+
1300
+ // TODO: could this be calculated linearly from FarAttenuationStart to FarAttenuationEnd?
1301
+ const decay = 1;
1302
+
1303
+ switch ( type ) {
1304
+
1305
+ case 0: // Point
1306
+ model = new PointLight( color, intensity, distance, decay );
1307
+ break;
1308
+
1309
+ case 1: // Directional
1310
+ model = new DirectionalLight( color, intensity );
1311
+ break;
1312
+
1313
+ case 2: // Spot
1314
+ let angle = Math.PI / 3;
1315
+ let penumbra = 0;
1316
+
1317
+ if ( lightAttribute.OuterAngle !== undefined ) {
1318
+
1319
+ angle = MathUtils.degToRad( lightAttribute.OuterAngle.value );
1320
+
1321
+ if ( lightAttribute.InnerAngle !== undefined ) {
1322
+
1323
+ penumbra = 1 - ( lightAttribute.InnerAngle.value / lightAttribute.OuterAngle.value );
1324
+ penumbra = Math.max( 0, penumbra ); // penumbra must be in the range [0,1]
1325
+
1326
+ }
1327
+
1328
+ } else if ( lightAttribute.InnerAngle !== undefined ) {
1329
+
1330
+ // fallback if only InnerAngle is defined
1331
+
1332
+ angle = MathUtils.degToRad( lightAttribute.InnerAngle.value );
1333
+
1334
+ }
1335
+
1336
+ model = new SpotLight( color, intensity, distance, angle, penumbra, decay );
1337
+ break;
1338
+
1339
+ default:
1340
+ console.warn( 'THREE.FBXLoader: Unknown light type ' + lightAttribute.LightType.value + ', defaulting to a PointLight.' );
1341
+ model = new PointLight( color, intensity );
1342
+ break;
1343
+
1344
+ }
1345
+
1346
+ if ( lightAttribute.CastShadows !== undefined && lightAttribute.CastShadows.value === 1 ) {
1347
+
1348
+ model.castShadow = true;
1349
+
1350
+ }
1351
+
1352
+ }
1353
+
1354
+ return model;
1355
+
1356
+ }
1357
+
1358
+ createMesh( relationships, geometryMap, materialMap ) {
1359
+
1360
+ let model;
1361
+ let geometry = null;
1362
+ let material = null;
1363
+ const materials = [];
1364
+
1365
+ // get geometry and materials(s) from connections
1366
+ relationships.children.forEach( function ( child ) {
1367
+
1368
+ if ( geometryMap.has( child.ID ) ) {
1369
+
1370
+ geometry = geometryMap.get( child.ID );
1371
+
1372
+ }
1373
+
1374
+ if ( materialMap.has( child.ID ) ) {
1375
+
1376
+ materials.push( materialMap.get( child.ID ) );
1377
+
1378
+ }
1379
+
1380
+ } );
1381
+
1382
+ if ( materials.length > 1 ) {
1383
+
1384
+ material = materials;
1385
+
1386
+ } else if ( materials.length > 0 ) {
1387
+
1388
+ material = materials[ 0 ];
1389
+
1390
+ } else {
1391
+
1392
+ material = new MeshPhongMaterial( {
1393
+ name: Loader.DEFAULT_MATERIAL_NAME,
1394
+ color: 0xcccccc
1395
+ } );
1396
+ materials.push( material );
1397
+
1398
+ }
1399
+
1400
+ if ( 'color' in geometry.attributes ) {
1401
+
1402
+ materials.forEach( function ( material ) {
1403
+
1404
+ material.vertexColors = true;
1405
+
1406
+ } );
1407
+
1408
+ }
1409
+
1410
+ // Sanitization: If geometry has groups, then it must match the provided material array.
1411
+ // If not, we need to clean up the `group.materialIndex` properties inside the groups and point at a (new) default material.
1412
+ // This isn't well defined; Unity creates default material, while Blender implicitly uses the previous material in the list.
1413
+ if ( geometry.groups.length > 0 ) {
1414
+
1415
+ let needsDefaultMaterial = false;
1416
+
1417
+ for ( let i = 0, il = geometry.groups.length; i < il; i ++ ) {
1418
+
1419
+ const group = geometry.groups[ i ];
1420
+
1421
+ if ( group.materialIndex < 0 || group.materialIndex >= materials.length ) {
1422
+
1423
+ group.materialIndex = materials.length;
1424
+ needsDefaultMaterial = true;
1425
+
1426
+ }
1427
+
1428
+ }
1429
+
1430
+ if ( needsDefaultMaterial ) {
1431
+
1432
+ const defaultMaterial = new MeshPhongMaterial();
1433
+ materials.push( defaultMaterial );
1434
+
1435
+ }
1436
+
1437
+ }
1438
+
1439
+ if ( geometry.FBX_Deformer ) {
1440
+
1441
+ model = new SkinnedMesh( geometry, material );
1442
+ model.normalizeSkinWeights();
1443
+
1444
+ } else {
1445
+
1446
+ model = new Mesh( geometry, material );
1447
+
1448
+ }
1449
+
1450
+ return model;
1451
+
1452
+ }
1453
+
1454
+ createCurve( relationships, geometryMap ) {
1455
+
1456
+ const geometry = relationships.children.reduce( function ( geo, child ) {
1457
+
1458
+ if ( geometryMap.has( child.ID ) ) geo = geometryMap.get( child.ID );
1459
+
1460
+ return geo;
1461
+
1462
+ }, null );
1463
+
1464
+ // FBX does not list materials for Nurbs lines, so we'll just put our own in here.
1465
+ const material = new LineBasicMaterial( {
1466
+ name: Loader.DEFAULT_MATERIAL_NAME,
1467
+ color: 0x3300ff,
1468
+ linewidth: 1
1469
+ } );
1470
+ return new Line( geometry, material );
1471
+
1472
+ }
1473
+
1474
+ // parse the model node for transform data
1475
+ getTransformData( model, modelNode ) {
1476
+
1477
+ const transformData = {};
1478
+
1479
+ if ( 'InheritType' in modelNode ) transformData.inheritType = parseInt( modelNode.InheritType.value );
1480
+
1481
+ if ( 'RotationOrder' in modelNode ) transformData.eulerOrder = getEulerOrder( modelNode.RotationOrder.value );
1482
+ else transformData.eulerOrder = getEulerOrder( 0 );
1483
+
1484
+ if ( 'Lcl_Translation' in modelNode ) transformData.translation = modelNode.Lcl_Translation.value;
1485
+
1486
+ if ( 'PreRotation' in modelNode ) transformData.preRotation = modelNode.PreRotation.value;
1487
+ if ( 'Lcl_Rotation' in modelNode ) transformData.rotation = modelNode.Lcl_Rotation.value;
1488
+ if ( 'PostRotation' in modelNode ) transformData.postRotation = modelNode.PostRotation.value;
1489
+
1490
+ if ( 'Lcl_Scaling' in modelNode ) transformData.scale = modelNode.Lcl_Scaling.value;
1491
+
1492
+ if ( 'ScalingOffset' in modelNode ) transformData.scalingOffset = modelNode.ScalingOffset.value;
1493
+ if ( 'ScalingPivot' in modelNode ) transformData.scalingPivot = modelNode.ScalingPivot.value;
1494
+
1495
+ if ( 'RotationOffset' in modelNode ) transformData.rotationOffset = modelNode.RotationOffset.value;
1496
+ if ( 'RotationPivot' in modelNode ) transformData.rotationPivot = modelNode.RotationPivot.value;
1497
+
1498
+ model.userData.transformData = transformData;
1499
+
1500
+ }
1501
+
1502
+ setLookAtProperties( model, modelNode ) {
1503
+
1504
+ if ( 'LookAtProperty' in modelNode ) {
1505
+
1506
+ const children = connections.get( model.ID ).children;
1507
+
1508
+ children.forEach( function ( child ) {
1509
+
1510
+ if ( child.relationship === 'LookAtProperty' ) {
1511
+
1512
+ const lookAtTarget = fbxTree.Objects.Model[ child.ID ];
1513
+
1514
+ if ( 'Lcl_Translation' in lookAtTarget ) {
1515
+
1516
+ const pos = lookAtTarget.Lcl_Translation.value;
1517
+
1518
+ // DirectionalLight, SpotLight
1519
+ if ( model.target !== undefined ) {
1520
+
1521
+ model.target.position.fromArray( pos );
1522
+ sceneGraph.add( model.target );
1523
+
1524
+ } else { // Cameras and other Object3Ds
1525
+
1526
+ model.lookAt( new Vector3().fromArray( pos ) );
1527
+
1528
+ }
1529
+
1530
+ }
1531
+
1532
+ }
1533
+
1534
+ } );
1535
+
1536
+ }
1537
+
1538
+ }
1539
+
1540
+ bindSkeleton( skeletons, geometryMap, modelMap ) {
1541
+
1542
+ for ( const ID in skeletons ) {
1543
+
1544
+ const skeleton = skeletons[ ID ];
1545
+
1546
+ // Compute bone inverses from TransformLink rather than from the
1547
+ // bones' current matrixWorld. The TransformLink matrices represent
1548
+ // each bone's global transform at the time the skin weights were
1549
+ // painted, which may differ from the scene-reconstructed transforms.
1550
+ const boneInverses = [];
1551
+
1552
+ for ( let i = 0, l = skeleton.bones.length; i < l; i ++ ) {
1553
+
1554
+ const inverse = new Matrix4();
1555
+
1556
+ if ( skeleton.bones[ i ] && skeleton.rawBones[ i ] ) {
1557
+
1558
+ inverse.copy( skeleton.rawBones[ i ].transformLink ).invert();
1559
+
1560
+ }
1561
+
1562
+ boneInverses.push( inverse );
1563
+
1564
+ }
1565
+
1566
+ const parents = connections.get( parseInt( skeleton.ID ) ).parents;
1567
+
1568
+ parents.forEach( function ( parent ) {
1569
+
1570
+ if ( geometryMap.has( parent.ID ) ) {
1571
+
1572
+ const geoID = parent.ID;
1573
+ const geoRelationships = connections.get( geoID );
1574
+
1575
+ geoRelationships.parents.forEach( function ( geoConnParent ) {
1576
+
1577
+ if ( modelMap.has( geoConnParent.ID ) ) {
1578
+
1579
+ const model = modelMap.get( geoConnParent.ID );
1580
+
1581
+ // Use the mesh's current matrixWorld as bind matrix.
1582
+ // The BindPose section is intentionally not used here
1583
+ // since it may contain scale/rotation from the model
1584
+ // hierarchy that is inconsistent with the TransformLink-
1585
+ // based bone inverses. Always provide a bind matrix to
1586
+ // prevent bind() from calling calculateInverses() which
1587
+ // would overwrite the bone inverses computed above.
1588
+ model.updateMatrixWorld( true );
1589
+
1590
+ model.bind( new Skeleton( skeleton.bones, boneInverses ), model.matrixWorld );
1591
+
1592
+ }
1593
+
1594
+ } );
1595
+
1596
+ }
1597
+
1598
+ } );
1599
+
1600
+ }
1601
+
1602
+ }
1603
+
1604
+ // Parse BindPose nodes and return a map of node ID to bind matrix.
1605
+ parsePoseNodes() {
1606
+
1607
+ const bindMatrices = {};
1608
+
1609
+ if ( 'Pose' in fbxTree.Objects ) {
1610
+
1611
+ const BindPoseNode = fbxTree.Objects.Pose;
1612
+
1613
+ for ( const nodeID in BindPoseNode ) {
1614
+
1615
+ if ( BindPoseNode[ nodeID ].attrType === 'BindPose' && BindPoseNode[ nodeID ].NbPoseNodes > 0 ) {
1616
+
1617
+ const poseNodes = BindPoseNode[ nodeID ].PoseNode;
1618
+
1619
+ if ( Array.isArray( poseNodes ) ) {
1620
+
1621
+ poseNodes.forEach( function ( poseNode ) {
1622
+
1623
+ bindMatrices[ poseNode.Node ] = new Matrix4().fromArray( poseNode.Matrix.a );
1624
+
1625
+ } );
1626
+
1627
+ } else {
1628
+
1629
+ bindMatrices[ poseNodes.Node ] = new Matrix4().fromArray( poseNodes.Matrix.a );
1630
+
1631
+ }
1632
+
1633
+ }
1634
+
1635
+ }
1636
+
1637
+ }
1638
+
1639
+ return bindMatrices;
1640
+
1641
+ }
1642
+
1643
+ addGlobalSceneSettings() {
1644
+
1645
+ if ( 'GlobalSettings' in fbxTree ) {
1646
+
1647
+ if ( 'AmbientColor' in fbxTree.GlobalSettings ) {
1648
+
1649
+ // Parse ambient color - if it's not set to black (default), create an ambient light
1650
+
1651
+ const ambientColor = fbxTree.GlobalSettings.AmbientColor.value;
1652
+ const r = ambientColor[ 0 ];
1653
+ const g = ambientColor[ 1 ];
1654
+ const b = ambientColor[ 2 ];
1655
+
1656
+ if ( r !== 0 || g !== 0 || b !== 0 ) {
1657
+
1658
+ const color = new Color().setRGB( r, g, b, SRGBColorSpace );
1659
+ sceneGraph.add( new AmbientLight( color, 1 ) );
1660
+
1661
+ }
1662
+
1663
+ }
1664
+
1665
+ if ( 'UnitScaleFactor' in fbxTree.GlobalSettings ) {
1666
+
1667
+ sceneGraph.userData.unitScaleFactor = fbxTree.GlobalSettings.UnitScaleFactor.value;
1668
+
1669
+ }
1670
+
1671
+ }
1672
+
1673
+ }
1674
+
1675
+ }
1676
+
1677
+ // parse Geometry data from FBXTree and return map of BufferGeometries
1678
+ class GeometryParser {
1679
+
1680
+ constructor() {
1681
+
1682
+ this.negativeMaterialIndices = false;
1683
+
1684
+ }
1685
+
1686
+ // Parse nodes in FBXTree.Objects.Geometry
1687
+ parse( deformers ) {
1688
+
1689
+ const geometryMap = new Map();
1690
+
1691
+ if ( 'Geometry' in fbxTree.Objects ) {
1692
+
1693
+ const geoNodes = fbxTree.Objects.Geometry;
1694
+
1695
+ for ( const nodeID in geoNodes ) {
1696
+
1697
+ const relationships = connections.get( parseInt( nodeID ) );
1698
+ const geo = this.parseGeometry( relationships, geoNodes[ nodeID ], deformers );
1699
+
1700
+ geometryMap.set( parseInt( nodeID ), geo );
1701
+
1702
+ }
1703
+
1704
+ }
1705
+
1706
+ // report warnings
1707
+
1708
+ if ( this.negativeMaterialIndices === true ) {
1709
+
1710
+ console.warn( 'THREE.FBXLoader: The FBX file contains invalid (negative) material indices. The asset might not render as expected.' );
1711
+
1712
+ }
1713
+
1714
+ return geometryMap;
1715
+
1716
+ }
1717
+
1718
+ // Parse single node in FBXTree.Objects.Geometry
1719
+ parseGeometry( relationships, geoNode, deformers ) {
1720
+
1721
+ switch ( geoNode.attrType ) {
1722
+
1723
+ case 'Mesh':
1724
+ return this.parseMeshGeometry( relationships, geoNode, deformers );
1725
+
1726
+ case 'NurbsCurve':
1727
+ return this.parseNurbsGeometry( geoNode );
1728
+
1729
+ }
1730
+
1731
+ }
1732
+
1733
+ // Parse single node mesh geometry in FBXTree.Objects.Geometry
1734
+ parseMeshGeometry( relationships, geoNode, deformers ) {
1735
+
1736
+ const skeletons = deformers.skeletons;
1737
+ const morphTargets = [];
1738
+
1739
+ const modelNodes = relationships.parents.map( function ( parent ) {
1740
+
1741
+ return fbxTree.Objects.Model[ parent.ID ];
1742
+
1743
+ } );
1744
+
1745
+ // don't create geometry if it is not associated with any models
1746
+ if ( modelNodes.length === 0 ) return;
1747
+
1748
+ const skeleton = relationships.children.reduce( function ( skeleton, child ) {
1749
+
1750
+ if ( skeletons[ child.ID ] !== undefined ) skeleton = skeletons[ child.ID ];
1751
+
1752
+ return skeleton;
1753
+
1754
+ }, null );
1755
+
1756
+ relationships.children.forEach( function ( child ) {
1757
+
1758
+ if ( deformers.morphTargets[ child.ID ] !== undefined ) {
1759
+
1760
+ morphTargets.push( deformers.morphTargets[ child.ID ] );
1761
+
1762
+ }
1763
+
1764
+ } );
1765
+
1766
+ // Assume one model and get the preRotation from that
1767
+ // if there is more than one model associated with the geometry this may cause problems
1768
+ const modelNode = modelNodes[ 0 ];
1769
+
1770
+ const transformData = {};
1771
+
1772
+ if ( 'RotationOrder' in modelNode ) transformData.eulerOrder = getEulerOrder( modelNode.RotationOrder.value );
1773
+ if ( 'InheritType' in modelNode ) transformData.inheritType = parseInt( modelNode.InheritType.value );
1774
+
1775
+ if ( 'GeometricTranslation' in modelNode ) transformData.translation = modelNode.GeometricTranslation.value;
1776
+ if ( 'GeometricRotation' in modelNode ) transformData.rotation = modelNode.GeometricRotation.value;
1777
+ if ( 'GeometricScaling' in modelNode ) transformData.scale = modelNode.GeometricScaling.value;
1778
+
1779
+ const transform = generateTransform( transformData );
1780
+
1781
+ return this.genGeometry( geoNode, skeleton, morphTargets, transform );
1782
+
1783
+ }
1784
+
1785
+ // Generate a BufferGeometry from a node in FBXTree.Objects.Geometry
1786
+ genGeometry( geoNode, skeleton, morphTargets, preTransform ) {
1787
+
1788
+ const geo = new BufferGeometry();
1789
+ if ( geoNode.attrName ) geo.name = geoNode.attrName;
1790
+
1791
+ const geoInfo = this.parseGeoNode( geoNode, skeleton );
1792
+ const buffers = this.genBuffers( geoInfo );
1793
+
1794
+ const positionAttribute = new Float32BufferAttribute( buffers.vertex, 3 );
1795
+
1796
+ positionAttribute.applyMatrix4( preTransform );
1797
+
1798
+ geo.setAttribute( 'position', positionAttribute );
1799
+
1800
+ if ( buffers.colors.length > 0 ) {
1801
+
1802
+ geo.setAttribute( 'color', new Float32BufferAttribute( buffers.colors, 3 ) );
1803
+
1804
+ }
1805
+
1806
+ if ( skeleton ) {
1807
+
1808
+ geo.setAttribute( 'skinIndex', new Uint16BufferAttribute( buffers.weightsIndices, 4 ) );
1809
+
1810
+ geo.setAttribute( 'skinWeight', new Float32BufferAttribute( buffers.vertexWeights, 4 ) );
1811
+
1812
+ // used later to bind the skeleton to the model
1813
+ geo.FBX_Deformer = skeleton;
1814
+
1815
+ }
1816
+
1817
+ if ( buffers.normal.length > 0 ) {
1818
+
1819
+ const normalMatrix = new Matrix3().getNormalMatrix( preTransform );
1820
+
1821
+ const normalAttribute = new Float32BufferAttribute( buffers.normal, 3 );
1822
+ normalAttribute.applyNormalMatrix( normalMatrix );
1823
+
1824
+ geo.setAttribute( 'normal', normalAttribute );
1825
+
1826
+ }
1827
+
1828
+ buffers.uvs.forEach( function ( uvBuffer, i ) {
1829
+
1830
+ const name = i === 0 ? 'uv' : `uv${ i }`;
1831
+
1832
+ geo.setAttribute( name, new Float32BufferAttribute( buffers.uvs[ i ], 2 ) );
1833
+
1834
+ } );
1835
+
1836
+ if ( geoInfo.material && geoInfo.material.mappingType !== 'AllSame' ) {
1837
+
1838
+ // Convert the material indices of each vertex into rendering groups on the geometry.
1839
+ let prevMaterialIndex = buffers.materialIndex[ 0 ];
1840
+ let startIndex = 0;
1841
+
1842
+ buffers.materialIndex.forEach( function ( currentIndex, i ) {
1843
+
1844
+ if ( currentIndex !== prevMaterialIndex ) {
1845
+
1846
+ geo.addGroup( startIndex, i - startIndex, prevMaterialIndex );
1847
+
1848
+ prevMaterialIndex = currentIndex;
1849
+ startIndex = i;
1850
+
1851
+ }
1852
+
1853
+ } );
1854
+
1855
+ // the loop above doesn't add the last group, do that here.
1856
+ if ( geo.groups.length > 0 ) {
1857
+
1858
+ const lastGroup = geo.groups[ geo.groups.length - 1 ];
1859
+ const lastIndex = lastGroup.start + lastGroup.count;
1860
+
1861
+ if ( lastIndex !== buffers.materialIndex.length ) {
1862
+
1863
+ geo.addGroup( lastIndex, buffers.materialIndex.length - lastIndex, prevMaterialIndex );
1864
+
1865
+ }
1866
+
1867
+ }
1868
+
1869
+ // case where there are multiple materials but the whole geometry is only
1870
+ // using one of them
1871
+ if ( geo.groups.length === 0 ) {
1872
+
1873
+ geo.addGroup( 0, buffers.materialIndex.length, buffers.materialIndex[ 0 ] );
1874
+
1875
+ }
1876
+
1877
+ }
1878
+
1879
+ this.addMorphTargets( geo, geoNode, morphTargets, preTransform );
1880
+
1881
+ return geo;
1882
+
1883
+ }
1884
+
1885
+ parseGeoNode( geoNode, skeleton ) {
1886
+
1887
+ const geoInfo = {};
1888
+
1889
+ geoInfo.vertexPositions = ( geoNode.Vertices !== undefined ) ? geoNode.Vertices.a : [];
1890
+ geoInfo.vertexIndices = ( geoNode.PolygonVertexIndex !== undefined ) ? geoNode.PolygonVertexIndex.a : [];
1891
+
1892
+ if ( geoNode.LayerElementColor && geoNode.LayerElementColor[ 0 ].Colors ) {
1893
+
1894
+ geoInfo.color = this.parseVertexColors( geoNode.LayerElementColor[ 0 ] );
1895
+
1896
+ }
1897
+
1898
+ if ( geoNode.LayerElementMaterial ) {
1899
+
1900
+ geoInfo.material = this.parseMaterialIndices( geoNode.LayerElementMaterial[ 0 ] );
1901
+
1902
+ }
1903
+
1904
+ if ( geoNode.LayerElementNormal ) {
1905
+
1906
+ geoInfo.normal = this.parseNormals( geoNode.LayerElementNormal[ 0 ] );
1907
+
1908
+ }
1909
+
1910
+ if ( geoNode.LayerElementUV ) {
1911
+
1912
+ geoInfo.uv = [];
1913
+
1914
+ let i = 0;
1915
+ while ( geoNode.LayerElementUV[ i ] ) {
1916
+
1917
+ if ( geoNode.LayerElementUV[ i ].UV ) {
1918
+
1919
+ geoInfo.uv.push( this.parseUVs( geoNode.LayerElementUV[ i ] ) );
1920
+
1921
+ }
1922
+
1923
+ i ++;
1924
+
1925
+ }
1926
+
1927
+ }
1928
+
1929
+ geoInfo.weightTable = {};
1930
+
1931
+ if ( skeleton !== null ) {
1932
+
1933
+ geoInfo.skeleton = skeleton;
1934
+
1935
+ skeleton.rawBones.forEach( function ( rawBone, i ) {
1936
+
1937
+ // loop over the bone's vertex indices and weights
1938
+ rawBone.indices.forEach( function ( index, j ) {
1939
+
1940
+ if ( geoInfo.weightTable[ index ] === undefined ) geoInfo.weightTable[ index ] = [];
1941
+
1942
+ geoInfo.weightTable[ index ].push( {
1943
+
1944
+ id: i,
1945
+ weight: rawBone.weights[ j ],
1946
+
1947
+ } );
1948
+
1949
+ } );
1950
+
1951
+ } );
1952
+
1953
+ }
1954
+
1955
+ return geoInfo;
1956
+
1957
+ }
1958
+
1959
+ genBuffers( geoInfo ) {
1960
+
1961
+ const buffers = {
1962
+ vertex: [],
1963
+ normal: [],
1964
+ colors: [],
1965
+ uvs: [],
1966
+ materialIndex: [],
1967
+ vertexWeights: [],
1968
+ weightsIndices: [],
1969
+ };
1970
+
1971
+ let polygonIndex = 0;
1972
+ let faceLength = 0;
1973
+ let displayedWeightsWarning = false;
1974
+
1975
+ // these will hold data for a single face
1976
+ let facePositionIndexes = [];
1977
+ let faceNormals = [];
1978
+ let faceColors = [];
1979
+ let faceUVs = [];
1980
+ let faceWeights = [];
1981
+ let faceWeightIndices = [];
1982
+
1983
+ const scope = this;
1984
+ geoInfo.vertexIndices.forEach( function ( vertexIndex, polygonVertexIndex ) {
1985
+
1986
+ let materialIndex;
1987
+ let endOfFace = false;
1988
+
1989
+ // Face index and vertex index arrays are combined in a single array
1990
+ // A cube with quad faces looks like this:
1991
+ // PolygonVertexIndex: *24 {
1992
+ // a: 0, 1, 3, -3, 2, 3, 5, -5, 4, 5, 7, -7, 6, 7, 1, -1, 1, 7, 5, -4, 6, 0, 2, -5
1993
+ // }
1994
+ // Negative numbers mark the end of a face - first face here is 0, 1, 3, -3
1995
+ // to find index of last vertex bit shift the index: ^ - 1
1996
+ if ( vertexIndex < 0 ) {
1997
+
1998
+ vertexIndex = vertexIndex ^ - 1; // equivalent to ( x * -1 ) - 1
1999
+ endOfFace = true;
2000
+
2001
+ }
2002
+
2003
+ let weightIndices = [];
2004
+ let weights = [];
2005
+
2006
+ facePositionIndexes.push( vertexIndex * 3, vertexIndex * 3 + 1, vertexIndex * 3 + 2 );
2007
+
2008
+ if ( geoInfo.color ) {
2009
+
2010
+ const data = getData( polygonVertexIndex, polygonIndex, vertexIndex, geoInfo.color );
2011
+
2012
+ faceColors.push( data[ 0 ], data[ 1 ], data[ 2 ] );
2013
+
2014
+ }
2015
+
2016
+ if ( geoInfo.skeleton ) {
2017
+
2018
+ if ( geoInfo.weightTable[ vertexIndex ] !== undefined ) {
2019
+
2020
+ geoInfo.weightTable[ vertexIndex ].forEach( function ( wt ) {
2021
+
2022
+ weights.push( wt.weight );
2023
+ weightIndices.push( wt.id );
2024
+
2025
+ } );
2026
+
2027
+
2028
+ }
2029
+
2030
+ if ( weights.length > 4 ) {
2031
+
2032
+ if ( ! displayedWeightsWarning ) {
2033
+
2034
+ console.warn( 'THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights.' );
2035
+ displayedWeightsWarning = true;
2036
+
2037
+ }
2038
+
2039
+ const wIndex = [ 0, 0, 0, 0 ];
2040
+ const Weight = [ 0, 0, 0, 0 ];
2041
+
2042
+ weights.forEach( function ( weight, weightIndex ) {
2043
+
2044
+ let currentWeight = weight;
2045
+ let currentIndex = weightIndices[ weightIndex ];
2046
+
2047
+ Weight.forEach( function ( comparedWeight, comparedWeightIndex, comparedWeightArray ) {
2048
+
2049
+ if ( currentWeight > comparedWeight ) {
2050
+
2051
+ comparedWeightArray[ comparedWeightIndex ] = currentWeight;
2052
+ currentWeight = comparedWeight;
2053
+
2054
+ const tmp = wIndex[ comparedWeightIndex ];
2055
+ wIndex[ comparedWeightIndex ] = currentIndex;
2056
+ currentIndex = tmp;
2057
+
2058
+ }
2059
+
2060
+ } );
2061
+
2062
+ } );
2063
+
2064
+ weightIndices = wIndex;
2065
+ weights = Weight;
2066
+
2067
+ }
2068
+
2069
+ // if the weight array is shorter than 4 pad with 0s
2070
+ while ( weights.length < 4 ) {
2071
+
2072
+ weights.push( 0 );
2073
+ weightIndices.push( 0 );
2074
+
2075
+ }
2076
+
2077
+ for ( let i = 0; i < 4; ++ i ) {
2078
+
2079
+ faceWeights.push( weights[ i ] );
2080
+ faceWeightIndices.push( weightIndices[ i ] );
2081
+
2082
+ }
2083
+
2084
+ }
2085
+
2086
+ if ( geoInfo.normal ) {
2087
+
2088
+ const data = getData( polygonVertexIndex, polygonIndex, vertexIndex, geoInfo.normal );
2089
+
2090
+ faceNormals.push( data[ 0 ], data[ 1 ], data[ 2 ] );
2091
+
2092
+ }
2093
+
2094
+ if ( geoInfo.material && geoInfo.material.mappingType !== 'AllSame' ) {
2095
+
2096
+ materialIndex = getData( polygonVertexIndex, polygonIndex, vertexIndex, geoInfo.material )[ 0 ];
2097
+
2098
+ if ( materialIndex < 0 ) {
2099
+
2100
+ scope.negativeMaterialIndices = true;
2101
+ materialIndex = 0; // fallback
2102
+
2103
+ }
2104
+
2105
+ }
2106
+
2107
+ if ( geoInfo.uv ) {
2108
+
2109
+ geoInfo.uv.forEach( function ( uv, i ) {
2110
+
2111
+ const data = getData( polygonVertexIndex, polygonIndex, vertexIndex, uv );
2112
+
2113
+ if ( faceUVs[ i ] === undefined ) {
2114
+
2115
+ faceUVs[ i ] = [];
2116
+
2117
+ }
2118
+
2119
+ faceUVs[ i ].push( data[ 0 ] );
2120
+ faceUVs[ i ].push( data[ 1 ] );
2121
+
2122
+ } );
2123
+
2124
+ }
2125
+
2126
+ faceLength ++;
2127
+
2128
+ if ( endOfFace ) {
2129
+
2130
+ scope.genFace( buffers, geoInfo, facePositionIndexes, materialIndex, faceNormals, faceColors, faceUVs, faceWeights, faceWeightIndices, faceLength );
2131
+
2132
+ polygonIndex ++;
2133
+ faceLength = 0;
2134
+
2135
+ // reset arrays for the next face
2136
+ facePositionIndexes = [];
2137
+ faceNormals = [];
2138
+ faceColors = [];
2139
+ faceUVs = [];
2140
+ faceWeights = [];
2141
+ faceWeightIndices = [];
2142
+
2143
+ }
2144
+
2145
+ } );
2146
+
2147
+ return buffers;
2148
+
2149
+ }
2150
+
2151
+ // See https://www.khronos.org/opengl/wiki/Calculating_a_Surface_Normal
2152
+ getNormalNewell( vertices ) {
2153
+
2154
+ const normal = new Vector3( 0.0, 0.0, 0.0 );
2155
+
2156
+ for ( let i = 0; i < vertices.length; i ++ ) {
2157
+
2158
+ const current = vertices[ i ];
2159
+ const next = vertices[ ( i + 1 ) % vertices.length ];
2160
+
2161
+ normal.x += ( current.y - next.y ) * ( current.z + next.z );
2162
+ normal.y += ( current.z - next.z ) * ( current.x + next.x );
2163
+ normal.z += ( current.x - next.x ) * ( current.y + next.y );
2164
+
2165
+ }
2166
+
2167
+ normal.normalize();
2168
+
2169
+ return normal;
2170
+
2171
+ }
2172
+
2173
+ getNormalTangentAndBitangent( vertices ) {
2174
+
2175
+ const normalVector = this.getNormalNewell( vertices );
2176
+ // Avoid up being equal or almost equal to normalVector
2177
+ const up = Math.abs( normalVector.z ) > 0.5 ? new Vector3( 0.0, 1.0, 0.0 ) : new Vector3( 0.0, 0.0, 1.0 );
2178
+ const tangent = up.cross( normalVector ).normalize();
2179
+ const bitangent = normalVector.clone().cross( tangent ).normalize();
2180
+
2181
+ return {
2182
+ normal: normalVector,
2183
+ tangent: tangent,
2184
+ bitangent: bitangent
2185
+ };
2186
+
2187
+ }
2188
+
2189
+ flattenVertex( vertex, normalTangent, normalBitangent ) {
2190
+
2191
+ return new Vector2(
2192
+ vertex.dot( normalTangent ),
2193
+ vertex.dot( normalBitangent )
2194
+ );
2195
+
2196
+ }
2197
+
2198
+ // Generate data for a single face in a geometry. If the face is a quad then split it into 2 tris
2199
+ genFace( buffers, geoInfo, facePositionIndexes, materialIndex, faceNormals, faceColors, faceUVs, faceWeights, faceWeightIndices, faceLength ) {
2200
+
2201
+ let triangles;
2202
+
2203
+ if ( faceLength > 3 ) {
2204
+
2205
+ // Triangulate n-gon using earcut
2206
+
2207
+ const vertices = [];
2208
+ // in morphing scenario vertexPositions represent morphPositions
2209
+ // while baseVertexPositions represent the original geometry's positions
2210
+ const positions = geoInfo.baseVertexPositions || geoInfo.vertexPositions;
2211
+ for ( let i = 0; i < facePositionIndexes.length; i += 3 ) {
2212
+
2213
+ vertices.push(
2214
+ new Vector3(
2215
+ positions[ facePositionIndexes[ i ] ],
2216
+ positions[ facePositionIndexes[ i + 1 ] ],
2217
+ positions[ facePositionIndexes[ i + 2 ] ]
2218
+ )
2219
+ );
2220
+
2221
+ }
2222
+
2223
+ const { tangent, bitangent } = this.getNormalTangentAndBitangent( vertices );
2224
+ const triangulationInput = [];
2225
+
2226
+ for ( const vertex of vertices ) {
2227
+
2228
+ triangulationInput.push( this.flattenVertex( vertex, tangent, bitangent ) );
2229
+
2230
+ }
2231
+
2232
+ // When vertices is an array of [0,0,0] elements (which is the case for vertices not participating in morph)
2233
+ // the triangulationInput will be an array of [0,0] elements
2234
+ // resulting in an array of 0 triangles being returned from ShapeUtils.triangulateShape
2235
+ // leading to not pushing into buffers.vertex the redundant vertices (the vertices that are not morphed).
2236
+ // That's why, in order to support morphing scenario, "positions" is looking first for baseVertexPositions,
2237
+ // so that we don't end up with an array of 0 triangles for the faces not participating in morph.
2238
+ triangles = ShapeUtils.triangulateShape( triangulationInput, [] );
2239
+
2240
+ } else {
2241
+
2242
+ // Regular triangle, skip earcut triangulation step
2243
+ triangles = [[ 0, 1, 2 ]];
2244
+
2245
+ }
2246
+
2247
+ for ( const [ i0, i1, i2 ] of triangles ) {
2248
+
2249
+ buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ i0 * 3 ] ] );
2250
+ buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ i0 * 3 + 1 ] ] );
2251
+ buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ i0 * 3 + 2 ] ] );
2252
+
2253
+ buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ i1 * 3 ] ] );
2254
+ buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ i1 * 3 + 1 ] ] );
2255
+ buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ i1 * 3 + 2 ] ] );
2256
+
2257
+ buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ i2 * 3 ] ] );
2258
+ buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ i2 * 3 + 1 ] ] );
2259
+ buffers.vertex.push( geoInfo.vertexPositions[ facePositionIndexes[ i2 * 3 + 2 ] ] );
2260
+
2261
+ if ( geoInfo.skeleton ) {
2262
+
2263
+ buffers.vertexWeights.push( faceWeights[ i0 * 4 ] );
2264
+ buffers.vertexWeights.push( faceWeights[ i0 * 4 + 1 ] );
2265
+ buffers.vertexWeights.push( faceWeights[ i0 * 4 + 2 ] );
2266
+ buffers.vertexWeights.push( faceWeights[ i0 * 4 + 3 ] );
2267
+
2268
+ buffers.vertexWeights.push( faceWeights[ i1 * 4 ] );
2269
+ buffers.vertexWeights.push( faceWeights[ i1 * 4 + 1 ] );
2270
+ buffers.vertexWeights.push( faceWeights[ i1 * 4 + 2 ] );
2271
+ buffers.vertexWeights.push( faceWeights[ i1 * 4 + 3 ] );
2272
+
2273
+ buffers.vertexWeights.push( faceWeights[ i2 * 4 ] );
2274
+ buffers.vertexWeights.push( faceWeights[ i2 * 4 + 1 ] );
2275
+ buffers.vertexWeights.push( faceWeights[ i2 * 4 + 2 ] );
2276
+ buffers.vertexWeights.push( faceWeights[ i2 * 4 + 3 ] );
2277
+
2278
+ buffers.weightsIndices.push( faceWeightIndices[ i0 * 4 ] );
2279
+ buffers.weightsIndices.push( faceWeightIndices[ i0 * 4 + 1 ] );
2280
+ buffers.weightsIndices.push( faceWeightIndices[ i0 * 4 + 2 ] );
2281
+ buffers.weightsIndices.push( faceWeightIndices[ i0 * 4 + 3 ] );
2282
+
2283
+ buffers.weightsIndices.push( faceWeightIndices[ i1 * 4 ] );
2284
+ buffers.weightsIndices.push( faceWeightIndices[ i1 * 4 + 1 ] );
2285
+ buffers.weightsIndices.push( faceWeightIndices[ i1 * 4 + 2 ] );
2286
+ buffers.weightsIndices.push( faceWeightIndices[ i1 * 4 + 3 ] );
2287
+
2288
+ buffers.weightsIndices.push( faceWeightIndices[ i2 * 4 ] );
2289
+ buffers.weightsIndices.push( faceWeightIndices[ i2 * 4 + 1 ] );
2290
+ buffers.weightsIndices.push( faceWeightIndices[ i2 * 4 + 2 ] );
2291
+ buffers.weightsIndices.push( faceWeightIndices[ i2 * 4 + 3 ] );
2292
+
2293
+ }
2294
+
2295
+ if ( geoInfo.color ) {
2296
+
2297
+ buffers.colors.push( faceColors[ i0 * 3 ] );
2298
+ buffers.colors.push( faceColors[ i0 * 3 + 1 ] );
2299
+ buffers.colors.push( faceColors[ i0 * 3 + 2 ] );
2300
+
2301
+ buffers.colors.push( faceColors[ i1 * 3 ] );
2302
+ buffers.colors.push( faceColors[ i1 * 3 + 1 ] );
2303
+ buffers.colors.push( faceColors[ i1 * 3 + 2 ] );
2304
+
2305
+ buffers.colors.push( faceColors[ i2 * 3 ] );
2306
+ buffers.colors.push( faceColors[ i2 * 3 + 1 ] );
2307
+ buffers.colors.push( faceColors[ i2 * 3 + 2 ] );
2308
+
2309
+ }
2310
+
2311
+ if ( geoInfo.material && geoInfo.material.mappingType !== 'AllSame' ) {
2312
+
2313
+ buffers.materialIndex.push( materialIndex );
2314
+ buffers.materialIndex.push( materialIndex );
2315
+ buffers.materialIndex.push( materialIndex );
2316
+
2317
+ }
2318
+
2319
+ if ( geoInfo.normal ) {
2320
+
2321
+ buffers.normal.push( faceNormals[ i0 * 3 ] );
2322
+ buffers.normal.push( faceNormals[ i0 * 3 + 1 ] );
2323
+ buffers.normal.push( faceNormals[ i0 * 3 + 2 ] );
2324
+
2325
+ buffers.normal.push( faceNormals[ i1 * 3 ] );
2326
+ buffers.normal.push( faceNormals[ i1 * 3 + 1 ] );
2327
+ buffers.normal.push( faceNormals[ i1 * 3 + 2 ] );
2328
+
2329
+ buffers.normal.push( faceNormals[ i2 * 3 ] );
2330
+ buffers.normal.push( faceNormals[ i2 * 3 + 1 ] );
2331
+ buffers.normal.push( faceNormals[ i2 * 3 + 2 ] );
2332
+
2333
+ }
2334
+
2335
+ if ( geoInfo.uv ) {
2336
+
2337
+ geoInfo.uv.forEach( function ( uv, j ) {
2338
+
2339
+ if ( buffers.uvs[ j ] === undefined ) buffers.uvs[ j ] = [];
2340
+
2341
+ buffers.uvs[ j ].push( faceUVs[ j ][ i0 * 2 ] );
2342
+ buffers.uvs[ j ].push( faceUVs[ j ][ i0 * 2 + 1 ] );
2343
+
2344
+ buffers.uvs[ j ].push( faceUVs[ j ][ i1 * 2 ] );
2345
+ buffers.uvs[ j ].push( faceUVs[ j ][ i1 * 2 + 1 ] );
2346
+
2347
+ buffers.uvs[ j ].push( faceUVs[ j ][ i2 * 2 ] );
2348
+ buffers.uvs[ j ].push( faceUVs[ j ][ i2 * 2 + 1 ] );
2349
+
2350
+ } );
2351
+
2352
+ }
2353
+
2354
+ }
2355
+
2356
+ }
2357
+
2358
+ addMorphTargets( parentGeo, parentGeoNode, morphTargets, preTransform ) {
2359
+
2360
+ if ( morphTargets.length === 0 ) return;
2361
+
2362
+ parentGeo.morphTargetsRelative = true;
2363
+
2364
+ parentGeo.morphAttributes.position = [];
2365
+ // parentGeo.morphAttributes.normal = []; // not implemented
2366
+
2367
+ // Morph attribute positions are stored as deltas (morphTargetsRelative = true), so the
2368
+ // translation component of the geometric transform must not be applied to them — only the
2369
+ // rotation/scale part. Otherwise every delta gets the geometric translation added, which
2370
+ // shifts morphed vertices away from their intended position by `weight * translation` as
2371
+ // the influence increases.
2372
+ const morphPreTransform = preTransform.clone().setPosition( 0, 0, 0 );
2373
+
2374
+ const scope = this;
2375
+ morphTargets.forEach( function ( morphTarget ) {
2376
+
2377
+ morphTarget.rawTargets.forEach( function ( rawTarget ) {
2378
+
2379
+ const morphGeoNode = fbxTree.Objects.Geometry[ rawTarget.geoID ];
2380
+
2381
+ if ( morphGeoNode !== undefined ) {
2382
+
2383
+ scope.genMorphGeometry( parentGeo, parentGeoNode, morphGeoNode, morphPreTransform, rawTarget.name );
2384
+
2385
+ }
2386
+
2387
+ } );
2388
+
2389
+ } );
2390
+
2391
+ }
2392
+
2393
+ // a morph geometry node is similar to a standard node, and the node is also contained
2394
+ // in FBXTree.Objects.Geometry, however it can only have attributes for position, normal
2395
+ // and a special attribute Index defining which vertices of the original geometry are affected
2396
+ // Normal and position attributes only have data for the vertices that are affected by the morph
2397
+ genMorphGeometry( parentGeo, parentGeoNode, morphGeoNode, preTransform, name ) {
2398
+
2399
+ const basePositions = parentGeoNode.Vertices !== undefined ? parentGeoNode.Vertices.a : [];
2400
+ const baseIndices = parentGeoNode.PolygonVertexIndex !== undefined ? parentGeoNode.PolygonVertexIndex.a : [];
2401
+
2402
+ const morphPositionsSparse = morphGeoNode.Vertices !== undefined ? morphGeoNode.Vertices.a : [];
2403
+ const morphIndices = morphGeoNode.Indexes !== undefined ? morphGeoNode.Indexes.a : [];
2404
+
2405
+ const length = parentGeo.attributes.position.count * 3;
2406
+ const morphPositions = new Float32Array( length );
2407
+
2408
+ for ( let i = 0; i < morphIndices.length; i ++ ) {
2409
+
2410
+ const morphIndex = morphIndices[ i ] * 3;
2411
+
2412
+ morphPositions[ morphIndex ] = morphPositionsSparse[ i * 3 ];
2413
+ morphPositions[ morphIndex + 1 ] = morphPositionsSparse[ i * 3 + 1 ];
2414
+ morphPositions[ morphIndex + 2 ] = morphPositionsSparse[ i * 3 + 2 ];
2415
+
2416
+ }
2417
+
2418
+ // TODO: add morph normal support
2419
+ const morphGeoInfo = {
2420
+ vertexIndices: baseIndices,
2421
+ vertexPositions: morphPositions,
2422
+ baseVertexPositions: basePositions
2423
+ };
2424
+
2425
+ const morphBuffers = this.genBuffers( morphGeoInfo );
2426
+
2427
+ const positionAttribute = new Float32BufferAttribute( morphBuffers.vertex, 3 );
2428
+ positionAttribute.name = name || morphGeoNode.attrName;
2429
+
2430
+ positionAttribute.applyMatrix4( preTransform );
2431
+
2432
+ parentGeo.morphAttributes.position.push( positionAttribute );
2433
+
2434
+ }
2435
+
2436
+ // Parse normal from FBXTree.Objects.Geometry.LayerElementNormal if it exists
2437
+ parseNormals( NormalNode ) {
2438
+
2439
+ const mappingType = NormalNode.MappingInformationType;
2440
+ const referenceType = NormalNode.ReferenceInformationType;
2441
+ const buffer = NormalNode.Normals.a;
2442
+ let indexBuffer = [];
2443
+ if ( referenceType === 'IndexToDirect' ) {
2444
+
2445
+ if ( 'NormalIndex' in NormalNode ) {
2446
+
2447
+ indexBuffer = NormalNode.NormalIndex.a;
2448
+
2449
+ } else if ( 'NormalsIndex' in NormalNode ) {
2450
+
2451
+ indexBuffer = NormalNode.NormalsIndex.a;
2452
+
2453
+ }
2454
+
2455
+ }
2456
+
2457
+ return {
2458
+ dataSize: 3,
2459
+ buffer: buffer,
2460
+ indices: indexBuffer,
2461
+ mappingType: mappingType,
2462
+ referenceType: referenceType
2463
+ };
2464
+
2465
+ }
2466
+
2467
+ // Parse UVs from FBXTree.Objects.Geometry.LayerElementUV if it exists
2468
+ parseUVs( UVNode ) {
2469
+
2470
+ const mappingType = UVNode.MappingInformationType;
2471
+ const referenceType = UVNode.ReferenceInformationType;
2472
+ const buffer = UVNode.UV.a;
2473
+ let indexBuffer = [];
2474
+ if ( referenceType === 'IndexToDirect' ) {
2475
+
2476
+ indexBuffer = UVNode.UVIndex.a;
2477
+
2478
+ }
2479
+
2480
+ return {
2481
+ dataSize: 2,
2482
+ buffer: buffer,
2483
+ indices: indexBuffer,
2484
+ mappingType: mappingType,
2485
+ referenceType: referenceType
2486
+ };
2487
+
2488
+ }
2489
+
2490
+ // Parse Vertex Colors from FBXTree.Objects.Geometry.LayerElementColor if it exists
2491
+ parseVertexColors( ColorNode ) {
2492
+
2493
+ const mappingType = ColorNode.MappingInformationType;
2494
+ const referenceType = ColorNode.ReferenceInformationType;
2495
+ const buffer = ColorNode.Colors.a;
2496
+ let indexBuffer = [];
2497
+ if ( referenceType === 'IndexToDirect' ) {
2498
+
2499
+ indexBuffer = ColorNode.ColorIndex.a;
2500
+
2501
+ }
2502
+
2503
+ for ( let i = 0, c = new Color(); i < buffer.length; i += 4 ) {
2504
+
2505
+ c.fromArray( buffer, i );
2506
+ ColorManagement.colorSpaceToWorking( c, SRGBColorSpace );
2507
+ c.toArray( buffer, i );
2508
+
2509
+ }
2510
+
2511
+ return {
2512
+ dataSize: 4,
2513
+ buffer: buffer,
2514
+ indices: indexBuffer,
2515
+ mappingType: mappingType,
2516
+ referenceType: referenceType
2517
+ };
2518
+
2519
+ }
2520
+
2521
+ // Parse mapping and material data in FBXTree.Objects.Geometry.LayerElementMaterial if it exists
2522
+ parseMaterialIndices( MaterialNode ) {
2523
+
2524
+ const mappingType = MaterialNode.MappingInformationType;
2525
+ const referenceType = MaterialNode.ReferenceInformationType;
2526
+
2527
+ if ( mappingType === 'NoMappingInformation' ) {
2528
+
2529
+ return {
2530
+ dataSize: 1,
2531
+ buffer: [ 0 ],
2532
+ indices: [ 0 ],
2533
+ mappingType: 'AllSame',
2534
+ referenceType: referenceType
2535
+ };
2536
+
2537
+ }
2538
+
2539
+ const materialIndexBuffer = MaterialNode.Materials.a;
2540
+
2541
+ // Since materials are stored as indices, there's a bit of a mismatch between FBX and what
2542
+ // we expect.So we create an intermediate buffer that points to the index in the buffer,
2543
+ // for conforming with the other functions we've written for other data.
2544
+ const materialIndices = [];
2545
+
2546
+ for ( let i = 0; i < materialIndexBuffer.length; ++ i ) {
2547
+
2548
+ materialIndices.push( i );
2549
+
2550
+ }
2551
+
2552
+ return {
2553
+ dataSize: 1,
2554
+ buffer: materialIndexBuffer,
2555
+ indices: materialIndices,
2556
+ mappingType: mappingType,
2557
+ referenceType: referenceType
2558
+ };
2559
+
2560
+ }
2561
+
2562
+ // Generate a NurbGeometry from a node in FBXTree.Objects.Geometry
2563
+ parseNurbsGeometry( geoNode ) {
2564
+
2565
+ const order = parseInt( geoNode.Order );
2566
+
2567
+ if ( isNaN( order ) ) {
2568
+
2569
+ console.error( 'THREE.FBXLoader: Invalid Order %s given for geometry ID: %s', geoNode.Order, geoNode.id );
2570
+ return new BufferGeometry();
2571
+
2572
+ }
2573
+
2574
+ const degree = order - 1;
2575
+
2576
+ const knots = geoNode.KnotVector.a;
2577
+ const controlPoints = [];
2578
+ const pointsValues = geoNode.Points.a;
2579
+
2580
+ for ( let i = 0, l = pointsValues.length; i < l; i += 4 ) {
2581
+
2582
+ controlPoints.push( new Vector4().fromArray( pointsValues, i ) );
2583
+
2584
+ }
2585
+
2586
+ let startKnot, endKnot;
2587
+
2588
+ if ( geoNode.Form === 'Closed' ) {
2589
+
2590
+ controlPoints.push( controlPoints[ 0 ] );
2591
+
2592
+ } else if ( geoNode.Form === 'Periodic' ) {
2593
+
2594
+ startKnot = degree;
2595
+ endKnot = knots.length - 1 - startKnot;
2596
+
2597
+ for ( let i = 0; i < degree; ++ i ) {
2598
+
2599
+ controlPoints.push( controlPoints[ i ] );
2600
+
2601
+ }
2602
+
2603
+ }
2604
+
2605
+ const curve = new NURBSCurve( degree, knots, controlPoints, startKnot, endKnot );
2606
+ const points = curve.getPoints( controlPoints.length * 12 );
2607
+
2608
+ return new BufferGeometry().setFromPoints( points );
2609
+
2610
+ }
2611
+
2612
+ }
2613
+
2614
+ // parse animation data from FBXTree
2615
+ class AnimationParser {
2616
+
2617
+ // take raw animation clips and turn them into three.js animation clips
2618
+ parse() {
2619
+
2620
+ const animationClips = [];
2621
+
2622
+ const rawClips = this.parseClips();
2623
+
2624
+ if ( rawClips !== undefined ) {
2625
+
2626
+ for ( const key in rawClips ) {
2627
+
2628
+ const rawClip = rawClips[ key ];
2629
+
2630
+ const clip = this.addClip( rawClip );
2631
+
2632
+ animationClips.push( clip );
2633
+
2634
+ }
2635
+
2636
+ }
2637
+
2638
+ return animationClips;
2639
+
2640
+ }
2641
+
2642
+ parseClips() {
2643
+
2644
+ // since the actual transformation data is stored in FBXTree.Objects.AnimationCurve,
2645
+ // if this is undefined we can safely assume there are no animations
2646
+ if ( fbxTree.Objects.AnimationCurve === undefined ) return undefined;
2647
+
2648
+ const curveNodesMap = this.parseAnimationCurveNodes();
2649
+
2650
+ this.parseAnimationCurves( curveNodesMap );
2651
+
2652
+ const layersMap = this.parseAnimationLayers( curveNodesMap );
2653
+ const rawClips = this.parseAnimStacks( layersMap );
2654
+
2655
+ return rawClips;
2656
+
2657
+ }
2658
+
2659
+ // parse nodes in FBXTree.Objects.AnimationCurveNode
2660
+ // each AnimationCurveNode holds data for an animation transform for a model (e.g. left arm rotation )
2661
+ // and is referenced by an AnimationLayer
2662
+ parseAnimationCurveNodes() {
2663
+
2664
+ const rawCurveNodes = fbxTree.Objects.AnimationCurveNode;
2665
+
2666
+ const curveNodesMap = new Map();
2667
+
2668
+ for ( const nodeID in rawCurveNodes ) {
2669
+
2670
+ const rawCurveNode = rawCurveNodes[ nodeID ];
2671
+
2672
+ if ( rawCurveNode.attrName.match( /S|R|T|DeformPercent/ ) !== null ) {
2673
+
2674
+ const curveNode = {
2675
+
2676
+ id: rawCurveNode.id,
2677
+ attr: rawCurveNode.attrName,
2678
+ curves: {},
2679
+
2680
+ };
2681
+
2682
+ curveNodesMap.set( curveNode.id, curveNode );
2683
+
2684
+ }
2685
+
2686
+ }
2687
+
2688
+ return curveNodesMap;
2689
+
2690
+ }
2691
+
2692
+ // parse nodes in FBXTree.Objects.AnimationCurve and connect them up to
2693
+ // previously parsed AnimationCurveNodes. Each AnimationCurve holds data for a single animated
2694
+ // axis ( e.g. times and values of x rotation)
2695
+ parseAnimationCurves( curveNodesMap ) {
2696
+
2697
+ const rawCurves = fbxTree.Objects.AnimationCurve;
2698
+
2699
+ // TODO: Many values are identical up to roundoff error, but won't be optimised
2700
+ // e.g. position times: [0, 0.4, 0. 8]
2701
+ // position values: [7.23538335023477e-7, 93.67518615722656, -0.9982695579528809, 7.23538335023477e-7, 93.67518615722656, -0.9982695579528809, 7.235384487103147e-7, 93.67520904541016, -0.9982695579528809]
2702
+ // clearly, this should be optimised to
2703
+ // times: [0], positions [7.23538335023477e-7, 93.67518615722656, -0.9982695579528809]
2704
+ // this shows up in nearly every FBX file, and generally time array is length > 100
2705
+
2706
+ for ( const nodeID in rawCurves ) {
2707
+
2708
+ const animationCurve = {
2709
+
2710
+ id: rawCurves[ nodeID ].id,
2711
+ times: rawCurves[ nodeID ].KeyTime.a.map( convertFBXTimeToSeconds ),
2712
+ values: rawCurves[ nodeID ].KeyValueFloat.a,
2713
+
2714
+ };
2715
+
2716
+ const relationships = connections.get( animationCurve.id );
2717
+
2718
+ if ( relationships !== undefined ) {
2719
+
2720
+ const animationCurveID = relationships.parents[ 0 ].ID;
2721
+ const animationCurveRelationship = relationships.parents[ 0 ].relationship;
2722
+
2723
+ if ( animationCurveRelationship.match( /X/ ) ) {
2724
+
2725
+ curveNodesMap.get( animationCurveID ).curves[ 'x' ] = animationCurve;
2726
+
2727
+ } else if ( animationCurveRelationship.match( /Y/ ) ) {
2728
+
2729
+ curveNodesMap.get( animationCurveID ).curves[ 'y' ] = animationCurve;
2730
+
2731
+ } else if ( animationCurveRelationship.match( /Z/ ) ) {
2732
+
2733
+ curveNodesMap.get( animationCurveID ).curves[ 'z' ] = animationCurve;
2734
+
2735
+ } else if ( animationCurveRelationship.match( /DeformPercent/ ) && curveNodesMap.has( animationCurveID ) ) {
2736
+
2737
+ curveNodesMap.get( animationCurveID ).curves[ 'morph' ] = animationCurve;
2738
+
2739
+ }
2740
+
2741
+ }
2742
+
2743
+ }
2744
+
2745
+ }
2746
+
2747
+ // parse nodes in FBXTree.Objects.AnimationLayer. Each layers holds references
2748
+ // to various AnimationCurveNodes and is referenced by an AnimationStack node
2749
+ // note: theoretically a stack can have multiple layers, however in practice there always seems to be one per stack
2750
+ parseAnimationLayers( curveNodesMap ) {
2751
+
2752
+ const rawLayers = fbxTree.Objects.AnimationLayer;
2753
+
2754
+ const layersMap = new Map();
2755
+
2756
+ for ( const nodeID in rawLayers ) {
2757
+
2758
+ const layerCurveNodes = [];
2759
+
2760
+ const connection = connections.get( parseInt( nodeID ) );
2761
+
2762
+ if ( connection !== undefined ) {
2763
+
2764
+ // all the animationCurveNodes used in the layer
2765
+ const children = connection.children;
2766
+
2767
+ children.forEach( function ( child, i ) {
2768
+
2769
+ if ( curveNodesMap.has( child.ID ) ) {
2770
+
2771
+ const curveNode = curveNodesMap.get( child.ID );
2772
+
2773
+ // check that the curves are defined for at least one axis, otherwise ignore the curveNode
2774
+ if ( curveNode.curves.x !== undefined || curveNode.curves.y !== undefined || curveNode.curves.z !== undefined ) {
2775
+
2776
+ if ( layerCurveNodes[ i ] === undefined ) {
2777
+
2778
+ const filteredParents = connections.get( child.ID ).parents.filter( function ( parent ) {
2779
+
2780
+ return parent.relationship !== undefined;
2781
+
2782
+ } );
2783
+
2784
+ if ( filteredParents.length === 0 ) return;
2785
+
2786
+ const modelID = filteredParents[ 0 ].ID;
2787
+
2788
+ if ( modelID !== undefined ) {
2789
+
2790
+ const rawModel = fbxTree.Objects.Model[ modelID.toString() ];
2791
+
2792
+ if ( rawModel === undefined ) {
2793
+
2794
+ console.warn( 'THREE.FBXLoader: Encountered a unused curve.', child );
2795
+ return;
2796
+
2797
+ }
2798
+
2799
+ const node = {
2800
+
2801
+ modelName: rawModel.attrName ? PropertyBinding.sanitizeNodeName( rawModel.attrName ) : '',
2802
+ ID: rawModel.id,
2803
+ initialPosition: [ 0, 0, 0 ],
2804
+ initialRotation: [ 0, 0, 0 ],
2805
+ initialScale: [ 1, 1, 1 ],
2806
+
2807
+ };
2808
+
2809
+ sceneGraph.traverse( function ( child ) {
2810
+
2811
+ if ( child.ID === rawModel.id ) {
2812
+
2813
+ node.transform = child.matrix;
2814
+
2815
+ if ( child.userData.transformData ) {
2816
+
2817
+ node.eulerOrder = child.userData.transformData.eulerOrder;
2818
+
2819
+ if ( child.userData.transformData.rotation ) node.initialRotation = child.userData.transformData.rotation;
2820
+
2821
+ }
2822
+
2823
+ }
2824
+
2825
+ } );
2826
+
2827
+ if ( ! node.transform ) node.transform = new Matrix4();
2828
+
2829
+ // if the animated model is pre rotated, we'll have to apply the pre rotations to every
2830
+ // animation value as well
2831
+ if ( 'PreRotation' in rawModel ) node.preRotation = rawModel.PreRotation.value;
2832
+ if ( 'PostRotation' in rawModel ) node.postRotation = rawModel.PostRotation.value;
2833
+
2834
+ layerCurveNodes[ i ] = node;
2835
+
2836
+ }
2837
+
2838
+ }
2839
+
2840
+ if ( layerCurveNodes[ i ] ) layerCurveNodes[ i ][ curveNode.attr ] = curveNode;
2841
+
2842
+ } else if ( curveNode.curves.morph !== undefined ) {
2843
+
2844
+ if ( layerCurveNodes[ i ] === undefined ) {
2845
+
2846
+ const filteredParents = connections.get( child.ID ).parents.filter( function ( parent ) {
2847
+
2848
+ return parent.relationship !== undefined;
2849
+
2850
+ } );
2851
+
2852
+ if ( filteredParents.length === 0 ) return;
2853
+
2854
+ const deformerID = filteredParents[ 0 ].ID;
2855
+
2856
+ const morpherID = connections.get( deformerID ).parents[ 0 ].ID;
2857
+ const geoID = connections.get( morpherID ).parents[ 0 ].ID;
2858
+
2859
+ // assuming geometry is not used in more than one model
2860
+ const modelID = connections.get( geoID ).parents[ 0 ].ID;
2861
+
2862
+ const rawModel = fbxTree.Objects.Model[ modelID ];
2863
+
2864
+ const node = {
2865
+
2866
+ modelName: rawModel.attrName ? PropertyBinding.sanitizeNodeName( rawModel.attrName ) : '',
2867
+ morphName: fbxTree.Objects.Deformer[ deformerID ].attrName,
2868
+
2869
+ };
2870
+
2871
+ layerCurveNodes[ i ] = node;
2872
+
2873
+ }
2874
+
2875
+ layerCurveNodes[ i ][ curveNode.attr ] = curveNode;
2876
+
2877
+ }
2878
+
2879
+ }
2880
+
2881
+ } );
2882
+
2883
+ layersMap.set( parseInt( nodeID ), layerCurveNodes );
2884
+
2885
+ }
2886
+
2887
+ }
2888
+
2889
+ return layersMap;
2890
+
2891
+ }
2892
+
2893
+ // parse nodes in FBXTree.Objects.AnimationStack. These are the top level node in the animation
2894
+ // hierarchy. Each Stack node will be used to create an AnimationClip
2895
+ parseAnimStacks( layersMap ) {
2896
+
2897
+ const rawStacks = fbxTree.Objects.AnimationStack;
2898
+
2899
+ // connect the stacks (clips) up to the layers
2900
+ const rawClips = {};
2901
+
2902
+ for ( const nodeID in rawStacks ) {
2903
+
2904
+ const children = connections.get( parseInt( nodeID ) ).children;
2905
+
2906
+ if ( children.length > 1 ) {
2907
+
2908
+ // it seems like stacks will always be associated with a single layer. But just in case there are files
2909
+ // where there are multiple layers per stack, we'll display a warning
2910
+ console.warn( 'THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.' );
2911
+
2912
+ }
2913
+
2914
+ const layer = layersMap.get( children[ 0 ].ID );
2915
+
2916
+ rawClips[ nodeID ] = {
2917
+
2918
+ name: rawStacks[ nodeID ].attrName,
2919
+ layer: layer,
2920
+
2921
+ };
2922
+
2923
+ }
2924
+
2925
+ return rawClips;
2926
+
2927
+ }
2928
+
2929
+ addClip( rawClip ) {
2930
+
2931
+ let tracks = [];
2932
+
2933
+ const scope = this;
2934
+ rawClip.layer.forEach( function ( rawTracks ) {
2935
+
2936
+ tracks = tracks.concat( scope.generateTracks( rawTracks ) );
2937
+
2938
+ } );
2939
+
2940
+ return new AnimationClip( rawClip.name, - 1, tracks );
2941
+
2942
+ }
2943
+
2944
+ generateTracks( rawTracks ) {
2945
+
2946
+ const tracks = [];
2947
+
2948
+ let initialPosition = new Vector3();
2949
+ let initialScale = new Vector3();
2950
+
2951
+ if ( rawTracks.transform ) rawTracks.transform.decompose( initialPosition, new Quaternion(), initialScale );
2952
+
2953
+ initialPosition = initialPosition.toArray();
2954
+ initialScale = initialScale.toArray();
2955
+
2956
+ if ( rawTracks.T !== undefined && Object.keys( rawTracks.T.curves ).length > 0 ) {
2957
+
2958
+ const positionTrack = this.generateVectorTrack( rawTracks.modelName, rawTracks.T.curves, initialPosition, 'position' );
2959
+ if ( positionTrack !== undefined ) tracks.push( positionTrack );
2960
+
2961
+ }
2962
+
2963
+ if ( rawTracks.R !== undefined && Object.keys( rawTracks.R.curves ).length > 0 ) {
2964
+
2965
+ const rotationTrack = this.generateRotationTrack( rawTracks.modelName, rawTracks.R.curves, rawTracks.preRotation, rawTracks.postRotation, rawTracks.eulerOrder, rawTracks.initialRotation );
2966
+ if ( rotationTrack !== undefined ) tracks.push( rotationTrack );
2967
+
2968
+ }
2969
+
2970
+ if ( rawTracks.S !== undefined && Object.keys( rawTracks.S.curves ).length > 0 ) {
2971
+
2972
+ const scaleTrack = this.generateVectorTrack( rawTracks.modelName, rawTracks.S.curves, initialScale, 'scale' );
2973
+ if ( scaleTrack !== undefined ) tracks.push( scaleTrack );
2974
+
2975
+ }
2976
+
2977
+ if ( rawTracks.DeformPercent !== undefined ) {
2978
+
2979
+ const morphTrack = this.generateMorphTrack( rawTracks );
2980
+ if ( morphTrack !== undefined ) tracks.push( morphTrack );
2981
+
2982
+ }
2983
+
2984
+ return tracks;
2985
+
2986
+ }
2987
+
2988
+ generateVectorTrack( modelName, curves, initialValue, type ) {
2989
+
2990
+ const times = this.getTimesForAllAxes( curves );
2991
+ const values = this.getKeyframeTrackValues( times, curves, initialValue );
2992
+
2993
+ return new VectorKeyframeTrack( modelName + '.' + type, times, values );
2994
+
2995
+ }
2996
+
2997
+ generateRotationTrack( modelName, curves, preRotation, postRotation, eulerOrder, initialRotation ) {
2998
+
2999
+ let times;
3000
+ let values;
3001
+
3002
+ if ( curves.x !== undefined || curves.y !== undefined || curves.z !== undefined ) {
3003
+
3004
+ // Get merged, sorted, unique times from all available curves
3005
+ const mergedTimes = this.getTimesForAllAxes( curves );
3006
+
3007
+ if ( mergedTimes.length > 0 ) {
3008
+
3009
+ const initialRot = initialRotation || [ 0, 0, 0 ];
3010
+
3011
+ // Synchronize all curves to the merged time array.
3012
+ // Missing axes are filled with constant values from the initial rotation (Lcl Rotation).
3013
+ // Existing curves at different times are linearly interpolated.
3014
+ const syncX = this.synchronizeCurve( curves.x, mergedTimes, initialRot[ 0 ] );
3015
+ const syncY = this.synchronizeCurve( curves.y, mergedTimes, initialRot[ 1 ] );
3016
+ const syncZ = this.synchronizeCurve( curves.z, mergedTimes, initialRot[ 2 ] );
3017
+
3018
+ const result = this.interpolateRotations( syncX, syncY, syncZ, eulerOrder );
3019
+
3020
+ times = result[ 0 ];
3021
+ values = result[ 1 ];
3022
+
3023
+ }
3024
+
3025
+ }
3026
+
3027
+ // For Maya models using "Joint Orient", Euler order only applies to rotation, not pre/post-rotations
3028
+ const defaultEulerOrder = getEulerOrder( 0 );
3029
+
3030
+ if ( preRotation !== undefined ) {
3031
+
3032
+ preRotation = preRotation.map( MathUtils.degToRad );
3033
+ preRotation.push( defaultEulerOrder );
3034
+
3035
+ preRotation = new Euler().fromArray( preRotation );
3036
+ preRotation = new Quaternion().setFromEuler( preRotation );
3037
+
3038
+ }
3039
+
3040
+ if ( postRotation !== undefined ) {
3041
+
3042
+ postRotation = postRotation.map( MathUtils.degToRad );
3043
+ postRotation.push( defaultEulerOrder );
3044
+
3045
+ postRotation = new Euler().fromArray( postRotation );
3046
+ postRotation = new Quaternion().setFromEuler( postRotation ).invert();
3047
+
3048
+ }
3049
+
3050
+ const quaternion = new Quaternion();
3051
+ const euler = new Euler();
3052
+
3053
+ const quaternionValues = [];
3054
+
3055
+ if ( ! values || ! times ) return undefined;
3056
+
3057
+ for ( let i = 0; i < values.length; i += 3 ) {
3058
+
3059
+ euler.set( values[ i ], values[ i + 1 ], values[ i + 2 ], eulerOrder );
3060
+ quaternion.setFromEuler( euler );
3061
+
3062
+ if ( preRotation !== undefined ) quaternion.premultiply( preRotation );
3063
+ if ( postRotation !== undefined ) quaternion.multiply( postRotation );
3064
+
3065
+ // Check unroll
3066
+ if ( i > 2 ) {
3067
+
3068
+ const prevQuat = new Quaternion().fromArray(
3069
+ quaternionValues,
3070
+ ( ( i - 3 ) / 3 ) * 4
3071
+ );
3072
+
3073
+ if ( prevQuat.dot( quaternion ) < 0 ) {
3074
+
3075
+ quaternion.set( - quaternion.x, - quaternion.y, - quaternion.z, - quaternion.w );
3076
+
3077
+ }
3078
+
3079
+ }
3080
+
3081
+ quaternion.toArray( quaternionValues, ( i / 3 ) * 4 );
3082
+
3083
+ }
3084
+
3085
+ return new QuaternionKeyframeTrack( modelName + '.quaternion', times, quaternionValues );
3086
+
3087
+ }
3088
+
3089
+ generateMorphTrack( rawTracks ) {
3090
+
3091
+ const curves = rawTracks.DeformPercent.curves.morph;
3092
+ const values = curves.values.map( function ( val ) {
3093
+
3094
+ return val / 100;
3095
+
3096
+ } );
3097
+
3098
+ const morphNum = sceneGraph.getObjectByName( rawTracks.modelName ).morphTargetDictionary[ rawTracks.morphName ];
3099
+
3100
+ return new NumberKeyframeTrack( rawTracks.modelName + '.morphTargetInfluences[' + morphNum + ']', curves.times, values );
3101
+
3102
+ }
3103
+
3104
+ // For all animated objects, times are defined separately for each axis
3105
+ // Here we'll combine the times into one sorted array without duplicates
3106
+ getTimesForAllAxes( curves ) {
3107
+
3108
+ let times = [];
3109
+
3110
+ // first join together the times for each axis, if defined
3111
+ if ( curves.x !== undefined ) times = times.concat( curves.x.times );
3112
+ if ( curves.y !== undefined ) times = times.concat( curves.y.times );
3113
+ if ( curves.z !== undefined ) times = times.concat( curves.z.times );
3114
+
3115
+ // then sort them
3116
+ times = times.sort( function ( a, b ) {
3117
+
3118
+ return a - b;
3119
+
3120
+ } );
3121
+
3122
+ // and remove duplicates
3123
+ if ( times.length > 1 ) {
3124
+
3125
+ let targetIndex = 1;
3126
+ let lastValue = times[ 0 ];
3127
+ for ( let i = 1; i < times.length; i ++ ) {
3128
+
3129
+ const currentValue = times[ i ];
3130
+ if ( currentValue !== lastValue ) {
3131
+
3132
+ times[ targetIndex ] = currentValue;
3133
+ lastValue = currentValue;
3134
+ targetIndex ++;
3135
+
3136
+ }
3137
+
3138
+ }
3139
+
3140
+ times = times.slice( 0, targetIndex );
3141
+
3142
+ }
3143
+
3144
+ return times;
3145
+
3146
+ }
3147
+
3148
+ getKeyframeTrackValues( times, curves, initialValue ) {
3149
+
3150
+ const prevValue = initialValue;
3151
+
3152
+ const values = [];
3153
+
3154
+ let xIndex = - 1;
3155
+ let yIndex = - 1;
3156
+ let zIndex = - 1;
3157
+
3158
+ times.forEach( function ( time ) {
3159
+
3160
+ if ( curves.x ) xIndex = curves.x.times.indexOf( time );
3161
+ if ( curves.y ) yIndex = curves.y.times.indexOf( time );
3162
+ if ( curves.z ) zIndex = curves.z.times.indexOf( time );
3163
+
3164
+ // if there is an x value defined for this frame, use that
3165
+ if ( xIndex !== - 1 ) {
3166
+
3167
+ const xValue = curves.x.values[ xIndex ];
3168
+ values.push( xValue );
3169
+ prevValue[ 0 ] = xValue;
3170
+
3171
+ } else {
3172
+
3173
+ // otherwise use the x value from the previous frame
3174
+ values.push( prevValue[ 0 ] );
3175
+
3176
+ }
3177
+
3178
+ if ( yIndex !== - 1 ) {
3179
+
3180
+ const yValue = curves.y.values[ yIndex ];
3181
+ values.push( yValue );
3182
+ prevValue[ 1 ] = yValue;
3183
+
3184
+ } else {
3185
+
3186
+ values.push( prevValue[ 1 ] );
3187
+
3188
+ }
3189
+
3190
+ if ( zIndex !== - 1 ) {
3191
+
3192
+ const zValue = curves.z.values[ zIndex ];
3193
+ values.push( zValue );
3194
+ prevValue[ 2 ] = zValue;
3195
+
3196
+ } else {
3197
+
3198
+ values.push( prevValue[ 2 ] );
3199
+
3200
+ }
3201
+
3202
+ } );
3203
+
3204
+ return values;
3205
+
3206
+ }
3207
+
3208
+ // Synchronize a curve to a target time array using linear interpolation.
3209
+ // If the curve is undefined (axis not animated), returns constant values from initialValue.
3210
+ synchronizeCurve( curve, targetTimes, initialValue ) {
3211
+
3212
+ if ( curve === undefined ) {
3213
+
3214
+ return { times: targetTimes, values: targetTimes.map( () => initialValue ) };
3215
+
3216
+ }
3217
+
3218
+ // If the curve already has the same number of keyframes as the target, assume times match
3219
+ if ( curve.times.length === targetTimes.length ) return curve;
3220
+
3221
+ // Linearly interpolate curve values at each target time
3222
+ const values = [];
3223
+
3224
+ for ( let i = 0; i < targetTimes.length; i ++ ) {
3225
+
3226
+ values.push( this.sampleCurveValue( curve, targetTimes[ i ], initialValue ) );
3227
+
3228
+ }
3229
+
3230
+ return { times: targetTimes, values: values };
3231
+
3232
+ }
3233
+
3234
+ // Sample a single value from a curve at a given time using linear interpolation
3235
+ sampleCurveValue( curve, time, initialValue ) {
3236
+
3237
+ const times = curve.times;
3238
+ const values = curve.values;
3239
+
3240
+ // Before first keyframe
3241
+ if ( time <= times[ 0 ] ) return values[ 0 ];
3242
+
3243
+ // After last keyframe
3244
+ if ( time >= times[ times.length - 1 ] ) return values[ values.length - 1 ];
3245
+
3246
+ // Find surrounding keyframes and linearly interpolate
3247
+ for ( let i = 0; i < times.length - 1; i ++ ) {
3248
+
3249
+ if ( time >= times[ i ] && time <= times[ i + 1 ] ) {
3250
+
3251
+ if ( times[ i ] === time ) return values[ i ];
3252
+
3253
+ const alpha = ( time - times[ i ] ) / ( times[ i + 1 ] - times[ i ] );
3254
+ return values[ i ] * ( 1 - alpha ) + values[ i + 1 ] * alpha;
3255
+
3256
+ }
3257
+
3258
+ }
3259
+
3260
+ return initialValue;
3261
+
3262
+ }
3263
+
3264
+ // Rotations are defined as Euler angles which can have values of any size
3265
+ // These will be converted to quaternions which don't support values greater than
3266
+ // PI, so we'll interpolate large rotations
3267
+ interpolateRotations( curvex, curvey, curvez, eulerOrder ) {
3268
+
3269
+ const times = [];
3270
+ const values = [];
3271
+
3272
+ // Add first frame
3273
+ times.push( curvex.times[ 0 ] );
3274
+ values.push( MathUtils.degToRad( curvex.values[ 0 ] ) );
3275
+ values.push( MathUtils.degToRad( curvey.values[ 0 ] ) );
3276
+ values.push( MathUtils.degToRad( curvez.values[ 0 ] ) );
3277
+
3278
+ for ( let i = 1; i < curvex.values.length; i ++ ) {
3279
+
3280
+ const initialValue = [
3281
+ curvex.values[ i - 1 ],
3282
+ curvey.values[ i - 1 ],
3283
+ curvez.values[ i - 1 ],
3284
+ ];
3285
+
3286
+ if ( isNaN( initialValue[ 0 ] ) || isNaN( initialValue[ 1 ] ) || isNaN( initialValue[ 2 ] ) ) {
3287
+
3288
+ continue;
3289
+
3290
+ }
3291
+
3292
+ const initialValueRad = initialValue.map( MathUtils.degToRad );
3293
+
3294
+ const currentValue = [
3295
+ curvex.values[ i ],
3296
+ curvey.values[ i ],
3297
+ curvez.values[ i ],
3298
+ ];
3299
+
3300
+ if ( isNaN( currentValue[ 0 ] ) || isNaN( currentValue[ 1 ] ) || isNaN( currentValue[ 2 ] ) ) {
3301
+
3302
+ continue;
3303
+
3304
+ }
3305
+
3306
+ const currentValueRad = currentValue.map( MathUtils.degToRad );
3307
+
3308
+ const valuesSpan = [
3309
+ currentValue[ 0 ] - initialValue[ 0 ],
3310
+ currentValue[ 1 ] - initialValue[ 1 ],
3311
+ currentValue[ 2 ] - initialValue[ 2 ],
3312
+ ];
3313
+
3314
+ const absoluteSpan = [
3315
+ Math.abs( valuesSpan[ 0 ] ),
3316
+ Math.abs( valuesSpan[ 1 ] ),
3317
+ Math.abs( valuesSpan[ 2 ] ),
3318
+ ];
3319
+
3320
+ if ( absoluteSpan[ 0 ] >= 180 || absoluteSpan[ 1 ] >= 180 || absoluteSpan[ 2 ] >= 180 ) {
3321
+
3322
+ const maxAbsSpan = Math.max( ...absoluteSpan );
3323
+
3324
+ const numSubIntervals = maxAbsSpan / 180;
3325
+
3326
+ const E1 = new Euler( ...initialValueRad, eulerOrder );
3327
+ const E2 = new Euler( ...currentValueRad, eulerOrder );
3328
+
3329
+ const Q1 = new Quaternion().setFromEuler( E1 );
3330
+ const Q2 = new Quaternion().setFromEuler( E2 );
3331
+
3332
+ // Check unroll
3333
+ if ( Q1.dot( Q2 ) < 0 ) {
3334
+
3335
+ Q2.set( - Q2.x, - Q2.y, - Q2.z, - Q2.w );
3336
+
3337
+ }
3338
+
3339
+ // Interpolate
3340
+ const initialTime = curvex.times[ i - 1 ];
3341
+ const timeSpan = curvex.times[ i ] - initialTime;
3342
+
3343
+ const Q = new Quaternion();
3344
+ const E = new Euler();
3345
+ for ( let t = 0; t < 1; t += 1 / numSubIntervals ) {
3346
+
3347
+ Q.copy( Q1.clone().slerp( Q2.clone(), t ) );
3348
+
3349
+ times.push( initialTime + t * timeSpan );
3350
+ E.setFromQuaternion( Q, eulerOrder );
3351
+
3352
+ values.push( E.x );
3353
+ values.push( E.y );
3354
+ values.push( E.z );
3355
+
3356
+ }
3357
+
3358
+ } else {
3359
+
3360
+ times.push( curvex.times[ i ] );
3361
+ values.push( MathUtils.degToRad( curvex.values[ i ] ) );
3362
+ values.push( MathUtils.degToRad( curvey.values[ i ] ) );
3363
+ values.push( MathUtils.degToRad( curvez.values[ i ] ) );
3364
+
3365
+ }
3366
+
3367
+ }
3368
+
3369
+ return [ times, values ];
3370
+
3371
+ }
3372
+
3373
+ }
3374
+
3375
+ // parse an FBX file in ASCII format
3376
+ class TextParser {
3377
+
3378
+ getPrevNode() {
3379
+
3380
+ return this.nodeStack[ this.currentIndent - 2 ];
3381
+
3382
+ }
3383
+
3384
+ getCurrentNode() {
3385
+
3386
+ return this.nodeStack[ this.currentIndent - 1 ];
3387
+
3388
+ }
3389
+
3390
+ getCurrentProp() {
3391
+
3392
+ return this.currentProp;
3393
+
3394
+ }
3395
+
3396
+ pushStack( node ) {
3397
+
3398
+ this.nodeStack.push( node );
3399
+ this.currentIndent += 1;
3400
+
3401
+ }
3402
+
3403
+ popStack() {
3404
+
3405
+ this.nodeStack.pop();
3406
+ this.currentIndent -= 1;
3407
+
3408
+ }
3409
+
3410
+ setCurrentProp( val, name ) {
3411
+
3412
+ this.currentProp = val;
3413
+ this.currentPropName = name;
3414
+
3415
+ }
3416
+
3417
+ parse( text ) {
3418
+
3419
+ this.currentIndent = 0;
3420
+
3421
+ this.allNodes = new FBXTree();
3422
+ this.nodeStack = [];
3423
+ this.currentProp = [];
3424
+ this.currentPropName = '';
3425
+
3426
+ const scope = this;
3427
+
3428
+ const split = text.split( /[\r\n]+/ );
3429
+
3430
+ split.forEach( function ( line, i ) {
3431
+
3432
+ const matchComment = line.match( /^[\s\t]*;/ );
3433
+ const matchEmpty = line.match( /^[\s\t]*$/ );
3434
+
3435
+ if ( matchComment || matchEmpty ) return;
3436
+
3437
+ const matchBeginning = line.match( '^\\t{' + scope.currentIndent + '}(\\w+):(.*){', '' );
3438
+ const matchProperty = line.match( '^\\t{' + ( scope.currentIndent ) + '}(\\w+):[\\s\\t\\r\\n](.*)' );
3439
+ const matchEnd = line.match( '^\\t{' + ( scope.currentIndent - 1 ) + '}}' );
3440
+
3441
+ if ( matchBeginning ) {
3442
+
3443
+ scope.parseNodeBegin( line, matchBeginning );
3444
+
3445
+ } else if ( matchProperty ) {
3446
+
3447
+ scope.parseNodeProperty( line, matchProperty, split[ ++ i ] );
3448
+
3449
+ } else if ( matchEnd ) {
3450
+
3451
+ scope.popStack();
3452
+
3453
+ } else if ( line.match( /^[^\s\t}]/ ) ) {
3454
+
3455
+ // large arrays are split over multiple lines terminated with a ',' character
3456
+ // if this is encountered the line needs to be joined to the previous line
3457
+ scope.parseNodePropertyContinued( line );
3458
+
3459
+ }
3460
+
3461
+ } );
3462
+
3463
+ return this.allNodes;
3464
+
3465
+ }
3466
+
3467
+ parseNodeBegin( line, property ) {
3468
+
3469
+ const nodeName = property[ 1 ].trim().replace( /^"/, '' ).replace( /"$/, '' );
3470
+
3471
+ const nodeAttrs = property[ 2 ].split( ',' ).map( function ( attr ) {
3472
+
3473
+ return attr.trim().replace( /^"/, '' ).replace( /"$/, '' );
3474
+
3475
+ } );
3476
+
3477
+ const node = { name: nodeName };
3478
+ const attrs = this.parseNodeAttr( nodeAttrs );
3479
+
3480
+ const currentNode = this.getCurrentNode();
3481
+
3482
+ // a top node
3483
+ if ( this.currentIndent === 0 ) {
3484
+
3485
+ this.allNodes.add( nodeName, node );
3486
+
3487
+ } else { // a subnode
3488
+
3489
+ // if the subnode already exists, append it
3490
+ if ( nodeName in currentNode ) {
3491
+
3492
+ // special case Pose needs PoseNodes as an array
3493
+ if ( nodeName === 'PoseNode' ) {
3494
+
3495
+ currentNode.PoseNode.push( node );
3496
+
3497
+ } else if ( currentNode[ nodeName ].id !== undefined ) {
3498
+
3499
+ currentNode[ nodeName ] = {};
3500
+ currentNode[ nodeName ][ currentNode[ nodeName ].id ] = currentNode[ nodeName ];
3501
+
3502
+ }
3503
+
3504
+ if ( attrs.id !== '' ) currentNode[ nodeName ][ attrs.id ] = node;
3505
+
3506
+ } else if ( typeof attrs.id === 'number' ) {
3507
+
3508
+ currentNode[ nodeName ] = {};
3509
+ currentNode[ nodeName ][ attrs.id ] = node;
3510
+
3511
+ } else if ( nodeName !== 'Properties70' ) {
3512
+
3513
+ if ( nodeName === 'PoseNode' ) currentNode[ nodeName ] = [ node ];
3514
+ else currentNode[ nodeName ] = node;
3515
+
3516
+ }
3517
+
3518
+ }
3519
+
3520
+ if ( typeof attrs.id === 'number' ) node.id = attrs.id;
3521
+ if ( attrs.name !== '' ) node.attrName = attrs.name;
3522
+ if ( attrs.type !== '' ) node.attrType = attrs.type;
3523
+
3524
+ this.pushStack( node );
3525
+
3526
+ }
3527
+
3528
+ parseNodeAttr( attrs ) {
3529
+
3530
+ let id = attrs[ 0 ];
3531
+
3532
+ if ( attrs[ 0 ] !== '' ) {
3533
+
3534
+ id = parseInt( attrs[ 0 ] );
3535
+
3536
+ if ( isNaN( id ) ) {
3537
+
3538
+ id = attrs[ 0 ];
3539
+
3540
+ }
3541
+
3542
+ }
3543
+
3544
+ let name = '', type = '';
3545
+
3546
+ if ( attrs.length > 1 ) {
3547
+
3548
+ name = attrs[ 1 ].replace( /^(\w+)::/, '' );
3549
+ type = attrs[ 2 ];
3550
+
3551
+ }
3552
+
3553
+ return { id: id, name: name, type: type };
3554
+
3555
+ }
3556
+
3557
+ parseNodeProperty( line, property, contentLine ) {
3558
+
3559
+ let propName = property[ 1 ].replace( /^"/, '' ).replace( /"$/, '' ).trim();
3560
+ let propValue = property[ 2 ].replace( /^"/, '' ).replace( /"$/, '' ).trim();
3561
+
3562
+ // for special case: base64 image data follows "Content: ," line
3563
+ // Content: ,
3564
+ // "/9j/4RDaRXhpZgAATU0A..."
3565
+ if ( propName === 'Content' && propValue === ',' ) {
3566
+
3567
+ propValue = contentLine.replace( /"/g, '' ).replace( /,$/, '' ).trim();
3568
+
3569
+ }
3570
+
3571
+ const currentNode = this.getCurrentNode();
3572
+ const parentName = currentNode.name;
3573
+
3574
+ if ( parentName === 'Properties70' ) {
3575
+
3576
+ this.parseNodeSpecialProperty( line, propName, propValue );
3577
+ return;
3578
+
3579
+ }
3580
+
3581
+ // Connections
3582
+ if ( propName === 'C' ) {
3583
+
3584
+ const connProps = propValue.split( ',' ).slice( 1 );
3585
+ const from = parseInt( connProps[ 0 ] );
3586
+ const to = parseInt( connProps[ 1 ] );
3587
+
3588
+ let rest = propValue.split( ',' ).slice( 3 );
3589
+
3590
+ rest = rest.map( function ( elem ) {
3591
+
3592
+ return elem.trim().replace( /^"/, '' );
3593
+
3594
+ } );
3595
+
3596
+ propName = 'connections';
3597
+ propValue = [ from, to ];
3598
+ append( propValue, rest );
3599
+
3600
+ if ( currentNode[ propName ] === undefined ) {
3601
+
3602
+ currentNode[ propName ] = [];
3603
+
3604
+ }
3605
+
3606
+ }
3607
+
3608
+ // Node
3609
+ if ( propName === 'Node' ) currentNode.id = propValue;
3610
+
3611
+ // connections
3612
+ if ( propName in currentNode && Array.isArray( currentNode[ propName ] ) ) {
3613
+
3614
+ currentNode[ propName ].push( propValue );
3615
+
3616
+ } else {
3617
+
3618
+ if ( propName !== 'a' ) currentNode[ propName ] = propValue;
3619
+ else currentNode.a = propValue;
3620
+
3621
+ }
3622
+
3623
+ this.setCurrentProp( currentNode, propName );
3624
+
3625
+ // convert string to array, unless it ends in ',' in which case more will be added to it
3626
+ if ( propName === 'a' && propValue.slice( - 1 ) !== ',' ) {
3627
+
3628
+ currentNode.a = parseNumberArray( propValue );
3629
+
3630
+ }
3631
+
3632
+ }
3633
+
3634
+ parseNodePropertyContinued( line ) {
3635
+
3636
+ const currentNode = this.getCurrentNode();
3637
+
3638
+ currentNode.a += line;
3639
+
3640
+ // if the line doesn't end in ',' we have reached the end of the property value
3641
+ // so convert the string to an array
3642
+ if ( line.slice( - 1 ) !== ',' ) {
3643
+
3644
+ currentNode.a = parseNumberArray( currentNode.a );
3645
+
3646
+ }
3647
+
3648
+ }
3649
+
3650
+ // parse "Property70"
3651
+ parseNodeSpecialProperty( line, propName, propValue ) {
3652
+
3653
+ // split this
3654
+ // P: "Lcl Scaling", "Lcl Scaling", "", "A",1,1,1
3655
+ // into array like below
3656
+ // ["Lcl Scaling", "Lcl Scaling", "", "A", "1,1,1" ]
3657
+ const props = propValue.split( '",' ).map( function ( prop ) {
3658
+
3659
+ return prop.trim().replace( /^\"/, '' ).replace( /\s/, '_' );
3660
+
3661
+ } );
3662
+
3663
+ const innerPropName = props[ 0 ];
3664
+ const innerPropType1 = props[ 1 ];
3665
+ const innerPropType2 = props[ 2 ];
3666
+ const innerPropFlag = props[ 3 ];
3667
+ let innerPropValue = props[ 4 ];
3668
+
3669
+ // cast values where needed, otherwise leave as strings
3670
+ switch ( innerPropType1 ) {
3671
+
3672
+ case 'int':
3673
+ case 'enum':
3674
+ case 'bool':
3675
+ case 'ULongLong':
3676
+ case 'double':
3677
+ case 'Number':
3678
+ case 'FieldOfView':
3679
+ innerPropValue = parseFloat( innerPropValue );
3680
+ break;
3681
+
3682
+ case 'Color':
3683
+ case 'ColorRGB':
3684
+ case 'Vector3D':
3685
+ case 'Lcl_Translation':
3686
+ case 'Lcl_Rotation':
3687
+ case 'Lcl_Scaling':
3688
+ innerPropValue = parseNumberArray( innerPropValue );
3689
+ break;
3690
+
3691
+ }
3692
+
3693
+ // CAUTION: these props must append to parent's parent
3694
+ this.getPrevNode()[ innerPropName ] = {
3695
+
3696
+ 'type': innerPropType1,
3697
+ 'type2': innerPropType2,
3698
+ 'flag': innerPropFlag,
3699
+ 'value': innerPropValue
3700
+
3701
+ };
3702
+
3703
+ this.setCurrentProp( this.getPrevNode(), innerPropName );
3704
+
3705
+ }
3706
+
3707
+ }
3708
+
3709
+ // Parse an FBX file in Binary format
3710
+ class BinaryParser {
3711
+
3712
+ parse( buffer ) {
3713
+
3714
+ const reader = new BinaryReader( buffer );
3715
+ reader.skip( 23 ); // skip magic 23 bytes
3716
+
3717
+ const version = reader.getUint32();
3718
+
3719
+ if ( version < 6400 ) {
3720
+
3721
+ throw new Error( 'THREE.FBXLoader: FBX version not supported, FileVersion: ' + version );
3722
+
3723
+ }
3724
+
3725
+ const allNodes = new FBXTree();
3726
+
3727
+ while ( ! this.endOfContent( reader ) ) {
3728
+
3729
+ const node = this.parseNode( reader, version );
3730
+ if ( node !== null ) allNodes.add( node.name, node );
3731
+
3732
+ }
3733
+
3734
+ return allNodes;
3735
+
3736
+ }
3737
+
3738
+ // Check if reader has reached the end of content.
3739
+ endOfContent( reader ) {
3740
+
3741
+ // footer size: 160bytes + 16-byte alignment padding
3742
+ // - 16bytes: magic
3743
+ // - padding til 16-byte alignment (at least 1byte?)
3744
+ // (seems like some exporters embed fixed 15 or 16bytes?)
3745
+ // - 4bytes: magic
3746
+ // - 4bytes: version
3747
+ // - 120bytes: zero
3748
+ // - 16bytes: magic
3749
+ if ( reader.size() % 16 === 0 ) {
3750
+
3751
+ return ( ( reader.getOffset() + 160 + 16 ) & ~ 0xf ) >= reader.size();
3752
+
3753
+ } else {
3754
+
3755
+ return reader.getOffset() + 160 + 16 >= reader.size();
3756
+
3757
+ }
3758
+
3759
+ }
3760
+
3761
+ // recursively parse nodes until the end of the file is reached
3762
+ parseNode( reader, version ) {
3763
+
3764
+ const node = {};
3765
+
3766
+ // The first three data sizes depends on version.
3767
+ const endOffset = ( version >= 7500 ) ? reader.getUint64() : reader.getUint32();
3768
+ const numProperties = ( version >= 7500 ) ? reader.getUint64() : reader.getUint32();
3769
+
3770
+ ( version >= 7500 ) ? reader.getUint64() : reader.getUint32(); // the returned propertyListLen is not used
3771
+
3772
+ const nameLen = reader.getUint8();
3773
+ const name = reader.getString( nameLen );
3774
+
3775
+ // Regards this node as NULL-record if endOffset is zero
3776
+ if ( endOffset === 0 ) return null;
3777
+
3778
+ const propertyList = [];
3779
+
3780
+ for ( let i = 0; i < numProperties; i ++ ) {
3781
+
3782
+ propertyList.push( this.parseProperty( reader ) );
3783
+
3784
+ }
3785
+
3786
+ // Regards the first three elements in propertyList as id, attrName, and attrType
3787
+ const id = propertyList.length > 0 ? propertyList[ 0 ] : '';
3788
+ const attrName = propertyList.length > 1 ? propertyList[ 1 ] : '';
3789
+ const attrType = propertyList.length > 2 ? propertyList[ 2 ] : '';
3790
+
3791
+ // check if this node represents just a single property
3792
+ // like (name, 0) set or (name2, [0, 1, 2]) set of {name: 0, name2: [0, 1, 2]}
3793
+ node.singleProperty = ( numProperties === 1 && reader.getOffset() === endOffset ) ? true : false;
3794
+
3795
+ while ( endOffset > reader.getOffset() ) {
3796
+
3797
+ const subNode = this.parseNode( reader, version );
3798
+
3799
+ if ( subNode !== null ) this.parseSubNode( name, node, subNode );
3800
+
3801
+ }
3802
+
3803
+ node.propertyList = propertyList; // raw property list used by parent
3804
+
3805
+ if ( typeof id === 'number' ) node.id = id;
3806
+ if ( attrName !== '' ) node.attrName = attrName;
3807
+ if ( attrType !== '' ) node.attrType = attrType;
3808
+ if ( name !== '' ) node.name = name;
3809
+
3810
+ return node;
3811
+
3812
+ }
3813
+
3814
+ parseSubNode( name, node, subNode ) {
3815
+
3816
+ // special case: child node is single property
3817
+ if ( subNode.singleProperty === true ) {
3818
+
3819
+ const value = subNode.propertyList[ 0 ];
3820
+
3821
+ if ( Array.isArray( value ) ) {
3822
+
3823
+ node[ subNode.name ] = subNode;
3824
+
3825
+ subNode.a = value;
3826
+
3827
+ } else {
3828
+
3829
+ node[ subNode.name ] = value;
3830
+
3831
+ }
3832
+
3833
+ } else if ( name === 'Connections' && subNode.name === 'C' ) {
3834
+
3835
+ const array = [];
3836
+
3837
+ subNode.propertyList.forEach( function ( property, i ) {
3838
+
3839
+ // first Connection is FBX type (OO, OP, etc.). We'll discard these
3840
+ if ( i !== 0 ) array.push( property );
3841
+
3842
+ } );
3843
+
3844
+ if ( node.connections === undefined ) {
3845
+
3846
+ node.connections = [];
3847
+
3848
+ }
3849
+
3850
+ node.connections.push( array );
3851
+
3852
+ } else if ( subNode.name === 'Properties70' ) {
3853
+
3854
+ const keys = Object.keys( subNode );
3855
+
3856
+ keys.forEach( function ( key ) {
3857
+
3858
+ node[ key ] = subNode[ key ];
3859
+
3860
+ } );
3861
+
3862
+ } else if ( name === 'Properties70' && subNode.name === 'P' ) {
3863
+
3864
+ let innerPropName = subNode.propertyList[ 0 ];
3865
+ let innerPropType1 = subNode.propertyList[ 1 ];
3866
+ const innerPropType2 = subNode.propertyList[ 2 ];
3867
+ const innerPropFlag = subNode.propertyList[ 3 ];
3868
+ let innerPropValue;
3869
+
3870
+ if ( innerPropName.indexOf( 'Lcl ' ) === 0 ) innerPropName = innerPropName.replace( 'Lcl ', 'Lcl_' );
3871
+ if ( innerPropType1.indexOf( 'Lcl ' ) === 0 ) innerPropType1 = innerPropType1.replace( 'Lcl ', 'Lcl_' );
3872
+
3873
+ if ( innerPropType1 === 'Color' || innerPropType1 === 'ColorRGB' || innerPropType1 === 'Vector' || innerPropType1 === 'Vector3D' || innerPropType1.indexOf( 'Lcl_' ) === 0 ) {
3874
+
3875
+ innerPropValue = [
3876
+ subNode.propertyList[ 4 ],
3877
+ subNode.propertyList[ 5 ],
3878
+ subNode.propertyList[ 6 ]
3879
+ ];
3880
+
3881
+ } else {
3882
+
3883
+ innerPropValue = subNode.propertyList[ 4 ];
3884
+
3885
+ }
3886
+
3887
+ // this will be copied to parent, see above
3888
+ node[ innerPropName ] = {
3889
+
3890
+ 'type': innerPropType1,
3891
+ 'type2': innerPropType2,
3892
+ 'flag': innerPropFlag,
3893
+ 'value': innerPropValue
3894
+
3895
+ };
3896
+
3897
+ } else if ( node[ subNode.name ] === undefined ) {
3898
+
3899
+ if ( typeof subNode.id === 'number' ) {
3900
+
3901
+ node[ subNode.name ] = {};
3902
+ node[ subNode.name ][ subNode.id ] = subNode;
3903
+
3904
+ } else {
3905
+
3906
+ node[ subNode.name ] = subNode;
3907
+
3908
+ }
3909
+
3910
+ } else {
3911
+
3912
+ if ( subNode.name === 'PoseNode' ) {
3913
+
3914
+ if ( ! Array.isArray( node[ subNode.name ] ) ) {
3915
+
3916
+ node[ subNode.name ] = [ node[ subNode.name ] ];
3917
+
3918
+ }
3919
+
3920
+ node[ subNode.name ].push( subNode );
3921
+
3922
+ } else if ( node[ subNode.name ][ subNode.id ] === undefined ) {
3923
+
3924
+ node[ subNode.name ][ subNode.id ] = subNode;
3925
+
3926
+ }
3927
+
3928
+ }
3929
+
3930
+ }
3931
+
3932
+ parseProperty( reader ) {
3933
+
3934
+ const type = reader.getString( 1 );
3935
+ let length;
3936
+
3937
+ switch ( type ) {
3938
+
3939
+ case 'C':
3940
+ return reader.getBoolean();
3941
+
3942
+ case 'D':
3943
+ return reader.getFloat64();
3944
+
3945
+ case 'F':
3946
+ return reader.getFloat32();
3947
+
3948
+ case 'I':
3949
+ return reader.getInt32();
3950
+
3951
+ case 'L':
3952
+ return reader.getInt64();
3953
+
3954
+ case 'R':
3955
+ length = reader.getUint32();
3956
+ return reader.getArrayBuffer( length );
3957
+
3958
+ case 'S':
3959
+ length = reader.getUint32();
3960
+ return reader.getString( length );
3961
+
3962
+ case 'Y':
3963
+ return reader.getInt16();
3964
+
3965
+ case 'b':
3966
+ case 'c':
3967
+ case 'd':
3968
+ case 'f':
3969
+ case 'i':
3970
+ case 'l':
3971
+
3972
+ const arrayLength = reader.getUint32();
3973
+ const encoding = reader.getUint32(); // 0: non-compressed, 1: compressed
3974
+ const compressedLength = reader.getUint32();
3975
+
3976
+ if ( encoding === 0 ) {
3977
+
3978
+ switch ( type ) {
3979
+
3980
+ case 'b':
3981
+ case 'c':
3982
+ return reader.getBooleanArray( arrayLength );
3983
+
3984
+ case 'd':
3985
+ return reader.getFloat64Array( arrayLength );
3986
+
3987
+ case 'f':
3988
+ return reader.getFloat32Array( arrayLength );
3989
+
3990
+ case 'i':
3991
+ return reader.getInt32Array( arrayLength );
3992
+
3993
+ case 'l':
3994
+ return reader.getInt64Array( arrayLength );
3995
+
3996
+ }
3997
+
3998
+ }
3999
+
4000
+ const data = unzlibSync( new Uint8Array( reader.getArrayBuffer( compressedLength ) ) );
4001
+ const reader2 = new BinaryReader( data.buffer );
4002
+
4003
+ switch ( type ) {
4004
+
4005
+ case 'b':
4006
+ case 'c':
4007
+ return reader2.getBooleanArray( arrayLength );
4008
+
4009
+ case 'd':
4010
+ return reader2.getFloat64Array( arrayLength );
4011
+
4012
+ case 'f':
4013
+ return reader2.getFloat32Array( arrayLength );
4014
+
4015
+ case 'i':
4016
+ return reader2.getInt32Array( arrayLength );
4017
+
4018
+ case 'l':
4019
+ return reader2.getInt64Array( arrayLength );
4020
+
4021
+ }
4022
+
4023
+ break; // cannot happen but is required by the DeepScan
4024
+
4025
+ default:
4026
+ throw new Error( 'THREE.FBXLoader: Unknown property type ' + type );
4027
+
4028
+ }
4029
+
4030
+ }
4031
+
4032
+ }
4033
+
4034
+ class BinaryReader {
4035
+
4036
+ constructor( buffer, littleEndian ) {
4037
+
4038
+ this.dv = new DataView( buffer );
4039
+ this.offset = 0;
4040
+ this.littleEndian = ( littleEndian !== undefined ) ? littleEndian : true;
4041
+ this._textDecoder = new TextDecoder();
4042
+
4043
+ }
4044
+
4045
+ getOffset() {
4046
+
4047
+ return this.offset;
4048
+
4049
+ }
4050
+
4051
+ size() {
4052
+
4053
+ return this.dv.buffer.byteLength;
4054
+
4055
+ }
4056
+
4057
+ skip( length ) {
4058
+
4059
+ this.offset += length;
4060
+
4061
+ }
4062
+
4063
+ // seems like true/false representation depends on exporter.
4064
+ // true: 1 or 'Y'(=0x59), false: 0 or 'T'(=0x54)
4065
+ // then sees LSB.
4066
+ getBoolean() {
4067
+
4068
+ return ( this.getUint8() & 1 ) === 1;
4069
+
4070
+ }
4071
+
4072
+ getBooleanArray( size ) {
4073
+
4074
+ const a = [];
4075
+
4076
+ for ( let i = 0; i < size; i ++ ) {
4077
+
4078
+ a.push( this.getBoolean() );
4079
+
4080
+ }
4081
+
4082
+ return a;
4083
+
4084
+ }
4085
+
4086
+ getUint8() {
4087
+
4088
+ const value = this.dv.getUint8( this.offset );
4089
+ this.offset += 1;
4090
+ return value;
4091
+
4092
+ }
4093
+
4094
+ getInt16() {
4095
+
4096
+ const value = this.dv.getInt16( this.offset, this.littleEndian );
4097
+ this.offset += 2;
4098
+ return value;
4099
+
4100
+ }
4101
+
4102
+ getInt32() {
4103
+
4104
+ const value = this.dv.getInt32( this.offset, this.littleEndian );
4105
+ this.offset += 4;
4106
+ return value;
4107
+
4108
+ }
4109
+
4110
+ getInt32Array( size ) {
4111
+
4112
+ const a = [];
4113
+
4114
+ for ( let i = 0; i < size; i ++ ) {
4115
+
4116
+ a.push( this.getInt32() );
4117
+
4118
+ }
4119
+
4120
+ return a;
4121
+
4122
+ }
4123
+
4124
+ getUint32() {
4125
+
4126
+ const value = this.dv.getUint32( this.offset, this.littleEndian );
4127
+ this.offset += 4;
4128
+ return value;
4129
+
4130
+ }
4131
+
4132
+ // JavaScript doesn't support 64-bit integer so calculate this here
4133
+ // 1 << 32 will return 1 so using multiply operation instead here.
4134
+ // There's a possibility that this method returns wrong value if the value
4135
+ // is out of the range between Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER.
4136
+ // TODO: safely handle 64-bit integer
4137
+ getInt64() {
4138
+
4139
+ let low, high;
4140
+
4141
+ if ( this.littleEndian ) {
4142
+
4143
+ low = this.getUint32();
4144
+ high = this.getUint32();
4145
+
4146
+ } else {
4147
+
4148
+ high = this.getUint32();
4149
+ low = this.getUint32();
4150
+
4151
+ }
4152
+
4153
+ // calculate negative value
4154
+ if ( high & 0x80000000 ) {
4155
+
4156
+ high = ~ high & 0xFFFFFFFF;
4157
+ low = ~ low & 0xFFFFFFFF;
4158
+
4159
+ if ( low === 0xFFFFFFFF ) high = ( high + 1 ) & 0xFFFFFFFF;
4160
+
4161
+ low = ( low + 1 ) & 0xFFFFFFFF;
4162
+
4163
+ return - ( high * 0x100000000 + low );
4164
+
4165
+ }
4166
+
4167
+ return high * 0x100000000 + low;
4168
+
4169
+ }
4170
+
4171
+ getInt64Array( size ) {
4172
+
4173
+ const a = [];
4174
+
4175
+ for ( let i = 0; i < size; i ++ ) {
4176
+
4177
+ a.push( this.getInt64() );
4178
+
4179
+ }
4180
+
4181
+ return a;
4182
+
4183
+ }
4184
+
4185
+ // Note: see getInt64() comment
4186
+ getUint64() {
4187
+
4188
+ let low, high;
4189
+
4190
+ if ( this.littleEndian ) {
4191
+
4192
+ low = this.getUint32();
4193
+ high = this.getUint32();
4194
+
4195
+ } else {
4196
+
4197
+ high = this.getUint32();
4198
+ low = this.getUint32();
4199
+
4200
+ }
4201
+
4202
+ return high * 0x100000000 + low;
4203
+
4204
+ }
4205
+
4206
+ getFloat32() {
4207
+
4208
+ const value = this.dv.getFloat32( this.offset, this.littleEndian );
4209
+ this.offset += 4;
4210
+ return value;
4211
+
4212
+ }
4213
+
4214
+ getFloat32Array( size ) {
4215
+
4216
+ const a = [];
4217
+
4218
+ for ( let i = 0; i < size; i ++ ) {
4219
+
4220
+ a.push( this.getFloat32() );
4221
+
4222
+ }
4223
+
4224
+ return a;
4225
+
4226
+ }
4227
+
4228
+ getFloat64() {
4229
+
4230
+ const value = this.dv.getFloat64( this.offset, this.littleEndian );
4231
+ this.offset += 8;
4232
+ return value;
4233
+
4234
+ }
4235
+
4236
+ getFloat64Array( size ) {
4237
+
4238
+ const a = [];
4239
+
4240
+ for ( let i = 0; i < size; i ++ ) {
4241
+
4242
+ a.push( this.getFloat64() );
4243
+
4244
+ }
4245
+
4246
+ return a;
4247
+
4248
+ }
4249
+
4250
+ getArrayBuffer( size ) {
4251
+
4252
+ const value = this.dv.buffer.slice( this.offset, this.offset + size );
4253
+ this.offset += size;
4254
+ return value;
4255
+
4256
+ }
4257
+
4258
+ getString( size ) {
4259
+
4260
+ const start = this.offset;
4261
+ let a = new Uint8Array( this.dv.buffer, start, size );
4262
+
4263
+ this.skip( size );
4264
+
4265
+ const nullByte = a.indexOf( 0 );
4266
+ if ( nullByte >= 0 ) a = new Uint8Array( this.dv.buffer, start, nullByte );
4267
+
4268
+ return this._textDecoder.decode( a );
4269
+
4270
+ }
4271
+
4272
+ }
4273
+
4274
+ // FBXTree holds a representation of the FBX data, returned by the TextParser ( FBX ASCII format)
4275
+ // and BinaryParser( FBX Binary format)
4276
+ class FBXTree {
4277
+
4278
+ add( key, val ) {
4279
+
4280
+ this[ key ] = val;
4281
+
4282
+ }
4283
+
4284
+ }
4285
+
4286
+ // ************** UTILITY FUNCTIONS **************
4287
+
4288
+ function isFbxFormatBinary( buffer ) {
4289
+
4290
+ const CORRECT = 'Kaydara\u0020FBX\u0020Binary\u0020\u0020\0';
4291
+
4292
+ return buffer.byteLength >= CORRECT.length && CORRECT === convertArrayBufferToString( buffer, 0, CORRECT.length );
4293
+
4294
+ }
4295
+
4296
+ function isFbxFormatASCII( text ) {
4297
+
4298
+ const CORRECT = [ 'K', 'a', 'y', 'd', 'a', 'r', 'a', '\\', 'F', 'B', 'X', '\\', 'B', 'i', 'n', 'a', 'r', 'y', '\\', '\\' ];
4299
+
4300
+ let cursor = 0;
4301
+
4302
+ function read( offset ) {
4303
+
4304
+ const result = text[ offset - 1 ];
4305
+ text = text.slice( cursor + offset );
4306
+ cursor ++;
4307
+ return result;
4308
+
4309
+ }
4310
+
4311
+ for ( let i = 0; i < CORRECT.length; ++ i ) {
4312
+
4313
+ const num = read( 1 );
4314
+ if ( num === CORRECT[ i ] ) {
4315
+
4316
+ return false;
4317
+
4318
+ }
4319
+
4320
+ }
4321
+
4322
+ return true;
4323
+
4324
+ }
4325
+
4326
+ function getFbxVersion( text ) {
4327
+
4328
+ const versionRegExp = /FBXVersion: (\d+)/;
4329
+ const match = text.match( versionRegExp );
4330
+
4331
+ if ( match ) {
4332
+
4333
+ const version = parseInt( match[ 1 ] );
4334
+ return version;
4335
+
4336
+ }
4337
+
4338
+ throw new Error( 'THREE.FBXLoader: Cannot find the version number for the file given.' );
4339
+
4340
+ }
4341
+
4342
+ // Converts FBX ticks into real time seconds.
4343
+ function convertFBXTimeToSeconds( time ) {
4344
+
4345
+ return time / 46186158000;
4346
+
4347
+ }
4348
+
4349
+ const dataArray = [];
4350
+
4351
+ // extracts the data from the correct position in the FBX array based on indexing type
4352
+ function getData( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {
4353
+
4354
+ let index;
4355
+
4356
+ switch ( infoObject.mappingType ) {
4357
+
4358
+ case 'ByPolygonVertex' :
4359
+ index = polygonVertexIndex;
4360
+ break;
4361
+ case 'ByPolygon' :
4362
+ index = polygonIndex;
4363
+ break;
4364
+ case 'ByVertice' :
4365
+ index = vertexIndex;
4366
+ break;
4367
+ case 'AllSame' :
4368
+ index = infoObject.indices[ 0 ];
4369
+ break;
4370
+ default :
4371
+ console.warn( 'THREE.FBXLoader: unknown attribute mapping type ' + infoObject.mappingType );
4372
+
4373
+ }
4374
+
4375
+ if ( infoObject.referenceType === 'IndexToDirect' ) index = infoObject.indices[ index ];
4376
+
4377
+ const from = index * infoObject.dataSize;
4378
+ const to = from + infoObject.dataSize;
4379
+
4380
+ return slice( dataArray, infoObject.buffer, from, to );
4381
+
4382
+ }
4383
+
4384
+ const tempEuler = new Euler();
4385
+ const tempVec = new Vector3();
4386
+
4387
+ // generate transformation from FBX transform data
4388
+ // ref: https://help.autodesk.com/view/FBX/2017/ENU/?guid=__files_GUID_10CDD63C_79C1_4F2D_BB28_AD2BE65A02ED_htm
4389
+ // ref: http://docs.autodesk.com/FBX/2014/ENU/FBX-SDK-Documentation/index.html?url=cpp_ref/_transformations_2main_8cxx-example.html,topicNumber=cpp_ref__transformations_2main_8cxx_example_htmlfc10a1e1-b18d-4e72-9dc0-70d0f1959f5e
4390
+ function generateTransform( transformData ) {
4391
+
4392
+ const lTranslationM = new Matrix4();
4393
+ const lPreRotationM = new Matrix4();
4394
+ const lRotationM = new Matrix4();
4395
+ const lPostRotationM = new Matrix4();
4396
+
4397
+ const lScalingM = new Matrix4();
4398
+ const lScalingPivotM = new Matrix4();
4399
+ const lScalingOffsetM = new Matrix4();
4400
+ const lRotationOffsetM = new Matrix4();
4401
+ const lRotationPivotM = new Matrix4();
4402
+
4403
+ const lParentGX = new Matrix4();
4404
+ const lParentLX = new Matrix4();
4405
+ const lGlobalT = new Matrix4();
4406
+
4407
+ const inheritType = ( transformData.inheritType ) ? transformData.inheritType : 0;
4408
+
4409
+ if ( transformData.translation ) lTranslationM.setPosition( tempVec.fromArray( transformData.translation ) );
4410
+
4411
+ // For Maya models using "Joint Orient", Euler order only applies to rotation, not pre/post-rotations
4412
+ const defaultEulerOrder = getEulerOrder( 0 );
4413
+
4414
+ if ( transformData.preRotation ) {
4415
+
4416
+ const array = transformData.preRotation.map( MathUtils.degToRad );
4417
+ array.push( defaultEulerOrder );
4418
+ lPreRotationM.makeRotationFromEuler( tempEuler.fromArray( array ) );
4419
+
4420
+ }
4421
+
4422
+ if ( transformData.rotation ) {
4423
+
4424
+ const array = transformData.rotation.map( MathUtils.degToRad );
4425
+ array.push( transformData.eulerOrder || defaultEulerOrder );
4426
+ lRotationM.makeRotationFromEuler( tempEuler.fromArray( array ) );
4427
+
4428
+ }
4429
+
4430
+ if ( transformData.postRotation ) {
4431
+
4432
+ const array = transformData.postRotation.map( MathUtils.degToRad );
4433
+ array.push( defaultEulerOrder );
4434
+ lPostRotationM.makeRotationFromEuler( tempEuler.fromArray( array ) );
4435
+ lPostRotationM.invert();
4436
+
4437
+ }
4438
+
4439
+ if ( transformData.scale ) lScalingM.scale( tempVec.fromArray( transformData.scale ) );
4440
+
4441
+ // Pivots and offsets
4442
+ if ( transformData.scalingOffset ) lScalingOffsetM.setPosition( tempVec.fromArray( transformData.scalingOffset ) );
4443
+ if ( transformData.scalingPivot ) lScalingPivotM.setPosition( tempVec.fromArray( transformData.scalingPivot ) );
4444
+ if ( transformData.rotationOffset ) lRotationOffsetM.setPosition( tempVec.fromArray( transformData.rotationOffset ) );
4445
+ if ( transformData.rotationPivot ) lRotationPivotM.setPosition( tempVec.fromArray( transformData.rotationPivot ) );
4446
+
4447
+ // parent transform
4448
+ if ( transformData.parentMatrixWorld ) {
4449
+
4450
+ lParentLX.copy( transformData.parentMatrix );
4451
+ lParentGX.copy( transformData.parentMatrixWorld );
4452
+
4453
+ }
4454
+
4455
+ const lLRM = lPreRotationM.clone().multiply( lRotationM ).multiply( lPostRotationM );
4456
+ // Global Rotation
4457
+ const lParentGRM = new Matrix4();
4458
+ lParentGRM.extractRotation( lParentGX );
4459
+
4460
+ // Global Shear*Scaling
4461
+ const lParentTM = new Matrix4();
4462
+ lParentTM.copyPosition( lParentGX );
4463
+
4464
+ const lParentGRSM = lParentTM.clone().invert().multiply( lParentGX );
4465
+ const lParentGSM = lParentGRM.clone().invert().multiply( lParentGRSM );
4466
+ const lLSM = lScalingM;
4467
+
4468
+ const lGlobalRS = new Matrix4();
4469
+
4470
+ if ( inheritType === 0 ) {
4471
+
4472
+ lGlobalRS.copy( lParentGRM ).multiply( lLRM ).multiply( lParentGSM ).multiply( lLSM );
4473
+
4474
+ } else if ( inheritType === 1 ) {
4475
+
4476
+ lGlobalRS.copy( lParentGRM ).multiply( lParentGSM ).multiply( lLRM ).multiply( lLSM );
4477
+
4478
+ } else {
4479
+
4480
+ const lParentLSM = new Matrix4().scale( new Vector3().setFromMatrixScale( lParentLX ) );
4481
+ const lParentLSM_inv = lParentLSM.clone().invert();
4482
+ const lParentGSM_noLocal = lParentGSM.clone().multiply( lParentLSM_inv );
4483
+
4484
+ lGlobalRS.copy( lParentGRM ).multiply( lLRM ).multiply( lParentGSM_noLocal ).multiply( lLSM );
4485
+
4486
+ }
4487
+
4488
+ const lRotationPivotM_inv = lRotationPivotM.clone().invert();
4489
+ const lScalingPivotM_inv = lScalingPivotM.clone().invert();
4490
+ // Calculate the local transform matrix
4491
+ 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 );
4492
+
4493
+ const lLocalTWithAllPivotAndOffsetInfo = new Matrix4().copyPosition( lTransform );
4494
+
4495
+ const lGlobalTranslation = lParentGX.clone().multiply( lLocalTWithAllPivotAndOffsetInfo );
4496
+ lGlobalT.copyPosition( lGlobalTranslation );
4497
+
4498
+ lTransform = lGlobalT.clone().multiply( lGlobalRS );
4499
+
4500
+ // from global to local
4501
+ lTransform.premultiply( lParentGX.invert() );
4502
+
4503
+ return lTransform;
4504
+
4505
+ }
4506
+
4507
+ // Returns the three.js intrinsic Euler order corresponding to FBX extrinsic Euler order
4508
+ // ref: http://help.autodesk.com/view/FBX/2017/ENU/?guid=__cpp_ref_class_fbx_euler_html
4509
+ function getEulerOrder( order ) {
4510
+
4511
+ order = order || 0;
4512
+
4513
+ const enums = [
4514
+ 'ZYX', // -> XYZ extrinsic
4515
+ 'YZX', // -> XZY extrinsic
4516
+ 'XZY', // -> YZX extrinsic
4517
+ 'ZXY', // -> YXZ extrinsic
4518
+ 'YXZ', // -> ZXY extrinsic
4519
+ 'XYZ', // -> ZYX extrinsic
4520
+ //'SphericXYZ', // not possible to support
4521
+ ];
4522
+
4523
+ if ( order === 6 ) {
4524
+
4525
+ console.warn( 'THREE.FBXLoader: unsupported Euler Order: Spherical XYZ. Animations and rotations may be incorrect.' );
4526
+ return enums[ 0 ];
4527
+
4528
+ }
4529
+
4530
+ return enums[ order ];
4531
+
4532
+ }
4533
+
4534
+ // Parses comma separated list of numbers and returns them an array.
4535
+ // Used internally by the TextParser
4536
+ function parseNumberArray( value ) {
4537
+
4538
+ const array = value.split( ',' ).map( function ( val ) {
4539
+
4540
+ return parseFloat( val );
4541
+
4542
+ } );
4543
+
4544
+ return array;
4545
+
4546
+ }
4547
+
4548
+ function convertArrayBufferToString( buffer, from, to ) {
4549
+
4550
+ if ( from === undefined ) from = 0;
4551
+ if ( to === undefined ) to = buffer.byteLength;
4552
+
4553
+ return new TextDecoder().decode( new Uint8Array( buffer, from, to ) );
4554
+
4555
+ }
4556
+
4557
+ function append( a, b ) {
4558
+
4559
+ for ( let i = 0, j = a.length, l = b.length; i < l; i ++, j ++ ) {
4560
+
4561
+ a[ j ] = b[ i ];
4562
+
4563
+ }
4564
+
4565
+ }
4566
+
4567
+ function slice( a, b, from, to ) {
4568
+
4569
+ for ( let i = from, j = 0; i < to; i ++, j ++ ) {
4570
+
4571
+ a[ j ] = b[ i ];
4572
+
4573
+ }
4574
+
4575
+ return a;
4576
+
4577
+ }
4578
+
4579
+
4580
+ export { FBXLoader };