@bitbybit-dev/manifold 1.2.0-rc.2 → 1.3.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 (35) hide show
  1. package/lib/api/inputs/manifold-inputs.d.ts +521 -224
  2. package/lib/api/inputs/manifold-inputs.js +380 -135
  3. package/lib/api/manifold-service.d.ts +37 -11
  4. package/lib/api/manifold-service.js +37 -11
  5. package/lib/api/services/cross-section/cross-section-booleans.d.ts +66 -29
  6. package/lib/api/services/cross-section/cross-section-booleans.js +66 -29
  7. package/lib/api/services/cross-section/cross-section-evaluate.d.ts +38 -17
  8. package/lib/api/services/cross-section/cross-section-evaluate.js +38 -17
  9. package/lib/api/services/cross-section/cross-section-operations.d.ts +73 -33
  10. package/lib/api/services/cross-section/cross-section-operations.js +73 -33
  11. package/lib/api/services/cross-section/cross-section-shapes.d.ts +38 -17
  12. package/lib/api/services/cross-section/cross-section-shapes.js +38 -17
  13. package/lib/api/services/cross-section/cross-section-transforms.d.ts +64 -29
  14. package/lib/api/services/cross-section/cross-section-transforms.js +64 -29
  15. package/lib/api/services/cross-section/cross-section.d.ts +81 -20
  16. package/lib/api/services/cross-section/cross-section.js +81 -20
  17. package/lib/api/services/manifold/manifold-booleans.d.ts +139 -43
  18. package/lib/api/services/manifold/manifold-booleans.js +143 -43
  19. package/lib/api/services/manifold/manifold-evaluate.d.ts +134 -59
  20. package/lib/api/services/manifold/manifold-evaluate.js +141 -59
  21. package/lib/api/services/manifold/manifold-operations.d.ts +195 -108
  22. package/lib/api/services/manifold/manifold-operations.js +197 -110
  23. package/lib/api/services/manifold/manifold-shapes.d.ts +64 -26
  24. package/lib/api/services/manifold/manifold-shapes.js +66 -28
  25. package/lib/api/services/manifold/manifold-transforms.d.ts +100 -38
  26. package/lib/api/services/manifold/manifold-transforms.js +100 -38
  27. package/lib/api/services/manifold/manifold.d.ts +25 -8
  28. package/lib/api/services/manifold/manifold.js +25 -8
  29. package/lib/api/services/mesh/mesh-evaluate.d.ts +103 -32
  30. package/lib/api/services/mesh/mesh-evaluate.js +108 -33
  31. package/lib/api/services/mesh/mesh-operations.d.ts +12 -15
  32. package/lib/api/services/mesh/mesh-operations.js +12 -15
  33. package/lib/api/services/mesh/mesh.d.ts +4 -2
  34. package/lib/api/services/mesh/mesh.js +4 -2
  35. package/package.json +3 -3
@@ -1,225 +1,312 @@
1
1
  import * as Inputs from "../../inputs";
2
2
  import * as Manifold3D from "manifold-3d";
3
3
  /**
4
- * Contains various functions for Solid meshes from Manifold library https://github.com/elalish/manifold
5
- * Thanks Manifold community for developing this kernel
4
+ * Changing Manifold solids beyond booleans: wrapping them in a convex hull, slicing and projecting
5
+ * them into cross-sections, refining and smoothing their meshes, simplifying them, composing and
6
+ * decomposing them, and computing normals and curvature into vertex property channels. A property
7
+ * channel is one number per vertex stored on the mesh, such as the three channels of a normal.
8
+ * Every method returns a new solid.
6
9
  */
7
10
  export declare class ManifoldOperations {
8
11
  private manifold;
9
12
  constructor(wasm: Manifold3D.ManifoldToplevel);
10
13
  /**
11
- * Computes convex hull of the manifold shape provided
12
- * @param inputs two shapes
13
- * @returns hulled manifold shape
14
+ * Wraps a solid in its convex hull, the smallest shape without dents that contains it, like
15
+ * shrink-wrap pulled tight over it.
16
+ * @param inputs - The solid
17
+ * @returns The convex hull
14
18
  * @group hulls
15
19
  * @shortname convex hull
16
20
  * @drawable true
21
+ * @example
22
+ * ```typescript
23
+ * const wrapped = await bitbybit.manifold.manifold.operations.hull({ manifold: shape });
24
+ * ```
17
25
  */
18
26
  hull(inputs: Inputs.Manifold.ManifoldDto<Manifold3D.Manifold>): Manifold3D.Manifold;
19
27
  /**
20
- * Hull points or manifolds
21
- * @param inputs manifold
22
- * @returns manifold
28
+ * Wraps points, solids or a mix of both in one convex hull, the smallest shape without dents
29
+ * that contains them all.
30
+ * @param inputs - The points and solids to wrap
31
+ * @returns The convex hull
23
32
  * @group hulls
24
33
  * @shortname hull points
25
34
  * @drawable true
35
+ * @example
36
+ * ```typescript
37
+ * const wrapped = await bitbybit.manifold.manifold.operations.hullPoints({ points: [[0, 0, 0], [10, 0, 0], [0, 10, 0], [0, 0, 10]] });
38
+ * ```
26
39
  */
27
40
  hullPoints(inputs: Inputs.Manifold.HullPointsDto<(Inputs.Base.Point3 | Manifold3D.Manifold)[]>): Manifold3D.Manifold;
28
41
  /**
29
- * Returns the cross section of this object parallel to the X-Y plane at the
30
- * specified height. Using a height equal to the bottom
31
- * of the bounding box will return the bottom faces, while using a height
32
- * equal to the top of the bounding box will return empty.
33
- * @param inputs manifold and height
34
- * @returns sliced cross section
42
+ * Cuts a solid with a plane parallel to the XY plane at the given Z height and returns the flat
43
+ * section as a cross-section.
44
+ *
45
+ * A height at the bottom of the solid's bounding box gives its bottom faces; a height at the
46
+ * top gives an empty cross-section.
47
+ * @param inputs - The solid and the Z height of the cut
48
+ * @returns The section as a cross-section
35
49
  * @group cross sections
36
50
  * @shortname slice
37
51
  * @drawable true
52
+ * @example
53
+ * ```typescript
54
+ * const section = await bitbybit.manifold.manifold.operations.slice({ manifold: sphere, height: 2 });
55
+ * ```
38
56
  */
39
57
  slice(inputs: Inputs.Manifold.SliceDto<Manifold3D.Manifold>): Manifold3D.CrossSection;
40
58
  /**
41
- * Creates a projection on xy plane from the shape outline
42
- * @param inputs manifold
43
- * @returns projected cross section
59
+ * Flattens a solid onto the XY plane and returns its outline as a cross-section, like its
60
+ * shadow under a light straight above.
61
+ * @param inputs - The solid
62
+ * @returns The outline as a cross-section
44
63
  * @group cross sections
45
64
  * @shortname project
46
65
  * @drawable true
66
+ * @example
67
+ * ```typescript
68
+ * const shadow = await bitbybit.manifold.manifold.operations.project({ manifold: shape });
69
+ * ```
47
70
  */
48
71
  project(inputs: Inputs.Manifold.ManifoldDto<Manifold3D.Manifold>): Manifold3D.CrossSection;
49
72
  /**
50
- * Return a copy of the manifold with the set tolerance value.
51
- * This performs mesh simplification when the tolerance value is increased.
52
- * @param inputs manifold and tolerance
53
- * @returns manifold with new tolerance
73
+ * Gives a solid a new tolerance, the rounding error it is allowed to carry, and simplifies its
74
+ * mesh when the tolerance grows.
75
+ *
76
+ * Triangles thinner than the tolerance are treated as degenerate and removed.
77
+ * @param inputs - The solid and the tolerance in model units
78
+ * @returns The solid with the new tolerance
54
79
  * @group basic
55
80
  * @shortname set tolerance
56
81
  * @drawable false
82
+ * @example
83
+ * ```typescript
84
+ * const coarser = await bitbybit.manifold.manifold.operations.setTolerance({ manifold: shape, tolerance: 0.01 });
85
+ * ```
57
86
  */
58
87
  setTolerance(inputs: Inputs.Manifold.ManifoldRefineToleranceDto<Manifold3D.Manifold>): Manifold3D.Manifold;
59
88
  /**
60
- * Returns the first of n sequential new unique mesh IDs for marking sets of triangles that can be looked up after further operations. Assign to Mesh.runOriginalID vector.
61
- * @param inputs count
62
- * @returns void
89
+ * Reserves a run of `count` unique mesh ids and returns the first, for marking sets of
90
+ * triangles that can be found again after later operations.
91
+ *
92
+ * Assign them to a mesh's `runOriginalID` before building a solid from it, for instance to keep
93
+ * several materials apart.
94
+ * @param inputs - How many ids to reserve
95
+ * @returns The first of the reserved ids; the rest follow in sequence
63
96
  * @group basic
64
97
  * @shortname reserve id
65
98
  * @drawable false
99
+ * @example
100
+ * ```typescript
101
+ * const firstId = await bitbybit.manifold.manifold.operations.reserveIds({ count: 2 });
102
+ * ```
66
103
  */
67
104
  reserveIds(inputs: Inputs.Manifold.CountDto): number;
68
105
  /**
69
- * If you copy a manifold, but you want this new copy to have new properties
70
- * (e.g. a different UV mapping), you can reset its IDs to a new original,
71
- * meaning it will now be referenced by its descendants instead of the meshes
72
- * it was built from, allowing you to differentiate the copies when applying
73
- * your properties to the final result.
106
+ * Makes a copy of a solid that counts as a new original, so the copy can carry its own vertex
107
+ * properties, such as a different UV mapping, and be told apart from what it was built from.
74
108
  *
75
- * This function also condenses all coplanar faces in the relation, and
76
- * collapses those edges. If you want to have inconsistent properties across
77
- * these faces, meaning you want to preserve some of these edges, you should
78
- * instead call GetMesh(), calculate your properties and use these to
79
- * construct a new manifold.
80
- * @param inputs manifold
81
- * @returns original manifold
109
+ * Coplanar faces are merged and the edges between them collapsed on the way; keep the mesh
110
+ * route instead when those edges must stay.
111
+ * @param inputs - The solid
112
+ * @returns The copy marked as an original
82
113
  * @group basic
83
114
  * @shortname as original
84
115
  * @drawable true
116
+ * @example
117
+ * ```typescript
118
+ * const original = await bitbybit.manifold.manifold.operations.asOriginal({ manifold: shape });
119
+ * ```
85
120
  */
86
121
  asOriginal(inputs: Inputs.Manifold.ManifoldDto<Manifold3D.Manifold>): Manifold3D.Manifold;
87
122
  /**
88
- * Constructs a new manifold from a list of other manifolds. This is a purely
89
- * topological operation, so care should be taken to avoid creating
90
- * overlapping results. It is the inverse operation of Decompose().
91
- * @param inputs manifold shapes
92
- * @returns composed manifold
123
+ * Packs several solids into one, the inverse of `decompose`.
124
+ *
125
+ * Solids that overlap are fused, as a boolean union would; solids kept apart stay separate
126
+ * pieces of the one result.
127
+ * @param inputs - The solids to pack together
128
+ * @returns One solid holding all of them
93
129
  * @group composition
94
130
  * @shortname compose
95
131
  * @drawable true
132
+ * @example
133
+ * ```typescript
134
+ * const packed = await bitbybit.manifold.manifold.operations.compose({ manifolds: [cube, sphere] });
135
+ * ```
96
136
  */
97
137
  compose(inputs: Inputs.Manifold.ManifoldsDto<Manifold3D.Manifold>): Manifold3D.Manifold;
98
138
  /**
99
- * This operation returns a vector of Manifolds that are topologically
100
- * disconnected. If everything is connected, the vector is length one,
101
- * containing a copy of the original. It is the inverse operation of
102
- * Compose().
103
- * @param inputs manifold
104
- * @returns decomposed manifold shapes
139
+ * Splits a solid into its separate, unconnected pieces, the inverse of `compose`.
140
+ *
141
+ * A solid that is all one piece comes back as a list of one copy.
142
+ * @param inputs - The solid
143
+ * @returns The separate pieces
105
144
  * @group composition
106
145
  * @shortname decompose
107
146
  * @drawable true
147
+ * @example
148
+ * ```typescript
149
+ * const pieces = await bitbybit.manifold.manifold.operations.decompose({ manifold: packed });
150
+ * ```
108
151
  */
109
152
  decompose(inputs: Inputs.Manifold.ManifoldDto<Manifold3D.Manifold>): Manifold3D.Manifold[];
110
153
  /**
111
- * Fills in vertex properties for normal vectors, calculated from the mesh
112
- * geometry. Flat faces composed of three or more triangles will remain flat.
113
- * @param inputs manifold and normal index with minimum sharp angle
114
- * @returns manifold with calculated normals
154
+ * Computes a normal for every vertex from the mesh and stores it in three property channels
155
+ * starting at `normalIdx`.
156
+ *
157
+ * Edges sharper than `minSharpAngle`, in degrees, keep separate normals on each side and stay
158
+ * crisp; at 0 every triangle keeps its own normal. Flat faces of several triangles stay flat.
159
+ * @param inputs - The solid, the first normal channel and the sharp angle in degrees
160
+ * @returns The solid with normals stored
115
161
  * @group adjustments
116
162
  * @shortname calculate normals
117
163
  * @drawable true
164
+ * @example
165
+ * ```typescript
166
+ * const withNormals = await bitbybit.manifold.manifold.operations.calculateNormals({ manifold: shape, normalIdx: 0, minSharpAngle: 60 });
167
+ * ```
118
168
  */
119
169
  calculateNormals(inputs: Inputs.Manifold.CalculateNormalsDto<Manifold3D.Manifold>): Manifold3D.Manifold;
120
170
  /**
121
- * Curvature is the inverse of the radius of curvature, and signed such that
122
- * positive is convex and negative is concave. There are two orthogonal
123
- * principal curvatures at any point on a manifold, with one maximum and the
124
- * other minimum. Gaussian curvature is their product, while mean
125
- * curvature is their sum. This approximates them for every vertex and assigns
126
- * them as vertex properties on the given channels.
127
- * @param inputs manifold and gaussian and mean index
128
- * @returns manifold with calculated curvature
171
+ * Computes how strongly the surface bends at every vertex and stores it in property channels:
172
+ * Gaussian curvature at `gaussianIdx`, mean curvature at `meanIdx`.
173
+ *
174
+ * Curvature is the inverse of the bending radius, positive where the surface is convex and
175
+ * negative where it is concave; an index below 0 skips that channel.
176
+ * @param inputs - The solid and the two channels to store into
177
+ * @returns The solid with curvature stored
129
178
  * @group adjustments
130
179
  * @shortname calculate curvature
131
180
  * @drawable true
181
+ * @example
182
+ * ```typescript
183
+ * const withCurvature = await bitbybit.manifold.manifold.operations.calculateCurvature({ manifold: shape, gaussianIdx: 0, meanIdx: 1 });
184
+ * ```
132
185
  */
133
186
  calculateCurvature(inputs: Inputs.Manifold.CalculateCurvatureDto<Manifold3D.Manifold>): Manifold3D.Manifold;
134
187
  /**
135
- * Increase the density of the mesh by splitting each edge into pieces such
136
- * that any point on the resulting triangles is roughly within tolerance of
137
- * the smoothly curved surface defined by the tangent vectors. This means
138
- * tightly curving regions will be divided more finely than smoother regions.
139
- * If halfedgeTangents are not present, the result will simply be a copy of
140
- * the original. Quads will ignore their interior triangle bisector.
141
- * @param inputs manifold and tolerance
142
- * @returns refined manifold
188
+ * Adds triangles to a smoothed solid until every point of its mesh lies within `tolerance` of
189
+ * the smooth surface, so tightly curved regions get more triangles than flat ones.
190
+ *
191
+ * Only a solid that was smoothed with `smoothOut` or `smoothByNormals` changes; any other comes
192
+ * back as a copy.
193
+ * @param inputs - The solid and the tolerance in model units
194
+ * @returns The refined solid
143
195
  * @group adjustments
144
196
  * @shortname refine to tolerance
145
197
  * @drawable true
198
+ * @example
199
+ * ```typescript
200
+ * const finer = await bitbybit.manifold.manifold.operations.refineToTolerance({ manifold: smoothed, tolerance: 0.01 });
201
+ * ```
146
202
  */
147
203
  refineToTolerance(inputs: Inputs.Manifold.ManifoldRefineToleranceDto<Manifold3D.Manifold>): Manifold3D.Manifold;
148
204
  /**
149
- * Increase the density of the mesh by splitting each edge into pieces of
150
- * roughly the input length. Interior verts are added to keep the rest of the
151
- * triangulation edges also of roughly the same length. If halfedgeTangents
152
- * are present (e.g. from the Smooth() constructor), the new vertices will be
153
- * moved to the interpolated surface according to their barycentric
154
- * coordinates.
155
- * @param inputs manifold and length
156
- * @returns refined manifold
205
+ * Adds triangles to a solid by splitting every edge into pieces of roughly the given length,
206
+ * adding inner vertices to keep the triangles even.
207
+ *
208
+ * On a solid smoothed with `smoothOut` or `smoothByNormals` the new vertices move onto the
209
+ * smooth surface; otherwise the surface stays as it is.
210
+ * @param inputs - The solid and the target edge length in model units
211
+ * @returns The refined solid
157
212
  * @group adjustments
158
213
  * @shortname refine to length
159
214
  * @drawable true
215
+ * @example
216
+ * ```typescript
217
+ * const finer = await bitbybit.manifold.manifold.operations.refineToLength({ manifold: smoothed, length: 0.5 });
218
+ * ```
160
219
  */
161
220
  refineToLength(inputs: Inputs.Manifold.ManifoldRefineLengthDto<Manifold3D.Manifold>): Manifold3D.Manifold;
162
221
  /**
163
- * Increase the density of the mesh by splitting every edge into n pieces. For
164
- * instance, with n = 2, each triangle will be split into 4 triangles. These
165
- * will all be coplanar (and will not be immediately collapsed) unless the
166
- * Mesh/Manifold has halfedgeTangents specified (e.g. from the Smooth()
167
- * constructor), in which case the new vertices will be moved to the
168
- * interpolated surface according to their barycentric coordinates.
169
- * @param inputs manifold and count
170
- * @returns refined manifold
222
+ * Adds triangles to a solid by splitting every edge into `number` pieces; with 2, each triangle
223
+ * becomes four.
224
+ *
225
+ * On a solid smoothed with `smoothOut` or `smoothByNormals` the new vertices move onto the
226
+ * smooth surface; otherwise the new triangles stay flat.
227
+ * @param inputs - The solid and how many pieces to split each edge into
228
+ * @returns The refined solid
171
229
  * @group adjustments
172
230
  * @shortname refine
173
231
  * @drawable true
232
+ * @example
233
+ * ```typescript
234
+ * const finer = await bitbybit.manifold.manifold.operations.refine({ manifold: smoothed, number: 2 });
235
+ * ```
174
236
  */
175
237
  refine(inputs: Inputs.Manifold.ManifoldRefineDto<Manifold3D.Manifold>): Manifold3D.Manifold;
176
238
  /**
177
- * Smooths out the Manifold by filling in the halfedgeTangent vectors. The
178
- * geometry will remain unchanged until Refine or RefineToLength is called to
179
- * interpolate the surface. This version uses the geometry of the triangles
180
- * and pseudo-normals to define the tangent vectors.
181
- * @param inputs manifold and minimum sharp angle and minimum smoothness
182
- * @returns smoothed manifold
239
+ * Marks a solid for smoothing by working out tangents from its triangles, so a later `refine`
240
+ * or `refineToLength` bends the new triangles into a smooth surface.
241
+ *
242
+ * Edges sharper than `minSharpAngle`, in degrees, stay sharp; `minSmoothness` above 0 rounds
243
+ * those a little, and 1 smooths everything. The geometry itself does not change until it is
244
+ * refined.
245
+ * @param inputs - The solid, the sharp angle in degrees and the smoothness of sharp edges
246
+ * @returns The solid with smoothing tangents
183
247
  * @group adjustments
184
248
  * @shortname smooth out
185
249
  * @drawable true
250
+ * @example
251
+ * ```typescript
252
+ * const smoothed = await bitbybit.manifold.manifold.operations.smoothOut({ manifold: cube, minSharpAngle: 60, minSmoothness: 0 });
253
+ * const rounded = await bitbybit.manifold.manifold.operations.refineToLength({ manifold: smoothed, length: 0.5 });
254
+ * ```
186
255
  */
187
256
  smoothOut(inputs: Inputs.Manifold.ManifoldSmoothOutDto<Manifold3D.Manifold>): Manifold3D.Manifold;
188
257
  /**
189
- * Smooths out the Manifold by filling in the halfedgeTangent vectors. The
190
- * geometry will remain unchanged until Refine or RefineToLength is called to
191
- * interpolate the surface. This version uses the supplied vertex normal
192
- * properties to define the tangent vectors.
193
- * @param inputs manifold and normal index
194
- * @returns smoothed manifold
258
+ * Marks a solid for smoothing using the normals stored in its vertex properties, so a later
259
+ * `refine` or `refineToLength` bends the new triangles into a smooth surface.
260
+ *
261
+ * `normalIdx` is the first of the three normal channels, as `calculateNormals` stores them;
262
+ * where the normals on a vertex disagree the edge stays sharp.
263
+ * @param inputs - The solid and the first normal channel
264
+ * @returns The solid with smoothing tangents
195
265
  * @group adjustments
196
266
  * @shortname smooth by normals
197
267
  * @drawable true
268
+ * @example
269
+ * ```typescript
270
+ * const smoothed = await bitbybit.manifold.manifold.operations.smoothByNormals({ manifold: withNormals, normalIdx: 0 });
271
+ * ```
198
272
  */
199
273
  smoothByNormals(inputs: Inputs.Manifold.ManifoldSmoothByNormalsDto<Manifold3D.Manifold>): Manifold3D.Manifold;
200
274
  /**
201
- * Return a copy of the manifold simplified to the given tolerance, but with
202
- * its actual tolerance value unchanged. The result will contain a subset of
203
- * the original verts and all surfaces will have moved by less than tolerance.
204
- * @param inputs manifold and tolerance
205
- * @returns simplified manifold
275
+ * Removes vertices from a solid's mesh while keeping every surface within `tolerance` of where
276
+ * it was, to cut the triangle count.
277
+ *
278
+ * The result keeps a subset of the original vertices; the solid's own tolerance value stays
279
+ * unchanged.
280
+ * @param inputs - The solid and how far surfaces may move, in model units
281
+ * @returns The simplified solid
206
282
  * @group adjustments
207
283
  * @shortname simplify
208
284
  * @drawable true
285
+ * @example
286
+ * ```typescript
287
+ * const lighter = await bitbybit.manifold.manifold.operations.simplify({ manifold: shape, tolerance: 0.05 });
288
+ * ```
209
289
  */
210
290
  simplify(inputs: Inputs.Manifold.ManifoldSimplifyDto<Manifold3D.Manifold>): Manifold3D.Manifold;
211
291
  /**
212
- * Create a new copy of this manifold with updated vertex properties by
213
- * supplying a function that takes the existing position and properties as
214
- * input. You may specify any number of output properties, allowing creation
215
- * and removal of channels. Note: undefined behavior will result if you read
216
- * past the number of input properties or write past the number of output
217
- * properties.
218
- * @param inputs manifold, numProp and property function
219
- * @returns manifold with updated properties
292
+ * Rewrites the vertex properties of a solid with a function that receives each vertex's
293
+ * position and old properties and fills in the new ones.
294
+ *
295
+ * `numProp` sets how many properties each vertex has afterwards, so channels can be added or
296
+ * dropped; reading past the old count or writing past the new one is undefined.
297
+ * @param inputs - The solid, the new property count and the function that fills the properties
298
+ * @returns The solid with the new properties
220
299
  * @group adjustments
221
300
  * @shortname set properties
222
301
  * @drawable true
302
+ * @example
303
+ * ```typescript
304
+ * const colored = await bitbybit.manifold.manifold.operations.setProperties({
305
+ * manifold: shape,
306
+ * numProp: 3,
307
+ * propFunc: (newProp, position) => { newProp[0] = position[0]; newProp[1] = position[1]; newProp[2] = position[2]; },
308
+ * });
309
+ * ```
223
310
  */
224
311
  setProperties(inputs: Inputs.Manifold.ManifoldSetPropertiesDto<Manifold3D.Manifold>): Manifold3D.Manifold;
225
312
  }