@newkrok/three-particles 0.8.4 → 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.8.4",
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.141.0",
30
+ "three": "^0.144.0",
31
31
  "three-noise": "1.1.2",
32
- "@newkrok/three-utils": "^0.3.0"
32
+ "@newkrok/three-utils": "^0.4.0"
33
33
  },
34
34
  "scripts": {
35
35
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -283,6 +283,26 @@ 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
307
  config = DEFAULT_PARTICLE_SYSTEM_CONFIG,
288
308
  externalNow
@@ -304,6 +324,7 @@ export const createParticleSystem = (
304
324
  lifetimeValues: {},
305
325
  creationTimes: [],
306
326
  noise: null,
327
+ isEnabled: true,
307
328
  };
308
329
 
309
330
  const normalizedConfig = patchObject(DEFAULT_PARTICLE_SYSTEM_CONFIG, config);
@@ -577,9 +598,10 @@ export const createParticleSystem = (
577
598
  generalData.startValues.startOpacity[particleIndex] =
578
599
  THREE.MathUtils.randFloat(startOpacity.min, startOpacity.max);
579
600
 
580
- geometry.attributes.rotation.array[particleIndex] = THREE.MathUtils.degToRad(
581
- THREE.MathUtils.randFloat(startRotation.min, startRotation.max)
582
- );
601
+ geometry.attributes.rotation.array[particleIndex] =
602
+ THREE.MathUtils.degToRad(
603
+ THREE.MathUtils.randFloat(startRotation.min, startRotation.max)
604
+ );
583
605
 
584
606
  if (normalizedConfig.rotationOverLifetime.isActive)
585
607
  generalData.lifetimeValues.rotationOverLifetime[particleIndex] =
@@ -691,25 +713,16 @@ export const createParticleSystem = (
691
713
  activateParticle,
692
714
  });
693
715
 
694
- return wrapper || particleSystem;
695
- };
716
+ const resumeEmitter = () => (generalData.isEnabled = true);
717
+ const pauseEmitter = () => (generalData.isEnabled = false);
718
+ const dispose = () => destroyParticleSystem(particleSystem);
696
719
 
697
- export const destroyParticleSystem = (particleSystem) => {
698
- createdParticleSystems = createdParticleSystems.filter(
699
- ({ particleSystem: savedParticleSystem, wrapper }) => {
700
- if (
701
- savedParticleSystem !== particleSystem &&
702
- wrapper !== particleSystem
703
- ) {
704
- return true;
705
- }
706
-
707
- savedParticleSystem.geometry.dispose();
708
- savedParticleSystem.material.dispose();
709
- savedParticleSystem.parent.remove(savedParticleSystem);
710
- return false;
711
- }
712
- );
720
+ return {
721
+ instance: wrapper || particleSystem,
722
+ resumeEmitter,
723
+ pauseEmitter,
724
+ dispose,
725
+ };
713
726
  };
714
727
 
715
728
  export const updateParticleSystems = ({ now, delta, elapsed }) => {
@@ -742,6 +755,7 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
742
755
  worldQuaternion,
743
756
  worldEuler,
744
757
  gravityVelocity,
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)