@bitbybit-dev/manifold 1.6.2 → 1.7.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.
@@ -4,6 +4,7 @@ import { Manifold } from "./services/manifold/manifold";
4
4
  import { CrossSection } from "./services/cross-section/cross-section";
5
5
  import { Mesh } from "./services/mesh/mesh";
6
6
  import { ManifoldRecipes } from "./services/recipes/recipes";
7
+ import type { BitbybitSettings } from "@bitbybit-dev/base";
7
8
  /**
8
9
  * The entry point to the Manifold kernel, a fast mesh-based solid modeler: `manifold` builds and
9
10
  * changes solids, `crossSection` handles the flat outlines they are extruded and revolved from,
@@ -25,6 +26,15 @@ export declare class ManifoldService {
25
26
  recipes: ManifoldRecipes;
26
27
  private readonly wasm;
27
28
  constructor(wasm: Manifold3D.ManifoldToplevel);
29
+ /**
30
+ * The settings this kernel works by, such as the coordinate system its numbers are in. Assign
31
+ * them once, before the calls they apply to: `manifold.settings = { coordinateSystem }`. With a
32
+ * coordinate system, `recipes` places what it builds in that system. A name that is no setting,
33
+ * or a value its setting does not take, is refused as an `InputError`. The settings read back
34
+ * are frozen, so they change only by assigning new ones.
35
+ */
36
+ get settings(): BitbybitSettings;
37
+ set settings(settings: BitbybitSettings);
28
38
  /**
29
39
  * Turns a solid into plain mesh data, or a cross-section into its polygons, ready for drawing
30
40
  * or export.
@@ -3,7 +3,7 @@ import { CrossSection } from "./services/cross-section/cross-section";
3
3
  import { Mesh } from "./services/mesh/mesh";
4
4
  import { ManifoldRecipes } from "./services/recipes/recipes";
5
5
  import { creasedMeshData, positionsOf } from "./services/mesh-data";
6
- import { BaseBitByBit } from "@bitbybit-dev/base";
6
+ import { BaseBitByBit, checkedSettings } from "@bitbybit-dev/base";
7
7
  /**
8
8
  * The entry point to the Manifold kernel, a fast mesh-based solid modeler: `manifold` builds and
9
9
  * changes solids, `crossSection` handles the flat outlines they are extruded and revolved from,
@@ -19,7 +19,20 @@ export class ManifoldService {
19
19
  this.manifold = new Manifold(wasm);
20
20
  this.crossSection = new CrossSection(wasm, this.base);
21
21
  this.mesh = new Mesh(wasm);
22
- this.recipes = new ManifoldRecipes(wasm, this.base.recipes);
22
+ this.recipes = new ManifoldRecipes(wasm, this.base.recipes, () => this.base.settings);
23
+ }
24
+ /**
25
+ * The settings this kernel works by, such as the coordinate system its numbers are in. Assign
26
+ * them once, before the calls they apply to: `manifold.settings = { coordinateSystem }`. With a
27
+ * coordinate system, `recipes` places what it builds in that system. A name that is no setting,
28
+ * or a value its setting does not take, is refused as an `InputError`. The settings read back
29
+ * are frozen, so they change only by assigning new ones.
30
+ */
31
+ get settings() {
32
+ return this.base.settings;
33
+ }
34
+ set settings(settings) {
35
+ this.base.settings = checkedSettings(settings);
23
36
  }
24
37
  /**
25
38
  * Turns a solid into plain mesh data, or a cross-section into its polygons, ready for drawing
@@ -1,5 +1,5 @@
1
1
  import type * as Manifold3D from "manifold-3d";
2
2
  import type { Base } from "@bitbybit-dev/base";
3
- export declare function turnedZtoY(matrix: Base.TransformMatrix): Manifold3D.Mat4;
4
- export declare function executeRecipe(wasm: Manifold3D.ManifoldToplevel, recipe: Base.Recipe, circularSegments: number, adjustZtoY: boolean, emptyWhenFailed: boolean): Manifold3D.Manifold[];
3
+ import { type RootPlacing } from "./recipe-placing";
4
+ export declare function executeRecipe(wasm: Manifold3D.ManifoldToplevel, recipe: Base.Recipe, circularSegments: number, placing: RootPlacing, emptyWhenFailed: boolean): Manifold3D.Manifold[];
5
5
  export declare function executeRecipeNodes(wasm: Manifold3D.ManifoldToplevel, recipe: Base.Recipe, circularSegments: number, emptyWhenFailed: boolean, nodes: readonly number[]): Map<number, Manifold3D.Manifold | undefined>;
@@ -1,12 +1,13 @@
1
1
  import { loftMesh } from "./recipe-loft";
2
+ import { outlineOf, reachedThrough, releaseOutline } from "./recipe-reach";
2
3
  import { manifoldOfMesh } from "../manifold-of-mesh";
3
4
  import { degreesOf } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/scalars";
5
+ import { asTheRecipeSays } from "./recipe-placing";
4
6
  const UNIT_HEIGHT = 1;
5
7
  const FULL_TURN = 2 * Math.PI;
6
8
  const MIN_REVOLVE_SEGMENTS = 3;
7
9
  const POSITION_PROPERTIES = 3;
8
10
  const FILL_RULE = "NonZero";
9
- const AXES = 3;
10
11
  const MAX_TOOL_PARTS = 64;
11
12
  function isHalfSpace(value) {
12
13
  return typeof value === "object" && value !== null && "op" in value;
@@ -55,18 +56,6 @@ function requiredInputsOf(node) {
55
56
  return [];
56
57
  }
57
58
  }
58
- function negatedWithoutNegativeZero(value) {
59
- return 0 - value;
60
- }
61
- export function turnedZtoY(matrix) {
62
- const [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p] = matrix;
63
- return [
64
- a, c, negatedWithoutNegativeZero(b), d,
65
- e, g, negatedWithoutNegativeZero(f), h,
66
- i, k, negatedWithoutNegativeZero(j), l,
67
- m, o, negatedWithoutNegativeZero(n), p,
68
- ];
69
- }
70
59
  function isClockwise(ring) {
71
60
  let twiceArea = 0;
72
61
  for (let at = 0, previous = ring.length - 1; at < ring.length; previous = at++) {
@@ -75,11 +64,11 @@ function isClockwise(ring) {
75
64
  return twiceArea < 0;
76
65
  }
77
66
  class RecipeExecutor {
78
- constructor(wasm, recipe, circularSegments, adjustZtoY, emptyWhenFailed) {
67
+ constructor(wasm, recipe, circularSegments, placing, emptyWhenFailed) {
79
68
  this.wasm = wasm;
80
69
  this.recipe = recipe;
81
70
  this.circularSegments = circularSegments;
82
- this.adjustZtoY = adjustZtoY;
71
+ this.placing = placing;
83
72
  this.emptyWhenFailed = emptyWhenFailed;
84
73
  this.built = [];
85
74
  this.failed = new Set();
@@ -142,7 +131,7 @@ class RecipeExecutor {
142
131
  placed(root, index) {
143
132
  let placed;
144
133
  try {
145
- placed = this.solid(root.node).transform(this.adjustZtoY ? turnedZtoY(root.matrix) : root.matrix);
134
+ placed = this.solid(root.node).transform(this.placing(root.matrix));
146
135
  expectNoError(placed.status(), root, index);
147
136
  return placed;
148
137
  }
@@ -292,30 +281,6 @@ class RecipeExecutor {
292
281
  swept.delete();
293
282
  }
294
283
  }
295
- reaching(tool, outside) {
296
- const reach = this.recipe.tolerance;
297
- const ofTool = tool.boundingBox();
298
- const below = ofTool.min.map((side, axis) => Math.abs(side - outside.min[axis]) <= reach);
299
- const above = ofTool.max.map((side, axis) => Math.abs(side - outside.max[axis]) <= reach);
300
- if (!below.includes(true) && !above.includes(true)) {
301
- return tool.translate([0, 0, 0]);
302
- }
303
- return tool.warp((vertex) => {
304
- for (let axis = 0; axis < AXES; axis++) {
305
- const drawn = vertex[axis];
306
- const fromBelow = drawn - ofTool.min[axis];
307
- const fromAbove = ofTool.max[axis] - drawn;
308
- const down = below[axis] && fromBelow <= reach;
309
- const up = above[axis] && fromAbove <= reach;
310
- if (down && (!up || fromBelow <= fromAbove)) {
311
- vertex[axis] = drawn - reach;
312
- }
313
- else if (up) {
314
- vertex[axis] = drawn + reach;
315
- }
316
- }
317
- });
318
- }
319
284
  joinsParts(index) {
320
285
  const node = this.recipe.nodes[index];
321
286
  return node.op === "compound" || node.op === "union" || (node.op === "transform" && this.joinsParts(node.of));
@@ -372,29 +337,28 @@ class RecipeExecutor {
372
337
  }
373
338
  into.push(part);
374
339
  }
375
- reachedParts(index, outside, into) {
340
+ reachedParts(index, outline, into) {
376
341
  const parts = this.toolParts(index);
377
342
  try {
378
343
  for (const part of parts) {
379
- into.push(this.reaching(part, outside));
344
+ into.push(reachedThrough(part, outline, this.recipe.tolerance));
380
345
  }
381
346
  }
382
347
  finally {
383
348
  parts.forEach(release);
384
349
  }
385
350
  }
386
- cut(solid, toolIndex, outside) {
387
- const tool = this.built[toolIndex];
388
- if (isHalfSpace(tool)) {
389
- const [nx, ny, nz] = tool.normal;
390
- const length = Math.hypot(nx, ny, nz);
391
- const offset = (nx * tool.origin[0] + ny * tool.origin[1] + nz * tool.origin[2]) / length;
392
- return solid.trimByPlane([-nx / length, -ny / length, -nz / length], -offset);
393
- }
351
+ trimmed(solid, tool) {
352
+ const [nx, ny, nz] = tool.normal;
353
+ const length = Math.hypot(nx, ny, nz);
354
+ const offset = (nx * tool.origin[0] + ny * tool.origin[1] + nz * tool.origin[2]) / length;
355
+ return solid.trimByPlane([-nx / length, -ny / length, -nz / length], -offset);
356
+ }
357
+ cut(solid, toolIndex, outline) {
394
358
  const tools = [];
395
359
  let reaching;
396
360
  try {
397
- this.reachedParts(toolIndex, outside, tools);
361
+ this.reachedParts(toolIndex, outline, tools);
398
362
  reaching = this.wasm.Manifold.union(tools);
399
363
  return solid.subtract(reaching);
400
364
  }
@@ -404,18 +368,34 @@ class RecipeExecutor {
404
368
  }
405
369
  }
406
370
  difference(node) {
407
- let outside = this.solid(node.of).boundingBox();
371
+ let outline;
408
372
  let current;
409
- for (const toolIndex of node.tools) {
410
- const previous = current;
411
- try {
412
- current = this.cut(previous !== null && previous !== void 0 ? previous : this.solid(node.of), toolIndex, outside);
413
- }
414
- finally {
415
- release(previous);
373
+ try {
374
+ for (const toolIndex of node.tools) {
375
+ const previous = current;
376
+ const solid = previous !== null && previous !== void 0 ? previous : this.solid(node.of);
377
+ const tool = this.built[toolIndex];
378
+ try {
379
+ if (isHalfSpace(tool)) {
380
+ current = this.trimmed(solid, tool);
381
+ if (outline) {
382
+ releaseOutline(outline);
383
+ }
384
+ outline = undefined;
385
+ }
386
+ else {
387
+ outline !== null && outline !== void 0 ? outline : (outline = outlineOf(solid));
388
+ current = this.cut(solid, toolIndex, outline);
389
+ }
390
+ }
391
+ finally {
392
+ release(previous);
393
+ }
416
394
  }
417
- if (isHalfSpace(this.built[toolIndex])) {
418
- outside = current.boundingBox();
395
+ }
396
+ finally {
397
+ if (outline) {
398
+ releaseOutline(outline);
419
399
  }
420
400
  }
421
401
  return current;
@@ -426,12 +406,12 @@ class RecipeExecutor {
426
406
  if (built.length === 0) {
427
407
  return host.translate([0, 0, 0]);
428
408
  }
429
- const outside = host.boundingBox();
409
+ const outline = outlineOf(host);
430
410
  const tools = [];
431
411
  let openings;
432
412
  try {
433
413
  for (const opening of built) {
434
- this.reachedParts(opening, outside, tools);
414
+ this.reachedParts(opening, outline, tools);
435
415
  }
436
416
  openings = this.wasm.Manifold.union(tools);
437
417
  return host.subtract(openings);
@@ -439,6 +419,7 @@ class RecipeExecutor {
439
419
  finally {
440
420
  tools.forEach(release);
441
421
  release(openings);
422
+ releaseOutline(outline);
442
423
  }
443
424
  }
444
425
  triangles(node, index) {
@@ -454,9 +435,9 @@ class RecipeExecutor {
454
435
  }
455
436
  }
456
437
  }
457
- export function executeRecipe(wasm, recipe, circularSegments, adjustZtoY, emptyWhenFailed) {
458
- return new RecipeExecutor(wasm, recipe, circularSegments, adjustZtoY, emptyWhenFailed).run();
438
+ export function executeRecipe(wasm, recipe, circularSegments, placing, emptyWhenFailed) {
439
+ return new RecipeExecutor(wasm, recipe, circularSegments, placing, emptyWhenFailed).run();
459
440
  }
460
441
  export function executeRecipeNodes(wasm, recipe, circularSegments, emptyWhenFailed, nodes) {
461
- return new RecipeExecutor(wasm, recipe, circularSegments, false, emptyWhenFailed).solidsOf(nodes);
442
+ return new RecipeExecutor(wasm, recipe, circularSegments, asTheRecipeSays, emptyWhenFailed).solidsOf(nodes);
462
443
  }
@@ -1,6 +1,6 @@
1
1
  import type * as Manifold3D from "manifold-3d";
2
- import type { Base } from "@bitbybit-dev/base";
3
- import type { Recipes } from "@bitbybit-dev/base";
2
+ import type { Base, Inputs as BaseInputs } from "@bitbybit-dev/base";
3
+ import { Recipes } from "@bitbybit-dev/base";
4
4
  import type * as Inputs from "../../inputs";
5
5
  import type * as Resolved from "../../resolved-inputs";
6
- export declare function recipeMeshes(wasm: Manifold3D.ManifoldToplevel, recipes: Recipes, recipe: Base.Recipe, options: Omit<Resolved.Manifold.BuildRecipeMeshesDto, "recipe">): Inputs.Manifold.RecipeMeshesDto;
6
+ export declare function recipeMeshes(wasm: Manifold3D.ManifoldToplevel, recipes: Recipes, recipe: Base.Recipe, options: Omit<Resolved.Manifold.BuildRecipeMeshesDto, "recipe">, coordinateSystem?: BaseInputs.Base.coordinateSystemEnum): Inputs.Manifold.RecipeMeshesDto;
@@ -1,25 +1,38 @@
1
+ import { Recipes } from "@bitbybit-dev/base";
1
2
  import { creasedMeshData, positionsOf } from "../mesh-data";
2
- import { executeRecipeNodes, turnedZtoY } from "./recipe-executor";
3
+ import { executeRecipeNodes } from "./recipe-executor";
4
+ import { mirrorIntoModel, placedAmongMirrored, turnedZtoY } from "./recipe-placing";
3
5
  const IDENTITY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
4
6
  const NO_MESH = -1;
5
7
  function placedBy(matrix, adjustZtoY) {
6
8
  return adjustZtoY ? turnedZtoY(matrix) : [...matrix];
7
9
  }
8
- function meshOf(solid, minSharpAngle) {
10
+ function meshOf(solid, minSharpAngle, mirror) {
9
11
  if (solid.isEmpty()) {
10
12
  return undefined;
11
13
  }
12
- const plain = solid.getMesh();
13
- return creasedMeshData(positionsOf(plain), plain.triVerts, minSharpAngle);
14
+ if (mirror === undefined) {
15
+ const plain = solid.getMesh();
16
+ return creasedMeshData(positionsOf(plain), plain.triVerts, minSharpAngle);
17
+ }
18
+ const mirrored = solid.transform(mirror);
19
+ try {
20
+ const plain = mirrored.getMesh();
21
+ return creasedMeshData(positionsOf(plain), plain.triVerts, minSharpAngle);
22
+ }
23
+ finally {
24
+ mirrored.delete();
25
+ }
14
26
  }
15
- export function recipeMeshes(wasm, recipes, recipe, options) {
27
+ export function recipeMeshes(wasm, recipes, recipe, options, coordinateSystem) {
28
+ const mirror = mirrorIntoModel(coordinateSystem, options.adjustZtoY);
16
29
  const sources = recipe.roots.map((root) => recipes.sourceOf({ recipe, node: root.node, matrix: root.matrix }));
17
30
  const solids = executeRecipeNodes(wasm, recipe, options.circularSegments, options.emptyWhenFailed, [...new Set(sources.map((source) => source.node))]);
18
31
  const meshes = [];
19
32
  const meshOfNode = new Map();
20
33
  try {
21
34
  solids.forEach((solid, node) => {
22
- const mesh = solid === undefined ? undefined : meshOf(solid, options.minSharpAngle);
35
+ const mesh = solid === undefined ? undefined : meshOf(solid, options.minSharpAngle, mirror);
23
36
  if (mesh !== undefined) {
24
37
  meshOfNode.set(node, meshes.push(mesh) - 1);
25
38
  }
@@ -30,16 +43,17 @@ export function recipeMeshes(wasm, recipes, recipe, options) {
30
43
  }
31
44
  const placements = recipe.roots.map((root, index) => {
32
45
  var _a;
33
- return (Object.assign({ mesh: (_a = meshOfNode.get(sources[index].node)) !== null && _a !== void 0 ? _a : NO_MESH, matrix: placedBy(sources[index].matrix, options.adjustZtoY), tag: root.tag }, (root.group === undefined ? {} : { group: root.group })));
46
+ return (Object.assign({ mesh: (_a = meshOfNode.get(sources[index].node)) !== null && _a !== void 0 ? _a : NO_MESH, matrix: mirror === undefined ? placedBy(sources[index].matrix, options.adjustZtoY) : placedAmongMirrored(sources[index].matrix, mirror), tag: root.tag }, (root.group === undefined ? {} : { group: root.group })));
34
47
  });
35
48
  const failed = sources.flatMap((source, index) => solids.get(source.node) === undefined ? [index] : []);
36
- recipes.surfaceMeshes({ recipe, roots: failed, adjustZtoY: false }).forEach((surface, at) => {
49
+ const surfaces = new Recipes(() => (mirror === undefined || coordinateSystem === undefined ? {} : { coordinateSystem }));
50
+ surfaces.surfaceMeshes({ recipe, roots: failed, adjustZtoY: mirror !== undefined && options.adjustZtoY }).forEach((surface, at) => {
37
51
  if (surface === undefined) {
38
52
  return;
39
53
  }
40
54
  const placement = placements[failed[at]];
41
55
  placement.mesh = meshes.push(creasedMeshData(surface.positions, surface.indices, options.minSharpAngle)) - 1;
42
- placement.matrix = placedBy(IDENTITY, options.adjustZtoY);
56
+ placement.matrix = mirror === undefined ? placedBy(IDENTITY, options.adjustZtoY) : [...IDENTITY];
43
57
  });
44
58
  return { meshes, placements };
45
59
  }
@@ -0,0 +1,9 @@
1
+ import type * as Manifold3D from "manifold-3d";
2
+ import { Inputs as BaseInputs } from "@bitbybit-dev/base";
3
+ import type { Base } from "@bitbybit-dev/base";
4
+ export type RootPlacing = (matrix: Base.TransformMatrix) => Manifold3D.Mat4;
5
+ export declare const asTheRecipeSays: RootPlacing;
6
+ export declare function turnedZtoY(matrix: Base.TransformMatrix): Manifold3D.Mat4;
7
+ export declare function mirrorIntoModel(coordinateSystem: BaseInputs.Base.coordinateSystemEnum | undefined, adjustZtoY: boolean): Base.TransformMatrix | undefined;
8
+ export declare function rootPlacingOf(coordinateSystem: BaseInputs.Base.coordinateSystemEnum | undefined, adjustZtoY: boolean): RootPlacing;
9
+ export declare function placedAmongMirrored(matrix: Base.TransformMatrix, mirror: Base.TransformMatrix): Base.TransformMatrix;
@@ -0,0 +1,32 @@
1
+ import { Inputs as BaseInputs } from "@bitbybit-dev/base";
2
+ import { followedBy } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/matrices";
3
+ import { meshMatrixInModel } from "@bitbybit-dev/base/lib/api/services/helpers/files/mesh-file-axes";
4
+ export const asTheRecipeSays = (matrix) => matrix;
5
+ function withoutNegativeZero(matrix) {
6
+ return matrix.map((value) => value + 0);
7
+ }
8
+ function negatedWithoutNegativeZero(value) {
9
+ return 0 - value;
10
+ }
11
+ export function turnedZtoY(matrix) {
12
+ const [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p] = matrix;
13
+ return [
14
+ a, c, negatedWithoutNegativeZero(b), d,
15
+ e, g, negatedWithoutNegativeZero(f), h,
16
+ i, k, negatedWithoutNegativeZero(j), l,
17
+ m, o, negatedWithoutNegativeZero(n), p,
18
+ ];
19
+ }
20
+ export function mirrorIntoModel(coordinateSystem, adjustZtoY) {
21
+ return coordinateSystem === BaseInputs.Base.coordinateSystemEnum.leftHanded ? meshMatrixInModel(coordinateSystem, adjustZtoY) : undefined;
22
+ }
23
+ export function rootPlacingOf(coordinateSystem, adjustZtoY) {
24
+ const mirror = mirrorIntoModel(coordinateSystem, adjustZtoY);
25
+ if (mirror !== undefined) {
26
+ return (matrix) => withoutNegativeZero(followedBy(matrix, mirror));
27
+ }
28
+ return adjustZtoY ? turnedZtoY : asTheRecipeSays;
29
+ }
30
+ export function placedAmongMirrored(matrix, mirror) {
31
+ return withoutNegativeZero(followedBy(followedBy(mirror, matrix), mirror));
32
+ }
@@ -0,0 +1,5 @@
1
+ import type * as Manifold3D from "manifold-3d";
2
+ import type { CutOutline } from "./recipe-types";
3
+ export declare function outlineOf(solid: Manifold3D.Manifold): CutOutline;
4
+ export declare function releaseOutline(outline: CutOutline): void;
5
+ export declare function reachedThrough(tool: Manifold3D.Manifold, outline: CutOutline, reach: number): Manifold3D.Manifold;
@@ -0,0 +1,414 @@
1
+ import { add3, between3, cross2, cross3, distance2, dot3, length2, length3, scale3, subtract2, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
2
+ import { axesAlong, axesToMatrix, pointToLocal, vectorToLocal } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
3
+ import { rigidInverse } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/matrices";
4
+ const AXES = 3;
5
+ const TRIANGLE_CORNERS = 3;
6
+ const BOX_VALUES = 2 * AXES;
7
+ const MIDDLE = 0.5;
8
+ const SAME_DIRECTION = 0.999999;
9
+ const ONE_PLANE = 0.999999999999;
10
+ const FARTHEST_SLIDE = 2;
11
+ const BEYOND = 1.001;
12
+ const FILLED = 0.999999999999;
13
+ const INDEXED_FROM = 256;
14
+ const SLICES_ALONG = 32;
15
+ const NOTHING_INDEXED = { axis: 0, sorted: new Uint32Array(0), least: new Float64Array(0), widest: 0, big: new Uint32Array(0) };
16
+ const ORIGIN = [0, 0, 0];
17
+ function pointAt(mesh, vert) {
18
+ const { numProp, vertProperties } = mesh;
19
+ return [vertProperties[vert * numProp], vertProperties[vert * numProp + 1], vertProperties[vert * numProp + 2]];
20
+ }
21
+ function pointsOf(mesh) {
22
+ return Array.from({ length: mesh.numVert }, (_, vert) => pointAt(mesh, vert));
23
+ }
24
+ function centredMesh(solid, centre) {
25
+ const centred = solid.translate(scale3(centre, -1));
26
+ try {
27
+ return centred.getMesh();
28
+ }
29
+ finally {
30
+ centred.delete();
31
+ }
32
+ }
33
+ function faceOf(mesh, tri) {
34
+ const corners = cornersOf(mesh.triVerts, tri).map((vert) => pointAt(mesh, vert));
35
+ const [a, b, c] = corners;
36
+ const spanned = cross3(subtract3(b, a), subtract3(c, a));
37
+ const twiceArea = length3(spanned);
38
+ if (!(twiceArea > 0)) {
39
+ return undefined;
40
+ }
41
+ const normal = scale3(spanned, 1 / twiceArea);
42
+ return { normal, offset: dot3(normal, a), corners };
43
+ }
44
+ function fillsItsBox(solid, box) {
45
+ const size = subtract3(box.max, box.min);
46
+ return solid.volume() >= FILLED * size[0] * size[1] * size[2];
47
+ }
48
+ export function outlineOf(solid) {
49
+ const box = solid.boundingBox();
50
+ if (solid.isEmpty() || fillsItsBox(solid, box)) {
51
+ return { solid: undefined, box, centre: ORIGIN, mesh: undefined, boxes: new Float64Array(0), index: NOTHING_INDEXED };
52
+ }
53
+ const centre = between3(box.min, box.max, MIDDLE);
54
+ const mesh = centredMesh(solid, centre);
55
+ const { numProp, triVerts, vertProperties } = mesh;
56
+ const boxes = new Float64Array(mesh.numTri * BOX_VALUES);
57
+ for (let tri = 0; tri < mesh.numTri; tri++) {
58
+ for (let axis = 0; axis < AXES; axis++) {
59
+ let least = Infinity;
60
+ let most = -Infinity;
61
+ for (let corner = 0; corner < TRIANGLE_CORNERS; corner++) {
62
+ const value = vertProperties[triVerts[tri * TRIANGLE_CORNERS + corner] * numProp + axis];
63
+ least = Math.min(least, value);
64
+ most = Math.max(most, value);
65
+ }
66
+ boxes[tri * BOX_VALUES + axis] = least;
67
+ boxes[tri * BOX_VALUES + AXES + axis] = most;
68
+ }
69
+ }
70
+ return { solid: solid.translate(ORIGIN), box, centre, mesh, boxes, index: indexedTriangles(boxes, mesh.numTri, box) };
71
+ }
72
+ function indexedTriangles(boxes, count, box) {
73
+ const size = subtract3(box.max, box.min);
74
+ const axis = size.indexOf(Math.max(...size));
75
+ const least = (tri) => boxes[tri * BOX_VALUES + axis];
76
+ const extent = (tri) => boxes[tri * BOX_VALUES + AXES + axis] - least(tri);
77
+ const all = Array.from({ length: count }, (_, tri) => tri);
78
+ const slice = count >= INDEXED_FROM ? size[axis] / SLICES_ALONG : -1;
79
+ const sorted = all.filter((tri) => extent(tri) <= slice).sort((first, second) => least(first) - least(second));
80
+ return {
81
+ axis,
82
+ sorted: Uint32Array.from(sorted),
83
+ least: Float64Array.from(sorted, least),
84
+ widest: sorted.reduce((widest, tri) => Math.max(widest, extent(tri)), 0),
85
+ big: Uint32Array.from(all.filter((tri) => !(extent(tri) <= slice))),
86
+ };
87
+ }
88
+ function countBelow(ascending, value, orEqual) {
89
+ let low = 0;
90
+ let high = ascending.length;
91
+ while (low < high) {
92
+ const middle = (low + high) >>> 1;
93
+ const before = orEqual ? ascending[middle] <= value : ascending[middle] < value;
94
+ if (before) {
95
+ low = middle + 1;
96
+ }
97
+ else {
98
+ high = middle;
99
+ }
100
+ }
101
+ return low;
102
+ }
103
+ function nearFaces(outline, low, high, margin) {
104
+ const { mesh, boxes, index } = outline;
105
+ const faces = [];
106
+ if (mesh === undefined) {
107
+ return faces;
108
+ }
109
+ const consider = (tri) => {
110
+ let meets = true;
111
+ for (let axis = 0; axis < AXES && meets; axis++) {
112
+ meets = boxes[tri * BOX_VALUES + axis] <= high[axis] + margin && low[axis] <= boxes[tri * BOX_VALUES + AXES + axis] + margin;
113
+ }
114
+ const face = meets ? faceOf(mesh, tri) : undefined;
115
+ if (face) {
116
+ faces.push(face);
117
+ }
118
+ };
119
+ const from = countBelow(index.least, low[index.axis] - margin - index.widest, false);
120
+ const to = countBelow(index.least, high[index.axis] + margin, true);
121
+ for (let at = from; at < to; at++) {
122
+ consider(index.sorted[at]);
123
+ }
124
+ index.big.forEach(consider);
125
+ return faces;
126
+ }
127
+ function axisDirection(axis, sign) {
128
+ return Array.from({ length: AXES }, (_, at) => (at === axis ? sign : 0));
129
+ }
130
+ function boxReach(ofTool, outside, reach) {
131
+ return {
132
+ below: ofTool.min.map((side, axis) => Math.abs(side - outside.min[axis]) <= reach),
133
+ above: ofTool.max.map((side, axis) => Math.abs(side - outside.max[axis]) <= reach),
134
+ };
135
+ }
136
+ function boxShift(vertex, ofTool, sides, reach) {
137
+ return vertex.map((drawn, axis) => {
138
+ const fromBelow = drawn - ofTool.min[axis];
139
+ const fromAbove = ofTool.max[axis] - drawn;
140
+ const down = sides.below[axis] && fromBelow <= reach;
141
+ const up = sides.above[axis] && fromAbove <= reach;
142
+ if (down && (!up || fromBelow <= fromAbove)) {
143
+ return -reach;
144
+ }
145
+ return up ? reach : 0;
146
+ });
147
+ }
148
+ function boxReached(tool, ofTool, sides, reach) {
149
+ if (!sides.below.includes(true) && !sides.above.includes(true)) {
150
+ return tool.translate([0, 0, 0]);
151
+ }
152
+ return tool.warp((vertex) => {
153
+ const shift = boxShift(vertex, ofTool, sides, reach);
154
+ for (let axis = 0; axis < AXES; axis++) {
155
+ vertex[axis] = vertex[axis] + shift[axis];
156
+ }
157
+ });
158
+ }
159
+ function reachedBoxSides(outline, sides) {
160
+ const { box, centre } = outline;
161
+ const planes = [];
162
+ for (let axis = 0; axis < AXES; axis++) {
163
+ if (sides.below[axis]) {
164
+ planes.push({ normal: axisDirection(axis, -1), offset: centre[axis] - box.min[axis] });
165
+ }
166
+ if (sides.above[axis]) {
167
+ planes.push({ normal: axisDirection(axis, 1), offset: box.max[axis] - centre[axis] });
168
+ }
169
+ }
170
+ return planes;
171
+ }
172
+ function hostFacesNear(outline, ofTool, sides, reach) {
173
+ const { centre } = outline;
174
+ const onReachedSides = reachedBoxSides(outline, sides);
175
+ return nearFaces(outline, subtract3(ofTool.min, centre), subtract3(ofTool.max, centre), reach).filter((face) => !onReachedSides.some((side) => dot3(side.normal, face.normal) >= SAME_DIRECTION && Math.abs(side.offset - face.offset) <= reach));
176
+ }
177
+ function cornersOf(triVerts, tri) {
178
+ return [triVerts[tri * TRIANGLE_CORNERS], triVerts[tri * TRIANGLE_CORNERS + 1], triVerts[tri * TRIANGLE_CORNERS + 2]];
179
+ }
180
+ function regionsOf(triVerts, points) {
181
+ const count = triVerts.length / TRIANGLE_CORNERS;
182
+ const spans = Array.from({ length: count }, (_, tri) => {
183
+ const [a, b, c] = cornersOf(triVerts, tri).map((vert) => points[vert]);
184
+ return cross3(subtract3(b, a), subtract3(c, a));
185
+ });
186
+ const across = new Map();
187
+ for (let tri = 0; tri < count; tri++) {
188
+ const corners = cornersOf(triVerts, tri);
189
+ corners.forEach((from, at) => across.set(from * points.length + corners[(at + 1) % TRIANGLE_CORNERS], tri));
190
+ }
191
+ const regionOf = new Int32Array(count).fill(-1);
192
+ const regions = [];
193
+ for (let seed = 0; seed < count; seed++) {
194
+ if (regionOf[seed] >= 0) {
195
+ continue;
196
+ }
197
+ const seedNormal = scale3(spans[seed], 1 / length3(spans[seed]));
198
+ const triangles = [seed];
199
+ regionOf[seed] = regions.length;
200
+ let spanned = spans[seed];
201
+ for (let next = 0; next < triangles.length; next++) {
202
+ const corners = cornersOf(triVerts, triangles[next]);
203
+ corners.forEach((from, at) => {
204
+ const other = across.get(corners[(at + 1) % TRIANGLE_CORNERS] * points.length + from);
205
+ if (other !== undefined && regionOf[other] < 0 && dot3(spans[other], seedNormal) >= ONE_PLANE * length3(spans[other])) {
206
+ regionOf[other] = regions.length;
207
+ triangles.push(other);
208
+ spanned = add3(spanned, spans[other]);
209
+ }
210
+ });
211
+ }
212
+ const normal = scale3(spanned, 1 / length3(spanned));
213
+ regions.push({ normal, offset: dot3(normal, points[triVerts[seed * TRIANGLE_CORNERS]]), triangles });
214
+ }
215
+ return { regions, regionOf };
216
+ }
217
+ function farthestFrom(points, from) {
218
+ return points.reduce((farthest, point) => (distance2(point, from) > distance2(farthest, from) ? point : farthest), from);
219
+ }
220
+ function farthestPair(points) {
221
+ const start = farthestFrom(points, points[0]);
222
+ return [start, farthestFrom(points, start)];
223
+ }
224
+ function spansArea(points, reach) {
225
+ const [start, end] = farthestPair(points);
226
+ const across = subtract2(end, start);
227
+ const wide = reach * length2(across);
228
+ return points.some((point) => Math.abs(cross2(across, subtract2(point, start))) > wide);
229
+ }
230
+ function withinTriangle(point, corners, reach) {
231
+ const turn = Math.sign(cross2(subtract2(corners[1], corners[0]), subtract2(corners[2], corners[0])));
232
+ return corners.every((from, at) => {
233
+ const edge = subtract2(corners[(at + 1) % corners.length], from);
234
+ return (turn * cross2(edge, subtract2(point, from))) / length2(edge) >= -reach;
235
+ });
236
+ }
237
+ function insidePoints(region, triVerts, points) {
238
+ return region.triangles.flatMap((tri) => {
239
+ const [a, b, c] = cornersOf(triVerts, tri).map((vert) => points[vert]);
240
+ const middleOfAb = between3(a, b, MIDDLE);
241
+ return [middleOfAb, between3(b, c, MIDDLE), between3(c, a, MIDDLE), between3(middleOfAb, c, MIDDLE)];
242
+ });
243
+ }
244
+ function clearBeyond(region, triVerts, points, outline, allowance, reach) {
245
+ const axes = axesAlong(add3(outline.centre, scale3(region.normal, region.offset)), region.normal);
246
+ const footprint = region.triangles.map((tri) => cornersOf(triVerts, tri).map((vert) => {
247
+ const [across, along] = pointToLocal(axes, add3(points[vert], outline.centre));
248
+ return [across, along];
249
+ }));
250
+ const inFrame = outline.solid.transform(rigidInverse(axesToMatrix(axes)));
251
+ let section;
252
+ let overlap;
253
+ try {
254
+ section = inFrame.slice(BEYOND * reach);
255
+ overlap = section.intersect(footprint);
256
+ return overlap.area() <= allowance;
257
+ }
258
+ finally {
259
+ inFrame.delete();
260
+ section === null || section === void 0 ? void 0 : section.delete();
261
+ overlap === null || overlap === void 0 ? void 0 : overlap.delete();
262
+ }
263
+ }
264
+ export function releaseOutline(outline) {
265
+ var _a;
266
+ (_a = outline.solid) === null || _a === void 0 ? void 0 : _a.delete();
267
+ }
268
+ function liesOnHost(region, triVerts, points, faces, outline, reach) {
269
+ const corners = [...new Set(region.triangles.flatMap((tri) => cornersOf(triVerts, tri)))].map((vert) => points[vert]);
270
+ const beneath = faces.filter((face) => dot3(face.normal, region.normal) >= SAME_DIRECTION && corners.every((corner) => Math.abs(dot3(face.normal, corner) - face.offset) <= reach));
271
+ if (beneath.length === 0) {
272
+ return false;
273
+ }
274
+ const axes = axesAlong(ORIGIN, region.normal);
275
+ const inPlane = (point) => {
276
+ const [across, along] = vectorToLocal(axes, point);
277
+ return [across, along];
278
+ };
279
+ const projected = corners.map(inPlane);
280
+ if (!spansArea(projected, reach)) {
281
+ return false;
282
+ }
283
+ const covering = beneath.map((face) => face.corners.map(inPlane));
284
+ const covered = [...projected, ...insidePoints(region, triVerts, points).map(inPlane)].every((point) => covering.some((triangle) => withinTriangle(point, triangle, reach)));
285
+ const [start, end] = farthestPair(projected);
286
+ return covered && clearBeyond(region, triVerts, points, outline, reach * distance2(start, end), reach);
287
+ }
288
+ function pushOf(plane, reach) {
289
+ return plane.pushed ? reach : 0;
290
+ }
291
+ function meetingMove(planes, reach) {
292
+ var _a;
293
+ const [first, second, third] = planes;
294
+ if (second === undefined) {
295
+ return scale3(first.normal, pushOf(first, reach));
296
+ }
297
+ const thirdNormal = (_a = third === null || third === void 0 ? void 0 : third.normal) !== null && _a !== void 0 ? _a : cross3(first.normal, second.normal);
298
+ const thirdPush = third === undefined ? 0 : pushOf(third, reach);
299
+ const crossOfFirst = cross3(second.normal, thirdNormal);
300
+ const crossOfSecond = cross3(thirdNormal, first.normal);
301
+ const crossOfThird = cross3(first.normal, second.normal);
302
+ const summed = add3(add3(scale3(crossOfFirst, pushOf(first, reach)), scale3(crossOfSecond, pushOf(second, reach))), scale3(crossOfThird, thirdPush));
303
+ return scale3(summed, 1 / dot3(first.normal, crossOfFirst));
304
+ }
305
+ function cornerMove(planes, reach) {
306
+ if (planes.length > AXES) {
307
+ return undefined;
308
+ }
309
+ const move = meetingMove(planes, reach);
310
+ return length3(move) <= FARTHEST_SLIDE * reach ? move : undefined;
311
+ }
312
+ function distinctRegions(at, normals, pushed) {
313
+ const distinct = [];
314
+ for (const region of at) {
315
+ const same = distinct.find((other) => dot3(normals[other], normals[region]) >= SAME_DIRECTION);
316
+ if (same === undefined) {
317
+ distinct.push(region);
318
+ }
319
+ else if (pushed[same] !== pushed[region]) {
320
+ return undefined;
321
+ }
322
+ }
323
+ return distinct;
324
+ }
325
+ function planesOf(regions, normals, pushed) {
326
+ return regions.map((region) => ({ normal: normals[region], pushed: pushed[region] }));
327
+ }
328
+ function cornerPlanes(atCorner, normals, pushed, reach) {
329
+ return atCorner.map((at) => {
330
+ const distinct = distinctRegions(at, normals, pushed);
331
+ if (distinct === undefined) {
332
+ return undefined;
333
+ }
334
+ if (!distinct.some((region) => pushed[region])) {
335
+ return [];
336
+ }
337
+ return cornerMove(planesOf(distinct, normals, pushed), reach) === undefined ? undefined : distinct;
338
+ });
339
+ }
340
+ function hasFlushTriangle(triVerts, points, faces, reach) {
341
+ for (let tri = 0; tri < triVerts.length / TRIANGLE_CORNERS; tri++) {
342
+ const [a, b, c] = cornersOf(triVerts, tri).map((vert) => points[vert]);
343
+ const spanned = cross3(subtract3(b, a), subtract3(c, a));
344
+ const twiceArea = length3(spanned);
345
+ if (faces.some((face) => dot3(face.normal, spanned) >= SAME_DIRECTION * twiceArea && Math.abs(dot3(face.normal, a) - face.offset) <= reach)) {
346
+ return true;
347
+ }
348
+ }
349
+ return false;
350
+ }
351
+ function normalsOf(regions, triVerts, points) {
352
+ return regions.map((region) => {
353
+ const spanned = region.triangles.reduce((sum, tri) => {
354
+ const [a, b, c] = cornersOf(triVerts, tri).map((vert) => points[vert]);
355
+ return add3(sum, cross3(subtract3(b, a), subtract3(c, a)));
356
+ }, ORIGIN);
357
+ return scale3(spanned, 1 / length3(spanned));
358
+ });
359
+ }
360
+ function pushedFaces(triVerts, points, faces, outline, reach) {
361
+ const { regions, regionOf } = regionsOf(triVerts, points);
362
+ const pushed = regions.map((region) => liesOnHost(region, triVerts, points, faces, outline, reach));
363
+ if (!pushed.includes(true)) {
364
+ return undefined;
365
+ }
366
+ const atCorner = points.map(() => []);
367
+ regionOf.forEach((region, tri) => {
368
+ for (const corner of cornersOf(triVerts, tri)) {
369
+ if (region >= 0 && !atCorner[corner].includes(region)) {
370
+ atCorner[corner].push(region);
371
+ }
372
+ }
373
+ });
374
+ const normals = regions.map((region) => region.normal);
375
+ let planesAt = cornerPlanes(atCorner, normals, pushed, reach);
376
+ while (planesAt.includes(undefined)) {
377
+ planesAt.forEach((planes, corner) => {
378
+ if (planes === undefined) {
379
+ atCorner[corner].forEach((region) => {
380
+ pushed[region] = false;
381
+ });
382
+ }
383
+ });
384
+ planesAt = cornerPlanes(atCorner, normals, pushed, reach);
385
+ }
386
+ return pushed.includes(true) ? { regions, planesAt: planesAt, pushed } : undefined;
387
+ }
388
+ export function reachedThrough(tool, outline, reach) {
389
+ const ofTool = tool.boundingBox();
390
+ const sides = boxReach(ofTool, outline.box, reach);
391
+ const faces = hostFacesNear(outline, ofTool, sides, reach);
392
+ if (faces.length === 0) {
393
+ return boxReached(tool, ofTool, sides, reach);
394
+ }
395
+ const mesh = centredMesh(tool, outline.centre);
396
+ const points = pointsOf(mesh);
397
+ const reached = hasFlushTriangle(mesh.triVerts, points, faces, reach) ? pushedFaces(mesh.triVerts, points, faces, outline, reach) : undefined;
398
+ if (reached === undefined) {
399
+ return boxReached(tool, ofTool, sides, reach);
400
+ }
401
+ return tool.warpBatch((verts, count) => {
402
+ const drawn = Array.from({ length: count }, (_, vert) => [verts[vert * AXES], verts[vert * AXES + 1], verts[vert * AXES + 2]]);
403
+ const centred = drawn.map((point) => subtract3(point, outline.centre));
404
+ const normals = normalsOf(reached.regions, mesh.triVerts, centred);
405
+ drawn.forEach((point, vert) => {
406
+ const planes = reached.planesAt[vert];
407
+ const move = planes.length === 0 ? ORIGIN : meetingMove(planesOf(planes, normals, reached.pushed), reach);
408
+ const shift = add3(move, boxShift(point, ofTool, sides, reach));
409
+ for (let axis = 0; axis < AXES; axis++) {
410
+ verts[vert * AXES + axis] = point[axis] + shift[axis];
411
+ }
412
+ });
413
+ });
414
+ }
@@ -2,3 +2,45 @@ import type * as Manifold3D from "manifold-3d";
2
2
  import type { Base } from "@bitbybit-dev/base";
3
3
  export type Built = Manifold3D.Manifold | Manifold3D.CrossSection | Base.RecipeHalfSpaceNode;
4
4
  export type ProfileRings = readonly (readonly Manifold3D.Vec2[])[];
5
+ export interface FacePlane {
6
+ readonly normal: Manifold3D.Vec3;
7
+ readonly offset: number;
8
+ }
9
+ export interface OutlineFace extends FacePlane {
10
+ readonly corners: readonly Manifold3D.Vec3[];
11
+ }
12
+ export interface TriangleIndex {
13
+ readonly axis: number;
14
+ readonly sorted: Uint32Array;
15
+ readonly least: Float64Array;
16
+ readonly widest: number;
17
+ readonly big: Uint32Array;
18
+ }
19
+ export interface CutOutline {
20
+ readonly solid: Manifold3D.Manifold | undefined;
21
+ readonly box: Manifold3D.Box;
22
+ readonly centre: Manifold3D.Vec3;
23
+ readonly mesh: Manifold3D.Mesh | undefined;
24
+ readonly boxes: Float64Array;
25
+ readonly index: TriangleIndex;
26
+ }
27
+ export interface BoxReach {
28
+ readonly below: readonly boolean[];
29
+ readonly above: readonly boolean[];
30
+ }
31
+ export interface ToolRegion extends FacePlane {
32
+ readonly triangles: readonly number[];
33
+ }
34
+ export interface CornerPlane {
35
+ readonly normal: Manifold3D.Vec3;
36
+ readonly pushed: boolean;
37
+ }
38
+ export interface ToolRegions {
39
+ readonly regions: readonly ToolRegion[];
40
+ readonly regionOf: Int32Array;
41
+ }
42
+ export interface ReachedFaces {
43
+ readonly regions: readonly ToolRegion[];
44
+ readonly planesAt: readonly (readonly number[])[];
45
+ readonly pushed: readonly boolean[];
46
+ }
@@ -1,5 +1,5 @@
1
1
  import type * as Manifold3D from "manifold-3d";
2
- import type { Recipes } from "@bitbybit-dev/base";
2
+ import type { BitbybitSettings, Recipes } from "@bitbybit-dev/base";
3
3
  import * as Inputs from "../../inputs/manifold-inputs";
4
4
  /**
5
5
  * Building recipes: solids described as data - polygons, circles, extrusions, turns and lofts, cuts,
@@ -12,14 +12,15 @@ import * as Inputs from "../../inputs/manifold-inputs";
12
12
  */
13
13
  export declare class ManifoldRecipes {
14
14
  private readonly recipes;
15
+ private readonly settings;
15
16
  private manifold;
16
- constructor(wasm: Manifold3D.ManifoldToplevel, recipes: Recipes);
17
+ constructor(wasm: Manifold3D.ManifoldToplevel, recipes: Recipes, settings?: () => BitbybitSettings);
17
18
  /**
18
19
  * Builds each root of a recipe as a solid placed by its matrix, in root order.
19
20
  *
20
- * Shared nodes are built once. An invalid recipe throws; a root the kernel cannot build, such as
21
- * an open mesh, throws unless `emptyWhenFailed` is set. A cut within `tolerance` of a side of the
22
- * box of what it cuts goes through it.
21
+ * Shared nodes are built once. An invalid recipe throws; a root the kernel cannot build throws
22
+ * unless `emptyWhenFailed` is set. A cut ending within `tolerance` of a side of the bounding box,
23
+ * or of a face its end lies wholly on, goes through.
23
24
  * @param inputs - The recipe, how finely circles are divided, and whether Z turns into Y
24
25
  * @returns One solid per root, in root order
25
26
  * @group build
@@ -2,6 +2,7 @@ import { resolveDto } from "@bitbybit-dev/base";
2
2
  import * as Inputs from "../../inputs/manifold-inputs";
3
3
  import { executeRecipe } from "./recipe-executor";
4
4
  import { recipeMeshes } from "./recipe-meshes";
5
+ import { rootPlacingOf } from "./recipe-placing";
5
6
  const MIN_CIRCLE_SIDES = 3;
6
7
  const MAX_SHARP_ANGLE = 180;
7
8
  const POSITION_PROPERTIES = 3;
@@ -15,16 +16,17 @@ const POSITION_PROPERTIES = 3;
15
16
  * @beta
16
17
  */
17
18
  export class ManifoldRecipes {
18
- constructor(wasm, recipes) {
19
+ constructor(wasm, recipes, settings = () => ({})) {
19
20
  this.recipes = recipes;
21
+ this.settings = settings;
20
22
  this.manifold = wasm;
21
23
  }
22
24
  /**
23
25
  * Builds each root of a recipe as a solid placed by its matrix, in root order.
24
26
  *
25
- * Shared nodes are built once. An invalid recipe throws; a root the kernel cannot build, such as
26
- * an open mesh, throws unless `emptyWhenFailed` is set. A cut within `tolerance` of a side of the
27
- * box of what it cuts goes through it.
27
+ * Shared nodes are built once. An invalid recipe throws; a root the kernel cannot build throws
28
+ * unless `emptyWhenFailed` is set. A cut ending within `tolerance` of a side of the bounding box,
29
+ * or of a face its end lies wholly on, goes through.
28
30
  * @param inputs - The recipe, how finely circles are divided, and whether Z turns into Y
29
31
  * @returns One solid per root, in root order
30
32
  * @group build
@@ -42,7 +44,7 @@ export class ManifoldRecipes {
42
44
  if (!Number.isSafeInteger(resolved.circularSegments) || resolved.circularSegments < MIN_CIRCLE_SIDES) {
43
45
  throw new RangeError(`A circle needs at least ${MIN_CIRCLE_SIDES} sides, got ${resolved.circularSegments}`);
44
46
  }
45
- return executeRecipe(this.manifold, recipe, resolved.circularSegments, resolved.adjustZtoY, resolved.emptyWhenFailed);
47
+ return executeRecipe(this.manifold, recipe, resolved.circularSegments, rootPlacingOf(this.settings().coordinateSystem, resolved.adjustZtoY), resolved.emptyWhenFailed);
46
48
  }
47
49
  /**
48
50
  * Builds a recipe into the meshes its roots draw, each step several roots place meshed once in
@@ -70,7 +72,7 @@ export class ManifoldRecipes {
70
72
  if (!(resolved.minSharpAngle >= 0 && resolved.minSharpAngle <= MAX_SHARP_ANGLE)) {
71
73
  throw new RangeError(`minSharpAngle must be an angle from 0 to ${MAX_SHARP_ANGLE} degrees, got ${resolved.minSharpAngle}`);
72
74
  }
73
- return recipeMeshes(this.manifold, this.recipes, recipe, resolved);
75
+ return recipeMeshes(this.manifold, this.recipes, recipe, resolved, this.settings().coordinateSystem);
74
76
  }
75
77
  /**
76
78
  * Gives the roots of a recipe made of triangle meshes alone as meshes, placed as `build` places
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitbybit-dev/manifold",
3
- "version": "1.6.2",
3
+ "version": "1.7.0",
4
4
  "description": "Bit By Bit Developers Manifold based CAD Library to Program Geometry",
5
5
  "homepage": "https://docs.bitbybit.dev/classes/Bit.Manifold",
6
6
  "main": "index.js",
@@ -55,6 +55,6 @@
55
55
  "type": "module",
56
56
  "dependencies": {
57
57
  "manifold-3d": "3.5.4",
58
- "@bitbybit-dev/base": "1.6.2"
58
+ "@bitbybit-dev/base": "1.7.0"
59
59
  }
60
60
  }