@margoengine/voxel-edit 0.0.0-stage → 1.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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +445 -2
- package/dist/animation.d.ts +50 -0
- package/dist/animation.js +88 -0
- package/dist/assist.d.ts +24 -0
- package/dist/assist.js +52 -0
- package/dist/brush-gpu.d.ts +62 -0
- package/dist/bytes.d.ts +55 -0
- package/dist/collab.d.ts +77 -0
- package/dist/collab.js +159 -0
- package/dist/edit.d.ts +30 -0
- package/dist/edit.js +361 -0
- package/dist/export.d.ts +58 -0
- package/dist/export.js +52 -0
- package/dist/file-colors-DHT5vrzW.js +55 -0
- package/dist/file-colors.d.ts +16 -0
- package/dist/format-plist.d.ts +4 -0
- package/dist/formats-extra.d.ts +20 -0
- package/dist/formats-extra.js +335 -0
- package/dist/formats.d.ts +96 -0
- package/dist/formats.js +924 -0
- package/dist/generate.d.ts +63 -0
- package/dist/generate.js +103 -0
- package/dist/gox.d.ts +60 -0
- package/dist/gpu.d.ts +74 -0
- package/dist/gpu.js +167 -0
- package/dist/grid-B2V0TGLV.js +120 -0
- package/dist/grid.d.ts +75 -0
- package/dist/history.d.ts +65 -0
- package/dist/history.js +75 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +631 -0
- package/dist/layout.d.ts +76 -0
- package/dist/library.d.ts +50 -0
- package/dist/library.js +89 -0
- package/dist/mesh.d.ts +128 -0
- package/dist/mesh.js +365 -0
- package/dist/model.d.ts +173 -0
- package/dist/pick.d.ts +34 -0
- package/dist/pick.js +122 -0
- package/dist/raster.d.ts +89 -0
- package/dist/rig.d.ts +88 -0
- package/dist/rig.js +216 -0
- package/dist/select.d.ts +50 -0
- package/dist/select.js +94 -0
- package/dist/shaders-BaY4gcm9.js +234 -0
- package/dist/shaders.d.ts +116 -0
- package/dist/shaders.js +1 -0
- package/dist/slices.d.ts +75 -0
- package/dist/smooth.d.ts +43 -0
- package/dist/smooth.js +212 -0
- package/dist/sparse.d.ts +239 -0
- package/dist/sparse.js +646 -0
- package/dist/stamp.d.ts +88 -0
- package/dist/vmax.d.ts +48 -0
- package/dist/vox-resolve.d.ts +64 -0
- package/dist/vox-scene.d.ts +51 -0
- package/dist/vox.d.ts +30 -0
- package/dist/vox.js +684 -0
- package/dist/voxelize.d.ts +70 -0
- package/dist/voxelize.js +249 -0
- package/dist/vxm.d.ts +54 -0
- package/package.json +130 -4
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { MutableVec3, Vec3 } from '@margoengine/math';
|
|
2
|
+
import { type GridEdit, type GridLimits, type VoxelGrid } from './grid.js';
|
|
3
|
+
/** Options every layout operation takes. */
|
|
4
|
+
export interface GridLayoutOptions extends GridLimits {
|
|
5
|
+
/** Selected cells of the input, as cell indexes; the result maps them too, selected air included. */
|
|
6
|
+
selection?: Iterable<number>;
|
|
7
|
+
}
|
|
8
|
+
/** What a layout operation returns: a {@link GridEdit} plus the cell and point mapping it applied. */
|
|
9
|
+
export interface GridLayout extends GridEdit {
|
|
10
|
+
/** The selected cells that stay inside, as indexes of the result, in input order; empty without a selection. */
|
|
11
|
+
selection: Float64Array;
|
|
12
|
+
/**
|
|
13
|
+
* The same mapping for a continuous point in corner coordinates (a pivot or a joint): the input's (0, 0, 0) corner
|
|
14
|
+
* and far corner map onto the result's box exactly as the cells do.
|
|
15
|
+
*/
|
|
16
|
+
mapPoint(point: Vec3): MutableVec3;
|
|
17
|
+
}
|
|
18
|
+
/** Options of {@link flipGrid}. */
|
|
19
|
+
export interface FlipOptions extends GridLayoutOptions {
|
|
20
|
+
/** The axis to reverse: cell `c` moves to `size - 1 - c`. */
|
|
21
|
+
axis: 'x' | 'y' | 'z';
|
|
22
|
+
}
|
|
23
|
+
/** Options of {@link turnGrid}. */
|
|
24
|
+
export interface TurnOptions extends GridLayoutOptions {
|
|
25
|
+
/** The axis to turn about. */
|
|
26
|
+
axis: 'x' | 'y' | 'z';
|
|
27
|
+
/** Right-handed quarter turns, any whole number (negative turns the other way). Default 1. */
|
|
28
|
+
turns?: number;
|
|
29
|
+
}
|
|
30
|
+
/** Options of {@link shiftGrid}. */
|
|
31
|
+
export interface ShiftOptions extends GridLayoutOptions {
|
|
32
|
+
/** Whole cells to move along x, y and z; cells leaving the box are dropped. */
|
|
33
|
+
offset: Vec3;
|
|
34
|
+
}
|
|
35
|
+
/** Options of {@link cropGrid}. */
|
|
36
|
+
export interface CropOptions extends GridLayoutOptions {
|
|
37
|
+
/** The input cell that becomes the result's (0, 0, 0); it may lie outside the input (the new cells are air). */
|
|
38
|
+
origin: Vec3;
|
|
39
|
+
/** Cells of the result along x, y and z, each at least 1. */
|
|
40
|
+
size: Vec3;
|
|
41
|
+
}
|
|
42
|
+
/** Options of {@link invertGrid}. */
|
|
43
|
+
export interface InvertOptions extends GridLimits {
|
|
44
|
+
/** Palette index of the cells that were air, 1-255. */
|
|
45
|
+
color: number;
|
|
46
|
+
}
|
|
47
|
+
/** Mirrors a grid along one principal axis, keeping its size: cell `c` on that axis moves to `size - 1 - c`. */
|
|
48
|
+
export declare function flipGrid(grid: VoxelGrid, options: FlipOptions): GridLayout;
|
|
49
|
+
/**
|
|
50
|
+
* Turns a grid by right-handed quarter turns about one axis; the two other sizes swap with each odd turn, so nothing
|
|
51
|
+
* is clipped. One turn about x maps cell (x, y, z) to (x, sz - 1 - z, y) in a grid of [sx, sz, sy]; about y,
|
|
52
|
+
* (z, y, sx - 1 - x) in [sz, sy, sx]; about z, (sy - 1 - y, x, z) in [sy, sx, sz].
|
|
53
|
+
*/
|
|
54
|
+
export declare function turnGrid(grid: VoxelGrid, options: TurnOptions): GridLayout;
|
|
55
|
+
/** Moves every cell by a whole-cell offset inside the same box; filled cells leaving it are dropped and counted. */
|
|
56
|
+
export declare function shiftGrid(grid: VoxelGrid, options: ShiftOptions): GridLayout;
|
|
57
|
+
/** The box of filled cells, `max` exclusive, or null when the grid holds no filled cell. */
|
|
58
|
+
export declare function occupiedBounds(grid: VoxelGrid, limits?: GridLimits): {
|
|
59
|
+
min: MutableVec3;
|
|
60
|
+
max: MutableVec3;
|
|
61
|
+
} | null;
|
|
62
|
+
/**
|
|
63
|
+
* Crops or extends a grid to `size` cells anchored at `origin`: input cell `origin + c` becomes result cell `c`, every
|
|
64
|
+
* cell keeps its palette index, cells past the input are air and filled cells outside the new box are clipped. A
|
|
65
|
+
* resize that keeps the lower corner is `origin` [0, 0, 0]; {@link fitGrid} shrinks to the filled cells.
|
|
66
|
+
*/
|
|
67
|
+
export declare function cropGrid(grid: VoxelGrid, options: CropOptions): GridLayout;
|
|
68
|
+
/**
|
|
69
|
+
* Shrinks a grid to the box of its filled cells ({@link occupiedBounds}); `origin` is that box's lower corner, the
|
|
70
|
+
* input cell now at (0, 0, 0). An empty grid keeps its whole box, origin [0, 0, 0].
|
|
71
|
+
*/
|
|
72
|
+
export declare function fitGrid(grid: VoxelGrid, options?: GridLayoutOptions): GridLayout & {
|
|
73
|
+
origin: MutableVec3;
|
|
74
|
+
};
|
|
75
|
+
/** Swaps filled and empty cells: filled cells become air and air takes `color`, in the same box. */
|
|
76
|
+
export declare function invertGrid(grid: VoxelGrid, options: InvertOptions): GridEdit;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** One entry in a library index. */
|
|
2
|
+
export interface LibraryEntry {
|
|
3
|
+
/** Stable id. */
|
|
4
|
+
id: string;
|
|
5
|
+
/** Display name. */
|
|
6
|
+
name: string;
|
|
7
|
+
/** URL of the .vox file, absolute or resolved against the index URL. */
|
|
8
|
+
url: string;
|
|
9
|
+
/** Optional author. */
|
|
10
|
+
author?: string;
|
|
11
|
+
/** Optional tags. */
|
|
12
|
+
tags?: string[];
|
|
13
|
+
/** Optional preview image URL. */
|
|
14
|
+
preview?: string;
|
|
15
|
+
}
|
|
16
|
+
/** A library index: a JSON document listing assets. */
|
|
17
|
+
export interface LibraryIndex {
|
|
18
|
+
/** Index format version. Currently 1. */
|
|
19
|
+
version: number;
|
|
20
|
+
/** Assets. */
|
|
21
|
+
assets: LibraryEntry[];
|
|
22
|
+
}
|
|
23
|
+
/** Options of {@link fetchLibrary} and {@link fetchAsset}. */
|
|
24
|
+
export interface LibraryFetchOptions {
|
|
25
|
+
/** Fetch for the index and assets, for example an AssetCache's or a LoadingManager's `fetch`. Default `globalThis.fetch`. */
|
|
26
|
+
fetch?: typeof fetch;
|
|
27
|
+
/** Aborts the request. */
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
/** Largest response body, in bytes; reading stops there. Default 32 MiB. */
|
|
30
|
+
maxBytes?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Resolve `assetUrl` against `indexUrl`. An absolute asset URL is kept. A protocol-relative asset
|
|
34
|
+
* (`//host/path`) keeps its host. A relative index is resolved against `documentBase` when that base is
|
|
35
|
+
* absolute (the page URL, or the fetch `Response.url`). With no absolute base no origin is invented: a root-path
|
|
36
|
+
* index (`/library/index.json`) gives a root path, a protocol-relative one a protocol-relative URL, and a relative
|
|
37
|
+
* one (`library/index.json`) a URL relative to the same place (`library/tree.vox`).
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveLibraryUrl(indexUrl: string, assetUrl: string, documentBase?: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Fetch a library index and resolve asset URLs against the index URL.
|
|
42
|
+
* @throws MargoError `failed` on an HTTP error status; TypeError or RangeError on a bad document or a body over
|
|
43
|
+
* `maxBytes`; the fetch's own error when the request is aborted.
|
|
44
|
+
*/
|
|
45
|
+
export declare function fetchLibrary(indexUrl: string, options?: LibraryFetchOptions): Promise<LibraryIndex>;
|
|
46
|
+
/**
|
|
47
|
+
* Fetch one asset's bytes.
|
|
48
|
+
* @throws MargoError `failed` on an HTTP error status; RangeError when the body exceeds `maxBytes`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function fetchAsset(entry: LibraryEntry, options?: LibraryFetchOptions): Promise<ArrayBuffer>;
|
package/dist/library.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { MargoError as e } from "@margoengine/math/errors";
|
|
2
|
+
//#region src/library.ts
|
|
3
|
+
var t = 33554432, n = 1e4, r = "https://library.invalid/", i = "margo-library-base", a = 32, o = `${i}/`.repeat(a);
|
|
4
|
+
function s(e, t, n) {
|
|
5
|
+
if (typeof e != "string" || !e) throw TypeError("Library index URL must be a non-empty string");
|
|
6
|
+
if (typeof t != "string" || !t) throw TypeError("Library asset URL must be a non-empty string");
|
|
7
|
+
if (h(t)) return t;
|
|
8
|
+
let s = m(e, n);
|
|
9
|
+
if (t.startsWith("//")) return s ? new URL(t, s).href : t;
|
|
10
|
+
if (s) return new URL(t, s).href;
|
|
11
|
+
let c = e.startsWith("/"), l = new URL(t, new URL(e, c ? r : r + o)), u = l.search + l.hash;
|
|
12
|
+
if (e.startsWith("//")) return `//${l.host}${l.pathname}${u}`;
|
|
13
|
+
if (c) return l.pathname + u;
|
|
14
|
+
let d = l.pathname.slice(1).split("/"), f = a;
|
|
15
|
+
for (; f && d[0] === i;) d.shift(), f--;
|
|
16
|
+
return "../".repeat(f) + d.join("/") + u;
|
|
17
|
+
}
|
|
18
|
+
async function c(e, t = {}) {
|
|
19
|
+
let r = await d(e, t), i = r.json;
|
|
20
|
+
if (!i || typeof i != "object" || !Array.isArray(i.assets)) throw TypeError("Library index has no assets array; the index must be {version: 1, assets: [...]}");
|
|
21
|
+
if (i.version !== 1) throw RangeError(`Library index version ${String(i.version)} is not 1; use a version 1 index`);
|
|
22
|
+
if (i.assets.length > n) throw RangeError(`Library index lists more than ${n} assets; split the library into several indexes`);
|
|
23
|
+
return {
|
|
24
|
+
version: 1,
|
|
25
|
+
assets: i.assets.map((e, t) => u(e, t, r.base))
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async function l(t, n = {}) {
|
|
29
|
+
let r = f(n), i = await (n.fetch ?? fetch)(t.url, { signal: n.signal });
|
|
30
|
+
if (!i.ok) throw new e("failed", `Library asset ${t.id} returned ${i.status}; check its URL`);
|
|
31
|
+
return p(i, r, t.url);
|
|
32
|
+
}
|
|
33
|
+
function u(e, t, n) {
|
|
34
|
+
if (!e || typeof e != "object") throw TypeError(`Library asset ${t} is not an object; list each asset as {id, ...}`);
|
|
35
|
+
let r = e;
|
|
36
|
+
if (typeof r.id != "string" || !r.id) throw TypeError(`Library asset ${t} needs a string id`);
|
|
37
|
+
if (typeof r.name != "string" || !r.name) throw TypeError(`Library asset ${t} needs a string name`);
|
|
38
|
+
if (typeof r.url != "string" || !r.url) throw TypeError(`Library asset ${t} needs a string url`);
|
|
39
|
+
return {
|
|
40
|
+
id: r.id,
|
|
41
|
+
name: r.name,
|
|
42
|
+
url: s(n, r.url),
|
|
43
|
+
...typeof r.author == "string" ? { author: r.author } : {},
|
|
44
|
+
...Array.isArray(r.tags) ? { tags: r.tags.filter((e) => typeof e == "string") } : {},
|
|
45
|
+
...typeof r.preview == "string" ? { preview: s(n, r.preview) } : {}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async function d(t, n) {
|
|
49
|
+
let r = f(n), i = await (n.fetch ?? fetch)(t, { signal: n.signal });
|
|
50
|
+
if (!i.ok) throw new e("failed", `Library index ${t} returned ${i.status}; check the URL`);
|
|
51
|
+
let a = await p(i, r, t), o = h(i.url) ? i.url : t;
|
|
52
|
+
return {
|
|
53
|
+
json: JSON.parse(new TextDecoder().decode(a)),
|
|
54
|
+
base: o
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function f(e) {
|
|
58
|
+
let n = e.maxBytes ?? t;
|
|
59
|
+
if (!Number.isSafeInteger(n) || n < 0) throw RangeError(`Library maxBytes is ${n}; pass a whole number of bytes, 0 or more`);
|
|
60
|
+
return n;
|
|
61
|
+
}
|
|
62
|
+
async function p(e, t, n) {
|
|
63
|
+
let r = Number(e.headers.get("content-length")), i = (e) => /* @__PURE__ */ RangeError(`Library response ${n} is ${e} bytes, over ${t}; raise maxBytes or serve a smaller file`);
|
|
64
|
+
if (Number.isFinite(r) && r > t) throw i(r);
|
|
65
|
+
if (!e.body) {
|
|
66
|
+
let n = await e.arrayBuffer();
|
|
67
|
+
if (n.byteLength > t) throw i(n.byteLength);
|
|
68
|
+
return n;
|
|
69
|
+
}
|
|
70
|
+
let a = e.body.getReader(), o = [], s = 0;
|
|
71
|
+
for (;;) {
|
|
72
|
+
let { done: e, value: n } = await a.read();
|
|
73
|
+
if (e) break;
|
|
74
|
+
if (s += n.byteLength, s > t) throw await a.cancel(), i(s);
|
|
75
|
+
o.push(n);
|
|
76
|
+
}
|
|
77
|
+
let c = new Uint8Array(s), l = 0;
|
|
78
|
+
for (let e of o) c.set(e, l), l += e.byteLength;
|
|
79
|
+
return c.buffer;
|
|
80
|
+
}
|
|
81
|
+
function m(e, t) {
|
|
82
|
+
if (h(e)) return e;
|
|
83
|
+
if (t && h(t)) return new URL(e, t).href;
|
|
84
|
+
}
|
|
85
|
+
function h(e) {
|
|
86
|
+
return /^[a-z][a-z0-9+.-]*:/i.test(e);
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
export { l as fetchAsset, c as fetchLibrary, s as resolveLibraryUrl };
|
package/dist/mesh.d.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { MutableVec3, Vec3 } from '@margoengine/math';
|
|
2
|
+
import { type VoxelGrid } from './grid.js';
|
|
3
|
+
import { SparseGrid } from './sparse.js';
|
|
4
|
+
/** Options of {@link meshGrid}. */
|
|
5
|
+
export interface GridMeshOptions {
|
|
6
|
+
/** Point subtracted from every vertex, in cells (the model's pivot). Default [0, 0, 0]. */
|
|
7
|
+
pivot?: Vec3;
|
|
8
|
+
/** Bake corner ambient occlusion into {@link GridMesh.ao}; quads only merge across equal shading. Default false. */
|
|
9
|
+
ambientOcclusion?: boolean;
|
|
10
|
+
/** Average normals across edges between quads meeting within `creaseAngle`. Default false (flat faces). */
|
|
11
|
+
smoothNormals?: boolean;
|
|
12
|
+
/** Largest angle in degrees, 0 to 180, smoothed across. Default 180. */
|
|
13
|
+
creaseAngle?: number;
|
|
14
|
+
/** Most quads, 0 to 1,000,000. Default 1,000,000. */
|
|
15
|
+
maxQuads?: number;
|
|
16
|
+
/** Most cells scanned, 1 to 134,217,728 (a sparse grid scans its chunks). Default 134,217,728. */
|
|
17
|
+
maxCells?: number;
|
|
18
|
+
}
|
|
19
|
+
/** A voxel mesh: 4 vertices and 2 triangles per quad, quads in order, wound counterclockwise seen from outside. */
|
|
20
|
+
export interface GridMesh {
|
|
21
|
+
/** xyz per vertex, in cells, minus the pivot. */
|
|
22
|
+
positions: Float32Array;
|
|
23
|
+
/** Unit xyz per vertex. */
|
|
24
|
+
normals: Float32Array;
|
|
25
|
+
/** Per-vertex ambient light, 0.4 (corner closed in) to 1 (open), with `ambientOcclusion`; empty otherwise. */
|
|
26
|
+
ao: Float32Array;
|
|
27
|
+
/** Triangle vertex indexes. */
|
|
28
|
+
indices: Uint32Array;
|
|
29
|
+
/** Palette index of each quad (its 4 vertices). */
|
|
30
|
+
paletteIndexes: Uint8Array;
|
|
31
|
+
/** Bounds of `positions`; [0, 0, 0] for both when the mesh is empty. */
|
|
32
|
+
min: MutableVec3;
|
|
33
|
+
max: MutableVec3;
|
|
34
|
+
}
|
|
35
|
+
/** Counts of a {@link meshGrid} call. */
|
|
36
|
+
export interface MeshStats {
|
|
37
|
+
/** Filled cells scanned. */
|
|
38
|
+
voxels: number;
|
|
39
|
+
quads: number;
|
|
40
|
+
triangles: number;
|
|
41
|
+
vertices: number;
|
|
42
|
+
}
|
|
43
|
+
/** Options of {@link chamferGrid}. */
|
|
44
|
+
export interface ChamferOptions {
|
|
45
|
+
/** Chamfer width in cells, in (0, 0.5). */
|
|
46
|
+
bevel: number;
|
|
47
|
+
/** Point subtracted from every vertex, in cells. Default [0, 0, 0]. */
|
|
48
|
+
pivot?: Vec3;
|
|
49
|
+
/** Most quads, 0 to 1,000,000. Default 1,000,000. */
|
|
50
|
+
maxQuads?: number;
|
|
51
|
+
/** Most cells scanned, 1 to 134,217,728. Default 134,217,728. */
|
|
52
|
+
maxCells?: number;
|
|
53
|
+
}
|
|
54
|
+
/** Triangle mesh from {@link chamferGrid}. Not a quad mesh: do not pass it to {@link partitionMesh}. */
|
|
55
|
+
export interface ChamferMesh {
|
|
56
|
+
/** xyz per vertex, in cells, minus the pivot. */
|
|
57
|
+
positions: Float32Array;
|
|
58
|
+
/** Unit xyz per vertex. Face panels keep their cube normal; corners are shared. */
|
|
59
|
+
normals: Float32Array;
|
|
60
|
+
/** Triangle vertex indexes. */
|
|
61
|
+
indices: Uint32Array;
|
|
62
|
+
/** Palette index of the source face for each triangle, in triangle order. */
|
|
63
|
+
trianglePalette: Uint8Array;
|
|
64
|
+
/** Bounds of `positions`. */
|
|
65
|
+
min: MutableVec3;
|
|
66
|
+
max: MutableVec3;
|
|
67
|
+
}
|
|
68
|
+
/** Counts of a {@link chamferGrid} call. */
|
|
69
|
+
export interface ChamferStats {
|
|
70
|
+
/** Filled cells scanned. */
|
|
71
|
+
voxels: number;
|
|
72
|
+
/** Exposed faces before chamfering. */
|
|
73
|
+
quads: number;
|
|
74
|
+
triangles: number;
|
|
75
|
+
/**
|
|
76
|
+
* Faces whose inset was shortened. Always 0: the chamfer insets each unit edge of a face by `bevel`, below half a
|
|
77
|
+
* cell, so no panel can cross itself and nothing is shortened.
|
|
78
|
+
*/
|
|
79
|
+
clamped: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Meshes the faces between filled cells and air, merging same-index faces into rectangles (greedy meshing). Faces
|
|
83
|
+
* between two filled cells are never emitted, so a sparse grid's chunk seams leave no inner walls. The grid is read,
|
|
84
|
+
* never changed.
|
|
85
|
+
*/
|
|
86
|
+
export declare function meshGrid(source: VoxelGrid | SparseGrid, options?: GridMeshOptions): {
|
|
87
|
+
mesh: GridMesh;
|
|
88
|
+
stats: MeshStats;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Chamfers the exposed faces of a grid by `bevel` cells. The hard cubic mesh stays available from {@link meshGrid}
|
|
92
|
+
* (omit a chamfer). Faces between two filled cells are not emitted, so openings stay open. The chamfer is the
|
|
93
|
+
* face-edge-vertex construction of `@margoengine/voxel/bevel` (Doo and Sabin 1978): each face keeps a panel inset by
|
|
94
|
+
* `bevel` from its creased edges, each crease becomes a 45 degree strip, and each corner a closing polygon, so the
|
|
95
|
+
* mesh is closed. Each triangle keeps the palette of the face that owns it.
|
|
96
|
+
* @throws RangeError when `bevel` is outside (0, 0.5) or a budget is exceeded.
|
|
97
|
+
*/
|
|
98
|
+
export declare function chamferGrid(source: VoxelGrid | SparseGrid, options: ChamferOptions): {
|
|
99
|
+
mesh: ChamferMesh;
|
|
100
|
+
stats: ChamferStats;
|
|
101
|
+
};
|
|
102
|
+
/** Options of {@link partitionMesh}. */
|
|
103
|
+
export interface PartitionOptions {
|
|
104
|
+
/** Most quads per part, 1 to 250,000 (four vertices a quad, a materials mesh's 1,000,000). Default 250,000. */
|
|
105
|
+
maxQuads?: number;
|
|
106
|
+
}
|
|
107
|
+
/** One upload-sized part of a {@link GridMesh}: quads of one palette index, in mesh order, 4 vertices each. */
|
|
108
|
+
export interface MeshPart {
|
|
109
|
+
/** Palette index of every quad in the part. */
|
|
110
|
+
paletteIndex: number;
|
|
111
|
+
/** xyz per vertex, copied from the mesh. */
|
|
112
|
+
positions: Float32Array;
|
|
113
|
+
/** Unit xyz per vertex. */
|
|
114
|
+
normals: Float32Array;
|
|
115
|
+
/** Per-vertex ambient light; empty when the mesh has none. */
|
|
116
|
+
ao: Float32Array;
|
|
117
|
+
/** Triangle vertex indexes into this part's vertices. */
|
|
118
|
+
indices: Uint32Array;
|
|
119
|
+
/** The mesh's index of each quad in the part, in order. */
|
|
120
|
+
quads: Uint32Array;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Splits a mesh from {@link meshGrid} into parts one material mesh each can take (`createMesh` of
|
|
124
|
+
* `@margoengine/materials`, at most 1,000,000 vertices): quads are visited in mesh order and each goes to its palette
|
|
125
|
+
* index's open part, which closes once it holds `maxQuads`. Parts come in the order of their first quad; every
|
|
126
|
+
* attribute is copied, never recomputed.
|
|
127
|
+
*/
|
|
128
|
+
export declare function partitionMesh(mesh: GridMesh, options?: PartitionOptions): MeshPart[];
|