polystrata-3d 0.0.0-stage → 0.1.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 +21 -0
- package/README.md +91 -2
- package/dist/brep3d.d.ts +85 -0
- package/dist/brep3d.d.ts.map +1 -0
- package/dist/index.cjs +420 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +420 -0
- package/dist/types.d.ts +106 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/wasm-bytes.d.ts +2 -0
- package/dist/wasm-bytes.d.ts.map +1 -0
- package/dist/wasm-kernel.d.ts +37 -0
- package/dist/wasm-kernel.d.ts.map +1 -0
- package/package.json +74 -4
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard 2-body Boolean operation selector.
|
|
3
|
+
*/
|
|
4
|
+
export type BooleanOp = "union" | "intersect" | "difference" | "xor";
|
|
5
|
+
/**
|
|
6
|
+
* Winding rule used to classify inside/outside of a 3D solid from its signed 3D solid-angle winding number:
|
|
7
|
+
* - `"positive"`: `w >= 1` (standard CAD/B-Rep convention where outward shell = +1, interior void = -1)
|
|
8
|
+
* - `"nonZero"`: `w !== 0`
|
|
9
|
+
* - `"evenOdd"`: `|w| % 2 === 1`
|
|
10
|
+
*/
|
|
11
|
+
export type WindingRule = "positive" | "nonZero" | "evenOdd";
|
|
12
|
+
/**
|
|
13
|
+
* Configuration options for the 3D Stratified Tolerance Complex kernel.
|
|
14
|
+
*/
|
|
15
|
+
export interface KernelOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Explicit base snap tolerance `r0` in world units.
|
|
18
|
+
* When omitted or `<= 0`, the kernel automatically selects a scale-aware tolerance
|
|
19
|
+
* (`1e-9 * boundingBoxDiagonal`) and caps vertex tolerance ball growth at `r_max = 4 * r0`.
|
|
20
|
+
*/
|
|
21
|
+
snapTolerance?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Merge collinear degree-2 vertices on output boundary loops (default: `true`).
|
|
24
|
+
*/
|
|
25
|
+
simplifyCollinear?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Winding rule used to determine inside/outside for each input solid (default: `"positive"`).
|
|
28
|
+
*/
|
|
29
|
+
windingRule?: WindingRule;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A 3D point in IEEE-754 double-precision (`f64`) world coordinates.
|
|
33
|
+
*/
|
|
34
|
+
export interface Point3D {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
z: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A 3-element coordinate tuple `[x, y, z]`.
|
|
41
|
+
*/
|
|
42
|
+
export type TuplePoint3D = readonly [number, number, number];
|
|
43
|
+
/**
|
|
44
|
+
* A planar 3D polygon face with an outward-oriented outer boundary loop and zero or more interior holes.
|
|
45
|
+
*/
|
|
46
|
+
export interface Face3D {
|
|
47
|
+
/** Outer boundary loop in CCW order when viewed against `normal`. */
|
|
48
|
+
outer: Point3D[];
|
|
49
|
+
/** Optional interior hole loops in CW order when viewed against `normal`. */
|
|
50
|
+
holes: Point3D[][];
|
|
51
|
+
/** Outward unit normal vector `(nx, ny, nz)`. */
|
|
52
|
+
normal: Point3D;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A 3D planar Boundary-Representation (B-Rep) solid.
|
|
56
|
+
*/
|
|
57
|
+
export interface Solid3D {
|
|
58
|
+
faces: Face3D[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A single 3D surface triangle emitted by ear-clipping a `Face3D`.
|
|
62
|
+
*/
|
|
63
|
+
export interface Triangle3D {
|
|
64
|
+
a: Point3D;
|
|
65
|
+
b: Point3D;
|
|
66
|
+
c: Point3D;
|
|
67
|
+
normal: Point3D;
|
|
68
|
+
faceIndex: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Output of a 3D Boolean or topological healing operation.
|
|
72
|
+
*/
|
|
73
|
+
export interface BRepResult3D {
|
|
74
|
+
/** Closed watertight 3D planar B-Rep solid. */
|
|
75
|
+
solid: Solid3D;
|
|
76
|
+
/** Triangulated surface mesh of `solid` for immediate 3D WebGL/Canvas rendering. */
|
|
77
|
+
triangles: Triangle3D[];
|
|
78
|
+
/** Signed enclosed volume via the Divergence Theorem (`(1/6) ∑ a · (b × c)`). */
|
|
79
|
+
totalVolume: number;
|
|
80
|
+
/** Total boundary surface area. */
|
|
81
|
+
totalSurfaceArea: number;
|
|
82
|
+
/** Number of canonical 3D vertices (`0-strata`). */
|
|
83
|
+
vertexCount: number;
|
|
84
|
+
/** Number of canonical 3D edges (`1-strata`). */
|
|
85
|
+
edgeCount: number;
|
|
86
|
+
/** Number of unmatched directed half-edges (`0` for a closed watertight 2-manifold). */
|
|
87
|
+
unmatchedHalfEdgeCount: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Lightweight zero-copy TypedArray result returned by `prepareBooleanTask` / `prepareBooleanTask3D`.
|
|
91
|
+
*/
|
|
92
|
+
export interface WasmBRep3DResult {
|
|
93
|
+
readonly faceCount: number;
|
|
94
|
+
readonly loopCount: number;
|
|
95
|
+
readonly triangleCount: number;
|
|
96
|
+
readonly totalVolume: number;
|
|
97
|
+
readonly totalSurfaceArea: number;
|
|
98
|
+
readonly vertexCount: number;
|
|
99
|
+
readonly edgeCount: number;
|
|
100
|
+
readonly unmatchedHalfEdgeCount: number;
|
|
101
|
+
readonly coords: Float64Array;
|
|
102
|
+
readonly loopMeta: Uint32Array;
|
|
103
|
+
readonly faceNormals: Float64Array;
|
|
104
|
+
readonly triangles: Float64Array;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA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AmC;IACnC,gBAAgB,EAAE,MAAM,CAAC;IACzB,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,wFAAwF;IACxF,sBAAsB,EAAE,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;CAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-bytes.d.ts","sourceRoot":"","sources":["../src/wasm-bytes.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,WAAW,EAAE,MAAmijuB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface Polystrata3DWasmExports {
|
|
2
|
+
memory: WebAssembly.Memory;
|
|
3
|
+
wasm_brep3d_alloc_input: (f64Count: number) => number;
|
|
4
|
+
wasm_brep3d_execute: (opCode: number, windingRule: number, snapFactor: number, simplifyCollinear: number) => number;
|
|
5
|
+
wasm_brep3d_get_out_coords_ptr: () => number;
|
|
6
|
+
wasm_brep3d_get_out_coords_len: () => number;
|
|
7
|
+
wasm_brep3d_get_out_loop_meta_ptr: () => number;
|
|
8
|
+
wasm_brep3d_get_out_loop_count: () => number;
|
|
9
|
+
wasm_brep3d_get_out_face_normals_ptr: () => number;
|
|
10
|
+
wasm_brep3d_get_out_face_count: () => number;
|
|
11
|
+
wasm_brep3d_get_out_triangles_ptr: () => number;
|
|
12
|
+
wasm_brep3d_get_out_triangles_len: () => number;
|
|
13
|
+
wasm_brep3d_get_out_volume: () => number;
|
|
14
|
+
wasm_brep3d_get_out_area: () => number;
|
|
15
|
+
wasm_brep3d_get_out_vertex_count: () => number;
|
|
16
|
+
wasm_brep3d_get_out_edge_count: () => number;
|
|
17
|
+
wasm_brep3d_get_out_unmatched_he_count: () => number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Asynchronously initialize the embedded 3D WebAssembly module.
|
|
21
|
+
*
|
|
22
|
+
* In Node.js, Bun, Deno, and Web Workers, `polystrata-3d` initializes synchronously on first call
|
|
23
|
+
* so calling `initPolystrata3D()` is optional. On browser main threads that restrict synchronous
|
|
24
|
+
* `new WebAssembly.Module()` compilation for modules > 4 KB, call `await initPolystrata3D()` once
|
|
25
|
+
* at application startup before invoking synchronous 3D Boolean operations.
|
|
26
|
+
*/
|
|
27
|
+
export declare function initPolystrata3D(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Alias for {@link initPolystrata3D}.
|
|
30
|
+
*/
|
|
31
|
+
export declare const initPolystrata: typeof initPolystrata3D;
|
|
32
|
+
/**
|
|
33
|
+
* Alias for {@link initPolystrata3D}.
|
|
34
|
+
*/
|
|
35
|
+
export declare const initPolystrataWasm: typeof initPolystrata3D;
|
|
36
|
+
export declare function getWasm(): Polystrata3DWasmExports;
|
|
37
|
+
//# sourceMappingURL=wasm-kernel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-kernel.d.ts","sourceRoot":"","sources":["../src/wasm-kernel.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;IAC3B,uBAAuB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IACtD,mBAAmB,EAAE,CACnB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,MAAM,KACtB,MAAM,CAAC;IACZ,8BAA8B,EAAE,MAAM,MAAM,CAAC;IAC7C,8BAA8B,EAAE,MAAM,MAAM,CAAC;IAC7C,iCAAiC,EAAE,MAAM,MAAM,CAAC;IAChD,8BAA8B,EAAE,MAAM,MAAM,CAAC;IAC7C,oCAAoC,EAAE,MAAM,MAAM,CAAC;IACnD,8BAA8B,EAAE,MAAM,MAAM,CAAC;IAC7C,iCAAiC,EAAE,MAAM,MAAM,CAAC;IAChD,iCAAiC,EAAE,MAAM,MAAM,CAAC;IAChD,0BAA0B,EAAE,MAAM,MAAM,CAAC;IACzC,wBAAwB,EAAE,MAAM,MAAM,CAAC;IACvC,gCAAgC,EAAE,MAAM,MAAM,CAAC;IAC/C,8BAA8B,EAAE,MAAM,MAAM,CAAC;IAC7C,sCAAsC,EAAE,MAAM,MAAM,CAAC;CACtD;AAsBD;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAStD;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,yBAAmB,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,kBAAkB,yBAAmB,CAAC;AAEnD,wBAAgB,OAAO,IAAI,uBAAuB,CAcjD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,76 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polystrata-3d",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "High-performance 3D Planar B-Rep Boolean operations, coplanar face unification, and topological healing kernel powered by Rust/WebAssembly",
|
|
7
|
+
"homepage": "https://polystrata3d.ptrbyr.com",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/pboyer/polystrata-3d.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/pboyer/polystrata-3d/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"3d-boolean",
|
|
17
|
+
"csg",
|
|
18
|
+
"brep",
|
|
19
|
+
"mesh-boolean",
|
|
20
|
+
"boolean-operations",
|
|
21
|
+
"geometry",
|
|
22
|
+
"computational-geometry",
|
|
23
|
+
"cad",
|
|
24
|
+
"wasm",
|
|
25
|
+
"3d"
|
|
26
|
+
],
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE"
|
|
32
|
+
],
|
|
33
|
+
"main": "./dist/index.cjs",
|
|
34
|
+
"module": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"default": "./dist/index.js"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./dist/index.d.cts",
|
|
44
|
+
"default": "./dist/index.cjs"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"./package.json": "./package.json"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=18.0.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"dev": "vite",
|
|
54
|
+
"build:wasm": "cargo build --target wasm32-unknown-unknown --release && node -e \"const fs=require('fs');const b=fs.readFileSync('target/wasm32-unknown-unknown/release/polystrata_3d.wasm');fs.writeFileSync('src/wasm-bytes.ts','// Auto-generated from crates/polystrata-3d-wasm\\nexport const WASM_BASE64: string = \\\"'+b.toString('base64')+'\\\";\\n');\"",
|
|
55
|
+
"build": "vite build --config vite.lib.config.ts && tsc -p tsconfig.build.json && node -e \"require('fs').copyFileSync('dist/index.d.ts','dist/index.d.cts')\"",
|
|
56
|
+
"build:demo": "vite build",
|
|
57
|
+
"preview": "vite preview",
|
|
58
|
+
"bench": "tsx bench/run.ts",
|
|
59
|
+
"test": "vitest run",
|
|
60
|
+
"typecheck": "tsc --noEmit",
|
|
61
|
+
"prepublishOnly": "npm run build && npm test"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@jscad/modeling": "^2.13.0",
|
|
65
|
+
"@types/node": "^26.6.5",
|
|
66
|
+
"@types/three": "^0.186.0",
|
|
67
|
+
"manifold-3d": "^3.5.4",
|
|
68
|
+
"three": "^0.186.1",
|
|
69
|
+
"three-bvh-csg": "^0.0.18",
|
|
70
|
+
"three-mesh-bvh": "^0.9.16",
|
|
71
|
+
"tsx": "^4.23.15",
|
|
72
|
+
"typescript": "^5.6.3",
|
|
73
|
+
"vite": "^5.4.11",
|
|
74
|
+
"vitest": "^2.1.8"
|
|
75
|
+
}
|
|
76
|
+
}
|