laymur 0.25.2 → 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 (186) hide show
  1. package/README.md +114 -34
  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/UIAnchor/UIAnchor.d.ts +2 -2
  7. package/dist/core/elements/UIAnchor/UIAnchor.js +3 -2
  8. package/dist/core/elements/UIAnimatedImage/UIAnimatedImage.d.ts +2 -2
  9. package/dist/core/elements/UIAnimatedImage/UIAnimatedImage.js +24 -12
  10. package/dist/core/elements/UIDummy/UIDummy.Internal.d.ts +13 -0
  11. package/dist/core/elements/UIDummy/UIDummy.d.ts +74 -5
  12. package/dist/core/elements/UIDummy/UIDummy.js +222 -29
  13. package/dist/core/elements/UIElement/UIElement.Internal.d.ts +1 -1
  14. package/dist/core/elements/UIElement/UIElement.d.ts +37 -1
  15. package/dist/core/elements/UIElement/UIElement.js +84 -6
  16. package/dist/core/elements/UIGraphics/UIGraphics.Internal.d.ts +1 -1
  17. package/dist/core/elements/UIGraphics/UIGraphics.d.ts +1 -1
  18. package/dist/core/elements/UIGraphics/UIGraphics.js +4 -4
  19. package/dist/core/elements/UIImage/UIImage.d.ts +2 -2
  20. package/dist/core/elements/UIImage/UIImage.js +10 -8
  21. package/dist/core/elements/UINineSlice/UINineSlice.d.ts +4 -4
  22. package/dist/core/elements/UINineSlice/UINineSlice.js +11 -9
  23. package/dist/core/elements/UIProgress/UIProgress.d.ts +2 -2
  24. package/dist/core/elements/UIProgress/UIProgress.js +17 -15
  25. package/dist/core/elements/UIScene/UIScene.Internal.d.ts +1 -1
  26. package/dist/core/elements/UIScene/UIScene.d.ts +3 -2
  27. package/dist/core/elements/UIScene/UIScene.js +21 -14
  28. package/dist/core/elements/UIText/UIText.Measuring.d.ts +1 -1
  29. package/dist/core/elements/UIText/UIText.d.ts +3 -3
  30. package/dist/core/elements/UIText/UIText.js +8 -8
  31. package/dist/core/index.d.ts +60 -11
  32. package/dist/core/index.js +22 -7
  33. package/dist/core/layers/UILayer/UILayer.d.ts +45 -5
  34. package/dist/core/layers/UILayer/UILayer.js +103 -10
  35. package/dist/core/layers/UIViewportLayer/UIViewportLayer.Internal.d.ts +27 -0
  36. package/dist/core/layers/{UIFullscreenLayer/UIFullscreenLayer.Internal.js → UIViewportLayer/UIViewportLayer.Internal.js} +1 -1
  37. package/dist/core/layers/UIViewportLayer/UIViewportLayer.d.ts +98 -0
  38. package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +251 -0
  39. package/dist/core/miscellaneous/UIAffineMatrix3.d.ts +13 -0
  40. package/dist/core/miscellaneous/UIAffineMatrix3.js +13 -0
  41. package/dist/core/miscellaneous/area/UIArea.d.ts +10 -1
  42. package/dist/core/miscellaneous/area/UIArea.js +4 -1
  43. package/dist/core/miscellaneous/area/UIAreaCircle.d.ts +1 -0
  44. package/dist/core/miscellaneous/area/UIAreaCircle.js +0 -1
  45. package/dist/core/miscellaneous/area/UIAreaPolygon.d.ts +1 -0
  46. package/dist/core/miscellaneous/area/UIAreaPolygon.js +0 -1
  47. package/dist/core/miscellaneous/area/UIAreaRectangle.d.ts +1 -0
  48. package/dist/core/miscellaneous/area/UIAreaRectangle.js +0 -1
  49. package/dist/core/miscellaneous/area/UIAreaRoundedRectangle.d.ts +1 -0
  50. package/dist/core/miscellaneous/area/UIAreaRoundedRectangle.js +0 -1
  51. package/dist/core/miscellaneous/asserts.d.ts +23 -0
  52. package/dist/core/miscellaneous/asserts.js +44 -0
  53. package/dist/core/miscellaneous/canvas.js +7 -2
  54. package/dist/core/miscellaneous/color/UIColor.js +5 -2
  55. package/dist/core/miscellaneous/computeTransform.d.ts +12 -0
  56. package/dist/core/miscellaneous/computeTransform.js +20 -0
  57. package/dist/core/miscellaneous/context-monitor/UIContextMonitor.d.ts +1 -0
  58. package/dist/core/miscellaneous/context-monitor/UIContextMonitor.js +60 -0
  59. package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.d.ts +17 -3
  60. package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.js +88 -26
  61. package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Layout.d.ts +9 -0
  62. package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Layout.js +29 -6
  63. package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.js +51 -11
  64. package/dist/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.d.ts +2 -0
  65. package/dist/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.js +47 -6
  66. package/dist/core/miscellaneous/generic-plane/shared.d.ts +15 -3
  67. package/dist/core/miscellaneous/generic-plane/shared.js +38 -7
  68. package/dist/core/miscellaneous/generic-plane/varyingPacking.d.ts +46 -0
  69. package/dist/core/miscellaneous/generic-plane/varyingPacking.js +170 -0
  70. package/dist/core/miscellaneous/mask/UIMask.Internal.d.ts +61 -0
  71. package/dist/core/miscellaneous/mask/UIMask.Internal.js +56 -0
  72. package/dist/core/miscellaneous/mask/UIMask.d.ts +84 -0
  73. package/dist/core/miscellaneous/mask/UIMask.js +265 -0
  74. package/dist/core/miscellaneous/mask/UIMaskMaterialPatch.d.ts +50 -0
  75. package/dist/core/miscellaneous/mask/UIMaskMaterialPatch.js +233 -0
  76. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunction.d.ts +10 -1
  77. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunction.js +7 -1
  78. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +2 -0
  79. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.js +0 -1
  80. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.d.ts +2 -0
  81. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.js +0 -1
  82. package/dist/core/miscellaneous/micro/UIMicro.Internal.d.ts +3 -0
  83. package/dist/core/miscellaneous/micro/UIMicro.Internal.js +1 -0
  84. package/dist/core/miscellaneous/micro/UIMicro.d.ts +18 -1
  85. package/dist/core/miscellaneous/micro/UIMicro.js +23 -2
  86. package/dist/core/miscellaneous/resize-policy/UIResizePolicy.d.ts +19 -1
  87. package/dist/core/miscellaneous/resize-policy/UIResizePolicy.js +16 -3
  88. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCover.js +2 -2
  89. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCross.js +2 -2
  90. package/dist/core/miscellaneous/resize-policy/UIResizePolicyCrossInverted.js +2 -2
  91. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFit.js +2 -2
  92. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFixedHeight.js +2 -2
  93. package/dist/core/miscellaneous/resize-policy/UIResizePolicyFixedWidth.js +2 -2
  94. package/dist/core/miscellaneous/text-style/UITextStyle.js +2 -2
  95. package/dist/core/miscellaneous/texture/UITextureView.d.ts +6 -2
  96. package/dist/core/miscellaneous/texture/UITextureView.js +13 -9
  97. package/dist/core/miscellaneous/viewport/UIElementViewport.d.ts +31 -0
  98. package/dist/core/miscellaneous/viewport/UIElementViewport.js +54 -0
  99. package/dist/core/miscellaneous/viewport/UIViewport.d.ts +37 -0
  100. package/dist/core/miscellaneous/viewport/UIViewport.js +31 -0
  101. package/dist/core/miscellaneous/viewport/UIWindowViewport.d.ts +13 -0
  102. package/dist/core/miscellaneous/viewport/UIWindowViewport.js +25 -0
  103. package/dist/core/miscellaneous/webglCapabilities.js +61 -55
  104. package/dist/core/shaders/UIMask.d.ts +15 -0
  105. package/dist/core/shaders/UIMask.js +45 -0
  106. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +36 -5
  107. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +23 -2
  108. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +153 -15
  109. package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.Internal.d.ts +3 -1
  110. package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.d.ts +1 -0
  111. package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.js +3 -0
  112. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +2 -0
  113. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.d.ts +3 -0
  114. package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.js +36 -16
  115. package/dist/debug/UIAspectDebug.js +4 -0
  116. package/dist/debug/UIHeightDebug.js +4 -0
  117. package/dist/debug/UIHorizontalDistanceDebug.js +5 -0
  118. package/dist/debug/UIHorizontalInterpolationDebug.js +5 -0
  119. package/dist/debug/UILayerDebug.d.ts +7 -0
  120. package/dist/debug/UILayerDebug.js +21 -0
  121. package/dist/debug/UIVerticalDistanceDebug.js +5 -0
  122. package/dist/debug/UIVerticalInterpolationDebug.js +5 -0
  123. package/dist/debug/UIWidthDebug.js +4 -0
  124. package/dist/debug/index.d.ts +2 -0
  125. package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.d.ts +8 -1
  126. package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.js +0 -2
  127. package/dist/particles/behaviorModules/UIBehaviorModule.d.ts +12 -2
  128. package/dist/particles/behaviorModules/UIBehaviorModule.js +2 -1
  129. package/dist/particles/behaviorModules/UIBehaviorPointGravity.d.ts +8 -1
  130. package/dist/particles/behaviorModules/UIBehaviorPointGravity.js +13 -12
  131. package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.d.ts +7 -0
  132. package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.js +6 -6
  133. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +7 -0
  134. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +4 -5
  135. package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.d.ts +8 -1
  136. package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.js +8 -10
  137. package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.d.ts +10 -2
  138. package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.js +8 -7
  139. package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.d.ts +7 -0
  140. package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.js +8 -10
  141. package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.d.ts +13 -4
  142. package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.js +12 -10
  143. package/dist/particles/elements/UIEmitter.Internal.d.ts +21 -1
  144. package/dist/particles/elements/UIEmitter.Internal.js +6 -0
  145. package/dist/particles/elements/UIEmitter.d.ts +20 -11
  146. package/dist/particles/elements/UIEmitter.js +100 -54
  147. package/dist/particles/index.d.ts +7 -1
  148. package/dist/particles/index.js +4 -0
  149. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +19 -4
  150. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +117 -83
  151. package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +8 -0
  152. package/dist/particles/instancedParticle/UIInstancedParticle.js +41 -4
  153. package/dist/particles/miscellaneous/miscellaneous.d.ts +34 -0
  154. package/dist/particles/miscellaneous/miscellaneous.js +72 -0
  155. package/dist/particles/renderingModules/UIRenderingColorOverLife.d.ts +4 -0
  156. package/dist/particles/renderingModules/UIRenderingColorOverLife.js +2 -4
  157. package/dist/particles/renderingModules/UIRenderingColorOverVelocity.d.ts +4 -0
  158. package/dist/particles/renderingModules/UIRenderingColorOverVelocity.js +2 -5
  159. package/dist/particles/renderingModules/UIRenderingModule.d.ts +11 -1
  160. package/dist/particles/renderingModules/UIRenderingModule.js +4 -1
  161. package/dist/particles/renderingModules/UIRenderingTexture.d.ts +4 -0
  162. package/dist/particles/renderingModules/UIRenderingTexture.js +2 -1
  163. package/dist/particles/shaders/UIRenderingColorOverLife.d.ts +1 -2
  164. package/dist/particles/shaders/UIRenderingColorOverLife.js +5 -3
  165. package/dist/particles/shaders/UIRenderingColorOverVelocity.d.ts +1 -9
  166. package/dist/particles/shaders/UIRenderingColorOverVelocity.js +6 -13
  167. package/dist/particles/spawnModules/UISpawnModule.d.ts +16 -1
  168. package/dist/particles/spawnModules/UISpawnModule.js +3 -1
  169. package/dist/particles/spawnModules/UISpawnOffset.d.ts +7 -0
  170. package/dist/particles/spawnModules/UISpawnOffset.js +0 -2
  171. package/dist/particles/spawnModules/UISpawnRandomLifetime.d.ts +8 -1
  172. package/dist/particles/spawnModules/UISpawnRandomLifetime.js +5 -7
  173. package/dist/particles/spawnModules/UISpawnRandomRotation.d.ts +7 -0
  174. package/dist/particles/spawnModules/UISpawnRandomRotation.js +5 -5
  175. package/dist/particles/spawnModules/UISpawnRandomScale.d.ts +7 -0
  176. package/dist/particles/spawnModules/UISpawnRandomScale.js +4 -5
  177. package/dist/particles/spawnModules/UISpawnRandomTorque.d.ts +7 -0
  178. package/dist/particles/spawnModules/UISpawnRandomTorque.js +5 -5
  179. package/dist/particles/spawnModules/UISpawnRandomVelocity.d.ts +7 -0
  180. package/dist/particles/spawnModules/UISpawnRandomVelocity.js +6 -6
  181. package/dist/particles/spawnModules/UISpawnRectangle.d.ts +7 -0
  182. package/dist/particles/spawnModules/UISpawnRectangle.js +6 -6
  183. package/package.json +13 -4
  184. package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts +0 -21
  185. package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.d.ts +0 -63
  186. package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.js +0 -144
@@ -1,3 +1,4 @@
1
+ import type { InstancedBufferAttribute } from "three";
1
2
  import type { Vector2Like } from "../../core/miscellaneous/math.js";
2
3
  import type { UIVector2Config } from "../miscellaneous/miscellaneous.js";
3
4
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
@@ -9,13 +10,19 @@ import { UIBehaviorModule } from "./UIBehaviorModule.js";
9
10
  export declare class UIBehaviorDirectionalGravity extends UIBehaviorModule<{
10
11
  builtin: "Matrix4";
11
12
  }> {
13
+ readonly requiredProperties: {
14
+ readonly builtin: "Matrix4";
15
+ };
12
16
  private directionInternal;
13
17
  /**
14
18
  * @param direction - Acceleration vector in units/second^2
15
19
  */
16
- constructor(direction: Vector2Like);
20
+ constructor(direction: UIVector2Config);
17
21
  /** Acceleration vector in units/second^2 */
18
22
  get direction(): Vector2Like;
19
23
  /** Acceleration vector in units/second^2 */
20
24
  set direction(value: UIVector2Config);
25
+ update(properties: {
26
+ builtin: InstancedBufferAttribute;
27
+ }, instanceCount: number, deltaTime: number): void;
21
28
  }
@@ -12,7 +12,6 @@ export class UIBehaviorDirectionalGravity extends UIBehaviorModule {
12
12
  */
13
13
  constructor(direction) {
14
14
  super();
15
- /** @internal */
16
15
  this.requiredProperties = { builtin: "Matrix4" };
17
16
  this.directionInternal = resolveUIVector2Config(direction);
18
17
  assertValidNumber(this.directionInternal.x, "UIBehaviorDirectionalGravity.constructor.direction.x");
@@ -28,7 +27,6 @@ export class UIBehaviorDirectionalGravity extends UIBehaviorModule {
28
27
  assertValidNumber(this.directionInternal.x, "UIBehaviorDirectionalGravity.direction.x");
29
28
  assertValidNumber(this.directionInternal.y, "UIBehaviorDirectionalGravity.direction.y");
30
29
  }
31
- /** @internal */
32
30
  update(properties, instanceCount, deltaTime) {
33
31
  const { builtin } = properties;
34
32
  const { array, itemSize } = builtin;
@@ -3,12 +3,22 @@ import type { UIPropertyName } from "../../core/miscellaneous/generic-plane/shar
3
3
  /**
4
4
  * Base class for particle behavior modules.
5
5
  *
6
- * Behavior modules update particle properties each frame.
6
+ * Behavior modules update particle properties each frame. Declare the per-particle properties
7
+ * the module touches in `requiredProperties` and change them in `update`.
7
8
  */
8
9
  export declare abstract class UIBehaviorModule<T extends Record<string, UIPropertyName> = Record<string, UIPropertyName>> {
10
+ /** Per-particle properties the module reads and writes, by name and type */
9
11
  abstract readonly requiredProperties: T;
12
+ /**
13
+ * Advances the particles in [0, instanceCount) by deltaTime seconds.
14
+ * @param properties Per-particle buffers of the required properties
15
+ * @param instanceCount Number of live particles
16
+ * @param deltaTime Frame step in seconds
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
19
+ */
10
20
  abstract update(properties: {
11
21
  [K in keyof T]: InstancedBufferAttribute;
12
- }, instanceCount: number, deltaTime: number): void;
22
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
13
23
  destroy?(): void;
14
24
  }
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * Base class for particle behavior modules.
3
3
  *
4
- * Behavior modules update particle properties each frame.
4
+ * Behavior modules update particle properties each frame. Declare the per-particle properties
5
+ * the module touches in `requiredProperties` and change them in `update`.
5
6
  */
6
7
  export class UIBehaviorModule {
7
8
  }
@@ -1,3 +1,4 @@
1
+ import type { InstancedBufferAttribute } from "three";
1
2
  import type { Vector2Like } from "../../core/miscellaneous/math.js";
2
3
  import { type UIRange, type UIRangeConfig, type UIVector2Config } from "../miscellaneous/miscellaneous.js";
3
4
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
@@ -9,6 +10,9 @@ import { UIBehaviorModule } from "./UIBehaviorModule.js";
9
10
  export declare class UIBehaviorPointGravity extends UIBehaviorModule<{
10
11
  builtin: "Matrix4";
11
12
  }> {
13
+ readonly requiredProperties: {
14
+ readonly builtin: "Matrix4";
15
+ };
12
16
  private centerInternal;
13
17
  private strengthInternal;
14
18
  private exponentInternal;
@@ -19,7 +23,7 @@ export declare class UIBehaviorPointGravity extends UIBehaviorModule<{
19
23
  * @param exponent - Distance power exponent range. Accepts number, tuple, or range object
20
24
  * @param threshold - Minimum distance range. Accepts number, tuple, or range object
21
25
  */
22
- constructor(center: Vector2Like, strength: UIRangeConfig, exponent?: UIRangeConfig, threshold?: UIRangeConfig);
26
+ constructor(center: UIVector2Config, strength: UIRangeConfig, exponent?: UIRangeConfig, threshold?: UIRangeConfig);
23
27
  /** Gravity center position */
24
28
  get center(): Vector2Like;
25
29
  /** Force multiplier range */
@@ -36,4 +40,7 @@ export declare class UIBehaviorPointGravity extends UIBehaviorModule<{
36
40
  set exponent(value: UIRangeConfig);
37
41
  /** Minimum distance range */
38
42
  set threshold(value: UIRangeConfig);
43
+ update(properties: {
44
+ builtin: InstancedBufferAttribute;
45
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
39
46
  }
@@ -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.
@@ -16,7 +16,6 @@ export class UIBehaviorPointGravity extends UIBehaviorModule {
16
16
  */
17
17
  constructor(center, strength, exponent = 2, threshold = 1) {
18
18
  super();
19
- /** @internal */
20
19
  this.requiredProperties = { builtin: "Matrix4" };
21
20
  this.centerInternal = resolveUIVector2Config(center);
22
21
  assertValidNumber(this.centerInternal.x, "UIBehaviorPointGravity.constructor.center.x");
@@ -28,8 +27,8 @@ export class UIBehaviorPointGravity extends UIBehaviorModule {
28
27
  assertValidNumber(this.exponentInternal.min, "UIBehaviorPointGravity.constructor.exponent.min");
29
28
  assertValidNumber(this.exponentInternal.max, "UIBehaviorPointGravity.constructor.exponent.max");
30
29
  this.thresholdInternal = resolveUIRangeConfig(threshold);
31
- assertValidNumber(this.thresholdInternal.min, "UIBehaviorPointGravity.constructor.threshold.min");
32
- 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");
33
32
  }
34
33
  /** Gravity center position */
35
34
  get center() {
@@ -68,27 +67,29 @@ export class UIBehaviorPointGravity extends UIBehaviorModule {
68
67
  /** Minimum distance range */
69
68
  set threshold(value) {
70
69
  this.thresholdInternal = resolveUIRangeConfig(value);
71
- assertValidNumber(this.thresholdInternal.min, "UIBehaviorPointGravity.threshold.min");
72
- assertValidNumber(this.thresholdInternal.max, "UIBehaviorPointGravity.threshold.max");
70
+ assertValidPositiveNumber(this.thresholdInternal.min, "UIBehaviorPointGravity.threshold.min");
71
+ assertValidPositiveNumber(this.thresholdInternal.max, "UIBehaviorPointGravity.threshold.max");
73
72
  }
74
- /** @internal */
75
- update(properties, instanceCount, deltaTime) {
73
+ update(properties, instanceCount, deltaTime, randomSalt) {
76
74
  const { builtin } = properties;
77
75
  const { array, itemSize } = builtin;
76
+ const thresholdStream = particleRandomStream(randomSalt, 0);
77
+ const strengthStream = particleRandomStream(randomSalt, 1);
78
+ const exponentStream = particleRandomStream(randomSalt, 2);
78
79
  for (let i = 0; i < instanceCount; i++) {
79
80
  const itemOffset = i * itemSize;
80
81
  const dx = this.centerInternal.x - array[itemOffset + BUILTIN_OFFSET_POSITION_X];
81
82
  const dy = this.centerInternal.y - array[itemOffset + BUILTIN_OFFSET_POSITION_Y];
82
- const thresholdT = array[itemOffset + BUILTIN_OFFSET_RANDOM_A];
83
+ const thresholdT = particleRandom(array, itemOffset, thresholdStream);
83
84
  const threshold = MathUtils.lerp(this.threshold.min, this.threshold.max, thresholdT);
84
85
  const thresholdSquared = threshold * threshold;
85
86
  const distanceSquared = dx * dx + dy * dy;
86
87
  if (distanceSquared < thresholdSquared) {
87
88
  continue;
88
89
  }
89
- const strengthT = array[itemOffset + BUILTIN_OFFSET_RANDOM_B];
90
+ const strengthT = particleRandom(array, itemOffset, strengthStream);
90
91
  const strength = MathUtils.lerp(this.strengthInternal.min, this.strengthInternal.max, strengthT);
91
- const exponentT = array[itemOffset + BUILTIN_OFFSET_RANDOM_C];
92
+ const exponentT = particleRandom(array, itemOffset, exponentStream);
92
93
  const exponent = MathUtils.lerp(this.exponentInternal.min, this.exponentInternal.max, exponentT);
93
94
  const distance = Math.sqrt(distanceSquared);
94
95
  const forceMagnitude = strength / Math.pow(distance, exponent);
@@ -1,3 +1,4 @@
1
+ import type { InstancedBufferAttribute } from "three";
1
2
  import type { UIAspectConfig, UIRange, UIRangeConfig } from "../miscellaneous/miscellaneous.js";
2
3
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
3
4
  /** Axis whose scale oscillates */
@@ -13,6 +14,9 @@ export type UIScaleOscillationAxis = "x" | "y";
13
14
  export declare class UIBehaviorScaleOscillation extends UIBehaviorModule<{
14
15
  builtin: "Matrix4";
15
16
  }> {
17
+ readonly requiredProperties: {
18
+ readonly builtin: "Matrix4";
19
+ };
16
20
  private readonly axisInternal;
17
21
  private frequencyInternal;
18
22
  private depthInternal;
@@ -38,4 +42,7 @@ export declare class UIBehaviorScaleOscillation extends UIBehaviorModule<{
38
42
  set depth(value: number);
39
43
  /** Width/height aspect ratio */
40
44
  set aspect(value: UIAspectConfig);
45
+ update(properties: {
46
+ builtin: InstancedBufferAttribute;
47
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
41
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.
@@ -19,7 +19,6 @@ export class UIBehaviorScaleOscillation extends UIBehaviorModule {
19
19
  */
20
20
  constructor(axis, frequency, depth = 1, aspect = 1) {
21
21
  super();
22
- /** @internal */
23
22
  this.requiredProperties = { builtin: "Matrix4" };
24
23
  this.axisInternal = axis;
25
24
  this.frequencyInternal = resolveUIRangeConfig(frequency);
@@ -62,15 +61,16 @@ export class UIBehaviorScaleOscillation extends UIBehaviorModule {
62
61
  this.aspectInternal = resolveAspect(value);
63
62
  assertValidPositiveNumber(this.aspectInternal, "UIBehaviorScaleOscillation.aspect");
64
63
  }
65
- /** @internal */
66
- update(properties, instanceCount) {
64
+ update(properties, instanceCount, deltaTime, randomSalt) {
67
65
  const { builtin } = properties;
68
66
  const { array, itemSize } = builtin;
67
+ const frequencyStream = particleRandomStream(randomSalt, 0);
68
+ const phaseStream = particleRandomStream(randomSalt, 1);
69
69
  for (let i = 0; i < instanceCount; i++) {
70
70
  const itemOffset = i * itemSize;
71
- const frequencyT = array[itemOffset + BUILTIN_OFFSET_RANDOM_E];
71
+ const frequencyT = particleRandom(array, itemOffset, frequencyStream);
72
72
  const frequency = MathUtils.lerp(this.frequencyInternal.min, this.frequencyInternal.max, frequencyT);
73
- const phase = array[itemOffset + BUILTIN_OFFSET_RANDOM_F] * Math.PI * 2;
73
+ const phase = particleRandom(array, itemOffset, phaseStream) * Math.PI * 2;
74
74
  const angle = array[itemOffset + BUILTIN_OFFSET_AGE] * frequency * Math.PI * 2 + phase;
75
75
  const factor = 1 - this.depthInternal * (1 - Math.cos(angle));
76
76
  if (this.axisInternal === "x") {
@@ -1,3 +1,4 @@
1
+ import type { InstancedBufferAttribute } from "three";
1
2
  import type { UIAspectConfig, UIRangeConfig } from "../miscellaneous/miscellaneous.js";
2
3
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
3
4
  /**
@@ -8,6 +9,9 @@ import { UIBehaviorModule } from "./UIBehaviorModule.js";
8
9
  export declare class UIBehaviorScaleOverLife extends UIBehaviorModule<{
9
10
  builtin: "Matrix4";
10
11
  }> {
12
+ readonly requiredProperties: {
13
+ readonly builtin: "Matrix4";
14
+ };
11
15
  private readonly scales;
12
16
  private aspectInternal;
13
17
  /**
@@ -19,4 +23,7 @@ export declare class UIBehaviorScaleOverLife extends UIBehaviorModule<{
19
23
  get aspect(): number;
20
24
  /** Width/height aspect ratio */
21
25
  set aspect(value: UIAspectConfig);
26
+ update(properties: {
27
+ builtin: InstancedBufferAttribute;
28
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
22
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.
@@ -14,7 +14,6 @@ export class UIBehaviorScaleOverLife extends UIBehaviorModule {
14
14
  */
15
15
  constructor(scales, aspect = 1) {
16
16
  super();
17
- /** @internal */
18
17
  this.requiredProperties = { builtin: "Matrix4" };
19
18
  this.scales = [];
20
19
  if (scales.length < 2) {
@@ -38,16 +37,16 @@ export class UIBehaviorScaleOverLife extends UIBehaviorModule {
38
37
  this.aspectInternal = resolveAspect(value);
39
38
  assertValidPositiveNumber(this.aspectInternal, "UIBehaviorScaleOverLife.aspect");
40
39
  }
41
- /** @internal */
42
- update(properties, instanceCount) {
40
+ update(properties, instanceCount, deltaTime, randomSalt) {
43
41
  const { builtin } = properties;
44
42
  const { array, itemSize } = builtin;
43
+ const scaleStream = particleRandomStream(randomSalt, 0);
45
44
  for (let i = 0; i < instanceCount; i++) {
46
45
  const itemOffset = i * itemSize;
47
46
  const lifeT = Math.min(array[itemOffset + BUILTIN_OFFSET_AGE] / array[itemOffset + BUILTIN_OFFSET_LIFETIME], 1);
48
47
  const segment = (this.scales.length - 1) * lifeT;
49
48
  const index = Math.floor(segment);
50
- const scaleT = array[itemOffset + BUILTIN_OFFSET_RANDOM_D];
49
+ const scaleT = particleRandom(array, itemOffset, scaleStream);
51
50
  const localT = segment - index;
52
51
  const scaleRange0 = this.scales[index];
53
52
  const scaleRange1 = this.scales[index + 1];
@@ -1,3 +1,4 @@
1
+ import type { InstancedBufferAttribute } from "three";
1
2
  import type { UIRange, UIRangeConfig } from "../miscellaneous/miscellaneous.js";
2
3
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
3
4
  /**
@@ -8,13 +9,19 @@ import { UIBehaviorModule } from "./UIBehaviorModule.js";
8
9
  export declare class UIBehaviorTorqueDamping extends UIBehaviorModule<{
9
10
  builtin: "Matrix4";
10
11
  }> {
12
+ readonly requiredProperties: {
13
+ readonly builtin: "Matrix4";
14
+ };
11
15
  private dampingInternal;
12
16
  /**
13
17
  * @param damping - Damping coefficient range (0-1). Accepts number, tuple, or range object
14
18
  */
15
- constructor(damping: number);
19
+ constructor(damping: UIRangeConfig);
16
20
  /** Damping coefficient range (0-1) */
17
21
  get damping(): UIRange;
18
22
  /** Damping coefficient range (0-1) */
19
23
  set damping(value: UIRangeConfig);
24
+ update(properties: {
25
+ builtin: InstancedBufferAttribute;
26
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
20
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.
@@ -13,11 +12,10 @@ export class UIBehaviorTorqueDamping extends UIBehaviorModule {
13
12
  */
14
13
  constructor(damping) {
15
14
  super();
16
- /** @internal */
17
15
  this.requiredProperties = { builtin: "Matrix4" };
18
16
  this.dampingInternal = resolveUIRangeConfig(damping);
19
- assertValidNonNegativeNumber(this.dampingInternal.min, `UIBehaviorTorqueDamping.constructor.damping.min`);
20
- 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`);
21
19
  }
22
20
  /** Damping coefficient range (0-1) */
23
21
  get damping() {
@@ -26,16 +24,16 @@ export class UIBehaviorTorqueDamping extends UIBehaviorModule {
26
24
  /** Damping coefficient range (0-1) */
27
25
  set damping(value) {
28
26
  this.dampingInternal = resolveUIRangeConfig(value);
29
- assertValidNonNegativeNumber(this.dampingInternal.min, `UIBehaviorTorqueDamping.damping.min`);
30
- assertValidNonNegativeNumber(this.dampingInternal.max, `UIBehaviorTorqueDamping.damping.max`);
27
+ assertValidUnitNumber(this.dampingInternal.min, `UIBehaviorTorqueDamping.damping.min`);
28
+ assertValidUnitNumber(this.dampingInternal.max, `UIBehaviorTorqueDamping.damping.max`);
31
29
  }
32
- /** @internal */
33
- update(properties, instanceCount, deltaTime) {
30
+ update(properties, instanceCount, deltaTime, randomSalt) {
34
31
  const { builtin } = properties;
35
32
  const { array, itemSize } = builtin;
33
+ const dampingStream = particleRandomStream(randomSalt, 0);
36
34
  for (let i = 0; i < instanceCount; i++) {
37
35
  const itemOffset = i * itemSize;
38
- const dampingT = array[itemOffset + BUILTIN_OFFSET_RANDOM_E];
36
+ const dampingT = particleRandom(array, itemOffset, dampingStream);
39
37
  const dampingFactor = Math.pow(1 - MathUtils.lerp(this.dampingInternal.min, this.dampingInternal.max, dampingT), deltaTime);
40
38
  array[itemOffset + BUILTIN_OFFSET_TORQUE] *= dampingFactor;
41
39
  }
@@ -1,20 +1,25 @@
1
+ import type { InstancedBufferAttribute } from "three";
1
2
  import type { UIRange, UIRangeConfig } from "../miscellaneous/miscellaneous.js";
2
3
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
3
4
  /**
4
5
  * Applies noise-based angular acceleration to particles.
5
6
  *
6
- * 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.
7
9
  */
8
10
  export declare class UIBehaviorTorqueNoise extends UIBehaviorModule<{
9
11
  builtin: "Matrix4";
10
12
  }> {
13
+ readonly requiredProperties: {
14
+ readonly builtin: "Matrix4";
15
+ };
11
16
  private scaleInternal;
12
17
  private strengthInternal;
13
18
  /**
14
19
  * @param scale - Noise frequency range. Accepts number, tuple, or range object
15
20
  * @param strength - Force multiplier range. Accepts number, tuple, or range object
16
21
  */
17
- constructor(scale: number, strength: number);
22
+ constructor(scale: UIRangeConfig, strength: UIRangeConfig);
18
23
  /** Noise frequency range */
19
24
  get scale(): UIRange;
20
25
  /** Force multiplier range */
@@ -23,4 +28,7 @@ export declare class UIBehaviorTorqueNoise extends UIBehaviorModule<{
23
28
  set scale(value: UIRangeConfig);
24
29
  /** Force multiplier range */
25
30
  set strength(value: UIRangeConfig);
31
+ update(properties: {
32
+ builtin: InstancedBufferAttribute;
33
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
26
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
  /**
@@ -14,7 +15,6 @@ export class UIBehaviorTorqueNoise extends UIBehaviorModule {
14
15
  */
15
16
  constructor(scale, strength) {
16
17
  super();
17
- /** @internal */
18
18
  this.requiredProperties = { builtin: "Matrix4" };
19
19
  this.scaleInternal = resolveUIRangeConfig(scale);
20
20
  assertValidPositiveNumber(this.scaleInternal.min, `UIBehaviorTorqueNoise.constructor.scale.min`);
@@ -43,16 +43,17 @@ export class UIBehaviorTorqueNoise extends UIBehaviorModule {
43
43
  assertValidNonNegativeNumber(this.strengthInternal.min, `UIBehaviorTorqueNoise.strength.min`);
44
44
  assertValidNonNegativeNumber(this.strengthInternal.max, `UIBehaviorTorqueNoise.strength.max`);
45
45
  }
46
- /** @internal */
47
- update(properties, instanceCount, deltaTime) {
46
+ update(properties, instanceCount, deltaTime, randomSalt) {
48
47
  const { builtin } = properties;
49
48
  const { array, itemSize } = builtin;
49
+ const scaleStream = particleRandomStream(randomSalt, 0);
50
+ const strengthStream = particleRandomStream(randomSalt, 1);
50
51
  for (let i = 0; i < instanceCount; i++) {
51
52
  const itemOffset = i * itemSize;
52
- const scaleT = array[itemOffset + BUILTIN_OFFSET_RANDOM_F];
53
+ const scaleT = particleRandom(array, itemOffset, scaleStream);
53
54
  const scale = MathUtils.lerp(this.scaleInternal.min, this.scaleInternal.max, scaleT);
54
55
  const noise = generateNoise2D(array[itemOffset + BUILTIN_OFFSET_POSITION_X] * scale, array[itemOffset + BUILTIN_OFFSET_POSITION_Y] * scale);
55
- const strengthT = array[itemOffset + BUILTIN_OFFSET_RANDOM_A];
56
+ const strengthT = particleRandom(array, itemOffset, strengthStream);
56
57
  const strength = MathUtils.lerp(this.strengthInternal.min, this.strengthInternal.max, strengthT);
57
58
  array[itemOffset + BUILTIN_OFFSET_TORQUE] += noise * strength * deltaTime;
58
59
  }
@@ -1,3 +1,4 @@
1
+ import type { InstancedBufferAttribute } from "three";
1
2
  import type { UIRange, UIRangeConfig } from "../miscellaneous/miscellaneous.js";
2
3
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
3
4
  /**
@@ -8,6 +9,9 @@ import { UIBehaviorModule } from "./UIBehaviorModule.js";
8
9
  export declare class UIBehaviorVelocityDamping extends UIBehaviorModule<{
9
10
  builtin: "Matrix4";
10
11
  }> {
12
+ readonly requiredProperties: {
13
+ readonly builtin: "Matrix4";
14
+ };
11
15
  private dampingInternal;
12
16
  /**
13
17
  * @param damping - Damping coefficient range (0-1). Accepts number, tuple, or range object
@@ -17,4 +21,7 @@ export declare class UIBehaviorVelocityDamping extends UIBehaviorModule<{
17
21
  get damping(): UIRange;
18
22
  /** Damping coefficient range (0-1) */
19
23
  set damping(value: UIRangeConfig);
24
+ update(properties: {
25
+ builtin: InstancedBufferAttribute;
26
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
20
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.
@@ -13,11 +12,10 @@ export class UIBehaviorVelocityDamping extends UIBehaviorModule {
13
12
  */
14
13
  constructor(damping) {
15
14
  super();
16
- /** @internal */
17
15
  this.requiredProperties = { builtin: "Matrix4" };
18
16
  this.dampingInternal = resolveUIRangeConfig(damping);
19
- assertValidNonNegativeNumber(this.dampingInternal.min, `UIBehaviorVelocityDamping.constructor.damping.min`);
20
- 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`);
21
19
  }
22
20
  /** Damping coefficient range (0-1) */
23
21
  get damping() {
@@ -26,16 +24,16 @@ export class UIBehaviorVelocityDamping extends UIBehaviorModule {
26
24
  /** Damping coefficient range (0-1) */
27
25
  set damping(value) {
28
26
  this.dampingInternal = resolveUIRangeConfig(value);
29
- assertValidNonNegativeNumber(this.dampingInternal.min, `UIBehaviorVelocityDamping.damping.min`);
30
- assertValidNonNegativeNumber(this.dampingInternal.max, `UIBehaviorVelocityDamping.damping.max`);
27
+ assertValidUnitNumber(this.dampingInternal.min, `UIBehaviorVelocityDamping.damping.min`);
28
+ assertValidUnitNumber(this.dampingInternal.max, `UIBehaviorVelocityDamping.damping.max`);
31
29
  }
32
- /** @internal */
33
- update(properties, instanceCount, deltaTime) {
30
+ update(properties, instanceCount, deltaTime, randomSalt) {
34
31
  const { builtin } = properties;
35
32
  const { array, itemSize } = builtin;
33
+ const dampingStream = particleRandomStream(randomSalt, 0);
36
34
  for (let i = 0; i < instanceCount; i++) {
37
35
  const itemOffset = i * itemSize;
38
- const dampingT = array[itemOffset + BUILTIN_OFFSET_RANDOM_B];
36
+ const dampingT = particleRandom(array, itemOffset, dampingStream);
39
37
  const dampingFactor = Math.pow(1 - MathUtils.lerp(this.dampingInternal.min, this.dampingInternal.max, dampingT), deltaTime);
40
38
  array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] *= dampingFactor;
41
39
  array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] *= dampingFactor;
@@ -1,20 +1,26 @@
1
+ import type { InstancedBufferAttribute } from "three";
1
2
  import { type UIRange, type UIRangeConfig } from "../miscellaneous/miscellaneous.js";
2
3
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
3
4
  /**
4
- * Applies noise-based acceleration to particles.
5
+ * Applies noise-based acceleration to particles: a still flow field that particles drift through.
5
6
  *
6
- * 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.
7
10
  */
8
11
  export declare class UIBehaviorVelocityNoise extends UIBehaviorModule<{
9
12
  builtin: "Matrix4";
10
13
  }> {
14
+ readonly requiredProperties: {
15
+ readonly builtin: "Matrix4";
16
+ };
11
17
  private scaleInternal;
12
18
  private strengthInternal;
13
19
  /**
14
- * @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
15
21
  * @param strength - Force multiplier range. Accepts number, tuple, or range object
16
22
  */
17
- constructor(scale?: number, strength?: number);
23
+ constructor(scale?: UIRangeConfig, strength?: UIRangeConfig);
18
24
  /** Noise frequency range */
19
25
  get scale(): UIRange;
20
26
  /** Force multiplier range */
@@ -23,4 +29,7 @@ export declare class UIBehaviorVelocityNoise extends UIBehaviorModule<{
23
29
  set scale(value: UIRangeConfig);
24
30
  /** Force multiplier range */
25
31
  set strength(value: UIRangeConfig);
32
+ update(properties: {
33
+ builtin: InstancedBufferAttribute;
34
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
26
35
  }
@@ -1,20 +1,21 @@
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
- /** @internal */
18
19
  this.requiredProperties = { builtin: "Matrix4" };
19
20
  this.scaleInternal = resolveUIRangeConfig(scale);
20
21
  assertValidPositiveNumber(this.scaleInternal.min, `UIBehaviorVelocityNoise.constructor.scale.min`);
@@ -43,19 +44,20 @@ export class UIBehaviorVelocityNoise extends UIBehaviorModule {
43
44
  assertValidNonNegativeNumber(this.strengthInternal.min, `UIBehaviorVelocityNoise.strength.min`);
44
45
  assertValidNonNegativeNumber(this.strengthInternal.max, `UIBehaviorVelocityNoise.strength.max`);
45
46
  }
46
- /** @internal */
47
- update(properties, instanceCount, deltaTime) {
47
+ update(properties, instanceCount, deltaTime, randomSalt) {
48
48
  const { builtin } = properties;
49
49
  const { array, itemSize } = builtin;
50
+ const scaleStream = particleRandomStream(randomSalt, 0);
51
+ const strengthStream = particleRandomStream(randomSalt, 1);
50
52
  for (let i = 0; i < instanceCount; i++) {
51
53
  const itemOffset = i * itemSize;
52
54
  const x = array[itemOffset + BUILTIN_OFFSET_POSITION_X];
53
55
  const y = array[itemOffset + BUILTIN_OFFSET_POSITION_Y];
54
- const scaleT = array[itemOffset + BUILTIN_OFFSET_RANDOM_C];
56
+ const scaleT = particleRandom(array, itemOffset, scaleStream);
55
57
  const scale = MathUtils.lerp(this.scaleInternal.min, this.scaleInternal.max, scaleT);
56
58
  const noiseX = generateNoise2D(x * scale, y * scale);
57
59
  const noiseY = generateNoise2D((x + 100) * scale, (y + 100) * scale);
58
- const strengthT = array[itemOffset + BUILTIN_OFFSET_RANDOM_D];
60
+ const strengthT = particleRandom(array, itemOffset, strengthStream);
59
61
  const strength = MathUtils.lerp(this.strengthInternal.min, this.strengthInternal.max, strengthT);
60
62
  array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] += noiseX * strength * deltaTime;
61
63
  array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] += noiseY * strength * deltaTime;