@newkrok/three-particles 1.0.3 → 2.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/README.md +28 -12
- package/dist/bundle-report.json +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/js/effects/three-particles/index.d.ts +7 -0
- package/dist/js/effects/three-particles/index.d.ts.map +1 -0
- package/dist/js/effects/three-particles/index.js +6 -0
- package/dist/js/effects/three-particles/shaders/particle-system-fragment-shader.glsl.d.ts +3 -0
- package/dist/js/effects/three-particles/shaders/particle-system-fragment-shader.glsl.d.ts.map +1 -0
- package/{src → dist}/js/effects/three-particles/shaders/particle-system-fragment-shader.glsl.js +66 -67
- package/dist/js/effects/three-particles/shaders/particle-system-vertex-shader.glsl.d.ts +3 -0
- package/dist/js/effects/three-particles/shaders/particle-system-vertex-shader.glsl.d.ts.map +1 -0
- package/{src → dist}/js/effects/three-particles/shaders/particle-system-vertex-shader.glsl.js +32 -33
- package/dist/js/effects/three-particles/three-particles-bezier.d.ts +5 -0
- package/dist/js/effects/three-particles/three-particles-bezier.d.ts.map +1 -0
- package/dist/js/effects/three-particles/three-particles-bezier.js +62 -0
- package/dist/js/effects/three-particles/three-particles-curves.d.ts +37 -0
- package/dist/js/effects/three-particles/three-particles-curves.d.ts.map +1 -0
- package/dist/js/effects/three-particles/three-particles-curves.js +37 -0
- package/dist/js/effects/three-particles/three-particles-enums.d.ts +25 -0
- package/dist/js/effects/three-particles/three-particles-enums.d.ts.map +1 -0
- package/dist/js/effects/three-particles/three-particles-enums.js +1 -0
- package/dist/js/effects/three-particles/three-particles-modifiers.d.ts +11 -0
- package/dist/js/effects/three-particles/three-particles-modifiers.d.ts.map +1 -0
- package/dist/js/effects/three-particles/three-particles-modifiers.js +93 -0
- package/dist/js/effects/three-particles/three-particles-utils.d.ts +36 -0
- package/dist/js/effects/three-particles/three-particles-utils.d.ts.map +1 -0
- package/dist/js/effects/three-particles/three-particles-utils.js +179 -0
- package/dist/js/effects/three-particles/three-particles.d.ts +13 -0
- package/dist/js/effects/three-particles/three-particles.d.ts.map +1 -0
- package/dist/js/effects/three-particles/three-particles.js +643 -0
- package/dist/js/effects/three-particles/types.d.ts +1037 -0
- package/dist/js/effects/three-particles/types.d.ts.map +1 -0
- package/dist/js/effects/three-particles/types.js +1 -0
- package/dist/three-particles.min.js +1 -0
- package/package.json +87 -37
- package/src/js/effects/three-particles/three-particles-bezier.js +0 -36
- package/src/js/effects/three-particles/three-particles-curves.js +0 -75
- package/src/js/effects/three-particles/three-particles-enums.js +0 -23
- package/src/js/effects/three-particles/three-particles-modifiers.js +0 -133
- package/src/js/effects/three-particles/three-particles-utils.js +0 -212
- package/src/js/effects/three-particles.d.ts +0 -138
- 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,138 +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 const enum SimulationSpace {
|
|
35
|
-
LOCAL = "LOCAL",
|
|
36
|
-
WORLD = "WORLD",
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const enum Shape {
|
|
40
|
-
SPHERE = "SPHERE",
|
|
41
|
-
CONE = "CONE",
|
|
42
|
-
BOX = "BOX",
|
|
43
|
-
CIRCLE = "CIRCLE",
|
|
44
|
-
RECTANGLE = "RECTANGLE",
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const enum EmitFrom {
|
|
48
|
-
VOLUME = "VOLUME",
|
|
49
|
-
SHELL = "SHELL",
|
|
50
|
-
EDGE = "EDGE",
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const enum TimeMode {
|
|
54
|
-
LIFETIME = "LIFETIME",
|
|
55
|
-
FPS = "FPS",
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export type ShapeConfig = {
|
|
59
|
-
shape?: Shape;
|
|
60
|
-
sphere?: {
|
|
61
|
-
radius?: number;
|
|
62
|
-
radiusThickness?: number;
|
|
63
|
-
arc?: number;
|
|
64
|
-
};
|
|
65
|
-
cone?: {
|
|
66
|
-
angle?: number;
|
|
67
|
-
radius?: number;
|
|
68
|
-
radiusThickness?: number;
|
|
69
|
-
arc?: number;
|
|
70
|
-
};
|
|
71
|
-
circle?: {
|
|
72
|
-
radius?: number;
|
|
73
|
-
radiusThickness?: number;
|
|
74
|
-
arc?: number;
|
|
75
|
-
};
|
|
76
|
-
rectangle?: {
|
|
77
|
-
rotation?: Point3D;
|
|
78
|
-
scale?: Point3D;
|
|
79
|
-
};
|
|
80
|
-
box?: {
|
|
81
|
-
scale?: Point3D;
|
|
82
|
-
emitFrom?: EmitFrom;
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export type TextureSheetAnimation = {
|
|
87
|
-
tiles?: THREE.Vector2;
|
|
88
|
-
timeMode?: TimeMode;
|
|
89
|
-
fps?: number;
|
|
90
|
-
startFrame?: MinMaxNumber;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export type ParticleSystemConfig = {
|
|
94
|
-
transform?: Transform;
|
|
95
|
-
duration?: number;
|
|
96
|
-
looping?: boolean;
|
|
97
|
-
startDelay?: MinMaxNumber;
|
|
98
|
-
startLifetime?: MinMaxNumber;
|
|
99
|
-
startSpeed?: MinMaxNumber;
|
|
100
|
-
startSize?: MinMaxNumber;
|
|
101
|
-
startRotation?: MinMaxNumber;
|
|
102
|
-
startColor?: MinMaxColor;
|
|
103
|
-
startOpacity?: MinMaxNumber;
|
|
104
|
-
gravity?: number;
|
|
105
|
-
simulationSpace?: SimulationSpace;
|
|
106
|
-
maxParticles?: number;
|
|
107
|
-
emission?: Emission;
|
|
108
|
-
shape?: ShapeConfig;
|
|
109
|
-
map?: THREE.Texture;
|
|
110
|
-
renderer?: any;
|
|
111
|
-
velocityOverLifetime?: any;
|
|
112
|
-
sizeOverLifetime?: any;
|
|
113
|
-
opacityOverLifetime?: any;
|
|
114
|
-
rotationOverLifetime?: any;
|
|
115
|
-
noise?: any;
|
|
116
|
-
textureSheetAnimation?: TextureSheetAnimation;
|
|
117
|
-
_editorData: any;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export type ParticleSystem = {
|
|
121
|
-
instance: THREE.Object3D;
|
|
122
|
-
resumeEmitter: () => void;
|
|
123
|
-
pauseEmitter: () => void;
|
|
124
|
-
dispose: () => void;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export type CycleData = {
|
|
128
|
-
now: number,
|
|
129
|
-
delta: number,
|
|
130
|
-
elapsed: number,
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
export function createParticleSystem(
|
|
134
|
-
config: ParticleSystemConfig,
|
|
135
|
-
externalNow?: number
|
|
136
|
-
): ParticleSystem;
|
|
137
|
-
|
|
138
|
-
export function updateParticleSystems(cycleData:CycleData): void;
|