sparcoon 0.5.0 → 0.6.1
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 +6 -6
- package/dist/emitter/FXEmitter.Internal.d.ts +50 -2
- package/dist/emitter/FXEmitter.Internal.js +1 -2
- package/dist/emitter/FXEmitter.d.ts +48 -1
- package/dist/emitter/FXEmitter.js +74 -11
- package/dist/emitter/behavior/FXBehavior.d.ts +12 -2
- package/dist/emitter/behavior/FXBehavior.js +3 -2
- package/dist/emitter/behavior/FXBehaviorDirectionalForce.d.ts +25 -0
- package/dist/emitter/behavior/FXBehaviorDirectionalForce.js +74 -0
- package/dist/emitter/behavior/FXBehaviorPointForce.d.ts +40 -0
- package/dist/emitter/behavior/FXBehaviorPointForce.js +98 -0
- package/dist/emitter/behavior/FXBehaviorScaleOverLife.d.ts +9 -8
- package/dist/emitter/behavior/FXBehaviorScaleOverLife.js +12 -29
- package/dist/emitter/behavior/FXBehaviorTorqueDamping.d.ts +4 -3
- package/dist/emitter/behavior/FXBehaviorTorqueDamping.js +3 -2
- package/dist/emitter/behavior/FXBehaviorTorqueNoise.d.ts +4 -3
- package/dist/emitter/behavior/FXBehaviorTorqueNoise.js +3 -2
- package/dist/emitter/behavior/FXBehaviorTorqueOverLife.d.ts +17 -0
- package/dist/emitter/behavior/FXBehaviorTorqueOverLife.js +34 -0
- package/dist/emitter/behavior/FXBehaviorVelocityDamping.d.ts +3 -2
- package/dist/emitter/behavior/FXBehaviorVelocityDamping.js +3 -2
- package/dist/emitter/behavior/FXBehaviorVelocityNoise.d.ts +6 -5
- package/dist/emitter/behavior/FXBehaviorVelocityNoise.js +6 -5
- package/dist/emitter/behavior/FXBehaviorVelocityOverLife.d.ts +20 -0
- package/dist/emitter/behavior/FXBehaviorVelocityOverLife.js +48 -0
- package/dist/emitter/spawn/FXSpawn.d.ts +4 -2
- package/dist/emitter/spawn/FXSpawn.js +3 -2
- package/dist/emitter/spawn/FXSpawnBox.d.ts +8 -16
- package/dist/emitter/spawn/FXSpawnBox.js +23 -39
- package/dist/emitter/spawn/{FXSpawnRandomLifetime.d.ts → FXSpawnLifetime.d.ts} +3 -5
- package/dist/emitter/spawn/{FXSpawnRandomLifetime.js → FXSpawnLifetime.js} +8 -10
- package/dist/emitter/spawn/FXSpawnOffset.d.ts +9 -0
- package/dist/emitter/spawn/FXSpawnOffset.js +9 -0
- package/dist/emitter/spawn/FXSpawnPoint.d.ts +8 -0
- package/dist/emitter/spawn/FXSpawnPoint.js +8 -0
- package/dist/emitter/spawn/{FXSpawnRandomRotation.d.ts → FXSpawnRotation.d.ts} +3 -5
- package/dist/emitter/spawn/{FXSpawnRandomRotation.js → FXSpawnRotation.js} +8 -10
- package/dist/emitter/spawn/{FXSpawnRandomScale.d.ts → FXSpawnScale.d.ts} +4 -6
- package/dist/emitter/spawn/{FXSpawnRandomScale.js → FXSpawnScale.js} +12 -14
- package/dist/emitter/spawn/FXSpawnSphere.d.ts +11 -6
- package/dist/emitter/spawn/FXSpawnSphere.js +11 -6
- package/dist/emitter/spawn/{FXSpawnRandomTorque.d.ts → FXSpawnTorque.d.ts} +3 -5
- package/dist/emitter/spawn/{FXSpawnRandomTorque.js → FXSpawnTorque.js} +8 -10
- package/dist/emitter/spawn/FXSpawnVelocity.d.ts +32 -0
- package/dist/emitter/spawn/{FXSpawnRandomVelocity.js → FXSpawnVelocity.js} +26 -11
- package/dist/index.d.ts +23 -16
- package/dist/index.js +20 -16
- package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.Internal.d.ts +4 -4
- package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.Internal.js +2 -2
- package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.d.ts +55 -5
- package/dist/materials/FXDiffuseMaterial/FXDiffuseMaterial.js +9 -2
- package/dist/materials/FXMaterial/FXDepthMaterial.Internal.d.ts +3 -3
- package/dist/materials/FXMaterial/FXDistanceMaterial.Internal.d.ts +3 -3
- package/dist/materials/FXMaterial/FXMaterial.d.ts +51 -5
- package/dist/materials/FXMaterial/FXMaterial.js +5 -0
- package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.Internal.d.ts +3 -3
- package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.d.ts +3 -3
- package/dist/materials/FXUnlitMaterial/FXUnlitMaterial.js +3 -3
- package/dist/miscellaneous/curve/FXCurve1D.Internal.d.ts +20 -0
- package/dist/miscellaneous/curve/FXCurve1D.d.ts +17 -0
- package/dist/miscellaneous/curve/FXCurve1D.js +94 -0
- package/dist/miscellaneous/miscellaneous.d.ts +3 -1
- package/dist/miscellaneous/miscellaneous.js +8 -4
- package/dist/miscellaneous/texture/FXTextureView.Internal.js +6 -0
- package/dist/miscellaneous/texture/FXTextureView.js +234 -0
- package/dist/nodes/color/FXNodeColor.d.ts +7 -0
- package/dist/nodes/color/FXNodeColor.js +11 -0
- package/dist/nodes/color/FXNodeColorOverLife.d.ts +25 -0
- package/dist/nodes/color/FXNodeColorOverLife.js +60 -0
- package/dist/nodes/color/FXNodeSphericalClip.d.ts +18 -0
- package/dist/nodes/color/FXNodeSphericalClip.js +45 -0
- package/dist/nodes/normal/FXNodeFlatNormal.d.ts +7 -0
- package/dist/nodes/normal/FXNodeFlatNormal.js +17 -0
- package/dist/nodes/normal/FXNodeNormal.d.ts +7 -0
- package/dist/nodes/normal/FXNodeNormal.js +7 -0
- package/dist/nodes/normal/FXNodeSphericalNormal.d.ts +7 -0
- package/dist/nodes/normal/{FXSphericalNormalNode.js → FXNodeSphericalNormal.js} +7 -4
- package/dist/nodes/texture/FXNodeAnimatedTexture.d.ts +47 -0
- package/dist/nodes/texture/FXNodeAnimatedTexture.js +137 -0
- package/dist/nodes/texture/FXNodeStaticTexture.d.ts +18 -0
- package/dist/nodes/texture/FXNodeStaticTexture.js +60 -0
- package/dist/nodes/texture/FXNodeTexture.d.ts +7 -0
- package/dist/nodes/texture/FXNodeTexture.js +11 -0
- package/package.json +2 -4
- package/dist/emitter/behavior/FXBehaviorDirectionalGravity.d.ts +0 -21
- package/dist/emitter/behavior/FXBehaviorDirectionalGravity.js +0 -51
- package/dist/emitter/behavior/FXBehaviorPointGravity.d.ts +0 -39
- package/dist/emitter/behavior/FXBehaviorPointGravity.js +0 -116
- package/dist/emitter/spawn/FXSpawnRandomVelocity.d.ts +0 -17
- package/dist/nodes/color/FXColorNode.d.ts +0 -3
- package/dist/nodes/color/FXColorNode.js +0 -8
- package/dist/nodes/color/FXColorOverLifeNode.d.ts +0 -6
- package/dist/nodes/color/FXColorOverLifeNode.js +0 -44
- package/dist/nodes/color/FXSphericalClipNode.d.ts +0 -5
- package/dist/nodes/color/FXSphericalClipNode.js +0 -30
- package/dist/nodes/normal/FXFlatNormalNode.d.ts +0 -4
- package/dist/nodes/normal/FXFlatNormalNode.js +0 -14
- package/dist/nodes/normal/FXNormalNode.d.ts +0 -3
- package/dist/nodes/normal/FXNormalNode.js +0 -4
- package/dist/nodes/normal/FXSphericalNormalNode.d.ts +0 -4
- package/dist/nodes/texture/FXAnimatedTextureNode.d.ts +0 -12
- package/dist/nodes/texture/FXAnimatedTextureNode.js +0 -88
- package/dist/nodes/texture/FXStaticTextureNode.d.ts +0 -6
- package/dist/nodes/texture/FXStaticTextureNode.js +0 -34
- package/dist/nodes/texture/FXTextureNode.d.ts +0 -3
- package/dist/nodes/texture/FXTextureNode.js +0 -8
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FXCurve1DConfig } from "../../miscellaneous/curve/FXCurve1D";
|
|
2
|
+
import { FXCurve1D } from "../../miscellaneous/curve/FXCurve1D";
|
|
3
|
+
import type { FXAspectConfig, FXRange } from "../../miscellaneous/miscellaneous";
|
|
2
4
|
import { FXBehavior } from "./FXBehavior";
|
|
3
5
|
/**
|
|
4
|
-
* Animates particle scale over lifetime
|
|
5
|
-
*
|
|
6
|
-
* Interpolates between scale anchors based on particle age. Requires at least 2 anchors.
|
|
6
|
+
* Animates particle scale over lifetime using a {@link FXCurve1D}
|
|
7
7
|
*/
|
|
8
8
|
export declare class FXBehaviorScaleOverLife extends FXBehavior<{
|
|
9
9
|
builtin: "Matrix4";
|
|
10
10
|
}> {
|
|
11
|
-
|
|
11
|
+
/** Active scale curve */
|
|
12
|
+
curve: FXCurve1D<FXRange>;
|
|
12
13
|
private aspectInternal;
|
|
13
14
|
/**
|
|
14
|
-
* @param
|
|
15
|
-
* @param aspect - Width/height ratio.
|
|
15
|
+
* @param curve - Scale curve; accepts a {@link FXCurve1D} instance or a `FXRange[]` shorthand
|
|
16
|
+
* @param aspect - Width/height ratio; must be positive. Defaults to `1`
|
|
16
17
|
*/
|
|
17
|
-
constructor(
|
|
18
|
+
constructor(curve: FXCurve1DConfig<FXRange>, aspect?: FXAspectConfig);
|
|
18
19
|
/** Width/height aspect ratio */
|
|
19
20
|
get aspect(): number;
|
|
20
21
|
/** Width/height aspect ratio */
|
|
@@ -1,32 +1,22 @@
|
|
|
1
1
|
import { MathUtils } from 'three';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { assertValidPositiveNumber } from '../../miscellaneous/asserts.js';
|
|
3
|
+
import { FXCurve1D } from '../../miscellaneous/curve/FXCurve1D.js';
|
|
4
|
+
import { resolveAspect, BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME, BUILTIN_OFFSET_RANDOM_A, BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y } from '../../miscellaneous/miscellaneous.js';
|
|
4
5
|
import { FXBehavior } from './FXBehavior.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
* Animates particle scale over lifetime
|
|
8
|
-
*
|
|
9
|
-
* Interpolates between scale anchors based on particle age. Requires at least 2 anchors.
|
|
8
|
+
* Animates particle scale over lifetime using a {@link FXCurve1D}
|
|
10
9
|
*/
|
|
11
10
|
class FXBehaviorScaleOverLife extends FXBehavior {
|
|
12
11
|
/**
|
|
13
|
-
* @param
|
|
14
|
-
* @param aspect - Width/height ratio.
|
|
12
|
+
* @param curve - Scale curve; accepts a {@link FXCurve1D} instance or a `FXRange[]` shorthand
|
|
13
|
+
* @param aspect - Width/height ratio; must be positive. Defaults to `1`
|
|
15
14
|
*/
|
|
16
|
-
constructor(
|
|
15
|
+
constructor(curve, aspect = 1) {
|
|
17
16
|
super();
|
|
18
17
|
/** @internal */
|
|
19
18
|
this.requiredProperties = { builtin: "Matrix4" };
|
|
20
|
-
this.
|
|
21
|
-
if (scales.length < 2) {
|
|
22
|
-
throw new Error("FXBehaviorScaleOverLife.scales: the number of scale anchors must be more than two");
|
|
23
|
-
}
|
|
24
|
-
for (let i = 0; i < scales.length; i++) {
|
|
25
|
-
const scale = resolveFXRangeConfig(scales[i]);
|
|
26
|
-
assertValidNonNegativeNumber(scale.min, `FXBehaviorScaleOverLife.constructor.scales[${i}].min`);
|
|
27
|
-
assertValidNonNegativeNumber(scale.max, `FXBehaviorScaleOverLife.constructor.scales[${i}].max`);
|
|
28
|
-
this._private_scales.push(scale);
|
|
29
|
-
}
|
|
19
|
+
this.curve = new FXCurve1D(curve);
|
|
30
20
|
this._private_aspectInternal = resolveAspect(aspect);
|
|
31
21
|
assertValidPositiveNumber(this._private_aspectInternal, "FXBehaviorScaleOverLife.constructor.aspect");
|
|
32
22
|
}
|
|
@@ -46,18 +36,11 @@ class FXBehaviorScaleOverLife extends FXBehavior {
|
|
|
46
36
|
for (let i = 0; i < instanceCount; i++) {
|
|
47
37
|
const itemOffset = i * itemSize;
|
|
48
38
|
const lifeT = Math.min(array[itemOffset + BUILTIN_OFFSET_AGE] / array[itemOffset + BUILTIN_OFFSET_LIFETIME], 1);
|
|
49
|
-
const segment = (this._private_scales.length - 1) * lifeT;
|
|
50
|
-
const index = Math.floor(segment);
|
|
51
|
-
// Constant over the life of a particle but different for each particle
|
|
52
39
|
const scaleT = array[itemOffset + BUILTIN_OFFSET_RANDOM_A];
|
|
53
|
-
const localT =
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const scale1 = MathUtils.lerp(scaleRange1.min, scaleRange1.max, scaleT);
|
|
58
|
-
const interpolatedScale = scale0 + (scale1 - scale0) * localT;
|
|
59
|
-
array[itemOffset + BUILTIN_OFFSET_SCALE_X] = interpolatedScale * this._private_aspectInternal;
|
|
60
|
-
array[itemOffset + BUILTIN_OFFSET_SCALE_Y] = interpolatedScale;
|
|
40
|
+
const { a, b, t: localT } = this.curve.sample(lifeT);
|
|
41
|
+
const scale = MathUtils.lerp(MathUtils.lerp(a.min, a.max, scaleT), MathUtils.lerp(b.min, b.max, scaleT), localT);
|
|
42
|
+
array[itemOffset + BUILTIN_OFFSET_SCALE_X] = scale * this._private_aspectInternal;
|
|
43
|
+
array[itemOffset + BUILTIN_OFFSET_SCALE_Y] = scale;
|
|
61
44
|
}
|
|
62
45
|
builtin.needsUpdate = true;
|
|
63
46
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { FXRange, FXRangeConfig } from "../../miscellaneous/miscellaneous";
|
|
2
2
|
import { FXBehavior } from "./FXBehavior";
|
|
3
3
|
/**
|
|
4
|
-
* Reduces particle angular velocity over time
|
|
4
|
+
* Reduces particle angular velocity over time
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* A damping value of `0` has no effect; `1` stops the particle instantly.
|
|
7
8
|
*/
|
|
8
9
|
export declare class FXBehaviorTorqueDamping extends FXBehavior<{
|
|
9
10
|
builtin: "Matrix4";
|
|
@@ -12,7 +13,7 @@ export declare class FXBehaviorTorqueDamping extends FXBehavior<{
|
|
|
12
13
|
/**
|
|
13
14
|
* @param damping - Damping coefficient range (0-1). Accepts number, tuple, or range object
|
|
14
15
|
*/
|
|
15
|
-
constructor(damping:
|
|
16
|
+
constructor(damping: FXRangeConfig);
|
|
16
17
|
/** Damping coefficient range (0-1) */
|
|
17
18
|
get damping(): FXRange;
|
|
18
19
|
/** Damping coefficient range (0-1) */
|
|
@@ -4,9 +4,10 @@ import { resolveFXRangeConfig, BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_TORQUE }
|
|
|
4
4
|
import { FXBehavior } from './FXBehavior.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Reduces particle angular velocity over time
|
|
7
|
+
* Reduces particle angular velocity over time
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* A damping value of `0` has no effect; `1` stops the particle instantly.
|
|
10
11
|
*/
|
|
11
12
|
class FXBehaviorTorqueDamping extends FXBehavior {
|
|
12
13
|
/**
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { FXRange, FXRangeConfig } from "../../miscellaneous/miscellaneous";
|
|
2
2
|
import { FXBehavior } from "./FXBehavior";
|
|
3
3
|
/**
|
|
4
|
-
* Applies noise-based angular acceleration to particles
|
|
4
|
+
* Applies noise-based angular acceleration to particles
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Higher `scale` values produce finer noise detail.
|
|
7
8
|
*/
|
|
8
9
|
export declare class FXBehaviorTorqueNoise extends FXBehavior<{
|
|
9
10
|
builtin: "Matrix4";
|
|
@@ -14,7 +15,7 @@ export declare class FXBehaviorTorqueNoise extends FXBehavior<{
|
|
|
14
15
|
* @param scale - Noise frequency range. Accepts number, tuple, or range object
|
|
15
16
|
* @param strength - Force multiplier range. Accepts number, tuple, or range object
|
|
16
17
|
*/
|
|
17
|
-
constructor(scale:
|
|
18
|
+
constructor(scale: FXRangeConfig, strength: FXRangeConfig);
|
|
18
19
|
/** Noise frequency range */
|
|
19
20
|
get scale(): FXRange;
|
|
20
21
|
/** Force multiplier range */
|
|
@@ -6,9 +6,10 @@ import { FXBehavior } from './FXBehavior.js';
|
|
|
6
6
|
|
|
7
7
|
const generateNoise3D = modExports.makeNoise3D();
|
|
8
8
|
/**
|
|
9
|
-
* Applies noise-based angular acceleration to particles
|
|
9
|
+
* Applies noise-based angular acceleration to particles
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Higher `scale` values produce finer noise detail.
|
|
12
13
|
*/
|
|
13
14
|
class FXBehaviorTorqueNoise extends FXBehavior {
|
|
14
15
|
/**
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FXCurve1DConfig } from "../../miscellaneous/curve/FXCurve1D";
|
|
2
|
+
import { FXCurve1D } from "../../miscellaneous/curve/FXCurve1D";
|
|
3
|
+
import type { FXRange } from "../../miscellaneous/miscellaneous";
|
|
4
|
+
import { FXBehavior } from "./FXBehavior";
|
|
5
|
+
/**
|
|
6
|
+
* Animates particle angular velocity over lifetime using a {@link FXCurve1D}
|
|
7
|
+
*/
|
|
8
|
+
export declare class FXBehaviorTorqueOverLife extends FXBehavior<{
|
|
9
|
+
builtin: "Matrix4";
|
|
10
|
+
}> {
|
|
11
|
+
/** Active torque curve */
|
|
12
|
+
curve: FXCurve1D<FXRange>;
|
|
13
|
+
/**
|
|
14
|
+
* @param curve - Torque curve; accepts a {@link FXCurve1D} instance or a `FXRange[]` shorthand
|
|
15
|
+
*/
|
|
16
|
+
constructor(curve: FXCurve1DConfig<FXRange>);
|
|
17
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MathUtils } from 'three';
|
|
2
|
+
import { FXCurve1D } from '../../miscellaneous/curve/FXCurve1D.js';
|
|
3
|
+
import { BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME, BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_TORQUE } from '../../miscellaneous/miscellaneous.js';
|
|
4
|
+
import { FXBehavior } from './FXBehavior.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Animates particle angular velocity over lifetime using a {@link FXCurve1D}
|
|
8
|
+
*/
|
|
9
|
+
class FXBehaviorTorqueOverLife extends FXBehavior {
|
|
10
|
+
/**
|
|
11
|
+
* @param curve - Torque curve; accepts a {@link FXCurve1D} instance or a `FXRange[]` shorthand
|
|
12
|
+
*/
|
|
13
|
+
constructor(curve) {
|
|
14
|
+
super();
|
|
15
|
+
/** @internal */
|
|
16
|
+
this.requiredProperties = { builtin: "Matrix4" };
|
|
17
|
+
this.curve = new FXCurve1D(curve);
|
|
18
|
+
}
|
|
19
|
+
/** @internal */
|
|
20
|
+
update(properties, instanceCount) {
|
|
21
|
+
const { builtin } = properties;
|
|
22
|
+
const { array, itemSize } = builtin;
|
|
23
|
+
for (let i = 0; i < instanceCount; i++) {
|
|
24
|
+
const itemOffset = i * itemSize;
|
|
25
|
+
const lifeT = Math.min(array[itemOffset + BUILTIN_OFFSET_AGE] / array[itemOffset + BUILTIN_OFFSET_LIFETIME], 1);
|
|
26
|
+
const torqueT = array[itemOffset + BUILTIN_OFFSET_RANDOM_B];
|
|
27
|
+
const { a, b, t: localT } = this.curve.sample(lifeT);
|
|
28
|
+
array[itemOffset + BUILTIN_OFFSET_TORQUE] = MathUtils.lerp(MathUtils.lerp(a.min, a.max, torqueT), MathUtils.lerp(b.min, b.max, torqueT), localT);
|
|
29
|
+
}
|
|
30
|
+
builtin.needsUpdate = true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { FXBehaviorTorqueOverLife };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { FXRange, FXRangeConfig } from "../../miscellaneous/miscellaneous";
|
|
2
2
|
import { FXBehavior } from "./FXBehavior";
|
|
3
3
|
/**
|
|
4
|
-
* Reduces particle velocity over time
|
|
4
|
+
* Reduces particle velocity over time
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* A damping value of `0` has no effect; `1` stops the particle instantly.
|
|
7
8
|
*/
|
|
8
9
|
export declare class FXBehaviorVelocityDamping extends FXBehavior<{
|
|
9
10
|
builtin: "Matrix4";
|
|
@@ -4,9 +4,10 @@ import { resolveFXRangeConfig, BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_VELOCITY_
|
|
|
4
4
|
import { FXBehavior } from './FXBehavior.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Reduces particle velocity over time
|
|
7
|
+
* Reduces particle velocity over time
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* A damping value of `0` has no effect; `1` stops the particle instantly.
|
|
10
11
|
*/
|
|
11
12
|
class FXBehaviorVelocityDamping extends FXBehavior {
|
|
12
13
|
/**
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { FXRange, FXRangeConfig } from "../../miscellaneous/miscellaneous";
|
|
2
2
|
import { FXBehavior } from "./FXBehavior";
|
|
3
3
|
/**
|
|
4
|
-
* Applies noise-based acceleration to particles
|
|
4
|
+
* Applies noise-based acceleration to particles
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Higher `scale` values produce finer noise detail.
|
|
7
8
|
*/
|
|
8
9
|
export declare class FXBehaviorVelocityNoise extends FXBehavior<{
|
|
9
10
|
builtin: "Matrix4";
|
|
@@ -11,10 +12,10 @@ export declare class FXBehaviorVelocityNoise extends FXBehavior<{
|
|
|
11
12
|
private scaleInternal;
|
|
12
13
|
private strengthInternal;
|
|
13
14
|
/**
|
|
14
|
-
* @param scale - Noise frequency range
|
|
15
|
-
* @param strength - Force multiplier range
|
|
15
|
+
* @param scale - Noise frequency range; must be positive.
|
|
16
|
+
* @param strength - Force multiplier range; must be non-negative.
|
|
16
17
|
*/
|
|
17
|
-
constructor(scale
|
|
18
|
+
constructor(scale: FXRangeConfig, strength: FXRangeConfig);
|
|
18
19
|
/** Noise frequency range */
|
|
19
20
|
get scale(): FXRange;
|
|
20
21
|
/** Force multiplier range */
|
|
@@ -8,16 +8,17 @@ const generateNoise3D0 = modExports.makeNoise3D();
|
|
|
8
8
|
const generateNoise3D1 = modExports.makeNoise3D();
|
|
9
9
|
const generateNoise3D2 = modExports.makeNoise3D();
|
|
10
10
|
/**
|
|
11
|
-
* Applies noise-based acceleration to particles
|
|
11
|
+
* Applies noise-based acceleration to particles
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Higher `scale` values produce finer noise detail.
|
|
14
15
|
*/
|
|
15
16
|
class FXBehaviorVelocityNoise extends FXBehavior {
|
|
16
17
|
/**
|
|
17
|
-
* @param scale - Noise frequency range
|
|
18
|
-
* @param strength - Force multiplier range
|
|
18
|
+
* @param scale - Noise frequency range; must be positive.
|
|
19
|
+
* @param strength - Force multiplier range; must be non-negative.
|
|
19
20
|
*/
|
|
20
|
-
constructor(scale
|
|
21
|
+
constructor(scale, strength) {
|
|
21
22
|
super();
|
|
22
23
|
/** @internal */
|
|
23
24
|
this.requiredProperties = { builtin: "Matrix4" };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FXCurve1DConfig } from "../../miscellaneous/curve/FXCurve1D";
|
|
2
|
+
import { FXCurve1D } from "../../miscellaneous/curve/FXCurve1D";
|
|
3
|
+
import type { FXRange } from "../../miscellaneous/miscellaneous";
|
|
4
|
+
import { FXBehavior } from "./FXBehavior";
|
|
5
|
+
/**
|
|
6
|
+
* Animates particle speed over lifetime using a {@link FXCurve1D}
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Particles with zero velocity are not affected.
|
|
10
|
+
*/
|
|
11
|
+
export declare class FXBehaviorVelocityOverLife extends FXBehavior<{
|
|
12
|
+
builtin: "Matrix4";
|
|
13
|
+
}> {
|
|
14
|
+
/** Active speed curve */
|
|
15
|
+
curve: FXCurve1D<FXRange>;
|
|
16
|
+
/**
|
|
17
|
+
* @param curve - Speed curve; accepts a {@link FXCurve1D} instance or a `FXRange[]` shorthand
|
|
18
|
+
*/
|
|
19
|
+
constructor(curve: FXCurve1DConfig<FXRange>);
|
|
20
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { MathUtils } from 'three';
|
|
2
|
+
import { FXCurve1D } from '../../miscellaneous/curve/FXCurve1D.js';
|
|
3
|
+
import { BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y, BUILTIN_OFFSET_VELOCITY_Z, BUILTIN_OFFSET_RANDOM_A } from '../../miscellaneous/miscellaneous.js';
|
|
4
|
+
import { FXBehavior } from './FXBehavior.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Animates particle speed over lifetime using a {@link FXCurve1D}
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Particles with zero velocity are not affected.
|
|
11
|
+
*/
|
|
12
|
+
class FXBehaviorVelocityOverLife extends FXBehavior {
|
|
13
|
+
/**
|
|
14
|
+
* @param curve - Speed curve; accepts a {@link FXCurve1D} instance or a `FXRange[]` shorthand
|
|
15
|
+
*/
|
|
16
|
+
constructor(curve) {
|
|
17
|
+
super();
|
|
18
|
+
/** @internal */
|
|
19
|
+
this.requiredProperties = { builtin: "Matrix4" };
|
|
20
|
+
this.curve = new FXCurve1D(curve);
|
|
21
|
+
}
|
|
22
|
+
/** @internal */
|
|
23
|
+
update(properties, instanceCount) {
|
|
24
|
+
const { builtin } = properties;
|
|
25
|
+
const { array, itemSize } = builtin;
|
|
26
|
+
for (let i = 0; i < instanceCount; i++) {
|
|
27
|
+
const itemOffset = i * itemSize;
|
|
28
|
+
const lifeT = Math.min(array[itemOffset + BUILTIN_OFFSET_AGE] / array[itemOffset + BUILTIN_OFFSET_LIFETIME], 1);
|
|
29
|
+
const velocityX = array[itemOffset + BUILTIN_OFFSET_VELOCITY_X];
|
|
30
|
+
const velocityY = array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y];
|
|
31
|
+
const velocityZ = array[itemOffset + BUILTIN_OFFSET_VELOCITY_Z];
|
|
32
|
+
const currentSpeed = Math.sqrt(velocityX * velocityX + velocityY * velocityY + velocityZ * velocityZ);
|
|
33
|
+
if (currentSpeed === 0) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const velocityT = array[itemOffset + BUILTIN_OFFSET_RANDOM_A];
|
|
37
|
+
const { a, b, t: localT } = this.curve.sample(lifeT);
|
|
38
|
+
const targetSpeed = MathUtils.lerp(MathUtils.lerp(a.min, a.max, velocityT), MathUtils.lerp(b.min, b.max, velocityT), localT);
|
|
39
|
+
const scaleFactor = targetSpeed / currentSpeed;
|
|
40
|
+
array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] = velocityX * scaleFactor;
|
|
41
|
+
array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] = velocityY * scaleFactor;
|
|
42
|
+
array[itemOffset + BUILTIN_OFFSET_VELOCITY_Z] = velocityZ * scaleFactor;
|
|
43
|
+
}
|
|
44
|
+
builtin.needsUpdate = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { FXBehaviorVelocityOverLife };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { FXPropertyName } from "../../instancedParticle/shared";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Abstract base for particle spawn modules that initialize per-particle properties at birth
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* @typeParam T - Map of local property keys to {@link FXPropertyName} identifiers,
|
|
6
|
+
* declaring which particle attributes this spawn module writes
|
|
6
7
|
*/
|
|
7
8
|
export declare abstract class FXSpawn<T extends Record<string, FXPropertyName> = Record<string, FXPropertyName>> {
|
|
9
|
+
/** Releases any resources held by this spawn module */
|
|
8
10
|
destroy?(): void;
|
|
9
11
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Abstract base for particle spawn modules that initialize per-particle properties at birth
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* @typeParam T - Map of local property keys to {@link FXPropertyName} identifiers,
|
|
5
|
+
* declaring which particle attributes this spawn module writes
|
|
5
6
|
*/
|
|
6
7
|
class FXSpawn {
|
|
7
8
|
}
|
|
@@ -2,26 +2,18 @@ import type { Vector3Like } from "../../miscellaneous/math";
|
|
|
2
2
|
import type { FXVector3Config } from "../../miscellaneous/miscellaneous";
|
|
3
3
|
import { FXSpawn } from "./FXSpawn";
|
|
4
4
|
/**
|
|
5
|
-
* Spawns particles at random positions within an axis-aligned bounding box
|
|
6
|
-
*
|
|
7
|
-
* Position is chosen uniformly within the bounds defined by min and max.
|
|
5
|
+
* Spawns particles at random positions within an axis-aligned bounding box centered at the origin
|
|
8
6
|
*/
|
|
9
7
|
export declare class FXSpawnBox extends FXSpawn<{
|
|
10
8
|
builtin: "Matrix4";
|
|
11
9
|
}> {
|
|
12
|
-
private
|
|
13
|
-
private maxInternal;
|
|
10
|
+
private sizeInternal;
|
|
14
11
|
/**
|
|
15
|
-
* @param
|
|
16
|
-
* @param max - Maximum corner of the spawn box
|
|
12
|
+
* @param size - Dimensions of the spawn box. Defaults to `{ x: 1, y: 1, z: 1 }`
|
|
17
13
|
*/
|
|
18
|
-
constructor(
|
|
19
|
-
/**
|
|
20
|
-
get
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
/** Minimum corner of the spawn box */
|
|
24
|
-
set min(value: FXVector3Config);
|
|
25
|
-
/** Maximum corner of the spawn box */
|
|
26
|
-
set max(value: FXVector3Config);
|
|
14
|
+
constructor(size?: FXVector3Config);
|
|
15
|
+
/** Size of the spawn box */
|
|
16
|
+
get size(): Vector3Like;
|
|
17
|
+
/** Size of the spawn box */
|
|
18
|
+
set size(value: FXVector3Config);
|
|
27
19
|
}
|
|
@@ -4,61 +4,45 @@ import { resolveFXVector3Config, BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSIT
|
|
|
4
4
|
import { FXSpawn } from './FXSpawn.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Spawns particles at random positions within an axis-aligned bounding box
|
|
8
|
-
*
|
|
9
|
-
* Position is chosen uniformly within the bounds defined by min and max.
|
|
7
|
+
* Spawns particles at random positions within an axis-aligned bounding box centered at the origin
|
|
10
8
|
*/
|
|
11
9
|
class FXSpawnBox extends FXSpawn {
|
|
12
10
|
/**
|
|
13
|
-
* @param
|
|
14
|
-
* @param max - Maximum corner of the spawn box
|
|
11
|
+
* @param size - Dimensions of the spawn box. Defaults to `{ x: 1, y: 1, z: 1 }`
|
|
15
12
|
*/
|
|
16
|
-
constructor(
|
|
13
|
+
constructor(size = { x: 1, y: 1, z: 1 }) {
|
|
17
14
|
super();
|
|
18
15
|
/** @internal */
|
|
19
16
|
this.requiredProperties = { builtin: "Matrix4" };
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
assertValidNumber(this.
|
|
23
|
-
assertValidNumber(this.
|
|
24
|
-
assertValidNumber(this._private_minInternal.z, "FXSpawnBox.constructor.min.z");
|
|
25
|
-
assertValidNumber(this._private_maxInternal.x, "FXSpawnBox.constructor.max.x");
|
|
26
|
-
assertValidNumber(this._private_maxInternal.y, "FXSpawnBox.constructor.max.y");
|
|
27
|
-
assertValidNumber(this._private_maxInternal.z, "FXSpawnBox.constructor.max.z");
|
|
17
|
+
this._private_sizeInternal = resolveFXVector3Config(size);
|
|
18
|
+
assertValidNumber(this._private_sizeInternal.x, "FXSpawnBox.constructor.size.x");
|
|
19
|
+
assertValidNumber(this._private_sizeInternal.y, "FXSpawnBox.constructor.size.y");
|
|
20
|
+
assertValidNumber(this._private_sizeInternal.z, "FXSpawnBox.constructor.size.z");
|
|
28
21
|
}
|
|
29
|
-
/**
|
|
30
|
-
get
|
|
31
|
-
return this.
|
|
22
|
+
/** Size of the spawn box */
|
|
23
|
+
get size() {
|
|
24
|
+
return this._private_sizeInternal;
|
|
32
25
|
}
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this._private_minInternal = resolveFXVector3Config(value);
|
|
40
|
-
assertValidNumber(this._private_minInternal.x, "FXSpawnBox.min.x");
|
|
41
|
-
assertValidNumber(this._private_minInternal.y, "FXSpawnBox.min.y");
|
|
42
|
-
assertValidNumber(this._private_minInternal.z, "FXSpawnBox.min.z");
|
|
43
|
-
}
|
|
44
|
-
/** Maximum corner of the spawn box */
|
|
45
|
-
set max(value) {
|
|
46
|
-
this._private_maxInternal = resolveFXVector3Config(value);
|
|
47
|
-
assertValidNumber(this._private_maxInternal.x, "FXSpawnBox.max.x");
|
|
48
|
-
assertValidNumber(this._private_maxInternal.y, "FXSpawnBox.max.y");
|
|
49
|
-
assertValidNumber(this._private_maxInternal.z, "FXSpawnBox.max.z");
|
|
26
|
+
/** Size of the spawn box */
|
|
27
|
+
set size(value) {
|
|
28
|
+
this._private_sizeInternal = resolveFXVector3Config(value);
|
|
29
|
+
assertValidNumber(this._private_sizeInternal.x, "FXSpawnBox.size.x");
|
|
30
|
+
assertValidNumber(this._private_sizeInternal.y, "FXSpawnBox.size.y");
|
|
31
|
+
assertValidNumber(this._private_sizeInternal.z, "FXSpawnBox.size.z");
|
|
50
32
|
}
|
|
51
33
|
/** @internal */
|
|
52
34
|
spawn(properties, instanceBegin, instanceEnd) {
|
|
53
35
|
const { builtin } = properties;
|
|
54
36
|
const { array, itemSize } = builtin;
|
|
55
|
-
const { x:
|
|
56
|
-
const
|
|
37
|
+
const { x: sizeX, y: sizeY, z: sizeZ } = this._private_sizeInternal;
|
|
38
|
+
const halfX = sizeX * 0.5;
|
|
39
|
+
const halfY = sizeY * 0.5;
|
|
40
|
+
const halfZ = sizeZ * 0.5;
|
|
57
41
|
for (let i = instanceBegin; i < instanceEnd; i++) {
|
|
58
42
|
const itemOffset = i * itemSize;
|
|
59
|
-
array[itemOffset + BUILTIN_OFFSET_POSITION_X] = MathUtils.randFloat(
|
|
60
|
-
array[itemOffset + BUILTIN_OFFSET_POSITION_Y] = MathUtils.randFloat(
|
|
61
|
-
array[itemOffset + BUILTIN_OFFSET_POSITION_Z] = MathUtils.randFloat(
|
|
43
|
+
array[itemOffset + BUILTIN_OFFSET_POSITION_X] = MathUtils.randFloat(-halfX, halfX);
|
|
44
|
+
array[itemOffset + BUILTIN_OFFSET_POSITION_Y] = MathUtils.randFloat(-halfY, halfY);
|
|
45
|
+
array[itemOffset + BUILTIN_OFFSET_POSITION_Z] = MathUtils.randFloat(-halfZ, halfZ);
|
|
62
46
|
}
|
|
63
47
|
builtin.needsUpdate = true;
|
|
64
48
|
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import type { FXRange, FXRangeConfig } from "../../miscellaneous/miscellaneous";
|
|
2
2
|
import { FXSpawn } from "./FXSpawn";
|
|
3
3
|
/**
|
|
4
|
-
* Assigns random lifetime to
|
|
5
|
-
*
|
|
6
|
-
* Lifetime is chosen uniformly from the specified range. Age is set to 0.
|
|
4
|
+
* Assigns a random lifetime to each spawned particle
|
|
7
5
|
*/
|
|
8
|
-
export declare class
|
|
6
|
+
export declare class FXSpawnLifetime extends FXSpawn<{
|
|
9
7
|
builtin: "Matrix4";
|
|
10
8
|
}> {
|
|
11
9
|
private lifetimeInternal;
|
|
12
10
|
/**
|
|
13
|
-
* @param lifetime - Lifetime range in seconds.
|
|
11
|
+
* @param lifetime - Lifetime range in seconds; must be positive. Defaults to `{ min: 4, max: 8 }`
|
|
14
12
|
*/
|
|
15
13
|
constructor(lifetime?: FXRangeConfig);
|
|
16
14
|
/** Lifetime range in seconds */
|
|
@@ -4,21 +4,19 @@ import { resolveFXRangeConfig, BUILTIN_OFFSET_LIFETIME, BUILTIN_OFFSET_AGE } fro
|
|
|
4
4
|
import { FXSpawn } from './FXSpawn.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Assigns random lifetime to
|
|
8
|
-
*
|
|
9
|
-
* Lifetime is chosen uniformly from the specified range. Age is set to 0.
|
|
7
|
+
* Assigns a random lifetime to each spawned particle
|
|
10
8
|
*/
|
|
11
|
-
class
|
|
9
|
+
class FXSpawnLifetime extends FXSpawn {
|
|
12
10
|
/**
|
|
13
|
-
* @param lifetime - Lifetime range in seconds.
|
|
11
|
+
* @param lifetime - Lifetime range in seconds; must be positive. Defaults to `{ min: 4, max: 8 }`
|
|
14
12
|
*/
|
|
15
13
|
constructor(lifetime = { min: 4, max: 8 }) {
|
|
16
14
|
super();
|
|
17
15
|
/** @internal */
|
|
18
16
|
this.requiredProperties = { builtin: "Matrix4" };
|
|
19
17
|
this._private_lifetimeInternal = resolveFXRangeConfig(lifetime);
|
|
20
|
-
assertValidPositiveNumber(this._private_lifetimeInternal.min, "
|
|
21
|
-
assertValidPositiveNumber(this._private_lifetimeInternal.max, "
|
|
18
|
+
assertValidPositiveNumber(this._private_lifetimeInternal.min, "FXSpawnLifetime.constructor.lifetime.min");
|
|
19
|
+
assertValidPositiveNumber(this._private_lifetimeInternal.max, "FXSpawnLifetime.constructor.lifetime.max");
|
|
22
20
|
}
|
|
23
21
|
/** Lifetime range in seconds */
|
|
24
22
|
get lifetime() {
|
|
@@ -27,8 +25,8 @@ class FXSpawnRandomLifetime extends FXSpawn {
|
|
|
27
25
|
/** Lifetime range in seconds */
|
|
28
26
|
set lifetime(value) {
|
|
29
27
|
this._private_lifetimeInternal = resolveFXRangeConfig(value);
|
|
30
|
-
assertValidPositiveNumber(this._private_lifetimeInternal.min, "
|
|
31
|
-
assertValidPositiveNumber(this._private_lifetimeInternal.max, "
|
|
28
|
+
assertValidPositiveNumber(this._private_lifetimeInternal.min, "FXSpawnLifetime.lifetime.min");
|
|
29
|
+
assertValidPositiveNumber(this._private_lifetimeInternal.max, "FXSpawnLifetime.lifetime.max");
|
|
32
30
|
}
|
|
33
31
|
/** @internal */
|
|
34
32
|
spawn(properties, instanceBegin, instanceEnd) {
|
|
@@ -44,4 +42,4 @@ class FXSpawnRandomLifetime extends FXSpawn {
|
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
export {
|
|
45
|
+
export { FXSpawnLifetime };
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import type { Vector3Like } from "../../miscellaneous/math";
|
|
2
2
|
import type { FXVector3Config } from "../../miscellaneous/miscellaneous";
|
|
3
3
|
import { FXSpawn } from "./FXSpawn";
|
|
4
|
+
/**
|
|
5
|
+
* Shifts particle spawn positions by a fixed offset
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Adds to the position set by any preceding spawn step rather than overwriting it.
|
|
9
|
+
*/
|
|
4
10
|
export declare class FXSpawnOffset extends FXSpawn<{
|
|
5
11
|
builtin: "Matrix4";
|
|
6
12
|
}> {
|
|
7
13
|
private offsetInternal;
|
|
14
|
+
/**
|
|
15
|
+
* @param offset - Position offset applied to each spawned particle. Defaults to `{ x: 0, y: 0, z: 0 }`
|
|
16
|
+
*/
|
|
8
17
|
constructor(offset?: FXVector3Config);
|
|
9
18
|
/** Particle position offset */
|
|
10
19
|
get offset(): Vector3Like;
|
|
@@ -2,7 +2,16 @@ import { assertValidNumber } from '../../miscellaneous/asserts.js';
|
|
|
2
2
|
import { resolveFXVector3Config, BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_POSITION_Z } from '../../miscellaneous/miscellaneous.js';
|
|
3
3
|
import { FXSpawn } from './FXSpawn.js';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Shifts particle spawn positions by a fixed offset
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Adds to the position set by any preceding spawn step rather than overwriting it.
|
|
10
|
+
*/
|
|
5
11
|
class FXSpawnOffset extends FXSpawn {
|
|
12
|
+
/**
|
|
13
|
+
* @param offset - Position offset applied to each spawned particle. Defaults to `{ x: 0, y: 0, z: 0 }`
|
|
14
|
+
*/
|
|
6
15
|
constructor(offset = { x: 0, y: 0, z: 0 }) {
|
|
7
16
|
super();
|
|
8
17
|
/** @internal */
|