@newkrok/three-particles 2.11.2 → 2.13.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 +2 -0
- package/dist/index.d.ts +165 -2
- package/dist/index.js +724 -23
- 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 +95 -1
- package/llms.txt +47 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,6 +20,8 @@ Particle system for ThreeJS.
|
|
|
20
20
|
* Sub-emitters triggered on particle birth or death events.
|
|
21
21
|
* Serialization support for saving and loading particle system configs.
|
|
22
22
|
* GPU instancing renderer (`RendererType.INSTANCED`) — removes `gl_PointSize` hardware limit, ideal for large particles or high particle counts.
|
|
23
|
+
* Trail / Ribbon renderer (`RendererType.TRAIL`) — continuous ribbon trails behind particles with configurable width, opacity, and color tapering.
|
|
24
|
+
* Mesh particle renderer (`RendererType.MESH`) — render each particle as a 3D mesh (debris, gems, coins) using GPU instancing with full 3D rotation and simple directional lighting.
|
|
23
25
|
* TypeDoc API documentation available.
|
|
24
26
|
|
|
25
27
|
# Live Demo & Examples
|
package/dist/index.d.ts
CHANGED
|
@@ -169,7 +169,34 @@ declare const enum RendererType {
|
|
|
169
169
|
* and enables batching multiple emitters into fewer draw calls.
|
|
170
170
|
* Recommended for 10 000+ particles or when large on-screen particle sizes are needed.
|
|
171
171
|
*/
|
|
172
|
-
INSTANCED = "INSTANCED"
|
|
172
|
+
INSTANCED = "INSTANCED",
|
|
173
|
+
/**
|
|
174
|
+
* Render each particle as a ribbon trail connecting its current and previous positions.
|
|
175
|
+
* Each particle stores a configurable number of position history samples, and the
|
|
176
|
+
* renderer builds a camera-facing triangle-strip ribbon through those samples.
|
|
177
|
+
*
|
|
178
|
+
* Trail width and opacity can taper along the ribbon length for effects like
|
|
179
|
+
* sword slashes, magic missiles, comet tails, and speed lines.
|
|
180
|
+
*
|
|
181
|
+
* Configure trail-specific properties via {@link TrailConfig} on the renderer.
|
|
182
|
+
*/
|
|
183
|
+
TRAIL = "TRAIL",
|
|
184
|
+
/**
|
|
185
|
+
* Render each particle as a 3D mesh using GPU instancing (`InstancedBufferGeometry`).
|
|
186
|
+
* Instead of flat billboard sprites, particles are rendered as real 3D geometry
|
|
187
|
+
* (e.g., cubes, spheres, tori, or any custom `THREE.BufferGeometry`).
|
|
188
|
+
*
|
|
189
|
+
* Key differences from billboard renderers:
|
|
190
|
+
* - **3D rotation**: Particles rotate in all three axes (quaternion-based).
|
|
191
|
+
* - **Normals**: Mesh geometry retains normals, enabling basic lighting.
|
|
192
|
+
* - **Arbitrary geometry**: Any `THREE.BufferGeometry` can be used per particle.
|
|
193
|
+
*
|
|
194
|
+
* All existing modifiers (sizeOverLifetime, colorOverLifetime, noise, force fields,
|
|
195
|
+
* sub-emitters) work with mesh particles.
|
|
196
|
+
*
|
|
197
|
+
* Configure mesh-specific properties via {@link MeshConfig} on the renderer.
|
|
198
|
+
*/
|
|
199
|
+
MESH = "MESH"
|
|
173
200
|
}
|
|
174
201
|
/**
|
|
175
202
|
* Defines how force diminishes with distance from a POINT force field center.
|
|
@@ -620,6 +647,82 @@ type TextureSheetAnimation = {
|
|
|
620
647
|
fps?: number;
|
|
621
648
|
startFrame?: Constant | RandomBetweenTwoConstants;
|
|
622
649
|
};
|
|
650
|
+
/**
|
|
651
|
+
* Configuration for the trail/ribbon renderer.
|
|
652
|
+
* Controls how particle trails are drawn when using `RendererType.TRAIL`.
|
|
653
|
+
*
|
|
654
|
+
* @property length - Number of position history samples per particle (trail segments).
|
|
655
|
+
* Higher values produce longer, smoother trails but cost more memory.
|
|
656
|
+
* @default 20
|
|
657
|
+
* @property widthOverTrail - Lifetime curve that controls the ribbon width along its length.
|
|
658
|
+
* At 0 the trail head (current position), at 1 the trail tail (oldest position).
|
|
659
|
+
* @default constant 1.0
|
|
660
|
+
* @property opacityOverTrail - Lifetime curve that controls opacity along the trail length.
|
|
661
|
+
* @default linear fade from 1 (head) to 0 (tail)
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* ```typescript
|
|
665
|
+
* // Long comet-style trail tapering to nothing
|
|
666
|
+
* trail: {
|
|
667
|
+
* length: 40,
|
|
668
|
+
* widthOverTrail: {
|
|
669
|
+
* type: LifeTimeCurve.BEZIER,
|
|
670
|
+
* scale: 1,
|
|
671
|
+
* bezierPoints: [
|
|
672
|
+
* { x: 0, y: 1, percentage: 0 },
|
|
673
|
+
* { x: 0.5, y: 0.4 },
|
|
674
|
+
* { x: 1, y: 0, percentage: 1 },
|
|
675
|
+
* ],
|
|
676
|
+
* },
|
|
677
|
+
* }
|
|
678
|
+
* ```
|
|
679
|
+
*/
|
|
680
|
+
type TrailConfig = {
|
|
681
|
+
/** Number of position history samples per particle. @default 20 */
|
|
682
|
+
length?: number;
|
|
683
|
+
/** Base ribbon width in world units. @default 1.0 */
|
|
684
|
+
width?: number;
|
|
685
|
+
/** Curve controlling ribbon width from head (0) to tail (1). */
|
|
686
|
+
widthOverTrail?: LifetimeCurve;
|
|
687
|
+
/** Curve controlling opacity from head (0) to tail (1). */
|
|
688
|
+
opacityOverTrail?: LifetimeCurve;
|
|
689
|
+
/**
|
|
690
|
+
* Per-channel color multiplier curves along the trail (head=0, tail=1).
|
|
691
|
+
* Works as multipliers on the particle's current color, same as colorOverLifetime.
|
|
692
|
+
* To achieve full color transitions, use white startColor.
|
|
693
|
+
*/
|
|
694
|
+
colorOverTrail?: {
|
|
695
|
+
isActive: boolean;
|
|
696
|
+
r: LifetimeCurve;
|
|
697
|
+
g: LifetimeCurve;
|
|
698
|
+
b: LifetimeCurve;
|
|
699
|
+
};
|
|
700
|
+
};
|
|
701
|
+
/**
|
|
702
|
+
* Configuration for the mesh particle renderer.
|
|
703
|
+
* Controls which 3D geometry is used when `rendererType` is `RendererType.MESH`.
|
|
704
|
+
*
|
|
705
|
+
* @property geometry - A `THREE.BufferGeometry` to render for each particle.
|
|
706
|
+
* Built-in Three.js primitives like `BoxGeometry`, `SphereGeometry`, `TorusGeometry`
|
|
707
|
+
* all work. The geometry's own normals and UVs are preserved.
|
|
708
|
+
*
|
|
709
|
+
* @example
|
|
710
|
+
* ```typescript
|
|
711
|
+
* // Cube mesh particles
|
|
712
|
+
* mesh: {
|
|
713
|
+
* geometry: new THREE.BoxGeometry(1, 1, 1),
|
|
714
|
+
* }
|
|
715
|
+
*
|
|
716
|
+
* // Icosahedron mesh particles
|
|
717
|
+
* mesh: {
|
|
718
|
+
* geometry: new THREE.IcosahedronGeometry(0.5, 0),
|
|
719
|
+
* }
|
|
720
|
+
* ```
|
|
721
|
+
*/
|
|
722
|
+
type MeshConfig = {
|
|
723
|
+
/** The geometry to render for each particle. */
|
|
724
|
+
geometry: THREE.BufferGeometry;
|
|
725
|
+
};
|
|
623
726
|
/**
|
|
624
727
|
* Configuration for the particle system renderer, controlling blending, transparency, depth, and background color behavior.
|
|
625
728
|
*
|
|
@@ -673,6 +776,20 @@ type Renderer = {
|
|
|
673
776
|
* @default RendererType.POINTS
|
|
674
777
|
*/
|
|
675
778
|
rendererType?: RendererType;
|
|
779
|
+
/**
|
|
780
|
+
* Trail/ribbon renderer configuration.
|
|
781
|
+
* Only used when `rendererType` is `RendererType.TRAIL`.
|
|
782
|
+
*
|
|
783
|
+
* @see TrailConfig
|
|
784
|
+
*/
|
|
785
|
+
trail?: TrailConfig;
|
|
786
|
+
/**
|
|
787
|
+
* Mesh particle renderer configuration.
|
|
788
|
+
* Only used when `rendererType` is `RendererType.MESH`.
|
|
789
|
+
*
|
|
790
|
+
* @see MeshConfig
|
|
791
|
+
*/
|
|
792
|
+
mesh?: MeshConfig;
|
|
676
793
|
};
|
|
677
794
|
/**
|
|
678
795
|
* Configuration for noise effects applied to particles in a particle system.
|
|
@@ -1482,6 +1599,20 @@ type GeneralData = {
|
|
|
1482
1599
|
isEnabled: boolean;
|
|
1483
1600
|
/** Tracks the state of each burst emission event */
|
|
1484
1601
|
burstStates?: Array<BurstState>;
|
|
1602
|
+
/**
|
|
1603
|
+
* Circular buffer storing position history for trail renderer.
|
|
1604
|
+
* Each particle has `trailLength` slots of (x, y, z) positions.
|
|
1605
|
+
* Only allocated when `RendererType.TRAIL` is used.
|
|
1606
|
+
*/
|
|
1607
|
+
positionHistory?: Float32Array;
|
|
1608
|
+
/** Write index per particle into the circular position history buffer. */
|
|
1609
|
+
positionHistoryIndex?: Uint16Array;
|
|
1610
|
+
/** Number of valid history samples per particle (fills up from 0 to trailLength). */
|
|
1611
|
+
positionHistoryCount?: Uint16Array;
|
|
1612
|
+
/** Trail length (number of history samples per particle). */
|
|
1613
|
+
trailLength?: number;
|
|
1614
|
+
/** Cached camera world position, updated each frame via onBeforeRender for billboard trails. */
|
|
1615
|
+
trailCameraPosition?: THREE.Vector3;
|
|
1485
1616
|
};
|
|
1486
1617
|
/** Union of all buffer attribute types Three.js uses in geometry. */
|
|
1487
1618
|
type AnyBufferAttribute = THREE.BufferAttribute | THREE.InstancedBufferAttribute | THREE.InterleavedBufferAttribute;
|
|
@@ -1502,6 +1633,8 @@ type MappedAttributes = {
|
|
|
1502
1633
|
colorG: AnyBufferAttribute;
|
|
1503
1634
|
colorB: AnyBufferAttribute;
|
|
1504
1635
|
colorA: AnyBufferAttribute;
|
|
1636
|
+
/** Packed quaternion vec4 for 3D mesh rotation (only present for RendererType.MESH). */
|
|
1637
|
+
quat?: AnyBufferAttribute;
|
|
1505
1638
|
};
|
|
1506
1639
|
type ParticleSystemInstance = {
|
|
1507
1640
|
particleSystem: THREE.Points | THREE.Mesh;
|
|
@@ -1544,6 +1677,29 @@ type ParticleSystemInstance = {
|
|
|
1544
1677
|
onParticleDeath?: (particleIndex: number, positionArr: THREE.TypedArray, velocity: THREE.Vector3, now: number) => void;
|
|
1545
1678
|
/** Called when a particle is born to trigger birth sub-emitters */
|
|
1546
1679
|
onParticleBirth?: (particleIndex: number, positionArr: THREE.TypedArray, velocity: THREE.Vector3, now: number) => void;
|
|
1680
|
+
/** Trail mesh for RendererType.TRAIL */
|
|
1681
|
+
trailMesh?: THREE.Mesh;
|
|
1682
|
+
/** Trail geometry position attribute */
|
|
1683
|
+
trailPositionAttr?: THREE.BufferAttribute;
|
|
1684
|
+
/** Trail geometry alpha attribute */
|
|
1685
|
+
trailAlphaAttr?: THREE.BufferAttribute;
|
|
1686
|
+
/** Trail geometry color attribute */
|
|
1687
|
+
trailColorAttr?: THREE.BufferAttribute;
|
|
1688
|
+
/** Trail width curve function */
|
|
1689
|
+
trailWidthCurveFn?: CurveFunction;
|
|
1690
|
+
/** Trail opacity curve function */
|
|
1691
|
+
trailOpacityCurveFn?: CurveFunction;
|
|
1692
|
+
/** Trail color-over-trail curve functions (r, g, b multipliers) */
|
|
1693
|
+
trailColorOverTrailFns?: {
|
|
1694
|
+
r: CurveFunction;
|
|
1695
|
+
g: CurveFunction;
|
|
1696
|
+
b: CurveFunction;
|
|
1697
|
+
};
|
|
1698
|
+
/** Trail config (length, width) */
|
|
1699
|
+
trailConfig?: {
|
|
1700
|
+
length: number;
|
|
1701
|
+
width: number;
|
|
1702
|
+
};
|
|
1547
1703
|
};
|
|
1548
1704
|
/**
|
|
1549
1705
|
* Represents a particle system instance, providing methods to control and manage its lifecycle.
|
|
@@ -1922,6 +2078,13 @@ declare const calculateRandomPositionAndVelocityOnRectangle: (position: THREE.Ve
|
|
|
1922
2078
|
rotation: Point3D;
|
|
1923
2079
|
scale: Point3D;
|
|
1924
2080
|
}) => void;
|
|
2081
|
+
/**
|
|
2082
|
+
* Creates a solid white 1x1 texture for mesh particles.
|
|
2083
|
+
* Unlike the circle texture used by point/billboard renderers, mesh particles
|
|
2084
|
+
* need a neutral texture so the geometry shape is visible.
|
|
2085
|
+
* @returns {THREE.CanvasTexture | null} The generated texture or null if context fails.
|
|
2086
|
+
*/
|
|
2087
|
+
declare const createDefaultMeshTexture: () => THREE.CanvasTexture | null;
|
|
1925
2088
|
/**
|
|
1926
2089
|
* Creates a default white circle texture using CanvasTexture.
|
|
1927
2090
|
* @returns {THREE.CanvasTexture | null} The generated texture or null if context fails.
|
|
@@ -2036,4 +2199,4 @@ declare const getDefaultParticleSystemConfig: () => any;
|
|
|
2036
2199
|
declare const createParticleSystem: (config?: ParticleSystemConfig, externalNow?: number) => ParticleSystem;
|
|
2037
2200
|
declare const updateParticleSystems: (cycleData: CycleData) => void;
|
|
2038
2201
|
|
|
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 };
|
|
2202
|
+
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 MeshConfig, 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 TrailConfig, type Transform, type VelocityOverLifetime, applyModifiers, blendingMap, calculateRandomPositionAndVelocityOnBox, calculateRandomPositionAndVelocityOnCircle, calculateRandomPositionAndVelocityOnCone, calculateRandomPositionAndVelocityOnRectangle, calculateRandomPositionAndVelocityOnSphere, calculateValue, createBezierCurveFunction, createDefaultMeshTexture, createDefaultParticleTexture, createParticleSystem, curveFunctionIdMap, getBezierCacheSize, getCurveFunction, getCurveFunctionFromConfig, getDefaultParticleSystemConfig, isLifeTimeCurve, removeBezierCurveFunction, updateParticleSystems };
|