@newkrok/three-particles 2.3.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/llms-full.txt ADDED
@@ -0,0 +1,523 @@
1
+ # @newkrok/three-particles — Full API Reference
2
+
3
+ > Three.js-based high-performance particle system library (v2.5.0)
4
+ > License: MIT | Author: Istvan Krisztian Somoracz
5
+ > Repository: https://github.com/NewKrok/three-particles
6
+
7
+ ---
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @newkrok/three-particles three
13
+ ```
14
+
15
+ Peer dependency: `three` ^0.180.0
16
+
17
+ ---
18
+
19
+ ## Main API
20
+
21
+ ### createParticleSystem(config: ParticleSystemConfig): ParticleSystem
22
+
23
+ Creates a new particle system and registers it for global updates.
24
+
25
+ ```typescript
26
+ import { createParticleSystem } from "@newkrok/three-particles";
27
+
28
+ const system = createParticleSystem({
29
+ duration: 5,
30
+ looping: true,
31
+ maxParticles: 200,
32
+ startLifetime: 3,
33
+ startSpeed: 2,
34
+ startSize: 0.5,
35
+ emission: { rateOverTime: 30 },
36
+ shape: { shape: Shape.CONE, cone: { angle: 0.5, radius: 1 } },
37
+ });
38
+
39
+ scene.add(system.instance);
40
+ ```
41
+
42
+ ### updateParticleSystems(cycleData: CycleData): void
43
+
44
+ Updates all registered particle systems. Call this in your animation loop.
45
+
46
+ ```typescript
47
+ import { updateParticleSystems } from "@newkrok/three-particles";
48
+
49
+ function animate() {
50
+ updateParticleSystems({
51
+ now: performance.now(),
52
+ delta: clock.getDelta(),
53
+ elapsed: clock.getElapsedTime(),
54
+ });
55
+ requestAnimationFrame(animate);
56
+ }
57
+ ```
58
+
59
+ ---
60
+
61
+ ## ParticleSystem (returned object)
62
+
63
+ | Property/Method | Type | Description |
64
+ |-----------------|------|-------------|
65
+ | `instance` | `THREE.Points \| Gyroscope` | The renderable object — add to scene |
66
+ | `pauseEmitter()` | `() => void` | Stop emitting new particles |
67
+ | `resumeEmitter()` | `() => void` | Resume emitting particles |
68
+ | `dispose()` | `() => void` | Destroy system, free resources |
69
+ | `update(cycleData)` | `(CycleData) => void` | Update this system individually |
70
+
71
+ ---
72
+
73
+ ## CycleData
74
+
75
+ ```typescript
76
+ type CycleData = {
77
+ now: number; // Current timestamp in milliseconds (performance.now())
78
+ delta: number; // Time since last frame in seconds
79
+ elapsed: number; // Total elapsed time in seconds
80
+ };
81
+ ```
82
+
83
+ ---
84
+
85
+ ## ParticleSystemConfig — Complete Reference
86
+
87
+ ### General Properties
88
+
89
+ | Property | Type | Default | Description |
90
+ |----------|------|---------|-------------|
91
+ | `transform` | `Transform` | origin | Position, rotation, scale of emitter |
92
+ | `duration` | `number` | 5.0 | System duration in seconds |
93
+ | `looping` | `boolean` | true | Loop after duration ends |
94
+ | `startDelay` | `number \| {min,max}` | 0.0 | Delay before first emission |
95
+ | `maxParticles` | `number` | 100 | Maximum concurrent particles |
96
+ | `gravity` | `number` | 0.0 | Downward acceleration |
97
+ | `simulationSpace` | `SimulationSpace` | LOCAL | LOCAL or WORLD coordinate space |
98
+
99
+ ### Start Properties
100
+
101
+ All start properties support three value types:
102
+ - **Constant**: `number` — fixed value
103
+ - **Random range**: `{ min: number, max: number }` — random between min and max
104
+ - **Curve**: `BezierCurve | EasingCurve` — value based on system lifetime
105
+
106
+ | Property | Default | Description |
107
+ |----------|---------|-------------|
108
+ | `startLifetime` | 5.0 | Particle lifetime in seconds |
109
+ | `startSpeed` | 1.0 | Initial particle speed |
110
+ | `startSize` | 1.0 | Initial particle size |
111
+ | `startOpacity` | 1.0 | Initial particle opacity (0-1) |
112
+ | `startRotation` | 0.0 | Initial rotation in degrees |
113
+ | `startColor` | white | `MinMaxColor` — color range for randomization |
114
+
115
+ ### startColor — MinMaxColor
116
+
117
+ ```typescript
118
+ type MinMaxColor = {
119
+ min?: Rgb; // { r?: number, g?: number, b?: number } — values 0.0 to 1.0
120
+ max?: Rgb;
121
+ };
122
+
123
+ // Example: random orange-to-yellow
124
+ startColor: {
125
+ min: { r: 1.0, g: 0.3, b: 0.0 },
126
+ max: { r: 1.0, g: 1.0, b: 0.0 },
127
+ }
128
+ ```
129
+
130
+ ---
131
+
132
+ ## Transform
133
+
134
+ ```typescript
135
+ type Transform = {
136
+ position?: THREE.Vector3;
137
+ rotation?: THREE.Vector3; // Radians per axis
138
+ scale?: THREE.Vector3;
139
+ };
140
+ ```
141
+
142
+ ---
143
+
144
+ ## Emission
145
+
146
+ ```typescript
147
+ type Emission = {
148
+ rateOverTime?: number | { min, max } | LifetimeCurve; // Particles per second (default: 10)
149
+ rateOverDistance?: number | { min, max } | LifetimeCurve; // Particles per unit moved (default: 0)
150
+ bursts?: Burst[]; // Instantaneous emissions
151
+ };
152
+ ```
153
+
154
+ ### Burst
155
+
156
+ ```typescript
157
+ type Burst = {
158
+ time: number; // Trigger time in seconds
159
+ count: number | { min: number, max: number }; // Particle count
160
+ cycles?: number; // Repeat count (default: 1)
161
+ interval?: number; // Seconds between cycles
162
+ probability?: number; // 0-1 chance of firing (default: 1)
163
+ };
164
+ ```
165
+
166
+ **Example — explosion with aftershocks:**
167
+ ```typescript
168
+ emission: {
169
+ rateOverTime: 0,
170
+ bursts: [
171
+ { time: 0, count: 100 }, // Main explosion
172
+ { time: 0.3, count: { min: 20, max: 40 } }, // First aftershock
173
+ { time: 0.5, count: 15, cycles: 4, interval: 0.1 }, // Debris pulses
174
+ ],
175
+ }
176
+ ```
177
+
178
+ ---
179
+
180
+ ## Shape Configuration
181
+
182
+ ```typescript
183
+ type ShapeConfig = {
184
+ shape?: Shape; // SPHERE | CONE | CIRCLE | RECTANGLE | BOX
185
+ sphere?: Sphere;
186
+ cone?: Cone;
187
+ circle?: Circle;
188
+ rectangle?: Rectangle;
189
+ box?: Box;
190
+ };
191
+ ```
192
+
193
+ ### Shape.SPHERE
194
+
195
+ ```typescript
196
+ type Sphere = {
197
+ radius?: number; // Default: 1
198
+ radiusThickness?: number; // 0-1, where 1 = solid sphere (default: 1)
199
+ arc?: number; // Radians, partial sphere (default: 2π)
200
+ };
201
+ ```
202
+
203
+ ### Shape.CONE
204
+
205
+ ```typescript
206
+ type Cone = {
207
+ angle?: number; // Cone angle in radians (default: ~0.44)
208
+ radius?: number; // Base radius (default: 1)
209
+ radiusThickness?: number; // 0-1 (default: 1)
210
+ arc?: number; // Radians (default: 2π)
211
+ };
212
+ ```
213
+
214
+ ### Shape.CIRCLE
215
+
216
+ ```typescript
217
+ type Circle = {
218
+ radius?: number; // Default: 1
219
+ radiusThickness?: number; // 0-1 (default: 1)
220
+ arc?: number; // Radians (default: 2π)
221
+ };
222
+ ```
223
+
224
+ ### Shape.RECTANGLE
225
+
226
+ ```typescript
227
+ type Rectangle = {
228
+ rotation?: Point3D; // { x?, y?, z? } in radians
229
+ scale?: Point3D; // { x?, y?, z? } dimensions
230
+ };
231
+ ```
232
+
233
+ ### Shape.BOX
234
+
235
+ ```typescript
236
+ type Box = {
237
+ scale?: Point3D; // { x?, y?, z? } dimensions
238
+ emitFrom?: EmitFrom; // VOLUME | SHELL | EDGE
239
+ };
240
+ ```
241
+
242
+ ---
243
+
244
+ ## Lifetime Modifiers
245
+
246
+ ### velocityOverLifetime
247
+
248
+ Modifies particle velocity over its lifetime. Supports linear (directional) and orbital (rotational) velocity.
249
+
250
+ ```typescript
251
+ type VelocityOverLifetime = {
252
+ isActive: boolean;
253
+ linear: {
254
+ x?: number | { min, max } | LifetimeCurve;
255
+ y?: number | { min, max } | LifetimeCurve;
256
+ z?: number | { min, max } | LifetimeCurve;
257
+ };
258
+ orbital: { // Values in degrees
259
+ x?: number | { min, max } | LifetimeCurve;
260
+ y?: number | { min, max } | LifetimeCurve;
261
+ z?: number | { min, max } | LifetimeCurve;
262
+ };
263
+ };
264
+ ```
265
+
266
+ ### sizeOverLifetime
267
+
268
+ ```typescript
269
+ sizeOverLifetime: {
270
+ isActive: boolean;
271
+ lifetimeCurve: LifetimeCurve; // Multiplier on startSize
272
+ }
273
+ ```
274
+
275
+ ### opacityOverLifetime
276
+
277
+ ```typescript
278
+ opacityOverLifetime: {
279
+ isActive: boolean;
280
+ lifetimeCurve: LifetimeCurve; // Multiplier on startOpacity
281
+ }
282
+ ```
283
+
284
+ ### colorOverLifetime
285
+
286
+ Each RGB channel is a separate curve acting as a multiplier (0-1) on startColor.
287
+ **Important**: Set startColor to white `{ r:1, g:1, b:1 }` for full color transitions.
288
+
289
+ ```typescript
290
+ colorOverLifetime: {
291
+ isActive: boolean;
292
+ r: LifetimeCurve;
293
+ g: LifetimeCurve;
294
+ b: LifetimeCurve;
295
+ }
296
+ ```
297
+
298
+ ### rotationOverLifetime
299
+
300
+ ```typescript
301
+ rotationOverLifetime: {
302
+ isActive: boolean;
303
+ min?: number; // Minimum rotation speed
304
+ max?: number; // Maximum rotation speed
305
+ }
306
+ ```
307
+
308
+ ---
309
+
310
+ ## Noise
311
+
312
+ FBM (Fractal Brownian Motion) noise affecting particles dynamically.
313
+
314
+ ```typescript
315
+ type NoiseConfig = {
316
+ isActive: boolean;
317
+ useRandomOffset: boolean; // Randomize noise per particle
318
+ strength: number; // Overall noise strength (default: 1)
319
+ frequency: number; // Noise frequency (default: 0.5)
320
+ octaves: number; // FBM octaves (default: 1)
321
+ positionAmount: number; // Position displacement (default: 1)
322
+ rotationAmount: number; // Rotation displacement (default: 0)
323
+ sizeAmount: number; // Size displacement (default: 0)
324
+ };
325
+ ```
326
+
327
+ ---
328
+
329
+ ## Renderer
330
+
331
+ ```typescript
332
+ type Renderer = {
333
+ blending: THREE.Blending; // Default: NormalBlending
334
+ discardBackgroundColor: boolean; // Default: false
335
+ backgroundColorTolerance: number; // Default: 1.0
336
+ backgroundColor: Rgb; // Default: { r:0, g:0, b:0 }
337
+ transparent: boolean; // Default: true
338
+ depthTest: boolean; // Default: true
339
+ depthWrite: boolean; // Default: false
340
+ };
341
+ ```
342
+
343
+ Common blending modes: `THREE.NormalBlending`, `THREE.AdditiveBlending`, `THREE.SubtractiveBlending`
344
+
345
+ ---
346
+
347
+ ## Texture Sheet Animation
348
+
349
+ Animate sprite sheets over particle lifetime.
350
+
351
+ ```typescript
352
+ type TextureSheetAnimation = {
353
+ tiles?: THREE.Vector2; // Grid dimensions (default: 1x1)
354
+ timeMode?: TimeMode; // LIFETIME or FPS (default: LIFETIME)
355
+ fps?: number; // Frames per second (default: 30)
356
+ startFrame?: number | { min, max }; // Starting frame (default: 0)
357
+ };
358
+ ```
359
+
360
+ ---
361
+
362
+ ## Texture (map)
363
+
364
+ ```typescript
365
+ const texture = new THREE.TextureLoader().load("particle.png");
366
+ const system = createParticleSystem({
367
+ map: texture,
368
+ // ...
369
+ });
370
+ ```
371
+
372
+ ---
373
+
374
+ ## Curve Types
375
+
376
+ ### BezierCurve
377
+
378
+ ```typescript
379
+ {
380
+ type: LifeTimeCurve.BEZIER,
381
+ scale: 1, // Optional multiplier
382
+ bezierPoints: [
383
+ { x: 0, y: 0, percentage: 0 }, // Start point
384
+ { x: 0.3, y: 0.8 }, // Control point
385
+ { x: 0.7, y: 0.2 }, // Control point
386
+ { x: 1, y: 1, percentage: 1 }, // End point
387
+ ],
388
+ }
389
+ ```
390
+
391
+ ### EasingCurve
392
+
393
+ ```typescript
394
+ {
395
+ type: LifeTimeCurve.EASING,
396
+ scale: 1, // Optional multiplier
397
+ curveFunction: (time: number) => number, // 0→1 input, any output
398
+ }
399
+ ```
400
+
401
+ ---
402
+
403
+ ## Enums
404
+
405
+ ### Shape
406
+ `SPHERE` | `CONE` | `CIRCLE` | `RECTANGLE` | `BOX`
407
+
408
+ ### EmitFrom
409
+ `VOLUME` | `SHELL` | `EDGE`
410
+
411
+ ### SimulationSpace
412
+ `LOCAL` | `WORLD`
413
+
414
+ ### TimeMode
415
+ `LIFETIME` | `FPS`
416
+
417
+ ### LifeTimeCurve
418
+ `BEZIER` | `EASING`
419
+
420
+ ---
421
+
422
+ ## Callbacks
423
+
424
+ ```typescript
425
+ createParticleSystem({
426
+ // Called every frame
427
+ onUpdate: ({ particleSystem, delta, elapsed, lifetime, iterationCount }) => {
428
+ // particleSystem: THREE.Points instance
429
+ // delta: seconds since last frame
430
+ // elapsed: total seconds
431
+ // lifetime: system duration
432
+ // iterationCount: number of completed loops
433
+ },
434
+
435
+ // Called when a non-looping system completes, or each loop iteration ends
436
+ onComplete: () => {
437
+ console.log("Particle system iteration complete");
438
+ },
439
+ });
440
+ ```
441
+
442
+ ---
443
+
444
+ ## Complete Example — Fire Effect
445
+
446
+ ```typescript
447
+ import * as THREE from "three";
448
+ import {
449
+ createParticleSystem,
450
+ updateParticleSystems,
451
+ Shape,
452
+ LifeTimeCurve,
453
+ SimulationSpace,
454
+ } from "@newkrok/three-particles";
455
+
456
+ const fireTexture = new THREE.TextureLoader().load("fire-particle.png");
457
+
458
+ const fire = createParticleSystem({
459
+ duration: 5,
460
+ looping: true,
461
+ maxParticles: 200,
462
+ startLifetime: { min: 0.5, max: 1.5 },
463
+ startSpeed: { min: 1, max: 3 },
464
+ startSize: { min: 0.3, max: 0.8 },
465
+ startColor: {
466
+ min: { r: 1.0, g: 0.2, b: 0.0 },
467
+ max: { r: 1.0, g: 0.8, b: 0.0 },
468
+ },
469
+ gravity: -1,
470
+ simulationSpace: SimulationSpace.WORLD,
471
+ emission: { rateOverTime: 50 },
472
+ shape: {
473
+ shape: Shape.CONE,
474
+ cone: { angle: 0.2, radius: 0.3, radiusThickness: 1 },
475
+ },
476
+ map: fireTexture,
477
+ renderer: {
478
+ blending: THREE.AdditiveBlending,
479
+ transparent: true,
480
+ depthTest: true,
481
+ depthWrite: false,
482
+ discardBackgroundColor: false,
483
+ backgroundColorTolerance: 1,
484
+ backgroundColor: { r: 0, g: 0, b: 0 },
485
+ },
486
+ sizeOverLifetime: {
487
+ isActive: true,
488
+ lifetimeCurve: {
489
+ type: LifeTimeCurve.BEZIER,
490
+ scale: 1,
491
+ bezierPoints: [
492
+ { x: 0, y: 1, percentage: 0 },
493
+ { x: 0.5, y: 0.5 },
494
+ { x: 1, y: 0, percentage: 1 },
495
+ ],
496
+ },
497
+ },
498
+ opacityOverLifetime: {
499
+ isActive: true,
500
+ lifetimeCurve: {
501
+ type: LifeTimeCurve.BEZIER,
502
+ scale: 1,
503
+ bezierPoints: [
504
+ { x: 0, y: 1, percentage: 0 },
505
+ { x: 0.7, y: 0.8 },
506
+ { x: 1, y: 0, percentage: 1 },
507
+ ],
508
+ },
509
+ },
510
+ });
511
+
512
+ scene.add(fire.instance);
513
+ ```
514
+
515
+ ---
516
+
517
+ ## Links
518
+
519
+ - Repository: https://github.com/NewKrok/three-particles
520
+ - API Docs: https://newkrok.github.io/three-particles/
521
+ - Visual Editor: https://github.com/NewKrok/three-particles-editor
522
+ - Editor Demo: https://newkrok.com/three-particles-editor/index.html
523
+ - npm: https://www.npmjs.com/package/@newkrok/three-particles
package/llms.txt ADDED
@@ -0,0 +1,121 @@
1
+ # @newkrok/three-particles
2
+
3
+ > Three.js-based high-performance particle system library for creating visually stunning particle effects. Perfect for game developers and 3D applications.
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ npm install @newkrok/three-particles three
9
+ ```
10
+
11
+ ```typescript
12
+ import * as THREE from "three";
13
+ import { createParticleSystem, updateParticleSystems } from "@newkrok/three-particles";
14
+
15
+ const scene = new THREE.Scene();
16
+
17
+ const { instance } = createParticleSystem({
18
+ duration: 5,
19
+ looping: true,
20
+ maxParticles: 100,
21
+ startLifetime: 2,
22
+ startSpeed: 3,
23
+ startSize: 0.5,
24
+ startColor: { min: { r: 1, g: 0.5, b: 0 }, max: { r: 1, g: 1, b: 0 } },
25
+ emission: { rateOverTime: 20 },
26
+ shape: { shape: Shape.CONE, cone: { angle: 0.4, radius: 0.5 } },
27
+ });
28
+
29
+ scene.add(instance);
30
+
31
+ // In your animation loop:
32
+ function animate() {
33
+ updateParticleSystems({
34
+ now: performance.now(),
35
+ delta: clock.getDelta(),
36
+ elapsed: clock.getElapsedTime(),
37
+ });
38
+ }
39
+ ```
40
+
41
+ ## Main API
42
+
43
+ - `createParticleSystem(config: ParticleSystemConfig): ParticleSystem` — Create a particle system
44
+ - `updateParticleSystems(cycleData: CycleData)` — Update all active particle systems
45
+
46
+ ### ParticleSystem Methods
47
+
48
+ - `instance` — The Three.js Points or Gyroscope object (add to scene)
49
+ - `pauseEmitter()` — Pause particle emission
50
+ - `resumeEmitter()` — Resume particle emission
51
+ - `dispose()` — Clean up and free resources
52
+ - `update(cycleData)` — Update this specific system only
53
+
54
+ ## Key Configuration Properties
55
+
56
+ | Property | Type | Default | Description |
57
+ |----------|------|---------|-------------|
58
+ | duration | number | 5.0 | Duration in seconds |
59
+ | looping | boolean | true | Whether to loop |
60
+ | maxParticles | number | 100 | Maximum active particles |
61
+ | startLifetime | number / {min,max} / Curve | 5.0 | Particle lifetime |
62
+ | startSpeed | number / {min,max} / Curve | 1.0 | Initial speed |
63
+ | startSize | number / {min,max} / Curve | 1.0 | Initial size |
64
+ | startOpacity | number / {min,max} / Curve | 1.0 | Initial opacity |
65
+ | startRotation | number / {min,max} / Curve | 0.0 | Initial rotation (degrees) |
66
+ | startColor | MinMaxColor | white | Color range |
67
+ | gravity | number | 0.0 | Gravity strength |
68
+ | simulationSpace | LOCAL / WORLD | LOCAL | Coordinate space |
69
+ | emission | Emission | rateOverTime: 10 | Emission config |
70
+ | shape | ShapeConfig | — | Emitter shape |
71
+ | map | THREE.Texture | undefined | Particle texture |
72
+
73
+ ## Emitter Shapes
74
+
75
+ - `Shape.SPHERE` — Spherical emission (radius, arc, radiusThickness)
76
+ - `Shape.CONE` — Conical emission (angle, radius, arc)
77
+ - `Shape.CIRCLE` — Circular flat emission (radius, arc)
78
+ - `Shape.RECTANGLE` — Rectangular flat emission (scale, rotation)
79
+ - `Shape.BOX` — Box volume emission (scale, emitFrom: VOLUME/SHELL/EDGE)
80
+
81
+ ## Lifetime Modifiers
82
+
83
+ - `velocityOverLifetime` — Linear & orbital velocity changes
84
+ - `sizeOverLifetime` — Size curve over lifetime
85
+ - `opacityOverLifetime` — Opacity curve over lifetime
86
+ - `colorOverLifetime` — RGB curves (multipliers on startColor)
87
+ - `rotationOverLifetime` — Rotation speed range
88
+ - `noise` — FBM noise affecting position, rotation, size
89
+
90
+ ## Burst Emission
91
+
92
+ ```typescript
93
+ emission: {
94
+ rateOverTime: 0,
95
+ bursts: [
96
+ { time: 0, count: 50 },
97
+ { time: 1, count: { min: 10, max: 30 }, probability: 0.8 },
98
+ { time: 0.5, count: 10, cycles: 3, interval: 0.2 },
99
+ ],
100
+ }
101
+ ```
102
+
103
+ ## Curves
104
+
105
+ Values support: constant `number`, random `{ min, max }`, or curves:
106
+
107
+ ```typescript
108
+ // Bezier curve
109
+ { type: LifeTimeCurve.BEZIER, bezierPoints: [...], scale: 1 }
110
+
111
+ // Easing function
112
+ { type: LifeTimeCurve.EASING, curveFunction: (t) => t * t, scale: 1 }
113
+ ```
114
+
115
+ ## Links
116
+
117
+ - Repository: https://github.com/NewKrok/three-particles
118
+ - API Docs: https://newkrok.github.io/three-particles/
119
+ - Visual Editor: https://github.com/NewKrok/three-particles-editor
120
+ - Editor Demo: https://newkrok.com/three-particles-editor/index.html
121
+ - Full LLM Reference: https://github.com/NewKrok/three-particles/blob/master/llms-full.txt