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