@newkrok/three-particles 0.8.4 → 1.0.1
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,37 +1,37 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@newkrok/three-particles",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Particle system for ThreeJS",
|
|
5
|
-
"main": "src/js/three-particles.js",
|
|
6
|
-
"bin": {
|
|
7
|
-
"three-particles": "src/js/three-particles.js"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/NewKrok/three-particles.git"
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"threejs",
|
|
15
|
-
"particle",
|
|
16
|
-
"particles",
|
|
17
|
-
"particle engine",
|
|
18
|
-
"effects",
|
|
19
|
-
"3d",
|
|
20
|
-
"lib"
|
|
21
|
-
],
|
|
22
|
-
"author": "Istvan Krisztian Somoracz",
|
|
23
|
-
"license": "MIT",
|
|
24
|
-
"bugs": {
|
|
25
|
-
"url": "https://github.com/NewKrok/three-particles/issues"
|
|
26
|
-
},
|
|
27
|
-
"homepage": "https://github.com/NewKrok/three-particles#readme",
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"easing-functions": "1.0.1",
|
|
30
|
-
"three": "^0.
|
|
31
|
-
"three-noise": "1.1.2",
|
|
32
|
-
"@newkrok/three-utils": "^0.
|
|
33
|
-
},
|
|
34
|
-
"scripts": {
|
|
35
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
36
|
-
}
|
|
37
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@newkrok/three-particles",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Particle system for ThreeJS",
|
|
5
|
+
"main": "src/js/effects/three-particles.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"three-particles": "src/js/effects/three-particles.js"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/NewKrok/three-particles.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"threejs",
|
|
15
|
+
"particle",
|
|
16
|
+
"particles",
|
|
17
|
+
"particle engine",
|
|
18
|
+
"effects",
|
|
19
|
+
"3d",
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
22
|
+
"author": "Istvan Krisztian Somoracz",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/NewKrok/three-particles/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/NewKrok/three-particles#readme",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"easing-functions": "1.0.1",
|
|
30
|
+
"three": "^0.144.0",
|
|
31
|
+
"three-noise": "1.1.2",
|
|
32
|
+
"@newkrok/three-utils": "^1.0.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const SimulationSpace = {
|
|
2
|
+
LOCAL: "LOCAL",
|
|
3
|
+
WORLD: "WORLD",
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export const Shape = {
|
|
7
|
+
SPHERE: "SPHERE",
|
|
8
|
+
CONE: "CONE",
|
|
9
|
+
BOX: "BOX",
|
|
10
|
+
CIRCLE: "CIRCLE",
|
|
11
|
+
RECTANGLE: "RECTANGLE",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const EmitFrom = {
|
|
15
|
+
VOLUME: "VOLUME",
|
|
16
|
+
SHELL: "SHELL",
|
|
17
|
+
EDGE: "EDGE",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const TimeMode = {
|
|
21
|
+
LIFETIME: "LIFETIME",
|
|
22
|
+
FPS: "FPS",
|
|
23
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export type Point3D = {
|
|
2
|
+
x?: number;
|
|
3
|
+
y?: number;
|
|
4
|
+
z?: number;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type Transform = {
|
|
8
|
+
position?: Point3D;
|
|
9
|
+
rotation?: Point3D;
|
|
10
|
+
scale?: Point3D;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type MinMaxNumber = {
|
|
14
|
+
min: number;
|
|
15
|
+
max: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type Rgb = {
|
|
19
|
+
r: number;
|
|
20
|
+
g: number;
|
|
21
|
+
b: number;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type MinMaxColor = {
|
|
25
|
+
min: Rgb;
|
|
26
|
+
max: Rgb;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type Emission = {
|
|
30
|
+
rateOverTime: number;
|
|
31
|
+
rateOverDistance: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type ParticleSystemConfig = {
|
|
35
|
+
transform: Transform;
|
|
36
|
+
duration: number;
|
|
37
|
+
looping: boolean;
|
|
38
|
+
startDelay: MinMaxNumber;
|
|
39
|
+
startLifetime: MinMaxNumber;
|
|
40
|
+
startSpeed: MinMaxNumber;
|
|
41
|
+
startSize: MinMaxNumber;
|
|
42
|
+
startRotation: MinMaxNumber;
|
|
43
|
+
startColor: MinMaxColor;
|
|
44
|
+
startOpacity: MinMaxNumber;
|
|
45
|
+
gravity: number;
|
|
46
|
+
simulationSpace: "LOCAL" | "WORLD";
|
|
47
|
+
maxParticles: number;
|
|
48
|
+
emission: Emission;
|
|
49
|
+
shape: any;
|
|
50
|
+
map: any;
|
|
51
|
+
renderer: any;
|
|
52
|
+
velocityOverLifetime: any;
|
|
53
|
+
sizeOverLifetime: any;
|
|
54
|
+
opacityOverLifetime: any;
|
|
55
|
+
rotationOverLifetime: any;
|
|
56
|
+
noise: any;
|
|
57
|
+
textureSheetAnimation: any;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type ParticleSystem = {
|
|
61
|
+
instance: THREE.Object3D;
|
|
62
|
+
resumeEmitter: () => void;
|
|
63
|
+
pauseEmitter: () => void;
|
|
64
|
+
dispose: () => void;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export function createParticleSystem(
|
|
68
|
+
config: ParticleSystemConfig,
|
|
69
|
+
externalNow?: number
|
|
70
|
+
): ParticleSystem;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
EmitFrom,
|
|
5
|
+
Shape,
|
|
6
|
+
SimulationSpace,
|
|
7
|
+
TimeMode,
|
|
8
|
+
} from "./three-particles/three-particles-enums.js";
|
|
3
9
|
import {
|
|
4
10
|
calculateRandomPositionAndVelocityOnBox,
|
|
5
11
|
calculateRandomPositionAndVelocityOnCircle,
|
|
@@ -11,38 +17,14 @@ import {
|
|
|
11
17
|
import { CurveFunction } from "./three-particles/three-particles-curves.js";
|
|
12
18
|
import { FBM } from "three-noise/build/three-noise.module.js";
|
|
13
19
|
import { Gyroscope } from "three/examples/jsm/misc/Gyroscope.js";
|
|
20
|
+
import { ObjectUtils } from "@newkrok/three-utils";
|
|
14
21
|
import ParticleSystemFragmentShader from "./three-particles/shaders/particle-system-fragment-shader.glsl.js";
|
|
15
22
|
import ParticleSystemVertexShader from "./three-particles/shaders/particle-system-vertex-shader.glsl.js";
|
|
16
23
|
import { applyModifiers } from "./three-particles/three-particles-modifiers.js";
|
|
17
24
|
import { createBezierCurveFunction } from "./three-particles/three-particles-bezier";
|
|
18
|
-
import { patchObject } from "@newkrok/three-utils/src/js/newkrok/three-utils/object-utils.js";
|
|
19
25
|
|
|
20
26
|
let createdParticleSystems = [];
|
|
21
27
|
|
|
22
|
-
export const SimulationSpace = {
|
|
23
|
-
LOCAL: "LOCAL",
|
|
24
|
-
WORLD: "WORLD",
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const Shape = {
|
|
28
|
-
SPHERE: "SPHERE",
|
|
29
|
-
CONE: "CONE",
|
|
30
|
-
BOX: "BOX",
|
|
31
|
-
CIRCLE: "CIRCLE",
|
|
32
|
-
RECTANGLE: "RECTANGLE",
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const EmitFrom = {
|
|
36
|
-
VOLUME: "VOLUME",
|
|
37
|
-
SHELL: "SHELL",
|
|
38
|
-
EDGE: "EDGE",
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const TimeMode = {
|
|
42
|
-
LIFETIME: "LIFETIME",
|
|
43
|
-
FPS: "FPS",
|
|
44
|
-
};
|
|
45
|
-
|
|
46
28
|
export const blendingMap = {
|
|
47
29
|
"THREE.NoBlending": THREE.NoBlending,
|
|
48
30
|
"THREE.NormalBlending": THREE.NormalBlending,
|
|
@@ -283,6 +265,29 @@ const calculatePositionAndVelocity = (
|
|
|
283
265
|
}
|
|
284
266
|
};
|
|
285
267
|
|
|
268
|
+
/**
|
|
269
|
+
* @deprecated Since version 1.0.1. Will be deleted in version 1.1.0. Use particleSystem.dispose instead.
|
|
270
|
+
*/
|
|
271
|
+
export const destroyParticleSystem = (particleSystem) => {
|
|
272
|
+
createdParticleSystems = createdParticleSystems.filter(
|
|
273
|
+
({ particleSystem: savedParticleSystem, wrapper }) => {
|
|
274
|
+
if (
|
|
275
|
+
savedParticleSystem !== particleSystem &&
|
|
276
|
+
wrapper !== particleSystem &&
|
|
277
|
+
particleSystem.instance !== particleSystem
|
|
278
|
+
) {
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
savedParticleSystem.geometry.dispose();
|
|
283
|
+
savedParticleSystem.material.dispose();
|
|
284
|
+
if (savedParticleSystem.parent)
|
|
285
|
+
savedParticleSystem.parent.remove(savedParticleSystem);
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
};
|
|
290
|
+
|
|
286
291
|
export const createParticleSystem = (
|
|
287
292
|
config = DEFAULT_PARTICLE_SYSTEM_CONFIG,
|
|
288
293
|
externalNow
|
|
@@ -304,9 +309,13 @@ export const createParticleSystem = (
|
|
|
304
309
|
lifetimeValues: {},
|
|
305
310
|
creationTimes: [],
|
|
306
311
|
noise: null,
|
|
312
|
+
isEnabled: true,
|
|
307
313
|
};
|
|
308
314
|
|
|
309
|
-
const normalizedConfig = patchObject(
|
|
315
|
+
const normalizedConfig = ObjectUtils.patchObject(
|
|
316
|
+
DEFAULT_PARTICLE_SYSTEM_CONFIG,
|
|
317
|
+
config
|
|
318
|
+
);
|
|
310
319
|
|
|
311
320
|
const bezierCompatibleProperties = [
|
|
312
321
|
"sizeOverLifetime",
|
|
@@ -577,9 +586,10 @@ export const createParticleSystem = (
|
|
|
577
586
|
generalData.startValues.startOpacity[particleIndex] =
|
|
578
587
|
THREE.MathUtils.randFloat(startOpacity.min, startOpacity.max);
|
|
579
588
|
|
|
580
|
-
geometry.attributes.rotation.array[particleIndex] =
|
|
581
|
-
THREE.MathUtils.
|
|
582
|
-
|
|
589
|
+
geometry.attributes.rotation.array[particleIndex] =
|
|
590
|
+
THREE.MathUtils.degToRad(
|
|
591
|
+
THREE.MathUtils.randFloat(startRotation.min, startRotation.max)
|
|
592
|
+
);
|
|
583
593
|
|
|
584
594
|
if (normalizedConfig.rotationOverLifetime.isActive)
|
|
585
595
|
generalData.lifetimeValues.rotationOverLifetime[particleIndex] =
|
|
@@ -691,25 +701,16 @@ export const createParticleSystem = (
|
|
|
691
701
|
activateParticle,
|
|
692
702
|
});
|
|
693
703
|
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
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
|
-
}
|
|
704
|
+
const resumeEmitter = () => (generalData.isEnabled = true);
|
|
705
|
+
const pauseEmitter = () => (generalData.isEnabled = false);
|
|
706
|
+
const dispose = () => destroyParticleSystem(particleSystem);
|
|
706
707
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
708
|
+
return {
|
|
709
|
+
instance: wrapper || particleSystem,
|
|
710
|
+
resumeEmitter,
|
|
711
|
+
pauseEmitter,
|
|
712
|
+
dispose,
|
|
713
|
+
};
|
|
713
714
|
};
|
|
714
715
|
|
|
715
716
|
export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
@@ -742,6 +743,7 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
|
742
743
|
worldQuaternion,
|
|
743
744
|
worldEuler,
|
|
744
745
|
gravityVelocity,
|
|
746
|
+
isEnabled,
|
|
745
747
|
} = generalData;
|
|
746
748
|
|
|
747
749
|
if (wrapper) generalData.wrapperQuaternion.copy(wrapper.parent.quaternion);
|
|
@@ -842,7 +844,7 @@ export const updateParticleSystems = ({ now, delta, elapsed }) => {
|
|
|
842
844
|
}
|
|
843
845
|
});
|
|
844
846
|
|
|
845
|
-
if (looping || lifetime < duration * 1000) {
|
|
847
|
+
if (isEnabled && (looping || lifetime < duration * 1000)) {
|
|
846
848
|
const emissionDelta = now - lastEmissionTime;
|
|
847
849
|
const neededParticlesByTime = Math.floor(
|
|
848
850
|
emission.rateOverTime * (emissionDelta / 1000)
|