@newkrok/three-particles 0.5.0 → 0.6.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/README.md CHANGED
@@ -18,4 +18,4 @@ Install with npm
18
18
  `npm i @newkrok/three-particles`
19
19
 
20
20
  Add as a package.json dependency
21
- `"dependencies": { ... "@newkrok/three-particles": "0.5.0" ... }, `
21
+ `"dependencies": { ... "@newkrok/three-particles": "0.6.0" ... }, `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newkrok/three-particles",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Particle system for ThreeJS",
5
5
  "main": "src/js/three-particles.js",
6
6
  "bin": {
@@ -12,7 +12,10 @@
12
12
  },
13
13
  "keywords": [
14
14
  "threejs",
15
+ "particle",
15
16
  "particles",
17
+ "particle engine",
18
+ "effects",
16
19
  "3d",
17
20
  "lib"
18
21
  ],
@@ -24,7 +27,7 @@
24
27
  "homepage": "https://github.com/NewKrok/three-particles#readme",
25
28
  "dependencies": {
26
29
  "easing-functions": "1.0.1",
27
- "three": "0.136.0",
30
+ "three": "0.137.0",
28
31
  "three-noise": "^1.1.1"
29
32
  },
30
33
  "scripts": {
@@ -1,4 +1,4 @@
1
- import * as THREE from "three/build/three.module.js";
1
+ import * as THREE from "three";
2
2
 
3
3
  import { getCurveFunction } from "./three-particles-curves.js";
4
4
 
@@ -1,4 +1,6 @@
1
- import * as THREE from "three/build/three.module.js";
1
+ import * as THREE from "three";
2
+
3
+ import { EmitFrom } from "../three-particles.js";
2
4
 
3
5
  export const patchObject = (
4
6
  objectA,
@@ -114,6 +116,54 @@ export const calculateRandomPositionAndVelocityOnCone = (
114
116
  );
115
117
  };
116
118
 
119
+ export const calculateRandomPositionAndVelocityOnBox = (
120
+ position,
121
+ velocity,
122
+ startSpeed,
123
+ { scale, emitFrom }
124
+ ) => {
125
+ switch (emitFrom) {
126
+ case EmitFrom.VOLUME:
127
+ position.x = Math.random() * scale.x - scale.x / 2;
128
+ position.y = Math.random() * scale.y - scale.y / 2;
129
+ position.z = Math.random() * scale.z - scale.z / 2;
130
+ break;
131
+
132
+ case EmitFrom.SHELL:
133
+ const side = Math.floor(Math.random() * 6);
134
+ const perpendicularAxis = side % 3;
135
+ const shellResult = [];
136
+ shellResult[perpendicularAxis] = side > 2 ? 1 : 0;
137
+ shellResult[(perpendicularAxis + 1) % 3] = Math.random();
138
+ shellResult[(perpendicularAxis + 2) % 3] = Math.random();
139
+ position.x = shellResult[0] * scale.x - scale.x / 2;
140
+ position.y = shellResult[1] * scale.y - scale.y / 2;
141
+ position.z = shellResult[2] * scale.z - scale.z / 2;
142
+ break;
143
+
144
+ case EmitFrom.EDGE:
145
+ const side2 = Math.floor(Math.random() * 6);
146
+ const perpendicularAxis2 = side2 % 3;
147
+ const edge = Math.floor(Math.random() * 4);
148
+ const edgeResult = [];
149
+ edgeResult[perpendicularAxis2] = side2 > 2 ? 1 : 0;
150
+ edgeResult[(perpendicularAxis2 + 1) % 3] =
151
+ edge < 2 ? Math.random() : edge - 2;
152
+ edgeResult[(perpendicularAxis2 + 2) % 3] =
153
+ edge < 2 ? edge : Math.random();
154
+ position.x = edgeResult[0] * scale.x - scale.x / 2;
155
+ position.y = edgeResult[1] * scale.y - scale.y / 2;
156
+ position.z = edgeResult[2] * scale.z - scale.z / 2;
157
+ break;
158
+ }
159
+
160
+ const randomizedSpeed = THREE.MathUtils.randFloat(
161
+ startSpeed.min,
162
+ startSpeed.max
163
+ );
164
+ velocity.set(0, 0, randomizedSpeed);
165
+ };
166
+
117
167
  export const calculateRandomPositionAndVelocityOnCircle = (
118
168
  position,
119
169
  velocity,
@@ -1,6 +1,7 @@
1
- import * as THREE from "three/build/three.module.js";
1
+ import * as THREE from "three";
2
2
 
3
3
  import {
4
+ calculateRandomPositionAndVelocityOnBox,
4
5
  calculateRandomPositionAndVelocityOnCircle,
5
6
  calculateRandomPositionAndVelocityOnCone,
6
7
  calculateRandomPositionAndVelocityOnRectangle,
@@ -13,7 +14,7 @@ import { FBM } from "three-noise/build/three-noise.module.js";
13
14
  import ParticleSystemFragmentShader from "./three-particles/shaders/particle-system-fragment-shader.glsl.js";
14
15
  import ParticleSystemVertexShader from "./three-particles/shaders/particle-system-vertex-shader.glsl.js";
15
16
  import { applyModifiers } from "./three-particles/three-particles-modifiers.js";
16
- import { createBezierCurveFunction } from "@newkrok/three-particles/src/js/effects/three-particles/three-particles-bezier";
17
+ import { createBezierCurveFunction } from "./three-particles/three-particles-bezier";
17
18
 
18
19
  let createdParticleSystems = [];
19
20
 
@@ -30,6 +31,12 @@ export const Shape = {
30
31
  RECTANGLE: "RECTANGLE",
31
32
  };
32
33
 
34
+ export const EmitFrom = {
35
+ VOLUME: "VOLUME",
36
+ SHELL: "SHELL",
37
+ EDGE: "EDGE",
38
+ };
39
+
33
40
  export const TimeMode = {
34
41
  LIFETIME: "LIFETIME",
35
42
  FPS: "FPS",
@@ -93,6 +100,10 @@ const DEFAULT_PARTICLE_SYSTEM_CONFIG = {
93
100
  rotation: { x: 0.0, y: 0.0 }, // TODO: add z rotation
94
101
  scale: { x: 1.0, y: 1.0 },
95
102
  },
103
+ box: {
104
+ scale: { x: 1.0, y: 1.0, z: 1.0 },
105
+ emitFrom: EmitFrom.VOLUME,
106
+ },
96
107
  },
97
108
  map: null,
98
109
  renderer: {
@@ -178,7 +189,7 @@ const createFloat32Attributes = ({
178
189
  };
179
190
 
180
191
  const calculatePositionAndVelocity = (
181
- { shape, sphere, cone, circle, rectangle },
192
+ { shape, sphere, cone, circle, rectangle, box },
182
193
  startSpeed,
183
194
  position,
184
195
  velocity,
@@ -220,6 +231,15 @@ const calculatePositionAndVelocity = (
220
231
  rectangle
221
232
  );
222
233
  break;
234
+
235
+ case Shape.BOX:
236
+ calculateRandomPositionAndVelocityOnBox(
237
+ position,
238
+ velocity,
239
+ startSpeed,
240
+ box
241
+ );
242
+ break;
223
243
  }
224
244
 
225
245
  if (velocityOverLifetime.isActive) {
@@ -528,6 +548,7 @@ export const createParticleSystem = (
528
548
  startPositions[particleIndex].y;
529
549
  geometry.attributes.position.array[positionIndex + 2] =
530
550
  startPositions[particleIndex].z;
551
+ geometry.attributes.position.needsUpdate = true;
531
552
 
532
553
  geometry.attributes.lifetime.array[particleIndex] = 0;
533
554
  geometry.attributes.lifetime.needsUpdate = true;