three-stdlib 2.25.0 → 2.25.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (539) hide show
  1. package/index.cjs +116401 -611
  2. package/index.js +116037 -263
  3. package/package.json +17 -4
  4. package/_polyfill/CapsuleGeometry.cjs +0 -22
  5. package/_polyfill/CapsuleGeometry.js +0 -22
  6. package/_polyfill/CompressedArrayTexture.cjs +0 -12
  7. package/_polyfill/CompressedArrayTexture.js +0 -12
  8. package/_polyfill/Data3DTexture.cjs +0 -17
  9. package/_polyfill/Data3DTexture.js +0 -17
  10. package/animation/AnimationClipCreator.cjs +0 -56
  11. package/animation/AnimationClipCreator.js +0 -56
  12. package/animation/CCDIKSolver.cjs +0 -269
  13. package/animation/CCDIKSolver.js +0 -269
  14. package/animation/MMDAnimationHelper.cjs +0 -688
  15. package/animation/MMDAnimationHelper.js +0 -688
  16. package/animation/MMDPhysics.cjs +0 -830
  17. package/animation/MMDPhysics.js +0 -830
  18. package/cameras/CinematicCamera.cjs +0 -131
  19. package/cameras/CinematicCamera.js +0 -131
  20. package/controls/ArcballControls.cjs +0 -2033
  21. package/controls/ArcballControls.js +0 -2033
  22. package/controls/DeviceOrientationControls.cjs +0 -85
  23. package/controls/DeviceOrientationControls.js +0 -85
  24. package/controls/DragControls.cjs +0 -182
  25. package/controls/DragControls.js +0 -182
  26. package/controls/FirstPersonControls.cjs +0 -229
  27. package/controls/FirstPersonControls.js +0 -229
  28. package/controls/FlyControls.cjs +0 -248
  29. package/controls/FlyControls.js +0 -248
  30. package/controls/OrbitControls.cjs +0 -791
  31. package/controls/OrbitControls.js +0 -791
  32. package/controls/PointerLockControls.cjs +0 -103
  33. package/controls/PointerLockControls.js +0 -103
  34. package/controls/TrackballControls.cjs +0 -502
  35. package/controls/TrackballControls.js +0 -502
  36. package/controls/TransformControls.cjs +0 -1089
  37. package/controls/TransformControls.js +0 -1089
  38. package/controls/experimental/CameraControls.cjs +0 -736
  39. package/controls/experimental/CameraControls.js +0 -736
  40. package/csm/CSM.cjs +0 -244
  41. package/csm/CSM.js +0 -244
  42. package/csm/CSMFrustum.cjs +0 -75
  43. package/csm/CSMFrustum.js +0 -75
  44. package/csm/CSMHelper.cjs +0 -114
  45. package/csm/CSMHelper.js +0 -114
  46. package/csm/CSMShader.cjs +0 -261
  47. package/csm/CSMShader.js +0 -261
  48. package/curves/CurveExtras.cjs +0 -214
  49. package/curves/CurveExtras.js +0 -214
  50. package/curves/NURBSCurve.cjs +0 -35
  51. package/curves/NURBSCurve.js +0 -35
  52. package/curves/NURBSSurface.cjs +0 -28
  53. package/curves/NURBSSurface.js +0 -28
  54. package/curves/NURBSUtils.cjs +0 -226
  55. package/curves/NURBSUtils.js +0 -226
  56. package/deprecated/Geometry.cjs +0 -971
  57. package/deprecated/Geometry.js +0 -971
  58. package/effects/AnaglyphEffect.cjs +0 -102
  59. package/effects/AnaglyphEffect.js +0 -102
  60. package/effects/AsciiEffect.cjs +0 -155
  61. package/effects/AsciiEffect.js +0 -155
  62. package/effects/OutlineEffect.cjs +0 -275
  63. package/effects/OutlineEffect.js +0 -275
  64. package/effects/ParallaxBarrierEffect.cjs +0 -65
  65. package/effects/ParallaxBarrierEffect.js +0 -65
  66. package/effects/PeppersGhostEffect.cjs +0 -88
  67. package/effects/PeppersGhostEffect.js +0 -88
  68. package/effects/StereoEffect.cjs +0 -35
  69. package/effects/StereoEffect.js +0 -35
  70. package/environments/RoomEnvironment.cjs +0 -95
  71. package/environments/RoomEnvironment.js +0 -78
  72. package/exporters/ColladaExporter.cjs +0 -331
  73. package/exporters/ColladaExporter.js +0 -331
  74. package/exporters/DRACOExporter.cjs +0 -141
  75. package/exporters/DRACOExporter.js +0 -141
  76. package/exporters/GLTFExporter.cjs +0 -1909
  77. package/exporters/GLTFExporter.js +0 -1909
  78. package/exporters/MMDExporter.cjs +0 -131
  79. package/exporters/MMDExporter.js +0 -131
  80. package/exporters/OBJExporter.cjs +0 -181
  81. package/exporters/OBJExporter.js +0 -181
  82. package/exporters/PLYExporter.cjs +0 -280
  83. package/exporters/PLYExporter.js +0 -280
  84. package/exporters/STLExporter.cjs +0 -146
  85. package/exporters/STLExporter.js +0 -146
  86. package/exporters/USDZExporter.cjs +0 -340
  87. package/exporters/USDZExporter.js +0 -340
  88. package/geometries/BoxLineGeometry.cjs +0 -45
  89. package/geometries/BoxLineGeometry.js +0 -45
  90. package/geometries/ConvexGeometry.cjs +0 -26
  91. package/geometries/ConvexGeometry.js +0 -26
  92. package/geometries/DecalGeometry.cjs +0 -184
  93. package/geometries/DecalGeometry.js +0 -184
  94. package/geometries/LightningStrike.cjs +0 -553
  95. package/geometries/LightningStrike.js +0 -553
  96. package/geometries/ParametricGeometries.cjs +0 -130
  97. package/geometries/ParametricGeometries.js +0 -130
  98. package/geometries/ParametricGeometry.cjs +0 -63
  99. package/geometries/ParametricGeometry.js +0 -63
  100. package/geometries/RoundedBoxGeometry.cjs +0 -91
  101. package/geometries/RoundedBoxGeometry.js +0 -91
  102. package/geometries/TeapotGeometry.cjs +0 -1563
  103. package/geometries/TeapotGeometry.js +0 -1563
  104. package/geometries/TextGeometry.cjs +0 -27
  105. package/geometries/TextGeometry.js +0 -27
  106. package/helpers/LightProbeHelper.cjs +0 -73
  107. package/helpers/LightProbeHelper.js +0 -73
  108. package/helpers/PositionalAudioHelper.cjs +0 -68
  109. package/helpers/PositionalAudioHelper.js +0 -68
  110. package/helpers/RectAreaLightHelper.cjs +0 -44
  111. package/helpers/RectAreaLightHelper.js +0 -44
  112. package/helpers/VertexNormalsHelper.cjs +0 -47
  113. package/helpers/VertexNormalsHelper.js +0 -47
  114. package/helpers/VertexTangentsHelper.cjs +0 -43
  115. package/helpers/VertexTangentsHelper.js +0 -43
  116. package/interactive/HTMLMesh.cjs +0 -325
  117. package/interactive/HTMLMesh.js +0 -325
  118. package/interactive/InteractiveGroup.cjs +0 -68
  119. package/interactive/InteractiveGroup.js +0 -68
  120. package/interactive/SelectionBox.cjs +0 -134
  121. package/interactive/SelectionBox.js +0 -134
  122. package/interactive/SelectionHelper.cjs +0 -51
  123. package/interactive/SelectionHelper.js +0 -51
  124. package/libs/MeshoptDecoder.cjs +0 -221
  125. package/libs/MeshoptDecoder.js +0 -221
  126. package/libs/MotionControllers.cjs +0 -325
  127. package/libs/MotionControllers.js +0 -325
  128. package/lights/LightProbeGenerator.cjs +0 -145
  129. package/lights/LightProbeGenerator.js +0 -145
  130. package/lights/RectAreaLightUniformsLib.cjs +0 -32846
  131. package/lights/RectAreaLightUniformsLib.js +0 -32846
  132. package/lines/Line2.cjs +0 -13
  133. package/lines/Line2.js +0 -13
  134. package/lines/LineGeometry.cjs +0 -44
  135. package/lines/LineGeometry.js +0 -44
  136. package/lines/LineMaterial.cjs +0 -547
  137. package/lines/LineMaterial.js +0 -547
  138. package/lines/LineSegments2.cjs +0 -203
  139. package/lines/LineSegments2.js +0 -203
  140. package/lines/LineSegmentsGeometry.cjs +0 -124
  141. package/lines/LineSegmentsGeometry.js +0 -124
  142. package/lines/Wireframe.cjs +0 -32
  143. package/lines/Wireframe.js +0 -32
  144. package/lines/WireframeGeometry2.cjs +0 -13
  145. package/lines/WireframeGeometry2.js +0 -13
  146. package/loaders/3DMLoader.cjs +0 -803
  147. package/loaders/3DMLoader.js +0 -803
  148. package/loaders/3MFLoader.cjs +0 -854
  149. package/loaders/3MFLoader.js +0 -854
  150. package/loaders/AMFLoader.cjs +0 -284
  151. package/loaders/AMFLoader.js +0 -284
  152. package/loaders/AssimpLoader.cjs +0 -1434
  153. package/loaders/AssimpLoader.js +0 -1434
  154. package/loaders/BVHLoader.cjs +0 -207
  155. package/loaders/BVHLoader.js +0 -207
  156. package/loaders/BasisTextureLoader.cjs +0 -489
  157. package/loaders/BasisTextureLoader.js +0 -489
  158. package/loaders/ColladaLoader.cjs +0 -2405
  159. package/loaders/ColladaLoader.js +0 -2405
  160. package/loaders/DDSLoader.cjs +0 -148
  161. package/loaders/DDSLoader.js +0 -148
  162. package/loaders/DRACOLoader.cjs +0 -341
  163. package/loaders/DRACOLoader.js +0 -341
  164. package/loaders/EXRLoader.cjs +0 -1356
  165. package/loaders/EXRLoader.js +0 -1356
  166. package/loaders/FBXLoader.cjs +0 -2457
  167. package/loaders/FBXLoader.js +0 -2457
  168. package/loaders/FontLoader.cjs +0 -123
  169. package/loaders/FontLoader.js +0 -123
  170. package/loaders/GCodeLoader.cjs +0 -141
  171. package/loaders/GCodeLoader.js +0 -141
  172. package/loaders/GLTFLoader.cjs +0 -2504
  173. package/loaders/GLTFLoader.js +0 -2504
  174. package/loaders/HDRCubeTextureLoader.cjs +0 -75
  175. package/loaders/HDRCubeTextureLoader.js +0 -75
  176. package/loaders/KMZLoader.cjs +0 -75
  177. package/loaders/KMZLoader.js +0 -75
  178. package/loaders/KTX2Loader.cjs +0 -480
  179. package/loaders/KTX2Loader.js +0 -480
  180. package/loaders/KTXLoader.cjs +0 -93
  181. package/loaders/KTXLoader.js +0 -93
  182. package/loaders/LDrawLoader.cjs +0 -1424
  183. package/loaders/LDrawLoader.js +0 -1424
  184. package/loaders/LUT3dlLoader.cjs +0 -103
  185. package/loaders/LUT3dlLoader.js +0 -103
  186. package/loaders/LUTCubeLoader.cjs +0 -107
  187. package/loaders/LUTCubeLoader.js +0 -107
  188. package/loaders/LWOLoader.cjs +0 -645
  189. package/loaders/LWOLoader.js +0 -645
  190. package/loaders/LottieLoader.cjs +0 -47
  191. package/loaders/LottieLoader.js +0 -47
  192. package/loaders/MD2Loader.cjs +0 -359
  193. package/loaders/MD2Loader.js +0 -359
  194. package/loaders/MDDLoader.cjs +0 -58
  195. package/loaders/MDDLoader.js +0 -58
  196. package/loaders/MMDLoader.cjs +0 -1121
  197. package/loaders/MMDLoader.js +0 -1121
  198. package/loaders/MTLLoader.cjs +0 -304
  199. package/loaders/MTLLoader.js +0 -304
  200. package/loaders/NRRDLoader.cjs +0 -401
  201. package/loaders/NRRDLoader.js +0 -401
  202. package/loaders/OBJLoader.cjs +0 -487
  203. package/loaders/OBJLoader.js +0 -487
  204. package/loaders/PCDLoader.cjs +0 -248
  205. package/loaders/PCDLoader.js +0 -248
  206. package/loaders/PDBLoader.cjs +0 -247
  207. package/loaders/PDBLoader.js +0 -247
  208. package/loaders/PLYLoader.cjs +0 -317
  209. package/loaders/PLYLoader.js +0 -317
  210. package/loaders/PRWMLoader.cjs +0 -160
  211. package/loaders/PRWMLoader.js +0 -160
  212. package/loaders/PVRLoader.cjs +0 -131
  213. package/loaders/PVRLoader.js +0 -131
  214. package/loaders/RGBELoader.cjs +0 -252
  215. package/loaders/RGBELoader.js +0 -252
  216. package/loaders/RGBMLoader.cjs +0 -1004
  217. package/loaders/RGBMLoader.js +0 -1004
  218. package/loaders/STLLoader.cjs +0 -190
  219. package/loaders/STLLoader.js +0 -190
  220. package/loaders/SVGLoader.cjs +0 -1712
  221. package/loaders/SVGLoader.js +0 -1712
  222. package/loaders/TDSLoader.cjs +0 -650
  223. package/loaders/TDSLoader.js +0 -650
  224. package/loaders/TGALoader.cjs +0 -285
  225. package/loaders/TGALoader.js +0 -285
  226. package/loaders/TTFLoader.cjs +0 -131
  227. package/loaders/TTFLoader.js +0 -131
  228. package/loaders/TiltLoader.cjs +0 -375
  229. package/loaders/TiltLoader.js +0 -375
  230. package/loaders/VOXLoader.cjs +0 -432
  231. package/loaders/VOXLoader.js +0 -432
  232. package/loaders/VRMLLoader.cjs +0 -2105
  233. package/loaders/VRMLLoader.js +0 -2105
  234. package/loaders/VRMLoader.cjs +0 -38
  235. package/loaders/VRMLoader.js +0 -38
  236. package/loaders/VTKLoader.cjs +0 -648
  237. package/loaders/VTKLoader.js +0 -648
  238. package/loaders/XLoader.cjs +0 -1258
  239. package/loaders/XLoader.js +0 -1258
  240. package/loaders/XYZLoader.cjs +0 -60
  241. package/loaders/XYZLoader.js +0 -60
  242. package/loaders/lwo/IFFParser.cjs +0 -743
  243. package/loaders/lwo/IFFParser.js +0 -743
  244. package/loaders/lwo/LWO2Parser.cjs +0 -312
  245. package/loaders/lwo/LWO2Parser.js +0 -312
  246. package/loaders/lwo/LWO3Parser.cjs +0 -282
  247. package/loaders/lwo/LWO3Parser.js +0 -282
  248. package/math/Capsule.cjs +0 -98
  249. package/math/Capsule.js +0 -98
  250. package/math/ColorConverter.cjs +0 -42
  251. package/math/ColorConverter.js +0 -42
  252. package/math/ConvexHull.cjs +0 -596
  253. package/math/ConvexHull.js +0 -596
  254. package/math/ImprovedNoise.cjs +0 -304
  255. package/math/ImprovedNoise.js +0 -304
  256. package/math/Lut.cjs +0 -137
  257. package/math/Lut.js +0 -137
  258. package/math/MeshSurfaceSampler.cjs +0 -103
  259. package/math/MeshSurfaceSampler.js +0 -103
  260. package/math/OBB.cjs +0 -242
  261. package/math/OBB.js +0 -242
  262. package/math/Octree.cjs +0 -273
  263. package/math/Octree.js +0 -273
  264. package/math/SimplexNoise.cjs +0 -440
  265. package/math/SimplexNoise.js +0 -440
  266. package/misc/ConvexObjectBreaker.cjs +0 -292
  267. package/misc/ConvexObjectBreaker.js +0 -292
  268. package/misc/GPUComputationRenderer.cjs +0 -205
  269. package/misc/GPUComputationRenderer.js +0 -205
  270. package/misc/Gyroscope.cjs +0 -33
  271. package/misc/Gyroscope.js +0 -33
  272. package/misc/MD2Character.cjs +0 -167
  273. package/misc/MD2Character.js +0 -167
  274. package/misc/MD2CharacterComplex.cjs +0 -332
  275. package/misc/MD2CharacterComplex.js +0 -332
  276. package/misc/MorphAnimMesh.cjs +0 -40
  277. package/misc/MorphAnimMesh.js +0 -40
  278. package/misc/MorphBlendMesh.cjs +0 -179
  279. package/misc/MorphBlendMesh.js +0 -179
  280. package/misc/ProgressiveLightmap.cjs +0 -186
  281. package/misc/ProgressiveLightmap.js +0 -186
  282. package/misc/RollerCoaster.cjs +0 -353
  283. package/misc/RollerCoaster.js +0 -353
  284. package/misc/Timer.cjs +0 -101
  285. package/misc/Timer.js +0 -101
  286. package/misc/TubePainter.cjs +0 -123
  287. package/misc/TubePainter.js +0 -123
  288. package/misc/Volume.cjs +0 -305
  289. package/misc/Volume.js +0 -305
  290. package/misc/VolumeSlice.cjs +0 -114
  291. package/misc/VolumeSlice.js +0 -114
  292. package/misc/WebGL.cjs +0 -74
  293. package/misc/WebGL.js +0 -74
  294. package/modifiers/CurveModifier.cjs +0 -232
  295. package/modifiers/CurveModifier.js +0 -232
  296. package/modifiers/EdgeSplitModifier.cjs +0 -167
  297. package/modifiers/EdgeSplitModifier.js +0 -168
  298. package/modifiers/SimplifyModifier.cjs +0 -301
  299. package/modifiers/SimplifyModifier.js +0 -301
  300. package/modifiers/TessellateModifier.cjs +0 -214
  301. package/modifiers/TessellateModifier.js +0 -214
  302. package/objects/GroundProjectedEnv.cjs +0 -134
  303. package/objects/GroundProjectedEnv.js +0 -134
  304. package/objects/Lensflare.cjs +0 -291
  305. package/objects/Lensflare.js +0 -291
  306. package/objects/LightningStorm.cjs +0 -110
  307. package/objects/LightningStorm.js +0 -110
  308. package/objects/MarchingCubes.cjs +0 -4809
  309. package/objects/MarchingCubes.js +0 -4809
  310. package/objects/Reflector.cjs +0 -202
  311. package/objects/Reflector.js +0 -202
  312. package/objects/ReflectorForSSRPass.cjs +0 -260
  313. package/objects/ReflectorForSSRPass.js +0 -260
  314. package/objects/ReflectorRTT.cjs +0 -10
  315. package/objects/ReflectorRTT.js +0 -10
  316. package/objects/Refractor.cjs +0 -215
  317. package/objects/Refractor.js +0 -215
  318. package/objects/ShadowMesh.cjs +0 -45
  319. package/objects/ShadowMesh.js +0 -45
  320. package/objects/Sky.cjs +0 -200
  321. package/objects/Sky.js +0 -200
  322. package/objects/Water.cjs +0 -242
  323. package/objects/Water.js +0 -242
  324. package/objects/Water2.cjs +0 -256
  325. package/objects/Water2.js +0 -256
  326. package/physics/AmmoPhysics.cjs +0 -166
  327. package/physics/AmmoPhysics.js +0 -166
  328. package/postprocessing/AdaptiveToneMappingPass.cjs +0 -218
  329. package/postprocessing/AdaptiveToneMappingPass.js +0 -218
  330. package/postprocessing/AfterimagePass.cjs +0 -68
  331. package/postprocessing/AfterimagePass.js +0 -68
  332. package/postprocessing/BloomPass.cjs +0 -109
  333. package/postprocessing/BloomPass.js +0 -109
  334. package/postprocessing/BokehPass.cjs +0 -90
  335. package/postprocessing/BokehPass.js +0 -90
  336. package/postprocessing/ClearPass.cjs +0 -36
  337. package/postprocessing/ClearPass.js +0 -36
  338. package/postprocessing/CubeTexturePass.cjs +0 -53
  339. package/postprocessing/CubeTexturePass.js +0 -53
  340. package/postprocessing/DotScreenPass.cjs +0 -49
  341. package/postprocessing/DotScreenPass.js +0 -49
  342. package/postprocessing/EffectComposer.cjs +0 -157
  343. package/postprocessing/EffectComposer.js +0 -157
  344. package/postprocessing/FilmPass.cjs +0 -51
  345. package/postprocessing/FilmPass.js +0 -51
  346. package/postprocessing/GlitchPass.cjs +0 -84
  347. package/postprocessing/GlitchPass.js +0 -84
  348. package/postprocessing/HalftonePass.cjs +0 -53
  349. package/postprocessing/HalftonePass.js +0 -53
  350. package/postprocessing/LUTPass.cjs +0 -142
  351. package/postprocessing/LUTPass.js +0 -142
  352. package/postprocessing/MaskPass.cjs +0 -69
  353. package/postprocessing/MaskPass.js +0 -69
  354. package/postprocessing/OutlinePass.cjs +0 -479
  355. package/postprocessing/OutlinePass.js +0 -479
  356. package/postprocessing/Pass.cjs +0 -48
  357. package/postprocessing/Pass.js +0 -48
  358. package/postprocessing/RenderPass.cjs +0 -59
  359. package/postprocessing/RenderPass.js +0 -59
  360. package/postprocessing/RenderPixelatedPass.cjs +0 -199
  361. package/postprocessing/RenderPixelatedPass.js +0 -199
  362. package/postprocessing/SAOPass.cjs +0 -288
  363. package/postprocessing/SAOPass.js +0 -288
  364. package/postprocessing/SMAAPass.cjs +0 -112
  365. package/postprocessing/SMAAPass.js +0 -112
  366. package/postprocessing/SSAARenderPass.cjs +0 -189
  367. package/postprocessing/SSAARenderPass.js +0 -189
  368. package/postprocessing/SSAOPass.cjs +0 -272
  369. package/postprocessing/SSAOPass.js +0 -272
  370. package/postprocessing/SSRPass.cjs +0 -411
  371. package/postprocessing/SSRPass.js +0 -411
  372. package/postprocessing/SavePass.cjs +0 -38
  373. package/postprocessing/SavePass.js +0 -38
  374. package/postprocessing/ShaderPass.cjs +0 -49
  375. package/postprocessing/ShaderPass.js +0 -49
  376. package/postprocessing/TAARenderPass.cjs +0 -174
  377. package/postprocessing/TAARenderPass.js +0 -174
  378. package/postprocessing/TexturePass.cjs +0 -42
  379. package/postprocessing/TexturePass.js +0 -42
  380. package/postprocessing/UnrealBloomPass.cjs +0 -277
  381. package/postprocessing/UnrealBloomPass.js +0 -277
  382. package/postprocessing/WaterPass.cjs +0 -72
  383. package/postprocessing/WaterPass.js +0 -72
  384. package/renderers/CSS2DRenderer.cjs +0 -122
  385. package/renderers/CSS2DRenderer.js +0 -122
  386. package/renderers/CSS3DRenderer.cjs +0 -167
  387. package/renderers/CSS3DRenderer.js +0 -167
  388. package/renderers/Projector.cjs +0 -499
  389. package/renderers/Projector.js +0 -499
  390. package/renderers/SVGRenderer.cjs +0 -311
  391. package/renderers/SVGRenderer.js +0 -311
  392. package/shaders/ACESFilmicToneMappingShader.cjs +0 -55
  393. package/shaders/ACESFilmicToneMappingShader.js +0 -55
  394. package/shaders/AfterimageShader.cjs +0 -32
  395. package/shaders/AfterimageShader.js +0 -32
  396. package/shaders/BasicShader.cjs +0 -12
  397. package/shaders/BasicShader.js +0 -12
  398. package/shaders/BleachBypassShader.cjs +0 -35
  399. package/shaders/BleachBypassShader.js +0 -35
  400. package/shaders/BlendShader.cjs +0 -30
  401. package/shaders/BlendShader.js +0 -30
  402. package/shaders/BokehShader.cjs +0 -109
  403. package/shaders/BokehShader.js +0 -109
  404. package/shaders/BokehShader2.cjs +0 -269
  405. package/shaders/BokehShader2.js +0 -269
  406. package/shaders/BrightnessContrastShader.cjs +0 -32
  407. package/shaders/BrightnessContrastShader.js +0 -32
  408. package/shaders/ColorCorrectionShader.cjs +0 -30
  409. package/shaders/ColorCorrectionShader.js +0 -30
  410. package/shaders/ColorifyShader.cjs +0 -28
  411. package/shaders/ColorifyShader.js +0 -28
  412. package/shaders/ConvolutionShader.cjs +0 -55
  413. package/shaders/ConvolutionShader.js +0 -55
  414. package/shaders/CopyShader.cjs +0 -25
  415. package/shaders/CopyShader.js +0 -25
  416. package/shaders/DOFMipMapShader.cjs +0 -32
  417. package/shaders/DOFMipMapShader.js +0 -32
  418. package/shaders/DepthLimitedBlurShader.cjs +0 -114
  419. package/shaders/DepthLimitedBlurShader.js +0 -114
  420. package/shaders/DigitalGlitch.cjs +0 -85
  421. package/shaders/DigitalGlitch.js +0 -85
  422. package/shaders/DotScreenShader.cjs +0 -39
  423. package/shaders/DotScreenShader.js +0 -39
  424. package/shaders/FXAAShader.cjs +0 -1098
  425. package/shaders/FXAAShader.js +0 -1098
  426. package/shaders/FilmShader.cjs +0 -53
  427. package/shaders/FilmShader.js +0 -53
  428. package/shaders/FocusShader.cjs +0 -55
  429. package/shaders/FocusShader.js +0 -55
  430. package/shaders/FreiChenShader.cjs +0 -64
  431. package/shaders/FreiChenShader.js +0 -64
  432. package/shaders/FresnelShader.cjs +0 -47
  433. package/shaders/FresnelShader.js +0 -47
  434. package/shaders/GammaCorrectionShader.cjs +0 -23
  435. package/shaders/GammaCorrectionShader.js +0 -23
  436. package/shaders/GodRaysShader.cjs +0 -183
  437. package/shaders/GodRaysShader.js +0 -183
  438. package/shaders/HalftoneShader.cjs +0 -228
  439. package/shaders/HalftoneShader.js +0 -228
  440. package/shaders/HorizontalBlurShader.cjs +0 -49
  441. package/shaders/HorizontalBlurShader.js +0 -49
  442. package/shaders/HorizontalTiltShiftShader.cjs +0 -37
  443. package/shaders/HorizontalTiltShiftShader.js +0 -37
  444. package/shaders/HueSaturationShader.cjs +0 -43
  445. package/shaders/HueSaturationShader.js +0 -43
  446. package/shaders/KaleidoShader.cjs +0 -34
  447. package/shaders/KaleidoShader.js +0 -34
  448. package/shaders/LuminosityHighPassShader.cjs +0 -37
  449. package/shaders/LuminosityHighPassShader.js +0 -37
  450. package/shaders/LuminosityShader.cjs +0 -25
  451. package/shaders/LuminosityShader.js +0 -25
  452. package/shaders/MirrorShader.cjs +0 -35
  453. package/shaders/MirrorShader.js +0 -35
  454. package/shaders/NormalMapShader.cjs +0 -31
  455. package/shaders/NormalMapShader.js +0 -31
  456. package/shaders/ParallaxShader.cjs +0 -133
  457. package/shaders/ParallaxShader.js +0 -133
  458. package/shaders/PixelShader.cjs +0 -28
  459. package/shaders/PixelShader.js +0 -28
  460. package/shaders/RGBShiftShader.cjs +0 -30
  461. package/shaders/RGBShiftShader.js +0 -30
  462. package/shaders/SAOShader.cjs +0 -144
  463. package/shaders/SAOShader.js +0 -144
  464. package/shaders/SMAAShader.cjs +0 -358
  465. package/shaders/SMAAShader.js +0 -358
  466. package/shaders/SSAOShader.cjs +0 -182
  467. package/shaders/SSAOShader.js +0 -182
  468. package/shaders/SSRShader.cjs +0 -342
  469. package/shaders/SSRShader.js +0 -342
  470. package/shaders/SepiaShader.cjs +0 -29
  471. package/shaders/SepiaShader.js +0 -29
  472. package/shaders/SobelOperatorShader.cjs +0 -54
  473. package/shaders/SobelOperatorShader.js +0 -54
  474. package/shaders/SubsurfaceScatteringShader.cjs +0 -98
  475. package/shaders/SubsurfaceScatteringShader.js +0 -98
  476. package/shaders/TechnicolorShader.cjs +0 -24
  477. package/shaders/TechnicolorShader.js +0 -24
  478. package/shaders/ToneMapShader.cjs +0 -51
  479. package/shaders/ToneMapShader.js +0 -51
  480. package/shaders/ToonShader.cjs +0 -188
  481. package/shaders/ToonShader.js +0 -188
  482. package/shaders/TriangleBlurShader.cjs +0 -37
  483. package/shaders/TriangleBlurShader.js +0 -37
  484. package/shaders/UnpackDepthRGBAShader.cjs +0 -26
  485. package/shaders/UnpackDepthRGBAShader.js +0 -26
  486. package/shaders/VerticalBlurShader.cjs +0 -50
  487. package/shaders/VerticalBlurShader.js +0 -50
  488. package/shaders/VerticalTiltShiftShader.cjs +0 -37
  489. package/shaders/VerticalTiltShiftShader.js +0 -37
  490. package/shaders/VignetteShader.cjs +0 -38
  491. package/shaders/VignetteShader.js +0 -38
  492. package/shaders/VolumeShader.cjs +0 -225
  493. package/shaders/VolumeShader.js +0 -225
  494. package/shaders/WaterRefractionShader.cjs +0 -59
  495. package/shaders/WaterRefractionShader.js +0 -59
  496. package/shaders/types.cjs +0 -1
  497. package/shaders/types.js +0 -1
  498. package/textures/FlakesTexture.cjs +0 -30
  499. package/textures/FlakesTexture.js +0 -30
  500. package/types/helpers.cjs +0 -4
  501. package/types/helpers.js +0 -4
  502. package/utils/BufferGeometryUtils.cjs +0 -636
  503. package/utils/BufferGeometryUtils.js +0 -636
  504. package/utils/GeometryCompressionUtils.cjs +0 -573
  505. package/utils/GeometryCompressionUtils.js +0 -573
  506. package/utils/GeometryUtils.cjs +0 -109
  507. package/utils/GeometryUtils.js +0 -109
  508. package/utils/RoughnessMipmapper.cjs +0 -223
  509. package/utils/RoughnessMipmapper.js +0 -223
  510. package/utils/SceneUtils.cjs +0 -36
  511. package/utils/SceneUtils.js +0 -36
  512. package/utils/ShadowMapViewer.cjs +0 -111
  513. package/utils/ShadowMapViewer.js +0 -111
  514. package/utils/SkeletonUtils.cjs +0 -211
  515. package/utils/SkeletonUtils.js +0 -211
  516. package/utils/UVsDebug.cjs +0 -80
  517. package/utils/UVsDebug.js +0 -80
  518. package/utils/WorkerPool.cjs +0 -62
  519. package/utils/WorkerPool.js +0 -62
  520. package/webxr/ARButton.cjs +0 -119
  521. package/webxr/ARButton.js +0 -119
  522. package/webxr/OculusHandModel.cjs +0 -82
  523. package/webxr/OculusHandModel.js +0 -82
  524. package/webxr/OculusHandPointerModel.cjs +0 -241
  525. package/webxr/OculusHandPointerModel.js +0 -224
  526. package/webxr/Text2D.cjs +0 -48
  527. package/webxr/Text2D.js +0 -31
  528. package/webxr/VRButton.cjs +0 -111
  529. package/webxr/VRButton.js +0 -111
  530. package/webxr/XRControllerModelFactory.cjs +0 -174
  531. package/webxr/XRControllerModelFactory.js +0 -174
  532. package/webxr/XREstimatedLight.cjs +0 -126
  533. package/webxr/XREstimatedLight.js +0 -126
  534. package/webxr/XRHandMeshModel.cjs +0 -82
  535. package/webxr/XRHandMeshModel.js +0 -82
  536. package/webxr/XRHandModelFactory.cjs +0 -61
  537. package/webxr/XRHandModelFactory.js +0 -61
  538. package/webxr/XRHandPrimitiveModel.cjs +0 -68
  539. package/webxr/XRHandPrimitiveModel.js +0 -68
@@ -1,1909 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const THREE = require("three");
4
- let _renderer;
5
- let fullscreenQuadGeometry;
6
- let fullscreenQuadMaterial;
7
- let fullscreenQuad;
8
- function decompress(texture, maxTextureSize = Infinity, renderer = null) {
9
- if (!fullscreenQuadGeometry)
10
- fullscreenQuadGeometry = new THREE.PlaneGeometry(2, 2, 1, 1);
11
- if (!fullscreenQuadMaterial)
12
- fullscreenQuadMaterial = new THREE.ShaderMaterial({
13
- uniforms: { blitTexture: new THREE.Uniform(texture) },
14
- vertexShader: (
15
- /* glsl */
16
- `
17
- varying vec2 vUv;
18
- void main(){
19
- vUv = uv;
20
- gl_Position = vec4(position.xy * 1.0,0.,.999999);
21
- }
22
- `
23
- ),
24
- fragmentShader: (
25
- /* glsl */
26
- `
27
- uniform sampler2D blitTexture;
28
- varying vec2 vUv;
29
-
30
- void main(){
31
- gl_FragColor = vec4(vUv.xy, 0, 1);
32
-
33
- #ifdef IS_SRGB
34
- gl_FragColor = LinearTosRGB( texture2D( blitTexture, vUv) );
35
- #else
36
- gl_FragColor = texture2D( blitTexture, vUv);
37
- #endif
38
- }
39
- `
40
- )
41
- });
42
- fullscreenQuadMaterial.uniforms.blitTexture.value = texture;
43
- fullscreenQuadMaterial.defines.IS_SRGB = "colorSpace" in texture ? texture.colorSpace === "srgb" : texture.encoding === 3001;
44
- fullscreenQuadMaterial.needsUpdate = true;
45
- if (!fullscreenQuad) {
46
- fullscreenQuad = new THREE.Mesh(fullscreenQuadGeometry, fullscreenQuadMaterial);
47
- fullscreenQuad.frustrumCulled = false;
48
- }
49
- const _camera = new THREE.PerspectiveCamera();
50
- const _scene = new THREE.Scene();
51
- _scene.add(fullscreenQuad);
52
- if (!renderer) {
53
- renderer = _renderer = new THREE.WebGLRenderer({ antialias: false });
54
- }
55
- renderer.setSize(Math.min(texture.image.width, maxTextureSize), Math.min(texture.image.height, maxTextureSize));
56
- renderer.clear();
57
- renderer.render(_scene, _camera);
58
- const readableTexture = new THREE.Texture(renderer.domElement);
59
- readableTexture.minFilter = texture.minFilter;
60
- readableTexture.magFilter = texture.magFilter;
61
- readableTexture.wrapS = texture.wrapS;
62
- readableTexture.wrapT = texture.wrapT;
63
- readableTexture.name = texture.name;
64
- if (_renderer) {
65
- _renderer.dispose();
66
- _renderer = null;
67
- }
68
- return readableTexture;
69
- }
70
- const KHR_mesh_quantization_ExtraAttrTypes = {
71
- POSITION: [
72
- "byte",
73
- "byte normalized",
74
- "unsigned byte",
75
- "unsigned byte normalized",
76
- "short",
77
- "short normalized",
78
- "unsigned short",
79
- "unsigned short normalized"
80
- ],
81
- NORMAL: ["byte normalized", "short normalized"],
82
- TANGENT: ["byte normalized", "short normalized"],
83
- TEXCOORD: ["byte", "byte normalized", "unsigned byte", "short", "short normalized", "unsigned short"]
84
- };
85
- class GLTFExporter {
86
- constructor() {
87
- this.pluginCallbacks = [];
88
- this.register(function(writer) {
89
- return new GLTFLightExtension(writer);
90
- });
91
- this.register(function(writer) {
92
- return new GLTFMaterialsUnlitExtension(writer);
93
- });
94
- this.register(function(writer) {
95
- return new GLTFMaterialsTransmissionExtension(writer);
96
- });
97
- this.register(function(writer) {
98
- return new GLTFMaterialsVolumeExtension(writer);
99
- });
100
- this.register(function(writer) {
101
- return new GLTFMaterialsIorExtension(writer);
102
- });
103
- this.register(function(writer) {
104
- return new GLTFMaterialsSpecularExtension(writer);
105
- });
106
- this.register(function(writer) {
107
- return new GLTFMaterialsClearcoatExtension(writer);
108
- });
109
- this.register(function(writer) {
110
- return new GLTFMaterialsIridescenceExtension(writer);
111
- });
112
- this.register(function(writer) {
113
- return new GLTFMaterialsSheenExtension(writer);
114
- });
115
- this.register(function(writer) {
116
- return new GLTFMaterialsAnisotropyExtension(writer);
117
- });
118
- this.register(function(writer) {
119
- return new GLTFMaterialsEmissiveStrengthExtension(writer);
120
- });
121
- }
122
- register(callback) {
123
- if (this.pluginCallbacks.indexOf(callback) === -1) {
124
- this.pluginCallbacks.push(callback);
125
- }
126
- return this;
127
- }
128
- unregister(callback) {
129
- if (this.pluginCallbacks.indexOf(callback) !== -1) {
130
- this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(callback), 1);
131
- }
132
- return this;
133
- }
134
- /**
135
- * Parse scenes and generate GLTF output
136
- * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
137
- * @param {Function} onDone Callback on completed
138
- * @param {Function} onError Callback on errors
139
- * @param {Object} options options
140
- */
141
- parse(input, onDone, onError, options) {
142
- const writer = new GLTFWriter();
143
- const plugins = [];
144
- for (let i = 0, il = this.pluginCallbacks.length; i < il; i++) {
145
- plugins.push(this.pluginCallbacks[i](writer));
146
- }
147
- writer.setPlugins(plugins);
148
- writer.write(input, onDone, options).catch(onError);
149
- }
150
- parseAsync(input, options) {
151
- const scope = this;
152
- return new Promise(function(resolve, reject) {
153
- scope.parse(input, resolve, reject, options);
154
- });
155
- }
156
- }
157
- const WEBGL_CONSTANTS = {
158
- POINTS: 0,
159
- LINES: 1,
160
- LINE_LOOP: 2,
161
- LINE_STRIP: 3,
162
- TRIANGLES: 4,
163
- TRIANGLE_STRIP: 5,
164
- TRIANGLE_FAN: 6,
165
- BYTE: 5120,
166
- UNSIGNED_BYTE: 5121,
167
- SHORT: 5122,
168
- UNSIGNED_SHORT: 5123,
169
- INT: 5124,
170
- UNSIGNED_INT: 5125,
171
- FLOAT: 5126,
172
- ARRAY_BUFFER: 34962,
173
- ELEMENT_ARRAY_BUFFER: 34963,
174
- NEAREST: 9728,
175
- LINEAR: 9729,
176
- NEAREST_MIPMAP_NEAREST: 9984,
177
- LINEAR_MIPMAP_NEAREST: 9985,
178
- NEAREST_MIPMAP_LINEAR: 9986,
179
- LINEAR_MIPMAP_LINEAR: 9987,
180
- CLAMP_TO_EDGE: 33071,
181
- MIRRORED_REPEAT: 33648,
182
- REPEAT: 10497
183
- };
184
- const KHR_MESH_QUANTIZATION = "KHR_mesh_quantization";
185
- const THREE_TO_WEBGL = {};
186
- THREE_TO_WEBGL[THREE.NearestFilter] = WEBGL_CONSTANTS.NEAREST;
187
- THREE_TO_WEBGL[THREE.NearestMipmapNearestFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_NEAREST;
188
- THREE_TO_WEBGL[THREE.NearestMipmapLinearFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_LINEAR;
189
- THREE_TO_WEBGL[THREE.LinearFilter] = WEBGL_CONSTANTS.LINEAR;
190
- THREE_TO_WEBGL[THREE.LinearMipmapNearestFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_NEAREST;
191
- THREE_TO_WEBGL[THREE.LinearMipmapLinearFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_LINEAR;
192
- THREE_TO_WEBGL[THREE.ClampToEdgeWrapping] = WEBGL_CONSTANTS.CLAMP_TO_EDGE;
193
- THREE_TO_WEBGL[THREE.RepeatWrapping] = WEBGL_CONSTANTS.REPEAT;
194
- THREE_TO_WEBGL[THREE.MirroredRepeatWrapping] = WEBGL_CONSTANTS.MIRRORED_REPEAT;
195
- const PATH_PROPERTIES = {
196
- scale: "scale",
197
- position: "translation",
198
- quaternion: "rotation",
199
- morphTargetInfluences: "weights"
200
- };
201
- const DEFAULT_SPECULAR_COLOR = new THREE.Color();
202
- const GLB_HEADER_BYTES = 12;
203
- const GLB_HEADER_MAGIC = 1179937895;
204
- const GLB_VERSION = 2;
205
- const GLB_CHUNK_PREFIX_BYTES = 8;
206
- const GLB_CHUNK_TYPE_JSON = 1313821514;
207
- const GLB_CHUNK_TYPE_BIN = 5130562;
208
- function equalArray(array1, array2) {
209
- return array1.length === array2.length && array1.every(function(element, index) {
210
- return element === array2[index];
211
- });
212
- }
213
- function stringToArrayBuffer(text) {
214
- return new TextEncoder().encode(text).buffer;
215
- }
216
- function isIdentityMatrix(matrix) {
217
- return equalArray(matrix.elements, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
218
- }
219
- function getMinMax(attribute, start, count) {
220
- const output = {
221
- min: new Array(attribute.itemSize).fill(Number.POSITIVE_INFINITY),
222
- max: new Array(attribute.itemSize).fill(Number.NEGATIVE_INFINITY)
223
- };
224
- for (let i = start; i < start + count; i++) {
225
- for (let a = 0; a < attribute.itemSize; a++) {
226
- let value;
227
- if (attribute.itemSize > 4) {
228
- value = attribute.array[i * attribute.itemSize + a];
229
- } else {
230
- if (a === 0)
231
- value = attribute.getX(i);
232
- else if (a === 1)
233
- value = attribute.getY(i);
234
- else if (a === 2)
235
- value = attribute.getZ(i);
236
- else if (a === 3)
237
- value = attribute.getW(i);
238
- if (attribute.normalized === true) {
239
- value = THREE.MathUtils.normalize(value, attribute.array);
240
- }
241
- }
242
- output.min[a] = Math.min(output.min[a], value);
243
- output.max[a] = Math.max(output.max[a], value);
244
- }
245
- }
246
- return output;
247
- }
248
- function getPaddedBufferSize(bufferSize) {
249
- return Math.ceil(bufferSize / 4) * 4;
250
- }
251
- function getPaddedArrayBuffer(arrayBuffer, paddingByte = 0) {
252
- const paddedLength = getPaddedBufferSize(arrayBuffer.byteLength);
253
- if (paddedLength !== arrayBuffer.byteLength) {
254
- const array = new Uint8Array(paddedLength);
255
- array.set(new Uint8Array(arrayBuffer));
256
- if (paddingByte !== 0) {
257
- for (let i = arrayBuffer.byteLength; i < paddedLength; i++) {
258
- array[i] = paddingByte;
259
- }
260
- }
261
- return array.buffer;
262
- }
263
- return arrayBuffer;
264
- }
265
- function getCanvas() {
266
- if (typeof document === "undefined" && typeof OffscreenCanvas !== "undefined") {
267
- return new OffscreenCanvas(1, 1);
268
- }
269
- return document.createElement("canvas");
270
- }
271
- function getToBlobPromise(canvas, mimeType) {
272
- if (canvas.toBlob !== void 0) {
273
- return new Promise((resolve) => canvas.toBlob(resolve, mimeType));
274
- }
275
- let quality;
276
- if (mimeType === "image/jpeg") {
277
- quality = 0.92;
278
- } else if (mimeType === "image/webp") {
279
- quality = 0.8;
280
- }
281
- return canvas.convertToBlob({
282
- type: mimeType,
283
- quality
284
- });
285
- }
286
- class GLTFWriter {
287
- constructor() {
288
- this.plugins = [];
289
- this.options = {};
290
- this.pending = [];
291
- this.buffers = [];
292
- this.byteOffset = 0;
293
- this.buffers = [];
294
- this.nodeMap = /* @__PURE__ */ new Map();
295
- this.skins = [];
296
- this.extensionsUsed = {};
297
- this.extensionsRequired = {};
298
- this.uids = /* @__PURE__ */ new Map();
299
- this.uid = 0;
300
- this.json = {
301
- asset: {
302
- version: "2.0",
303
- generator: "THREE.GLTFExporter"
304
- }
305
- };
306
- this.cache = {
307
- meshes: /* @__PURE__ */ new Map(),
308
- attributes: /* @__PURE__ */ new Map(),
309
- attributesNormalized: /* @__PURE__ */ new Map(),
310
- materials: /* @__PURE__ */ new Map(),
311
- textures: /* @__PURE__ */ new Map(),
312
- images: /* @__PURE__ */ new Map()
313
- };
314
- }
315
- setPlugins(plugins) {
316
- this.plugins = plugins;
317
- }
318
- /**
319
- * Parse scenes and generate GLTF output
320
- * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
321
- * @param {Function} onDone Callback on completed
322
- * @param {Object} options options
323
- */
324
- async write(input, onDone, options = {}) {
325
- this.options = Object.assign(
326
- {
327
- // default options
328
- binary: false,
329
- trs: false,
330
- onlyVisible: true,
331
- maxTextureSize: Infinity,
332
- animations: [],
333
- includeCustomExtensions: false
334
- },
335
- options
336
- );
337
- if (this.options.animations.length > 0) {
338
- this.options.trs = true;
339
- }
340
- this.processInput(input);
341
- await Promise.all(this.pending);
342
- const writer = this;
343
- const buffers = writer.buffers;
344
- const json = writer.json;
345
- options = writer.options;
346
- const extensionsUsed = writer.extensionsUsed;
347
- const extensionsRequired = writer.extensionsRequired;
348
- const blob = new Blob(buffers, { type: "application/octet-stream" });
349
- const extensionsUsedList = Object.keys(extensionsUsed);
350
- const extensionsRequiredList = Object.keys(extensionsRequired);
351
- if (extensionsUsedList.length > 0)
352
- json.extensionsUsed = extensionsUsedList;
353
- if (extensionsRequiredList.length > 0)
354
- json.extensionsRequired = extensionsRequiredList;
355
- if (json.buffers && json.buffers.length > 0)
356
- json.buffers[0].byteLength = blob.size;
357
- if (options.binary === true) {
358
- const reader = new FileReader();
359
- reader.readAsArrayBuffer(blob);
360
- reader.onloadend = function() {
361
- const binaryChunk = getPaddedArrayBuffer(reader.result);
362
- const binaryChunkPrefix = new DataView(new ArrayBuffer(GLB_CHUNK_PREFIX_BYTES));
363
- binaryChunkPrefix.setUint32(0, binaryChunk.byteLength, true);
364
- binaryChunkPrefix.setUint32(4, GLB_CHUNK_TYPE_BIN, true);
365
- const jsonChunk = getPaddedArrayBuffer(stringToArrayBuffer(JSON.stringify(json)), 32);
366
- const jsonChunkPrefix = new DataView(new ArrayBuffer(GLB_CHUNK_PREFIX_BYTES));
367
- jsonChunkPrefix.setUint32(0, jsonChunk.byteLength, true);
368
- jsonChunkPrefix.setUint32(4, GLB_CHUNK_TYPE_JSON, true);
369
- const header = new ArrayBuffer(GLB_HEADER_BYTES);
370
- const headerView = new DataView(header);
371
- headerView.setUint32(0, GLB_HEADER_MAGIC, true);
372
- headerView.setUint32(4, GLB_VERSION, true);
373
- const totalByteLength = GLB_HEADER_BYTES + jsonChunkPrefix.byteLength + jsonChunk.byteLength + binaryChunkPrefix.byteLength + binaryChunk.byteLength;
374
- headerView.setUint32(8, totalByteLength, true);
375
- const glbBlob = new Blob([header, jsonChunkPrefix, jsonChunk, binaryChunkPrefix, binaryChunk], {
376
- type: "application/octet-stream"
377
- });
378
- const glbReader = new FileReader();
379
- glbReader.readAsArrayBuffer(glbBlob);
380
- glbReader.onloadend = function() {
381
- onDone(glbReader.result);
382
- };
383
- };
384
- } else {
385
- if (json.buffers && json.buffers.length > 0) {
386
- const reader = new FileReader();
387
- reader.readAsDataURL(blob);
388
- reader.onloadend = function() {
389
- const base64data = reader.result;
390
- json.buffers[0].uri = base64data;
391
- onDone(json);
392
- };
393
- } else {
394
- onDone(json);
395
- }
396
- }
397
- }
398
- /**
399
- * Serializes a userData.
400
- *
401
- * @param {THREE.Object3D|THREE.Material} object
402
- * @param {Object} objectDef
403
- */
404
- serializeUserData(object, objectDef) {
405
- if (Object.keys(object.userData).length === 0)
406
- return;
407
- const options = this.options;
408
- const extensionsUsed = this.extensionsUsed;
409
- try {
410
- const json = JSON.parse(JSON.stringify(object.userData));
411
- if (options.includeCustomExtensions && json.gltfExtensions) {
412
- if (objectDef.extensions === void 0)
413
- objectDef.extensions = {};
414
- for (const extensionName in json.gltfExtensions) {
415
- objectDef.extensions[extensionName] = json.gltfExtensions[extensionName];
416
- extensionsUsed[extensionName] = true;
417
- }
418
- delete json.gltfExtensions;
419
- }
420
- if (Object.keys(json).length > 0)
421
- objectDef.extras = json;
422
- } catch (error) {
423
- console.warn(
424
- "THREE.GLTFExporter: userData of '" + object.name + "' won't be serialized because of JSON.stringify error - " + error.message
425
- );
426
- }
427
- }
428
- /**
429
- * Returns ids for buffer attributes.
430
- * @param {Object} object
431
- * @return {Integer}
432
- */
433
- getUID(attribute, isRelativeCopy = false) {
434
- if (this.uids.has(attribute) === false) {
435
- const uids2 = /* @__PURE__ */ new Map();
436
- uids2.set(true, this.uid++);
437
- uids2.set(false, this.uid++);
438
- this.uids.set(attribute, uids2);
439
- }
440
- const uids = this.uids.get(attribute);
441
- return uids.get(isRelativeCopy);
442
- }
443
- /**
444
- * Checks if normal attribute values are normalized.
445
- *
446
- * @param {BufferAttribute} normal
447
- * @returns {Boolean}
448
- */
449
- isNormalizedNormalAttribute(normal) {
450
- const cache = this.cache;
451
- if (cache.attributesNormalized.has(normal))
452
- return false;
453
- const v = new THREE.Vector3();
454
- for (let i = 0, il = normal.count; i < il; i++) {
455
- if (Math.abs(v.fromBufferAttribute(normal, i).length() - 1) > 5e-4)
456
- return false;
457
- }
458
- return true;
459
- }
460
- /**
461
- * Creates normalized normal buffer attribute.
462
- *
463
- * @param {BufferAttribute} normal
464
- * @returns {BufferAttribute}
465
- *
466
- */
467
- createNormalizedNormalAttribute(normal) {
468
- const cache = this.cache;
469
- if (cache.attributesNormalized.has(normal))
470
- return cache.attributesNormalized.get(normal);
471
- const attribute = normal.clone();
472
- const v = new THREE.Vector3();
473
- for (let i = 0, il = attribute.count; i < il; i++) {
474
- v.fromBufferAttribute(attribute, i);
475
- if (v.x === 0 && v.y === 0 && v.z === 0) {
476
- v.setX(1);
477
- } else {
478
- v.normalize();
479
- }
480
- attribute.setXYZ(i, v.x, v.y, v.z);
481
- }
482
- cache.attributesNormalized.set(normal, attribute);
483
- return attribute;
484
- }
485
- /**
486
- * Applies a texture transform, if present, to the map definition. Requires
487
- * the KHR_texture_transform extension.
488
- *
489
- * @param {Object} mapDef
490
- * @param {THREE.Texture} texture
491
- */
492
- applyTextureTransform(mapDef, texture) {
493
- let didTransform = false;
494
- const transformDef = {};
495
- if (texture.offset.x !== 0 || texture.offset.y !== 0) {
496
- transformDef.offset = texture.offset.toArray();
497
- didTransform = true;
498
- }
499
- if (texture.rotation !== 0) {
500
- transformDef.rotation = texture.rotation;
501
- didTransform = true;
502
- }
503
- if (texture.repeat.x !== 1 || texture.repeat.y !== 1) {
504
- transformDef.scale = texture.repeat.toArray();
505
- didTransform = true;
506
- }
507
- if (didTransform) {
508
- mapDef.extensions = mapDef.extensions || {};
509
- mapDef.extensions["KHR_texture_transform"] = transformDef;
510
- this.extensionsUsed["KHR_texture_transform"] = true;
511
- }
512
- }
513
- buildMetalRoughTexture(metalnessMap, roughnessMap) {
514
- if (metalnessMap === roughnessMap)
515
- return metalnessMap;
516
- function getEncodingConversion(map) {
517
- if ("colorSpace" in map ? map.colorSpace === "srgb" : map.encoding === 3001) {
518
- return function SRGBToLinear(c) {
519
- return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
520
- };
521
- }
522
- return function LinearToLinear(c) {
523
- return c;
524
- };
525
- }
526
- console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.");
527
- if (metalnessMap instanceof THREE.CompressedTexture) {
528
- metalnessMap = decompress(metalnessMap);
529
- }
530
- if (roughnessMap instanceof THREE.CompressedTexture) {
531
- roughnessMap = decompress(roughnessMap);
532
- }
533
- const metalness = metalnessMap ? metalnessMap.image : null;
534
- const roughness = roughnessMap ? roughnessMap.image : null;
535
- const width = Math.max(metalness ? metalness.width : 0, roughness ? roughness.width : 0);
536
- const height = Math.max(metalness ? metalness.height : 0, roughness ? roughness.height : 0);
537
- const canvas = getCanvas();
538
- canvas.width = width;
539
- canvas.height = height;
540
- const context = canvas.getContext("2d");
541
- context.fillStyle = "#00ffff";
542
- context.fillRect(0, 0, width, height);
543
- const composite = context.getImageData(0, 0, width, height);
544
- if (metalness) {
545
- context.drawImage(metalness, 0, 0, width, height);
546
- const convert = getEncodingConversion(metalnessMap);
547
- const data = context.getImageData(0, 0, width, height).data;
548
- for (let i = 2; i < data.length; i += 4) {
549
- composite.data[i] = convert(data[i] / 256) * 256;
550
- }
551
- }
552
- if (roughness) {
553
- context.drawImage(roughness, 0, 0, width, height);
554
- const convert = getEncodingConversion(roughnessMap);
555
- const data = context.getImageData(0, 0, width, height).data;
556
- for (let i = 1; i < data.length; i += 4) {
557
- composite.data[i] = convert(data[i] / 256) * 256;
558
- }
559
- }
560
- context.putImageData(composite, 0, 0);
561
- const reference = metalnessMap || roughnessMap;
562
- const texture = reference.clone();
563
- texture.source = new THREE.Texture(canvas).source;
564
- if ("colorSpace" in texture)
565
- texture.colorSpace = "";
566
- else
567
- texture.encoding = 3e3;
568
- texture.channel = (metalnessMap || roughnessMap).channel;
569
- if (metalnessMap && roughnessMap && metalnessMap.channel !== roughnessMap.channel) {
570
- console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match.");
571
- }
572
- return texture;
573
- }
574
- /**
575
- * Process a buffer to append to the default one.
576
- * @param {ArrayBuffer} buffer
577
- * @return {Integer}
578
- */
579
- processBuffer(buffer) {
580
- const json = this.json;
581
- const buffers = this.buffers;
582
- if (!json.buffers)
583
- json.buffers = [{ byteLength: 0 }];
584
- buffers.push(buffer);
585
- return 0;
586
- }
587
- /**
588
- * Process and generate a BufferView
589
- * @param {BufferAttribute} attribute
590
- * @param {number} componentType
591
- * @param {number} start
592
- * @param {number} count
593
- * @param {number} target (Optional) Target usage of the BufferView
594
- * @return {Object}
595
- */
596
- processBufferView(attribute, componentType, start, count, target) {
597
- const json = this.json;
598
- if (!json.bufferViews)
599
- json.bufferViews = [];
600
- let componentSize;
601
- switch (componentType) {
602
- case WEBGL_CONSTANTS.BYTE:
603
- case WEBGL_CONSTANTS.UNSIGNED_BYTE:
604
- componentSize = 1;
605
- break;
606
- case WEBGL_CONSTANTS.SHORT:
607
- case WEBGL_CONSTANTS.UNSIGNED_SHORT:
608
- componentSize = 2;
609
- break;
610
- default:
611
- componentSize = 4;
612
- }
613
- const byteLength = getPaddedBufferSize(count * attribute.itemSize * componentSize);
614
- const dataView = new DataView(new ArrayBuffer(byteLength));
615
- let offset = 0;
616
- for (let i = start; i < start + count; i++) {
617
- for (let a = 0; a < attribute.itemSize; a++) {
618
- let value;
619
- if (attribute.itemSize > 4) {
620
- value = attribute.array[i * attribute.itemSize + a];
621
- } else {
622
- if (a === 0)
623
- value = attribute.getX(i);
624
- else if (a === 1)
625
- value = attribute.getY(i);
626
- else if (a === 2)
627
- value = attribute.getZ(i);
628
- else if (a === 3)
629
- value = attribute.getW(i);
630
- if (attribute.normalized === true) {
631
- value = THREE.MathUtils.normalize(value, attribute.array);
632
- }
633
- }
634
- if (componentType === WEBGL_CONSTANTS.FLOAT) {
635
- dataView.setFloat32(offset, value, true);
636
- } else if (componentType === WEBGL_CONSTANTS.INT) {
637
- dataView.setInt32(offset, value, true);
638
- } else if (componentType === WEBGL_CONSTANTS.UNSIGNED_INT) {
639
- dataView.setUint32(offset, value, true);
640
- } else if (componentType === WEBGL_CONSTANTS.SHORT) {
641
- dataView.setInt16(offset, value, true);
642
- } else if (componentType === WEBGL_CONSTANTS.UNSIGNED_SHORT) {
643
- dataView.setUint16(offset, value, true);
644
- } else if (componentType === WEBGL_CONSTANTS.BYTE) {
645
- dataView.setInt8(offset, value);
646
- } else if (componentType === WEBGL_CONSTANTS.UNSIGNED_BYTE) {
647
- dataView.setUint8(offset, value);
648
- }
649
- offset += componentSize;
650
- }
651
- }
652
- const bufferViewDef = {
653
- buffer: this.processBuffer(dataView.buffer),
654
- byteOffset: this.byteOffset,
655
- byteLength
656
- };
657
- if (target !== void 0)
658
- bufferViewDef.target = target;
659
- if (target === WEBGL_CONSTANTS.ARRAY_BUFFER) {
660
- bufferViewDef.byteStride = attribute.itemSize * componentSize;
661
- }
662
- this.byteOffset += byteLength;
663
- json.bufferViews.push(bufferViewDef);
664
- const output = {
665
- id: json.bufferViews.length - 1,
666
- byteLength: 0
667
- };
668
- return output;
669
- }
670
- /**
671
- * Process and generate a BufferView from an image Blob.
672
- * @param {Blob} blob
673
- * @return {Promise<Integer>}
674
- */
675
- processBufferViewImage(blob) {
676
- const writer = this;
677
- const json = writer.json;
678
- if (!json.bufferViews)
679
- json.bufferViews = [];
680
- return new Promise(function(resolve) {
681
- const reader = new FileReader();
682
- reader.readAsArrayBuffer(blob);
683
- reader.onloadend = function() {
684
- const buffer = getPaddedArrayBuffer(reader.result);
685
- const bufferViewDef = {
686
- buffer: writer.processBuffer(buffer),
687
- byteOffset: writer.byteOffset,
688
- byteLength: buffer.byteLength
689
- };
690
- writer.byteOffset += buffer.byteLength;
691
- resolve(json.bufferViews.push(bufferViewDef) - 1);
692
- };
693
- });
694
- }
695
- /**
696
- * Process attribute to generate an accessor
697
- * @param {BufferAttribute} attribute Attribute to process
698
- * @param {THREE.BufferGeometry} geometry (Optional) Geometry used for truncated draw range
699
- * @param {Integer} start (Optional)
700
- * @param {Integer} count (Optional)
701
- * @return {Integer|null} Index of the processed accessor on the "accessors" array
702
- */
703
- processAccessor(attribute, geometry, start, count) {
704
- const json = this.json;
705
- const types = {
706
- 1: "SCALAR",
707
- 2: "VEC2",
708
- 3: "VEC3",
709
- 4: "VEC4",
710
- 9: "MAT3",
711
- 16: "MAT4"
712
- };
713
- let componentType;
714
- if (attribute.array.constructor === Float32Array) {
715
- componentType = WEBGL_CONSTANTS.FLOAT;
716
- } else if (attribute.array.constructor === Int32Array) {
717
- componentType = WEBGL_CONSTANTS.INT;
718
- } else if (attribute.array.constructor === Uint32Array) {
719
- componentType = WEBGL_CONSTANTS.UNSIGNED_INT;
720
- } else if (attribute.array.constructor === Int16Array) {
721
- componentType = WEBGL_CONSTANTS.SHORT;
722
- } else if (attribute.array.constructor === Uint16Array) {
723
- componentType = WEBGL_CONSTANTS.UNSIGNED_SHORT;
724
- } else if (attribute.array.constructor === Int8Array) {
725
- componentType = WEBGL_CONSTANTS.BYTE;
726
- } else if (attribute.array.constructor === Uint8Array) {
727
- componentType = WEBGL_CONSTANTS.UNSIGNED_BYTE;
728
- } else {
729
- throw new Error(
730
- "THREE.GLTFExporter: Unsupported bufferAttribute component type: " + attribute.array.constructor.name
731
- );
732
- }
733
- if (start === void 0)
734
- start = 0;
735
- if (count === void 0)
736
- count = attribute.count;
737
- if (count === 0)
738
- return null;
739
- const minMax = getMinMax(attribute, start, count);
740
- let bufferViewTarget;
741
- if (geometry !== void 0) {
742
- bufferViewTarget = attribute === geometry.index ? WEBGL_CONSTANTS.ELEMENT_ARRAY_BUFFER : WEBGL_CONSTANTS.ARRAY_BUFFER;
743
- }
744
- const bufferView = this.processBufferView(attribute, componentType, start, count, bufferViewTarget);
745
- const accessorDef = {
746
- bufferView: bufferView.id,
747
- byteOffset: bufferView.byteOffset,
748
- componentType,
749
- count,
750
- max: minMax.max,
751
- min: minMax.min,
752
- type: types[attribute.itemSize]
753
- };
754
- if (attribute.normalized === true)
755
- accessorDef.normalized = true;
756
- if (!json.accessors)
757
- json.accessors = [];
758
- return json.accessors.push(accessorDef) - 1;
759
- }
760
- /**
761
- * Process image
762
- * @param {Image} image to process
763
- * @param {Integer} format of the image (RGBAFormat)
764
- * @param {Boolean} flipY before writing out the image
765
- * @param {String} mimeType export format
766
- * @return {Integer} Index of the processed texture in the "images" array
767
- */
768
- processImage(image, format, flipY, mimeType = "image/png") {
769
- if (image !== null) {
770
- const writer = this;
771
- const cache = writer.cache;
772
- const json = writer.json;
773
- const options = writer.options;
774
- const pending = writer.pending;
775
- if (!cache.images.has(image))
776
- cache.images.set(image, {});
777
- const cachedImages = cache.images.get(image);
778
- const key = mimeType + ":flipY/" + flipY.toString();
779
- if (cachedImages[key] !== void 0)
780
- return cachedImages[key];
781
- if (!json.images)
782
- json.images = [];
783
- const imageDef = { mimeType };
784
- const canvas = getCanvas();
785
- canvas.width = Math.min(image.width, options.maxTextureSize);
786
- canvas.height = Math.min(image.height, options.maxTextureSize);
787
- const ctx = canvas.getContext("2d");
788
- if (flipY === true) {
789
- ctx.translate(0, canvas.height);
790
- ctx.scale(1, -1);
791
- }
792
- if (image.data !== void 0) {
793
- if (format !== THREE.RGBAFormat) {
794
- console.error("GLTFExporter: Only RGBAFormat is supported.", format);
795
- }
796
- if (image.width > options.maxTextureSize || image.height > options.maxTextureSize) {
797
- console.warn("GLTFExporter: Image size is bigger than maxTextureSize", image);
798
- }
799
- const data = new Uint8ClampedArray(image.height * image.width * 4);
800
- for (let i = 0; i < data.length; i += 4) {
801
- data[i + 0] = image.data[i + 0];
802
- data[i + 1] = image.data[i + 1];
803
- data[i + 2] = image.data[i + 2];
804
- data[i + 3] = image.data[i + 3];
805
- }
806
- ctx.putImageData(new ImageData(data, image.width, image.height), 0, 0);
807
- } else {
808
- ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
809
- }
810
- if (options.binary === true) {
811
- pending.push(
812
- getToBlobPromise(canvas, mimeType).then((blob) => writer.processBufferViewImage(blob)).then((bufferViewIndex) => {
813
- imageDef.bufferView = bufferViewIndex;
814
- })
815
- );
816
- } else {
817
- if (canvas.toDataURL !== void 0) {
818
- imageDef.uri = canvas.toDataURL(mimeType);
819
- } else {
820
- pending.push(
821
- getToBlobPromise(canvas, mimeType).then((blob) => new FileReader().readAsDataURL(blob)).then((dataURL) => {
822
- imageDef.uri = dataURL;
823
- })
824
- );
825
- }
826
- }
827
- const index = json.images.push(imageDef) - 1;
828
- cachedImages[key] = index;
829
- return index;
830
- } else {
831
- throw new Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.");
832
- }
833
- }
834
- /**
835
- * Process sampler
836
- * @param {Texture} map Texture to process
837
- * @return {Integer} Index of the processed texture in the "samplers" array
838
- */
839
- processSampler(map) {
840
- const json = this.json;
841
- if (!json.samplers)
842
- json.samplers = [];
843
- const samplerDef = {
844
- magFilter: THREE_TO_WEBGL[map.magFilter],
845
- minFilter: THREE_TO_WEBGL[map.minFilter],
846
- wrapS: THREE_TO_WEBGL[map.wrapS],
847
- wrapT: THREE_TO_WEBGL[map.wrapT]
848
- };
849
- return json.samplers.push(samplerDef) - 1;
850
- }
851
- /**
852
- * Process texture
853
- * @param {Texture} map Map to process
854
- * @return {Integer} Index of the processed texture in the "textures" array
855
- */
856
- processTexture(map) {
857
- const writer = this;
858
- const options = writer.options;
859
- const cache = this.cache;
860
- const json = this.json;
861
- if (cache.textures.has(map))
862
- return cache.textures.get(map);
863
- if (!json.textures)
864
- json.textures = [];
865
- if (map instanceof THREE.CompressedTexture) {
866
- map = decompress(map, options.maxTextureSize);
867
- }
868
- let mimeType = map.userData.mimeType;
869
- if (mimeType === "image/webp")
870
- mimeType = "image/png";
871
- const textureDef = {
872
- sampler: this.processSampler(map),
873
- source: this.processImage(map.image, map.format, map.flipY, mimeType)
874
- };
875
- if (map.name)
876
- textureDef.name = map.name;
877
- this._invokeAll(function(ext) {
878
- ext.writeTexture && ext.writeTexture(map, textureDef);
879
- });
880
- const index = json.textures.push(textureDef) - 1;
881
- cache.textures.set(map, index);
882
- return index;
883
- }
884
- /**
885
- * Process material
886
- * @param {THREE.Material} material Material to process
887
- * @return {Integer|null} Index of the processed material in the "materials" array
888
- */
889
- processMaterial(material) {
890
- const cache = this.cache;
891
- const json = this.json;
892
- if (cache.materials.has(material))
893
- return cache.materials.get(material);
894
- if (material.isShaderMaterial) {
895
- console.warn("GLTFExporter: THREE.ShaderMaterial not supported.");
896
- return null;
897
- }
898
- if (!json.materials)
899
- json.materials = [];
900
- const materialDef = { pbrMetallicRoughness: {} };
901
- if (material.isMeshStandardMaterial !== true && material.isMeshBasicMaterial !== true) {
902
- console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");
903
- }
904
- const color = material.color.toArray().concat([material.opacity]);
905
- if (!equalArray(color, [1, 1, 1, 1])) {
906
- materialDef.pbrMetallicRoughness.baseColorFactor = color;
907
- }
908
- if (material.isMeshStandardMaterial) {
909
- materialDef.pbrMetallicRoughness.metallicFactor = material.metalness;
910
- materialDef.pbrMetallicRoughness.roughnessFactor = material.roughness;
911
- } else {
912
- materialDef.pbrMetallicRoughness.metallicFactor = 0.5;
913
- materialDef.pbrMetallicRoughness.roughnessFactor = 0.5;
914
- }
915
- if (material.metalnessMap || material.roughnessMap) {
916
- const metalRoughTexture = this.buildMetalRoughTexture(material.metalnessMap, material.roughnessMap);
917
- const metalRoughMapDef = {
918
- index: this.processTexture(metalRoughTexture),
919
- channel: metalRoughTexture.channel
920
- };
921
- this.applyTextureTransform(metalRoughMapDef, metalRoughTexture);
922
- materialDef.pbrMetallicRoughness.metallicRoughnessTexture = metalRoughMapDef;
923
- }
924
- if (material.map) {
925
- const baseColorMapDef = {
926
- index: this.processTexture(material.map),
927
- texCoord: material.map.channel
928
- };
929
- this.applyTextureTransform(baseColorMapDef, material.map);
930
- materialDef.pbrMetallicRoughness.baseColorTexture = baseColorMapDef;
931
- }
932
- if (material.emissive) {
933
- const emissive = material.emissive;
934
- const maxEmissiveComponent = Math.max(emissive.r, emissive.g, emissive.b);
935
- if (maxEmissiveComponent > 0) {
936
- materialDef.emissiveFactor = material.emissive.toArray();
937
- }
938
- if (material.emissiveMap) {
939
- const emissiveMapDef = {
940
- index: this.processTexture(material.emissiveMap),
941
- texCoord: material.emissiveMap.channel
942
- };
943
- this.applyTextureTransform(emissiveMapDef, material.emissiveMap);
944
- materialDef.emissiveTexture = emissiveMapDef;
945
- }
946
- }
947
- if (material.normalMap) {
948
- const normalMapDef = {
949
- index: this.processTexture(material.normalMap),
950
- texCoord: material.normalMap.channel
951
- };
952
- if (material.normalScale && material.normalScale.x !== 1) {
953
- normalMapDef.scale = material.normalScale.x;
954
- }
955
- this.applyTextureTransform(normalMapDef, material.normalMap);
956
- materialDef.normalTexture = normalMapDef;
957
- }
958
- if (material.aoMap) {
959
- const occlusionMapDef = {
960
- index: this.processTexture(material.aoMap),
961
- texCoord: material.aoMap.channel
962
- };
963
- if (material.aoMapIntensity !== 1) {
964
- occlusionMapDef.strength = material.aoMapIntensity;
965
- }
966
- this.applyTextureTransform(occlusionMapDef, material.aoMap);
967
- materialDef.occlusionTexture = occlusionMapDef;
968
- }
969
- if (material.transparent) {
970
- materialDef.alphaMode = "BLEND";
971
- } else {
972
- if (material.alphaTest > 0) {
973
- materialDef.alphaMode = "MASK";
974
- materialDef.alphaCutoff = material.alphaTest;
975
- }
976
- }
977
- if (material.side === THREE.DoubleSide)
978
- materialDef.doubleSided = true;
979
- if (material.name !== "")
980
- materialDef.name = material.name;
981
- this.serializeUserData(material, materialDef);
982
- this._invokeAll(function(ext) {
983
- ext.writeMaterial && ext.writeMaterial(material, materialDef);
984
- });
985
- const index = json.materials.push(materialDef) - 1;
986
- cache.materials.set(material, index);
987
- return index;
988
- }
989
- /**
990
- * Process mesh
991
- * @param {THREE.Mesh} mesh Mesh to process
992
- * @return {Integer|null} Index of the processed mesh in the "meshes" array
993
- */
994
- processMesh(mesh) {
995
- const cache = this.cache;
996
- const json = this.json;
997
- const meshCacheKeyParts = [mesh.geometry.uuid];
998
- if (Array.isArray(mesh.material)) {
999
- for (let i = 0, l = mesh.material.length; i < l; i++) {
1000
- meshCacheKeyParts.push(mesh.material[i].uuid);
1001
- }
1002
- } else {
1003
- meshCacheKeyParts.push(mesh.material.uuid);
1004
- }
1005
- const meshCacheKey = meshCacheKeyParts.join(":");
1006
- if (cache.meshes.has(meshCacheKey))
1007
- return cache.meshes.get(meshCacheKey);
1008
- const geometry = mesh.geometry;
1009
- let mode;
1010
- if (mesh.isLineSegments) {
1011
- mode = WEBGL_CONSTANTS.LINES;
1012
- } else if (mesh.isLineLoop) {
1013
- mode = WEBGL_CONSTANTS.LINE_LOOP;
1014
- } else if (mesh.isLine) {
1015
- mode = WEBGL_CONSTANTS.LINE_STRIP;
1016
- } else if (mesh.isPoints) {
1017
- mode = WEBGL_CONSTANTS.POINTS;
1018
- } else {
1019
- mode = mesh.material.wireframe ? WEBGL_CONSTANTS.LINES : WEBGL_CONSTANTS.TRIANGLES;
1020
- }
1021
- const meshDef = {};
1022
- const attributes = {};
1023
- const primitives = [];
1024
- const targets = [];
1025
- const nameConversion = {
1026
- uv: "TEXCOORD_0",
1027
- [THREE.REVISION.replace(/\D+/g, "") >= 152 ? "uv1" : "uv2"]: "TEXCOORD_1",
1028
- color: "COLOR_0",
1029
- skinWeight: "WEIGHTS_0",
1030
- skinIndex: "JOINTS_0"
1031
- };
1032
- const originalNormal = geometry.getAttribute("normal");
1033
- if (originalNormal !== void 0 && !this.isNormalizedNormalAttribute(originalNormal)) {
1034
- console.warn("THREE.GLTFExporter: Creating normalized normal attribute from the non-normalized one.");
1035
- geometry.setAttribute("normal", this.createNormalizedNormalAttribute(originalNormal));
1036
- }
1037
- let modifiedAttribute = null;
1038
- for (let attributeName in geometry.attributes) {
1039
- if (attributeName.slice(0, 5) === "morph")
1040
- continue;
1041
- const attribute = geometry.attributes[attributeName];
1042
- attributeName = nameConversion[attributeName] || attributeName.toUpperCase();
1043
- const validVertexAttributes = /^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/;
1044
- if (!validVertexAttributes.test(attributeName))
1045
- attributeName = "_" + attributeName;
1046
- if (cache.attributes.has(this.getUID(attribute))) {
1047
- attributes[attributeName] = cache.attributes.get(this.getUID(attribute));
1048
- continue;
1049
- }
1050
- modifiedAttribute = null;
1051
- const array = attribute.array;
1052
- if (attributeName === "JOINTS_0" && !(array instanceof Uint16Array) && !(array instanceof Uint8Array)) {
1053
- console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.');
1054
- modifiedAttribute = new THREE.BufferAttribute(new Uint16Array(array), attribute.itemSize, attribute.normalized);
1055
- }
1056
- const accessor = this.processAccessor(modifiedAttribute || attribute, geometry);
1057
- if (accessor !== null) {
1058
- if (!attributeName.startsWith("_")) {
1059
- this.detectMeshQuantization(attributeName, attribute);
1060
- }
1061
- attributes[attributeName] = accessor;
1062
- cache.attributes.set(this.getUID(attribute), accessor);
1063
- }
1064
- }
1065
- if (originalNormal !== void 0)
1066
- geometry.setAttribute("normal", originalNormal);
1067
- if (Object.keys(attributes).length === 0)
1068
- return null;
1069
- if (mesh.morphTargetInfluences !== void 0 && mesh.morphTargetInfluences.length > 0) {
1070
- const weights = [];
1071
- const targetNames = [];
1072
- const reverseDictionary = {};
1073
- if (mesh.morphTargetDictionary !== void 0) {
1074
- for (const key in mesh.morphTargetDictionary) {
1075
- reverseDictionary[mesh.morphTargetDictionary[key]] = key;
1076
- }
1077
- }
1078
- for (let i = 0; i < mesh.morphTargetInfluences.length; ++i) {
1079
- const target = {};
1080
- let warned = false;
1081
- for (const attributeName in geometry.morphAttributes) {
1082
- if (attributeName !== "position" && attributeName !== "normal") {
1083
- if (!warned) {
1084
- console.warn("GLTFExporter: Only POSITION and NORMAL morph are supported.");
1085
- warned = true;
1086
- }
1087
- continue;
1088
- }
1089
- const attribute = geometry.morphAttributes[attributeName][i];
1090
- const gltfAttributeName = attributeName.toUpperCase();
1091
- const baseAttribute = geometry.attributes[attributeName];
1092
- if (cache.attributes.has(this.getUID(attribute, true))) {
1093
- target[gltfAttributeName] = cache.attributes.get(this.getUID(attribute, true));
1094
- continue;
1095
- }
1096
- const relativeAttribute = attribute.clone();
1097
- if (!geometry.morphTargetsRelative) {
1098
- for (let j = 0, jl = attribute.count; j < jl; j++) {
1099
- for (let a = 0; a < attribute.itemSize; a++) {
1100
- if (a === 0)
1101
- relativeAttribute.setX(j, attribute.getX(j) - baseAttribute.getX(j));
1102
- if (a === 1)
1103
- relativeAttribute.setY(j, attribute.getY(j) - baseAttribute.getY(j));
1104
- if (a === 2)
1105
- relativeAttribute.setZ(j, attribute.getZ(j) - baseAttribute.getZ(j));
1106
- if (a === 3)
1107
- relativeAttribute.setW(j, attribute.getW(j) - baseAttribute.getW(j));
1108
- }
1109
- }
1110
- }
1111
- target[gltfAttributeName] = this.processAccessor(relativeAttribute, geometry);
1112
- cache.attributes.set(this.getUID(baseAttribute, true), target[gltfAttributeName]);
1113
- }
1114
- targets.push(target);
1115
- weights.push(mesh.morphTargetInfluences[i]);
1116
- if (mesh.morphTargetDictionary !== void 0)
1117
- targetNames.push(reverseDictionary[i]);
1118
- }
1119
- meshDef.weights = weights;
1120
- if (targetNames.length > 0) {
1121
- meshDef.extras = {};
1122
- meshDef.extras.targetNames = targetNames;
1123
- }
1124
- }
1125
- const isMultiMaterial = Array.isArray(mesh.material);
1126
- if (isMultiMaterial && geometry.groups.length === 0)
1127
- return null;
1128
- const materials = isMultiMaterial ? mesh.material : [mesh.material];
1129
- const groups = isMultiMaterial ? geometry.groups : [{ materialIndex: 0, start: void 0, count: void 0 }];
1130
- for (let i = 0, il = groups.length; i < il; i++) {
1131
- const primitive = {
1132
- mode,
1133
- attributes
1134
- };
1135
- this.serializeUserData(geometry, primitive);
1136
- if (targets.length > 0)
1137
- primitive.targets = targets;
1138
- if (geometry.index !== null) {
1139
- let cacheKey = this.getUID(geometry.index);
1140
- if (groups[i].start !== void 0 || groups[i].count !== void 0) {
1141
- cacheKey += ":" + groups[i].start + ":" + groups[i].count;
1142
- }
1143
- if (cache.attributes.has(cacheKey)) {
1144
- primitive.indices = cache.attributes.get(cacheKey);
1145
- } else {
1146
- primitive.indices = this.processAccessor(geometry.index, geometry, groups[i].start, groups[i].count);
1147
- cache.attributes.set(cacheKey, primitive.indices);
1148
- }
1149
- if (primitive.indices === null)
1150
- delete primitive.indices;
1151
- }
1152
- const material = this.processMaterial(materials[groups[i].materialIndex]);
1153
- if (material !== null)
1154
- primitive.material = material;
1155
- primitives.push(primitive);
1156
- }
1157
- meshDef.primitives = primitives;
1158
- if (!json.meshes)
1159
- json.meshes = [];
1160
- this._invokeAll(function(ext) {
1161
- ext.writeMesh && ext.writeMesh(mesh, meshDef);
1162
- });
1163
- const index = json.meshes.push(meshDef) - 1;
1164
- cache.meshes.set(meshCacheKey, index);
1165
- return index;
1166
- }
1167
- /**
1168
- * If a vertex attribute with a
1169
- * [non-standard data type](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview)
1170
- * is used, it is checked whether it is a valid data type according to the
1171
- * [KHR_mesh_quantization](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md)
1172
- * extension.
1173
- * In this case the extension is automatically added to the list of used extensions.
1174
- *
1175
- * @param {string} attributeName
1176
- * @param {THREE.BufferAttribute} attribute
1177
- */
1178
- detectMeshQuantization(attributeName, attribute) {
1179
- if (this.extensionsUsed[KHR_MESH_QUANTIZATION])
1180
- return;
1181
- let attrType = void 0;
1182
- switch (attribute.array.constructor) {
1183
- case Int8Array:
1184
- attrType = "byte";
1185
- break;
1186
- case Uint8Array:
1187
- attrType = "unsigned byte";
1188
- break;
1189
- case Int16Array:
1190
- attrType = "short";
1191
- break;
1192
- case Uint16Array:
1193
- attrType = "unsigned short";
1194
- break;
1195
- default:
1196
- return;
1197
- }
1198
- if (attribute.normalized)
1199
- attrType += " normalized";
1200
- const attrNamePrefix = attributeName.split("_", 1)[0];
1201
- if (KHR_mesh_quantization_ExtraAttrTypes[attrNamePrefix] && KHR_mesh_quantization_ExtraAttrTypes[attrNamePrefix].includes(attrType)) {
1202
- this.extensionsUsed[KHR_MESH_QUANTIZATION] = true;
1203
- this.extensionsRequired[KHR_MESH_QUANTIZATION] = true;
1204
- }
1205
- }
1206
- /**
1207
- * Process camera
1208
- * @param {THREE.Camera} camera Camera to process
1209
- * @return {Integer} Index of the processed mesh in the "camera" array
1210
- */
1211
- processCamera(camera) {
1212
- const json = this.json;
1213
- if (!json.cameras)
1214
- json.cameras = [];
1215
- const isOrtho = camera.isOrthographicCamera;
1216
- const cameraDef = {
1217
- type: isOrtho ? "orthographic" : "perspective"
1218
- };
1219
- if (isOrtho) {
1220
- cameraDef.orthographic = {
1221
- xmag: camera.right * 2,
1222
- ymag: camera.top * 2,
1223
- zfar: camera.far <= 0 ? 1e-3 : camera.far,
1224
- znear: camera.near < 0 ? 0 : camera.near
1225
- };
1226
- } else {
1227
- cameraDef.perspective = {
1228
- aspectRatio: camera.aspect,
1229
- yfov: THREE.MathUtils.degToRad(camera.fov),
1230
- zfar: camera.far <= 0 ? 1e-3 : camera.far,
1231
- znear: camera.near < 0 ? 0 : camera.near
1232
- };
1233
- }
1234
- if (camera.name !== "")
1235
- cameraDef.name = camera.type;
1236
- return json.cameras.push(cameraDef) - 1;
1237
- }
1238
- /**
1239
- * Creates glTF animation entry from AnimationClip object.
1240
- *
1241
- * Status:
1242
- * - Only properties listed in PATH_PROPERTIES may be animated.
1243
- *
1244
- * @param {THREE.AnimationClip} clip
1245
- * @param {THREE.Object3D} root
1246
- * @return {number|null}
1247
- */
1248
- processAnimation(clip, root) {
1249
- const json = this.json;
1250
- const nodeMap = this.nodeMap;
1251
- if (!json.animations)
1252
- json.animations = [];
1253
- clip = GLTFExporter.Utils.mergeMorphTargetTracks(clip.clone(), root);
1254
- const tracks = clip.tracks;
1255
- const channels = [];
1256
- const samplers = [];
1257
- for (let i = 0; i < tracks.length; ++i) {
1258
- const track = tracks[i];
1259
- const trackBinding = THREE.PropertyBinding.parseTrackName(track.name);
1260
- let trackNode = THREE.PropertyBinding.findNode(root, trackBinding.nodeName);
1261
- const trackProperty = PATH_PROPERTIES[trackBinding.propertyName];
1262
- if (trackBinding.objectName === "bones") {
1263
- if (trackNode.isSkinnedMesh === true) {
1264
- trackNode = trackNode.skeleton.getBoneByName(trackBinding.objectIndex);
1265
- } else {
1266
- trackNode = void 0;
1267
- }
1268
- }
1269
- if (!trackNode || !trackProperty) {
1270
- console.warn('THREE.GLTFExporter: Could not export animation track "%s".', track.name);
1271
- return null;
1272
- }
1273
- const inputItemSize = 1;
1274
- let outputItemSize = track.values.length / track.times.length;
1275
- if (trackProperty === PATH_PROPERTIES.morphTargetInfluences) {
1276
- outputItemSize /= trackNode.morphTargetInfluences.length;
1277
- }
1278
- let interpolation;
1279
- if (track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === true) {
1280
- interpolation = "CUBICSPLINE";
1281
- outputItemSize /= 3;
1282
- } else if (track.getInterpolation() === THREE.InterpolateDiscrete) {
1283
- interpolation = "STEP";
1284
- } else {
1285
- interpolation = "LINEAR";
1286
- }
1287
- samplers.push({
1288
- input: this.processAccessor(new THREE.BufferAttribute(track.times, inputItemSize)),
1289
- output: this.processAccessor(new THREE.BufferAttribute(track.values, outputItemSize)),
1290
- interpolation
1291
- });
1292
- channels.push({
1293
- sampler: samplers.length - 1,
1294
- target: {
1295
- node: nodeMap.get(trackNode),
1296
- path: trackProperty
1297
- }
1298
- });
1299
- }
1300
- json.animations.push({
1301
- name: clip.name || "clip_" + json.animations.length,
1302
- samplers,
1303
- channels
1304
- });
1305
- return json.animations.length - 1;
1306
- }
1307
- /**
1308
- * @param {THREE.Object3D} object
1309
- * @return {number|null}
1310
- */
1311
- processSkin(object) {
1312
- const json = this.json;
1313
- const nodeMap = this.nodeMap;
1314
- const node = json.nodes[nodeMap.get(object)];
1315
- const skeleton = object.skeleton;
1316
- if (skeleton === void 0)
1317
- return null;
1318
- const rootJoint = object.skeleton.bones[0];
1319
- if (rootJoint === void 0)
1320
- return null;
1321
- const joints = [];
1322
- const inverseBindMatrices = new Float32Array(skeleton.bones.length * 16);
1323
- const temporaryBoneInverse = new THREE.Matrix4();
1324
- for (let i = 0; i < skeleton.bones.length; ++i) {
1325
- joints.push(nodeMap.get(skeleton.bones[i]));
1326
- temporaryBoneInverse.copy(skeleton.boneInverses[i]);
1327
- temporaryBoneInverse.multiply(object.bindMatrix).toArray(inverseBindMatrices, i * 16);
1328
- }
1329
- if (json.skins === void 0)
1330
- json.skins = [];
1331
- json.skins.push({
1332
- inverseBindMatrices: this.processAccessor(new THREE.BufferAttribute(inverseBindMatrices, 16)),
1333
- joints,
1334
- skeleton: nodeMap.get(rootJoint)
1335
- });
1336
- const skinIndex = node.skin = json.skins.length - 1;
1337
- return skinIndex;
1338
- }
1339
- /**
1340
- * Process Object3D node
1341
- * @param {THREE.Object3D} node Object3D to processNode
1342
- * @return {Integer} Index of the node in the nodes list
1343
- */
1344
- processNode(object) {
1345
- const json = this.json;
1346
- const options = this.options;
1347
- const nodeMap = this.nodeMap;
1348
- if (!json.nodes)
1349
- json.nodes = [];
1350
- const nodeDef = {};
1351
- if (options.trs) {
1352
- const rotation = object.quaternion.toArray();
1353
- const position = object.position.toArray();
1354
- const scale = object.scale.toArray();
1355
- if (!equalArray(rotation, [0, 0, 0, 1])) {
1356
- nodeDef.rotation = rotation;
1357
- }
1358
- if (!equalArray(position, [0, 0, 0])) {
1359
- nodeDef.translation = position;
1360
- }
1361
- if (!equalArray(scale, [1, 1, 1])) {
1362
- nodeDef.scale = scale;
1363
- }
1364
- } else {
1365
- if (object.matrixAutoUpdate) {
1366
- object.updateMatrix();
1367
- }
1368
- if (isIdentityMatrix(object.matrix) === false) {
1369
- nodeDef.matrix = object.matrix.elements;
1370
- }
1371
- }
1372
- if (object.name !== "")
1373
- nodeDef.name = String(object.name);
1374
- this.serializeUserData(object, nodeDef);
1375
- if (object.isMesh || object.isLine || object.isPoints) {
1376
- const meshIndex = this.processMesh(object);
1377
- if (meshIndex !== null)
1378
- nodeDef.mesh = meshIndex;
1379
- } else if (object.isCamera) {
1380
- nodeDef.camera = this.processCamera(object);
1381
- }
1382
- if (object.isSkinnedMesh)
1383
- this.skins.push(object);
1384
- if (object.children.length > 0) {
1385
- const children = [];
1386
- for (let i = 0, l = object.children.length; i < l; i++) {
1387
- const child = object.children[i];
1388
- if (child.visible || options.onlyVisible === false) {
1389
- const nodeIndex2 = this.processNode(child);
1390
- if (nodeIndex2 !== null)
1391
- children.push(nodeIndex2);
1392
- }
1393
- }
1394
- if (children.length > 0)
1395
- nodeDef.children = children;
1396
- }
1397
- this._invokeAll(function(ext) {
1398
- ext.writeNode && ext.writeNode(object, nodeDef);
1399
- });
1400
- const nodeIndex = json.nodes.push(nodeDef) - 1;
1401
- nodeMap.set(object, nodeIndex);
1402
- return nodeIndex;
1403
- }
1404
- /**
1405
- * Process Scene
1406
- * @param {Scene} node Scene to process
1407
- */
1408
- processScene(scene) {
1409
- const json = this.json;
1410
- const options = this.options;
1411
- if (!json.scenes) {
1412
- json.scenes = [];
1413
- json.scene = 0;
1414
- }
1415
- const sceneDef = {};
1416
- if (scene.name !== "")
1417
- sceneDef.name = scene.name;
1418
- json.scenes.push(sceneDef);
1419
- const nodes = [];
1420
- for (let i = 0, l = scene.children.length; i < l; i++) {
1421
- const child = scene.children[i];
1422
- if (child.visible || options.onlyVisible === false) {
1423
- const nodeIndex = this.processNode(child);
1424
- if (nodeIndex !== null)
1425
- nodes.push(nodeIndex);
1426
- }
1427
- }
1428
- if (nodes.length > 0)
1429
- sceneDef.nodes = nodes;
1430
- this.serializeUserData(scene, sceneDef);
1431
- }
1432
- /**
1433
- * Creates a Scene to hold a list of objects and parse it
1434
- * @param {Array} objects List of objects to process
1435
- */
1436
- processObjects(objects) {
1437
- const scene = new THREE.Scene();
1438
- scene.name = "AuxScene";
1439
- for (let i = 0; i < objects.length; i++) {
1440
- scene.children.push(objects[i]);
1441
- }
1442
- this.processScene(scene);
1443
- }
1444
- /**
1445
- * @param {THREE.Object3D|Array<THREE.Object3D>} input
1446
- */
1447
- processInput(input) {
1448
- const options = this.options;
1449
- input = input instanceof Array ? input : [input];
1450
- this._invokeAll(function(ext) {
1451
- ext.beforeParse && ext.beforeParse(input);
1452
- });
1453
- const objectsWithoutScene = [];
1454
- for (let i = 0; i < input.length; i++) {
1455
- if (input[i] instanceof THREE.Scene) {
1456
- this.processScene(input[i]);
1457
- } else {
1458
- objectsWithoutScene.push(input[i]);
1459
- }
1460
- }
1461
- if (objectsWithoutScene.length > 0)
1462
- this.processObjects(objectsWithoutScene);
1463
- for (let i = 0; i < this.skins.length; ++i) {
1464
- this.processSkin(this.skins[i]);
1465
- }
1466
- for (let i = 0; i < options.animations.length; ++i) {
1467
- this.processAnimation(options.animations[i], input[0]);
1468
- }
1469
- this._invokeAll(function(ext) {
1470
- ext.afterParse && ext.afterParse(input);
1471
- });
1472
- }
1473
- _invokeAll(func) {
1474
- for (let i = 0, il = this.plugins.length; i < il; i++) {
1475
- func(this.plugins[i]);
1476
- }
1477
- }
1478
- }
1479
- class GLTFLightExtension {
1480
- constructor(writer) {
1481
- this.writer = writer;
1482
- this.name = "KHR_lights_punctual";
1483
- }
1484
- writeNode(light, nodeDef) {
1485
- if (!light.isLight)
1486
- return;
1487
- if (!light.isDirectionalLight && !light.isPointLight && !light.isSpotLight) {
1488
- console.warn("THREE.GLTFExporter: Only directional, point, and spot lights are supported.", light);
1489
- return;
1490
- }
1491
- const writer = this.writer;
1492
- const json = writer.json;
1493
- const extensionsUsed = writer.extensionsUsed;
1494
- const lightDef = {};
1495
- if (light.name)
1496
- lightDef.name = light.name;
1497
- lightDef.color = light.color.toArray();
1498
- lightDef.intensity = light.intensity;
1499
- if (light.isDirectionalLight) {
1500
- lightDef.type = "directional";
1501
- } else if (light.isPointLight) {
1502
- lightDef.type = "point";
1503
- if (light.distance > 0)
1504
- lightDef.range = light.distance;
1505
- } else if (light.isSpotLight) {
1506
- lightDef.type = "spot";
1507
- if (light.distance > 0)
1508
- lightDef.range = light.distance;
1509
- lightDef.spot = {};
1510
- lightDef.spot.innerConeAngle = (light.penumbra - 1) * light.angle * -1;
1511
- lightDef.spot.outerConeAngle = light.angle;
1512
- }
1513
- if (light.decay !== void 0 && light.decay !== 2) {
1514
- console.warn(
1515
- "THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."
1516
- );
1517
- }
1518
- if (light.target && (light.target.parent !== light || light.target.position.x !== 0 || light.target.position.y !== 0 || light.target.position.z !== -1)) {
1519
- console.warn(
1520
- "THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1."
1521
- );
1522
- }
1523
- if (!extensionsUsed[this.name]) {
1524
- json.extensions = json.extensions || {};
1525
- json.extensions[this.name] = { lights: [] };
1526
- extensionsUsed[this.name] = true;
1527
- }
1528
- const lights = json.extensions[this.name].lights;
1529
- lights.push(lightDef);
1530
- nodeDef.extensions = nodeDef.extensions || {};
1531
- nodeDef.extensions[this.name] = { light: lights.length - 1 };
1532
- }
1533
- }
1534
- class GLTFMaterialsUnlitExtension {
1535
- constructor(writer) {
1536
- this.writer = writer;
1537
- this.name = "KHR_materials_unlit";
1538
- }
1539
- writeMaterial(material, materialDef) {
1540
- if (!material.isMeshBasicMaterial)
1541
- return;
1542
- const writer = this.writer;
1543
- const extensionsUsed = writer.extensionsUsed;
1544
- materialDef.extensions = materialDef.extensions || {};
1545
- materialDef.extensions[this.name] = {};
1546
- extensionsUsed[this.name] = true;
1547
- materialDef.pbrMetallicRoughness.metallicFactor = 0;
1548
- materialDef.pbrMetallicRoughness.roughnessFactor = 0.9;
1549
- }
1550
- }
1551
- class GLTFMaterialsClearcoatExtension {
1552
- constructor(writer) {
1553
- this.writer = writer;
1554
- this.name = "KHR_materials_clearcoat";
1555
- }
1556
- writeMaterial(material, materialDef) {
1557
- if (!material.isMeshPhysicalMaterial || material.clearcoat === 0)
1558
- return;
1559
- const writer = this.writer;
1560
- const extensionsUsed = writer.extensionsUsed;
1561
- const extensionDef = {};
1562
- extensionDef.clearcoatFactor = material.clearcoat;
1563
- if (material.clearcoatMap) {
1564
- const clearcoatMapDef = {
1565
- index: writer.processTexture(material.clearcoatMap),
1566
- texCoord: material.clearcoatMap.channel
1567
- };
1568
- writer.applyTextureTransform(clearcoatMapDef, material.clearcoatMap);
1569
- extensionDef.clearcoatTexture = clearcoatMapDef;
1570
- }
1571
- extensionDef.clearcoatRoughnessFactor = material.clearcoatRoughness;
1572
- if (material.clearcoatRoughnessMap) {
1573
- const clearcoatRoughnessMapDef = {
1574
- index: writer.processTexture(material.clearcoatRoughnessMap),
1575
- texCoord: material.clearcoatRoughnessMap.channel
1576
- };
1577
- writer.applyTextureTransform(clearcoatRoughnessMapDef, material.clearcoatRoughnessMap);
1578
- extensionDef.clearcoatRoughnessTexture = clearcoatRoughnessMapDef;
1579
- }
1580
- if (material.clearcoatNormalMap) {
1581
- const clearcoatNormalMapDef = {
1582
- index: writer.processTexture(material.clearcoatNormalMap),
1583
- texCoord: material.clearcoatNormalMap.channel
1584
- };
1585
- writer.applyTextureTransform(clearcoatNormalMapDef, material.clearcoatNormalMap);
1586
- extensionDef.clearcoatNormalTexture = clearcoatNormalMapDef;
1587
- }
1588
- materialDef.extensions = materialDef.extensions || {};
1589
- materialDef.extensions[this.name] = extensionDef;
1590
- extensionsUsed[this.name] = true;
1591
- }
1592
- }
1593
- class GLTFMaterialsIridescenceExtension {
1594
- constructor(writer) {
1595
- this.writer = writer;
1596
- this.name = "KHR_materials_iridescence";
1597
- }
1598
- writeMaterial(material, materialDef) {
1599
- if (!material.isMeshPhysicalMaterial || material.iridescence === 0)
1600
- return;
1601
- const writer = this.writer;
1602
- const extensionsUsed = writer.extensionsUsed;
1603
- const extensionDef = {};
1604
- extensionDef.iridescenceFactor = material.iridescence;
1605
- if (material.iridescenceMap) {
1606
- const iridescenceMapDef = {
1607
- index: writer.processTexture(material.iridescenceMap),
1608
- texCoord: material.iridescenceMap.channel
1609
- };
1610
- writer.applyTextureTransform(iridescenceMapDef, material.iridescenceMap);
1611
- extensionDef.iridescenceTexture = iridescenceMapDef;
1612
- }
1613
- extensionDef.iridescenceIor = material.iridescenceIOR;
1614
- extensionDef.iridescenceThicknessMinimum = material.iridescenceThicknessRange[0];
1615
- extensionDef.iridescenceThicknessMaximum = material.iridescenceThicknessRange[1];
1616
- if (material.iridescenceThicknessMap) {
1617
- const iridescenceThicknessMapDef = {
1618
- index: writer.processTexture(material.iridescenceThicknessMap),
1619
- texCoord: material.iridescenceThicknessMap.channel
1620
- };
1621
- writer.applyTextureTransform(iridescenceThicknessMapDef, material.iridescenceThicknessMap);
1622
- extensionDef.iridescenceThicknessTexture = iridescenceThicknessMapDef;
1623
- }
1624
- materialDef.extensions = materialDef.extensions || {};
1625
- materialDef.extensions[this.name] = extensionDef;
1626
- extensionsUsed[this.name] = true;
1627
- }
1628
- }
1629
- class GLTFMaterialsTransmissionExtension {
1630
- constructor(writer) {
1631
- this.writer = writer;
1632
- this.name = "KHR_materials_transmission";
1633
- }
1634
- writeMaterial(material, materialDef) {
1635
- if (!material.isMeshPhysicalMaterial || material.transmission === 0)
1636
- return;
1637
- const writer = this.writer;
1638
- const extensionsUsed = writer.extensionsUsed;
1639
- const extensionDef = {};
1640
- extensionDef.transmissionFactor = material.transmission;
1641
- if (material.transmissionMap) {
1642
- const transmissionMapDef = {
1643
- index: writer.processTexture(material.transmissionMap),
1644
- texCoord: material.transmissionMap.channel
1645
- };
1646
- writer.applyTextureTransform(transmissionMapDef, material.transmissionMap);
1647
- extensionDef.transmissionTexture = transmissionMapDef;
1648
- }
1649
- materialDef.extensions = materialDef.extensions || {};
1650
- materialDef.extensions[this.name] = extensionDef;
1651
- extensionsUsed[this.name] = true;
1652
- }
1653
- }
1654
- class GLTFMaterialsVolumeExtension {
1655
- constructor(writer) {
1656
- this.writer = writer;
1657
- this.name = "KHR_materials_volume";
1658
- }
1659
- writeMaterial(material, materialDef) {
1660
- if (!material.isMeshPhysicalMaterial || material.transmission === 0)
1661
- return;
1662
- const writer = this.writer;
1663
- const extensionsUsed = writer.extensionsUsed;
1664
- const extensionDef = {};
1665
- extensionDef.thicknessFactor = material.thickness;
1666
- if (material.thicknessMap) {
1667
- const thicknessMapDef = {
1668
- index: writer.processTexture(material.thicknessMap),
1669
- texCoord: material.thicknessMap.channel
1670
- };
1671
- writer.applyTextureTransform(thicknessMapDef, material.thicknessMap);
1672
- extensionDef.thicknessTexture = thicknessMapDef;
1673
- }
1674
- extensionDef.attenuationDistance = material.attenuationDistance;
1675
- extensionDef.attenuationColor = material.attenuationColor.toArray();
1676
- materialDef.extensions = materialDef.extensions || {};
1677
- materialDef.extensions[this.name] = extensionDef;
1678
- extensionsUsed[this.name] = true;
1679
- }
1680
- }
1681
- class GLTFMaterialsIorExtension {
1682
- constructor(writer) {
1683
- this.writer = writer;
1684
- this.name = "KHR_materials_ior";
1685
- }
1686
- writeMaterial(material, materialDef) {
1687
- if (!material.isMeshPhysicalMaterial || material.ior === 1.5)
1688
- return;
1689
- const writer = this.writer;
1690
- const extensionsUsed = writer.extensionsUsed;
1691
- const extensionDef = {};
1692
- extensionDef.ior = material.ior;
1693
- materialDef.extensions = materialDef.extensions || {};
1694
- materialDef.extensions[this.name] = extensionDef;
1695
- extensionsUsed[this.name] = true;
1696
- }
1697
- }
1698
- class GLTFMaterialsSpecularExtension {
1699
- constructor(writer) {
1700
- this.writer = writer;
1701
- this.name = "KHR_materials_specular";
1702
- }
1703
- writeMaterial(material, materialDef) {
1704
- if (!material.isMeshPhysicalMaterial || material.specularIntensity === 1 && material.specularColor.equals(DEFAULT_SPECULAR_COLOR) && !material.specularIntensityMap && !material.specularColorTexture)
1705
- return;
1706
- const writer = this.writer;
1707
- const extensionsUsed = writer.extensionsUsed;
1708
- const extensionDef = {};
1709
- if (material.specularIntensityMap) {
1710
- const specularIntensityMapDef = {
1711
- index: writer.processTexture(material.specularIntensityMap),
1712
- texCoord: material.specularIntensityMap.channel
1713
- };
1714
- writer.applyTextureTransform(specularIntensityMapDef, material.specularIntensityMap);
1715
- extensionDef.specularTexture = specularIntensityMapDef;
1716
- }
1717
- if (material.specularColorMap) {
1718
- const specularColorMapDef = {
1719
- index: writer.processTexture(material.specularColorMap),
1720
- texCoord: material.specularColorMap.channel
1721
- };
1722
- writer.applyTextureTransform(specularColorMapDef, material.specularColorMap);
1723
- extensionDef.specularColorTexture = specularColorMapDef;
1724
- }
1725
- extensionDef.specularFactor = material.specularIntensity;
1726
- extensionDef.specularColorFactor = material.specularColor.toArray();
1727
- materialDef.extensions = materialDef.extensions || {};
1728
- materialDef.extensions[this.name] = extensionDef;
1729
- extensionsUsed[this.name] = true;
1730
- }
1731
- }
1732
- class GLTFMaterialsSheenExtension {
1733
- constructor(writer) {
1734
- this.writer = writer;
1735
- this.name = "KHR_materials_sheen";
1736
- }
1737
- writeMaterial(material, materialDef) {
1738
- if (!material.isMeshPhysicalMaterial || material.sheen == 0)
1739
- return;
1740
- const writer = this.writer;
1741
- const extensionsUsed = writer.extensionsUsed;
1742
- const extensionDef = {};
1743
- if (material.sheenRoughnessMap) {
1744
- const sheenRoughnessMapDef = {
1745
- index: writer.processTexture(material.sheenRoughnessMap),
1746
- texCoord: material.sheenRoughnessMap.channel
1747
- };
1748
- writer.applyTextureTransform(sheenRoughnessMapDef, material.sheenRoughnessMap);
1749
- extensionDef.sheenRoughnessTexture = sheenRoughnessMapDef;
1750
- }
1751
- if (material.sheenColorMap) {
1752
- const sheenColorMapDef = {
1753
- index: writer.processTexture(material.sheenColorMap),
1754
- texCoord: material.sheenColorMap.channel
1755
- };
1756
- writer.applyTextureTransform(sheenColorMapDef, material.sheenColorMap);
1757
- extensionDef.sheenColorTexture = sheenColorMapDef;
1758
- }
1759
- extensionDef.sheenRoughnessFactor = material.sheenRoughness;
1760
- extensionDef.sheenColorFactor = material.sheenColor.toArray();
1761
- materialDef.extensions = materialDef.extensions || {};
1762
- materialDef.extensions[this.name] = extensionDef;
1763
- extensionsUsed[this.name] = true;
1764
- }
1765
- }
1766
- class GLTFMaterialsAnisotropyExtension {
1767
- constructor(writer) {
1768
- this.writer = writer;
1769
- this.name = "KHR_materials_anisotropy";
1770
- }
1771
- writeMaterial(material, materialDef) {
1772
- if (!material.isMeshPhysicalMaterial || material.anisotropy == 0)
1773
- return;
1774
- const writer = this.writer;
1775
- const extensionsUsed = writer.extensionsUsed;
1776
- const extensionDef = {};
1777
- if (material.anisotropyMap) {
1778
- const anisotropyMapDef = { index: writer.processTexture(material.anisotropyMap) };
1779
- writer.applyTextureTransform(anisotropyMapDef, material.anisotropyMap);
1780
- extensionDef.anisotropyTexture = anisotropyMapDef;
1781
- }
1782
- extensionDef.anisotropyStrength = material.anisotropy;
1783
- extensionDef.anisotropyRotation = material.anisotropyRotation;
1784
- materialDef.extensions = materialDef.extensions || {};
1785
- materialDef.extensions[this.name] = extensionDef;
1786
- extensionsUsed[this.name] = true;
1787
- }
1788
- }
1789
- class GLTFMaterialsEmissiveStrengthExtension {
1790
- constructor(writer) {
1791
- this.writer = writer;
1792
- this.name = "KHR_materials_emissive_strength";
1793
- }
1794
- writeMaterial(material, materialDef) {
1795
- if (!material.isMeshStandardMaterial || material.emissiveIntensity === 1)
1796
- return;
1797
- const writer = this.writer;
1798
- const extensionsUsed = writer.extensionsUsed;
1799
- const extensionDef = {};
1800
- extensionDef.emissiveStrength = material.emissiveIntensity;
1801
- materialDef.extensions = materialDef.extensions || {};
1802
- materialDef.extensions[this.name] = extensionDef;
1803
- extensionsUsed[this.name] = true;
1804
- }
1805
- }
1806
- GLTFExporter.Utils = {
1807
- insertKeyframe: function(track, time) {
1808
- const tolerance = 1e-3;
1809
- const valueSize = track.getValueSize();
1810
- const times = new track.TimeBufferType(track.times.length + 1);
1811
- const values = new track.ValueBufferType(track.values.length + valueSize);
1812
- const interpolant = track.createInterpolant(new track.ValueBufferType(valueSize));
1813
- let index;
1814
- if (track.times.length === 0) {
1815
- times[0] = time;
1816
- for (let i = 0; i < valueSize; i++) {
1817
- values[i] = 0;
1818
- }
1819
- index = 0;
1820
- } else if (time < track.times[0]) {
1821
- if (Math.abs(track.times[0] - time) < tolerance)
1822
- return 0;
1823
- times[0] = time;
1824
- times.set(track.times, 1);
1825
- values.set(interpolant.evaluate(time), 0);
1826
- values.set(track.values, valueSize);
1827
- index = 0;
1828
- } else if (time > track.times[track.times.length - 1]) {
1829
- if (Math.abs(track.times[track.times.length - 1] - time) < tolerance) {
1830
- return track.times.length - 1;
1831
- }
1832
- times[times.length - 1] = time;
1833
- times.set(track.times, 0);
1834
- values.set(track.values, 0);
1835
- values.set(interpolant.evaluate(time), track.values.length);
1836
- index = times.length - 1;
1837
- } else {
1838
- for (let i = 0; i < track.times.length; i++) {
1839
- if (Math.abs(track.times[i] - time) < tolerance)
1840
- return i;
1841
- if (track.times[i] < time && track.times[i + 1] > time) {
1842
- times.set(track.times.slice(0, i + 1), 0);
1843
- times[i + 1] = time;
1844
- times.set(track.times.slice(i + 1), i + 2);
1845
- values.set(track.values.slice(0, (i + 1) * valueSize), 0);
1846
- values.set(interpolant.evaluate(time), (i + 1) * valueSize);
1847
- values.set(track.values.slice((i + 1) * valueSize), (i + 2) * valueSize);
1848
- index = i + 1;
1849
- break;
1850
- }
1851
- }
1852
- }
1853
- track.times = times;
1854
- track.values = values;
1855
- return index;
1856
- },
1857
- mergeMorphTargetTracks: function(clip, root) {
1858
- const tracks = [];
1859
- const mergedTracks = {};
1860
- const sourceTracks = clip.tracks;
1861
- for (let i = 0; i < sourceTracks.length; ++i) {
1862
- let sourceTrack = sourceTracks[i];
1863
- const sourceTrackBinding = THREE.PropertyBinding.parseTrackName(sourceTrack.name);
1864
- const sourceTrackNode = THREE.PropertyBinding.findNode(root, sourceTrackBinding.nodeName);
1865
- if (sourceTrackBinding.propertyName !== "morphTargetInfluences" || sourceTrackBinding.propertyIndex === void 0) {
1866
- tracks.push(sourceTrack);
1867
- continue;
1868
- }
1869
- if (sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodDiscrete && sourceTrack.createInterpolant !== sourceTrack.InterpolantFactoryMethodLinear) {
1870
- if (sourceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
1871
- throw new Error("THREE.GLTFExporter: Cannot merge tracks with glTF CUBICSPLINE interpolation.");
1872
- }
1873
- console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead.");
1874
- sourceTrack = sourceTrack.clone();
1875
- sourceTrack.setInterpolation(THREE.InterpolateLinear);
1876
- }
1877
- const targetCount = sourceTrackNode.morphTargetInfluences.length;
1878
- const targetIndex = sourceTrackNode.morphTargetDictionary[sourceTrackBinding.propertyIndex];
1879
- if (targetIndex === void 0) {
1880
- throw new Error("THREE.GLTFExporter: Morph target name not found: " + sourceTrackBinding.propertyIndex);
1881
- }
1882
- let mergedTrack;
1883
- if (mergedTracks[sourceTrackNode.uuid] === void 0) {
1884
- mergedTrack = sourceTrack.clone();
1885
- const values = new mergedTrack.ValueBufferType(targetCount * mergedTrack.times.length);
1886
- for (let j = 0; j < mergedTrack.times.length; j++) {
1887
- values[j * targetCount + targetIndex] = mergedTrack.values[j];
1888
- }
1889
- mergedTrack.name = (sourceTrackBinding.nodeName || "") + ".morphTargetInfluences";
1890
- mergedTrack.values = values;
1891
- mergedTracks[sourceTrackNode.uuid] = mergedTrack;
1892
- tracks.push(mergedTrack);
1893
- continue;
1894
- }
1895
- const sourceInterpolant = sourceTrack.createInterpolant(new sourceTrack.ValueBufferType(1));
1896
- mergedTrack = mergedTracks[sourceTrackNode.uuid];
1897
- for (let j = 0; j < mergedTrack.times.length; j++) {
1898
- mergedTrack.values[j * targetCount + targetIndex] = sourceInterpolant.evaluate(mergedTrack.times[j]);
1899
- }
1900
- for (let j = 0; j < sourceTrack.times.length; j++) {
1901
- const keyframeIndex = this.insertKeyframe(mergedTrack, sourceTrack.times[j]);
1902
- mergedTrack.values[keyframeIndex * targetCount + targetIndex] = sourceTrack.values[j];
1903
- }
1904
- }
1905
- clip.tracks = tracks;
1906
- return clip;
1907
- }
1908
- };
1909
- exports.GLTFExporter = GLTFExporter;