three-low-poly 0.9.26 → 0.9.28

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/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ import { ExtrudeGeometry } from 'three';
8
8
  import { Group } from 'three';
9
9
  import { InstancedMesh } from 'three';
10
10
  import { Material } from 'three';
11
+ import { MaterialEventMap } from 'three';
11
12
  import { Mesh } from 'three';
12
13
  import { MeshBasicMaterial } from 'three';
13
14
  import { MeshLambertMaterial } from 'three';
@@ -16,7 +17,7 @@ import { MeshPhysicalMaterial } from 'three';
16
17
  import { MeshStandardMaterial } from 'three';
17
18
  import { Object3D } from 'three';
18
19
  import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
19
- import { ParametricGeometry } from 'three-stdlib';
20
+ import { ParametricGeometry } from 'three/addons/geometries/ParametricGeometry.js';
20
21
  import { PerspectiveCamera } from 'three';
21
22
  import { Plane } from 'three';
22
23
  import { PlaneGeometry } from 'three';
@@ -69,7 +70,7 @@ import { Vector3 } from 'three';
69
70
  * instancedMesh.geometry.setAttribute("instanceColor", new THREE.InstancedBufferAttribute(colors, 3));
70
71
  * ```
71
72
  */
72
- export declare function addInstanceColor(material: Material): Material;
73
+ export declare function addInstanceColor(material: Material): Material< MaterialEventMap>;
73
74
 
74
75
  /**
75
76
  * Utility function to add noise-based vertex displacement to an existing Three.js material.
@@ -647,6 +648,59 @@ export declare interface BookshelfOptions extends BookshelfGeometryOptions {
647
648
  color?: ColorRepresentation;
648
649
  }
649
650
 
651
+ /**
652
+ * Boulder prefab — a {@link BoulderGeometry} lumped by coherent 3D noise, with a
653
+ * matte flat-shaded stone material. Centered on the origin; casts and receives
654
+ * shadows. Vary `seed` per instance for a field of unique boulders.
655
+ */
656
+ export declare class Boulder extends Mesh<BoulderGeometry, MeshStandardMaterial> {
657
+ readonly radius: number;
658
+ constructor({ color, flatShading, ...geometryOptions }?: BoulderOptions);
659
+ }
660
+
661
+ /**
662
+ * Boulder — an icosphere lumped by coherent 3D fbm ({@link fbm3}) displaced along
663
+ * each vertex's radial direction. The 3D counterpart to the terrain heightfields:
664
+ * same noise strategy, applied over a closed surface instead of a height map.
665
+ *
666
+ * The icosphere is welded (`mergeVertices` after stripping seam UVs) so coincident
667
+ * vertices share one displacement — the coherent noise then moves neighbors together,
668
+ * so the surface stays watertight and never cracks (the failure mode of displacing a
669
+ * non-indexed polyhedron along normals). Real baked geometry, so shadows, raycasts,
670
+ * and physics colliders match what's drawn, on WebGL and WebGPU/TSL alike.
671
+ *
672
+ * Centered on the origin. Pair with a `flatShading` material for a faceted low-poly
673
+ * look. Vary `seed` per instance to fill a field with unique boulders.
674
+ */
675
+ export declare class BoulderGeometry extends BufferGeometry {
676
+ readonly radius: number;
677
+ constructor({ radius, detail, noiseHeight, noiseScale, octaves, persistence, seed, }?: BoulderGeometryOptions);
678
+ }
679
+
680
+ export declare interface BoulderGeometryOptions {
681
+ /** Base radius before displacement (world units). Defaults to `1`. */
682
+ radius?: number;
683
+ /** Icosahedron subdivision — more detail = more, finer facets. Defaults to `2`. */
684
+ detail?: number;
685
+ /** Radial relief amplitude (world units, ±). Keep below `radius`. Defaults to `0.35`. */
686
+ noiseHeight?: number;
687
+ /** Noise frequency over the unit sphere — higher packs more, smaller lumps. Defaults to `1.6`. */
688
+ noiseScale?: number;
689
+ /** fbm octaves (detail layers). Defaults to `3`. */
690
+ octaves?: number;
691
+ /** fbm gain per octave (0–1); lower is smoother, higher is rougher. Defaults to `0.5`. */
692
+ persistence?: number;
693
+ /** Seed for reproducible shape. Defaults to `1`. */
694
+ seed?: number;
695
+ }
696
+
697
+ export declare interface BoulderOptions extends BoulderGeometryOptions {
698
+ /** Stone tint. Defaults to `#6f6f6f`. */
699
+ color?: ColorRepresentation;
700
+ /** Faceted low-poly shading. Defaults to `true`. */
701
+ flatShading?: boolean;
702
+ }
703
+
650
704
  export declare enum BoxSide {
651
705
  LEFT = "left",
652
706
  RIGHT = "right",
@@ -1783,6 +1837,90 @@ export declare interface DollyClipOptions extends CameraClipTiming {
1783
1837
  ease?: EasingFunction;
1784
1838
  }
1785
1839
 
1840
+ /**
1841
+ * Fine dust drifting through a lit interior — tiny additive specks slowly
1842
+ * settling and wafting, twinkling as they catch the light and all but vanishing
1843
+ * in shadow. This is the thing that sells a light shaft as volumetric. Additive
1844
+ * spheres read the same from any angle, so no billboarding is needed.
1845
+ *
1846
+ * Call {@link DustMotesEffect.update} each frame with elapsed time in seconds.
1847
+ *
1848
+ * @example
1849
+ * ```typescript
1850
+ * const dust = new DustMotesEffect({
1851
+ * count: 150,
1852
+ * width: 8,
1853
+ * height: 9,
1854
+ * depth: 8,
1855
+ * color: "#aebfe6",
1856
+ * });
1857
+ * scene.add(dust);
1858
+ *
1859
+ * onFrame((dt) => dust.update(dt));
1860
+ * ```
1861
+ */
1862
+ export declare class DustMotesEffect extends InstancedMesh {
1863
+ private readonly width;
1864
+ private readonly height;
1865
+ private readonly depth;
1866
+ private readonly floorY;
1867
+ private readonly waft;
1868
+ private readonly scaleMin;
1869
+ private readonly scaleMax;
1870
+ private readonly px;
1871
+ private readonly py;
1872
+ private readonly pz;
1873
+ private readonly settle;
1874
+ private readonly twinkle;
1875
+ private readonly phase;
1876
+ private readonly dummy;
1877
+ private clock;
1878
+ constructor(options?: DustMotesEffectOptions);
1879
+ /**
1880
+ * Advance the drift and twinkle. Pass elapsed frame time in seconds.
1881
+ */
1882
+ update(dt: number): void;
1883
+ /** Release geometry and materials held by the field. */
1884
+ dispose(): this;
1885
+ private respawn;
1886
+ private writeMatrices;
1887
+ }
1888
+
1889
+ export declare interface DustMotesEffectOptions {
1890
+ /** Number of dust instances. Defaults to `150`. */
1891
+ count?: number;
1892
+ /** Horizontal spread (world units). Defaults to `12`. */
1893
+ width?: number;
1894
+ /** Vertical spawn span (world units). Defaults to `8`. */
1895
+ height?: number;
1896
+ /** Depth spread (world units). Defaults to `12`. */
1897
+ depth?: number;
1898
+ /** World Y of the volume floor; motes respawn at the top after settling past it. Defaults to `0`. */
1899
+ floorY?: number;
1900
+ /** Speck tint. Defaults to `#aebfe6`. */
1901
+ color?: ColorRepresentation;
1902
+ /** Speck radius (world units). Defaults to `0.02`. */
1903
+ radius?: number;
1904
+ /** Base material opacity. Defaults to `0.9`. */
1905
+ opacity?: number;
1906
+ /** Override the default additive speck material. */
1907
+ material?: Material;
1908
+ /** Minimum settle (fall) speed (units/s). Defaults to `0.1`. */
1909
+ settleMin?: number;
1910
+ /** Maximum settle (fall) speed (units/s). Defaults to `0.35`. */
1911
+ settleMax?: number;
1912
+ /** Lateral waft amplitude (units/s). Defaults to `0.08`. */
1913
+ waft?: number;
1914
+ /** Smallest twinkle scale multiplier. Defaults to `0.6`. */
1915
+ scaleMin?: number;
1916
+ /** Largest twinkle scale multiplier. Defaults to `1.2`. */
1917
+ scaleMax?: number;
1918
+ /** Minimum twinkle frequency (rad/s). Defaults to `0.7`. */
1919
+ twinkleMin?: number;
1920
+ /** Maximum twinkle frequency (rad/s). Defaults to `1.6`. */
1921
+ twinkleMax?: number;
1922
+ }
1923
+
1786
1924
  /**
1787
1925
  * Easing functions for interpolating values over time.
1788
1926
  *
@@ -2617,44 +2755,6 @@ export declare function hexToHsl(hex: number): [number, number, number];
2617
2755
  */
2618
2756
  export declare function hexToRgb(hex: number): [number, number, number];
2619
2757
 
2620
- /**
2621
- * Hill prefab — hemispherical terrain mound.
2622
- */
2623
- export declare class Hill extends Mesh<HillGeometry, MeshStandardMaterial> {
2624
- readonly radius: number;
2625
- readonly height: number;
2626
- constructor({ color, ...geometryOptions }?: HillOptions);
2627
- }
2628
-
2629
- /**
2630
- * Hemispherical hill — a sphere cap scaled on Y, base on the Y=0 plane.
2631
- */
2632
- export declare class HillGeometry extends BufferGeometry {
2633
- readonly radius: number;
2634
- readonly height: number;
2635
- constructor({ radius, height, widthSegments, heightSegments, phiStart, phiLength, }?: HillGeometryOptions);
2636
- }
2637
-
2638
- export declare interface HillGeometryOptions {
2639
- /** Base sphere radius before vertical squash. Defaults to `3`. */
2640
- radius?: number;
2641
- /** Peak height. Defaults to `0.6`. */
2642
- height?: number;
2643
- /** Horizontal segments. Defaults to `64`. */
2644
- widthSegments?: number;
2645
- /** Vertical segments. Defaults to `16`. */
2646
- heightSegments?: number;
2647
- /** Azimuth start angle (radians). Defaults to `0`. */
2648
- phiStart?: number;
2649
- /** Azimuth sweep (radians). Defaults to `2π`. */
2650
- phiLength?: number;
2651
- }
2652
-
2653
- export declare interface HillOptions extends HillGeometryOptions {
2654
- /** Surface tint. Defaults to `#00ff00`. */
2655
- color?: ColorRepresentation;
2656
- }
2657
-
2658
2758
  /**
2659
2759
  * Example usage:
2660
2760
  * ```
@@ -3030,43 +3130,6 @@ export declare interface MossyRockOptions extends MossyRockGeometryOptions {
3030
3130
  mossOpacity?: number;
3031
3131
  }
3032
3132
 
3033
- /**
3034
- * Mound prefab — flat-topped terrain cap.
3035
- */
3036
- export declare class Mound extends Mesh<MoundGeometry, MeshStandardMaterial> {
3037
- readonly radius: number;
3038
- constructor({ color, radius, ...geometryOptions }?: MoundOptions);
3039
- }
3040
-
3041
- /**
3042
- * Mound-like geometry with a flat top — sphere cap, base on Y=0.
3043
- */
3044
- export declare class MoundGeometry extends BufferGeometry {
3045
- readonly radius: number;
3046
- readonly thetaLength: number;
3047
- constructor({ radius, widthSegments, heightSegments, phiStart, phiLength, thetaLength, }?: MoundGeometryOptions);
3048
- }
3049
-
3050
- export declare interface MoundGeometryOptions {
3051
- /** Sphere radius. Defaults to a cap width of `5` at `thetaLength`. */
3052
- radius?: number;
3053
- /** Horizontal segments. Defaults to `64`. */
3054
- widthSegments?: number;
3055
- /** Vertical segments. Defaults to `32`. */
3056
- heightSegments?: number;
3057
- /** Azimuth start angle (radians). Defaults to `0`. */
3058
- phiStart?: number;
3059
- /** Azimuth sweep (radians). Defaults to `2π`. */
3060
- phiLength?: number;
3061
- /** Polar sweep from the north pole (radians). Defaults to `π/10`. */
3062
- thetaLength?: number;
3063
- }
3064
-
3065
- export declare interface MoundOptions extends MoundGeometryOptions {
3066
- /** Surface tint. Defaults to `#00ff00`. */
3067
- color?: ColorRepresentation;
3068
- }
3069
-
3070
3133
  /**
3071
3134
  * Fast seeded PRNG — portfolio Gotham/Water parity.
3072
3135
  * Returns a closure yielding floats in [0, 1).
@@ -3843,6 +3906,51 @@ export declare interface RowOfBooksOptions<T extends Material = Material> {
3843
3906
  seed?: number;
3844
3907
  }
3845
3908
 
3909
+ /**
3910
+ * Scatter a field of instanced boulders inside a horizontal bounds region — a "created
3911
+ * layer" of the noise-lumped {@link BoulderGeometry}. Unlike {@link scatterRocks}, which
3912
+ * rotates a single shared shape, this generates several distinct boulder geometries
3913
+ * (see `variants`) and distributes instances across them, so the field reads as unique
3914
+ * rocks while staying to a few draw calls.
3915
+ *
3916
+ * Returns a {@link Group} of {@link InstancedMesh}es (one per variant), each sharing the
3917
+ * stone material. Pass a `seed` for a reproducible field. Dispose each child's geometry
3918
+ * and the shared material when removing it.
3919
+ *
3920
+ * @example
3921
+ * ```ts
3922
+ * const boulders = scatterBoulders({ count: 24, width: 12, depth: 12, seed: 1337 });
3923
+ * scene.add(boulders);
3924
+ * ```
3925
+ */
3926
+ export declare function scatterBoulders({ count, width, depth, heightJitter, scaleMin, scaleMax, seed, radius, detail, noiseHeight, noiseScale, octaves, persistence, variants, material, color, }?: ScatterBouldersOptions): Group;
3927
+
3928
+ export declare interface ScatterBouldersOptions extends RockScatterPlacementOptions {
3929
+ /** Base radius for each boulder geometry. Defaults to `1`. */
3930
+ radius?: number;
3931
+ /** Icosphere subdivision per boulder. Defaults to `2`. */
3932
+ detail?: number;
3933
+ /** Radial relief amplitude per boulder. Defaults to `0.35`. */
3934
+ noiseHeight?: number;
3935
+ /** Noise frequency per boulder. Defaults to `1.6`. */
3936
+ noiseScale?: number;
3937
+ /** fbm octaves per boulder. Defaults to `3`. */
3938
+ octaves?: number;
3939
+ /** fbm gain per octave. Defaults to `0.5`. */
3940
+ persistence?: number;
3941
+ /**
3942
+ * Distinct boulder geometries generated and distributed across the field. Each is
3943
+ * a real, unique lumped shape (unlike rotating one shared mesh); instances round-robin
3944
+ * across them, so the field stays batch-friendly (one draw call per variant).
3945
+ * Defaults to `4`.
3946
+ */
3947
+ variants?: number;
3948
+ /** Override the default stone material (shared across all instances). */
3949
+ material?: Material;
3950
+ /** Stone tint when `material` is omitted. Defaults to `#6f6f6f`. */
3951
+ color?: ColorRepresentation;
3952
+ }
3953
+
3846
3954
  /**
3847
3955
  * Scatter instanced mossy rocks inside a horizontal bounds region.
3848
3956
  *
@@ -4489,6 +4597,8 @@ export declare class StarFieldEffect extends Object3D {
4489
4597
  private readonly baseSize;
4490
4598
  private readonly baseScales?;
4491
4599
  private readonly twinklePhases?;
4600
+ /** Untwinkled per-point RGB (points style), multiplied by each star's pulse each frame. */
4601
+ private baseColors?;
4492
4602
  private spriteTexture?;
4493
4603
  private readonly dummy;
4494
4604
  constructor(options?: StarFieldEffectOptions);
@@ -4500,8 +4610,9 @@ export declare class StarFieldEffect extends Object3D {
4500
4610
  /**
4501
4611
  * Animate twinkling. No-op when `twinkle` is `false`.
4502
4612
  *
4503
- * Points style modulates sprite size; burst style pulses each instance scale with
4504
- * a per-star phase offset. Pass elapsed time in seconds (defaults to `performance.now()`).
4613
+ * Both styles pulse with a per-star phase offset so stars twinkle out of sync:
4614
+ * points modulate per-point brightness (via the color attribute), burst pulses
4615
+ * each instance scale. Pass elapsed time in seconds (defaults to `performance.now()`).
4505
4616
  */
4506
4617
  update(elapsed?: number): void;
4507
4618
  private createPointsField;
@@ -4603,6 +4714,130 @@ export declare interface StoneFencePostOptions extends StoneFencePostGeometryOpt
4603
4714
  color?: ColorRepresentation;
4604
4715
  }
4605
4716
 
4717
+ /**
4718
+ * Rounded terrain mound prefab — a {@link TerrainMoundGeometry} with a matte,
4719
+ * flat-shaded material. Base sits on Y=0; drop it into a scene as a diorama
4720
+ * ground or a small rise. Casts and receives shadows.
4721
+ */
4722
+ export declare class TerrainMound extends Mesh<TerrainMoundGeometry, MeshStandardMaterial> {
4723
+ readonly radius: number;
4724
+ readonly height: number;
4725
+ constructor({ color, flatShading, ...geometryOptions }?: TerrainMoundOptions);
4726
+ }
4727
+
4728
+ /**
4729
+ * Rounded terrain cap — a circular disc bulged into a gentle dome, then broken up
4730
+ * with coherent fbm noise so it reads as rolling terrain rather than a smooth lens.
4731
+ * The relief tapers to a clean circular rim seated on the Y=0 plane.
4732
+ *
4733
+ * Displacement is baked into real vertices (no shader), so shadows, raycasts, and
4734
+ * any physics collider derived from the mesh match exactly what's drawn — and it
4735
+ * renders identically on WebGL and WebGPU/TSL. Pair with a `flatShading` material
4736
+ * for a faceted low-poly look; the coherent noise keeps neighboring vertices moving
4737
+ * together, so faces never tear.
4738
+ *
4739
+ * Local frame: base on Y=0, peak toward +Y, centered on the origin.
4740
+ */
4741
+ export declare class TerrainMoundGeometry extends BufferGeometry {
4742
+ readonly radius: number;
4743
+ readonly height: number;
4744
+ constructor({ radius, height, radialSegments, angularSegments, noiseHeight, noiseScale, octaves, persistence, rim, seed, }?: TerrainMoundGeometryOptions);
4745
+ }
4746
+
4747
+ export declare interface TerrainMoundGeometryOptions {
4748
+ /** Footprint radius (world units). Defaults to `8`. */
4749
+ radius?: number;
4750
+ /** Dome peak height at the center. Defaults to `1.2`. */
4751
+ height?: number;
4752
+ /** Concentric rings from center to rim. Defaults to `40`. */
4753
+ radialSegments?: number;
4754
+ /** Segments around the circumference. Defaults to `64`. */
4755
+ angularSegments?: number;
4756
+ /** Amplitude of the terrain relief added on top of the dome. Defaults to `0.5`. */
4757
+ noiseHeight?: number;
4758
+ /** Noise frequency — higher packs more, smaller bumps into the footprint. Defaults to `0.35`. */
4759
+ noiseScale?: number;
4760
+ /** fbm octaves (detail layers). Defaults to `4`. */
4761
+ octaves?: number;
4762
+ /** fbm gain per octave (0–1); lower is smoother, higher is rougher. Defaults to `0.5`. */
4763
+ persistence?: number;
4764
+ /** Normalized radius (0–1) where the rim begins fading relief to a flat edge. Defaults to `0.82`. */
4765
+ rim?: number;
4766
+ /** Seed for reproducible terrain. Defaults to `1`. */
4767
+ seed?: number;
4768
+ }
4769
+
4770
+ export declare interface TerrainMoundOptions extends TerrainMoundGeometryOptions {
4771
+ /** Surface tint. Defaults to `#3a5a3a`. */
4772
+ color?: ColorRepresentation;
4773
+ /** Faceted low-poly shading. Defaults to `true`. */
4774
+ flatShading?: boolean;
4775
+ }
4776
+
4777
+ /**
4778
+ * Rectangular terrain patch prefab — a {@link TerrainPlaneGeometry} with a matte,
4779
+ * flat-shaded material. Base grid on Y=0; drop it into a scene as a diorama ground
4780
+ * or a tileable terrain field. Casts and receives shadows.
4781
+ */
4782
+ export declare class TerrainPlane extends Mesh<TerrainPlaneGeometry, MeshStandardMaterial> {
4783
+ readonly width: number;
4784
+ readonly depth: number;
4785
+ constructor({ color, flatShading, ...geometryOptions }?: TerrainPlaneOptions);
4786
+ }
4787
+
4788
+ /**
4789
+ * Rectangular terrain patch — a flat grid displaced on Y by the shared coherent fbm
4790
+ * sampler ({@link fbm2}). The rectangular counterpart to {@link TerrainMoundGeometry}:
4791
+ * same noise strategy, grid layout instead of a radial disc.
4792
+ *
4793
+ * A pure heightfield (Y is single-valued per XZ) so faces can never fold, and it's
4794
+ * baked into real vertices — shadows, raycasts, and physics colliders match what's
4795
+ * drawn, on WebGL and WebGPU/TSL alike. Pair with a `flatShading` material for a
4796
+ * faceted low-poly look. Leave `edgeFalloff` at `0` for a tileable field; raise it to
4797
+ * seat the edges flat at Y=0.
4798
+ *
4799
+ * Local frame: base grid on Y=0, relief toward ±Y, centered on the origin.
4800
+ */
4801
+ export declare class TerrainPlaneGeometry extends BufferGeometry {
4802
+ readonly width: number;
4803
+ readonly depth: number;
4804
+ constructor({ width, depth, widthSegments, depthSegments, noiseHeight, noiseScale, octaves, persistence, edgeFalloff, seed, }?: TerrainPlaneGeometryOptions);
4805
+ }
4806
+
4807
+ export declare interface TerrainPlaneGeometryOptions {
4808
+ /** Extent along X (world units). Defaults to `16`. */
4809
+ width?: number;
4810
+ /** Extent along Z (world units). Defaults to `16`. */
4811
+ depth?: number;
4812
+ /** Grid segments along X. Defaults to `48`. */
4813
+ widthSegments?: number;
4814
+ /** Grid segments along Z. Defaults to `48`. */
4815
+ depthSegments?: number;
4816
+ /** Amplitude of the terrain relief (world units, ±). Defaults to `0.8`. */
4817
+ noiseHeight?: number;
4818
+ /** Noise frequency — higher packs more, smaller features into the footprint. Defaults to `0.35`. */
4819
+ noiseScale?: number;
4820
+ /** fbm octaves (detail layers). Defaults to `4`. */
4821
+ octaves?: number;
4822
+ /** fbm gain per octave (0–1); lower is smoother, higher is rougher. Defaults to `0.5`. */
4823
+ persistence?: number;
4824
+ /**
4825
+ * Border band (0–1 fraction of the half-extent) over which relief fades to a flat
4826
+ * edge at Y=0. `0` leaves a raw, seamless heightfield (tileable); higher values
4827
+ * seat the slab like a contained diorama patch. Defaults to `0`.
4828
+ */
4829
+ edgeFalloff?: number;
4830
+ /** Seed for reproducible terrain. Defaults to `1`. */
4831
+ seed?: number;
4832
+ }
4833
+
4834
+ export declare interface TerrainPlaneOptions extends TerrainPlaneGeometryOptions {
4835
+ /** Surface tint. Defaults to `#3a5a3a`. */
4836
+ color?: ColorRepresentation;
4837
+ /** Faceted low-poly shading. Defaults to `true`. */
4838
+ flatShading?: boolean;
4839
+ }
4840
+
4606
4841
  /**
4607
4842
  * Material indices
4608
4843
  * 0: Base