@plastic-software/three 0.167.0

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