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