@newkrok/three-particles 0.7.1 → 0.8.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newkrok/three-particles",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "Particle system for ThreeJS",
|
|
5
5
|
"main": "src/js/three-particles.js",
|
|
6
6
|
"bin": {
|
|
@@ -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.
|
|
31
|
-
"three-noise": "
|
|
32
|
-
"@newkrok/three-utils": "0.1.
|
|
30
|
+
"three": "0.140.1",
|
|
31
|
+
"three-noise": "1.1.2",
|
|
32
|
+
"@newkrok/three-utils": "0.1.1"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -2,7 +2,9 @@ import * as THREE from "three";
|
|
|
2
2
|
|
|
3
3
|
import { getCurveFunction } from "./three-particles-curves.js";
|
|
4
4
|
|
|
5
|
+
const ROTATION_CONVERTER = THREE.MathUtils.radToDeg(1);
|
|
5
6
|
const noiseInput = new THREE.Vector3(0, 0, 0);
|
|
7
|
+
const orbitalEuler = new THREE.Euler();
|
|
6
8
|
|
|
7
9
|
const curveModifiers = [
|
|
8
10
|
// {key:"colorOverLifetime", attributeKeys:["colorR", "colorG", "colorB"]},
|
|
@@ -23,12 +25,38 @@ export const applyModifiers = ({
|
|
|
23
25
|
noise,
|
|
24
26
|
startValues,
|
|
25
27
|
lifetimeValues,
|
|
28
|
+
hasOrbitalVelocity,
|
|
29
|
+
orbitalVelocityData,
|
|
26
30
|
normalizedConfig,
|
|
27
31
|
attributes,
|
|
32
|
+
particleLifetime,
|
|
28
33
|
particleLifetimePercentage,
|
|
29
34
|
particleIndex,
|
|
30
35
|
forceUpdate = false,
|
|
31
36
|
}) => {
|
|
37
|
+
if (hasOrbitalVelocity) {
|
|
38
|
+
const positionIndex = particleIndex * 3;
|
|
39
|
+
const positionArr = attributes.position.array;
|
|
40
|
+
const { speed, positionOffset } = orbitalVelocityData[particleIndex];
|
|
41
|
+
|
|
42
|
+
positionArr[positionIndex] -= positionOffset.x;
|
|
43
|
+
positionArr[positionIndex + 1] -= positionOffset.y;
|
|
44
|
+
positionArr[positionIndex + 2] -= positionOffset.z;
|
|
45
|
+
|
|
46
|
+
orbitalEuler.set(
|
|
47
|
+
speed.x * ROTATION_CONVERTER * delta,
|
|
48
|
+
speed.z * ROTATION_CONVERTER * delta,
|
|
49
|
+
speed.y * ROTATION_CONVERTER * delta
|
|
50
|
+
);
|
|
51
|
+
positionOffset.applyEuler(orbitalEuler);
|
|
52
|
+
|
|
53
|
+
positionArr[positionIndex] += positionOffset.x;
|
|
54
|
+
positionArr[positionIndex + 1] += positionOffset.y;
|
|
55
|
+
positionArr[positionIndex + 2] += positionOffset.z;
|
|
56
|
+
|
|
57
|
+
attributes.position.needsUpdate = true;
|
|
58
|
+
}
|
|
59
|
+
|
|
32
60
|
curveModifiers.forEach(({ key, attributeKeys, startValueKeys }) => {
|
|
33
61
|
const curveModifier = normalizedConfig[key];
|
|
34
62
|
if (curveModifier.isActive) {
|
|
@@ -43,6 +43,7 @@ export const calculateRandomPositionAndVelocityOnSphere = (
|
|
|
43
43
|
position.y * speedMultiplierByPosition * randomizedSpeed,
|
|
44
44
|
position.z * speedMultiplierByPosition * randomizedSpeed
|
|
45
45
|
);
|
|
46
|
+
velocity.applyQuaternion(quaternion);
|
|
46
47
|
};
|
|
47
48
|
|
|
48
49
|
export const calculateRandomPositionAndVelocityOnCone = (
|
|
@@ -91,6 +92,7 @@ export const calculateRandomPositionAndVelocityOnCone = (
|
|
|
91
92
|
randomizedSpeed,
|
|
92
93
|
Math.cos(normalizedAngle) * randomizedSpeed
|
|
93
94
|
);
|
|
95
|
+
velocity.applyQuaternion(quaternion);
|
|
94
96
|
};
|
|
95
97
|
|
|
96
98
|
export const calculateRandomPositionAndVelocityOnBox = (
|
|
@@ -142,6 +144,7 @@ export const calculateRandomPositionAndVelocityOnBox = (
|
|
|
142
144
|
startSpeed.max
|
|
143
145
|
);
|
|
144
146
|
velocity.set(0, 0, randomizedSpeed);
|
|
147
|
+
velocity.applyQuaternion(quaternion);
|
|
145
148
|
};
|
|
146
149
|
|
|
147
150
|
export const calculateRandomPositionAndVelocityOnCircle = (
|
|
@@ -180,6 +183,7 @@ export const calculateRandomPositionAndVelocityOnCircle = (
|
|
|
180
183
|
position.y * speedMultiplierByPosition * randomizedSpeed,
|
|
181
184
|
0
|
|
182
185
|
);
|
|
186
|
+
velocity.applyQuaternion(quaternion);
|
|
183
187
|
};
|
|
184
188
|
|
|
185
189
|
export const calculateRandomPositionAndVelocityOnRectangle = (
|
|
@@ -204,4 +208,5 @@ export const calculateRandomPositionAndVelocityOnRectangle = (
|
|
|
204
208
|
startSpeed.max
|
|
205
209
|
);
|
|
206
210
|
velocity.set(0, 0, randomizedSpeed);
|
|
211
|
+
velocity.applyQuaternion(quaternion);
|
|
207
212
|
};
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
|
|
11
11
|
import { CurveFunction } from "./three-particles/three-particles-curves.js";
|
|
12
12
|
import { FBM } from "three-noise/build/three-noise.module.js";
|
|
13
|
-
import { Gyroscope } from "three/examples/jsm/misc/Gyroscope";
|
|
13
|
+
import { Gyroscope } from "three/examples/jsm/misc/Gyroscope.js";
|
|
14
14
|
import ParticleSystemFragmentShader from "./three-particles/shaders/particle-system-fragment-shader.glsl.js";
|
|
15
15
|
import ParticleSystemVertexShader from "./three-particles/shaders/particle-system-vertex-shader.glsl.js";
|
|
16
16
|
import { applyModifiers } from "./three-particles/three-particles-modifiers.js";
|
|
@@ -253,18 +253,33 @@ const calculatePositionAndVelocity = (
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
if (velocityOverLifetime.isActive) {
|
|
256
|
-
|
|
257
|
-
velocityOverLifetime.linear.x.min
|
|
258
|
-
velocityOverLifetime.linear.x.max
|
|
259
|
-
)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
velocityOverLifetime.linear.
|
|
267
|
-
|
|
256
|
+
if (
|
|
257
|
+
velocityOverLifetime.linear.x.min !== 0 ||
|
|
258
|
+
velocityOverLifetime.linear.x.max !== 0
|
|
259
|
+
) {
|
|
260
|
+
velocity.x += THREE.MathUtils.randFloat(
|
|
261
|
+
velocityOverLifetime.linear.x.min,
|
|
262
|
+
velocityOverLifetime.linear.x.max
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
if (
|
|
266
|
+
velocityOverLifetime.linear.y.min !== 0 ||
|
|
267
|
+
velocityOverLifetime.linear.y.max !== 0
|
|
268
|
+
) {
|
|
269
|
+
velocity.y += THREE.MathUtils.randFloat(
|
|
270
|
+
velocityOverLifetime.linear.y.min,
|
|
271
|
+
velocityOverLifetime.linear.y.max
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
if (
|
|
275
|
+
velocityOverLifetime.linear.z.min !== 0 ||
|
|
276
|
+
velocityOverLifetime.linear.z.max !== 0
|
|
277
|
+
) {
|
|
278
|
+
velocity.z += THREE.MathUtils.randFloat(
|
|
279
|
+
velocityOverLifetime.linear.z.min,
|
|
280
|
+
velocityOverLifetime.linear.z.max
|
|
281
|
+
);
|
|
282
|
+
}
|
|
268
283
|
}
|
|
269
284
|
};
|
|
270
285
|
|
|
@@ -283,6 +298,8 @@ export const createParticleSystem = (
|
|
|
283
298
|
worldEuler: new THREE.Euler(),
|
|
284
299
|
gravityVelocity: new THREE.Vector3(0, 0, 0),
|
|
285
300
|
startValues: {},
|
|
301
|
+
hasOrbitalVelocity: false,
|
|
302
|
+
orbitalVelocityData: [],
|
|
286
303
|
lifetimeValues: {},
|
|
287
304
|
creationTimes: [],
|
|
288
305
|
noise: null,
|
|
@@ -343,6 +360,24 @@ export const createParticleSystem = (
|
|
|
343
360
|
);
|
|
344
361
|
|
|
345
362
|
generalData.creationTimes = Array.from({ length: maxParticles }, () => 0);
|
|
363
|
+
generalData.hasOrbitalVelocity =
|
|
364
|
+
normalizedConfig.velocityOverLifetime.isActive &&
|
|
365
|
+
(normalizedConfig.velocityOverLifetime.orbital.x.min !== 0 ||
|
|
366
|
+
normalizedConfig.velocityOverLifetime.orbital.x.max !== 0 ||
|
|
367
|
+
normalizedConfig.velocityOverLifetime.orbital.y.min !== 0 ||
|
|
368
|
+
normalizedConfig.velocityOverLifetime.orbital.y.max !== 0 ||
|
|
369
|
+
normalizedConfig.velocityOverLifetime.orbital.z.min !== 0 ||
|
|
370
|
+
normalizedConfig.velocityOverLifetime.orbital.z.max !== 0);
|
|
371
|
+
|
|
372
|
+
if (generalData.hasOrbitalVelocity) {
|
|
373
|
+
generalData.orbitalVelocityData = Array.from(
|
|
374
|
+
{ length: maxParticles },
|
|
375
|
+
() => ({
|
|
376
|
+
speed: new THREE.Vector3(),
|
|
377
|
+
positionOffset: new THREE.Vector3(),
|
|
378
|
+
})
|
|
379
|
+
);
|
|
380
|
+
}
|
|
346
381
|
|
|
347
382
|
const startValueKeys = ["startSize", "startOpacity"];
|
|
348
383
|
startValueKeys.forEach((key) => {
|
|
@@ -572,6 +607,31 @@ export const createParticleSystem = (
|
|
|
572
607
|
(position ? position.z : 0) + startPositions[particleIndex].z;
|
|
573
608
|
geometry.attributes.position.needsUpdate = true;
|
|
574
609
|
|
|
610
|
+
if (generalData.hasOrbitalVelocity) {
|
|
611
|
+
generalData.orbitalVelocityData[particleIndex].speed.set(
|
|
612
|
+
THREE.MathUtils.randFloat(
|
|
613
|
+
normalizedConfig.velocityOverLifetime.orbital.x.min,
|
|
614
|
+
normalizedConfig.velocityOverLifetime.orbital.x.max
|
|
615
|
+
) *
|
|
616
|
+
(Math.PI / 180),
|
|
617
|
+
THREE.MathUtils.randFloat(
|
|
618
|
+
normalizedConfig.velocityOverLifetime.orbital.y.min,
|
|
619
|
+
normalizedConfig.velocityOverLifetime.orbital.y.max
|
|
620
|
+
) *
|
|
621
|
+
(Math.PI / 180),
|
|
622
|
+
THREE.MathUtils.randFloat(
|
|
623
|
+
normalizedConfig.velocityOverLifetime.orbital.z.min,
|
|
624
|
+
normalizedConfig.velocityOverLifetime.orbital.z.max
|
|
625
|
+
) *
|
|
626
|
+
(Math.PI / 180)
|
|
627
|
+
);
|
|
628
|
+
generalData.orbitalVelocityData[particleIndex].positionOffset.set(
|
|
629
|
+
startPositions[particleIndex].x,
|
|
630
|
+
startPositions[particleIndex].y,
|
|
631
|
+
startPositions[particleIndex].z
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
|
|
575
635
|
geometry.attributes.lifetime.array[particleIndex] = 0;
|
|
576
636
|
geometry.attributes.lifetime.needsUpdate = true;
|
|
577
637
|
|
|
@@ -581,8 +641,11 @@ export const createParticleSystem = (
|
|
|
581
641
|
noise: generalData.noise,
|
|
582
642
|
startValues: generalData.startValues,
|
|
583
643
|
lifetimeValues: generalData.lifetimeValues,
|
|
644
|
+
hasOrbitalVelocity: generalData.hasOrbitalVelocity,
|
|
645
|
+
orbitalVelocityData: generalData.orbitalVelocityData,
|
|
584
646
|
normalizedConfig,
|
|
585
647
|
attributes: particleSystem.geometry.attributes,
|
|
648
|
+
particleLifetime: 0,
|
|
586
649
|
particleLifetimePercentage: 0,
|
|
587
650
|
particleIndex,
|
|
588
651
|
forceUpdate: true,
|
|
@@ -678,6 +741,7 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
|
678
741
|
worldQuaternion,
|
|
679
742
|
worldEuler,
|
|
680
743
|
gravityVelocity,
|
|
744
|
+
hasOrbitalVelocity,
|
|
681
745
|
} = generalData;
|
|
682
746
|
|
|
683
747
|
if (wrapper) generalData.wrapperQuaternion.copy(wrapper.parent.quaternion);
|
|
@@ -694,7 +758,6 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
|
694
758
|
currentWorldPosition.y - lastWorldPosition.y,
|
|
695
759
|
currentWorldPosition.z - lastWorldPosition.z
|
|
696
760
|
);
|
|
697
|
-
worldPositionChange.applyQuaternion(worldQuaternion.invert());
|
|
698
761
|
}
|
|
699
762
|
generalData.distanceFromLastEmitByDistance += worldPositionChange.length();
|
|
700
763
|
particleSystem.getWorldPosition(lastWorldPosition);
|
|
@@ -725,9 +788,9 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
|
725
788
|
deactivateParticle(index);
|
|
726
789
|
else {
|
|
727
790
|
const velocity = velocities[index];
|
|
728
|
-
velocity.x -= gravityVelocity.x;
|
|
729
|
-
velocity.y -= gravityVelocity.y;
|
|
730
|
-
velocity.z -= gravityVelocity.z;
|
|
791
|
+
velocity.x -= gravityVelocity.x * delta;
|
|
792
|
+
velocity.y -= gravityVelocity.y * delta;
|
|
793
|
+
velocity.z -= gravityVelocity.z * delta;
|
|
731
794
|
|
|
732
795
|
if (
|
|
733
796
|
gravity !== 0 ||
|
|
@@ -747,6 +810,7 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
|
747
810
|
positionArr[positionIndex + 1] -= worldPositionChange.y;
|
|
748
811
|
positionArr[positionIndex + 2] -= worldPositionChange.z;
|
|
749
812
|
}
|
|
813
|
+
|
|
750
814
|
positionArr[positionIndex] += velocity.x * delta;
|
|
751
815
|
positionArr[positionIndex + 1] += velocity.y * delta;
|
|
752
816
|
positionArr[positionIndex + 2] += velocity.z * delta;
|
|
@@ -766,8 +830,11 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
|
766
830
|
noise: generalData.noise,
|
|
767
831
|
startValues: generalData.startValues,
|
|
768
832
|
lifetimeValues: generalData.lifetimeValues,
|
|
833
|
+
hasOrbitalVelocity: generalData.hasOrbitalVelocity,
|
|
834
|
+
orbitalVelocityData: generalData.orbitalVelocityData,
|
|
769
835
|
normalizedConfig,
|
|
770
836
|
attributes: particleSystem.geometry.attributes,
|
|
837
|
+
particleLifetime,
|
|
771
838
|
particleLifetimePercentage,
|
|
772
839
|
particleIndex: index,
|
|
773
840
|
});
|