laymur 0.26.0 → 0.27.0

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 (134) hide show
  1. package/README.md +79 -35
  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 +7 -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.js +1 -1
  46. package/dist/core/miscellaneous/resize-policy/UIResizePolicy.d.ts +7 -4
  47. package/dist/core/miscellaneous/resize-policy/UIResizePolicy.js +13 -6
  48. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCover.js +2 -2
  49. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCross.js +2 -2
  50. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCrossInverted.js +2 -2
  51. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFit.js +2 -2
  52. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFixedHeight.js +2 -2
  53. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFixedWidth.js +2 -2
  54. package/dist/core/miscellaneous/text-style/UITextStyle.js +2 -2
  55. package/dist/core/miscellaneous/texture/UITextureView.d.ts +4 -1
  56. package/dist/core/miscellaneous/texture/UITextureView.js +10 -7
  57. package/dist/core/miscellaneous/viewport/UIElementViewport.d.ts +31 -0
  58. package/dist/core/miscellaneous/viewport/UIElementViewport.js +54 -0
  59. package/dist/core/miscellaneous/viewport/UIViewport.d.ts +37 -0
  60. package/dist/core/miscellaneous/viewport/UIViewport.js +31 -0
  61. package/dist/core/miscellaneous/viewport/UIWindowViewport.d.ts +13 -0
  62. package/dist/core/miscellaneous/viewport/UIWindowViewport.js +25 -0
  63. package/dist/core/miscellaneous/webglCapabilities.js +61 -55
  64. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +36 -5
  65. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +23 -2
  66. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +153 -15
  67. package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.Internal.d.ts +1 -1
  68. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +2 -0
  69. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.d.ts +3 -0
  70. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.js +36 -16
  71. package/dist/debug/UIAspectDebug.js +4 -0
  72. package/dist/debug/UIHeightDebug.js +4 -0
  73. package/dist/debug/UIHorizontalDistanceDebug.js +5 -0
  74. package/dist/debug/UIHorizontalInterpolationDebug.js +5 -0
  75. package/dist/debug/UILayerDebug.d.ts +7 -0
  76. package/dist/debug/UILayerDebug.js +21 -0
  77. package/dist/debug/UIVerticalDistanceDebug.js +5 -0
  78. package/dist/debug/UIVerticalInterpolationDebug.js +5 -0
  79. package/dist/debug/UIWidthDebug.js +4 -0
  80. package/dist/debug/index.d.ts +1 -1
  81. package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.d.ts +1 -1
  82. package/dist/particles/behaviorModules/UIBehaviorModule.d.ts +5 -1
  83. package/dist/particles/behaviorModules/UIBehaviorPointGravity.d.ts +2 -2
  84. package/dist/particles/behaviorModules/UIBehaviorPointGravity.js +13 -10
  85. package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.d.ts +1 -1
  86. package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.js +6 -4
  87. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +1 -1
  88. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +4 -3
  89. package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.d.ts +2 -2
  90. package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.js +8 -8
  91. package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.d.ts +4 -3
  92. package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.js +8 -5
  93. package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.d.ts +1 -1
  94. package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.js +8 -8
  95. package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.d.ts +7 -5
  96. package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.js +12 -8
  97. package/dist/particles/elements/UIEmitter.Internal.d.ts +15 -2
  98. package/dist/particles/elements/UIEmitter.Internal.js +6 -0
  99. package/dist/particles/elements/UIEmitter.d.ts +19 -3
  100. package/dist/particles/elements/UIEmitter.js +100 -54
  101. package/dist/particles/index.d.ts +3 -2
  102. package/dist/particles/index.js +1 -0
  103. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +8 -2
  104. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +16 -11
  105. package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +7 -0
  106. package/dist/particles/instancedParticle/UIInstancedParticle.js +37 -2
  107. package/dist/particles/miscellaneous/miscellaneous.d.ts +34 -0
  108. package/dist/particles/miscellaneous/miscellaneous.js +72 -0
  109. package/dist/particles/renderingModules/UIRenderingColorOverLife.js +2 -2
  110. package/dist/particles/renderingModules/UIRenderingColorOverVelocity.js +2 -3
  111. package/dist/particles/renderingModules/UIRenderingModule.d.ts +3 -2
  112. package/dist/particles/renderingModules/UIRenderingModule.js +2 -1
  113. package/dist/particles/renderingModules/UIRenderingTexture.js +2 -1
  114. package/dist/particles/shaders/UIRenderingColorOverLife.d.ts +1 -2
  115. package/dist/particles/shaders/UIRenderingColorOverLife.js +5 -3
  116. package/dist/particles/shaders/UIRenderingColorOverVelocity.d.ts +1 -9
  117. package/dist/particles/shaders/UIRenderingColorOverVelocity.js +6 -13
  118. package/dist/particles/spawnModules/UISpawnModule.d.ts +5 -2
  119. package/dist/particles/spawnModules/UISpawnRandomLifetime.d.ts +2 -2
  120. package/dist/particles/spawnModules/UISpawnRandomLifetime.js +5 -5
  121. package/dist/particles/spawnModules/UISpawnRandomRotation.d.ts +1 -1
  122. package/dist/particles/spawnModules/UISpawnRandomRotation.js +5 -3
  123. package/dist/particles/spawnModules/UISpawnRandomScale.d.ts +1 -1
  124. package/dist/particles/spawnModules/UISpawnRandomScale.js +4 -3
  125. package/dist/particles/spawnModules/UISpawnRandomTorque.d.ts +1 -1
  126. package/dist/particles/spawnModules/UISpawnRandomTorque.js +5 -3
  127. package/dist/particles/spawnModules/UISpawnRandomVelocity.d.ts +1 -1
  128. package/dist/particles/spawnModules/UISpawnRandomVelocity.js +6 -4
  129. package/dist/particles/spawnModules/UISpawnRectangle.d.ts +1 -1
  130. package/dist/particles/spawnModules/UISpawnRectangle.js +6 -4
  131. package/package.json +13 -4
  132. package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts +0 -21
  133. package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.d.ts +0 -63
  134. package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.js +0 -144
@@ -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.0",
4
4
  "description": "Constraint-based UI library for Three.js mobile advertisements",
5
5
  "keywords": [
6
6
  "ui",
@@ -22,6 +22,8 @@
22
22
  "scripts": {
23
23
  "clean": "rm -rf dist",
24
24
  "build": "npm run clean && tsc -p tsconfig.json",
25
+ "lint": "eslint src",
26
+ "format": "prettier --write . && eslint src --fix",
25
27
  "prepublishOnly": "npm run build"
26
28
  },
27
29
  "main": "./dist/core/index.js",
@@ -53,12 +55,19 @@
53
55
  "ferrsign": "^0.0.4",
54
56
  "three": ">=0.157.0 <0.180.0"
55
57
  },
58
+ "peerDependenciesMeta": {
59
+ "fast-simplex-noise": {
60
+ "optional": true
61
+ }
62
+ },
56
63
  "devDependencies": {
57
64
  "@types/node": "^25.0.2",
58
65
  "@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",
66
+ "@typescript-eslint/eslint-plugin": "^8.72.1",
67
+ "@typescript-eslint/parser": "^8.72.1",
68
+ "eslint": "^10.14.0",
69
+ "eslint-plugin-simple-import-sort": "^12.1.1",
70
+ "prettier": "^3.9.10",
62
71
  "typescript": "^5.8.3"
63
72
  }
64
73
  }
@@ -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
- }
@@ -1,144 +0,0 @@
1
- import { Ferrsign1 } from "ferrsign";
2
- import { MathUtils, Ray, Vector3 } from "three";
3
- import { assertValidNumber } from "../../miscellaneous/asserts.js";
4
- import { isUIModeInteractive } from "../../miscellaneous/UIMode.js";
5
- import { UILayer } from "../UILayer/UILayer.js";
6
- import { FULLSCREEN_LAYER_DEFAULT_RESIZE_POLICY } from "./UIFullscreenLayer.Internal.js";
7
- /** Layer that automatically handles browser window resizing and input events */
8
- export class UIFullscreenLayer extends UILayer {
9
- constructor(options) {
10
- const resizePolicy = options?.resizePolicy ?? FULLSCREEN_LAYER_DEFAULT_RESIZE_POLICY;
11
- const scale = resizePolicy.calculateScale(window.innerWidth, window.innerHeight);
12
- super({
13
- width: window.innerWidth * scale,
14
- height: window.innerHeight * scale,
15
- ...options,
16
- });
17
- this.resizePolicyDirty = false;
18
- this.signalPointerPressedInternal = new Ferrsign1();
19
- this.signalPointerMovedInternal = new Ferrsign1();
20
- this.signalPointerReleasedInternal = new Ferrsign1();
21
- this.onResize = () => {
22
- const scale = this.resizePolicy.calculateScale(window.innerWidth, window.innerHeight);
23
- this.resizePolicy.dirty = false;
24
- this.resizePolicyDirty = false;
25
- this.resizeInternal(window.innerWidth * scale, window.innerHeight * scale);
26
- };
27
- this.onPointerDown = (event) => {
28
- this.handleWindowInput(event, "onPointerDown", this.signalPointerPressedInternal);
29
- };
30
- this.onPointerMove = (event) => {
31
- this.handleWindowInput(event, "onPointerMove", this.signalPointerMovedInternal);
32
- };
33
- this.onPointerUp = (event) => {
34
- this.handleWindowInput(event, "onPointerUp", this.signalPointerReleasedInternal);
35
- };
36
- this.resizePolicyInternal = resizePolicy;
37
- window.addEventListener("resize", this.onResize);
38
- window.addEventListener("pointerdown", this.onPointerDown);
39
- window.addEventListener("pointermove", this.onPointerMove);
40
- window.addEventListener("pointerup", this.onPointerUp);
41
- }
42
- /** Current resize policy */
43
- get resizePolicy() {
44
- return this.resizePolicyInternal;
45
- }
46
- /** Signal fired when pointer is pressed */
47
- get signalPointerPressed() {
48
- return this.signalPointerPressedInternal;
49
- }
50
- /** Signal fired when pointer is moved */
51
- get signalPointerMoved() {
52
- return this.signalPointerMovedInternal;
53
- }
54
- /** Signal fired when pointer is released */
55
- get signalPointerReleased() {
56
- return this.signalPointerReleasedInternal;
57
- }
58
- /** Updates resize policy */
59
- set resizePolicy(value) {
60
- if (this.resizePolicyInternal !== value) {
61
- this.resizePolicyInternal = value;
62
- this.resizePolicyDirty = true;
63
- }
64
- }
65
- /** Removes event listeners and destroys the layer with its elements and constraints */
66
- destroy() {
67
- window.removeEventListener("resize", this.onResize);
68
- window.removeEventListener("pointerdown", this.onPointerDown);
69
- window.removeEventListener("pointermove", this.onPointerMove);
70
- window.removeEventListener("pointerup", this.onPointerUp);
71
- super.destroy();
72
- }
73
- /**
74
- * Renders layer and all visible elements
75
- * @param renderer Three.js WebGL renderer
76
- * @param deltaTime Time since last frame in seconds
77
- */
78
- render(renderer, deltaTime) {
79
- assertValidNumber(deltaTime, "UIFullscreenLayer.render.deltaTime");
80
- if (this.destroyed) {
81
- return;
82
- }
83
- if (this.resizePolicy.dirty || this.resizePolicyDirty) {
84
- this.onResize();
85
- }
86
- super.renderInternal(renderer, deltaTime);
87
- }
88
- /**
89
- * Projects 3D world position to 2D layer coordinates
90
- * @param position World position
91
- * @param camera Three.js camera
92
- * @param result Reusable vector instance
93
- * @returns Layer coordinates
94
- */
95
- projectWorldPosition(position, camera, result = new Vector3()) {
96
- result.copy(position).project(camera);
97
- result.x = MathUtils.mapLinear(result.x, -1, 1, this.x, this.width);
98
- result.y = MathUtils.mapLinear(result.y, -1, 1, this.y, this.height);
99
- return result;
100
- }
101
- /**
102
- * Projects 2D layer coordinates to 3D world position
103
- * @param position Layer coordinates
104
- * @param camera Three.js camera
105
- * @param z Depth coordinate
106
- * @param result Reusable vector instance
107
- * @returns World position
108
- */
109
- projectLayerPosition(position, camera, z = -1, result = new Vector3()) {
110
- return result
111
- .set(MathUtils.mapLinear(position.x, this.x, this.width, -1, 1), MathUtils.mapLinear(position.y, this.y, this.height, -1, 1), z)
112
- .unproject(camera);
113
- }
114
- /**
115
- * Builds ray from layer position through camera
116
- * @param position Layer coordinates
117
- * @param camera Three.js camera
118
- * @param result Reusable ray instance
119
- * @returns Ray from near to far plane
120
- */
121
- buildRay(position, camera, result = new Ray()) {
122
- const near = new Vector3(MathUtils.mapLinear(position.x, this.x, this.width, -1, 1), MathUtils.mapLinear(position.y, this.y, this.height, -1, 1), -1).unproject(camera);
123
- const far = new Vector3(MathUtils.mapLinear(position.x, this.x, this.width, -1, 1), MathUtils.mapLinear(position.y, this.y, this.height, -1, 1), 1).unproject(camera);
124
- const direction = far.sub(near).normalize();
125
- return result.set(near, direction);
126
- }
127
- handleWindowInput(event, pointerFunctionName, signal) {
128
- const rect = event.target instanceof HTMLElement ? event.target.getBoundingClientRect() : null;
129
- const x = rect ? event.clientX - rect.left : event.clientX;
130
- const y = rect ? rect.bottom - event.clientY : window.innerHeight - event.clientY;
131
- const scale = this.resizePolicy.calculateScale(window.innerWidth, window.innerHeight);
132
- const scaledX = x * scale;
133
- const scaledY = y * scale;
134
- if (isUIModeInteractive(this.mode)) {
135
- signal.emit({
136
- x: scaledX,
137
- y: scaledY,
138
- identifier: event.pointerId,
139
- layer: this,
140
- });
141
- this.inputWrapperInternal[pointerFunctionName](scaledX, scaledY, event.pointerId);
142
- }
143
- }
144
- }