laymur 0.27.1 → 0.28.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 (82) hide show
  1. package/README.md +46 -1
  2. package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.js +2 -1
  3. package/dist/core/constraints/UICustomConstraint.js +1 -1
  4. package/dist/core/constraints/UIHeightConstraint/UIHeightConstraint.js +2 -1
  5. package/dist/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.js +2 -1
  6. package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +2 -1
  7. package/dist/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.js +2 -1
  8. package/dist/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.js +2 -1
  9. package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +2 -1
  10. package/dist/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.js +2 -1
  11. package/dist/core/constraints/UIWidthConstraint/UIWidthConstraint.js +2 -1
  12. package/dist/core/constraints/constraintAsserts.d.ts +41 -0
  13. package/dist/core/constraints/constraintAsserts.js +171 -0
  14. package/dist/core/elements/UIDummy/UIDummy.d.ts +8 -5
  15. package/dist/core/elements/UIDummy/UIDummy.js +21 -10
  16. package/dist/core/elements/UIElement/UIElement.Internal.d.ts +6 -5
  17. package/dist/core/elements/UIElement/UIElement.Internal.js +0 -4
  18. package/dist/core/elements/UIElement/UIElement.d.ts +12 -6
  19. package/dist/core/elements/UIElement/UIElement.js +14 -7
  20. package/dist/core/elements/UIText/UIText.d.ts +6 -1
  21. package/dist/core/elements/UIText/UIText.js +22 -12
  22. package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +1 -1
  23. package/dist/core/miscellaneous/UIBlendMode.d.ts +5 -0
  24. package/dist/core/miscellaneous/UIBlendMode.js +7 -0
  25. package/dist/core/miscellaneous/asserts.d.ts +0 -41
  26. package/dist/core/miscellaneous/asserts.js +0 -170
  27. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +10 -7
  28. package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.js +11 -8
  29. package/dist/core/miscellaneous/text-style/UITextStyle.Internal.d.ts +4 -1
  30. package/dist/core/miscellaneous/text-style/UITextStyle.d.ts +4 -1
  31. package/dist/core/miscellaneous/text-style/UITextStyle.js +4 -1
  32. package/dist/core/shaders/UIProgressMaskFunctionCircular.js +1 -2
  33. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +6 -2
  34. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +1 -0
  35. package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +18 -9
  36. package/dist/particles/behaviorModules/UIBehaviorAlignToVelocity.d.ts +44 -0
  37. package/dist/particles/behaviorModules/UIBehaviorAlignToVelocity.js +75 -0
  38. package/dist/particles/behaviorModules/UIBehaviorBounce.d.ts +51 -0
  39. package/dist/particles/behaviorModules/UIBehaviorBounce.js +107 -0
  40. package/dist/particles/behaviorModules/UIBehaviorOrbit.d.ts +39 -0
  41. package/dist/particles/behaviorModules/UIBehaviorOrbit.js +73 -0
  42. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +7 -2
  43. package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +9 -5
  44. package/dist/particles/behaviorModules/UIBehaviorSeek.d.ts +38 -0
  45. package/dist/particles/behaviorModules/UIBehaviorSeek.js +75 -0
  46. package/dist/particles/elements/UIEmitter.Internal.d.ts +45 -1
  47. package/dist/particles/elements/UIEmitter.Internal.js +25 -1
  48. package/dist/particles/elements/UIEmitter.Schedule.d.ts +31 -0
  49. package/dist/particles/elements/UIEmitter.Schedule.js +81 -0
  50. package/dist/particles/elements/UIEmitter.d.ts +79 -9
  51. package/dist/particles/elements/UIEmitter.js +239 -82
  52. package/dist/particles/index.d.ts +13 -1
  53. package/dist/particles/index.js +11 -1
  54. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +6 -0
  55. package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +27 -0
  56. package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +7 -1
  57. package/dist/particles/instancedParticle/UIInstancedParticle.js +12 -1
  58. package/dist/particles/miscellaneous/miscellaneous.d.ts +22 -0
  59. package/dist/particles/miscellaneous/miscellaneous.js +38 -0
  60. package/dist/particles/renderingModules/UIRenderingFlipbook.d.ts +41 -0
  61. package/dist/particles/renderingModules/UIRenderingFlipbook.js +70 -0
  62. package/dist/particles/renderingModules/UIRenderingModule.d.ts +2 -1
  63. package/dist/particles/renderingModules/UIRenderingModule.js +2 -1
  64. package/dist/particles/renderingModules/UIRenderingRandomColor.d.ts +19 -0
  65. package/dist/particles/renderingModules/UIRenderingRandomColor.js +28 -0
  66. package/dist/particles/renderingModules/UIRenderingShape.d.ts +31 -0
  67. package/dist/particles/renderingModules/UIRenderingShape.js +54 -0
  68. package/dist/particles/renderingModules/UIRenderingTexture.d.ts +1 -1
  69. package/dist/particles/renderingModules/UIRenderingTexture.js +4 -28
  70. package/dist/particles/shaders/UIRenderingFlipbook.d.ts +5 -0
  71. package/dist/particles/shaders/UIRenderingFlipbook.js +19 -0
  72. package/dist/particles/shaders/UIRenderingRandomColor.d.ts +2 -0
  73. package/dist/particles/shaders/UIRenderingRandomColor.js +10 -0
  74. package/dist/particles/shaders/UIRenderingShape.d.ts +6 -0
  75. package/dist/particles/shaders/UIRenderingShape.js +15 -0
  76. package/dist/particles/shaders/UIRenderingTexture.d.ts +4 -2
  77. package/dist/particles/shaders/UIRenderingTexture.js +27 -2
  78. package/dist/particles/spawnModules/UISpawnCircle.d.ts +44 -0
  79. package/dist/particles/spawnModules/UISpawnCircle.js +81 -0
  80. package/dist/particles/spawnModules/UISpawnRadialVelocity.d.ts +37 -0
  81. package/dist/particles/spawnModules/UISpawnRadialVelocity.js +75 -0
  82. package/package.json +1 -1
@@ -0,0 +1,75 @@
1
+ import { assertValidNonNegativeNumber, assertValidNumber, assertValidPositiveNumber, } from "../../core/miscellaneous/asserts.js";
2
+ import { BUILTIN_OFFSET_ROTATION, BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, resolveAspect, } from "../miscellaneous/miscellaneous.js";
3
+ import { UIBehaviorModule } from "./UIBehaviorModule.js";
4
+ /**
5
+ * Turns the X axis of particles along their velocity and stretches them along it with speed, as
6
+ * motion blur of sparks and streaks.
7
+ *
8
+ * Sets the rotation every frame, so torque has no effect. The length is derived from the Y scale,
9
+ * so the module composes with any scale source: put it after `UISpawnRandomScale` or
10
+ * `UIBehaviorScaleOverLife` in the sequence. A particle at rest keeps its rotation.
11
+ */
12
+ export class UIBehaviorAlignToVelocity extends UIBehaviorModule {
13
+ /**
14
+ * @param stretch - Seconds of motion added to the length: the length grows by speed * stretch
15
+ * @param aspect - Width/height ratio at rest, the same as given to the scale module. Accepts
16
+ * number or texture
17
+ * @param rotationOffset - Angle in radians added to the direction, for sprites drawn along
18
+ * another axis
19
+ */
20
+ constructor(stretch = 0, aspect = 1, rotationOffset = 0) {
21
+ super();
22
+ this.requiredProperties = { builtin: "Matrix4" };
23
+ this.stretchInternal = stretch;
24
+ this.aspectInternal = resolveAspect(aspect);
25
+ this.rotationOffsetInternal = rotationOffset;
26
+ assertValidNonNegativeNumber(stretch, "UIBehaviorAlignToVelocity.constructor.stretch");
27
+ assertValidPositiveNumber(this.aspectInternal, "UIBehaviorAlignToVelocity.constructor.aspect");
28
+ assertValidNumber(rotationOffset, "UIBehaviorAlignToVelocity.constructor.rotationOffset");
29
+ }
30
+ /** Seconds of motion added to the length */
31
+ get stretch() {
32
+ return this.stretchInternal;
33
+ }
34
+ /** Width/height aspect ratio at rest */
35
+ get aspect() {
36
+ return this.aspectInternal;
37
+ }
38
+ /** Angle in radians added to the direction */
39
+ get rotationOffset() {
40
+ return this.rotationOffsetInternal;
41
+ }
42
+ /** Seconds of motion added to the length */
43
+ set stretch(value) {
44
+ assertValidNonNegativeNumber(value, "UIBehaviorAlignToVelocity.stretch");
45
+ this.stretchInternal = value;
46
+ }
47
+ /** Width/height aspect ratio at rest */
48
+ set aspect(value) {
49
+ this.aspectInternal = resolveAspect(value);
50
+ assertValidPositiveNumber(this.aspectInternal, "UIBehaviorAlignToVelocity.aspect");
51
+ }
52
+ /** Angle in radians added to the direction */
53
+ set rotationOffset(value) {
54
+ assertValidNumber(value, "UIBehaviorAlignToVelocity.rotationOffset");
55
+ this.rotationOffsetInternal = value;
56
+ }
57
+ update(properties, instanceCount) {
58
+ const { builtin } = properties;
59
+ const { array, itemSize } = builtin;
60
+ for (let i = 0; i < instanceCount; i++) {
61
+ const itemOffset = i * itemSize;
62
+ const velocityX = array[itemOffset + BUILTIN_OFFSET_VELOCITY_X];
63
+ const velocityY = array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y];
64
+ const speed = Math.hypot(velocityX, velocityY);
65
+ if (speed > 0) {
66
+ array[itemOffset + BUILTIN_OFFSET_ROTATION] =
67
+ Math.atan2(velocityY, velocityX) + this.rotationOffsetInternal;
68
+ }
69
+ array[itemOffset + BUILTIN_OFFSET_SCALE_X] =
70
+ array[itemOffset + BUILTIN_OFFSET_SCALE_Y] * this.aspectInternal +
71
+ speed * this.stretchInternal;
72
+ }
73
+ builtin.needsUpdate = true;
74
+ }
75
+ }
@@ -0,0 +1,51 @@
1
+ import type { InstancedBufferAttribute } from "three";
2
+ import type { Vector2Like } from "../../core/miscellaneous/math.js";
3
+ import type { UIVector2Config } from "../miscellaneous/miscellaneous.js";
4
+ import { UIBehaviorModule } from "./UIBehaviorModule.js";
5
+ /**
6
+ * Keeps particles on one side of a line and bounces them off it, as a floor or a wall.
7
+ *
8
+ * The line passes through a point, and its normal points to the free side. A particle behind it
9
+ * is put back on the line, the velocity into it is reflected and scaled by the restitution, and
10
+ * the velocity along it decays by the friction while in contact, as `UIBehaviorVelocityDamping`
11
+ * does. The point and the normal are in the particle space of the emitter.
12
+ */
13
+ export declare class UIBehaviorBounce extends UIBehaviorModule<{
14
+ builtin: "Matrix4";
15
+ }> {
16
+ readonly requiredProperties: {
17
+ readonly builtin: "Matrix4";
18
+ };
19
+ private pointInternal;
20
+ private normalX;
21
+ private normalY;
22
+ private restitutionInternal;
23
+ private frictionInternal;
24
+ /**
25
+ * @param point - A point of the line
26
+ * @param normal - Direction to the free side, normalized by the module
27
+ * @param restitution - Share of the speed into the line kept after a bounce, from 0 to 1
28
+ * @param friction - Share of the speed along the line lost per second of contact, from 0 to 1
29
+ */
30
+ constructor(point: UIVector2Config, normal?: UIVector2Config, restitution?: number, friction?: number);
31
+ /** A point of the line */
32
+ get point(): Vector2Like;
33
+ /** Unit direction to the free side */
34
+ get normal(): Vector2Like;
35
+ /** Share of the speed into the line kept after a bounce */
36
+ get restitution(): number;
37
+ /** Share of the speed along the line lost per second of contact */
38
+ get friction(): number;
39
+ /** A point of the line */
40
+ set point(value: UIVector2Config);
41
+ /** Direction to the free side, normalized by the module */
42
+ set normal(value: UIVector2Config);
43
+ /** Share of the speed into the line kept after a bounce */
44
+ set restitution(value: number);
45
+ /** Share of the speed along the line lost per second of contact */
46
+ set friction(value: number);
47
+ update(properties: {
48
+ builtin: InstancedBufferAttribute;
49
+ }, instanceCount: number, deltaTime: number): void;
50
+ private setNormal;
51
+ }
@@ -0,0 +1,107 @@
1
+ import { assertValidNumber, assertValidUnitNumber } from "../../core/miscellaneous/asserts.js";
2
+ import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, resolveUIVector2Config, } from "../miscellaneous/miscellaneous.js";
3
+ import { UIBehaviorModule } from "./UIBehaviorModule.js";
4
+ /**
5
+ * Keeps particles on one side of a line and bounces them off it, as a floor or a wall.
6
+ *
7
+ * The line passes through a point, and its normal points to the free side. A particle behind it
8
+ * is put back on the line, the velocity into it is reflected and scaled by the restitution, and
9
+ * the velocity along it decays by the friction while in contact, as `UIBehaviorVelocityDamping`
10
+ * does. The point and the normal are in the particle space of the emitter.
11
+ */
12
+ export class UIBehaviorBounce extends UIBehaviorModule {
13
+ /**
14
+ * @param point - A point of the line
15
+ * @param normal - Direction to the free side, normalized by the module
16
+ * @param restitution - Share of the speed into the line kept after a bounce, from 0 to 1
17
+ * @param friction - Share of the speed along the line lost per second of contact, from 0 to 1
18
+ */
19
+ constructor(point, normal = { x: 0, y: 1 }, restitution = 0.5, friction = 0.9) {
20
+ super();
21
+ this.requiredProperties = { builtin: "Matrix4" };
22
+ this.normalX = 0;
23
+ this.normalY = 1;
24
+ this.pointInternal = resolveUIVector2Config(point);
25
+ assertValidNumber(this.pointInternal.x, "UIBehaviorBounce.constructor.point.x");
26
+ assertValidNumber(this.pointInternal.y, "UIBehaviorBounce.constructor.point.y");
27
+ this.setNormal(normal, "UIBehaviorBounce.constructor.normal");
28
+ assertValidUnitNumber(restitution, "UIBehaviorBounce.constructor.restitution");
29
+ assertValidUnitNumber(friction, "UIBehaviorBounce.constructor.friction");
30
+ this.restitutionInternal = restitution;
31
+ this.frictionInternal = friction;
32
+ }
33
+ /** A point of the line */
34
+ get point() {
35
+ return this.pointInternal;
36
+ }
37
+ /** Unit direction to the free side */
38
+ get normal() {
39
+ return { x: this.normalX, y: this.normalY };
40
+ }
41
+ /** Share of the speed into the line kept after a bounce */
42
+ get restitution() {
43
+ return this.restitutionInternal;
44
+ }
45
+ /** Share of the speed along the line lost per second of contact */
46
+ get friction() {
47
+ return this.frictionInternal;
48
+ }
49
+ /** A point of the line */
50
+ set point(value) {
51
+ this.pointInternal = resolveUIVector2Config(value);
52
+ assertValidNumber(this.pointInternal.x, "UIBehaviorBounce.point.x");
53
+ assertValidNumber(this.pointInternal.y, "UIBehaviorBounce.point.y");
54
+ }
55
+ /** Direction to the free side, normalized by the module */
56
+ set normal(value) {
57
+ this.setNormal(value, "UIBehaviorBounce.normal");
58
+ }
59
+ /** Share of the speed into the line kept after a bounce */
60
+ set restitution(value) {
61
+ assertValidUnitNumber(value, "UIBehaviorBounce.restitution");
62
+ this.restitutionInternal = value;
63
+ }
64
+ /** Share of the speed along the line lost per second of contact */
65
+ set friction(value) {
66
+ assertValidUnitNumber(value, "UIBehaviorBounce.friction");
67
+ this.frictionInternal = value;
68
+ }
69
+ update(properties, instanceCount, deltaTime) {
70
+ const { builtin } = properties;
71
+ const { array, itemSize } = builtin;
72
+ const { x: pointX, y: pointY } = this.pointInternal;
73
+ const { normalX, normalY } = this;
74
+ const keptAlong = Math.pow(1 - this.frictionInternal, deltaTime);
75
+ for (let i = 0; i < instanceCount; i++) {
76
+ const itemOffset = i * itemSize;
77
+ const depth = (array[itemOffset + BUILTIN_OFFSET_POSITION_X] - pointX) * normalX +
78
+ (array[itemOffset + BUILTIN_OFFSET_POSITION_Y] - pointY) * normalY;
79
+ if (depth >= 0) {
80
+ continue;
81
+ }
82
+ array[itemOffset + BUILTIN_OFFSET_POSITION_X] -= normalX * depth;
83
+ array[itemOffset + BUILTIN_OFFSET_POSITION_Y] -= normalY * depth;
84
+ const velocityX = array[itemOffset + BUILTIN_OFFSET_VELOCITY_X];
85
+ const velocityY = array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y];
86
+ // Split into the parts across the line (normal * across) and along it
87
+ const across = velocityX * normalX + velocityY * normalY;
88
+ const alongX = velocityX - normalX * across;
89
+ const alongY = velocityY - normalY * across;
90
+ const acrossAfter = across < 0 ? -across * this.restitutionInternal : across;
91
+ array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] = alongX * keptAlong + normalX * acrossAfter;
92
+ array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] = alongY * keptAlong + normalY * acrossAfter;
93
+ }
94
+ builtin.needsUpdate = true;
95
+ }
96
+ setNormal(value, subject) {
97
+ const { x, y } = resolveUIVector2Config(value);
98
+ assertValidNumber(x, `${subject}.x`);
99
+ assertValidNumber(y, `${subject}.y`);
100
+ const length = Math.hypot(x, y);
101
+ if (length === 0) {
102
+ throw new Error(`${subject}: normal must not be zero`);
103
+ }
104
+ this.normalX = x / length;
105
+ this.normalY = y / length;
106
+ }
107
+ }
@@ -0,0 +1,39 @@
1
+ import type { InstancedBufferAttribute } from "three";
2
+ import type { Vector2Like } from "../../core/miscellaneous/math.js";
3
+ import type { UIRange, UIRangeConfig, UIVector2Config } from "../miscellaneous/miscellaneous.js";
4
+ import { UIBehaviorModule } from "./UIBehaviorModule.js";
5
+ /**
6
+ * Turns the motion of particles around a center: position and velocity rotate together at an
7
+ * angular speed, so a particle at rest circles the center at its distance and one moving outward
8
+ * spirals.
9
+ *
10
+ * The rotation is kinematic, not a force: the distance to the center stays unless the velocity
11
+ * changes it. The center is in the particle space of the emitter.
12
+ */
13
+ export declare class UIBehaviorOrbit extends UIBehaviorModule<{
14
+ builtin: "Matrix4";
15
+ }> {
16
+ readonly requiredProperties: {
17
+ readonly builtin: "Matrix4";
18
+ };
19
+ private centerInternal;
20
+ private angularSpeedInternal;
21
+ /**
22
+ * @param angularSpeed - Radians per second, counter-clockwise for positive values. Accepts
23
+ * number, tuple, or range object
24
+ * @param center - Center of the rotation
25
+ */
26
+ constructor(angularSpeed: UIRangeConfig, center?: UIVector2Config);
27
+ /** Radians per second, counter-clockwise for positive values */
28
+ get angularSpeed(): UIRange;
29
+ /** Center of the rotation */
30
+ get center(): Vector2Like;
31
+ /** Radians per second, counter-clockwise for positive values */
32
+ set angularSpeed(value: UIRangeConfig);
33
+ /** Center of the rotation */
34
+ set center(value: UIVector2Config);
35
+ update(properties: {
36
+ builtin: InstancedBufferAttribute;
37
+ }, instanceCount: number, deltaTime: number, randomSalt: number): void;
38
+ private assertValid;
39
+ }
@@ -0,0 +1,73 @@
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_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, particleRandom, particleRandomStream, resolveUIRangeConfig, resolveUIVector2Config, } from "../miscellaneous/miscellaneous.js";
4
+ import { UIBehaviorModule } from "./UIBehaviorModule.js";
5
+ /**
6
+ * Turns the motion of particles around a center: position and velocity rotate together at an
7
+ * angular speed, so a particle at rest circles the center at its distance and one moving outward
8
+ * spirals.
9
+ *
10
+ * The rotation is kinematic, not a force: the distance to the center stays unless the velocity
11
+ * changes it. The center is in the particle space of the emitter.
12
+ */
13
+ export class UIBehaviorOrbit extends UIBehaviorModule {
14
+ /**
15
+ * @param angularSpeed - Radians per second, counter-clockwise for positive values. Accepts
16
+ * number, tuple, or range object
17
+ * @param center - Center of the rotation
18
+ */
19
+ constructor(angularSpeed, center = 0) {
20
+ super();
21
+ this.requiredProperties = { builtin: "Matrix4" };
22
+ this.angularSpeedInternal = resolveUIRangeConfig(angularSpeed);
23
+ this.centerInternal = resolveUIVector2Config(center);
24
+ this.assertValid("UIBehaviorOrbit.constructor");
25
+ }
26
+ /** Radians per second, counter-clockwise for positive values */
27
+ get angularSpeed() {
28
+ return this.angularSpeedInternal;
29
+ }
30
+ /** Center of the rotation */
31
+ get center() {
32
+ return this.centerInternal;
33
+ }
34
+ /** Radians per second, counter-clockwise for positive values */
35
+ set angularSpeed(value) {
36
+ this.angularSpeedInternal = resolveUIRangeConfig(value);
37
+ this.assertValid("UIBehaviorOrbit");
38
+ }
39
+ /** Center of the rotation */
40
+ set center(value) {
41
+ this.centerInternal = resolveUIVector2Config(value);
42
+ this.assertValid("UIBehaviorOrbit");
43
+ }
44
+ update(properties, instanceCount, deltaTime, randomSalt) {
45
+ const { builtin } = properties;
46
+ const { array, itemSize } = builtin;
47
+ const { x: centerX, y: centerY } = this.centerInternal;
48
+ const { min: speedMin, max: speedMax } = this.angularSpeedInternal;
49
+ const speedStream = particleRandomStream(randomSalt, 0);
50
+ for (let i = 0; i < instanceCount; i++) {
51
+ const itemOffset = i * itemSize;
52
+ const angle = MathUtils.lerp(speedMin, speedMax, particleRandom(array, itemOffset, speedStream)) *
53
+ deltaTime;
54
+ const cos = Math.cos(angle);
55
+ const sin = Math.sin(angle);
56
+ const offsetX = array[itemOffset + BUILTIN_OFFSET_POSITION_X] - centerX;
57
+ const offsetY = array[itemOffset + BUILTIN_OFFSET_POSITION_Y] - centerY;
58
+ array[itemOffset + BUILTIN_OFFSET_POSITION_X] = centerX + offsetX * cos - offsetY * sin;
59
+ array[itemOffset + BUILTIN_OFFSET_POSITION_Y] = centerY + offsetX * sin + offsetY * cos;
60
+ const velocityX = array[itemOffset + BUILTIN_OFFSET_VELOCITY_X];
61
+ const velocityY = array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y];
62
+ array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] = velocityX * cos - velocityY * sin;
63
+ array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] = velocityX * sin + velocityY * cos;
64
+ }
65
+ builtin.needsUpdate = true;
66
+ }
67
+ assertValid(subject) {
68
+ assertValidNumber(this.angularSpeedInternal.min, `${subject}.angularSpeed.min`);
69
+ assertValidNumber(this.angularSpeedInternal.max, `${subject}.angularSpeed.max`);
70
+ assertValidNumber(this.centerInternal.x, `${subject}.center.x`);
71
+ assertValidNumber(this.centerInternal.y, `${subject}.center.y`);
72
+ }
73
+ }
@@ -1,10 +1,12 @@
1
1
  import type { InstancedBufferAttribute } from "three";
2
2
  import type { UIAspectConfig, UIRangeConfig } from "../miscellaneous/miscellaneous.js";
3
+ import { UIEasing } from "../miscellaneous/miscellaneous.js";
3
4
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
4
5
  /**
5
6
  * Animates particle scale over lifetime.
6
7
  *
7
- * Interpolates between scale anchors based on particle age. Requires at least 2 anchors.
8
+ * Interpolates between scale anchors based on particle age, with the easing within each span
9
+ * between two anchors. Requires at least 2 anchors.
8
10
  */
9
11
  export declare class UIBehaviorScaleOverLife extends UIBehaviorModule<{
10
12
  builtin: "Matrix4";
@@ -12,13 +14,16 @@ export declare class UIBehaviorScaleOverLife extends UIBehaviorModule<{
12
14
  readonly requiredProperties: {
13
15
  readonly builtin: "Matrix4";
14
16
  };
17
+ /** Easing within each span between two anchors */
18
+ easing: UIEasing;
15
19
  private readonly scales;
16
20
  private aspectInternal;
17
21
  /**
18
22
  * @param scales - Scale anchor points. Each accepts number, tuple, or range object
19
23
  * @param aspect - Width/height ratio. Accepts number or texture
24
+ * @param easing - Easing within each span between two anchors
20
25
  */
21
- constructor(scales: UIRangeConfig[], aspect?: UIAspectConfig);
26
+ constructor(scales: UIRangeConfig[], aspect?: UIAspectConfig, easing?: UIEasing);
22
27
  /** Width/height aspect ratio */
23
28
  get aspect(): number;
24
29
  /** Width/height aspect ratio */
@@ -1,21 +1,24 @@
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_SCALE_X, BUILTIN_OFFSET_SCALE_Y, particleRandom, particleRandomStream, resolveAspect, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
3
+ import { applyEasing, BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME, BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y, particleRandom, particleRandomStream, resolveAspect, resolveUIRangeConfig, UIEasing, } from "../miscellaneous/miscellaneous.js";
4
4
  import { UIBehaviorModule } from "./UIBehaviorModule.js";
5
5
  /**
6
6
  * Animates particle scale over lifetime.
7
7
  *
8
- * Interpolates between scale anchors based on particle age. Requires at least 2 anchors.
8
+ * Interpolates between scale anchors based on particle age, with the easing within each span
9
+ * between two anchors. Requires at least 2 anchors.
9
10
  */
10
11
  export class UIBehaviorScaleOverLife extends UIBehaviorModule {
11
12
  /**
12
13
  * @param scales - Scale anchor points. Each accepts number, tuple, or range object
13
14
  * @param aspect - Width/height ratio. Accepts number or texture
15
+ * @param easing - Easing within each span between two anchors
14
16
  */
15
- constructor(scales, aspect = 1) {
17
+ constructor(scales, aspect = 1, easing = UIEasing.LINEAR) {
16
18
  super();
17
19
  this.requiredProperties = { builtin: "Matrix4" };
18
20
  this.scales = [];
21
+ this.easing = easing;
19
22
  if (scales.length < 2) {
20
23
  throw new Error(`UIBehaviorScaleOverLife.constructor.scales: at least two scale anchors are required, got ${scales.length}`);
21
24
  }
@@ -45,9 +48,10 @@ export class UIBehaviorScaleOverLife extends UIBehaviorModule {
45
48
  const itemOffset = i * itemSize;
46
49
  const lifeT = Math.min(array[itemOffset + BUILTIN_OFFSET_AGE] / array[itemOffset + BUILTIN_OFFSET_LIFETIME], 1);
47
50
  const segment = (this.scales.length - 1) * lifeT;
48
- const index = Math.floor(segment);
51
+ // The last span also takes lifeT = 1, of a particle that outlives its lifetime this frame
52
+ const index = Math.min(Math.floor(segment), this.scales.length - 2);
49
53
  const scaleT = particleRandom(array, itemOffset, scaleStream);
50
- const localT = segment - index;
54
+ const localT = applyEasing(this.easing, segment - index);
51
55
  const scaleRange0 = this.scales[index];
52
56
  const scaleRange1 = this.scales[index + 1];
53
57
  const scale0 = MathUtils.lerp(scaleRange0.min, scaleRange0.max, scaleT);
@@ -0,0 +1,38 @@
1
+ import type { InstancedBufferAttribute } from "three";
2
+ import type { Vector2Like } from "../../core/miscellaneous/math.js";
3
+ import type { UIVector2Config } from "../miscellaneous/miscellaneous.js";
4
+ import { UIBehaviorModule } from "./UIBehaviorModule.js";
5
+ /**
6
+ * Steers particles into a target point at the end of their life, such as coins flying into a
7
+ * counter. With `UIEmitter.signalParticleDied` the death of a particle marks its arrival.
8
+ *
9
+ * Each frame the particle gets the constant acceleration that would bring it from its position and
10
+ * velocity to the target in the life left, so it keeps its initial motion and curves into the
11
+ * target. Put it last in the behavior sequence: modules after it move the particle off course.
12
+ * The target is in the particle space of the emitter.
13
+ */
14
+ export declare class UIBehaviorSeek extends UIBehaviorModule<{
15
+ builtin: "Matrix4";
16
+ }> {
17
+ readonly requiredProperties: {
18
+ readonly builtin: "Matrix4";
19
+ };
20
+ private targetInternal;
21
+ private delayInternal;
22
+ /**
23
+ * @param target - Point the particles arrive at
24
+ * @param delay - Part of the life before steering starts, from 0 to 1
25
+ */
26
+ constructor(target: UIVector2Config, delay?: number);
27
+ /** Point the particles arrive at */
28
+ get target(): Vector2Like;
29
+ /** Part of the life before steering starts */
30
+ get delay(): number;
31
+ /** Point the particles arrive at */
32
+ set target(value: UIVector2Config);
33
+ /** Part of the life before steering starts */
34
+ set delay(value: number);
35
+ update(properties: {
36
+ builtin: InstancedBufferAttribute;
37
+ }, instanceCount: number, deltaTime: number): void;
38
+ }
@@ -0,0 +1,75 @@
1
+ import { assertValidNumber } from "../../core/miscellaneous/asserts.js";
2
+ import { assertValidUnitNumber, BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME, BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, resolveUIVector2Config, } from "../miscellaneous/miscellaneous.js";
3
+ import { UIBehaviorModule } from "./UIBehaviorModule.js";
4
+ /**
5
+ * Steers particles into a target point at the end of their life, such as coins flying into a
6
+ * counter. With `UIEmitter.signalParticleDied` the death of a particle marks its arrival.
7
+ *
8
+ * Each frame the particle gets the constant acceleration that would bring it from its position and
9
+ * velocity to the target in the life left, so it keeps its initial motion and curves into the
10
+ * target. Put it last in the behavior sequence: modules after it move the particle off course.
11
+ * The target is in the particle space of the emitter.
12
+ */
13
+ export class UIBehaviorSeek extends UIBehaviorModule {
14
+ /**
15
+ * @param target - Point the particles arrive at
16
+ * @param delay - Part of the life before steering starts, from 0 to 1
17
+ */
18
+ constructor(target, delay = 0) {
19
+ super();
20
+ this.requiredProperties = { builtin: "Matrix4" };
21
+ this.targetInternal = resolveUIVector2Config(target);
22
+ assertValidNumber(this.targetInternal.x, "UIBehaviorSeek.constructor.target.x");
23
+ assertValidNumber(this.targetInternal.y, "UIBehaviorSeek.constructor.target.y");
24
+ assertValidUnitNumber(delay, "UIBehaviorSeek.constructor.delay");
25
+ this.delayInternal = delay;
26
+ }
27
+ /** Point the particles arrive at */
28
+ get target() {
29
+ return this.targetInternal;
30
+ }
31
+ /** Part of the life before steering starts */
32
+ get delay() {
33
+ return this.delayInternal;
34
+ }
35
+ /** Point the particles arrive at */
36
+ set target(value) {
37
+ this.targetInternal = resolveUIVector2Config(value);
38
+ assertValidNumber(this.targetInternal.x, "UIBehaviorSeek.target.x");
39
+ assertValidNumber(this.targetInternal.y, "UIBehaviorSeek.target.y");
40
+ }
41
+ /** Part of the life before steering starts */
42
+ set delay(value) {
43
+ assertValidUnitNumber(value, "UIBehaviorSeek.delay");
44
+ this.delayInternal = value;
45
+ }
46
+ update(properties, instanceCount, deltaTime) {
47
+ const { builtin } = properties;
48
+ const { array, itemSize } = builtin;
49
+ const { x: targetX, y: targetY } = this.targetInternal;
50
+ for (let i = 0; i < instanceCount; i++) {
51
+ const itemOffset = i * itemSize;
52
+ const lifetime = array[itemOffset + BUILTIN_OFFSET_LIFETIME];
53
+ const age = array[itemOffset + BUILTIN_OFFSET_AGE];
54
+ if (age < lifetime * this.delayInternal) {
55
+ continue;
56
+ }
57
+ const offsetX = targetX - array[itemOffset + BUILTIN_OFFSET_POSITION_X];
58
+ const offsetY = targetY - array[itemOffset + BUILTIN_OFFSET_POSITION_Y];
59
+ const timeLeft = lifetime - age;
60
+ if (timeLeft <= deltaTime) {
61
+ // The last frame of the life: the particle lands on the target at its end.
62
+ array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] = offsetX / deltaTime;
63
+ array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] = offsetY / deltaTime;
64
+ continue;
65
+ }
66
+ // p + v * t + a * t^2 / 2 = target at t = timeLeft
67
+ const velocityX = array[itemOffset + BUILTIN_OFFSET_VELOCITY_X];
68
+ const velocityY = array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y];
69
+ const scale = (2 * deltaTime) / (timeLeft * timeLeft);
70
+ array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] += (offsetX - velocityX * timeLeft) * scale;
71
+ array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] += (offsetY - velocityY * timeLeft) * scale;
72
+ }
73
+ builtin.needsUpdate = true;
74
+ }
75
+ }
@@ -1,9 +1,23 @@
1
1
  import type { UIAnchorOptions } from "../../core/elements/UIAnchor/UIAnchor.Internal.js";
2
- import { UIMode } from "../../core/index.js";
2
+ import { UIBlendMode, UIMode } from "../../core/index.js";
3
+ /** Coordinate space of particle positions */
4
+ export declare enum UIEmitterSpace {
5
+ /** Relative to the emitter: live particles move with it */
6
+ LOCAL = 0,
7
+ /** Layer coordinates: a particle stays where it was spawned when the emitter moves */
8
+ WORLD = 1
9
+ }
3
10
  /** Configuration options for UIEmitter */
4
11
  export interface UIEmitterOptions extends UIAnchorOptions {
5
12
  /** Whether the particles are drawn */
6
13
  mode: UIEmitterMode;
14
+ /** Color blending of the particles with what is drawn under them */
15
+ blendMode: UIBlendMode;
16
+ /**
17
+ * Coordinate space of particle positions, and of the points behavior modules take, such as a
18
+ * gravity center. Spawn modules always write positions relative to the emitter.
19
+ */
20
+ space: UIEmitterSpace;
7
21
  /** Number of particles to allocate for up front; a hint, not a limit */
8
22
  expectedCapacity: number;
9
23
  /** Capacity is kept a multiple of this; the buffers double when they grow */
@@ -18,18 +32,48 @@ export interface UIEmitterOptions extends UIAnchorOptions {
18
32
  /** Whether to call destroy() on all modules when the emitter is destroyed */
19
33
  automaticallyDestroyModules: boolean;
20
34
  }
35
+ /** Options of `UIEmitter.play` */
21
36
  export interface UIEmitterPlayOptions {
37
+ /** Seconds of emission, endless by default */
22
38
  duration: number;
39
+ /** Particles per unit of distance the emitter moves, on top of the particles per second */
40
+ ratePerDistance: number;
41
+ /** Particles per burst, the first burst at the start. No bursts by default. */
42
+ burstCount: number;
43
+ /** Seconds between bursts, a single burst by default */
44
+ burstInterval: number;
45
+ }
46
+ /**
47
+ * Path of the emitter over a frame of `time` seconds, in layer coordinates. Particles spawned at a
48
+ * moment of the frame start at the point of that moment, interpolated linearly.
49
+ */
50
+ export interface UISpawnPath {
51
+ time: number;
52
+ fromX: number;
53
+ fromY: number;
54
+ toX: number;
55
+ toY: number;
23
56
  }
24
57
  export declare function ignoreInput(): boolean;
25
58
  export type UIEmitterMode = UIMode.HIDDEN | UIMode.VISIBLE;
26
59
  export declare const EMITTER_DEFAULT_MODE: UIEmitterMode;
60
+ export declare const EMITTER_DEFAULT_BLEND_MODE = UIBlendMode.NORMAL;
61
+ export declare const EMITTER_DEFAULT_SPACE = UIEmitterSpace.LOCAL;
27
62
  export declare const EMITTER_DEFAULT_EXPECTED_CAPACITY = 32;
28
63
  export declare const EMITTER_DEFAULT_CAPACITY_STEP = 32;
29
64
  export declare const EMITTER_DEFAULT_MAX_DELTA_TIME = 0.1;
30
65
  export declare const EMITTER_DEFAULT_LIFETIME = 1;
66
+ export declare const EMITTER_DEFAULT_PREWARM_STEP: number;
31
67
  export declare const EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES = true;
32
68
  /** Salts the emitter hands out: one for the builtin values the shaders read, one per module */
33
69
  export declare const EMITTER_SHADER_SALT = 0;
34
70
  export declare const EMITTER_SPAWN_SALT_BASE = 256;
35
71
  export declare const EMITTER_BEHAVIOR_SALT_BASE = 512;
72
+ /**
73
+ * Moves a particle along its velocity and torque for `time` seconds, negative to move it back
74
+ * @param array Builtin buffer
75
+ * @param itemOffset Offset of the particle in the builtin buffer
76
+ */
77
+ export declare function advanceParticle(array: {
78
+ [index: number]: number;
79
+ }, itemOffset: number, time: number): void;
@@ -1,14 +1,38 @@
1
- import { UIMode } from "../../core/index.js";
1
+ import { UIBlendMode, UIMode } from "../../core/index.js";
2
+ import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_ROTATION, BUILTIN_OFFSET_TORQUE, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, } from "../miscellaneous/miscellaneous.js";
3
+ /** Coordinate space of particle positions */
4
+ export var UIEmitterSpace;
5
+ (function (UIEmitterSpace) {
6
+ /** Relative to the emitter: live particles move with it */
7
+ UIEmitterSpace[UIEmitterSpace["LOCAL"] = 0] = "LOCAL";
8
+ /** Layer coordinates: a particle stays where it was spawned when the emitter moves */
9
+ UIEmitterSpace[UIEmitterSpace["WORLD"] = 1] = "WORLD";
10
+ })(UIEmitterSpace || (UIEmitterSpace = {}));
2
11
  export function ignoreInput() {
3
12
  return false;
4
13
  }
5
14
  export const EMITTER_DEFAULT_MODE = UIMode.VISIBLE;
15
+ export const EMITTER_DEFAULT_BLEND_MODE = UIBlendMode.NORMAL;
16
+ export const EMITTER_DEFAULT_SPACE = UIEmitterSpace.LOCAL;
6
17
  export const EMITTER_DEFAULT_EXPECTED_CAPACITY = 32;
7
18
  export const EMITTER_DEFAULT_CAPACITY_STEP = 32;
8
19
  export const EMITTER_DEFAULT_MAX_DELTA_TIME = 0.1;
9
20
  export const EMITTER_DEFAULT_LIFETIME = 1;
21
+ export const EMITTER_DEFAULT_PREWARM_STEP = 1 / 30;
10
22
  export const EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES = true;
11
23
  /** Salts the emitter hands out: one for the builtin values the shaders read, one per module */
12
24
  export const EMITTER_SHADER_SALT = 0;
13
25
  export const EMITTER_SPAWN_SALT_BASE = 0x100;
14
26
  export const EMITTER_BEHAVIOR_SALT_BASE = 0x200;
27
+ /**
28
+ * Moves a particle along its velocity and torque for `time` seconds, negative to move it back
29
+ * @param array Builtin buffer
30
+ * @param itemOffset Offset of the particle in the builtin buffer
31
+ */
32
+ export function advanceParticle(array, itemOffset, time) {
33
+ array[itemOffset + BUILTIN_OFFSET_POSITION_X] +=
34
+ array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] * time;
35
+ array[itemOffset + BUILTIN_OFFSET_POSITION_Y] +=
36
+ array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] * time;
37
+ array[itemOffset + BUILTIN_OFFSET_ROTATION] += array[itemOffset + BUILTIN_OFFSET_TORQUE] * time;
38
+ }