@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/README.md
CHANGED
|
@@ -19,6 +19,7 @@ Particle system for ThreeJS.
|
|
|
19
19
|
* Force fields and attractors for dynamic particle behavior (point attraction/repulsion, directional wind).
|
|
20
20
|
* Sub-emitters triggered on particle birth or death events.
|
|
21
21
|
* Serialization support for saving and loading particle system configs.
|
|
22
|
+
* GPU instancing renderer (`RendererType.INSTANCED`) — removes `gl_PointSize` hardware limit, ideal for large particles or high particle counts.
|
|
22
23
|
* TypeDoc API documentation available.
|
|
23
24
|
|
|
24
25
|
# Live Demo & Examples
|
|
@@ -66,6 +67,78 @@ scene.add(instance);
|
|
|
66
67
|
updateParticleSystems({now, delta, elapsed});
|
|
67
68
|
```
|
|
68
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
|
+
|
|
69
142
|
# Documentation
|
|
70
143
|
|
|
71
144
|
Automatically generated TypeDoc: [https://newkrok.github.io/three-particles/api/](https://newkrok.github.io/three-particles/api/)
|
package/dist/index.d.ts
CHANGED
|
@@ -151,6 +151,26 @@ declare const enum ForceFieldType {
|
|
|
151
151
|
*/
|
|
152
152
|
DIRECTIONAL = "DIRECTIONAL"
|
|
153
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Defines the rendering technique used for particles.
|
|
156
|
+
*
|
|
157
|
+
* @enum {string}
|
|
158
|
+
*/
|
|
159
|
+
declare const enum RendererType {
|
|
160
|
+
/**
|
|
161
|
+
* Render particles as point sprites using `THREE.Points`.
|
|
162
|
+
* This is the default renderer, efficient for small to medium particle counts.
|
|
163
|
+
* Note: point size is limited by `gl_PointSize` hardware caps (typically 64–256 px).
|
|
164
|
+
*/
|
|
165
|
+
POINTS = "POINTS",
|
|
166
|
+
/**
|
|
167
|
+
* Render particles as camera-facing quads using `THREE.InstancedBufferGeometry`.
|
|
168
|
+
* Removes the `gl_PointSize` hardware limit, supports stretched billboards,
|
|
169
|
+
* and enables batching multiple emitters into fewer draw calls.
|
|
170
|
+
* Recommended for 10 000+ particles or when large on-screen particle sizes are needed.
|
|
171
|
+
*/
|
|
172
|
+
INSTANCED = "INSTANCED"
|
|
173
|
+
}
|
|
154
174
|
/**
|
|
155
175
|
* Defines how force diminishes with distance from a POINT force field center.
|
|
156
176
|
* Only applicable to {@link ForceFieldType.POINT} force fields.
|
|
@@ -643,6 +663,16 @@ type Renderer = {
|
|
|
643
663
|
transparent: boolean;
|
|
644
664
|
depthTest: boolean;
|
|
645
665
|
depthWrite: boolean;
|
|
666
|
+
/**
|
|
667
|
+
* Selects the rendering technique for particles.
|
|
668
|
+
*
|
|
669
|
+
* - `RendererType.POINTS` (default) — classic point-sprite renderer using `THREE.Points`.
|
|
670
|
+
* - `RendererType.INSTANCED` — camera-facing quads via `InstancedBufferGeometry`,
|
|
671
|
+
* removing the `gl_PointSize` hardware limit and enabling stretched billboards.
|
|
672
|
+
*
|
|
673
|
+
* @default RendererType.POINTS
|
|
674
|
+
*/
|
|
675
|
+
rendererType?: RendererType;
|
|
646
676
|
};
|
|
647
677
|
/**
|
|
648
678
|
* Configuration for noise effects applied to particles in a particle system.
|
|
@@ -1392,7 +1422,7 @@ type ParticleSystemConfig = {
|
|
|
1392
1422
|
* Called on every update frame with particle system data.
|
|
1393
1423
|
*/
|
|
1394
1424
|
onUpdate?: (data: {
|
|
1395
|
-
particleSystem: THREE.Points;
|
|
1425
|
+
particleSystem: THREE.Points | THREE.Mesh;
|
|
1396
1426
|
delta: number;
|
|
1397
1427
|
elapsed: number;
|
|
1398
1428
|
lifetime: number;
|
|
@@ -1453,15 +1483,36 @@ type GeneralData = {
|
|
|
1453
1483
|
/** Tracks the state of each burst emission event */
|
|
1454
1484
|
burstStates?: Array<BurstState>;
|
|
1455
1485
|
};
|
|
1486
|
+
/** Union of all buffer attribute types Three.js uses in geometry. */
|
|
1487
|
+
type AnyBufferAttribute = THREE.BufferAttribute | THREE.InstancedBufferAttribute | THREE.InterleavedBufferAttribute;
|
|
1488
|
+
/**
|
|
1489
|
+
* A view that maps standard attribute names (e.g. 'position', 'size') to
|
|
1490
|
+
* their actual geometry attribute objects, which may have different names
|
|
1491
|
+
* in the instanced renderer (e.g. 'instanceOffset', 'instanceSize').
|
|
1492
|
+
*/
|
|
1493
|
+
type MappedAttributes = {
|
|
1494
|
+
position: AnyBufferAttribute;
|
|
1495
|
+
isActive: AnyBufferAttribute;
|
|
1496
|
+
lifetime: AnyBufferAttribute;
|
|
1497
|
+
startLifetime: AnyBufferAttribute;
|
|
1498
|
+
startFrame: AnyBufferAttribute;
|
|
1499
|
+
size: AnyBufferAttribute;
|
|
1500
|
+
rotation: AnyBufferAttribute;
|
|
1501
|
+
colorR: AnyBufferAttribute;
|
|
1502
|
+
colorG: AnyBufferAttribute;
|
|
1503
|
+
colorB: AnyBufferAttribute;
|
|
1504
|
+
colorA: AnyBufferAttribute;
|
|
1505
|
+
};
|
|
1456
1506
|
type ParticleSystemInstance = {
|
|
1457
|
-
particleSystem: THREE.Points;
|
|
1507
|
+
particleSystem: THREE.Points | THREE.Mesh;
|
|
1458
1508
|
wrapper?: Gyroscope;
|
|
1509
|
+
mappedAttributes: MappedAttributes;
|
|
1459
1510
|
elapsedUniform: {
|
|
1460
1511
|
value: number;
|
|
1461
1512
|
};
|
|
1462
1513
|
generalData: GeneralData;
|
|
1463
1514
|
onUpdate: (data: {
|
|
1464
|
-
particleSystem: THREE.Points;
|
|
1515
|
+
particleSystem: THREE.Points | THREE.Mesh;
|
|
1465
1516
|
delta: number;
|
|
1466
1517
|
elapsed: number;
|
|
1467
1518
|
lifetime: number;
|
|
@@ -1469,7 +1520,7 @@ type ParticleSystemInstance = {
|
|
|
1469
1520
|
iterationCount: number;
|
|
1470
1521
|
}) => void;
|
|
1471
1522
|
onComplete: (data: {
|
|
1472
|
-
particleSystem: THREE.Points;
|
|
1523
|
+
particleSystem: THREE.Points | THREE.Mesh;
|
|
1473
1524
|
}) => void;
|
|
1474
1525
|
creationTime: number;
|
|
1475
1526
|
lastEmissionTime: number;
|
|
@@ -1515,7 +1566,7 @@ type ParticleSystemInstance = {
|
|
|
1515
1566
|
* particleSystem.dispose(); // Cleanup the particle system
|
|
1516
1567
|
*/
|
|
1517
1568
|
type ParticleSystem = {
|
|
1518
|
-
instance: THREE.Points | Gyroscope;
|
|
1569
|
+
instance: THREE.Points | THREE.Mesh | Gyroscope;
|
|
1519
1570
|
resumeEmitter: () => void;
|
|
1520
1571
|
pauseEmitter: () => void;
|
|
1521
1572
|
dispose: () => void;
|
|
@@ -1719,7 +1770,7 @@ declare const applyModifiers: ({ delta, generalData, normalizedConfig, attribute
|
|
|
1719
1770
|
delta: number;
|
|
1720
1771
|
generalData: GeneralData;
|
|
1721
1772
|
normalizedConfig: NormalizedParticleSystemConfig;
|
|
1722
|
-
attributes:
|
|
1773
|
+
attributes: MappedAttributes;
|
|
1723
1774
|
particleLifetimePercentage: number;
|
|
1724
1775
|
particleIndex: number;
|
|
1725
1776
|
}) => void;
|
|
@@ -1985,4 +2036,4 @@ declare const getDefaultParticleSystemConfig: () => any;
|
|
|
1985
2036
|
declare const createParticleSystem: (config?: ParticleSystemConfig, externalNow?: number) => ParticleSystem;
|
|
1986
2037
|
declare const updateParticleSystems: (cycleData: CycleData) => void;
|
|
1987
2038
|
|
|
1988
|
-
export { type BezierCurve, type BezierPoint, type Box, type Burst, type BurstState, type Circle, type Cone, type Constant, type CurveBase, type CurveFunction, CurveFunctionId, type CycleData, type EasingCurve, type Emission, EmitFrom, type ForceFieldConfig, ForceFieldFalloff, ForceFieldType, type GeneralData, LifeTimeCurve, type LifetimeCurve, type MinMaxColor, type Noise, type NoiseConfig, type NormalizedForceFieldConfig, type NormalizedParticleSystemConfig, type ParticleSystem, type ParticleSystemConfig, type ParticleSystemInstance, type Point3D, type RandomBetweenTwoConstants, type Rectangle, type Renderer, type Rgb, Shape, type ShapeConfig, SimulationSpace, type Sphere, type SubEmitterConfig, SubEmitterTrigger, type TextureSheetAnimation, TimeMode, type Transform, type VelocityOverLifetime, applyModifiers, blendingMap, calculateRandomPositionAndVelocityOnBox, calculateRandomPositionAndVelocityOnCircle, calculateRandomPositionAndVelocityOnCone, calculateRandomPositionAndVelocityOnRectangle, calculateRandomPositionAndVelocityOnSphere, calculateValue, createBezierCurveFunction, createDefaultParticleTexture, createParticleSystem, curveFunctionIdMap, getBezierCacheSize, getCurveFunction, getCurveFunctionFromConfig, getDefaultParticleSystemConfig, isLifeTimeCurve, removeBezierCurveFunction, updateParticleSystems };
|
|
2039
|
+
export { type BezierCurve, type BezierPoint, type Box, type Burst, type BurstState, type Circle, type Cone, type Constant, type CurveBase, type CurveFunction, CurveFunctionId, type CycleData, type EasingCurve, type Emission, EmitFrom, type ForceFieldConfig, ForceFieldFalloff, ForceFieldType, type GeneralData, LifeTimeCurve, type LifetimeCurve, type MappedAttributes, type MinMaxColor, type Noise, type NoiseConfig, type NormalizedForceFieldConfig, type NormalizedParticleSystemConfig, type ParticleSystem, type ParticleSystemConfig, type ParticleSystemInstance, type Point3D, type RandomBetweenTwoConstants, type Rectangle, type Renderer, RendererType, type Rgb, Shape, type ShapeConfig, SimulationSpace, type Sphere, type SubEmitterConfig, SubEmitterTrigger, type TextureSheetAnimation, TimeMode, type Transform, type VelocityOverLifetime, applyModifiers, blendingMap, calculateRandomPositionAndVelocityOnBox, calculateRandomPositionAndVelocityOnCircle, calculateRandomPositionAndVelocityOnCone, calculateRandomPositionAndVelocityOnRectangle, calculateRandomPositionAndVelocityOnSphere, calculateValue, createBezierCurveFunction, createDefaultParticleTexture, createParticleSystem, curveFunctionIdMap, getBezierCacheSize, getCurveFunction, getCurveFunctionFromConfig, getDefaultParticleSystemConfig, isLifeTimeCurve, removeBezierCurveFunction, updateParticleSystems };
|