@newkrok/three-particles 1.0.2 → 2.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.
Files changed (44) hide show
  1. package/README.md +28 -12
  2. package/dist/bundle-report.json +1 -0
  3. package/dist/index.d.ts +7 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +6 -0
  6. package/dist/js/effects/three-particles/index.d.ts +7 -0
  7. package/dist/js/effects/three-particles/index.d.ts.map +1 -0
  8. package/dist/js/effects/three-particles/index.js +6 -0
  9. package/dist/js/effects/three-particles/shaders/particle-system-fragment-shader.glsl.d.ts +3 -0
  10. package/dist/js/effects/three-particles/shaders/particle-system-fragment-shader.glsl.d.ts.map +1 -0
  11. package/{src → dist}/js/effects/three-particles/shaders/particle-system-fragment-shader.glsl.js +66 -67
  12. package/dist/js/effects/three-particles/shaders/particle-system-vertex-shader.glsl.d.ts +3 -0
  13. package/dist/js/effects/three-particles/shaders/particle-system-vertex-shader.glsl.d.ts.map +1 -0
  14. package/{src → dist}/js/effects/three-particles/shaders/particle-system-vertex-shader.glsl.js +32 -33
  15. package/dist/js/effects/three-particles/three-particles-bezier.d.ts +5 -0
  16. package/dist/js/effects/three-particles/three-particles-bezier.d.ts.map +1 -0
  17. package/dist/js/effects/three-particles/three-particles-bezier.js +62 -0
  18. package/dist/js/effects/three-particles/three-particles-curves.d.ts +37 -0
  19. package/dist/js/effects/three-particles/three-particles-curves.d.ts.map +1 -0
  20. package/dist/js/effects/three-particles/three-particles-curves.js +37 -0
  21. package/dist/js/effects/three-particles/three-particles-enums.d.ts +25 -0
  22. package/dist/js/effects/three-particles/three-particles-enums.d.ts.map +1 -0
  23. package/dist/js/effects/three-particles/three-particles-enums.js +1 -0
  24. package/dist/js/effects/three-particles/three-particles-modifiers.d.ts +11 -0
  25. package/dist/js/effects/three-particles/three-particles-modifiers.d.ts.map +1 -0
  26. package/dist/js/effects/three-particles/three-particles-modifiers.js +93 -0
  27. package/dist/js/effects/three-particles/three-particles-utils.d.ts +31 -0
  28. package/dist/js/effects/three-particles/three-particles-utils.d.ts.map +1 -0
  29. package/dist/js/effects/three-particles/three-particles-utils.js +145 -0
  30. package/dist/js/effects/three-particles/three-particles.d.ts +13 -0
  31. package/dist/js/effects/three-particles/three-particles.d.ts.map +1 -0
  32. package/dist/js/effects/three-particles/three-particles.js +642 -0
  33. package/dist/js/effects/three-particles/types.d.ts +1037 -0
  34. package/dist/js/effects/three-particles/types.d.ts.map +1 -0
  35. package/dist/js/effects/three-particles/types.js +1 -0
  36. package/dist/three-particles.min.js +1 -0
  37. package/package.json +87 -37
  38. package/src/js/effects/three-particles/three-particles-bezier.js +0 -36
  39. package/src/js/effects/three-particles/three-particles-curves.js +0 -75
  40. package/src/js/effects/three-particles/three-particles-enums.js +0 -23
  41. package/src/js/effects/three-particles/three-particles-modifiers.js +0 -133
  42. package/src/js/effects/three-particles/three-particles-utils.js +0 -212
  43. package/src/js/effects/three-particles.d.ts +0 -79
  44. package/src/js/effects/three-particles.js +0 -931
@@ -1,212 +0,0 @@
1
- import * as THREE from "three";
2
-
3
- import { EmitFrom } from "./three-particles-enums.js";
4
-
5
- export const calculateRandomPositionAndVelocityOnSphere = (
6
- position,
7
- quaternion,
8
- velocity,
9
- startSpeed,
10
- { radius, radiusThickness, arc }
11
- ) => {
12
- const u = Math.random() * (arc / 360);
13
- const v = Math.random();
14
- const randomizedDistanceRatio = Math.random();
15
- const theta = 2 * Math.PI * u;
16
- const phi = Math.acos(2 * v - 1);
17
- const sinPhi = Math.sin(phi);
18
-
19
- const xDirection = sinPhi * Math.cos(theta);
20
- const yDirection = sinPhi * Math.sin(theta);
21
- const zDirection = Math.cos(phi);
22
- const normalizedThickness = 1 - radiusThickness;
23
-
24
- position.x =
25
- radius * normalizedThickness * xDirection +
26
- radius * radiusThickness * randomizedDistanceRatio * xDirection;
27
- position.y =
28
- radius * normalizedThickness * yDirection +
29
- radius * radiusThickness * randomizedDistanceRatio * yDirection;
30
- position.z =
31
- radius * normalizedThickness * zDirection +
32
- radius * radiusThickness * randomizedDistanceRatio * zDirection;
33
-
34
- position.applyQuaternion(quaternion);
35
-
36
- const randomizedSpeed = THREE.MathUtils.randFloat(
37
- startSpeed.min,
38
- startSpeed.max
39
- );
40
- const speedMultiplierByPosition = 1 / position.length();
41
- velocity.set(
42
- position.x * speedMultiplierByPosition * randomizedSpeed,
43
- position.y * speedMultiplierByPosition * randomizedSpeed,
44
- position.z * speedMultiplierByPosition * randomizedSpeed
45
- );
46
- velocity.applyQuaternion(quaternion);
47
- };
48
-
49
- export const calculateRandomPositionAndVelocityOnCone = (
50
- position,
51
- quaternion,
52
- velocity,
53
- startSpeed,
54
- { radius, radiusThickness, arc, angle = 90 }
55
- ) => {
56
- const theta = 2 * Math.PI * Math.random() * (arc / 360);
57
- const randomizedDistanceRatio = Math.random();
58
-
59
- const xDirection = Math.cos(theta);
60
- const yDirection = Math.sin(theta);
61
- const normalizedThickness = 1 - radiusThickness;
62
-
63
- position.x =
64
- radius * normalizedThickness * xDirection +
65
- radius * radiusThickness * randomizedDistanceRatio * xDirection;
66
- position.y =
67
- radius * normalizedThickness * yDirection +
68
- radius * radiusThickness * randomizedDistanceRatio * yDirection;
69
- position.z = 0;
70
-
71
- position.applyQuaternion(quaternion);
72
-
73
- const positionLength = position.length();
74
- const normalizedAngle = Math.abs(
75
- (positionLength / radius) * THREE.MathUtils.degToRad(angle)
76
- );
77
- const sinNormalizedAngle = Math.sin(normalizedAngle);
78
-
79
- const randomizedSpeed = THREE.MathUtils.randFloat(
80
- startSpeed.min,
81
- startSpeed.max
82
- );
83
- const speedMultiplierByPosition = 1 / positionLength;
84
- velocity.set(
85
- position.x *
86
- sinNormalizedAngle *
87
- speedMultiplierByPosition *
88
- randomizedSpeed,
89
- position.y *
90
- sinNormalizedAngle *
91
- speedMultiplierByPosition *
92
- randomizedSpeed,
93
- Math.cos(normalizedAngle) * randomizedSpeed
94
- );
95
- velocity.applyQuaternion(quaternion);
96
- };
97
-
98
- export const calculateRandomPositionAndVelocityOnBox = (
99
- position,
100
- quaternion,
101
- velocity,
102
- startSpeed,
103
- { scale, emitFrom }
104
- ) => {
105
- switch (emitFrom) {
106
- case EmitFrom.VOLUME:
107
- position.x = Math.random() * scale.x - scale.x / 2;
108
- position.y = Math.random() * scale.y - scale.y / 2;
109
- position.z = Math.random() * scale.z - scale.z / 2;
110
- break;
111
-
112
- case EmitFrom.SHELL:
113
- const side = Math.floor(Math.random() * 6);
114
- const perpendicularAxis = side % 3;
115
- const shellResult = [];
116
- shellResult[perpendicularAxis] = side > 2 ? 1 : 0;
117
- shellResult[(perpendicularAxis + 1) % 3] = Math.random();
118
- shellResult[(perpendicularAxis + 2) % 3] = Math.random();
119
- position.x = shellResult[0] * scale.x - scale.x / 2;
120
- position.y = shellResult[1] * scale.y - scale.y / 2;
121
- position.z = shellResult[2] * scale.z - scale.z / 2;
122
- break;
123
-
124
- case EmitFrom.EDGE:
125
- const side2 = Math.floor(Math.random() * 6);
126
- const perpendicularAxis2 = side2 % 3;
127
- const edge = Math.floor(Math.random() * 4);
128
- const edgeResult = [];
129
- edgeResult[perpendicularAxis2] = side2 > 2 ? 1 : 0;
130
- edgeResult[(perpendicularAxis2 + 1) % 3] =
131
- edge < 2 ? Math.random() : edge - 2;
132
- edgeResult[(perpendicularAxis2 + 2) % 3] =
133
- edge < 2 ? edge : Math.random();
134
- position.x = edgeResult[0] * scale.x - scale.x / 2;
135
- position.y = edgeResult[1] * scale.y - scale.y / 2;
136
- position.z = edgeResult[2] * scale.z - scale.z / 2;
137
- break;
138
- }
139
-
140
- position.applyQuaternion(quaternion);
141
-
142
- const randomizedSpeed = THREE.MathUtils.randFloat(
143
- startSpeed.min,
144
- startSpeed.max
145
- );
146
- velocity.set(0, 0, randomizedSpeed);
147
- velocity.applyQuaternion(quaternion);
148
- };
149
-
150
- export const calculateRandomPositionAndVelocityOnCircle = (
151
- position,
152
- quaternion,
153
- velocity,
154
- startSpeed,
155
- { radius, radiusThickness, arc }
156
- ) => {
157
- const theta = 2 * Math.PI * Math.random() * (arc / 360);
158
- const randomizedDistanceRatio = Math.random();
159
-
160
- const xDirection = Math.cos(theta);
161
- const yDirection = Math.sin(theta);
162
- const normalizedThickness = 1 - radiusThickness;
163
-
164
- position.x =
165
- radius * normalizedThickness * xDirection +
166
- radius * radiusThickness * randomizedDistanceRatio * xDirection;
167
- position.y =
168
- radius * normalizedThickness * yDirection +
169
- radius * radiusThickness * randomizedDistanceRatio * yDirection;
170
- position.z = 0;
171
-
172
- position.applyQuaternion(quaternion);
173
-
174
- const randomizedSpeed = THREE.MathUtils.randFloat(
175
- startSpeed.min,
176
- startSpeed.max
177
- );
178
-
179
- const positionLength = position.length();
180
- const speedMultiplierByPosition = 1 / positionLength;
181
- velocity.set(
182
- position.x * speedMultiplierByPosition * randomizedSpeed,
183
- position.y * speedMultiplierByPosition * randomizedSpeed,
184
- 0
185
- );
186
- velocity.applyQuaternion(quaternion);
187
- };
188
-
189
- export const calculateRandomPositionAndVelocityOnRectangle = (
190
- position,
191
- quaternion,
192
- velocity,
193
- startSpeed,
194
- { rotation, scale }
195
- ) => {
196
- const xOffset = Math.random() * scale.x - scale.x / 2;
197
- const yOffset = Math.random() * scale.y - scale.y / 2;
198
- const rotationX = THREE.MathUtils.degToRad(rotation.x);
199
- const rotationY = THREE.MathUtils.degToRad(rotation.y);
200
- position.x = xOffset * Math.cos(rotationY);
201
- position.y = yOffset * Math.cos(rotationX);
202
- position.z = xOffset * Math.sin(rotationY) - yOffset * Math.sin(rotationX);
203
-
204
- position.applyQuaternion(quaternion);
205
-
206
- const randomizedSpeed = THREE.MathUtils.randFloat(
207
- startSpeed.min,
208
- startSpeed.max
209
- );
210
- velocity.set(0, 0, randomizedSpeed);
211
- velocity.applyQuaternion(quaternion);
212
- };
@@ -1,79 +0,0 @@
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?: THREE.Texture;
51
- renderer?: any;
52
- velocityOverLifetime?: any;
53
- sizeOverLifetime?: any;
54
- opacityOverLifetime?: any;
55
- rotationOverLifetime?: any;
56
- noise?: any;
57
- textureSheetAnimation?: any;
58
- _editorData: any;
59
- };
60
-
61
- export type ParticleSystem = {
62
- instance: THREE.Object3D;
63
- resumeEmitter: () => void;
64
- pauseEmitter: () => void;
65
- dispose: () => void;
66
- };
67
-
68
- export type CycleData = {
69
- now: number,
70
- delta: number,
71
- elapsed: number,
72
- };
73
-
74
- export function createParticleSystem(
75
- config: ParticleSystemConfig,
76
- externalNow?: number
77
- ): ParticleSystem;
78
-
79
- export function updateParticleSystems(cycleData:CycleData): void;