@newkrok/three-particles 2.10.4 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -0
- package/dist/index.d.ts +58 -7
- package/dist/index.js +303 -111
- package/dist/index.js.map +1 -1
- package/dist/three-particles.min.js +1 -1
- package/dist/three-particles.min.js.map +1 -1
- package/llms-full.txt +180 -4
- package/llms.txt +68 -0
- package/package.json +1 -1
package/llms-full.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @newkrok/three-particles — Full API Reference
|
|
2
2
|
|
|
3
|
-
> Three.js-based high-performance particle system library (v2.
|
|
3
|
+
> Three.js-based high-performance particle system library (v2.11.0)
|
|
4
4
|
> License: MIT | Author: Istvan Krisztian Somoracz
|
|
5
5
|
> Repository: https://github.com/NewKrok/three-particles
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
npm install @newkrok/three-particles three
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Peer dependency: `three` ^0.
|
|
15
|
+
Peer dependency: `three` ^0.182.0
|
|
16
16
|
|
|
17
17
|
---
|
|
18
18
|
|
|
@@ -62,7 +62,7 @@ function animate() {
|
|
|
62
62
|
|
|
63
63
|
| Property/Method | Type | Description |
|
|
64
64
|
|-----------------|------|-------------|
|
|
65
|
-
| `instance` | `THREE.Points \| Gyroscope` | The renderable object — add to scene |
|
|
65
|
+
| `instance` | `THREE.Points \| THREE.Mesh \| Gyroscope` | The renderable object — add to scene (Mesh when using RendererType.INSTANCED) |
|
|
66
66
|
| `pauseEmitter()` | `() => void` | Stop emitting new particles |
|
|
67
67
|
| `resumeEmitter()` | `() => void` | Resume emitting particles |
|
|
68
68
|
| `dispose()` | `() => void` | Destroy system, free resources |
|
|
@@ -337,7 +337,15 @@ type Renderer = {
|
|
|
337
337
|
transparent: boolean; // Default: true
|
|
338
338
|
depthTest: boolean; // Default: true
|
|
339
339
|
depthWrite: boolean; // Default: false
|
|
340
|
+
rendererType?: RendererType; // Default: RendererType.POINTS
|
|
340
341
|
};
|
|
342
|
+
|
|
343
|
+
enum RendererType {
|
|
344
|
+
POINTS = 'POINTS', // Classic point sprites (THREE.Points). Default.
|
|
345
|
+
INSTANCED = 'INSTANCED', // Camera-facing quads via InstancedBufferGeometry.
|
|
346
|
+
// Removes gl_PointSize hardware limit, supports large particles.
|
|
347
|
+
// Recommended for 10 000+ particles or large on-screen sizes.
|
|
348
|
+
}
|
|
341
349
|
```
|
|
342
350
|
|
|
343
351
|
Common blending modes: `THREE.NormalBlending`, `THREE.AdditiveBlending`, `THREE.SubtractiveBlending`
|
|
@@ -417,6 +425,9 @@ const system = createParticleSystem({
|
|
|
417
425
|
### LifeTimeCurve
|
|
418
426
|
`BEZIER` | `EASING`
|
|
419
427
|
|
|
428
|
+
### RendererType
|
|
429
|
+
`POINTS` (default — classic point sprites) | `INSTANCED` (GPU instanced quads, no gl_PointSize limit)
|
|
430
|
+
|
|
420
431
|
---
|
|
421
432
|
|
|
422
433
|
## Callbacks
|
|
@@ -425,7 +436,7 @@ const system = createParticleSystem({
|
|
|
425
436
|
createParticleSystem({
|
|
426
437
|
// Called every frame
|
|
427
438
|
onUpdate: ({ particleSystem, delta, elapsed, lifetime, iterationCount }) => {
|
|
428
|
-
// particleSystem: THREE.Points instance
|
|
439
|
+
// particleSystem: THREE.Points or THREE.Mesh instance
|
|
429
440
|
// delta: seconds since last frame
|
|
430
441
|
// elapsed: total seconds
|
|
431
442
|
// lifetime: system duration
|
|
@@ -514,6 +525,171 @@ scene.add(fire.instance);
|
|
|
514
525
|
|
|
515
526
|
---
|
|
516
527
|
|
|
528
|
+
## Sub-Emitters
|
|
529
|
+
|
|
530
|
+
Trigger child particle systems when particles are born or die.
|
|
531
|
+
|
|
532
|
+
```typescript
|
|
533
|
+
type SubEmitter = {
|
|
534
|
+
trigger: SubEmitterTrigger; // BIRTH or DEATH
|
|
535
|
+
config: ParticleSystemConfig; // The child particle system config
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
// Usage
|
|
539
|
+
createParticleSystem({
|
|
540
|
+
// ... main system config
|
|
541
|
+
subEmitters: [
|
|
542
|
+
{ trigger: SubEmitterTrigger.BIRTH, config: sparkConfig },
|
|
543
|
+
{ trigger: SubEmitterTrigger.DEATH, config: explosionConfig },
|
|
544
|
+
],
|
|
545
|
+
});
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### SubEmitterTrigger
|
|
549
|
+
- `BIRTH` — Spawns child system at the position of each newly created particle
|
|
550
|
+
- `DEATH` — Spawns child system at the position of each dying particle
|
|
551
|
+
|
|
552
|
+
---
|
|
553
|
+
|
|
554
|
+
## Force Fields
|
|
555
|
+
|
|
556
|
+
Apply forces to particles dynamically. Supports point attraction/repulsion and directional wind.
|
|
557
|
+
|
|
558
|
+
```typescript
|
|
559
|
+
type ForceField = {
|
|
560
|
+
type: ForceFieldType; // POINT or DIRECTIONAL
|
|
561
|
+
position?: Point3D; // For POINT type — center of force
|
|
562
|
+
direction?: Point3D; // For DIRECTIONAL type — force direction
|
|
563
|
+
strength: number; // Force strength (negative = repulsion for POINT)
|
|
564
|
+
radius?: number; // For POINT type — area of effect
|
|
565
|
+
falloff?: ForceFieldFalloff; // NONE, LINEAR, or QUADRATIC
|
|
566
|
+
};
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
### ForceFieldType
|
|
570
|
+
- `POINT` — Attracts (positive strength) or repels (negative strength) particles toward/from a point
|
|
571
|
+
- `DIRECTIONAL` — Applies a constant force in a direction (e.g., wind)
|
|
572
|
+
|
|
573
|
+
### ForceFieldFalloff
|
|
574
|
+
- `NONE` — Constant force regardless of distance
|
|
575
|
+
- `LINEAR` — Force decreases linearly with distance
|
|
576
|
+
- `QUADRATIC` — Force decreases with the square of distance (realistic gravity-like falloff)
|
|
577
|
+
|
|
578
|
+
**Example — Vortex with wind:**
|
|
579
|
+
```typescript
|
|
580
|
+
createParticleSystem({
|
|
581
|
+
// ... particle config
|
|
582
|
+
forceFields: [
|
|
583
|
+
{
|
|
584
|
+
type: ForceFieldType.POINT,
|
|
585
|
+
position: { x: 0, y: 2, z: 0 },
|
|
586
|
+
strength: 5,
|
|
587
|
+
radius: 3,
|
|
588
|
+
falloff: ForceFieldFalloff.LINEAR,
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
type: ForceFieldType.DIRECTIONAL,
|
|
592
|
+
direction: { x: 1, y: 0, z: 0 },
|
|
593
|
+
strength: 2,
|
|
594
|
+
},
|
|
595
|
+
],
|
|
596
|
+
});
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
---
|
|
600
|
+
|
|
601
|
+
## Serialization
|
|
602
|
+
|
|
603
|
+
Save and load particle system configurations as JSON.
|
|
604
|
+
|
|
605
|
+
```typescript
|
|
606
|
+
import {
|
|
607
|
+
serializeParticleSystemConfig,
|
|
608
|
+
deserializeParticleSystemConfig,
|
|
609
|
+
} from "@newkrok/three-particles";
|
|
610
|
+
|
|
611
|
+
// Serialize (config → JSON-safe object)
|
|
612
|
+
const json = serializeParticleSystemConfig(config);
|
|
613
|
+
const jsonString = JSON.stringify(json);
|
|
614
|
+
|
|
615
|
+
// Deserialize (JSON-safe object → config)
|
|
616
|
+
const restored = deserializeParticleSystemConfig(JSON.parse(jsonString));
|
|
617
|
+
const system = createParticleSystem(restored);
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
---
|
|
621
|
+
|
|
622
|
+
## Usage with React Three Fiber
|
|
623
|
+
|
|
624
|
+
The library works with [React Three Fiber](https://github.com/pmndrs/react-three-fiber) without any additional wrapper package. Use `createParticleSystem` directly with React hooks:
|
|
625
|
+
|
|
626
|
+
```tsx
|
|
627
|
+
import { useRef, useEffect } from "react";
|
|
628
|
+
import { useFrame } from "@react-three/fiber";
|
|
629
|
+
import {
|
|
630
|
+
createParticleSystem,
|
|
631
|
+
Shape,
|
|
632
|
+
type ParticleSystem,
|
|
633
|
+
} from "@newkrok/three-particles";
|
|
634
|
+
import * as THREE from "three";
|
|
635
|
+
|
|
636
|
+
function FireEffect({ config }: { config?: Record<string, unknown> }) {
|
|
637
|
+
const groupRef = useRef<THREE.Group>(null);
|
|
638
|
+
const systemRef = useRef<ParticleSystem | null>(null);
|
|
639
|
+
|
|
640
|
+
useEffect(() => {
|
|
641
|
+
const system = createParticleSystem({
|
|
642
|
+
duration: 5,
|
|
643
|
+
looping: true,
|
|
644
|
+
maxParticles: 200,
|
|
645
|
+
startLifetime: { min: 0.5, max: 1.5 },
|
|
646
|
+
startSpeed: { min: 1, max: 3 },
|
|
647
|
+
startSize: { min: 0.3, max: 0.8 },
|
|
648
|
+
startColor: {
|
|
649
|
+
min: { r: 1, g: 0.2, b: 0 },
|
|
650
|
+
max: { r: 1, g: 0.8, b: 0 },
|
|
651
|
+
},
|
|
652
|
+
gravity: -1,
|
|
653
|
+
emission: { rateOverTime: 50 },
|
|
654
|
+
shape: { shape: Shape.CONE, cone: { angle: 0.2, radius: 0.3 } },
|
|
655
|
+
renderer: {
|
|
656
|
+
blending: THREE.AdditiveBlending,
|
|
657
|
+
transparent: true,
|
|
658
|
+
depthWrite: false,
|
|
659
|
+
},
|
|
660
|
+
...config,
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
systemRef.current = system;
|
|
664
|
+
groupRef.current?.add(system.instance);
|
|
665
|
+
|
|
666
|
+
return () => {
|
|
667
|
+
system.dispose();
|
|
668
|
+
};
|
|
669
|
+
}, [config]);
|
|
670
|
+
|
|
671
|
+
useFrame((_, delta) => {
|
|
672
|
+
systemRef.current?.update({
|
|
673
|
+
now: performance.now(),
|
|
674
|
+
delta,
|
|
675
|
+
elapsed: 0,
|
|
676
|
+
});
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
return <group ref={groupRef} />;
|
|
680
|
+
}
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
### Key Integration Points
|
|
684
|
+
|
|
685
|
+
- **`useEffect`** — Create the particle system on mount, dispose on unmount
|
|
686
|
+
- **`useFrame`** — Drive per-frame updates using R3F's render loop (use `system.update()` for individual system control instead of the global `updateParticleSystems()`)
|
|
687
|
+
- **`<group ref>`** — Attach `system.instance` to a group so R3F manages the scene graph
|
|
688
|
+
- **Config changes** — Pass `config` as a dependency to `useEffect` to recreate on changes
|
|
689
|
+
- **No wrapper package needed** — The imperative API integrates naturally with React hooks
|
|
690
|
+
|
|
691
|
+
---
|
|
692
|
+
|
|
517
693
|
## Links
|
|
518
694
|
|
|
519
695
|
- Repository: https://github.com/NewKrok/three-particles
|
package/llms.txt
CHANGED
|
@@ -69,6 +69,12 @@ function animate() {
|
|
|
69
69
|
| emission | Emission | rateOverTime: 10 | Emission config |
|
|
70
70
|
| shape | ShapeConfig | — | Emitter shape |
|
|
71
71
|
| map | THREE.Texture | undefined | Particle texture |
|
|
72
|
+
| renderer | Renderer | — | Renderer settings (blending, rendererType, etc.) |
|
|
73
|
+
|
|
74
|
+
## Renderer Types
|
|
75
|
+
|
|
76
|
+
- `RendererType.POINTS` (default) — Classic point sprites via `THREE.Points`
|
|
77
|
+
- `RendererType.INSTANCED` — Camera-facing quads via `InstancedBufferGeometry`, removes `gl_PointSize` hardware limit
|
|
72
78
|
|
|
73
79
|
## Emitter Shapes
|
|
74
80
|
|
|
@@ -112,6 +118,68 @@ Values support: constant `number`, random `{ min, max }`, or curves:
|
|
|
112
118
|
{ type: LifeTimeCurve.EASING, curveFunction: (t) => t * t, scale: 1 }
|
|
113
119
|
```
|
|
114
120
|
|
|
121
|
+
## Sub-Emitters
|
|
122
|
+
|
|
123
|
+
Trigger child particle systems on particle birth or death:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
subEmitters: [
|
|
127
|
+
{ trigger: SubEmitterTrigger.BIRTH, config: sparkConfig },
|
|
128
|
+
{ trigger: SubEmitterTrigger.DEATH, config: explosionConfig },
|
|
129
|
+
]
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Force Fields
|
|
133
|
+
|
|
134
|
+
Point attractors/repulsors and directional wind forces:
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
forceFields: [
|
|
138
|
+
{
|
|
139
|
+
type: ForceFieldType.POINT,
|
|
140
|
+
position: { x: 0, y: 2, z: 0 },
|
|
141
|
+
strength: 5,
|
|
142
|
+
radius: 3,
|
|
143
|
+
falloff: ForceFieldFalloff.LINEAR,
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
type: ForceFieldType.DIRECTIONAL,
|
|
147
|
+
direction: { x: 1, y: 0, z: 0 },
|
|
148
|
+
strength: 2,
|
|
149
|
+
},
|
|
150
|
+
]
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Usage with React Three Fiber
|
|
154
|
+
|
|
155
|
+
No wrapper package needed — use hooks directly:
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
import { useRef, useEffect } from "react";
|
|
159
|
+
import { useFrame } from "@react-three/fiber";
|
|
160
|
+
import { createParticleSystem, type ParticleSystem } from "@newkrok/three-particles";
|
|
161
|
+
|
|
162
|
+
function ParticleEffect({ config }) {
|
|
163
|
+
const groupRef = useRef(null);
|
|
164
|
+
const systemRef = useRef(null);
|
|
165
|
+
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
const system = createParticleSystem(config);
|
|
168
|
+
systemRef.current = system;
|
|
169
|
+
groupRef.current?.add(system.instance);
|
|
170
|
+
return () => system.dispose();
|
|
171
|
+
}, [config]);
|
|
172
|
+
|
|
173
|
+
useFrame((_, delta) => {
|
|
174
|
+
systemRef.current?.update({ now: performance.now(), delta, elapsed: 0 });
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return <group ref={groupRef} />;
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Key: `useEffect` for create/dispose, `useFrame` for per-frame updates, `system.update()` for individual system control.
|
|
182
|
+
|
|
115
183
|
## Links
|
|
116
184
|
|
|
117
185
|
- Repository: https://github.com/NewKrok/three-particles
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newkrok/three-particles",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Three.js-based high-performance particle system library designed for creating visually stunning particle effects with ease. Perfect for game developers and 3D applications.",
|
|
6
6
|
"main": "./dist/index.js",
|