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,6 +1,6 @@
1
1
  import { MathUtils } from "three";
2
- import { assertValidNumber } from "../../core/miscellaneous/asserts.js";
3
- import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_RANDOM_A, BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_RANDOM_C, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, resolveUIRangeConfig, resolveUIVector2Config, } from "../miscellaneous/miscellaneous.js";
2
+ import { assertValidNumber, assertValidPositiveNumber } from "../../core/miscellaneous/asserts.js";
3
+ import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, particleRandom, particleRandomStream, resolveUIRangeConfig, resolveUIVector2Config, } from "../miscellaneous/miscellaneous.js";
4
4
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
5
5
  /**
6
6
  * Applies gravity attraction toward a point.
@@ -27,8 +27,8 @@ export class UIBehaviorPointGravity extends UIBehaviorModule {
27
27
  assertValidNumber(this.exponentInternal.min, "UIBehaviorPointGravity.constructor.exponent.min");
28
28
  assertValidNumber(this.exponentInternal.max, "UIBehaviorPointGravity.constructor.exponent.max");
29
29
  this.thresholdInternal = resolveUIRangeConfig(threshold);
30
- assertValidNumber(this.thresholdInternal.min, "UIBehaviorPointGravity.constructor.threshold.min");
31
- assertValidNumber(this.thresholdInternal.max, "UIBehaviorPointGravity.constructor.threshold.max");
30
+ assertValidPositiveNumber(this.thresholdInternal.min, "UIBehaviorPointGravity.constructor.threshold.min");
31
+ assertValidPositiveNumber(this.thresholdInternal.max, "UIBehaviorPointGravity.constructor.threshold.max");
32
32
  }
33
33
  /** Gravity center position */
34
34
  get center() {
@@ -67,26 +67,29 @@ export class UIBehaviorPointGravity extends UIBehaviorModule {
67
67
  /** Minimum distance range */
68
68
  set threshold(value) {
69
69
  this.thresholdInternal = resolveUIRangeConfig(value);
70
- assertValidNumber(this.thresholdInternal.min, "UIBehaviorPointGravity.threshold.min");
71
- assertValidNumber(this.thresholdInternal.max, "UIBehaviorPointGravity.threshold.max");
70
+ assertValidPositiveNumber(this.thresholdInternal.min, "UIBehaviorPointGravity.threshold.min");
71
+ assertValidPositiveNumber(this.thresholdInternal.max, "UIBehaviorPointGravity.threshold.max");
72
72
  }
73
- update(properties, instanceCount, deltaTime) {
73
+ update(properties, instanceCount, deltaTime, randomSalt) {
74
74
  const { builtin } = properties;
75
75
  const { array, itemSize } = builtin;
76
+ const thresholdStream = particleRandomStream(randomSalt, 0);
77
+ const strengthStream = particleRandomStream(randomSalt, 1);
78
+ const exponentStream = particleRandomStream(randomSalt, 2);
76
79
  for (let i = 0; i < instanceCount; i++) {
77
80
  const itemOffset = i * itemSize;
78
81
  const dx = this.centerInternal.x - array[itemOffset + BUILTIN_OFFSET_POSITION_X];
79
82
  const dy = this.centerInternal.y - array[itemOffset + BUILTIN_OFFSET_POSITION_Y];
80
- const thresholdT = array[itemOffset + BUILTIN_OFFSET_RANDOM_A];
83
+ const thresholdT = particleRandom(array, itemOffset, thresholdStream);
81
84
  const threshold = MathUtils.lerp(this.threshold.min, this.threshold.max, thresholdT);
82
85
  const thresholdSquared = threshold * threshold;
83
86
  const distanceSquared = dx * dx + dy * dy;
84
87
  if (distanceSquared < thresholdSquared) {
85
88
  continue;
86
89
  }
87
- const strengthT = array[itemOffset + BUILTIN_OFFSET_RANDOM_B];
90
+ const strengthT = particleRandom(array, itemOffset, strengthStream);
88
91
  const strength = MathUtils.lerp(this.strengthInternal.min, this.strengthInternal.max, strengthT);
89
- const exponentT = array[itemOffset + BUILTIN_OFFSET_RANDOM_C];
92
+ const exponentT = particleRandom(array, itemOffset, exponentStream);
90
93
  const exponent = MathUtils.lerp(this.exponentInternal.min, this.exponentInternal.max, exponentT);
91
94
  const distance = Math.sqrt(distanceSquared);
92
95
  const forceMagnitude = strength / Math.pow(distance, exponent);
@@ -44,5 +44,5 @@ export declare class UIBehaviorScaleOscillation extends UIBehaviorModule<{
44
44
  set aspect(value: UIAspectConfig);
45
45
  update(properties: {
46
46
  builtin: InstancedBufferAttribute;
47
- }, instanceCount: number): void;
47
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
48
48
  }
@@ -1,6 +1,6 @@
1
1
  import { MathUtils } from "three";
2
2
  import { assertValidNonNegativeNumber, assertValidPositiveNumber, } from "../../core/miscellaneous/asserts.js";
3
- import { BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_RANDOM_E, BUILTIN_OFFSET_RANDOM_F, BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y, resolveAspect, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
3
+ import { BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y, particleRandom, particleRandomStream, resolveAspect, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
4
4
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
5
5
  /**
6
6
  * Oscillates particle scale along one axis, like a paper piece turning its edge to the viewer.
@@ -61,14 +61,16 @@ export class UIBehaviorScaleOscillation extends UIBehaviorModule {
61
61
  this.aspectInternal = resolveAspect(value);
62
62
  assertValidPositiveNumber(this.aspectInternal, "UIBehaviorScaleOscillation.aspect");
63
63
  }
64
- update(properties, instanceCount) {
64
+ update(properties, instanceCount, deltaTime, randomSalt) {
65
65
  const { builtin } = properties;
66
66
  const { array, itemSize } = builtin;
67
+ const frequencyStream = particleRandomStream(randomSalt, 0);
68
+ const phaseStream = particleRandomStream(randomSalt, 1);
67
69
  for (let i = 0; i < instanceCount; i++) {
68
70
  const itemOffset = i * itemSize;
69
- const frequencyT = array[itemOffset + BUILTIN_OFFSET_RANDOM_E];
71
+ const frequencyT = particleRandom(array, itemOffset, frequencyStream);
70
72
  const frequency = MathUtils.lerp(this.frequencyInternal.min, this.frequencyInternal.max, frequencyT);
71
- const phase = array[itemOffset + BUILTIN_OFFSET_RANDOM_F] * Math.PI * 2;
73
+ const phase = particleRandom(array, itemOffset, phaseStream) * Math.PI * 2;
72
74
  const angle = array[itemOffset + BUILTIN_OFFSET_AGE] * frequency * Math.PI * 2 + phase;
73
75
  const factor = 1 - this.depthInternal * (1 - Math.cos(angle));
74
76
  if (this.axisInternal === "x") {
@@ -25,5 +25,5 @@ export declare class UIBehaviorScaleOverLife extends UIBehaviorModule<{
25
25
  set aspect(value: UIAspectConfig);
26
26
  update(properties: {
27
27
  builtin: InstancedBufferAttribute;
28
- }, instanceCount: number): void;
28
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
29
29
  }
@@ -1,6 +1,6 @@
1
1
  import { MathUtils } from "three";
2
2
  import { assertValidNonNegativeNumber, assertValidPositiveNumber, } from "../../core/miscellaneous/asserts.js";
3
- import { BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME, BUILTIN_OFFSET_RANDOM_D, BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y, resolveAspect, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
3
+ import { BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME, BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y, particleRandom, particleRandomStream, resolveAspect, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
4
4
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
5
5
  /**
6
6
  * Animates particle scale over lifetime.
@@ -37,15 +37,16 @@ export class UIBehaviorScaleOverLife extends UIBehaviorModule {
37
37
  this.aspectInternal = resolveAspect(value);
38
38
  assertValidPositiveNumber(this.aspectInternal, "UIBehaviorScaleOverLife.aspect");
39
39
  }
40
- update(properties, instanceCount) {
40
+ update(properties, instanceCount, deltaTime, randomSalt) {
41
41
  const { builtin } = properties;
42
42
  const { array, itemSize } = builtin;
43
+ const scaleStream = particleRandomStream(randomSalt, 0);
43
44
  for (let i = 0; i < instanceCount; i++) {
44
45
  const itemOffset = i * itemSize;
45
46
  const lifeT = Math.min(array[itemOffset + BUILTIN_OFFSET_AGE] / array[itemOffset + BUILTIN_OFFSET_LIFETIME], 1);
46
47
  const segment = (this.scales.length - 1) * lifeT;
47
48
  const index = Math.floor(segment);
48
- const scaleT = array[itemOffset + BUILTIN_OFFSET_RANDOM_D];
49
+ const scaleT = particleRandom(array, itemOffset, scaleStream);
49
50
  const localT = segment - index;
50
51
  const scaleRange0 = this.scales[index];
51
52
  const scaleRange1 = this.scales[index + 1];
@@ -16,12 +16,12 @@ export declare class UIBehaviorTorqueDamping extends UIBehaviorModule<{
16
16
  /**
17
17
  * @param damping - Damping coefficient range (0-1). Accepts number, tuple, or range object
18
18
  */
19
- constructor(damping: number);
19
+ constructor(damping: UIRangeConfig);
20
20
  /** Damping coefficient range (0-1) */
21
21
  get damping(): UIRange;
22
22
  /** Damping coefficient range (0-1) */
23
23
  set damping(value: UIRangeConfig);
24
24
  update(properties: {
25
25
  builtin: InstancedBufferAttribute;
26
- }, instanceCount: number, deltaTime: number): void;
26
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
27
27
  }
@@ -1,6 +1,5 @@
1
1
  import { MathUtils } from "three";
2
- import { assertValidNonNegativeNumber } from "../../core/miscellaneous/asserts.js";
3
- import { BUILTIN_OFFSET_RANDOM_E, BUILTIN_OFFSET_TORQUE, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
2
+ import { assertValidUnitNumber, BUILTIN_OFFSET_TORQUE, particleRandom, particleRandomStream, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
4
3
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
5
4
  /**
6
5
  * Reduces particle angular velocity over time.
@@ -15,8 +14,8 @@ export class UIBehaviorTorqueDamping extends UIBehaviorModule {
15
14
  super();
16
15
  this.requiredProperties = { builtin: "Matrix4" };
17
16
  this.dampingInternal = resolveUIRangeConfig(damping);
18
- assertValidNonNegativeNumber(this.dampingInternal.min, `UIBehaviorTorqueDamping.constructor.damping.min`);
19
- assertValidNonNegativeNumber(this.dampingInternal.max, `UIBehaviorTorqueDamping.constructor.damping.max`);
17
+ assertValidUnitNumber(this.dampingInternal.min, `UIBehaviorTorqueDamping.constructor.damping.min`);
18
+ assertValidUnitNumber(this.dampingInternal.max, `UIBehaviorTorqueDamping.constructor.damping.max`);
20
19
  }
21
20
  /** Damping coefficient range (0-1) */
22
21
  get damping() {
@@ -25,15 +24,16 @@ export class UIBehaviorTorqueDamping extends UIBehaviorModule {
25
24
  /** Damping coefficient range (0-1) */
26
25
  set damping(value) {
27
26
  this.dampingInternal = resolveUIRangeConfig(value);
28
- assertValidNonNegativeNumber(this.dampingInternal.min, `UIBehaviorTorqueDamping.damping.min`);
29
- assertValidNonNegativeNumber(this.dampingInternal.max, `UIBehaviorTorqueDamping.damping.max`);
27
+ assertValidUnitNumber(this.dampingInternal.min, `UIBehaviorTorqueDamping.damping.min`);
28
+ assertValidUnitNumber(this.dampingInternal.max, `UIBehaviorTorqueDamping.damping.max`);
30
29
  }
31
- update(properties, instanceCount, deltaTime) {
30
+ update(properties, instanceCount, deltaTime, randomSalt) {
32
31
  const { builtin } = properties;
33
32
  const { array, itemSize } = builtin;
33
+ const dampingStream = particleRandomStream(randomSalt, 0);
34
34
  for (let i = 0; i < instanceCount; i++) {
35
35
  const itemOffset = i * itemSize;
36
- const dampingT = array[itemOffset + BUILTIN_OFFSET_RANDOM_E];
36
+ const dampingT = particleRandom(array, itemOffset, dampingStream);
37
37
  const dampingFactor = Math.pow(1 - MathUtils.lerp(this.dampingInternal.min, this.dampingInternal.max, dampingT), deltaTime);
38
38
  array[itemOffset + BUILTIN_OFFSET_TORQUE] *= dampingFactor;
39
39
  }
@@ -4,7 +4,8 @@ import { UIBehaviorModule } from "./UIBehaviorModule.js";
4
4
  /**
5
5
  * Applies noise-based angular acceleration to particles.
6
6
  *
7
- * Uses 2D noise based on particle position. Higher scale means finer noise detail.
7
+ * The noise is sampled at the particle position times scale, so 1 / scale is the size of a noise
8
+ * detail in layer units; around 0.005 gives a smooth change over a few hundred units.
8
9
  */
9
10
  export declare class UIBehaviorTorqueNoise extends UIBehaviorModule<{
10
11
  builtin: "Matrix4";
@@ -18,7 +19,7 @@ export declare class UIBehaviorTorqueNoise extends UIBehaviorModule<{
18
19
  * @param scale - Noise frequency range. Accepts number, tuple, or range object
19
20
  * @param strength - Force multiplier range. Accepts number, tuple, or range object
20
21
  */
21
- constructor(scale: number, strength: number);
22
+ constructor(scale: UIRangeConfig, strength: UIRangeConfig);
22
23
  /** Noise frequency range */
23
24
  get scale(): UIRange;
24
25
  /** Force multiplier range */
@@ -29,5 +30,5 @@ export declare class UIBehaviorTorqueNoise extends UIBehaviorModule<{
29
30
  set strength(value: UIRangeConfig);
30
31
  update(properties: {
31
32
  builtin: InstancedBufferAttribute;
32
- }, instanceCount: number, deltaTime: number): void;
33
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
33
34
  }
@@ -1,11 +1,12 @@
1
1
  import { MathUtils } from "three";
2
2
  import { assertValidNonNegativeNumber, assertValidPositiveNumber, } from "../../core/miscellaneous/asserts.js";
3
- import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_RANDOM_A, BUILTIN_OFFSET_RANDOM_F, BUILTIN_OFFSET_TORQUE, generateNoise2D, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
3
+ import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_TORQUE, generateNoise2D, particleRandom, particleRandomStream, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
4
4
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
5
5
  /**
6
6
  * Applies noise-based angular acceleration to particles.
7
7
  *
8
- * Uses 2D noise based on particle position. Higher scale means finer noise detail.
8
+ * The noise is sampled at the particle position times scale, so 1 / scale is the size of a noise
9
+ * detail in layer units; around 0.005 gives a smooth change over a few hundred units.
9
10
  */
10
11
  export class UIBehaviorTorqueNoise extends UIBehaviorModule {
11
12
  /**
@@ -42,15 +43,17 @@ export class UIBehaviorTorqueNoise extends UIBehaviorModule {
42
43
  assertValidNonNegativeNumber(this.strengthInternal.min, `UIBehaviorTorqueNoise.strength.min`);
43
44
  assertValidNonNegativeNumber(this.strengthInternal.max, `UIBehaviorTorqueNoise.strength.max`);
44
45
  }
45
- update(properties, instanceCount, deltaTime) {
46
+ update(properties, instanceCount, deltaTime, randomSalt) {
46
47
  const { builtin } = properties;
47
48
  const { array, itemSize } = builtin;
49
+ const scaleStream = particleRandomStream(randomSalt, 0);
50
+ const strengthStream = particleRandomStream(randomSalt, 1);
48
51
  for (let i = 0; i < instanceCount; i++) {
49
52
  const itemOffset = i * itemSize;
50
- const scaleT = array[itemOffset + BUILTIN_OFFSET_RANDOM_F];
53
+ const scaleT = particleRandom(array, itemOffset, scaleStream);
51
54
  const scale = MathUtils.lerp(this.scaleInternal.min, this.scaleInternal.max, scaleT);
52
55
  const noise = generateNoise2D(array[itemOffset + BUILTIN_OFFSET_POSITION_X] * scale, array[itemOffset + BUILTIN_OFFSET_POSITION_Y] * scale);
53
- const strengthT = array[itemOffset + BUILTIN_OFFSET_RANDOM_A];
56
+ const strengthT = particleRandom(array, itemOffset, strengthStream);
54
57
  const strength = MathUtils.lerp(this.strengthInternal.min, this.strengthInternal.max, strengthT);
55
58
  array[itemOffset + BUILTIN_OFFSET_TORQUE] += noise * strength * deltaTime;
56
59
  }
@@ -23,5 +23,5 @@ export declare class UIBehaviorVelocityDamping extends UIBehaviorModule<{
23
23
  set damping(value: UIRangeConfig);
24
24
  update(properties: {
25
25
  builtin: InstancedBufferAttribute;
26
- }, instanceCount: number, deltaTime: number): void;
26
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
27
27
  }
@@ -1,6 +1,5 @@
1
1
  import { MathUtils } from "three";
2
- import { assertValidNonNegativeNumber } from "../../core/miscellaneous/asserts.js";
3
- import { BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
2
+ import { assertValidUnitNumber, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, particleRandom, particleRandomStream, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
4
3
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
5
4
  /**
6
5
  * Reduces particle velocity over time.
@@ -15,8 +14,8 @@ export class UIBehaviorVelocityDamping extends UIBehaviorModule {
15
14
  super();
16
15
  this.requiredProperties = { builtin: "Matrix4" };
17
16
  this.dampingInternal = resolveUIRangeConfig(damping);
18
- assertValidNonNegativeNumber(this.dampingInternal.min, `UIBehaviorVelocityDamping.constructor.damping.min`);
19
- assertValidNonNegativeNumber(this.dampingInternal.max, `UIBehaviorVelocityDamping.constructor.damping.max`);
17
+ assertValidUnitNumber(this.dampingInternal.min, `UIBehaviorVelocityDamping.constructor.damping.min`);
18
+ assertValidUnitNumber(this.dampingInternal.max, `UIBehaviorVelocityDamping.constructor.damping.max`);
20
19
  }
21
20
  /** Damping coefficient range (0-1) */
22
21
  get damping() {
@@ -25,15 +24,16 @@ export class UIBehaviorVelocityDamping extends UIBehaviorModule {
25
24
  /** Damping coefficient range (0-1) */
26
25
  set damping(value) {
27
26
  this.dampingInternal = resolveUIRangeConfig(value);
28
- assertValidNonNegativeNumber(this.dampingInternal.min, `UIBehaviorVelocityDamping.damping.min`);
29
- assertValidNonNegativeNumber(this.dampingInternal.max, `UIBehaviorVelocityDamping.damping.max`);
27
+ assertValidUnitNumber(this.dampingInternal.min, `UIBehaviorVelocityDamping.damping.min`);
28
+ assertValidUnitNumber(this.dampingInternal.max, `UIBehaviorVelocityDamping.damping.max`);
30
29
  }
31
- update(properties, instanceCount, deltaTime) {
30
+ update(properties, instanceCount, deltaTime, randomSalt) {
32
31
  const { builtin } = properties;
33
32
  const { array, itemSize } = builtin;
33
+ const dampingStream = particleRandomStream(randomSalt, 0);
34
34
  for (let i = 0; i < instanceCount; i++) {
35
35
  const itemOffset = i * itemSize;
36
- const dampingT = array[itemOffset + BUILTIN_OFFSET_RANDOM_B];
36
+ const dampingT = particleRandom(array, itemOffset, dampingStream);
37
37
  const dampingFactor = Math.pow(1 - MathUtils.lerp(this.dampingInternal.min, this.dampingInternal.max, dampingT), deltaTime);
38
38
  array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] *= dampingFactor;
39
39
  array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] *= dampingFactor;
@@ -2,9 +2,11 @@ import type { InstancedBufferAttribute } from "three";
2
2
  import { type UIRange, type UIRangeConfig } from "../miscellaneous/miscellaneous.js";
3
3
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
4
4
  /**
5
- * Applies noise-based acceleration to particles.
5
+ * Applies noise-based acceleration to particles: a still flow field that particles drift through.
6
6
  *
7
- * Uses 2D noise based on particle position. Higher scale means finer noise detail.
7
+ * The noise is sampled at the particle position times scale, so 1 / scale is the size of a noise
8
+ * detail in layer units. A detail much smaller than the distance a particle moves in a frame
9
+ * turns the drift into jitter.
8
10
  */
9
11
  export declare class UIBehaviorVelocityNoise extends UIBehaviorModule<{
10
12
  builtin: "Matrix4";
@@ -15,10 +17,10 @@ export declare class UIBehaviorVelocityNoise extends UIBehaviorModule<{
15
17
  private scaleInternal;
16
18
  private strengthInternal;
17
19
  /**
18
- * @param scale - Noise frequency range. Accepts number, tuple, or range object
20
+ * @param scale - Noise frequency range in 1 / layer units. Accepts number, tuple, or range object
19
21
  * @param strength - Force multiplier range. Accepts number, tuple, or range object
20
22
  */
21
- constructor(scale?: number, strength?: number);
23
+ constructor(scale?: UIRangeConfig, strength?: UIRangeConfig);
22
24
  /** Noise frequency range */
23
25
  get scale(): UIRange;
24
26
  /** Force multiplier range */
@@ -29,5 +31,5 @@ export declare class UIBehaviorVelocityNoise extends UIBehaviorModule<{
29
31
  set strength(value: UIRangeConfig);
30
32
  update(properties: {
31
33
  builtin: InstancedBufferAttribute;
32
- }, instanceCount: number, deltaTime: number): void;
34
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
33
35
  }
@@ -1,18 +1,20 @@
1
1
  import { MathUtils } from "three";
2
2
  import { assertValidNonNegativeNumber, assertValidPositiveNumber, } from "../../core/miscellaneous/asserts.js";
3
- import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_RANDOM_C, BUILTIN_OFFSET_RANDOM_D, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, generateNoise2D, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
3
+ import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, generateNoise2D, particleRandom, particleRandomStream, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
4
4
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
5
5
  /**
6
- * Applies noise-based acceleration to particles.
6
+ * Applies noise-based acceleration to particles: a still flow field that particles drift through.
7
7
  *
8
- * Uses 2D noise based on particle position. Higher scale means finer noise detail.
8
+ * The noise is sampled at the particle position times scale, so 1 / scale is the size of a noise
9
+ * detail in layer units. A detail much smaller than the distance a particle moves in a frame
10
+ * turns the drift into jitter.
9
11
  */
10
12
  export class UIBehaviorVelocityNoise extends UIBehaviorModule {
11
13
  /**
12
- * @param scale - Noise frequency range. Accepts number, tuple, or range object
14
+ * @param scale - Noise frequency range in 1 / layer units. Accepts number, tuple, or range object
13
15
  * @param strength - Force multiplier range. Accepts number, tuple, or range object
14
16
  */
15
- constructor(scale = 100, strength = 500) {
17
+ constructor(scale = 0.005, strength = 500) {
16
18
  super();
17
19
  this.requiredProperties = { builtin: "Matrix4" };
18
20
  this.scaleInternal = resolveUIRangeConfig(scale);
@@ -42,18 +44,20 @@ export class UIBehaviorVelocityNoise extends UIBehaviorModule {
42
44
  assertValidNonNegativeNumber(this.strengthInternal.min, `UIBehaviorVelocityNoise.strength.min`);
43
45
  assertValidNonNegativeNumber(this.strengthInternal.max, `UIBehaviorVelocityNoise.strength.max`);
44
46
  }
45
- update(properties, instanceCount, deltaTime) {
47
+ update(properties, instanceCount, deltaTime, randomSalt) {
46
48
  const { builtin } = properties;
47
49
  const { array, itemSize } = builtin;
50
+ const scaleStream = particleRandomStream(randomSalt, 0);
51
+ const strengthStream = particleRandomStream(randomSalt, 1);
48
52
  for (let i = 0; i < instanceCount; i++) {
49
53
  const itemOffset = i * itemSize;
50
54
  const x = array[itemOffset + BUILTIN_OFFSET_POSITION_X];
51
55
  const y = array[itemOffset + BUILTIN_OFFSET_POSITION_Y];
52
- const scaleT = array[itemOffset + BUILTIN_OFFSET_RANDOM_C];
56
+ const scaleT = particleRandom(array, itemOffset, scaleStream);
53
57
  const scale = MathUtils.lerp(this.scaleInternal.min, this.scaleInternal.max, scaleT);
54
58
  const noiseX = generateNoise2D(x * scale, y * scale);
55
59
  const noiseY = generateNoise2D((x + 100) * scale, (y + 100) * scale);
56
- const strengthT = array[itemOffset + BUILTIN_OFFSET_RANDOM_D];
60
+ const strengthT = particleRandom(array, itemOffset, strengthStream);
57
61
  const strength = MathUtils.lerp(this.strengthInternal.min, this.strengthInternal.max, strengthT);
58
62
  array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] += noiseX * strength * deltaTime;
59
63
  array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] += noiseY * strength * deltaTime;
@@ -1,13 +1,20 @@
1
- import { UIMode } from "../../core/index.js";
2
1
  import type { UIAnchorOptions } from "../../core/elements/UIAnchor/UIAnchor.Internal.js";
2
+ import { UIMode } from "../../core/index.js";
3
3
  /** Configuration options for UIEmitter */
4
4
  export interface UIEmitterOptions extends UIAnchorOptions {
5
5
  /** Whether the particles are drawn */
6
6
  mode: UIEmitterMode;
7
7
  /** Number of particles to allocate for up front; a hint, not a limit */
8
8
  expectedCapacity: number;
9
- /** Number of particles the buffers grow by */
9
+ /** Capacity is kept a multiple of this; the buffers double when they grow */
10
10
  capacityStep: number;
11
+ /** Longest frame step in seconds; longer frames, such as after a hidden tab, are clamped */
12
+ maxDeltaTime: number;
13
+ /**
14
+ * Seed of the random values, a non-negative integer. Emitters with one seed and one sequence
15
+ * of spawns produce the same particles. Random by default.
16
+ */
17
+ seed: number;
11
18
  /** Whether to call destroy() on all modules when the emitter is destroyed */
12
19
  automaticallyDestroyModules: boolean;
13
20
  }
@@ -19,4 +26,10 @@ export type UIEmitterMode = UIMode.HIDDEN | UIMode.VISIBLE;
19
26
  export declare const EMITTER_DEFAULT_MODE: UIEmitterMode;
20
27
  export declare const EMITTER_DEFAULT_EXPECTED_CAPACITY = 32;
21
28
  export declare const EMITTER_DEFAULT_CAPACITY_STEP = 32;
29
+ export declare const EMITTER_DEFAULT_MAX_DELTA_TIME = 0.1;
30
+ export declare const EMITTER_DEFAULT_LIFETIME = 1;
22
31
  export declare const EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES = true;
32
+ /** Salts the emitter hands out: one for the builtin values the shaders read, one per module */
33
+ export declare const EMITTER_SHADER_SALT = 0;
34
+ export declare const EMITTER_SPAWN_SALT_BASE = 256;
35
+ export declare const EMITTER_BEHAVIOR_SALT_BASE = 512;
@@ -5,4 +5,10 @@ export function ignoreInput() {
5
5
  export const EMITTER_DEFAULT_MODE = UIMode.VISIBLE;
6
6
  export const EMITTER_DEFAULT_EXPECTED_CAPACITY = 32;
7
7
  export const EMITTER_DEFAULT_CAPACITY_STEP = 32;
8
+ export const EMITTER_DEFAULT_MAX_DELTA_TIME = 0.1;
9
+ export const EMITTER_DEFAULT_LIFETIME = 1;
8
10
  export const EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES = true;
11
+ /** Salts the emitter hands out: one for the builtin values the shaders read, one per module */
12
+ export const EMITTER_SHADER_SALT = 0;
13
+ export const EMITTER_SPAWN_SALT_BASE = 0x100;
14
+ export const EMITTER_BEHAVIOR_SALT_BASE = 0x200;
@@ -1,5 +1,5 @@
1
- import type { UILayer } from "../../core/index.js";
2
1
  import { UIAnchor } from "../../core/elements/UIAnchor/UIAnchor.js";
2
+ import type { UILayer } from "../../core/index.js";
3
3
  import type { UIBehaviorModule } from "../behaviorModules/UIBehaviorModule.js";
4
4
  import type { UIRenderingModule } from "../renderingModules/UIRenderingModule.js";
5
5
  import type { UISpawnModule } from "../spawnModules/UISpawnModule.js";
@@ -22,6 +22,10 @@ export declare class UIEmitter extends UIAnchor {
22
22
  private emissionDuration;
23
23
  private emissionElapsed;
24
24
  private modeInternal;
25
+ private maxDeltaTimeInternal;
26
+ private seedInternal;
27
+ /** Particles spawned since the seed was set; picks the seed of the next particle */
28
+ private spawnedCount;
25
29
  /**
26
30
  * @param layer - Layer containing this emitter
27
31
  * @param spawnSequence - Modules that initialize new particles
@@ -30,6 +34,10 @@ export declare class UIEmitter extends UIAnchor {
30
34
  * @param options - Configuration options
31
35
  */
32
36
  constructor(layer: UILayer, spawnSequence: UISpawnModule[], behaviorSequence: readonly UIBehaviorModule[], renderingSequence: readonly UIRenderingModule[], options?: Partial<UIEmitterOptions>);
37
+ /** Seed of the random values */
38
+ get seed(): number;
39
+ /** Longest frame step in seconds; longer frames are clamped */
40
+ get maxDeltaTime(): number;
33
41
  /** Visibility mode */
34
42
  get mode(): UIEmitterMode;
35
43
  /**
@@ -39,15 +47,23 @@ export declare class UIEmitter extends UIAnchor {
39
47
  get zIndex(): number;
40
48
  /** Visibility mode */
41
49
  set mode(value: UIEmitterMode);
50
+ /** Longest frame step in seconds; longer frames are clamped */
51
+ set maxDeltaTime(value: number);
52
+ /**
53
+ * Sets the seed and restarts its sequence: the next particles repeat those spawned after the
54
+ * same seed was set before
55
+ */
56
+ set seed(value: number);
42
57
  /**
43
58
  * Rendering order among the elements of the layer. Higher values on top; elements with equal
44
59
  * values keep the order of creation, a later one on top.
45
60
  */
46
61
  set zIndex(value: number);
47
62
  /**
48
- * Spawns a specific number of particles immediately.
63
+ * Spawns a specific number of particles immediately. Before the spawn modules run, every
64
+ * property of a new particle is 0, except scale 1 and lifetime 1 second.
49
65
  *
50
- * @param count - Number of particles to create
66
+ * @param count - Number of particles to create, a non-negative integer
51
67
  */
52
68
  burst(count: number): void;
53
69
  /** Removes all active particles */