@n3rdw1z4rd/core 0.18.4 → 0.19.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.
Files changed (109) hide show
  1. package/README.md +72 -10
  2. package/dist/astar.d.ts +44 -0
  3. package/dist/astar.js +118 -0
  4. package/dist/canvas-renderer.d.ts +154 -0
  5. package/dist/canvas-renderer.js +200 -0
  6. package/dist/clock.d.ts +69 -0
  7. package/dist/clock.js +108 -0
  8. package/dist/color-palette.d.ts +25 -0
  9. package/dist/color-palette.js +112 -0
  10. package/dist/color.d.ts +90 -0
  11. package/dist/color.js +224 -0
  12. package/dist/css/main.css +1 -3
  13. package/dist/disposable.d.ts +27 -0
  14. package/dist/disposable.js +32 -0
  15. package/dist/dungeon-generator.d.ts +142 -0
  16. package/dist/dungeon-generator.js +288 -0
  17. package/dist/ecs.d.ts +87 -0
  18. package/dist/ecs.js +101 -0
  19. package/dist/emitter.d.ts +40 -0
  20. package/dist/emitter.js +54 -0
  21. package/dist/event-queue.d.ts +29 -0
  22. package/dist/event-queue.js +40 -0
  23. package/dist/index.cjs +3813 -0
  24. package/dist/index.d.cts +2655 -0
  25. package/dist/index.d.ts +35 -873
  26. package/dist/index.js +34 -3986
  27. package/dist/input/action-map.d.ts +79 -0
  28. package/dist/input/action-map.js +131 -0
  29. package/dist/input/bindings.d.ts +273 -0
  30. package/dist/input/bindings.js +250 -0
  31. package/dist/input/gestures.d.ts +108 -0
  32. package/dist/input/gestures.js +159 -0
  33. package/dist/input/index.d.ts +5 -0
  34. package/dist/input/index.js +5 -0
  35. package/dist/input/input.d.ts +297 -0
  36. package/dist/input/input.js +695 -0
  37. package/dist/log.d.ts +8 -0
  38. package/dist/log.js +9 -0
  39. package/dist/map2d.d.ts +83 -0
  40. package/dist/map2d.js +120 -0
  41. package/dist/map3d-CHDJiq5T.d.cts +236 -0
  42. package/dist/map3d.d.ts +94 -0
  43. package/dist/map3d.js +148 -0
  44. package/dist/math.d.ts +176 -0
  45. package/dist/math.js +206 -0
  46. package/dist/misc.d.ts +46 -0
  47. package/dist/misc.js +71 -0
  48. package/dist/observable.d.ts +43 -0
  49. package/dist/observable.js +53 -0
  50. package/dist/particle-renderer.d.ts +47 -0
  51. package/dist/particle-renderer.js +82 -0
  52. package/dist/particle-system-2d.d.ts +60 -0
  53. package/dist/particle-system-2d.js +147 -0
  54. package/dist/random.d.ts +46 -0
  55. package/dist/random.js +74 -0
  56. package/dist/rectangle.d.ts +44 -0
  57. package/dist/rectangle.js +69 -0
  58. package/dist/rng.d.ts +72 -0
  59. package/dist/rng.js +152 -0
  60. package/dist/signal.d.ts +34 -0
  61. package/dist/signal.js +41 -0
  62. package/dist/spatial-partition-2d.d.ts +42 -0
  63. package/dist/spatial-partition-2d.js +52 -0
  64. package/dist/spatial-partition-3d-Ba-VBveM.cjs +1324 -0
  65. package/dist/spatial-partition-3d.d.ts +44 -0
  66. package/dist/spatial-partition-3d.js +57 -0
  67. package/dist/three/asteroid-mesh.d.ts +41 -0
  68. package/dist/three/asteroid-mesh.js +44 -0
  69. package/dist/three/camera-rig.d.ts +140 -0
  70. package/dist/three/camera-rig.js +197 -0
  71. package/dist/three/cube-sphere-geometry.d.ts +55 -0
  72. package/dist/three/cube-sphere-geometry.js +239 -0
  73. package/dist/three/ecs.d.ts +75 -0
  74. package/dist/three/ecs.js +64 -0
  75. package/dist/three/index.d.ts +12 -0
  76. package/dist/three/index.js +12 -0
  77. package/dist/three/particle-system-3d.d.ts +53 -0
  78. package/dist/three/particle-system-3d.js +224 -0
  79. package/dist/three/renderer.d.ts +38 -0
  80. package/dist/three/renderer.js +57 -0
  81. package/dist/three/starfield.d.ts +23 -0
  82. package/dist/three/starfield.js +64 -0
  83. package/dist/three/texture-atlas.d.ts +76 -0
  84. package/dist/three/texture-atlas.js +84 -0
  85. package/dist/three/texture-utils.d.ts +31 -0
  86. package/dist/three/texture-utils.js +44 -0
  87. package/dist/three/voxel-geometry.d.ts +72 -0
  88. package/dist/three/voxel-geometry.js +231 -0
  89. package/dist/three/voxel-mesh.d.ts +67 -0
  90. package/dist/three/voxel-mesh.js +71 -0
  91. package/dist/three.cjs +1307 -0
  92. package/dist/three.d.cts +655 -0
  93. package/dist/tilemap.d.ts +17 -0
  94. package/dist/tilemap.js +26 -0
  95. package/dist/types.d.ts +34 -0
  96. package/dist/types.js +0 -0
  97. package/dist/vector.d.ts +78 -0
  98. package/dist/vector.js +169 -0
  99. package/dist/webgl-renderer.d.ts +89 -0
  100. package/dist/webgl-renderer.js +140 -0
  101. package/dist/webgl.d.ts +357 -0
  102. package/dist/webgl.js +628 -0
  103. package/dist/worker-interface.d.ts +30 -0
  104. package/dist/worker-interface.js +39 -0
  105. package/package.json +55 -13
  106. package/dist/css/index.ts +0 -1
  107. package/dist/index.css +0 -104
  108. package/dist/index.d.mts +0 -873
  109. package/dist/index.mjs +0 -3982
@@ -0,0 +1,38 @@
1
+ import { WebGLRenderer, WebGLRendererParameters } from "three";
2
+ //#region src/three/renderer.d.ts
3
+ /**
4
+ * `WebGLRenderer` that uses the device pixel ratio and can size itself to its parent element.
5
+ *
6
+ * ```ts
7
+ * const renderer = new Renderer({ antialias: true });
8
+ * container.appendChild(renderer.domElement);
9
+ *
10
+ * // each frame
11
+ * if (renderer.resize()) {
12
+ * camera.aspect = renderer.aspectRatio;
13
+ * camera.updateProjectionMatrix();
14
+ * }
15
+ * renderer.render(scene, camera);
16
+ * ```
17
+ *
18
+ * @category Rendering
19
+ */
20
+ export declare class Renderer extends WebGLRenderer {
21
+ private _size;
22
+ /** CSS pixels, same as setSize() and resize(); domElement.width/height are CSS pixels * pixel ratio */
23
+ get width(): number;
24
+ /** CSS pixels */
25
+ get height(): number;
26
+ /** width / height (1 while the height is 0) */
27
+ get aspectRatio(): number;
28
+ constructor(parameters?: WebGLRendererParameters);
29
+ /**
30
+ * Sets the size in CSS pixels, if it differs from the current one. A missing `width` / `height`
31
+ * defaults to the parent element's client size (or the current size when there is no parent, or
32
+ * the parent has no size yet, e.g. before layout or while hidden).
33
+ *
34
+ * @returns whether the size changed
35
+ */
36
+ resize(width?: number, height?: number): boolean;
37
+ }
38
+ //#endregion
@@ -0,0 +1,57 @@
1
+ import { Vector2, WebGLRenderer } from "three";
2
+ //#region src/three/renderer.ts
3
+ /**
4
+ * `WebGLRenderer` that uses the device pixel ratio and can size itself to its parent element.
5
+ *
6
+ * ```ts
7
+ * const renderer = new Renderer({ antialias: true });
8
+ * container.appendChild(renderer.domElement);
9
+ *
10
+ * // each frame
11
+ * if (renderer.resize()) {
12
+ * camera.aspect = renderer.aspectRatio;
13
+ * camera.updateProjectionMatrix();
14
+ * }
15
+ * renderer.render(scene, camera);
16
+ * ```
17
+ *
18
+ * @category Rendering
19
+ */
20
+ var Renderer = class extends WebGLRenderer {
21
+ _size = new Vector2();
22
+ /** CSS pixels, same as setSize() and resize(); domElement.width/height are CSS pixels * pixel ratio */
23
+ get width() {
24
+ return this.getSize(this._size).width;
25
+ }
26
+ /** CSS pixels */
27
+ get height() {
28
+ return this.getSize(this._size).height;
29
+ }
30
+ /** width / height (1 while the height is 0) */
31
+ get aspectRatio() {
32
+ return this.height > 0 ? this.width / this.height : 1;
33
+ }
34
+ constructor(parameters) {
35
+ super(parameters);
36
+ this.setPixelRatio(window.devicePixelRatio);
37
+ }
38
+ /**
39
+ * Sets the size in CSS pixels, if it differs from the current one. A missing `width` / `height`
40
+ * defaults to the parent element's client size (or the current size when there is no parent, or
41
+ * the parent has no size yet, e.g. before layout or while hidden).
42
+ *
43
+ * @returns whether the size changed
44
+ */
45
+ resize(width, height) {
46
+ let resized = false;
47
+ width = width ?? (this.domElement.parentElement?.clientWidth || this.width);
48
+ height = height ?? (this.domElement.parentElement?.clientHeight || this.height);
49
+ if (this.width !== width || this.height !== height) {
50
+ this.setSize(width, height);
51
+ resized = true;
52
+ }
53
+ return resized;
54
+ }
55
+ };
56
+ //#endregion
57
+ export { Renderer };
@@ -0,0 +1,23 @@
1
+ import { Group, Points, Vector3 } from "three";
2
+ //#region src/three/starfield.d.ts
3
+ /**
4
+ * Points spread uniformly over a sphere's surface, for a distant star backdrop (point size 5 with
5
+ * size attenuation, 0.9 opacity). The same `seed` always gives the same stars; without one,
6
+ * positions come from the shared {@link rng}.
7
+ *
8
+ * @param radius sphere radius in world units
9
+ * @param count number of stars
10
+ * @param color 0xRRGGBB
11
+ * @param seed seeds a private {@link Rng} for a reproducible starfield
12
+ * @category Geometry & Meshes
13
+ */
14
+ export declare function CreateStarfield(radius?: number, count?: number, color?: number, seed?: number): Points;
15
+ /**
16
+ * A sun: a bright unlit sphere (radius 50, color 0xffddaa) plus a white `PointLight` (intensity
17
+ * 10, no distance falloff) at the same spot.
18
+ *
19
+ * @param position where to put both, in the group's space; default the origin
20
+ * @category Geometry & Meshes
21
+ */
22
+ export declare function CreateSystemStar(position?: Vector3): Group;
23
+ //#endregion
@@ -0,0 +1,64 @@
1
+ import { Rng, rng } from "../rng.js";
2
+ import { BufferAttribute, BufferGeometry, Group, Mesh, MeshBasicMaterial, PointLight, Points, PointsMaterial, SphereGeometry, Vector3 } from "three";
3
+ //#region src/three/starfield.ts
4
+ /**
5
+ * Points spread uniformly over a sphere's surface, for a distant star backdrop (point size 5 with
6
+ * size attenuation, 0.9 opacity). The same `seed` always gives the same stars; without one,
7
+ * positions come from the shared {@link rng}.
8
+ *
9
+ * @param radius sphere radius in world units
10
+ * @param count number of stars
11
+ * @param color 0xRRGGBB
12
+ * @param seed seeds a private {@link Rng} for a reproducible starfield
13
+ * @category Geometry & Meshes
14
+ */
15
+ function CreateStarfield(radius = 1e3, count = 5e3, color = 16777215, seed) {
16
+ const random = seed === void 0 ? rng : new Rng(seed);
17
+ const geometry = new BufferGeometry();
18
+ const positions = new Float32Array(count * 3);
19
+ for (let i = 0; i < count; i++) {
20
+ const theta = random.nextFloat() * Math.PI * 2;
21
+ const phi = Math.acos(random.nextFloat() * 2 - 1);
22
+ const x = radius * Math.sin(phi) * Math.cos(theta);
23
+ const y = radius * Math.sin(phi) * Math.sin(theta);
24
+ const z = radius * Math.cos(phi);
25
+ positions.set([
26
+ x,
27
+ y,
28
+ z
29
+ ], i * 3);
30
+ }
31
+ geometry.setAttribute("position", new BufferAttribute(positions, 3));
32
+ const material = new PointsMaterial({
33
+ color,
34
+ size: 5,
35
+ sizeAttenuation: true,
36
+ transparent: true,
37
+ opacity: .9
38
+ });
39
+ const stars = new Points(geometry, material);
40
+ stars.name = "Starfield";
41
+ return stars;
42
+ }
43
+ /**
44
+ * A sun: a bright unlit sphere (radius 50, color 0xffddaa) plus a white `PointLight` (intensity
45
+ * 10, no distance falloff) at the same spot.
46
+ *
47
+ * @param position where to put both, in the group's space; default the origin
48
+ * @category Geometry & Meshes
49
+ */
50
+ function CreateSystemStar(position) {
51
+ const star = new Group();
52
+ const starPos = position ?? new Vector3();
53
+ const starGeo = new SphereGeometry(50, 32, 32);
54
+ const starMat = new MeshBasicMaterial({ color: 16768426 });
55
+ const starMesh = new Mesh(starGeo, starMat);
56
+ starMesh.position.copy(starPos);
57
+ star.add(starMesh);
58
+ const starLight = new PointLight(16777215, 10, 0, 0);
59
+ starLight.position.copy(starPos);
60
+ star.add(starLight);
61
+ return star;
62
+ }
63
+ //#endregion
64
+ export { CreateStarfield, CreateSystemStar };
@@ -0,0 +1,76 @@
1
+ import { TextureData } from "./texture-utils.js";
2
+ import { MeshLambertMaterial, MeshLambertMaterialParameters, Texture } from "three";
3
+ //#region src/three/texture-atlas.d.ts
4
+ /**
5
+ * Texture coordinate `[u, v]`, each 0..1, with v = 1 at the image's top (three.js convention).
6
+ *
7
+ * @category Textures
8
+ */
9
+ export type UV = [number, number];
10
+ /**
11
+ * Tile layout of a {@link TextureAtlas}.
12
+ *
13
+ * @category Textures
14
+ */
15
+ export interface AtlasParams {
16
+ /** pixels, default 16 */
17
+ tileWidth?: number;
18
+ /** pixels, default tileWidth */
19
+ tileHeight?: number;
20
+ /** pixels from the left edge before the first column, default 0 */
21
+ offsetX?: number;
22
+ /** pixels from the top edge before the first row, default 0 */
23
+ offsetY?: number;
24
+ /** pixels between neighbouring tiles, default 0 */
25
+ spacing?: number;
26
+ }
27
+ /**
28
+ * Tile layout and UV lookup for a texture atlas (tile sheet). Tiles are numbered left to
29
+ * right, top to bottom, starting at 0.
30
+ *
31
+ * Not a material: use `atlas.texture` as the `map` of any material, or `createMaterial()`
32
+ * for the common Lambert setup. The texture's `magFilter` is set to `NearestFilter`.
33
+ *
34
+ * ```ts
35
+ * const atlas = await TextureAtlas.load('tiles.png', { tileWidth: 16 });
36
+ * const material = atlas.createMaterial();
37
+ * const [u, v] = atlas.getUV(5, 0, 0); // bottom-left of tile 5
38
+ * ```
39
+ *
40
+ * @category Textures
41
+ */
42
+ export declare class TextureAtlas {
43
+ /** the whole sheet */
44
+ readonly texture: Texture;
45
+ /** texture size in pixels */
46
+ readonly width: number;
47
+ /** texture size in pixels */
48
+ readonly height: number;
49
+ /** pixels */
50
+ readonly tileWidth: number;
51
+ /** pixels */
52
+ readonly tileHeight: number;
53
+ /** pixels from the left edge before the first column */
54
+ readonly offsetX: number;
55
+ /** pixels from the top edge before the first row */
56
+ readonly offsetY: number;
57
+ /** pixels between neighbouring tiles */
58
+ readonly spacing: number;
59
+ /** tiles per row */
60
+ readonly columns: number;
61
+ /** tiles per column (only whole tiles count) */
62
+ readonly rows: number;
63
+ /** `columns * rows` */
64
+ get tileCount(): number;
65
+ constructor(textureData: TextureData, params?: AtlasParams);
66
+ /** Loads the image at `url` (see {@link LoadTexture}) and builds an atlas from it. */
67
+ static load(url: string, params?: AtlasParams): Promise<TextureAtlas>;
68
+ /**
69
+ * UV of a point inside a tile. `u` and `v` are in [0, 1] across the tile, with (0, 0) at the
70
+ * tile's bottom-left and (1, 1) at its top-right, matching three.js (v = 1 is the image's top).
71
+ */
72
+ getUV(tile: number, u: number, v: number): UV;
73
+ /** a Lambert material using this atlas, set up for pixel-art tiles with transparency */
74
+ createMaterial(params?: MeshLambertMaterialParameters): MeshLambertMaterial;
75
+ }
76
+ //#endregion
@@ -0,0 +1,84 @@
1
+ import { LoadTexture } from "./texture-utils.js";
2
+ import { MeshLambertMaterial, NearestFilter } from "three";
3
+ //#region src/three/texture-atlas.ts
4
+ /**
5
+ * Tile layout and UV lookup for a texture atlas (tile sheet). Tiles are numbered left to
6
+ * right, top to bottom, starting at 0.
7
+ *
8
+ * Not a material: use `atlas.texture` as the `map` of any material, or `createMaterial()`
9
+ * for the common Lambert setup. The texture's `magFilter` is set to `NearestFilter`.
10
+ *
11
+ * ```ts
12
+ * const atlas = await TextureAtlas.load('tiles.png', { tileWidth: 16 });
13
+ * const material = atlas.createMaterial();
14
+ * const [u, v] = atlas.getUV(5, 0, 0); // bottom-left of tile 5
15
+ * ```
16
+ *
17
+ * @category Textures
18
+ */
19
+ var TextureAtlas = class TextureAtlas {
20
+ /** the whole sheet */
21
+ texture;
22
+ /** texture size in pixels */
23
+ width;
24
+ /** texture size in pixels */
25
+ height;
26
+ /** pixels */
27
+ tileWidth;
28
+ /** pixels */
29
+ tileHeight;
30
+ /** pixels from the left edge before the first column */
31
+ offsetX;
32
+ /** pixels from the top edge before the first row */
33
+ offsetY;
34
+ /** pixels between neighbouring tiles */
35
+ spacing;
36
+ /** tiles per row */
37
+ columns;
38
+ /** tiles per column (only whole tiles count) */
39
+ rows;
40
+ /** `columns * rows` */
41
+ get tileCount() {
42
+ return this.columns * this.rows;
43
+ }
44
+ constructor(textureData, params = {}) {
45
+ this.texture = textureData.texture;
46
+ this.texture.magFilter = NearestFilter;
47
+ this.width = textureData.width;
48
+ this.height = textureData.height;
49
+ this.tileWidth = params.tileWidth ?? 16;
50
+ this.tileHeight = params.tileHeight ?? this.tileWidth;
51
+ this.offsetX = params.offsetX ?? 0;
52
+ this.offsetY = params.offsetY ?? 0;
53
+ this.spacing = params.spacing ?? 0;
54
+ this.columns = Math.floor((this.width - this.offsetX + this.spacing) / (this.tileWidth + this.spacing));
55
+ this.rows = Math.floor((this.height - this.offsetY + this.spacing) / (this.tileHeight + this.spacing));
56
+ }
57
+ /** Loads the image at `url` (see {@link LoadTexture}) and builds an atlas from it. */
58
+ static load(url, params) {
59
+ return LoadTexture(url).then((textureData) => new TextureAtlas(textureData, params));
60
+ }
61
+ /**
62
+ * UV of a point inside a tile. `u` and `v` are in [0, 1] across the tile, with (0, 0) at the
63
+ * tile's bottom-left and (1, 1) at its top-right, matching three.js (v = 1 is the image's top).
64
+ */
65
+ getUV(tile, u, v) {
66
+ const column = tile % this.columns;
67
+ const row = Math.floor(tile / this.columns);
68
+ const x = this.offsetX + column * (this.tileWidth + this.spacing) + u * this.tileWidth;
69
+ const y = this.offsetY + row * (this.tileHeight + this.spacing) + (1 - v) * this.tileHeight;
70
+ return [x / this.width, 1 - y / this.height];
71
+ }
72
+ /** a Lambert material using this atlas, set up for pixel-art tiles with transparency */
73
+ createMaterial(params = {}) {
74
+ return new MeshLambertMaterial({
75
+ map: this.texture,
76
+ alphaTest: .1,
77
+ transparent: true,
78
+ name: "TextureAtlas",
79
+ ...params
80
+ });
81
+ }
82
+ };
83
+ //#endregion
84
+ export { TextureAtlas };
@@ -0,0 +1,31 @@
1
+ import { Texture } from "three";
2
+ //#region src/three/texture-utils.d.ts
3
+ /**
4
+ * A loaded texture with its image size, as returned by {@link LoadTexture}.
5
+ *
6
+ * @category Textures
7
+ */
8
+ export interface TextureData {
9
+ /** image width in pixels */
10
+ width: number;
11
+ /** image height in pixels */
12
+ height: number;
13
+ /** the loaded texture */
14
+ texture: Texture<any>;
15
+ }
16
+ /**
17
+ * Loads an image into a `Texture` with three's `TextureLoader`.
18
+ *
19
+ * @returns resolves once the image has loaded; rejects with the loader's error
20
+ * @category Textures
21
+ */
22
+ export declare function LoadTexture(url: string): Promise<TextureData>;
23
+ /**
24
+ * A clone of `texture` showing only the rectangle at (x, y) of size w x h, in pixels with y measured
25
+ * from the image's top, via `offset` / `repeat`. Sets `magFilter` to `NearestFilter` and `wrapS` / `wrapT`
26
+ * to `RepeatWrapping`. The clone shares the source image, so no pixels are copied.
27
+ *
28
+ * @category Textures
29
+ */
30
+ export declare function CreateSubTexture(texture: Texture, x: number, y: number, w: number, h: number): Texture;
31
+ //#endregion
@@ -0,0 +1,44 @@
1
+ import { NearestFilter, RepeatWrapping, TextureLoader } from "three";
2
+ //#region src/three/texture-utils.ts
3
+ /**
4
+ * Loads an image into a `Texture` with three's `TextureLoader`.
5
+ *
6
+ * @returns resolves once the image has loaded; rejects with the loader's error
7
+ * @category Textures
8
+ */
9
+ function LoadTexture(url) {
10
+ return new Promise((res, rej) => {
11
+ new TextureLoader().load(url, (texture) => {
12
+ const width = texture.source.data.width;
13
+ const height = texture.source.data.height;
14
+ res({
15
+ width,
16
+ height,
17
+ texture
18
+ });
19
+ }, (_ev) => {}, (err) => rej(err));
20
+ });
21
+ }
22
+ /**
23
+ * A clone of `texture` showing only the rectangle at (x, y) of size w x h, in pixels with y measured
24
+ * from the image's top, via `offset` / `repeat`. Sets `magFilter` to `NearestFilter` and `wrapS` / `wrapT`
25
+ * to `RepeatWrapping`. The clone shares the source image, so no pixels are copied.
26
+ *
27
+ * @category Textures
28
+ */
29
+ function CreateSubTexture(texture, x, y, w, h) {
30
+ const subTexture = texture.clone();
31
+ subTexture.magFilter = NearestFilter;
32
+ subTexture.wrapS = RepeatWrapping;
33
+ subTexture.wrapT = RepeatWrapping;
34
+ w /= subTexture.width;
35
+ h /= subTexture.height;
36
+ x /= subTexture.width;
37
+ y = 1 - h - y / subTexture.height;
38
+ subTexture.offset.set(x, y);
39
+ subTexture.repeat.set(w, h);
40
+ subTexture.needsUpdate = true;
41
+ return subTexture;
42
+ }
43
+ //#endregion
44
+ export { CreateSubTexture, LoadTexture };
@@ -0,0 +1,72 @@
1
+ import { ColorPalette } from "../color-palette.js";
2
+ import { Map3D } from "../map3d.js";
3
+ import { BufferGeometry } from "three";
4
+ //#region src/three/voxel-geometry.d.ts
5
+ /**
6
+ * Options for {@link buildVoxelGeometry} and {@link VoxelGeometry}.
7
+ *
8
+ * @category Voxels
9
+ */
10
+ export interface BuildVoxelGeometryOptions {
11
+ /** voxel value -> 0xRRGGBB (sRGB) */
12
+ palette?: ColorPalette;
13
+ /** color for values the palette doesn't cover; default: a stable color hashed from the value */
14
+ missingColor?: number;
15
+ /** voxel lookup where this map has none (e.g. neighbouring chunks) */
16
+ neighbor?: (x: number, y: number, z: number) => number;
17
+ /** also emit faces between two solid voxels. Default false. */
18
+ includeHiddenFaces?: boolean;
19
+ /** merge same-looking faces into larger quads. Default true. */
20
+ greedy?: boolean;
21
+ /** darken vertices in corners and creases. Default true. */
22
+ ambientOcclusion?: boolean;
23
+ /** 0..1: how dark the most occluded corner gets. Default 0.5. */
24
+ aoStrength?: number;
25
+ /** rebuild into this geometry instead of creating one */
26
+ target?: BufferGeometry;
27
+ }
28
+ /**
29
+ * Builds a mesh for the voxels in `voxels`: one quad per visible face, merged into larger quads
30
+ * (`greedy`) and shaded with per-vertex ambient occlusion. A voxel's value is its palette index;
31
+ * the map's default value means empty.
32
+ *
33
+ * Positions are in the map's own coordinates, so a chunk stored in chunk-local coordinates is
34
+ * placed by positioning its mesh. Pass `neighbor` so faces against neighbouring chunks are culled
35
+ * and their voxels count for ambient occlusion.
36
+ *
37
+ * The geometry has position, normal and color attributes and an index; use a material with
38
+ * `vertexColors: true`. The output is deterministic: the same voxels and options always produce
39
+ * the same buffers.
40
+ *
41
+ * ```ts
42
+ * const voxels = new Map3D();
43
+ * voxels.setArea(0, 0, 0, 7, 0, 7, 0); // 8x1x8 slab of palette index 0
44
+ * voxels.set(3, 1, 3, 1);
45
+ *
46
+ * const geometry = buildVoxelGeometry(voxels, { palette: [0x55aa33, 0x8b5a2b] });
47
+ * scene.add(new Mesh(geometry, new MeshLambertMaterial({ vertexColors: true })));
48
+ * ```
49
+ *
50
+ * @returns `options.target` if given, otherwise a new geometry
51
+ * @category Voxels
52
+ */
53
+ export declare function buildVoxelGeometry(voxels: Map3D, options?: BuildVoxelGeometryOptions): BufferGeometry;
54
+ /**
55
+ * Geometry that owns its voxels; call `update()` after changing them. See
56
+ * {@link buildVoxelGeometry} for how voxels are meshed, and {@link VoxelMesh} for an editable mesh
57
+ * that tracks changes for you.
58
+ *
59
+ * @category Voxels
60
+ */
61
+ export declare class VoxelGeometry extends BufferGeometry {
62
+ type: string;
63
+ /** voxel data (palette indices); the map's default value is empty */
64
+ voxels: Map3D;
65
+ /** meshing options used by every `update()` */
66
+ options: Omit<BuildVoxelGeometryOptions, 'target'>;
67
+ /** Builds the geometry right away. */
68
+ constructor(voxels?: Map3D, options?: Omit<BuildVoxelGeometryOptions, 'target'>);
69
+ /** Rebuilds the geometry from `voxels` and `options`. */
70
+ update(): this;
71
+ }
72
+ //#endregion