laymur 0.26.0 → 0.27.1

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 (140) hide show
  1. package/README.md +80 -36
  2. package/dist/core/constraints/UICustomConstraint.d.ts +1 -1
  3. package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +1 -1
  4. package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +1 -1
  5. package/dist/core/constraints/builders/UIConstraint2DBuilder.d.ts +2 -3
  6. package/dist/core/elements/UIAnimatedImage/UIAnimatedImage.d.ts +2 -2
  7. package/dist/core/elements/UIAnimatedImage/UIAnimatedImage.js +24 -12
  8. package/dist/core/elements/UIDummy/UIDummy.Internal.d.ts +10 -0
  9. package/dist/core/elements/UIDummy/UIDummy.d.ts +42 -5
  10. package/dist/core/elements/UIDummy/UIDummy.js +119 -25
  11. package/dist/core/elements/UIElement/UIElement.Internal.d.ts +1 -1
  12. package/dist/core/elements/UIElement/UIElement.d.ts +14 -0
  13. package/dist/core/elements/UIElement/UIElement.js +34 -3
  14. package/dist/core/elements/UIGraphics/UIGraphics.Internal.d.ts +1 -1
  15. package/dist/core/elements/UIGraphics/UIGraphics.d.ts +1 -1
  16. package/dist/core/elements/UIGraphics/UIGraphics.js +2 -2
  17. package/dist/core/elements/UIImage/UIImage.d.ts +2 -2
  18. package/dist/core/elements/UIImage/UIImage.js +10 -8
  19. package/dist/core/elements/UINineSlice/UINineSlice.d.ts +4 -4
  20. package/dist/core/elements/UINineSlice/UINineSlice.js +11 -9
  21. package/dist/core/elements/UIProgress/UIProgress.d.ts +2 -2
  22. package/dist/core/elements/UIProgress/UIProgress.js +15 -10
  23. package/dist/core/elements/UIScene/UIScene.Internal.d.ts +1 -1
  24. package/dist/core/elements/UIScene/UIScene.d.ts +3 -2
  25. package/dist/core/elements/UIScene/UIScene.js +18 -12
  26. package/dist/core/elements/UIText/UIText.Measuring.d.ts +1 -1
  27. package/dist/core/elements/UIText/UIText.d.ts +3 -3
  28. package/dist/core/elements/UIText/UIText.js +6 -6
  29. package/dist/core/index.d.ts +44 -41
  30. package/dist/core/index.js +12 -9
  31. package/dist/core/layers/UILayer/UILayer.d.ts +40 -4
  32. package/dist/core/layers/UILayer/UILayer.js +70 -9
  33. package/dist/core/layers/UIViewportLayer/UIViewportLayer.Internal.d.ts +27 -0
  34. package/dist/core/layers/{UIFullscreenLayer/UIFullscreenLayer.Internal.js → UIViewportLayer/UIViewportLayer.Internal.js} +1 -1
  35. package/dist/core/layers/UIViewportLayer/UIViewportLayer.d.ts +98 -0
  36. package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +251 -0
  37. package/dist/core/miscellaneous/asserts.d.ts +14 -0
  38. package/dist/core/miscellaneous/asserts.js +28 -0
  39. package/dist/core/miscellaneous/canvas.js +10 -2
  40. package/dist/core/miscellaneous/color/UIColor.js +4 -2
  41. package/dist/core/miscellaneous/computeTransform.d.ts +12 -0
  42. package/dist/core/miscellaneous/computeTransform.js +20 -0
  43. package/dist/core/miscellaneous/context-monitor/UIContextMonitor.d.ts +1 -0
  44. package/dist/core/miscellaneous/context-monitor/UIContextMonitor.js +60 -0
  45. package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.js +2 -1
  46. package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.js +1 -1
  47. package/dist/core/miscellaneous/mask/UIMaskMaterialPatch.js +2 -1
  48. package/dist/core/miscellaneous/resize-policy/UIResizePolicy.d.ts +7 -4
  49. package/dist/core/miscellaneous/resize-policy/UIResizePolicy.js +13 -6
  50. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCover.d.ts +1 -1
  51. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCover.js +3 -3
  52. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCross.js +2 -2
  53. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCrossInverted.js +2 -2
  54. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFit.d.ts +1 -1
  55. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFit.js +3 -3
  56. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFixedHeight.js +2 -2
  57. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFixedWidth.js +2 -2
  58. package/dist/core/miscellaneous/text-style/UITextStyle.js +2 -2
  59. package/dist/core/miscellaneous/texture/UITextureView.d.ts +4 -1
  60. package/dist/core/miscellaneous/texture/UITextureView.js +10 -7
  61. package/dist/core/miscellaneous/viewport/UIElementViewport.d.ts +31 -0
  62. package/dist/core/miscellaneous/viewport/UIElementViewport.js +54 -0
  63. package/dist/core/miscellaneous/viewport/UIViewport.d.ts +37 -0
  64. package/dist/core/miscellaneous/viewport/UIViewport.js +31 -0
  65. package/dist/core/miscellaneous/viewport/UIWindowViewport.d.ts +13 -0
  66. package/dist/core/miscellaneous/viewport/UIWindowViewport.js +25 -0
  67. package/dist/core/miscellaneous/webglCapabilities.js +61 -55
  68. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +36 -5
  69. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +23 -2
  70. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +153 -15
  71. package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.Internal.d.ts +1 -1
  72. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +2 -0
  73. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.d.ts +3 -0
  74. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.js +36 -16
  75. package/dist/debug/UIAspectDebug.js +8 -7
  76. package/dist/debug/UIHeightDebug.js +8 -4
  77. package/dist/debug/UIHorizontalDistanceDebug.js +9 -7
  78. package/dist/debug/UIHorizontalInterpolationDebug.js +16 -10
  79. package/dist/debug/UILayerDebug.d.ts +7 -0
  80. package/dist/debug/UILayerDebug.js +21 -0
  81. package/dist/debug/UIVerticalDistanceDebug.js +9 -7
  82. package/dist/debug/UIVerticalInterpolationDebug.js +16 -10
  83. package/dist/debug/UIWidthDebug.js +8 -4
  84. package/dist/debug/index.d.ts +1 -1
  85. package/dist/debug/miscellaneous.d.ts +7 -0
  86. package/dist/debug/miscellaneous.js +11 -1
  87. package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.d.ts +1 -1
  88. package/dist/particles/behaviorModules/UIBehaviorModule.d.ts +5 -1
  89. package/dist/particles/behaviorModules/UIBehaviorPointGravity.d.ts +2 -2
  90. package/dist/particles/behaviorModules/UIBehaviorPointGravity.js +13 -10
  91. package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.d.ts +1 -1
  92. package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.js +6 -4
  93. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +1 -1
  94. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +4 -3
  95. package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.d.ts +2 -2
  96. package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.js +8 -8
  97. package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.d.ts +4 -3
  98. package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.js +8 -5
  99. package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.d.ts +1 -1
  100. package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.js +8 -8
  101. package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.d.ts +7 -5
  102. package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.js +12 -8
  103. package/dist/particles/elements/UIEmitter.Internal.d.ts +15 -2
  104. package/dist/particles/elements/UIEmitter.Internal.js +6 -0
  105. package/dist/particles/elements/UIEmitter.d.ts +19 -3
  106. package/dist/particles/elements/UIEmitter.js +100 -54
  107. package/dist/particles/index.d.ts +3 -2
  108. package/dist/particles/index.js +1 -0
  109. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +8 -2
  110. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +16 -11
  111. package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +7 -0
  112. package/dist/particles/instancedParticle/UIInstancedParticle.js +37 -2
  113. package/dist/particles/miscellaneous/miscellaneous.d.ts +34 -0
  114. package/dist/particles/miscellaneous/miscellaneous.js +72 -0
  115. package/dist/particles/renderingModules/UIRenderingColorOverLife.js +2 -2
  116. package/dist/particles/renderingModules/UIRenderingColorOverVelocity.js +2 -3
  117. package/dist/particles/renderingModules/UIRenderingModule.d.ts +3 -2
  118. package/dist/particles/renderingModules/UIRenderingModule.js +2 -1
  119. package/dist/particles/renderingModules/UIRenderingTexture.js +2 -1
  120. package/dist/particles/shaders/UIRenderingColorOverLife.d.ts +1 -2
  121. package/dist/particles/shaders/UIRenderingColorOverLife.js +5 -3
  122. package/dist/particles/shaders/UIRenderingColorOverVelocity.d.ts +1 -9
  123. package/dist/particles/shaders/UIRenderingColorOverVelocity.js +6 -13
  124. package/dist/particles/spawnModules/UISpawnModule.d.ts +5 -2
  125. package/dist/particles/spawnModules/UISpawnRandomLifetime.d.ts +2 -2
  126. package/dist/particles/spawnModules/UISpawnRandomLifetime.js +5 -5
  127. package/dist/particles/spawnModules/UISpawnRandomRotation.d.ts +1 -1
  128. package/dist/particles/spawnModules/UISpawnRandomRotation.js +5 -3
  129. package/dist/particles/spawnModules/UISpawnRandomScale.d.ts +1 -1
  130. package/dist/particles/spawnModules/UISpawnRandomScale.js +4 -3
  131. package/dist/particles/spawnModules/UISpawnRandomTorque.d.ts +1 -1
  132. package/dist/particles/spawnModules/UISpawnRandomTorque.js +5 -3
  133. package/dist/particles/spawnModules/UISpawnRandomVelocity.d.ts +1 -1
  134. package/dist/particles/spawnModules/UISpawnRandomVelocity.js +6 -4
  135. package/dist/particles/spawnModules/UISpawnRectangle.d.ts +1 -1
  136. package/dist/particles/spawnModules/UISpawnRectangle.js +6 -4
  137. package/package.json +34 -22
  138. package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts +0 -21
  139. package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.d.ts +0 -63
  140. package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.js +0 -144
@@ -1,6 +1,17 @@
1
1
  import { makeNoise2D } from "fast-simplex-noise";
2
2
  import { ClampToEdgeWrapping, DataTexture, LinearFilter, RGBAFormat, SRGBColorSpace, Texture, UnsignedByteType, UVMapping, } from "three";
3
+ export { assertValidNonNegativeInteger, assertValidUnitNumber, } from "../../core/miscellaneous/asserts.js";
3
4
  import { getTextureImageSize } from "../../core/miscellaneous/texture/UITextureView.Internal.js";
5
+ /** Formats a number as a GLSL float literal */
6
+ export function toGLSLFloat(value) {
7
+ const literal = String(value);
8
+ return /[.e]/.test(literal) ? literal : `${literal}.0`;
9
+ }
10
+ /** GLSL expression of the u that samples a gradient texture of `size` texels at t in [0, 1] */
11
+ export function buildGradientCoordinate(t, size) {
12
+ // Texel centers: the first stop at t = 0, the last at t = 1.
13
+ return `${t} * ${toGLSLFloat((size - 1) / size)} + ${toGLSLFloat(0.5 / size)}`;
14
+ }
4
15
  export function resolveUIRangeConfig(config) {
5
16
  if (typeof config === "number") {
6
17
  return { min: config, max: config };
@@ -62,3 +73,64 @@ export const BUILTIN_OFFSET_RANDOM_C = 12;
62
73
  export const BUILTIN_OFFSET_RANDOM_D = 13;
63
74
  export const BUILTIN_OFFSET_RANDOM_E = 14;
64
75
  export const BUILTIN_OFFSET_RANDOM_F = 15;
76
+ /** 2^24: integers below it are exact in float32, so the builtin buffer can carry a seed */
77
+ const PARTICLE_SEED_RANGE = 16777216;
78
+ /**
79
+ * 32-bit integer hash (lowbias32 by C. Wellons). A bijection in which every input bit affects
80
+ * every output bit. CPU only: GLSL ES 1.00 has no integer bit operations.
81
+ * @param value Integer; taken modulo 2^32
82
+ * @returns Unsigned 32-bit hash
83
+ */
84
+ function hashUint32(value) {
85
+ let x = value >>> 0;
86
+ x ^= x >>> 16;
87
+ x = Math.imul(x, 0x7feb352d);
88
+ x ^= x >>> 15;
89
+ x = Math.imul(x, 0x846ca68b);
90
+ x ^= x >>> 16;
91
+ return x >>> 0;
92
+ }
93
+ /**
94
+ * Maps a hash to [0, 1) with 24 bits: exact in float32, so a stored value stays below 1
95
+ * @param hash Unsigned 32-bit hash
96
+ * @returns Uniform value in [0, 1)
97
+ */
98
+ function hashToUnit(hash) {
99
+ return (hash >>> 8) / PARTICLE_SEED_RANGE;
100
+ }
101
+ /**
102
+ * Seed of the particle i of an emitter: a 24-bit integer
103
+ * @param emitterSeed Seed of the emitter
104
+ * @param index Number of particles the emitter spawned before this one
105
+ */
106
+ export function computeParticleSeed(emitterSeed, index) {
107
+ return hashUint32(emitterSeed ^ hashUint32(index)) >>> 8;
108
+ }
109
+ /**
110
+ * Stores a particle seed in the builtin buffer. The slot doubles as `PARTICLE_RANDOM_F`: the
111
+ * stored value seed / 2^24 is uniform in [0, 1).
112
+ */
113
+ export function writeParticleSeed(array, itemOffset, seed) {
114
+ array[itemOffset + BUILTIN_OFFSET_RANDOM_F] = seed / PARTICLE_SEED_RANGE;
115
+ }
116
+ /**
117
+ * Stream of random values of one module: one value per particle, independent of the other
118
+ * streams. Constant for a module, so compute it once per spawn or update call.
119
+ * @param salt Salt the emitter gives the module
120
+ * @param channel Index of the value within the module, below 64
121
+ * @returns Stream key for `particleRandom`
122
+ */
123
+ export function particleRandomStream(salt, channel) {
124
+ return hashUint32(Math.imul(salt, 64) + channel);
125
+ }
126
+ /**
127
+ * Random value of a particle in a stream, constant over the particle's life
128
+ * @param array Builtin buffer
129
+ * @param itemOffset Offset of the particle in the builtin buffer
130
+ * @param stream Key from `particleRandomStream`
131
+ * @returns Uniform value in [0, 1)
132
+ */
133
+ export function particleRandom(array, itemOffset, stream) {
134
+ const seed = Math.round(array[itemOffset + BUILTIN_OFFSET_RANDOM_F] * PARTICLE_SEED_RANGE);
135
+ return hashToUnit(hashUint32(seed ^ stream));
136
+ }
@@ -1,5 +1,5 @@
1
1
  import { buildGradientTexture } from "../miscellaneous/miscellaneous.js";
2
- import source from "../shaders/UIRenderingColorOverLife.js";
2
+ import { buildColorOverLifeSource } from "../shaders/UIRenderingColorOverLife.js";
3
3
  import { UIRenderingModule } from "./UIRenderingModule.js";
4
4
  /**
5
5
  * Colors particles based on lifetime progression.
@@ -15,11 +15,11 @@ export class UIRenderingColorOverLife extends UIRenderingModule {
15
15
  this.requiredProperties = {
16
16
  builtin: "Matrix4",
17
17
  };
18
- this.source = source;
19
18
  if (colors.length === 0) {
20
19
  throw new Error("UIRenderingColorOverLife.constructor.colors: colors array cannot be empty");
21
20
  }
22
21
  this.requiredUniforms = { colorOverLifeTexture: buildGradientTexture(colors) };
22
+ this.source = buildColorOverLifeSource(colors.length);
23
23
  }
24
24
  destroy() {
25
25
  this.requiredUniforms.colorOverLifeTexture.dispose();
@@ -1,5 +1,5 @@
1
1
  import { buildGradientTexture } from "../miscellaneous/miscellaneous.js";
2
- import source from "../shaders/UIRenderingColorOverVelocity.js";
2
+ import { buildColorOverVelocitySource } from "../shaders/UIRenderingColorOverVelocity.js";
3
3
  import { UIRenderingModule } from "./UIRenderingModule.js";
4
4
  /**
5
5
  * Colors particles based on velocity magnitude.
@@ -16,15 +16,14 @@ export class UIRenderingColorOverVelocity extends UIRenderingModule {
16
16
  this.requiredProperties = {
17
17
  builtin: "Matrix4",
18
18
  };
19
- this.source = source;
20
19
  if (colors.length === 0) {
21
20
  throw new Error("UIRenderingColorOverVelocity.constructor.colors: colors array cannot be empty");
22
21
  }
23
22
  if (maxVelocity <= 0) {
24
23
  throw new Error(`UIRenderingColorOverVelocity.constructor.maxVelocity: value must be greater than 0, got ${maxVelocity}`);
25
24
  }
26
- this.source = source.replace("COLOR_OVER_VELOCITY_MAX", `COLOR_OVER_VELOCITY_MAX ${maxVelocity.toFixed(2)}`);
27
25
  this.requiredUniforms = { colorOverVelocityTexture: buildGradientTexture(colors) };
26
+ this.source = buildColorOverVelocitySource(colors.length, maxVelocity);
28
27
  }
29
28
  destroy() {
30
29
  this.requiredUniforms.colorOverVelocityTexture.dispose();
@@ -4,12 +4,13 @@ import type { UIProperty, UIPropertyName } from "../../core/miscellaneous/generi
4
4
  *
5
5
  * The source defines `vec4 draw()`; the colors of all rendering modules are multiplied. It reads
6
6
  * `p_uv`, uniforms and properties as `p_<name>`, and builtin values through the `PARTICLE_*`
7
- * macros, which are cheaper than reading `p_builtin` as a whole.
7
+ * macros, which are cheaper than reading `p_builtin` as a whole. Uniforms belong to the module:
8
+ * the emitter renames them per module, so modules of one type keep their own values.
8
9
  */
9
10
  export declare abstract class UIRenderingModule {
10
11
  /** Per-particle properties the source reads, by name and type */
11
12
  readonly requiredProperties?: Record<string, UIPropertyName>;
12
- /** Uniforms the source reads, as `p_<name>` */
13
+ /** Uniforms the source reads, as `p_<name>`; names must be GLSL identifiers */
13
14
  abstract readonly requiredUniforms: Record<string, UIProperty>;
14
15
  /** GLSL source defining `vec4 draw()` */
15
16
  abstract readonly source: string;
@@ -3,7 +3,8 @@
3
3
  *
4
4
  * The source defines `vec4 draw()`; the colors of all rendering modules are multiplied. It reads
5
5
  * `p_uv`, uniforms and properties as `p_<name>`, and builtin values through the `PARTICLE_*`
6
- * macros, which are cheaper than reading `p_builtin` as a whole.
6
+ * macros, which are cheaper than reading `p_builtin` as a whole. Uniforms belong to the module:
7
+ * the emitter renames them per module, so modules of one type keep their own values.
7
8
  */
8
9
  export class UIRenderingModule {
9
10
  }
@@ -16,7 +16,8 @@ function buildMultiTextureShader(count) {
16
16
  }
17
17
  return [
18
18
  "vec4 draw() {",
19
- ` int idx = int(PARTICLE_RANDOM_A * ${count}.0);`,
19
+ // Clamped: at mediump precision a value just below 1 can round up to 1
20
+ ` int idx = int(min(PARTICLE_RANDOM_A * ${count}.0, ${count}.0 - 0.5));`,
20
21
  " mat3 t;",
21
22
  ...branches,
22
23
  " vec2 transformedUV = (t * vec3(p_uv, 1.0)).xy;",
@@ -1,2 +1 @@
1
- declare const source: string;
2
- export default source;
1
+ export declare function buildColorOverLifeSource(gradientSize: number): string;
@@ -1,7 +1,9 @@
1
- const source = `
1
+ import { buildGradientCoordinate } from "../miscellaneous/miscellaneous.js";
2
+ export function buildColorOverLifeSource(gradientSize) {
3
+ return `
2
4
  vec4 draw() {
3
5
  float t = clamp(PARTICLE_AGE / PARTICLE_LIFETIME, 0.0, 1.0);
4
- return srgbTexture2D(p_colorOverLifeTexture, vec2(t, 0.5));
6
+ return srgbTexture2D(p_colorOverLifeTexture, vec2(${buildGradientCoordinate("t", gradientSize)}, 0.5));
5
7
  }
6
8
  `;
7
- export default source;
9
+ }
@@ -1,9 +1 @@
1
- /**
2
- * The empty COLOR_OVER_VELOCITY_MAX macro is a placeholder: UIRenderingColorOverVelocity
3
- * rewrites the first occurrence of that token into "COLOR_OVER_VELOCITY_MAX <value>",
4
- * which turns this line into a real definition. The newline after it is load-bearing -
5
- * a "#define" body runs to end of line, so collapsing it would swallow draw() into
6
- * the macro and leave the shader without an entry point.
7
- */
8
- declare const source: string;
9
- export default source;
1
+ export declare function buildColorOverVelocitySource(gradientSize: number, maxVelocity: number): string;
@@ -1,16 +1,9 @@
1
- /**
2
- * The empty COLOR_OVER_VELOCITY_MAX macro is a placeholder: UIRenderingColorOverVelocity
3
- * rewrites the first occurrence of that token into "COLOR_OVER_VELOCITY_MAX <value>",
4
- * which turns this line into a real definition. The newline after it is load-bearing -
5
- * a "#define" body runs to end of line, so collapsing it would swallow draw() into
6
- * the macro and leave the shader without an entry point.
7
- */
8
- const source = `
9
- #define COLOR_OVER_VELOCITY_MAX
10
-
1
+ import { buildGradientCoordinate, toGLSLFloat } from "../miscellaneous/miscellaneous.js";
2
+ export function buildColorOverVelocitySource(gradientSize, maxVelocity) {
3
+ return `
11
4
  vec4 draw() {
12
- float t = clamp(length(vec2(PARTICLE_VELOCITY_X, PARTICLE_VELOCITY_Y)) / COLOR_OVER_VELOCITY_MAX, 0.0, 1.0);
13
- return srgbTexture2D(p_colorOverVelocityTexture, vec2(t, 0.5));
5
+ float t = clamp(length(vec2(PARTICLE_VELOCITY_X, PARTICLE_VELOCITY_Y)) / ${toGLSLFloat(maxVelocity)}, 0.0, 1.0);
6
+ return srgbTexture2D(p_colorOverVelocityTexture, vec2(${buildGradientCoordinate("t", gradientSize)}, 0.5));
14
7
  }
15
8
  `;
16
- export default source;
9
+ }
@@ -11,11 +11,14 @@ export declare abstract class UISpawnModule<T extends Record<string, UIPropertyN
11
11
  /** Per-particle properties the module writes, by name and type */
12
12
  abstract readonly requiredProperties: T;
13
13
  /**
14
- * Initializes the particles in [instanceBegin, instanceEnd).
14
+ * Initializes the particles in [instanceBegin, instanceEnd). They come zeroed, except builtin
15
+ * scale 1 and lifetime 1 second, and with their seed set.
15
16
  * @param properties Per-particle buffers of the required properties
17
+ * @param randomSalt Salt for `particleRandomStream`: random values of the module are
18
+ * independent of those of other modules, also of another instance of the same module
16
19
  */
17
20
  abstract spawn(properties: {
18
21
  [K in keyof T]: InstancedBufferAttribute;
19
- }, instanceBegin: number, instanceEnd: number): void;
22
+ }, instanceBegin: number, instanceEnd: number, randomSalt: number): void;
20
23
  destroy?(): void;
21
24
  }
@@ -4,7 +4,7 @@ import { UISpawnModule } from "./UISpawnModule.js";
4
4
  /**
5
5
  * Assigns random lifetime to particles.
6
6
  *
7
- * Lifetime is chosen uniformly from the specified range. Age is set to 0.
7
+ * Lifetime is chosen uniformly from the specified range.
8
8
  */
9
9
  export declare class UISpawnRandomLifetime extends UISpawnModule<{
10
10
  builtin: "Matrix4";
@@ -23,5 +23,5 @@ export declare class UISpawnRandomLifetime extends UISpawnModule<{
23
23
  set lifetime(value: UIRangeConfig);
24
24
  spawn(properties: {
25
25
  builtin: InstancedBufferAttribute;
26
- }, instanceBegin: number, instanceEnd: number): void;
26
+ }, instanceBegin: number, instanceEnd: number, randomSalt: number): void;
27
27
  }
@@ -1,11 +1,11 @@
1
1
  import { MathUtils } from "three";
2
2
  import { assertValidPositiveNumber } from "../../core/miscellaneous/asserts.js";
3
- import { BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
3
+ import { BUILTIN_OFFSET_LIFETIME, particleRandom, particleRandomStream, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
4
4
  import { UISpawnModule } from "./UISpawnModule.js";
5
5
  /**
6
6
  * Assigns random lifetime to particles.
7
7
  *
8
- * Lifetime is chosen uniformly from the specified range. Age is set to 0.
8
+ * Lifetime is chosen uniformly from the specified range.
9
9
  */
10
10
  export class UISpawnRandomLifetime extends UISpawnModule {
11
11
  /**
@@ -28,14 +28,14 @@ export class UISpawnRandomLifetime extends UISpawnModule {
28
28
  assertValidPositiveNumber(this.lifetimeInternal.min, "UISpawnRandomLifetime.lifetime.min");
29
29
  assertValidPositiveNumber(this.lifetimeInternal.max, "UISpawnRandomLifetime.lifetime.max");
30
30
  }
31
- spawn(properties, instanceBegin, instanceEnd) {
31
+ spawn(properties, instanceBegin, instanceEnd, randomSalt) {
32
32
  const { builtin } = properties;
33
33
  const { array, itemSize } = builtin;
34
34
  const { min: lifetimeMin, max: lifetimeMax } = this.lifetimeInternal;
35
+ const lifetimeStream = particleRandomStream(randomSalt, 0);
35
36
  for (let i = instanceBegin; i < instanceEnd; i++) {
36
37
  const itemOffset = i * itemSize;
37
- array[itemOffset + BUILTIN_OFFSET_LIFETIME] = MathUtils.randFloat(lifetimeMin, lifetimeMax);
38
- array[itemOffset + BUILTIN_OFFSET_AGE] = 0;
38
+ array[itemOffset + BUILTIN_OFFSET_LIFETIME] = MathUtils.lerp(lifetimeMin, lifetimeMax, particleRandom(array, itemOffset, lifetimeStream));
39
39
  }
40
40
  builtin.needsUpdate = true;
41
41
  }
@@ -23,5 +23,5 @@ export declare class UISpawnRandomRotation extends UISpawnModule<{
23
23
  set rotation(value: UIRangeConfig);
24
24
  spawn(properties: {
25
25
  builtin: InstancedBufferAttribute;
26
- }, instanceBegin: number, instanceEnd: number): void;
26
+ }, instanceBegin: number, instanceEnd: number, randomSalt: number): void;
27
27
  }
@@ -1,6 +1,6 @@
1
1
  import { MathUtils } from "three";
2
2
  import { assertValidNumber } from "../../core/miscellaneous/asserts.js";
3
- import { BUILTIN_OFFSET_ROTATION, resolveUIRangeConfig } from "../miscellaneous/miscellaneous.js";
3
+ import { BUILTIN_OFFSET_ROTATION, particleRandom, particleRandomStream, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
4
4
  import { UISpawnModule } from "./UISpawnModule.js";
5
5
  /**
6
6
  * Assigns random rotation to particles.
@@ -28,12 +28,14 @@ export class UISpawnRandomRotation extends UISpawnModule {
28
28
  assertValidNumber(this.rotationInternal.min, "UISpawnRandomRotation.rotation.min");
29
29
  assertValidNumber(this.rotationInternal.max, "UISpawnRandomRotation.rotation.max");
30
30
  }
31
- spawn(properties, instanceBegin, instanceEnd) {
31
+ spawn(properties, instanceBegin, instanceEnd, randomSalt) {
32
32
  const { builtin } = properties;
33
33
  const { array, itemSize } = builtin;
34
34
  const { min: rotationMin, max: rotationMax } = this.rotationInternal;
35
+ const rotationStream = particleRandomStream(randomSalt, 0);
35
36
  for (let i = instanceBegin; i < instanceEnd; i++) {
36
- array[i * itemSize + BUILTIN_OFFSET_ROTATION] = MathUtils.randFloat(rotationMin, rotationMax);
37
+ const itemOffset = i * itemSize;
38
+ array[itemOffset + BUILTIN_OFFSET_ROTATION] = MathUtils.lerp(rotationMin, rotationMax, particleRandom(array, itemOffset, rotationStream));
37
39
  }
38
40
  builtin.needsUpdate = true;
39
41
  }
@@ -29,5 +29,5 @@ export declare class UISpawnRandomScale extends UISpawnModule<{
29
29
  set aspect(value: UIAspectConfig);
30
30
  spawn(properties: {
31
31
  builtin: InstancedBufferAttribute;
32
- }, instanceBegin: number, instanceEnd: number): void;
32
+ }, instanceBegin: number, instanceEnd: number, randomSalt: number): void;
33
33
  }
@@ -1,6 +1,6 @@
1
1
  import { MathUtils } from "three";
2
2
  import { assertValidPositiveNumber } from "../../core/miscellaneous/asserts.js";
3
- import { BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y, resolveAspect, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
3
+ import { BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y, particleRandom, particleRandomStream, resolveAspect, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
4
4
  import { UISpawnModule } from "./UISpawnModule.js";
5
5
  /**
6
6
  * Assigns random scale to particles.
@@ -40,13 +40,14 @@ export class UISpawnRandomScale extends UISpawnModule {
40
40
  this.aspectInternal = resolveAspect(value);
41
41
  assertValidPositiveNumber(this.aspectInternal, "UISpawnRandomScale.aspect");
42
42
  }
43
- spawn(properties, instanceBegin, instanceEnd) {
43
+ spawn(properties, instanceBegin, instanceEnd, randomSalt) {
44
44
  const { builtin } = properties;
45
45
  const { array, itemSize } = builtin;
46
46
  const { min: scaleMin, max: scaleMax } = this.scaleInternal;
47
+ const scaleStream = particleRandomStream(randomSalt, 0);
47
48
  for (let i = instanceBegin; i < instanceEnd; i++) {
48
49
  const itemOffset = i * itemSize;
49
- const randomScale = MathUtils.randFloat(scaleMin, scaleMax);
50
+ const randomScale = MathUtils.lerp(scaleMin, scaleMax, particleRandom(array, itemOffset, scaleStream));
50
51
  array[itemOffset + BUILTIN_OFFSET_SCALE_X] = randomScale * this.aspectInternal;
51
52
  array[itemOffset + BUILTIN_OFFSET_SCALE_Y] = randomScale;
52
53
  }
@@ -23,5 +23,5 @@ export declare class UISpawnRandomTorque extends UISpawnModule<{
23
23
  set torque(value: UIRangeConfig);
24
24
  spawn(properties: {
25
25
  builtin: InstancedBufferAttribute;
26
- }, instanceBegin: number, instanceEnd: number): void;
26
+ }, instanceBegin: number, instanceEnd: number, randomSalt: number): void;
27
27
  }
@@ -1,6 +1,6 @@
1
1
  import { MathUtils } from "three";
2
2
  import { assertValidNumber } from "../../core/miscellaneous/asserts.js";
3
- import { BUILTIN_OFFSET_TORQUE, resolveUIRangeConfig } from "../miscellaneous/miscellaneous.js";
3
+ import { BUILTIN_OFFSET_TORQUE, particleRandom, particleRandomStream, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
4
4
  import { UISpawnModule } from "./UISpawnModule.js";
5
5
  /**
6
6
  * Assigns random angular velocity to particles.
@@ -28,12 +28,14 @@ export class UISpawnRandomTorque extends UISpawnModule {
28
28
  assertValidNumber(this.torqueInternal.min, "UISpawnRandomTorque.torque.min");
29
29
  assertValidNumber(this.torqueInternal.max, "UISpawnRandomTorque.torque.max");
30
30
  }
31
- spawn(properties, instanceBegin, instanceEnd) {
31
+ spawn(properties, instanceBegin, instanceEnd, randomSalt) {
32
32
  const { builtin } = properties;
33
33
  const { array, itemSize } = builtin;
34
34
  const { min: torqueMin, max: torqueMax } = this.torqueInternal;
35
+ const torqueStream = particleRandomStream(randomSalt, 0);
35
36
  for (let i = instanceBegin; i < instanceEnd; i++) {
36
- array[i * itemSize + BUILTIN_OFFSET_TORQUE] = MathUtils.randFloat(torqueMin, torqueMax);
37
+ const itemOffset = i * itemSize;
38
+ array[itemOffset + BUILTIN_OFFSET_TORQUE] = MathUtils.lerp(torqueMin, torqueMax, particleRandom(array, itemOffset, torqueStream));
37
39
  }
38
40
  builtin.needsUpdate = true;
39
41
  }
@@ -29,5 +29,5 @@ export declare class UISpawnRandomVelocity extends UISpawnModule<{
29
29
  set magnitude(value: UIRangeConfig);
30
30
  spawn(properties: {
31
31
  builtin: InstancedBufferAttribute;
32
- }, instanceBegin: number, instanceEnd: number): void;
32
+ }, instanceBegin: number, instanceEnd: number, randomSalt: number): void;
33
33
  }
@@ -1,6 +1,6 @@
1
1
  import { MathUtils } from "three";
2
2
  import { assertValidNumber } from "../../core/miscellaneous/asserts.js";
3
- import { BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
3
+ import { BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, particleRandom, particleRandomStream, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
4
4
  import { UISpawnModule } from "./UISpawnModule.js";
5
5
  /**
6
6
  * Assigns random velocity to particles.
@@ -42,15 +42,17 @@ export class UISpawnRandomVelocity extends UISpawnModule {
42
42
  assertValidNumber(this.magnitudeInternal.min, "UISpawnRandomVelocity.magnitude.min");
43
43
  assertValidNumber(this.magnitudeInternal.max, "UISpawnRandomVelocity.magnitude.max");
44
44
  }
45
- spawn(properties, instanceBegin, instanceEnd) {
45
+ spawn(properties, instanceBegin, instanceEnd, randomSalt) {
46
46
  const { builtin } = properties;
47
47
  const { array, itemSize } = builtin;
48
48
  const { min: angleMin, max: angleMax } = this.angleInternal;
49
49
  const { min: magnitudeMin, max: magnitudeMax } = this.magnitudeInternal;
50
+ const angleStream = particleRandomStream(randomSalt, 0);
51
+ const magnitudeStream = particleRandomStream(randomSalt, 1);
50
52
  for (let i = instanceBegin; i < instanceEnd; i++) {
51
53
  const itemOffset = i * itemSize;
52
- const angle = MathUtils.randFloat(angleMin, angleMax);
53
- const magnitude = MathUtils.randFloat(magnitudeMin, magnitudeMax);
54
+ const angle = MathUtils.lerp(angleMin, angleMax, particleRandom(array, itemOffset, angleStream));
55
+ const magnitude = MathUtils.lerp(magnitudeMin, magnitudeMax, particleRandom(array, itemOffset, magnitudeStream));
54
56
  array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] = Math.cos(angle) * magnitude;
55
57
  array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] = Math.sin(angle) * magnitude;
56
58
  }
@@ -30,5 +30,5 @@ export declare class UISpawnRectangle extends UISpawnModule<{
30
30
  set max(value: UIVector2Config);
31
31
  spawn(properties: {
32
32
  builtin: InstancedBufferAttribute;
33
- }, instanceBegin: number, instanceEnd: number): void;
33
+ }, instanceBegin: number, instanceEnd: number, randomSalt: number): void;
34
34
  }
@@ -1,6 +1,6 @@
1
1
  import { MathUtils } from "three";
2
2
  import { assertValidNumber } from "../../core/miscellaneous/asserts.js";
3
- import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, resolveUIVector2Config, } from "../miscellaneous/miscellaneous.js";
3
+ import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, particleRandom, particleRandomStream, resolveUIVector2Config, } from "../miscellaneous/miscellaneous.js";
4
4
  import { UISpawnModule } from "./UISpawnModule.js";
5
5
  /**
6
6
  * Spawns particles at random positions within a rectangle.
@@ -42,15 +42,17 @@ export class UISpawnRectangle extends UISpawnModule {
42
42
  assertValidNumber(this.maxInternal.x, "UISpawnRectangle.max.x");
43
43
  assertValidNumber(this.maxInternal.y, "UISpawnRectangle.max.y");
44
44
  }
45
- spawn(properties, instanceBegin, instanceEnd) {
45
+ spawn(properties, instanceBegin, instanceEnd, randomSalt) {
46
46
  const { builtin } = properties;
47
47
  const { array, itemSize } = builtin;
48
48
  const { x: minX, y: minY } = this.minInternal;
49
49
  const { x: maxX, y: maxY } = this.maxInternal;
50
+ const xStream = particleRandomStream(randomSalt, 0);
51
+ const yStream = particleRandomStream(randomSalt, 1);
50
52
  for (let i = instanceBegin; i < instanceEnd; i++) {
51
53
  const itemOffset = i * itemSize;
52
- array[itemOffset + BUILTIN_OFFSET_POSITION_X] = MathUtils.randFloat(minX, maxX);
53
- array[itemOffset + BUILTIN_OFFSET_POSITION_Y] = MathUtils.randFloat(minY, maxY);
54
+ array[itemOffset + BUILTIN_OFFSET_POSITION_X] = MathUtils.lerp(minX, maxX, particleRandom(array, itemOffset, xStream));
55
+ array[itemOffset + BUILTIN_OFFSET_POSITION_Y] = MathUtils.lerp(minY, maxY, particleRandom(array, itemOffset, yStream));
54
56
  }
55
57
  builtin.needsUpdate = true;
56
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "laymur",
3
- "version": "0.26.0",
3
+ "version": "0.27.1",
4
4
  "description": "Constraint-based UI library for Three.js mobile advertisements",
5
5
  "keywords": [
6
6
  "ui",
@@ -11,27 +11,17 @@
11
11
  "layout",
12
12
  "typescript"
13
13
  ],
14
- "author": "jango",
15
- "license": "MIT",
14
+ "homepage": "https://github.com/jango-git/laymur#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/jango-git/laymur/issues"
17
+ },
16
18
  "repository": {
17
19
  "type": "git",
18
20
  "url": "git+https://github.com/jango-git/laymur.git"
19
21
  },
22
+ "license": "MIT",
23
+ "author": "jango",
20
24
  "type": "module",
21
- "sideEffects": false,
22
- "scripts": {
23
- "clean": "rm -rf dist",
24
- "build": "npm run clean && tsc -p tsconfig.json",
25
- "prepublishOnly": "npm run build"
26
- },
27
- "main": "./dist/core/index.js",
28
- "module": "./dist/core/index.js",
29
- "types": "./dist/core/index.d.ts",
30
- "files": [
31
- "dist",
32
- "README.md",
33
- "LICENSE"
34
- ],
35
25
  "exports": {
36
26
  ".": {
37
27
  "types": "./dist/core/index.d.ts",
@@ -47,18 +37,40 @@
47
37
  },
48
38
  "./package.json": "./package.json"
49
39
  },
40
+ "main": "./dist/core/index.js",
41
+ "types": "./dist/core/index.d.ts",
42
+ "files": [
43
+ "dist",
44
+ "README.md",
45
+ "LICENSE"
46
+ ],
47
+ "sideEffects": false,
48
+ "scripts": {
49
+ "clean": "rm -rf dist",
50
+ "build": "npm run clean && tsc -p tsconfig.json",
51
+ "lint": "eslint src",
52
+ "format": "prettier --write . && eslint src --fix",
53
+ "prepublishOnly": "npm run build"
54
+ },
50
55
  "peerDependencies": {
51
56
  "@lume/kiwi": "^0.4.4",
52
57
  "fast-simplex-noise": "^4.0.0",
53
- "ferrsign": "^0.0.4",
54
- "three": ">=0.157.0 <0.180.0"
58
+ "ferrsign": "^0.0.6",
59
+ "three": ">=0.157.0 <0.188.0"
60
+ },
61
+ "peerDependenciesMeta": {
62
+ "fast-simplex-noise": {
63
+ "optional": true
64
+ }
55
65
  },
56
66
  "devDependencies": {
57
67
  "@types/node": "^25.0.2",
58
68
  "@types/three": "^0.157.0",
59
- "@typescript-eslint/eslint-plugin": "^8.32.0",
60
- "@typescript-eslint/parser": "^8.32.0",
61
- "eslint": "^9.26.0",
69
+ "@typescript-eslint/eslint-plugin": "^8.72.1",
70
+ "@typescript-eslint/parser": "^8.72.1",
71
+ "eslint": "^10.14.0",
72
+ "eslint-plugin-simple-import-sort": "^12.1.1",
73
+ "prettier": "^3.9.10",
62
74
  "typescript": "^5.8.3"
63
75
  }
64
76
  }
@@ -1,21 +0,0 @@
1
- import type { UIResizePolicy } from "../../miscellaneous/resize-policy/UIResizePolicy.js";
2
- import { UIResizePolicyNone } from "../../miscellaneous/resize-policy/UIResizePolicyNone.js";
3
- import type { UILayerOptions } from "../UILayer/UILayer.Internal.js";
4
- import type { UIFullscreenLayer } from "./UIFullscreenLayer.js";
5
- /** Fullscreen layer input event data */
6
- export interface UIFullscreenLayerInputEventData {
7
- /** X coordinate */
8
- x: number;
9
- /** Y coordinate */
10
- y: number;
11
- /** Pointer identifier */
12
- identifier: number;
13
- /** Layer that emitted the event */
14
- layer: UIFullscreenLayer;
15
- }
16
- /** Configuration for fullscreen layer */
17
- export interface UIFullscreenLayerOptions extends Omit<UILayerOptions, "width" | "height"> {
18
- /** Strategy for handling window resize */
19
- resizePolicy: UIResizePolicy;
20
- }
21
- export declare const FULLSCREEN_LAYER_DEFAULT_RESIZE_POLICY: UIResizePolicyNone;
@@ -1,63 +0,0 @@
1
- import type { FerrsignView1 } from "ferrsign";
2
- import type { Camera, Vector2, WebGLRenderer } from "three";
3
- import { Ray, Vector3 } from "three";
4
- import type { UIResizePolicy } from "../../miscellaneous/resize-policy/UIResizePolicy.js";
5
- import { UILayer } from "../UILayer/UILayer.js";
6
- import type { UIFullscreenLayerInputEventData, UIFullscreenLayerOptions } from "./UIFullscreenLayer.Internal.js";
7
- /** Layer that automatically handles browser window resizing and input events */
8
- export declare class UIFullscreenLayer extends UILayer {
9
- private resizePolicyInternal;
10
- private resizePolicyDirty;
11
- private readonly signalPointerPressedInternal;
12
- private readonly signalPointerMovedInternal;
13
- private readonly signalPointerReleasedInternal;
14
- constructor(options?: Partial<UIFullscreenLayerOptions>);
15
- /** Current resize policy */
16
- get resizePolicy(): UIResizePolicy;
17
- /** Signal fired when pointer is pressed */
18
- get signalPointerPressed(): FerrsignView1<UIFullscreenLayerInputEventData>;
19
- /** Signal fired when pointer is moved */
20
- get signalPointerMoved(): FerrsignView1<UIFullscreenLayerInputEventData>;
21
- /** Signal fired when pointer is released */
22
- get signalPointerReleased(): FerrsignView1<UIFullscreenLayerInputEventData>;
23
- /** Updates resize policy */
24
- set resizePolicy(value: UIResizePolicy);
25
- /** Removes event listeners and destroys the layer with its elements and constraints */
26
- destroy(): void;
27
- /**
28
- * Renders layer and all visible elements
29
- * @param renderer Three.js WebGL renderer
30
- * @param deltaTime Time since last frame in seconds
31
- */
32
- render(renderer: WebGLRenderer, deltaTime: number): void;
33
- /**
34
- * Projects 3D world position to 2D layer coordinates
35
- * @param position World position
36
- * @param camera Three.js camera
37
- * @param result Reusable vector instance
38
- * @returns Layer coordinates
39
- */
40
- projectWorldPosition(position: Vector3, camera: Camera, result?: Vector3): Vector3;
41
- /**
42
- * Projects 2D layer coordinates to 3D world position
43
- * @param position Layer coordinates
44
- * @param camera Three.js camera
45
- * @param z Depth coordinate
46
- * @param result Reusable vector instance
47
- * @returns World position
48
- */
49
- projectLayerPosition(position: Vector2, camera: Camera, z?: number, result?: Vector3): Vector3;
50
- /**
51
- * Builds ray from layer position through camera
52
- * @param position Layer coordinates
53
- * @param camera Three.js camera
54
- * @param result Reusable ray instance
55
- * @returns Ray from near to far plane
56
- */
57
- buildRay(position: Vector2, camera: Camera, result?: Ray): Ray;
58
- private readonly onResize;
59
- private readonly onPointerDown;
60
- private readonly onPointerMove;
61
- private readonly onPointerUp;
62
- private handleWindowInput;
63
- }