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