@newkrok/three-particles 2.10.4 → 2.11.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/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
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: THREE.NormalBufferAttributes;
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 };