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,8 +1,22 @@
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
+ /** Configuration options for UIEmitter */
3
4
  export interface UIEmitterOptions extends UIAnchorOptions {
5
+ /** Whether the particles are drawn */
6
+ mode: UIEmitterMode;
7
+ /** Number of particles to allocate for up front; a hint, not a limit */
4
8
  expectedCapacity: number;
9
+ /** Capacity is kept a multiple of this; the buffers double when they grow */
5
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;
18
+ /** Whether to call destroy() on all modules when the emitter is destroyed */
19
+ automaticallyDestroyModules: boolean;
6
20
  }
7
21
  export interface UIEmitterPlayOptions {
8
22
  duration: number;
@@ -12,4 +26,10 @@ export type UIEmitterMode = UIMode.HIDDEN | UIMode.VISIBLE;
12
26
  export declare const EMITTER_DEFAULT_MODE: UIEmitterMode;
13
27
  export declare const EMITTER_DEFAULT_EXPECTED_CAPACITY = 32;
14
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;
15
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,16 +1,9 @@
1
- import type { UILayer } from "../../core/index.js";
2
1
  import { UIAnchor } from "../../core/elements/UIAnchor/UIAnchor.js";
3
- import type { UIAnchorOptions } from "../../core/elements/UIAnchor/UIAnchor.Internal.js";
2
+ import type { UILayer } from "../../core/index.js";
4
3
  import type { UIBehaviorModule } from "../behaviorModules/UIBehaviorModule.js";
5
4
  import type { UIRenderingModule } from "../renderingModules/UIRenderingModule.js";
6
5
  import type { UISpawnModule } from "../spawnModules/UISpawnModule.js";
7
- import type { UIEmitterMode, UIEmitterPlayOptions } from "./UIEmitter.Internal.js";
8
- export interface UIEmitterOptions extends UIAnchorOptions {
9
- mode: UIEmitterMode;
10
- expectedCapacity: number;
11
- capacityStep: number;
12
- automaticallyDestroyModules: boolean;
13
- }
6
+ import type { UIEmitterMode, UIEmitterOptions, UIEmitterPlayOptions } from "./UIEmitter.Internal.js";
14
7
  /**
15
8
  * Particle emitter element.
16
9
  *
@@ -29,6 +22,10 @@ export declare class UIEmitter extends UIAnchor {
29
22
  private emissionDuration;
30
23
  private emissionElapsed;
31
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;
32
29
  /**
33
30
  * @param layer - Layer containing this emitter
34
31
  * @param spawnSequence - Modules that initialize new particles
@@ -37,6 +34,10 @@ export declare class UIEmitter extends UIAnchor {
37
34
  * @param options - Configuration options
38
35
  */
39
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;
40
41
  /** Visibility mode */
41
42
  get mode(): UIEmitterMode;
42
43
  /**
@@ -46,15 +47,23 @@ export declare class UIEmitter extends UIAnchor {
46
47
  get zIndex(): number;
47
48
  /** Visibility mode */
48
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);
49
57
  /**
50
58
  * Rendering order among the elements of the layer. Higher values on top; elements with equal
51
59
  * values keep the order of creation, a later one on top.
52
60
  */
53
61
  set zIndex(value: number);
54
62
  /**
55
- * 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.
56
65
  *
57
- * @param count - Number of particles to create
66
+ * @param count - Number of particles to create, a non-negative integer
58
67
  */
59
68
  burst(count: number): void;
60
69
  /** Removes all active particles */
@@ -1,12 +1,23 @@
1
1
  import { Vector2 } from "three";
2
2
  import { UIAnchor } from "../../core/elements/UIAnchor/UIAnchor.js";
3
- import { assertValidNumber } from "../../core/miscellaneous/asserts.js";
3
+ import { assertValidNumber, assertValidPositiveNumber } from "../../core/miscellaneous/asserts.js";
4
4
  import { resolveGLSLTypeInfo } from "../../core/miscellaneous/generic-plane/shared.js";
5
5
  import { isUIModeVisible } from "../../core/miscellaneous/UIMode.js";
6
+ import { collectProperties, collectRenderingUniforms, } from "../instancedParticle/UIInstancedParticle.Internal.js";
6
7
  import { UIInstancedParticle } from "../instancedParticle/UIInstancedParticle.js";
7
- import { collectProperties, collectUniforms, } from "../instancedParticle/UIInstancedParticle.Internal.js";
8
- import { BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_RANDOM_A, BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_RANDOM_C, BUILTIN_OFFSET_RANDOM_D, BUILTIN_OFFSET_RANDOM_E, BUILTIN_OFFSET_RANDOM_F, BUILTIN_OFFSET_ROTATION, BUILTIN_OFFSET_TORQUE, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, } from "../miscellaneous/miscellaneous.js";
9
- import { EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES, EMITTER_DEFAULT_CAPACITY_STEP, EMITTER_DEFAULT_EXPECTED_CAPACITY, EMITTER_DEFAULT_MODE, ignoreInput, } from "./UIEmitter.Internal.js";
8
+ import { assertValidNonNegativeInteger, BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME, BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_RANDOM_A, BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_RANDOM_C, BUILTIN_OFFSET_RANDOM_D, BUILTIN_OFFSET_RANDOM_E, BUILTIN_OFFSET_ROTATION, BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y, BUILTIN_OFFSET_TORQUE, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, computeParticleSeed, particleRandom, particleRandomStream, writeParticleSeed, } from "../miscellaneous/miscellaneous.js";
9
+ import { EMITTER_BEHAVIOR_SALT_BASE, EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES, EMITTER_DEFAULT_CAPACITY_STEP, EMITTER_DEFAULT_EXPECTED_CAPACITY, EMITTER_DEFAULT_LIFETIME, EMITTER_DEFAULT_MAX_DELTA_TIME, EMITTER_DEFAULT_MODE, EMITTER_SHADER_SALT, EMITTER_SPAWN_SALT_BASE, ignoreInput, } from "./UIEmitter.Internal.js";
10
+ /** Builtin slots of the random values the shaders read, each with its stream */
11
+ const SHADER_RANDOM_SLOTS = [
12
+ BUILTIN_OFFSET_RANDOM_A,
13
+ BUILTIN_OFFSET_RANDOM_B,
14
+ BUILTIN_OFFSET_RANDOM_C,
15
+ BUILTIN_OFFSET_RANDOM_D,
16
+ BUILTIN_OFFSET_RANDOM_E,
17
+ ].map((offset, channel) => ({
18
+ offset,
19
+ stream: particleRandomStream(EMITTER_SHADER_SALT, channel),
20
+ }));
10
21
  /**
11
22
  * Particle emitter element.
12
23
  *
@@ -29,30 +40,31 @@ export class UIEmitter extends UIAnchor {
29
40
  this.emissionAccumulator = 0;
30
41
  this.emissionDuration = Infinity;
31
42
  this.emissionElapsed = 0;
32
- this.onRendering = (renderer, deltaTime) => {
43
+ /** Particles spawned since the seed was set; picks the seed of the next particle */
44
+ this.spawnedCount = 0;
45
+ this.onRendering = (renderer, rawDeltaTime) => {
33
46
  this.layer.sceneWrapper.setOrderedObjectDepth(this.mesh, this.layer.inputWrapper.getDepth(this.catcherHandler));
34
- {
35
- const { builtin } = this.mesh.propertyBuffers;
36
- const { array, itemSize } = builtin;
47
+ const deltaTime = Math.min(rawDeltaTime, this.maxDeltaTimeInternal);
48
+ if (this.mesh.instanceCount > 0) {
49
+ const { array, itemSize } = this.mesh.propertyBuffers.builtin;
37
50
  for (let i = 0; i < this.mesh.instanceCount; i++) {
38
51
  array[i * itemSize + BUILTIN_OFFSET_AGE] += deltaTime;
39
52
  }
40
- builtin.needsUpdate = true;
41
53
  this.mesh.removeDeadParticles();
42
54
  }
43
55
  if (this.emissionRate > 0) {
56
+ const emittedBefore = this.emissionElapsed;
44
57
  this.emissionElapsed += deltaTime;
58
+ this.emissionAccumulator +=
59
+ this.emissionRate * (Math.min(this.emissionElapsed, this.emissionDuration) - emittedBefore);
60
+ const particlesToSpawn = Math.floor(this.emissionAccumulator);
61
+ if (particlesToSpawn > 0) {
62
+ this.burst(particlesToSpawn);
63
+ this.emissionAccumulator -= particlesToSpawn;
64
+ }
45
65
  if (this.emissionElapsed >= this.emissionDuration) {
46
66
  this.stop();
47
67
  }
48
- else {
49
- this.emissionAccumulator += this.emissionRate * deltaTime;
50
- const particlesToSpawn = Math.floor(this.emissionAccumulator);
51
- if (particlesToSpawn > 0) {
52
- this.burst(particlesToSpawn);
53
- this.emissionAccumulator -= particlesToSpawn;
54
- }
55
- }
56
68
  }
57
69
  if (this.mesh.instanceCount === 0) {
58
70
  return;
@@ -60,30 +72,23 @@ export class UIEmitter extends UIAnchor {
60
72
  this.mesh.setOrigin(this.x, this.y);
61
73
  {
62
74
  const { propertyBuffers, instanceCount } = this.mesh;
63
- for (const module of this.behaviorSequence) {
64
- module.update(propertyBuffers, instanceCount, deltaTime);
75
+ for (let index = 0; index < this.behaviorSequence.length; index++) {
76
+ this.behaviorSequence[index].update(propertyBuffers, instanceCount, deltaTime, EMITTER_BEHAVIOR_SALT_BASE + index);
65
77
  }
66
78
  }
67
79
  const { builtin } = this.mesh.propertyBuffers;
68
80
  const { array, itemSize } = builtin;
69
- {
70
- for (let i = 0; i < this.mesh.instanceCount; i++) {
71
- const itemOffset = i * itemSize;
72
- array[itemOffset + BUILTIN_OFFSET_POSITION_X] +=
73
- array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] * deltaTime;
74
- array[itemOffset + BUILTIN_OFFSET_POSITION_Y] +=
75
- array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] * deltaTime;
76
- }
77
- builtin.needsUpdate = true;
78
- }
79
- {
80
- for (let i = 0; i < this.mesh.instanceCount; i++) {
81
- const itemOffset = i * itemSize;
82
- array[itemOffset + BUILTIN_OFFSET_ROTATION] +=
83
- array[itemOffset + BUILTIN_OFFSET_TORQUE] * deltaTime;
84
- }
85
- builtin.needsUpdate = true;
81
+ for (let i = 0; i < this.mesh.instanceCount; i++) {
82
+ const itemOffset = i * itemSize;
83
+ array[itemOffset + BUILTIN_OFFSET_POSITION_X] +=
84
+ array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] * deltaTime;
85
+ array[itemOffset + BUILTIN_OFFSET_POSITION_Y] +=
86
+ array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] * deltaTime;
87
+ array[itemOffset + BUILTIN_OFFSET_ROTATION] +=
88
+ array[itemOffset + BUILTIN_OFFSET_TORQUE] * deltaTime;
86
89
  }
90
+ builtin.needsUpdate = true;
91
+ this.mesh.limitUploadToLiveInstances();
87
92
  };
88
93
  const collectedProperties = {
89
94
  builtin: resolveGLSLTypeInfo("Matrix4"),
@@ -92,8 +97,8 @@ export class UIEmitter extends UIAnchor {
92
97
  // 4, 5 scaleX, scaleY
93
98
  // 6, 7 rotation, torque
94
99
  // 8, 9 lifetime, age
95
- // 10, 11, 12 randomX, randomY, randomZ
96
- // 13, 14, 16 reservedX, reservedY, reservedZ
100
+ // 10-14 random values A-E for shaders
101
+ // 15 seed, read by shaders as random value F
97
102
  };
98
103
  collectProperties(collectedProperties, spawnSequence, "UIEmitter.constructor.spawnSequence");
99
104
  collectProperties(collectedProperties, behaviorSequence, "UIEmitter.constructor.behaviorSequence");
@@ -101,15 +106,33 @@ export class UIEmitter extends UIAnchor {
101
106
  const collectedUniforms = {
102
107
  origin: { value: new Vector2(), glslTypeInfo: resolveGLSLTypeInfo("Vector2") },
103
108
  };
104
- collectUniforms(collectedUniforms, renderingSequence, "UIEmitter.constructor.renderingSequence");
109
+ const renderingSources = collectRenderingUniforms(collectedUniforms, renderingSequence, "UIEmitter.constructor.renderingSequence");
105
110
  const zIndex = 0;
106
- this.catcherHandler = this.layer.inputWrapper.createInputCatcher(ignoreInput, ignoreInput, ignoreInput, zIndex);
107
- this.mesh = new UIInstancedParticle(this.renderingSequence.map((module) => module.source), collectedUniforms, collectedProperties, options.expectedCapacity ?? EMITTER_DEFAULT_EXPECTED_CAPACITY, options.capacityStep ?? EMITTER_DEFAULT_CAPACITY_STEP);
111
+ this.catcherHandler = this.layer.inputWrapper.createInputCatcher({
112
+ catchPointerDown: ignoreInput,
113
+ catchPointerMove: ignoreInput,
114
+ catchPointerUp: ignoreInput,
115
+ catchPointerCancel: ignoreInput,
116
+ }, zIndex);
117
+ this.mesh = new UIInstancedParticle(renderingSources, collectedUniforms, collectedProperties, options.expectedCapacity ?? EMITTER_DEFAULT_EXPECTED_CAPACITY, options.capacityStep ?? EMITTER_DEFAULT_CAPACITY_STEP);
108
118
  this.layer.signalRendering.on(this.onRendering);
109
119
  this.layer.sceneWrapper.insertOrderedObject(this.mesh, this.layer.inputWrapper.getDepth(this.catcherHandler));
110
120
  this.automaticallyDestroyModules =
111
121
  options.automaticallyDestroyModules ?? EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES;
112
122
  this.modeInternal = options.mode ?? EMITTER_DEFAULT_MODE;
123
+ this.mesh.visible = isUIModeVisible(this.modeInternal);
124
+ this.maxDeltaTimeInternal = options.maxDeltaTime ?? EMITTER_DEFAULT_MAX_DELTA_TIME;
125
+ assertValidPositiveNumber(this.maxDeltaTimeInternal, "UIEmitter.constructor.maxDeltaTime");
126
+ this.seedInternal = options.seed ?? Math.floor(Math.random() * 0x100000000);
127
+ assertValidNonNegativeInteger(this.seedInternal, "UIEmitter.constructor.seed");
128
+ }
129
+ /** Seed of the random values */
130
+ get seed() {
131
+ return this.seedInternal;
132
+ }
133
+ /** Longest frame step in seconds; longer frames are clamped */
134
+ get maxDeltaTime() {
135
+ return this.maxDeltaTimeInternal;
113
136
  }
114
137
  /** Visibility mode */
115
138
  get mode() {
@@ -130,6 +153,22 @@ export class UIEmitter extends UIAnchor {
130
153
  this.mesh.visible = isUIModeVisible(value);
131
154
  }
132
155
  }
156
+ /** Longest frame step in seconds; longer frames are clamped */
157
+ set maxDeltaTime(value) {
158
+ this.assertNotDestroyed("UIEmitter.maxDeltaTime");
159
+ assertValidPositiveNumber(value, "UIEmitter.maxDeltaTime");
160
+ this.maxDeltaTimeInternal = value;
161
+ }
162
+ /**
163
+ * Sets the seed and restarts its sequence: the next particles repeat those spawned after the
164
+ * same seed was set before
165
+ */
166
+ set seed(value) {
167
+ this.assertNotDestroyed("UIEmitter.seed");
168
+ assertValidNonNegativeInteger(value, "UIEmitter.seed");
169
+ this.seedInternal = value;
170
+ this.spawnedCount = 0;
171
+ }
133
172
  /**
134
173
  * Rendering order among the elements of the layer. Higher values on top; elements with equal
135
174
  * values keep the order of creation, a later one on top.
@@ -140,32 +179,39 @@ export class UIEmitter extends UIAnchor {
140
179
  this.layer.inputWrapper.setZIndex(this.catcherHandler, value);
141
180
  }
142
181
  /**
143
- * Spawns a specific number of particles immediately.
182
+ * Spawns a specific number of particles immediately. Before the spawn modules run, every
183
+ * property of a new particle is 0, except scale 1 and lifetime 1 second.
144
184
  *
145
- * @param count - Number of particles to create
185
+ * @param count - Number of particles to create, a non-negative integer
146
186
  */
147
187
  burst(count) {
148
188
  this.assertNotDestroyed("UIEmitter.burst");
189
+ assertValidNonNegativeInteger(count, "UIEmitter.burst.count");
190
+ if (count === 0) {
191
+ return;
192
+ }
149
193
  const instanceBegin = this.mesh.instanceCount;
150
194
  this.mesh.createInstances(count);
151
195
  const instanceEnd = this.mesh.instanceCount;
196
+ // A slot may hold a dead particle's values.
197
+ this.mesh.resetInstances(instanceBegin, instanceEnd);
152
198
  {
153
- const { builtin } = this.mesh.propertyBuffers;
154
- const { array, itemSize } = builtin;
199
+ const { array, itemSize } = this.mesh.propertyBuffers.builtin;
155
200
  for (let i = instanceBegin; i < instanceEnd; i++) {
156
201
  const itemOffset = i * itemSize;
157
- array[itemOffset + BUILTIN_OFFSET_RANDOM_A] = Math.random();
158
- array[itemOffset + BUILTIN_OFFSET_RANDOM_B] = Math.random();
159
- array[itemOffset + BUILTIN_OFFSET_RANDOM_C] = Math.random();
160
- array[itemOffset + BUILTIN_OFFSET_RANDOM_D] = Math.random();
161
- array[itemOffset + BUILTIN_OFFSET_RANDOM_E] = Math.random();
162
- array[itemOffset + BUILTIN_OFFSET_RANDOM_F] = Math.random();
202
+ array[itemOffset + BUILTIN_OFFSET_SCALE_X] = 1;
203
+ array[itemOffset + BUILTIN_OFFSET_SCALE_Y] = 1;
204
+ array[itemOffset + BUILTIN_OFFSET_LIFETIME] = EMITTER_DEFAULT_LIFETIME;
205
+ writeParticleSeed(array, itemOffset, computeParticleSeed(this.seedInternal, this.spawnedCount++));
206
+ for (const { offset, stream } of SHADER_RANDOM_SLOTS) {
207
+ array[itemOffset + offset] = particleRandom(array, itemOffset, stream);
208
+ }
163
209
  }
164
- builtin.needsUpdate = true;
165
210
  }
166
- for (const spawnModule of this.spawnSequence) {
167
- spawnModule.spawn(this.mesh.propertyBuffers, instanceBegin, instanceEnd);
211
+ for (let index = 0; index < this.spawnSequence.length; index++) {
212
+ this.spawnSequence[index].spawn(this.mesh.propertyBuffers, instanceBegin, instanceEnd, EMITTER_SPAWN_SALT_BASE + index);
168
213
  }
214
+ this.mesh.limitUploadToLiveInstances();
169
215
  }
170
216
  /** Removes all active particles */
171
217
  clear() {
@@ -1,16 +1,22 @@
1
1
  export { UIBehaviorDirectionalGravity } from "./behaviorModules/UIBehaviorDirectionalGravity.js";
2
+ export { UIBehaviorModule } from "./behaviorModules/UIBehaviorModule.js";
2
3
  export { UIBehaviorPointGravity } from "./behaviorModules/UIBehaviorPointGravity.js";
3
- export { UIBehaviorScaleOscillation } from "./behaviorModules/UIBehaviorScaleOscillation.js";
4
4
  export type { UIScaleOscillationAxis } from "./behaviorModules/UIBehaviorScaleOscillation.js";
5
+ export { UIBehaviorScaleOscillation } from "./behaviorModules/UIBehaviorScaleOscillation.js";
5
6
  export { UIBehaviorScaleOverLife } from "./behaviorModules/UIBehaviorScaleOverLife.js";
6
7
  export { UIBehaviorTorqueDamping } from "./behaviorModules/UIBehaviorTorqueDamping.js";
7
8
  export { UIBehaviorTorqueNoise } from "./behaviorModules/UIBehaviorTorqueNoise.js";
8
9
  export { UIBehaviorVelocityDamping } from "./behaviorModules/UIBehaviorVelocityDamping.js";
9
10
  export { UIBehaviorVelocityNoise } from "./behaviorModules/UIBehaviorVelocityNoise.js";
11
+ export type { UIEmitterMode, UIEmitterOptions, UIEmitterPlayOptions, } from "./elements/UIEmitter.Internal.js";
10
12
  export { UIEmitter } from "./elements/UIEmitter.js";
13
+ export type { UIAspectConfig, UIRange, UIRangeConfig, UIVector2Config, } from "./miscellaneous/miscellaneous.js";
14
+ export { particleRandom, particleRandomStream } from "./miscellaneous/miscellaneous.js";
11
15
  export { UIRenderingColorOverLife } from "./renderingModules/UIRenderingColorOverLife.js";
12
16
  export { UIRenderingColorOverVelocity } from "./renderingModules/UIRenderingColorOverVelocity.js";
17
+ export { UIRenderingModule } from "./renderingModules/UIRenderingModule.js";
13
18
  export { UIRenderingTexture } from "./renderingModules/UIRenderingTexture.js";
19
+ export { UISpawnModule } from "./spawnModules/UISpawnModule.js";
14
20
  export { UISpawnOffset } from "./spawnModules/UISpawnOffset.js";
15
21
  export { UISpawnRandomLifetime } from "./spawnModules/UISpawnRandomLifetime.js";
16
22
  export { UISpawnRandomRotation } from "./spawnModules/UISpawnRandomRotation.js";
@@ -1,4 +1,5 @@
1
1
  export { UIBehaviorDirectionalGravity } from "./behaviorModules/UIBehaviorDirectionalGravity.js";
2
+ export { UIBehaviorModule } from "./behaviorModules/UIBehaviorModule.js";
2
3
  export { UIBehaviorPointGravity } from "./behaviorModules/UIBehaviorPointGravity.js";
3
4
  export { UIBehaviorScaleOscillation } from "./behaviorModules/UIBehaviorScaleOscillation.js";
4
5
  export { UIBehaviorScaleOverLife } from "./behaviorModules/UIBehaviorScaleOverLife.js";
@@ -7,9 +8,12 @@ export { UIBehaviorTorqueNoise } from "./behaviorModules/UIBehaviorTorqueNoise.j
7
8
  export { UIBehaviorVelocityDamping } from "./behaviorModules/UIBehaviorVelocityDamping.js";
8
9
  export { UIBehaviorVelocityNoise } from "./behaviorModules/UIBehaviorVelocityNoise.js";
9
10
  export { UIEmitter } from "./elements/UIEmitter.js";
11
+ export { particleRandom, particleRandomStream } from "./miscellaneous/miscellaneous.js";
10
12
  export { UIRenderingColorOverLife } from "./renderingModules/UIRenderingColorOverLife.js";
11
13
  export { UIRenderingColorOverVelocity } from "./renderingModules/UIRenderingColorOverVelocity.js";
14
+ export { UIRenderingModule } from "./renderingModules/UIRenderingModule.js";
12
15
  export { UIRenderingTexture } from "./renderingModules/UIRenderingTexture.js";
16
+ export { UISpawnModule } from "./spawnModules/UISpawnModule.js";
13
17
  export { UISpawnOffset } from "./spawnModules/UISpawnOffset.js";
14
18
  export { UISpawnRandomLifetime } from "./spawnModules/UISpawnRandomLifetime.js";
15
19
  export { UISpawnRandomRotation } from "./spawnModules/UISpawnRandomRotation.js";
@@ -4,9 +4,24 @@ export declare const INSTANCED_PARTICLE_GEOMETRY: InstancedBufferGeometry;
4
4
  export declare function collectProperties(keeper: Record<string, GLTypeInfo>, modules: readonly {
5
5
  requiredProperties?: Record<string, UIPropertyName>;
6
6
  }[], debugContext: string): void;
7
- export declare function collectUniforms(keeper: Record<string, GLProperty>, modules: readonly {
7
+ /**
8
+ * Collects the uniforms of rendering modules under per-module names, `p_<name>` of module i
9
+ * becoming `p_m<i>_<name>`, so modules of one type keep their own values.
10
+ * @returns Sources with their uniform references renamed accordingly
11
+ */
12
+ export declare function collectRenderingUniforms(keeper: Record<string, GLProperty>, modules: readonly {
8
13
  requiredUniforms: Record<string, UIProperty>;
9
- }[], debugContext: string): void;
14
+ source: string;
15
+ }[], debugContext: string): string[];
10
16
  export declare function buildParticleVertexShader(uniformDeclarations: string[], attributeDeclarations: string[], varyingDeclarations: string[], vertexAssignments: string[]): string;
11
- export declare function buildParticleFragmentShader(uniformDeclarations: string[], varyingDeclarations: string[], sources: string[]): string;
12
- export declare function buildParticleMaterial(sources: string[], uniformProperties: Record<string, GLProperty>, varyingProperties: Record<string, GLTypeInfo>): ShaderMaterial;
17
+ /**
18
+ * Builds the fragment shader of a particle mesh. Sources read particle values through the
19
+ * PARTICLE_* macros and properties as p_* globals, all filled from packed varyings.
20
+ * @param fieldDeclarations Packed varyings, p_* globals and PARTICLE_* macros
21
+ * @param fieldAssignments Statements filling the p_* globals at the start of main
22
+ */
23
+ export declare function buildParticleFragmentShader(uniformDeclarations: string[], fieldDeclarations: string[], fieldAssignments: string[], sources: string[]): string;
24
+ export declare function buildParticleMaterial(sources: string[], uniformProperties: Record<string, GLProperty>, varyingProperties: Record<string, GLTypeInfo>): {
25
+ material: ShaderMaterial;
26
+ varyingRowCount: number;
27
+ };