vc-spaces365-threejs 0.180.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -0
  3. package/build/three.cjs +77750 -0
  4. package/build/three.core.js +58846 -0
  5. package/build/three.core.min.js +6 -0
  6. package/build/three.module.js +18484 -0
  7. package/build/three.module.min.js +6 -0
  8. package/build/three.tsl.js +636 -0
  9. package/build/three.tsl.min.js +6 -0
  10. package/build/three.webgpu.js +77332 -0
  11. package/build/three.webgpu.min.js +6 -0
  12. package/build/three.webgpu.nodes.js +77103 -0
  13. package/build/three.webgpu.nodes.min.js +6 -0
  14. package/examples/fonts/LICENSE +13 -0
  15. package/examples/fonts/README.md +11 -0
  16. package/examples/fonts/droid/NOTICE +190 -0
  17. package/examples/fonts/droid/README.txt +18 -0
  18. package/examples/fonts/droid/droid_sans_bold.typeface.json +1 -0
  19. package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +1 -0
  20. package/examples/fonts/droid/droid_sans_regular.typeface.json +1 -0
  21. package/examples/fonts/droid/droid_serif_bold.typeface.json +1 -0
  22. package/examples/fonts/droid/droid_serif_regular.typeface.json +1 -0
  23. package/examples/fonts/gentilis_bold.typeface.json +1 -0
  24. package/examples/fonts/gentilis_regular.typeface.json +1 -0
  25. package/examples/fonts/helvetiker_bold.typeface.json +1 -0
  26. package/examples/fonts/helvetiker_regular.typeface.json +1 -0
  27. package/examples/fonts/optimer_bold.typeface.json +1 -0
  28. package/examples/fonts/optimer_regular.typeface.json +1 -0
  29. package/examples/fonts/ttf/README.md +9 -0
  30. package/examples/fonts/ttf/kenpixel.ttf +0 -0
  31. package/examples/jsm/Addons.js +285 -0
  32. package/examples/jsm/animation/AnimationClipCreator.js +168 -0
  33. package/examples/jsm/animation/CCDIKSolver.js +591 -0
  34. package/examples/jsm/capabilities/WebGL.js +113 -0
  35. package/examples/jsm/capabilities/WebGPU.js +59 -0
  36. package/examples/jsm/controls/ArcballControls.js +3536 -0
  37. package/examples/jsm/controls/DragControls.js +452 -0
  38. package/examples/jsm/controls/FirstPersonControls.js +447 -0
  39. package/examples/jsm/controls/FlyControls.js +380 -0
  40. package/examples/jsm/controls/MapControls.js +62 -0
  41. package/examples/jsm/controls/OrbitControls.js +1860 -0
  42. package/examples/jsm/controls/PointerLockControls.js +264 -0
  43. package/examples/jsm/controls/TrackballControls.js +1001 -0
  44. package/examples/jsm/controls/TransformControls.js +1918 -0
  45. package/examples/jsm/csm/CSM.js +597 -0
  46. package/examples/jsm/csm/CSMFrustum.js +209 -0
  47. package/examples/jsm/csm/CSMHelper.js +243 -0
  48. package/examples/jsm/csm/CSMShader.js +307 -0
  49. package/examples/jsm/csm/CSMShadowNode.js +599 -0
  50. package/examples/jsm/curves/CurveExtras.js +694 -0
  51. package/examples/jsm/curves/NURBSCurve.js +155 -0
  52. package/examples/jsm/curves/NURBSSurface.js +98 -0
  53. package/examples/jsm/curves/NURBSUtils.js +532 -0
  54. package/examples/jsm/curves/NURBSVolume.js +82 -0
  55. package/examples/jsm/effects/AnaglyphEffect.js +179 -0
  56. package/examples/jsm/effects/AsciiEffect.js +310 -0
  57. package/examples/jsm/effects/OutlineEffect.js +489 -0
  58. package/examples/jsm/effects/ParallaxBarrierEffect.js +155 -0
  59. package/examples/jsm/effects/StereoEffect.js +91 -0
  60. package/examples/jsm/environments/DebugEnvironment.js +102 -0
  61. package/examples/jsm/environments/RoomEnvironment.js +182 -0
  62. package/examples/jsm/exporters/DRACOExporter.js +311 -0
  63. package/examples/jsm/exporters/EXRExporter.js +618 -0
  64. package/examples/jsm/exporters/GLTFExporter.js +3595 -0
  65. package/examples/jsm/exporters/KTX2Exporter.js +347 -0
  66. package/examples/jsm/exporters/OBJExporter.js +308 -0
  67. package/examples/jsm/exporters/PLYExporter.js +562 -0
  68. package/examples/jsm/exporters/STLExporter.js +221 -0
  69. package/examples/jsm/exporters/USDZExporter.js +1228 -0
  70. package/examples/jsm/geometries/BoxLineGeometry.js +92 -0
  71. package/examples/jsm/geometries/ConvexGeometry.js +72 -0
  72. package/examples/jsm/geometries/DecalGeometry.js +420 -0
  73. package/examples/jsm/geometries/ParametricFunctions.js +100 -0
  74. package/examples/jsm/geometries/ParametricGeometry.js +172 -0
  75. package/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  76. package/examples/jsm/geometries/TeapotGeometry.js +689 -0
  77. package/examples/jsm/geometries/TextGeometry.js +83 -0
  78. package/examples/jsm/helpers/LightProbeHelper.js +165 -0
  79. package/examples/jsm/helpers/LightProbeHelperGPU.js +102 -0
  80. package/examples/jsm/helpers/OctreeHelper.js +109 -0
  81. package/examples/jsm/helpers/PositionalAudioHelper.js +169 -0
  82. package/examples/jsm/helpers/RapierHelper.js +59 -0
  83. package/examples/jsm/helpers/RectAreaLightHelper.js +118 -0
  84. package/examples/jsm/helpers/TextureHelper.js +265 -0
  85. package/examples/jsm/helpers/TextureHelperGPU.js +214 -0
  86. package/examples/jsm/helpers/VertexNormalsHelper.js +155 -0
  87. package/examples/jsm/helpers/VertexTangentsHelper.js +133 -0
  88. package/examples/jsm/helpers/ViewHelper.js +422 -0
  89. package/examples/jsm/interactive/HTMLMesh.js +605 -0
  90. package/examples/jsm/interactive/InteractiveGroup.js +224 -0
  91. package/examples/jsm/interactive/SelectionBox.js +294 -0
  92. package/examples/jsm/interactive/SelectionHelper.js +150 -0
  93. package/examples/jsm/libs/ammo.wasm.js +822 -0
  94. package/examples/jsm/libs/ammo.wasm.wasm +0 -0
  95. package/examples/jsm/libs/basis/README.md +46 -0
  96. package/examples/jsm/libs/basis/basis_transcoder.js +19 -0
  97. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  98. package/examples/jsm/libs/chevrotain.module.min.js +141 -0
  99. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  100. package/examples/jsm/libs/draco/README.md +32 -0
  101. package/examples/jsm/libs/draco/draco_decoder.js +34 -0
  102. package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
  103. package/examples/jsm/libs/draco/draco_encoder.js +33 -0
  104. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -0
  105. package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -0
  106. package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
  107. package/examples/jsm/libs/draco/gltf/draco_encoder.js +33 -0
  108. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
  109. package/examples/jsm/libs/ecsy.module.js +1792 -0
  110. package/examples/jsm/libs/fflate.module.js +2672 -0
  111. package/examples/jsm/libs/ktx-parse.module.js +1 -0
  112. package/examples/jsm/libs/lil-gui.module.min.js +8 -0
  113. package/examples/jsm/libs/lottie_canvas.module.js +14849 -0
  114. package/examples/jsm/libs/meshopt_decoder.module.js +195 -0
  115. package/examples/jsm/libs/mikktspace.module.js +128 -0
  116. package/examples/jsm/libs/motion-controllers.module.js +397 -0
  117. package/examples/jsm/libs/opentype.module.js +14506 -0
  118. package/examples/jsm/libs/potpack.module.js +125 -0
  119. package/examples/jsm/libs/rhino3dm/rhino3dm.js +21 -0
  120. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +16 -0
  121. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  122. package/examples/jsm/libs/stats.module.js +167 -0
  123. package/examples/jsm/libs/surfaceNet.js +201 -0
  124. package/examples/jsm/libs/tween.module.js +876 -0
  125. package/examples/jsm/libs/utif.module.js +1665 -0
  126. package/examples/jsm/libs/zstddec.module.js +1 -0
  127. package/examples/jsm/lighting/TiledLighting.js +42 -0
  128. package/examples/jsm/lights/LightProbeGenerator.js +337 -0
  129. package/examples/jsm/lights/RectAreaLightTexturesLib.js +127 -0
  130. package/examples/jsm/lights/RectAreaLightUniformsLib.js +40 -0
  131. package/examples/jsm/lines/Line2.js +56 -0
  132. package/examples/jsm/lines/LineGeometry.js +157 -0
  133. package/examples/jsm/lines/LineMaterial.js +697 -0
  134. package/examples/jsm/lines/LineSegments2.js +426 -0
  135. package/examples/jsm/lines/LineSegmentsGeometry.js +298 -0
  136. package/examples/jsm/lines/Wireframe.js +108 -0
  137. package/examples/jsm/lines/WireframeGeometry2.js +49 -0
  138. package/examples/jsm/lines/webgpu/Line2.js +46 -0
  139. package/examples/jsm/lines/webgpu/LineSegments2.js +411 -0
  140. package/examples/jsm/lines/webgpu/Wireframe.js +86 -0
  141. package/examples/jsm/loaders/3DMLoader.js +1835 -0
  142. package/examples/jsm/loaders/3MFLoader.js +1621 -0
  143. package/examples/jsm/loaders/AMFLoader.js +541 -0
  144. package/examples/jsm/loaders/BVHLoader.js +484 -0
  145. package/examples/jsm/loaders/ColladaLoader.js +4155 -0
  146. package/examples/jsm/loaders/DDSLoader.js +385 -0
  147. package/examples/jsm/loaders/DRACOLoader.js +688 -0
  148. package/examples/jsm/loaders/EXRLoader.js +2784 -0
  149. package/examples/jsm/loaders/FBXLoader.js +4382 -0
  150. package/examples/jsm/loaders/FontLoader.js +242 -0
  151. package/examples/jsm/loaders/GCodeLoader.js +292 -0
  152. package/examples/jsm/loaders/GLTFLoader.js +4890 -0
  153. package/examples/jsm/loaders/HDRCubeTextureLoader.js +164 -0
  154. package/examples/jsm/loaders/HDRLoader.js +486 -0
  155. package/examples/jsm/loaders/IESLoader.js +379 -0
  156. package/examples/jsm/loaders/KMZLoader.js +163 -0
  157. package/examples/jsm/loaders/KTX2Loader.js +1228 -0
  158. package/examples/jsm/loaders/KTXLoader.js +197 -0
  159. package/examples/jsm/loaders/LDrawLoader.js +2519 -0
  160. package/examples/jsm/loaders/LUT3dlLoader.js +205 -0
  161. package/examples/jsm/loaders/LUTCubeLoader.js +190 -0
  162. package/examples/jsm/loaders/LUTImageLoader.js +190 -0
  163. package/examples/jsm/loaders/LWOLoader.js +1079 -0
  164. package/examples/jsm/loaders/LottieLoader.js +130 -0
  165. package/examples/jsm/loaders/MD2Loader.js +435 -0
  166. package/examples/jsm/loaders/MDDLoader.js +147 -0
  167. package/examples/jsm/loaders/MTLLoader.js +593 -0
  168. package/examples/jsm/loaders/MaterialXLoader.js +1087 -0
  169. package/examples/jsm/loaders/NRRDLoader.js +718 -0
  170. package/examples/jsm/loaders/OBJLoader.js +955 -0
  171. package/examples/jsm/loaders/PCDLoader.js +618 -0
  172. package/examples/jsm/loaders/PDBLoader.js +272 -0
  173. package/examples/jsm/loaders/PLYLoader.js +805 -0
  174. package/examples/jsm/loaders/PVRLoader.js +270 -0
  175. package/examples/jsm/loaders/RGBELoader.js +18 -0
  176. package/examples/jsm/loaders/STLLoader.js +421 -0
  177. package/examples/jsm/loaders/SVGLoader.js +3267 -0
  178. package/examples/jsm/loaders/TDSLoader.js +1144 -0
  179. package/examples/jsm/loaders/TGALoader.js +540 -0
  180. package/examples/jsm/loaders/TIFFLoader.js +59 -0
  181. package/examples/jsm/loaders/TTFLoader.js +261 -0
  182. package/examples/jsm/loaders/USDLoader.js +219 -0
  183. package/examples/jsm/loaders/USDZLoader.js +16 -0
  184. package/examples/jsm/loaders/UltraHDRLoader.js +630 -0
  185. package/examples/jsm/loaders/VOXLoader.js +376 -0
  186. package/examples/jsm/loaders/VRMLLoader.js +3569 -0
  187. package/examples/jsm/loaders/VTKLoader.js +1276 -0
  188. package/examples/jsm/loaders/XYZLoader.js +143 -0
  189. package/examples/jsm/loaders/lwo/IFFParser.js +1217 -0
  190. package/examples/jsm/loaders/lwo/LWO2Parser.js +414 -0
  191. package/examples/jsm/loaders/lwo/LWO3Parser.js +373 -0
  192. package/examples/jsm/loaders/usd/USDAParser.js +741 -0
  193. package/examples/jsm/loaders/usd/USDCParser.js +17 -0
  194. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +183 -0
  195. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +154 -0
  196. package/examples/jsm/materials/MeshGouraudMaterial.js +434 -0
  197. package/examples/jsm/materials/MeshPostProcessingMaterial.js +167 -0
  198. package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
  199. package/examples/jsm/math/Capsule.js +159 -0
  200. package/examples/jsm/math/ColorConverter.js +58 -0
  201. package/examples/jsm/math/ColorSpaces.js +147 -0
  202. package/examples/jsm/math/ConvexHull.js +1695 -0
  203. package/examples/jsm/math/ImprovedNoise.js +88 -0
  204. package/examples/jsm/math/Lut.js +317 -0
  205. package/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  206. package/examples/jsm/math/OBB.js +535 -0
  207. package/examples/jsm/math/Octree.js +692 -0
  208. package/examples/jsm/math/SimplexNoise.js +470 -0
  209. package/examples/jsm/misc/ConvexObjectBreaker.js +539 -0
  210. package/examples/jsm/misc/GPUComputationRenderer.js +506 -0
  211. package/examples/jsm/misc/Gyroscope.js +78 -0
  212. package/examples/jsm/misc/MD2Character.js +391 -0
  213. package/examples/jsm/misc/MD2CharacterComplex.js +740 -0
  214. package/examples/jsm/misc/MorphAnimMesh.js +119 -0
  215. package/examples/jsm/misc/MorphBlendMesh.js +425 -0
  216. package/examples/jsm/misc/ProgressiveLightMap.js +370 -0
  217. package/examples/jsm/misc/ProgressiveLightMapGPU.js +322 -0
  218. package/examples/jsm/misc/RollerCoaster.js +623 -0
  219. package/examples/jsm/misc/TubePainter.js +256 -0
  220. package/examples/jsm/misc/Volume.js +521 -0
  221. package/examples/jsm/misc/VolumeSlice.js +276 -0
  222. package/examples/jsm/modifiers/CurveModifier.js +374 -0
  223. package/examples/jsm/modifiers/CurveModifierGPU.js +256 -0
  224. package/examples/jsm/modifiers/EdgeSplitModifier.js +299 -0
  225. package/examples/jsm/modifiers/SimplifyModifier.js +632 -0
  226. package/examples/jsm/modifiers/TessellateModifier.js +340 -0
  227. package/examples/jsm/objects/GroundedSkybox.js +69 -0
  228. package/examples/jsm/objects/Lensflare.js +489 -0
  229. package/examples/jsm/objects/LensflareMesh.js +376 -0
  230. package/examples/jsm/objects/MarchingCubes.js +1261 -0
  231. package/examples/jsm/objects/Reflector.js +338 -0
  232. package/examples/jsm/objects/ReflectorForSSRPass.js +393 -0
  233. package/examples/jsm/objects/Refractor.js +389 -0
  234. package/examples/jsm/objects/ShadowMesh.js +130 -0
  235. package/examples/jsm/objects/Sky.js +237 -0
  236. package/examples/jsm/objects/SkyMesh.js +243 -0
  237. package/examples/jsm/objects/Water.js +373 -0
  238. package/examples/jsm/objects/Water2.js +401 -0
  239. package/examples/jsm/objects/Water2Mesh.js +199 -0
  240. package/examples/jsm/objects/WaterMesh.js +196 -0
  241. package/examples/jsm/offscreen/jank.js +45 -0
  242. package/examples/jsm/offscreen/offscreen.js +8 -0
  243. package/examples/jsm/offscreen/scene.js +86 -0
  244. package/examples/jsm/physics/AmmoPhysics.js +354 -0
  245. package/examples/jsm/physics/JoltPhysics.js +330 -0
  246. package/examples/jsm/physics/RapierPhysics.js +432 -0
  247. package/examples/jsm/postprocessing/AfterimagePass.js +185 -0
  248. package/examples/jsm/postprocessing/BloomPass.js +274 -0
  249. package/examples/jsm/postprocessing/BokehPass.js +218 -0
  250. package/examples/jsm/postprocessing/ClearPass.js +97 -0
  251. package/examples/jsm/postprocessing/CubeTexturePass.js +146 -0
  252. package/examples/jsm/postprocessing/DotScreenPass.js +114 -0
  253. package/examples/jsm/postprocessing/EffectComposer.js +363 -0
  254. package/examples/jsm/postprocessing/FXAAPass.js +40 -0
  255. package/examples/jsm/postprocessing/FilmPass.js +113 -0
  256. package/examples/jsm/postprocessing/GTAOPass.js +727 -0
  257. package/examples/jsm/postprocessing/GlitchPass.js +177 -0
  258. package/examples/jsm/postprocessing/HalftonePass.js +134 -0
  259. package/examples/jsm/postprocessing/LUTPass.js +138 -0
  260. package/examples/jsm/postprocessing/MaskPass.js +195 -0
  261. package/examples/jsm/postprocessing/OutlinePass.js +776 -0
  262. package/examples/jsm/postprocessing/OutputPass.js +139 -0
  263. package/examples/jsm/postprocessing/Pass.js +191 -0
  264. package/examples/jsm/postprocessing/RenderPass.js +183 -0
  265. package/examples/jsm/postprocessing/RenderPixelatedPass.js +314 -0
  266. package/examples/jsm/postprocessing/RenderTransitionPass.js +267 -0
  267. package/examples/jsm/postprocessing/SAOPass.js +407 -0
  268. package/examples/jsm/postprocessing/SMAAPass.js +230 -0
  269. package/examples/jsm/postprocessing/SSAARenderPass.js +313 -0
  270. package/examples/jsm/postprocessing/SSAOPass.js +527 -0
  271. package/examples/jsm/postprocessing/SSRPass.js +856 -0
  272. package/examples/jsm/postprocessing/SavePass.js +132 -0
  273. package/examples/jsm/postprocessing/ShaderPass.js +135 -0
  274. package/examples/jsm/postprocessing/TAARenderPass.js +243 -0
  275. package/examples/jsm/postprocessing/TexturePass.js +131 -0
  276. package/examples/jsm/postprocessing/UnrealBloomPass.js +492 -0
  277. package/examples/jsm/renderers/CSS2DRenderer.js +317 -0
  278. package/examples/jsm/renderers/CSS3DRenderer.js +453 -0
  279. package/examples/jsm/renderers/Projector.js +936 -0
  280. package/examples/jsm/renderers/SVGRenderer.js +685 -0
  281. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +96 -0
  282. package/examples/jsm/shaders/AfterimageShader.js +63 -0
  283. package/examples/jsm/shaders/BasicShader.js +36 -0
  284. package/examples/jsm/shaders/BleachBypassShader.js +68 -0
  285. package/examples/jsm/shaders/BlendShader.js +56 -0
  286. package/examples/jsm/shaders/BokehShader.js +151 -0
  287. package/examples/jsm/shaders/BokehShader2.js +404 -0
  288. package/examples/jsm/shaders/BrightnessContrastShader.js +62 -0
  289. package/examples/jsm/shaders/ColorCorrectionShader.js +59 -0
  290. package/examples/jsm/shaders/ColorifyShader.js +57 -0
  291. package/examples/jsm/shaders/ConvolutionShader.js +74 -0
  292. package/examples/jsm/shaders/CopyShader.js +52 -0
  293. package/examples/jsm/shaders/DOFMipMapShader.js +63 -0
  294. package/examples/jsm/shaders/DepthLimitedBlurShader.js +180 -0
  295. package/examples/jsm/shaders/DigitalGlitch.js +104 -0
  296. package/examples/jsm/shaders/DotScreenShader.js +75 -0
  297. package/examples/jsm/shaders/ExposureShader.js +51 -0
  298. package/examples/jsm/shaders/FXAAShader.js +298 -0
  299. package/examples/jsm/shaders/FilmShader.js +72 -0
  300. package/examples/jsm/shaders/FocusShader.js +94 -0
  301. package/examples/jsm/shaders/FreiChenShader.js +103 -0
  302. package/examples/jsm/shaders/GTAOShader.js +421 -0
  303. package/examples/jsm/shaders/GammaCorrectionShader.js +52 -0
  304. package/examples/jsm/shaders/GodRaysShader.js +333 -0
  305. package/examples/jsm/shaders/HalftoneShader.js +321 -0
  306. package/examples/jsm/shaders/HorizontalBlurShader.js +68 -0
  307. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +70 -0
  308. package/examples/jsm/shaders/HueSaturationShader.js +74 -0
  309. package/examples/jsm/shaders/KaleidoShader.js +65 -0
  310. package/examples/jsm/shaders/LuminosityHighPassShader.js +68 -0
  311. package/examples/jsm/shaders/LuminosityShader.js +54 -0
  312. package/examples/jsm/shaders/MirrorShader.js +62 -0
  313. package/examples/jsm/shaders/NormalMapShader.js +60 -0
  314. package/examples/jsm/shaders/OutputShader.js +103 -0
  315. package/examples/jsm/shaders/PoissonDenoiseShader.js +235 -0
  316. package/examples/jsm/shaders/RGBShiftShader.js +61 -0
  317. package/examples/jsm/shaders/SAOShader.js +188 -0
  318. package/examples/jsm/shaders/SMAAShader.js +489 -0
  319. package/examples/jsm/shaders/SSAOShader.js +321 -0
  320. package/examples/jsm/shaders/SSRShader.js +395 -0
  321. package/examples/jsm/shaders/SepiaShader.js +57 -0
  322. package/examples/jsm/shaders/SobelOperatorShader.js +98 -0
  323. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +95 -0
  324. package/examples/jsm/shaders/TechnicolorShader.js +51 -0
  325. package/examples/jsm/shaders/ToonShader.js +349 -0
  326. package/examples/jsm/shaders/TriangleBlurShader.js +79 -0
  327. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +62 -0
  328. package/examples/jsm/shaders/VelocityShader.js +137 -0
  329. package/examples/jsm/shaders/VerticalBlurShader.js +66 -0
  330. package/examples/jsm/shaders/VerticalTiltShiftShader.js +70 -0
  331. package/examples/jsm/shaders/VignetteShader.js +56 -0
  332. package/examples/jsm/shaders/VolumeShader.js +298 -0
  333. package/examples/jsm/shaders/WaterRefractionShader.js +106 -0
  334. package/examples/jsm/textures/FlakesTexture.js +54 -0
  335. package/examples/jsm/textures/IESTexture.js +101 -0
  336. package/examples/jsm/transpiler/AST.js +631 -0
  337. package/examples/jsm/transpiler/GLSLDecoder.js +1171 -0
  338. package/examples/jsm/transpiler/Linker.js +327 -0
  339. package/examples/jsm/transpiler/ShaderToyDecoder.js +49 -0
  340. package/examples/jsm/transpiler/TSLEncoder.js +933 -0
  341. package/examples/jsm/transpiler/Transpiler.js +67 -0
  342. package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
  343. package/examples/jsm/transpiler/WGSLEncoder.js +812 -0
  344. package/examples/jsm/tsl/display/AfterImageNode.js +242 -0
  345. package/examples/jsm/tsl/display/AnaglyphPassNode.js +107 -0
  346. package/examples/jsm/tsl/display/AnamorphicNode.js +281 -0
  347. package/examples/jsm/tsl/display/BleachBypass.js +33 -0
  348. package/examples/jsm/tsl/display/BloomNode.js +520 -0
  349. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +207 -0
  350. package/examples/jsm/tsl/display/DenoiseNode.js +332 -0
  351. package/examples/jsm/tsl/display/DepthOfFieldNode.js +547 -0
  352. package/examples/jsm/tsl/display/DotScreenNode.js +104 -0
  353. package/examples/jsm/tsl/display/FXAANode.js +365 -0
  354. package/examples/jsm/tsl/display/FilmNode.js +101 -0
  355. package/examples/jsm/tsl/display/GTAONode.js +530 -0
  356. package/examples/jsm/tsl/display/GaussianBlurNode.js +378 -0
  357. package/examples/jsm/tsl/display/LensflareNode.js +279 -0
  358. package/examples/jsm/tsl/display/Lut3DNode.js +109 -0
  359. package/examples/jsm/tsl/display/MotionBlur.js +33 -0
  360. package/examples/jsm/tsl/display/OutlineNode.js +751 -0
  361. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +89 -0
  362. package/examples/jsm/tsl/display/PixelationPassNode.js +334 -0
  363. package/examples/jsm/tsl/display/RGBShiftNode.js +96 -0
  364. package/examples/jsm/tsl/display/SMAANode.js +768 -0
  365. package/examples/jsm/tsl/display/SSAAPassNode.js +358 -0
  366. package/examples/jsm/tsl/display/SSGINode.js +650 -0
  367. package/examples/jsm/tsl/display/SSRNode.js +654 -0
  368. package/examples/jsm/tsl/display/Sepia.js +24 -0
  369. package/examples/jsm/tsl/display/SobelOperatorNode.js +168 -0
  370. package/examples/jsm/tsl/display/StereoCompositePassNode.js +185 -0
  371. package/examples/jsm/tsl/display/StereoPassNode.js +120 -0
  372. package/examples/jsm/tsl/display/TRAANode.js +461 -0
  373. package/examples/jsm/tsl/display/TransitionNode.js +141 -0
  374. package/examples/jsm/tsl/display/boxBlur.js +64 -0
  375. package/examples/jsm/tsl/display/hashBlur.js +53 -0
  376. package/examples/jsm/tsl/lighting/TiledLightsNode.js +422 -0
  377. package/examples/jsm/tsl/math/Bayer.js +34 -0
  378. package/examples/jsm/tsl/shadows/TileShadowNode.js +456 -0
  379. package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +212 -0
  380. package/examples/jsm/tsl/utils/Raymarching.js +70 -0
  381. package/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
  382. package/examples/jsm/utils/CameraUtils.js +82 -0
  383. package/examples/jsm/utils/GeometryCompressionUtils.js +547 -0
  384. package/examples/jsm/utils/GeometryUtils.js +226 -0
  385. package/examples/jsm/utils/LDrawUtils.js +211 -0
  386. package/examples/jsm/utils/SceneOptimizer.js +458 -0
  387. package/examples/jsm/utils/SceneUtils.js +363 -0
  388. package/examples/jsm/utils/ShadowMapViewer.js +230 -0
  389. package/examples/jsm/utils/ShadowMapViewerGPU.js +233 -0
  390. package/examples/jsm/utils/SkeletonUtils.js +490 -0
  391. package/examples/jsm/utils/SortUtils.js +175 -0
  392. package/examples/jsm/utils/UVsDebug.js +173 -0
  393. package/examples/jsm/utils/WebGLTextureUtils.js +115 -0
  394. package/examples/jsm/utils/WebGPUTextureUtils.js +81 -0
  395. package/examples/jsm/utils/WorkerPool.js +167 -0
  396. package/examples/jsm/webxr/ARButton.js +251 -0
  397. package/examples/jsm/webxr/OculusHandModel.js +194 -0
  398. package/examples/jsm/webxr/OculusHandPointerModel.js +539 -0
  399. package/examples/jsm/webxr/Text2D.js +52 -0
  400. package/examples/jsm/webxr/VRButton.js +264 -0
  401. package/examples/jsm/webxr/XRButton.js +246 -0
  402. package/examples/jsm/webxr/XRControllerModelFactory.js +403 -0
  403. package/examples/jsm/webxr/XREstimatedLight.js +254 -0
  404. package/examples/jsm/webxr/XRHandMeshModel.js +151 -0
  405. package/examples/jsm/webxr/XRHandModelFactory.js +197 -0
  406. package/examples/jsm/webxr/XRHandPrimitiveModel.js +147 -0
  407. package/examples/jsm/webxr/XRPlanes.js +118 -0
  408. package/package.json +134 -0
  409. package/src/Three.Core.js +185 -0
  410. package/src/Three.Legacy.js +0 -0
  411. package/src/Three.TSL.js +629 -0
  412. package/src/Three.WebGPU.Nodes.js +24 -0
  413. package/src/Three.WebGPU.js +26 -0
  414. package/src/Three.js +9 -0
  415. package/src/animation/AnimationAction.js +932 -0
  416. package/src/animation/AnimationClip.js +628 -0
  417. package/src/animation/AnimationMixer.js +854 -0
  418. package/src/animation/AnimationObjectGroup.js +411 -0
  419. package/src/animation/AnimationUtils.js +506 -0
  420. package/src/animation/KeyframeTrack.js +597 -0
  421. package/src/animation/PropertyBinding.js +794 -0
  422. package/src/animation/PropertyMixer.js +385 -0
  423. package/src/animation/tracks/BooleanKeyframeTrack.js +55 -0
  424. package/src/animation/tracks/ColorKeyframeTrack.js +36 -0
  425. package/src/animation/tracks/NumberKeyframeTrack.js +36 -0
  426. package/src/animation/tracks/QuaternionKeyframeTrack.js +51 -0
  427. package/src/animation/tracks/StringKeyframeTrack.js +55 -0
  428. package/src/animation/tracks/VectorKeyframeTrack.js +36 -0
  429. package/src/audio/Audio.js +778 -0
  430. package/src/audio/AudioAnalyser.js +97 -0
  431. package/src/audio/AudioContext.js +40 -0
  432. package/src/audio/AudioListener.js +216 -0
  433. package/src/audio/PositionalAudio.js +253 -0
  434. package/src/cameras/ArrayCamera.js +54 -0
  435. package/src/cameras/Camera.js +130 -0
  436. package/src/cameras/CubeCamera.js +239 -0
  437. package/src/cameras/OrthographicCamera.js +245 -0
  438. package/src/cameras/PerspectiveCamera.js +407 -0
  439. package/src/cameras/StereoCamera.js +146 -0
  440. package/src/constants.js +1675 -0
  441. package/src/core/BufferAttribute.js +1044 -0
  442. package/src/core/BufferGeometry.js +1446 -0
  443. package/src/core/Clock.js +128 -0
  444. package/src/core/EventDispatcher.js +131 -0
  445. package/src/core/GLBufferAttribute.js +171 -0
  446. package/src/core/InstancedBufferAttribute.js +68 -0
  447. package/src/core/InstancedBufferGeometry.js +60 -0
  448. package/src/core/InstancedInterleavedBuffer.js +74 -0
  449. package/src/core/InterleavedBuffer.js +291 -0
  450. package/src/core/InterleavedBufferAttribute.js +549 -0
  451. package/src/core/Layers.js +121 -0
  452. package/src/core/Object3D.js +1619 -0
  453. package/src/core/Raycaster.js +262 -0
  454. package/src/core/RenderTarget.js +392 -0
  455. package/src/core/RenderTarget3D.js +48 -0
  456. package/src/core/Timer.js +184 -0
  457. package/src/core/Uniform.js +46 -0
  458. package/src/core/UniformsGroup.js +180 -0
  459. package/src/extras/Controls.js +120 -0
  460. package/src/extras/DataUtils.js +217 -0
  461. package/src/extras/Earcut.js +22 -0
  462. package/src/extras/ImageUtils.js +137 -0
  463. package/src/extras/PMREMGenerator.js +966 -0
  464. package/src/extras/ShapeUtils.js +114 -0
  465. package/src/extras/TextureUtils.js +293 -0
  466. package/src/extras/core/Curve.js +517 -0
  467. package/src/extras/core/CurvePath.js +296 -0
  468. package/src/extras/core/Interpolations.js +105 -0
  469. package/src/extras/core/Path.js +329 -0
  470. package/src/extras/core/Shape.js +165 -0
  471. package/src/extras/core/ShapePath.js +367 -0
  472. package/src/extras/curves/ArcCurve.js +39 -0
  473. package/src/extras/curves/CatmullRomCurve3.js +326 -0
  474. package/src/extras/curves/CubicBezierCurve.js +145 -0
  475. package/src/extras/curves/CubicBezierCurve3.js +129 -0
  476. package/src/extras/curves/Curves.js +10 -0
  477. package/src/extras/curves/EllipseCurve.js +258 -0
  478. package/src/extras/curves/LineCurve.js +128 -0
  479. package/src/extras/curves/LineCurve3.js +128 -0
  480. package/src/extras/curves/QuadraticBezierCurve.js +133 -0
  481. package/src/extras/curves/QuadraticBezierCurve3.js +118 -0
  482. package/src/extras/curves/SplineCurve.js +145 -0
  483. package/src/extras/lib/earcut.js +685 -0
  484. package/src/geometries/BoxGeometry.js +218 -0
  485. package/src/geometries/CapsuleGeometry.js +217 -0
  486. package/src/geometries/CircleGeometry.js +141 -0
  487. package/src/geometries/ConeGeometry.js +69 -0
  488. package/src/geometries/CylinderGeometry.js +332 -0
  489. package/src/geometries/DodecahedronGeometry.js +98 -0
  490. package/src/geometries/EdgesGeometry.js +180 -0
  491. package/src/geometries/ExtrudeGeometry.js +909 -0
  492. package/src/geometries/Geometries.js +21 -0
  493. package/src/geometries/IcosahedronGeometry.js +74 -0
  494. package/src/geometries/LatheGeometry.js +229 -0
  495. package/src/geometries/OctahedronGeometry.js +69 -0
  496. package/src/geometries/PlaneGeometry.js +132 -0
  497. package/src/geometries/PolyhedronGeometry.js +348 -0
  498. package/src/geometries/RingGeometry.js +164 -0
  499. package/src/geometries/ShapeGeometry.js +232 -0
  500. package/src/geometries/SphereGeometry.js +174 -0
  501. package/src/geometries/TetrahedronGeometry.js +66 -0
  502. package/src/geometries/TorusGeometry.js +155 -0
  503. package/src/geometries/TorusKnotGeometry.js +205 -0
  504. package/src/geometries/TubeGeometry.js +252 -0
  505. package/src/geometries/WireframeGeometry.js +179 -0
  506. package/src/helpers/ArrowHelper.js +171 -0
  507. package/src/helpers/AxesHelper.js +96 -0
  508. package/src/helpers/Box3Helper.js +83 -0
  509. package/src/helpers/BoxHelper.js +149 -0
  510. package/src/helpers/CameraHelper.js +342 -0
  511. package/src/helpers/DirectionalLightHelper.js +145 -0
  512. package/src/helpers/GridHelper.js +82 -0
  513. package/src/helpers/HemisphereLightHelper.js +127 -0
  514. package/src/helpers/PlaneHelper.js +96 -0
  515. package/src/helpers/PointLightHelper.js +135 -0
  516. package/src/helpers/PolarGridHelper.js +126 -0
  517. package/src/helpers/SkeletonHelper.js +194 -0
  518. package/src/helpers/SpotLightHelper.js +151 -0
  519. package/src/lights/AmbientLight.js +42 -0
  520. package/src/lights/DirectionalLight.js +100 -0
  521. package/src/lights/DirectionalLightShadow.js +31 -0
  522. package/src/lights/HemisphereLight.js +66 -0
  523. package/src/lights/Light.js +95 -0
  524. package/src/lights/LightProbe.js +90 -0
  525. package/src/lights/LightShadow.js +338 -0
  526. package/src/lights/PointLight.js +116 -0
  527. package/src/lights/PointLightShadow.js +117 -0
  528. package/src/lights/RectAreaLight.js +115 -0
  529. package/src/lights/SpotLight.js +173 -0
  530. package/src/lights/SpotLightShadow.js +80 -0
  531. package/src/lights/webgpu/IESSpotLight.js +46 -0
  532. package/src/lights/webgpu/ProjectorLight.js +46 -0
  533. package/src/loaders/AnimationLoader.js +98 -0
  534. package/src/loaders/AudioLoader.js +98 -0
  535. package/src/loaders/BufferGeometryLoader.js +242 -0
  536. package/src/loaders/Cache.js +87 -0
  537. package/src/loaders/CompressedTextureLoader.js +167 -0
  538. package/src/loaders/CubeTextureLoader.js +103 -0
  539. package/src/loaders/DataTextureLoader.js +172 -0
  540. package/src/loaders/FileLoader.js +368 -0
  541. package/src/loaders/IESLoader.js +327 -0
  542. package/src/loaders/ImageBitmapLoader.js +220 -0
  543. package/src/loaders/ImageLoader.js +168 -0
  544. package/src/loaders/Loader.js +216 -0
  545. package/src/loaders/LoaderUtils.js +59 -0
  546. package/src/loaders/LoadingManager.js +307 -0
  547. package/src/loaders/MaterialLoader.js +438 -0
  548. package/src/loaders/ObjectLoader.js +1264 -0
  549. package/src/loaders/TextureLoader.js +74 -0
  550. package/src/loaders/nodes/NodeLoader.js +194 -0
  551. package/src/loaders/nodes/NodeMaterialLoader.js +108 -0
  552. package/src/loaders/nodes/NodeObjectLoader.js +151 -0
  553. package/src/materials/LineBasicMaterial.js +122 -0
  554. package/src/materials/LineDashedMaterial.js +86 -0
  555. package/src/materials/Material.js +1015 -0
  556. package/src/materials/Materials.js +39 -0
  557. package/src/materials/MeshBasicMaterial.js +249 -0
  558. package/src/materials/MeshDepthMaterial.js +147 -0
  559. package/src/materials/MeshDistanceMaterial.js +119 -0
  560. package/src/materials/MeshLambertMaterial.js +392 -0
  561. package/src/materials/MeshMatcapMaterial.js +223 -0
  562. package/src/materials/MeshNormalMaterial.js +174 -0
  563. package/src/materials/MeshPhongMaterial.js +411 -0
  564. package/src/materials/MeshPhysicalMaterial.js +535 -0
  565. package/src/materials/MeshStandardMaterial.js +424 -0
  566. package/src/materials/MeshToonMaterial.js +320 -0
  567. package/src/materials/PointsMaterial.js +139 -0
  568. package/src/materials/RawShaderMaterial.js +42 -0
  569. package/src/materials/ShaderMaterial.js +394 -0
  570. package/src/materials/ShadowMaterial.js +91 -0
  571. package/src/materials/SpriteMaterial.js +136 -0
  572. package/src/materials/nodes/Line2NodeMaterial.js +542 -0
  573. package/src/materials/nodes/LineBasicNodeMaterial.js +46 -0
  574. package/src/materials/nodes/LineDashedNodeMaterial.js +132 -0
  575. package/src/materials/nodes/MeshBasicNodeMaterial.js +134 -0
  576. package/src/materials/nodes/MeshLambertNodeMaterial.js +82 -0
  577. package/src/materials/nodes/MeshMatcapNodeMaterial.js +77 -0
  578. package/src/materials/nodes/MeshNormalNodeMaterial.js +67 -0
  579. package/src/materials/nodes/MeshPhongNodeMaterial.js +141 -0
  580. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +518 -0
  581. package/src/materials/nodes/MeshSSSNodeMaterial.js +175 -0
  582. package/src/materials/nodes/MeshStandardNodeMaterial.js +186 -0
  583. package/src/materials/nodes/MeshToonNodeMaterial.js +66 -0
  584. package/src/materials/nodes/NodeMaterial.js +1271 -0
  585. package/src/materials/nodes/NodeMaterials.js +21 -0
  586. package/src/materials/nodes/PointsNodeMaterial.js +211 -0
  587. package/src/materials/nodes/ShadowNodeMaterial.js +76 -0
  588. package/src/materials/nodes/SpriteNodeMaterial.js +186 -0
  589. package/src/materials/nodes/VolumeNodeMaterial.js +81 -0
  590. package/src/materials/nodes/manager/NodeMaterialObserver.js +612 -0
  591. package/src/math/Box2.js +381 -0
  592. package/src/math/Box3.js +805 -0
  593. package/src/math/Color.js +967 -0
  594. package/src/math/ColorManagement.js +215 -0
  595. package/src/math/Cylindrical.js +120 -0
  596. package/src/math/Euler.js +449 -0
  597. package/src/math/Frustum.js +285 -0
  598. package/src/math/FrustumArray.js +258 -0
  599. package/src/math/Interpolant.js +320 -0
  600. package/src/math/Line3.js +336 -0
  601. package/src/math/MathUtils.js +751 -0
  602. package/src/math/Matrix2.js +124 -0
  603. package/src/math/Matrix3.js +613 -0
  604. package/src/math/Matrix4.js +1301 -0
  605. package/src/math/Plane.js +367 -0
  606. package/src/math/Quaternion.js +943 -0
  607. package/src/math/Ray.js +655 -0
  608. package/src/math/Sphere.js +420 -0
  609. package/src/math/Spherical.js +147 -0
  610. package/src/math/SphericalHarmonics3.js +341 -0
  611. package/src/math/Triangle.js +539 -0
  612. package/src/math/Vector2.js +866 -0
  613. package/src/math/Vector3.js +1261 -0
  614. package/src/math/Vector4.js +1063 -0
  615. package/src/math/interpolants/CubicInterpolant.js +159 -0
  616. package/src/math/interpolants/DiscreteInterpolant.js +34 -0
  617. package/src/math/interpolants/LinearInterpolant.js +51 -0
  618. package/src/math/interpolants/QuaternionLinearInterpolant.js +48 -0
  619. package/src/nodes/Nodes.js +148 -0
  620. package/src/nodes/TSL.js +173 -0
  621. package/src/nodes/accessors/AccessorsUtils.js +53 -0
  622. package/src/nodes/accessors/Arrays.js +68 -0
  623. package/src/nodes/accessors/BatchNode.js +163 -0
  624. package/src/nodes/accessors/Bitangent.js +82 -0
  625. package/src/nodes/accessors/BufferAttributeNode.js +340 -0
  626. package/src/nodes/accessors/BufferNode.js +101 -0
  627. package/src/nodes/accessors/BuiltinNode.js +63 -0
  628. package/src/nodes/accessors/Camera.js +282 -0
  629. package/src/nodes/accessors/ClippingNode.js +255 -0
  630. package/src/nodes/accessors/CubeTextureNode.js +190 -0
  631. package/src/nodes/accessors/InstanceNode.js +244 -0
  632. package/src/nodes/accessors/InstancedMeshNode.js +50 -0
  633. package/src/nodes/accessors/Lights.js +129 -0
  634. package/src/nodes/accessors/MaterialNode.js +775 -0
  635. package/src/nodes/accessors/MaterialProperties.js +59 -0
  636. package/src/nodes/accessors/MaterialReferenceNode.js +85 -0
  637. package/src/nodes/accessors/ModelNode.js +184 -0
  638. package/src/nodes/accessors/ModelViewProjectionNode.js +13 -0
  639. package/src/nodes/accessors/MorphNode.js +310 -0
  640. package/src/nodes/accessors/Normal.js +243 -0
  641. package/src/nodes/accessors/Object3DNode.js +268 -0
  642. package/src/nodes/accessors/PointUVNode.js +55 -0
  643. package/src/nodes/accessors/Position.js +74 -0
  644. package/src/nodes/accessors/ReferenceBaseNode.js +357 -0
  645. package/src/nodes/accessors/ReferenceNode.js +424 -0
  646. package/src/nodes/accessors/ReflectVector.js +36 -0
  647. package/src/nodes/accessors/RendererReferenceNode.js +79 -0
  648. package/src/nodes/accessors/SceneNode.js +145 -0
  649. package/src/nodes/accessors/SkinningNode.js +327 -0
  650. package/src/nodes/accessors/StorageBufferNode.js +416 -0
  651. package/src/nodes/accessors/StorageTextureNode.js +242 -0
  652. package/src/nodes/accessors/Tangent.js +70 -0
  653. package/src/nodes/accessors/TangentUtils.js +46 -0
  654. package/src/nodes/accessors/Texture3DNode.js +199 -0
  655. package/src/nodes/accessors/TextureBicubic.js +92 -0
  656. package/src/nodes/accessors/TextureNode.js +894 -0
  657. package/src/nodes/accessors/TextureSizeNode.js +77 -0
  658. package/src/nodes/accessors/UV.js +11 -0
  659. package/src/nodes/accessors/UniformArrayNode.js +348 -0
  660. package/src/nodes/accessors/UserDataNode.js +77 -0
  661. package/src/nodes/accessors/VelocityNode.js +224 -0
  662. package/src/nodes/accessors/VertexColorNode.js +110 -0
  663. package/src/nodes/code/CodeNode.js +181 -0
  664. package/src/nodes/code/ExpressionNode.js +68 -0
  665. package/src/nodes/code/FunctionCallNode.js +187 -0
  666. package/src/nodes/code/FunctionNode.js +183 -0
  667. package/src/nodes/code/ScriptableNode.js +726 -0
  668. package/src/nodes/code/ScriptableValueNode.js +253 -0
  669. package/src/nodes/core/ArrayNode.js +154 -0
  670. package/src/nodes/core/AssignNode.js +202 -0
  671. package/src/nodes/core/AttributeNode.js +168 -0
  672. package/src/nodes/core/BypassNode.js +93 -0
  673. package/src/nodes/core/CacheNode.js +100 -0
  674. package/src/nodes/core/ConstNode.js +67 -0
  675. package/src/nodes/core/ContextNode.js +190 -0
  676. package/src/nodes/core/IndexNode.js +164 -0
  677. package/src/nodes/core/InputNode.js +136 -0
  678. package/src/nodes/core/LightingModel.js +77 -0
  679. package/src/nodes/core/MRTNode.js +150 -0
  680. package/src/nodes/core/Node.js +959 -0
  681. package/src/nodes/core/NodeAttribute.js +53 -0
  682. package/src/nodes/core/NodeBuilder.js +2968 -0
  683. package/src/nodes/core/NodeCache.js +75 -0
  684. package/src/nodes/core/NodeCode.js +46 -0
  685. package/src/nodes/core/NodeFrame.js +306 -0
  686. package/src/nodes/core/NodeFunction.js +69 -0
  687. package/src/nodes/core/NodeFunctionInput.js +61 -0
  688. package/src/nodes/core/NodeParser.js +23 -0
  689. package/src/nodes/core/NodeUniform.js +91 -0
  690. package/src/nodes/core/NodeUtils.js +480 -0
  691. package/src/nodes/core/NodeVar.js +60 -0
  692. package/src/nodes/core/NodeVarying.js +63 -0
  693. package/src/nodes/core/OutputStructNode.js +103 -0
  694. package/src/nodes/core/ParameterNode.js +94 -0
  695. package/src/nodes/core/PropertyNode.js +344 -0
  696. package/src/nodes/core/StackNode.js +376 -0
  697. package/src/nodes/core/StructNode.js +120 -0
  698. package/src/nodes/core/StructType.js +13 -0
  699. package/src/nodes/core/StructTypeNode.js +154 -0
  700. package/src/nodes/core/SubBuildNode.js +89 -0
  701. package/src/nodes/core/TempNode.js +88 -0
  702. package/src/nodes/core/UniformGroupNode.js +137 -0
  703. package/src/nodes/core/UniformNode.js +243 -0
  704. package/src/nodes/core/VarNode.js +284 -0
  705. package/src/nodes/core/VaryingNode.js +227 -0
  706. package/src/nodes/core/constants.js +68 -0
  707. package/src/nodes/display/BlendModes.js +235 -0
  708. package/src/nodes/display/BumpMapNode.js +117 -0
  709. package/src/nodes/display/ColorAdjustment.js +141 -0
  710. package/src/nodes/display/ColorSpaceFunctions.js +54 -0
  711. package/src/nodes/display/ColorSpaceNode.js +164 -0
  712. package/src/nodes/display/FrontFacingNode.js +102 -0
  713. package/src/nodes/display/NormalMapNode.js +118 -0
  714. package/src/nodes/display/PassNode.js +905 -0
  715. package/src/nodes/display/PosterizeNode.js +65 -0
  716. package/src/nodes/display/RenderOutputNode.js +124 -0
  717. package/src/nodes/display/ScreenNode.js +290 -0
  718. package/src/nodes/display/ToneMappingFunctions.js +242 -0
  719. package/src/nodes/display/ToneMappingNode.js +121 -0
  720. package/src/nodes/display/ToonOutlinePassNode.js +183 -0
  721. package/src/nodes/display/ViewportDepthNode.js +294 -0
  722. package/src/nodes/display/ViewportDepthTextureNode.js +67 -0
  723. package/src/nodes/display/ViewportSharedTextureNode.js +73 -0
  724. package/src/nodes/display/ViewportTextureNode.js +228 -0
  725. package/src/nodes/fog/Fog.js +114 -0
  726. package/src/nodes/functions/BSDF/BRDF_GGX.js +55 -0
  727. package/src/nodes/functions/BSDF/BRDF_Lambert.js +9 -0
  728. package/src/nodes/functions/BSDF/BRDF_Sheen.js +57 -0
  729. package/src/nodes/functions/BSDF/DFGApprox.js +30 -0
  730. package/src/nodes/functions/BSDF/D_GGX.js +23 -0
  731. package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +28 -0
  732. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +13 -0
  733. package/src/nodes/functions/BSDF/F_Schlick.js +16 -0
  734. package/src/nodes/functions/BSDF/LTC.js +175 -0
  735. package/src/nodes/functions/BSDF/Schlick_to_F0.js +21 -0
  736. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +26 -0
  737. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +29 -0
  738. package/src/nodes/functions/BasicLightingModel.js +100 -0
  739. package/src/nodes/functions/PhongLightingModel.js +99 -0
  740. package/src/nodes/functions/PhysicalLightingModel.js +796 -0
  741. package/src/nodes/functions/ShadowMaskModel.js +58 -0
  742. package/src/nodes/functions/ToonLightingModel.js +70 -0
  743. package/src/nodes/functions/VolumetricLightingModel.js +183 -0
  744. package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
  745. package/src/nodes/functions/material/getGeometryRoughness.js +19 -0
  746. package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
  747. package/src/nodes/functions/material/getRoughness.js +18 -0
  748. package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
  749. package/src/nodes/geometry/RangeNode.js +172 -0
  750. package/src/nodes/gpgpu/AtomicFunctionNode.js +274 -0
  751. package/src/nodes/gpgpu/BarrierNode.js +89 -0
  752. package/src/nodes/gpgpu/ComputeBuiltinNode.js +228 -0
  753. package/src/nodes/gpgpu/ComputeNode.js +273 -0
  754. package/src/nodes/gpgpu/SubgroupFunctionNode.js +430 -0
  755. package/src/nodes/gpgpu/WorkgroupInfoNode.js +234 -0
  756. package/src/nodes/lighting/AONode.js +45 -0
  757. package/src/nodes/lighting/AmbientLightNode.js +35 -0
  758. package/src/nodes/lighting/AnalyticLightNode.js +256 -0
  759. package/src/nodes/lighting/BasicEnvironmentNode.js +49 -0
  760. package/src/nodes/lighting/BasicLightMapNode.js +49 -0
  761. package/src/nodes/lighting/DirectionalLightNode.js +39 -0
  762. package/src/nodes/lighting/EnvironmentNode.js +153 -0
  763. package/src/nodes/lighting/HemisphereLightNode.js +87 -0
  764. package/src/nodes/lighting/IESSpotLightNode.js +49 -0
  765. package/src/nodes/lighting/IrradianceNode.js +44 -0
  766. package/src/nodes/lighting/LightProbeNode.js +73 -0
  767. package/src/nodes/lighting/LightUtils.js +25 -0
  768. package/src/nodes/lighting/LightingContextNode.js +115 -0
  769. package/src/nodes/lighting/LightingNode.js +36 -0
  770. package/src/nodes/lighting/LightsNode.js +455 -0
  771. package/src/nodes/lighting/PointLightNode.js +102 -0
  772. package/src/nodes/lighting/PointShadowNode.js +306 -0
  773. package/src/nodes/lighting/ProjectorLightNode.js +91 -0
  774. package/src/nodes/lighting/RectAreaLightNode.js +133 -0
  775. package/src/nodes/lighting/ShadowBaseNode.js +81 -0
  776. package/src/nodes/lighting/ShadowFilterNode.js +274 -0
  777. package/src/nodes/lighting/ShadowNode.js +745 -0
  778. package/src/nodes/lighting/SpotLightNode.js +168 -0
  779. package/src/nodes/materialx/DISCLAIMER.md +199 -0
  780. package/src/nodes/materialx/MaterialXNodes.js +197 -0
  781. package/src/nodes/materialx/lib/mx_hsv.js +127 -0
  782. package/src/nodes/materialx/lib/mx_noise.js +1491 -0
  783. package/src/nodes/materialx/lib/mx_transform_color.js +23 -0
  784. package/src/nodes/math/BitcastNode.js +156 -0
  785. package/src/nodes/math/ConditionalNode.js +245 -0
  786. package/src/nodes/math/Hash.js +21 -0
  787. package/src/nodes/math/MathNode.js +1167 -0
  788. package/src/nodes/math/MathUtils.js +54 -0
  789. package/src/nodes/math/OperatorNode.js +751 -0
  790. package/src/nodes/math/TriNoise3D.js +71 -0
  791. package/src/nodes/parsers/GLSLNodeFunction.js +168 -0
  792. package/src/nodes/parsers/GLSLNodeParser.js +25 -0
  793. package/src/nodes/pmrem/PMREMNode.js +397 -0
  794. package/src/nodes/pmrem/PMREMUtils.js +288 -0
  795. package/src/nodes/procedural/Checker.js +22 -0
  796. package/src/nodes/shapes/Shapes.js +33 -0
  797. package/src/nodes/tsl/TSLBase.js +35 -0
  798. package/src/nodes/tsl/TSLCore.js +1209 -0
  799. package/src/nodes/utils/ArrayElementNode.js +77 -0
  800. package/src/nodes/utils/ConvertNode.js +100 -0
  801. package/src/nodes/utils/CubeMapNode.js +237 -0
  802. package/src/nodes/utils/DebugNode.js +83 -0
  803. package/src/nodes/utils/Discard.js +24 -0
  804. package/src/nodes/utils/EquirectUV.js +27 -0
  805. package/src/nodes/utils/EventNode.js +83 -0
  806. package/src/nodes/utils/FlipNode.js +106 -0
  807. package/src/nodes/utils/FunctionOverloadingNode.js +152 -0
  808. package/src/nodes/utils/JoinNode.js +117 -0
  809. package/src/nodes/utils/LoopNode.js +354 -0
  810. package/src/nodes/utils/MatcapUV.js +22 -0
  811. package/src/nodes/utils/MaxMipLevelNode.js +103 -0
  812. package/src/nodes/utils/MemberNode.js +120 -0
  813. package/src/nodes/utils/Oscillators.js +41 -0
  814. package/src/nodes/utils/Packing.js +21 -0
  815. package/src/nodes/utils/PostProcessingUtils.js +95 -0
  816. package/src/nodes/utils/RTTNode.js +279 -0
  817. package/src/nodes/utils/ReflectorNode.js +623 -0
  818. package/src/nodes/utils/RemapNode.js +125 -0
  819. package/src/nodes/utils/RotateNode.js +103 -0
  820. package/src/nodes/utils/SampleNode.js +91 -0
  821. package/src/nodes/utils/SetNode.js +108 -0
  822. package/src/nodes/utils/SplitNode.js +179 -0
  823. package/src/nodes/utils/SpriteSheetUVNode.js +90 -0
  824. package/src/nodes/utils/SpriteUtils.js +63 -0
  825. package/src/nodes/utils/StorageArrayElementNode.js +143 -0
  826. package/src/nodes/utils/Timer.js +26 -0
  827. package/src/nodes/utils/TriplanarTextures.js +65 -0
  828. package/src/nodes/utils/UVUtils.js +39 -0
  829. package/src/nodes/utils/ViewportUtils.js +26 -0
  830. package/src/objects/BatchedMesh.js +1654 -0
  831. package/src/objects/Bone.js +41 -0
  832. package/src/objects/ClippingGroup.js +68 -0
  833. package/src/objects/Group.js +41 -0
  834. package/src/objects/InstancedMesh.js +395 -0
  835. package/src/objects/LOD.js +329 -0
  836. package/src/objects/Line.js +329 -0
  837. package/src/objects/LineLoop.js +37 -0
  838. package/src/objects/LineSegments.js +74 -0
  839. package/src/objects/Mesh.js +496 -0
  840. package/src/objects/Points.js +228 -0
  841. package/src/objects/Skeleton.js +383 -0
  842. package/src/objects/SkinnedMesh.js +352 -0
  843. package/src/objects/Sprite.js +245 -0
  844. package/src/renderers/WebGL3DRenderTarget.js +48 -0
  845. package/src/renderers/WebGLArrayRenderTarget.js +48 -0
  846. package/src/renderers/WebGLCubeRenderTarget.js +182 -0
  847. package/src/renderers/WebGLRenderTarget.js +34 -0
  848. package/src/renderers/WebGLRenderer.js +3508 -0
  849. package/src/renderers/common/Animation.js +147 -0
  850. package/src/renderers/common/Attributes.js +118 -0
  851. package/src/renderers/common/Backend.js +685 -0
  852. package/src/renderers/common/Background.js +212 -0
  853. package/src/renderers/common/BindGroup.js +61 -0
  854. package/src/renderers/common/Binding.js +60 -0
  855. package/src/renderers/common/Bindings.js +343 -0
  856. package/src/renderers/common/Buffer.js +87 -0
  857. package/src/renderers/common/BufferUtils.js +58 -0
  858. package/src/renderers/common/BundleGroup.js +83 -0
  859. package/src/renderers/common/ChainMap.js +98 -0
  860. package/src/renderers/common/ClippingContext.js +262 -0
  861. package/src/renderers/common/Color4.js +77 -0
  862. package/src/renderers/common/ComputePipeline.js +41 -0
  863. package/src/renderers/common/Constants.js +15 -0
  864. package/src/renderers/common/CubeRenderTarget.js +103 -0
  865. package/src/renderers/common/DataMap.js +90 -0
  866. package/src/renderers/common/Geometries.js +344 -0
  867. package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
  868. package/src/renderers/common/Info.js +172 -0
  869. package/src/renderers/common/Lighting.js +73 -0
  870. package/src/renderers/common/Pipeline.js +35 -0
  871. package/src/renderers/common/Pipelines.js +465 -0
  872. package/src/renderers/common/PostProcessing.js +245 -0
  873. package/src/renderers/common/ProgrammableStage.js +78 -0
  874. package/src/renderers/common/QuadMesh.js +106 -0
  875. package/src/renderers/common/RenderBundle.js +24 -0
  876. package/src/renderers/common/RenderBundles.js +67 -0
  877. package/src/renderers/common/RenderContext.js +265 -0
  878. package/src/renderers/common/RenderContexts.js +116 -0
  879. package/src/renderers/common/RenderList.js +400 -0
  880. package/src/renderers/common/RenderLists.js +77 -0
  881. package/src/renderers/common/RenderObject.js +901 -0
  882. package/src/renderers/common/RenderObjects.js +202 -0
  883. package/src/renderers/common/RenderPipeline.js +40 -0
  884. package/src/renderers/common/Renderer.js +3125 -0
  885. package/src/renderers/common/RendererUtils.js +191 -0
  886. package/src/renderers/common/SampledTexture.js +144 -0
  887. package/src/renderers/common/Sampler.js +139 -0
  888. package/src/renderers/common/Storage3DTexture.js +100 -0
  889. package/src/renderers/common/StorageArrayTexture.js +84 -0
  890. package/src/renderers/common/StorageBuffer.js +41 -0
  891. package/src/renderers/common/StorageBufferAttribute.js +46 -0
  892. package/src/renderers/common/StorageInstancedBufferAttribute.js +46 -0
  893. package/src/renderers/common/StorageTexture.js +78 -0
  894. package/src/renderers/common/Textures.js +491 -0
  895. package/src/renderers/common/TimestampQueryPool.js +99 -0
  896. package/src/renderers/common/Uniform.js +367 -0
  897. package/src/renderers/common/UniformBuffer.js +34 -0
  898. package/src/renderers/common/UniformsGroup.js +487 -0
  899. package/src/renderers/common/XRManager.js +1676 -0
  900. package/src/renderers/common/XRRenderTarget.js +91 -0
  901. package/src/renderers/common/extras/PMREMGenerator.js +946 -0
  902. package/src/renderers/common/nodes/NodeBuilderState.js +152 -0
  903. package/src/renderers/common/nodes/NodeLibrary.js +196 -0
  904. package/src/renderers/common/nodes/NodeSampledTexture.js +140 -0
  905. package/src/renderers/common/nodes/NodeSampler.js +50 -0
  906. package/src/renderers/common/nodes/NodeStorageBuffer.js +61 -0
  907. package/src/renderers/common/nodes/NodeUniform.js +418 -0
  908. package/src/renderers/common/nodes/NodeUniformBuffer.js +53 -0
  909. package/src/renderers/common/nodes/NodeUniformsGroup.js +51 -0
  910. package/src/renderers/common/nodes/Nodes.js +819 -0
  911. package/src/renderers/shaders/ShaderChunk/alphahash_fragment.glsl.js +7 -0
  912. package/src/renderers/shaders/ShaderChunk/alphahash_pars_fragment.glsl.js +68 -0
  913. package/src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl.js +7 -0
  914. package/src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl.js +7 -0
  915. package/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js +16 -0
  916. package/src/renderers/shaders/ShaderChunk/alphatest_pars_fragment.glsl.js +5 -0
  917. package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +26 -0
  918. package/src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl.js +8 -0
  919. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +49 -0
  920. package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +5 -0
  921. package/src/renderers/shaders/ShaderChunk/begin_vertex.glsl.js +9 -0
  922. package/src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl.js +9 -0
  923. package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +33 -0
  924. package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +43 -0
  925. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_begin.glsl.js +7 -0
  926. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js +10 -0
  927. package/src/renderers/shaders/ShaderChunk/clearcoat_pars_fragment.glsl.js +21 -0
  928. package/src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl.js +78 -0
  929. package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_fragment.glsl.js +9 -0
  930. package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_vertex.glsl.js +7 -0
  931. package/src/renderers/shaders/ShaderChunk/clipping_planes_vertex.glsl.js +7 -0
  932. package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +11 -0
  933. package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +11 -0
  934. package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +11 -0
  935. package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +31 -0
  936. package/src/renderers/shaders/ShaderChunk/colorspace_fragment.glsl.js +3 -0
  937. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +15 -0
  938. package/src/renderers/shaders/ShaderChunk/common.glsl.js +137 -0
  939. package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +186 -0
  940. package/src/renderers/shaders/ShaderChunk/default_fragment.glsl.js +5 -0
  941. package/src/renderers/shaders/ShaderChunk/default_vertex.glsl.js +5 -0
  942. package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +63 -0
  943. package/src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl.js +9 -0
  944. package/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl.js +7 -0
  945. package/src/renderers/shaders/ShaderChunk/dithering_fragment.glsl.js +7 -0
  946. package/src/renderers/shaders/ShaderChunk/dithering_pars_fragment.glsl.js +20 -0
  947. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +17 -0
  948. package/src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl.js +7 -0
  949. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +15 -0
  950. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +62 -0
  951. package/src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl.js +21 -0
  952. package/src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl.js +22 -0
  953. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +69 -0
  954. package/src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js +37 -0
  955. package/src/renderers/shaders/ShaderChunk/fog_fragment.glsl.js +17 -0
  956. package/src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl.js +19 -0
  957. package/src/renderers/shaders/ShaderChunk/fog_pars_vertex.glsl.js +7 -0
  958. package/src/renderers/shaders/ShaderChunk/fog_vertex.glsl.js +7 -0
  959. package/src/renderers/shaders/ShaderChunk/gradientmap_pars_fragment.glsl.js +27 -0
  960. package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +120 -0
  961. package/src/renderers/shaders/ShaderChunk/iridescence_pars_fragment.glsl.js +14 -0
  962. package/src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl.js +8 -0
  963. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +209 -0
  964. package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +13 -0
  965. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +40 -0
  966. package/src/renderers/shaders/ShaderChunk/lights_lambert_fragment.glsl.js +5 -0
  967. package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +28 -0
  968. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +254 -0
  969. package/src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl.js +7 -0
  970. package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +32 -0
  971. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +157 -0
  972. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +563 -0
  973. package/src/renderers/shaders/ShaderChunk/lights_toon_fragment.glsl.js +4 -0
  974. package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +26 -0
  975. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +9 -0
  976. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +9 -0
  977. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +8 -0
  978. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +8 -0
  979. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +17 -0
  980. package/src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl.js +7 -0
  981. package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +27 -0
  982. package/src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl.js +27 -0
  983. package/src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl.js +12 -0
  984. package/src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl.js +7 -0
  985. package/src/renderers/shaders/ShaderChunk/morphcolor_vertex.glsl.js +24 -0
  986. package/src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js +14 -0
  987. package/src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl.js +16 -0
  988. package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +26 -0
  989. package/src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl.js +16 -0
  990. package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +76 -0
  991. package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +33 -0
  992. package/src/renderers/shaders/ShaderChunk/normal_pars_fragment.glsl.js +14 -0
  993. package/src/renderers/shaders/ShaderChunk/normal_pars_vertex.glsl.js +14 -0
  994. package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +14 -0
  995. package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +43 -0
  996. package/src/renderers/shaders/ShaderChunk/opaque_fragment.glsl.js +11 -0
  997. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +100 -0
  998. package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +8 -0
  999. package/src/renderers/shaders/ShaderChunk/project_vertex.glsl.js +19 -0
  1000. package/src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl.js +12 -0
  1001. package/src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl.js +7 -0
  1002. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +337 -0
  1003. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +71 -0
  1004. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +68 -0
  1005. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +66 -0
  1006. package/src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl.js +10 -0
  1007. package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +25 -0
  1008. package/src/renderers/shaders/ShaderChunk/skinning_vertex.glsl.js +15 -0
  1009. package/src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl.js +20 -0
  1010. package/src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl.js +14 -0
  1011. package/src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl.js +7 -0
  1012. package/src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl.js +7 -0
  1013. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +200 -0
  1014. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +36 -0
  1015. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +235 -0
  1016. package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +119 -0
  1017. package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +145 -0
  1018. package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +122 -0
  1019. package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +21 -0
  1020. package/src/renderers/shaders/ShaderChunk.js +270 -0
  1021. package/src/renderers/shaders/ShaderLib/background.glsl.js +40 -0
  1022. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +63 -0
  1023. package/src/renderers/shaders/ShaderLib/cube.glsl.js +36 -0
  1024. package/src/renderers/shaders/ShaderLib/depth.glsl.js +114 -0
  1025. package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +78 -0
  1026. package/src/renderers/shaders/ShaderLib/equirect.glsl.js +35 -0
  1027. package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +76 -0
  1028. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +116 -0
  1029. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +125 -0
  1030. package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +112 -0
  1031. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +87 -0
  1032. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +127 -0
  1033. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +229 -0
  1034. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +119 -0
  1035. package/src/renderers/shaders/ShaderLib/points.glsl.js +87 -0
  1036. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +58 -0
  1037. package/src/renderers/shaders/ShaderLib/sprite.glsl.js +79 -0
  1038. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +53 -0
  1039. package/src/renderers/shaders/ShaderLib.js +361 -0
  1040. package/src/renderers/shaders/UniformsLib.js +235 -0
  1041. package/src/renderers/shaders/UniformsUtils.js +112 -0
  1042. package/src/renderers/webgl/WebGLAnimation.js +53 -0
  1043. package/src/renderers/webgl/WebGLAttributes.js +237 -0
  1044. package/src/renderers/webgl/WebGLBackground.js +303 -0
  1045. package/src/renderers/webgl/WebGLBindingStates.js +594 -0
  1046. package/src/renderers/webgl/WebGLBufferRenderer.js +89 -0
  1047. package/src/renderers/webgl/WebGLCapabilities.js +145 -0
  1048. package/src/renderers/webgl/WebGLClipping.js +171 -0
  1049. package/src/renderers/webgl/WebGLCubeMaps.js +99 -0
  1050. package/src/renderers/webgl/WebGLCubeUVMaps.js +134 -0
  1051. package/src/renderers/webgl/WebGLExtensions.js +84 -0
  1052. package/src/renderers/webgl/WebGLGeometries.js +183 -0
  1053. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +100 -0
  1054. package/src/renderers/webgl/WebGLInfo.js +73 -0
  1055. package/src/renderers/webgl/WebGLLights.js +571 -0
  1056. package/src/renderers/webgl/WebGLMaterials.js +591 -0
  1057. package/src/renderers/webgl/WebGLMorphtargets.js +168 -0
  1058. package/src/renderers/webgl/WebGLObjects.js +92 -0
  1059. package/src/renderers/webgl/WebGLProgram.js +1091 -0
  1060. package/src/renderers/webgl/WebGLPrograms.js +667 -0
  1061. package/src/renderers/webgl/WebGLProperties.js +55 -0
  1062. package/src/renderers/webgl/WebGLRenderLists.js +238 -0
  1063. package/src/renderers/webgl/WebGLRenderStates.js +116 -0
  1064. package/src/renderers/webgl/WebGLShader.js +12 -0
  1065. package/src/renderers/webgl/WebGLShaderCache.js +124 -0
  1066. package/src/renderers/webgl/WebGLShadowMap.js +436 -0
  1067. package/src/renderers/webgl/WebGLState.js +1332 -0
  1068. package/src/renderers/webgl/WebGLTextures.js +2342 -0
  1069. package/src/renderers/webgl/WebGLUniforms.js +1166 -0
  1070. package/src/renderers/webgl/WebGLUniformsGroups.js +394 -0
  1071. package/src/renderers/webgl/WebGLUtils.js +213 -0
  1072. package/src/renderers/webgl-fallback/WebGLBackend.js +2633 -0
  1073. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +140 -0
  1074. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +1517 -0
  1075. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +325 -0
  1076. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +64 -0
  1077. package/src/renderers/webgl-fallback/utils/WebGLConstants.js +14 -0
  1078. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +83 -0
  1079. package/src/renderers/webgl-fallback/utils/WebGLState.js +1144 -0
  1080. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +1304 -0
  1081. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +366 -0
  1082. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +313 -0
  1083. package/src/renderers/webgpu/WebGPUBackend.js +2456 -0
  1084. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +69 -0
  1085. package/src/renderers/webgpu/WebGPURenderer.js +106 -0
  1086. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +66 -0
  1087. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +100 -0
  1088. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +2248 -0
  1089. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +187 -0
  1090. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +25 -0
  1091. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +449 -0
  1092. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +484 -0
  1093. package/src/renderers/webgpu/utils/WebGPUConstants.js +339 -0
  1094. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +781 -0
  1095. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +439 -0
  1096. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +1505 -0
  1097. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +287 -0
  1098. package/src/renderers/webgpu/utils/WebGPUUtils.js +227 -0
  1099. package/src/renderers/webxr/WebXRController.js +428 -0
  1100. package/src/renderers/webxr/WebXRDepthSensing.js +155 -0
  1101. package/src/renderers/webxr/WebXRManager.js +1103 -0
  1102. package/src/scenes/Fog.js +98 -0
  1103. package/src/scenes/FogExp2.js +86 -0
  1104. package/src/scenes/Scene.js +165 -0
  1105. package/src/textures/CanvasTexture.js +45 -0
  1106. package/src/textures/CompressedArrayTexture.js +89 -0
  1107. package/src/textures/CompressedCubeTexture.js +48 -0
  1108. package/src/textures/CompressedTexture.js +86 -0
  1109. package/src/textures/CubeTexture.js +81 -0
  1110. package/src/textures/Data3DTexture.js +112 -0
  1111. package/src/textures/DataArrayTexture.js +134 -0
  1112. package/src/textures/DataTexture.js +87 -0
  1113. package/src/textures/DepthTexture.js +104 -0
  1114. package/src/textures/ExternalTexture.js +56 -0
  1115. package/src/textures/FramebufferTexture.js +85 -0
  1116. package/src/textures/Source.js +230 -0
  1117. package/src/textures/Texture.js +801 -0
  1118. package/src/textures/VideoFrameTexture.js +72 -0
  1119. package/src/textures/VideoTexture.js +125 -0
  1120. package/src/utils.js +216 -0
@@ -0,0 +1,3595 @@
1
+ import {
2
+ BufferAttribute,
3
+ ClampToEdgeWrapping,
4
+ Color,
5
+ DoubleSide,
6
+ InterpolateDiscrete,
7
+ InterpolateLinear,
8
+ NoColorSpace,
9
+ LinearFilter,
10
+ LinearMipmapLinearFilter,
11
+ LinearMipmapNearestFilter,
12
+ MathUtils,
13
+ Matrix4,
14
+ MirroredRepeatWrapping,
15
+ NearestFilter,
16
+ NearestMipmapLinearFilter,
17
+ NearestMipmapNearestFilter,
18
+ PropertyBinding,
19
+ RGBAFormat,
20
+ RepeatWrapping,
21
+ Scene,
22
+ Source,
23
+ SRGBColorSpace,
24
+ CompressedTexture,
25
+ Vector3,
26
+ Quaternion,
27
+ REVISION,
28
+ ImageUtils
29
+ } from 'three';
30
+
31
+ /**
32
+ * The KHR_mesh_quantization extension allows these extra attribute component types
33
+ *
34
+ * @see https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md#extending-mesh-attributes
35
+ */
36
+ const KHR_mesh_quantization_ExtraAttrTypes = {
37
+ POSITION: [
38
+ 'byte',
39
+ 'byte normalized',
40
+ 'unsigned byte',
41
+ 'unsigned byte normalized',
42
+ 'short',
43
+ 'short normalized',
44
+ 'unsigned short',
45
+ 'unsigned short normalized',
46
+ ],
47
+ NORMAL: [
48
+ 'byte normalized',
49
+ 'short normalized',
50
+ ],
51
+ TANGENT: [
52
+ 'byte normalized',
53
+ 'short normalized',
54
+ ],
55
+ TEXCOORD: [
56
+ 'byte',
57
+ 'byte normalized',
58
+ 'unsigned byte',
59
+ 'short',
60
+ 'short normalized',
61
+ 'unsigned short',
62
+ ],
63
+ };
64
+
65
+ /**
66
+ * An exporter for `glTF` 2.0.
67
+ *
68
+ * glTF (GL Transmission Format) is an [open format specification]{@link https://github.com/KhronosGroup/glTF/tree/master/specification/2.0}
69
+ * for efficient delivery and loading of 3D content. Assets may be provided either in JSON (.gltf)
70
+ * or binary (.glb) format. External files store textures (.jpg, .png) and additional binary
71
+ * data (.bin). A glTF asset may deliver one or more scenes, including meshes, materials,
72
+ * textures, skins, skeletons, morph targets, animations, lights, and/or cameras.
73
+ *
74
+ * GLTFExporter supports the [glTF 2.0 extensions]{@link https://github.com/KhronosGroup/glTF/tree/master/extensions/}:
75
+ *
76
+ * - KHR_lights_punctual
77
+ * - KHR_materials_clearcoat
78
+ * - KHR_materials_dispersion
79
+ * - KHR_materials_emissive_strength
80
+ * - KHR_materials_ior
81
+ * - KHR_materials_iridescence
82
+ * - KHR_materials_specular
83
+ * - KHR_materials_sheen
84
+ * - KHR_materials_transmission
85
+ * - KHR_materials_unlit
86
+ * - KHR_materials_volume
87
+ * - KHR_mesh_quantization
88
+ * - KHR_texture_transform
89
+ * - EXT_materials_bump
90
+ * - EXT_mesh_gpu_instancing
91
+ *
92
+ * The following glTF 2.0 extension is supported by an external user plugin:
93
+ *
94
+ * - [KHR_materials_variants]{@link https://github.com/takahirox/three-gltf-extensions}
95
+ *
96
+ * ```js
97
+ * const exporter = new GLTFExporter();
98
+ * const data = await exporter.parseAsync( scene, options );
99
+ * ```
100
+ *
101
+ * @three_import import { GLTFExporter } from 'three/addons/exporters/GLTFExporter.js';
102
+ */
103
+ class GLTFExporter {
104
+
105
+ /**
106
+ * Constructs a new glTF exporter.
107
+ */
108
+ constructor() {
109
+
110
+ /**
111
+ * A reference to a texture utils module.
112
+ *
113
+ * @type {?(WebGLTextureUtils|WebGPUTextureUtils)}
114
+ * @default null
115
+ */
116
+ this.textureUtils = null;
117
+
118
+ this.pluginCallbacks = [];
119
+
120
+ this.register( function ( writer ) {
121
+
122
+ return new GLTFLightExtension( writer );
123
+
124
+ } );
125
+
126
+ this.register( function ( writer ) {
127
+
128
+ return new GLTFMaterialsUnlitExtension( writer );
129
+
130
+ } );
131
+
132
+ this.register( function ( writer ) {
133
+
134
+ return new GLTFMaterialsTransmissionExtension( writer );
135
+
136
+ } );
137
+
138
+ this.register( function ( writer ) {
139
+
140
+ return new GLTFMaterialsVolumeExtension( writer );
141
+
142
+ } );
143
+
144
+ this.register( function ( writer ) {
145
+
146
+ return new GLTFMaterialsIorExtension( writer );
147
+
148
+ } );
149
+
150
+ this.register( function ( writer ) {
151
+
152
+ return new GLTFMaterialsSpecularExtension( writer );
153
+
154
+ } );
155
+
156
+ this.register( function ( writer ) {
157
+
158
+ return new GLTFMaterialsClearcoatExtension( writer );
159
+
160
+ } );
161
+
162
+ this.register( function ( writer ) {
163
+
164
+ return new GLTFMaterialsDispersionExtension( writer );
165
+
166
+ } );
167
+
168
+ this.register( function ( writer ) {
169
+
170
+ return new GLTFMaterialsIridescenceExtension( writer );
171
+
172
+ } );
173
+
174
+ this.register( function ( writer ) {
175
+
176
+ return new GLTFMaterialsSheenExtension( writer );
177
+
178
+ } );
179
+
180
+ this.register( function ( writer ) {
181
+
182
+ return new GLTFMaterialsAnisotropyExtension( writer );
183
+
184
+ } );
185
+
186
+ this.register( function ( writer ) {
187
+
188
+ return new GLTFMaterialsEmissiveStrengthExtension( writer );
189
+
190
+ } );
191
+
192
+ this.register( function ( writer ) {
193
+
194
+ return new GLTFMaterialsBumpExtension( writer );
195
+
196
+ } );
197
+
198
+ this.register( function ( writer ) {
199
+
200
+ return new GLTFMeshGpuInstancing( writer );
201
+
202
+ } );
203
+
204
+ }
205
+
206
+ /**
207
+ * Registers a plugin callback. This API is internally used to implement the various
208
+ * glTF extensions but can also used by third-party code to add additional logic
209
+ * to the exporter.
210
+ *
211
+ * @param {function(writer:GLTFWriter)} callback - The callback function to register.
212
+ * @return {GLTFExporter} A reference to this exporter.
213
+ */
214
+ register( callback ) {
215
+
216
+ if ( this.pluginCallbacks.indexOf( callback ) === - 1 ) {
217
+
218
+ this.pluginCallbacks.push( callback );
219
+
220
+ }
221
+
222
+ return this;
223
+
224
+ }
225
+
226
+ /**
227
+ * Unregisters a plugin callback.
228
+ *
229
+ * @param {Function} callback - The callback function to unregister.
230
+ * @return {GLTFExporter} A reference to this exporter.
231
+ */
232
+ unregister( callback ) {
233
+
234
+ if ( this.pluginCallbacks.indexOf( callback ) !== - 1 ) {
235
+
236
+ this.pluginCallbacks.splice( this.pluginCallbacks.indexOf( callback ), 1 );
237
+
238
+ }
239
+
240
+ return this;
241
+
242
+ }
243
+
244
+ /**
245
+ * Sets the texture utils for this exporter. Only relevant when compressed textures have to be exported.
246
+ *
247
+ * Depending on whether you use {@link WebGLRenderer} or {@link WebGPURenderer}, you must inject the
248
+ * corresponding texture utils {@link WebGLTextureUtils} or {@link WebGPUTextureUtils}.
249
+ *
250
+ * @param {WebGLTextureUtils|WebGPUTextureUtils} utils - The texture utils.
251
+ * @return {GLTFExporter} A reference to this exporter.
252
+ */
253
+ setTextureUtils( utils ) {
254
+
255
+ this.textureUtils = utils;
256
+
257
+ return this;
258
+
259
+ }
260
+
261
+ /**
262
+ * Parses the given scenes and generates the glTF output.
263
+ *
264
+ * @param {Scene|Array<Scene>} input - A scene or an array of scenes.
265
+ * @param {GLTFExporter~OnDone} onDone - A callback function that is executed when the export has finished.
266
+ * @param {GLTFExporter~OnError} onError - A callback function that is executed when an error happens.
267
+ * @param {GLTFExporter~Options} options - options
268
+ */
269
+ parse( input, onDone, onError, options ) {
270
+
271
+ const writer = new GLTFWriter();
272
+ const plugins = [];
273
+
274
+ for ( let i = 0, il = this.pluginCallbacks.length; i < il; i ++ ) {
275
+
276
+ plugins.push( this.pluginCallbacks[ i ]( writer ) );
277
+
278
+ }
279
+
280
+ writer.setPlugins( plugins );
281
+ writer.setTextureUtils( this.textureUtils );
282
+ writer.writeAsync( input, onDone, options ).catch( onError );
283
+
284
+ }
285
+
286
+ /**
287
+ * Async version of {@link GLTFExporter#parse}.
288
+ *
289
+ * @param {Scene|Array<Scene>} input - A scene or an array of scenes.
290
+ * @param {GLTFExporter~Options} options - options.
291
+ * @return {Promise<ArrayBuffer|string>} A Promise that resolved with the exported glTF data.
292
+ */
293
+ parseAsync( input, options ) {
294
+
295
+ const scope = this;
296
+
297
+ return new Promise( function ( resolve, reject ) {
298
+
299
+ scope.parse( input, resolve, reject, options );
300
+
301
+ } );
302
+
303
+ }
304
+
305
+ }
306
+
307
+ //------------------------------------------------------------------------------
308
+ // Constants
309
+ //------------------------------------------------------------------------------
310
+
311
+ const WEBGL_CONSTANTS = {
312
+ POINTS: 0x0000,
313
+ LINES: 0x0001,
314
+ LINE_LOOP: 0x0002,
315
+ LINE_STRIP: 0x0003,
316
+ TRIANGLES: 0x0004,
317
+ TRIANGLE_STRIP: 0x0005,
318
+ TRIANGLE_FAN: 0x0006,
319
+
320
+ BYTE: 0x1400,
321
+ UNSIGNED_BYTE: 0x1401,
322
+ SHORT: 0x1402,
323
+ UNSIGNED_SHORT: 0x1403,
324
+ INT: 0x1404,
325
+ UNSIGNED_INT: 0x1405,
326
+ FLOAT: 0x1406,
327
+
328
+ ARRAY_BUFFER: 0x8892,
329
+ ELEMENT_ARRAY_BUFFER: 0x8893,
330
+
331
+ NEAREST: 0x2600,
332
+ LINEAR: 0x2601,
333
+ NEAREST_MIPMAP_NEAREST: 0x2700,
334
+ LINEAR_MIPMAP_NEAREST: 0x2701,
335
+ NEAREST_MIPMAP_LINEAR: 0x2702,
336
+ LINEAR_MIPMAP_LINEAR: 0x2703,
337
+
338
+ CLAMP_TO_EDGE: 33071,
339
+ MIRRORED_REPEAT: 33648,
340
+ REPEAT: 10497
341
+ };
342
+
343
+ const KHR_MESH_QUANTIZATION = 'KHR_mesh_quantization';
344
+
345
+ const THREE_TO_WEBGL = {};
346
+
347
+ THREE_TO_WEBGL[ NearestFilter ] = WEBGL_CONSTANTS.NEAREST;
348
+ THREE_TO_WEBGL[ NearestMipmapNearestFilter ] = WEBGL_CONSTANTS.NEAREST_MIPMAP_NEAREST;
349
+ THREE_TO_WEBGL[ NearestMipmapLinearFilter ] = WEBGL_CONSTANTS.NEAREST_MIPMAP_LINEAR;
350
+ THREE_TO_WEBGL[ LinearFilter ] = WEBGL_CONSTANTS.LINEAR;
351
+ THREE_TO_WEBGL[ LinearMipmapNearestFilter ] = WEBGL_CONSTANTS.LINEAR_MIPMAP_NEAREST;
352
+ THREE_TO_WEBGL[ LinearMipmapLinearFilter ] = WEBGL_CONSTANTS.LINEAR_MIPMAP_LINEAR;
353
+
354
+ THREE_TO_WEBGL[ ClampToEdgeWrapping ] = WEBGL_CONSTANTS.CLAMP_TO_EDGE;
355
+ THREE_TO_WEBGL[ RepeatWrapping ] = WEBGL_CONSTANTS.REPEAT;
356
+ THREE_TO_WEBGL[ MirroredRepeatWrapping ] = WEBGL_CONSTANTS.MIRRORED_REPEAT;
357
+
358
+ const PATH_PROPERTIES = {
359
+ scale: 'scale',
360
+ position: 'translation',
361
+ quaternion: 'rotation',
362
+ morphTargetInfluences: 'weights'
363
+ };
364
+
365
+ const DEFAULT_SPECULAR_COLOR = new Color();
366
+
367
+ // GLB constants
368
+ // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#glb-file-format-specification
369
+
370
+ const GLB_HEADER_BYTES = 12;
371
+ const GLB_HEADER_MAGIC = 0x46546C67;
372
+ const GLB_VERSION = 2;
373
+
374
+ const GLB_CHUNK_PREFIX_BYTES = 8;
375
+ const GLB_CHUNK_TYPE_JSON = 0x4E4F534A;
376
+ const GLB_CHUNK_TYPE_BIN = 0x004E4942;
377
+
378
+ //------------------------------------------------------------------------------
379
+ // Utility functions
380
+ //------------------------------------------------------------------------------
381
+
382
+ /**
383
+ * Compare two arrays
384
+ *
385
+ * @private
386
+ * @param {Array} array1 Array 1 to compare
387
+ * @param {Array} array2 Array 2 to compare
388
+ * @return {boolean} Returns true if both arrays are equal
389
+ */
390
+ function equalArray( array1, array2 ) {
391
+
392
+ return ( array1.length === array2.length ) && array1.every( function ( element, index ) {
393
+
394
+ return element === array2[ index ];
395
+
396
+ } );
397
+
398
+ }
399
+
400
+ /**
401
+ * Converts a string to an ArrayBuffer.
402
+ *
403
+ * @private
404
+ * @param {string} text
405
+ * @return {ArrayBuffer}
406
+ */
407
+ function stringToArrayBuffer( text ) {
408
+
409
+ return new TextEncoder().encode( text ).buffer;
410
+
411
+ }
412
+
413
+ /**
414
+ * Is identity matrix
415
+ *
416
+ * @private
417
+ * @param {Matrix4} matrix
418
+ * @returns {boolean} Returns true, if parameter is identity matrix
419
+ */
420
+ function isIdentityMatrix( matrix ) {
421
+
422
+ return equalArray( matrix.elements, [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ] );
423
+
424
+ }
425
+
426
+ /**
427
+ * Get the min and max vectors from the given attribute
428
+ *
429
+ * @private
430
+ * @param {BufferAttribute} attribute Attribute to find the min/max in range from start to start + count
431
+ * @param {number} start Start index
432
+ * @param {number} count Range to cover
433
+ * @return {Object} Object containing the `min` and `max` values (As an array of attribute.itemSize components)
434
+ */
435
+ function getMinMax( attribute, start, count ) {
436
+
437
+ const output = {
438
+
439
+ min: new Array( attribute.itemSize ).fill( Number.POSITIVE_INFINITY ),
440
+ max: new Array( attribute.itemSize ).fill( Number.NEGATIVE_INFINITY )
441
+
442
+ };
443
+
444
+ for ( let i = start; i < start + count; i ++ ) {
445
+
446
+ for ( let a = 0; a < attribute.itemSize; a ++ ) {
447
+
448
+ let value;
449
+
450
+ if ( attribute.itemSize > 4 ) {
451
+
452
+ // no support for interleaved data for itemSize > 4
453
+
454
+ value = attribute.array[ i * attribute.itemSize + a ];
455
+
456
+ } else {
457
+
458
+ if ( a === 0 ) value = attribute.getX( i );
459
+ else if ( a === 1 ) value = attribute.getY( i );
460
+ else if ( a === 2 ) value = attribute.getZ( i );
461
+ else if ( a === 3 ) value = attribute.getW( i );
462
+
463
+ if ( attribute.normalized === true ) {
464
+
465
+ value = MathUtils.normalize( value, attribute.array );
466
+
467
+ }
468
+
469
+ }
470
+
471
+ output.min[ a ] = Math.min( output.min[ a ], value );
472
+ output.max[ a ] = Math.max( output.max[ a ], value );
473
+
474
+ }
475
+
476
+ }
477
+
478
+ return output;
479
+
480
+ }
481
+
482
+ /**
483
+ * Get the required size + padding for a buffer, rounded to the next 4-byte boundary.
484
+ * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#data-alignment
485
+ *
486
+ * @private
487
+ * @param {number} bufferSize The size the original buffer. Should be an integer.
488
+ * @returns {number} new buffer size with required padding as an integer.
489
+ *
490
+ */
491
+ function getPaddedBufferSize( bufferSize ) {
492
+
493
+ return Math.ceil( bufferSize / 4 ) * 4;
494
+
495
+ }
496
+
497
+ /**
498
+ * Returns a buffer aligned to 4-byte boundary.
499
+ *
500
+ * @private
501
+ * @param {ArrayBuffer} arrayBuffer Buffer to pad
502
+ * @param {number} [paddingByte=0] Should be an integer
503
+ * @returns {ArrayBuffer} The same buffer if it's already aligned to 4-byte boundary or a new buffer
504
+ */
505
+ function getPaddedArrayBuffer( arrayBuffer, paddingByte = 0 ) {
506
+
507
+ const paddedLength = getPaddedBufferSize( arrayBuffer.byteLength );
508
+
509
+ if ( paddedLength !== arrayBuffer.byteLength ) {
510
+
511
+ const array = new Uint8Array( paddedLength );
512
+ array.set( new Uint8Array( arrayBuffer ) );
513
+
514
+ if ( paddingByte !== 0 ) {
515
+
516
+ for ( let i = arrayBuffer.byteLength; i < paddedLength; i ++ ) {
517
+
518
+ array[ i ] = paddingByte;
519
+
520
+ }
521
+
522
+ }
523
+
524
+ return array.buffer;
525
+
526
+ }
527
+
528
+ return arrayBuffer;
529
+
530
+ }
531
+
532
+ function getCanvas() {
533
+
534
+ if ( typeof document === 'undefined' && typeof OffscreenCanvas !== 'undefined' ) {
535
+
536
+ return new OffscreenCanvas( 1, 1 );
537
+
538
+ }
539
+
540
+ return document.createElement( 'canvas' );
541
+
542
+ }
543
+
544
+ function getToBlobPromise( canvas, mimeType ) {
545
+
546
+ if ( typeof OffscreenCanvas !== 'undefined' && canvas instanceof OffscreenCanvas ) {
547
+
548
+ let quality;
549
+
550
+ // Blink's implementation of convertToBlob seems to default to a quality level of 100%
551
+ // Use the Blink default quality levels of toBlob instead so that file sizes are comparable.
552
+ if ( mimeType === 'image/jpeg' ) {
553
+
554
+ quality = 0.92;
555
+
556
+ } else if ( mimeType === 'image/webp' ) {
557
+
558
+ quality = 0.8;
559
+
560
+ }
561
+
562
+ return canvas.convertToBlob( {
563
+
564
+ type: mimeType,
565
+ quality: quality
566
+
567
+ } );
568
+
569
+ } else {
570
+
571
+ // HTMLCanvasElement code path
572
+
573
+ return new Promise( ( resolve ) => canvas.toBlob( resolve, mimeType ) );
574
+
575
+ }
576
+
577
+ }
578
+
579
+ /**
580
+ * Writer
581
+ *
582
+ * @private
583
+ */
584
+ class GLTFWriter {
585
+
586
+ constructor() {
587
+
588
+ this.plugins = [];
589
+
590
+ this.options = {};
591
+ this.pending = [];
592
+ this.buffers = [];
593
+
594
+ this.byteOffset = 0;
595
+ this.buffers = [];
596
+ this.nodeMap = new Map();
597
+ this.skins = [];
598
+
599
+ this.extensionsUsed = {};
600
+ this.extensionsRequired = {};
601
+
602
+ this.uids = new Map();
603
+ this.uid = 0;
604
+
605
+ this.json = {
606
+ asset: {
607
+ version: '2.0',
608
+ generator: 'THREE.GLTFExporter r' + REVISION
609
+ }
610
+ };
611
+
612
+ this.cache = {
613
+ meshes: new Map(),
614
+ attributes: new Map(),
615
+ attributesNormalized: new Map(),
616
+ materials: new Map(),
617
+ textures: new Map(),
618
+ images: new Map()
619
+ };
620
+
621
+ this.textureUtils = null;
622
+
623
+ }
624
+
625
+ setPlugins( plugins ) {
626
+
627
+ this.plugins = plugins;
628
+
629
+ }
630
+
631
+ setTextureUtils( utils ) {
632
+
633
+ this.textureUtils = utils;
634
+
635
+ }
636
+
637
+ /**
638
+ * Parse scenes and generate GLTF output
639
+ *
640
+ * @param {Scene|Array<Scene>} input Scene or Array of THREE.Scenes
641
+ * @param {Function} onDone Callback on completed
642
+ * @param {Object} options options
643
+ */
644
+ async writeAsync( input, onDone, options = {} ) {
645
+
646
+ this.options = Object.assign( {
647
+ // default options
648
+ binary: false,
649
+ trs: false,
650
+ onlyVisible: true,
651
+ maxTextureSize: Infinity,
652
+ animations: [],
653
+ includeCustomExtensions: false
654
+ }, options );
655
+
656
+ if ( this.options.animations.length > 0 ) {
657
+
658
+ // Only TRS properties, and not matrices, may be targeted by animation.
659
+ this.options.trs = true;
660
+
661
+ }
662
+
663
+ await this.processInputAsync( input );
664
+
665
+ await Promise.all( this.pending );
666
+
667
+ const writer = this;
668
+ const buffers = writer.buffers;
669
+ const json = writer.json;
670
+ options = writer.options;
671
+
672
+ const extensionsUsed = writer.extensionsUsed;
673
+ const extensionsRequired = writer.extensionsRequired;
674
+
675
+ // Merge buffers.
676
+ const blob = new Blob( buffers, { type: 'application/octet-stream' } );
677
+
678
+ // Declare extensions.
679
+ const extensionsUsedList = Object.keys( extensionsUsed );
680
+ const extensionsRequiredList = Object.keys( extensionsRequired );
681
+
682
+ if ( extensionsUsedList.length > 0 ) json.extensionsUsed = extensionsUsedList;
683
+ if ( extensionsRequiredList.length > 0 ) json.extensionsRequired = extensionsRequiredList;
684
+
685
+ // Update bytelength of the single buffer.
686
+ if ( json.buffers && json.buffers.length > 0 ) json.buffers[ 0 ].byteLength = blob.size;
687
+
688
+ if ( options.binary === true ) {
689
+
690
+ // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#glb-file-format-specification
691
+
692
+ const reader = new FileReader();
693
+ reader.readAsArrayBuffer( blob );
694
+ reader.onloadend = function () {
695
+
696
+ // Binary chunk.
697
+ const binaryChunk = getPaddedArrayBuffer( reader.result );
698
+ const binaryChunkPrefix = new DataView( new ArrayBuffer( GLB_CHUNK_PREFIX_BYTES ) );
699
+ binaryChunkPrefix.setUint32( 0, binaryChunk.byteLength, true );
700
+ binaryChunkPrefix.setUint32( 4, GLB_CHUNK_TYPE_BIN, true );
701
+
702
+ // JSON chunk.
703
+ const jsonChunk = getPaddedArrayBuffer( stringToArrayBuffer( JSON.stringify( json ) ), 0x20 );
704
+ const jsonChunkPrefix = new DataView( new ArrayBuffer( GLB_CHUNK_PREFIX_BYTES ) );
705
+ jsonChunkPrefix.setUint32( 0, jsonChunk.byteLength, true );
706
+ jsonChunkPrefix.setUint32( 4, GLB_CHUNK_TYPE_JSON, true );
707
+
708
+ // GLB header.
709
+ const header = new ArrayBuffer( GLB_HEADER_BYTES );
710
+ const headerView = new DataView( header );
711
+ headerView.setUint32( 0, GLB_HEADER_MAGIC, true );
712
+ headerView.setUint32( 4, GLB_VERSION, true );
713
+ const totalByteLength = GLB_HEADER_BYTES
714
+ + jsonChunkPrefix.byteLength + jsonChunk.byteLength
715
+ + binaryChunkPrefix.byteLength + binaryChunk.byteLength;
716
+ headerView.setUint32( 8, totalByteLength, true );
717
+
718
+ const glbBlob = new Blob( [
719
+ header,
720
+ jsonChunkPrefix,
721
+ jsonChunk,
722
+ binaryChunkPrefix,
723
+ binaryChunk
724
+ ], { type: 'application/octet-stream' } );
725
+
726
+ const glbReader = new FileReader();
727
+ glbReader.readAsArrayBuffer( glbBlob );
728
+ glbReader.onloadend = function () {
729
+
730
+ onDone( glbReader.result );
731
+
732
+ };
733
+
734
+ };
735
+
736
+ } else {
737
+
738
+ if ( json.buffers && json.buffers.length > 0 ) {
739
+
740
+ const reader = new FileReader();
741
+ reader.readAsDataURL( blob );
742
+ reader.onloadend = function () {
743
+
744
+ const base64data = reader.result;
745
+ json.buffers[ 0 ].uri = base64data;
746
+ onDone( json );
747
+
748
+ };
749
+
750
+ } else {
751
+
752
+ onDone( json );
753
+
754
+ }
755
+
756
+ }
757
+
758
+
759
+ }
760
+
761
+ /**
762
+ * Serializes a userData.
763
+ *
764
+ * @param {THREE.Object3D|THREE.Material|THREE.BufferGeometry|THREE.AnimationClip} object
765
+ * @param {Object} objectDef
766
+ */
767
+ serializeUserData( object, objectDef ) {
768
+
769
+ if ( Object.keys( object.userData ).length === 0 ) return;
770
+
771
+ const options = this.options;
772
+ const extensionsUsed = this.extensionsUsed;
773
+
774
+ try {
775
+
776
+ const json = JSON.parse( JSON.stringify( object.userData ) );
777
+
778
+ if ( options.includeCustomExtensions && json.gltfExtensions ) {
779
+
780
+ if ( objectDef.extensions === undefined ) objectDef.extensions = {};
781
+
782
+ for ( const extensionName in json.gltfExtensions ) {
783
+
784
+ objectDef.extensions[ extensionName ] = json.gltfExtensions[ extensionName ];
785
+ extensionsUsed[ extensionName ] = true;
786
+
787
+ }
788
+
789
+ delete json.gltfExtensions;
790
+
791
+ }
792
+
793
+ if ( Object.keys( json ).length > 0 ) objectDef.extras = json;
794
+
795
+ } catch ( error ) {
796
+
797
+ console.warn( 'THREE.GLTFExporter: userData of \'' + object.name + '\' ' +
798
+ 'won\'t be serialized because of JSON.stringify error - ' + error.message );
799
+
800
+ }
801
+
802
+ }
803
+
804
+ /**
805
+ * Returns ids for buffer attributes.
806
+ *
807
+ * @param {Object} attribute
808
+ * @param {boolean} [isRelativeCopy=false]
809
+ * @return {number} An integer
810
+ */
811
+ getUID( attribute, isRelativeCopy = false ) {
812
+
813
+ if ( this.uids.has( attribute ) === false ) {
814
+
815
+ const uids = new Map();
816
+
817
+ uids.set( true, this.uid ++ );
818
+ uids.set( false, this.uid ++ );
819
+
820
+ this.uids.set( attribute, uids );
821
+
822
+ }
823
+
824
+ const uids = this.uids.get( attribute );
825
+
826
+ return uids.get( isRelativeCopy );
827
+
828
+ }
829
+
830
+ /**
831
+ * Checks if normal attribute values are normalized.
832
+ *
833
+ * @param {BufferAttribute} normal
834
+ * @returns {boolean}
835
+ */
836
+ isNormalizedNormalAttribute( normal ) {
837
+
838
+ const cache = this.cache;
839
+
840
+ if ( cache.attributesNormalized.has( normal ) ) return false;
841
+
842
+ const v = new Vector3();
843
+
844
+ for ( let i = 0, il = normal.count; i < il; i ++ ) {
845
+
846
+ // 0.0005 is from glTF-validator
847
+ if ( Math.abs( v.fromBufferAttribute( normal, i ).length() - 1.0 ) > 0.0005 ) return false;
848
+
849
+ }
850
+
851
+ return true;
852
+
853
+ }
854
+
855
+ /**
856
+ * Creates normalized normal buffer attribute.
857
+ *
858
+ * @param {BufferAttribute} normal
859
+ * @returns {BufferAttribute}
860
+ *
861
+ */
862
+ createNormalizedNormalAttribute( normal ) {
863
+
864
+ const cache = this.cache;
865
+
866
+ if ( cache.attributesNormalized.has( normal ) ) return cache.attributesNormalized.get( normal );
867
+
868
+ const attribute = normal.clone();
869
+ const v = new Vector3();
870
+
871
+ for ( let i = 0, il = attribute.count; i < il; i ++ ) {
872
+
873
+ v.fromBufferAttribute( attribute, i );
874
+
875
+ if ( v.x === 0 && v.y === 0 && v.z === 0 ) {
876
+
877
+ // if values can't be normalized set (1, 0, 0)
878
+ v.setX( 1.0 );
879
+
880
+ } else {
881
+
882
+ v.normalize();
883
+
884
+ }
885
+
886
+ attribute.setXYZ( i, v.x, v.y, v.z );
887
+
888
+ }
889
+
890
+ cache.attributesNormalized.set( normal, attribute );
891
+
892
+ return attribute;
893
+
894
+ }
895
+
896
+ /**
897
+ * Applies a texture transform, if present, to the map definition. Requires
898
+ * the KHR_texture_transform extension.
899
+ *
900
+ * @param {Object} mapDef
901
+ * @param {THREE.Texture} texture
902
+ */
903
+ applyTextureTransform( mapDef, texture ) {
904
+
905
+ let didTransform = false;
906
+ const transformDef = {};
907
+
908
+ if ( texture.offset.x !== 0 || texture.offset.y !== 0 ) {
909
+
910
+ transformDef.offset = texture.offset.toArray();
911
+ didTransform = true;
912
+
913
+ }
914
+
915
+ if ( texture.rotation !== 0 ) {
916
+
917
+ transformDef.rotation = texture.rotation;
918
+ didTransform = true;
919
+
920
+ }
921
+
922
+ if ( texture.repeat.x !== 1 || texture.repeat.y !== 1 ) {
923
+
924
+ transformDef.scale = texture.repeat.toArray();
925
+ didTransform = true;
926
+
927
+ }
928
+
929
+ if ( didTransform ) {
930
+
931
+ mapDef.extensions = mapDef.extensions || {};
932
+ mapDef.extensions[ 'KHR_texture_transform' ] = transformDef;
933
+ this.extensionsUsed[ 'KHR_texture_transform' ] = true;
934
+
935
+ }
936
+
937
+ }
938
+
939
+ async buildMetalRoughTextureAsync( metalnessMap, roughnessMap ) {
940
+
941
+ if ( metalnessMap === roughnessMap ) return metalnessMap;
942
+
943
+ function getEncodingConversion( map ) {
944
+
945
+ if ( map.colorSpace === SRGBColorSpace ) {
946
+
947
+ return function SRGBToLinear( c ) {
948
+
949
+ return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
950
+
951
+ };
952
+
953
+ }
954
+
955
+ return function LinearToLinear( c ) {
956
+
957
+ return c;
958
+
959
+ };
960
+
961
+ }
962
+
963
+ if ( metalnessMap instanceof CompressedTexture ) {
964
+
965
+ metalnessMap = await this.decompressTextureAsync( metalnessMap );
966
+
967
+ }
968
+
969
+ if ( roughnessMap instanceof CompressedTexture ) {
970
+
971
+ roughnessMap = await this.decompressTextureAsync( roughnessMap );
972
+
973
+ }
974
+
975
+ const metalness = metalnessMap ? metalnessMap.image : null;
976
+ const roughness = roughnessMap ? roughnessMap.image : null;
977
+
978
+ const width = Math.max( metalness ? metalness.width : 0, roughness ? roughness.width : 0 );
979
+ const height = Math.max( metalness ? metalness.height : 0, roughness ? roughness.height : 0 );
980
+
981
+ const canvas = getCanvas();
982
+ canvas.width = width;
983
+ canvas.height = height;
984
+
985
+ const context = canvas.getContext( '2d', {
986
+ willReadFrequently: true,
987
+ } );
988
+ context.fillStyle = '#00ffff';
989
+ context.fillRect( 0, 0, width, height );
990
+
991
+ const composite = context.getImageData( 0, 0, width, height );
992
+
993
+ if ( metalness ) {
994
+
995
+ context.drawImage( metalness, 0, 0, width, height );
996
+
997
+ const convert = getEncodingConversion( metalnessMap );
998
+ const data = context.getImageData( 0, 0, width, height ).data;
999
+
1000
+ for ( let i = 2; i < data.length; i += 4 ) {
1001
+
1002
+ composite.data[ i ] = convert( data[ i ] / 256 ) * 256;
1003
+
1004
+ }
1005
+
1006
+ }
1007
+
1008
+ if ( roughness ) {
1009
+
1010
+ context.drawImage( roughness, 0, 0, width, height );
1011
+
1012
+ const convert = getEncodingConversion( roughnessMap );
1013
+ const data = context.getImageData( 0, 0, width, height ).data;
1014
+
1015
+ for ( let i = 1; i < data.length; i += 4 ) {
1016
+
1017
+ composite.data[ i ] = convert( data[ i ] / 256 ) * 256;
1018
+
1019
+ }
1020
+
1021
+ }
1022
+
1023
+ context.putImageData( composite, 0, 0 );
1024
+
1025
+ //
1026
+
1027
+ const reference = metalnessMap || roughnessMap;
1028
+
1029
+ const texture = reference.clone();
1030
+
1031
+ texture.source = new Source( canvas );
1032
+ texture.colorSpace = NoColorSpace;
1033
+ texture.channel = ( metalnessMap || roughnessMap ).channel;
1034
+
1035
+ if ( metalnessMap && roughnessMap && metalnessMap.channel !== roughnessMap.channel ) {
1036
+
1037
+ console.warn( 'THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match.' );
1038
+
1039
+ }
1040
+
1041
+ console.warn( 'THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.' );
1042
+
1043
+ return texture;
1044
+
1045
+ }
1046
+
1047
+
1048
+ async decompressTextureAsync( texture, maxTextureSize = Infinity ) {
1049
+
1050
+ if ( this.textureUtils === null ) {
1051
+
1052
+ throw new Error( 'THREE.GLTFExporter: setTextureUtils() must be called to process compressed textures.' );
1053
+
1054
+ }
1055
+
1056
+ return await this.textureUtils.decompress( texture, maxTextureSize );
1057
+
1058
+ }
1059
+
1060
+ /**
1061
+ * Process a buffer to append to the default one.
1062
+ * @param {ArrayBuffer} buffer
1063
+ * @return {0}
1064
+ */
1065
+ processBuffer( buffer ) {
1066
+
1067
+ const json = this.json;
1068
+ const buffers = this.buffers;
1069
+
1070
+ if ( ! json.buffers ) json.buffers = [ { byteLength: 0 } ];
1071
+
1072
+ // All buffers are merged before export.
1073
+ buffers.push( buffer );
1074
+
1075
+ return 0;
1076
+
1077
+ }
1078
+
1079
+ /**
1080
+ * Process and generate a BufferView
1081
+ * @param {BufferAttribute} attribute
1082
+ * @param {number} componentType
1083
+ * @param {number} start
1084
+ * @param {number} count
1085
+ * @param {number} [target] Target usage of the BufferView
1086
+ * @return {Object}
1087
+ */
1088
+ processBufferView( attribute, componentType, start, count, target ) {
1089
+
1090
+ const json = this.json;
1091
+
1092
+ if ( ! json.bufferViews ) json.bufferViews = [];
1093
+
1094
+ // Create a new dataview and dump the attribute's array into it
1095
+
1096
+ let componentSize;
1097
+
1098
+ switch ( componentType ) {
1099
+
1100
+ case WEBGL_CONSTANTS.BYTE:
1101
+ case WEBGL_CONSTANTS.UNSIGNED_BYTE:
1102
+
1103
+ componentSize = 1;
1104
+
1105
+ break;
1106
+
1107
+ case WEBGL_CONSTANTS.SHORT:
1108
+ case WEBGL_CONSTANTS.UNSIGNED_SHORT:
1109
+
1110
+ componentSize = 2;
1111
+
1112
+ break;
1113
+
1114
+ default:
1115
+
1116
+ componentSize = 4;
1117
+
1118
+ }
1119
+
1120
+ let byteStride = attribute.itemSize * componentSize;
1121
+
1122
+ if ( target === WEBGL_CONSTANTS.ARRAY_BUFFER ) {
1123
+
1124
+ // Each element of a vertex attribute MUST be aligned to 4-byte boundaries
1125
+ // inside a bufferView
1126
+ byteStride = Math.ceil( byteStride / 4 ) * 4;
1127
+
1128
+ }
1129
+
1130
+ const byteLength = getPaddedBufferSize( count * byteStride );
1131
+ const dataView = new DataView( new ArrayBuffer( byteLength ) );
1132
+ let offset = 0;
1133
+
1134
+ for ( let i = start; i < start + count; i ++ ) {
1135
+
1136
+ for ( let a = 0; a < attribute.itemSize; a ++ ) {
1137
+
1138
+ let value;
1139
+
1140
+ if ( attribute.itemSize > 4 ) {
1141
+
1142
+ // no support for interleaved data for itemSize > 4
1143
+
1144
+ value = attribute.array[ i * attribute.itemSize + a ];
1145
+
1146
+ } else {
1147
+
1148
+ if ( a === 0 ) value = attribute.getX( i );
1149
+ else if ( a === 1 ) value = attribute.getY( i );
1150
+ else if ( a === 2 ) value = attribute.getZ( i );
1151
+ else if ( a === 3 ) value = attribute.getW( i );
1152
+
1153
+ if ( attribute.normalized === true ) {
1154
+
1155
+ value = MathUtils.normalize( value, attribute.array );
1156
+
1157
+ }
1158
+
1159
+ }
1160
+
1161
+ if ( componentType === WEBGL_CONSTANTS.FLOAT ) {
1162
+
1163
+ dataView.setFloat32( offset, value, true );
1164
+
1165
+ } else if ( componentType === WEBGL_CONSTANTS.INT ) {
1166
+
1167
+ dataView.setInt32( offset, value, true );
1168
+
1169
+ } else if ( componentType === WEBGL_CONSTANTS.UNSIGNED_INT ) {
1170
+
1171
+ dataView.setUint32( offset, value, true );
1172
+
1173
+ } else if ( componentType === WEBGL_CONSTANTS.SHORT ) {
1174
+
1175
+ dataView.setInt16( offset, value, true );
1176
+
1177
+ } else if ( componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT ) {
1178
+
1179
+ dataView.setUint16( offset, value, true );
1180
+
1181
+ } else if ( componentType === WEBGL_CONSTANTS.BYTE ) {
1182
+
1183
+ dataView.setInt8( offset, value );
1184
+
1185
+ } else if ( componentType === WEBGL_CONSTANTS.UNSIGNED_BYTE ) {
1186
+
1187
+ dataView.setUint8( offset, value );
1188
+
1189
+ }
1190
+
1191
+ offset += componentSize;
1192
+
1193
+ }
1194
+
1195
+ if ( ( offset % byteStride ) !== 0 ) {
1196
+
1197
+ offset += byteStride - ( offset % byteStride );
1198
+
1199
+ }
1200
+
1201
+ }
1202
+
1203
+ const bufferViewDef = {
1204
+
1205
+ buffer: this.processBuffer( dataView.buffer ),
1206
+ byteOffset: this.byteOffset,
1207
+ byteLength: byteLength
1208
+
1209
+ };
1210
+
1211
+ if ( target !== undefined ) bufferViewDef.target = target;
1212
+
1213
+ if ( target === WEBGL_CONSTANTS.ARRAY_BUFFER ) {
1214
+
1215
+ // Only define byteStride for vertex attributes.
1216
+ bufferViewDef.byteStride = byteStride;
1217
+
1218
+ }
1219
+
1220
+ this.byteOffset += byteLength;
1221
+
1222
+ json.bufferViews.push( bufferViewDef );
1223
+
1224
+ // @TODO Merge bufferViews where possible.
1225
+ const output = {
1226
+
1227
+ id: json.bufferViews.length - 1,
1228
+ byteLength: 0
1229
+
1230
+ };
1231
+
1232
+ return output;
1233
+
1234
+ }
1235
+
1236
+ /**
1237
+ * Process and generate a BufferView from an image Blob.
1238
+ * @param {Blob} blob
1239
+ * @return {Promise<number>} An integer
1240
+ */
1241
+ processBufferViewImage( blob ) {
1242
+
1243
+ const writer = this;
1244
+ const json = writer.json;
1245
+
1246
+ if ( ! json.bufferViews ) json.bufferViews = [];
1247
+
1248
+ return new Promise( function ( resolve ) {
1249
+
1250
+ const reader = new FileReader();
1251
+ reader.readAsArrayBuffer( blob );
1252
+ reader.onloadend = function () {
1253
+
1254
+ const buffer = getPaddedArrayBuffer( reader.result );
1255
+
1256
+ const bufferViewDef = {
1257
+ buffer: writer.processBuffer( buffer ),
1258
+ byteOffset: writer.byteOffset,
1259
+ byteLength: buffer.byteLength
1260
+ };
1261
+
1262
+ writer.byteOffset += buffer.byteLength;
1263
+ resolve( json.bufferViews.push( bufferViewDef ) - 1 );
1264
+
1265
+ };
1266
+
1267
+ } );
1268
+
1269
+ }
1270
+
1271
+ /**
1272
+ * Process attribute to generate an accessor
1273
+ * @param {BufferAttribute} attribute Attribute to process
1274
+ * @param {?BufferGeometry} [geometry] Geometry used for truncated draw range
1275
+ * @param {number} [start=0]
1276
+ * @param {number} [count=Infinity]
1277
+ * @return {?number} Index of the processed accessor on the "accessors" array
1278
+ */
1279
+ processAccessor( attribute, geometry, start, count ) {
1280
+
1281
+ const json = this.json;
1282
+
1283
+ const types = {
1284
+
1285
+ 1: 'SCALAR',
1286
+ 2: 'VEC2',
1287
+ 3: 'VEC3',
1288
+ 4: 'VEC4',
1289
+ 9: 'MAT3',
1290
+ 16: 'MAT4'
1291
+
1292
+ };
1293
+
1294
+ let componentType;
1295
+
1296
+ // Detect the component type of the attribute array
1297
+ if ( attribute.array.constructor === Float32Array ) {
1298
+
1299
+ componentType = WEBGL_CONSTANTS.FLOAT;
1300
+
1301
+ } else if ( attribute.array.constructor === Int32Array ) {
1302
+
1303
+ componentType = WEBGL_CONSTANTS.INT;
1304
+
1305
+ } else if ( attribute.array.constructor === Uint32Array ) {
1306
+
1307
+ componentType = WEBGL_CONSTANTS.UNSIGNED_INT;
1308
+
1309
+ } else if ( attribute.array.constructor === Int16Array ) {
1310
+
1311
+ componentType = WEBGL_CONSTANTS.SHORT;
1312
+
1313
+ } else if ( attribute.array.constructor === Uint16Array ) {
1314
+
1315
+ componentType = WEBGL_CONSTANTS.UNSIGNED_SHORT;
1316
+
1317
+ } else if ( attribute.array.constructor === Int8Array ) {
1318
+
1319
+ componentType = WEBGL_CONSTANTS.BYTE;
1320
+
1321
+ } else if ( attribute.array.constructor === Uint8Array ) {
1322
+
1323
+ componentType = WEBGL_CONSTANTS.UNSIGNED_BYTE;
1324
+
1325
+ } else {
1326
+
1327
+ throw new Error( 'THREE.GLTFExporter: Unsupported bufferAttribute component type: ' + attribute.array.constructor.name );
1328
+
1329
+ }
1330
+
1331
+ if ( start === undefined ) start = 0;
1332
+ if ( count === undefined || count === Infinity ) count = attribute.count;
1333
+
1334
+ // Skip creating an accessor if the attribute doesn't have data to export
1335
+ if ( count === 0 ) return null;
1336
+
1337
+ const minMax = getMinMax( attribute, start, count );
1338
+ let bufferViewTarget;
1339
+
1340
+ // If geometry isn't provided, don't infer the target usage of the bufferView. For
1341
+ // animation samplers, target must not be set.
1342
+ if ( geometry !== undefined ) {
1343
+
1344
+ bufferViewTarget = attribute === geometry.index ? WEBGL_CONSTANTS.ELEMENT_ARRAY_BUFFER : WEBGL_CONSTANTS.ARRAY_BUFFER;
1345
+
1346
+ }
1347
+
1348
+ const bufferView = this.processBufferView( attribute, componentType, start, count, bufferViewTarget );
1349
+
1350
+ const accessorDef = {
1351
+
1352
+ bufferView: bufferView.id,
1353
+ byteOffset: bufferView.byteOffset,
1354
+ componentType: componentType,
1355
+ count: count,
1356
+ max: minMax.max,
1357
+ min: minMax.min,
1358
+ type: types[ attribute.itemSize ]
1359
+
1360
+ };
1361
+
1362
+ if ( attribute.normalized === true ) accessorDef.normalized = true;
1363
+ if ( ! json.accessors ) json.accessors = [];
1364
+
1365
+ return json.accessors.push( accessorDef ) - 1;
1366
+
1367
+ }
1368
+
1369
+ /**
1370
+ * Process image
1371
+ * @param {Image} image to process
1372
+ * @param {number} format Identifier of the format (RGBAFormat)
1373
+ * @param {boolean} flipY before writing out the image
1374
+ * @param {string} mimeType export format
1375
+ * @return {number} Index of the processed texture in the "images" array
1376
+ */
1377
+ processImage( image, format, flipY, mimeType = 'image/png' ) {
1378
+
1379
+ if ( image !== null ) {
1380
+
1381
+ const writer = this;
1382
+ const cache = writer.cache;
1383
+ const json = writer.json;
1384
+ const options = writer.options;
1385
+ const pending = writer.pending;
1386
+
1387
+ if ( ! cache.images.has( image ) ) cache.images.set( image, {} );
1388
+
1389
+ const cachedImages = cache.images.get( image );
1390
+
1391
+ const key = mimeType + ':flipY/' + flipY.toString();
1392
+
1393
+ if ( cachedImages[ key ] !== undefined ) return cachedImages[ key ];
1394
+
1395
+ if ( ! json.images ) json.images = [];
1396
+
1397
+ const imageDef = { mimeType: mimeType };
1398
+
1399
+ const canvas = getCanvas();
1400
+
1401
+ canvas.width = Math.min( image.width, options.maxTextureSize );
1402
+ canvas.height = Math.min( image.height, options.maxTextureSize );
1403
+
1404
+ const ctx = canvas.getContext( '2d', {
1405
+ willReadFrequently: true,
1406
+ } );
1407
+
1408
+ if ( flipY === true ) {
1409
+
1410
+ ctx.translate( 0, canvas.height );
1411
+ ctx.scale( 1, - 1 );
1412
+
1413
+ }
1414
+
1415
+ if ( image.data !== undefined ) { // THREE.DataTexture
1416
+
1417
+ if ( format !== RGBAFormat ) {
1418
+
1419
+ console.error( 'GLTFExporter: Only RGBAFormat is supported.', format );
1420
+
1421
+ }
1422
+
1423
+ if ( image.width > options.maxTextureSize || image.height > options.maxTextureSize ) {
1424
+
1425
+ console.warn( 'GLTFExporter: Image size is bigger than maxTextureSize', image );
1426
+
1427
+ }
1428
+
1429
+ const data = new Uint8ClampedArray( image.height * image.width * 4 );
1430
+
1431
+ for ( let i = 0; i < data.length; i += 4 ) {
1432
+
1433
+ data[ i + 0 ] = image.data[ i + 0 ];
1434
+ data[ i + 1 ] = image.data[ i + 1 ];
1435
+ data[ i + 2 ] = image.data[ i + 2 ];
1436
+ data[ i + 3 ] = image.data[ i + 3 ];
1437
+
1438
+ }
1439
+
1440
+ ctx.putImageData( new ImageData( data, image.width, image.height ), 0, 0 );
1441
+
1442
+ } else {
1443
+
1444
+ if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
1445
+ ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
1446
+ ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ||
1447
+ ( typeof OffscreenCanvas !== 'undefined' && image instanceof OffscreenCanvas ) ) {
1448
+
1449
+ ctx.drawImage( image, 0, 0, canvas.width, canvas.height );
1450
+
1451
+ } else {
1452
+
1453
+ throw new Error( 'THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.' );
1454
+
1455
+ }
1456
+
1457
+ }
1458
+
1459
+ if ( options.binary === true ) {
1460
+
1461
+ pending.push(
1462
+
1463
+ getToBlobPromise( canvas, mimeType )
1464
+ .then( blob => writer.processBufferViewImage( blob ) )
1465
+ .then( bufferViewIndex => {
1466
+
1467
+ imageDef.bufferView = bufferViewIndex;
1468
+
1469
+ } )
1470
+
1471
+ );
1472
+
1473
+ } else {
1474
+
1475
+ imageDef.uri = ImageUtils.getDataURL( canvas, mimeType );
1476
+
1477
+ }
1478
+
1479
+ const index = json.images.push( imageDef ) - 1;
1480
+ cachedImages[ key ] = index;
1481
+ return index;
1482
+
1483
+ } else {
1484
+
1485
+ throw new Error( 'THREE.GLTFExporter: No valid image data found. Unable to process texture.' );
1486
+
1487
+ }
1488
+
1489
+ }
1490
+
1491
+ /**
1492
+ * Process sampler
1493
+ * @param {Texture} map Texture to process
1494
+ * @return {number} Index of the processed texture in the "samplers" array
1495
+ */
1496
+ processSampler( map ) {
1497
+
1498
+ const json = this.json;
1499
+
1500
+ if ( ! json.samplers ) json.samplers = [];
1501
+
1502
+ const samplerDef = {
1503
+ magFilter: THREE_TO_WEBGL[ map.magFilter ],
1504
+ minFilter: THREE_TO_WEBGL[ map.minFilter ],
1505
+ wrapS: THREE_TO_WEBGL[ map.wrapS ],
1506
+ wrapT: THREE_TO_WEBGL[ map.wrapT ]
1507
+ };
1508
+
1509
+ return json.samplers.push( samplerDef ) - 1;
1510
+
1511
+ }
1512
+
1513
+ /**
1514
+ * Process texture
1515
+ * @param {Texture} map Map to process
1516
+ * @return {Promise<number>} Index of the processed texture in the "textures" array
1517
+ */
1518
+ async processTextureAsync( map ) {
1519
+
1520
+ const writer = this;
1521
+ const options = writer.options;
1522
+ const cache = this.cache;
1523
+ const json = this.json;
1524
+
1525
+ if ( cache.textures.has( map ) ) return cache.textures.get( map );
1526
+
1527
+ if ( ! json.textures ) json.textures = [];
1528
+
1529
+ // make non-readable textures (e.g. CompressedTexture) readable by blitting them into a new texture
1530
+ if ( map instanceof CompressedTexture ) {
1531
+
1532
+ map = await this.decompressTextureAsync( map, options.maxTextureSize );
1533
+
1534
+ }
1535
+
1536
+ let mimeType = map.userData.mimeType;
1537
+
1538
+ if ( mimeType === 'image/webp' ) mimeType = 'image/png';
1539
+
1540
+ const textureDef = {
1541
+ sampler: this.processSampler( map ),
1542
+ source: this.processImage( map.image, map.format, map.flipY, mimeType )
1543
+ };
1544
+
1545
+ if ( map.name ) textureDef.name = map.name;
1546
+
1547
+ await this._invokeAllAsync( async function ( ext ) {
1548
+
1549
+ ext.writeTexture && await ext.writeTexture( map, textureDef );
1550
+
1551
+ } );
1552
+
1553
+ const index = json.textures.push( textureDef ) - 1;
1554
+ cache.textures.set( map, index );
1555
+ return index;
1556
+
1557
+ }
1558
+
1559
+ /**
1560
+ * Process material
1561
+ * @param {THREE.Material} material Material to process
1562
+ * @return {Promise<?number>} Index of the processed material in the "materials" array
1563
+ */
1564
+ async processMaterialAsync( material ) {
1565
+
1566
+ const cache = this.cache;
1567
+ const json = this.json;
1568
+
1569
+ if ( cache.materials.has( material ) ) return cache.materials.get( material );
1570
+
1571
+ if ( material.isShaderMaterial ) {
1572
+
1573
+ console.warn( 'GLTFExporter: THREE.ShaderMaterial not supported.' );
1574
+ return null;
1575
+
1576
+ }
1577
+
1578
+ if ( ! json.materials ) json.materials = [];
1579
+
1580
+ // @QUESTION Should we avoid including any attribute that has the default value?
1581
+ const materialDef = { pbrMetallicRoughness: {} };
1582
+
1583
+ if ( material.isMeshStandardMaterial !== true && material.isMeshBasicMaterial !== true ) {
1584
+
1585
+ console.warn( 'GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.' );
1586
+
1587
+ }
1588
+
1589
+ // pbrMetallicRoughness.baseColorFactor
1590
+ const color = material.color.toArray().concat( [ material.opacity ] );
1591
+
1592
+ if ( ! equalArray( color, [ 1, 1, 1, 1 ] ) ) {
1593
+
1594
+ materialDef.pbrMetallicRoughness.baseColorFactor = color;
1595
+
1596
+ }
1597
+
1598
+ if ( material.isMeshStandardMaterial ) {
1599
+
1600
+ materialDef.pbrMetallicRoughness.metallicFactor = material.metalness;
1601
+ materialDef.pbrMetallicRoughness.roughnessFactor = material.roughness;
1602
+
1603
+ } else {
1604
+
1605
+ materialDef.pbrMetallicRoughness.metallicFactor = 0;
1606
+ materialDef.pbrMetallicRoughness.roughnessFactor = 1;
1607
+
1608
+ }
1609
+
1610
+ // pbrMetallicRoughness.metallicRoughnessTexture
1611
+ if ( material.metalnessMap || material.roughnessMap ) {
1612
+
1613
+ const metalRoughTexture = await this.buildMetalRoughTextureAsync( material.metalnessMap, material.roughnessMap );
1614
+
1615
+ const metalRoughMapDef = {
1616
+ index: await this.processTextureAsync( metalRoughTexture ),
1617
+ texCoord: metalRoughTexture.channel
1618
+ };
1619
+ this.applyTextureTransform( metalRoughMapDef, metalRoughTexture );
1620
+ materialDef.pbrMetallicRoughness.metallicRoughnessTexture = metalRoughMapDef;
1621
+
1622
+ }
1623
+
1624
+ // pbrMetallicRoughness.baseColorTexture
1625
+ if ( material.map ) {
1626
+
1627
+ const baseColorMapDef = {
1628
+ index: await this.processTextureAsync( material.map ),
1629
+ texCoord: material.map.channel
1630
+ };
1631
+ this.applyTextureTransform( baseColorMapDef, material.map );
1632
+ materialDef.pbrMetallicRoughness.baseColorTexture = baseColorMapDef;
1633
+
1634
+ }
1635
+
1636
+ if ( material.emissive ) {
1637
+
1638
+ const emissive = material.emissive;
1639
+ const maxEmissiveComponent = Math.max( emissive.r, emissive.g, emissive.b );
1640
+
1641
+ if ( maxEmissiveComponent > 0 ) {
1642
+
1643
+ materialDef.emissiveFactor = material.emissive.toArray();
1644
+
1645
+ }
1646
+
1647
+ // emissiveTexture
1648
+ if ( material.emissiveMap ) {
1649
+
1650
+ const emissiveMapDef = {
1651
+ index: await this.processTextureAsync( material.emissiveMap ),
1652
+ texCoord: material.emissiveMap.channel
1653
+ };
1654
+ this.applyTextureTransform( emissiveMapDef, material.emissiveMap );
1655
+ materialDef.emissiveTexture = emissiveMapDef;
1656
+
1657
+ }
1658
+
1659
+ }
1660
+
1661
+ // normalTexture
1662
+ if ( material.normalMap ) {
1663
+
1664
+ const normalMapDef = {
1665
+ index: await this.processTextureAsync( material.normalMap ),
1666
+ texCoord: material.normalMap.channel
1667
+ };
1668
+
1669
+ if ( material.normalScale && material.normalScale.x !== 1 ) {
1670
+
1671
+ // glTF normal scale is univariate. Ignore `y`, which may be flipped.
1672
+ // Context: https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
1673
+ normalMapDef.scale = material.normalScale.x;
1674
+
1675
+ }
1676
+
1677
+ this.applyTextureTransform( normalMapDef, material.normalMap );
1678
+ materialDef.normalTexture = normalMapDef;
1679
+
1680
+ }
1681
+
1682
+ // occlusionTexture
1683
+ if ( material.aoMap ) {
1684
+
1685
+ const occlusionMapDef = {
1686
+ index: await this.processTextureAsync( material.aoMap ),
1687
+ texCoord: material.aoMap.channel
1688
+ };
1689
+
1690
+ if ( material.aoMapIntensity !== 1.0 ) {
1691
+
1692
+ occlusionMapDef.strength = material.aoMapIntensity;
1693
+
1694
+ }
1695
+
1696
+ this.applyTextureTransform( occlusionMapDef, material.aoMap );
1697
+ materialDef.occlusionTexture = occlusionMapDef;
1698
+
1699
+ }
1700
+
1701
+ // alphaMode
1702
+ if ( material.transparent ) {
1703
+
1704
+ materialDef.alphaMode = 'BLEND';
1705
+
1706
+ } else {
1707
+
1708
+ if ( material.alphaTest > 0.0 ) {
1709
+
1710
+ materialDef.alphaMode = 'MASK';
1711
+ materialDef.alphaCutoff = material.alphaTest;
1712
+
1713
+ }
1714
+
1715
+ }
1716
+
1717
+ // doubleSided
1718
+ if ( material.side === DoubleSide ) materialDef.doubleSided = true;
1719
+ if ( material.name !== '' ) materialDef.name = material.name;
1720
+
1721
+ this.serializeUserData( material, materialDef );
1722
+
1723
+ await this._invokeAllAsync( async function ( ext ) {
1724
+
1725
+ ext.writeMaterialAsync && await ext.writeMaterialAsync( material, materialDef );
1726
+
1727
+ } );
1728
+
1729
+ const index = json.materials.push( materialDef ) - 1;
1730
+ cache.materials.set( material, index );
1731
+ return index;
1732
+
1733
+ }
1734
+
1735
+ /**
1736
+ * Process mesh
1737
+ * @param {THREE.Mesh} mesh Mesh to process
1738
+ * @return {Promise<?number>} Index of the processed mesh in the "meshes" array
1739
+ */
1740
+ async processMeshAsync( mesh ) {
1741
+
1742
+ const cache = this.cache;
1743
+ const json = this.json;
1744
+
1745
+ const meshCacheKeyParts = [ mesh.geometry.uuid ];
1746
+
1747
+ if ( Array.isArray( mesh.material ) ) {
1748
+
1749
+ for ( let i = 0, l = mesh.material.length; i < l; i ++ ) {
1750
+
1751
+ meshCacheKeyParts.push( mesh.material[ i ].uuid );
1752
+
1753
+ }
1754
+
1755
+ } else {
1756
+
1757
+ meshCacheKeyParts.push( mesh.material.uuid );
1758
+
1759
+ }
1760
+
1761
+ const meshCacheKey = meshCacheKeyParts.join( ':' );
1762
+
1763
+ if ( cache.meshes.has( meshCacheKey ) ) return cache.meshes.get( meshCacheKey );
1764
+
1765
+ const geometry = mesh.geometry;
1766
+
1767
+ let mode;
1768
+
1769
+ // Use the correct mode
1770
+ if ( mesh.isLineSegments ) {
1771
+
1772
+ mode = WEBGL_CONSTANTS.LINES;
1773
+
1774
+ } else if ( mesh.isLineLoop ) {
1775
+
1776
+ mode = WEBGL_CONSTANTS.LINE_LOOP;
1777
+
1778
+ } else if ( mesh.isLine ) {
1779
+
1780
+ mode = WEBGL_CONSTANTS.LINE_STRIP;
1781
+
1782
+ } else if ( mesh.isPoints ) {
1783
+
1784
+ mode = WEBGL_CONSTANTS.POINTS;
1785
+
1786
+ } else {
1787
+
1788
+ mode = mesh.material.wireframe ? WEBGL_CONSTANTS.LINES : WEBGL_CONSTANTS.TRIANGLES;
1789
+
1790
+ }
1791
+
1792
+ const meshDef = {};
1793
+ const attributes = {};
1794
+ const primitives = [];
1795
+ const targets = [];
1796
+
1797
+ // Conversion between attributes names in threejs and gltf spec
1798
+ const nameConversion = {
1799
+ uv: 'TEXCOORD_0',
1800
+ uv1: 'TEXCOORD_1',
1801
+ uv2: 'TEXCOORD_2',
1802
+ uv3: 'TEXCOORD_3',
1803
+ color: 'COLOR_0',
1804
+ skinWeight: 'WEIGHTS_0',
1805
+ skinIndex: 'JOINTS_0'
1806
+ };
1807
+
1808
+ const originalNormal = geometry.getAttribute( 'normal' );
1809
+
1810
+ if ( originalNormal !== undefined && ! this.isNormalizedNormalAttribute( originalNormal ) ) {
1811
+
1812
+ console.warn( 'THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one.' );
1813
+
1814
+ geometry.setAttribute( 'normal', this.createNormalizedNormalAttribute( originalNormal ) );
1815
+
1816
+ }
1817
+
1818
+ // @QUESTION Detect if .vertexColors = true?
1819
+ // For every attribute create an accessor
1820
+ let modifiedAttribute = null;
1821
+
1822
+ for ( let attributeName in geometry.attributes ) {
1823
+
1824
+ // Ignore morph target attributes, which are exported later.
1825
+ if ( attributeName.slice( 0, 5 ) === 'morph' ) continue;
1826
+
1827
+ const attribute = geometry.attributes[ attributeName ];
1828
+ attributeName = nameConversion[ attributeName ] || attributeName.toUpperCase();
1829
+
1830
+ // Prefix all geometry attributes except the ones specifically
1831
+ // listed in the spec; non-spec attributes are considered custom.
1832
+ const validVertexAttributes =
1833
+ /^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/;
1834
+
1835
+ if ( ! validVertexAttributes.test( attributeName ) ) attributeName = '_' + attributeName;
1836
+
1837
+ if ( cache.attributes.has( this.getUID( attribute ) ) ) {
1838
+
1839
+ attributes[ attributeName ] = cache.attributes.get( this.getUID( attribute ) );
1840
+ continue;
1841
+
1842
+ }
1843
+
1844
+ // Enforce glTF vertex attribute requirements:
1845
+ // - JOINTS_0 must be UNSIGNED_BYTE or UNSIGNED_SHORT
1846
+ // - Only custom attributes may be INT or UNSIGNED_INT
1847
+ modifiedAttribute = null;
1848
+ const array = attribute.array;
1849
+
1850
+ if ( attributeName === 'JOINTS_0' &&
1851
+ ! ( array instanceof Uint16Array ) &&
1852
+ ! ( array instanceof Uint8Array ) ) {
1853
+
1854
+ console.warn( 'GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.' );
1855
+ modifiedAttribute = new BufferAttribute( new Uint16Array( array ), attribute.itemSize, attribute.normalized );
1856
+
1857
+ } else if ( ( array instanceof Uint32Array || array instanceof Int32Array ) && ! attributeName.startsWith( '_' ) ) {
1858
+
1859
+ console.warn( `GLTFExporter: Attribute "${ attributeName }" converted to type FLOAT.` );
1860
+ modifiedAttribute = GLTFExporter.Utils.toFloat32BufferAttribute( attribute );
1861
+
1862
+ }
1863
+
1864
+ const accessor = this.processAccessor( modifiedAttribute || attribute, geometry );
1865
+
1866
+ if ( accessor !== null ) {
1867
+
1868
+ if ( ! attributeName.startsWith( '_' ) ) {
1869
+
1870
+ this.detectMeshQuantization( attributeName, attribute );
1871
+
1872
+ }
1873
+
1874
+ attributes[ attributeName ] = accessor;
1875
+ cache.attributes.set( this.getUID( attribute ), accessor );
1876
+
1877
+ }
1878
+
1879
+ }
1880
+
1881
+ if ( originalNormal !== undefined ) geometry.setAttribute( 'normal', originalNormal );
1882
+
1883
+ // Skip if no exportable attributes found
1884
+ if ( Object.keys( attributes ).length === 0 ) return null;
1885
+
1886
+ // Morph targets
1887
+ if ( mesh.morphTargetInfluences !== undefined && mesh.morphTargetInfluences.length > 0 ) {
1888
+
1889
+ const weights = [];
1890
+ const targetNames = [];
1891
+ const reverseDictionary = {};
1892
+
1893
+ if ( mesh.morphTargetDictionary !== undefined ) {
1894
+
1895
+ for ( const key in mesh.morphTargetDictionary ) {
1896
+
1897
+ reverseDictionary[ mesh.morphTargetDictionary[ key ] ] = key;
1898
+
1899
+ }
1900
+
1901
+ }
1902
+
1903
+ for ( let i = 0; i < mesh.morphTargetInfluences.length; ++ i ) {
1904
+
1905
+ const target = {};
1906
+ let warned = false;
1907
+
1908
+ for ( const attributeName in geometry.morphAttributes ) {
1909
+
1910
+ // glTF 2.0 morph supports only POSITION/NORMAL/TANGENT.
1911
+ // Three.js doesn't support TANGENT yet.
1912
+
1913
+ if ( attributeName !== 'position' && attributeName !== 'normal' ) {
1914
+
1915
+ if ( ! warned ) {
1916
+
1917
+ console.warn( 'GLTFExporter: Only POSITION and NORMAL morph are supported.' );
1918
+ warned = true;
1919
+
1920
+ }
1921
+
1922
+ continue;
1923
+
1924
+ }
1925
+
1926
+ const attribute = geometry.morphAttributes[ attributeName ][ i ];
1927
+ const gltfAttributeName = attributeName.toUpperCase();
1928
+
1929
+ // Three.js morph attribute has absolute values while the one of glTF has relative values.
1930
+ //
1931
+ // glTF 2.0 Specification:
1932
+ // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#morph-targets
1933
+
1934
+ const baseAttribute = geometry.attributes[ attributeName ];
1935
+
1936
+ if ( cache.attributes.has( this.getUID( attribute, true ) ) ) {
1937
+
1938
+ target[ gltfAttributeName ] = cache.attributes.get( this.getUID( attribute, true ) );
1939
+ continue;
1940
+
1941
+ }
1942
+
1943
+ // Clones attribute not to override
1944
+ const relativeAttribute = attribute.clone();
1945
+
1946
+ if ( ! geometry.morphTargetsRelative ) {
1947
+
1948
+ for ( let j = 0, jl = attribute.count; j < jl; j ++ ) {
1949
+
1950
+ for ( let a = 0; a < attribute.itemSize; a ++ ) {
1951
+
1952
+ if ( a === 0 ) relativeAttribute.setX( j, attribute.getX( j ) - baseAttribute.getX( j ) );
1953
+ if ( a === 1 ) relativeAttribute.setY( j, attribute.getY( j ) - baseAttribute.getY( j ) );
1954
+ if ( a === 2 ) relativeAttribute.setZ( j, attribute.getZ( j ) - baseAttribute.getZ( j ) );
1955
+ if ( a === 3 ) relativeAttribute.setW( j, attribute.getW( j ) - baseAttribute.getW( j ) );
1956
+
1957
+ }
1958
+
1959
+ }
1960
+
1961
+ }
1962
+
1963
+ target[ gltfAttributeName ] = this.processAccessor( relativeAttribute, geometry );
1964
+ cache.attributes.set( this.getUID( baseAttribute, true ), target[ gltfAttributeName ] );
1965
+
1966
+ }
1967
+
1968
+ targets.push( target );
1969
+
1970
+ weights.push( mesh.morphTargetInfluences[ i ] );
1971
+
1972
+ if ( mesh.morphTargetDictionary !== undefined ) targetNames.push( reverseDictionary[ i ] );
1973
+
1974
+ }
1975
+
1976
+ meshDef.weights = weights;
1977
+
1978
+ if ( targetNames.length > 0 ) {
1979
+
1980
+ meshDef.extras = {};
1981
+ meshDef.extras.targetNames = targetNames;
1982
+
1983
+ }
1984
+
1985
+ }
1986
+
1987
+ const isMultiMaterial = Array.isArray( mesh.material );
1988
+
1989
+ if ( isMultiMaterial && geometry.groups.length === 0 ) return null;
1990
+
1991
+ let didForceIndices = false;
1992
+
1993
+ if ( isMultiMaterial && geometry.index === null ) {
1994
+
1995
+ const indices = [];
1996
+
1997
+ for ( let i = 0, il = geometry.attributes.position.count; i < il; i ++ ) {
1998
+
1999
+ indices[ i ] = i;
2000
+
2001
+ }
2002
+
2003
+ geometry.setIndex( indices );
2004
+
2005
+ didForceIndices = true;
2006
+
2007
+ }
2008
+
2009
+ const materials = isMultiMaterial ? mesh.material : [ mesh.material ];
2010
+ const groups = isMultiMaterial ? geometry.groups : [ { materialIndex: 0, start: undefined, count: undefined } ];
2011
+
2012
+ for ( let i = 0, il = groups.length; i < il; i ++ ) {
2013
+
2014
+ const primitive = {
2015
+ mode: mode,
2016
+ attributes: attributes,
2017
+ };
2018
+
2019
+ this.serializeUserData( geometry, primitive );
2020
+
2021
+ if ( targets.length > 0 ) primitive.targets = targets;
2022
+
2023
+ if ( geometry.index !== null ) {
2024
+
2025
+ let cacheKey = this.getUID( geometry.index );
2026
+
2027
+ if ( groups[ i ].start !== undefined || groups[ i ].count !== undefined ) {
2028
+
2029
+ cacheKey += ':' + groups[ i ].start + ':' + groups[ i ].count;
2030
+
2031
+ }
2032
+
2033
+ if ( cache.attributes.has( cacheKey ) ) {
2034
+
2035
+ primitive.indices = cache.attributes.get( cacheKey );
2036
+
2037
+ } else {
2038
+
2039
+ primitive.indices = this.processAccessor( geometry.index, geometry, groups[ i ].start, groups[ i ].count );
2040
+ cache.attributes.set( cacheKey, primitive.indices );
2041
+
2042
+ }
2043
+
2044
+ if ( primitive.indices === null ) delete primitive.indices;
2045
+
2046
+ }
2047
+
2048
+ const material = await this.processMaterialAsync( materials[ groups[ i ].materialIndex ] );
2049
+
2050
+ if ( material !== null ) primitive.material = material;
2051
+
2052
+ primitives.push( primitive );
2053
+
2054
+ }
2055
+
2056
+ if ( didForceIndices === true ) {
2057
+
2058
+ geometry.setIndex( null );
2059
+
2060
+ }
2061
+
2062
+ meshDef.primitives = primitives;
2063
+
2064
+ if ( ! json.meshes ) json.meshes = [];
2065
+
2066
+ await this._invokeAllAsync( function ( ext ) {
2067
+
2068
+ ext.writeMesh && ext.writeMesh( mesh, meshDef );
2069
+
2070
+ } );
2071
+
2072
+ const index = json.meshes.push( meshDef ) - 1;
2073
+ cache.meshes.set( meshCacheKey, index );
2074
+ return index;
2075
+
2076
+ }
2077
+
2078
+ /**
2079
+ * If a vertex attribute with a
2080
+ * [non-standard data type](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview)
2081
+ * is used, it is checked whether it is a valid data type according to the
2082
+ * [KHR_mesh_quantization](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md)
2083
+ * extension.
2084
+ * In this case the extension is automatically added to the list of used extensions.
2085
+ *
2086
+ * @param {string} attributeName
2087
+ * @param {THREE.BufferAttribute} attribute
2088
+ */
2089
+ detectMeshQuantization( attributeName, attribute ) {
2090
+
2091
+ if ( this.extensionsUsed[ KHR_MESH_QUANTIZATION ] ) return;
2092
+
2093
+ let attrType = undefined;
2094
+
2095
+ switch ( attribute.array.constructor ) {
2096
+
2097
+ case Int8Array:
2098
+
2099
+ attrType = 'byte';
2100
+
2101
+ break;
2102
+
2103
+ case Uint8Array:
2104
+
2105
+ attrType = 'unsigned byte';
2106
+
2107
+ break;
2108
+
2109
+ case Int16Array:
2110
+
2111
+ attrType = 'short';
2112
+
2113
+ break;
2114
+
2115
+ case Uint16Array:
2116
+
2117
+ attrType = 'unsigned short';
2118
+
2119
+ break;
2120
+
2121
+ default:
2122
+
2123
+ return;
2124
+
2125
+ }
2126
+
2127
+ if ( attribute.normalized ) attrType += ' normalized';
2128
+
2129
+ const attrNamePrefix = attributeName.split( '_', 1 )[ 0 ];
2130
+
2131
+ if ( KHR_mesh_quantization_ExtraAttrTypes[ attrNamePrefix ] && KHR_mesh_quantization_ExtraAttrTypes[ attrNamePrefix ].includes( attrType ) ) {
2132
+
2133
+ this.extensionsUsed[ KHR_MESH_QUANTIZATION ] = true;
2134
+ this.extensionsRequired[ KHR_MESH_QUANTIZATION ] = true;
2135
+
2136
+ }
2137
+
2138
+ }
2139
+
2140
+ /**
2141
+ * Process camera
2142
+ * @param {THREE.Camera} camera Camera to process
2143
+ * @return {number} Index of the processed mesh in the "camera" array
2144
+ */
2145
+ processCamera( camera ) {
2146
+
2147
+ const json = this.json;
2148
+
2149
+ if ( ! json.cameras ) json.cameras = [];
2150
+
2151
+ const isOrtho = camera.isOrthographicCamera;
2152
+
2153
+ const cameraDef = {
2154
+ type: isOrtho ? 'orthographic' : 'perspective'
2155
+ };
2156
+
2157
+ if ( isOrtho ) {
2158
+
2159
+ cameraDef.orthographic = {
2160
+ xmag: camera.right * 2,
2161
+ ymag: camera.top * 2,
2162
+ zfar: camera.far <= 0 ? 0.001 : camera.far,
2163
+ znear: camera.near < 0 ? 0 : camera.near
2164
+ };
2165
+
2166
+ } else {
2167
+
2168
+ cameraDef.perspective = {
2169
+ aspectRatio: camera.aspect,
2170
+ yfov: MathUtils.degToRad( camera.fov ),
2171
+ zfar: camera.far <= 0 ? 0.001 : camera.far,
2172
+ znear: camera.near < 0 ? 0 : camera.near
2173
+ };
2174
+
2175
+ }
2176
+
2177
+ // Question: Is saving "type" as name intentional?
2178
+ if ( camera.name !== '' ) cameraDef.name = camera.type;
2179
+
2180
+ return json.cameras.push( cameraDef ) - 1;
2181
+
2182
+ }
2183
+
2184
+ /**
2185
+ * Creates glTF animation entry from AnimationClip object.
2186
+ *
2187
+ * Status:
2188
+ * - Only properties listed in PATH_PROPERTIES may be animated.
2189
+ *
2190
+ * @param {THREE.AnimationClip} clip
2191
+ * @param {THREE.Object3D} root
2192
+ * @return {?number}
2193
+ */
2194
+ processAnimation( clip, root ) {
2195
+
2196
+ const json = this.json;
2197
+ const nodeMap = this.nodeMap;
2198
+
2199
+ if ( ! json.animations ) json.animations = [];
2200
+
2201
+ clip = GLTFExporter.Utils.mergeMorphTargetTracks( clip.clone(), root );
2202
+
2203
+ const tracks = clip.tracks;
2204
+ const channels = [];
2205
+ const samplers = [];
2206
+
2207
+ for ( let i = 0; i < tracks.length; ++ i ) {
2208
+
2209
+ const track = tracks[ i ];
2210
+ const trackBinding = PropertyBinding.parseTrackName( track.name );
2211
+ let trackNode = PropertyBinding.findNode( root, trackBinding.nodeName );
2212
+ const trackProperty = PATH_PROPERTIES[ trackBinding.propertyName ];
2213
+
2214
+ if ( trackBinding.objectName === 'bones' ) {
2215
+
2216
+ if ( trackNode.isSkinnedMesh === true ) {
2217
+
2218
+ trackNode = trackNode.skeleton.getBoneByName( trackBinding.objectIndex );
2219
+
2220
+ } else {
2221
+
2222
+ trackNode = undefined;
2223
+
2224
+ }
2225
+
2226
+ }
2227
+
2228
+ if ( ! trackNode || ! trackProperty ) {
2229
+
2230
+ console.warn( 'THREE.GLTFExporter: Could not export animation track "%s".', track.name );
2231
+ continue;
2232
+
2233
+ }
2234
+
2235
+ const inputItemSize = 1;
2236
+ let outputItemSize = track.values.length / track.times.length;
2237
+
2238
+ if ( trackProperty === PATH_PROPERTIES.morphTargetInfluences ) {
2239
+
2240
+ outputItemSize /= trackNode.morphTargetInfluences.length;
2241
+
2242
+ }
2243
+
2244
+ let interpolation;
2245
+
2246
+ // @TODO export CubicInterpolant(InterpolateSmooth) as CUBICSPLINE
2247
+
2248
+ // Detecting glTF cubic spline interpolant by checking factory method's special property
2249
+ // GLTFCubicSplineInterpolant is a custom interpolant and track doesn't return
2250
+ // valid value from .getInterpolation().
2251
+ if ( track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === true ) {
2252
+
2253
+ interpolation = 'CUBICSPLINE';
2254
+
2255
+ // itemSize of CUBICSPLINE keyframe is 9
2256
+ // (VEC3 * 3: inTangent, splineVertex, and outTangent)
2257
+ // but needs to be stored as VEC3 so dividing by 3 here.
2258
+ outputItemSize /= 3;
2259
+
2260
+ } else if ( track.getInterpolation() === InterpolateDiscrete ) {
2261
+
2262
+ interpolation = 'STEP';
2263
+
2264
+ } else {
2265
+
2266
+ interpolation = 'LINEAR';
2267
+
2268
+ }
2269
+
2270
+ samplers.push( {
2271
+ input: this.processAccessor( new BufferAttribute( track.times, inputItemSize ) ),
2272
+ output: this.processAccessor( new BufferAttribute( track.values, outputItemSize ) ),
2273
+ interpolation: interpolation
2274
+ } );
2275
+
2276
+ channels.push( {
2277
+ sampler: samplers.length - 1,
2278
+ target: {
2279
+ node: nodeMap.get( trackNode ),
2280
+ path: trackProperty
2281
+ }
2282
+ } );
2283
+
2284
+ }
2285
+
2286
+ const animationDef = {
2287
+ name: clip.name || 'clip_' + json.animations.length,
2288
+ samplers: samplers,
2289
+ channels: channels
2290
+ };
2291
+
2292
+ this.serializeUserData( clip, animationDef );
2293
+
2294
+ json.animations.push( animationDef );
2295
+
2296
+ return json.animations.length - 1;
2297
+
2298
+ }
2299
+
2300
+ /**
2301
+ * @param {THREE.Object3D} object
2302
+ * @return {?number}
2303
+ */
2304
+ processSkin( object ) {
2305
+
2306
+ const json = this.json;
2307
+ const nodeMap = this.nodeMap;
2308
+
2309
+ const node = json.nodes[ nodeMap.get( object ) ];
2310
+
2311
+ const skeleton = object.skeleton;
2312
+
2313
+ if ( skeleton === undefined ) return null;
2314
+
2315
+ const rootJoint = object.skeleton.bones[ 0 ];
2316
+
2317
+ if ( rootJoint === undefined ) return null;
2318
+
2319
+ const joints = [];
2320
+ const inverseBindMatrices = new Float32Array( skeleton.bones.length * 16 );
2321
+ const temporaryBoneInverse = new Matrix4();
2322
+
2323
+ for ( let i = 0; i < skeleton.bones.length; ++ i ) {
2324
+
2325
+ joints.push( nodeMap.get( skeleton.bones[ i ] ) );
2326
+ temporaryBoneInverse.copy( skeleton.boneInverses[ i ] );
2327
+ temporaryBoneInverse.multiply( object.bindMatrix ).toArray( inverseBindMatrices, i * 16 );
2328
+
2329
+ }
2330
+
2331
+ if ( json.skins === undefined ) json.skins = [];
2332
+
2333
+ json.skins.push( {
2334
+ inverseBindMatrices: this.processAccessor( new BufferAttribute( inverseBindMatrices, 16 ) ),
2335
+ joints: joints,
2336
+ skeleton: nodeMap.get( rootJoint )
2337
+ } );
2338
+
2339
+ const skinIndex = node.skin = json.skins.length - 1;
2340
+
2341
+ return skinIndex;
2342
+
2343
+ }
2344
+
2345
+ /**
2346
+ * Process Object3D node
2347
+ * @param {THREE.Object3D} object Object3D to processNodeAsync
2348
+ * @return {Promise<number>} Index of the node in the nodes list
2349
+ */
2350
+ async processNodeAsync( object ) {
2351
+
2352
+ const json = this.json;
2353
+ const options = this.options;
2354
+ const nodeMap = this.nodeMap;
2355
+
2356
+ if ( ! json.nodes ) json.nodes = [];
2357
+
2358
+ const nodeDef = {};
2359
+
2360
+ if ( options.trs ) {
2361
+
2362
+ const rotation = object.quaternion.toArray();
2363
+ const position = object.position.toArray();
2364
+ const scale = object.scale.toArray();
2365
+
2366
+ if ( ! equalArray( rotation, [ 0, 0, 0, 1 ] ) ) {
2367
+
2368
+ nodeDef.rotation = rotation;
2369
+
2370
+ }
2371
+
2372
+ if ( ! equalArray( position, [ 0, 0, 0 ] ) ) {
2373
+
2374
+ nodeDef.translation = position;
2375
+
2376
+ }
2377
+
2378
+ if ( ! equalArray( scale, [ 1, 1, 1 ] ) ) {
2379
+
2380
+ nodeDef.scale = scale;
2381
+
2382
+ }
2383
+
2384
+ } else {
2385
+
2386
+ if ( object.matrixAutoUpdate ) {
2387
+
2388
+ object.updateMatrix();
2389
+
2390
+ }
2391
+
2392
+ if ( isIdentityMatrix( object.matrix ) === false ) {
2393
+
2394
+ nodeDef.matrix = object.matrix.elements;
2395
+
2396
+ }
2397
+
2398
+ }
2399
+
2400
+ // We don't export empty strings name because it represents no-name in Three.js.
2401
+ if ( object.name !== '' ) nodeDef.name = String( object.name );
2402
+
2403
+ this.serializeUserData( object, nodeDef );
2404
+
2405
+ if ( object.isMesh || object.isLine || object.isPoints ) {
2406
+
2407
+ const meshIndex = await this.processMeshAsync( object );
2408
+
2409
+ if ( meshIndex !== null ) nodeDef.mesh = meshIndex;
2410
+
2411
+ } else if ( object.isCamera ) {
2412
+
2413
+ nodeDef.camera = this.processCamera( object );
2414
+
2415
+ }
2416
+
2417
+ if ( object.isSkinnedMesh ) this.skins.push( object );
2418
+
2419
+ const nodeIndex = json.nodes.push( nodeDef ) - 1;
2420
+ nodeMap.set( object, nodeIndex );
2421
+
2422
+ if ( object.children.length > 0 ) {
2423
+
2424
+ const children = [];
2425
+
2426
+ for ( let i = 0, l = object.children.length; i < l; i ++ ) {
2427
+
2428
+ const child = object.children[ i ];
2429
+
2430
+ if ( child.visible || options.onlyVisible === false ) {
2431
+
2432
+ const childNodeIndex = await this.processNodeAsync( child );
2433
+
2434
+ if ( childNodeIndex !== null ) children.push( childNodeIndex );
2435
+
2436
+ }
2437
+
2438
+ }
2439
+
2440
+ if ( children.length > 0 ) nodeDef.children = children;
2441
+
2442
+ }
2443
+
2444
+ await this._invokeAllAsync( function ( ext ) {
2445
+
2446
+ ext.writeNode && ext.writeNode( object, nodeDef );
2447
+
2448
+ } );
2449
+
2450
+ return nodeIndex;
2451
+
2452
+ }
2453
+
2454
+ /**
2455
+ * Process Scene
2456
+ * @param {Scene} scene Scene to process
2457
+ */
2458
+ async processSceneAsync( scene ) {
2459
+
2460
+ const json = this.json;
2461
+ const options = this.options;
2462
+
2463
+ if ( ! json.scenes ) {
2464
+
2465
+ json.scenes = [];
2466
+ json.scene = 0;
2467
+
2468
+ }
2469
+
2470
+ const sceneDef = {};
2471
+
2472
+ if ( scene.name !== '' ) sceneDef.name = scene.name;
2473
+
2474
+ json.scenes.push( sceneDef );
2475
+
2476
+ const nodes = [];
2477
+
2478
+ for ( let i = 0, l = scene.children.length; i < l; i ++ ) {
2479
+
2480
+ const child = scene.children[ i ];
2481
+
2482
+ if ( child.visible || options.onlyVisible === false ) {
2483
+
2484
+ const nodeIndex = await this.processNodeAsync( child );
2485
+
2486
+ if ( nodeIndex !== null ) nodes.push( nodeIndex );
2487
+
2488
+ }
2489
+
2490
+ }
2491
+
2492
+ if ( nodes.length > 0 ) sceneDef.nodes = nodes;
2493
+
2494
+ this.serializeUserData( scene, sceneDef );
2495
+
2496
+ }
2497
+
2498
+ /**
2499
+ * Creates a Scene to hold a list of objects and parse it
2500
+ * @param {Array<THREE.Object3D>} objects List of objects to process
2501
+ */
2502
+ async processObjectsAsync( objects ) {
2503
+
2504
+ const scene = new Scene();
2505
+ scene.name = 'AuxScene';
2506
+
2507
+ for ( let i = 0; i < objects.length; i ++ ) {
2508
+
2509
+ // We push directly to children instead of calling `add` to prevent
2510
+ // modify the .parent and break its original scene and hierarchy
2511
+ scene.children.push( objects[ i ] );
2512
+
2513
+ }
2514
+
2515
+ await this.processSceneAsync( scene );
2516
+
2517
+ }
2518
+
2519
+ /**
2520
+ * @param {THREE.Object3D|Array<THREE.Object3D>} input
2521
+ */
2522
+ async processInputAsync( input ) {
2523
+
2524
+ const options = this.options;
2525
+
2526
+ input = input instanceof Array ? input : [ input ];
2527
+
2528
+ await this._invokeAllAsync( function ( ext ) {
2529
+
2530
+ ext.beforeParse && ext.beforeParse( input );
2531
+
2532
+ } );
2533
+
2534
+ const objectsWithoutScene = [];
2535
+
2536
+ for ( let i = 0; i < input.length; i ++ ) {
2537
+
2538
+ if ( input[ i ] instanceof Scene ) {
2539
+
2540
+ await this.processSceneAsync( input[ i ] );
2541
+
2542
+ } else {
2543
+
2544
+ objectsWithoutScene.push( input[ i ] );
2545
+
2546
+ }
2547
+
2548
+ }
2549
+
2550
+ if ( objectsWithoutScene.length > 0 ) {
2551
+
2552
+ await this.processObjectsAsync( objectsWithoutScene );
2553
+
2554
+ }
2555
+
2556
+ for ( let i = 0; i < this.skins.length; ++ i ) {
2557
+
2558
+ this.processSkin( this.skins[ i ] );
2559
+
2560
+ }
2561
+
2562
+ for ( let i = 0; i < options.animations.length; ++ i ) {
2563
+
2564
+ this.processAnimation( options.animations[ i ], input[ 0 ] );
2565
+
2566
+ }
2567
+
2568
+ await this._invokeAllAsync( function ( ext ) {
2569
+
2570
+ ext.afterParse && ext.afterParse( input );
2571
+
2572
+ } );
2573
+
2574
+ }
2575
+
2576
+ async _invokeAllAsync( func ) {
2577
+
2578
+ for ( let i = 0, il = this.plugins.length; i < il; i ++ ) {
2579
+
2580
+ await func( this.plugins[ i ] );
2581
+
2582
+ }
2583
+
2584
+ }
2585
+
2586
+ }
2587
+
2588
+ /**
2589
+ * Punctual Lights Extension
2590
+ *
2591
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
2592
+ *
2593
+ * @private
2594
+ */
2595
+ class GLTFLightExtension {
2596
+
2597
+ constructor( writer ) {
2598
+
2599
+ this.writer = writer;
2600
+ this.name = 'KHR_lights_punctual';
2601
+
2602
+ }
2603
+
2604
+ writeNode( light, nodeDef ) {
2605
+
2606
+ if ( ! light.isLight ) return;
2607
+
2608
+ if ( ! light.isDirectionalLight && ! light.isPointLight && ! light.isSpotLight ) {
2609
+
2610
+ console.warn( 'THREE.GLTFExporter: Only directional, point, and spot lights are supported.', light );
2611
+ return;
2612
+
2613
+ }
2614
+
2615
+ const writer = this.writer;
2616
+ const json = writer.json;
2617
+ const extensionsUsed = writer.extensionsUsed;
2618
+
2619
+ const lightDef = {};
2620
+
2621
+ if ( light.name ) lightDef.name = light.name;
2622
+
2623
+ lightDef.color = light.color.toArray();
2624
+
2625
+ lightDef.intensity = light.intensity;
2626
+
2627
+ if ( light.isDirectionalLight ) {
2628
+
2629
+ lightDef.type = 'directional';
2630
+
2631
+ } else if ( light.isPointLight ) {
2632
+
2633
+ lightDef.type = 'point';
2634
+
2635
+ if ( light.distance > 0 ) lightDef.range = light.distance;
2636
+
2637
+ } else if ( light.isSpotLight ) {
2638
+
2639
+ lightDef.type = 'spot';
2640
+
2641
+ if ( light.distance > 0 ) lightDef.range = light.distance;
2642
+
2643
+ lightDef.spot = {};
2644
+ lightDef.spot.innerConeAngle = ( 1.0 - light.penumbra ) * light.angle;
2645
+ lightDef.spot.outerConeAngle = light.angle;
2646
+
2647
+ }
2648
+
2649
+ if ( light.decay !== undefined && light.decay !== 2 ) {
2650
+
2651
+ console.warn( 'THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, '
2652
+ + 'and expects light.decay=2.' );
2653
+
2654
+ }
2655
+
2656
+ if ( light.target
2657
+ && ( light.target.parent !== light
2658
+ || light.target.position.x !== 0
2659
+ || light.target.position.y !== 0
2660
+ || light.target.position.z !== - 1 ) ) {
2661
+
2662
+ console.warn( 'THREE.GLTFExporter: Light direction may be lost. For best results, '
2663
+ + 'make light.target a child of the light with position 0,0,-1.' );
2664
+
2665
+ }
2666
+
2667
+ if ( ! extensionsUsed[ this.name ] ) {
2668
+
2669
+ json.extensions = json.extensions || {};
2670
+ json.extensions[ this.name ] = { lights: [] };
2671
+ extensionsUsed[ this.name ] = true;
2672
+
2673
+ }
2674
+
2675
+ const lights = json.extensions[ this.name ].lights;
2676
+ lights.push( lightDef );
2677
+
2678
+ nodeDef.extensions = nodeDef.extensions || {};
2679
+ nodeDef.extensions[ this.name ] = { light: lights.length - 1 };
2680
+
2681
+ }
2682
+
2683
+ }
2684
+
2685
+ /**
2686
+ * Unlit Materials Extension
2687
+ *
2688
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
2689
+ *
2690
+ * @private
2691
+ */
2692
+ class GLTFMaterialsUnlitExtension {
2693
+
2694
+ constructor( writer ) {
2695
+
2696
+ this.writer = writer;
2697
+ this.name = 'KHR_materials_unlit';
2698
+
2699
+ }
2700
+
2701
+ async writeMaterialAsync( material, materialDef ) {
2702
+
2703
+ if ( ! material.isMeshBasicMaterial ) return;
2704
+
2705
+ const writer = this.writer;
2706
+ const extensionsUsed = writer.extensionsUsed;
2707
+
2708
+ materialDef.extensions = materialDef.extensions || {};
2709
+ materialDef.extensions[ this.name ] = {};
2710
+
2711
+ extensionsUsed[ this.name ] = true;
2712
+
2713
+ materialDef.pbrMetallicRoughness.metallicFactor = 0.0;
2714
+ materialDef.pbrMetallicRoughness.roughnessFactor = 0.9;
2715
+
2716
+ }
2717
+
2718
+ }
2719
+
2720
+ /**
2721
+ * Clearcoat Materials Extension
2722
+ *
2723
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat
2724
+ *
2725
+ * @private
2726
+ */
2727
+ class GLTFMaterialsClearcoatExtension {
2728
+
2729
+ constructor( writer ) {
2730
+
2731
+ this.writer = writer;
2732
+ this.name = 'KHR_materials_clearcoat';
2733
+
2734
+ }
2735
+
2736
+ async writeMaterialAsync( material, materialDef ) {
2737
+
2738
+ if ( ! material.isMeshPhysicalMaterial || material.clearcoat === 0 ) return;
2739
+
2740
+ const writer = this.writer;
2741
+ const extensionsUsed = writer.extensionsUsed;
2742
+
2743
+ const extensionDef = {};
2744
+
2745
+ extensionDef.clearcoatFactor = material.clearcoat;
2746
+
2747
+ if ( material.clearcoatMap ) {
2748
+
2749
+ const clearcoatMapDef = {
2750
+ index: await writer.processTextureAsync( material.clearcoatMap ),
2751
+ texCoord: material.clearcoatMap.channel
2752
+ };
2753
+ writer.applyTextureTransform( clearcoatMapDef, material.clearcoatMap );
2754
+ extensionDef.clearcoatTexture = clearcoatMapDef;
2755
+
2756
+ }
2757
+
2758
+ extensionDef.clearcoatRoughnessFactor = material.clearcoatRoughness;
2759
+
2760
+ if ( material.clearcoatRoughnessMap ) {
2761
+
2762
+ const clearcoatRoughnessMapDef = {
2763
+ index: await writer.processTextureAsync( material.clearcoatRoughnessMap ),
2764
+ texCoord: material.clearcoatRoughnessMap.channel
2765
+ };
2766
+ writer.applyTextureTransform( clearcoatRoughnessMapDef, material.clearcoatRoughnessMap );
2767
+ extensionDef.clearcoatRoughnessTexture = clearcoatRoughnessMapDef;
2768
+
2769
+ }
2770
+
2771
+ if ( material.clearcoatNormalMap ) {
2772
+
2773
+ const clearcoatNormalMapDef = {
2774
+ index: await writer.processTextureAsync( material.clearcoatNormalMap ),
2775
+ texCoord: material.clearcoatNormalMap.channel
2776
+ };
2777
+
2778
+ if ( material.clearcoatNormalScale.x !== 1 ) clearcoatNormalMapDef.scale = material.clearcoatNormalScale.x;
2779
+
2780
+ writer.applyTextureTransform( clearcoatNormalMapDef, material.clearcoatNormalMap );
2781
+ extensionDef.clearcoatNormalTexture = clearcoatNormalMapDef;
2782
+
2783
+ }
2784
+
2785
+ materialDef.extensions = materialDef.extensions || {};
2786
+ materialDef.extensions[ this.name ] = extensionDef;
2787
+
2788
+ extensionsUsed[ this.name ] = true;
2789
+
2790
+
2791
+ }
2792
+
2793
+ }
2794
+
2795
+ /**
2796
+ * Materials dispersion Extension
2797
+ *
2798
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_dispersion
2799
+ *
2800
+ * @private
2801
+ */
2802
+ class GLTFMaterialsDispersionExtension {
2803
+
2804
+ constructor( writer ) {
2805
+
2806
+ this.writer = writer;
2807
+ this.name = 'KHR_materials_dispersion';
2808
+
2809
+ }
2810
+
2811
+ async writeMaterialAsync( material, materialDef ) {
2812
+
2813
+ if ( ! material.isMeshPhysicalMaterial || material.dispersion === 0 ) return;
2814
+
2815
+ const writer = this.writer;
2816
+ const extensionsUsed = writer.extensionsUsed;
2817
+
2818
+ const extensionDef = {};
2819
+
2820
+ extensionDef.dispersion = material.dispersion;
2821
+
2822
+ materialDef.extensions = materialDef.extensions || {};
2823
+ materialDef.extensions[ this.name ] = extensionDef;
2824
+
2825
+ extensionsUsed[ this.name ] = true;
2826
+
2827
+ }
2828
+
2829
+ }
2830
+
2831
+ /**
2832
+ * Iridescence Materials Extension
2833
+ *
2834
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_iridescence
2835
+ *
2836
+ * @private
2837
+ */
2838
+ class GLTFMaterialsIridescenceExtension {
2839
+
2840
+ constructor( writer ) {
2841
+
2842
+ this.writer = writer;
2843
+ this.name = 'KHR_materials_iridescence';
2844
+
2845
+ }
2846
+
2847
+ async writeMaterialAsync( material, materialDef ) {
2848
+
2849
+ if ( ! material.isMeshPhysicalMaterial || material.iridescence === 0 ) return;
2850
+
2851
+ const writer = this.writer;
2852
+ const extensionsUsed = writer.extensionsUsed;
2853
+
2854
+ const extensionDef = {};
2855
+
2856
+ extensionDef.iridescenceFactor = material.iridescence;
2857
+
2858
+ if ( material.iridescenceMap ) {
2859
+
2860
+ const iridescenceMapDef = {
2861
+ index: await writer.processTextureAsync( material.iridescenceMap ),
2862
+ texCoord: material.iridescenceMap.channel
2863
+ };
2864
+ writer.applyTextureTransform( iridescenceMapDef, material.iridescenceMap );
2865
+ extensionDef.iridescenceTexture = iridescenceMapDef;
2866
+
2867
+ }
2868
+
2869
+ extensionDef.iridescenceIor = material.iridescenceIOR;
2870
+ extensionDef.iridescenceThicknessMinimum = material.iridescenceThicknessRange[ 0 ];
2871
+ extensionDef.iridescenceThicknessMaximum = material.iridescenceThicknessRange[ 1 ];
2872
+
2873
+ if ( material.iridescenceThicknessMap ) {
2874
+
2875
+ const iridescenceThicknessMapDef = {
2876
+ index: await writer.processTextureAsync( material.iridescenceThicknessMap ),
2877
+ texCoord: material.iridescenceThicknessMap.channel
2878
+ };
2879
+ writer.applyTextureTransform( iridescenceThicknessMapDef, material.iridescenceThicknessMap );
2880
+ extensionDef.iridescenceThicknessTexture = iridescenceThicknessMapDef;
2881
+
2882
+ }
2883
+
2884
+ materialDef.extensions = materialDef.extensions || {};
2885
+ materialDef.extensions[ this.name ] = extensionDef;
2886
+
2887
+ extensionsUsed[ this.name ] = true;
2888
+
2889
+ }
2890
+
2891
+ }
2892
+
2893
+ /**
2894
+ * Transmission Materials Extension
2895
+ *
2896
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission
2897
+ *
2898
+ * @private
2899
+ */
2900
+ class GLTFMaterialsTransmissionExtension {
2901
+
2902
+ constructor( writer ) {
2903
+
2904
+ this.writer = writer;
2905
+ this.name = 'KHR_materials_transmission';
2906
+
2907
+ }
2908
+
2909
+ async writeMaterialAsync( material, materialDef ) {
2910
+
2911
+ if ( ! material.isMeshPhysicalMaterial || material.transmission === 0 ) return;
2912
+
2913
+ const writer = this.writer;
2914
+ const extensionsUsed = writer.extensionsUsed;
2915
+
2916
+ const extensionDef = {};
2917
+
2918
+ extensionDef.transmissionFactor = material.transmission;
2919
+
2920
+ if ( material.transmissionMap ) {
2921
+
2922
+ const transmissionMapDef = {
2923
+ index: await writer.processTextureAsync( material.transmissionMap ),
2924
+ texCoord: material.transmissionMap.channel
2925
+ };
2926
+ writer.applyTextureTransform( transmissionMapDef, material.transmissionMap );
2927
+ extensionDef.transmissionTexture = transmissionMapDef;
2928
+
2929
+ }
2930
+
2931
+ materialDef.extensions = materialDef.extensions || {};
2932
+ materialDef.extensions[ this.name ] = extensionDef;
2933
+
2934
+ extensionsUsed[ this.name ] = true;
2935
+
2936
+ }
2937
+
2938
+ }
2939
+
2940
+ /**
2941
+ * Materials Volume Extension
2942
+ *
2943
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume
2944
+ *
2945
+ * @private
2946
+ */
2947
+ class GLTFMaterialsVolumeExtension {
2948
+
2949
+ constructor( writer ) {
2950
+
2951
+ this.writer = writer;
2952
+ this.name = 'KHR_materials_volume';
2953
+
2954
+ }
2955
+
2956
+ async writeMaterialAsync( material, materialDef ) {
2957
+
2958
+ if ( ! material.isMeshPhysicalMaterial || material.transmission === 0 ) return;
2959
+
2960
+ const writer = this.writer;
2961
+ const extensionsUsed = writer.extensionsUsed;
2962
+
2963
+ const extensionDef = {};
2964
+
2965
+ extensionDef.thicknessFactor = material.thickness;
2966
+
2967
+ if ( material.thicknessMap ) {
2968
+
2969
+ const thicknessMapDef = {
2970
+ index: await writer.processTextureAsync( material.thicknessMap ),
2971
+ texCoord: material.thicknessMap.channel
2972
+ };
2973
+ writer.applyTextureTransform( thicknessMapDef, material.thicknessMap );
2974
+ extensionDef.thicknessTexture = thicknessMapDef;
2975
+
2976
+ }
2977
+
2978
+ if ( material.attenuationDistance !== Infinity ) {
2979
+
2980
+ extensionDef.attenuationDistance = material.attenuationDistance;
2981
+
2982
+ }
2983
+
2984
+ extensionDef.attenuationColor = material.attenuationColor.toArray();
2985
+
2986
+ materialDef.extensions = materialDef.extensions || {};
2987
+ materialDef.extensions[ this.name ] = extensionDef;
2988
+
2989
+ extensionsUsed[ this.name ] = true;
2990
+
2991
+ }
2992
+
2993
+ }
2994
+
2995
+ /**
2996
+ * Materials ior Extension
2997
+ *
2998
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior
2999
+ *
3000
+ * @private
3001
+ */
3002
+ class GLTFMaterialsIorExtension {
3003
+
3004
+ constructor( writer ) {
3005
+
3006
+ this.writer = writer;
3007
+ this.name = 'KHR_materials_ior';
3008
+
3009
+ }
3010
+
3011
+ async writeMaterialAsync( material, materialDef ) {
3012
+
3013
+ if ( ! material.isMeshPhysicalMaterial || material.ior === 1.5 ) return;
3014
+
3015
+ const writer = this.writer;
3016
+ const extensionsUsed = writer.extensionsUsed;
3017
+
3018
+ const extensionDef = {};
3019
+
3020
+ extensionDef.ior = material.ior;
3021
+
3022
+ materialDef.extensions = materialDef.extensions || {};
3023
+ materialDef.extensions[ this.name ] = extensionDef;
3024
+
3025
+ extensionsUsed[ this.name ] = true;
3026
+
3027
+ }
3028
+
3029
+ }
3030
+
3031
+ /**
3032
+ * Materials specular Extension
3033
+ *
3034
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular
3035
+ *
3036
+ * @private
3037
+ */
3038
+ class GLTFMaterialsSpecularExtension {
3039
+
3040
+ constructor( writer ) {
3041
+
3042
+ this.writer = writer;
3043
+ this.name = 'KHR_materials_specular';
3044
+
3045
+ }
3046
+
3047
+ async writeMaterialAsync( material, materialDef ) {
3048
+
3049
+ if ( ! material.isMeshPhysicalMaterial || ( material.specularIntensity === 1.0 &&
3050
+ material.specularColor.equals( DEFAULT_SPECULAR_COLOR ) &&
3051
+ ! material.specularIntensityMap && ! material.specularColorMap ) ) return;
3052
+
3053
+ const writer = this.writer;
3054
+ const extensionsUsed = writer.extensionsUsed;
3055
+
3056
+ const extensionDef = {};
3057
+
3058
+ if ( material.specularIntensityMap ) {
3059
+
3060
+ const specularIntensityMapDef = {
3061
+ index: await writer.processTextureAsync( material.specularIntensityMap ),
3062
+ texCoord: material.specularIntensityMap.channel
3063
+ };
3064
+ writer.applyTextureTransform( specularIntensityMapDef, material.specularIntensityMap );
3065
+ extensionDef.specularTexture = specularIntensityMapDef;
3066
+
3067
+ }
3068
+
3069
+ if ( material.specularColorMap ) {
3070
+
3071
+ const specularColorMapDef = {
3072
+ index: await writer.processTextureAsync( material.specularColorMap ),
3073
+ texCoord: material.specularColorMap.channel
3074
+ };
3075
+ writer.applyTextureTransform( specularColorMapDef, material.specularColorMap );
3076
+ extensionDef.specularColorTexture = specularColorMapDef;
3077
+
3078
+ }
3079
+
3080
+ extensionDef.specularFactor = material.specularIntensity;
3081
+ extensionDef.specularColorFactor = material.specularColor.toArray();
3082
+
3083
+ materialDef.extensions = materialDef.extensions || {};
3084
+ materialDef.extensions[ this.name ] = extensionDef;
3085
+
3086
+ extensionsUsed[ this.name ] = true;
3087
+
3088
+ }
3089
+
3090
+ }
3091
+
3092
+ /**
3093
+ * Sheen Materials Extension
3094
+ *
3095
+ * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
3096
+ *
3097
+ * @private
3098
+ */
3099
+ class GLTFMaterialsSheenExtension {
3100
+
3101
+ constructor( writer ) {
3102
+
3103
+ this.writer = writer;
3104
+ this.name = 'KHR_materials_sheen';
3105
+
3106
+ }
3107
+
3108
+ async writeMaterialAsync( material, materialDef ) {
3109
+
3110
+ if ( ! material.isMeshPhysicalMaterial || material.sheen == 0.0 ) return;
3111
+
3112
+ const writer = this.writer;
3113
+ const extensionsUsed = writer.extensionsUsed;
3114
+
3115
+ const extensionDef = {};
3116
+
3117
+ if ( material.sheenRoughnessMap ) {
3118
+
3119
+ const sheenRoughnessMapDef = {
3120
+ index: await writer.processTextureAsync( material.sheenRoughnessMap ),
3121
+ texCoord: material.sheenRoughnessMap.channel
3122
+ };
3123
+ writer.applyTextureTransform( sheenRoughnessMapDef, material.sheenRoughnessMap );
3124
+ extensionDef.sheenRoughnessTexture = sheenRoughnessMapDef;
3125
+
3126
+ }
3127
+
3128
+ if ( material.sheenColorMap ) {
3129
+
3130
+ const sheenColorMapDef = {
3131
+ index: await writer.processTextureAsync( material.sheenColorMap ),
3132
+ texCoord: material.sheenColorMap.channel
3133
+ };
3134
+ writer.applyTextureTransform( sheenColorMapDef, material.sheenColorMap );
3135
+ extensionDef.sheenColorTexture = sheenColorMapDef;
3136
+
3137
+ }
3138
+
3139
+ extensionDef.sheenRoughnessFactor = material.sheenRoughness;
3140
+ extensionDef.sheenColorFactor = material.sheenColor.toArray();
3141
+
3142
+ materialDef.extensions = materialDef.extensions || {};
3143
+ materialDef.extensions[ this.name ] = extensionDef;
3144
+
3145
+ extensionsUsed[ this.name ] = true;
3146
+
3147
+ }
3148
+
3149
+ }
3150
+
3151
+ /**
3152
+ * Anisotropy Materials Extension
3153
+ *
3154
+ * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_anisotropy
3155
+ *
3156
+ * @private
3157
+ */
3158
+ class GLTFMaterialsAnisotropyExtension {
3159
+
3160
+ constructor( writer ) {
3161
+
3162
+ this.writer = writer;
3163
+ this.name = 'KHR_materials_anisotropy';
3164
+
3165
+ }
3166
+
3167
+ async writeMaterialAsync( material, materialDef ) {
3168
+
3169
+ if ( ! material.isMeshPhysicalMaterial || material.anisotropy == 0.0 ) return;
3170
+
3171
+ const writer = this.writer;
3172
+ const extensionsUsed = writer.extensionsUsed;
3173
+
3174
+ const extensionDef = {};
3175
+
3176
+ if ( material.anisotropyMap ) {
3177
+
3178
+ const anisotropyMapDef = { index: await writer.processTextureAsync( material.anisotropyMap ) };
3179
+ writer.applyTextureTransform( anisotropyMapDef, material.anisotropyMap );
3180
+ extensionDef.anisotropyTexture = anisotropyMapDef;
3181
+
3182
+ }
3183
+
3184
+ extensionDef.anisotropyStrength = material.anisotropy;
3185
+ extensionDef.anisotropyRotation = material.anisotropyRotation;
3186
+
3187
+ materialDef.extensions = materialDef.extensions || {};
3188
+ materialDef.extensions[ this.name ] = extensionDef;
3189
+
3190
+ extensionsUsed[ this.name ] = true;
3191
+
3192
+ }
3193
+
3194
+ }
3195
+
3196
+ /**
3197
+ * Materials Emissive Strength Extension
3198
+ *
3199
+ * Specification: https://github.com/KhronosGroup/glTF/blob/5768b3ce0ef32bc39cdf1bef10b948586635ead3/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md
3200
+ *
3201
+ * @private
3202
+ */
3203
+ class GLTFMaterialsEmissiveStrengthExtension {
3204
+
3205
+ constructor( writer ) {
3206
+
3207
+ this.writer = writer;
3208
+ this.name = 'KHR_materials_emissive_strength';
3209
+
3210
+ }
3211
+
3212
+ async writeMaterialAsync( material, materialDef ) {
3213
+
3214
+ if ( ! material.isMeshStandardMaterial || material.emissiveIntensity === 1.0 ) return;
3215
+
3216
+ const writer = this.writer;
3217
+ const extensionsUsed = writer.extensionsUsed;
3218
+
3219
+ const extensionDef = {};
3220
+
3221
+ extensionDef.emissiveStrength = material.emissiveIntensity;
3222
+
3223
+ materialDef.extensions = materialDef.extensions || {};
3224
+ materialDef.extensions[ this.name ] = extensionDef;
3225
+
3226
+ extensionsUsed[ this.name ] = true;
3227
+
3228
+ }
3229
+
3230
+ }
3231
+
3232
+
3233
+ /**
3234
+ * Materials bump Extension
3235
+ *
3236
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_materials_bump
3237
+ *
3238
+ * @private
3239
+ */
3240
+ class GLTFMaterialsBumpExtension {
3241
+
3242
+ constructor( writer ) {
3243
+
3244
+ this.writer = writer;
3245
+ this.name = 'EXT_materials_bump';
3246
+
3247
+ }
3248
+
3249
+ async writeMaterialAsync( material, materialDef ) {
3250
+
3251
+ if ( ! material.isMeshStandardMaterial || (
3252
+ material.bumpScale === 1 &&
3253
+ ! material.bumpMap ) ) return;
3254
+
3255
+ const writer = this.writer;
3256
+ const extensionsUsed = writer.extensionsUsed;
3257
+
3258
+ const extensionDef = {};
3259
+
3260
+ if ( material.bumpMap ) {
3261
+
3262
+ const bumpMapDef = {
3263
+ index: await writer.processTextureAsync( material.bumpMap ),
3264
+ texCoord: material.bumpMap.channel
3265
+ };
3266
+ writer.applyTextureTransform( bumpMapDef, material.bumpMap );
3267
+ extensionDef.bumpTexture = bumpMapDef;
3268
+
3269
+ }
3270
+
3271
+ extensionDef.bumpFactor = material.bumpScale;
3272
+
3273
+ materialDef.extensions = materialDef.extensions || {};
3274
+ materialDef.extensions[ this.name ] = extensionDef;
3275
+
3276
+ extensionsUsed[ this.name ] = true;
3277
+
3278
+ }
3279
+
3280
+ }
3281
+
3282
+ /**
3283
+ * GPU Instancing Extension
3284
+ *
3285
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_mesh_gpu_instancing
3286
+ *
3287
+ * @private
3288
+ */
3289
+ class GLTFMeshGpuInstancing {
3290
+
3291
+ constructor( writer ) {
3292
+
3293
+ this.writer = writer;
3294
+ this.name = 'EXT_mesh_gpu_instancing';
3295
+
3296
+ }
3297
+
3298
+ writeNode( object, nodeDef ) {
3299
+
3300
+ if ( ! object.isInstancedMesh ) return;
3301
+
3302
+ const writer = this.writer;
3303
+
3304
+ const mesh = object;
3305
+
3306
+ const translationAttr = new Float32Array( mesh.count * 3 );
3307
+ const rotationAttr = new Float32Array( mesh.count * 4 );
3308
+ const scaleAttr = new Float32Array( mesh.count * 3 );
3309
+
3310
+ const matrix = new Matrix4();
3311
+ const position = new Vector3();
3312
+ const quaternion = new Quaternion();
3313
+ const scale = new Vector3();
3314
+
3315
+ for ( let i = 0; i < mesh.count; i ++ ) {
3316
+
3317
+ mesh.getMatrixAt( i, matrix );
3318
+ matrix.decompose( position, quaternion, scale );
3319
+
3320
+ position.toArray( translationAttr, i * 3 );
3321
+ quaternion.toArray( rotationAttr, i * 4 );
3322
+ scale.toArray( scaleAttr, i * 3 );
3323
+
3324
+ }
3325
+
3326
+ const attributes = {
3327
+ TRANSLATION: writer.processAccessor( new BufferAttribute( translationAttr, 3 ) ),
3328
+ ROTATION: writer.processAccessor( new BufferAttribute( rotationAttr, 4 ) ),
3329
+ SCALE: writer.processAccessor( new BufferAttribute( scaleAttr, 3 ) ),
3330
+ };
3331
+
3332
+ if ( mesh.instanceColor )
3333
+ attributes._COLOR_0 = writer.processAccessor( mesh.instanceColor );
3334
+
3335
+ nodeDef.extensions = nodeDef.extensions || {};
3336
+ nodeDef.extensions[ this.name ] = { attributes };
3337
+
3338
+ writer.extensionsUsed[ this.name ] = true;
3339
+ writer.extensionsRequired[ this.name ] = true;
3340
+
3341
+ }
3342
+
3343
+ }
3344
+
3345
+ /**
3346
+ * Static utility functions
3347
+ *
3348
+ * @private
3349
+ */
3350
+ GLTFExporter.Utils = {
3351
+
3352
+ insertKeyframe: function ( track, time ) {
3353
+
3354
+ const tolerance = 0.001; // 1ms
3355
+ const valueSize = track.getValueSize();
3356
+
3357
+ const times = new track.TimeBufferType( track.times.length + 1 );
3358
+ const values = new track.ValueBufferType( track.values.length + valueSize );
3359
+ const interpolant = track.createInterpolant( new track.ValueBufferType( valueSize ) );
3360
+
3361
+ let index;
3362
+
3363
+ if ( track.times.length === 0 ) {
3364
+
3365
+ times[ 0 ] = time;
3366
+
3367
+ for ( let i = 0; i < valueSize; i ++ ) {
3368
+
3369
+ values[ i ] = 0;
3370
+
3371
+ }
3372
+
3373
+ index = 0;
3374
+
3375
+ } else if ( time < track.times[ 0 ] ) {
3376
+
3377
+ if ( Math.abs( track.times[ 0 ] - time ) < tolerance ) return 0;
3378
+
3379
+ times[ 0 ] = time;
3380
+ times.set( track.times, 1 );
3381
+
3382
+ values.set( interpolant.evaluate( time ), 0 );
3383
+ values.set( track.values, valueSize );
3384
+
3385
+ index = 0;
3386
+
3387
+ } else if ( time > track.times[ track.times.length - 1 ] ) {
3388
+
3389
+ if ( Math.abs( track.times[ track.times.length - 1 ] - time ) < tolerance ) {
3390
+
3391
+ return track.times.length - 1;
3392
+
3393
+ }
3394
+
3395
+ times[ times.length - 1 ] = time;
3396
+ times.set( track.times, 0 );
3397
+
3398
+ values.set( track.values, 0 );
3399
+ values.set( interpolant.evaluate( time ), track.values.length );
3400
+
3401
+ index = times.length - 1;
3402
+
3403
+ } else {
3404
+
3405
+ for ( let i = 0; i < track.times.length; i ++ ) {
3406
+
3407
+ if ( Math.abs( track.times[ i ] - time ) < tolerance ) return i;
3408
+
3409
+ if ( track.times[ i ] < time && track.times[ i + 1 ] > time ) {
3410
+
3411
+ times.set( track.times.slice( 0, i + 1 ), 0 );
3412
+ times[ i + 1 ] = time;
3413
+ times.set( track.times.slice( i + 1 ), i + 2 );
3414
+
3415
+ values.set( track.values.slice( 0, ( i + 1 ) * valueSize ), 0 );
3416
+ values.set( interpolant.evaluate( time ), ( i + 1 ) * valueSize );
3417
+ values.set( track.values.slice( ( i + 1 ) * valueSize ), ( i + 2 ) * valueSize );
3418
+
3419
+ index = i + 1;
3420
+
3421
+ break;
3422
+
3423
+ }
3424
+
3425
+ }
3426
+
3427
+ }
3428
+
3429
+ track.times = times;
3430
+ track.values = values;
3431
+
3432
+ return index;
3433
+
3434
+ },
3435
+
3436
+ mergeMorphTargetTracks: function ( clip, root ) {
3437
+
3438
+ const tracks = [];
3439
+ const mergedTracks = {};
3440
+ const sourceTracks = clip.tracks;
3441
+
3442
+ for ( let i = 0; i < sourceTracks.length; ++ i ) {
3443
+
3444
+ let sourceTrack = sourceTracks[ i ];
3445
+ const sourceTrackBinding = PropertyBinding.parseTrackName( sourceTrack.name );
3446
+ const sourceTrackNode = PropertyBinding.findNode( root, sourceTrackBinding.nodeName );
3447
+
3448
+ if ( sourceTrackBinding.propertyName !== 'morphTargetInfluences' || sourceTrackBinding.propertyIndex === undefined ) {
3449
+
3450
+ // Tracks that don't affect morph targets, or that affect all morph targets together, can be left as-is.
3451
+ tracks.push( sourceTrack );
3452
+ continue;
3453
+
3454
+ }
3455
+
3456
+ if ( sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodDiscrete
3457
+ && sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodLinear ) {
3458
+
3459
+ if ( sourceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
3460
+
3461
+ // This should never happen, because glTF morph target animations
3462
+ // affect all targets already.
3463
+ throw new Error( 'THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.' );
3464
+
3465
+ }
3466
+
3467
+ console.warn( 'THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead.' );
3468
+
3469
+ sourceTrack = sourceTrack.clone();
3470
+ sourceTrack.setInterpolation( InterpolateLinear );
3471
+
3472
+ }
3473
+
3474
+ const targetCount = sourceTrackNode.morphTargetInfluences.length;
3475
+ const targetIndex = sourceTrackNode.morphTargetDictionary[ sourceTrackBinding.propertyIndex ];
3476
+
3477
+ if ( targetIndex === undefined ) {
3478
+
3479
+ throw new Error( 'THREE.GLTFExporter: Morph target name not found: ' + sourceTrackBinding.propertyIndex );
3480
+
3481
+ }
3482
+
3483
+ let mergedTrack;
3484
+
3485
+ // If this is the first time we've seen this object, create a new
3486
+ // track to store merged keyframe data for each morph target.
3487
+ if ( mergedTracks[ sourceTrackNode.uuid ] === undefined ) {
3488
+
3489
+ mergedTrack = sourceTrack.clone();
3490
+
3491
+ const values = new mergedTrack.ValueBufferType( targetCount * mergedTrack.times.length );
3492
+
3493
+ for ( let j = 0; j < mergedTrack.times.length; j ++ ) {
3494
+
3495
+ values[ j * targetCount + targetIndex ] = mergedTrack.values[ j ];
3496
+
3497
+ }
3498
+
3499
+ // We need to take into consideration the intended target node
3500
+ // of our original un-merged morphTarget animation.
3501
+ mergedTrack.name = ( sourceTrackBinding.nodeName || '' ) + '.morphTargetInfluences';
3502
+ mergedTrack.values = values;
3503
+
3504
+ mergedTracks[ sourceTrackNode.uuid ] = mergedTrack;
3505
+ tracks.push( mergedTrack );
3506
+
3507
+ continue;
3508
+
3509
+ }
3510
+
3511
+ const sourceInterpolant = sourceTrack.createInterpolant( new sourceTrack.ValueBufferType( 1 ) );
3512
+
3513
+ mergedTrack = mergedTracks[ sourceTrackNode.uuid ];
3514
+
3515
+ // For every existing keyframe of the merged track, write a (possibly
3516
+ // interpolated) value from the source track.
3517
+ for ( let j = 0; j < mergedTrack.times.length; j ++ ) {
3518
+
3519
+ mergedTrack.values[ j * targetCount + targetIndex ] = sourceInterpolant.evaluate( mergedTrack.times[ j ] );
3520
+
3521
+ }
3522
+
3523
+ // For every existing keyframe of the source track, write a (possibly
3524
+ // new) keyframe to the merged track. Values from the previous loop may
3525
+ // be written again, but keyframes are de-duplicated.
3526
+ for ( let j = 0; j < sourceTrack.times.length; j ++ ) {
3527
+
3528
+ const keyframeIndex = this.insertKeyframe( mergedTrack, sourceTrack.times[ j ] );
3529
+ mergedTrack.values[ keyframeIndex * targetCount + targetIndex ] = sourceTrack.values[ j ];
3530
+
3531
+ }
3532
+
3533
+ }
3534
+
3535
+ clip.tracks = tracks;
3536
+
3537
+ return clip;
3538
+
3539
+ },
3540
+
3541
+ toFloat32BufferAttribute: function ( srcAttribute ) {
3542
+
3543
+ const dstAttribute = new BufferAttribute( new Float32Array( srcAttribute.count * srcAttribute.itemSize ), srcAttribute.itemSize, false );
3544
+
3545
+ if ( ! srcAttribute.normalized && ! srcAttribute.isInterleavedBufferAttribute ) {
3546
+
3547
+ dstAttribute.array.set( srcAttribute.array );
3548
+
3549
+ return dstAttribute;
3550
+
3551
+ }
3552
+
3553
+ for ( let i = 0, il = srcAttribute.count; i < il; i ++ ) {
3554
+
3555
+ for ( let j = 0; j < srcAttribute.itemSize; j ++ ) {
3556
+
3557
+ dstAttribute.setComponent( i, j, srcAttribute.getComponent( i, j ) );
3558
+
3559
+ }
3560
+
3561
+ }
3562
+
3563
+ return dstAttribute;
3564
+
3565
+ }
3566
+
3567
+ };
3568
+
3569
+ /**
3570
+ * Export options of `GLTFExporter`.
3571
+ *
3572
+ * @typedef {Object} GLTFExporter~Options
3573
+ * @property {boolean} [trs=false] - Export position, rotation and scale instead of matrix per node.
3574
+ * @property {boolean} [onlyVisible=true] - Export only visible 3D objects.
3575
+ * @property {boolean} [binary=false] - Export in binary (.glb) format, returning an ArrayBuffer.
3576
+ * @property {number} [maxTextureSize=Infinity] - Restricts the image maximum size (both width and height) to the given value.
3577
+ * @property {Array<AnimationClip>} [animations=[]] - List of animations to be included in the export.
3578
+ * @property {boolean} [includeCustomExtensions=false] - Export custom glTF extensions defined on an object's `userData.gltfExtensions` property.
3579
+ **/
3580
+
3581
+ /**
3582
+ * onDone callback of `GLTFExporter`.
3583
+ *
3584
+ * @callback GLTFExporter~OnDone
3585
+ * @param {ArrayBuffer|string} result - The generated .gltf (JSON) or .glb (binary).
3586
+ */
3587
+
3588
+ /**
3589
+ * onError callback of `GLTFExporter`.
3590
+ *
3591
+ * @callback GLTFExporter~OnError
3592
+ * @param {Error} error - The error object.
3593
+ */
3594
+
3595
+ export { GLTFExporter };