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