@newkrok/three-particles 0.8.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newkrok/three-particles",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Particle system for ThreeJS",
|
|
5
|
-
"main": "src/js/three-particles.js",
|
|
5
|
+
"main": "src/js/effects/three-particles.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"three-particles": "src/js/three-particles.js"
|
|
7
|
+
"three-particles": "src/js/effects/three-particles.js"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"homepage": "https://github.com/NewKrok/three-particles#readme",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"easing-functions": "1.0.1",
|
|
30
|
-
"three": "0.
|
|
30
|
+
"three": "^0.144.0",
|
|
31
31
|
"three-noise": "1.1.2",
|
|
32
|
-
"@newkrok/three-utils": "0.
|
|
32
|
+
"@newkrok/three-utils": "^0.4.0"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -72,7 +72,7 @@ export const calculateRandomPositionAndVelocityOnCone = (
|
|
|
72
72
|
|
|
73
73
|
const positionLength = position.length();
|
|
74
74
|
const normalizedAngle = Math.abs(
|
|
75
|
-
(positionLength / radius) * THREE.
|
|
75
|
+
(positionLength / radius) * THREE.MathUtils.degToRad(angle)
|
|
76
76
|
);
|
|
77
77
|
const sinNormalizedAngle = Math.sin(normalizedAngle);
|
|
78
78
|
|
|
@@ -195,8 +195,8 @@ export const calculateRandomPositionAndVelocityOnRectangle = (
|
|
|
195
195
|
) => {
|
|
196
196
|
const xOffset = Math.random() * scale.x - scale.x / 2;
|
|
197
197
|
const yOffset = Math.random() * scale.y - scale.y / 2;
|
|
198
|
-
const rotationX = THREE.
|
|
199
|
-
const rotationY = THREE.
|
|
198
|
+
const rotationX = THREE.MathUtils.degToRad(rotation.x);
|
|
199
|
+
const rotationY = THREE.MathUtils.degToRad(rotation.y);
|
|
200
200
|
position.x = xOffset * Math.cos(rotationY);
|
|
201
201
|
position.y = yOffset * Math.cos(rotationX);
|
|
202
202
|
position.z = xOffset * Math.sin(rotationY) - yOffset * Math.sin(rotationX);
|
|
@@ -283,10 +283,31 @@ const calculatePositionAndVelocity = (
|
|
|
283
283
|
}
|
|
284
284
|
};
|
|
285
285
|
|
|
286
|
+
export const destroyParticleSystem = (particleSystem) => {
|
|
287
|
+
createdParticleSystems = createdParticleSystems.filter(
|
|
288
|
+
({ particleSystem: savedParticleSystem, wrapper }) => {
|
|
289
|
+
if (
|
|
290
|
+
savedParticleSystem !== particleSystem &&
|
|
291
|
+
wrapper !== particleSystem &&
|
|
292
|
+
particleSystem.instance !== particleSystem
|
|
293
|
+
) {
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
savedParticleSystem.geometry.dispose();
|
|
298
|
+
savedParticleSystem.material.dispose();
|
|
299
|
+
if (savedParticleSystem.parent)
|
|
300
|
+
savedParticleSystem.parent.remove(savedParticleSystem);
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
);
|
|
304
|
+
};
|
|
305
|
+
|
|
286
306
|
export const createParticleSystem = (
|
|
287
|
-
config = DEFAULT_PARTICLE_SYSTEM_CONFIG
|
|
307
|
+
config = DEFAULT_PARTICLE_SYSTEM_CONFIG,
|
|
308
|
+
externalNow
|
|
288
309
|
) => {
|
|
289
|
-
const now = Date.now();
|
|
310
|
+
const now = externalNow || Date.now();
|
|
290
311
|
const generalData = {
|
|
291
312
|
distanceFromLastEmitByDistance: 0,
|
|
292
313
|
lastWorldPosition: new THREE.Vector3(-99999),
|
|
@@ -303,6 +324,7 @@ export const createParticleSystem = (
|
|
|
303
324
|
lifetimeValues: {},
|
|
304
325
|
creationTimes: [],
|
|
305
326
|
noise: null,
|
|
327
|
+
isEnabled: true,
|
|
306
328
|
};
|
|
307
329
|
|
|
308
330
|
const normalizedConfig = patchObject(DEFAULT_PARTICLE_SYSTEM_CONFIG, config);
|
|
@@ -497,7 +519,7 @@ export const createParticleSystem = (
|
|
|
497
519
|
createFloat32AttributesRequest("opacity", 0);
|
|
498
520
|
|
|
499
521
|
createFloat32AttributesRequest("rotation", () =>
|
|
500
|
-
THREE.
|
|
522
|
+
THREE.MathUtils.degToRad(
|
|
501
523
|
THREE.MathUtils.randFloat(startRotation.min, startRotation.max)
|
|
502
524
|
)
|
|
503
525
|
);
|
|
@@ -576,9 +598,10 @@ export const createParticleSystem = (
|
|
|
576
598
|
generalData.startValues.startOpacity[particleIndex] =
|
|
577
599
|
THREE.MathUtils.randFloat(startOpacity.min, startOpacity.max);
|
|
578
600
|
|
|
579
|
-
geometry.attributes.rotation.array[particleIndex] =
|
|
580
|
-
THREE.MathUtils.
|
|
581
|
-
|
|
601
|
+
geometry.attributes.rotation.array[particleIndex] =
|
|
602
|
+
THREE.MathUtils.degToRad(
|
|
603
|
+
THREE.MathUtils.randFloat(startRotation.min, startRotation.max)
|
|
604
|
+
);
|
|
582
605
|
|
|
583
606
|
if (normalizedConfig.rotationOverLifetime.isActive)
|
|
584
607
|
generalData.lifetimeValues.rotationOverLifetime[particleIndex] =
|
|
@@ -656,9 +679,9 @@ export const createParticleSystem = (
|
|
|
656
679
|
particleSystem.sortParticles = true;
|
|
657
680
|
|
|
658
681
|
particleSystem.position.copy(transform.position);
|
|
659
|
-
particleSystem.rotation.x = THREE.
|
|
660
|
-
particleSystem.rotation.y = THREE.
|
|
661
|
-
particleSystem.rotation.z = THREE.
|
|
682
|
+
particleSystem.rotation.x = THREE.MathUtils.degToRad(transform.rotation.x);
|
|
683
|
+
particleSystem.rotation.y = THREE.MathUtils.degToRad(transform.rotation.y);
|
|
684
|
+
particleSystem.rotation.z = THREE.MathUtils.degToRad(transform.rotation.z);
|
|
662
685
|
particleSystem.scale.copy(transform.scale);
|
|
663
686
|
|
|
664
687
|
const calculatedCreationTime =
|
|
@@ -690,25 +713,16 @@ export const createParticleSystem = (
|
|
|
690
713
|
activateParticle,
|
|
691
714
|
});
|
|
692
715
|
|
|
693
|
-
|
|
694
|
-
|
|
716
|
+
const resumeEmitter = () => (generalData.isEnabled = true);
|
|
717
|
+
const pauseEmitter = () => (generalData.isEnabled = false);
|
|
718
|
+
const dispose = () => destroyParticleSystem(particleSystem);
|
|
695
719
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
) {
|
|
703
|
-
return true;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
savedParticleSystem.geometry.dispose();
|
|
707
|
-
savedParticleSystem.material.dispose();
|
|
708
|
-
savedParticleSystem.parent.remove(savedParticleSystem);
|
|
709
|
-
return false;
|
|
710
|
-
}
|
|
711
|
-
);
|
|
720
|
+
return {
|
|
721
|
+
instance: wrapper || particleSystem,
|
|
722
|
+
resumeEmitter,
|
|
723
|
+
pauseEmitter,
|
|
724
|
+
dispose,
|
|
725
|
+
};
|
|
712
726
|
};
|
|
713
727
|
|
|
714
728
|
export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
@@ -741,7 +755,7 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
|
741
755
|
worldQuaternion,
|
|
742
756
|
worldEuler,
|
|
743
757
|
gravityVelocity,
|
|
744
|
-
|
|
758
|
+
isEnabled,
|
|
745
759
|
} = generalData;
|
|
746
760
|
|
|
747
761
|
if (wrapper) generalData.wrapperQuaternion.copy(wrapper.parent.quaternion);
|
|
@@ -842,7 +856,7 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
|
842
856
|
}
|
|
843
857
|
});
|
|
844
858
|
|
|
845
|
-
if (looping || lifetime < duration * 1000) {
|
|
859
|
+
if (isEnabled && (looping || lifetime < duration * 1000)) {
|
|
846
860
|
const emissionDelta = now - lastEmissionTime;
|
|
847
861
|
const neededParticlesByTime = Math.floor(
|
|
848
862
|
emission.rateOverTime * (emissionDelta / 1000)
|