@newkrok/three-particles 0.6.1 → 0.6.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/README.md +5 -1
- package/package.json +1 -1
- package/src/js/effects/three-particles.js +38 -8
package/README.md
CHANGED
|
@@ -6,6 +6,10 @@ Particle system for ThreeJS
|
|
|
6
6
|
|
|
7
7
|
You can create your own particle effects with it's editor https://github.com/NewKrok/three-particles-editor
|
|
8
8
|
|
|
9
|
+
# Video
|
|
10
|
+
- Projectiles: https://youtu.be/Q352JuxON04
|
|
11
|
+
- First preview: https://youtu.be/dtN_bndvoGU
|
|
12
|
+
|
|
9
13
|
# Live demo
|
|
10
14
|
|
|
11
15
|
https://newkrok.com/three-particles-editor/index.html
|
|
@@ -18,4 +22,4 @@ Install with npm
|
|
|
18
22
|
`npm i @newkrok/three-particles`
|
|
19
23
|
|
|
20
24
|
Add as a package.json dependency
|
|
21
|
-
`"dependencies": { ... "@newkrok/three-particles": "0.6.
|
|
25
|
+
`"dependencies": { ... "@newkrok/three-particles": "0.6.2" ... }, `
|
package/package.json
CHANGED
|
@@ -480,7 +480,7 @@ export const createParticleSystem = (
|
|
|
480
480
|
geometry.attributes.colorA.needsUpdate = true;
|
|
481
481
|
};
|
|
482
482
|
|
|
483
|
-
const activateParticle = ({ particleIndex, activationTime }) => {
|
|
483
|
+
const activateParticle = ({ particleIndex, activationTime, position }) => {
|
|
484
484
|
geometry.attributes.isActive.array[particleIndex] = true;
|
|
485
485
|
generalData.creationTimes[particleIndex] = activationTime;
|
|
486
486
|
|
|
@@ -543,11 +543,11 @@ export const createParticleSystem = (
|
|
|
543
543
|
);
|
|
544
544
|
const positionIndex = Math.floor(particleIndex * 3);
|
|
545
545
|
geometry.attributes.position.array[positionIndex] =
|
|
546
|
-
startPositions[particleIndex].x;
|
|
546
|
+
(position ? position.x : 0) + startPositions[particleIndex].x;
|
|
547
547
|
geometry.attributes.position.array[positionIndex + 1] =
|
|
548
|
-
startPositions[particleIndex].y;
|
|
548
|
+
(position ? position.y : 0) + startPositions[particleIndex].y;
|
|
549
549
|
geometry.attributes.position.array[positionIndex + 2] =
|
|
550
|
-
startPositions[particleIndex].z;
|
|
550
|
+
(position ? position.z : 0) + startPositions[particleIndex].z;
|
|
551
551
|
geometry.attributes.position.needsUpdate = true;
|
|
552
552
|
|
|
553
553
|
geometry.attributes.lifetime.array[particleIndex] = 0;
|
|
@@ -642,6 +642,8 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
|
642
642
|
gravityVelocity,
|
|
643
643
|
} = generalData;
|
|
644
644
|
|
|
645
|
+
const lastWorldPositionSnapshot = { ...lastWorldPosition };
|
|
646
|
+
|
|
645
647
|
const lifetime = now - creationTime;
|
|
646
648
|
particleSystem.material.uniforms.elapsed.value = elapsed;
|
|
647
649
|
|
|
@@ -652,7 +654,7 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
|
652
654
|
currentWorldPosition.y - lastWorldPosition.y,
|
|
653
655
|
currentWorldPosition.z - lastWorldPosition.z
|
|
654
656
|
);
|
|
655
|
-
worldPositionChange.applyQuaternion(worldQuaternion.invert())
|
|
657
|
+
worldPositionChange.applyQuaternion(worldQuaternion.invert());
|
|
656
658
|
}
|
|
657
659
|
generalData.distanceFromLastEmitByDistance += worldPositionChange.length();
|
|
658
660
|
particleSystem.getWorldPosition(lastWorldPosition);
|
|
@@ -669,7 +671,7 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
|
669
671
|
lastWorldPosition.x,
|
|
670
672
|
lastWorldPosition.y + gravity,
|
|
671
673
|
lastWorldPosition.z
|
|
672
|
-
|
|
674
|
+
);
|
|
673
675
|
particleSystem.worldToLocal(gravityVelocity);
|
|
674
676
|
}
|
|
675
677
|
|
|
@@ -746,12 +748,28 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
|
746
748
|
(1 / emission.rateOverDistance)
|
|
747
749
|
)
|
|
748
750
|
: 0;
|
|
751
|
+
const distanceStep =
|
|
752
|
+
neededParticlesByDistance > 0
|
|
753
|
+
? {
|
|
754
|
+
x:
|
|
755
|
+
(currentWorldPosition.x - lastWorldPositionSnapshot.x) /
|
|
756
|
+
neededParticlesByDistance,
|
|
757
|
+
y:
|
|
758
|
+
(currentWorldPosition.y - lastWorldPositionSnapshot.y) /
|
|
759
|
+
neededParticlesByDistance,
|
|
760
|
+
z:
|
|
761
|
+
(currentWorldPosition.z - lastWorldPositionSnapshot.z) /
|
|
762
|
+
neededParticlesByDistance,
|
|
763
|
+
}
|
|
764
|
+
: null;
|
|
749
765
|
const neededParticles = neededParticlesByTime + neededParticlesByDistance;
|
|
750
766
|
|
|
751
|
-
if (emission.rateOverDistance > 0 && neededParticlesByDistance >= 1)
|
|
767
|
+
if (emission.rateOverDistance > 0 && neededParticlesByDistance >= 1) {
|
|
752
768
|
generalData.distanceFromLastEmitByDistance = 0;
|
|
769
|
+
}
|
|
753
770
|
|
|
754
771
|
if (neededParticles > 0) {
|
|
772
|
+
let generatedParticlesByDistanceNeeds = 0;
|
|
755
773
|
for (let i = 0; i < neededParticles; i++) {
|
|
756
774
|
let particleIndex = -1;
|
|
757
775
|
particleSystem.geometry.attributes.isActive.array.find(
|
|
@@ -770,7 +788,19 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
|
770
788
|
particleIndex <
|
|
771
789
|
particleSystem.geometry.attributes.isActive.array.length
|
|
772
790
|
) {
|
|
773
|
-
|
|
791
|
+
let position;
|
|
792
|
+
if (generatedParticlesByDistanceNeeds < neededParticlesByDistance) {
|
|
793
|
+
position =
|
|
794
|
+
generatedParticlesByDistanceNeeds < neededParticlesByDistance
|
|
795
|
+
? {
|
|
796
|
+
x: distanceStep.x * generatedParticlesByDistanceNeeds,
|
|
797
|
+
y: distanceStep.y * generatedParticlesByDistanceNeeds,
|
|
798
|
+
z: distanceStep.z * generatedParticlesByDistanceNeeds,
|
|
799
|
+
}
|
|
800
|
+
: null;
|
|
801
|
+
generatedParticlesByDistanceNeeds++;
|
|
802
|
+
}
|
|
803
|
+
activateParticle({ particleIndex, activationTime: now, position });
|
|
774
804
|
props.lastEmissionTime = now;
|
|
775
805
|
}
|
|
776
806
|
}
|