@cadit-app/manifold-fillet 1.0.0 → 1.0.2

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.
@@ -4,7 +4,7 @@
4
4
  * Point-based selection: Find edges nearest to a 3D point
5
5
  * Angle-based selection: Find all edges sharper than a threshold angle
6
6
  */
7
- import { Manifold } from 'manifold-3d';
7
+ import type { Manifold } from 'manifold-3d';
8
8
  /** Point-based edge selection - fillet edge nearest to a point */
9
9
  export interface PointEdgeSelection {
10
10
  type: 'point';
package/dist/example.js CHANGED
@@ -1,13 +1,12 @@
1
1
  /**
2
- * Example usage of the fillet library in CADit environment.
2
+ * Example usage of the fillet library.
3
3
  *
4
- * In CADit, `manifold` is available as a global variable containing
5
- * the initialized Manifold WASM module.
4
+ * Works on both manifoldcad.org and CADit.
6
5
  */
7
6
  import { Manifold } from 'manifold-3d/manifoldCAD';
8
7
  import { createFillet } from './index';
9
- // Create fillet API bound to the manifold instance
10
- const { fillet } = createFillet(manifold);
8
+ // Create fillet API bound to the Manifold class
9
+ const { fillet } = createFillet(Manifold);
11
10
  const box = Manifold.cube([20, 20, 20], true);
12
11
  // Fillet the edge at position (10, 10, 0)
13
12
  const rounded = fillet(box, {
package/dist/fillet.d.ts CHANGED
@@ -10,7 +10,8 @@
10
10
  * 3. Subtract tube from wedge → cutting tool (just the corner tip)
11
11
  * 4. Subtract cutting tool from original → rounded edge
12
12
  */
13
- import type { Manifold, ManifoldToplevel } from 'manifold-3d';
13
+ import type { Manifold } from 'manifold-3d';
14
+ import type { ManifoldStatic } from './index';
14
15
  import { EdgeSelection } from './edgeSelection';
15
16
  export interface FilletOptions {
16
17
  /** Fillet radius */
@@ -23,10 +24,10 @@ export interface FilletOptions {
23
24
  /**
24
25
  * Apply fillet/round to selected edges of a Manifold.
25
26
  *
26
- * @param manifold - The initialized Manifold WASM module
27
+ * @param Manifold - The Manifold class with static constructors
27
28
  * @param mf - The Manifold shape to fillet
28
29
  * @param options - Fillet options (radius, selection, segments)
29
30
  * @returns A new Manifold with filleted edges
30
31
  */
31
- export declare function filletWithManifold(manifold: ManifoldToplevel, mf: Manifold, options: FilletOptions): Manifold;
32
+ export declare function filletWithManifold(Manifold: ManifoldStatic, mf: Manifold, options: FilletOptions): Manifold;
32
33
  export type { EdgeSelection, PointEdgeSelection, AngleEdgeSelection } from './edgeSelection';
package/dist/fillet.js CHANGED
@@ -14,12 +14,12 @@ import { extractEdges, selectEdges } from './edgeSelection';
14
14
  /**
15
15
  * Apply fillet/round to selected edges of a Manifold.
16
16
  *
17
- * @param manifold - The initialized Manifold WASM module
17
+ * @param Manifold - The Manifold class with static constructors
18
18
  * @param mf - The Manifold shape to fillet
19
19
  * @param options - Fillet options (radius, selection, segments)
20
20
  * @returns A new Manifold with filleted edges
21
21
  */
22
- export function filletWithManifold(manifold, mf, options) {
22
+ export function filletWithManifold(Manifold, mf, options) {
23
23
  const { radius, selection, segments = 16 } = options;
24
24
  if (radius <= 0) {
25
25
  throw new Error('Fillet radius must be positive');
@@ -45,7 +45,7 @@ export function filletWithManifold(manifold, mf, options) {
45
45
  // Only handling convex edges (standard fillets)
46
46
  // Filter out flat edges (dihedral angle approx 0) which are just triangulation artifacts
47
47
  if (edge.dihedralAngle > 5 && edge.dihedralAngle < 175) {
48
- const tool = createFilletCuttingTool(manifold, edge, radius, segments);
48
+ const tool = createFilletCuttingTool(Manifold, edge, radius, segments);
49
49
  if (tool && tool.volume() > 1e-9) {
50
50
  cuttingTools.push(tool);
51
51
  }
@@ -64,7 +64,7 @@ export function filletWithManifold(manifold, mf, options) {
64
64
  /**
65
65
  * Create a fillet cutting tool using the wedge-minus-tube approach.
66
66
  */
67
- function createFilletCuttingTool(manifold, edge, radius, segments) {
67
+ function createFilletCuttingTool(Manifold, edge, radius, segments) {
68
68
  // Edge endpoints
69
69
  const [x0, y0, z0] = edge.p0;
70
70
  const [x1, y1, z1] = edge.p1;
@@ -90,9 +90,9 @@ function createFilletCuttingTool(manifold, edge, radius, segments) {
90
90
  y1 - n0y * radius - n1y * radius + edgeDir[1] * ext,
91
91
  z1 - n0z * radius - n1z * radius + edgeDir[2] * ext
92
92
  ];
93
- const sphere0 = manifold.Manifold.sphere(radius, segments).translate(tubeStart);
94
- const sphere1 = manifold.Manifold.sphere(radius, segments).translate(tubeEnd);
95
- const tube = manifold.Manifold.hull([sphere0, sphere1]);
93
+ const sphere0 = Manifold.sphere(radius, segments).translate(tubeStart);
94
+ const sphere1 = Manifold.sphere(radius, segments).translate(tubeEnd);
95
+ const tube = Manifold.hull([sphere0, sphere1]);
96
96
  // 2. WEDGE: Triangular prism extending INWARD
97
97
  // CRITICAL: The wedge depth must be limited so it is completely contained
98
98
  // within the tube on the "back" side. If deeper than the tube, subtracting
@@ -110,7 +110,7 @@ function createFilletCuttingTool(manifold, edge, radius, segments) {
110
110
  wedgePoints.push([eX, eY, eZ]); // Edge
111
111
  wedgePoints.push([eX - n0x * wedgeDepth, eY - n0y * wedgeDepth, eZ - n0z * wedgeDepth]);
112
112
  wedgePoints.push([eX - n1x * wedgeDepth, eY - n1y * wedgeDepth, eZ - n1z * wedgeDepth]);
113
- const wedge = manifold.Manifold.hull(wedgePoints);
113
+ const wedge = Manifold.hull(wedgePoints);
114
114
  // 3. CUTTING TOOL: Wedge - Tube
115
115
  // Since wedge is small, wedge - tube leaves only the corner tip.
116
116
  return wedge.subtract(tube);
package/dist/index.d.ts CHANGED
@@ -3,22 +3,38 @@
3
3
  *
4
4
  * Usage:
5
5
  * ```typescript
6
+ * // Option 1: With full Manifold module
6
7
  * import ManifoldModule from 'manifold-3d';
7
8
  * import { createFillet } from '@cadit-app/brute-force-fillet';
8
9
  *
9
- * const manifold = await ManifoldModule();
10
- * const { fillet } = createFillet(manifold);
10
+ * const wasm = await ManifoldModule();
11
+ * const { fillet } = createFillet(wasm.Manifold);
11
12
  *
12
- * const box = manifold.Manifold.cube([10, 10, 10], true);
13
- * const rounded = fillet(box, { radius: 1, selection: { type: 'angle', minAngle: 80 } });
13
+ * // Option 2: With Manifold class directly (e.g., manifoldcad.org)
14
+ * import { Manifold } from 'manifold-3d/manifoldCAD';
15
+ * import { createFillet } from '@cadit-app/brute-force-fillet';
16
+ *
17
+ * const { fillet } = createFillet(Manifold);
14
18
  * ```
15
19
  */
16
- import type { Manifold, ManifoldToplevel } from 'manifold-3d';
20
+ import type { Manifold } from 'manifold-3d';
17
21
  import { FilletOptions } from './fillet';
18
22
  import { extractEdges, selectEdges, edgeDirection, edgeInwardDirection, sampleEdge, MeshEdge } from './edgeSelection';
19
- export type { ManifoldToplevel } from './context';
20
23
  export type { FilletOptions } from './fillet';
21
24
  export type { MeshEdge, EdgeSelection, PointEdgeSelection, AngleEdgeSelection } from './edgeSelection';
25
+ /**
26
+ * The Manifold class type with static constructors.
27
+ * This is what you get from `manifold.Manifold` or `import { Manifold } from 'manifold-3d/manifoldCAD'`.
28
+ */
29
+ export interface ManifoldStatic {
30
+ cube: (size: [number, number, number] | number, center?: boolean) => Manifold;
31
+ sphere: (radius: number, circularSegments?: number) => Manifold;
32
+ cylinder: (height: number, radiusLow: number, radiusHigh?: number, circularSegments?: number, center?: boolean) => Manifold;
33
+ hull: (manifolds: Manifold[] | [number, number, number][]) => Manifold;
34
+ union: (manifolds: Manifold[]) => Manifold;
35
+ intersection: (manifolds: Manifold[]) => Manifold;
36
+ difference: (manifolds: Manifold[]) => Manifold;
37
+ }
22
38
  /**
23
39
  * The fillet API returned by createFillet.
24
40
  */
@@ -65,28 +81,30 @@ export interface FilletAPI {
65
81
  sampleEdge: typeof sampleEdge;
66
82
  }
67
83
  /**
68
- * Creates a fillet API bound to a specific Manifold instance.
84
+ * Creates a fillet API bound to a specific Manifold class.
69
85
  *
70
- * @param manifold - The initialized Manifold WASM module (from `await ManifoldModule()`)
71
- * @returns An object containing all fillet functions bound to the manifold instance
86
+ * @param Manifold - The Manifold class with static constructors (cube, sphere, hull, etc.)
87
+ * @returns An object containing all fillet functions bound to the Manifold class
72
88
  *
73
89
  * @example
74
90
  * ```typescript
75
- * import ManifoldModule from 'manifold-3d';
91
+ * // On manifoldcad.org:
92
+ * import { Manifold } from 'manifold-3d/manifoldCAD';
76
93
  * import { createFillet } from '@cadit-app/brute-force-fillet';
77
94
  *
78
- * const manifold = await ManifoldModule();
79
- * const { fillet } = createFillet(manifold);
95
+ * const { fillet } = createFillet(Manifold);
96
+ * const box = Manifold.cube([10, 10, 10], true);
97
+ * const rounded = fillet(box, { radius: 1, selection: { type: 'angle', minAngle: 80 } });
80
98
  *
81
- * const box = manifold.Manifold.cube([10, 10, 10], true);
82
- * const rounded = fillet(box, {
83
- * radius: 1,
84
- * selection: { type: 'angle', minAngle: 80 }
85
- * });
99
+ * // In Node.js:
100
+ * import ManifoldModule from 'manifold-3d';
101
+ * const wasm = await ManifoldModule();
102
+ * const { fillet } = createFillet(wasm.Manifold);
86
103
  * ```
87
104
  */
88
- export declare function createFillet(manifold: ManifoldToplevel): FilletAPI;
105
+ export declare function createFillet(Manifold: ManifoldStatic): FilletAPI;
89
106
  export { extractEdges, selectEdges, edgeDirection, edgeInwardDirection, sampleEdge };
90
107
  export { filletWithManifold } from './fillet';
91
108
  export { pipeAlongPath, pipeAlongPathExtended } from './pipeAlongPath';
92
109
  export { buildWedge } from './wedgeBuilder';
110
+ export { default } from './example';
package/dist/index.js CHANGED
@@ -3,14 +3,18 @@
3
3
  *
4
4
  * Usage:
5
5
  * ```typescript
6
+ * // Option 1: With full Manifold module
6
7
  * import ManifoldModule from 'manifold-3d';
7
8
  * import { createFillet } from '@cadit-app/brute-force-fillet';
8
9
  *
9
- * const manifold = await ManifoldModule();
10
- * const { fillet } = createFillet(manifold);
10
+ * const wasm = await ManifoldModule();
11
+ * const { fillet } = createFillet(wasm.Manifold);
11
12
  *
12
- * const box = manifold.Manifold.cube([10, 10, 10], true);
13
- * const rounded = fillet(box, { radius: 1, selection: { type: 'angle', minAngle: 80 } });
13
+ * // Option 2: With Manifold class directly (e.g., manifoldcad.org)
14
+ * import { Manifold } from 'manifold-3d/manifoldCAD';
15
+ * import { createFillet } from '@cadit-app/brute-force-fillet';
16
+ *
17
+ * const { fillet } = createFillet(Manifold);
14
18
  * ```
15
19
  */
16
20
  import { filletWithManifold } from './fillet';
@@ -18,32 +22,33 @@ import { pipeAlongPath, pipeAlongPathExtended } from './pipeAlongPath';
18
22
  import { buildWedge } from './wedgeBuilder';
19
23
  import { extractEdges, selectEdges, edgeDirection, edgeInwardDirection, sampleEdge } from './edgeSelection';
20
24
  /**
21
- * Creates a fillet API bound to a specific Manifold instance.
25
+ * Creates a fillet API bound to a specific Manifold class.
22
26
  *
23
- * @param manifold - The initialized Manifold WASM module (from `await ManifoldModule()`)
24
- * @returns An object containing all fillet functions bound to the manifold instance
27
+ * @param Manifold - The Manifold class with static constructors (cube, sphere, hull, etc.)
28
+ * @returns An object containing all fillet functions bound to the Manifold class
25
29
  *
26
30
  * @example
27
31
  * ```typescript
28
- * import ManifoldModule from 'manifold-3d';
32
+ * // On manifoldcad.org:
33
+ * import { Manifold } from 'manifold-3d/manifoldCAD';
29
34
  * import { createFillet } from '@cadit-app/brute-force-fillet';
30
35
  *
31
- * const manifold = await ManifoldModule();
32
- * const { fillet } = createFillet(manifold);
36
+ * const { fillet } = createFillet(Manifold);
37
+ * const box = Manifold.cube([10, 10, 10], true);
38
+ * const rounded = fillet(box, { radius: 1, selection: { type: 'angle', minAngle: 80 } });
33
39
  *
34
- * const box = manifold.Manifold.cube([10, 10, 10], true);
35
- * const rounded = fillet(box, {
36
- * radius: 1,
37
- * selection: { type: 'angle', minAngle: 80 }
38
- * });
40
+ * // In Node.js:
41
+ * import ManifoldModule from 'manifold-3d';
42
+ * const wasm = await ManifoldModule();
43
+ * const { fillet } = createFillet(wasm.Manifold);
39
44
  * ```
40
45
  */
41
- export function createFillet(manifold) {
46
+ export function createFillet(Manifold) {
42
47
  return {
43
- fillet: (mf, options) => filletWithManifold(manifold, mf, options),
44
- pipeAlongPath: (path, radius, segments) => pipeAlongPath(manifold, path, radius, segments),
45
- pipeAlongPathExtended: (path, radius, extensionFactor, segments) => pipeAlongPathExtended(manifold, path, radius, extensionFactor, segments),
46
- buildWedge: (edge, distance, inflate) => buildWedge(manifold, edge, distance, inflate),
48
+ fillet: (mf, options) => filletWithManifold(Manifold, mf, options),
49
+ pipeAlongPath: (path, radius, segments) => pipeAlongPath(Manifold, path, radius, segments),
50
+ pipeAlongPathExtended: (path, radius, extensionFactor, segments) => pipeAlongPathExtended(Manifold, path, radius, extensionFactor, segments),
51
+ buildWedge: (edge, distance, inflate) => buildWedge(Manifold, edge, distance, inflate),
47
52
  // These don't need manifold instance
48
53
  extractEdges,
49
54
  selectEdges,
@@ -58,3 +63,4 @@ export { extractEdges, selectEdges, edgeDirection, edgeInwardDirection, sampleEd
58
63
  export { filletWithManifold } from './fillet';
59
64
  export { pipeAlongPath, pipeAlongPathExtended } from './pipeAlongPath';
60
65
  export { buildWedge } from './wedgeBuilder';
66
+ export { default } from './example';
@@ -3,25 +3,26 @@
3
3
  * This approach is reliable for curved paths and produces
4
4
  * smooth results with proper manifold topology.
5
5
  */
6
- import type { Manifold, ManifoldToplevel } from 'manifold-3d';
6
+ import type { Manifold } from 'manifold-3d';
7
+ import type { ManifoldStatic } from './index';
7
8
  /**
8
9
  * Creates a tube along a polyline path using convex hulls of spheres.
9
10
  *
10
- * @param manifold - The initialized Manifold WASM module
11
+ * @param Manifold - The Manifold class with static constructors
11
12
  * @param path Array of 3D points defining the path
12
13
  * @param radius Radius of the tube
13
14
  * @param segments Optional circular segments for sphere quality
14
15
  * @returns Manifold representing the tube
15
16
  */
16
- export declare function pipeAlongPath(manifold: ManifoldToplevel, path: [number, number, number][], radius: number, segments?: number): Manifold;
17
+ export declare function pipeAlongPath(Manifold: ManifoldStatic, path: [number, number, number][], radius: number, segments?: number): Manifold;
17
18
  /**
18
19
  * Creates a tube along an edge path that extends slightly beyond
19
20
  * the endpoints to ensure proper boolean overlap.
20
21
  *
21
- * @param manifold - The initialized Manifold WASM module
22
+ * @param Manifold - The Manifold class with static constructors
22
23
  * @param path Path points
23
24
  * @param radius Tube radius
24
25
  * @param extensionFactor How much to extend beyond endpoints (as fraction of radius)
25
26
  * @param segments Circular segments
26
27
  */
27
- export declare function pipeAlongPathExtended(manifold: ManifoldToplevel, path: [number, number, number][], radius: number, extensionFactor?: number, segments?: number): Manifold;
28
+ export declare function pipeAlongPathExtended(Manifold: ManifoldStatic, path: [number, number, number][], radius: number, extensionFactor?: number, segments?: number): Manifold;
@@ -6,20 +6,20 @@
6
6
  /**
7
7
  * Creates a tube along a polyline path using convex hulls of spheres.
8
8
  *
9
- * @param manifold - The initialized Manifold WASM module
9
+ * @param Manifold - The Manifold class with static constructors
10
10
  * @param path Array of 3D points defining the path
11
11
  * @param radius Radius of the tube
12
12
  * @param segments Optional circular segments for sphere quality
13
13
  * @returns Manifold representing the tube
14
14
  */
15
- export function pipeAlongPath(manifold, path, radius, segments) {
15
+ export function pipeAlongPath(Manifold, path, radius, segments) {
16
16
  if (path.length < 2) {
17
17
  throw new Error('Path must have at least 2 points');
18
18
  }
19
19
  // Create spheres at each path point
20
20
  const spheres = [];
21
21
  for (const [x, y, z] of path) {
22
- const sphere = manifold.Manifold.sphere(radius, segments)
22
+ const sphere = Manifold.sphere(radius, segments)
23
23
  .translate([x, y, z]);
24
24
  spheres.push(sphere);
25
25
  }
@@ -27,26 +27,26 @@ export function pipeAlongPath(manifold, path, radius, segments) {
27
27
  const segments_ = [];
28
28
  for (let i = 0; i < path.length - 1; i++) {
29
29
  // Hull two adjacent spheres to form a tube segment
30
- const segment = manifold.Manifold.hull([spheres[i], spheres[i + 1]]);
30
+ const segment = Manifold.hull([spheres[i], spheres[i + 1]]);
31
31
  segments_.push(segment);
32
32
  }
33
33
  // Union all segments
34
34
  if (segments_.length === 1) {
35
35
  return segments_[0];
36
36
  }
37
- return manifold.Manifold.union(segments_);
37
+ return Manifold.union(segments_);
38
38
  }
39
39
  /**
40
40
  * Creates a tube along an edge path that extends slightly beyond
41
41
  * the endpoints to ensure proper boolean overlap.
42
42
  *
43
- * @param manifold - The initialized Manifold WASM module
43
+ * @param Manifold - The Manifold class with static constructors
44
44
  * @param path Path points
45
45
  * @param radius Tube radius
46
46
  * @param extensionFactor How much to extend beyond endpoints (as fraction of radius)
47
47
  * @param segments Circular segments
48
48
  */
49
- export function pipeAlongPathExtended(manifold, path, radius, extensionFactor = 0.1, segments) {
49
+ export function pipeAlongPathExtended(Manifold, path, radius, extensionFactor = 0.1, segments) {
50
50
  if (path.length < 2) {
51
51
  throw new Error('Path must have at least 2 points');
52
52
  }
@@ -72,7 +72,7 @@ export function pipeAlongPathExtended(manifold, path, radius, extensionFactor =
72
72
  ...path,
73
73
  [end[0] + endDir[0] * ext, end[1] + endDir[1] * ext, end[2] + endDir[2] * ext]
74
74
  ];
75
- return pipeAlongPath(manifold, extendedPath, radius, segments);
75
+ return pipeAlongPath(Manifold, extendedPath, radius, segments);
76
76
  }
77
77
  function normalize(v) {
78
78
  const len = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
@@ -5,7 +5,8 @@
5
5
  * adjacent face normals. This creates a triangular prism that,
6
6
  * when the tube is subtracted, leaves the fillet surface.
7
7
  */
8
- import type { Manifold, ManifoldToplevel } from 'manifold-3d';
8
+ import type { Manifold } from 'manifold-3d';
9
+ import type { ManifoldStatic } from './index';
9
10
  import { MeshEdge } from './edgeSelection';
10
11
  /**
11
12
  * Creates a wedge solid along an edge.
@@ -14,10 +15,10 @@ import { MeshEdge } from './edgeSelection';
14
15
  * - Along the edge direction (with small extension)
15
16
  * - From the edge outward along both face normals
16
17
  *
17
- * @param manifold - The initialized Manifold WASM module
18
+ * @param Manifold - The Manifold class with static constructors
18
19
  * @param edge The edge to build wedge for
19
20
  * @param distance How far to offset along face normals
20
21
  * @param inflate Extra inflation for boolean overlap (typically 2× precision)
21
22
  * @returns Manifold representing the wedge
22
23
  */
23
- export declare function buildWedge(manifold: ManifoldToplevel, edge: MeshEdge, distance: number, inflate?: number): Manifold;
24
+ export declare function buildWedge(Manifold: ManifoldStatic, edge: MeshEdge, distance: number, inflate?: number): Manifold;
@@ -13,13 +13,13 @@ import { edgeDirection } from './edgeSelection';
13
13
  * - Along the edge direction (with small extension)
14
14
  * - From the edge outward along both face normals
15
15
  *
16
- * @param manifold - The initialized Manifold WASM module
16
+ * @param Manifold - The Manifold class with static constructors
17
17
  * @param edge The edge to build wedge for
18
18
  * @param distance How far to offset along face normals
19
19
  * @param inflate Extra inflation for boolean overlap (typically 2× precision)
20
20
  * @returns Manifold representing the wedge
21
21
  */
22
- export function buildWedge(manifold, edge, distance, inflate = 0.001) {
22
+ export function buildWedge(Manifold, edge, distance, inflate = 0.001) {
23
23
  // Edge vector and direction
24
24
  const edgeVec = [
25
25
  edge.p1[0] - edge.p0[0],
@@ -84,7 +84,7 @@ export function buildWedge(manifold, edge, distance, inflate = 0.001) {
84
84
  // Build the wedge as a convex hull of these 6 points
85
85
  // This guarantees a valid manifold
86
86
  const points = [s0, sA, sB, e0, eA, eB];
87
- return manifold.Manifold.hull(points);
87
+ return Manifold.hull(points);
88
88
  }
89
89
  /**
90
90
  * Cross product of two vectors, normalized.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cadit-app/manifold-fillet",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Fillet and round operations for Manifold meshes",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",