sparcoon 0.0.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/LICENSE +21 -0
- package/dist/behaviorModules/FXBehaviorDirectionalGravity.d.ts +21 -0
- package/dist/behaviorModules/FXBehaviorDirectionalGravity.js +47 -0
- package/dist/behaviorModules/FXBehaviorModule.d.ts +14 -0
- package/dist/behaviorModules/FXBehaviorModule.js +9 -0
- package/dist/behaviorModules/FXBehaviorPointGravity.d.ts +39 -0
- package/dist/behaviorModules/FXBehaviorPointGravity.js +110 -0
- package/dist/behaviorModules/FXBehaviorScaleOverLife.d.ts +22 -0
- package/dist/behaviorModules/FXBehaviorScaleOverLife.js +66 -0
- package/dist/behaviorModules/FXBehaviorTorqueDamping.d.ts +20 -0
- package/dist/behaviorModules/FXBehaviorTorqueDamping.js +48 -0
- package/dist/behaviorModules/FXBehaviorTorqueNoise.d.ts +26 -0
- package/dist/behaviorModules/FXBehaviorTorqueNoise.js +66 -0
- package/dist/behaviorModules/FXBehaviorVelocityDamping.d.ts +20 -0
- package/dist/behaviorModules/FXBehaviorVelocityDamping.js +49 -0
- package/dist/behaviorModules/FXBehaviorVelocityNoise.d.ts +26 -0
- package/dist/behaviorModules/FXBehaviorVelocityNoise.js +73 -0
- package/dist/color/FXColor.Internal.d.ts +7 -0
- package/dist/color/FXColor.Internal.js +42 -0
- package/dist/color/FXColor.d.ts +234 -0
- package/dist/color/FXColor.js +636 -0
- package/dist/elements/FXEmitter.Internal.d.ts +10 -0
- package/dist/elements/FXEmitter.Internal.js +5 -0
- package/dist/elements/FXEmitter.d.ts +29 -0
- package/dist/elements/FXEmitter.js +154 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +18 -0
- package/dist/instancedParticle/FXInstancedParticle.Internal.d.ts +13 -0
- package/dist/instancedParticle/FXInstancedParticle.Internal.js +216 -0
- package/dist/instancedParticle/FXInstancedParticle.d.ts +17 -0
- package/dist/instancedParticle/FXInstancedParticle.js +93 -0
- package/dist/instancedParticle/shared.d.ts +27 -0
- package/dist/instancedParticle/shared.js +123 -0
- package/dist/miscellaneous/FXTransparencyMode.d.ts +7 -0
- package/dist/miscellaneous/asserts.d.ts +21 -0
- package/dist/miscellaneous/asserts.js +48 -0
- package/dist/miscellaneous/math.d.ts +8 -0
- package/dist/miscellaneous/math.js +11 -0
- package/dist/miscellaneous/miscellaneous.d.ts +33 -0
- package/dist/miscellaneous/miscellaneous.js +66 -0
- package/dist/miscellaneous/texture/FXTextureView.Internal.d.ts +49 -0
- package/dist/miscellaneous/texture/FXTextureView.Internal.js +6 -0
- package/dist/miscellaneous/texture/FXTextureView.d.ts +72 -0
- package/dist/miscellaneous/texture/FXTextureView.js +234 -0
- package/dist/miscellaneous/webglCapabilities.d.ts +1 -0
- package/dist/miscellaneous/webglCapabilities.js +45 -0
- package/dist/renderingModules/FXRenderingColorOverLife.d.ts +14 -0
- package/dist/renderingModules/FXRenderingColorOverLife.js +32 -0
- package/dist/renderingModules/FXRenderingColorOverVelocity.d.ts +15 -0
- package/dist/renderingModules/FXRenderingColorOverVelocity.js +37 -0
- package/dist/renderingModules/FXRenderingModule.d.ts +8 -0
- package/dist/renderingModules/FXRenderingModule.js +9 -0
- package/dist/renderingModules/FXRenderingTexture.d.ts +14 -0
- package/dist/renderingModules/FXRenderingTexture.js +26 -0
- package/dist/shaders/FXRenderingColorOverLife.glsl.js +3 -0
- package/dist/shaders/FXRenderingColorOverVelocity.glsl.js +3 -0
- package/dist/shaders/FXRenderingTexture.glsl.js +3 -0
- package/dist/spawnModules/FXSpawnBox.d.ts +27 -0
- package/dist/spawnModules/FXSpawnBox.js +67 -0
- package/dist/spawnModules/FXSpawnModule.d.ts +9 -0
- package/dist/spawnModules/FXSpawnModule.js +9 -0
- package/dist/spawnModules/FXSpawnOffset.d.ts +21 -0
- package/dist/spawnModules/FXSpawnOffset.js +49 -0
- package/dist/spawnModules/FXSpawnRandomLifetime.d.ts +20 -0
- package/dist/spawnModules/FXSpawnRandomLifetime.js +47 -0
- package/dist/spawnModules/FXSpawnRandomRotation.d.ts +20 -0
- package/dist/spawnModules/FXSpawnRandomRotation.js +45 -0
- package/dist/spawnModules/FXSpawnRandomScale.d.ts +26 -0
- package/dist/spawnModules/FXSpawnRandomScale.js +60 -0
- package/dist/spawnModules/FXSpawnRandomTorque.d.ts +20 -0
- package/dist/spawnModules/FXSpawnRandomTorque.js +45 -0
- package/dist/spawnModules/FXSpawnRandomVelocity.d.ts +26 -0
- package/dist/spawnModules/FXSpawnRandomVelocity.js +64 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jango
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Vector3Like } from "../miscellaneous/math";
|
|
2
|
+
import { type FXVector3Config } from "../miscellaneous/miscellaneous";
|
|
3
|
+
import { FXBehaviorModule } from "./FXBehaviorModule";
|
|
4
|
+
/**
|
|
5
|
+
* Applies constant acceleration to all particles.
|
|
6
|
+
*
|
|
7
|
+
* Adds the direction vector to particle velocity each frame.
|
|
8
|
+
*/
|
|
9
|
+
export declare class FXBehaviorDirectionalGravity extends FXBehaviorModule<{
|
|
10
|
+
builtin: "Matrix4";
|
|
11
|
+
}> {
|
|
12
|
+
private directionInternal;
|
|
13
|
+
/**
|
|
14
|
+
* @param direction - Acceleration vector in units/second²
|
|
15
|
+
*/
|
|
16
|
+
constructor(direction: Vector3Like);
|
|
17
|
+
/** Acceleration vector in units/second² */
|
|
18
|
+
get direction(): Vector3Like;
|
|
19
|
+
/** Acceleration vector in units/second² */
|
|
20
|
+
set direction(value: FXVector3Config);
|
|
21
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { assertValidNumber } from '../miscellaneous/asserts.js';
|
|
2
|
+
import { resolveFXVector2Config, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y } from '../miscellaneous/miscellaneous.js';
|
|
3
|
+
import { FXBehaviorModule } from './FXBehaviorModule.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Applies constant acceleration to all particles.
|
|
7
|
+
*
|
|
8
|
+
* Adds the direction vector to particle velocity each frame.
|
|
9
|
+
*/
|
|
10
|
+
class FXBehaviorDirectionalGravity extends FXBehaviorModule {
|
|
11
|
+
/**
|
|
12
|
+
* @param direction - Acceleration vector in units/second²
|
|
13
|
+
*/
|
|
14
|
+
constructor(direction) {
|
|
15
|
+
super();
|
|
16
|
+
/** @internal */
|
|
17
|
+
this.requiredProperties = { builtin: "Matrix4" };
|
|
18
|
+
this._private_directionInternal = resolveFXVector2Config(direction);
|
|
19
|
+
assertValidNumber(this._private_directionInternal.x, "UIBehaviorDirectionalGravity.constructor.direction.x");
|
|
20
|
+
assertValidNumber(this._private_directionInternal.y, "UIBehaviorDirectionalGravity.constructor.direction.y");
|
|
21
|
+
}
|
|
22
|
+
/** Acceleration vector in units/second² */
|
|
23
|
+
get direction() {
|
|
24
|
+
return this._private_directionInternal;
|
|
25
|
+
}
|
|
26
|
+
/** Acceleration vector in units/second² */
|
|
27
|
+
set direction(value) {
|
|
28
|
+
this._private_directionInternal = resolveFXVector2Config(value);
|
|
29
|
+
assertValidNumber(this._private_directionInternal.x, "UIBehaviorDirectionalGravity.direction.x");
|
|
30
|
+
assertValidNumber(this._private_directionInternal.y, "UIBehaviorDirectionalGravity.direction.y");
|
|
31
|
+
}
|
|
32
|
+
/** @internal */
|
|
33
|
+
update(properties, instanceCount, deltaTime) {
|
|
34
|
+
const { builtin } = properties;
|
|
35
|
+
const { array, itemSize } = builtin;
|
|
36
|
+
const offsetX = this._private_directionInternal.x * deltaTime;
|
|
37
|
+
const offsetY = this._private_directionInternal.y * deltaTime;
|
|
38
|
+
for (let i = 0; i < instanceCount; i++) {
|
|
39
|
+
const itemOffset = i * itemSize;
|
|
40
|
+
array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] += offsetX;
|
|
41
|
+
array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] += offsetY;
|
|
42
|
+
}
|
|
43
|
+
builtin.needsUpdate = true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { FXBehaviorDirectionalGravity };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { InstancedBufferAttribute } from "three";
|
|
2
|
+
import type { FXPropertyName } from "../instancedParticle/shared";
|
|
3
|
+
/**
|
|
4
|
+
* Base class for particle behavior modules.
|
|
5
|
+
*
|
|
6
|
+
* Behavior modules update particle properties each frame.
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class FXBehaviorModule<T extends Record<string, FXPropertyName> = Record<string, FXPropertyName>> {
|
|
9
|
+
abstract readonly requiredProperties: T;
|
|
10
|
+
abstract update(properties: {
|
|
11
|
+
[K in keyof T]: InstancedBufferAttribute;
|
|
12
|
+
}, instanceCount: number, deltaTime: number): void;
|
|
13
|
+
destroy?(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Vector3Like } from "../miscellaneous/math";
|
|
2
|
+
import { type FXRange, type FXRangeConfig, type FXVector3Config } from "../miscellaneous/miscellaneous";
|
|
3
|
+
import { FXBehaviorModule } from "./FXBehaviorModule";
|
|
4
|
+
/**
|
|
5
|
+
* Applies gravity attraction toward a point.
|
|
6
|
+
*
|
|
7
|
+
* Force follows inverse power law: strength / distance^exponent. Particles closer than threshold are unaffected.
|
|
8
|
+
*/
|
|
9
|
+
export declare class FXBehaviorPointGravity extends FXBehaviorModule<{
|
|
10
|
+
builtin: "Matrix4";
|
|
11
|
+
}> {
|
|
12
|
+
private centerInternal;
|
|
13
|
+
private strengthInternal;
|
|
14
|
+
private exponentInternal;
|
|
15
|
+
private thresholdInternal;
|
|
16
|
+
/**
|
|
17
|
+
* @param center - Gravity center position
|
|
18
|
+
* @param strength - Force multiplier range. Accepts number, tuple, or range object
|
|
19
|
+
* @param exponent - Distance power exponent range. Accepts number, tuple, or range object
|
|
20
|
+
* @param threshold - Minimum distance range. Accepts number, tuple, or range object
|
|
21
|
+
*/
|
|
22
|
+
constructor(center: Vector3Like, strength: FXRangeConfig, exponent?: FXRangeConfig, threshold?: FXRangeConfig);
|
|
23
|
+
/** Gravity center position */
|
|
24
|
+
get center(): Vector3Like;
|
|
25
|
+
/** Force multiplier range */
|
|
26
|
+
get strength(): FXRange;
|
|
27
|
+
/** Distance power exponent range */
|
|
28
|
+
get exponent(): FXRange;
|
|
29
|
+
/** Minimum distance range */
|
|
30
|
+
get threshold(): FXRange;
|
|
31
|
+
/** Gravity center position */
|
|
32
|
+
set center(value: FXVector3Config);
|
|
33
|
+
/** Force multiplier range */
|
|
34
|
+
set strength(value: FXRangeConfig);
|
|
35
|
+
/** Distance power exponent range */
|
|
36
|
+
set exponent(value: FXRangeConfig);
|
|
37
|
+
/** Minimum distance range */
|
|
38
|
+
set threshold(value: FXRangeConfig);
|
|
39
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { MathUtils } from 'three';
|
|
2
|
+
import { assertValidNumber } from '../miscellaneous/asserts.js';
|
|
3
|
+
import { resolveFXVector2Config, resolveFXRangeConfig, BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_RANDOM_A, BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_RANDOM_C, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y } from '../miscellaneous/miscellaneous.js';
|
|
4
|
+
import { FXBehaviorModule } from './FXBehaviorModule.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Applies gravity attraction toward a point.
|
|
8
|
+
*
|
|
9
|
+
* Force follows inverse power law: strength / distance^exponent. Particles closer than threshold are unaffected.
|
|
10
|
+
*/
|
|
11
|
+
class FXBehaviorPointGravity extends FXBehaviorModule {
|
|
12
|
+
/**
|
|
13
|
+
* @param center - Gravity center position
|
|
14
|
+
* @param strength - Force multiplier range. Accepts number, tuple, or range object
|
|
15
|
+
* @param exponent - Distance power exponent range. Accepts number, tuple, or range object
|
|
16
|
+
* @param threshold - Minimum distance range. Accepts number, tuple, or range object
|
|
17
|
+
*/
|
|
18
|
+
constructor(center, strength, exponent = 2, threshold = 1) {
|
|
19
|
+
super();
|
|
20
|
+
/** @internal */
|
|
21
|
+
this.requiredProperties = { builtin: "Matrix4" };
|
|
22
|
+
this._private_centerInternal = resolveFXVector2Config(center);
|
|
23
|
+
assertValidNumber(this._private_centerInternal.x, "UIBehaviorPointGravity.constructor.center.x");
|
|
24
|
+
assertValidNumber(this._private_centerInternal.y, "UIBehaviorPointGravity.constructor.center.y");
|
|
25
|
+
this._private_strengthInternal = resolveFXRangeConfig(strength);
|
|
26
|
+
assertValidNumber(this._private_strengthInternal.min, "UIBehaviorPointGravity.constructor.strength.min");
|
|
27
|
+
assertValidNumber(this._private_strengthInternal.max, "UIBehaviorPointGravity.constructor.strength.max");
|
|
28
|
+
this._private_exponentInternal = resolveFXRangeConfig(exponent);
|
|
29
|
+
assertValidNumber(this._private_exponentInternal.min, "UIBehaviorPointGravity.constructor.exponent.min");
|
|
30
|
+
assertValidNumber(this._private_exponentInternal.max, "UIBehaviorPointGravity.constructor.exponent.max");
|
|
31
|
+
this._private_thresholdInternal = resolveFXRangeConfig(threshold);
|
|
32
|
+
assertValidNumber(this._private_thresholdInternal.min, "UIBehaviorPointGravity.constructor.threshold.min");
|
|
33
|
+
assertValidNumber(this._private_thresholdInternal.max, "UIBehaviorPointGravity.constructor.threshold.max");
|
|
34
|
+
}
|
|
35
|
+
/** Gravity center position */
|
|
36
|
+
get center() {
|
|
37
|
+
return this._private_centerInternal;
|
|
38
|
+
}
|
|
39
|
+
/** Force multiplier range */
|
|
40
|
+
get strength() {
|
|
41
|
+
return this._private_strengthInternal;
|
|
42
|
+
}
|
|
43
|
+
/** Distance power exponent range */
|
|
44
|
+
get exponent() {
|
|
45
|
+
return this._private_exponentInternal;
|
|
46
|
+
}
|
|
47
|
+
/** Minimum distance range */
|
|
48
|
+
get threshold() {
|
|
49
|
+
return this._private_thresholdInternal;
|
|
50
|
+
}
|
|
51
|
+
/** Gravity center position */
|
|
52
|
+
set center(value) {
|
|
53
|
+
this._private_centerInternal = resolveFXVector2Config(value);
|
|
54
|
+
assertValidNumber(this._private_centerInternal.x, "UIBehaviorPointGravity.center.x");
|
|
55
|
+
assertValidNumber(this._private_centerInternal.y, "UIBehaviorPointGravity.center.y");
|
|
56
|
+
}
|
|
57
|
+
/** Force multiplier range */
|
|
58
|
+
set strength(value) {
|
|
59
|
+
this._private_strengthInternal = resolveFXRangeConfig(value);
|
|
60
|
+
assertValidNumber(this._private_strengthInternal.min, "UIBehaviorPointGravity.strength.min");
|
|
61
|
+
assertValidNumber(this._private_strengthInternal.max, "UIBehaviorPointGravity.strength.max");
|
|
62
|
+
}
|
|
63
|
+
/** Distance power exponent range */
|
|
64
|
+
set exponent(value) {
|
|
65
|
+
this._private_exponentInternal = resolveFXRangeConfig(value);
|
|
66
|
+
assertValidNumber(this._private_exponentInternal.min, "UIBehaviorPointGravity.exponent.min");
|
|
67
|
+
assertValidNumber(this._private_exponentInternal.max, "UIBehaviorPointGravity.exponent.max");
|
|
68
|
+
}
|
|
69
|
+
/** Minimum distance range */
|
|
70
|
+
set threshold(value) {
|
|
71
|
+
this._private_thresholdInternal = resolveFXRangeConfig(value);
|
|
72
|
+
assertValidNumber(this._private_thresholdInternal.min, "UIBehaviorPointGravity.threshold.min");
|
|
73
|
+
assertValidNumber(this._private_thresholdInternal.max, "UIBehaviorPointGravity.threshold.max");
|
|
74
|
+
}
|
|
75
|
+
/** @internal */
|
|
76
|
+
update(properties, instanceCount, deltaTime) {
|
|
77
|
+
const { builtin } = properties;
|
|
78
|
+
const { array, itemSize } = builtin;
|
|
79
|
+
for (let i = 0; i < instanceCount; i++) {
|
|
80
|
+
const itemOffset = i * itemSize;
|
|
81
|
+
const dx = this._private_centerInternal.x - array[itemOffset + BUILTIN_OFFSET_POSITION_X];
|
|
82
|
+
const dy = this._private_centerInternal.y - array[itemOffset + BUILTIN_OFFSET_POSITION_Y];
|
|
83
|
+
// Constant over the life of a particle but different for each particle
|
|
84
|
+
const thresholdT = array[itemOffset + BUILTIN_OFFSET_RANDOM_A];
|
|
85
|
+
const threshold = MathUtils.lerp(this.threshold.min, this.threshold.max, thresholdT);
|
|
86
|
+
const thresholdSquared = threshold * threshold;
|
|
87
|
+
const distanceSquared = dx * dx + dy * dy;
|
|
88
|
+
if (distanceSquared < thresholdSquared) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
// Constant over the life of a particle but different for each particle
|
|
92
|
+
const strengthT = array[itemOffset + BUILTIN_OFFSET_RANDOM_B];
|
|
93
|
+
const strength = MathUtils.lerp(this._private_strengthInternal.min, this._private_strengthInternal.max, strengthT);
|
|
94
|
+
// Constant over the life of a particle but different for each particle
|
|
95
|
+
const exponentT = array[itemOffset + BUILTIN_OFFSET_RANDOM_C];
|
|
96
|
+
const exponent = MathUtils.lerp(this._private_exponentInternal.min, this._private_exponentInternal.max, exponentT);
|
|
97
|
+
const distance = Math.sqrt(distanceSquared);
|
|
98
|
+
const forceMagnitude = strength / Math.pow(distance, exponent);
|
|
99
|
+
const directionX = dx / distance;
|
|
100
|
+
const directionY = dy / distance;
|
|
101
|
+
const accelerationX = directionX * forceMagnitude;
|
|
102
|
+
const accelerationY = directionY * forceMagnitude;
|
|
103
|
+
array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] += accelerationX * deltaTime;
|
|
104
|
+
array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] += accelerationY * deltaTime;
|
|
105
|
+
}
|
|
106
|
+
builtin.needsUpdate = true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { FXBehaviorPointGravity };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type FXAspectConfig, type FXRangeConfig } from "../miscellaneous/miscellaneous";
|
|
2
|
+
import { FXBehaviorModule } from "./FXBehaviorModule";
|
|
3
|
+
/**
|
|
4
|
+
* Animates particle scale over lifetime.
|
|
5
|
+
*
|
|
6
|
+
* Interpolates between scale anchors based on particle age. Requires at least 2 anchors.
|
|
7
|
+
*/
|
|
8
|
+
export declare class FXBehaviorScaleOverLife extends FXBehaviorModule<{
|
|
9
|
+
builtin: "Matrix4";
|
|
10
|
+
}> {
|
|
11
|
+
private readonly scales;
|
|
12
|
+
private aspectInternal;
|
|
13
|
+
/**
|
|
14
|
+
* @param scales - Scale anchor points. Each accepts number, tuple, or range object
|
|
15
|
+
* @param aspect - Width/height ratio. Accepts number or texture
|
|
16
|
+
*/
|
|
17
|
+
constructor(scales: FXRangeConfig[], aspect?: FXAspectConfig);
|
|
18
|
+
/** Width/height aspect ratio */
|
|
19
|
+
get aspect(): number;
|
|
20
|
+
/** Width/height aspect ratio */
|
|
21
|
+
set aspect(value: FXAspectConfig);
|
|
22
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { MathUtils } from 'three';
|
|
2
|
+
import { assertValidNonNegativeNumber, assertValidPositiveNumber } from '../miscellaneous/asserts.js';
|
|
3
|
+
import { resolveFXRangeConfig, resolveAspect, BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME, BUILTIN_OFFSET_RANDOM_A, BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y } from '../miscellaneous/miscellaneous.js';
|
|
4
|
+
import { FXBehaviorModule } from './FXBehaviorModule.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Animates particle scale over lifetime.
|
|
8
|
+
*
|
|
9
|
+
* Interpolates between scale anchors based on particle age. Requires at least 2 anchors.
|
|
10
|
+
*/
|
|
11
|
+
class FXBehaviorScaleOverLife extends FXBehaviorModule {
|
|
12
|
+
/**
|
|
13
|
+
* @param scales - Scale anchor points. Each accepts number, tuple, or range object
|
|
14
|
+
* @param aspect - Width/height ratio. Accepts number or texture
|
|
15
|
+
*/
|
|
16
|
+
constructor(scales, aspect = 1) {
|
|
17
|
+
super();
|
|
18
|
+
/** @internal */
|
|
19
|
+
this.requiredProperties = { builtin: "Matrix4" };
|
|
20
|
+
this._private_scales = [];
|
|
21
|
+
if (scales.length < 2) {
|
|
22
|
+
throw new Error("UIBehaviorScaleOverLife.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, `UIBehaviorScaleOverLife.constructor.scales[${i}].min`);
|
|
27
|
+
assertValidNonNegativeNumber(scale.max, `UIBehaviorScaleOverLife.constructor.scales[${i}].max`);
|
|
28
|
+
this._private_scales.push(scale);
|
|
29
|
+
}
|
|
30
|
+
this._private_aspectInternal = resolveAspect(aspect);
|
|
31
|
+
assertValidPositiveNumber(this._private_aspectInternal, "UIBehaviorScaleOverLife.constructor.aspect");
|
|
32
|
+
}
|
|
33
|
+
/** Width/height aspect ratio */
|
|
34
|
+
get aspect() {
|
|
35
|
+
return this._private_aspectInternal;
|
|
36
|
+
}
|
|
37
|
+
/** Width/height aspect ratio */
|
|
38
|
+
set aspect(value) {
|
|
39
|
+
this._private_aspectInternal = resolveAspect(value);
|
|
40
|
+
assertValidPositiveNumber(this._private_aspectInternal, "UIBehaviorScaleOverLife.aspect");
|
|
41
|
+
}
|
|
42
|
+
/** @internal */
|
|
43
|
+
update(properties, instanceCount) {
|
|
44
|
+
const { builtin } = properties;
|
|
45
|
+
const { array, itemSize } = builtin;
|
|
46
|
+
for (let i = 0; i < instanceCount; i++) {
|
|
47
|
+
const itemOffset = i * itemSize;
|
|
48
|
+
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
|
+
const scaleT = array[itemOffset + BUILTIN_OFFSET_RANDOM_A];
|
|
53
|
+
const localT = segment - index;
|
|
54
|
+
const scaleRange0 = this._private_scales[index];
|
|
55
|
+
const scaleRange1 = this._private_scales[index + 1];
|
|
56
|
+
const scale0 = MathUtils.lerp(scaleRange0.min, scaleRange0.max, scaleT);
|
|
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;
|
|
61
|
+
}
|
|
62
|
+
builtin.needsUpdate = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { FXBehaviorScaleOverLife };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type FXRange, type FXRangeConfig } from "../miscellaneous/miscellaneous";
|
|
2
|
+
import { FXBehaviorModule } from "./FXBehaviorModule";
|
|
3
|
+
/**
|
|
4
|
+
* Reduces particle angular velocity over time.
|
|
5
|
+
*
|
|
6
|
+
* Applies exponential decay to torque. Damping of 0 means no effect, 1 means instant stop.
|
|
7
|
+
*/
|
|
8
|
+
export declare class FXBehaviorTorqueDamping extends FXBehaviorModule<{
|
|
9
|
+
builtin: "Matrix4";
|
|
10
|
+
}> {
|
|
11
|
+
private dampingInternal;
|
|
12
|
+
/**
|
|
13
|
+
* @param damping - Damping coefficient range (0-1). Accepts number, tuple, or range object
|
|
14
|
+
*/
|
|
15
|
+
constructor(damping: number);
|
|
16
|
+
/** Damping coefficient range (0-1) */
|
|
17
|
+
get damping(): FXRange;
|
|
18
|
+
/** Damping coefficient range (0-1) */
|
|
19
|
+
set damping(value: FXRangeConfig);
|
|
20
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { MathUtils } from 'three';
|
|
2
|
+
import { assertValidNonNegativeNumber } from '../miscellaneous/asserts.js';
|
|
3
|
+
import { resolveFXRangeConfig, BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_TORQUE } from '../miscellaneous/miscellaneous.js';
|
|
4
|
+
import { FXBehaviorModule } from './FXBehaviorModule.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Reduces particle angular velocity over time.
|
|
8
|
+
*
|
|
9
|
+
* Applies exponential decay to torque. Damping of 0 means no effect, 1 means instant stop.
|
|
10
|
+
*/
|
|
11
|
+
class FXBehaviorTorqueDamping extends FXBehaviorModule {
|
|
12
|
+
/**
|
|
13
|
+
* @param damping - Damping coefficient range (0-1). Accepts number, tuple, or range object
|
|
14
|
+
*/
|
|
15
|
+
constructor(damping) {
|
|
16
|
+
super();
|
|
17
|
+
/** @internal */
|
|
18
|
+
this.requiredProperties = { builtin: "Matrix4" };
|
|
19
|
+
this._private_dampingInternal = resolveFXRangeConfig(damping);
|
|
20
|
+
assertValidNonNegativeNumber(this._private_dampingInternal.min, `UIBehaviorTorqueDamping.constructor.damping.min`);
|
|
21
|
+
assertValidNonNegativeNumber(this._private_dampingInternal.max, `UIBehaviorTorqueDamping.constructor.damping.max`);
|
|
22
|
+
}
|
|
23
|
+
/** Damping coefficient range (0-1) */
|
|
24
|
+
get damping() {
|
|
25
|
+
return this._private_dampingInternal;
|
|
26
|
+
}
|
|
27
|
+
/** Damping coefficient range (0-1) */
|
|
28
|
+
set damping(value) {
|
|
29
|
+
this._private_dampingInternal = resolveFXRangeConfig(value);
|
|
30
|
+
assertValidNonNegativeNumber(this._private_dampingInternal.min, `UIBehaviorTorqueDamping.damping.min`);
|
|
31
|
+
assertValidNonNegativeNumber(this._private_dampingInternal.max, `UIBehaviorTorqueDamping.damping.max`);
|
|
32
|
+
}
|
|
33
|
+
/** @internal */
|
|
34
|
+
update(properties, instanceCount, deltaTime) {
|
|
35
|
+
const { builtin } = properties;
|
|
36
|
+
const { array, itemSize } = builtin;
|
|
37
|
+
for (let i = 0; i < instanceCount; i++) {
|
|
38
|
+
const itemOffset = i * itemSize;
|
|
39
|
+
// Constant over the life of a particle but different for each particle
|
|
40
|
+
const dampingT = array[itemOffset + BUILTIN_OFFSET_RANDOM_B];
|
|
41
|
+
const dampingFactor = Math.pow(1 - MathUtils.lerp(this._private_dampingInternal.min, this._private_dampingInternal.max, dampingT), deltaTime);
|
|
42
|
+
array[itemOffset + BUILTIN_OFFSET_TORQUE] *= dampingFactor;
|
|
43
|
+
}
|
|
44
|
+
builtin.needsUpdate = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { FXBehaviorTorqueDamping };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type FXRange, type FXRangeConfig } from "../miscellaneous/miscellaneous";
|
|
2
|
+
import { FXBehaviorModule } from "./FXBehaviorModule";
|
|
3
|
+
/**
|
|
4
|
+
* Applies noise-based angular acceleration to particles.
|
|
5
|
+
*
|
|
6
|
+
* Uses 2D noise based on particle position. Higher scale means finer noise detail.
|
|
7
|
+
*/
|
|
8
|
+
export declare class FXBehaviorTorqueNoise extends FXBehaviorModule<{
|
|
9
|
+
builtin: "Matrix4";
|
|
10
|
+
}> {
|
|
11
|
+
private scaleInternal;
|
|
12
|
+
private strengthInternal;
|
|
13
|
+
/**
|
|
14
|
+
* @param scale - Noise frequency range. Accepts number, tuple, or range object
|
|
15
|
+
* @param strength - Force multiplier range. Accepts number, tuple, or range object
|
|
16
|
+
*/
|
|
17
|
+
constructor(scale: number, strength: number);
|
|
18
|
+
/** Noise frequency range */
|
|
19
|
+
get scale(): FXRange;
|
|
20
|
+
/** Force multiplier range */
|
|
21
|
+
get strength(): FXRange;
|
|
22
|
+
/** Noise frequency range */
|
|
23
|
+
set scale(value: FXRangeConfig);
|
|
24
|
+
/** Force multiplier range */
|
|
25
|
+
set strength(value: FXRangeConfig);
|
|
26
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { MathUtils } from 'three';
|
|
2
|
+
import { assertValidPositiveNumber, assertValidNonNegativeNumber } from '../miscellaneous/asserts.js';
|
|
3
|
+
import { resolveFXRangeConfig, BUILTIN_OFFSET_RANDOM_C, generateNoise3D, BUILTIN_OFFSET_POSITION_Z, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_RANDOM_A, BUILTIN_OFFSET_TORQUE } from '../miscellaneous/miscellaneous.js';
|
|
4
|
+
import { FXBehaviorModule } from './FXBehaviorModule.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Applies noise-based angular acceleration to particles.
|
|
8
|
+
*
|
|
9
|
+
* Uses 2D noise based on particle position. Higher scale means finer noise detail.
|
|
10
|
+
*/
|
|
11
|
+
class FXBehaviorTorqueNoise extends FXBehaviorModule {
|
|
12
|
+
/**
|
|
13
|
+
* @param scale - Noise frequency range. Accepts number, tuple, or range object
|
|
14
|
+
* @param strength - Force multiplier range. Accepts number, tuple, or range object
|
|
15
|
+
*/
|
|
16
|
+
constructor(scale, strength) {
|
|
17
|
+
super();
|
|
18
|
+
/** @internal */
|
|
19
|
+
this.requiredProperties = { builtin: "Matrix4" };
|
|
20
|
+
this._private_scaleInternal = resolveFXRangeConfig(scale);
|
|
21
|
+
assertValidPositiveNumber(this._private_scaleInternal.min, `UIBehaviorTorqueNoise.constructor.scale.min`);
|
|
22
|
+
assertValidPositiveNumber(this._private_scaleInternal.max, `UIBehaviorTorqueNoise.constructor.scale.max`);
|
|
23
|
+
this._private_strengthInternal = resolveFXRangeConfig(strength);
|
|
24
|
+
assertValidNonNegativeNumber(this._private_strengthInternal.min, `UIBehaviorTorqueNoise.constructor.strength.min`);
|
|
25
|
+
assertValidNonNegativeNumber(this._private_strengthInternal.max, `UIBehaviorTorqueNoise.constructor.strength.max`);
|
|
26
|
+
}
|
|
27
|
+
/** Noise frequency range */
|
|
28
|
+
get scale() {
|
|
29
|
+
return this._private_scaleInternal;
|
|
30
|
+
}
|
|
31
|
+
/** Force multiplier range */
|
|
32
|
+
get strength() {
|
|
33
|
+
return this._private_strengthInternal;
|
|
34
|
+
}
|
|
35
|
+
/** Noise frequency range */
|
|
36
|
+
set scale(value) {
|
|
37
|
+
this._private_scaleInternal = resolveFXRangeConfig(value);
|
|
38
|
+
assertValidPositiveNumber(this._private_scaleInternal.min, `UIBehaviorTorqueNoise.scale.min`);
|
|
39
|
+
assertValidPositiveNumber(this._private_scaleInternal.max, `UIBehaviorTorqueNoise.scale.max`);
|
|
40
|
+
}
|
|
41
|
+
/** Force multiplier range */
|
|
42
|
+
set strength(value) {
|
|
43
|
+
this._private_strengthInternal = resolveFXRangeConfig(value);
|
|
44
|
+
assertValidNonNegativeNumber(this._private_strengthInternal.min, `UIBehaviorTorqueNoise.strength.min`);
|
|
45
|
+
assertValidNonNegativeNumber(this._private_strengthInternal.max, `UIBehaviorTorqueNoise.strength.max`);
|
|
46
|
+
}
|
|
47
|
+
/** @internal */
|
|
48
|
+
update(properties, instanceCount, deltaTime) {
|
|
49
|
+
const { builtin } = properties;
|
|
50
|
+
const { array, itemSize } = builtin;
|
|
51
|
+
for (let i = 0; i < instanceCount; i++) {
|
|
52
|
+
const itemOffset = i * itemSize;
|
|
53
|
+
// Constant over the life of a particle but different for each particle
|
|
54
|
+
const scaleT = array[itemOffset + BUILTIN_OFFSET_RANDOM_C];
|
|
55
|
+
const scale = MathUtils.lerp(this._private_scaleInternal.min, this._private_scaleInternal.max, scaleT);
|
|
56
|
+
const noise = generateNoise3D(array[itemOffset + BUILTIN_OFFSET_POSITION_X] * scale, array[itemOffset + BUILTIN_OFFSET_POSITION_Y] * scale, array[itemOffset + BUILTIN_OFFSET_POSITION_Z] * scale);
|
|
57
|
+
// Constant over the life of a particle but different for each particle
|
|
58
|
+
const strengthT = array[itemOffset + BUILTIN_OFFSET_RANDOM_A];
|
|
59
|
+
const strength = MathUtils.lerp(this._private_strengthInternal.min, this._private_strengthInternal.max, strengthT);
|
|
60
|
+
array[itemOffset + BUILTIN_OFFSET_TORQUE] += noise * strength * deltaTime;
|
|
61
|
+
}
|
|
62
|
+
builtin.needsUpdate = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { FXBehaviorTorqueNoise };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type FXRange, type FXRangeConfig } from "../miscellaneous/miscellaneous";
|
|
2
|
+
import { FXBehaviorModule } from "./FXBehaviorModule";
|
|
3
|
+
/**
|
|
4
|
+
* Reduces particle velocity over time.
|
|
5
|
+
*
|
|
6
|
+
* Applies exponential decay to velocity. Damping of 0 means no effect, 1 means instant stop.
|
|
7
|
+
*/
|
|
8
|
+
export declare class FXBehaviorVelocityDamping extends FXBehaviorModule<{
|
|
9
|
+
builtin: "Matrix4";
|
|
10
|
+
}> {
|
|
11
|
+
private dampingInternal;
|
|
12
|
+
/**
|
|
13
|
+
* @param damping - Damping coefficient range (0-1). Accepts number, tuple, or range object
|
|
14
|
+
*/
|
|
15
|
+
constructor(damping: FXRangeConfig);
|
|
16
|
+
/** Damping coefficient range (0-1) */
|
|
17
|
+
get damping(): FXRange;
|
|
18
|
+
/** Damping coefficient range (0-1) */
|
|
19
|
+
set damping(value: FXRangeConfig);
|
|
20
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { MathUtils } from 'three';
|
|
2
|
+
import { assertValidNonNegativeNumber } from '../miscellaneous/asserts.js';
|
|
3
|
+
import { resolveFXRangeConfig, BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_VELOCITY_X, BUILTIN_OFFSET_VELOCITY_Y } from '../miscellaneous/miscellaneous.js';
|
|
4
|
+
import { FXBehaviorModule } from './FXBehaviorModule.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Reduces particle velocity over time.
|
|
8
|
+
*
|
|
9
|
+
* Applies exponential decay to velocity. Damping of 0 means no effect, 1 means instant stop.
|
|
10
|
+
*/
|
|
11
|
+
class FXBehaviorVelocityDamping extends FXBehaviorModule {
|
|
12
|
+
/**
|
|
13
|
+
* @param damping - Damping coefficient range (0-1). Accepts number, tuple, or range object
|
|
14
|
+
*/
|
|
15
|
+
constructor(damping) {
|
|
16
|
+
super();
|
|
17
|
+
/** @internal */
|
|
18
|
+
this.requiredProperties = { builtin: "Matrix4" };
|
|
19
|
+
this._private_dampingInternal = resolveFXRangeConfig(damping);
|
|
20
|
+
assertValidNonNegativeNumber(this._private_dampingInternal.min, `UIBehaviorVelocityDamping.constructor.damping.min`);
|
|
21
|
+
assertValidNonNegativeNumber(this._private_dampingInternal.max, `UIBehaviorVelocityDamping.constructor.damping.max`);
|
|
22
|
+
}
|
|
23
|
+
/** Damping coefficient range (0-1) */
|
|
24
|
+
get damping() {
|
|
25
|
+
return this._private_dampingInternal;
|
|
26
|
+
}
|
|
27
|
+
/** Damping coefficient range (0-1) */
|
|
28
|
+
set damping(value) {
|
|
29
|
+
this._private_dampingInternal = resolveFXRangeConfig(value);
|
|
30
|
+
assertValidNonNegativeNumber(this._private_dampingInternal.min, `UIBehaviorVelocityDamping.damping.min`);
|
|
31
|
+
assertValidNonNegativeNumber(this._private_dampingInternal.max, `UIBehaviorVelocityDamping.damping.max`);
|
|
32
|
+
}
|
|
33
|
+
/** @internal */
|
|
34
|
+
update(properties, instanceCount, deltaTime) {
|
|
35
|
+
const { builtin } = properties;
|
|
36
|
+
const { array, itemSize } = builtin;
|
|
37
|
+
for (let i = 0; i < instanceCount; i++) {
|
|
38
|
+
const itemOffset = i * itemSize;
|
|
39
|
+
// Constant over the life of a particle but different for each particle
|
|
40
|
+
const dampingT = array[itemOffset + BUILTIN_OFFSET_RANDOM_B];
|
|
41
|
+
const dampingFactor = Math.pow(1 - MathUtils.lerp(this._private_dampingInternal.min, this._private_dampingInternal.max, dampingT), deltaTime);
|
|
42
|
+
array[itemOffset + BUILTIN_OFFSET_VELOCITY_X] *= dampingFactor;
|
|
43
|
+
array[itemOffset + BUILTIN_OFFSET_VELOCITY_Y] *= dampingFactor;
|
|
44
|
+
}
|
|
45
|
+
builtin.needsUpdate = true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { FXBehaviorVelocityDamping };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type FXRange, type FXRangeConfig } from "../miscellaneous/miscellaneous";
|
|
2
|
+
import { FXBehaviorModule } from "./FXBehaviorModule";
|
|
3
|
+
/**
|
|
4
|
+
* Applies noise-based acceleration to particles.
|
|
5
|
+
*
|
|
6
|
+
* Uses 2D noise based on particle position. Higher scale means finer noise detail.
|
|
7
|
+
*/
|
|
8
|
+
export declare class FXBehaviorVelocityNoise extends FXBehaviorModule<{
|
|
9
|
+
builtin: "Matrix4";
|
|
10
|
+
}> {
|
|
11
|
+
private scaleInternal;
|
|
12
|
+
private strengthInternal;
|
|
13
|
+
/**
|
|
14
|
+
* @param scale - Noise frequency range. Accepts number, tuple, or range object
|
|
15
|
+
* @param strength - Force multiplier range. Accepts number, tuple, or range object
|
|
16
|
+
*/
|
|
17
|
+
constructor(scale?: number, strength?: number);
|
|
18
|
+
/** Noise frequency range */
|
|
19
|
+
get scale(): FXRange;
|
|
20
|
+
/** Force multiplier range */
|
|
21
|
+
get strength(): FXRange;
|
|
22
|
+
/** Noise frequency range */
|
|
23
|
+
set scale(value: FXRangeConfig);
|
|
24
|
+
/** Force multiplier range */
|
|
25
|
+
set strength(value: FXRangeConfig);
|
|
26
|
+
}
|