laymur 0.27.1 → 0.29.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.
- package/README.md +99 -5
- package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.d.ts +14 -3
- package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.js +40 -6
- package/dist/core/constraints/UICustomConstraint.js +2 -2
- package/dist/core/constraints/UIHeightConstraint/UIHeightConstraint.js +3 -2
- package/dist/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.js +3 -2
- package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +3 -2
- package/dist/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.js +3 -2
- package/dist/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.d.ts +6 -0
- package/dist/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.js +8 -0
- package/dist/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.js +3 -2
- package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +3 -2
- package/dist/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.js +3 -2
- package/dist/core/constraints/UIWidthConstraint/UIWidthConstraint.js +3 -2
- package/dist/core/constraints/constraintAsserts.d.ts +41 -0
- package/dist/core/constraints/constraintAsserts.js +171 -0
- package/dist/core/elements/UICanvasElement/UICanvasElement.d.ts +54 -0
- package/dist/core/elements/UICanvasElement/UICanvasElement.js +70 -0
- package/dist/core/elements/UIDummy/UIDummy.Internal.d.ts +2 -0
- package/dist/core/elements/UIDummy/UIDummy.d.ts +8 -5
- package/dist/core/elements/UIDummy/UIDummy.js +24 -11
- package/dist/core/elements/UIElement/UIElement.Internal.d.ts +6 -5
- package/dist/core/elements/UIElement/UIElement.Internal.js +0 -4
- package/dist/core/elements/UIElement/UIElement.d.ts +12 -6
- package/dist/core/elements/UIElement/UIElement.js +14 -7
- package/dist/core/elements/UIGraphics/UIGraphics.Internal.d.ts +42 -2
- package/dist/core/elements/UIGraphics/UIGraphics.Internal.js +2 -2
- package/dist/core/elements/UIGraphics/UIGraphics.d.ts +48 -34
- package/dist/core/elements/UIGraphics/UIGraphics.js +196 -93
- package/dist/core/elements/UIImage/UIImage.d.ts +11 -1
- package/dist/core/elements/UIImage/UIImage.js +14 -0
- package/dist/core/elements/UIScene/UIScene.Internal.d.ts +10 -1
- package/dist/core/elements/UIScene/UIScene.Internal.js +1 -0
- package/dist/core/elements/UIScene/UIScene.d.ts +11 -1
- package/dist/core/elements/UIScene/UIScene.js +29 -5
- package/dist/core/elements/UIText/UIText.Interfaces.d.ts +2 -2
- package/dist/core/elements/UIText/UIText.Internal.d.ts +14 -1
- package/dist/core/elements/UIText/UIText.Internal.js +12 -0
- package/dist/core/elements/UIText/UIText.Measuring.d.ts +9 -4
- package/dist/core/elements/UIText/UIText.Measuring.js +17 -6
- package/dist/core/elements/UIText/UIText.Rendering.d.ts +7 -16
- package/dist/core/elements/UIText/UIText.Rendering.js +212 -46
- package/dist/core/elements/UIText/UIText.d.ts +64 -29
- package/dist/core/elements/UIText/UIText.js +134 -149
- package/dist/core/index.d.ts +10 -4
- package/dist/core/index.js +5 -1
- package/dist/core/layers/UILayer/UILayer.d.ts +17 -3
- package/dist/core/layers/UILayer/UILayer.js +35 -4
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.d.ts +2 -0
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +4 -1
- package/dist/core/miscellaneous/UIBlendMode.d.ts +5 -0
- package/dist/core/miscellaneous/UIBlendMode.js +7 -0
- package/dist/core/miscellaneous/asserts.d.ts +0 -41
- package/dist/core/miscellaneous/asserts.js +0 -170
- package/dist/core/miscellaneous/canvas-surface/UICanvasSurface.d.ts +46 -0
- package/dist/core/miscellaneous/canvas-surface/UICanvasSurface.js +86 -0
- package/dist/core/miscellaneous/color/UIColor.d.ts +17 -0
- package/dist/core/miscellaneous/color/UIColor.js +22 -0
- package/dist/core/miscellaneous/color/canvasColor.d.ts +9 -0
- package/dist/core/miscellaneous/color/canvasColor.js +15 -0
- package/dist/core/miscellaneous/insets/UIInsets.d.ts +3 -0
- package/dist/core/miscellaneous/insets/UIInsets.js +15 -0
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +10 -7
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.js +11 -8
- package/dist/core/miscellaneous/paint/UIGradient.Internal.d.ts +37 -0
- package/dist/core/miscellaneous/paint/UIGradient.Internal.js +14 -0
- package/dist/core/miscellaneous/paint/UIGradient.d.ts +18 -0
- package/dist/core/miscellaneous/paint/UIGradient.js +35 -0
- package/dist/core/miscellaneous/paint/UILinearGradient.d.ts +14 -0
- package/dist/core/miscellaneous/paint/UILinearGradient.js +22 -0
- package/dist/core/miscellaneous/paint/UIPaint.Internal.d.ts +21 -0
- package/dist/core/miscellaneous/paint/UIPaint.Internal.js +1 -0
- package/dist/core/miscellaneous/paint/UIPaint.d.ts +17 -0
- package/dist/core/miscellaneous/paint/UIPaint.js +21 -0
- package/dist/core/miscellaneous/paint/UIRadialGradient.d.ts +18 -0
- package/dist/core/miscellaneous/paint/UIRadialGradient.js +33 -0
- package/dist/core/miscellaneous/shared.d.ts +14 -0
- package/dist/core/miscellaneous/shared.js +11 -0
- package/dist/core/miscellaneous/text-style/UITextStyle.Internal.d.ts +91 -30
- package/dist/core/miscellaneous/text-style/UITextStyle.Internal.js +12 -8
- package/dist/core/miscellaneous/text-style/UITextStyle.d.ts +41 -63
- package/dist/core/miscellaneous/text-style/UITextStyle.js +165 -291
- package/dist/core/miscellaneous/texture/UITextureView.Internal.d.ts +2 -1
- package/dist/core/miscellaneous/texture/UITextureView.Internal.js +12 -3
- package/dist/core/shaders/UIProgressMaskFunctionCircular.js +1 -2
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +7 -3
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +2 -1
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +19 -10
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +6 -2
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.d.ts +41 -9
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.js +97 -35
- package/dist/particles/behaviorModules/UIBehaviorAlignToVelocity.d.ts +44 -0
- package/dist/particles/behaviorModules/UIBehaviorAlignToVelocity.js +75 -0
- package/dist/particles/behaviorModules/UIBehaviorBounce.d.ts +51 -0
- package/dist/particles/behaviorModules/UIBehaviorBounce.js +107 -0
- package/dist/particles/behaviorModules/UIBehaviorOrbit.d.ts +39 -0
- package/dist/particles/behaviorModules/UIBehaviorOrbit.js +73 -0
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +7 -2
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +9 -5
- package/dist/particles/behaviorModules/UIBehaviorSeek.d.ts +38 -0
- package/dist/particles/behaviorModules/UIBehaviorSeek.js +75 -0
- package/dist/particles/elements/UIEmitter.Internal.d.ts +48 -1
- package/dist/particles/elements/UIEmitter.Internal.js +26 -1
- package/dist/particles/elements/UIEmitter.Schedule.d.ts +31 -0
- package/dist/particles/elements/UIEmitter.Schedule.js +81 -0
- package/dist/particles/elements/UIEmitter.d.ts +79 -9
- package/dist/particles/elements/UIEmitter.js +241 -83
- package/dist/particles/index.d.ts +13 -1
- package/dist/particles/index.js +11 -1
- package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +6 -0
- package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +27 -0
- package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +7 -1
- package/dist/particles/instancedParticle/UIInstancedParticle.js +12 -1
- package/dist/particles/miscellaneous/miscellaneous.d.ts +22 -0
- package/dist/particles/miscellaneous/miscellaneous.js +38 -0
- package/dist/particles/renderingModules/UIRenderingFlipbook.d.ts +41 -0
- package/dist/particles/renderingModules/UIRenderingFlipbook.js +70 -0
- package/dist/particles/renderingModules/UIRenderingModule.d.ts +2 -1
- package/dist/particles/renderingModules/UIRenderingModule.js +2 -1
- package/dist/particles/renderingModules/UIRenderingRandomColor.d.ts +19 -0
- package/dist/particles/renderingModules/UIRenderingRandomColor.js +28 -0
- package/dist/particles/renderingModules/UIRenderingShape.d.ts +31 -0
- package/dist/particles/renderingModules/UIRenderingShape.js +54 -0
- package/dist/particles/renderingModules/UIRenderingTexture.d.ts +1 -1
- package/dist/particles/renderingModules/UIRenderingTexture.js +4 -28
- package/dist/particles/shaders/UIRenderingFlipbook.d.ts +5 -0
- package/dist/particles/shaders/UIRenderingFlipbook.js +19 -0
- package/dist/particles/shaders/UIRenderingRandomColor.d.ts +2 -0
- package/dist/particles/shaders/UIRenderingRandomColor.js +10 -0
- package/dist/particles/shaders/UIRenderingShape.d.ts +6 -0
- package/dist/particles/shaders/UIRenderingShape.js +15 -0
- package/dist/particles/shaders/UIRenderingTexture.d.ts +4 -2
- package/dist/particles/shaders/UIRenderingTexture.js +27 -2
- package/dist/particles/spawnModules/UISpawnCircle.d.ts +44 -0
- package/dist/particles/spawnModules/UISpawnCircle.js +81 -0
- package/dist/particles/spawnModules/UISpawnRadialVelocity.d.ts +37 -0
- package/dist/particles/spawnModules/UISpawnRadialVelocity.js +75 -0
- package/package.json +1 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { InstancedBufferAttribute } from "three";
|
|
2
|
+
import type { UIRange, UIRangeConfig } from "../miscellaneous/miscellaneous.js";
|
|
3
|
+
import { UISpawnModule } from "./UISpawnModule.js";
|
|
4
|
+
/** How `UISpawnCircle` places particles along its arc */
|
|
5
|
+
export declare enum UICircleDistribution {
|
|
6
|
+
/** Each particle at a random angle */
|
|
7
|
+
RANDOM = 0,
|
|
8
|
+
/** The particles of one spawn call, such as one burst, evenly spaced */
|
|
9
|
+
EVEN = 1
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Spawns particles within a circle, a ring or a sector of them.
|
|
13
|
+
*
|
|
14
|
+
* Positions are uniform by area between the inner and the outer radius; equal radii give a
|
|
15
|
+
* circle line. Angles are in radians, counter-clockwise from the right.
|
|
16
|
+
*/
|
|
17
|
+
export declare class UISpawnCircle extends UISpawnModule<{
|
|
18
|
+
builtin: "Matrix4";
|
|
19
|
+
}> {
|
|
20
|
+
readonly requiredProperties: {
|
|
21
|
+
readonly builtin: "Matrix4";
|
|
22
|
+
};
|
|
23
|
+
distribution: UICircleDistribution;
|
|
24
|
+
private radiusInternal;
|
|
25
|
+
private arcInternal;
|
|
26
|
+
/**
|
|
27
|
+
* @param radius - Inner and outer radius. Accepts number, tuple, or range object
|
|
28
|
+
* @param arc - Angle range in radians. Accepts number, tuple, or range object
|
|
29
|
+
* @param distribution - Random or even placement along the arc
|
|
30
|
+
*/
|
|
31
|
+
constructor(radius?: UIRangeConfig, arc?: UIRangeConfig, distribution?: UICircleDistribution);
|
|
32
|
+
/** Inner and outer radius */
|
|
33
|
+
get radius(): UIRange;
|
|
34
|
+
/** Angle range in radians */
|
|
35
|
+
get arc(): UIRange;
|
|
36
|
+
/** Inner and outer radius */
|
|
37
|
+
set radius(value: UIRangeConfig);
|
|
38
|
+
/** Angle range in radians */
|
|
39
|
+
set arc(value: UIRangeConfig);
|
|
40
|
+
spawn(properties: {
|
|
41
|
+
builtin: InstancedBufferAttribute;
|
|
42
|
+
}, instanceBegin: number, instanceEnd: number, randomSalt: number): void;
|
|
43
|
+
private assertValid;
|
|
44
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { MathUtils } from "three";
|
|
2
|
+
import { assertValidNonNegativeNumber, assertValidNumber, } from "../../core/miscellaneous/asserts.js";
|
|
3
|
+
import { BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, particleRandom, particleRandomStream, resolveUIRangeConfig, } from "../miscellaneous/miscellaneous.js";
|
|
4
|
+
import { UISpawnModule } from "./UISpawnModule.js";
|
|
5
|
+
/** How `UISpawnCircle` places particles along its arc */
|
|
6
|
+
export var UICircleDistribution;
|
|
7
|
+
(function (UICircleDistribution) {
|
|
8
|
+
/** Each particle at a random angle */
|
|
9
|
+
UICircleDistribution[UICircleDistribution["RANDOM"] = 0] = "RANDOM";
|
|
10
|
+
/** The particles of one spawn call, such as one burst, evenly spaced */
|
|
11
|
+
UICircleDistribution[UICircleDistribution["EVEN"] = 1] = "EVEN";
|
|
12
|
+
})(UICircleDistribution || (UICircleDistribution = {}));
|
|
13
|
+
/**
|
|
14
|
+
* Spawns particles within a circle, a ring or a sector of them.
|
|
15
|
+
*
|
|
16
|
+
* Positions are uniform by area between the inner and the outer radius; equal radii give a
|
|
17
|
+
* circle line. Angles are in radians, counter-clockwise from the right.
|
|
18
|
+
*/
|
|
19
|
+
export class UISpawnCircle extends UISpawnModule {
|
|
20
|
+
/**
|
|
21
|
+
* @param radius - Inner and outer radius. Accepts number, tuple, or range object
|
|
22
|
+
* @param arc - Angle range in radians. Accepts number, tuple, or range object
|
|
23
|
+
* @param distribution - Random or even placement along the arc
|
|
24
|
+
*/
|
|
25
|
+
constructor(radius = { min: 0, max: 50 }, arc = { min: -Math.PI, max: Math.PI }, distribution = UICircleDistribution.RANDOM) {
|
|
26
|
+
super();
|
|
27
|
+
this.requiredProperties = { builtin: "Matrix4" };
|
|
28
|
+
this.radiusInternal = resolveUIRangeConfig(radius);
|
|
29
|
+
this.arcInternal = resolveUIRangeConfig(arc);
|
|
30
|
+
this.distribution = distribution;
|
|
31
|
+
this.assertValid("UISpawnCircle.constructor");
|
|
32
|
+
}
|
|
33
|
+
/** Inner and outer radius */
|
|
34
|
+
get radius() {
|
|
35
|
+
return this.radiusInternal;
|
|
36
|
+
}
|
|
37
|
+
/** Angle range in radians */
|
|
38
|
+
get arc() {
|
|
39
|
+
return this.arcInternal;
|
|
40
|
+
}
|
|
41
|
+
/** Inner and outer radius */
|
|
42
|
+
set radius(value) {
|
|
43
|
+
this.radiusInternal = resolveUIRangeConfig(value);
|
|
44
|
+
this.assertValid("UISpawnCircle");
|
|
45
|
+
}
|
|
46
|
+
/** Angle range in radians */
|
|
47
|
+
set arc(value) {
|
|
48
|
+
this.arcInternal = resolveUIRangeConfig(value);
|
|
49
|
+
this.assertValid("UISpawnCircle");
|
|
50
|
+
}
|
|
51
|
+
spawn(properties, instanceBegin, instanceEnd, randomSalt) {
|
|
52
|
+
const { builtin } = properties;
|
|
53
|
+
const { array, itemSize } = builtin;
|
|
54
|
+
const { min: arcMin, max: arcMax } = this.arcInternal;
|
|
55
|
+
const innerSquared = this.radiusInternal.min * this.radiusInternal.min;
|
|
56
|
+
const outerSquared = this.radiusInternal.max * this.radiusInternal.max;
|
|
57
|
+
const even = this.distribution === UICircleDistribution.EVEN;
|
|
58
|
+
const count = instanceEnd - instanceBegin;
|
|
59
|
+
const angleStream = particleRandomStream(randomSalt, 0);
|
|
60
|
+
const radiusStream = particleRandomStream(randomSalt, 1);
|
|
61
|
+
for (let i = instanceBegin; i < instanceEnd; i++) {
|
|
62
|
+
const itemOffset = i * itemSize;
|
|
63
|
+
// Cell centers: a full circle gets equal gaps, also between the last and the first.
|
|
64
|
+
const angleT = even
|
|
65
|
+
? (i - instanceBegin + 0.5) / count
|
|
66
|
+
: particleRandom(array, itemOffset, angleStream);
|
|
67
|
+
const angle = MathUtils.lerp(arcMin, arcMax, angleT);
|
|
68
|
+
// Area grows with r^2, so r^2 is uniform for a uniform density.
|
|
69
|
+
const radius = Math.sqrt(MathUtils.lerp(innerSquared, outerSquared, particleRandom(array, itemOffset, radiusStream)));
|
|
70
|
+
array[itemOffset + BUILTIN_OFFSET_POSITION_X] = Math.cos(angle) * radius;
|
|
71
|
+
array[itemOffset + BUILTIN_OFFSET_POSITION_Y] = Math.sin(angle) * radius;
|
|
72
|
+
}
|
|
73
|
+
builtin.needsUpdate = true;
|
|
74
|
+
}
|
|
75
|
+
assertValid(subject) {
|
|
76
|
+
assertValidNonNegativeNumber(this.radiusInternal.min, `${subject}.radius.min`);
|
|
77
|
+
assertValidNonNegativeNumber(this.radiusInternal.max, `${subject}.radius.max`);
|
|
78
|
+
assertValidNumber(this.arcInternal.min, `${subject}.arc.min`);
|
|
79
|
+
assertValidNumber(this.arcInternal.max, `${subject}.arc.max`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 { UISpawnModule } from "./UISpawnModule.js";
|
|
5
|
+
/**
|
|
6
|
+
* Assigns velocity along the direction from a center to the spawn position: outward for a positive
|
|
7
|
+
* speed, inward for a negative one.
|
|
8
|
+
*
|
|
9
|
+
* Reads the position, so it goes after the shape module in the spawn sequence. A particle at the
|
|
10
|
+
* center moves in a random direction.
|
|
11
|
+
*/
|
|
12
|
+
export declare class UISpawnRadialVelocity extends UISpawnModule<{
|
|
13
|
+
builtin: "Matrix4";
|
|
14
|
+
}> {
|
|
15
|
+
readonly requiredProperties: {
|
|
16
|
+
readonly builtin: "Matrix4";
|
|
17
|
+
};
|
|
18
|
+
private magnitudeInternal;
|
|
19
|
+
private centerInternal;
|
|
20
|
+
/**
|
|
21
|
+
* @param magnitude - Speed range in units/second. Accepts number, tuple, or range object
|
|
22
|
+
* @param center - Center relative to the emitter
|
|
23
|
+
*/
|
|
24
|
+
constructor(magnitude?: UIRangeConfig, center?: UIVector2Config);
|
|
25
|
+
/** Speed range in units/second */
|
|
26
|
+
get magnitude(): UIRange;
|
|
27
|
+
/** Center relative to the emitter */
|
|
28
|
+
get center(): Vector2Like;
|
|
29
|
+
/** Speed range in units/second */
|
|
30
|
+
set magnitude(value: UIRangeConfig);
|
|
31
|
+
/** Center relative to the emitter */
|
|
32
|
+
set center(value: UIVector2Config);
|
|
33
|
+
spawn(properties: {
|
|
34
|
+
builtin: InstancedBufferAttribute;
|
|
35
|
+
}, instanceBegin: number, instanceEnd: number, randomSalt: number): void;
|
|
36
|
+
private assertValid;
|
|
37
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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 { UISpawnModule } from "./UISpawnModule.js";
|
|
5
|
+
/**
|
|
6
|
+
* Assigns velocity along the direction from a center to the spawn position: outward for a positive
|
|
7
|
+
* speed, inward for a negative one.
|
|
8
|
+
*
|
|
9
|
+
* Reads the position, so it goes after the shape module in the spawn sequence. A particle at the
|
|
10
|
+
* center moves in a random direction.
|
|
11
|
+
*/
|
|
12
|
+
export class UISpawnRadialVelocity extends UISpawnModule {
|
|
13
|
+
/**
|
|
14
|
+
* @param magnitude - Speed range in units/second. Accepts number, tuple, or range object
|
|
15
|
+
* @param center - Center relative to the emitter
|
|
16
|
+
*/
|
|
17
|
+
constructor(magnitude = { min: 50, max: 100 }, center = 0) {
|
|
18
|
+
super();
|
|
19
|
+
this.requiredProperties = { builtin: "Matrix4" };
|
|
20
|
+
this.magnitudeInternal = resolveUIRangeConfig(magnitude);
|
|
21
|
+
this.centerInternal = resolveUIVector2Config(center);
|
|
22
|
+
this.assertValid("UISpawnRadialVelocity.constructor");
|
|
23
|
+
}
|
|
24
|
+
/** Speed range in units/second */
|
|
25
|
+
get magnitude() {
|
|
26
|
+
return this.magnitudeInternal;
|
|
27
|
+
}
|
|
28
|
+
/** Center relative to the emitter */
|
|
29
|
+
get center() {
|
|
30
|
+
return this.centerInternal;
|
|
31
|
+
}
|
|
32
|
+
/** Speed range in units/second */
|
|
33
|
+
set magnitude(value) {
|
|
34
|
+
this.magnitudeInternal = resolveUIRangeConfig(value);
|
|
35
|
+
this.assertValid("UISpawnRadialVelocity");
|
|
36
|
+
}
|
|
37
|
+
/** Center relative to the emitter */
|
|
38
|
+
set center(value) {
|
|
39
|
+
this.centerInternal = resolveUIVector2Config(value);
|
|
40
|
+
this.assertValid("UISpawnRadialVelocity");
|
|
41
|
+
}
|
|
42
|
+
spawn(properties, instanceBegin, instanceEnd, randomSalt) {
|
|
43
|
+
const { builtin } = properties;
|
|
44
|
+
const { array, itemSize } = builtin;
|
|
45
|
+
const { min: magnitudeMin, max: magnitudeMax } = this.magnitudeInternal;
|
|
46
|
+
const { x: centerX, y: centerY } = this.centerInternal;
|
|
47
|
+
const magnitudeStream = particleRandomStream(randomSalt, 0);
|
|
48
|
+
const angleStream = particleRandomStream(randomSalt, 1);
|
|
49
|
+
for (let i = instanceBegin; i < instanceEnd; i++) {
|
|
50
|
+
const itemOffset = i * itemSize;
|
|
51
|
+
const magnitude = MathUtils.lerp(magnitudeMin, magnitudeMax, particleRandom(array, itemOffset, magnitudeStream));
|
|
52
|
+
let directionX = array[itemOffset + BUILTIN_OFFSET_POSITION_X] - centerX;
|
|
53
|
+
let directionY = array[itemOffset + BUILTIN_OFFSET_POSITION_Y] - centerY;
|
|
54
|
+
const length = Math.hypot(directionX, directionY);
|
|
55
|
+
if (length > 0) {
|
|
56
|
+
directionX /= length;
|
|
57
|
+
directionY /= length;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const angle = particleRandom(array, itemOffset, angleStream) * Math.PI * 2;
|
|
61
|
+
directionX = Math.cos(angle);
|
|
62
|
+
directionY = Math.sin(angle);
|
|
63
|
+
}
|
|
64
|
+
array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] = directionX * magnitude;
|
|
65
|
+
array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] = directionY * magnitude;
|
|
66
|
+
}
|
|
67
|
+
builtin.needsUpdate = true;
|
|
68
|
+
}
|
|
69
|
+
assertValid(subject) {
|
|
70
|
+
assertValidNumber(this.magnitudeInternal.min, `${subject}.magnitude.min`);
|
|
71
|
+
assertValidNumber(this.magnitudeInternal.max, `${subject}.magnitude.max`);
|
|
72
|
+
assertValidNumber(this.centerInternal.x, `${subject}.center.x`);
|
|
73
|
+
assertValidNumber(this.centerInternal.y, `${subject}.center.y`);
|
|
74
|
+
}
|
|
75
|
+
}
|