@newkrok/three-particles 1.0.3 → 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 -138
  44. package/src/js/effects/three-particles.js +0 -931
@@ -0,0 +1,1037 @@
1
+ import * as THREE from 'three';
2
+ import { Gyroscope } from 'three/examples/jsm/misc/Gyroscope.js';
3
+ import { FBM } from 'three-noise/build/three-noise.module.js';
4
+ import { EmitFrom, LifeTimeCurve, Shape, SimulationSpace, TimeMode } from './three-particles-enums.js';
5
+ /**
6
+ * A fixed numerical value.
7
+ * Used for properties that require a constant value.
8
+ *
9
+ * @example
10
+ * const delay: Constant = 2; // Fixed delay of 2 seconds.
11
+ */
12
+ export type Constant = number;
13
+ /**
14
+ * An object that defines a range for random number generation.
15
+ * Contains `min` and `max` properties.
16
+ *
17
+ * @property min - The minimum value for the random range.
18
+ * @property max - The maximum value for the random range.
19
+ *
20
+ * @example
21
+ * const randomDelay: RandomBetweenTwoConstants = { min: 0.5, max: 2 }; // Random delay between 0.5 and 2 seconds.
22
+ */
23
+ export type RandomBetweenTwoConstants = {
24
+ min?: number;
25
+ max?: number;
26
+ };
27
+ /**
28
+ * Base type for curves, containing common properties.
29
+ * @property scale - A scaling factor for the curve.
30
+ */
31
+ export type CurveBase = {
32
+ scale?: number;
33
+ };
34
+ /**
35
+ * A function that defines how the value changes over time.
36
+ * @param time - A normalized value between 0 and 1 representing the progress of the curve.
37
+ * @returns The corresponding value based on the curve function.
38
+ */
39
+ export type CurveFunction = (time: number) => number;
40
+ /**
41
+ * A Bézier curve point representing a control point.
42
+ * @property x - The time (normalized between 0 and 1).
43
+ * @property y - The value at that point.
44
+ * @property percentage - (Optional) Normalized position within the curve (for additional flexibility).
45
+ */
46
+ export type BezierPoint = {
47
+ x: number;
48
+ y: number;
49
+ percentage?: number;
50
+ };
51
+ /**
52
+ * A Bézier curve representation for controlling particle properties.
53
+ * @property type - Specifies that this curve is of type `bezier`.
54
+ * @property bezierPoints - An array of control points defining the Bézier curve.
55
+ * @example
56
+ * {
57
+ * type: LifeTimeCurve.BEZIER,
58
+ * bezierPoints: [
59
+ * { x: 0, y: 0.275, percentage: 0 },
60
+ * { x: 0.1666, y: 0.4416 },
61
+ * { x: 0.5066, y: 0.495, percentage: 0.5066 },
62
+ * { x: 1, y: 1, percentage: 1 }
63
+ * ]
64
+ * }
65
+ */
66
+ export type BezierCurve = CurveBase & {
67
+ type: LifeTimeCurve.BEZIER;
68
+ bezierPoints: Array<BezierPoint>;
69
+ };
70
+ /**
71
+ * An easing curve representation using a custom function.
72
+ * @property type - Specifies that this curve is of type `easing`.
73
+ * @property curveFunction - A function defining how the value changes over time.
74
+ * @example
75
+ * {
76
+ * type: LifeTimeCurve.EASING,
77
+ * curveFunction: (time) => Math.sin(time * Math.PI) // Simple easing function
78
+ * }
79
+ */
80
+ export type EasingCurve = CurveBase & {
81
+ type: LifeTimeCurve.EASING;
82
+ curveFunction: CurveFunction;
83
+ };
84
+ /**
85
+ * A flexible curve representation that supports Bézier curves and easing functions.
86
+ */
87
+ export type LifetimeCurve = BezierCurve | EasingCurve;
88
+ /**
89
+ * Represents a point in 3D space with optional x, y, and z coordinates.
90
+ * Each coordinate is a number and is optional, allowing for partial definitions.
91
+ *
92
+ * @example
93
+ * // A point with all coordinates defined
94
+ * const point: Point3D = { x: 10, y: 20, z: 30 };
95
+ *
96
+ * @example
97
+ * // A point with only one coordinate defined
98
+ * const point: Point3D = { x: 10 };
99
+ *
100
+ * @default
101
+ * // Default values are undefined for all coordinates.
102
+ * const point: Point3D = {};
103
+ */
104
+ export type Point3D = {
105
+ x?: number;
106
+ y?: number;
107
+ z?: number;
108
+ };
109
+ /**
110
+ * Represents a transform in 3D space, including position, rotation, and scale.
111
+ * Each property is optional and represented as a THREE.Vector3 instance.
112
+ *
113
+ * - `position`: Defines the translation of an object in 3D space.
114
+ * - `rotation`: Defines the rotation of an object in radians for each axis (x, y, z).
115
+ * - `scale`: Defines the scale of an object along each axis.
116
+ *
117
+ * @example
118
+ * // A transform with all properties defined
119
+ * const transform: Transform = {
120
+ * position: new THREE.Vector3(10, 20, 30),
121
+ * rotation: new THREE.Vector3(Math.PI / 2, 0, 0),
122
+ * scale: new THREE.Vector3(1, 1, 1),
123
+ * };
124
+ *
125
+ * @example
126
+ * // A transform with only position defined
127
+ * const transform: Transform = {
128
+ * position: new THREE.Vector3(5, 5, 5),
129
+ * };
130
+ *
131
+ * @default
132
+ * // Default values are undefined for all properties.
133
+ * const transform: Transform = {};
134
+ */
135
+ export type Transform = {
136
+ position?: THREE.Vector3;
137
+ rotation?: THREE.Vector3;
138
+ scale?: THREE.Vector3;
139
+ };
140
+ export type Rgb = {
141
+ r?: number;
142
+ g?: number;
143
+ b?: number;
144
+ };
145
+ export type MinMaxColor = {
146
+ min?: Rgb;
147
+ max?: Rgb;
148
+ };
149
+ /**
150
+ * Defines the emission behavior of the particles.
151
+ * Supports rates defined over time or distance using constant values, random ranges, or curves (Bézier or easing).
152
+ *
153
+ * @default
154
+ * rateOverTime: 10.0
155
+ * rateOverDistance: 0.0
156
+ *
157
+ * @example
158
+ * // Rate over time as a constant value
159
+ * rateOverTime: 10;
160
+ *
161
+ * // Rate over time as a random range
162
+ * rateOverTime: { min: 5, max: 15 };
163
+ *
164
+ * // Rate over time using a Bézier curve
165
+ * rateOverTime: {
166
+ * type: 'bezier',
167
+ * bezierPoints: [
168
+ * { x: 0, y: 0, percentage: 0 },
169
+ * { x: 0.5, y: 50 },
170
+ * { x: 1, y: 100, percentage: 1 }
171
+ * ],
172
+ * scale: 1
173
+ * };
174
+ *
175
+ * // Rate over distance as a constant value
176
+ * rateOverDistance: 2;
177
+ *
178
+ * // Rate over distance as a random range
179
+ * rateOverDistance: { min: 1, max: 3 };
180
+ *
181
+ * // Rate over distance using an easing curve
182
+ * rateOverDistance: {
183
+ * type: 'easing',
184
+ * curveFunction: (distance) => Math.sin(distance),
185
+ * scale: 0.5
186
+ * };
187
+ */
188
+ export type Emission = {
189
+ rateOverTime?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
190
+ rateOverDistance?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
191
+ };
192
+ /**
193
+ * Configuration for a sphere shape used in particle systems.
194
+ *
195
+ * @property radius - The radius of the sphere.
196
+ * @property radiusThickness - The thickness of the sphere's shell (0 to 1, where 1 is solid).
197
+ * @property arc - The angular arc of the sphere (in radians).
198
+ *
199
+ * @example
200
+ * const sphere: Sphere = {
201
+ * radius: 5,
202
+ * radiusThickness: 0.8,
203
+ * arc: Math.PI,
204
+ * };
205
+ */
206
+ export type Sphere = {
207
+ radius?: number;
208
+ radiusThickness?: number;
209
+ arc?: number;
210
+ };
211
+ /**
212
+ * Configuration for a cone shape used in particle systems.
213
+ *
214
+ * @property angle - The angle of the cone (in radians).
215
+ * @property radius - The radius of the cone's base.
216
+ * @property radiusThickness - The thickness of the cone's base (0 to 1, where 1 is solid).
217
+ * @property arc - The angular arc of the cone's base (in radians).
218
+ *
219
+ * @example
220
+ * const cone: Cone = {
221
+ * angle: Math.PI / 4,
222
+ * radius: 10,
223
+ * radiusThickness: 0.5,
224
+ * arc: Math.PI * 2,
225
+ * };
226
+ */
227
+ export type Cone = {
228
+ angle?: number;
229
+ radius?: number;
230
+ radiusThickness?: number;
231
+ arc?: number;
232
+ };
233
+ /**
234
+ * Configuration for a circle shape used in particle systems.
235
+ *
236
+ * @property radius - The radius of the circle.
237
+ * @property radiusThickness - The thickness of the circle's shell (0 to 1, where 1 is solid).
238
+ * @property arc - The angular arc of the circle (in radians).
239
+ *
240
+ * @example
241
+ * const circle: Circle = {
242
+ * radius: 10,
243
+ * radiusThickness: 0.5,
244
+ * arc: Math.PI,
245
+ * };
246
+ */
247
+ export type Circle = {
248
+ radius?: number;
249
+ radiusThickness?: number;
250
+ arc?: number;
251
+ };
252
+ /**
253
+ * Configuration for a rectangle shape used in particle systems.
254
+ *
255
+ * @property rotation - The rotation of the rectangle as a 3D point (in radians for each axis).
256
+ * @property scale - The scale of the rectangle as a 3D point.
257
+ *
258
+ * @example
259
+ * const rectangle: Rectangle = {
260
+ * rotation: { x: Math.PI / 4, y: 0, z: 0 },
261
+ * scale: { x: 10, y: 5, z: 1 },
262
+ * };
263
+ */
264
+ export type Rectangle = {
265
+ rotation?: Point3D;
266
+ scale?: Point3D;
267
+ };
268
+ /**
269
+ * Configuration for a box shape used in particle systems.
270
+ *
271
+ * @property scale - The scale of the box as a 3D point.
272
+ * @property emitFrom - Specifies where particles are emitted from within the box.
273
+ *
274
+ * @example
275
+ * const box: Box = {
276
+ * scale: { x: 10, y: 10, z: 10 },
277
+ * emitFrom: EmitFrom.EDGE,
278
+ * };
279
+ */
280
+ export type Box = {
281
+ scale?: Point3D;
282
+ emitFrom?: EmitFrom;
283
+ };
284
+ /**
285
+ * Configuration for defining a 3D shape used in particle systems.
286
+ * Specifies the shape type and its parameters, including spheres, cones, circles, rectangles, and boxes.
287
+ *
288
+ * @property shape - The type of the shape to be used.
289
+ * @property sphere - Configuration for a sphere shape.
290
+ * @property cone - Configuration for a cone shape.
291
+ * @property circle - Configuration for a circle shape.
292
+ * @property rectangle - Configuration for a rectangle shape.
293
+ * @property box - Configuration for a box shape.
294
+ *
295
+ * @example
296
+ * const shapeConfig: ShapeConfig = {
297
+ * shape: Shape.SPHERE,
298
+ * sphere: {
299
+ * radius: 5,
300
+ * radiusThickness: 0.8,
301
+ * arc: Math.PI,
302
+ * },
303
+ * };
304
+ */
305
+ export type ShapeConfig = {
306
+ shape?: Shape;
307
+ sphere?: Sphere;
308
+ cone?: Cone;
309
+ circle?: Circle;
310
+ rectangle?: Rectangle;
311
+ box?: Box;
312
+ };
313
+ /**
314
+ * Defines the texture sheet animation settings for particles.
315
+ * Allows configuring the animation frames, timing mode, frames per second, and the starting frame.
316
+ *
317
+ * @default
318
+ * tiles: new THREE.Vector2(1.0, 1.0)
319
+ * timeMode: TimeMode.LIFETIME
320
+ * fps: 30.0
321
+ * startFrame: 0
322
+ *
323
+ * @example
324
+ * // Basic configuration with default values
325
+ * textureSheetAnimation: {
326
+ * tiles: new THREE.Vector2(1.0, 1.0),
327
+ * timeMode: TimeMode.LIFETIME,
328
+ * fps: 30.0,
329
+ * startFrame: 0
330
+ * };
331
+ *
332
+ * // Custom configuration
333
+ * textureSheetAnimation: {
334
+ * tiles: new THREE.Vector2(4, 4), // 4x4 grid of animation tiles
335
+ * timeMode: TimeMode.SPEED,
336
+ * fps: 60.0,
337
+ * startFrame: { min: 0, max: 15 } // Random start frame between 0 and 15
338
+ * };
339
+ */
340
+ export type TextureSheetAnimation = {
341
+ tiles?: THREE.Vector2;
342
+ timeMode?: TimeMode;
343
+ fps?: number;
344
+ startFrame?: Constant | RandomBetweenTwoConstants;
345
+ };
346
+ /**
347
+ * Configuration for the particle system renderer, controlling blending, transparency, depth, and background color behavior.
348
+ *
349
+ * @property blending - Defines the blending mode for the particle system (e.g., additive blending).
350
+ * @property discardBackgroundColor - Whether to discard particles that match the background color.
351
+ * @property backgroundColorTolerance - The tolerance for matching the background color when `discardBackgroundColor` is true.
352
+ * @property backgroundColor - The background color as an RGB value, used when `discardBackgroundColor` is enabled.
353
+ * @property transparent - Whether the particle system uses transparency.
354
+ * @property depthTest - Whether to enable depth testing for particles (determines if particles are rendered behind or in front of other objects).
355
+ * @property depthWrite - Whether to write depth information for the particles (affects sorting and rendering order).
356
+ *
357
+ * @example
358
+ * // A renderer configuration with additive blending and transparent particles
359
+ * const renderer: Renderer = {
360
+ * blending: THREE.AdditiveBlending,
361
+ * discardBackgroundColor: true,
362
+ * backgroundColorTolerance: 0.1,
363
+ * backgroundColor: { r: 0, g: 0, b: 0 },
364
+ * transparent: true,
365
+ * depthTest: true,
366
+ * depthWrite: false,
367
+ * };
368
+ *
369
+ * @default
370
+ * // Default values for the renderer configuration
371
+ * const renderer: Renderer = {
372
+ * blending: THREE.NormalBlending,
373
+ * discardBackgroundColor: false,
374
+ * backgroundColorTolerance: 1.0,
375
+ * backgroundColor: { r: 0, g: 0, b: 0 },
376
+ * transparent: false,
377
+ * depthTest: true,
378
+ * depthWrite: true,
379
+ * };
380
+ */
381
+ export type Renderer = {
382
+ blending: THREE.Blending;
383
+ discardBackgroundColor: boolean;
384
+ backgroundColorTolerance: number;
385
+ backgroundColor: Rgb;
386
+ transparent: boolean;
387
+ depthTest: boolean;
388
+ depthWrite: boolean;
389
+ };
390
+ /**
391
+ * Configuration for noise effects applied to particles in a particle system.
392
+ * Noise can affect particle position, rotation, and size dynamically.
393
+ *
394
+ * @property isActive - Whether noise is enabled for the particle system.
395
+ * @property strength - The overall strength of the noise effect.
396
+ * @property positionAmount - The amount of noise applied to particle positions.
397
+ * @property rotationAmount - The amount of noise applied to particle rotations.
398
+ * @property sizeAmount - The amount of noise applied to particle sizes.
399
+ * @property sampler - An optional noise sampler (e.g., FBM for fractal Brownian motion) to generate noise values.
400
+ * @property offsets - An optional array of offsets to randomize noise generation per particle.
401
+ *
402
+ * @example
403
+ * // A noise configuration with position and rotation noise
404
+ * const noise: Noise = {
405
+ * isActive: true,
406
+ * strength: 0.5,
407
+ * positionAmount: 1.0,
408
+ * rotationAmount: 0.3,
409
+ * sizeAmount: 0.0,
410
+ * sampler: new FBM(),
411
+ * offsets: [0.1, 0.2, 0.3],
412
+ * };
413
+ *
414
+ * @default
415
+ * // Default values for noise configuration
416
+ * const noise: Noise = {
417
+ * isActive: false,
418
+ * strength: 1.0,
419
+ * positionAmount: 0.0,
420
+ * rotationAmount: 0.0,
421
+ * sizeAmount: 0.0,
422
+ * sampler: undefined,
423
+ * offsets: undefined,
424
+ * };
425
+ */
426
+ export type Noise = {
427
+ isActive: boolean;
428
+ strength: number;
429
+ positionAmount: number;
430
+ rotationAmount: number;
431
+ sizeAmount: number;
432
+ sampler?: FBM;
433
+ offsets?: Array<number>;
434
+ };
435
+ export type NoiseConfig = {
436
+ isActive: boolean;
437
+ useRandomOffset: boolean;
438
+ strength: number;
439
+ frequency: number;
440
+ octaves: number;
441
+ positionAmount: number;
442
+ rotationAmount: number;
443
+ sizeAmount: number;
444
+ };
445
+ /**
446
+ * Defines the velocity of particles over their lifetime, allowing for linear and orbital velocity (in degrees) adjustments.
447
+ * Supports constant values, random ranges, or curves (Bézier or easing) for each axis.
448
+ *
449
+ * @default
450
+ * isActive: false
451
+ * linear: { x: 0.0, y: 0.0, z: 0.0 }
452
+ * orbital: { x: 0.0, y: 0.0, z: 0.0 }
453
+ *
454
+ * @example
455
+ * // Linear velocity with a constant value
456
+ * linear: { x: 1, y: 0, z: -0.5 };
457
+ *
458
+ * // Linear velocity with random ranges
459
+ * linear: {
460
+ * x: { min: -1, max: 1 },
461
+ * y: { min: 0, max: 2 }
462
+ * };
463
+ *
464
+ * // Linear velocity using a Bézier curve
465
+ * linear: {
466
+ * z: {
467
+ * type: 'bezier',
468
+ * bezierPoints: [
469
+ * { x: 0, y: 0, percentage: 0 },
470
+ * { x: 0.5, y: 2 },
471
+ * { x: 1, y: 10, percentage: 1 }
472
+ * ],
473
+ * scale: 2
474
+ * }
475
+ * };
476
+ *
477
+ * // Orbital velocity with a constant value
478
+ * orbital: { x: 3, y: 5, z: 0 };
479
+ *
480
+ * // Orbital velocity using an easing curve
481
+ * orbital: {
482
+ * x: {
483
+ * type: 'easing',
484
+ * curveFunction: (time) => Math.sin(time * Math.PI),
485
+ * scale: 1.5
486
+ * }
487
+ * };
488
+ */
489
+ export type VelocityOverLifetime = {
490
+ isActive: boolean;
491
+ linear: {
492
+ x?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
493
+ y?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
494
+ z?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
495
+ };
496
+ orbital: {
497
+ x?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
498
+ y?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
499
+ z?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
500
+ };
501
+ };
502
+ /**
503
+ * Configuration object for the particle system.
504
+ * Defines all aspects of the particle system, including its appearance, behavior, and runtime events.
505
+ */
506
+ export type ParticleSystemConfig = {
507
+ /**
508
+ * Defines the position, rotation, and scale of the particle system.
509
+ *
510
+ * @see Transform
511
+ * @default
512
+ * transform: {
513
+ * position: new THREE.Vector3(),
514
+ * rotation: new THREE.Vector3(),
515
+ * scale: new THREE.Vector3(1, 1, 1),
516
+ * }
517
+ */
518
+ transform?: Transform;
519
+ /**
520
+ * Duration of the particle system in seconds.
521
+ * Must be a positive value.
522
+ * @default 5.0
523
+ * @example
524
+ * const duration: number = 5; // System runs for 5 seconds.
525
+ */
526
+ duration?: number;
527
+ /**
528
+ * Indicates whether the system should loop after finishing.
529
+ * @default true
530
+ * @example
531
+ * looping: true; // System loops continuously.
532
+ */
533
+ looping?: boolean;
534
+ /**
535
+ * Delay before the particle system starts emitting particles.
536
+ * Supports a fixed value (`Constant`) or a random range (`RandomBetweenTwoConstants`).
537
+ * @default 0.0
538
+ * @example
539
+ * startDelay: 2; // Fixed 2-second delay.
540
+ * startDelay: { min: 0.5, max: 2 }; // Random delay between 0.5 and 2 seconds.
541
+ */
542
+ startDelay?: Constant | RandomBetweenTwoConstants;
543
+ /**
544
+ * Initial lifetime of the particles.
545
+ * Supports constant value, random range, or curves (Bézier or easing).
546
+ * @default 5.0
547
+ * @example
548
+ * // Constant 3 seconds.
549
+ * startLifetime: 3;
550
+ *
551
+ * // Random range between 1 and 4 seconds.
552
+ * startLifetime: { min: 1, max: 4 };
553
+ *
554
+ * // Bézier curve example with scaling.
555
+ * startLifetime: {
556
+ * type: LifeTimeCurve.BEZIER,
557
+ * bezierPoints: [
558
+ * { x: 0, y: 0.275, percentage: 0 },
559
+ * { x: 0.5, y: 0.5 },
560
+ * { x: 1, y: 1, percentage: 1 }
561
+ * ],
562
+ * scale: 2
563
+ * };
564
+ *
565
+ * // Easing curve example with scaling.
566
+ * startLifetime: {
567
+ * type: LifeTimeCurve.EASING,
568
+ * curveFunction: (time) => Math.sin(time * Math.PI),
569
+ * scale: 0.5
570
+ * };
571
+ */
572
+ startLifetime?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
573
+ /**
574
+ * Defines the initial speed of the particles.
575
+ * Supports constant values, random ranges, or curves (Bézier or easing).
576
+ * @default 1.0
577
+ * @example
578
+ * // Constant value
579
+ * startSpeed: 3;
580
+ *
581
+ * // Random range
582
+ * startSpeed: { min: 1, max: 4 };
583
+ *
584
+ * // Bézier curve example with scaling.
585
+ * startSpeed: {
586
+ * type: 'bezier',
587
+ * bezierPoints: [
588
+ * { x: 0, y: 0.275, percentage: 0 },
589
+ * { x: 0.5, y: 0.5 },
590
+ * { x: 1, y: 1, percentage: 1 }
591
+ * ],
592
+ * scale: 2
593
+ * };
594
+ *
595
+ * // Easing curve example with scaling.
596
+ * startSpeed: {
597
+ * type: 'easing',
598
+ * curveFunction: (time) => Math.sin(time * Math.PI),
599
+ * scale: 1.5
600
+ * };
601
+ */
602
+ startSpeed?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
603
+ /**
604
+ * Defines the initial size of the particles.
605
+ * Supports constant values, random ranges, or curves (Bézier or easing).
606
+ * @default 1.0
607
+ * @example
608
+ * // Constant value
609
+ * startSize: 3;
610
+ *
611
+ * // Random range
612
+ * startSize: { min: 1, max: 4 };
613
+ *
614
+ * // Bézier curve example with scaling.
615
+ * startSize: {
616
+ * type: 'bezier',
617
+ * bezierPoints: [
618
+ * { x: 0, y: 0.275, percentage: 0 },
619
+ * { x: 0.5, y: 0.5 },
620
+ * { x: 1, y: 1, percentage: 1 }
621
+ * ],
622
+ * scale: 2
623
+ * };
624
+ *
625
+ * // Easing curve example with scaling.
626
+ * startSize: {
627
+ * type: 'easing',
628
+ * curveFunction: (time) => Math.sin(time * Math.PI),
629
+ * scale: 1.5
630
+ * };
631
+ */
632
+ startSize?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
633
+ /**
634
+ * Defines the initial opacity of the particles.
635
+ * Supports constant values, random ranges, or curves (Bézier or easing).
636
+ * @default 1.0
637
+ * @example
638
+ * // Constant value
639
+ * startOpacity: 3;
640
+ *
641
+ * // Random range
642
+ * startOpacity: { min: 1, max: 4 };
643
+ *
644
+ * // Bézier curve example with scaling.
645
+ * startOpacity: {
646
+ * type: 'bezier',
647
+ * bezierPoints: [
648
+ * { x: 0, y: 0.275, percentage: 0 },
649
+ * { x: 0.5, y: 0.5 },
650
+ * { x: 1, y: 1, percentage: 1 }
651
+ * ],
652
+ * scale: 2
653
+ * };
654
+ *
655
+ * // Easing curve example with scaling.
656
+ * startOpacity: {
657
+ * type: 'easing',
658
+ * curveFunction: (time) => Math.sin(time * Math.PI),
659
+ * scale: 1.5
660
+ * };
661
+ */
662
+ startOpacity?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
663
+ /**
664
+ * Defines the initial rotation of the particles in degrees.
665
+ * Supports constant values, random ranges, or curves (Bézier or easing).
666
+ * @default 0.0
667
+ * @example
668
+ * // Constant value
669
+ * startRotation: 3;
670
+ *
671
+ * // Random range
672
+ * startRotation: { min: 1, max: 4 };
673
+ *
674
+ * // Bézier curve example with scaling.
675
+ * startRotation: {
676
+ * type: 'bezier',
677
+ * bezierPoints: [
678
+ * { x: 0, y: 0.275, percentage: 0 },
679
+ * { x: 0.5, y: 0.5 },
680
+ * { x: 1, y: 1, percentage: 1 }
681
+ * ],
682
+ * scale: 2
683
+ * };
684
+ *
685
+ * // Easing curve example with scaling.
686
+ * startRotation: {
687
+ * type: 'easing',
688
+ * curveFunction: (time) => Math.sin(time * Math.PI),
689
+ * scale: 1.5
690
+ * };
691
+ */
692
+ startRotation?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
693
+ /**
694
+ * Initial color of the particles.
695
+ * Supports a min-max range for color interpolation.
696
+ *
697
+ * @default
698
+ * startColor: {
699
+ * min: { r: 1.0, g: 1.0, b: 1.0 },
700
+ * max: { r: 1.0, g: 1.0, b: 1.0 },
701
+ * }
702
+ */
703
+ startColor?: MinMaxColor;
704
+ /**
705
+ * Defines the gravity strength applied to particles.
706
+ * This value affects the downward acceleration of particles over time.
707
+ *
708
+ * @default 0.0
709
+ *
710
+ * @example
711
+ * // No gravity
712
+ * gravity: 0;
713
+ *
714
+ * // Moderate gravity
715
+ * gravity: 9.8; // Similar to Earth's gravity
716
+ *
717
+ * // Strong gravity
718
+ * gravity: 20.0;
719
+ */
720
+ gravity?: Constant;
721
+ /**
722
+ * Defines the simulation space in which particles are simulated.
723
+ * Determines whether the particles move relative to the local object space or the world space.
724
+ *
725
+ * @default SimulationSpace.LOCAL
726
+ *
727
+ * @example
728
+ * // Simulate particles in local space (default)
729
+ * simulationSpace: SimulationSpace.LOCAL;
730
+ *
731
+ * // Simulate particles in world space
732
+ * simulationSpace: SimulationSpace.WORLD;
733
+ */
734
+ simulationSpace?: SimulationSpace;
735
+ /**
736
+ * Defines the maximum number of particles allowed in the system.
737
+ * This value limits the total number of active particles at any given time.
738
+ *
739
+ * @default 100.0
740
+ *
741
+ * @example
742
+ * // Default value
743
+ * maxParticles: 100.0;
744
+ *
745
+ * // Increase the maximum number of particles
746
+ * maxParticles: 500.0;
747
+ *
748
+ * // Limit to a small number of particles
749
+ * maxParticles: 10.0;
750
+ */
751
+ maxParticles?: Constant;
752
+ /**
753
+ * Defines the particle emission settings.
754
+ * Configures the emission rate over time and distance.
755
+ *
756
+ * @see Emission
757
+ * @default
758
+ * emission: {
759
+ * rateOverTime: 10.0,
760
+ * rateOverDistance: 0.0,
761
+ * }
762
+ */
763
+ emission?: Emission;
764
+ /**
765
+ * Configuration for the emitter shape.
766
+ * Determines the shape and parameters for particle emission.
767
+ *
768
+ * @see ShapeConfig
769
+ */
770
+ shape?: ShapeConfig;
771
+ /**
772
+ * Defines the texture used for rendering particles.
773
+ * This texture is applied to all particles in the system, and can be used to control their appearance.
774
+ *
775
+ * @default undefined
776
+ *
777
+ * @example
778
+ * // Using a predefined texture
779
+ * map: new THREE.TextureLoader().load('path/to/texture.png');
780
+ *
781
+ * // No texture (default behavior)
782
+ * map: undefined;
783
+ */
784
+ map?: THREE.Texture;
785
+ /**
786
+ * Renderer configuration for blending, transparency, and depth testing.
787
+ *
788
+ * @see Renderer
789
+ * @default
790
+ * renderer: {
791
+ * blending: THREE.NormalBlending,
792
+ * discardBackgroundColor: false,
793
+ * backgroundColorTolerance: 1.0,
794
+ * backgroundColor: { r: 1.0, g: 1.0, b: 1.0 },
795
+ * transparent: true,
796
+ * depthTest: true,
797
+ * depthWrite: false
798
+ * }
799
+ */
800
+ renderer?: Renderer;
801
+ /**
802
+ * Defines the velocity settings of particles over their lifetime.
803
+ * Configures both linear and orbital velocity changes.
804
+ *
805
+ * @see VelocityOverLifetime
806
+ * @default
807
+ * velocityOverLifetime: {
808
+ * isActive: false,
809
+ * linear: {
810
+ * x: 0,
811
+ * y: 0,
812
+ * z: 0,
813
+ * },
814
+ * orbital: {
815
+ * x: 0,
816
+ * y: 0,
817
+ * z: 0,
818
+ * },
819
+ * }
820
+ */
821
+ velocityOverLifetime?: VelocityOverLifetime;
822
+ /**
823
+ * Controls the size of particles over their lifetime.
824
+ * The size can be adjusted using a lifetime curve (Bézier or other supported types).
825
+ *
826
+ * @default
827
+ * sizeOverLifetime: {
828
+ * isActive: false,
829
+ * lifetimeCurve: {
830
+ * type: LifeTimeCurve.BEZIER,
831
+ * scale: 1,
832
+ * bezierPoints: [
833
+ * { x: 0, y: 0, percentage: 0 },
834
+ * { x: 1, y: 1, percentage: 1 },
835
+ * ],
836
+ * },
837
+ * }
838
+ */
839
+ sizeOverLifetime?: {
840
+ isActive: boolean;
841
+ lifetimeCurve: LifetimeCurve;
842
+ };
843
+ /**
844
+ * Controls the opacity of particles over their lifetime.
845
+ * The opacity can be adjusted using a lifetime curve (Bézier or other supported types).
846
+ *
847
+ * @default
848
+ * opacityOverLifetime: {
849
+ * isActive: false,
850
+ * lifetimeCurve: {
851
+ * type: LifeTimeCurve.BEZIER,
852
+ * scale: 1,
853
+ * bezierPoints: [
854
+ * { x: 0, y: 0, percentage: 0 },
855
+ * { x: 1, y: 1, percentage: 1 },
856
+ * ],
857
+ * },
858
+ * }
859
+ */
860
+ opacityOverLifetime?: {
861
+ isActive: boolean;
862
+ lifetimeCurve: LifetimeCurve;
863
+ };
864
+ /**
865
+ * Controls the rotation of particles over their lifetime.
866
+ * The rotation can be randomized between two constants, and the feature can be toggled on or off.
867
+ *
868
+ * @default
869
+ * rotationOverLifetime: {
870
+ * isActive: false,
871
+ * min: 0.0,
872
+ * max: 0.0,
873
+ * }
874
+ */
875
+ rotationOverLifetime?: {
876
+ isActive: boolean;
877
+ } & RandomBetweenTwoConstants;
878
+ /**
879
+ * Noise configuration affecting position, rotation, and size.
880
+ *
881
+ * @see NoiseConfig
882
+ * @default
883
+ * noise: {
884
+ * isActive: false,
885
+ * useRandomOffset: false,
886
+ * strength: 1.0,
887
+ * frequency: 0.5,
888
+ * octaves: 1,
889
+ * positionAmount: 1.0,
890
+ * rotationAmount: 0.0,
891
+ * sizeAmount: 0.0,
892
+ * }
893
+ */
894
+ noise?: NoiseConfig;
895
+ /**
896
+ * Configures the texture sheet animation settings for particles.
897
+ * Controls how textures are animated over the lifetime of particles.
898
+ *
899
+ * @see TextureSheetAnimation
900
+ * @default
901
+ * textureSheetAnimation: {
902
+ * tiles: new THREE.Vector2(1.0, 1.0),
903
+ * timeMode: TimeMode.LIFETIME,
904
+ * fps: 30.0,
905
+ * startFrame: 0,
906
+ * }
907
+ */
908
+ textureSheetAnimation?: TextureSheetAnimation;
909
+ /**
910
+ * Called on every update frame with particle system data.
911
+ */
912
+ onUpdate?: (data: {
913
+ particleSystem: THREE.Points;
914
+ delta: number;
915
+ elapsed: number;
916
+ lifetime: number;
917
+ iterationCount: number;
918
+ }) => void;
919
+ /**
920
+ * Called when the system completes an iteration.
921
+ */
922
+ onComplete?: () => void;
923
+ };
924
+ export type NormalizedParticleSystemConfig = Required<ParticleSystemConfig>;
925
+ export type GeneralData = {
926
+ particleSystemId: number;
927
+ normalizedLifetimePercentage: number;
928
+ creationTimes: Array<number>;
929
+ distanceFromLastEmitByDistance: number;
930
+ lastWorldPosition: THREE.Vector3;
931
+ currentWorldPosition: THREE.Vector3;
932
+ worldPositionChange: THREE.Vector3;
933
+ wrapperQuaternion: THREE.Quaternion;
934
+ lastWorldQuaternion: THREE.Quaternion;
935
+ worldQuaternion: THREE.Quaternion;
936
+ worldEuler: THREE.Euler;
937
+ gravityVelocity: THREE.Vector3;
938
+ startValues: Record<string, Array<number>>;
939
+ linearVelocityData?: Array<{
940
+ speed: THREE.Vector3;
941
+ valueModifiers: {
942
+ x?: CurveFunction;
943
+ y?: CurveFunction;
944
+ z?: CurveFunction;
945
+ };
946
+ }>;
947
+ orbitalVelocityData?: Array<{
948
+ speed: THREE.Vector3;
949
+ positionOffset: THREE.Vector3;
950
+ valueModifiers: {
951
+ x?: CurveFunction;
952
+ y?: CurveFunction;
953
+ z?: CurveFunction;
954
+ };
955
+ }>;
956
+ lifetimeValues: Record<string, Array<number>>;
957
+ noise: Noise;
958
+ isEnabled: boolean;
959
+ };
960
+ export type ParticleSystemInstance = {
961
+ particleSystem: THREE.Points;
962
+ wrapper?: Gyroscope;
963
+ generalData: GeneralData;
964
+ onUpdate: (data: {
965
+ particleSystem: THREE.Points;
966
+ delta: number;
967
+ elapsed: number;
968
+ lifetime: number;
969
+ normalizedLifetime: number;
970
+ iterationCount: number;
971
+ }) => void;
972
+ onComplete: (data: {
973
+ particleSystem: THREE.Points;
974
+ }) => void;
975
+ creationTime: number;
976
+ lastEmissionTime: number;
977
+ duration: number;
978
+ looping: boolean;
979
+ simulationSpace: SimulationSpace;
980
+ gravity: number;
981
+ emission: Emission;
982
+ normalizedConfig: NormalizedParticleSystemConfig;
983
+ iterationCount: number;
984
+ velocities: Array<THREE.Vector3>;
985
+ deactivateParticle: (particleIndex: number) => void;
986
+ activateParticle: (data: {
987
+ particleIndex: number;
988
+ activationTime: number;
989
+ position: Required<Point3D>;
990
+ }) => void;
991
+ };
992
+ /**
993
+ * Represents a particle system instance, providing methods to control and manage its lifecycle.
994
+ *
995
+ * @property instance - The underlying Three.js `Points` object or a `Gyroscope` used for particle rendering.
996
+ * @property resumeEmitter - Resumes the particle emitter, allowing particles to be emitted again.
997
+ * @property pauseEmitter - Pauses the particle emitter, stopping any new particles from being emitted.
998
+ * @property dispose - Disposes of the particle system, cleaning up resources to free memory.
999
+ *
1000
+ * @example
1001
+ * const particleSystem: ParticleSystem = {
1002
+ * instance: new THREE.Points(geometry, material),
1003
+ * resumeEmitter: () => { /* resume logic * / },
1004
+ * pauseEmitter: () => { /* pause logic * / },
1005
+ * dispose: () => { /* cleanup logic * / },
1006
+ * };
1007
+ *
1008
+ * particleSystem.pauseEmitter(); // Stop particle emission
1009
+ * particleSystem.resumeEmitter(); // Resume particle emission
1010
+ * particleSystem.dispose(); // Cleanup the particle system
1011
+ */
1012
+ export type ParticleSystem = {
1013
+ instance: THREE.Points | Gyroscope;
1014
+ resumeEmitter: () => void;
1015
+ pauseEmitter: () => void;
1016
+ dispose: () => void;
1017
+ };
1018
+ /**
1019
+ * Data representing the current cycle of the particle system's update loop.
1020
+ *
1021
+ * @property now - The current timestamp in milliseconds.
1022
+ * @property delta - The time elapsed since the last update, in seconds.
1023
+ * @property elapsed - The total time elapsed since the particle system started, in seconds.
1024
+ *
1025
+ * @example
1026
+ * const cycleData: CycleData = {
1027
+ * now: performance.now(),
1028
+ * delta: 0.016, // 16ms frame time
1029
+ * elapsed: 1.25, // 1.25 seconds since start
1030
+ * };
1031
+ */
1032
+ export type CycleData = {
1033
+ now: number;
1034
+ delta: number;
1035
+ elapsed: number;
1036
+ };
1037
+ //# sourceMappingURL=types.d.ts.map