custom-pixi-particles 8.1.1 → 8.1.2
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/dist/index.d.ts +15 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/Model.d.ts +32 -0
- package/dist/lib/Model.js +44 -0
- package/dist/lib/Model.js.map +1 -0
- package/dist/lib/Particle.d.ts +234 -0
- package/dist/lib/Particle.js +201 -0
- package/dist/lib/Particle.js.map +1 -0
- package/dist/lib/ParticlePool.d.ts +37 -0
- package/dist/lib/ParticlePool.js +56 -0
- package/dist/lib/ParticlePool.js.map +1 -0
- package/dist/lib/behaviour/AngularVelocityBehaviour.d.ts +61 -0
- package/dist/lib/behaviour/AngularVelocityBehaviour.js +118 -0
- package/dist/lib/behaviour/AngularVelocityBehaviour.js.map +1 -0
- package/dist/lib/behaviour/AttractionRepulsionBehaviour.d.ts +42 -0
- package/dist/lib/behaviour/AttractionRepulsionBehaviour.js +78 -0
- package/dist/lib/behaviour/AttractionRepulsionBehaviour.js.map +1 -0
- package/dist/lib/behaviour/Behaviour.d.ts +33 -0
- package/dist/lib/behaviour/Behaviour.js +45 -0
- package/dist/lib/behaviour/Behaviour.js.map +1 -0
- package/dist/lib/behaviour/BehaviourNames.d.ts +22 -0
- package/dist/lib/behaviour/BehaviourNames.js +23 -0
- package/dist/lib/behaviour/BehaviourNames.js.map +1 -0
- package/dist/lib/behaviour/CollisionBehaviour.d.ts +86 -0
- package/dist/lib/behaviour/CollisionBehaviour.js +140 -0
- package/dist/lib/behaviour/CollisionBehaviour.js.map +1 -0
- package/dist/lib/behaviour/ColorBehaviour.d.ts +67 -0
- package/dist/lib/behaviour/ColorBehaviour.js +193 -0
- package/dist/lib/behaviour/ColorBehaviour.js.map +1 -0
- package/dist/lib/behaviour/EmitDirectionBehaviour.d.ts +52 -0
- package/dist/lib/behaviour/EmitDirectionBehaviour.js +105 -0
- package/dist/lib/behaviour/EmitDirectionBehaviour.js.map +1 -0
- package/dist/lib/behaviour/EmitterBehaviours.d.ts +69 -0
- package/dist/lib/behaviour/EmitterBehaviours.js +116 -0
- package/dist/lib/behaviour/EmitterBehaviours.js.map +1 -0
- package/dist/lib/behaviour/ForceFieldsBehaviour.d.ts +53 -0
- package/dist/lib/behaviour/ForceFieldsBehaviour.js +80 -0
- package/dist/lib/behaviour/ForceFieldsBehaviour.js.map +1 -0
- package/dist/lib/behaviour/GroupingBehaviour.d.ts +57 -0
- package/dist/lib/behaviour/GroupingBehaviour.js +143 -0
- package/dist/lib/behaviour/GroupingBehaviour.js.map +1 -0
- package/dist/lib/behaviour/LifeBehaviour.d.ts +47 -0
- package/dist/lib/behaviour/LifeBehaviour.js +65 -0
- package/dist/lib/behaviour/LifeBehaviour.js.map +1 -0
- package/dist/lib/behaviour/LightEffectBehaviour.d.ts +59 -0
- package/dist/lib/behaviour/LightEffectBehaviour.js +94 -0
- package/dist/lib/behaviour/LightEffectBehaviour.js.map +1 -0
- package/dist/lib/behaviour/NoiseBasedMotionBehaviour.d.ts +28 -0
- package/dist/lib/behaviour/NoiseBasedMotionBehaviour.js +50 -0
- package/dist/lib/behaviour/NoiseBasedMotionBehaviour.js.map +1 -0
- package/dist/lib/behaviour/PositionBehaviour.d.ts +164 -0
- package/dist/lib/behaviour/PositionBehaviour.js +484 -0
- package/dist/lib/behaviour/PositionBehaviour.js.map +1 -0
- package/dist/lib/behaviour/RotationBehaviour.d.ts +59 -0
- package/dist/lib/behaviour/RotationBehaviour.js +100 -0
- package/dist/lib/behaviour/RotationBehaviour.js.map +1 -0
- package/dist/lib/behaviour/SizeBehaviour.d.ts +61 -0
- package/dist/lib/behaviour/SizeBehaviour.js +156 -0
- package/dist/lib/behaviour/SizeBehaviour.js.map +1 -0
- package/dist/lib/behaviour/SoundReactiveBehaviour.d.ts +58 -0
- package/dist/lib/behaviour/SoundReactiveBehaviour.js +132 -0
- package/dist/lib/behaviour/SoundReactiveBehaviour.js.map +1 -0
- package/dist/lib/behaviour/SpawnBehaviour.d.ts +89 -0
- package/dist/lib/behaviour/SpawnBehaviour.js +705 -0
- package/dist/lib/behaviour/SpawnBehaviour.js.map +1 -0
- package/dist/lib/behaviour/StretchBehaviour.d.ts +30 -0
- package/dist/lib/behaviour/StretchBehaviour.js +59 -0
- package/dist/lib/behaviour/StretchBehaviour.js.map +1 -0
- package/dist/lib/behaviour/TemperatureBehaviour.d.ts +47 -0
- package/dist/lib/behaviour/TemperatureBehaviour.js +64 -0
- package/dist/lib/behaviour/TemperatureBehaviour.js.map +1 -0
- package/dist/lib/behaviour/TimelineBehaviour.d.ts +73 -0
- package/dist/lib/behaviour/TimelineBehaviour.js +100 -0
- package/dist/lib/behaviour/TimelineBehaviour.js.map +1 -0
- package/dist/lib/behaviour/TurbulenceBehaviour.d.ts +73 -0
- package/dist/lib/behaviour/TurbulenceBehaviour.js +133 -0
- package/dist/lib/behaviour/TurbulenceBehaviour.js.map +1 -0
- package/dist/lib/behaviour/index.d.ts +23 -0
- package/dist/lib/behaviour/index.js +24 -0
- package/dist/lib/behaviour/index.js.map +1 -0
- package/dist/lib/customPixiParticlesSettingsInterface.d.ts +19 -0
- package/dist/lib/customPixiParticlesSettingsInterface.js +2 -0
- package/dist/lib/customPixiParticlesSettingsInterface.js.map +1 -0
- package/dist/lib/emission/AbstractEmission.d.ts +30 -0
- package/dist/lib/emission/AbstractEmission.js +39 -0
- package/dist/lib/emission/AbstractEmission.js.map +1 -0
- package/dist/lib/emission/EmissionTypes.d.ts +6 -0
- package/dist/lib/emission/EmissionTypes.js +6 -0
- package/dist/lib/emission/EmissionTypes.js.map +1 -0
- package/dist/lib/emission/RandomEmission.d.ts +44 -0
- package/dist/lib/emission/RandomEmission.js +66 -0
- package/dist/lib/emission/RandomEmission.js.map +1 -0
- package/dist/lib/emission/StandardEmission.d.ts +62 -0
- package/dist/lib/emission/StandardEmission.js +87 -0
- package/dist/lib/emission/StandardEmission.js.map +1 -0
- package/dist/lib/emission/UniformEmission.d.ts +56 -0
- package/dist/lib/emission/UniformEmission.js +83 -0
- package/dist/lib/emission/UniformEmission.js.map +1 -0
- package/dist/lib/emission/index.d.ts +6 -0
- package/dist/lib/emission/index.js +7 -0
- package/dist/lib/emission/index.js.map +1 -0
- package/dist/lib/emitter/Duration.d.ts +27 -0
- package/dist/lib/emitter/Duration.js +41 -0
- package/dist/lib/emitter/Duration.js.map +1 -0
- package/dist/lib/emitter/Emitter.d.ts +116 -0
- package/dist/lib/emitter/Emitter.js +240 -0
- package/dist/lib/emitter/Emitter.js.map +1 -0
- package/dist/lib/emitter/index.d.ts +3 -0
- package/dist/lib/emitter/index.js +4 -0
- package/dist/lib/emitter/index.js.map +1 -0
- package/dist/lib/index.d.ts +20 -0
- package/dist/lib/index.js +21 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/parser/BehaviourParser.d.ts +21 -0
- package/dist/lib/parser/BehaviourParser.js +72 -0
- package/dist/lib/parser/BehaviourParser.js.map +1 -0
- package/dist/lib/parser/CompatibilityHelper.d.ts +12 -0
- package/dist/lib/parser/CompatibilityHelper.js +19 -0
- package/dist/lib/parser/CompatibilityHelper.js.map +1 -0
- package/dist/lib/parser/EmitControllerParser.d.ts +27 -0
- package/dist/lib/parser/EmitControllerParser.js +39 -0
- package/dist/lib/parser/EmitControllerParser.js.map +1 -0
- package/dist/lib/parser/EmitterParser.d.ts +67 -0
- package/dist/lib/parser/EmitterParser.js +168 -0
- package/dist/lib/parser/EmitterParser.js.map +1 -0
- package/dist/lib/parser/index.d.ts +5 -0
- package/dist/lib/parser/index.js +6 -0
- package/dist/lib/parser/index.js.map +1 -0
- package/dist/lib/pixi/Renderer.d.ts +125 -0
- package/dist/lib/pixi/Renderer.js +560 -0
- package/dist/lib/pixi/Renderer.js.map +1 -0
- package/dist/lib/pixi/TestRenderer.d.ts +125 -0
- package/dist/lib/pixi/TestRenderer.js +560 -0
- package/dist/lib/pixi/TestRenderer.js.map +1 -0
- package/dist/lib/util/Color.d.ts +133 -0
- package/dist/lib/util/Color.js +173 -0
- package/dist/lib/util/Color.js.map +1 -0
- package/dist/lib/util/List.d.ts +49 -0
- package/dist/lib/util/List.js +87 -0
- package/dist/lib/util/List.js.map +1 -0
- package/dist/lib/util/MinMax.d.ts +34 -0
- package/dist/lib/util/MinMax.js +46 -0
- package/dist/lib/util/MinMax.js.map +1 -0
- package/dist/lib/util/Point.d.ts +34 -0
- package/dist/lib/util/Point.js +46 -0
- package/dist/lib/util/Point.js.map +1 -0
- package/dist/lib/util/Random.d.ts +24 -0
- package/dist/lib/util/Random.js +30 -0
- package/dist/lib/util/Random.js.map +1 -0
- package/dist/lib/util/ThereBack.d.ts +14 -0
- package/dist/lib/util/ThereBack.js +23 -0
- package/dist/lib/util/ThereBack.js.map +1 -0
- package/dist/lib/util/index.d.ts +5 -0
- package/dist/lib/util/index.js +6 -0
- package/dist/lib/util/index.js.map +1 -0
- package/dist/lib/util/maths.d.ts +10 -0
- package/dist/lib/util/maths.js +13 -0
- package/dist/lib/util/maths.js.map +1 -0
- package/dist/lib/util/turbulencePool.d.ts +4 -0
- package/dist/lib/util/turbulencePool.js +7 -0
- package/dist/lib/util/turbulencePool.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import Behaviour from './Behaviour';
|
|
2
|
+
import Particle from '../Particle';
|
|
3
|
+
export default class AngularVelocityBehaviour extends Behaviour {
|
|
4
|
+
protected priority: number;
|
|
5
|
+
private enabled;
|
|
6
|
+
private degrees;
|
|
7
|
+
private degreesVariance;
|
|
8
|
+
private maxRadius;
|
|
9
|
+
private maxRadiusVariance;
|
|
10
|
+
private minRadius;
|
|
11
|
+
private minRadiusVariance;
|
|
12
|
+
private oscillate;
|
|
13
|
+
private oscillationSpeed;
|
|
14
|
+
private oscillationAmplitude;
|
|
15
|
+
private linearRadiusReduction;
|
|
16
|
+
private dynamicRadius;
|
|
17
|
+
/**
|
|
18
|
+
* Initializes particle properties of the behaviour
|
|
19
|
+
*
|
|
20
|
+
* @param {Particle} particle - The current particle
|
|
21
|
+
* @memberof AngularVelocityBehaviour
|
|
22
|
+
*/
|
|
23
|
+
init: (particle: Particle) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Applies the behaviour to the particle
|
|
26
|
+
*
|
|
27
|
+
* @param {Particle} particle - The current particle
|
|
28
|
+
* @param {number} deltaTime - Time elapsed since the last frame
|
|
29
|
+
* @memberof AngularVelocityBehaviour
|
|
30
|
+
*/
|
|
31
|
+
apply: (particle: Particle, deltaTime: number) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the name of the behaviour
|
|
34
|
+
*
|
|
35
|
+
* @returns {string} Name of the behaviour
|
|
36
|
+
* @memberof AngularVelocityBehaviour
|
|
37
|
+
*/
|
|
38
|
+
getName(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the properties of the behaviour
|
|
41
|
+
*
|
|
42
|
+
* @returns {object} Properties of the behaviour
|
|
43
|
+
* @memberof AngularVelocityBehaviour
|
|
44
|
+
*/
|
|
45
|
+
getProps(): {
|
|
46
|
+
enabled: boolean;
|
|
47
|
+
degrees: number;
|
|
48
|
+
degreesVariance: number;
|
|
49
|
+
maxRadius: number;
|
|
50
|
+
maxRadiusVariance: number;
|
|
51
|
+
minRadius: number;
|
|
52
|
+
minRadiusVariance: number;
|
|
53
|
+
oscillate: boolean;
|
|
54
|
+
oscillationSpeed: number;
|
|
55
|
+
oscillationAmplitude: number;
|
|
56
|
+
linearRadiusReduction: boolean;
|
|
57
|
+
dynamicRadius: boolean;
|
|
58
|
+
priority: number;
|
|
59
|
+
name: string;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import Behaviour from './Behaviour';
|
|
2
|
+
import math from '../util/maths';
|
|
3
|
+
import BehaviourNames from './BehaviourNames';
|
|
4
|
+
export default class AngularVelocityBehaviour extends Behaviour {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.priority = 100;
|
|
8
|
+
this.enabled = false;
|
|
9
|
+
this.degrees = 0;
|
|
10
|
+
this.degreesVariance = 0;
|
|
11
|
+
this.maxRadius = 0;
|
|
12
|
+
this.maxRadiusVariance = 0;
|
|
13
|
+
this.minRadius = 0;
|
|
14
|
+
this.minRadiusVariance = 0;
|
|
15
|
+
this.oscillate = false; // Oscillate angular velocity
|
|
16
|
+
this.oscillationSpeed = 1; // Speed of oscillation
|
|
17
|
+
this.oscillationAmplitude = 10; // Amplitude of oscillation in degrees
|
|
18
|
+
this.linearRadiusReduction = true; // Linear or exponential radius reduction
|
|
19
|
+
this.dynamicRadius = false; // Allow dynamic radius changes during lifetime
|
|
20
|
+
/**
|
|
21
|
+
* Initializes particle properties of the behaviour
|
|
22
|
+
*
|
|
23
|
+
* @param {Particle} particle - The current particle
|
|
24
|
+
* @memberof AngularVelocityBehaviour
|
|
25
|
+
*/
|
|
26
|
+
this.init = (particle) => {
|
|
27
|
+
if (!this.enabled)
|
|
28
|
+
return;
|
|
29
|
+
particle.radiansPerSecond = math.degreesToRadians(this.degrees + this.varianceFrom(this.degreesVariance));
|
|
30
|
+
const radiusStart = this.maxRadius + this.varianceFrom(this.maxRadiusVariance);
|
|
31
|
+
const radiusEnd = this.minRadius + this.varianceFrom(this.minRadiusVariance);
|
|
32
|
+
particle.radiusStart = radiusStart;
|
|
33
|
+
particle.radiusEnd = radiusEnd;
|
|
34
|
+
particle.velocityAngle = 0;
|
|
35
|
+
particle.x = 0;
|
|
36
|
+
particle.y = 0;
|
|
37
|
+
particle.radius = radiusStart;
|
|
38
|
+
particle.angle = 0;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Applies the behaviour to the particle
|
|
42
|
+
*
|
|
43
|
+
* @param {Particle} particle - The current particle
|
|
44
|
+
* @param {number} deltaTime - Time elapsed since the last frame
|
|
45
|
+
* @memberof AngularVelocityBehaviour
|
|
46
|
+
*/
|
|
47
|
+
this.apply = (particle, deltaTime) => {
|
|
48
|
+
if (!this.enabled)
|
|
49
|
+
return;
|
|
50
|
+
if (particle.skipAngularVelocityBehaviour)
|
|
51
|
+
return;
|
|
52
|
+
const { radiusStart, radiusEnd, radiansPerSecond, lifeProgress, velocityAngle } = particle;
|
|
53
|
+
let angleVelocity = radiansPerSecond;
|
|
54
|
+
// Oscillation logic
|
|
55
|
+
if (this.oscillate) {
|
|
56
|
+
const oscillationFactor = Math.sin(particle.lifeTime * this.oscillationSpeed) * this.oscillationAmplitude;
|
|
57
|
+
angleVelocity += math.degreesToRadians(oscillationFactor);
|
|
58
|
+
}
|
|
59
|
+
// Update angle
|
|
60
|
+
const newVelocityAngle = velocityAngle + angleVelocity * deltaTime;
|
|
61
|
+
// Radius calculation
|
|
62
|
+
let newRadius;
|
|
63
|
+
if (this.linearRadiusReduction) {
|
|
64
|
+
newRadius = radiusStart + (radiusEnd - radiusStart) * lifeProgress;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// Exponential radius reduction
|
|
68
|
+
const progressFactor = Math.pow(lifeProgress, 2);
|
|
69
|
+
newRadius = radiusStart + (radiusEnd - radiusStart) * progressFactor;
|
|
70
|
+
}
|
|
71
|
+
if (this.dynamicRadius) {
|
|
72
|
+
newRadius += Math.sin(particle.lifeTime * 2 * Math.PI) * 5; // Example dynamic change
|
|
73
|
+
}
|
|
74
|
+
const movementX = Math.cos(newVelocityAngle) * newRadius;
|
|
75
|
+
const movementY = Math.sin(newVelocityAngle) * newRadius;
|
|
76
|
+
particle.velocityAngle = newVelocityAngle;
|
|
77
|
+
particle.radius = newRadius;
|
|
78
|
+
particle.movement.x = movementX;
|
|
79
|
+
particle.movement.y = movementY;
|
|
80
|
+
particle.x = movementX;
|
|
81
|
+
particle.y = movementY;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns the name of the behaviour
|
|
86
|
+
*
|
|
87
|
+
* @returns {string} Name of the behaviour
|
|
88
|
+
* @memberof AngularVelocityBehaviour
|
|
89
|
+
*/
|
|
90
|
+
getName() {
|
|
91
|
+
return BehaviourNames.ANGULAR_BEHAVIOUR;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns the properties of the behaviour
|
|
95
|
+
*
|
|
96
|
+
* @returns {object} Properties of the behaviour
|
|
97
|
+
* @memberof AngularVelocityBehaviour
|
|
98
|
+
*/
|
|
99
|
+
getProps() {
|
|
100
|
+
return {
|
|
101
|
+
enabled: this.enabled,
|
|
102
|
+
degrees: this.degrees,
|
|
103
|
+
degreesVariance: this.degreesVariance,
|
|
104
|
+
maxRadius: this.maxRadius,
|
|
105
|
+
maxRadiusVariance: this.maxRadiusVariance,
|
|
106
|
+
minRadius: this.minRadius,
|
|
107
|
+
minRadiusVariance: this.minRadiusVariance,
|
|
108
|
+
oscillate: this.oscillate,
|
|
109
|
+
oscillationSpeed: this.oscillationSpeed,
|
|
110
|
+
oscillationAmplitude: this.oscillationAmplitude,
|
|
111
|
+
linearRadiusReduction: this.linearRadiusReduction,
|
|
112
|
+
dynamicRadius: this.dynamicRadius,
|
|
113
|
+
priority: this.priority,
|
|
114
|
+
name: this.getName(),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=AngularVelocityBehaviour.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AngularVelocityBehaviour.js","sourceRoot":"","sources":["../../../src/lib/behaviour/AngularVelocityBehaviour.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAA;AACnC,OAAO,IAAI,MAAM,eAAe,CAAA;AAChC,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAG7C,MAAM,CAAC,OAAO,OAAO,wBAAyB,SAAQ,SAAS;IAA/D;;QACY,aAAQ,GAAW,GAAG,CAAA;QACxB,YAAO,GAAY,KAAK,CAAA;QACxB,YAAO,GAAW,CAAC,CAAA;QACnB,oBAAe,GAAW,CAAC,CAAA;QA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AAS,GAAG,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,GAAG,SAAS,CAAA;YAExD,QAAQ,CAAC,aAAa,GAAG,gBAAgB,CAAA;YACzC,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAA;YAC3B,QAAQ,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAA;YAC/B,QAAQ,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAA;YAC/B,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAA;YACtB,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAA;QACxB,CAAC,CAAA;IAoCH,CAAC;IAlCC;;;;;OAKG;IACH,OAAO;QACL,OAAO,cAAc,CAAC,iBAAiB,CAAA;IACzC,CAAC;IAED;;;;;OAKG;IACH,QAAQ;QACN,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,oBAAoB,EAAE,IAAI,CAAC,oBAAoB;YAC/C,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;YACjD,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE;SACrB,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Behaviour } from './index';
|
|
2
|
+
import Particle from '../Particle';
|
|
3
|
+
/**
|
|
4
|
+
* AttractionRepulsionBehaviour applies attraction or repulsion forces to particles
|
|
5
|
+
* without overriding other position-related behaviors.
|
|
6
|
+
* @extends Behaviour
|
|
7
|
+
*/
|
|
8
|
+
export default class AttractionRepulsionBehaviour extends Behaviour {
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
priority: number;
|
|
11
|
+
/**
|
|
12
|
+
* List of influence points affecting particles.
|
|
13
|
+
* Each point: { point: Point, strength: number, range: number }
|
|
14
|
+
*/
|
|
15
|
+
influencePoints: never[];
|
|
16
|
+
/**
|
|
17
|
+
* Initializes the particle, but does not modify position directly.
|
|
18
|
+
* @param {Particle} particle - The particle to initialize.
|
|
19
|
+
*/
|
|
20
|
+
init: (particle: Particle) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Applies attraction or repulsion forces to the particle additively.
|
|
23
|
+
* @param {Particle} particle - The particle to apply the behavior to.
|
|
24
|
+
* @param {number} deltaTime - Time elapsed since the last frame.
|
|
25
|
+
*/
|
|
26
|
+
apply: (particle: Particle, deltaTime: number) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the name of the behavior.
|
|
29
|
+
* @returns {string} - The name of the behavior.
|
|
30
|
+
*/
|
|
31
|
+
getName(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the properties of the behavior.
|
|
34
|
+
* @returns {object} - The properties of the behavior.
|
|
35
|
+
*/
|
|
36
|
+
getProps(): {
|
|
37
|
+
enabled: boolean;
|
|
38
|
+
priority: number;
|
|
39
|
+
influencePoints: never[];
|
|
40
|
+
name: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Behaviour, BehaviourNames } from './index';
|
|
2
|
+
/**
|
|
3
|
+
* AttractionRepulsionBehaviour applies attraction or repulsion forces to particles
|
|
4
|
+
* without overriding other position-related behaviors.
|
|
5
|
+
* @extends Behaviour
|
|
6
|
+
*/
|
|
7
|
+
export default class AttractionRepulsionBehaviour extends Behaviour {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.enabled = true;
|
|
11
|
+
this.priority = 200; // Ensure this runs after PositionBehaviour if needed
|
|
12
|
+
/**
|
|
13
|
+
* List of influence points affecting particles.
|
|
14
|
+
* Each point: { point: Point, strength: number, range: number }
|
|
15
|
+
*/
|
|
16
|
+
this.influencePoints = [];
|
|
17
|
+
/**
|
|
18
|
+
* Initializes the particle, but does not modify position directly.
|
|
19
|
+
* @param {Particle} particle - The particle to initialize.
|
|
20
|
+
*/
|
|
21
|
+
this.init = (particle) => {
|
|
22
|
+
// Initialization logic if needed.
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Applies attraction or repulsion forces to the particle additively.
|
|
26
|
+
* @param {Particle} particle - The particle to apply the behavior to.
|
|
27
|
+
* @param {number} deltaTime - Time elapsed since the last frame.
|
|
28
|
+
*/
|
|
29
|
+
this.apply = (particle, deltaTime) => {
|
|
30
|
+
if (!this.enabled || particle.skipPositionBehaviour || particle.skipAttractionRepulsionBehaviour)
|
|
31
|
+
return;
|
|
32
|
+
// Accumulate influence forces
|
|
33
|
+
let totalForceX = 0;
|
|
34
|
+
let totalForceY = 0;
|
|
35
|
+
this.influencePoints.forEach(({ point, strength, range }) => {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
const dx = point.x - particle.x;
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
const dy = point.y - particle.y;
|
|
40
|
+
const distanceSquared = dx * dx + dy * dy;
|
|
41
|
+
if (distanceSquared > range * range || distanceSquared === 0)
|
|
42
|
+
return;
|
|
43
|
+
const distance = Math.sqrt(distanceSquared);
|
|
44
|
+
const force = strength * (1 - distance / range) * deltaTime;
|
|
45
|
+
const normalizedDx = dx / distance;
|
|
46
|
+
const normalizedDy = dy / distance;
|
|
47
|
+
totalForceX += normalizedDx * force;
|
|
48
|
+
totalForceY += normalizedDy * force;
|
|
49
|
+
});
|
|
50
|
+
// Add forces to particle velocity (or acceleration for smoother effects)
|
|
51
|
+
particle.velocity.x += totalForceX;
|
|
52
|
+
particle.velocity.y += totalForceY;
|
|
53
|
+
// Apply updated velocity to position additively
|
|
54
|
+
particle.x += particle.velocity.x * deltaTime;
|
|
55
|
+
particle.y += particle.velocity.y * deltaTime;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets the name of the behavior.
|
|
60
|
+
* @returns {string} - The name of the behavior.
|
|
61
|
+
*/
|
|
62
|
+
getName() {
|
|
63
|
+
return BehaviourNames.ATTRACTION_REPULSION_BEHAVIOUR;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets the properties of the behavior.
|
|
67
|
+
* @returns {object} - The properties of the behavior.
|
|
68
|
+
*/
|
|
69
|
+
getProps() {
|
|
70
|
+
return {
|
|
71
|
+
enabled: this.enabled,
|
|
72
|
+
priority: this.priority,
|
|
73
|
+
influencePoints: this.influencePoints,
|
|
74
|
+
name: this.getName(),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=AttractionRepulsionBehaviour.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttractionRepulsionBehaviour.js","sourceRoot":"","sources":["../../../src/lib/behaviour/AttractionRepulsionBehaviour.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAGnD;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,4BAA6B,SAAQ,SAAS;IAAnE;;QACE,YAAO,GAAG,IAAI,CAAA;QACd,aAAQ,GAAG,GAAG,CAAA,CAAC,qDAAqD;QAEpE;;;WAGG;QACH,oBAAe,GAAG,EAAE,CAAA;QAEpB;;;WAGG;QACH,SAAI,GAAG,CAAC,QAAkB,EAAE,EAAE;YAC5B,kCAAkC;QACpC,CAAC,CAAA;QAED;;;;WAIG;QACH,UAAK,GAAG,CAAC,QAAkB,EAAE,SAAiB,EAAE,EAAE;YAChD,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,Q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,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAA;QAC/C,CAAC,CAAA;IAsBH,CAAC;IApBC;;;OAGG;IACH,OAAO;QACL,OAAO,cAAc,CAAC,8BAA8B,CAAA;IACtD,CAAC;IAED;;;OAGG;IACH,QAAQ;QACN,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE;SACrB,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import BehaviourParser from '../parser/BehaviourParser';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new Behaviour
|
|
4
|
+
*
|
|
5
|
+
* @class
|
|
6
|
+
*/
|
|
7
|
+
export default class Behaviour {
|
|
8
|
+
/**
|
|
9
|
+
* A protected property used to store the priority of the behaviour
|
|
10
|
+
*
|
|
11
|
+
* @protected
|
|
12
|
+
*/
|
|
13
|
+
protected priority: number;
|
|
14
|
+
/**
|
|
15
|
+
* Calculates the variance from a given value
|
|
16
|
+
*
|
|
17
|
+
* @param {number} value - a given value
|
|
18
|
+
* @returns {number} the variance based on the given value
|
|
19
|
+
*/
|
|
20
|
+
varianceFrom: (value: number) => number;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the name of the behaviour
|
|
23
|
+
*
|
|
24
|
+
* @returns {string} The name of the behaviour
|
|
25
|
+
*/
|
|
26
|
+
getName(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the parser for the behaviour
|
|
29
|
+
*
|
|
30
|
+
* @returns {BehaviourParser} The parser for the behaviour
|
|
31
|
+
*/
|
|
32
|
+
getParser: () => BehaviourParser;
|
|
33
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import BehaviourParser from '../parser/BehaviourParser';
|
|
2
|
+
import { Random } from '../util';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new Behaviour
|
|
5
|
+
*
|
|
6
|
+
* @class
|
|
7
|
+
*/
|
|
8
|
+
export default class Behaviour {
|
|
9
|
+
constructor() {
|
|
10
|
+
/**
|
|
11
|
+
* A protected property used to store the priority of the behaviour
|
|
12
|
+
*
|
|
13
|
+
* @protected
|
|
14
|
+
*/
|
|
15
|
+
this.priority = 0;
|
|
16
|
+
/**
|
|
17
|
+
* Calculates the variance from a given value
|
|
18
|
+
*
|
|
19
|
+
* @param {number} value - a given value
|
|
20
|
+
* @returns {number} the variance based on the given value
|
|
21
|
+
*/
|
|
22
|
+
this.varianceFrom = (value) => {
|
|
23
|
+
if (value === 0)
|
|
24
|
+
return 0;
|
|
25
|
+
return Random.uniform(-1.0, 1.0) * value;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Gets the parser for the behaviour
|
|
29
|
+
*
|
|
30
|
+
* @returns {BehaviourParser} The parser for the behaviour
|
|
31
|
+
*/
|
|
32
|
+
this.getParser = () => {
|
|
33
|
+
return new BehaviourParser(this);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Gets the name of the behaviour
|
|
38
|
+
*
|
|
39
|
+
* @returns {string} The name of the behaviour
|
|
40
|
+
*/
|
|
41
|
+
getName() {
|
|
42
|
+
throw new Error('This method has to be overridden in subclass');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=Behaviour.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Behaviour.js","sourceRoot":"","sources":["../../../src/lib/behaviour/Behaviour.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEhC;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAA9B;QACE;;;;WAIG;QACO,aAAQ,GAAG,CAAC,CAAA;QAEtB;;;;;WAKG;QACH,iBAAY,GAAG,CAAC,KAAa,EAAE,EAAE;YAC/B,IAAI,KAAK,KAAK,CAAC;gBAAE,OAAO,CAAC,CAAA;YACzB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,CAAA;QAC1C,CAAC,CAAA;QAWD;;;;WAIG;QACH,cAAS,GAAG,GAAG,EAAE;YACf,OAAO,IAAI,eAAe,CAAC,IAAI,CAAC,CAAA;QAClC,CAAC,CAAA;IACH,CAAC;IAjBC;;;;OAIG;IACH,OAAO;QACL,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;IACjE,CAAC;CAUF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare const behaviourNames: {
|
|
2
|
+
ANGULAR_BEHAVIOUR: string;
|
|
3
|
+
LIFE_BEHAVIOUR: string;
|
|
4
|
+
COLOR_BEHAVIOUR: string;
|
|
5
|
+
POSITION_BEHAVIOUR: string;
|
|
6
|
+
SIZE_BEHAVIOUR: string;
|
|
7
|
+
EMIT_DIRECTION: string;
|
|
8
|
+
ROTATION_BEHAVIOUR: string;
|
|
9
|
+
TURBULENCE_BEHAVIOUR: string;
|
|
10
|
+
COLLISION_BEHAVIOUR: string;
|
|
11
|
+
ATTRACTION_REPULSION_BEHAVIOUR: string;
|
|
12
|
+
NOISE_BASED_MOTION_BEHAVIOUR: string;
|
|
13
|
+
FORCE_FIELDS_BEHAVIOUR: string;
|
|
14
|
+
SPAWN_BEHAVIOUR: string;
|
|
15
|
+
TIMELINE_BEHAVIOUR: string;
|
|
16
|
+
GROUPING_BEHAVIOUR: string;
|
|
17
|
+
SOUND_REACTIVE_BEHAVIOUR: string;
|
|
18
|
+
LIGHT_EFFECT_BEHAVIOUR: string;
|
|
19
|
+
STRETCH_BEHAVIOUR: string;
|
|
20
|
+
TEMPERATURE_BEHAVIOUR: string;
|
|
21
|
+
};
|
|
22
|
+
export default behaviourNames;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const behaviourNames = {
|
|
2
|
+
ANGULAR_BEHAVIOUR: 'AngularVelocityBehaviour',
|
|
3
|
+
LIFE_BEHAVIOUR: 'LifeBehaviour',
|
|
4
|
+
COLOR_BEHAVIOUR: 'ColorBehaviour',
|
|
5
|
+
POSITION_BEHAVIOUR: 'PositionBehaviour',
|
|
6
|
+
SIZE_BEHAVIOUR: 'SizeBehaviour',
|
|
7
|
+
EMIT_DIRECTION: 'EmitDirectionBehaviour',
|
|
8
|
+
ROTATION_BEHAVIOUR: 'RotationBehaviour',
|
|
9
|
+
TURBULENCE_BEHAVIOUR: 'TurbulenceBehaviour',
|
|
10
|
+
COLLISION_BEHAVIOUR: 'CollisionBehaviour',
|
|
11
|
+
ATTRACTION_REPULSION_BEHAVIOUR: 'AttractionRepulsionBehaviour',
|
|
12
|
+
NOISE_BASED_MOTION_BEHAVIOUR: 'NoiseBasedMotionBehaviour',
|
|
13
|
+
FORCE_FIELDS_BEHAVIOUR: 'ForceFieldsBehaviour',
|
|
14
|
+
SPAWN_BEHAVIOUR: 'SpawnBehaviour',
|
|
15
|
+
TIMELINE_BEHAVIOUR: 'TimelineBehaviour',
|
|
16
|
+
GROUPING_BEHAVIOUR: 'GroupingBehaviour',
|
|
17
|
+
SOUND_REACTIVE_BEHAVIOUR: 'SoundReactiveBehaviour',
|
|
18
|
+
LIGHT_EFFECT_BEHAVIOUR: 'LightEffectBehaviour',
|
|
19
|
+
STRETCH_BEHAVIOUR: 'StretchBehaviour',
|
|
20
|
+
TEMPERATURE_BEHAVIOUR: 'TemperatureBehaviour',
|
|
21
|
+
};
|
|
22
|
+
export default behaviourNames;
|
|
23
|
+
//# sourceMappingURL=BehaviourNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BehaviourNames.js","sourceRoot":"","sources":["../../../src/lib/behaviour/BehaviourNames.ts"],"names":[],"mappings":"AAAA,MAAM,cAAc,GAAG;IACrB,iBAAiB,EAAE,0BAA0B;IAC7C,cAAc,EAAE,eAAe;IAC/B,eAAe,EAAE,gBAAgB;IACjC,kBAAkB,EAAE,mBAAmB;IACvC,cAAc,EAAE,eAAe;IAC/B,cAAc,EAAE,wBAAwB;IACxC,kBAAkB,EAAE,mBAAmB;IACvC,oBAAoB,EAAE,qBAAqB;IAC3C,mBAAmB,EAAE,oBAAoB;IACzC,8BAA8B,EAAE,8BAA8B;IAC9D,4BAA4B,EAAE,2BAA2B;IACzD,sBAAsB,EAAE,sBAAsB;IAC9C,eAAe,EAAE,gBAAgB;IACjC,kBAAkB,EAAE,mBAAmB;IACvC,kBAAkB,EAAE,mBAAmB;IACvC,wBAAwB,EAAE,wBAAwB;IAClD,sBAAsB,EAAE,sBAAsB;IAC9C,iBAAiB,EAAE,kBAAkB;IACrC,qBAAqB,EAAE,sBAAsB;CAC9C,CAAA;AAED,eAAe,cAAc,CAAA"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Behaviour } from './index';
|
|
2
|
+
import Particle from '../Particle';
|
|
3
|
+
import Model from '../Model';
|
|
4
|
+
export default class CollisionBehaviour extends Behaviour {
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
skipPositionBehaviourOnCollision: boolean;
|
|
7
|
+
skipAngularVelocityBehaviourOnCollision: boolean;
|
|
8
|
+
skipColorBehaviourOnCollision: boolean;
|
|
9
|
+
skipAttractionRepulsionBehaviourOnCollision: boolean;
|
|
10
|
+
skipEmitDirectionBehaviourOnCollision: boolean;
|
|
11
|
+
skipRotationBehaviourOnCollision: boolean;
|
|
12
|
+
skipSizeBehaviourOnCollision: boolean;
|
|
13
|
+
priority: number;
|
|
14
|
+
distance: number;
|
|
15
|
+
lines: {
|
|
16
|
+
point1: {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
};
|
|
20
|
+
point2: {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
};
|
|
24
|
+
}[];
|
|
25
|
+
/**
|
|
26
|
+
* Function that initializes a particle
|
|
27
|
+
* @param {Particle} particle - The particle to be initialized
|
|
28
|
+
* @param {Model} model - The model of the particle
|
|
29
|
+
*/
|
|
30
|
+
init: (particle: Particle, model: Model) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Applies the particle's velocity and acceleration to move it and calculate its size, rotation, and position.
|
|
33
|
+
* @param {Particle} particle - The particle to be moved
|
|
34
|
+
* @param {number} deltaTime - The time delta for the movement calculation
|
|
35
|
+
* @param {Model} model - The model containing information about the particle's movement
|
|
36
|
+
*/
|
|
37
|
+
apply: (particle: Particle, deltaTime: number, model: Model) => void;
|
|
38
|
+
reflectVelocity: (particle: Particle, normal: {
|
|
39
|
+
x: number;
|
|
40
|
+
y: number;
|
|
41
|
+
}) => void;
|
|
42
|
+
checkCollisionAndReflect: (particle: Particle) => boolean;
|
|
43
|
+
calculateNormal: (point1: {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
}, point2: {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
}) => {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
};
|
|
53
|
+
pointToLineDistance: (x: number, y: number, x1: number, y1: number, x2: number, y2: number) => number;
|
|
54
|
+
/**
|
|
55
|
+
* Gets the name of the behaviour
|
|
56
|
+
* @return {BehaviourNames} The name of the behaviour
|
|
57
|
+
*/
|
|
58
|
+
getName(): string;
|
|
59
|
+
/**
|
|
60
|
+
* @description Retrieves the properties of the object.
|
|
61
|
+
* @returns {Object} The properties of the object.
|
|
62
|
+
*/
|
|
63
|
+
getProps(): {
|
|
64
|
+
enabled: boolean;
|
|
65
|
+
skipPositionBehaviourOnCollision: boolean;
|
|
66
|
+
skipAngularVelocityBehaviourOnCollision: boolean;
|
|
67
|
+
skipColorBehaviourOnCollision: boolean;
|
|
68
|
+
skipAttractionRepulsionBehaviourOnCollision: boolean;
|
|
69
|
+
skipEmitDirectionBehaviourOnCollision: boolean;
|
|
70
|
+
skipRotationBehaviourOnCollision: boolean;
|
|
71
|
+
skipSizeBehaviourOnCollision: boolean;
|
|
72
|
+
priority: number;
|
|
73
|
+
lines: {
|
|
74
|
+
point1: {
|
|
75
|
+
x: number;
|
|
76
|
+
y: number;
|
|
77
|
+
};
|
|
78
|
+
point2: {
|
|
79
|
+
x: number;
|
|
80
|
+
y: number;
|
|
81
|
+
};
|
|
82
|
+
}[];
|
|
83
|
+
distance: number;
|
|
84
|
+
name: string;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Behaviour, BehaviourNames } from './index';
|
|
2
|
+
export default class CollisionBehaviour extends Behaviour {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.enabled = false;
|
|
6
|
+
this.skipPositionBehaviourOnCollision = false;
|
|
7
|
+
this.skipAngularVelocityBehaviourOnCollision = false;
|
|
8
|
+
this.skipColorBehaviourOnCollision = false;
|
|
9
|
+
this.skipAttractionRepulsionBehaviourOnCollision = false;
|
|
10
|
+
this.skipEmitDirectionBehaviourOnCollision = false;
|
|
11
|
+
this.skipRotationBehaviourOnCollision = false;
|
|
12
|
+
this.skipSizeBehaviourOnCollision = false;
|
|
13
|
+
this.priority = 10000;
|
|
14
|
+
this.distance = 10;
|
|
15
|
+
this.lines = [
|
|
16
|
+
{ point1: { x: 0, y: 0 }, point2: { x: 0, y: 0 } },
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Function that initializes a particle
|
|
20
|
+
* @param {Particle} particle - The particle to be initialized
|
|
21
|
+
* @param {Model} model - The model of the particle
|
|
22
|
+
*/
|
|
23
|
+
this.init = (particle, model) => {
|
|
24
|
+
// do nothing
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Applies the particle's velocity and acceleration to move it and calculate its size, rotation, and position.
|
|
28
|
+
* @param {Particle} particle - The particle to be moved
|
|
29
|
+
* @param {number} deltaTime - The time delta for the movement calculation
|
|
30
|
+
* @param {Model} model - The model containing information about the particle's movement
|
|
31
|
+
*/
|
|
32
|
+
this.apply = (particle, deltaTime, model) => {
|
|
33
|
+
if (!this.enabled)
|
|
34
|
+
return;
|
|
35
|
+
this.checkCollisionAndReflect(particle);
|
|
36
|
+
};
|
|
37
|
+
this.reflectVelocity = (particle, normal) => {
|
|
38
|
+
const dotProduct = particle.velocity.x * normal.x + particle.velocity.y * normal.y;
|
|
39
|
+
particle.velocity.x = particle.velocity.x - 2 * dotProduct * normal.x;
|
|
40
|
+
particle.velocity.y = particle.velocity.y - 2 * dotProduct * normal.y;
|
|
41
|
+
if (this.skipPositionBehaviourOnCollision) {
|
|
42
|
+
particle.skipPositionBehaviour = true;
|
|
43
|
+
}
|
|
44
|
+
if (this.skipAngularVelocityBehaviourOnCollision) {
|
|
45
|
+
particle.skipAngularVelocityBehaviour = true;
|
|
46
|
+
}
|
|
47
|
+
if (this.skipColorBehaviourOnCollision) {
|
|
48
|
+
particle.skipColorBehaviour = true;
|
|
49
|
+
}
|
|
50
|
+
if (this.skipAttractionRepulsionBehaviourOnCollision) {
|
|
51
|
+
particle.skipAttractionRepulsionBehaviour = true;
|
|
52
|
+
}
|
|
53
|
+
if (this.skipEmitDirectionBehaviourOnCollision) {
|
|
54
|
+
particle.skipEmitDirectionBehaviour = true;
|
|
55
|
+
}
|
|
56
|
+
if (this.skipRotationBehaviourOnCollision) {
|
|
57
|
+
particle.skipRotationBehaviour = true;
|
|
58
|
+
}
|
|
59
|
+
if (this.skipSizeBehaviourOnCollision) {
|
|
60
|
+
particle.skipSizeBehaviour = true;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
this.checkCollisionAndReflect = (particle) => {
|
|
64
|
+
if (this.lines.length === 0)
|
|
65
|
+
return false; // No lines to check collision
|
|
66
|
+
for (const line of this.lines) {
|
|
67
|
+
const { point1, point2 } = line;
|
|
68
|
+
// Check if the particle is near the line segment (using point-line distance)
|
|
69
|
+
const dist = this.pointToLineDistance(particle.x, particle.y, point1.x, point1.y, point2.x, point2.y);
|
|
70
|
+
if (dist <= this.distance) {
|
|
71
|
+
// Reflect velocity based on the line's normal
|
|
72
|
+
const normal = this.calculateNormal(point1, point2);
|
|
73
|
+
this.reflectVelocity(particle, normal);
|
|
74
|
+
return true; // Stop further checks after first collision
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
};
|
|
79
|
+
this.calculateNormal = (point1, point2) => {
|
|
80
|
+
const dx = point2.x - point1.x;
|
|
81
|
+
const dy = point2.y - point1.y;
|
|
82
|
+
const length = Math.sqrt(dx * dx + dy * dy);
|
|
83
|
+
return { x: -dy / length, y: dx / length }; // Perpendicular vector (normalized)
|
|
84
|
+
};
|
|
85
|
+
this.pointToLineDistance = (x, y, x1, y1, x2, y2) => {
|
|
86
|
+
const A = x - x1;
|
|
87
|
+
const B = y - y1;
|
|
88
|
+
const C = x2 - x1;
|
|
89
|
+
const D = y2 - y1;
|
|
90
|
+
const dot = A * C + B * D;
|
|
91
|
+
const lenSq = C * C + D * D;
|
|
92
|
+
const param = lenSq !== 0 ? dot / lenSq : -1;
|
|
93
|
+
let xx;
|
|
94
|
+
let yy;
|
|
95
|
+
if (param < 0) {
|
|
96
|
+
xx = x1;
|
|
97
|
+
yy = y1;
|
|
98
|
+
}
|
|
99
|
+
else if (param > 1) {
|
|
100
|
+
xx = x2;
|
|
101
|
+
yy = y2;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
xx = x1 + param * C;
|
|
105
|
+
yy = y1 + param * D;
|
|
106
|
+
}
|
|
107
|
+
const dx = x - xx;
|
|
108
|
+
const dy = y - yy;
|
|
109
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Gets the name of the behaviour
|
|
114
|
+
* @return {BehaviourNames} The name of the behaviour
|
|
115
|
+
*/
|
|
116
|
+
getName() {
|
|
117
|
+
return BehaviourNames.COLLISION_BEHAVIOUR;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @description Retrieves the properties of the object.
|
|
121
|
+
* @returns {Object} The properties of the object.
|
|
122
|
+
*/
|
|
123
|
+
getProps() {
|
|
124
|
+
return {
|
|
125
|
+
enabled: this.enabled,
|
|
126
|
+
skipPositionBehaviourOnCollision: this.skipPositionBehaviourOnCollision,
|
|
127
|
+
skipAngularVelocityBehaviourOnCollision: this.skipAngularVelocityBehaviourOnCollision,
|
|
128
|
+
skipColorBehaviourOnCollision: this.skipColorBehaviourOnCollision,
|
|
129
|
+
skipAttractionRepulsionBehaviourOnCollision: this.skipAttractionRepulsionBehaviourOnCollision,
|
|
130
|
+
skipEmitDirectionBehaviourOnCollision: this.skipEmitDirectionBehaviourOnCollision,
|
|
131
|
+
skipRotationBehaviourOnCollision: this.skipRotationBehaviourOnCollision,
|
|
132
|
+
skipSizeBehaviourOnCollision: this.skipSizeBehaviourOnCollision,
|
|
133
|
+
priority: this.priority,
|
|
134
|
+
lines: this.lines,
|
|
135
|
+
distance: this.distance,
|
|
136
|
+
name: this.getName(),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=CollisionBehaviour.js.map
|