@onerjs/core 8.48.4 → 8.48.6

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 (119) hide show
  1. package/Animations/animatable.core.d.ts +13 -0
  2. package/Animations/animatable.core.js +46 -7
  3. package/Animations/animatable.core.js.map +1 -1
  4. package/Cameras/Inputs/geospatialCameraPointersInput.js +10 -8
  5. package/Cameras/Inputs/geospatialCameraPointersInput.js.map +1 -1
  6. package/Cameras/geospatialCameraMovement.js +2 -2
  7. package/Cameras/geospatialCameraMovement.js.map +1 -1
  8. package/FrameGraph/Node/Blocks/Rendering/iblShadowsRendererBlock.d.ts +105 -0
  9. package/FrameGraph/Node/Blocks/Rendering/iblShadowsRendererBlock.js +318 -0
  10. package/FrameGraph/Node/Blocks/Rendering/iblShadowsRendererBlock.js.map +1 -0
  11. package/FrameGraph/Node/Blocks/index.d.ts +1 -0
  12. package/FrameGraph/Node/Blocks/index.js +1 -0
  13. package/FrameGraph/Node/Blocks/index.js.map +1 -1
  14. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.d.ts +34 -0
  15. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.js +144 -0
  16. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.js.map +1 -0
  17. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsSpatialBlurTask.d.ts +26 -0
  18. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsSpatialBlurTask.js +82 -0
  19. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsSpatialBlurTask.js.map +1 -0
  20. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsTracingTask.d.ts +61 -0
  21. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsTracingTask.js +207 -0
  22. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsTracingTask.js.map +1 -0
  23. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsVoxelizationTask.d.ts +104 -0
  24. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsVoxelizationTask.js +218 -0
  25. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsVoxelizationTask.js.map +1 -0
  26. package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.d.ts +217 -0
  27. package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.js +640 -0
  28. package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.js.map +1 -0
  29. package/FrameGraph/frameGraph.js +1 -0
  30. package/FrameGraph/frameGraph.js.map +1 -1
  31. package/FrameGraph/index.d.ts +1 -0
  32. package/FrameGraph/index.js +1 -0
  33. package/FrameGraph/index.js.map +1 -1
  34. package/Materials/PBR/openpbrMaterial.d.ts +13 -2
  35. package/Materials/PBR/openpbrMaterial.js +47 -16
  36. package/Materials/PBR/openpbrMaterial.js.map +1 -1
  37. package/Materials/PBR/pbrBRDFConfiguration.js +1 -1
  38. package/Materials/PBR/pbrBRDFConfiguration.js.map +1 -1
  39. package/Materials/Textures/Filtering/hdrFiltering.js +6 -0
  40. package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
  41. package/Materials/Textures/envCubeTexture.js +13 -13
  42. package/Materials/Textures/envCubeTexture.js.map +1 -1
  43. package/Materials/materialHelper.functions.js +1 -1
  44. package/Materials/materialHelper.functions.js.map +1 -1
  45. package/Misc/textureTools.d.ts +3 -1
  46. package/Misc/textureTools.js +74 -13
  47. package/Misc/textureTools.js.map +1 -1
  48. package/Particles/baseParticleSystem.d.ts +33 -1
  49. package/Particles/baseParticleSystem.js +65 -0
  50. package/Particles/baseParticleSystem.js.map +1 -1
  51. package/Particles/computeShaderParticleSystem.js +6 -0
  52. package/Particles/computeShaderParticleSystem.js.map +1 -1
  53. package/Particles/gpuParticleSystem.d.ts +24 -6
  54. package/Particles/gpuParticleSystem.js +85 -36
  55. package/Particles/gpuParticleSystem.js.map +1 -1
  56. package/Particles/particleSystem.d.ts +0 -7
  57. package/Particles/particleSystem.js +3 -15
  58. package/Particles/particleSystem.js.map +1 -1
  59. package/Particles/thinParticleSystem.d.ts +1 -3
  60. package/Particles/thinParticleSystem.js +1 -27
  61. package/Particles/thinParticleSystem.js.map +1 -1
  62. package/Particles/webgl2ParticleSystem.js +7 -0
  63. package/Particles/webgl2ParticleSystem.js.map +1 -1
  64. package/Rendering/IBLShadows/iblShadowsAccumulationPass.js +1 -1
  65. package/Rendering/IBLShadows/iblShadowsAccumulationPass.js.map +1 -1
  66. package/Rendering/IBLShadows/iblShadowsPluginMaterial.d.ts +3 -1
  67. package/Rendering/IBLShadows/iblShadowsPluginMaterial.js +11 -1
  68. package/Rendering/IBLShadows/iblShadowsPluginMaterial.js.map +1 -1
  69. package/Rendering/IBLShadows/iblShadowsRenderPipeline.d.ts +0 -19
  70. package/Rendering/IBLShadows/iblShadowsRenderPipeline.js +21 -65
  71. package/Rendering/IBLShadows/iblShadowsRenderPipeline.js.map +1 -1
  72. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.d.ts +15 -52
  73. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js +129 -220
  74. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js.map +1 -1
  75. package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js +3 -0
  76. package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js.map +1 -1
  77. package/Rendering/geometryBufferRenderer.d.ts +14 -5
  78. package/Rendering/geometryBufferRenderer.js +6 -2
  79. package/Rendering/geometryBufferRenderer.js.map +1 -1
  80. package/Rendering/geometryBufferRendererSceneComponent.d.ts +4 -6
  81. package/Rendering/geometryBufferRendererSceneComponent.js.map +1 -1
  82. package/Rendering/iblCdfGenerator.d.ts +10 -0
  83. package/Rendering/iblCdfGenerator.js +52 -17
  84. package/Rendering/iblCdfGenerator.js.map +1 -1
  85. package/Rendering/index.d.ts +0 -6
  86. package/Rendering/index.js +0 -6
  87. package/Rendering/index.js.map +1 -1
  88. package/Shaders/ShadersInclude/openpbrDirectLighting.js +6 -1
  89. package/Shaders/ShadersInclude/openpbrDirectLighting.js.map +1 -1
  90. package/Shaders/ShadersInclude/openpbrEnvironmentLighting.js +1 -1
  91. package/Shaders/ShadersInclude/openpbrEnvironmentLighting.js.map +1 -1
  92. package/Shaders/gpuUpdateParticles.vertex.js +12 -6
  93. package/Shaders/gpuUpdateParticles.vertex.js.map +1 -1
  94. package/Shaders/iblShadowVoxelTracing.fragment.js +5 -1
  95. package/Shaders/iblShadowVoxelTracing.fragment.js.map +1 -1
  96. package/Shaders/iblVoxelGrid.fragment.d.ts +1 -0
  97. package/Shaders/iblVoxelGrid.fragment.js +33 -5
  98. package/Shaders/iblVoxelGrid.fragment.js.map +1 -1
  99. package/Shaders/lod3D.fragment.d.ts +5 -0
  100. package/Shaders/lod3D.fragment.js +13 -0
  101. package/Shaders/lod3D.fragment.js.map +1 -0
  102. package/Shaders/openpbr.fragment.js +5 -0
  103. package/Shaders/openpbr.fragment.js.map +1 -1
  104. package/ShadersWGSL/ShadersInclude/openpbrDirectLighting.js +6 -1
  105. package/ShadersWGSL/ShadersInclude/openpbrDirectLighting.js.map +1 -1
  106. package/ShadersWGSL/ShadersInclude/openpbrEnvironmentLighting.js +1 -1
  107. package/ShadersWGSL/ShadersInclude/openpbrEnvironmentLighting.js.map +1 -1
  108. package/ShadersWGSL/gpuUpdateParticles.compute.js +14 -7
  109. package/ShadersWGSL/gpuUpdateParticles.compute.js.map +1 -1
  110. package/ShadersWGSL/iblShadowVoxelTracing.fragment.js +5 -1
  111. package/ShadersWGSL/iblShadowVoxelTracing.fragment.js.map +1 -1
  112. package/ShadersWGSL/iblVoxelGrid.fragment.js +1 -1
  113. package/ShadersWGSL/iblVoxelGrid.fragment.js.map +1 -1
  114. package/ShadersWGSL/lod3D.fragment.d.ts +5 -0
  115. package/ShadersWGSL/lod3D.fragment.js +13 -0
  116. package/ShadersWGSL/lod3D.fragment.js.map +1 -0
  117. package/ShadersWGSL/openpbr.fragment.js +5 -0
  118. package/ShadersWGSL/openpbr.fragment.js.map +1 -1
  119. package/package.json +1 -1
@@ -228,11 +228,16 @@ export async function WhenTextureReadyAsync(texture) {
228
228
  * This is convienent to get 8-bit RGBA values for a texture in a GPU compressed format, which cannot be read using readPixels.
229
229
  * @internal
230
230
  */
231
- async function ReadPixelsUsingRTT(texture, width, height, face, lod) {
231
+ async function ReadPixelsUsingRTT(texture, width, height, face, lod, slice = 0) {
232
232
  const scene = texture.getScene();
233
233
  const engine = scene.getEngine();
234
+ const sourceInternalTexture = texture.getInternalTexture();
235
+ const is3DTexture = texture.is3D || !!sourceInternalTexture?.is3D;
234
236
  if (!engine.isWebGPU) {
235
- if (texture.isCube) {
237
+ if (is3DTexture) {
238
+ await import("../Shaders/lod3D.fragment.js");
239
+ }
240
+ else if (texture.isCube) {
236
241
  await import("../Shaders/lodCube.fragment.js");
237
242
  }
238
243
  else {
@@ -240,7 +245,10 @@ async function ReadPixelsUsingRTT(texture, width, height, face, lod) {
240
245
  }
241
246
  }
242
247
  else {
243
- if (texture.isCube) {
248
+ if (is3DTexture) {
249
+ await import("../ShadersWGSL/lod3D.fragment.js");
250
+ }
251
+ else if (texture.isCube) {
244
252
  await import("../ShadersWGSL/lodCube.fragment.js");
245
253
  }
246
254
  else {
@@ -248,7 +256,15 @@ async function ReadPixelsUsingRTT(texture, width, height, face, lod) {
248
256
  }
249
257
  }
250
258
  let lodPostProcess;
251
- if (!texture.isCube) {
259
+ if (is3DTexture) {
260
+ lodPostProcess = new PostProcess("lod3D", "lod3D", {
261
+ uniforms: ["lod", "gamma", "slice"],
262
+ samplingMode: Texture.NEAREST_NEAREST_MIPNEAREST,
263
+ engine,
264
+ shaderLanguage: engine.isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */,
265
+ });
266
+ }
267
+ else if (!texture.isCube) {
252
268
  lodPostProcess = new PostProcess("lod", "lod", {
253
269
  uniforms: ["lod", "gamma"],
254
270
  samplingMode: Texture.NEAREST_NEAREST_MIPNEAREST,
@@ -278,11 +294,13 @@ async function ReadPixelsUsingRTT(texture, width, height, face, lod) {
278
294
  effect.setTexture("textureSampler", texture);
279
295
  effect.setFloat("lod", lod);
280
296
  effect.setInt("gamma", texture.gammaSpace ? 1 : 0);
297
+ if (is3DTexture) {
298
+ effect.setFloat("slice", slice);
299
+ }
281
300
  };
282
- const internalTexture = texture.getInternalTexture();
283
301
  try {
284
- if (rtt.renderTarget && internalTexture) {
285
- const samplingMode = internalTexture.samplingMode;
302
+ if (rtt.renderTarget && sourceInternalTexture) {
303
+ const samplingMode = sourceInternalTexture.samplingMode;
286
304
  if (lod !== 0) {
287
305
  texture.updateSamplingMode(Texture.NEAREST_NEAREST_MIPNEAREST);
288
306
  }
@@ -293,7 +311,7 @@ async function ReadPixelsUsingRTT(texture, width, height, face, lod) {
293
311
  texture.updateSamplingMode(samplingMode);
294
312
  //Reading datas from WebGL
295
313
  const bufferView = await engine.readPixels(0, 0, width, height);
296
- const data = new Uint8Array(bufferView.buffer, 0, bufferView.byteLength);
314
+ const data = new Uint8Array(bufferView.buffer, bufferView.byteOffset, bufferView.byteLength);
297
315
  // Unbind
298
316
  engine.unBindFramebuffer(rtt.renderTarget);
299
317
  return data;
@@ -311,27 +329,32 @@ async function ReadPixelsUsingRTT(texture, width, height, face, lod) {
311
329
  * Gets the pixel data of the specified texture, either by reading it directly
312
330
  * or by rendering it to an intermediate RGBA texture and retrieving the bytes from it.
313
331
  * This is convenient to get 8-bit RGBA values for a texture in a GPU compressed format.
332
+ * When direct readback returns non-RGBA channel layouts, the result is normalized to RGBA8.
314
333
  * @param texture the source texture
315
334
  * @param width the target width of the result, which does not have to match the source texture width
316
335
  * @param height the target height of the result, which does not have to match the source texture height
317
336
  * @param face if the texture has multiple faces, the face index to use for the source
318
337
  * @param lod if the texture has multiple LODs, the lod index to use for the source
319
338
  * @param forceRTT if true, forces the use of the RTT path for reading pixels (useful for cube maps to ensure correct orientation and gamma)
339
+ * @param slice if the texture is 3D, the depth slice index to use for the source
320
340
  * @returns the 8-bit texture data
321
341
  */
322
- export async function GetTextureDataAsync(texture, width, height, face = 0, lod = 0, forceRTT = false) {
342
+ export async function GetTextureDataAsync(texture, width, height, face = 0, lod = 0, forceRTT = false, slice = 0) {
323
343
  await WhenTextureReadyAsync(texture);
344
+ const internalTexture = texture.getInternalTexture();
345
+ const is3DTexture = texture.is3D || !!internalTexture?.is3D;
324
346
  const { width: textureWidth, height: textureHeight } = texture.getSize();
325
347
  const targetWidth = width ?? textureWidth;
326
348
  const targetHeight = height ?? textureHeight;
327
349
  // If the internal texture format is compressed, we cannot read the pixels directly.
328
350
  // If we're resizing the texture, we need to use a render target texture.
329
351
  // forceRTT can be used to ensure correct orientation and gamma for cube maps.
330
- if (forceRTT || IsCompressedTextureFormat(texture.textureFormat) || targetWidth !== textureWidth || targetHeight !== textureHeight) {
331
- if (texture.is2DArray || texture.is3D) {
332
- throw new Error(`Reading pixels from 2D array or 3D textures with ${forceRTT ? "RTT" : "compression"} is not supported.`);
352
+ // 3D textures must also use RTT because direct readPixels does not expose slice selection.
353
+ if (forceRTT || is3DTexture || IsCompressedTextureFormat(texture.textureFormat) || targetWidth !== textureWidth || targetHeight !== textureHeight) {
354
+ if (texture.is2DArray) {
355
+ throw new Error(`Reading pixels from 2D array textures with ${forceRTT ? "RTT" : "compression"} is not supported.`);
333
356
  }
334
- return await ReadPixelsUsingRTT(texture, targetWidth, targetHeight, face, lod);
357
+ return await ReadPixelsUsingRTT(texture, targetWidth, targetHeight, face, lod, slice);
335
358
  }
336
359
  let data = (await texture.readPixels(face, lod));
337
360
  if (!data) {
@@ -347,6 +370,44 @@ export async function GetTextureDataAsync(texture, width, height, face = 0, lod
347
370
  }
348
371
  data = data2;
349
372
  }
373
+ // Some backends (notably WebGPU for single/dual/triple channel formats) can return
374
+ // readback data that is not RGBA8. The inspector preview pipeline expects 4 bytes
375
+ // per pixel, so normalize to RGBA here when needed.
376
+ const pixelCount = targetWidth * targetHeight;
377
+ const expectedLength = pixelCount * 4;
378
+ if (data.length !== expectedLength) {
379
+ const componentCount = pixelCount === 0 ? 0 : data.length / pixelCount;
380
+ if (componentCount === 1 || componentCount === 2 || componentCount === 3) {
381
+ const normalizedData = new Uint8Array(expectedLength);
382
+ for (let pixel = 0, src = 0, dst = 0; pixel < pixelCount; pixel++, dst += 4) {
383
+ const c0 = data[src++];
384
+ if (componentCount === 1) {
385
+ // Luminance/R-style data: replicate to RGB and use opaque alpha.
386
+ normalizedData[dst] = c0;
387
+ normalizedData[dst + 1] = c0;
388
+ normalizedData[dst + 2] = c0;
389
+ normalizedData[dst + 3] = 255;
390
+ continue;
391
+ }
392
+ const c1 = data[src++];
393
+ if (componentCount === 2) {
394
+ // Two-channel data has no standard blue/alpha semantics for preview,
395
+ // so preserve R/G, clear B, and force opaque alpha.
396
+ normalizedData[dst] = c0;
397
+ normalizedData[dst + 1] = c1;
398
+ normalizedData[dst + 2] = 0;
399
+ normalizedData[dst + 3] = 255;
400
+ continue;
401
+ }
402
+ // RGB data: append an opaque alpha channel.
403
+ normalizedData[dst] = c0;
404
+ normalizedData[dst + 1] = c1;
405
+ normalizedData[dst + 2] = data[src++];
406
+ normalizedData[dst + 3] = 255;
407
+ }
408
+ return normalizedData;
409
+ }
410
+ }
350
411
  return data;
351
412
  }
352
413
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"textureTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/textureTools.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAI3D,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AA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AO,IAAI,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB;;;;;;;OAOG;IACH,iBAAiB;IAEjB;;;;;;;;;OASG;IACH,gBAAgB;IAChB;;;;OAIG;IACH,WAAW;IAEX;;;;OAIG;IACH,aAAa;IAEb;;;;;;;;;OASG;IACH,mBAAmB;CACtB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { type BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { type InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { PassPostProcess } from \"../PostProcesses/passPostProcess\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { type Scene } from \"../scene\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\nimport { type Observable } from \"./observable\";\r\nimport { type Nullable } from \"../types\";\r\nimport { Clamp } from \"../Maths/math.scalar.functions\";\r\n\r\n/**\r\n * Uses the GPU to create a copy texture rescaled at a given size\r\n * @param texture Texture to copy from\r\n * @param width defines the desired width\r\n * @param height defines the desired height\r\n * @param useBilinearMode defines if bilinear mode has to be used\r\n * @returns the generated texture\r\n */\r\nexport function CreateResizedCopy(texture: Texture, width: number, height: number, useBilinearMode: boolean = true): Texture {\r\n const scene = <Scene>texture.getScene();\r\n const engine = scene.getEngine();\r\n\r\n const rtt = new RenderTargetTexture(\r\n \"resized\" + texture.name,\r\n { width: width, height: height },\r\n scene,\r\n !texture.noMipmap,\r\n true,\r\n (<InternalTexture>texture._texture).type,\r\n false,\r\n texture.samplingMode,\r\n false\r\n );\r\n\r\n rtt.wrapU = texture.wrapU;\r\n rtt.wrapV = texture.wrapV;\r\n rtt.uOffset = texture.uOffset;\r\n rtt.vOffset = texture.vOffset;\r\n rtt.uScale = texture.uScale;\r\n rtt.vScale = texture.vScale;\r\n rtt.uAng = texture.uAng;\r\n rtt.vAng = texture.vAng;\r\n rtt.wAng = texture.wAng;\r\n rtt.coordinatesIndex = texture.coordinatesIndex;\r\n rtt.level = texture.level;\r\n rtt.anisotropicFilteringLevel = texture.anisotropicFilteringLevel;\r\n (<InternalTexture>rtt._texture).isReady = false;\r\n\r\n texture.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n texture.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n\r\n const passPostProcess = new PassPostProcess(\r\n \"pass\",\r\n 1,\r\n null,\r\n useBilinearMode ? Texture.BILINEAR_SAMPLINGMODE : Texture.NEAREST_SAMPLINGMODE,\r\n engine,\r\n false,\r\n Constants.TEXTURETYPE_UNSIGNED_BYTE\r\n );\r\n passPostProcess.externalTextureSamplerBinding = true;\r\n passPostProcess.onEffectCreatedObservable.addOnce((e) => {\r\n e.executeWhenCompiled(() => {\r\n passPostProcess.onApply = function (effect) {\r\n effect.setTexture(\"textureSampler\", texture);\r\n };\r\n\r\n const internalTexture = rtt.renderTarget;\r\n\r\n if (internalTexture) {\r\n scene.postProcessManager.directRender([passPostProcess], internalTexture);\r\n\r\n engine.unBindFramebuffer(internalTexture);\r\n rtt.disposeFramebufferObjects();\r\n passPostProcess.dispose();\r\n\r\n rtt.getInternalTexture()!.isReady = true;\r\n }\r\n });\r\n });\r\n\r\n return rtt;\r\n}\r\n\r\n/**\r\n * Apply a post process to a texture\r\n * @param postProcessName name of the fragment post process\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param type type of the output texture. If not provided, use the one from internalTexture\r\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\r\n * @param format format of the output texture. If not provided, use the one from internalTexture\r\n * @param width width of the output texture. If not provided, use the one from internalTexture\r\n * @param height height of the output texture. If not provided, use the one from internalTexture\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\n// eslint-disable-next-line @typescript-eslint/promise-function-async\r\nexport function ApplyPostProcess(\r\n postProcessName: string,\r\n internalTexture: InternalTexture,\r\n scene: Scene,\r\n type?: number,\r\n samplingMode?: number,\r\n format?: number,\r\n width?: number,\r\n height?: number\r\n): Promise<InternalTexture> {\r\n // Gets everything ready.\r\n const engine = internalTexture.getEngine();\r\n\r\n internalTexture.isReady = false;\r\n\r\n samplingMode = samplingMode ?? internalTexture.samplingMode;\r\n type = type ?? internalTexture.type;\r\n format = format ?? internalTexture.format;\r\n width = width ?? internalTexture.width;\r\n height = height ?? internalTexture.height;\r\n\r\n if (type === -1) {\r\n type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n }\r\n\r\n return new Promise((resolve) => {\r\n // Create the post process\r\n const postProcess = new PostProcess(\"postprocess\", postProcessName, null, null, 1, null, samplingMode, engine, false, undefined, type, undefined, null, false, format);\r\n postProcess.externalTextureSamplerBinding = true;\r\n\r\n // Hold the output of the decoding.\r\n const encodedTexture = engine.createRenderTargetTexture(\r\n { width: width, height: height },\r\n {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n generateStencilBuffer: false,\r\n samplingMode,\r\n type,\r\n format,\r\n }\r\n );\r\n\r\n postProcess.onEffectCreatedObservable.addOnce((e) => {\r\n e.executeWhenCompiled(() => {\r\n // PP Render Pass\r\n postProcess.onApply = (effect) => {\r\n effect._bindTexture(\"textureSampler\", internalTexture);\r\n effect.setFloat2(\"scale\", 1, 1);\r\n };\r\n scene.postProcessManager.directRender([postProcess], encodedTexture, true);\r\n\r\n // Cleanup\r\n engine.restoreDefaultFramebuffer();\r\n engine._releaseTexture(internalTexture);\r\n if (postProcess) {\r\n postProcess.dispose();\r\n }\r\n\r\n // Internal Swap\r\n encodedTexture._swapAndDie(internalTexture);\r\n\r\n // Ready to get rolling again.\r\n internalTexture.type = type!;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.isReady = true;\r\n\r\n resolve(internalTexture);\r\n });\r\n });\r\n });\r\n}\r\n\r\n// ref: http://stackoverflow.com/questions/32633585/how-do-you-convert-to-half-floats-in-javascript\r\nlet floatView: Float32Array;\r\nlet int32View: Int32Array;\r\n/**\r\n * Converts a number to half float\r\n * @param value number to convert\r\n * @returns converted number\r\n */\r\nexport function ToHalfFloat(value: number): number {\r\n if (!floatView) {\r\n floatView = new Float32Array(1);\r\n int32View = new Int32Array(floatView.buffer);\r\n }\r\n\r\n floatView[0] = value;\r\n const x = int32View[0];\r\n\r\n let bits = (x >> 16) & 0x8000; /* Get the sign */\r\n let m = (x >> 12) & 0x07ff; /* Keep one extra bit for rounding */\r\n const e = (x >> 23) & 0xff; /* Using int is faster here */\r\n\r\n /* If zero, or denormal, or exponent underflows too much for a denormal\r\n * half, return signed zero. */\r\n if (e < 103) {\r\n return bits;\r\n }\r\n\r\n /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */\r\n if (e > 142) {\r\n bits |= 0x7c00;\r\n /* If exponent was 0xff and one mantissa bit was set, it means NaN,\r\n * not Inf, so make sure we set one mantissa bit too. */\r\n bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;\r\n return bits;\r\n }\r\n\r\n /* If exponent underflows but not too much, return a denormal */\r\n if (e < 113) {\r\n m |= 0x0800;\r\n /* Extra rounding may overflow and set mantissa to 0 and exponent\r\n * to 1, which is OK. */\r\n bits |= (m >> (114 - e)) + ((m >> (113 - e)) & 1);\r\n return bits;\r\n }\r\n\r\n bits |= ((e - 112) << 10) | (m >> 1);\r\n bits += m & 1;\r\n return bits;\r\n}\r\n\r\n/**\r\n * Converts a half float to a number\r\n * @param value half float to convert\r\n * @returns converted half float\r\n */\r\nexport function FromHalfFloat(value: number): number {\r\n const s = (value & 0x8000) >> 15;\r\n const e = (value & 0x7c00) >> 10;\r\n const f = value & 0x03ff;\r\n\r\n if (e === 0) {\r\n return (s ? -1 : 1) * Math.pow(2, -14) * (f / Math.pow(2, 10));\r\n } else if (e == 0x1f) {\r\n return f ? NaN : (s ? -1 : 1) * Infinity;\r\n }\r\n\r\n return (s ? -1 : 1) * Math.pow(2, e - 15) * (1 + f / Math.pow(2, 10));\r\n}\r\n\r\nfunction IsCompressedTextureFormat(format: number): boolean {\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT5:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT3:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT1:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB_S3TC_DXT1:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB_S3TC_DXT1_EXT:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB8_ETC2:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ETC2:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:\r\n return true;\r\n default:\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n * Waits for when the given texture is ready to be used (downloaded, converted, mip mapped...)\r\n * @param texture the texture to wait for\r\n * @returns a promise that resolves when the texture is ready\r\n */\r\nexport async function WhenTextureReadyAsync(texture: BaseTexture): Promise<void> {\r\n if (texture.isReady()) {\r\n return;\r\n }\r\n\r\n if (texture.loadingError) {\r\n throw new Error(texture.errorObject?.message || `Texture ${texture.name} errored while loading.`);\r\n }\r\n\r\n const onLoadObservable = (texture as any).onLoadObservable as Observable<BaseTexture>;\r\n if (onLoadObservable) {\r\n return await new Promise((res) => onLoadObservable.addOnce(() => res()));\r\n }\r\n\r\n const onLoadedObservable = texture._texture?.onLoadedObservable;\r\n if (onLoadedObservable) {\r\n return await new Promise((res) => onLoadedObservable.addOnce(() => res()));\r\n }\r\n\r\n throw new Error(`Cannot determine readiness of texture ${texture.name}.`);\r\n}\r\n\r\n/**\r\n * Gets the data of the specified texture by rendering it to an intermediate RGBA texture and retrieving the bytes from it.\r\n * This is convienent to get 8-bit RGBA values for a texture in a GPU compressed format, which cannot be read using readPixels.\r\n * @internal\r\n */\r\nasync function ReadPixelsUsingRTT(texture: BaseTexture, width: number, height: number, face: number, lod: number): Promise<Uint8Array> {\r\n const scene = texture.getScene()!;\r\n const engine = scene.getEngine();\r\n\r\n if (!engine.isWebGPU) {\r\n if (texture.isCube) {\r\n await import(\"../Shaders/lodCube.fragment\");\r\n } else {\r\n await import(\"../Shaders/lod.fragment\");\r\n }\r\n } else {\r\n if (texture.isCube) {\r\n await import(\"../ShadersWGSL/lodCube.fragment\");\r\n } else {\r\n await import(\"../ShadersWGSL/lod.fragment\");\r\n }\r\n }\r\n\r\n let lodPostProcess: PostProcess;\r\n\r\n if (!texture.isCube) {\r\n lodPostProcess = new PostProcess(\"lod\", \"lod\", {\r\n uniforms: [\"lod\", \"gamma\"],\r\n samplingMode: Texture.NEAREST_NEAREST_MIPNEAREST,\r\n engine,\r\n shaderLanguage: engine.isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n });\r\n } else {\r\n const faceDefines = [\"#define POSITIVEX\", \"#define NEGATIVEX\", \"#define POSITIVEY\", \"#define NEGATIVEY\", \"#define POSITIVEZ\", \"#define NEGATIVEZ\"];\r\n lodPostProcess = new PostProcess(\"lodCube\", \"lodCube\", {\r\n uniforms: [\"lod\", \"gamma\"],\r\n samplingMode: Texture.NEAREST_NEAREST_MIPNEAREST,\r\n engine,\r\n defines: faceDefines[face],\r\n shaderLanguage: engine.isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n });\r\n }\r\n\r\n await new Promise((resolve) => {\r\n lodPostProcess.onEffectCreatedObservable.addOnce((e) => {\r\n e.executeWhenCompiled(() => {\r\n resolve(0);\r\n });\r\n });\r\n });\r\n\r\n const rtt = new RenderTargetTexture(\"temp\", { width: width, height: height }, scene, false);\r\n\r\n lodPostProcess.onApply = function (effect) {\r\n effect.setTexture(\"textureSampler\", texture);\r\n effect.setFloat(\"lod\", lod);\r\n effect.setInt(\"gamma\", texture.gammaSpace ? 1 : 0);\r\n };\r\n\r\n const internalTexture = texture.getInternalTexture();\r\n\r\n try {\r\n if (rtt.renderTarget && internalTexture) {\r\n const samplingMode = internalTexture.samplingMode;\r\n if (lod !== 0) {\r\n texture.updateSamplingMode(Texture.NEAREST_NEAREST_MIPNEAREST);\r\n } else {\r\n texture.updateSamplingMode(Texture.NEAREST_NEAREST);\r\n }\r\n\r\n scene.postProcessManager.directRender([lodPostProcess], rtt.renderTarget, true);\r\n texture.updateSamplingMode(samplingMode);\r\n\r\n //Reading datas from WebGL\r\n const bufferView = await engine.readPixels(0, 0, width, height);\r\n const data = new Uint8Array(bufferView.buffer, 0, bufferView.byteLength);\r\n\r\n // Unbind\r\n engine.unBindFramebuffer(rtt.renderTarget);\r\n\r\n return data;\r\n } else {\r\n throw Error(\"Render to texture failed.\");\r\n }\r\n } finally {\r\n rtt.dispose();\r\n lodPostProcess.dispose();\r\n }\r\n}\r\n\r\n/**\r\n * Gets the pixel data of the specified texture, either by reading it directly\r\n * or by rendering it to an intermediate RGBA texture and retrieving the bytes from it.\r\n * This is convenient to get 8-bit RGBA values for a texture in a GPU compressed format.\r\n * @param texture the source texture\r\n * @param width the target width of the result, which does not have to match the source texture width\r\n * @param height the target height of the result, which does not have to match the source texture height\r\n * @param face if the texture has multiple faces, the face index to use for the source\r\n * @param lod if the texture has multiple LODs, the lod index to use for the source\r\n * @param forceRTT if true, forces the use of the RTT path for reading pixels (useful for cube maps to ensure correct orientation and gamma)\r\n * @returns the 8-bit texture data\r\n */\r\nexport async function GetTextureDataAsync(\r\n texture: BaseTexture,\r\n width?: number,\r\n height?: number,\r\n face: number = 0,\r\n lod: number = 0,\r\n forceRTT: boolean = false\r\n): Promise<Uint8Array> {\r\n await WhenTextureReadyAsync(texture);\r\n\r\n const { width: textureWidth, height: textureHeight } = texture.getSize();\r\n const targetWidth = width ?? textureWidth;\r\n const targetHeight = height ?? textureHeight;\r\n\r\n // If the internal texture format is compressed, we cannot read the pixels directly.\r\n // If we're resizing the texture, we need to use a render target texture.\r\n // forceRTT can be used to ensure correct orientation and gamma for cube maps.\r\n if (forceRTT || IsCompressedTextureFormat(texture.textureFormat) || targetWidth !== textureWidth || targetHeight !== textureHeight) {\r\n if (texture.is2DArray || texture.is3D) {\r\n throw new Error(`Reading pixels from 2D array or 3D textures with ${forceRTT ? \"RTT\" : \"compression\"} is not supported.`);\r\n }\r\n return await ReadPixelsUsingRTT(texture, targetWidth, targetHeight, face, lod);\r\n }\r\n\r\n let data = (await texture.readPixels(face, lod)) as Nullable<Uint8Array | Float32Array>;\r\n if (!data) {\r\n throw new Error(`Failed to read pixels from texture ${texture.name}.`);\r\n }\r\n\r\n // Convert float RGBA values to uint8, if necessary.\r\n if (data instanceof Float32Array) {\r\n const data2 = new Uint8Array(data.length);\r\n let n = data.length;\r\n while (n--) {\r\n const v = data[n];\r\n data2[n] = Math.round(Clamp(v) * 255);\r\n }\r\n data = data2;\r\n }\r\n\r\n return data;\r\n}\r\n\r\n/**\r\n * Class used to host texture specific utilities\r\n */\r\nexport const TextureTools = {\r\n /**\r\n * Uses the GPU to create a copy texture rescaled at a given size\r\n * @param texture Texture to copy from\r\n * @param width defines the desired width\r\n * @param height defines the desired height\r\n * @param useBilinearMode defines if bilinear mode has to be used\r\n * @returns the generated texture\r\n */\r\n CreateResizedCopy,\r\n\r\n /**\r\n * Apply a post process to a texture\r\n * @param postProcessName name of the fragment post process\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param type type of the output texture. If not provided, use the one from internalTexture\r\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\r\n * @param format format of the output texture. If not provided, use the one from internalTexture\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\n ApplyPostProcess,\r\n /**\r\n * Converts a number to half float\r\n * @param value number to convert\r\n * @returns converted number\r\n */\r\n ToHalfFloat,\r\n\r\n /**\r\n * Converts a half float to a number\r\n * @param value half float to convert\r\n * @returns converted half float\r\n */\r\n FromHalfFloat,\r\n\r\n /**\r\n * Gets the data of the specified texture by rendering it to an intermediate RGBA texture and retrieving the bytes from it.\r\n * This is convienent to get 8-bit RGBA values for a texture in a GPU compressed format.\r\n * @param texture the source texture\r\n * @param width the width of the result, which does not have to match the source texture width\r\n * @param height the height of the result, which does not have to match the source texture height\r\n * @param face if the texture has multiple faces, the face index to use for the source\r\n * @param lod if the texture has multiple LODs, the lod index to use for the source\r\n * @returns the 8-bit texture data\r\n */\r\n GetTextureDataAsync,\r\n};\r\n"]}
1
+ {"version":3,"file":"textureTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/textureTools.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EA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,GAAG,CAAC,CAAC;oBAC5B,cAAc,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;oBAC9B,SAAS;gBACb,CAAC;gBAED,4CAA4C;gBAC5C,cAAc,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;gBACzB,cAAc,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;gBAC7B,cAAc,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;gBACtC,cAAc,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;YAClC,CAAC;YAED,OAAO,cAAc,CAAC;QAC1B,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB;;;;;;;OAOG;IACH,iBAAiB;IAEjB;;;;;;;;;OASG;IACH,gBAAgB;IAChB;;;;OAIG;IACH,WAAW;IAEX;;;;OAIG;IACH,aAAa;IAEb;;;;;;;;;OASG;IACH,mBAAmB;CACtB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { type BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { type InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { PassPostProcess } from \"../PostProcesses/passPostProcess\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { type Scene } from \"../scene\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\nimport { type Observable } from \"./observable\";\r\nimport { type Nullable } from \"../types\";\r\nimport { Clamp } from \"../Maths/math.scalar.functions\";\r\n\r\n/**\r\n * Uses the GPU to create a copy texture rescaled at a given size\r\n * @param texture Texture to copy from\r\n * @param width defines the desired width\r\n * @param height defines the desired height\r\n * @param useBilinearMode defines if bilinear mode has to be used\r\n * @returns the generated texture\r\n */\r\nexport function CreateResizedCopy(texture: Texture, width: number, height: number, useBilinearMode: boolean = true): Texture {\r\n const scene = <Scene>texture.getScene();\r\n const engine = scene.getEngine();\r\n\r\n const rtt = new RenderTargetTexture(\r\n \"resized\" + texture.name,\r\n { width: width, height: height },\r\n scene,\r\n !texture.noMipmap,\r\n true,\r\n (<InternalTexture>texture._texture).type,\r\n false,\r\n texture.samplingMode,\r\n false\r\n );\r\n\r\n rtt.wrapU = texture.wrapU;\r\n rtt.wrapV = texture.wrapV;\r\n rtt.uOffset = texture.uOffset;\r\n rtt.vOffset = texture.vOffset;\r\n rtt.uScale = texture.uScale;\r\n rtt.vScale = texture.vScale;\r\n rtt.uAng = texture.uAng;\r\n rtt.vAng = texture.vAng;\r\n rtt.wAng = texture.wAng;\r\n rtt.coordinatesIndex = texture.coordinatesIndex;\r\n rtt.level = texture.level;\r\n rtt.anisotropicFilteringLevel = texture.anisotropicFilteringLevel;\r\n (<InternalTexture>rtt._texture).isReady = false;\r\n\r\n texture.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n texture.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n\r\n const passPostProcess = new PassPostProcess(\r\n \"pass\",\r\n 1,\r\n null,\r\n useBilinearMode ? Texture.BILINEAR_SAMPLINGMODE : Texture.NEAREST_SAMPLINGMODE,\r\n engine,\r\n false,\r\n Constants.TEXTURETYPE_UNSIGNED_BYTE\r\n );\r\n passPostProcess.externalTextureSamplerBinding = true;\r\n passPostProcess.onEffectCreatedObservable.addOnce((e) => {\r\n e.executeWhenCompiled(() => {\r\n passPostProcess.onApply = function (effect) {\r\n effect.setTexture(\"textureSampler\", texture);\r\n };\r\n\r\n const internalTexture = rtt.renderTarget;\r\n\r\n if (internalTexture) {\r\n scene.postProcessManager.directRender([passPostProcess], internalTexture);\r\n\r\n engine.unBindFramebuffer(internalTexture);\r\n rtt.disposeFramebufferObjects();\r\n passPostProcess.dispose();\r\n\r\n rtt.getInternalTexture()!.isReady = true;\r\n }\r\n });\r\n });\r\n\r\n return rtt;\r\n}\r\n\r\n/**\r\n * Apply a post process to a texture\r\n * @param postProcessName name of the fragment post process\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param type type of the output texture. If not provided, use the one from internalTexture\r\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\r\n * @param format format of the output texture. If not provided, use the one from internalTexture\r\n * @param width width of the output texture. If not provided, use the one from internalTexture\r\n * @param height height of the output texture. If not provided, use the one from internalTexture\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\n// eslint-disable-next-line @typescript-eslint/promise-function-async\r\nexport function ApplyPostProcess(\r\n postProcessName: string,\r\n internalTexture: InternalTexture,\r\n scene: Scene,\r\n type?: number,\r\n samplingMode?: number,\r\n format?: number,\r\n width?: number,\r\n height?: number\r\n): Promise<InternalTexture> {\r\n // Gets everything ready.\r\n const engine = internalTexture.getEngine();\r\n\r\n internalTexture.isReady = false;\r\n\r\n samplingMode = samplingMode ?? internalTexture.samplingMode;\r\n type = type ?? internalTexture.type;\r\n format = format ?? internalTexture.format;\r\n width = width ?? internalTexture.width;\r\n height = height ?? internalTexture.height;\r\n\r\n if (type === -1) {\r\n type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n }\r\n\r\n return new Promise((resolve) => {\r\n // Create the post process\r\n const postProcess = new PostProcess(\"postprocess\", postProcessName, null, null, 1, null, samplingMode, engine, false, undefined, type, undefined, null, false, format);\r\n postProcess.externalTextureSamplerBinding = true;\r\n\r\n // Hold the output of the decoding.\r\n const encodedTexture = engine.createRenderTargetTexture(\r\n { width: width, height: height },\r\n {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n generateStencilBuffer: false,\r\n samplingMode,\r\n type,\r\n format,\r\n }\r\n );\r\n\r\n postProcess.onEffectCreatedObservable.addOnce((e) => {\r\n e.executeWhenCompiled(() => {\r\n // PP Render Pass\r\n postProcess.onApply = (effect) => {\r\n effect._bindTexture(\"textureSampler\", internalTexture);\r\n effect.setFloat2(\"scale\", 1, 1);\r\n };\r\n scene.postProcessManager.directRender([postProcess], encodedTexture, true);\r\n\r\n // Cleanup\r\n engine.restoreDefaultFramebuffer();\r\n engine._releaseTexture(internalTexture);\r\n if (postProcess) {\r\n postProcess.dispose();\r\n }\r\n\r\n // Internal Swap\r\n encodedTexture._swapAndDie(internalTexture);\r\n\r\n // Ready to get rolling again.\r\n internalTexture.type = type!;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.isReady = true;\r\n\r\n resolve(internalTexture);\r\n });\r\n });\r\n });\r\n}\r\n\r\n// ref: http://stackoverflow.com/questions/32633585/how-do-you-convert-to-half-floats-in-javascript\r\nlet floatView: Float32Array;\r\nlet int32View: Int32Array;\r\n/**\r\n * Converts a number to half float\r\n * @param value number to convert\r\n * @returns converted number\r\n */\r\nexport function ToHalfFloat(value: number): number {\r\n if (!floatView) {\r\n floatView = new Float32Array(1);\r\n int32View = new Int32Array(floatView.buffer);\r\n }\r\n\r\n floatView[0] = value;\r\n const x = int32View[0];\r\n\r\n let bits = (x >> 16) & 0x8000; /* Get the sign */\r\n let m = (x >> 12) & 0x07ff; /* Keep one extra bit for rounding */\r\n const e = (x >> 23) & 0xff; /* Using int is faster here */\r\n\r\n /* If zero, or denormal, or exponent underflows too much for a denormal\r\n * half, return signed zero. */\r\n if (e < 103) {\r\n return bits;\r\n }\r\n\r\n /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */\r\n if (e > 142) {\r\n bits |= 0x7c00;\r\n /* If exponent was 0xff and one mantissa bit was set, it means NaN,\r\n * not Inf, so make sure we set one mantissa bit too. */\r\n bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;\r\n return bits;\r\n }\r\n\r\n /* If exponent underflows but not too much, return a denormal */\r\n if (e < 113) {\r\n m |= 0x0800;\r\n /* Extra rounding may overflow and set mantissa to 0 and exponent\r\n * to 1, which is OK. */\r\n bits |= (m >> (114 - e)) + ((m >> (113 - e)) & 1);\r\n return bits;\r\n }\r\n\r\n bits |= ((e - 112) << 10) | (m >> 1);\r\n bits += m & 1;\r\n return bits;\r\n}\r\n\r\n/**\r\n * Converts a half float to a number\r\n * @param value half float to convert\r\n * @returns converted half float\r\n */\r\nexport function FromHalfFloat(value: number): number {\r\n const s = (value & 0x8000) >> 15;\r\n const e = (value & 0x7c00) >> 10;\r\n const f = value & 0x03ff;\r\n\r\n if (e === 0) {\r\n return (s ? -1 : 1) * Math.pow(2, -14) * (f / Math.pow(2, 10));\r\n } else if (e == 0x1f) {\r\n return f ? NaN : (s ? -1 : 1) * Infinity;\r\n }\r\n\r\n return (s ? -1 : 1) * Math.pow(2, e - 15) * (1 + f / Math.pow(2, 10));\r\n}\r\n\r\nfunction IsCompressedTextureFormat(format: number): boolean {\r\n switch (format) {\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT5:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT3:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT1:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB_S3TC_DXT1:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB_S3TC_DXT1_EXT:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB8_ETC2:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ETC2:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC:\r\n case Constants.TEXTUREFORMAT_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:\r\n return true;\r\n default:\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n * Waits for when the given texture is ready to be used (downloaded, converted, mip mapped...)\r\n * @param texture the texture to wait for\r\n * @returns a promise that resolves when the texture is ready\r\n */\r\nexport async function WhenTextureReadyAsync(texture: BaseTexture): Promise<void> {\r\n if (texture.isReady()) {\r\n return;\r\n }\r\n\r\n if (texture.loadingError) {\r\n throw new Error(texture.errorObject?.message || `Texture ${texture.name} errored while loading.`);\r\n }\r\n\r\n const onLoadObservable = (texture as any).onLoadObservable as Observable<BaseTexture>;\r\n if (onLoadObservable) {\r\n return await new Promise((res) => onLoadObservable.addOnce(() => res()));\r\n }\r\n\r\n const onLoadedObservable = texture._texture?.onLoadedObservable;\r\n if (onLoadedObservable) {\r\n return await new Promise((res) => onLoadedObservable.addOnce(() => res()));\r\n }\r\n\r\n throw new Error(`Cannot determine readiness of texture ${texture.name}.`);\r\n}\r\n\r\n/**\r\n * Gets the data of the specified texture by rendering it to an intermediate RGBA texture and retrieving the bytes from it.\r\n * This is convienent to get 8-bit RGBA values for a texture in a GPU compressed format, which cannot be read using readPixels.\r\n * @internal\r\n */\r\nasync function ReadPixelsUsingRTT(texture: BaseTexture, width: number, height: number, face: number, lod: number, slice: number = 0): Promise<Uint8Array> {\r\n const scene = texture.getScene()!;\r\n const engine = scene.getEngine();\r\n const sourceInternalTexture = texture.getInternalTexture();\r\n const is3DTexture = texture.is3D || !!sourceInternalTexture?.is3D;\r\n\r\n if (!engine.isWebGPU) {\r\n if (is3DTexture) {\r\n await import(\"../Shaders/lod3D.fragment\");\r\n } else if (texture.isCube) {\r\n await import(\"../Shaders/lodCube.fragment\");\r\n } else {\r\n await import(\"../Shaders/lod.fragment\");\r\n }\r\n } else {\r\n if (is3DTexture) {\r\n await import(\"../ShadersWGSL/lod3D.fragment\");\r\n } else if (texture.isCube) {\r\n await import(\"../ShadersWGSL/lodCube.fragment\");\r\n } else {\r\n await import(\"../ShadersWGSL/lod.fragment\");\r\n }\r\n }\r\n\r\n let lodPostProcess: PostProcess;\r\n\r\n if (is3DTexture) {\r\n lodPostProcess = new PostProcess(\"lod3D\", \"lod3D\", {\r\n uniforms: [\"lod\", \"gamma\", \"slice\"],\r\n samplingMode: Texture.NEAREST_NEAREST_MIPNEAREST,\r\n engine,\r\n shaderLanguage: engine.isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n });\r\n } else if (!texture.isCube) {\r\n lodPostProcess = new PostProcess(\"lod\", \"lod\", {\r\n uniforms: [\"lod\", \"gamma\"],\r\n samplingMode: Texture.NEAREST_NEAREST_MIPNEAREST,\r\n engine,\r\n shaderLanguage: engine.isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n });\r\n } else {\r\n const faceDefines = [\"#define POSITIVEX\", \"#define NEGATIVEX\", \"#define POSITIVEY\", \"#define NEGATIVEY\", \"#define POSITIVEZ\", \"#define NEGATIVEZ\"];\r\n lodPostProcess = new PostProcess(\"lodCube\", \"lodCube\", {\r\n uniforms: [\"lod\", \"gamma\"],\r\n samplingMode: Texture.NEAREST_NEAREST_MIPNEAREST,\r\n engine,\r\n defines: faceDefines[face],\r\n shaderLanguage: engine.isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\r\n });\r\n }\r\n\r\n await new Promise((resolve) => {\r\n lodPostProcess.onEffectCreatedObservable.addOnce((e) => {\r\n e.executeWhenCompiled(() => {\r\n resolve(0);\r\n });\r\n });\r\n });\r\n\r\n const rtt = new RenderTargetTexture(\"temp\", { width: width, height: height }, scene, false);\r\n\r\n lodPostProcess.onApply = function (effect) {\r\n effect.setTexture(\"textureSampler\", texture);\r\n effect.setFloat(\"lod\", lod);\r\n effect.setInt(\"gamma\", texture.gammaSpace ? 1 : 0);\r\n if (is3DTexture) {\r\n effect.setFloat(\"slice\", slice);\r\n }\r\n };\r\n\r\n try {\r\n if (rtt.renderTarget && sourceInternalTexture) {\r\n const samplingMode = sourceInternalTexture.samplingMode;\r\n if (lod !== 0) {\r\n texture.updateSamplingMode(Texture.NEAREST_NEAREST_MIPNEAREST);\r\n } else {\r\n texture.updateSamplingMode(Texture.NEAREST_NEAREST);\r\n }\r\n\r\n scene.postProcessManager.directRender([lodPostProcess], rtt.renderTarget, true);\r\n texture.updateSamplingMode(samplingMode);\r\n\r\n //Reading datas from WebGL\r\n const bufferView = await engine.readPixels(0, 0, width, height);\r\n const data = new Uint8Array(bufferView.buffer, bufferView.byteOffset, bufferView.byteLength);\r\n\r\n // Unbind\r\n engine.unBindFramebuffer(rtt.renderTarget);\r\n\r\n return data;\r\n } else {\r\n throw Error(\"Render to texture failed.\");\r\n }\r\n } finally {\r\n rtt.dispose();\r\n lodPostProcess.dispose();\r\n }\r\n}\r\n\r\n/**\r\n * Gets the pixel data of the specified texture, either by reading it directly\r\n * or by rendering it to an intermediate RGBA texture and retrieving the bytes from it.\r\n * This is convenient to get 8-bit RGBA values for a texture in a GPU compressed format.\r\n * When direct readback returns non-RGBA channel layouts, the result is normalized to RGBA8.\r\n * @param texture the source texture\r\n * @param width the target width of the result, which does not have to match the source texture width\r\n * @param height the target height of the result, which does not have to match the source texture height\r\n * @param face if the texture has multiple faces, the face index to use for the source\r\n * @param lod if the texture has multiple LODs, the lod index to use for the source\r\n * @param forceRTT if true, forces the use of the RTT path for reading pixels (useful for cube maps to ensure correct orientation and gamma)\r\n * @param slice if the texture is 3D, the depth slice index to use for the source\r\n * @returns the 8-bit texture data\r\n */\r\nexport async function GetTextureDataAsync(\r\n texture: BaseTexture,\r\n width?: number,\r\n height?: number,\r\n face: number = 0,\r\n lod: number = 0,\r\n forceRTT: boolean = false,\r\n slice: number = 0\r\n): Promise<Uint8Array> {\r\n await WhenTextureReadyAsync(texture);\r\n const internalTexture = texture.getInternalTexture();\r\n const is3DTexture = texture.is3D || !!internalTexture?.is3D;\r\n\r\n const { width: textureWidth, height: textureHeight } = texture.getSize();\r\n const targetWidth = width ?? textureWidth;\r\n const targetHeight = height ?? textureHeight;\r\n\r\n // If the internal texture format is compressed, we cannot read the pixels directly.\r\n // If we're resizing the texture, we need to use a render target texture.\r\n // forceRTT can be used to ensure correct orientation and gamma for cube maps.\r\n // 3D textures must also use RTT because direct readPixels does not expose slice selection.\r\n if (forceRTT || is3DTexture || IsCompressedTextureFormat(texture.textureFormat) || targetWidth !== textureWidth || targetHeight !== textureHeight) {\r\n if (texture.is2DArray) {\r\n throw new Error(`Reading pixels from 2D array textures with ${forceRTT ? \"RTT\" : \"compression\"} is not supported.`);\r\n }\r\n return await ReadPixelsUsingRTT(texture, targetWidth, targetHeight, face, lod, slice);\r\n }\r\n\r\n let data = (await texture.readPixels(face, lod)) as Nullable<Uint8Array | Float32Array>;\r\n if (!data) {\r\n throw new Error(`Failed to read pixels from texture ${texture.name}.`);\r\n }\r\n\r\n // Convert float RGBA values to uint8, if necessary.\r\n if (data instanceof Float32Array) {\r\n const data2 = new Uint8Array(data.length);\r\n let n = data.length;\r\n while (n--) {\r\n const v = data[n];\r\n data2[n] = Math.round(Clamp(v) * 255);\r\n }\r\n data = data2;\r\n }\r\n\r\n // Some backends (notably WebGPU for single/dual/triple channel formats) can return\r\n // readback data that is not RGBA8. The inspector preview pipeline expects 4 bytes\r\n // per pixel, so normalize to RGBA here when needed.\r\n const pixelCount = targetWidth * targetHeight;\r\n const expectedLength = pixelCount * 4;\r\n\r\n if (data.length !== expectedLength) {\r\n const componentCount = pixelCount === 0 ? 0 : data.length / pixelCount;\r\n\r\n if (componentCount === 1 || componentCount === 2 || componentCount === 3) {\r\n const normalizedData = new Uint8Array(expectedLength);\r\n\r\n for (let pixel = 0, src = 0, dst = 0; pixel < pixelCount; pixel++, dst += 4) {\r\n const c0 = data[src++];\r\n\r\n if (componentCount === 1) {\r\n // Luminance/R-style data: replicate to RGB and use opaque alpha.\r\n normalizedData[dst] = c0;\r\n normalizedData[dst + 1] = c0;\r\n normalizedData[dst + 2] = c0;\r\n normalizedData[dst + 3] = 255;\r\n continue;\r\n }\r\n\r\n const c1 = data[src++];\r\n if (componentCount === 2) {\r\n // Two-channel data has no standard blue/alpha semantics for preview,\r\n // so preserve R/G, clear B, and force opaque alpha.\r\n normalizedData[dst] = c0;\r\n normalizedData[dst + 1] = c1;\r\n normalizedData[dst + 2] = 0;\r\n normalizedData[dst + 3] = 255;\r\n continue;\r\n }\r\n\r\n // RGB data: append an opaque alpha channel.\r\n normalizedData[dst] = c0;\r\n normalizedData[dst + 1] = c1;\r\n normalizedData[dst + 2] = data[src++];\r\n normalizedData[dst + 3] = 255;\r\n }\r\n\r\n return normalizedData;\r\n }\r\n }\r\n\r\n return data;\r\n}\r\n\r\n/**\r\n * Class used to host texture specific utilities\r\n */\r\nexport const TextureTools = {\r\n /**\r\n * Uses the GPU to create a copy texture rescaled at a given size\r\n * @param texture Texture to copy from\r\n * @param width defines the desired width\r\n * @param height defines the desired height\r\n * @param useBilinearMode defines if bilinear mode has to be used\r\n * @returns the generated texture\r\n */\r\n CreateResizedCopy,\r\n\r\n /**\r\n * Apply a post process to a texture\r\n * @param postProcessName name of the fragment post process\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param type type of the output texture. If not provided, use the one from internalTexture\r\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\r\n * @param format format of the output texture. If not provided, use the one from internalTexture\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\n ApplyPostProcess,\r\n /**\r\n * Converts a number to half float\r\n * @param value number to convert\r\n * @returns converted number\r\n */\r\n ToHalfFloat,\r\n\r\n /**\r\n * Converts a half float to a number\r\n * @param value half float to convert\r\n * @returns converted half float\r\n */\r\n FromHalfFloat,\r\n\r\n /**\r\n * Gets the data of the specified texture by rendering it to an intermediate RGBA texture and retrieving the bytes from it.\r\n * This is convienent to get 8-bit RGBA values for a texture in a GPU compressed format.\r\n * @param texture the source texture\r\n * @param width the width of the result, which does not have to match the source texture width\r\n * @param height the height of the result, which does not have to match the source texture height\r\n * @param face if the texture has multiple faces, the face index to use for the source\r\n * @param lod if the texture has multiple LODs, the lod index to use for the source\r\n * @returns the 8-bit texture data\r\n */\r\n GetTextureDataAsync,\r\n};\r\n"]}
@@ -3,7 +3,7 @@ import { Vector2, Vector3 } from "../Maths/math.vector.js";
3
3
  import { type AbstractMesh } from "../Meshes/abstractMesh.js";
4
4
  import { type ImageProcessingConfiguration } from "../Materials/imageProcessingConfiguration.js";
5
5
  import { ImageProcessingConfigurationDefines } from "../Materials/imageProcessingConfiguration.defines.js";
6
- import { type ColorGradient, type FactorGradient, type Color3Gradient, type IValueGradient } from "../Misc/gradients.js";
6
+ import { type ColorGradient, FactorGradient, type Color3Gradient, type IValueGradient } from "../Misc/gradients.js";
7
7
  import { type BoxParticleEmitter } from "../Particles/EmitterTypes/boxParticleEmitter.js";
8
8
  import { type BaseTexture } from "../Materials/Textures/baseTexture.js";
9
9
  import { Color4 } from "../Maths/math.color.js";
@@ -21,6 +21,7 @@ import { type HemisphericParticleEmitter } from "./EmitterTypes/hemisphericParti
21
21
  import { type SphereDirectedParticleEmitter, type SphereParticleEmitter } from "./EmitterTypes/sphereParticleEmitter.js";
22
22
  import { type CylinderDirectedParticleEmitter, type CylinderParticleEmitter } from "./EmitterTypes/cylinderParticleEmitter.js";
23
23
  import { type ConeDirectedParticleEmitter, type ConeParticleEmitter } from "./EmitterTypes/coneParticleEmitter.js";
24
+ import { type Attractor } from "./attractor.js";
24
25
  /**
25
26
  * This represents the base class for particle system in Babylon.
26
27
  * Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust.
@@ -197,6 +198,23 @@ export declare class BaseParticleSystem implements IClipPlanesHolder {
197
198
  set noiseTexture(value: Nullable<ProceduralTexture>);
198
199
  /** Gets or sets the strength to apply to the noise value (default is (10, 10, 10)) */
199
200
  noiseStrength: Vector3;
201
+ /** @internal */
202
+ protected _attractors: Attractor[];
203
+ /**
204
+ * The list of attractors used to change the direction of the particles in the system.
205
+ * Please note that this is a copy of the internal array. If you want to modify it, please use the addAttractor and removeAttractor methods.
206
+ */
207
+ get attractors(): Attractor[];
208
+ /**
209
+ * Add an attractor to the particle system. Attractors are used to change the direction of the particles in the system.
210
+ * @param attractor - The attractor to add to the particle system
211
+ */
212
+ addAttractor(attractor: Attractor): void;
213
+ /**
214
+ * Removes an attractor from the particle system. Attractors are used to change the direction of the particles in the system.
215
+ * @param attractor - The attractor to remove from the particle system
216
+ */
217
+ removeAttractor(attractor: Attractor): void;
200
218
  /**
201
219
  * Callback triggered when the particle animation is ending.
202
220
  */
@@ -510,6 +528,20 @@ export declare class BaseParticleSystem implements IClipPlanesHolder {
510
528
  protected _attachImageProcessingConfiguration(configuration: Nullable<ImageProcessingConfiguration>): void;
511
529
  /** @internal */
512
530
  protected _reset(): void;
531
+ /**
532
+ * Adds a new factor gradient to the given array, sorted by gradient value.
533
+ * @param factorGradients - The array of factor gradients to add to
534
+ * @param gradient - The gradient value (between 0 and 1)
535
+ * @param factor - The first factor value
536
+ * @param factor2 - Optional second factor value for per-particle randomization
537
+ */
538
+ protected _addFactorGradient(factorGradients: FactorGradient[], gradient: number, factor: number, factor2?: number): void;
539
+ /**
540
+ * Removes a factor gradient from the given array by its gradient value.
541
+ * @param factorGradients - The array of factor gradients to remove from
542
+ * @param gradient - The gradient value to match for removal
543
+ */
544
+ protected _removeFactorGradient(factorGradients: Nullable<FactorGradient[]>, gradient: number): void;
513
545
  /**
514
546
  * @internal
515
547
  */
@@ -1,5 +1,6 @@
1
1
  import { Vector2, Vector3 } from "../Maths/math.vector.js";
2
2
  import { ImageProcessingConfigurationDefines } from "../Materials/imageProcessingConfiguration.defines.js";
3
+ import { FactorGradient } from "../Misc/gradients.js";
3
4
 
4
5
  import { Color4 } from "../Maths/math.color.js";
5
6
  import "../Engines/Extensions/engine.dynamicBuffer.js";
@@ -42,6 +43,30 @@ export class BaseParticleSystem {
42
43
  this._noiseTexture = value;
43
44
  this._reset();
44
45
  }
46
+ /**
47
+ * The list of attractors used to change the direction of the particles in the system.
48
+ * Please note that this is a copy of the internal array. If you want to modify it, please use the addAttractor and removeAttractor methods.
49
+ */
50
+ get attractors() {
51
+ return this._attractors.slice(0);
52
+ }
53
+ /**
54
+ * Add an attractor to the particle system. Attractors are used to change the direction of the particles in the system.
55
+ * @param attractor - The attractor to add to the particle system
56
+ */
57
+ addAttractor(attractor) {
58
+ this._attractors.push(attractor);
59
+ }
60
+ /**
61
+ * Removes an attractor from the particle system. Attractors are used to change the direction of the particles in the system.
62
+ * @param attractor - The attractor to remove from the particle system
63
+ */
64
+ removeAttractor(attractor) {
65
+ const index = this._attractors.indexOf(attractor);
66
+ if (index !== -1) {
67
+ this._attractors.splice(index, 1);
68
+ }
69
+ }
45
70
  /** @internal */
46
71
  get _isAnimationSheetEnabled() {
47
72
  return this._animationSheetEnabled;
@@ -326,6 +351,44 @@ export class BaseParticleSystem {
326
351
  }
327
352
  /** @internal */
328
353
  _reset() { }
354
+ /**
355
+ * Adds a new factor gradient to the given array, sorted by gradient value.
356
+ * @param factorGradients - The array of factor gradients to add to
357
+ * @param gradient - The gradient value (between 0 and 1)
358
+ * @param factor - The first factor value
359
+ * @param factor2 - Optional second factor value for per-particle randomization
360
+ */
361
+ _addFactorGradient(factorGradients, gradient, factor, factor2) {
362
+ const newGradient = new FactorGradient(gradient, factor, factor2);
363
+ factorGradients.push(newGradient);
364
+ factorGradients.sort((a, b) => {
365
+ if (a.gradient < b.gradient) {
366
+ return -1;
367
+ }
368
+ else if (a.gradient > b.gradient) {
369
+ return 1;
370
+ }
371
+ return 0;
372
+ });
373
+ }
374
+ /**
375
+ * Removes a factor gradient from the given array by its gradient value.
376
+ * @param factorGradients - The array of factor gradients to remove from
377
+ * @param gradient - The gradient value to match for removal
378
+ */
379
+ _removeFactorGradient(factorGradients, gradient) {
380
+ if (!factorGradients) {
381
+ return;
382
+ }
383
+ let index = 0;
384
+ for (const factorGradient of factorGradients) {
385
+ if (factorGradient.gradient === gradient) {
386
+ factorGradients.splice(index, 1);
387
+ break;
388
+ }
389
+ index++;
390
+ }
391
+ }
329
392
  /**
330
393
  * @internal
331
394
  */
@@ -466,6 +529,8 @@ export class BaseParticleSystem {
466
529
  this._noiseTexture = null;
467
530
  /** Gets or sets the strength to apply to the noise value (default is (10, 10, 10)) */
468
531
  this.noiseStrength = new Vector3(10, 10, 10);
532
+ /** @internal */
533
+ this._attractors = [];
469
534
  /**
470
535
  * Callback triggered when the particle animation is ending.
471
536
  */