@bitbybit-dev/manifold 1.4.1 → 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
@@ -51,7 +51,7 @@ export var Manifold;
51
51
  /**
52
52
  * Provide options without default values
53
53
  */
54
- constructor(manifoldOrCrossSection, faceOpacity, faceMaterial, faceColour, crossSectionColour, crossSectionWidth, crossSectionOpacity, computeNormals, drawTwoSided, backFaceColour, backFaceOpacity) {
54
+ constructor(manifoldOrCrossSection, faceOpacity, faceMaterial, faceColour, crossSectionColour, crossSectionWidth, crossSectionOpacity, computeNormals, drawTwoSided, backFaceColour, backFaceOpacity, minSharpAngle) {
55
55
  /**
56
56
  * How opaque the faces are, from 0 for invisible to 1 for solid.
57
57
  * @default 1
@@ -84,10 +84,20 @@ export var Manifold;
84
84
  */
85
85
  this.crossSectionOpacity = 1;
86
86
  /**
87
- * When true, normals are computed for the mesh so it shades smoothly.
88
- * @default false
87
+ * When true, solids shade smoothly across edges flatter than `minSharpAngle` and keep sharper
88
+ * ones crisp; when false, every face is shaded flat.
89
+ * @default true
90
+ */
91
+ this.computeNormals = true;
92
+ /**
93
+ * The angle between two faces, in degrees, above which their shared edge is drawn sharp when
94
+ * `computeNormals` is true.
95
+ * @default 40
96
+ * @minimum 0
97
+ * @maximum 180
98
+ * @step 5
89
99
  */
90
- this.computeNormals = false;
100
+ this.minSharpAngle = 40;
91
101
  /**
92
102
  * When true, the back of each face is drawn in its own color, which shows which way faces
93
103
  * point.
@@ -140,6 +150,9 @@ export var Manifold;
140
150
  if (backFaceOpacity !== undefined) {
141
151
  this.backFaceOpacity = backFaceOpacity;
142
152
  }
153
+ if (minSharpAngle !== undefined) {
154
+ this.minSharpAngle = minSharpAngle;
155
+ }
143
156
  }
144
157
  }
145
158
  Manifold.DrawManifoldOrCrossSectionDto = DrawManifoldOrCrossSectionDto;
@@ -151,7 +164,7 @@ export var Manifold;
151
164
  /**
152
165
  * Provide options without default values
153
166
  */
154
- constructor(manifoldsOrCrossSections, faceOpacity, faceMaterial, faceColour, crossSectionColour, crossSectionWidth, crossSectionOpacity, computeNormals, drawTwoSided, backFaceColour, backFaceOpacity) {
167
+ constructor(manifoldsOrCrossSections, faceOpacity, faceMaterial, faceColour, crossSectionColour, crossSectionWidth, crossSectionOpacity, computeNormals, drawTwoSided, backFaceColour, backFaceOpacity, minSharpAngle) {
155
168
  /**
156
169
  * The color of the faces as a hex string such as `#ff0000`.
157
170
  * @default #ff0000
@@ -184,10 +197,20 @@ export var Manifold;
184
197
  */
185
198
  this.crossSectionOpacity = 1;
186
199
  /**
187
- * When true, normals are computed for the meshes so they shade smoothly.
188
- * @default false
200
+ * When true, solids shade smoothly across edges flatter than `minSharpAngle` and keep sharper
201
+ * ones crisp; when false, every face is shaded flat.
202
+ * @default true
203
+ */
204
+ this.computeNormals = true;
205
+ /**
206
+ * The angle between two faces, in degrees, above which their shared edge is drawn sharp when
207
+ * `computeNormals` is true.
208
+ * @default 40
209
+ * @minimum 0
210
+ * @maximum 180
211
+ * @step 5
189
212
  */
190
- this.computeNormals = false;
213
+ this.minSharpAngle = 40;
191
214
  /**
192
215
  * When true, the back of each face is drawn in its own color, which shows which way faces
193
216
  * point.
@@ -240,6 +263,9 @@ export var Manifold;
240
263
  if (backFaceOpacity !== undefined) {
241
264
  this.backFaceOpacity = backFaceOpacity;
242
265
  }
266
+ if (minSharpAngle !== undefined) {
267
+ this.minSharpAngle = minSharpAngle;
268
+ }
243
269
  }
244
270
  }
245
271
  Manifold.DrawManifoldsOrCrossSectionsDto = DrawManifoldsOrCrossSectionsDto;
@@ -1134,6 +1160,62 @@ export var Manifold;
1134
1160
  }
1135
1161
  }
1136
1162
  Manifold.RevolveDto = RevolveDto;
1163
+ /**
1164
+ * Cross-sections and the frames that place them for `crossSection.operations.loft`, which joins them
1165
+ * in order into a solid.
1166
+ */
1167
+ class LoftDto {
1168
+ constructor(crossSections, frames) {
1169
+ if (crossSections !== undefined) {
1170
+ this.crossSections = crossSections;
1171
+ }
1172
+ if (frames !== undefined) {
1173
+ this.frames = frames;
1174
+ }
1175
+ }
1176
+ }
1177
+ Manifold.LoftDto = LoftDto;
1178
+ /**
1179
+ * A cross-section, a path and the corner settings for `crossSection.operations.sweep`, which
1180
+ * carries the cross-section along the path into a solid.
1181
+ */
1182
+ class SweepDto {
1183
+ constructor(crossSection, path, cornerRadius, circularSegments, xDirection) {
1184
+ /**
1185
+ * How much the path's corners are rounded; 0 keeps them sharp, mitred so the solid keeps its
1186
+ * width.
1187
+ * @default 0
1188
+ * @minimum 0
1189
+ * @maximum Infinity
1190
+ * @step 0.1
1191
+ */
1192
+ this.cornerRadius = 0;
1193
+ /**
1194
+ * How many segments a whole turn of a rounded corner is divided into; more is rounder.
1195
+ * @default 32
1196
+ * @minimum 3
1197
+ * @maximum Infinity
1198
+ * @step 1
1199
+ */
1200
+ this.circularSegments = 32;
1201
+ if (crossSection !== undefined) {
1202
+ this.crossSection = crossSection;
1203
+ }
1204
+ if (path !== undefined) {
1205
+ this.path = path;
1206
+ }
1207
+ if (cornerRadius !== undefined) {
1208
+ this.cornerRadius = cornerRadius;
1209
+ }
1210
+ if (circularSegments !== undefined) {
1211
+ this.circularSegments = circularSegments;
1212
+ }
1213
+ if (xDirection !== undefined) {
1214
+ this.xDirection = xDirection;
1215
+ }
1216
+ }
1217
+ }
1218
+ Manifold.SweepDto = SweepDto;
1137
1219
  /**
1138
1220
  * A cross-section and the offset settings for `crossSection.operations.offset`.
1139
1221
  */
@@ -1785,13 +1867,16 @@ export var Manifold;
1785
1867
  * A solid or cross-section and an optional normal channel for `decomposeManifoldOrCrossSection`.
1786
1868
  */
1787
1869
  class DecomposeManifoldOrCrossSectionDto {
1788
- constructor(manifoldOrCrossSection, normalIdx) {
1870
+ constructor(manifoldOrCrossSection, normalIdx, minSharpAngle) {
1789
1871
  if (manifoldOrCrossSection !== undefined) {
1790
1872
  this.manifoldOrCrossSection = manifoldOrCrossSection;
1791
1873
  }
1792
1874
  if (normalIdx !== undefined) {
1793
1875
  this.normalIdx = normalIdx;
1794
1876
  }
1877
+ if (minSharpAngle !== undefined) {
1878
+ this.minSharpAngle = minSharpAngle;
1879
+ }
1795
1880
  }
1796
1881
  }
1797
1882
  Manifold.DecomposeManifoldOrCrossSectionDto = DecomposeManifoldOrCrossSectionDto;
@@ -1822,14 +1907,156 @@ export var Manifold;
1822
1907
  * `decomposeManifoldsOrCrossSections`.
1823
1908
  */
1824
1909
  class DecomposeManifoldsOrCrossSectionsDto {
1825
- constructor(manifoldsOrCrossSections, normalIdx) {
1910
+ constructor(manifoldsOrCrossSections, normalIdx, minSharpAngle) {
1826
1911
  if (manifoldsOrCrossSections !== undefined) {
1827
1912
  this.manifoldsOrCrossSections = manifoldsOrCrossSections;
1828
1913
  }
1829
1914
  if (normalIdx !== undefined) {
1830
1915
  this.normalIdx = normalIdx;
1831
1916
  }
1917
+ if (minSharpAngle !== undefined) {
1918
+ this.minSharpAngle = minSharpAngle;
1919
+ }
1832
1920
  }
1833
1921
  }
1834
1922
  Manifold.DecomposeManifoldsOrCrossSectionsDto = DecomposeManifoldsOrCrossSectionsDto;
1923
+ /**
1924
+ * A recipe for `recipes.build`, which builds each of its roots as a solid, with how finely circles
1925
+ * are divided and whether Z turns into Y. Experimental: the recipe format may still change.
1926
+ * @beta
1927
+ */
1928
+ class BuildRecipeDto {
1929
+ constructor(recipe, circularSegments, adjustZtoY, emptyWhenFailed) {
1930
+ /**
1931
+ * How many flat sides each circle of the recipe is divided into; more is rounder. The recipe
1932
+ * leaves this to the kernel, so it is chosen here.
1933
+ * @default 32
1934
+ * @minimum 3
1935
+ * @maximum Infinity
1936
+ * @step 1
1937
+ */
1938
+ this.circularSegments = 32;
1939
+ /**
1940
+ * When true, each solid turns a quarter turn about X so the recipe's Z points along Y, which is
1941
+ * up when drawn: `(x, y, z)` becomes `(x, z, -y)`.
1942
+ * @default false
1943
+ */
1944
+ this.adjustZtoY = false;
1945
+ /**
1946
+ * When true, a root that cannot be built, such as an open mesh, comes back empty, and an
1947
+ * opening that cannot is left uncut; when false, both stop the build.
1948
+ * @default false
1949
+ */
1950
+ this.emptyWhenFailed = false;
1951
+ if (recipe !== undefined) {
1952
+ this.recipe = recipe;
1953
+ }
1954
+ if (circularSegments !== undefined) {
1955
+ this.circularSegments = circularSegments;
1956
+ }
1957
+ if (adjustZtoY !== undefined) {
1958
+ this.adjustZtoY = adjustZtoY;
1959
+ }
1960
+ if (emptyWhenFailed !== undefined) {
1961
+ this.emptyWhenFailed = emptyWhenFailed;
1962
+ }
1963
+ }
1964
+ }
1965
+ Manifold.BuildRecipeDto = BuildRecipeDto;
1966
+ /**
1967
+ * A recipe for `recipes.surfaceMeshes`, which gives the roots made of triangle meshes alone as
1968
+ * meshes, with which roots to read and whether Z turns into Y. Experimental: the recipe format may
1969
+ * still change.
1970
+ * @beta
1971
+ */
1972
+ class RecipeSurfaceMeshesDto {
1973
+ constructor(recipe, roots, adjustZtoY) {
1974
+ /**
1975
+ * When true, each mesh turns a quarter turn about X so the recipe's Z points along Y, as
1976
+ * `recipes.build` turns its solids: `(x, y, z)` becomes `(x, z, -y)`.
1977
+ * @default false
1978
+ */
1979
+ this.adjustZtoY = false;
1980
+ if (recipe !== undefined) {
1981
+ this.recipe = recipe;
1982
+ }
1983
+ if (roots !== undefined) {
1984
+ this.roots = roots;
1985
+ }
1986
+ if (adjustZtoY !== undefined) {
1987
+ this.adjustZtoY = adjustZtoY;
1988
+ }
1989
+ }
1990
+ }
1991
+ Manifold.RecipeSurfaceMeshesDto = RecipeSurfaceMeshesDto;
1992
+ /**
1993
+ * A recipe for `recipes.meshes`, which gives the meshes its roots draw, with how finely circles are
1994
+ * divided, whether Z turns into Y, whether failures are skipped and where normals split.
1995
+ * Experimental: the recipe format may still change.
1996
+ * @beta
1997
+ */
1998
+ class BuildRecipeMeshesDto {
1999
+ constructor(recipe, circularSegments, adjustZtoY, emptyWhenFailed, minSharpAngle) {
2000
+ /**
2001
+ * How many flat sides each circle of the recipe is divided into; more is rounder.
2002
+ * @default 32
2003
+ * @minimum 3
2004
+ * @maximum Infinity
2005
+ * @step 1
2006
+ */
2007
+ this.circularSegments = 32;
2008
+ /**
2009
+ * When true, every placement turns a quarter turn about X so the recipe's Z points along Y,
2010
+ * which is up when drawn: `(x, y, z)` becomes `(x, z, -y)`.
2011
+ * @default false
2012
+ */
2013
+ this.adjustZtoY = false;
2014
+ /**
2015
+ * When true, a root that cannot be built draws as its surface if it is triangles alone, else
2016
+ * draws nothing; when false, it stops the build.
2017
+ * @default false
2018
+ */
2019
+ this.emptyWhenFailed = false;
2020
+ /**
2021
+ * Edges sharper than this, in degrees, keep a normal on each side; 0 shades every face flat.
2022
+ * @default 40
2023
+ * @minimum 0
2024
+ * @maximum 180
2025
+ * @step 5
2026
+ */
2027
+ this.minSharpAngle = 40;
2028
+ if (recipe !== undefined) {
2029
+ this.recipe = recipe;
2030
+ }
2031
+ if (circularSegments !== undefined) {
2032
+ this.circularSegments = circularSegments;
2033
+ }
2034
+ if (adjustZtoY !== undefined) {
2035
+ this.adjustZtoY = adjustZtoY;
2036
+ }
2037
+ if (emptyWhenFailed !== undefined) {
2038
+ this.emptyWhenFailed = emptyWhenFailed;
2039
+ }
2040
+ if (minSharpAngle !== undefined) {
2041
+ this.minSharpAngle = minSharpAngle;
2042
+ }
2043
+ }
2044
+ }
2045
+ Manifold.BuildRecipeMeshesDto = BuildRecipeMeshesDto;
2046
+ /**
2047
+ * Where one recipe root draws: which mesh, placed by which matrix, with the root's tag and group.
2048
+ * Experimental: the recipe format may still change.
2049
+ * @beta
2050
+ */
2051
+ class RecipeMeshPlacementDto {
2052
+ }
2053
+ Manifold.RecipeMeshPlacementDto = RecipeMeshPlacementDto;
2054
+ /**
2055
+ * The meshes a recipe draws, each shared one once, and one placement per root, in root order.
2056
+ * Experimental: the recipe format may still change.
2057
+ * @beta
2058
+ */
2059
+ class RecipeMeshesDto {
2060
+ }
2061
+ Manifold.RecipeMeshesDto = RecipeMeshesDto;
1835
2062
  })(Manifold || (Manifold = {}));
@@ -1,15 +1,16 @@
1
- import * as Manifold3D from "manifold-3d";
2
- import * as Inputs from "./inputs";
1
+ import type * as Manifold3D from "manifold-3d";
2
+ import type * as Inputs from "./inputs";
3
3
  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
+ import { ManifoldRecipes } from "./services/recipes/recipes";
6
7
  /**
7
8
  * The entry point to the Manifold kernel, a fast mesh-based solid modeler: `manifold` builds and
8
- * changes solids, `crossSection` handles the flat outlines they are extruded and revolved from, and
9
- * `mesh` reads the triangle data. Manifold works on triangle meshes rather than exact curves, so
10
- * booleans are quick and always watertight, and it keeps its own Z axis as up: extrusions grow
11
- * along Z and slices are parallel to the XY plane. The methods on the service itself turn solids
12
- * and cross-sections into plain mesh data for drawing.
9
+ * changes solids, `crossSection` handles the flat outlines they are extruded and revolved from,
10
+ * `mesh` reads the triangle data, and `recipes` builds solids described as data. Manifold works on
11
+ * triangle meshes rather than exact curves, so booleans are quick and always watertight, and it
12
+ * keeps its own Z axis as up: extrusions grow along Z and slices are parallel to the XY plane. The
13
+ * methods on the service itself turn solids and cross-sections into plain mesh data for drawing.
13
14
  */
14
15
  export declare class ManifoldService {
15
16
  plugins: any;
@@ -17,13 +18,19 @@ export declare class ManifoldService {
17
18
  crossSection: CrossSection;
18
19
  private base;
19
20
  mesh: Mesh;
21
+ /**
22
+ * Experimental: builds solids described as data, whose format may still change.
23
+ * @beta
24
+ */
25
+ recipes: ManifoldRecipes;
26
+ private readonly wasm;
20
27
  constructor(wasm: Manifold3D.ManifoldToplevel);
21
28
  /**
22
29
  * Turns a solid into plain mesh data, or a cross-section into its polygons, ready for drawing
23
30
  * or export.
24
31
  *
25
- * `normalIdx` names the vertex property channel that holds normals, when the solid carries
26
- * them.
32
+ * `normalIdx` names the channel holding normals the solid carries. With `minSharpAngle`, normals
33
+ * follow each position, smooth across flatter edges and split across sharper ones.
27
34
  * @param inputs - The solid or cross-section and the optional normal channel
28
35
  * @returns The mesh data of a solid, or the polygons of a cross-section
29
36
  * @group decompose
@@ -1,28 +1,32 @@
1
1
  import { Manifold } from "./services/manifold/manifold";
2
2
  import { CrossSection } from "./services/cross-section/cross-section";
3
3
  import { Mesh } from "./services/mesh/mesh";
4
+ import { ManifoldRecipes } from "./services/recipes/recipes";
5
+ import { creasedMeshData, positionsOf } from "./services/mesh-data";
4
6
  import { BaseBitByBit } from "../base";
5
7
  /**
6
8
  * The entry point to the Manifold kernel, a fast mesh-based solid modeler: `manifold` builds and
7
- * changes solids, `crossSection` handles the flat outlines they are extruded and revolved from, and
8
- * `mesh` reads the triangle data. Manifold works on triangle meshes rather than exact curves, so
9
- * booleans are quick and always watertight, and it keeps its own Z axis as up: extrusions grow
10
- * along Z and slices are parallel to the XY plane. The methods on the service itself turn solids
11
- * and cross-sections into plain mesh data for drawing.
9
+ * changes solids, `crossSection` handles the flat outlines they are extruded and revolved from,
10
+ * `mesh` reads the triangle data, and `recipes` builds solids described as data. Manifold works on
11
+ * triangle meshes rather than exact curves, so booleans are quick and always watertight, and it
12
+ * keeps its own Z axis as up: extrusions grow along Z and slices are parallel to the XY plane. The
13
+ * methods on the service itself turn solids and cross-sections into plain mesh data for drawing.
12
14
  */
13
15
  export class ManifoldService {
14
16
  constructor(wasm) {
17
+ this.wasm = wasm;
15
18
  this.base = new BaseBitByBit();
16
19
  this.manifold = new Manifold(wasm);
17
20
  this.crossSection = new CrossSection(wasm, this.base);
18
21
  this.mesh = new Mesh(wasm);
22
+ this.recipes = new ManifoldRecipes(wasm);
19
23
  }
20
24
  /**
21
25
  * Turns a solid into plain mesh data, or a cross-section into its polygons, ready for drawing
22
26
  * or export.
23
27
  *
24
- * `normalIdx` names the vertex property channel that holds normals, when the solid carries
25
- * them.
28
+ * `normalIdx` names the channel holding normals the solid carries. With `minSharpAngle`, normals
29
+ * follow each position, smooth across flatter edges and split across sharper ones.
26
30
  * @param inputs - The solid or cross-section and the optional normal channel
27
31
  * @returns The mesh data of a solid, or the polygons of a cross-section
28
32
  * @group decompose
@@ -35,7 +39,15 @@ export class ManifoldService {
35
39
  */
36
40
  decomposeManifoldOrCrossSection(inputs) {
37
41
  if (inputs.manifoldOrCrossSection.getMesh) {
38
- return inputs.manifoldOrCrossSection.getMesh(inputs.normalIdx);
42
+ const solid = inputs.manifoldOrCrossSection;
43
+ if (inputs.minSharpAngle === undefined) {
44
+ return solid.getMesh(inputs.normalIdx);
45
+ }
46
+ if (!Number.isFinite(inputs.minSharpAngle) || inputs.minSharpAngle < 0) {
47
+ throw new RangeError(`minSharpAngle must be a finite angle of at least 0 degrees, got ${inputs.minSharpAngle}`);
48
+ }
49
+ const plain = solid.getMesh();
50
+ return new this.wasm.Mesh(creasedMeshData(positionsOf(plain), plain.triVerts, inputs.minSharpAngle));
39
51
  }
40
52
  else {
41
53
  return inputs.manifoldOrCrossSection.toPolygons();
@@ -117,6 +129,7 @@ export class ManifoldService {
117
129
  const normalIdx = inputs.normalIdx ? inputs.normalIdx[index] : undefined;
118
130
  return this.decomposeManifoldOrCrossSection({
119
131
  manifoldOrCrossSection,
132
+ minSharpAngle: inputs.minSharpAngle,
120
133
  normalIdx
121
134
  });
122
135
  });
@@ -6,6 +6,8 @@ export * from "@bitbybit-dev/base/lib/api/resolved-inputs";
6
6
  * the way `resolveDto` hands a DTO to the code that reads it.
7
7
  */
8
8
  export declare namespace Manifold {
9
+ type BuildRecipeDto = WithDefaults<Inputs.Manifold.BuildRecipeDto, "circularSegments" | "adjustZtoY" | "emptyWhenFailed">;
10
+ type BuildRecipeMeshesDto = WithDefaults<Inputs.Manifold.BuildRecipeMeshesDto, "circularSegments" | "adjustZtoY" | "emptyWhenFailed" | "minSharpAngle">;
9
11
  type CalculateCurvatureDto<T> = WithDefaults<Inputs.Manifold.CalculateCurvatureDto<T>, "gaussianIdx" | "meanIdx">;
10
12
  type CalculateNormalsDto<T> = WithDefaults<Inputs.Manifold.CalculateNormalsDto<T>, "normalIdx" | "minSharpAngle">;
11
13
  type CircleDto = WithDefaults<Inputs.Manifold.CircleDto, "radius" | "circularSegments">;
@@ -23,11 +25,12 @@ export declare namespace Manifold {
23
25
  type DecomposedManifoldMeshDto = Inputs.Manifold.DecomposedManifoldMeshDto;
24
26
  type DecomposeManifoldOrCrossSectionDto<T> = Inputs.Manifold.DecomposeManifoldOrCrossSectionDto<T>;
25
27
  type DecomposeManifoldsOrCrossSectionsDto<T> = Inputs.Manifold.DecomposeManifoldsOrCrossSectionsDto<T>;
26
- type DrawManifoldOrCrossSectionDto<T, M> = WithDefaults<Inputs.Manifold.DrawManifoldOrCrossSectionDto<T, M>, "faceOpacity" | "faceColour" | "crossSectionColour" | "crossSectionWidth" | "crossSectionOpacity" | "computeNormals" | "drawTwoSided" | "backFaceColour" | "backFaceOpacity">;
27
- type DrawManifoldsOrCrossSectionsDto<T, M> = WithDefaults<Inputs.Manifold.DrawManifoldsOrCrossSectionsDto<T, M>, "faceColour" | "faceOpacity" | "crossSectionColour" | "crossSectionWidth" | "crossSectionOpacity" | "computeNormals" | "drawTwoSided" | "backFaceColour" | "backFaceOpacity">;
28
+ type DrawManifoldOrCrossSectionDto<T, M> = WithDefaults<Inputs.Manifold.DrawManifoldOrCrossSectionDto<T, M>, "faceOpacity" | "faceColour" | "crossSectionColour" | "crossSectionWidth" | "crossSectionOpacity" | "computeNormals" | "minSharpAngle" | "drawTwoSided" | "backFaceColour" | "backFaceOpacity">;
29
+ type DrawManifoldsOrCrossSectionsDto<T, M> = WithDefaults<Inputs.Manifold.DrawManifoldsOrCrossSectionsDto<T, M>, "faceColour" | "faceOpacity" | "crossSectionColour" | "crossSectionWidth" | "crossSectionOpacity" | "computeNormals" | "minSharpAngle" | "drawTwoSided" | "backFaceColour" | "backFaceOpacity">;
28
30
  type ExtrudeDto<T> = WithDefaults<Inputs.Manifold.ExtrudeDto<T>, "height" | "nDivisions" | "twistDegrees" | "scaleTopX" | "scaleTopY" | "center">;
29
31
  type FromPolygonPointsDto = Inputs.Manifold.FromPolygonPointsDto;
30
32
  type HullPointsDto<T> = Inputs.Manifold.HullPointsDto<T>;
33
+ type LoftDto<T> = Inputs.Manifold.LoftDto<T>;
31
34
  type ManifoldDto<T> = Inputs.Manifold.ManifoldDto<T>;
32
35
  type ManifoldOrCrossSectionDto<T> = Inputs.Manifold.ManifoldOrCrossSectionDto<T>;
33
36
  type ManifoldRefineDto<T> = WithDefaults<Inputs.Manifold.ManifoldRefineDto<T>, "number">;
@@ -52,6 +55,9 @@ export declare namespace Manifold {
52
55
  type MirrorDto<T> = WithDefaults<Inputs.Manifold.MirrorDto<T>, "normal">;
53
56
  type OffsetDto<T> = WithDefaults<Inputs.Manifold.OffsetDto<T>, "delta" | "joinType" | "miterLimit" | "circularSegments">;
54
57
  type RayCastDto<T> = WithDefaults<Inputs.Manifold.RayCastDto<T>, "origin" | "endpoint">;
58
+ type RecipeMeshesDto = Inputs.Manifold.RecipeMeshesDto;
59
+ type RecipeMeshPlacementDto = Inputs.Manifold.RecipeMeshPlacementDto;
60
+ type RecipeSurfaceMeshesDto = WithDefaults<Inputs.Manifold.RecipeSurfaceMeshesDto, "adjustZtoY">;
55
61
  type RectangleDto = WithDefaults<Inputs.Manifold.RectangleDto, "length" | "height" | "center">;
56
62
  type RevolveDto<T> = WithDefaults<Inputs.Manifold.RevolveDto<T>, "revolveDegrees" | "matchProfile" | "circularSegments">;
57
63
  type RotateCrossSectionDto<T> = WithDefaults<Inputs.Manifold.RotateCrossSectionDto<T>, "degrees">;
@@ -68,6 +74,7 @@ export declare namespace Manifold {
68
74
  type SplitByPlaneOnOffsetsDto<T> = WithDefaults<Inputs.Manifold.SplitByPlaneOnOffsetsDto<T>, "normal" | "originOffsets">;
69
75
  type SplitManifoldsDto<T> = Inputs.Manifold.SplitManifoldsDto<T>;
70
76
  type SquareDto = WithDefaults<Inputs.Manifold.SquareDto, "center" | "size">;
77
+ type SweepDto<T> = WithDefaults<Inputs.Manifold.SweepDto<T>, "cornerRadius" | "circularSegments">;
71
78
  type TransformCrossSectionDto<T> = Inputs.Manifold.TransformCrossSectionDto<T>;
72
79
  type TransformDto<T> = Inputs.Manifold.TransformDto<T>;
73
80
  type TransformsDto<T> = Inputs.Manifold.TransformsDto<T>;
@@ -1,5 +1,5 @@
1
- import * as Inputs from "../../inputs/manifold-inputs";
2
- import * as Manifold3D from "manifold-3d";
1
+ import type * as Inputs from "../../inputs/manifold-inputs";
2
+ import type * as Manifold3D from "manifold-3d";
3
3
  /**
4
4
  * Combining Manifold cross-sections: fusing, cutting and intersecting two or many flat outlines at
5
5
  * once. The two-shape and many-shape forms give the same results and exist for convenience; every
@@ -1,5 +1,5 @@
1
- import * as Inputs from "../../inputs";
2
- import * as Manifold3D from "manifold-3d";
1
+ import type * as Inputs from "../../inputs";
2
+ import type * as Manifold3D from "manifold-3d";
3
3
  /**
4
4
  * Measuring Manifold cross-sections: area, emptiness, vertex and contour counts and the bounding
5
5
  * rectangle. Nothing here changes the cross-section.
@@ -1,9 +1,10 @@
1
1
  import * as Inputs from "../../inputs/manifold-inputs";
2
- import * as Manifold3D from "manifold-3d";
2
+ import type * as Manifold3D from "manifold-3d";
3
3
  /**
4
4
  * Working with Manifold cross-sections beyond booleans: turning them into solids by extruding along
5
- * Z or revolving, offsetting their outlines, wrapping them in a convex hull, simplifying them, and
6
- * composing and decomposing them. Every method returns a new shape.
5
+ * Z, revolving, lofting through frames or sweeping along a path, offsetting their outlines, wrapping
6
+ * them in a convex hull, simplifying them, and composing and decomposing them. Every method returns a
7
+ * new shape.
7
8
  */
8
9
  export declare class CrossSectionOperations {
9
10
  private manifold;
@@ -58,6 +59,43 @@ export declare class CrossSectionOperations {
58
59
  * ```
59
60
  */
60
61
  revolve(inputs: Inputs.Manifold.RevolveDto<Manifold3D.CrossSection>): Manifold3D.Manifold;
62
+ /**
63
+ * Joins cross-sections placed by frames into a solid, each section to the next by straight
64
+ * sides, closed at both ends: a taper from one outline to another, or one outline through many
65
+ * frames.
66
+ *
67
+ * Corner `i` of a section joins corner `i` of the next, so differing sections need matching loops;
68
+ * frames move the sections apart, mirroring all or none.
69
+ * @param inputs - The cross-sections, one or one per frame, and the frames that place them
70
+ * @returns The lofted solid
71
+ * @group basic
72
+ * @shortname loft
73
+ * @drawable true
74
+ * @example
75
+ * ```typescript
76
+ * const square = await bitbybit.manifold.crossSection.shapes.square({ size: 2, center: true });
77
+ * const solid = await bitbybit.manifold.crossSection.operations.loft({ crossSections: [square], frames: [[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], [0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1, 0, 0, 0, 4, 1]] });
78
+ * ```
79
+ */
80
+ loft(inputs: Inputs.Manifold.LoftDto<Manifold3D.CrossSection>): Manifold3D.Manifold;
81
+ /**
82
+ * Carries a cross-section along a path of points into a solid, square to the path at every
83
+ * point and turning with it without twisting, like a pipe, a rail or a cable.
84
+ *
85
+ * Sharp corners are mitred so the solid keeps its width; `cornerRadius` rounds them instead.
86
+ * `xDirection` sets where the profile's X axis points at the start.
87
+ * @param inputs - The cross-section, the path, the corner radius and its segments, and the profile's starting X direction
88
+ * @returns The swept solid
89
+ * @group basic
90
+ * @shortname sweep
91
+ * @drawable true
92
+ * @example
93
+ * ```typescript
94
+ * const ring = await bitbybit.manifold.crossSection.shapes.circle({ radius: 1, circularSegments: 32 });
95
+ * const pipe = await bitbybit.manifold.crossSection.operations.sweep({ crossSection: ring, path: [[0, 0, 0], [10, 0, 0], [10, 10, 0], [10, 10, 10]], cornerRadius: 3, circularSegments: 32 });
96
+ * ```
97
+ */
98
+ sweep(inputs: Inputs.Manifold.SweepDto<Manifold3D.CrossSection>): Manifold3D.Manifold;
61
99
  /**
62
100
  * Moves the outline of a cross-section outward by `delta`, or inward for a negative delta, so
63
101
  * an outer contour grows and a hole shrinks.
@@ -1,9 +1,20 @@
1
1
  import * as Inputs from "../../inputs/manifold-inputs";
2
- import { resolveDto } from "@bitbybit-dev/base";
2
+ import { InputError, resolveDto } from "@bitbybit-dev/base";
3
+ import { isTransformMatrix, linearDeterminant } from "@bitbybit-dev/base/lib/api/services/helpers/matrices";
4
+ import { pathTangents, roundedPath3, sweepMatrices, transportedAxes } from "@bitbybit-dev/base/lib/api/services/helpers/paths";
5
+ import { loftMesh } from "../recipes/recipe-loft";
6
+ import { DEGENERATE_DETERMINANT, FULL_TURN, MIN_CIRCLE_SIDES, MIN_LOFT_FRAMES, NO_DIRECTION } from "./cross-section.constants";
7
+ function isPlacing(frame) {
8
+ return isTransformMatrix(frame) && frame[3] === 0 && frame[7] === 0 && frame[11] === 0 && frame[15] === 1 && Math.abs(linearDeterminant(frame)) > DEGENERATE_DETERMINANT;
9
+ }
10
+ function distinctPoints(path) {
11
+ return path.filter((point, at) => at === 0 || point.some((value, axis) => value !== path[at - 1][axis]));
12
+ }
3
13
  /**
4
14
  * Working with Manifold cross-sections beyond booleans: turning them into solids by extruding along
5
- * Z or revolving, offsetting their outlines, wrapping them in a convex hull, simplifying them, and
6
- * composing and decomposing them. Every method returns a new shape.
15
+ * Z, revolving, lofting through frames or sweeping along a path, offsetting their outlines, wrapping
16
+ * them in a convex hull, simplifying them, and composing and decomposing them. Every method returns a
17
+ * new shape.
7
18
  */
8
19
  export class CrossSectionOperations {
9
20
  constructor(wasm) {
@@ -73,6 +84,77 @@ export class CrossSectionOperations {
73
84
  return res;
74
85
  }
75
86
  }
87
+ /**
88
+ * Joins cross-sections placed by frames into a solid, each section to the next by straight
89
+ * sides, closed at both ends: a taper from one outline to another, or one outline through many
90
+ * frames.
91
+ *
92
+ * Corner `i` of a section joins corner `i` of the next, so differing sections need matching loops;
93
+ * frames move the sections apart, mirroring all or none.
94
+ * @param inputs - The cross-sections, one or one per frame, and the frames that place them
95
+ * @returns The lofted solid
96
+ * @group basic
97
+ * @shortname loft
98
+ * @drawable true
99
+ * @example
100
+ * ```typescript
101
+ * const square = await bitbybit.manifold.crossSection.shapes.square({ size: 2, center: true });
102
+ * const solid = await bitbybit.manifold.crossSection.operations.loft({ crossSections: [square], frames: [[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], [0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1, 0, 0, 0, 4, 1]] });
103
+ * ```
104
+ */
105
+ loft(inputs) {
106
+ const { crossSections, frames } = inputs;
107
+ if (!Array.isArray(frames) || frames.length < MIN_LOFT_FRAMES) {
108
+ throw new InputError(`A loft needs at least ${MIN_LOFT_FRAMES} frames`, "frames");
109
+ }
110
+ const wrong = frames.findIndex((frame) => !isPlacing(frame));
111
+ if (wrong >= 0) {
112
+ throw new InputError(`Frame ${wrong} is not sixteen numbers in column-major order with 0, 0, 0, 1 as the bottom row that place a plane without flattening it`, "frames");
113
+ }
114
+ const firstMirrors = linearDeterminant(frames[0]) < 0;
115
+ const turnedOver = frames.findIndex((frame) => linearDeterminant(frame) < 0 !== firstMirrors);
116
+ if (turnedOver >= 0) {
117
+ throw new InputError(`Frame ${turnedOver} turns the profile over where frame 0 does not, or the other way round: a loft's frames all mirror, or none do`, "frames");
118
+ }
119
+ if (!Array.isArray(crossSections) || (crossSections.length !== 1 && crossSections.length !== frames.length)) {
120
+ throw new InputError(`A loft needs one cross-section, or one for each of its ${frames.length} frames`, "crossSections");
121
+ }
122
+ const sections = crossSections.map((crossSection) => crossSection.toPolygons());
123
+ return this.manifold.Manifold.ofMesh(loftMesh(this.manifold, sections, Float64Array.from(frames.flat()), undefined, "The loft"));
124
+ }
125
+ /**
126
+ * Carries a cross-section along a path of points into a solid, square to the path at every
127
+ * point and turning with it without twisting, like a pipe, a rail or a cable.
128
+ *
129
+ * Sharp corners are mitred so the solid keeps its width; `cornerRadius` rounds them instead.
130
+ * `xDirection` sets where the profile's X axis points at the start.
131
+ * @param inputs - The cross-section, the path, the corner radius and its segments, and the profile's starting X direction
132
+ * @returns The swept solid
133
+ * @group basic
134
+ * @shortname sweep
135
+ * @drawable true
136
+ * @example
137
+ * ```typescript
138
+ * const ring = await bitbybit.manifold.crossSection.shapes.circle({ radius: 1, circularSegments: 32 });
139
+ * const pipe = await bitbybit.manifold.crossSection.operations.sweep({ crossSection: ring, path: [[0, 0, 0], [10, 0, 0], [10, 10, 0], [10, 10, 10]], cornerRadius: 3, circularSegments: 32 });
140
+ * ```
141
+ */
142
+ sweep(inputs) {
143
+ var _a;
144
+ const resolved = resolveDto(Inputs.Manifold.SweepDto, inputs);
145
+ const path = Array.isArray(resolved.path) ? distinctPoints(resolved.path) : [];
146
+ if (path.length < MIN_LOFT_FRAMES) {
147
+ throw new InputError(`A sweep needs a path of at least ${MIN_LOFT_FRAMES} distinct points`, "path");
148
+ }
149
+ if (!Number.isSafeInteger(resolved.circularSegments) || resolved.circularSegments < MIN_CIRCLE_SIDES) {
150
+ throw new InputError(`A rounded corner needs at least ${MIN_CIRCLE_SIDES} segments a turn, got ${resolved.circularSegments}`, "circularSegments");
151
+ }
152
+ const step = FULL_TURN / resolved.circularSegments;
153
+ const points = resolved.cornerRadius > 0 ? roundedPath3(path, resolved.cornerRadius, (turn) => Math.ceil(turn / step)) : path;
154
+ const tangents = pathTangents(points);
155
+ const frames = sweepMatrices(points, tangents, transportedAxes(points, tangents, (_a = resolved.xDirection) !== null && _a !== void 0 ? _a : NO_DIRECTION));
156
+ return this.loft({ crossSections: [resolved.crossSection], frames });
157
+ }
76
158
  /**
77
159
  * Moves the outline of a cross-section outward by `delta`, or inward for a negative delta, so
78
160
  * an outer contour grows and a hole shrinks.