@newkrok/three-particles 2.6.3 → 2.6.4

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 (39) hide show
  1. package/dist/index.d.ts +1782 -7
  2. package/dist/index.js +1578 -6
  3. package/dist/index.js.map +1 -0
  4. package/dist/three-particles.min.js +1 -2
  5. package/dist/three-particles.min.js.map +1 -0
  6. package/package.json +5 -7
  7. package/dist/bundle-report.json +0 -1
  8. package/dist/index.d.ts.map +0 -1
  9. package/dist/js/effects/three-particles/index.d.ts +0 -7
  10. package/dist/js/effects/three-particles/index.d.ts.map +0 -1
  11. package/dist/js/effects/three-particles/index.js +0 -6
  12. package/dist/js/effects/three-particles/shaders/particle-system-fragment-shader.glsl.d.ts +0 -3
  13. package/dist/js/effects/three-particles/shaders/particle-system-fragment-shader.glsl.d.ts.map +0 -1
  14. package/dist/js/effects/three-particles/shaders/particle-system-fragment-shader.glsl.js +0 -71
  15. package/dist/js/effects/three-particles/shaders/particle-system-vertex-shader.glsl.d.ts +0 -3
  16. package/dist/js/effects/three-particles/shaders/particle-system-vertex-shader.glsl.d.ts.map +0 -1
  17. package/dist/js/effects/three-particles/shaders/particle-system-vertex-shader.glsl.js +0 -37
  18. package/dist/js/effects/three-particles/three-particles-bezier.d.ts +0 -5
  19. package/dist/js/effects/three-particles/three-particles-bezier.d.ts.map +0 -1
  20. package/dist/js/effects/three-particles/three-particles-bezier.js +0 -62
  21. package/dist/js/effects/three-particles/three-particles-curves.d.ts +0 -108
  22. package/dist/js/effects/three-particles/three-particles-curves.d.ts.map +0 -1
  23. package/dist/js/effects/three-particles/three-particles-curves.js +0 -62
  24. package/dist/js/effects/three-particles/three-particles-enums.d.ts +0 -115
  25. package/dist/js/effects/three-particles/three-particles-enums.d.ts.map +0 -1
  26. package/dist/js/effects/three-particles/three-particles-enums.js +0 -1
  27. package/dist/js/effects/three-particles/three-particles-modifiers.d.ts +0 -73
  28. package/dist/js/effects/three-particles/three-particles-modifiers.d.ts.map +0 -1
  29. package/dist/js/effects/three-particles/three-particles-modifiers.js +0 -168
  30. package/dist/js/effects/three-particles/three-particles-utils.d.ts +0 -159
  31. package/dist/js/effects/three-particles/three-particles-utils.d.ts.map +0 -1
  32. package/dist/js/effects/three-particles/three-particles-utils.js +0 -302
  33. package/dist/js/effects/three-particles/three-particles.d.ts +0 -107
  34. package/dist/js/effects/three-particles/three-particles.d.ts.map +0 -1
  35. package/dist/js/effects/three-particles/three-particles.js +0 -972
  36. package/dist/js/effects/three-particles/types.d.ts +0 -1223
  37. package/dist/js/effects/three-particles/types.d.ts.map +0 -1
  38. package/dist/js/effects/three-particles/types.js +0 -1
  39. package/dist/three-particles.min.js.LICENSE.txt +0 -6
@@ -1,1223 +0,0 @@
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
- /**
141
- * Represents an RGB color with normalized values (0.0 to 1.0).
142
- *
143
- * @example
144
- * ```typescript
145
- * // Pure red
146
- * const red: Rgb = { r: 1.0, g: 0.0, b: 0.0 };
147
- *
148
- * // Pure white
149
- * const white: Rgb = { r: 1.0, g: 1.0, b: 1.0 };
150
- *
151
- * // Orange
152
- * const orange: Rgb = { r: 1.0, g: 0.5, b: 0.0 };
153
- * ```
154
- */
155
- export type Rgb = {
156
- /** Red channel (0.0 to 1.0) */
157
- r?: number;
158
- /** Green channel (0.0 to 1.0) */
159
- g?: number;
160
- /** Blue channel (0.0 to 1.0) */
161
- b?: number;
162
- };
163
- /**
164
- * Defines a color range for random particle colors.
165
- * Each particle will receive a random color between min and max on emission.
166
- *
167
- * @example
168
- * ```typescript
169
- * // Random colors between red and yellow
170
- * const fireColors: MinMaxColor = {
171
- * min: { r: 1.0, g: 0.0, b: 0.0 }, // Red
172
- * max: { r: 1.0, g: 1.0, b: 0.0 } // Yellow
173
- * };
174
- *
175
- * // Fixed white color (no randomness)
176
- * const white: MinMaxColor = {
177
- * min: { r: 1.0, g: 1.0, b: 1.0 },
178
- * max: { r: 1.0, g: 1.0, b: 1.0 }
179
- * };
180
- * ```
181
- */
182
- export type MinMaxColor = {
183
- /** Minimum color values (lower bound for random selection) */
184
- min?: Rgb;
185
- /** Maximum color values (upper bound for random selection) */
186
- max?: Rgb;
187
- };
188
- /**
189
- * Defines a burst emission event that emits a specific number of particles at a given time.
190
- * Bursts are useful for explosions, impacts, fireworks, and other instantaneous particle effects.
191
- *
192
- * @property time - The time (in seconds) after the particle system starts when this burst should occur.
193
- * @property count - The number of particles to emit. Can be a constant or a random range.
194
- * @property cycles - The number of times this burst should repeat. Defaults to 1 (single burst).
195
- * @property interval - The time interval (in seconds) between burst cycles. Only used when cycles > 1.
196
- * @property probability - The probability (0.0 to 1.0) that this burst will occur. Defaults to 1.0.
197
- *
198
- * @example
199
- * // Simple burst at start
200
- * { time: 0, count: 50 }
201
- *
202
- * // Random count burst at 1 second
203
- * { time: 1, count: { min: 20, max: 30 } }
204
- *
205
- * // Repeating burst with interval
206
- * { time: 0.5, count: 10, cycles: 3, interval: 0.2 }
207
- * // Emits at 0.5s, 0.7s, 0.9s
208
- *
209
- * // Probabilistic burst (50% chance)
210
- * { time: 2, count: 100, probability: 0.5 }
211
- */
212
- export type Burst = {
213
- /** Time in seconds when the burst should occur */
214
- time: number;
215
- /** Number of particles to emit (constant or random range) */
216
- count: Constant | RandomBetweenTwoConstants;
217
- /** Number of times to repeat this burst. Defaults to 1. */
218
- cycles?: number;
219
- /** Time interval in seconds between burst cycles. Defaults to 0. */
220
- interval?: number;
221
- /** Probability (0-1) that this burst will occur. Defaults to 1. */
222
- probability?: number;
223
- };
224
- /**
225
- * Defines the emission behavior of the particles.
226
- * Supports rates defined over time or distance using constant values, random ranges, or curves (Bézier or easing).
227
- * Also supports burst emissions for instantaneous particle effects.
228
- *
229
- * @default
230
- * rateOverTime: 10.0
231
- * rateOverDistance: 0.0
232
- * bursts: []
233
- *
234
- * @example
235
- * // Rate over time as a constant value
236
- * rateOverTime: 10;
237
- *
238
- * // Rate over time as a random range
239
- * rateOverTime: { min: 5, max: 15 };
240
- *
241
- * // Rate over time using a Bézier curve
242
- * rateOverTime: {
243
- * type: 'bezier',
244
- * bezierPoints: [
245
- * { x: 0, y: 0, percentage: 0 },
246
- * { x: 0.5, y: 50 },
247
- * { x: 1, y: 100, percentage: 1 }
248
- * ],
249
- * scale: 1
250
- * };
251
- *
252
- * // Rate over distance as a constant value
253
- * rateOverDistance: 2;
254
- *
255
- * // Rate over distance as a random range
256
- * rateOverDistance: { min: 1, max: 3 };
257
- *
258
- * // Rate over distance using an easing curve
259
- * rateOverDistance: {
260
- * type: 'easing',
261
- * curveFunction: (distance) => Math.sin(distance),
262
- * scale: 0.5
263
- * };
264
- *
265
- * // Burst emissions for explosions
266
- * bursts: [
267
- * { time: 0, count: 50 },
268
- * { time: 1, count: { min: 20, max: 30 }, probability: 0.8 },
269
- * { time: 0.5, count: 10, cycles: 3, interval: 0.2 }
270
- * ];
271
- */
272
- export type Emission = {
273
- rateOverTime?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
274
- rateOverDistance?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
275
- /** Array of burst configurations for instantaneous particle emissions */
276
- bursts?: Array<Burst>;
277
- };
278
- /**
279
- * Configuration for a sphere shape used in particle systems.
280
- *
281
- * @property radius - The radius of the sphere.
282
- * @property radiusThickness - The thickness of the sphere's shell (0 to 1, where 1 is solid).
283
- * @property arc - The angular arc of the sphere (in radians).
284
- *
285
- * @example
286
- * const sphere: Sphere = {
287
- * radius: 5,
288
- * radiusThickness: 0.8,
289
- * arc: Math.PI,
290
- * };
291
- */
292
- export type Sphere = {
293
- radius?: number;
294
- radiusThickness?: number;
295
- arc?: number;
296
- };
297
- /**
298
- * Configuration for a cone shape used in particle systems.
299
- *
300
- * @property angle - The angle of the cone (in radians).
301
- * @property radius - The radius of the cone's base.
302
- * @property radiusThickness - The thickness of the cone's base (0 to 1, where 1 is solid).
303
- * @property arc - The angular arc of the cone's base (in radians).
304
- *
305
- * @example
306
- * const cone: Cone = {
307
- * angle: Math.PI / 4,
308
- * radius: 10,
309
- * radiusThickness: 0.5,
310
- * arc: Math.PI * 2,
311
- * };
312
- */
313
- export type Cone = {
314
- angle?: number;
315
- radius?: number;
316
- radiusThickness?: number;
317
- arc?: number;
318
- };
319
- /**
320
- * Configuration for a circle shape used in particle systems.
321
- *
322
- * @property radius - The radius of the circle.
323
- * @property radiusThickness - The thickness of the circle's shell (0 to 1, where 1 is solid).
324
- * @property arc - The angular arc of the circle (in radians).
325
- *
326
- * @example
327
- * const circle: Circle = {
328
- * radius: 10,
329
- * radiusThickness: 0.5,
330
- * arc: Math.PI,
331
- * };
332
- */
333
- export type Circle = {
334
- radius?: number;
335
- radiusThickness?: number;
336
- arc?: number;
337
- };
338
- /**
339
- * Configuration for a rectangle shape used in particle systems.
340
- *
341
- * @property rotation - The rotation of the rectangle as a 3D point (in radians for each axis).
342
- * @property scale - The scale of the rectangle as a 3D point.
343
- *
344
- * @example
345
- * const rectangle: Rectangle = {
346
- * rotation: { x: Math.PI / 4, y: 0, z: 0 },
347
- * scale: { x: 10, y: 5, z: 1 },
348
- * };
349
- */
350
- export type Rectangle = {
351
- rotation?: Point3D;
352
- scale?: Point3D;
353
- };
354
- /**
355
- * Configuration for a box shape used in particle systems.
356
- *
357
- * @property scale - The scale of the box as a 3D point.
358
- * @property emitFrom - Specifies where particles are emitted from within the box.
359
- *
360
- * @example
361
- * const box: Box = {
362
- * scale: { x: 10, y: 10, z: 10 },
363
- * emitFrom: EmitFrom.EDGE,
364
- * };
365
- */
366
- export type Box = {
367
- scale?: Point3D;
368
- emitFrom?: EmitFrom;
369
- };
370
- /**
371
- * Configuration for defining a 3D shape used in particle systems.
372
- * Specifies the shape type and its parameters, including spheres, cones, circles, rectangles, and boxes.
373
- *
374
- * @property shape - The type of the shape to be used.
375
- * @property sphere - Configuration for a sphere shape.
376
- * @property cone - Configuration for a cone shape.
377
- * @property circle - Configuration for a circle shape.
378
- * @property rectangle - Configuration for a rectangle shape.
379
- * @property box - Configuration for a box shape.
380
- *
381
- * @example
382
- * const shapeConfig: ShapeConfig = {
383
- * shape: Shape.SPHERE,
384
- * sphere: {
385
- * radius: 5,
386
- * radiusThickness: 0.8,
387
- * arc: Math.PI,
388
- * },
389
- * };
390
- */
391
- export type ShapeConfig = {
392
- shape?: Shape;
393
- sphere?: Sphere;
394
- cone?: Cone;
395
- circle?: Circle;
396
- rectangle?: Rectangle;
397
- box?: Box;
398
- };
399
- /**
400
- * Defines the texture sheet animation settings for particles.
401
- * Allows configuring the animation frames, timing mode, frames per second, and the starting frame.
402
- *
403
- * @default
404
- * tiles: new THREE.Vector2(1.0, 1.0)
405
- * timeMode: TimeMode.LIFETIME
406
- * fps: 30.0
407
- * startFrame: 0
408
- *
409
- * @example
410
- * // Basic configuration with default values
411
- * textureSheetAnimation: {
412
- * tiles: new THREE.Vector2(1.0, 1.0),
413
- * timeMode: TimeMode.LIFETIME,
414
- * fps: 30.0,
415
- * startFrame: 0
416
- * };
417
- *
418
- * // Custom configuration
419
- * textureSheetAnimation: {
420
- * tiles: new THREE.Vector2(4, 4), // 4x4 grid of animation tiles
421
- * timeMode: TimeMode.SPEED,
422
- * fps: 60.0,
423
- * startFrame: { min: 0, max: 15 } // Random start frame between 0 and 15
424
- * };
425
- */
426
- export type TextureSheetAnimation = {
427
- tiles?: THREE.Vector2;
428
- timeMode?: TimeMode;
429
- fps?: number;
430
- startFrame?: Constant | RandomBetweenTwoConstants;
431
- };
432
- /**
433
- * Configuration for the particle system renderer, controlling blending, transparency, depth, and background color behavior.
434
- *
435
- * @property blending - Defines the blending mode for the particle system (e.g., additive blending).
436
- * @property discardBackgroundColor - Whether to discard particles that match the background color.
437
- * @property backgroundColorTolerance - The tolerance for matching the background color when `discardBackgroundColor` is true.
438
- * @property backgroundColor - The background color as an RGB value, used when `discardBackgroundColor` is enabled.
439
- * @property transparent - Whether the particle system uses transparency.
440
- * @property depthTest - Whether to enable depth testing for particles (determines if particles are rendered behind or in front of other objects).
441
- * @property depthWrite - Whether to write depth information for the particles (affects sorting and rendering order).
442
- *
443
- * @example
444
- * // A renderer configuration with additive blending and transparent particles
445
- * const renderer: Renderer = {
446
- * blending: THREE.AdditiveBlending,
447
- * discardBackgroundColor: true,
448
- * backgroundColorTolerance: 0.1,
449
- * backgroundColor: { r: 0, g: 0, b: 0 },
450
- * transparent: true,
451
- * depthTest: true,
452
- * depthWrite: false,
453
- * };
454
- *
455
- * @default
456
- * // Default values for the renderer configuration
457
- * const renderer: Renderer = {
458
- * blending: THREE.NormalBlending,
459
- * discardBackgroundColor: false,
460
- * backgroundColorTolerance: 1.0,
461
- * backgroundColor: { r: 0, g: 0, b: 0 },
462
- * transparent: false,
463
- * depthTest: true,
464
- * depthWrite: true,
465
- * };
466
- */
467
- export type Renderer = {
468
- blending: THREE.Blending;
469
- discardBackgroundColor: boolean;
470
- backgroundColorTolerance: number;
471
- backgroundColor: Rgb;
472
- transparent: boolean;
473
- depthTest: boolean;
474
- depthWrite: boolean;
475
- };
476
- /**
477
- * Configuration for noise effects applied to particles in a particle system.
478
- * Noise can affect particle position, rotation, and size dynamically.
479
- *
480
- * @property isActive - Whether noise is enabled for the particle system.
481
- * @property strength - The overall strength of the noise effect.
482
- * @property positionAmount - The amount of noise applied to particle positions.
483
- * @property rotationAmount - The amount of noise applied to particle rotations.
484
- * @property sizeAmount - The amount of noise applied to particle sizes.
485
- * @property sampler - An optional noise sampler (e.g., FBM for fractal Brownian motion) to generate noise values.
486
- * @property offsets - An optional array of offsets to randomize noise generation per particle.
487
- *
488
- * @example
489
- * // A noise configuration with position and rotation noise
490
- * const noise: Noise = {
491
- * isActive: true,
492
- * strength: 0.5,
493
- * positionAmount: 1.0,
494
- * rotationAmount: 0.3,
495
- * sizeAmount: 0.0,
496
- * sampler: new FBM(),
497
- * offsets: [0.1, 0.2, 0.3],
498
- * };
499
- *
500
- * @default
501
- * // Default values for noise configuration
502
- * const noise: Noise = {
503
- * isActive: false,
504
- * strength: 1.0,
505
- * positionAmount: 0.0,
506
- * rotationAmount: 0.0,
507
- * sizeAmount: 0.0,
508
- * sampler: undefined,
509
- * offsets: undefined,
510
- * };
511
- */
512
- export type Noise = {
513
- isActive: boolean;
514
- strength: number;
515
- noisePower: number;
516
- positionAmount: number;
517
- rotationAmount: number;
518
- sizeAmount: number;
519
- sampler?: FBM;
520
- offsets?: Array<number>;
521
- };
522
- export type NoiseConfig = {
523
- isActive: boolean;
524
- useRandomOffset: boolean;
525
- strength: number;
526
- frequency: number;
527
- octaves: number;
528
- positionAmount: number;
529
- rotationAmount: number;
530
- sizeAmount: number;
531
- };
532
- /**
533
- * Defines the velocity of particles over their lifetime, allowing for linear and orbital velocity (in degrees) adjustments.
534
- * Supports constant values, random ranges, or curves (Bézier or easing) for each axis.
535
- *
536
- * @default
537
- * isActive: false
538
- * linear: { x: 0.0, y: 0.0, z: 0.0 }
539
- * orbital: { x: 0.0, y: 0.0, z: 0.0 }
540
- *
541
- * @example
542
- * // Linear velocity with a constant value
543
- * linear: { x: 1, y: 0, z: -0.5 };
544
- *
545
- * // Linear velocity with random ranges
546
- * linear: {
547
- * x: { min: -1, max: 1 },
548
- * y: { min: 0, max: 2 }
549
- * };
550
- *
551
- * // Linear velocity using a Bézier curve
552
- * linear: {
553
- * z: {
554
- * type: 'bezier',
555
- * bezierPoints: [
556
- * { x: 0, y: 0, percentage: 0 },
557
- * { x: 0.5, y: 2 },
558
- * { x: 1, y: 10, percentage: 1 }
559
- * ],
560
- * scale: 2
561
- * }
562
- * };
563
- *
564
- * // Orbital velocity with a constant value
565
- * orbital: { x: 3, y: 5, z: 0 };
566
- *
567
- * // Orbital velocity using an easing curve
568
- * orbital: {
569
- * x: {
570
- * type: 'easing',
571
- * curveFunction: (time) => Math.sin(time * Math.PI),
572
- * scale: 1.5
573
- * }
574
- * };
575
- */
576
- export type VelocityOverLifetime = {
577
- isActive: boolean;
578
- linear: {
579
- x?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
580
- y?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
581
- z?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
582
- };
583
- orbital: {
584
- x?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
585
- y?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
586
- z?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
587
- };
588
- };
589
- /**
590
- * Configuration object for the particle system.
591
- * Defines all aspects of the particle system, including its appearance, behavior, and runtime events.
592
- */
593
- export type ParticleSystemConfig = {
594
- /**
595
- * Defines the position, rotation, and scale of the particle system.
596
- *
597
- * @see Transform
598
- * @default
599
- * transform: {
600
- * position: new THREE.Vector3(),
601
- * rotation: new THREE.Vector3(),
602
- * scale: new THREE.Vector3(1, 1, 1),
603
- * }
604
- */
605
- transform?: Transform;
606
- /**
607
- * Duration of the particle system in seconds.
608
- * Must be a positive value.
609
- * @default 5.0
610
- * @example
611
- * const duration: number = 5; // System runs for 5 seconds.
612
- */
613
- duration?: number;
614
- /**
615
- * Indicates whether the system should loop after finishing.
616
- * @default true
617
- * @example
618
- * looping: true; // System loops continuously.
619
- */
620
- looping?: boolean;
621
- /**
622
- * Delay before the particle system starts emitting particles.
623
- * Supports a fixed value (`Constant`) or a random range (`RandomBetweenTwoConstants`).
624
- * @default 0.0
625
- * @example
626
- * startDelay: 2; // Fixed 2-second delay.
627
- * startDelay: { min: 0.5, max: 2 }; // Random delay between 0.5 and 2 seconds.
628
- */
629
- startDelay?: Constant | RandomBetweenTwoConstants;
630
- /**
631
- * Initial lifetime of the particles.
632
- * Supports constant value, random range, or curves (Bézier or easing).
633
- * @default 5.0
634
- * @example
635
- * // Constant 3 seconds.
636
- * startLifetime: 3;
637
- *
638
- * // Random range between 1 and 4 seconds.
639
- * startLifetime: { min: 1, max: 4 };
640
- *
641
- * // Bézier curve example with scaling.
642
- * startLifetime: {
643
- * type: LifeTimeCurve.BEZIER,
644
- * bezierPoints: [
645
- * { x: 0, y: 0.275, percentage: 0 },
646
- * { x: 0.5, y: 0.5 },
647
- * { x: 1, y: 1, percentage: 1 }
648
- * ],
649
- * scale: 2
650
- * };
651
- *
652
- * // Easing curve example with scaling.
653
- * startLifetime: {
654
- * type: LifeTimeCurve.EASING,
655
- * curveFunction: (time) => Math.sin(time * Math.PI),
656
- * scale: 0.5
657
- * };
658
- */
659
- startLifetime?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
660
- /**
661
- * Defines the initial speed of the particles.
662
- * Supports constant values, random ranges, or curves (Bézier or easing).
663
- * @default 1.0
664
- * @example
665
- * // Constant value
666
- * startSpeed: 3;
667
- *
668
- * // Random range
669
- * startSpeed: { min: 1, max: 4 };
670
- *
671
- * // Bézier curve example with scaling.
672
- * startSpeed: {
673
- * type: 'bezier',
674
- * bezierPoints: [
675
- * { x: 0, y: 0.275, percentage: 0 },
676
- * { x: 0.5, y: 0.5 },
677
- * { x: 1, y: 1, percentage: 1 }
678
- * ],
679
- * scale: 2
680
- * };
681
- *
682
- * // Easing curve example with scaling.
683
- * startSpeed: {
684
- * type: 'easing',
685
- * curveFunction: (time) => Math.sin(time * Math.PI),
686
- * scale: 1.5
687
- * };
688
- */
689
- startSpeed?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
690
- /**
691
- * Defines the initial size of the particles.
692
- * Supports constant values, random ranges, or curves (Bézier or easing).
693
- * @default 1.0
694
- * @example
695
- * // Constant value
696
- * startSize: 3;
697
- *
698
- * // Random range
699
- * startSize: { min: 1, max: 4 };
700
- *
701
- * // Bézier curve example with scaling.
702
- * startSize: {
703
- * type: 'bezier',
704
- * bezierPoints: [
705
- * { x: 0, y: 0.275, percentage: 0 },
706
- * { x: 0.5, y: 0.5 },
707
- * { x: 1, y: 1, percentage: 1 }
708
- * ],
709
- * scale: 2
710
- * };
711
- *
712
- * // Easing curve example with scaling.
713
- * startSize: {
714
- * type: 'easing',
715
- * curveFunction: (time) => Math.sin(time * Math.PI),
716
- * scale: 1.5
717
- * };
718
- */
719
- startSize?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
720
- /**
721
- * Defines the initial opacity of the particles.
722
- * Supports constant values, random ranges, or curves (Bézier or easing).
723
- * @default 1.0
724
- * @example
725
- * // Constant value
726
- * startOpacity: 3;
727
- *
728
- * // Random range
729
- * startOpacity: { min: 1, max: 4 };
730
- *
731
- * // Bézier curve example with scaling.
732
- * startOpacity: {
733
- * type: 'bezier',
734
- * bezierPoints: [
735
- * { x: 0, y: 0.275, percentage: 0 },
736
- * { x: 0.5, y: 0.5 },
737
- * { x: 1, y: 1, percentage: 1 }
738
- * ],
739
- * scale: 2
740
- * };
741
- *
742
- * // Easing curve example with scaling.
743
- * startOpacity: {
744
- * type: 'easing',
745
- * curveFunction: (time) => Math.sin(time * Math.PI),
746
- * scale: 1.5
747
- * };
748
- */
749
- startOpacity?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
750
- /**
751
- * Defines the initial rotation of the particles in degrees.
752
- * Supports constant values, random ranges, or curves (Bézier or easing).
753
- * @default 0.0
754
- * @example
755
- * // Constant value
756
- * startRotation: 3;
757
- *
758
- * // Random range
759
- * startRotation: { min: 1, max: 4 };
760
- *
761
- * // Bézier curve example with scaling.
762
- * startRotation: {
763
- * type: 'bezier',
764
- * bezierPoints: [
765
- * { x: 0, y: 0.275, percentage: 0 },
766
- * { x: 0.5, y: 0.5 },
767
- * { x: 1, y: 1, percentage: 1 }
768
- * ],
769
- * scale: 2
770
- * };
771
- *
772
- * // Easing curve example with scaling.
773
- * startRotation: {
774
- * type: 'easing',
775
- * curveFunction: (time) => Math.sin(time * Math.PI),
776
- * scale: 1.5
777
- * };
778
- */
779
- startRotation?: Constant | RandomBetweenTwoConstants | LifetimeCurve;
780
- /**
781
- * Initial color of the particles.
782
- * Supports a min-max range for color interpolation.
783
- *
784
- * @default
785
- * startColor: {
786
- * min: { r: 1.0, g: 1.0, b: 1.0 },
787
- * max: { r: 1.0, g: 1.0, b: 1.0 },
788
- * }
789
- */
790
- startColor?: MinMaxColor;
791
- /**
792
- * Defines the gravity strength applied to particles.
793
- * This value affects the downward acceleration of particles over time.
794
- *
795
- * @default 0.0
796
- *
797
- * @example
798
- * // No gravity
799
- * gravity: 0;
800
- *
801
- * // Moderate gravity
802
- * gravity: 9.8; // Similar to Earth's gravity
803
- *
804
- * // Strong gravity
805
- * gravity: 20.0;
806
- */
807
- gravity?: Constant;
808
- /**
809
- * Defines the simulation space in which particles are simulated.
810
- * Determines whether the particles move relative to the local object space or the world space.
811
- *
812
- * @default SimulationSpace.LOCAL
813
- *
814
- * @example
815
- * // Simulate particles in local space (default)
816
- * simulationSpace: SimulationSpace.LOCAL;
817
- *
818
- * // Simulate particles in world space
819
- * simulationSpace: SimulationSpace.WORLD;
820
- */
821
- simulationSpace?: SimulationSpace;
822
- /**
823
- * Defines the maximum number of particles allowed in the system.
824
- * This value limits the total number of active particles at any given time.
825
- *
826
- * @default 100.0
827
- *
828
- * @example
829
- * // Default value
830
- * maxParticles: 100.0;
831
- *
832
- * // Increase the maximum number of particles
833
- * maxParticles: 500.0;
834
- *
835
- * // Limit to a small number of particles
836
- * maxParticles: 10.0;
837
- */
838
- maxParticles?: Constant;
839
- /**
840
- * Defines the particle emission settings.
841
- * Configures the emission rate over time and distance.
842
- *
843
- * @see Emission
844
- * @default
845
- * emission: {
846
- * rateOverTime: 10.0,
847
- * rateOverDistance: 0.0,
848
- * }
849
- */
850
- emission?: Emission;
851
- /**
852
- * Configuration for the emitter shape.
853
- * Determines the shape and parameters for particle emission.
854
- *
855
- * @see ShapeConfig
856
- */
857
- shape?: ShapeConfig;
858
- /**
859
- * Defines the texture used for rendering particles.
860
- * This texture is applied to all particles in the system, and can be used to control their appearance.
861
- *
862
- * @default undefined
863
- *
864
- * @example
865
- * // Using a predefined texture
866
- * map: new THREE.TextureLoader().load('path/to/texture.png');
867
- *
868
- * // No texture (default behavior)
869
- * map: undefined;
870
- */
871
- map?: THREE.Texture;
872
- /**
873
- * Renderer configuration for blending, transparency, and depth testing.
874
- *
875
- * @see Renderer
876
- * @default
877
- * renderer: {
878
- * blending: THREE.NormalBlending,
879
- * discardBackgroundColor: false,
880
- * backgroundColorTolerance: 1.0,
881
- * backgroundColor: { r: 1.0, g: 1.0, b: 1.0 },
882
- * transparent: true,
883
- * depthTest: true,
884
- * depthWrite: false
885
- * }
886
- */
887
- renderer?: Renderer;
888
- /**
889
- * Defines the velocity settings of particles over their lifetime.
890
- * Configures both linear and orbital velocity changes.
891
- *
892
- * @see VelocityOverLifetime
893
- * @default
894
- * velocityOverLifetime: {
895
- * isActive: false,
896
- * linear: {
897
- * x: 0,
898
- * y: 0,
899
- * z: 0,
900
- * },
901
- * orbital: {
902
- * x: 0,
903
- * y: 0,
904
- * z: 0,
905
- * },
906
- * }
907
- */
908
- velocityOverLifetime?: VelocityOverLifetime;
909
- /**
910
- * Controls the size of particles over their lifetime.
911
- * The size can be adjusted using a lifetime curve (Bézier or other supported types).
912
- *
913
- * @default
914
- * sizeOverLifetime: {
915
- * isActive: false,
916
- * lifetimeCurve: {
917
- * type: LifeTimeCurve.BEZIER,
918
- * scale: 1,
919
- * bezierPoints: [
920
- * { x: 0, y: 0, percentage: 0 },
921
- * { x: 1, y: 1, percentage: 1 },
922
- * ],
923
- * },
924
- * }
925
- */
926
- sizeOverLifetime?: {
927
- isActive: boolean;
928
- lifetimeCurve: LifetimeCurve;
929
- };
930
- /**
931
- * Controls the opacity of particles over their lifetime.
932
- * The opacity can be adjusted using a lifetime curve (Bézier or other supported types).
933
- *
934
- * @default
935
- * opacityOverLifetime: {
936
- * isActive: false,
937
- * lifetimeCurve: {
938
- * type: LifeTimeCurve.BEZIER,
939
- * scale: 1,
940
- * bezierPoints: [
941
- * { x: 0, y: 0, percentage: 0 },
942
- * { x: 1, y: 1, percentage: 1 },
943
- * ],
944
- * },
945
- * }
946
- */
947
- opacityOverLifetime?: {
948
- isActive: boolean;
949
- lifetimeCurve: LifetimeCurve;
950
- };
951
- /**
952
- * Controls the color of particles over their lifetime.
953
- * Each RGB channel can be adjusted independently using a lifetime curve (Bézier or easing).
954
- * The curves act as multipliers (0-1 range) that are applied to the particle's start color.
955
- *
956
- * This follows Unity's Color over Lifetime behavior where the final color is:
957
- * finalColor = startColor * colorOverLifetime
958
- *
959
- * **IMPORTANT**: To achieve full color transitions, set startColor to white { r: 1, g: 1, b: 1 }.
960
- * If startColor has any channel set to 0, that channel cannot be modified by colorOverLifetime.
961
- *
962
- * @example
963
- * // Rainbow effect - requires white startColor
964
- * startColor: { min: { r: 1, g: 1, b: 1 }, max: { r: 1, g: 1, b: 1 } }
965
- * colorOverLifetime: {
966
- * isActive: true,
967
- * r: { // Red: full -> half -> off
968
- * type: LifeTimeCurve.BEZIER,
969
- * scale: 1,
970
- * bezierPoints: [
971
- * { x: 0, y: 1, percentage: 0 },
972
- * { x: 0.5, y: 0.5, percentage: 0.5 },
973
- * { x: 1, y: 0, percentage: 1 },
974
- * ],
975
- * },
976
- * g: { // Green: off -> full -> off
977
- * type: LifeTimeCurve.BEZIER,
978
- * scale: 1,
979
- * bezierPoints: [
980
- * { x: 0, y: 0, percentage: 0 },
981
- * { x: 0.5, y: 1, percentage: 0.5 },
982
- * { x: 1, y: 0, percentage: 1 },
983
- * ],
984
- * },
985
- * b: { // Blue: off -> half -> full
986
- * type: LifeTimeCurve.BEZIER,
987
- * scale: 1,
988
- * bezierPoints: [
989
- * { x: 0, y: 0, percentage: 0 },
990
- * { x: 0.5, y: 0.5, percentage: 0.5 },
991
- * { x: 1, y: 1, percentage: 1 },
992
- * ],
993
- * },
994
- * }
995
- *
996
- * @default
997
- * colorOverLifetime: {
998
- * isActive: false,
999
- * r: {
1000
- * type: LifeTimeCurve.BEZIER,
1001
- * scale: 1,
1002
- * bezierPoints: [
1003
- * { x: 0, y: 1, percentage: 0 },
1004
- * { x: 1, y: 1, percentage: 1 },
1005
- * ],
1006
- * },
1007
- * g: {
1008
- * type: LifeTimeCurve.BEZIER,
1009
- * scale: 1,
1010
- * bezierPoints: [
1011
- * { x: 0, y: 1, percentage: 0 },
1012
- * { x: 1, y: 1, percentage: 1 },
1013
- * ],
1014
- * },
1015
- * b: {
1016
- * type: LifeTimeCurve.BEZIER,
1017
- * scale: 1,
1018
- * bezierPoints: [
1019
- * { x: 0, y: 1, percentage: 0 },
1020
- * { x: 1, y: 1, percentage: 1 },
1021
- * ],
1022
- * },
1023
- * }
1024
- */
1025
- colorOverLifetime?: {
1026
- isActive: boolean;
1027
- r: LifetimeCurve;
1028
- g: LifetimeCurve;
1029
- b: LifetimeCurve;
1030
- };
1031
- /**
1032
- * Controls the rotation of particles over their lifetime.
1033
- * The rotation can be randomized between two constants, and the feature can be toggled on or off.
1034
- *
1035
- * @default
1036
- * rotationOverLifetime: {
1037
- * isActive: false,
1038
- * min: 0.0,
1039
- * max: 0.0,
1040
- * }
1041
- */
1042
- rotationOverLifetime?: {
1043
- isActive: boolean;
1044
- } & RandomBetweenTwoConstants;
1045
- /**
1046
- * Noise configuration affecting position, rotation, and size.
1047
- *
1048
- * @see NoiseConfig
1049
- * @default
1050
- * noise: {
1051
- * isActive: false,
1052
- * useRandomOffset: false,
1053
- * strength: 1.0,
1054
- * frequency: 0.5,
1055
- * octaves: 1,
1056
- * positionAmount: 1.0,
1057
- * rotationAmount: 0.0,
1058
- * sizeAmount: 0.0,
1059
- * }
1060
- */
1061
- noise?: NoiseConfig;
1062
- /**
1063
- * Configures the texture sheet animation settings for particles.
1064
- * Controls how textures are animated over the lifetime of particles.
1065
- *
1066
- * @see TextureSheetAnimation
1067
- * @default
1068
- * textureSheetAnimation: {
1069
- * tiles: new THREE.Vector2(1.0, 1.0),
1070
- * timeMode: TimeMode.LIFETIME,
1071
- * fps: 30.0,
1072
- * startFrame: 0,
1073
- * }
1074
- */
1075
- textureSheetAnimation?: TextureSheetAnimation;
1076
- /**
1077
- * Called on every update frame with particle system data.
1078
- */
1079
- onUpdate?: (data: {
1080
- particleSystem: THREE.Points;
1081
- delta: number;
1082
- elapsed: number;
1083
- lifetime: number;
1084
- iterationCount: number;
1085
- }) => void;
1086
- /**
1087
- * Called when the system completes an iteration.
1088
- */
1089
- onComplete?: () => void;
1090
- };
1091
- export type NormalizedParticleSystemConfig = Required<ParticleSystemConfig>;
1092
- /**
1093
- * Tracks the state of a burst emission event.
1094
- * Used internally to determine when bursts should fire and how many cycles remain.
1095
- */
1096
- export type BurstState = {
1097
- /** Number of cycles that have been executed so far */
1098
- cyclesExecuted: number;
1099
- /** Time (in ms) when the last cycle was executed */
1100
- lastCycleTime: number;
1101
- /** Whether the probability check passed for this iteration */
1102
- probabilityPassed: boolean;
1103
- };
1104
- export type GeneralData = {
1105
- particleSystemId: number;
1106
- normalizedLifetimePercentage: number;
1107
- creationTimes: Array<number>;
1108
- distanceFromLastEmitByDistance: number;
1109
- lastWorldPosition: THREE.Vector3;
1110
- currentWorldPosition: THREE.Vector3;
1111
- worldPositionChange: THREE.Vector3;
1112
- wrapperQuaternion: THREE.Quaternion;
1113
- lastWorldQuaternion: THREE.Quaternion;
1114
- worldQuaternion: THREE.Quaternion;
1115
- worldEuler: THREE.Euler;
1116
- gravityVelocity: THREE.Vector3;
1117
- startValues: Record<string, Array<number>>;
1118
- linearVelocityData?: Array<{
1119
- speed: THREE.Vector3;
1120
- valueModifiers: {
1121
- x?: CurveFunction;
1122
- y?: CurveFunction;
1123
- z?: CurveFunction;
1124
- };
1125
- }>;
1126
- orbitalVelocityData?: Array<{
1127
- speed: THREE.Vector3;
1128
- positionOffset: THREE.Vector3;
1129
- valueModifiers: {
1130
- x?: CurveFunction;
1131
- y?: CurveFunction;
1132
- z?: CurveFunction;
1133
- };
1134
- }>;
1135
- lifetimeValues: Record<string, Array<number>>;
1136
- noise: Noise;
1137
- isEnabled: boolean;
1138
- /** Tracks the state of each burst emission event */
1139
- burstStates?: Array<BurstState>;
1140
- };
1141
- export type ParticleSystemInstance = {
1142
- particleSystem: THREE.Points;
1143
- wrapper?: Gyroscope;
1144
- elapsedUniform: {
1145
- value: number;
1146
- };
1147
- generalData: GeneralData;
1148
- onUpdate: (data: {
1149
- particleSystem: THREE.Points;
1150
- delta: number;
1151
- elapsed: number;
1152
- lifetime: number;
1153
- normalizedLifetime: number;
1154
- iterationCount: number;
1155
- }) => void;
1156
- onComplete: (data: {
1157
- particleSystem: THREE.Points;
1158
- }) => void;
1159
- creationTime: number;
1160
- lastEmissionTime: number;
1161
- duration: number;
1162
- looping: boolean;
1163
- simulationSpace: SimulationSpace;
1164
- gravity: number;
1165
- emission: Emission;
1166
- normalizedConfig: NormalizedParticleSystemConfig;
1167
- iterationCount: number;
1168
- velocities: Array<THREE.Vector3>;
1169
- freeList: Array<number>;
1170
- deactivateParticle: (particleIndex: number) => void;
1171
- activateParticle: (data: {
1172
- particleIndex: number;
1173
- activationTime: number;
1174
- position: Required<Point3D>;
1175
- }) => void;
1176
- };
1177
- /**
1178
- * Represents a particle system instance, providing methods to control and manage its lifecycle.
1179
- *
1180
- * @property instance - The underlying Three.js `Points` object or a `Gyroscope` used for particle rendering.
1181
- * @property resumeEmitter - Resumes the particle emitter, allowing particles to be emitted again.
1182
- * @property pauseEmitter - Pauses the particle emitter, stopping any new particles from being emitted.
1183
- * @property dispose - Disposes of the particle system, cleaning up resources to free memory.
1184
- *
1185
- * @example
1186
- * const particleSystem: ParticleSystem = {
1187
- * instance: new THREE.Points(geometry, material),
1188
- * resumeEmitter: () => { /* resume logic * / },
1189
- * pauseEmitter: () => { /* pause logic * / },
1190
- * dispose: () => { /* cleanup logic * / },
1191
- * };
1192
- *
1193
- * particleSystem.pauseEmitter(); // Stop particle emission
1194
- * particleSystem.resumeEmitter(); // Resume particle emission
1195
- * particleSystem.dispose(); // Cleanup the particle system
1196
- */
1197
- export type ParticleSystem = {
1198
- instance: THREE.Points | Gyroscope;
1199
- resumeEmitter: () => void;
1200
- pauseEmitter: () => void;
1201
- dispose: () => void;
1202
- update: (cycleData: CycleData) => void;
1203
- };
1204
- /**
1205
- * Data representing the current cycle of the particle system's update loop.
1206
- *
1207
- * @property now - The current timestamp in milliseconds.
1208
- * @property delta - The time elapsed since the last update, in seconds.
1209
- * @property elapsed - The total time elapsed since the particle system started, in seconds.
1210
- *
1211
- * @example
1212
- * const cycleData: CycleData = {
1213
- * now: performance.now(),
1214
- * delta: 0.016, // 16ms frame time
1215
- * elapsed: 1.25, // 1.25 seconds since start
1216
- * };
1217
- */
1218
- export type CycleData = {
1219
- now: number;
1220
- delta: number;
1221
- elapsed: number;
1222
- };
1223
- //# sourceMappingURL=types.d.ts.map