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