@newkrok/three-particles 2.11.0 → 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 CHANGED
@@ -67,6 +67,78 @@ scene.add(instance);
67
67
  updateParticleSystems({now, delta, elapsed});
68
68
  ```
69
69
 
70
+ # Usage with React Three Fiber
71
+
72
+ The library works seamlessly with [React Three Fiber](https://github.com/pmndrs/react-three-fiber). No additional wrapper package is needed — use `createParticleSystem` directly with React hooks:
73
+
74
+ ```tsx
75
+ import { useRef, useEffect } from "react";
76
+ import { useFrame } from "@react-three/fiber";
77
+ import {
78
+ createParticleSystem,
79
+ Shape,
80
+ type ParticleSystem,
81
+ } from "@newkrok/three-particles";
82
+ import * as THREE from "three";
83
+
84
+ function FireEffect({ config }: { config?: Record<string, unknown> }) {
85
+ const groupRef = useRef<THREE.Group>(null);
86
+ const systemRef = useRef<ParticleSystem | null>(null);
87
+
88
+ useEffect(() => {
89
+ const system = createParticleSystem({
90
+ duration: 5,
91
+ looping: true,
92
+ maxParticles: 200,
93
+ startLifetime: { min: 0.5, max: 1.5 },
94
+ startSpeed: { min: 1, max: 3 },
95
+ startSize: { min: 0.3, max: 0.8 },
96
+ startColor: {
97
+ min: { r: 1, g: 0.2, b: 0 },
98
+ max: { r: 1, g: 0.8, b: 0 },
99
+ },
100
+ gravity: -1,
101
+ emission: { rateOverTime: 50 },
102
+ shape: { shape: Shape.CONE, cone: { angle: 0.2, radius: 0.3 } },
103
+ renderer: {
104
+ blending: THREE.AdditiveBlending,
105
+ transparent: true,
106
+ depthWrite: false,
107
+ },
108
+ ...config,
109
+ });
110
+
111
+ systemRef.current = system;
112
+ groupRef.current?.add(system.instance);
113
+
114
+ return () => {
115
+ system.dispose();
116
+ };
117
+ }, [config]);
118
+
119
+ useFrame((_, delta) => {
120
+ systemRef.current?.update({
121
+ now: performance.now(),
122
+ delta,
123
+ elapsed: 0,
124
+ });
125
+ });
126
+
127
+ return <group ref={groupRef} />;
128
+ }
129
+
130
+ // In your R3F Canvas:
131
+ // <Canvas>
132
+ // <FireEffect />
133
+ // </Canvas>
134
+ ```
135
+
136
+ **Key points:**
137
+ - Use `useEffect` to create and dispose the particle system
138
+ - Use `useFrame` to drive updates each frame (call `system.update()` instead of `updateParticleSystems()` for per-system control)
139
+ - Add the `system.instance` to a `<group>` ref so R3F manages the scene graph
140
+ - Return a cleanup function from `useEffect` that calls `system.dispose()`
141
+
70
142
  # Documentation
71
143
 
72
144
  Automatically generated TypeDoc: [https://newkrok.github.io/three-particles/api/](https://newkrok.github.io/three-particles/api/)
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.10.4)
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.180.0
15
+ Peer dependency: `three` ^0.182.0
16
16
 
17
17
  ---
18
18
 
@@ -525,6 +525,171 @@ scene.add(fire.instance);
525
525
 
526
526
  ---
527
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
+
528
693
  ## Links
529
694
 
530
695
  - Repository: https://github.com/NewKrok/three-particles
package/llms.txt CHANGED
@@ -118,6 +118,68 @@ Values support: constant `number`, random `{ min, max }`, or curves:
118
118
  { type: LifeTimeCurve.EASING, curveFunction: (t) => t * t, scale: 1 }
119
119
  ```
120
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
+
121
183
  ## Links
122
184
 
123
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.11.0",
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",