@bitbybit-dev/manifold 1.4.0 → 1.5.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/lib/api/dto-registry.js +13 -4
  2. package/lib/api/inputs/manifold-inputs.d.ts +249 -8
  3. package/lib/api/inputs/manifold-inputs.js +237 -10
  4. package/lib/api/manifold-service.d.ts +16 -9
  5. package/lib/api/manifold-service.js +21 -8
  6. package/lib/api/resolved-inputs/index.d.ts +9 -2
  7. package/lib/api/services/cross-section/cross-section-booleans.d.ts +2 -2
  8. package/lib/api/services/cross-section/cross-section-evaluate.d.ts +2 -2
  9. package/lib/api/services/cross-section/cross-section-operations.d.ts +41 -3
  10. package/lib/api/services/cross-section/cross-section-operations.js +85 -3
  11. package/lib/api/services/cross-section/cross-section-shapes.d.ts +1 -1
  12. package/lib/api/services/cross-section/cross-section-transforms.d.ts +1 -1
  13. package/lib/api/services/cross-section/cross-section.constants.d.ts +6 -0
  14. package/lib/api/services/cross-section/cross-section.constants.js +5 -0
  15. package/lib/api/services/cross-section/cross-section.d.ts +2 -2
  16. package/lib/api/services/manifold/manifold-booleans.d.ts +1 -1
  17. package/lib/api/services/manifold/manifold-evaluate.d.ts +1 -1
  18. package/lib/api/services/manifold/manifold-operations.d.ts +1 -1
  19. package/lib/api/services/manifold/manifold-shapes.d.ts +1 -1
  20. package/lib/api/services/manifold/manifold-shapes.js +2 -17
  21. package/lib/api/services/manifold/manifold-transforms.d.ts +1 -1
  22. package/lib/api/services/manifold/manifold.d.ts +2 -2
  23. package/lib/api/services/mesh/mesh-evaluate.d.ts +1 -1
  24. package/lib/api/services/mesh/mesh-operations.d.ts +2 -2
  25. package/lib/api/services/mesh/mesh.d.ts +1 -1
  26. package/lib/api/services/mesh-data.d.ts +4 -0
  27. package/lib/api/services/mesh-data.js +23 -0
  28. package/lib/api/services/recipes/recipe-executor.d.ts +5 -0
  29. package/lib/api/services/recipes/recipe-executor.js +339 -0
  30. package/lib/api/services/recipes/recipe-loft.d.ts +3 -0
  31. package/lib/api/services/recipes/recipe-loft.js +85 -0
  32. package/lib/api/services/recipes/recipe-meshes.d.ts +5 -0
  33. package/lib/api/services/recipes/recipe-meshes.js +46 -0
  34. package/lib/api/services/recipes/recipe-types.d.ts +4 -0
  35. package/lib/api/services/recipes/recipe-types.js +1 -0
  36. package/lib/api/services/recipes/recipes.constants.d.ts +3 -0
  37. package/lib/api/services/recipes/recipes.constants.js +3 -0
  38. package/lib/api/services/recipes/recipes.d.ts +71 -0
  39. package/lib/api/services/recipes/recipes.js +104 -0
  40. package/package.json +2 -2
@@ -0,0 +1,46 @@
1
+ import { recipeSourceOf, recipeSurfaceMeshes } from "@bitbybit-dev/base";
2
+ import { creasedMeshData, positionsOf } from "../mesh-data";
3
+ import { executeRecipeNodes, turnedZtoY } from "./recipe-executor";
4
+ const IDENTITY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5
+ const NO_MESH = -1;
6
+ function placedBy(matrix, adjustZtoY) {
7
+ return adjustZtoY ? turnedZtoY(matrix) : [...matrix];
8
+ }
9
+ function meshOf(solid, minSharpAngle) {
10
+ if (solid.isEmpty()) {
11
+ return undefined;
12
+ }
13
+ const plain = solid.getMesh();
14
+ return creasedMeshData(positionsOf(plain), plain.triVerts, minSharpAngle);
15
+ }
16
+ export function recipeMeshes(wasm, recipe, options) {
17
+ const sources = recipe.roots.map((root) => recipeSourceOf(recipe, root.node, root.matrix));
18
+ const solids = executeRecipeNodes(wasm, recipe, options.circularSegments, options.emptyWhenFailed, [...new Set(sources.map((source) => source.node))]);
19
+ const meshes = [];
20
+ const meshOfNode = new Map();
21
+ try {
22
+ solids.forEach((solid, node) => {
23
+ const mesh = solid === undefined ? undefined : meshOf(solid, options.minSharpAngle);
24
+ if (mesh !== undefined) {
25
+ meshOfNode.set(node, meshes.push(mesh) - 1);
26
+ }
27
+ });
28
+ }
29
+ finally {
30
+ solids.forEach((solid) => solid === null || solid === void 0 ? void 0 : solid.delete());
31
+ }
32
+ const placements = recipe.roots.map((root, index) => {
33
+ var _a;
34
+ 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 })));
35
+ });
36
+ const failed = sources.flatMap((source, index) => solids.get(source.node) === undefined ? [index] : []);
37
+ recipeSurfaceMeshes(recipe, failed, false).forEach((surface, at) => {
38
+ if (surface === undefined) {
39
+ return;
40
+ }
41
+ const placement = placements[failed[at]];
42
+ placement.mesh = meshes.push(creasedMeshData(surface.positions, surface.indices, options.minSharpAngle)) - 1;
43
+ placement.matrix = placedBy(IDENTITY, options.adjustZtoY);
44
+ });
45
+ return { meshes, placements };
46
+ }
@@ -0,0 +1,4 @@
1
+ import type * as Manifold3D from "manifold-3d";
2
+ import type { Base } from "@bitbybit-dev/base";
3
+ export type Built = Manifold3D.Manifold | Manifold3D.CrossSection | Base.RecipeHalfSpaceNode;
4
+ export type ProfileRings = readonly (readonly Manifold3D.Vec2[])[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const DEGREES_PER_RADIAN: number;
2
+ export declare const TRIANGLE_CORNERS = 3;
3
+ export declare const FLOAT32_THICKNESS: number;
@@ -0,0 +1,3 @@
1
+ export const DEGREES_PER_RADIAN = 180 / Math.PI;
2
+ export const TRIANGLE_CORNERS = 3;
3
+ export const FLOAT32_THICKNESS = Math.pow(2, -20);
@@ -0,0 +1,71 @@
1
+ import type * as Manifold3D from "manifold-3d";
2
+ import * as Inputs from "../../inputs/manifold-inputs";
3
+ /**
4
+ * Building recipes: solids described as data - polygons, circles, extrusions, turns and lofts, cuts,
5
+ * unions, openings, transforms and triangle meshes - by a package that does not build geometry
6
+ * itself, such as one that reads building models. Every result is a watertight mesh solid, so walls with their
7
+ * openings cut and roofs clipped come back ready to draw or to combine further.
8
+ *
9
+ * Experimental: the recipe format may still change before it is declared stable.
10
+ * @beta
11
+ */
12
+ export declare class ManifoldRecipes {
13
+ private manifold;
14
+ constructor(wasm: Manifold3D.ManifoldToplevel);
15
+ /**
16
+ * Builds each root of a recipe as a solid placed by its matrix, in root order.
17
+ *
18
+ * Shared nodes are built once. An invalid recipe throws before anything is built; a root the
19
+ * kernel cannot build, such as an open mesh, throws naming its node unless `emptyWhenFailed` is
20
+ * set. Circles get `circularSegments` sides; `tolerance` and `millimetresPerUnit` are not applied.
21
+ * @param inputs - The recipe, how finely circles are divided, and whether Z turns into Y
22
+ * @returns One solid per root, in root order
23
+ * @group build
24
+ * @shortname build recipe
25
+ * @drawable true
26
+ * @example
27
+ * ```typescript
28
+ * const recipe = await bitbybit.ifc.geometry.recipe({ model });
29
+ * const solids = await bitbybit.manifold.recipes.build({ recipe, adjustZtoY: true, emptyWhenFailed: true });
30
+ * ```
31
+ */
32
+ build(inputs: Inputs.Manifold.BuildRecipeDto): Manifold3D.Manifold[];
33
+ /**
34
+ * Builds a recipe into the meshes its roots draw, each step several roots place meshed once in
35
+ * its own coordinates, and gives every root a placement: its mesh, its matrix and its tag.
36
+ *
37
+ * Turns and moves fold into the placements, so a door type placed a hundred times is one mesh;
38
+ * normals split at edges sharper than `minSharpAngle`.
39
+ * @param inputs - The recipe, how finely circles are divided, whether Z turns into Y, whether failures are skipped, and where normals split
40
+ * @returns The meshes and one placement per root, in root order
41
+ * @group build
42
+ * @shortname recipe meshes
43
+ * @drawable false
44
+ * @example
45
+ * ```typescript
46
+ * const recipe = await bitbybit.ifc.geometry.recipe({ model });
47
+ * const { meshes, placements } = await bitbybit.manifold.recipes.meshes({ recipe, adjustZtoY: true, emptyWhenFailed: true });
48
+ * ```
49
+ */
50
+ meshes(inputs: Inputs.Manifold.BuildRecipeMeshesDto): Inputs.Manifold.RecipeMeshesDto;
51
+ /**
52
+ * Gives the roots of a recipe made of triangle meshes alone as meshes, placed as `build` places
53
+ * its solids, without building anything.
54
+ *
55
+ * `build` gives an open mesh back empty, since it cannot be a solid; this gives it as the surface
56
+ * it is, its openings left uncut. A root holding any other step comes back as an empty mesh.
57
+ * @param inputs - The recipe, which roots to read, and whether Z turns into Y
58
+ * @returns One mesh per asked root, in the order asked, ready to draw
59
+ * @group build
60
+ * @shortname surface meshes
61
+ * @drawable true
62
+ * @example
63
+ * ```typescript
64
+ * const solids = await bitbybit.manifold.recipes.build({ recipe, adjustZtoY: true, emptyWhenFailed: true });
65
+ * const meshes = await bitbybit.manifold.manifold.manifoldsToMeshes({ manifolds: solids });
66
+ * const open = meshes.flatMap((mesh, index) => mesh.triVerts.length === 0 ? [index] : []);
67
+ * const surfaces = await bitbybit.manifold.recipes.surfaceMeshes({ recipe, roots: open, adjustZtoY: true });
68
+ * ```
69
+ */
70
+ surfaceMeshes(inputs: Inputs.Manifold.RecipeSurfaceMeshesDto): Inputs.Manifold.DecomposedManifoldMeshDto[];
71
+ }
@@ -0,0 +1,104 @@
1
+ import { recipeSurfaceMeshes, resolveDto, toRecipe } from "@bitbybit-dev/base";
2
+ import * as Inputs from "../../inputs/manifold-inputs";
3
+ import { executeRecipe } from "./recipe-executor";
4
+ import { recipeMeshes } from "./recipe-meshes";
5
+ const MIN_CIRCLE_SIDES = 3;
6
+ const MAX_SHARP_ANGLE = 180;
7
+ const POSITION_PROPERTIES = 3;
8
+ /**
9
+ * Building recipes: solids described as data - polygons, circles, extrusions, turns and lofts, cuts,
10
+ * unions, openings, transforms and triangle meshes - by a package that does not build geometry
11
+ * itself, such as one that reads building models. Every result is a watertight mesh solid, so walls with their
12
+ * openings cut and roofs clipped come back ready to draw or to combine further.
13
+ *
14
+ * Experimental: the recipe format may still change before it is declared stable.
15
+ * @beta
16
+ */
17
+ export class ManifoldRecipes {
18
+ constructor(wasm) {
19
+ this.manifold = wasm;
20
+ }
21
+ /**
22
+ * Builds each root of a recipe as a solid placed by its matrix, in root order.
23
+ *
24
+ * Shared nodes are built once. An invalid recipe throws before anything is built; a root the
25
+ * kernel cannot build, such as an open mesh, throws naming its node unless `emptyWhenFailed` is
26
+ * set. Circles get `circularSegments` sides; `tolerance` and `millimetresPerUnit` are not applied.
27
+ * @param inputs - The recipe, how finely circles are divided, and whether Z turns into Y
28
+ * @returns One solid per root, in root order
29
+ * @group build
30
+ * @shortname build recipe
31
+ * @drawable true
32
+ * @example
33
+ * ```typescript
34
+ * const recipe = await bitbybit.ifc.geometry.recipe({ model });
35
+ * const solids = await bitbybit.manifold.recipes.build({ recipe, adjustZtoY: true, emptyWhenFailed: true });
36
+ * ```
37
+ */
38
+ build(inputs) {
39
+ const resolved = resolveDto(Inputs.Manifold.BuildRecipeDto, inputs);
40
+ const recipe = toRecipe(resolved.recipe);
41
+ if (!Number.isSafeInteger(resolved.circularSegments) || resolved.circularSegments < MIN_CIRCLE_SIDES) {
42
+ throw new RangeError(`A circle needs at least ${MIN_CIRCLE_SIDES} sides, got ${resolved.circularSegments}`);
43
+ }
44
+ return executeRecipe(this.manifold, recipe, resolved.circularSegments, resolved.adjustZtoY, resolved.emptyWhenFailed);
45
+ }
46
+ /**
47
+ * Builds a recipe into the meshes its roots draw, each step several roots place meshed once in
48
+ * its own coordinates, and gives every root a placement: its mesh, its matrix and its tag.
49
+ *
50
+ * Turns and moves fold into the placements, so a door type placed a hundred times is one mesh;
51
+ * normals split at edges sharper than `minSharpAngle`.
52
+ * @param inputs - The recipe, how finely circles are divided, whether Z turns into Y, whether failures are skipped, and where normals split
53
+ * @returns The meshes and one placement per root, in root order
54
+ * @group build
55
+ * @shortname recipe meshes
56
+ * @drawable false
57
+ * @example
58
+ * ```typescript
59
+ * const recipe = await bitbybit.ifc.geometry.recipe({ model });
60
+ * const { meshes, placements } = await bitbybit.manifold.recipes.meshes({ recipe, adjustZtoY: true, emptyWhenFailed: true });
61
+ * ```
62
+ */
63
+ meshes(inputs) {
64
+ const resolved = resolveDto(Inputs.Manifold.BuildRecipeMeshesDto, inputs);
65
+ const recipe = toRecipe(resolved.recipe);
66
+ if (!Number.isSafeInteger(resolved.circularSegments) || resolved.circularSegments < MIN_CIRCLE_SIDES) {
67
+ throw new RangeError(`A circle needs at least ${MIN_CIRCLE_SIDES} sides, got ${resolved.circularSegments}`);
68
+ }
69
+ if (!(resolved.minSharpAngle >= 0 && resolved.minSharpAngle <= MAX_SHARP_ANGLE)) {
70
+ throw new RangeError(`minSharpAngle must be an angle from 0 to ${MAX_SHARP_ANGLE} degrees, got ${resolved.minSharpAngle}`);
71
+ }
72
+ return recipeMeshes(this.manifold, recipe, resolved);
73
+ }
74
+ /**
75
+ * Gives the roots of a recipe made of triangle meshes alone as meshes, placed as `build` places
76
+ * its solids, without building anything.
77
+ *
78
+ * `build` gives an open mesh back empty, since it cannot be a solid; this gives it as the surface
79
+ * it is, its openings left uncut. A root holding any other step comes back as an empty mesh.
80
+ * @param inputs - The recipe, which roots to read, and whether Z turns into Y
81
+ * @returns One mesh per asked root, in the order asked, ready to draw
82
+ * @group build
83
+ * @shortname surface meshes
84
+ * @drawable true
85
+ * @example
86
+ * ```typescript
87
+ * const solids = await bitbybit.manifold.recipes.build({ recipe, adjustZtoY: true, emptyWhenFailed: true });
88
+ * const meshes = await bitbybit.manifold.manifold.manifoldsToMeshes({ manifolds: solids });
89
+ * const open = meshes.flatMap((mesh, index) => mesh.triVerts.length === 0 ? [index] : []);
90
+ * const surfaces = await bitbybit.manifold.recipes.surfaceMeshes({ recipe, roots: open, adjustZtoY: true });
91
+ * ```
92
+ */
93
+ surfaceMeshes(inputs) {
94
+ const resolved = resolveDto(Inputs.Manifold.RecipeSurfaceMeshesDto, inputs);
95
+ return recipeSurfaceMeshes(resolved.recipe, resolved.roots, resolved.adjustZtoY).map((mesh) => {
96
+ var _a, _b;
97
+ return ({
98
+ numProp: POSITION_PROPERTIES,
99
+ vertProperties: (_a = mesh === null || mesh === void 0 ? void 0 : mesh.positions) !== null && _a !== void 0 ? _a : new Float32Array(0),
100
+ triVerts: (_b = mesh === null || mesh === void 0 ? void 0 : mesh.indices) !== null && _b !== void 0 ? _b : new Uint32Array(0),
101
+ });
102
+ });
103
+ }
104
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitbybit-dev/manifold",
3
- "version": "1.4.0",
3
+ "version": "1.5.0-rc.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.3",
58
- "@bitbybit-dev/base": "1.4.0"
58
+ "@bitbybit-dev/base": "1.5.0-rc.0"
59
59
  }
60
60
  }