@newkrok/three-particles 2.16.1 → 3.0.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
@@ -177,6 +177,10 @@ enableWebGPU();
177
177
  import * as THREE from "three/webgpu";
178
178
  const renderer = new THREE.WebGPURenderer({ antialias: true });
179
179
  await renderer.init();
180
+ // No special outputColorSpace handling needed — the library follows the
181
+ // standard three.js linear workflow (user colors sRGB, shader math linear,
182
+ // renderer converts on output). Leave outputColorSpace at its default
183
+ // (SRGBColorSpace).
180
184
 
181
185
  // 3. Create a GPU-accelerated particle system
182
186
  import { createParticleSystem, SimulationBackend } from "@newkrok/three-particles";
@@ -236,6 +240,22 @@ Automatically generated TypeDoc: [https://newkrok.github.io/three-particles/api/
236
240
 
237
241
  ## Important Notes
238
242
 
243
+ ### Color Conventions
244
+
245
+ All RGB values in particle configs (`startColor`, `backgroundColor`) are
246
+ **sRGB** — the same convention used everywhere else in three.js. Pass the
247
+ value a color picker gives you (e.g. `{ r: 1, g: 0, b: 0 }` for pure red)
248
+ and the renderer will display it correctly.
249
+
250
+ Internally the library decodes these to linear for shader math and relies
251
+ on the renderer's standard output pass to convert back to sRGB on the way
252
+ to the framebuffer. No special `outputColorSpace` setup is required; the
253
+ three.js default (`SRGBColorSpace`) works.
254
+
255
+ User-supplied color map textures should also be tagged as sRGB
256
+ (`texture.colorSpace = THREE.SRGBColorSpace`) — this is also the
257
+ three.js default for color textures loaded via `TextureLoader`.
258
+
239
259
  ### Color Over Lifetime
240
260
 
241
261
  The `colorOverLifetime` feature uses a **multiplier-based approach** (similar to Unity's particle system), where each RGB channel curve acts as a multiplier applied to the particle's `startColor`.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,42 @@
1
1
  import * as THREE from 'three';
2
- import { Gyroscope } from 'three/examples/jsm/misc/Gyroscope.js';
3
2
  import { FBM } from 'three-noise/build/three-noise.module.js';
4
3
 
4
+ declare const REVISION: string;
5
+
6
+ /**
7
+ * Standard IEC 61966-2-1 sRGB → linear transfer function.
8
+ * Matches `THREE.ColorManagement.SRGBToLinear` and the GLSL
9
+ * `ShaderChunk.colorspace_fragment` implementation, so that user-provided
10
+ * colors go through the exact same conversion the rest of the Three.js
11
+ * pipeline uses for sRGB-tagged inputs.
12
+ *
13
+ * Input: a channel value in [0, 1] interpreted as sRGB.
14
+ * Output: the corresponding linear value in [0, 1].
15
+ */
16
+ declare const sRGBToLinear: (c: number) => number;
17
+ /**
18
+ * Standard IEC 61966-2-1 linear → sRGB transfer function.
19
+ * Inverse of {@link sRGBToLinear}. Useful for one-shot migration of
20
+ * legacy color values that were authored under the old raw-byte pipeline.
21
+ */
22
+ declare const linearToSRGB: (c: number) => number;
23
+ /**
24
+ * Converts an sRGB {r, g, b} triplet to linear space.
25
+ * Used when uploading user-authored colors (e.g. `backgroundColor`) as
26
+ * shader uniforms that must match the linear-space texture samples and
27
+ * vertex colors used elsewhere in the pipeline. Missing channels default
28
+ * to 0 to mirror the permissive shape of the `Rgb` config type.
29
+ */
30
+ declare const rgbSRGBToLinear: (c: {
31
+ r?: number;
32
+ g?: number;
33
+ b?: number;
34
+ }) => {
35
+ r: number;
36
+ g: number;
37
+ b: number;
38
+ };
39
+
5
40
  /**
6
41
  * Defines the coordinate space in which particles are simulated.
7
42
  *
@@ -1829,9 +1864,27 @@ type GeneralData = {
1829
1864
  lastWorldPosition: THREE.Vector3;
1830
1865
  currentWorldPosition: THREE.Vector3;
1831
1866
  worldPositionChange: THREE.Vector3;
1867
+ /**
1868
+ * For WORLD simulation space: the full world transform of the emitter
1869
+ * (parent.matrixWorld × particleSystem.matrix). Used to position new
1870
+ * particles in world coordinates at emit time and to orient the
1871
+ * emission shape. The particleSystem's own matrixWorld is forced to
1872
+ * identity so the buffer coordinates render as world coordinates.
1873
+ */
1874
+ sourceWorldMatrix: THREE.Matrix4;
1832
1875
  wrapperQuaternion: THREE.Quaternion;
1833
- lastWorldQuaternion: THREE.Quaternion;
1834
1876
  worldQuaternion: THREE.Quaternion;
1877
+ /**
1878
+ * Emitter world scale (decomposed from the full parent chain). Used to
1879
+ * match Unity's parent-scale semantics:
1880
+ * - WORLD mode: scales the shape-emission offset at spawn time (the
1881
+ * Shape module in Unity obeys parent scale when Scaling Mode is
1882
+ * Local/Hierarchy). Live particles are unaffected.
1883
+ * - LOCAL mode: gravity is stored in local units, so it is divided by
1884
+ * this scale so the rendered fall matches world -g m/s² regardless
1885
+ * of parent scale.
1886
+ */
1887
+ worldScale: THREE.Vector3;
1835
1888
  worldEuler: THREE.Euler;
1836
1889
  gravityVelocity: THREE.Vector3;
1837
1890
  startValues: Record<string, Array<number>>;
@@ -1910,7 +1963,6 @@ type MappedAttributes = {
1910
1963
  };
1911
1964
  type ParticleSystemInstance = {
1912
1965
  particleSystem: THREE.Points | THREE.Mesh;
1913
- wrapper?: Gyroscope;
1914
1966
  mappedAttributes: MappedAttributes;
1915
1967
  /** Shared interleaved Float32Array backing all scalar per-particle attributes. */
1916
1968
  scalarArray: Float32Array;
@@ -2007,7 +2059,7 @@ type ParticleSystemInstance = {
2007
2059
  /**
2008
2060
  * Represents a particle system instance, providing methods to control and manage its lifecycle.
2009
2061
  *
2010
- * @property instance - The underlying Three.js `Points` object or a `Gyroscope` used for particle rendering.
2062
+ * @property instance - The underlying Three.js `Points` or `Mesh` object used for particle rendering.
2011
2063
  * @property resumeEmitter - Resumes the particle emitter, allowing particles to be emitted again.
2012
2064
  * @property pauseEmitter - Pauses the particle emitter, stopping any new particles from being emitted.
2013
2065
  * @property dispose - Disposes of the particle system, cleaning up resources to free memory.
@@ -2025,7 +2077,7 @@ type ParticleSystemInstance = {
2025
2077
  * particleSystem.dispose(); // Cleanup the particle system
2026
2078
  */
2027
2079
  type ParticleSystem = {
2028
- instance: THREE.Points | THREE.Mesh | Gyroscope;
2080
+ instance: THREE.Points | THREE.Mesh;
2029
2081
  resumeEmitter: () => void;
2030
2082
  pauseEmitter: () => void;
2031
2083
  dispose: () => void;
@@ -2715,4 +2767,4 @@ declare const getDefaultParticleSystemConfig: () => any;
2715
2767
  declare const createParticleSystem: (config?: ParticleSystemConfig, externalNow?: number) => ParticleSystem;
2716
2768
  declare const updateParticleSystems: (cycleData: CycleData) => void;
2717
2769
 
2718
- export { type BezierCurve, type BezierPoint, type Box, type Burst, type BurstState, type Circle, type CollisionPlaneConfig, CollisionPlaneMode, 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 NormalizedCollisionPlaneConfig, type NormalizedForceFieldConfig, type NormalizedParticleSystemConfig, type ParticleSystem, type ParticleSystemConfig, type ParticleSystemInstance, type Point3D, type RandomBetweenTwoConstants, type Rectangle, type Renderer, RendererType, type Rgb, SCALAR_STRIDE, S_COLOR_A, S_COLOR_B, S_COLOR_G, S_COLOR_R, S_IS_ACTIVE, S_LIFETIME, S_ROTATION, S_SIZE, S_START_FRAME, S_START_LIFETIME, Shape, type ShapeConfig, SimulationBackend, SimulationSpace, type SoftParticlesConfig, 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, deserializeParticleSystem, getBezierCacheSize, getCurveFunction, getCurveFunctionFromConfig, getDefaultParticleSystemConfig, isComputeCapableRenderer, isLifeTimeCurve, registerTSLMaterialFactory, removeBezierCurveFunction, resolveSimulationBackend, serializeParticleSystem, updateParticleSystems };
2770
+ export { type BezierCurve, type BezierPoint, type Box, type Burst, type BurstState, type Circle, type CollisionPlaneConfig, CollisionPlaneMode, 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 NormalizedCollisionPlaneConfig, type NormalizedForceFieldConfig, type NormalizedParticleSystemConfig, type ParticleSystem, type ParticleSystemConfig, type ParticleSystemInstance, type Point3D, REVISION, type RandomBetweenTwoConstants, type Rectangle, type Renderer, RendererType, type Rgb, SCALAR_STRIDE, S_COLOR_A, S_COLOR_B, S_COLOR_G, S_COLOR_R, S_IS_ACTIVE, S_LIFETIME, S_ROTATION, S_SIZE, S_START_FRAME, S_START_LIFETIME, Shape, type ShapeConfig, SimulationBackend, SimulationSpace, type SoftParticlesConfig, 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, deserializeParticleSystem, getBezierCacheSize, getCurveFunction, getCurveFunctionFromConfig, getDefaultParticleSystemConfig, isComputeCapableRenderer, isLifeTimeCurve, linearToSRGB, registerTSLMaterialFactory, removeBezierCurveFunction, resolveSimulationBackend, rgbSRGBToLinear, sRGBToLinear, serializeParticleSystem, updateParticleSystems };