three-stdlib 2.35.3 → 2.35.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (514) hide show
  1. package/_polyfill/CapsuleGeometry.cjs +20 -17
  2. package/_polyfill/CapsuleGeometry.cjs.map +1 -1
  3. package/_polyfill/CapsuleGeometry.js +20 -17
  4. package/_polyfill/CapsuleGeometry.js.map +1 -1
  5. package/_polyfill/constants.cjs +1 -1
  6. package/_polyfill/constants.cjs.map +1 -1
  7. package/_polyfill/constants.js +1 -1
  8. package/_polyfill/constants.js.map +1 -1
  9. package/animation/AnimationClipCreator.cjs +13 -13
  10. package/animation/AnimationClipCreator.cjs.map +1 -1
  11. package/animation/AnimationClipCreator.js +13 -13
  12. package/animation/AnimationClipCreator.js.map +1 -1
  13. package/animation/CCDIKSolver.cjs +11 -11
  14. package/animation/CCDIKSolver.cjs.map +1 -1
  15. package/animation/CCDIKSolver.js +12 -12
  16. package/animation/CCDIKSolver.js.map +1 -1
  17. package/animation/MMDAnimationHelper.cjs +1 -1
  18. package/animation/MMDAnimationHelper.cjs.map +1 -1
  19. package/animation/MMDAnimationHelper.js +1 -1
  20. package/animation/MMDAnimationHelper.js.map +1 -1
  21. package/animation/MMDPhysics.cjs +4 -4
  22. package/animation/MMDPhysics.cjs.map +1 -1
  23. package/animation/MMDPhysics.js +4 -4
  24. package/animation/MMDPhysics.js.map +1 -1
  25. package/controls/ArcballControls.cjs +2 -2
  26. package/controls/ArcballControls.cjs.map +1 -1
  27. package/controls/ArcballControls.js +3 -3
  28. package/controls/ArcballControls.js.map +1 -1
  29. package/controls/FirstPersonControls.cjs +1 -1
  30. package/controls/FirstPersonControls.cjs.map +1 -1
  31. package/controls/FirstPersonControls.js +1 -1
  32. package/controls/FirstPersonControls.js.map +1 -1
  33. package/controls/OrbitControls.cjs +2 -2
  34. package/controls/OrbitControls.cjs.map +1 -1
  35. package/controls/OrbitControls.js +3 -3
  36. package/controls/OrbitControls.js.map +1 -1
  37. package/controls/PointerLockControls.cjs +2 -2
  38. package/controls/PointerLockControls.cjs.map +1 -1
  39. package/controls/PointerLockControls.js +3 -3
  40. package/controls/PointerLockControls.js.map +1 -1
  41. package/csm/CSM.cjs +4 -4
  42. package/csm/CSM.cjs.map +1 -1
  43. package/csm/CSM.js +5 -5
  44. package/csm/CSM.js.map +1 -1
  45. package/csm/CSMFrustum.cjs +1 -1
  46. package/csm/CSMFrustum.cjs.map +1 -1
  47. package/csm/CSMFrustum.js +2 -2
  48. package/csm/CSMFrustum.js.map +1 -1
  49. package/deprecated/Geometry.cjs +722 -715
  50. package/deprecated/Geometry.cjs.map +1 -1
  51. package/deprecated/Geometry.js +723 -716
  52. package/deprecated/Geometry.js.map +1 -1
  53. package/effects/AnaglyphEffect.cjs +2 -1
  54. package/effects/AnaglyphEffect.cjs.map +1 -1
  55. package/effects/AnaglyphEffect.js +3 -2
  56. package/effects/AnaglyphEffect.js.map +1 -1
  57. package/effects/OutlineEffect.cjs +2 -1
  58. package/effects/OutlineEffect.cjs.map +1 -1
  59. package/effects/OutlineEffect.js +3 -2
  60. package/effects/OutlineEffect.js.map +1 -1
  61. package/effects/ParallaxBarrierEffect.cjs +2 -1
  62. package/effects/ParallaxBarrierEffect.cjs.map +1 -1
  63. package/effects/ParallaxBarrierEffect.js +3 -2
  64. package/effects/ParallaxBarrierEffect.js.map +1 -1
  65. package/exporters/DRACOExporter.cjs +133 -122
  66. package/exporters/DRACOExporter.cjs.map +1 -1
  67. package/exporters/DRACOExporter.d.ts +23 -21
  68. package/exporters/DRACOExporter.js +133 -122
  69. package/exporters/DRACOExporter.js.map +1 -1
  70. package/exporters/GLTFExporter.cjs +170 -167
  71. package/exporters/GLTFExporter.cjs.map +1 -1
  72. package/exporters/GLTFExporter.js +170 -167
  73. package/exporters/GLTFExporter.js.map +1 -1
  74. package/geometries/LightningStrike.cjs +524 -515
  75. package/geometries/LightningStrike.cjs.map +1 -1
  76. package/geometries/LightningStrike.js +524 -515
  77. package/geometries/LightningStrike.js.map +1 -1
  78. package/geometries/RoundedBoxGeometry.cjs +1 -1
  79. package/geometries/RoundedBoxGeometry.cjs.map +1 -1
  80. package/geometries/RoundedBoxGeometry.js +2 -2
  81. package/geometries/RoundedBoxGeometry.js.map +1 -1
  82. package/helpers/RaycasterHelper.cjs +2 -2
  83. package/helpers/RaycasterHelper.cjs.map +1 -1
  84. package/helpers/RaycasterHelper.js +3 -3
  85. package/helpers/RaycasterHelper.js.map +1 -1
  86. package/helpers/VertexNormalsHelper.cjs +3 -3
  87. package/helpers/VertexNormalsHelper.cjs.map +1 -1
  88. package/helpers/VertexNormalsHelper.js +4 -4
  89. package/helpers/VertexNormalsHelper.js.map +1 -1
  90. package/helpers/VertexTangentsHelper.cjs +2 -2
  91. package/helpers/VertexTangentsHelper.cjs.map +1 -1
  92. package/helpers/VertexTangentsHelper.js +3 -3
  93. package/helpers/VertexTangentsHelper.js.map +1 -1
  94. package/interactive/InteractiveGroup.cjs +1 -1
  95. package/interactive/InteractiveGroup.cjs.map +1 -1
  96. package/interactive/InteractiveGroup.js +2 -2
  97. package/interactive/InteractiveGroup.js.map +1 -1
  98. package/interactive/SelectionBox.cjs +15 -15
  99. package/interactive/SelectionBox.cjs.map +1 -1
  100. package/interactive/SelectionBox.js +16 -16
  101. package/interactive/SelectionBox.js.map +1 -1
  102. package/libs/chevrotain.cjs +1 -1
  103. package/libs/chevrotain.cjs.map +1 -1
  104. package/libs/chevrotain.js +1 -1
  105. package/libs/chevrotain.js.map +1 -1
  106. package/libs/lottie.cjs +1 -1
  107. package/libs/lottie.cjs.map +1 -1
  108. package/libs/lottie.js +1 -1
  109. package/libs/lottie.js.map +1 -1
  110. package/libs/opentype.cjs +1 -1
  111. package/libs/opentype.cjs.map +1 -1
  112. package/libs/opentype.js +1 -1
  113. package/libs/opentype.js.map +1 -1
  114. package/lights/LightProbeGenerator.cjs +5 -5
  115. package/lights/LightProbeGenerator.cjs.map +1 -1
  116. package/lights/LightProbeGenerator.js +5 -5
  117. package/lights/LightProbeGenerator.js.map +1 -1
  118. package/lights/RectAreaLightUniformsLib.cjs +3 -3
  119. package/lights/RectAreaLightUniformsLib.cjs.map +1 -1
  120. package/lights/RectAreaLightUniformsLib.js +3 -3
  121. package/lights/RectAreaLightUniformsLib.js.map +1 -1
  122. package/lines/LineMaterial.cjs +2 -1
  123. package/lines/LineMaterial.cjs.map +1 -1
  124. package/lines/LineMaterial.js +3 -2
  125. package/lines/LineMaterial.js.map +1 -1
  126. package/lines/LineSegments2.cjs +13 -13
  127. package/lines/LineSegments2.cjs.map +1 -1
  128. package/lines/LineSegments2.js +14 -14
  129. package/lines/LineSegments2.js.map +1 -1
  130. package/lines/LineSegmentsGeometry.cjs +2 -2
  131. package/lines/LineSegmentsGeometry.cjs.map +1 -1
  132. package/lines/LineSegmentsGeometry.js +3 -3
  133. package/lines/LineSegmentsGeometry.js.map +1 -1
  134. package/lines/Wireframe.cjs +3 -3
  135. package/lines/Wireframe.cjs.map +1 -1
  136. package/lines/Wireframe.js +4 -4
  137. package/lines/Wireframe.js.map +1 -1
  138. package/loaders/BasisTextureLoader.cjs +441 -435
  139. package/loaders/BasisTextureLoader.cjs.map +1 -1
  140. package/loaders/BasisTextureLoader.js +441 -435
  141. package/loaders/BasisTextureLoader.js.map +1 -1
  142. package/loaders/EXRLoader.cjs +2 -1
  143. package/loaders/EXRLoader.cjs.map +1 -1
  144. package/loaders/EXRLoader.js +3 -2
  145. package/loaders/EXRLoader.js.map +1 -1
  146. package/loaders/FBXLoader.cjs +2 -2
  147. package/loaders/FBXLoader.cjs.map +1 -1
  148. package/loaders/FBXLoader.js +2 -2
  149. package/loaders/FBXLoader.js.map +1 -1
  150. package/loaders/FontLoader.cjs +2 -2
  151. package/loaders/FontLoader.cjs.map +1 -1
  152. package/loaders/FontLoader.d.ts +2 -2
  153. package/loaders/FontLoader.js +2 -2
  154. package/loaders/FontLoader.js.map +1 -1
  155. package/loaders/GLTFLoader.cjs +2 -2
  156. package/loaders/GLTFLoader.cjs.map +1 -1
  157. package/loaders/GLTFLoader.js +2 -2
  158. package/loaders/GLTFLoader.js.map +1 -1
  159. package/loaders/KTX2Loader.cjs +377 -374
  160. package/loaders/KTX2Loader.cjs.map +1 -1
  161. package/loaders/KTX2Loader.js +377 -374
  162. package/loaders/KTX2Loader.js.map +1 -1
  163. package/loaders/LDrawLoader.cjs +5 -4
  164. package/loaders/LDrawLoader.cjs.map +1 -1
  165. package/loaders/LDrawLoader.js +6 -5
  166. package/loaders/LDrawLoader.js.map +1 -1
  167. package/loaders/OBJLoader.cjs +5 -5
  168. package/loaders/OBJLoader.cjs.map +1 -1
  169. package/loaders/OBJLoader.js +6 -6
  170. package/loaders/OBJLoader.js.map +1 -1
  171. package/loaders/PRWMLoader.cjs +46 -43
  172. package/loaders/PRWMLoader.cjs.map +1 -1
  173. package/loaders/PRWMLoader.js +46 -43
  174. package/loaders/PRWMLoader.js.map +1 -1
  175. package/loaders/SVGLoader.cjs +1694 -1688
  176. package/loaders/SVGLoader.cjs.map +1 -1
  177. package/loaders/SVGLoader.js +1694 -1688
  178. package/loaders/SVGLoader.js.map +1 -1
  179. package/loaders/XLoader.cjs +1 -1
  180. package/loaders/XLoader.cjs.map +1 -1
  181. package/loaders/XLoader.js +1 -1
  182. package/loaders/XLoader.js.map +1 -1
  183. package/math/Capsule.cjs +3 -3
  184. package/math/Capsule.cjs.map +1 -1
  185. package/math/Capsule.js +3 -3
  186. package/math/Capsule.js.map +1 -1
  187. package/math/ColorConverter.cjs +9 -9
  188. package/math/ColorConverter.cjs.map +1 -1
  189. package/math/ColorConverter.js +9 -9
  190. package/math/ColorConverter.js.map +1 -1
  191. package/math/ConvexHull.cjs +53 -50
  192. package/math/ConvexHull.cjs.map +1 -1
  193. package/math/ConvexHull.js +53 -50
  194. package/math/ConvexHull.js.map +1 -1
  195. package/math/ImprovedNoise.cjs +1 -1
  196. package/math/ImprovedNoise.cjs.map +1 -1
  197. package/math/ImprovedNoise.js +1 -1
  198. package/math/ImprovedNoise.js.map +1 -1
  199. package/math/MeshSurfaceSampler.cjs +2 -2
  200. package/math/MeshSurfaceSampler.cjs.map +1 -1
  201. package/math/MeshSurfaceSampler.js +2 -2
  202. package/math/MeshSurfaceSampler.js.map +1 -1
  203. package/math/OBB.cjs +14 -14
  204. package/math/OBB.cjs.map +1 -1
  205. package/math/OBB.js +15 -15
  206. package/math/OBB.js.map +1 -1
  207. package/math/Octree.cjs +7 -7
  208. package/math/Octree.cjs.map +1 -1
  209. package/math/Octree.js +8 -8
  210. package/math/Octree.js.map +1 -1
  211. package/misc/ConvexObjectBreaker.cjs +271 -268
  212. package/misc/ConvexObjectBreaker.cjs.map +1 -1
  213. package/misc/ConvexObjectBreaker.js +272 -269
  214. package/misc/ConvexObjectBreaker.js.map +1 -1
  215. package/misc/Gyroscope.cjs +6 -6
  216. package/misc/Gyroscope.cjs.map +1 -1
  217. package/misc/Gyroscope.js +7 -7
  218. package/misc/Gyroscope.js.map +1 -1
  219. package/modifiers/CurveModifier.cjs +1 -1
  220. package/modifiers/CurveModifier.cjs.map +1 -1
  221. package/modifiers/CurveModifier.js +2 -2
  222. package/modifiers/CurveModifier.js.map +1 -1
  223. package/modifiers/SimplifyModifier.cjs +2 -2
  224. package/modifiers/SimplifyModifier.cjs.map +1 -1
  225. package/modifiers/SimplifyModifier.js +2 -2
  226. package/modifiers/SimplifyModifier.js.map +1 -1
  227. package/objects/BatchedMesh.cjs +2 -2
  228. package/objects/BatchedMesh.cjs.map +1 -1
  229. package/objects/BatchedMesh.js +3 -3
  230. package/objects/BatchedMesh.js.map +1 -1
  231. package/objects/GroundProjectedEnv.cjs +2 -1
  232. package/objects/GroundProjectedEnv.cjs.map +1 -1
  233. package/objects/GroundProjectedEnv.js +3 -2
  234. package/objects/GroundProjectedEnv.js.map +1 -1
  235. package/objects/Lensflare.cjs +209 -206
  236. package/objects/Lensflare.cjs.map +1 -1
  237. package/objects/Lensflare.js +209 -206
  238. package/objects/Lensflare.js.map +1 -1
  239. package/objects/Reflector.cjs +154 -146
  240. package/objects/Reflector.cjs.map +1 -1
  241. package/objects/Reflector.js +154 -146
  242. package/objects/Reflector.js.map +1 -1
  243. package/objects/ReflectorForSSRPass.cjs +183 -180
  244. package/objects/ReflectorForSSRPass.cjs.map +1 -1
  245. package/objects/ReflectorForSSRPass.js +183 -180
  246. package/objects/ReflectorForSSRPass.js.map +1 -1
  247. package/objects/Refractor.cjs +164 -161
  248. package/objects/Refractor.cjs.map +1 -1
  249. package/objects/Refractor.js +164 -161
  250. package/objects/Refractor.js.map +1 -1
  251. package/objects/ShadowMesh.cjs +1 -1
  252. package/objects/ShadowMesh.cjs.map +1 -1
  253. package/objects/ShadowMesh.js +2 -2
  254. package/objects/ShadowMesh.js.map +1 -1
  255. package/objects/Sky.cjs +35 -32
  256. package/objects/Sky.cjs.map +1 -1
  257. package/objects/Sky.d.ts +100 -6
  258. package/objects/Sky.js +35 -32
  259. package/objects/Sky.js.map +1 -1
  260. package/objects/Water.cjs +2 -1
  261. package/objects/Water.cjs.map +1 -1
  262. package/objects/Water.js +3 -2
  263. package/objects/Water.js.map +1 -1
  264. package/objects/Water2.cjs +143 -140
  265. package/objects/Water2.cjs.map +1 -1
  266. package/objects/Water2.js +143 -140
  267. package/objects/Water2.js.map +1 -1
  268. package/package.json +1 -1
  269. package/postprocessing/SAOPass.cjs +267 -264
  270. package/postprocessing/SAOPass.cjs.map +1 -1
  271. package/postprocessing/SAOPass.js +267 -264
  272. package/postprocessing/SAOPass.js.map +1 -1
  273. package/postprocessing/SSAOPass.cjs +253 -250
  274. package/postprocessing/SSAOPass.cjs.map +1 -1
  275. package/postprocessing/SSAOPass.js +253 -250
  276. package/postprocessing/SSAOPass.js.map +1 -1
  277. package/postprocessing/SSRPass.cjs +379 -376
  278. package/postprocessing/SSRPass.cjs.map +1 -1
  279. package/postprocessing/SSRPass.js +379 -376
  280. package/postprocessing/SSRPass.js.map +1 -1
  281. package/postprocessing/UnrealBloomPass.cjs +205 -202
  282. package/postprocessing/UnrealBloomPass.cjs.map +1 -1
  283. package/postprocessing/UnrealBloomPass.js +205 -202
  284. package/postprocessing/UnrealBloomPass.js.map +1 -1
  285. package/renderers/CSS2DRenderer.cjs +5 -5
  286. package/renderers/CSS2DRenderer.cjs.map +1 -1
  287. package/renderers/CSS2DRenderer.js +5 -5
  288. package/renderers/CSS2DRenderer.js.map +1 -1
  289. package/renderers/CSS3DRenderer.cjs +5 -5
  290. package/renderers/CSS3DRenderer.cjs.map +1 -1
  291. package/renderers/CSS3DRenderer.js +6 -6
  292. package/renderers/CSS3DRenderer.js.map +1 -1
  293. package/shaders/ACESFilmicToneMappingShader.cjs +71 -46
  294. package/shaders/ACESFilmicToneMappingShader.cjs.map +1 -1
  295. package/shaders/ACESFilmicToneMappingShader.js +71 -46
  296. package/shaders/ACESFilmicToneMappingShader.js.map +1 -1
  297. package/shaders/AfterimageShader.cjs +41 -22
  298. package/shaders/AfterimageShader.cjs.map +1 -1
  299. package/shaders/AfterimageShader.js +41 -22
  300. package/shaders/AfterimageShader.js.map +1 -1
  301. package/shaders/BasicShader.cjs +20 -6
  302. package/shaders/BasicShader.cjs.map +1 -1
  303. package/shaders/BasicShader.js +20 -6
  304. package/shaders/BasicShader.js.map +1 -1
  305. package/shaders/BleachBypassShader.cjs +46 -26
  306. package/shaders/BleachBypassShader.cjs.map +1 -1
  307. package/shaders/BleachBypassShader.js +46 -26
  308. package/shaders/BleachBypassShader.js.map +1 -1
  309. package/shaders/BlendShader.cjs +33 -19
  310. package/shaders/BlendShader.cjs.map +1 -1
  311. package/shaders/BlendShader.js +33 -19
  312. package/shaders/BlendShader.js.map +1 -1
  313. package/shaders/BokehShader.cjs +117 -90
  314. package/shaders/BokehShader.cjs.map +1 -1
  315. package/shaders/BokehShader.js +117 -90
  316. package/shaders/BokehShader.js.map +1 -1
  317. package/shaders/BokehShader2.cjs +333 -232
  318. package/shaders/BokehShader2.cjs.map +1 -1
  319. package/shaders/BokehShader2.js +333 -232
  320. package/shaders/BokehShader2.js.map +1 -1
  321. package/shaders/BrightnessContrastShader.cjs +38 -22
  322. package/shaders/BrightnessContrastShader.cjs.map +1 -1
  323. package/shaders/BrightnessContrastShader.js +38 -22
  324. package/shaders/BrightnessContrastShader.js.map +1 -1
  325. package/shaders/ColorCorrectionShader.cjs +35 -21
  326. package/shaders/ColorCorrectionShader.cjs.map +1 -1
  327. package/shaders/ColorCorrectionShader.js +35 -21
  328. package/shaders/ColorCorrectionShader.js.map +1 -1
  329. package/shaders/ColorifyShader.cjs +34 -19
  330. package/shaders/ColorifyShader.cjs.map +1 -1
  331. package/shaders/ColorifyShader.js +34 -19
  332. package/shaders/ColorifyShader.js.map +1 -1
  333. package/shaders/ConvolutionShader.cjs +43 -24
  334. package/shaders/ConvolutionShader.cjs.map +1 -1
  335. package/shaders/ConvolutionShader.js +43 -24
  336. package/shaders/ConvolutionShader.js.map +1 -1
  337. package/shaders/CopyShader.cjs +30 -16
  338. package/shaders/CopyShader.cjs.map +1 -1
  339. package/shaders/CopyShader.js +30 -16
  340. package/shaders/CopyShader.js.map +1 -1
  341. package/shaders/DOFMipMapShader.cjs +38 -21
  342. package/shaders/DOFMipMapShader.cjs.map +1 -1
  343. package/shaders/DOFMipMapShader.js +38 -21
  344. package/shaders/DOFMipMapShader.js.map +1 -1
  345. package/shaders/DepthLimitedBlurShader.cjs +98 -69
  346. package/shaders/DepthLimitedBlurShader.cjs.map +1 -1
  347. package/shaders/DepthLimitedBlurShader.js +98 -69
  348. package/shaders/DepthLimitedBlurShader.js.map +1 -1
  349. package/shaders/DigitalGlitch.cjs +70 -59
  350. package/shaders/DigitalGlitch.cjs.map +1 -1
  351. package/shaders/DigitalGlitch.js +70 -59
  352. package/shaders/DigitalGlitch.js.map +1 -1
  353. package/shaders/DotScreenShader.cjs +49 -28
  354. package/shaders/DotScreenShader.cjs.map +1 -1
  355. package/shaders/DotScreenShader.js +49 -28
  356. package/shaders/DotScreenShader.js.map +1 -1
  357. package/shaders/FXAAShader.cjs +1098 -1089
  358. package/shaders/FXAAShader.cjs.map +1 -1
  359. package/shaders/FXAAShader.js +1098 -1089
  360. package/shaders/FXAAShader.js.map +1 -1
  361. package/shaders/FilmShader.cjs +57 -29
  362. package/shaders/FilmShader.cjs.map +1 -1
  363. package/shaders/FilmShader.js +57 -29
  364. package/shaders/FilmShader.js.map +1 -1
  365. package/shaders/FocusShader.cjs +70 -43
  366. package/shaders/FocusShader.cjs.map +1 -1
  367. package/shaders/FocusShader.js +70 -43
  368. package/shaders/FocusShader.js.map +1 -1
  369. package/shaders/FreiChenShader.cjs +74 -53
  370. package/shaders/FreiChenShader.cjs.map +1 -1
  371. package/shaders/FreiChenShader.js +74 -53
  372. package/shaders/FreiChenShader.js.map +1 -1
  373. package/shaders/FresnelShader.cjs +55 -35
  374. package/shaders/FresnelShader.cjs.map +1 -1
  375. package/shaders/FresnelShader.js +55 -35
  376. package/shaders/FresnelShader.js.map +1 -1
  377. package/shaders/GammaCorrectionShader.cjs +33 -19
  378. package/shaders/GammaCorrectionShader.cjs.map +1 -1
  379. package/shaders/GammaCorrectionShader.js +33 -19
  380. package/shaders/GammaCorrectionShader.js.map +1 -1
  381. package/shaders/GodRaysShader.cjs +193 -116
  382. package/shaders/GodRaysShader.cjs.map +1 -1
  383. package/shaders/GodRaysShader.js +193 -116
  384. package/shaders/GodRaysShader.js.map +1 -1
  385. package/shaders/HalftoneShader.cjs +270 -192
  386. package/shaders/HalftoneShader.cjs.map +1 -1
  387. package/shaders/HalftoneShader.js +270 -192
  388. package/shaders/HalftoneShader.js.map +1 -1
  389. package/shaders/HorizontalTiltShiftShader.cjs +43 -27
  390. package/shaders/HorizontalTiltShiftShader.cjs.map +1 -1
  391. package/shaders/HorizontalTiltShiftShader.js +43 -27
  392. package/shaders/HorizontalTiltShiftShader.js.map +1 -1
  393. package/shaders/HueSaturationShader.cjs +47 -31
  394. package/shaders/HueSaturationShader.cjs.map +1 -1
  395. package/shaders/HueSaturationShader.js +47 -31
  396. package/shaders/HueSaturationShader.js.map +1 -1
  397. package/shaders/KaleidoShader.cjs +37 -24
  398. package/shaders/KaleidoShader.cjs.map +1 -1
  399. package/shaders/KaleidoShader.js +37 -24
  400. package/shaders/KaleidoShader.js.map +1 -1
  401. package/shaders/LuminosityHighPassShader.cjs +43 -24
  402. package/shaders/LuminosityHighPassShader.cjs.map +1 -1
  403. package/shaders/LuminosityHighPassShader.js +43 -24
  404. package/shaders/LuminosityHighPassShader.js.map +1 -1
  405. package/shaders/LuminosityShader.cjs +34 -17
  406. package/shaders/LuminosityShader.cjs.map +1 -1
  407. package/shaders/LuminosityShader.js +34 -17
  408. package/shaders/LuminosityShader.js.map +1 -1
  409. package/shaders/MirrorShader.cjs +39 -26
  410. package/shaders/MirrorShader.cjs.map +1 -1
  411. package/shaders/MirrorShader.js +39 -26
  412. package/shaders/MirrorShader.js.map +1 -1
  413. package/shaders/NormalMapShader.cjs +36 -21
  414. package/shaders/NormalMapShader.cjs.map +1 -1
  415. package/shaders/NormalMapShader.js +36 -21
  416. package/shaders/NormalMapShader.js.map +1 -1
  417. package/shaders/ParallaxShader.cjs +147 -97
  418. package/shaders/ParallaxShader.cjs.map +1 -1
  419. package/shaders/ParallaxShader.js +147 -97
  420. package/shaders/ParallaxShader.js.map +1 -1
  421. package/shaders/PixelShader.cjs +31 -18
  422. package/shaders/PixelShader.cjs.map +1 -1
  423. package/shaders/PixelShader.js +31 -18
  424. package/shaders/PixelShader.js.map +1 -1
  425. package/shaders/RGBShiftShader.cjs +33 -20
  426. package/shaders/RGBShiftShader.cjs.map +1 -1
  427. package/shaders/RGBShiftShader.js +33 -20
  428. package/shaders/RGBShiftShader.js.map +1 -1
  429. package/shaders/SAOShader.cjs +154 -117
  430. package/shaders/SAOShader.cjs.map +1 -1
  431. package/shaders/SAOShader.js +154 -117
  432. package/shaders/SAOShader.js.map +1 -1
  433. package/shaders/SMAAShader.cjs +358 -270
  434. package/shaders/SMAAShader.cjs.map +1 -1
  435. package/shaders/SMAAShader.js +358 -270
  436. package/shaders/SMAAShader.js.map +1 -1
  437. package/shaders/SSAOShader.cjs +236 -142
  438. package/shaders/SSAOShader.cjs.map +1 -1
  439. package/shaders/SSAOShader.js +236 -142
  440. package/shaders/SSAOShader.js.map +1 -1
  441. package/shaders/SSRShader.cjs +4 -4
  442. package/shaders/SSRShader.cjs.map +1 -1
  443. package/shaders/SSRShader.js +4 -4
  444. package/shaders/SSRShader.js.map +1 -1
  445. package/shaders/SepiaShader.cjs +36 -20
  446. package/shaders/SepiaShader.cjs.map +1 -1
  447. package/shaders/SepiaShader.js +36 -20
  448. package/shaders/SepiaShader.js.map +1 -1
  449. package/shaders/SobelOperatorShader.cjs +64 -37
  450. package/shaders/SobelOperatorShader.cjs.map +1 -1
  451. package/shaders/SobelOperatorShader.js +64 -37
  452. package/shaders/SobelOperatorShader.js.map +1 -1
  453. package/shaders/TechnicolorShader.cjs +29 -16
  454. package/shaders/TechnicolorShader.cjs.map +1 -1
  455. package/shaders/TechnicolorShader.js +29 -16
  456. package/shaders/TechnicolorShader.js.map +1 -1
  457. package/shaders/ToneMapShader.cjs +55 -35
  458. package/shaders/ToneMapShader.cjs.map +1 -1
  459. package/shaders/ToneMapShader.js +55 -35
  460. package/shaders/ToneMapShader.js.map +1 -1
  461. package/shaders/ToonShader.cjs +275 -165
  462. package/shaders/ToonShader.cjs.map +1 -1
  463. package/shaders/ToonShader.js +275 -165
  464. package/shaders/ToonShader.js.map +1 -1
  465. package/shaders/TriangleBlurShader.cjs +50 -27
  466. package/shaders/TriangleBlurShader.cjs.map +1 -1
  467. package/shaders/TriangleBlurShader.js +50 -27
  468. package/shaders/TriangleBlurShader.js.map +1 -1
  469. package/shaders/UnpackDepthRGBAShader.cjs +32 -17
  470. package/shaders/UnpackDepthRGBAShader.cjs.map +1 -1
  471. package/shaders/UnpackDepthRGBAShader.js +32 -17
  472. package/shaders/UnpackDepthRGBAShader.js.map +1 -1
  473. package/shaders/VerticalTiltShiftShader.cjs +43 -27
  474. package/shaders/VerticalTiltShiftShader.cjs.map +1 -1
  475. package/shaders/VerticalTiltShiftShader.js +43 -27
  476. package/shaders/VerticalTiltShiftShader.js.map +1 -1
  477. package/shaders/VignetteShader.cjs +43 -27
  478. package/shaders/VignetteShader.cjs.map +1 -1
  479. package/shaders/VignetteShader.js +43 -27
  480. package/shaders/VignetteShader.js.map +1 -1
  481. package/shaders/VolumeShader.cjs +264 -213
  482. package/shaders/VolumeShader.cjs.map +1 -1
  483. package/shaders/VolumeShader.js +264 -213
  484. package/shaders/VolumeShader.js.map +1 -1
  485. package/shaders/WaterRefractionShader.cjs +63 -35
  486. package/shaders/WaterRefractionShader.cjs.map +1 -1
  487. package/shaders/WaterRefractionShader.js +63 -35
  488. package/shaders/WaterRefractionShader.js.map +1 -1
  489. package/utils/GeometryCompressionUtils.cjs +2 -1
  490. package/utils/GeometryCompressionUtils.cjs.map +1 -1
  491. package/utils/GeometryCompressionUtils.js +3 -2
  492. package/utils/GeometryCompressionUtils.js.map +1 -1
  493. package/utils/RoughnessMipmapper.cjs +3 -3
  494. package/utils/RoughnessMipmapper.cjs.map +1 -1
  495. package/utils/RoughnessMipmapper.js +4 -4
  496. package/utils/RoughnessMipmapper.js.map +1 -1
  497. package/webxr/ARButton.cjs +109 -106
  498. package/webxr/ARButton.cjs.map +1 -1
  499. package/webxr/ARButton.d.ts +4 -3
  500. package/webxr/ARButton.js +109 -106
  501. package/webxr/ARButton.js.map +1 -1
  502. package/webxr/OculusHandPointerModel.cjs +2 -2
  503. package/webxr/OculusHandPointerModel.cjs.map +1 -1
  504. package/webxr/OculusHandPointerModel.js +2 -2
  505. package/webxr/OculusHandPointerModel.js.map +1 -1
  506. package/webxr/VRButton.cjs +98 -95
  507. package/webxr/VRButton.cjs.map +1 -1
  508. package/webxr/VRButton.d.ts +6 -5
  509. package/webxr/VRButton.js +98 -95
  510. package/webxr/VRButton.js.map +1 -1
  511. package/webxr/XRHandPrimitiveModel.cjs +2 -2
  512. package/webxr/XRHandPrimitiveModel.cjs.map +1 -1
  513. package/webxr/XRHandPrimitiveModel.js +3 -3
  514. package/webxr/XRHandPrimitiveModel.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"BatchedMesh.cjs","sources":["../../src/objects/BatchedMesh.ts"],"sourcesContent":["import {\n Matrix4,\n BufferAttribute,\n InterleavedBufferAttribute,\n Mesh,\n BufferGeometry,\n Material,\n DataTexture,\n IUniform,\n MathUtils,\n RGBAFormat,\n FloatType,\n} from 'three'\n\nconst ID_ATTR_NAME = '_batch_id_'\nconst _identityMatrix = new Matrix4()\nconst _zeroScaleMatrix = new Matrix4().set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)\n\n// Custom shaders\nconst batchingParsVertex = /* glsl */ `\n#ifdef BATCHING\n\tattribute float ${ID_ATTR_NAME};\n\tuniform highp sampler2D batchingTexture;\n\tmat4 getBatchingMatrix( const in float i ) {\n\n\t\tint size = textureSize( batchingTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\n\t}\n#endif\n`\n\nconst batchingbaseVertex = /* glsl */ `\n#ifdef BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( ${ID_ATTR_NAME} );\n#endif\n`\n\nconst batchingnormalVertex = /* glsl */ `\n#ifdef BATCHING\n\tobjectNormal = vec4( batchingMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( batchingMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif\n`\n\nconst batchingVertex = /* glsl */ `\n#ifdef BATCHING\n\ttransformed = ( batchingMatrix * vec4( transformed, 1.0 ) ).xyz;\n#endif\n`\n\n// @TODO: SkinnedMesh support?\n// @TODO: Future work if needed. Move into the core. Can be optimized more with WEBGL_multi_draw.\n\n// copies data from attribute \"src\" into \"target\" starting at \"targetOffset\"\nfunction copyAttributeData(\n src: BufferAttribute | InterleavedBufferAttribute,\n target: BufferAttribute | InterleavedBufferAttribute,\n targetOffset = 0,\n): void {\n const itemSize = target.itemSize\n if (\n (src as InterleavedBufferAttribute).isInterleavedBufferAttribute ||\n src.array.constructor !== target.array.constructor\n ) {\n // use the component getters and setters if the array data cannot\n // be copied directly\n const vertexCount = src.count\n for (let i = 0; i < vertexCount; i++) {\n for (let c = 0; c < itemSize; c++) {\n // @ts-ignore\n target.setComponent(i + targetOffset, c, src.getComponent(i, c))\n }\n }\n } else {\n // faster copy approach using typed array set function\n // @ts-ignore\n target.array.set(src.array, targetOffset * itemSize)\n }\n\n target.needsUpdate = true\n}\n\nclass BatchedMesh extends Mesh<BufferGeometry, Material> {\n _vertexStarts: number[]\n _vertexCounts: number[]\n _indexStarts: number[]\n _indexCounts: number[]\n _reservedRanges: { vertexStart: number; vertexCount: number; indexStart: number; indexCount: number }[]\n _visible: boolean[]\n _active: boolean[]\n _maxGeometryCount: number\n _maxVertexCount: number\n _maxIndexCount: number\n _geometryInitialized: boolean\n _geometryCount: number\n _matrices: Matrix4[]\n _matricesTexture: DataTexture | null\n _customUniforms: Record<string, IUniform>\n\n constructor(\n maxGeometryCount: number,\n maxVertexCount: number,\n maxIndexCount = maxVertexCount * 2,\n material?: Material,\n ) {\n super(new BufferGeometry(), material)\n\n this._vertexStarts = []\n this._vertexCounts = []\n this._indexStarts = []\n this._indexCounts = []\n this._reservedRanges = []\n\n this._visible = []\n this._active = []\n\n this._maxGeometryCount = maxGeometryCount\n this._maxVertexCount = maxVertexCount\n this._maxIndexCount = maxIndexCount\n\n this._geometryInitialized = false\n this._geometryCount = 0\n\n // Local matrix per geometry by using data texture\n // @TODO: Support uniform parameter per geometry\n\n this._matrices = []\n this._matricesTexture = null!\n\n // @TODO: Calculate the entire binding box and make frustumCulled true\n this.frustumCulled = false\n\n this._customUniforms = {\n batchingTexture: { value: null },\n }\n\n this._initMatricesTexture()\n this._initShader()\n\n this.onBeforeRender = function () {\n if (this.material.defines) {\n this.material.defines.BATCHING = true\n }\n\n // @TODO: Implement frustum culling for each geometry\n }\n\n this.onAfterRender = function () {\n if (this.material.defines) {\n this.material.defines.BATCHING = false\n }\n }\n }\n\n _initMatricesTexture(): void {\n // layout (1 matrix = 4 pixels)\n // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)\n // with 8x8 pixel texture max 16 matrices * 4 pixels = (8 * 8)\n // 16x16 pixel texture max 64 matrices * 4 pixels = (16 * 16)\n // 32x32 pixel texture max 256 matrices * 4 pixels = (32 * 32)\n // 64x64 pixel texture max 1024 matrices * 4 pixels = (64 * 64)\n\n let size = Math.sqrt(this._maxGeometryCount * 4) // 4 pixels needed for 1 matrix\n size = MathUtils.ceilPowerOfTwo(size)\n size = Math.max(size, 4)\n\n const matricesArray = new Float32Array(size * size * 4) // 4 floats per RGBA pixel\n const matricesTexture = new DataTexture(matricesArray, size, size, RGBAFormat, FloatType)\n\n this._matricesTexture = matricesTexture\n this._customUniforms.batchingTexture.value = this._matricesTexture\n }\n\n _initShader(): void {\n const material = this.material\n const currentOnBeforeCompile = material.onBeforeCompile\n const customUniforms = this._customUniforms\n\n material.onBeforeCompile = function onBeforeCompile(parameters, renderer) {\n // Is this replacement stable across any materials?\n parameters.vertexShader = parameters.vertexShader\n .replace('#include <skinning_pars_vertex>', '#include <skinning_pars_vertex>\\n' + batchingParsVertex)\n .replace('#include <uv_vertex>', '#include <uv_vertex>\\n' + batchingbaseVertex)\n .replace('#include <skinnormal_vertex>', '#include <skinnormal_vertex>\\n' + batchingnormalVertex)\n .replace('#include <skinning_vertex>', '#include <skinning_vertex>\\n' + batchingVertex)\n\n for (const uniformName in customUniforms) {\n parameters.uniforms[uniformName] = customUniforms[uniformName]\n }\n\n currentOnBeforeCompile.call(this, parameters, renderer)\n }\n\n material.defines = material.defines || {}\n material.defines.BATCHING = false\n }\n\n _initializeGeometry(reference: BufferGeometry): void {\n // @TODO: geometry.groups support?\n // @TODO: geometry.drawRange support?\n // @TODO: geometry.morphAttributes support?\n\n const geometry = this.geometry\n const maxVertexCount = this._maxVertexCount\n const maxGeometryCount = this._maxGeometryCount\n const maxIndexCount = this._maxIndexCount\n if (this._geometryInitialized === false) {\n for (const attributeName in reference.attributes) {\n const srcAttribute = reference.getAttribute(attributeName)\n const { array, itemSize, normalized } = srcAttribute\n\n const dstArray = new (array.constructor as Float32ArrayConstructor)(maxVertexCount * itemSize)\n const dstAttribute = new (srcAttribute.constructor as any)(dstArray, itemSize, normalized)\n\n // TODO: add usage in @types/three\n // @ts-ignore\n dstAttribute.setUsage(srcAttribute.usage)\n\n geometry.setAttribute(attributeName, dstAttribute)\n }\n\n if (reference.getIndex() !== null) {\n const indexArray = maxVertexCount > 65536 ? new Uint32Array(maxIndexCount) : new Uint16Array(maxIndexCount)\n\n geometry.setIndex(new BufferAttribute(indexArray, 1))\n }\n\n const idArray = maxGeometryCount > 65536 ? new Uint32Array(maxVertexCount) : new Uint16Array(maxVertexCount)\n geometry.setAttribute(ID_ATTR_NAME, new BufferAttribute(idArray, 1))\n\n this._geometryInitialized = true\n }\n }\n\n // Make sure the geometry is compatible with the existing combined geometry atributes\n _validateGeometry(geometry: BufferGeometry): void {\n // check that the geometry doesn't have a version of our reserved id attribute\n if (geometry.getAttribute(ID_ATTR_NAME)) {\n throw new Error(`BatchedMesh: Geometry cannot use attribute \"${ID_ATTR_NAME}\"`)\n }\n\n // check to ensure the geometries are using consistent attributes and indices\n const batchGeometry = this.geometry\n if (Boolean(geometry.getIndex()) !== Boolean(batchGeometry.getIndex())) {\n throw new Error('BatchedMesh: All geometries must consistently have \"index\".')\n }\n\n for (const attributeName in batchGeometry.attributes) {\n if (attributeName === ID_ATTR_NAME) {\n continue\n }\n\n if (!geometry.hasAttribute(attributeName)) {\n throw new Error(\n `BatchedMesh: Added geometry missing \"${attributeName}\". All geometries must have consistent attributes.`,\n )\n }\n\n const srcAttribute = geometry.getAttribute(attributeName)\n const dstAttribute = batchGeometry.getAttribute(attributeName)\n if (srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized) {\n throw new Error('BatchedMesh: All attributes must have a consistent itemSize and normalized value.')\n }\n }\n }\n\n getGeometryCount(): number {\n return this._geometryCount\n }\n\n getVertexCount(): number {\n const reservedRanges = this._reservedRanges\n if (reservedRanges.length === 0) {\n return 0\n } else {\n const finalRange = reservedRanges[reservedRanges.length - 1]\n return finalRange.vertexStart + finalRange.vertexCount\n }\n }\n\n getIndexCount(): number {\n const reservedRanges = this._reservedRanges\n const geometry = this.geometry\n if (geometry.getIndex() === null || reservedRanges.length === 0) {\n return 0\n } else {\n const finalRange = reservedRanges[reservedRanges.length - 1]\n return finalRange.indexStart + finalRange.indexCount\n }\n }\n\n addGeometry(geometry: BufferGeometry, vertexCount = -1, indexCount = -1): number {\n this._initializeGeometry(geometry)\n\n this._validateGeometry(geometry)\n\n // ensure we're not over geometry\n if (this._geometryCount >= this._maxGeometryCount) {\n throw new Error('BatchedMesh: Maximum geometry count reached.')\n }\n\n // get the necessary range fo the geometry\n const range = {\n vertexStart: -1,\n vertexCount: -1,\n indexStart: -1,\n indexCount: -1,\n }\n\n let lastRange = null\n const reservedRanges = this._reservedRanges\n if (this._geometryCount !== 0) {\n lastRange = reservedRanges[reservedRanges.length - 1]\n }\n\n if (vertexCount === -1) {\n range.vertexCount = geometry.getAttribute('position').count\n } else {\n range.vertexCount = vertexCount\n }\n\n if (lastRange === null) {\n range.vertexStart = 0\n } else {\n range.vertexStart = lastRange.vertexStart + lastRange.vertexCount\n }\n\n if (geometry.getIndex() !== null) {\n if (indexCount === -1) {\n range.indexCount = geometry.getIndex()!.count\n } else {\n range.indexCount = indexCount\n }\n\n if (lastRange === null) {\n range.indexStart = 0\n } else {\n range.indexStart = lastRange.indexStart + lastRange.indexCount\n }\n }\n\n if (\n (range.indexStart !== -1 && range.indexStart + range.indexCount > this._maxIndexCount) ||\n range.vertexStart + range.vertexCount > this._maxVertexCount\n ) {\n throw new Error('BatchedMesh: Reserved space request exceeds the maximum buffer size.')\n }\n\n const indexCounts = this._indexCounts\n const indexStarts = this._indexStarts\n const vertexCounts = this._vertexCounts\n const vertexStarts = this._vertexStarts\n\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture\n const matrices = this._matrices\n const matricesArray = this._matricesTexture!.image.data\n\n // push new visibility states\n visible.push(true)\n active.push(true)\n\n // update id\n const geometryId = this._geometryCount\n this._geometryCount++\n\n // initialize matrix information\n matrices.push(new Matrix4())\n _identityMatrix.toArray(matricesArray, geometryId * 16)\n matricesTexture!.needsUpdate = true\n\n // add the reserved range\n reservedRanges.push(range)\n\n // push new geometry data range\n vertexStarts.push(range.vertexStart)\n vertexCounts.push(range.vertexCount)\n\n if (geometry.getIndex() !== null) {\n // push new index range\n indexStarts.push(range.indexCount)\n indexCounts.push(range.indexCount)\n }\n\n // set the id for the geometry\n const idAttribute = this.geometry.getAttribute(ID_ATTR_NAME)\n for (let i = 0; i < range.vertexCount; i++) {\n idAttribute.setX(range.vertexStart + i, geometryId)\n }\n\n idAttribute.needsUpdate = true\n\n // update the geometry\n this.setGeometryAt(geometryId, geometry)\n\n return geometryId\n }\n\n /**\n * @deprecated use `addGeometry` instead.\n */\n applyGeometry(geometry: BufferGeometry): number {\n return this.addGeometry(geometry)\n }\n\n setGeometryAt(id: number, geometry: BufferGeometry): number {\n if (id >= this._geometryCount) {\n throw new Error('BatchedMesh: Maximum geometry count reached.')\n }\n\n this._validateGeometry(geometry)\n\n const range = this._reservedRanges[id]\n if (\n (geometry.getIndex() !== null && geometry.getIndex()!.count > range.indexCount) ||\n geometry.attributes.position.count > range.vertexCount\n ) {\n throw new Error('BatchedMesh: Reserved space not large enough for provided geometry.')\n }\n\n // copy geometry over\n const batchGeometry = this.geometry\n const srcPositionAttribute = geometry.getAttribute('position')\n const hasIndex = batchGeometry.getIndex() !== null\n const dstIndex = batchGeometry.getIndex()!\n const srcIndex = geometry.getIndex()!\n\n // copy attribute data over\n const vertexStart = range.vertexStart\n const vertexCount = range.vertexCount\n for (const attributeName in batchGeometry.attributes) {\n if (attributeName === ID_ATTR_NAME) {\n continue\n }\n\n const srcAttribute = geometry.getAttribute(attributeName)\n const dstAttribute = batchGeometry.getAttribute(attributeName)\n copyAttributeData(srcAttribute, dstAttribute, vertexStart)\n\n // fill the rest in with zeroes\n const itemSize = srcAttribute.itemSize\n for (let i = srcAttribute.count, l = vertexCount; i < l; i++) {\n const index = vertexStart + i\n for (let c = 0; c < itemSize; c++) {\n // @ts-ignore\n dstAttribute.setComponent(index, c, 0)\n }\n }\n\n dstAttribute.needsUpdate = true\n }\n\n this._vertexCounts[id] = srcPositionAttribute.count\n\n if (hasIndex) {\n // fill the rest in with zeroes\n const indexStart = range.indexStart\n\n // copy index data over\n for (let i = 0; i < srcIndex.count; i++) {\n dstIndex.setX(indexStart + i, vertexStart + srcIndex.getX(i))\n }\n\n // fill the rest in with zeroes\n for (let i = srcIndex.count, l = range.indexCount; i < l; i++) {\n dstIndex.setX(indexStart + i, vertexStart)\n }\n\n dstIndex.needsUpdate = true\n this._indexCounts[id] = srcIndex.count\n }\n\n return id\n }\n\n deleteGeometry(geometryId: number): this {\n // Note: User needs to call optimize() afterward to pack the data.\n\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matricesArray = matricesTexture.image.data\n if (geometryId >= active.length || active[geometryId] === false) {\n return this\n }\n\n active[geometryId] = false\n _zeroScaleMatrix.toArray(matricesArray, geometryId * 16)\n matricesTexture!.needsUpdate = true\n\n return this\n }\n\n optimize(): never {\n throw new Error('BatchedMesh: Optimize function not implemented.')\n }\n\n setMatrixAt(geometryId: number, matrix: Matrix4): this {\n // @TODO: Map geometryId to index of the arrays because\n // optimize() can make geometryId mismatch the index\n\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matrices = this._matrices\n const matricesArray = matricesTexture.image.data\n if (geometryId >= matrices.length || active[geometryId] === false) {\n return this\n }\n\n if (visible[geometryId] === true) {\n matrix.toArray(matricesArray, geometryId * 16)\n matricesTexture.needsUpdate = true\n }\n\n matrices[geometryId].copy(matrix)\n\n return this\n }\n\n getMatrixAt(geometryId: number, matrix: Matrix4): Matrix4 {\n const matrices = this._matrices\n const active = this._active\n if (geometryId >= matrices.length || active[geometryId] === false) {\n return matrix\n }\n\n return matrix.copy(matrices[geometryId])\n }\n\n setVisibleAt(geometryId: number, value: boolean): this {\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matrices = this._matrices\n const matricesArray = matricesTexture.image.data\n\n // if the geometry is out of range, not active, or visibility state\n // does not change then return early\n if (geometryId >= visible.length || active[geometryId] === false || visible[geometryId] === value) {\n return this\n }\n\n // scale the matrix to zero if it's hidden\n if (value === true) {\n matrices[geometryId].toArray(matricesArray, geometryId * 16)\n } else {\n _zeroScaleMatrix.toArray(matricesArray, geometryId * 16)\n }\n\n matricesTexture.needsUpdate = true\n visible[geometryId] = value\n\n return this\n }\n\n getVisibleAt(geometryId: number): boolean {\n const visible = this._visible\n const active = this._active\n\n // return early if the geometry is out of range or not active\n if (geometryId >= visible.length || active[geometryId] === false) {\n return false\n }\n\n return visible[geometryId]\n }\n\n raycast(): void {\n console.warn('BatchedMesh: Raycast function not implemented.')\n }\n\n copy(): never {\n // super.copy( source );\n\n throw new Error('BatchedMesh: Copy function not implemented.')\n }\n\n toJSON(): never {\n throw new Error('BatchedMesh: toJSON function not implemented.')\n }\n\n dispose(): this {\n // Assuming the geometry is not shared with other meshes\n this.geometry.dispose()\n\n this._matricesTexture!.dispose()\n this._matricesTexture = null!\n\n return this\n }\n}\n\nexport { BatchedMesh }\n"],"names":["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;AAAA,EAEA,UAAgB;AACd,YAAQ,KAAK,gDAAgD;AAAA,EAC/D;AAAA,EAEA,OAAc;AAGN,UAAA,IAAI,MAAM,6CAA6C;AAAA,EAC/D;AAAA,EAEA,SAAgB;AACR,UAAA,IAAI,MAAM,+CAA+C;AAAA,EACjE;AAAA,EAEA,UAAgB;AAEd,SAAK,SAAS;AAEd,SAAK,iBAAkB;AACvB,SAAK,mBAAmB;AAEjB,WAAA;AAAA,EACT;AACF;;"}
1
+ {"version":3,"file":"BatchedMesh.cjs","sources":["../../src/objects/BatchedMesh.ts"],"sourcesContent":["import {\n Matrix4,\n BufferAttribute,\n InterleavedBufferAttribute,\n Mesh,\n BufferGeometry,\n Material,\n DataTexture,\n IUniform,\n MathUtils,\n RGBAFormat,\n FloatType,\n} from 'three'\n\nconst ID_ATTR_NAME = '_batch_id_'\nconst _identityMatrix = /* @__PURE__ */ new Matrix4()\nconst _zeroScaleMatrix = /* @__PURE__ */ (() => new Matrix4().set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1))()\n\n// Custom shaders\nconst batchingParsVertex = /* glsl */ `\n#ifdef BATCHING\n\tattribute float ${ID_ATTR_NAME};\n\tuniform highp sampler2D batchingTexture;\n\tmat4 getBatchingMatrix( const in float i ) {\n\n\t\tint size = textureSize( batchingTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\n\t}\n#endif\n`\n\nconst batchingbaseVertex = /* glsl */ `\n#ifdef BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( ${ID_ATTR_NAME} );\n#endif\n`\n\nconst batchingnormalVertex = /* glsl */ `\n#ifdef BATCHING\n\tobjectNormal = vec4( batchingMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( batchingMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif\n`\n\nconst batchingVertex = /* glsl */ `\n#ifdef BATCHING\n\ttransformed = ( batchingMatrix * vec4( transformed, 1.0 ) ).xyz;\n#endif\n`\n\n// @TODO: SkinnedMesh support?\n// @TODO: Future work if needed. Move into the core. Can be optimized more with WEBGL_multi_draw.\n\n// copies data from attribute \"src\" into \"target\" starting at \"targetOffset\"\nfunction copyAttributeData(\n src: BufferAttribute | InterleavedBufferAttribute,\n target: BufferAttribute | InterleavedBufferAttribute,\n targetOffset = 0,\n): void {\n const itemSize = target.itemSize\n if (\n (src as InterleavedBufferAttribute).isInterleavedBufferAttribute ||\n src.array.constructor !== target.array.constructor\n ) {\n // use the component getters and setters if the array data cannot\n // be copied directly\n const vertexCount = src.count\n for (let i = 0; i < vertexCount; i++) {\n for (let c = 0; c < itemSize; c++) {\n // @ts-ignore\n target.setComponent(i + targetOffset, c, src.getComponent(i, c))\n }\n }\n } else {\n // faster copy approach using typed array set function\n // @ts-ignore\n target.array.set(src.array, targetOffset * itemSize)\n }\n\n target.needsUpdate = true\n}\n\nclass BatchedMesh extends Mesh<BufferGeometry, Material> {\n _vertexStarts: number[]\n _vertexCounts: number[]\n _indexStarts: number[]\n _indexCounts: number[]\n _reservedRanges: { vertexStart: number; vertexCount: number; indexStart: number; indexCount: number }[]\n _visible: boolean[]\n _active: boolean[]\n _maxGeometryCount: number\n _maxVertexCount: number\n _maxIndexCount: number\n _geometryInitialized: boolean\n _geometryCount: number\n _matrices: Matrix4[]\n _matricesTexture: DataTexture | null\n _customUniforms: Record<string, IUniform>\n\n constructor(\n maxGeometryCount: number,\n maxVertexCount: number,\n maxIndexCount = maxVertexCount * 2,\n material?: Material,\n ) {\n super(new BufferGeometry(), material)\n\n this._vertexStarts = []\n this._vertexCounts = []\n this._indexStarts = []\n this._indexCounts = []\n this._reservedRanges = []\n\n this._visible = []\n this._active = []\n\n this._maxGeometryCount = maxGeometryCount\n this._maxVertexCount = maxVertexCount\n this._maxIndexCount = maxIndexCount\n\n this._geometryInitialized = false\n this._geometryCount = 0\n\n // Local matrix per geometry by using data texture\n // @TODO: Support uniform parameter per geometry\n\n this._matrices = []\n this._matricesTexture = null!\n\n // @TODO: Calculate the entire binding box and make frustumCulled true\n this.frustumCulled = false\n\n this._customUniforms = {\n batchingTexture: { value: null },\n }\n\n this._initMatricesTexture()\n this._initShader()\n\n this.onBeforeRender = function () {\n if (this.material.defines) {\n this.material.defines.BATCHING = true\n }\n\n // @TODO: Implement frustum culling for each geometry\n }\n\n this.onAfterRender = function () {\n if (this.material.defines) {\n this.material.defines.BATCHING = false\n }\n }\n }\n\n _initMatricesTexture(): void {\n // layout (1 matrix = 4 pixels)\n // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)\n // with 8x8 pixel texture max 16 matrices * 4 pixels = (8 * 8)\n // 16x16 pixel texture max 64 matrices * 4 pixels = (16 * 16)\n // 32x32 pixel texture max 256 matrices * 4 pixels = (32 * 32)\n // 64x64 pixel texture max 1024 matrices * 4 pixels = (64 * 64)\n\n let size = Math.sqrt(this._maxGeometryCount * 4) // 4 pixels needed for 1 matrix\n size = MathUtils.ceilPowerOfTwo(size)\n size = Math.max(size, 4)\n\n const matricesArray = new Float32Array(size * size * 4) // 4 floats per RGBA pixel\n const matricesTexture = new DataTexture(matricesArray, size, size, RGBAFormat, FloatType)\n\n this._matricesTexture = matricesTexture\n this._customUniforms.batchingTexture.value = this._matricesTexture\n }\n\n _initShader(): void {\n const material = this.material\n const currentOnBeforeCompile = material.onBeforeCompile\n const customUniforms = this._customUniforms\n\n material.onBeforeCompile = function onBeforeCompile(parameters, renderer) {\n // Is this replacement stable across any materials?\n parameters.vertexShader = parameters.vertexShader\n .replace('#include <skinning_pars_vertex>', '#include <skinning_pars_vertex>\\n' + batchingParsVertex)\n .replace('#include <uv_vertex>', '#include <uv_vertex>\\n' + batchingbaseVertex)\n .replace('#include <skinnormal_vertex>', '#include <skinnormal_vertex>\\n' + batchingnormalVertex)\n .replace('#include <skinning_vertex>', '#include <skinning_vertex>\\n' + batchingVertex)\n\n for (const uniformName in customUniforms) {\n parameters.uniforms[uniformName] = customUniforms[uniformName]\n }\n\n currentOnBeforeCompile.call(this, parameters, renderer)\n }\n\n material.defines = material.defines || {}\n material.defines.BATCHING = false\n }\n\n _initializeGeometry(reference: BufferGeometry): void {\n // @TODO: geometry.groups support?\n // @TODO: geometry.drawRange support?\n // @TODO: geometry.morphAttributes support?\n\n const geometry = this.geometry\n const maxVertexCount = this._maxVertexCount\n const maxGeometryCount = this._maxGeometryCount\n const maxIndexCount = this._maxIndexCount\n if (this._geometryInitialized === false) {\n for (const attributeName in reference.attributes) {\n const srcAttribute = reference.getAttribute(attributeName)\n const { array, itemSize, normalized } = srcAttribute\n\n const dstArray = new (array.constructor as Float32ArrayConstructor)(maxVertexCount * itemSize)\n const dstAttribute = new (srcAttribute.constructor as any)(dstArray, itemSize, normalized)\n\n // TODO: add usage in @types/three\n // @ts-ignore\n dstAttribute.setUsage(srcAttribute.usage)\n\n geometry.setAttribute(attributeName, dstAttribute)\n }\n\n if (reference.getIndex() !== null) {\n const indexArray = maxVertexCount > 65536 ? new Uint32Array(maxIndexCount) : new Uint16Array(maxIndexCount)\n\n geometry.setIndex(new BufferAttribute(indexArray, 1))\n }\n\n const idArray = maxGeometryCount > 65536 ? new Uint32Array(maxVertexCount) : new Uint16Array(maxVertexCount)\n geometry.setAttribute(ID_ATTR_NAME, new BufferAttribute(idArray, 1))\n\n this._geometryInitialized = true\n }\n }\n\n // Make sure the geometry is compatible with the existing combined geometry atributes\n _validateGeometry(geometry: BufferGeometry): void {\n // check that the geometry doesn't have a version of our reserved id attribute\n if (geometry.getAttribute(ID_ATTR_NAME)) {\n throw new Error(`BatchedMesh: Geometry cannot use attribute \"${ID_ATTR_NAME}\"`)\n }\n\n // check to ensure the geometries are using consistent attributes and indices\n const batchGeometry = this.geometry\n if (Boolean(geometry.getIndex()) !== Boolean(batchGeometry.getIndex())) {\n throw new Error('BatchedMesh: All geometries must consistently have \"index\".')\n }\n\n for (const attributeName in batchGeometry.attributes) {\n if (attributeName === ID_ATTR_NAME) {\n continue\n }\n\n if (!geometry.hasAttribute(attributeName)) {\n throw new Error(\n `BatchedMesh: Added geometry missing \"${attributeName}\". All geometries must have consistent attributes.`,\n )\n }\n\n const srcAttribute = geometry.getAttribute(attributeName)\n const dstAttribute = batchGeometry.getAttribute(attributeName)\n if (srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized) {\n throw new Error('BatchedMesh: All attributes must have a consistent itemSize and normalized value.')\n }\n }\n }\n\n getGeometryCount(): number {\n return this._geometryCount\n }\n\n getVertexCount(): number {\n const reservedRanges = this._reservedRanges\n if (reservedRanges.length === 0) {\n return 0\n } else {\n const finalRange = reservedRanges[reservedRanges.length - 1]\n return finalRange.vertexStart + finalRange.vertexCount\n }\n }\n\n getIndexCount(): number {\n const reservedRanges = this._reservedRanges\n const geometry = this.geometry\n if (geometry.getIndex() === null || reservedRanges.length === 0) {\n return 0\n } else {\n const finalRange = reservedRanges[reservedRanges.length - 1]\n return finalRange.indexStart + finalRange.indexCount\n }\n }\n\n addGeometry(geometry: BufferGeometry, vertexCount = -1, indexCount = -1): number {\n this._initializeGeometry(geometry)\n\n this._validateGeometry(geometry)\n\n // ensure we're not over geometry\n if (this._geometryCount >= this._maxGeometryCount) {\n throw new Error('BatchedMesh: Maximum geometry count reached.')\n }\n\n // get the necessary range fo the geometry\n const range = {\n vertexStart: -1,\n vertexCount: -1,\n indexStart: -1,\n indexCount: -1,\n }\n\n let lastRange = null\n const reservedRanges = this._reservedRanges\n if (this._geometryCount !== 0) {\n lastRange = reservedRanges[reservedRanges.length - 1]\n }\n\n if (vertexCount === -1) {\n range.vertexCount = geometry.getAttribute('position').count\n } else {\n range.vertexCount = vertexCount\n }\n\n if (lastRange === null) {\n range.vertexStart = 0\n } else {\n range.vertexStart = lastRange.vertexStart + lastRange.vertexCount\n }\n\n if (geometry.getIndex() !== null) {\n if (indexCount === -1) {\n range.indexCount = geometry.getIndex()!.count\n } else {\n range.indexCount = indexCount\n }\n\n if (lastRange === null) {\n range.indexStart = 0\n } else {\n range.indexStart = lastRange.indexStart + lastRange.indexCount\n }\n }\n\n if (\n (range.indexStart !== -1 && range.indexStart + range.indexCount > this._maxIndexCount) ||\n range.vertexStart + range.vertexCount > this._maxVertexCount\n ) {\n throw new Error('BatchedMesh: Reserved space request exceeds the maximum buffer size.')\n }\n\n const indexCounts = this._indexCounts\n const indexStarts = this._indexStarts\n const vertexCounts = this._vertexCounts\n const vertexStarts = this._vertexStarts\n\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture\n const matrices = this._matrices\n const matricesArray = this._matricesTexture!.image.data\n\n // push new visibility states\n visible.push(true)\n active.push(true)\n\n // update id\n const geometryId = this._geometryCount\n this._geometryCount++\n\n // initialize matrix information\n matrices.push(new Matrix4())\n _identityMatrix.toArray(matricesArray, geometryId * 16)\n matricesTexture!.needsUpdate = true\n\n // add the reserved range\n reservedRanges.push(range)\n\n // push new geometry data range\n vertexStarts.push(range.vertexStart)\n vertexCounts.push(range.vertexCount)\n\n if (geometry.getIndex() !== null) {\n // push new index range\n indexStarts.push(range.indexCount)\n indexCounts.push(range.indexCount)\n }\n\n // set the id for the geometry\n const idAttribute = this.geometry.getAttribute(ID_ATTR_NAME)\n for (let i = 0; i < range.vertexCount; i++) {\n idAttribute.setX(range.vertexStart + i, geometryId)\n }\n\n idAttribute.needsUpdate = true\n\n // update the geometry\n this.setGeometryAt(geometryId, geometry)\n\n return geometryId\n }\n\n /**\n * @deprecated use `addGeometry` instead.\n */\n applyGeometry(geometry: BufferGeometry): number {\n return this.addGeometry(geometry)\n }\n\n setGeometryAt(id: number, geometry: BufferGeometry): number {\n if (id >= this._geometryCount) {\n throw new Error('BatchedMesh: Maximum geometry count reached.')\n }\n\n this._validateGeometry(geometry)\n\n const range = this._reservedRanges[id]\n if (\n (geometry.getIndex() !== null && geometry.getIndex()!.count > range.indexCount) ||\n geometry.attributes.position.count > range.vertexCount\n ) {\n throw new Error('BatchedMesh: Reserved space not large enough for provided geometry.')\n }\n\n // copy geometry over\n const batchGeometry = this.geometry\n const srcPositionAttribute = geometry.getAttribute('position')\n const hasIndex = batchGeometry.getIndex() !== null\n const dstIndex = batchGeometry.getIndex()!\n const srcIndex = geometry.getIndex()!\n\n // copy attribute data over\n const vertexStart = range.vertexStart\n const vertexCount = range.vertexCount\n for (const attributeName in batchGeometry.attributes) {\n if (attributeName === ID_ATTR_NAME) {\n continue\n }\n\n const srcAttribute = geometry.getAttribute(attributeName)\n const dstAttribute = batchGeometry.getAttribute(attributeName)\n copyAttributeData(srcAttribute, dstAttribute, vertexStart)\n\n // fill the rest in with zeroes\n const itemSize = srcAttribute.itemSize\n for (let i = srcAttribute.count, l = vertexCount; i < l; i++) {\n const index = vertexStart + i\n for (let c = 0; c < itemSize; c++) {\n // @ts-ignore\n dstAttribute.setComponent(index, c, 0)\n }\n }\n\n dstAttribute.needsUpdate = true\n }\n\n this._vertexCounts[id] = srcPositionAttribute.count\n\n if (hasIndex) {\n // fill the rest in with zeroes\n const indexStart = range.indexStart\n\n // copy index data over\n for (let i = 0; i < srcIndex.count; i++) {\n dstIndex.setX(indexStart + i, vertexStart + srcIndex.getX(i))\n }\n\n // fill the rest in with zeroes\n for (let i = srcIndex.count, l = range.indexCount; i < l; i++) {\n dstIndex.setX(indexStart + i, vertexStart)\n }\n\n dstIndex.needsUpdate = true\n this._indexCounts[id] = srcIndex.count\n }\n\n return id\n }\n\n deleteGeometry(geometryId: number): this {\n // Note: User needs to call optimize() afterward to pack the data.\n\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matricesArray = matricesTexture.image.data\n if (geometryId >= active.length || active[geometryId] === false) {\n return this\n }\n\n active[geometryId] = false\n _zeroScaleMatrix.toArray(matricesArray, geometryId * 16)\n matricesTexture!.needsUpdate = true\n\n return this\n }\n\n optimize(): never {\n throw new Error('BatchedMesh: Optimize function not implemented.')\n }\n\n setMatrixAt(geometryId: number, matrix: Matrix4): this {\n // @TODO: Map geometryId to index of the arrays because\n // optimize() can make geometryId mismatch the index\n\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matrices = this._matrices\n const matricesArray = matricesTexture.image.data\n if (geometryId >= matrices.length || active[geometryId] === false) {\n return this\n }\n\n if (visible[geometryId] === true) {\n matrix.toArray(matricesArray, geometryId * 16)\n matricesTexture.needsUpdate = true\n }\n\n matrices[geometryId].copy(matrix)\n\n return this\n }\n\n getMatrixAt(geometryId: number, matrix: Matrix4): Matrix4 {\n const matrices = this._matrices\n const active = this._active\n if (geometryId >= matrices.length || active[geometryId] === false) {\n return matrix\n }\n\n return matrix.copy(matrices[geometryId])\n }\n\n setVisibleAt(geometryId: number, value: boolean): this {\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matrices = this._matrices\n const matricesArray = matricesTexture.image.data\n\n // if the geometry is out of range, not active, or visibility state\n // does not change then return early\n if (geometryId >= visible.length || active[geometryId] === false || visible[geometryId] === value) {\n return this\n }\n\n // scale the matrix to zero if it's hidden\n if (value === true) {\n matrices[geometryId].toArray(matricesArray, geometryId * 16)\n } else {\n _zeroScaleMatrix.toArray(matricesArray, geometryId * 16)\n }\n\n matricesTexture.needsUpdate = true\n visible[geometryId] = value\n\n return this\n }\n\n getVisibleAt(geometryId: number): boolean {\n const visible = this._visible\n const active = this._active\n\n // return early if the geometry is out of range or not active\n if (geometryId >= visible.length || active[geometryId] === false) {\n return false\n }\n\n return visible[geometryId]\n }\n\n raycast(): void {\n console.warn('BatchedMesh: Raycast function not implemented.')\n }\n\n copy(): never {\n // super.copy( source );\n\n throw new Error('BatchedMesh: Copy function not implemented.')\n }\n\n toJSON(): never {\n throw new Error('BatchedMesh: toJSON function not implemented.')\n }\n\n dispose(): this {\n // Assuming the geometry is not shared with other meshes\n this.geometry.dispose()\n\n this._matricesTexture!.dispose()\n this._matricesTexture = null!\n\n return this\n }\n}\n\nexport { BatchedMesh }\n"],"names":["Matrix4","Mesh","BufferGeometry","MathUtils","DataTexture","RGBAFormat","FloatType","BufferAttribute"],"mappings":";;;;;;;;;AAcA,MAAM,eAAe;AACrB,MAAM,sCAAsCA,MAAAA;AAC5C,MAAM,0CAA0C,IAAIA,MAAAA,UAAU,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAGhH,MAAM;AAAA;AAAA,EAAgC;AAAA;AAAA,mBAEnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBnB,MAAM;AAAA;AAAA,EAAgC;AAAA;AAAA,4CAEM;AAAA;AAAA;AAAA;AAI5C,MAAM;AAAA;AAAA,EAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASxC,MAAM;AAAA;AAAA,EAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAUlC,SAAS,kBACP,KACA,QACA,eAAe,GACT;AACN,QAAM,WAAW,OAAO;AACxB,MACG,IAAmC,gCACpC,IAAI,MAAM,gBAAgB,OAAO,MAAM,aACvC;AAGA,UAAM,cAAc,IAAI;AACxB,aAAS,IAAI,GAAG,IAAI,aAAa,KAAK;AACpC,eAAS,IAAI,GAAG,IAAI,UAAU,KAAK;AAE1B,eAAA,aAAa,IAAI,cAAc,GAAG,IAAI,aAAa,GAAG,CAAC,CAAC;AAAA,MACjE;AAAA,IACF;AAAA,EAAA,OACK;AAGL,WAAO,MAAM,IAAI,IAAI,OAAO,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,WAAA;AAAA,EACT;AAAA,EAEA,aAAa,YAA6B;AACxC,UAAM,UAAU,KAAK;AACrB,UAAM,SAAS,KAAK;AAGpB,QAAI,cAAc,QAAQ,UAAU,OAAO,UAAU,MAAM,OAAO;AACzD,aAAA;AAAA,IACT;AAEA,WAAO,QAAQ,UAAU;AAAA,EAC3B;AAAA,EAEA,UAAgB;AACd,YAAQ,KAAK,gDAAgD;AAAA,EAC/D;AAAA,EAEA,OAAc;AAGN,UAAA,IAAI,MAAM,6CAA6C;AAAA,EAC/D;AAAA,EAEA,SAAgB;AACR,UAAA,IAAI,MAAM,+CAA+C;AAAA,EACjE;AAAA,EAEA,UAAgB;AAEd,SAAK,SAAS;AAEd,SAAK,iBAAkB;AACvB,SAAK,mBAAmB;AAEjB,WAAA;AAAA,EACT;AACF;;"}
@@ -4,10 +4,10 @@ var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
6
6
  };
7
- import { Matrix4, Mesh, BufferGeometry, MathUtils, DataTexture, RGBAFormat, FloatType, BufferAttribute } from "three";
7
+ import { Mesh, BufferGeometry, MathUtils, DataTexture, RGBAFormat, FloatType, BufferAttribute, Matrix4 } from "three";
8
8
  const ID_ATTR_NAME = "_batch_id_";
9
- const _identityMatrix = new Matrix4();
10
- const _zeroScaleMatrix = new Matrix4().set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
9
+ const _identityMatrix = /* @__PURE__ */ new Matrix4();
10
+ const _zeroScaleMatrix = /* @__PURE__ */ (() => new Matrix4().set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1))();
11
11
  const batchingParsVertex = (
12
12
  /* glsl */
13
13
  `
@@ -1 +1 @@
1
- {"version":3,"file":"BatchedMesh.js","sources":["../../src/objects/BatchedMesh.ts"],"sourcesContent":["import {\n Matrix4,\n BufferAttribute,\n InterleavedBufferAttribute,\n Mesh,\n BufferGeometry,\n Material,\n DataTexture,\n IUniform,\n MathUtils,\n RGBAFormat,\n FloatType,\n} from 'three'\n\nconst ID_ATTR_NAME = '_batch_id_'\nconst _identityMatrix = new Matrix4()\nconst _zeroScaleMatrix = new Matrix4().set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)\n\n// Custom shaders\nconst batchingParsVertex = /* glsl */ `\n#ifdef BATCHING\n\tattribute float ${ID_ATTR_NAME};\n\tuniform highp sampler2D batchingTexture;\n\tmat4 getBatchingMatrix( const in float i ) {\n\n\t\tint size = textureSize( batchingTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\n\t}\n#endif\n`\n\nconst batchingbaseVertex = /* glsl */ `\n#ifdef BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( ${ID_ATTR_NAME} );\n#endif\n`\n\nconst batchingnormalVertex = /* glsl */ `\n#ifdef BATCHING\n\tobjectNormal = vec4( batchingMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( batchingMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif\n`\n\nconst batchingVertex = /* glsl */ `\n#ifdef BATCHING\n\ttransformed = ( batchingMatrix * vec4( transformed, 1.0 ) ).xyz;\n#endif\n`\n\n// @TODO: SkinnedMesh support?\n// @TODO: Future work if needed. Move into the core. Can be optimized more with WEBGL_multi_draw.\n\n// copies data from attribute \"src\" into \"target\" starting at \"targetOffset\"\nfunction copyAttributeData(\n src: BufferAttribute | InterleavedBufferAttribute,\n target: BufferAttribute | InterleavedBufferAttribute,\n targetOffset = 0,\n): void {\n const itemSize = target.itemSize\n if (\n (src as InterleavedBufferAttribute).isInterleavedBufferAttribute ||\n src.array.constructor !== target.array.constructor\n ) {\n // use the component getters and setters if the array data cannot\n // be copied directly\n const vertexCount = src.count\n for (let i = 0; i < vertexCount; i++) {\n for (let c = 0; c < itemSize; c++) {\n // @ts-ignore\n target.setComponent(i + targetOffset, c, src.getComponent(i, c))\n }\n }\n } else {\n // faster copy approach using typed array set function\n // @ts-ignore\n target.array.set(src.array, targetOffset * itemSize)\n }\n\n target.needsUpdate = true\n}\n\nclass BatchedMesh extends Mesh<BufferGeometry, Material> {\n _vertexStarts: number[]\n _vertexCounts: number[]\n _indexStarts: number[]\n _indexCounts: number[]\n _reservedRanges: { vertexStart: number; vertexCount: number; indexStart: number; indexCount: number }[]\n _visible: boolean[]\n _active: boolean[]\n _maxGeometryCount: number\n _maxVertexCount: number\n _maxIndexCount: number\n _geometryInitialized: boolean\n _geometryCount: number\n _matrices: Matrix4[]\n _matricesTexture: DataTexture | null\n _customUniforms: Record<string, IUniform>\n\n constructor(\n maxGeometryCount: number,\n maxVertexCount: number,\n maxIndexCount = maxVertexCount * 2,\n material?: Material,\n ) {\n super(new BufferGeometry(), material)\n\n this._vertexStarts = []\n this._vertexCounts = []\n this._indexStarts = []\n this._indexCounts = []\n this._reservedRanges = []\n\n this._visible = []\n this._active = []\n\n this._maxGeometryCount = maxGeometryCount\n this._maxVertexCount = maxVertexCount\n this._maxIndexCount = maxIndexCount\n\n this._geometryInitialized = false\n this._geometryCount = 0\n\n // Local matrix per geometry by using data texture\n // @TODO: Support uniform parameter per geometry\n\n this._matrices = []\n this._matricesTexture = null!\n\n // @TODO: Calculate the entire binding box and make frustumCulled true\n this.frustumCulled = false\n\n this._customUniforms = {\n batchingTexture: { value: null },\n }\n\n this._initMatricesTexture()\n this._initShader()\n\n this.onBeforeRender = function () {\n if (this.material.defines) {\n this.material.defines.BATCHING = true\n }\n\n // @TODO: Implement frustum culling for each geometry\n }\n\n this.onAfterRender = function () {\n if (this.material.defines) {\n this.material.defines.BATCHING = false\n }\n }\n }\n\n _initMatricesTexture(): void {\n // layout (1 matrix = 4 pixels)\n // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)\n // with 8x8 pixel texture max 16 matrices * 4 pixels = (8 * 8)\n // 16x16 pixel texture max 64 matrices * 4 pixels = (16 * 16)\n // 32x32 pixel texture max 256 matrices * 4 pixels = (32 * 32)\n // 64x64 pixel texture max 1024 matrices * 4 pixels = (64 * 64)\n\n let size = Math.sqrt(this._maxGeometryCount * 4) // 4 pixels needed for 1 matrix\n size = MathUtils.ceilPowerOfTwo(size)\n size = Math.max(size, 4)\n\n const matricesArray = new Float32Array(size * size * 4) // 4 floats per RGBA pixel\n const matricesTexture = new DataTexture(matricesArray, size, size, RGBAFormat, FloatType)\n\n this._matricesTexture = matricesTexture\n this._customUniforms.batchingTexture.value = this._matricesTexture\n }\n\n _initShader(): void {\n const material = this.material\n const currentOnBeforeCompile = material.onBeforeCompile\n const customUniforms = this._customUniforms\n\n material.onBeforeCompile = function onBeforeCompile(parameters, renderer) {\n // Is this replacement stable across any materials?\n parameters.vertexShader = parameters.vertexShader\n .replace('#include <skinning_pars_vertex>', '#include <skinning_pars_vertex>\\n' + batchingParsVertex)\n .replace('#include <uv_vertex>', '#include <uv_vertex>\\n' + batchingbaseVertex)\n .replace('#include <skinnormal_vertex>', '#include <skinnormal_vertex>\\n' + batchingnormalVertex)\n .replace('#include <skinning_vertex>', '#include <skinning_vertex>\\n' + batchingVertex)\n\n for (const uniformName in customUniforms) {\n parameters.uniforms[uniformName] = customUniforms[uniformName]\n }\n\n currentOnBeforeCompile.call(this, parameters, renderer)\n }\n\n material.defines = material.defines || {}\n material.defines.BATCHING = false\n }\n\n _initializeGeometry(reference: BufferGeometry): void {\n // @TODO: geometry.groups support?\n // @TODO: geometry.drawRange support?\n // @TODO: geometry.morphAttributes support?\n\n const geometry = this.geometry\n const maxVertexCount = this._maxVertexCount\n const maxGeometryCount = this._maxGeometryCount\n const maxIndexCount = this._maxIndexCount\n if (this._geometryInitialized === false) {\n for (const attributeName in reference.attributes) {\n const srcAttribute = reference.getAttribute(attributeName)\n const { array, itemSize, normalized } = srcAttribute\n\n const dstArray = new (array.constructor as Float32ArrayConstructor)(maxVertexCount * itemSize)\n const dstAttribute = new (srcAttribute.constructor as any)(dstArray, itemSize, normalized)\n\n // TODO: add usage in @types/three\n // @ts-ignore\n dstAttribute.setUsage(srcAttribute.usage)\n\n geometry.setAttribute(attributeName, dstAttribute)\n }\n\n if (reference.getIndex() !== null) {\n const indexArray = maxVertexCount > 65536 ? new Uint32Array(maxIndexCount) : new Uint16Array(maxIndexCount)\n\n geometry.setIndex(new BufferAttribute(indexArray, 1))\n }\n\n const idArray = maxGeometryCount > 65536 ? new Uint32Array(maxVertexCount) : new Uint16Array(maxVertexCount)\n geometry.setAttribute(ID_ATTR_NAME, new BufferAttribute(idArray, 1))\n\n this._geometryInitialized = true\n }\n }\n\n // Make sure the geometry is compatible with the existing combined geometry atributes\n _validateGeometry(geometry: BufferGeometry): void {\n // check that the geometry doesn't have a version of our reserved id attribute\n if (geometry.getAttribute(ID_ATTR_NAME)) {\n throw new Error(`BatchedMesh: Geometry cannot use attribute \"${ID_ATTR_NAME}\"`)\n }\n\n // check to ensure the geometries are using consistent attributes and indices\n const batchGeometry = this.geometry\n if (Boolean(geometry.getIndex()) !== Boolean(batchGeometry.getIndex())) {\n throw new Error('BatchedMesh: All geometries must consistently have \"index\".')\n }\n\n for (const attributeName in batchGeometry.attributes) {\n if (attributeName === ID_ATTR_NAME) {\n continue\n }\n\n if (!geometry.hasAttribute(attributeName)) {\n throw new Error(\n `BatchedMesh: Added geometry missing \"${attributeName}\". All geometries must have consistent attributes.`,\n )\n }\n\n const srcAttribute = geometry.getAttribute(attributeName)\n const dstAttribute = batchGeometry.getAttribute(attributeName)\n if (srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized) {\n throw new Error('BatchedMesh: All attributes must have a consistent itemSize and normalized value.')\n }\n }\n }\n\n getGeometryCount(): number {\n return this._geometryCount\n }\n\n getVertexCount(): number {\n const reservedRanges = this._reservedRanges\n if (reservedRanges.length === 0) {\n return 0\n } else {\n const finalRange = reservedRanges[reservedRanges.length - 1]\n return finalRange.vertexStart + finalRange.vertexCount\n }\n }\n\n getIndexCount(): number {\n const reservedRanges = this._reservedRanges\n const geometry = this.geometry\n if (geometry.getIndex() === null || reservedRanges.length === 0) {\n return 0\n } else {\n const finalRange = reservedRanges[reservedRanges.length - 1]\n return finalRange.indexStart + finalRange.indexCount\n }\n }\n\n addGeometry(geometry: BufferGeometry, vertexCount = -1, indexCount = -1): number {\n this._initializeGeometry(geometry)\n\n this._validateGeometry(geometry)\n\n // ensure we're not over geometry\n if (this._geometryCount >= this._maxGeometryCount) {\n throw new Error('BatchedMesh: Maximum geometry count reached.')\n }\n\n // get the necessary range fo the geometry\n const range = {\n vertexStart: -1,\n vertexCount: -1,\n indexStart: -1,\n indexCount: -1,\n }\n\n let lastRange = null\n const reservedRanges = this._reservedRanges\n if (this._geometryCount !== 0) {\n lastRange = reservedRanges[reservedRanges.length - 1]\n }\n\n if (vertexCount === -1) {\n range.vertexCount = geometry.getAttribute('position').count\n } else {\n range.vertexCount = vertexCount\n }\n\n if (lastRange === null) {\n range.vertexStart = 0\n } else {\n range.vertexStart = lastRange.vertexStart + lastRange.vertexCount\n }\n\n if (geometry.getIndex() !== null) {\n if (indexCount === -1) {\n range.indexCount = geometry.getIndex()!.count\n } else {\n range.indexCount = indexCount\n }\n\n if (lastRange === null) {\n range.indexStart = 0\n } else {\n range.indexStart = lastRange.indexStart + lastRange.indexCount\n }\n }\n\n if (\n (range.indexStart !== -1 && range.indexStart + range.indexCount > this._maxIndexCount) ||\n range.vertexStart + range.vertexCount > this._maxVertexCount\n ) {\n throw new Error('BatchedMesh: Reserved space request exceeds the maximum buffer size.')\n }\n\n const indexCounts = this._indexCounts\n const indexStarts = this._indexStarts\n const vertexCounts = this._vertexCounts\n const vertexStarts = this._vertexStarts\n\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture\n const matrices = this._matrices\n const matricesArray = this._matricesTexture!.image.data\n\n // push new visibility states\n visible.push(true)\n active.push(true)\n\n // update id\n const geometryId = this._geometryCount\n this._geometryCount++\n\n // initialize matrix information\n matrices.push(new Matrix4())\n _identityMatrix.toArray(matricesArray, geometryId * 16)\n matricesTexture!.needsUpdate = true\n\n // add the reserved range\n reservedRanges.push(range)\n\n // push new geometry data range\n vertexStarts.push(range.vertexStart)\n vertexCounts.push(range.vertexCount)\n\n if (geometry.getIndex() !== null) {\n // push new index range\n indexStarts.push(range.indexCount)\n indexCounts.push(range.indexCount)\n }\n\n // set the id for the geometry\n const idAttribute = this.geometry.getAttribute(ID_ATTR_NAME)\n for (let i = 0; i < range.vertexCount; i++) {\n idAttribute.setX(range.vertexStart + i, geometryId)\n }\n\n idAttribute.needsUpdate = true\n\n // update the geometry\n this.setGeometryAt(geometryId, geometry)\n\n return geometryId\n }\n\n /**\n * @deprecated use `addGeometry` instead.\n */\n applyGeometry(geometry: BufferGeometry): number {\n return this.addGeometry(geometry)\n }\n\n setGeometryAt(id: number, geometry: BufferGeometry): number {\n if (id >= this._geometryCount) {\n throw new Error('BatchedMesh: Maximum geometry count reached.')\n }\n\n this._validateGeometry(geometry)\n\n const range = this._reservedRanges[id]\n if (\n (geometry.getIndex() !== null && geometry.getIndex()!.count > range.indexCount) ||\n geometry.attributes.position.count > range.vertexCount\n ) {\n throw new Error('BatchedMesh: Reserved space not large enough for provided geometry.')\n }\n\n // copy geometry over\n const batchGeometry = this.geometry\n const srcPositionAttribute = geometry.getAttribute('position')\n const hasIndex = batchGeometry.getIndex() !== null\n const dstIndex = batchGeometry.getIndex()!\n const srcIndex = geometry.getIndex()!\n\n // copy attribute data over\n const vertexStart = range.vertexStart\n const vertexCount = range.vertexCount\n for (const attributeName in batchGeometry.attributes) {\n if (attributeName === ID_ATTR_NAME) {\n continue\n }\n\n const srcAttribute = geometry.getAttribute(attributeName)\n const dstAttribute = batchGeometry.getAttribute(attributeName)\n copyAttributeData(srcAttribute, dstAttribute, vertexStart)\n\n // fill the rest in with zeroes\n const itemSize = srcAttribute.itemSize\n for (let i = srcAttribute.count, l = vertexCount; i < l; i++) {\n const index = vertexStart + i\n for (let c = 0; c < itemSize; c++) {\n // @ts-ignore\n dstAttribute.setComponent(index, c, 0)\n }\n }\n\n dstAttribute.needsUpdate = true\n }\n\n this._vertexCounts[id] = srcPositionAttribute.count\n\n if (hasIndex) {\n // fill the rest in with zeroes\n const indexStart = range.indexStart\n\n // copy index data over\n for (let i = 0; i < srcIndex.count; i++) {\n dstIndex.setX(indexStart + i, vertexStart + srcIndex.getX(i))\n }\n\n // fill the rest in with zeroes\n for (let i = srcIndex.count, l = range.indexCount; i < l; i++) {\n dstIndex.setX(indexStart + i, vertexStart)\n }\n\n dstIndex.needsUpdate = true\n this._indexCounts[id] = srcIndex.count\n }\n\n return id\n }\n\n deleteGeometry(geometryId: number): this {\n // Note: User needs to call optimize() afterward to pack the data.\n\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matricesArray = matricesTexture.image.data\n if (geometryId >= active.length || active[geometryId] === false) {\n return this\n }\n\n active[geometryId] = false\n _zeroScaleMatrix.toArray(matricesArray, geometryId * 16)\n matricesTexture!.needsUpdate = true\n\n return this\n }\n\n optimize(): never {\n throw new Error('BatchedMesh: Optimize function not implemented.')\n }\n\n setMatrixAt(geometryId: number, matrix: Matrix4): this {\n // @TODO: Map geometryId to index of the arrays because\n // optimize() can make geometryId mismatch the index\n\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matrices = this._matrices\n const matricesArray = matricesTexture.image.data\n if (geometryId >= matrices.length || active[geometryId] === false) {\n return this\n }\n\n if (visible[geometryId] === true) {\n matrix.toArray(matricesArray, geometryId * 16)\n matricesTexture.needsUpdate = true\n }\n\n matrices[geometryId].copy(matrix)\n\n return this\n }\n\n getMatrixAt(geometryId: number, matrix: Matrix4): Matrix4 {\n const matrices = this._matrices\n const active = this._active\n if (geometryId >= matrices.length || active[geometryId] === false) {\n return matrix\n }\n\n return matrix.copy(matrices[geometryId])\n }\n\n setVisibleAt(geometryId: number, value: boolean): this {\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matrices = this._matrices\n const matricesArray = matricesTexture.image.data\n\n // if the geometry is out of range, not active, or visibility state\n // does not change then return early\n if (geometryId >= visible.length || active[geometryId] === false || visible[geometryId] === value) {\n return this\n }\n\n // scale the matrix to zero if it's hidden\n if (value === true) {\n matrices[geometryId].toArray(matricesArray, geometryId * 16)\n } else {\n _zeroScaleMatrix.toArray(matricesArray, geometryId * 16)\n }\n\n matricesTexture.needsUpdate = true\n visible[geometryId] = value\n\n return this\n }\n\n getVisibleAt(geometryId: number): boolean {\n const visible = this._visible\n const active = this._active\n\n // return early if the geometry is out of range or not active\n if (geometryId >= visible.length || active[geometryId] === false) {\n return false\n }\n\n return visible[geometryId]\n }\n\n raycast(): void {\n console.warn('BatchedMesh: Raycast function not implemented.')\n }\n\n copy(): never {\n // super.copy( source );\n\n throw new Error('BatchedMesh: Copy function not implemented.')\n }\n\n toJSON(): never {\n throw new Error('BatchedMesh: toJSON function not implemented.')\n }\n\n dispose(): this {\n // Assuming the geometry is not shared with other meshes\n this.geometry.dispose()\n\n this._matricesTexture!.dispose()\n this._matricesTexture = null!\n\n return this\n }\n}\n\nexport { BatchedMesh }\n"],"names":[],"mappings":";;;;;;;AAcA,MAAM,eAAe;AACrB,MAAM,kBAAkB,IAAI;AAC5B,MAAM,mBAAmB,IAAI,QAAQ,EAAE,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAGzF,MAAM;AAAA;AAAA,EAAgC;AAA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ute,\n InterleavedBufferAttribute,\n Mesh,\n BufferGeometry,\n Material,\n DataTexture,\n IUniform,\n MathUtils,\n RGBAFormat,\n FloatType,\n} from 'three'\n\nconst ID_ATTR_NAME = '_batch_id_'\nconst _identityMatrix = /* @__PURE__ */ new Matrix4()\nconst _zeroScaleMatrix = /* @__PURE__ */ (() => new Matrix4().set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1))()\n\n// Custom shaders\nconst batchingParsVertex = /* glsl */ `\n#ifdef BATCHING\n\tattribute float ${ID_ATTR_NAME};\n\tuniform highp sampler2D batchingTexture;\n\tmat4 getBatchingMatrix( const in float i ) {\n\n\t\tint size = textureSize( batchingTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\n\t}\n#endif\n`\n\nconst batchingbaseVertex = /* glsl */ `\n#ifdef BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( ${ID_ATTR_NAME} );\n#endif\n`\n\nconst batchingnormalVertex = /* glsl */ `\n#ifdef BATCHING\n\tobjectNormal = vec4( batchingMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( batchingMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif\n`\n\nconst batchingVertex = /* glsl */ `\n#ifdef BATCHING\n\ttransformed = ( batchingMatrix * vec4( transformed, 1.0 ) ).xyz;\n#endif\n`\n\n// @TODO: SkinnedMesh support?\n// @TODO: Future work if needed. Move into the core. Can be optimized more with WEBGL_multi_draw.\n\n// copies data from attribute \"src\" into \"target\" starting at \"targetOffset\"\nfunction copyAttributeData(\n src: BufferAttribute | InterleavedBufferAttribute,\n target: BufferAttribute | InterleavedBufferAttribute,\n targetOffset = 0,\n): void {\n const itemSize = target.itemSize\n if (\n (src as InterleavedBufferAttribute).isInterleavedBufferAttribute ||\n src.array.constructor !== target.array.constructor\n ) {\n // use the component getters and setters if the array data cannot\n // be copied directly\n const vertexCount = src.count\n for (let i = 0; i < vertexCount; i++) {\n for (let c = 0; c < itemSize; c++) {\n // @ts-ignore\n target.setComponent(i + targetOffset, c, src.getComponent(i, c))\n }\n }\n } else {\n // faster copy approach using typed array set function\n // @ts-ignore\n target.array.set(src.array, targetOffset * itemSize)\n }\n\n target.needsUpdate = true\n}\n\nclass BatchedMesh extends Mesh<BufferGeometry, Material> {\n _vertexStarts: number[]\n _vertexCounts: number[]\n _indexStarts: number[]\n _indexCounts: number[]\n _reservedRanges: { vertexStart: number; vertexCount: number; indexStart: number; indexCount: number }[]\n _visible: boolean[]\n _active: boolean[]\n _maxGeometryCount: number\n _maxVertexCount: number\n _maxIndexCount: number\n _geometryInitialized: boolean\n _geometryCount: number\n _matrices: Matrix4[]\n _matricesTexture: DataTexture | null\n _customUniforms: Record<string, IUniform>\n\n constructor(\n maxGeometryCount: number,\n maxVertexCount: number,\n maxIndexCount = maxVertexCount * 2,\n material?: Material,\n ) {\n super(new BufferGeometry(), material)\n\n this._vertexStarts = []\n this._vertexCounts = []\n this._indexStarts = []\n this._indexCounts = []\n this._reservedRanges = []\n\n this._visible = []\n this._active = []\n\n this._maxGeometryCount = maxGeometryCount\n this._maxVertexCount = maxVertexCount\n this._maxIndexCount = maxIndexCount\n\n this._geometryInitialized = false\n this._geometryCount = 0\n\n // Local matrix per geometry by using data texture\n // @TODO: Support uniform parameter per geometry\n\n this._matrices = []\n this._matricesTexture = null!\n\n // @TODO: Calculate the entire binding box and make frustumCulled true\n this.frustumCulled = false\n\n this._customUniforms = {\n batchingTexture: { value: null },\n }\n\n this._initMatricesTexture()\n this._initShader()\n\n this.onBeforeRender = function () {\n if (this.material.defines) {\n this.material.defines.BATCHING = true\n }\n\n // @TODO: Implement frustum culling for each geometry\n }\n\n this.onAfterRender = function () {\n if (this.material.defines) {\n this.material.defines.BATCHING = false\n }\n }\n }\n\n _initMatricesTexture(): void {\n // layout (1 matrix = 4 pixels)\n // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)\n // with 8x8 pixel texture max 16 matrices * 4 pixels = (8 * 8)\n // 16x16 pixel texture max 64 matrices * 4 pixels = (16 * 16)\n // 32x32 pixel texture max 256 matrices * 4 pixels = (32 * 32)\n // 64x64 pixel texture max 1024 matrices * 4 pixels = (64 * 64)\n\n let size = Math.sqrt(this._maxGeometryCount * 4) // 4 pixels needed for 1 matrix\n size = MathUtils.ceilPowerOfTwo(size)\n size = Math.max(size, 4)\n\n const matricesArray = new Float32Array(size * size * 4) // 4 floats per RGBA pixel\n const matricesTexture = new DataTexture(matricesArray, size, size, RGBAFormat, FloatType)\n\n this._matricesTexture = matricesTexture\n this._customUniforms.batchingTexture.value = this._matricesTexture\n }\n\n _initShader(): void {\n const material = this.material\n const currentOnBeforeCompile = material.onBeforeCompile\n const customUniforms = this._customUniforms\n\n material.onBeforeCompile = function onBeforeCompile(parameters, renderer) {\n // Is this replacement stable across any materials?\n parameters.vertexShader = parameters.vertexShader\n .replace('#include <skinning_pars_vertex>', '#include <skinning_pars_vertex>\\n' + batchingParsVertex)\n .replace('#include <uv_vertex>', '#include <uv_vertex>\\n' + batchingbaseVertex)\n .replace('#include <skinnormal_vertex>', '#include <skinnormal_vertex>\\n' + batchingnormalVertex)\n .replace('#include <skinning_vertex>', '#include <skinning_vertex>\\n' + batchingVertex)\n\n for (const uniformName in customUniforms) {\n parameters.uniforms[uniformName] = customUniforms[uniformName]\n }\n\n currentOnBeforeCompile.call(this, parameters, renderer)\n }\n\n material.defines = material.defines || {}\n material.defines.BATCHING = false\n }\n\n _initializeGeometry(reference: BufferGeometry): void {\n // @TODO: geometry.groups support?\n // @TODO: geometry.drawRange support?\n // @TODO: geometry.morphAttributes support?\n\n const geometry = this.geometry\n const maxVertexCount = this._maxVertexCount\n const maxGeometryCount = this._maxGeometryCount\n const maxIndexCount = this._maxIndexCount\n if (this._geometryInitialized === false) {\n for (const attributeName in reference.attributes) {\n const srcAttribute = reference.getAttribute(attributeName)\n const { array, itemSize, normalized } = srcAttribute\n\n const dstArray = new (array.constructor as Float32ArrayConstructor)(maxVertexCount * itemSize)\n const dstAttribute = new (srcAttribute.constructor as any)(dstArray, itemSize, normalized)\n\n // TODO: add usage in @types/three\n // @ts-ignore\n dstAttribute.setUsage(srcAttribute.usage)\n\n geometry.setAttribute(attributeName, dstAttribute)\n }\n\n if (reference.getIndex() !== null) {\n const indexArray = maxVertexCount > 65536 ? new Uint32Array(maxIndexCount) : new Uint16Array(maxIndexCount)\n\n geometry.setIndex(new BufferAttribute(indexArray, 1))\n }\n\n const idArray = maxGeometryCount > 65536 ? new Uint32Array(maxVertexCount) : new Uint16Array(maxVertexCount)\n geometry.setAttribute(ID_ATTR_NAME, new BufferAttribute(idArray, 1))\n\n this._geometryInitialized = true\n }\n }\n\n // Make sure the geometry is compatible with the existing combined geometry atributes\n _validateGeometry(geometry: BufferGeometry): void {\n // check that the geometry doesn't have a version of our reserved id attribute\n if (geometry.getAttribute(ID_ATTR_NAME)) {\n throw new Error(`BatchedMesh: Geometry cannot use attribute \"${ID_ATTR_NAME}\"`)\n }\n\n // check to ensure the geometries are using consistent attributes and indices\n const batchGeometry = this.geometry\n if (Boolean(geometry.getIndex()) !== Boolean(batchGeometry.getIndex())) {\n throw new Error('BatchedMesh: All geometries must consistently have \"index\".')\n }\n\n for (const attributeName in batchGeometry.attributes) {\n if (attributeName === ID_ATTR_NAME) {\n continue\n }\n\n if (!geometry.hasAttribute(attributeName)) {\n throw new Error(\n `BatchedMesh: Added geometry missing \"${attributeName}\". All geometries must have consistent attributes.`,\n )\n }\n\n const srcAttribute = geometry.getAttribute(attributeName)\n const dstAttribute = batchGeometry.getAttribute(attributeName)\n if (srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized) {\n throw new Error('BatchedMesh: All attributes must have a consistent itemSize and normalized value.')\n }\n }\n }\n\n getGeometryCount(): number {\n return this._geometryCount\n }\n\n getVertexCount(): number {\n const reservedRanges = this._reservedRanges\n if (reservedRanges.length === 0) {\n return 0\n } else {\n const finalRange = reservedRanges[reservedRanges.length - 1]\n return finalRange.vertexStart + finalRange.vertexCount\n }\n }\n\n getIndexCount(): number {\n const reservedRanges = this._reservedRanges\n const geometry = this.geometry\n if (geometry.getIndex() === null || reservedRanges.length === 0) {\n return 0\n } else {\n const finalRange = reservedRanges[reservedRanges.length - 1]\n return finalRange.indexStart + finalRange.indexCount\n }\n }\n\n addGeometry(geometry: BufferGeometry, vertexCount = -1, indexCount = -1): number {\n this._initializeGeometry(geometry)\n\n this._validateGeometry(geometry)\n\n // ensure we're not over geometry\n if (this._geometryCount >= this._maxGeometryCount) {\n throw new Error('BatchedMesh: Maximum geometry count reached.')\n }\n\n // get the necessary range fo the geometry\n const range = {\n vertexStart: -1,\n vertexCount: -1,\n indexStart: -1,\n indexCount: -1,\n }\n\n let lastRange = null\n const reservedRanges = this._reservedRanges\n if (this._geometryCount !== 0) {\n lastRange = reservedRanges[reservedRanges.length - 1]\n }\n\n if (vertexCount === -1) {\n range.vertexCount = geometry.getAttribute('position').count\n } else {\n range.vertexCount = vertexCount\n }\n\n if (lastRange === null) {\n range.vertexStart = 0\n } else {\n range.vertexStart = lastRange.vertexStart + lastRange.vertexCount\n }\n\n if (geometry.getIndex() !== null) {\n if (indexCount === -1) {\n range.indexCount = geometry.getIndex()!.count\n } else {\n range.indexCount = indexCount\n }\n\n if (lastRange === null) {\n range.indexStart = 0\n } else {\n range.indexStart = lastRange.indexStart + lastRange.indexCount\n }\n }\n\n if (\n (range.indexStart !== -1 && range.indexStart + range.indexCount > this._maxIndexCount) ||\n range.vertexStart + range.vertexCount > this._maxVertexCount\n ) {\n throw new Error('BatchedMesh: Reserved space request exceeds the maximum buffer size.')\n }\n\n const indexCounts = this._indexCounts\n const indexStarts = this._indexStarts\n const vertexCounts = this._vertexCounts\n const vertexStarts = this._vertexStarts\n\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture\n const matrices = this._matrices\n const matricesArray = this._matricesTexture!.image.data\n\n // push new visibility states\n visible.push(true)\n active.push(true)\n\n // update id\n const geometryId = this._geometryCount\n this._geometryCount++\n\n // initialize matrix information\n matrices.push(new Matrix4())\n _identityMatrix.toArray(matricesArray, geometryId * 16)\n matricesTexture!.needsUpdate = true\n\n // add the reserved range\n reservedRanges.push(range)\n\n // push new geometry data range\n vertexStarts.push(range.vertexStart)\n vertexCounts.push(range.vertexCount)\n\n if (geometry.getIndex() !== null) {\n // push new index range\n indexStarts.push(range.indexCount)\n indexCounts.push(range.indexCount)\n }\n\n // set the id for the geometry\n const idAttribute = this.geometry.getAttribute(ID_ATTR_NAME)\n for (let i = 0; i < range.vertexCount; i++) {\n idAttribute.setX(range.vertexStart + i, geometryId)\n }\n\n idAttribute.needsUpdate = true\n\n // update the geometry\n this.setGeometryAt(geometryId, geometry)\n\n return geometryId\n }\n\n /**\n * @deprecated use `addGeometry` instead.\n */\n applyGeometry(geometry: BufferGeometry): number {\n return this.addGeometry(geometry)\n }\n\n setGeometryAt(id: number, geometry: BufferGeometry): number {\n if (id >= this._geometryCount) {\n throw new Error('BatchedMesh: Maximum geometry count reached.')\n }\n\n this._validateGeometry(geometry)\n\n const range = this._reservedRanges[id]\n if (\n (geometry.getIndex() !== null && geometry.getIndex()!.count > range.indexCount) ||\n geometry.attributes.position.count > range.vertexCount\n ) {\n throw new Error('BatchedMesh: Reserved space not large enough for provided geometry.')\n }\n\n // copy geometry over\n const batchGeometry = this.geometry\n const srcPositionAttribute = geometry.getAttribute('position')\n const hasIndex = batchGeometry.getIndex() !== null\n const dstIndex = batchGeometry.getIndex()!\n const srcIndex = geometry.getIndex()!\n\n // copy attribute data over\n const vertexStart = range.vertexStart\n const vertexCount = range.vertexCount\n for (const attributeName in batchGeometry.attributes) {\n if (attributeName === ID_ATTR_NAME) {\n continue\n }\n\n const srcAttribute = geometry.getAttribute(attributeName)\n const dstAttribute = batchGeometry.getAttribute(attributeName)\n copyAttributeData(srcAttribute, dstAttribute, vertexStart)\n\n // fill the rest in with zeroes\n const itemSize = srcAttribute.itemSize\n for (let i = srcAttribute.count, l = vertexCount; i < l; i++) {\n const index = vertexStart + i\n for (let c = 0; c < itemSize; c++) {\n // @ts-ignore\n dstAttribute.setComponent(index, c, 0)\n }\n }\n\n dstAttribute.needsUpdate = true\n }\n\n this._vertexCounts[id] = srcPositionAttribute.count\n\n if (hasIndex) {\n // fill the rest in with zeroes\n const indexStart = range.indexStart\n\n // copy index data over\n for (let i = 0; i < srcIndex.count; i++) {\n dstIndex.setX(indexStart + i, vertexStart + srcIndex.getX(i))\n }\n\n // fill the rest in with zeroes\n for (let i = srcIndex.count, l = range.indexCount; i < l; i++) {\n dstIndex.setX(indexStart + i, vertexStart)\n }\n\n dstIndex.needsUpdate = true\n this._indexCounts[id] = srcIndex.count\n }\n\n return id\n }\n\n deleteGeometry(geometryId: number): this {\n // Note: User needs to call optimize() afterward to pack the data.\n\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matricesArray = matricesTexture.image.data\n if (geometryId >= active.length || active[geometryId] === false) {\n return this\n }\n\n active[geometryId] = false\n _zeroScaleMatrix.toArray(matricesArray, geometryId * 16)\n matricesTexture!.needsUpdate = true\n\n return this\n }\n\n optimize(): never {\n throw new Error('BatchedMesh: Optimize function not implemented.')\n }\n\n setMatrixAt(geometryId: number, matrix: Matrix4): this {\n // @TODO: Map geometryId to index of the arrays because\n // optimize() can make geometryId mismatch the index\n\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matrices = this._matrices\n const matricesArray = matricesTexture.image.data\n if (geometryId >= matrices.length || active[geometryId] === false) {\n return this\n }\n\n if (visible[geometryId] === true) {\n matrix.toArray(matricesArray, geometryId * 16)\n matricesTexture.needsUpdate = true\n }\n\n matrices[geometryId].copy(matrix)\n\n return this\n }\n\n getMatrixAt(geometryId: number, matrix: Matrix4): Matrix4 {\n const matrices = this._matrices\n const active = this._active\n if (geometryId >= matrices.length || active[geometryId] === false) {\n return matrix\n }\n\n return matrix.copy(matrices[geometryId])\n }\n\n setVisibleAt(geometryId: number, value: boolean): this {\n const visible = this._visible\n const active = this._active\n const matricesTexture = this._matricesTexture!\n const matrices = this._matrices\n const matricesArray = matricesTexture.image.data\n\n // if the geometry is out of range, not active, or visibility state\n // does not change then return early\n if (geometryId >= visible.length || active[geometryId] === false || visible[geometryId] === value) {\n return this\n }\n\n // scale the matrix to zero if it's hidden\n if (value === true) {\n matrices[geometryId].toArray(matricesArray, geometryId * 16)\n } else {\n _zeroScaleMatrix.toArray(matricesArray, geometryId * 16)\n }\n\n matricesTexture.needsUpdate = true\n visible[geometryId] = value\n\n return this\n }\n\n getVisibleAt(geometryId: number): boolean {\n const visible = this._visible\n const active = this._active\n\n // return early if the geometry is out of range or not active\n if (geometryId >= visible.length || active[geometryId] === false) {\n return false\n }\n\n return visible[geometryId]\n }\n\n raycast(): void {\n console.warn('BatchedMesh: Raycast function not implemented.')\n }\n\n copy(): never {\n // super.copy( source );\n\n throw new Error('BatchedMesh: Copy function not implemented.')\n }\n\n toJSON(): never {\n throw new Error('BatchedMesh: toJSON function not implemented.')\n }\n\n dispose(): this {\n // Assuming the geometry is not shared with other meshes\n this.geometry.dispose()\n\n this._matricesTexture!.dispose()\n this._matricesTexture = null!\n\n return this\n }\n}\n\nexport { BatchedMesh }\n"],"names":[],"mappings":";;;;;;;AAcA,MAAM,eAAe;AACrB,MAAM,sCAAsC;AAC5C,MAAM,0CAA0C,IAAI,UAAU,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAA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Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const THREE = require("three");
4
+ const constants = require("../_polyfill/constants.cjs");
4
5
  const isCubeTexture = (def) => def && def.isCubeTexture;
5
6
  class GroundProjectedEnv extends THREE.Mesh {
6
7
  constructor(texture, options) {
@@ -101,7 +102,7 @@ class GroundProjectedEnv extends THREE.Mesh {
101
102
  #endif
102
103
  gl_FragColor = vec4( outcolor, 1.0 );
103
104
  #include <tonemapping_fragment>
104
- #include <${parseInt(THREE.REVISION.replace(/\D+/g, "")) >= 154 ? "colorspace_fragment" : "encodings_fragment"}>
105
+ #include <${constants.version >= 154 ? "colorspace_fragment" : "encodings_fragment"}>
105
106
  }
106
107
  `;
107
108
  const uniforms = {
@@ -1 +1 @@
1
- {"version":3,"file":"GroundProjectedEnv.cjs","sources":["../../src/objects/GroundProjectedEnv.ts"],"sourcesContent":["import {\n Mesh,\n IcosahedronGeometry,\n ShaderMaterial,\n DoubleSide,\n Texture,\n CubeTexture,\n BufferGeometry,\n REVISION,\n} from 'three'\n\nexport interface GroundProjectedEnvParameters {\n height?: number\n radius?: number\n}\n\nconst isCubeTexture = (def: CubeTexture | Texture): def is CubeTexture => def && (def as CubeTexture).isCubeTexture\n\nexport class GroundProjectedEnv extends Mesh<BufferGeometry, ShaderMaterial> {\n constructor(texture: CubeTexture | Texture, options?: GroundProjectedEnvParameters) {\n const isCubeMap = isCubeTexture(texture)\n const w = (isCubeMap ? texture.image[0]?.width : texture.image.width) ?? 1024\n const cubeSize = w / 4\n const _lodMax = Math.floor(Math.log2(cubeSize))\n const _cubeSize = Math.pow(2, _lodMax)\n const width = 3 * Math.max(_cubeSize, 16 * 7)\n const height = 4 * _cubeSize\n\n const defines = [\n isCubeMap ? '#define ENVMAP_TYPE_CUBE' : '',\n `#define CUBEUV_TEXEL_WIDTH ${1.0 / width}`,\n `#define CUBEUV_TEXEL_HEIGHT ${1.0 / height}`,\n `#define CUBEUV_MAX_MIP ${_lodMax}.0`,\n ]\n\n const vertexShader = /* glsl */ `\n varying vec3 vWorldPosition;\n void main() \n {\n vec4 worldPosition = ( modelMatrix * vec4( position, 1.0 ) );\n vWorldPosition = worldPosition.xyz;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n `\n const fragmentShader =\n defines.join('\\n') +\n /* glsl */ `\n #define ENVMAP_TYPE_CUBE_UV\n varying vec3 vWorldPosition;\n uniform float radius;\n uniform float height;\n uniform float angle;\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube map;\n #else\n uniform sampler2D map;\n #endif\n // From: https://www.shadertoy.com/view/4tsBD7\n float diskIntersectWithBackFaceCulling( vec3 ro, vec3 rd, vec3 c, vec3 n, float r ) \n {\n float d = dot ( rd, n );\n \n if( d > 0.0 ) { return 1e6; }\n \n vec3 o = ro - c;\n float t = - dot( n, o ) / d;\n vec3 q = o + rd * t;\n \n return ( dot( q, q ) < r * r ) ? t : 1e6;\n }\n // From: https://www.iquilezles.org/www/articles/intersectors/intersectors.htm\n float sphereIntersect( vec3 ro, vec3 rd, vec3 ce, float ra ) \n {\n vec3 oc = ro - ce;\n float b = dot( oc, rd );\n float c = dot( oc, oc ) - ra * ra;\n float h = b * b - c;\n \n if( h < 0.0 ) { return -1.0; }\n \n h = sqrt( h );\n \n return - b + h;\n }\n vec3 project() \n {\n vec3 p = normalize( vWorldPosition );\n vec3 camPos = cameraPosition;\n camPos.y -= height;\n float intersection = sphereIntersect( camPos, p, vec3( 0.0 ), radius );\n if( intersection > 0.0 ) {\n \n vec3 h = vec3( 0.0, - height, 0.0 );\n float intersection2 = diskIntersectWithBackFaceCulling( camPos, p, h, vec3( 0.0, 1.0, 0.0 ), radius );\n p = ( camPos + min( intersection, intersection2 ) * p ) / radius;\n } else {\n p = vec3( 0.0, 1.0, 0.0 );\n }\n return p;\n }\n #include <common>\n #include <cube_uv_reflection_fragment>\n void main() \n {\n vec3 projectedWorldPosition = project();\n \n #ifdef ENVMAP_TYPE_CUBE\n vec3 outcolor = textureCube( map, projectedWorldPosition ).rgb;\n #else\n vec3 direction = normalize( projectedWorldPosition );\n vec2 uv = equirectUv( direction );\n vec3 outcolor = texture2D( map, uv ).rgb;\n #endif\n gl_FragColor = vec4( outcolor, 1.0 );\n #include <tonemapping_fragment>\n #include <${parseInt(REVISION.replace(/\\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>\n }\n `\n\n const uniforms = {\n map: { value: texture },\n height: { value: options?.height || 15 },\n radius: { value: options?.radius || 100 },\n }\n\n const geometry = new IcosahedronGeometry(1, 16)\n const material = new ShaderMaterial({\n uniforms,\n fragmentShader,\n vertexShader,\n side: DoubleSide,\n })\n\n super(geometry, material)\n }\n\n set radius(radius: number) {\n this.material.uniforms.radius.value = radius\n }\n\n get radius(): number {\n return this.material.uniforms.radius.value\n }\n\n set height(height: number) {\n this.material.uniforms.height.value = height\n }\n\n get height(): number {\n return this.material.uniforms.height.value\n }\n}\n"],"names":["Mesh","REVISION","IcosahedronGeometry","ShaderMaterial","DoubleSide"],"mappings":";;;AAgBA,MAAM,gBAAgB,CAAC,QAAmD,OAAQ,IAAoB;AAE/F,MAAM,2BAA2BA,MAAAA,KAAqC;AAAA,EAC3E,YAAY,SAAgC,SAAwC;;AAC5E,UAAA,YAAY,cAAc,OAAO;AACjC,UAAA,KAAK,kBAAY,aAAQ,MAAM,CAAC,MAAf,mBAAkB,QAAQ,QAAQ,MAAM,UAApD,YAA8D;AACzE,UAAM,WAAW,IAAI;AACrB,UAAM,UAAU,KAAK,MAAM,KAAK,KAAK,QAAQ,CAAC;AAC9C,UAAM,YAAY,KAAK,IAAI,GAAG,OAAO;AACrC,UAAM,QAAQ,IAAI,KAAK,IAAI,WAAW,KAAK,CAAC;AAC5C,UAAM,SAAS,IAAI;AAEnB,UAAM,UAAU;AAAA,MACd,YAAY,6BAA6B;AAAA,MACzC,8BAA8B,IAAM;AAAA,MACpC,+BAA+B,IAAM;AAAA,MACrC,0BAA0B;AAAA,IAAA;AA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ACxC;AAAA,EAEA,IAAI,SAAiB;AACZ,WAAA,KAAK,SAAS,SAAS,OAAO;AAAA,EACvC;AACF;;"}
1
+ {"version":3,"file":"GroundProjectedEnv.cjs","sources":["../../src/objects/GroundProjectedEnv.ts"],"sourcesContent":["import { Mesh, IcosahedronGeometry, ShaderMaterial, DoubleSide, Texture, CubeTexture, BufferGeometry } from 'three'\nimport { version } from '../_polyfill/constants'\n\nexport interface GroundProjectedEnvParameters {\n height?: number\n radius?: number\n}\n\nconst isCubeTexture = (def: CubeTexture | Texture): def is CubeTexture => def && (def as CubeTexture).isCubeTexture\n\nexport class GroundProjectedEnv extends Mesh<BufferGeometry, ShaderMaterial> {\n constructor(texture: CubeTexture | Texture, options?: GroundProjectedEnvParameters) {\n const isCubeMap = isCubeTexture(texture)\n const w = (isCubeMap ? texture.image[0]?.width : texture.image.width) ?? 1024\n const cubeSize = w / 4\n const _lodMax = Math.floor(Math.log2(cubeSize))\n const _cubeSize = Math.pow(2, _lodMax)\n const width = 3 * Math.max(_cubeSize, 16 * 7)\n const height = 4 * _cubeSize\n\n const defines = [\n isCubeMap ? '#define ENVMAP_TYPE_CUBE' : '',\n `#define CUBEUV_TEXEL_WIDTH ${1.0 / width}`,\n `#define CUBEUV_TEXEL_HEIGHT ${1.0 / height}`,\n `#define CUBEUV_MAX_MIP ${_lodMax}.0`,\n ]\n\n const vertexShader = /* glsl */ `\n varying vec3 vWorldPosition;\n void main() \n {\n vec4 worldPosition = ( modelMatrix * vec4( position, 1.0 ) );\n vWorldPosition = worldPosition.xyz;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n `\n const fragmentShader =\n defines.join('\\n') +\n /* glsl */ `\n #define ENVMAP_TYPE_CUBE_UV\n varying vec3 vWorldPosition;\n uniform float radius;\n uniform float height;\n uniform float angle;\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube map;\n #else\n uniform sampler2D map;\n #endif\n // From: https://www.shadertoy.com/view/4tsBD7\n float diskIntersectWithBackFaceCulling( vec3 ro, vec3 rd, vec3 c, vec3 n, float r ) \n {\n float d = dot ( rd, n );\n \n if( d > 0.0 ) { return 1e6; }\n \n vec3 o = ro - c;\n float t = - dot( n, o ) / d;\n vec3 q = o + rd * t;\n \n return ( dot( q, q ) < r * r ) ? t : 1e6;\n }\n // From: https://www.iquilezles.org/www/articles/intersectors/intersectors.htm\n float sphereIntersect( vec3 ro, vec3 rd, vec3 ce, float ra ) \n {\n vec3 oc = ro - ce;\n float b = dot( oc, rd );\n float c = dot( oc, oc ) - ra * ra;\n float h = b * b - c;\n \n if( h < 0.0 ) { return -1.0; }\n \n h = sqrt( h );\n \n return - b + h;\n }\n vec3 project() \n {\n vec3 p = normalize( vWorldPosition );\n vec3 camPos = cameraPosition;\n camPos.y -= height;\n float intersection = sphereIntersect( camPos, p, vec3( 0.0 ), radius );\n if( intersection > 0.0 ) {\n \n vec3 h = vec3( 0.0, - height, 0.0 );\n float intersection2 = diskIntersectWithBackFaceCulling( camPos, p, h, vec3( 0.0, 1.0, 0.0 ), radius );\n p = ( camPos + min( intersection, intersection2 ) * p ) / radius;\n } else {\n p = vec3( 0.0, 1.0, 0.0 );\n }\n return p;\n }\n #include <common>\n #include <cube_uv_reflection_fragment>\n void main() \n {\n vec3 projectedWorldPosition = project();\n \n #ifdef ENVMAP_TYPE_CUBE\n vec3 outcolor = textureCube( map, projectedWorldPosition ).rgb;\n #else\n vec3 direction = normalize( projectedWorldPosition );\n vec2 uv = equirectUv( direction );\n vec3 outcolor = texture2D( map, uv ).rgb;\n #endif\n gl_FragColor = vec4( outcolor, 1.0 );\n #include <tonemapping_fragment>\n #include <${version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>\n }\n `\n\n const uniforms = {\n map: { value: texture },\n height: { value: options?.height || 15 },\n radius: { value: options?.radius || 100 },\n }\n\n const geometry = new IcosahedronGeometry(1, 16)\n const material = new ShaderMaterial({\n uniforms,\n fragmentShader,\n vertexShader,\n side: DoubleSide,\n })\n\n super(geometry, material)\n }\n\n set radius(radius: number) {\n this.material.uniforms.radius.value = radius\n }\n\n get radius(): number {\n return this.material.uniforms.radius.value\n }\n\n set height(height: number) {\n this.material.uniforms.height.value = height\n }\n\n get height(): number {\n return this.material.uniforms.height.value\n }\n}\n"],"names":["Mesh","version","IcosahedronGeometry","ShaderMaterial","DoubleSide"],"mappings":";;;;AAQA,MAAM,gBAAgB,CAAC,QAAmD,OAAQ,IAAoB;AAE/F,MAAM,2BAA2BA,MAAAA,KAAqC;AAAA,EAC3E,YAAY,SAAgC,SAAwC;;AAC5E,UAAA,YAAY,cAAc,OAAO;AACjC,UAAA,KAAK,kBAAY,aAAQ,MAAM,CAAC,MAAf,mBAAkB,QAAQ,QAAQ,MAAM,UAApD,YAA8D;AACzE,UAAM,WAAW,IAAI;AACrB,UAAM,UAAU,KAAK,MAAM,KAAK,KAAK,QAAQ,CAAC;AAC9C,UAAM,YAAY,KAAK,IAAI,GAAG,OAAO;AACrC,UAAM,QAAQ,IAAI,KAAK,IAAI,WAAW,KAAK,CAAC;AAC5C,UAAM,SAAS,IAAI;AAEnB,UAAM,UAAU;AAAA,MACd,YAAY,6BAA6B;AAAA,MACzC,8BAA8B,IAAM;AAAA,MACpC,+BAA+B,IAAM;AAAA,MACrC,0BAA0B;AAAA,IAAA;AAGtB,UAAA;AAAA;AAAA,MAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAU1B,UAAA,iBACJ,QAAQ,KAAK,IAAI;AAAA,IACN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAqEOC,qBAAW,MAAM,wBAAwB;AAAA;AAAA;AAI7D,UAAM,WAAW;AAAA,MACf,KAAK,EAAE,OAAO,QAAQ;AAAA,MACtB,QAAQ,EAAE,QAAO,mCAAS,WAAU,GAAG;AAAA,MACvC,QAAQ,EAAE,QAAO,mCAAS,WAAU,IAAI;AAAA,IAAA;AAG1C,UAAM,WAAW,IAAIC,MAAAA,oBAAoB,GAAG,EAAE;AACxC,UAAA,WAAW,IAAIC,qBAAe;AAAA,MAClC;AAAA,MACA;AAAA,MACA;AAAA,MACA,MAAMC,MAAA;AAAA,IAAA,CACP;AAED,UAAM,UAAU,QAAQ;AAAA,EAC1B;AAAA,EAEA,IAAI,OAAO,QAAgB;AACpB,SAAA,SAAS,SAAS,OAAO,QAAQ;AAAA,EACxC;AAAA,EAEA,IAAI,SAAiB;AACZ,WAAA,KAAK,SAAS,SAAS,OAAO;AAAA,EACvC;AAAA,EAEA,IAAI,OAAO,QAAgB;AACpB,SAAA,SAAS,SAAS,OAAO,QAAQ;AAAA,EACxC;AAAA,EAEA,IAAI,SAAiB;AACZ,WAAA,KAAK,SAAS,SAAS,OAAO;AAAA,EACvC;AACF;;"}
@@ -1,4 +1,5 @@
1
- import { Mesh, REVISION, IcosahedronGeometry, ShaderMaterial, DoubleSide } from "three";
1
+ import { Mesh, IcosahedronGeometry, ShaderMaterial, DoubleSide } from "three";
2
+ import { version } from "../_polyfill/constants.js";
2
3
  const isCubeTexture = (def) => def && def.isCubeTexture;
3
4
  class GroundProjectedEnv extends Mesh {
4
5
  constructor(texture, options) {
@@ -99,7 +100,7 @@ class GroundProjectedEnv extends Mesh {
99
100
  #endif
100
101
  gl_FragColor = vec4( outcolor, 1.0 );
101
102
  #include <tonemapping_fragment>
102
- #include <${parseInt(REVISION.replace(/\D+/g, "")) >= 154 ? "colorspace_fragment" : "encodings_fragment"}>
103
+ #include <${version >= 154 ? "colorspace_fragment" : "encodings_fragment"}>
103
104
  }
104
105
  `;
105
106
  const uniforms = {
@@ -1 +1 @@
1
- {"version":3,"file":"GroundProjectedEnv.js","sources":["../../src/objects/GroundProjectedEnv.ts"],"sourcesContent":["import {\n Mesh,\n IcosahedronGeometry,\n ShaderMaterial,\n DoubleSide,\n Texture,\n CubeTexture,\n BufferGeometry,\n REVISION,\n} from 'three'\n\nexport interface GroundProjectedEnvParameters {\n height?: number\n radius?: number\n}\n\nconst isCubeTexture = (def: CubeTexture | Texture): def is CubeTexture => def && (def as CubeTexture).isCubeTexture\n\nexport class GroundProjectedEnv extends Mesh<BufferGeometry, ShaderMaterial> {\n constructor(texture: CubeTexture | Texture, options?: GroundProjectedEnvParameters) {\n const isCubeMap = isCubeTexture(texture)\n const w = (isCubeMap ? texture.image[0]?.width : texture.image.width) ?? 1024\n const cubeSize = w / 4\n const _lodMax = Math.floor(Math.log2(cubeSize))\n const _cubeSize = Math.pow(2, _lodMax)\n const width = 3 * Math.max(_cubeSize, 16 * 7)\n const height = 4 * _cubeSize\n\n const defines = [\n isCubeMap ? '#define ENVMAP_TYPE_CUBE' : '',\n `#define CUBEUV_TEXEL_WIDTH ${1.0 / width}`,\n `#define CUBEUV_TEXEL_HEIGHT ${1.0 / height}`,\n `#define CUBEUV_MAX_MIP ${_lodMax}.0`,\n ]\n\n const vertexShader = /* glsl */ `\n varying vec3 vWorldPosition;\n void main() \n {\n vec4 worldPosition = ( modelMatrix * vec4( position, 1.0 ) );\n vWorldPosition = worldPosition.xyz;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n `\n const fragmentShader =\n defines.join('\\n') +\n /* glsl */ `\n #define ENVMAP_TYPE_CUBE_UV\n varying vec3 vWorldPosition;\n uniform float radius;\n uniform float height;\n uniform float angle;\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube map;\n #else\n uniform sampler2D map;\n #endif\n // From: https://www.shadertoy.com/view/4tsBD7\n float diskIntersectWithBackFaceCulling( vec3 ro, vec3 rd, vec3 c, vec3 n, float r ) \n {\n float d = dot ( rd, n );\n \n if( d > 0.0 ) { return 1e6; }\n \n vec3 o = ro - c;\n float t = - dot( n, o ) / d;\n vec3 q = o + rd * t;\n \n return ( dot( q, q ) < r * r ) ? t : 1e6;\n }\n // From: https://www.iquilezles.org/www/articles/intersectors/intersectors.htm\n float sphereIntersect( vec3 ro, vec3 rd, vec3 ce, float ra ) \n {\n vec3 oc = ro - ce;\n float b = dot( oc, rd );\n float c = dot( oc, oc ) - ra * ra;\n float h = b * b - c;\n \n if( h < 0.0 ) { return -1.0; }\n \n h = sqrt( h );\n \n return - b + h;\n }\n vec3 project() \n {\n vec3 p = normalize( vWorldPosition );\n vec3 camPos = cameraPosition;\n camPos.y -= height;\n float intersection = sphereIntersect( camPos, p, vec3( 0.0 ), radius );\n if( intersection > 0.0 ) {\n \n vec3 h = vec3( 0.0, - height, 0.0 );\n float intersection2 = diskIntersectWithBackFaceCulling( camPos, p, h, vec3( 0.0, 1.0, 0.0 ), radius );\n p = ( camPos + min( intersection, intersection2 ) * p ) / radius;\n } else {\n p = vec3( 0.0, 1.0, 0.0 );\n }\n return p;\n }\n #include <common>\n #include <cube_uv_reflection_fragment>\n void main() \n {\n vec3 projectedWorldPosition = project();\n \n #ifdef ENVMAP_TYPE_CUBE\n vec3 outcolor = textureCube( map, projectedWorldPosition ).rgb;\n #else\n vec3 direction = normalize( projectedWorldPosition );\n vec2 uv = equirectUv( direction );\n vec3 outcolor = texture2D( map, uv ).rgb;\n #endif\n gl_FragColor = vec4( outcolor, 1.0 );\n #include <tonemapping_fragment>\n #include <${parseInt(REVISION.replace(/\\D+/g, '')) >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>\n }\n `\n\n const uniforms = {\n map: { value: texture },\n height: { value: options?.height || 15 },\n radius: { value: options?.radius || 100 },\n }\n\n const geometry = new IcosahedronGeometry(1, 16)\n const material = new ShaderMaterial({\n uniforms,\n fragmentShader,\n vertexShader,\n side: DoubleSide,\n })\n\n super(geometry, material)\n }\n\n set radius(radius: number) {\n this.material.uniforms.radius.value = radius\n }\n\n get radius(): number {\n return this.material.uniforms.radius.value\n }\n\n set height(height: number) {\n this.material.uniforms.height.value = height\n }\n\n get height(): number {\n return this.material.uniforms.height.value\n }\n}\n"],"names":[],"mappings":";AAgBA,MAAM,gBAAgB,CAAC,QAAmD,OAAQ,IAAoB;AAE/F,MAAM,2BAA2B,KAAqC;AAAA,EAC3E,YAAY,SAAgC,SAAwC;;AAC5E,UAAA,YAAY,cAAc,OAAO;AACjC,UAAA,KAAK,kBAAY,aAAQ,MAAM,CAAC,MAAf,mBAAkB,QAAQ,QAAQ,MAAM,UAApD,YAA8D;AACzE,UAAM,WAAW,IAAI;AACrB,UAAM,UAAU,KAAK,MAAM,KAAK,KAAK,QAAQ,CAAC;AAC9C,UAAM,YAAY,KAAK,IAAI,GAAG,OAAO;AACrC,UAAM,QAAQ,IAAI,KAAK,IAAI,WAAW,KAAK,CAAC;AAC5C,UAAM,SAAS,IAAI;AAEnB,UAAM,UAAU;AAAA,MACd,YAAY,6BAA6B;AAAA,MACzC,8BAA8B,IAAM;AAAA,MACpC,+BAA+B,IAAM;AAAA,MACrC,0BAA0B;AAAA,IAAA;AAGtB,UAAA;AAAA;AAAA,MAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAU1B,UAAA,iBACJ,QAAQ,KAAK,IAAI;AAAA,IACN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAqEO,SAAS,SAAS,QAAQ,QAAQ,EAAE,CAAC,KAAK,MAAM,wBAAwB;AAAA;AAAA;AAI5F,UAAM,WAAW;AAAA,MACf,KAAK,EAAE,OAAO,QAAQ;AAAA,MACtB,QAAQ,EAAE,QAAO,mCAAS,WAAU,GAAG;AAAA,MACvC,QAAQ,EAAE,QAAO,mCAAS,WAAU,IAAI;AAAA,IAAA;AAG1C,UAAM,WAAW,IAAI,oBAAoB,GAAG,EAAE;AACxC,UAAA,WAAW,IAAI,eAAe;AAAA,MAClC;AAAA,MACA;AAAA,MACA;AAAA,MACA,MAAM;AAAA,IAAA,CACP;AAED,UAAM,UAAU,QAAQ;AAAA,EAC1B;AAAA,EAEA,IAAI,OAAO,QAAgB;AACpB,SAAA,SAAS,SAAS,OAAO,QAAQ;AAAA,EACxC;AAAA,EAEA,IAAI,SAAiB;AACZ,WAAA,KAAK,SAAS,SAAS,OAAO;AAAA,EACvC;AAAA,EAEA,IAAI,OAAO,QAAgB;AACpB,SAAA,SAAS,SAAS,OAAO,QAAQ;AAAA,EACxC;AAAA,EAEA,IAAI,SAAiB;AACZ,WAAA,KAAK,SAAS,SAAS,OAAO;AAAA,EACvC;AACF;"}
1
+ {"version":3,"file":"GroundProjectedEnv.js","sources":["../../src/objects/GroundProjectedEnv.ts"],"sourcesContent":["import { Mesh, IcosahedronGeometry, ShaderMaterial, DoubleSide, Texture, CubeTexture, BufferGeometry } from 'three'\nimport { version } from '../_polyfill/constants'\n\nexport interface GroundProjectedEnvParameters {\n height?: number\n radius?: number\n}\n\nconst isCubeTexture = (def: CubeTexture | Texture): def is CubeTexture => def && (def as CubeTexture).isCubeTexture\n\nexport class GroundProjectedEnv extends Mesh<BufferGeometry, ShaderMaterial> {\n constructor(texture: CubeTexture | Texture, options?: GroundProjectedEnvParameters) {\n const isCubeMap = isCubeTexture(texture)\n const w = (isCubeMap ? texture.image[0]?.width : texture.image.width) ?? 1024\n const cubeSize = w / 4\n const _lodMax = Math.floor(Math.log2(cubeSize))\n const _cubeSize = Math.pow(2, _lodMax)\n const width = 3 * Math.max(_cubeSize, 16 * 7)\n const height = 4 * _cubeSize\n\n const defines = [\n isCubeMap ? '#define ENVMAP_TYPE_CUBE' : '',\n `#define CUBEUV_TEXEL_WIDTH ${1.0 / width}`,\n `#define CUBEUV_TEXEL_HEIGHT ${1.0 / height}`,\n `#define CUBEUV_MAX_MIP ${_lodMax}.0`,\n ]\n\n const vertexShader = /* glsl */ `\n varying vec3 vWorldPosition;\n void main() \n {\n vec4 worldPosition = ( modelMatrix * vec4( position, 1.0 ) );\n vWorldPosition = worldPosition.xyz;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n `\n const fragmentShader =\n defines.join('\\n') +\n /* glsl */ `\n #define ENVMAP_TYPE_CUBE_UV\n varying vec3 vWorldPosition;\n uniform float radius;\n uniform float height;\n uniform float angle;\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube map;\n #else\n uniform sampler2D map;\n #endif\n // From: https://www.shadertoy.com/view/4tsBD7\n float diskIntersectWithBackFaceCulling( vec3 ro, vec3 rd, vec3 c, vec3 n, float r ) \n {\n float d = dot ( rd, n );\n \n if( d > 0.0 ) { return 1e6; }\n \n vec3 o = ro - c;\n float t = - dot( n, o ) / d;\n vec3 q = o + rd * t;\n \n return ( dot( q, q ) < r * r ) ? t : 1e6;\n }\n // From: https://www.iquilezles.org/www/articles/intersectors/intersectors.htm\n float sphereIntersect( vec3 ro, vec3 rd, vec3 ce, float ra ) \n {\n vec3 oc = ro - ce;\n float b = dot( oc, rd );\n float c = dot( oc, oc ) - ra * ra;\n float h = b * b - c;\n \n if( h < 0.0 ) { return -1.0; }\n \n h = sqrt( h );\n \n return - b + h;\n }\n vec3 project() \n {\n vec3 p = normalize( vWorldPosition );\n vec3 camPos = cameraPosition;\n camPos.y -= height;\n float intersection = sphereIntersect( camPos, p, vec3( 0.0 ), radius );\n if( intersection > 0.0 ) {\n \n vec3 h = vec3( 0.0, - height, 0.0 );\n float intersection2 = diskIntersectWithBackFaceCulling( camPos, p, h, vec3( 0.0, 1.0, 0.0 ), radius );\n p = ( camPos + min( intersection, intersection2 ) * p ) / radius;\n } else {\n p = vec3( 0.0, 1.0, 0.0 );\n }\n return p;\n }\n #include <common>\n #include <cube_uv_reflection_fragment>\n void main() \n {\n vec3 projectedWorldPosition = project();\n \n #ifdef ENVMAP_TYPE_CUBE\n vec3 outcolor = textureCube( map, projectedWorldPosition ).rgb;\n #else\n vec3 direction = normalize( projectedWorldPosition );\n vec2 uv = equirectUv( direction );\n vec3 outcolor = texture2D( map, uv ).rgb;\n #endif\n gl_FragColor = vec4( outcolor, 1.0 );\n #include <tonemapping_fragment>\n #include <${version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>\n }\n `\n\n const uniforms = {\n map: { value: texture },\n height: { value: options?.height || 15 },\n radius: { value: options?.radius || 100 },\n }\n\n const geometry = new IcosahedronGeometry(1, 16)\n const material = new ShaderMaterial({\n uniforms,\n fragmentShader,\n vertexShader,\n side: DoubleSide,\n })\n\n super(geometry, material)\n }\n\n set radius(radius: number) {\n this.material.uniforms.radius.value = radius\n }\n\n get radius(): number {\n return this.material.uniforms.radius.value\n }\n\n set height(height: number) {\n this.material.uniforms.height.value = height\n }\n\n get height(): number {\n return this.material.uniforms.height.value\n }\n}\n"],"names":[],"mappings":";;AAQA,MAAM,gBAAgB,CAAC,QAAmD,OAAQ,IAAoB;AAE/F,MAAM,2BAA2B,KAAqC;AAAA,EAC3E,YAAY,SAAgC,SAAwC;;AAC5E,UAAA,YAAY,cAAc,OAAO;AACjC,UAAA,KAAK,kBAAY,aAAQ,MAAM,CAAC,MAAf,mBAAkB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