@bitbybit-dev/manifold 1.2.0 → 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
@@ -10,47 +10,57 @@ import * as Inputs from "../../inputs/manifold-inputs";
10
10
  * The value is absolute, not relative: it is chosen to be far above the noise of double arithmetic on
11
11
  * ordinary CAD magnitudes and far below any distance a model means to express. Two vertices that
12
12
  * genuinely sit closer together than this are merged, and two that straddle a grid boundary are not -
13
- * that is inherent to snapping, and the alternative, a neighbourhood search, costs more than it is
13
+ * that is inherent to snapping, and the alternative, a neighborhood search, costs more than it is
14
14
  * worth here.
15
15
  */
16
16
  const VERTEX_MERGE_TOLERANCE = 1e-7;
17
- /** Snaps a coordinate onto the merge grid, normalising a negative zero so it keys the same as zero. */
17
+ /** Snaps a coordinate onto the merge grid, normalizing a negative zero so it keys the same as zero. */
18
18
  const quantize = (coordinate) => Math.round(coordinate / VERTEX_MERGE_TOLERANCE) || 0;
19
19
  /**
20
- * Contains various functions for Solid meshes from Manifold library https://github.com/elalish/manifold
21
- * Thanks Manifold community for developing this kernel
20
+ * Building Manifold solids: the cube, sphere, cylinder and tetrahedron primitives, and solids from
21
+ * triangle meshes or lists of triangles. The kernel keeps Z as its up axis, so a cylinder stands
22
+ * along Z and a cube's `size` runs along X, Y and Z; every solid comes back as a closed triangle
23
+ * mesh.
22
24
  */
23
25
  export class ManifoldShapes {
24
26
  constructor(wasm) {
25
27
  this.manifold = wasm;
26
28
  }
27
29
  /**
28
- * Convert a Mesh into a Manifold, retaining its properties and merging only
29
- * the positions according to the merge vectors. Will throw an error if the
30
- * result is not an oriented 2-manifold. Will collapse degenerate triangles
31
- * and unnecessary vertices.
30
+ * Builds a solid from plain mesh data, the form `manifoldToMesh` hands out, so a mesh can make
31
+ * a round trip through other tools.
32
32
  *
33
- * All fields are read, making this structure suitable for a lossless
34
- * round-trip of data from manifoldToMesh(). For multi-material input, use
35
- * reserveIDs() to set a unique originalID for each material, and sort the
36
- * materials into triangle runs.
37
- * @param inputs mesh definition
38
- * @returns manifold
33
+ * The mesh must be closed and consistently oriented, or an error is thrown; degenerate
34
+ * triangles and unneeded vertices are removed on the way in.
35
+ * @param inputs - The mesh data
36
+ * @returns The solid
39
37
  * @group create
40
38
  * @shortname manifold from mesh
41
39
  * @drawable true
40
+ * @example
41
+ * ```typescript
42
+ * const solid = await bitbybit.manifold.manifold.shapes.manifoldFromMesh({ mesh });
43
+ * ```
42
44
  */
43
45
  manifoldFromMesh(inputs) {
44
46
  const { Manifold } = this.manifold;
45
47
  return new Manifold(inputs.mesh);
46
48
  }
47
49
  /**
48
- * Create a Manifold from a set of polygon points describing triangles.
49
- * @param inputs Polygon points
50
- * @returns Manifold
50
+ * Builds a solid from a list of triangles, each given as three points, merging points that
51
+ * coincide.
52
+ *
53
+ * The triangles must form a closed, consistently oriented surface; entries that are not three
54
+ * points are skipped, and points with missing coordinates throw an error.
55
+ * @param inputs - The triangles as lists of three points
56
+ * @returns The solid
51
57
  * @group create
52
58
  * @shortname from polygon points
53
59
  * @drawable true
60
+ * @example
61
+ * ```typescript
62
+ * const solid = await bitbybit.manifold.manifold.shapes.fromPolygonPoints({ polygonPoints: triangles });
63
+ * ```
54
64
  */
55
65
  fromPolygonPoints(inputs) {
56
66
  const { Manifold } = this.manifold;
@@ -93,12 +103,19 @@ export class ManifoldShapes {
93
103
  return new Manifold(meshDto);
94
104
  }
95
105
  /**
96
- * Create a 3D cube shape
97
- * @param inputs Cube parameters
98
- * @returns Cube solid
106
+ * Creates a cube solid with the given side length.
107
+ *
108
+ * With `center` true the cube is centered on the origin; otherwise its corner sits on the origin
109
+ * and it extends along the positive axes.
110
+ * @param inputs - The side length and whether to center it
111
+ * @returns The box solid
99
112
  * @group primitives
100
113
  * @shortname cube
101
114
  * @drawable true
115
+ * @example
116
+ * ```typescript
117
+ * const box = await bitbybit.manifold.manifold.shapes.cube({ size: 10, center: true });
118
+ * ```
102
119
  */
103
120
  cube(inputs) {
104
121
  const { Manifold } = this.manifold;
@@ -106,12 +123,19 @@ export class ManifoldShapes {
106
123
  return cube(inputs.size, inputs.center);
107
124
  }
108
125
  /**
109
- * Create a 3D sphere shape
110
- * @param inputs Sphere parameters
111
- * @returns Sphere solid
126
+ * Creates a sphere solid of the given radius, centered on the origin.
127
+ *
128
+ * `circularSegments` is the number of segments around the sphere; it is rounded up to a
129
+ * multiple of four, since the sphere is built by refining an octahedron.
130
+ * @param inputs - The radius and the number of segments around the sphere
131
+ * @returns The sphere solid
112
132
  * @group primitives
113
133
  * @shortname sphere
114
134
  * @drawable true
135
+ * @example
136
+ * ```typescript
137
+ * const ball = await bitbybit.manifold.manifold.shapes.sphere({ radius: 5, circularSegments: 32 });
138
+ * ```
115
139
  */
116
140
  sphere(inputs) {
117
141
  const { Manifold } = this.manifold;
@@ -119,11 +143,16 @@ export class ManifoldShapes {
119
143
  return sphere(inputs.radius, inputs.circularSegments);
120
144
  }
121
145
  /**
122
- * Create a 3D tetrahedron shape
123
- * @returns Tetrahedron solid
146
+ * Creates a tetrahedron solid centered on the origin, with one corner at `[1, 1, 1]` and the
147
+ * others placed symmetrically.
148
+ * @returns The tetrahedron solid
124
149
  * @group primitives
125
150
  * @shortname tetrahedron
126
151
  * @drawable true
152
+ * @example
153
+ * ```typescript
154
+ * const tetra = await bitbybit.manifold.manifold.shapes.tetrahedron();
155
+ * ```
127
156
  */
128
157
  tetrahedron() {
129
158
  const { Manifold } = this.manifold;
@@ -131,12 +160,21 @@ export class ManifoldShapes {
131
160
  return tetrahedron();
132
161
  }
133
162
  /**
134
- * Create a 3D cylinder shape
135
- * @param inputs Cylinder parameters
136
- * @returns Cylinder solid
163
+ * Creates a cylinder solid standing along Z, or a cone when the top radius differs from the
164
+ * bottom one.
165
+ *
166
+ * `radiusLow` is the bottom radius and must be above 0, `radiusHigh` the top radius, which may
167
+ * be 0 for a point; `circularSegments` sets how round the sides are. `center` centers the
168
+ * cylinder on the origin instead of standing it on it.
169
+ * @param inputs - The height, the bottom and top radii, the number of segments and whether to center it
170
+ * @returns The cylinder or cone solid
137
171
  * @group primitives
138
172
  * @shortname cylinder
139
173
  * @drawable true
174
+ * @example
175
+ * ```typescript
176
+ * const cone = await bitbybit.manifold.manifold.shapes.cylinder({ height: 10, radiusLow: 4, radiusHigh: 1, circularSegments: 32, center: false });
177
+ * ```
140
178
  */
141
179
  cylinder(inputs) {
142
180
  const { Manifold } = this.manifold;
@@ -1,111 +1,173 @@
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
+ * Moving, turning, scaling, mirroring and warping Manifold solids. The kernel combines transforms
5
+ * lazily, so chaining them is cheap; angles are in degrees, and rotations turn about the origin, X
6
+ * first, then Y, then Z. Every method returns a new solid.
6
7
  */
7
8
  export declare class ManifoldTransforms {
8
9
  constructor(_wasm: Manifold3D.ManifoldToplevel);
9
10
  /**
10
- * Scales a manifold shape with 3D vector
11
- * @param inputs manifold and scale vector
12
- * @returns Scaled manifold shape
11
+ * Scales a solid by a separate factor along X, Y and Z, about the origin.
12
+ * @param inputs - The solid and the three factors
13
+ * @returns The scaled solid
13
14
  * @group transforms
14
15
  * @shortname scale 3d
15
16
  * @drawable true
17
+ * @example
18
+ * ```typescript
19
+ * const stretched = await bitbybit.manifold.manifold.transforms.scale3D({ manifold: cube, vector: [1, 2, 1] });
20
+ * ```
16
21
  */
17
22
  scale3D(inputs: Inputs.Manifold.Scale3DDto<Manifold3D.Manifold>): Manifold3D.Manifold;
18
23
  /**
19
- * Scales a manifold shape with single factor
20
- * @param inputs manifold and scale factor
21
- * @returns Scaled manifold shape
24
+ * Scales a solid by a factor per axis, about the origin; it takes the same inputs as `scale3D`,
25
+ * so use equal factors for a uniform scale.
26
+ * @param inputs - The solid and the three factors
27
+ * @returns The scaled solid
22
28
  * @group transforms
23
29
  * @shortname scale uniform
24
30
  * @drawable true
31
+ * @example
32
+ * ```typescript
33
+ * const bigger = await bitbybit.manifold.manifold.transforms.scale({ manifold: cube, vector: [2, 2, 2] });
34
+ * ```
25
35
  */
26
36
  scale(inputs: Inputs.Manifold.Scale3DDto<Manifold3D.Manifold>): Manifold3D.Manifold;
27
37
  /**
28
- * Mirrors a manifold shape over a plane defined by a normal vector
29
- * @param inputs manifold and normal vector
30
- * @returns Mirrored manifold shape
38
+ * Mirrors a solid across the plane through the origin with the given normal.
39
+ *
40
+ * A zero-length normal gives an empty solid.
41
+ * @param inputs - The solid and the normal of the mirror plane
42
+ * @returns The mirrored solid
31
43
  * @group transforms
32
44
  * @shortname mirror
33
45
  * @drawable true
46
+ * @example
47
+ * ```typescript
48
+ * const other = await bitbybit.manifold.manifold.transforms.mirror({ manifold: shape, normal: [1, 0, 0] });
49
+ * ```
34
50
  */
35
51
  mirror(inputs: Inputs.Manifold.MirrorDto<Manifold3D.Manifold>): Manifold3D.Manifold;
36
52
  /**
37
- * Translates a manifold shape along the vector
38
- * @param inputs manifold and trnaslation vector
39
- * @returns Translated manifold shape
53
+ * Moves a solid by a vector, in model units.
54
+ * @param inputs - The solid and the vector to move it by
55
+ * @returns The moved solid
40
56
  * @group transforms
41
57
  * @shortname translate
42
58
  * @drawable true
59
+ * @example
60
+ * ```typescript
61
+ * const moved = await bitbybit.manifold.manifold.transforms.translate({ manifold: cube, vector: [10, 0, 0] });
62
+ * ```
43
63
  */
44
64
  translate(inputs: Inputs.Manifold.TranslateDto<Manifold3D.Manifold>): Manifold3D.Manifold;
45
65
  /**
46
- * Translates a manifold shape along by multiple vectors
47
- * @param inputs manifold and trnaslation vectors
48
- * @returns Translated manifold shapes
66
+ * Makes one moved copy of a solid per vector, for laying out repeats.
67
+ * @param inputs - The solid and the vectors to move copies by
68
+ * @returns One moved copy per vector, in the same order
49
69
  * @group multiple
50
70
  * @shortname translate by vectors
51
71
  * @drawable true
72
+ * @example
73
+ * ```typescript
74
+ * const row = await bitbybit.manifold.manifold.transforms.translateByVectors({ manifold: cube, vectors: [[0, 0, 0], [10, 0, 0], [20, 0, 0]] });
75
+ * ```
52
76
  */
53
77
  translateByVectors(inputs: Inputs.Manifold.TranslateByVectorsDto<Manifold3D.Manifold>): Manifold3D.Manifold[];
54
78
  /**
55
- * Translates a manifold shape along x, y, z
56
- * @param inputs manifold and trnaslation coordinates
57
- * @returns Translated manifold shape
79
+ * Moves a solid by separate distances along X, Y and Z, in model units.
80
+ * @param inputs - The solid and the three distances
81
+ * @returns The moved solid
58
82
  * @group transforms
59
83
  * @shortname translate xyz
60
84
  * @drawable true
85
+ * @example
86
+ * ```typescript
87
+ * const moved = await bitbybit.manifold.manifold.transforms.translateXYZ({ manifold: cube, x: 10, y: 0, z: 5 });
88
+ * ```
61
89
  */
62
90
  translateXYZ(inputs: Inputs.Manifold.TranslateXYZDto<Manifold3D.Manifold>): Manifold3D.Manifold;
63
91
  /**
64
- * Rotates a manifold shape along the vector containing euler angles
65
- * @param inputs manifold and rotation vector
66
- * @returns Rotated manifold shape
92
+ * Rotates a solid about the origin by Euler angles in degrees: first about X, then Y, then Z.
93
+ *
94
+ * Multiples of 90 degrees are exact, with no rounding error.
95
+ * @param inputs - The solid and the three angles in degrees
96
+ * @returns The rotated solid
67
97
  * @group transforms
68
98
  * @shortname rotate
69
99
  * @drawable true
100
+ * @example
101
+ * ```typescript
102
+ * const turned = await bitbybit.manifold.manifold.transforms.rotate({ manifold: cube, vector: [0, 0, 45] });
103
+ * ```
70
104
  */
71
105
  rotate(inputs: Inputs.Manifold.RotateDto<Manifold3D.Manifold>): Manifold3D.Manifold;
72
106
  /**
73
- * Rotates a manifold shape along the x y z euler angles
74
- * @param inputs manifold and rotation eulers
75
- * @returns Rotated manifold shape
107
+ * Rotates a solid about the origin by separate angles in degrees about X, then Y, then Z.
108
+ *
109
+ * Multiples of 90 degrees are exact, with no rounding error.
110
+ * @param inputs - The solid and the three angles in degrees
111
+ * @returns The rotated solid
76
112
  * @group transforms
77
113
  * @shortname rotate xyz
78
114
  * @drawable true
115
+ * @example
116
+ * ```typescript
117
+ * const turned = await bitbybit.manifold.manifold.transforms.rotateXYZ({ manifold: cube, x: 0, y: 0, z: 45 });
118
+ * ```
79
119
  */
80
120
  rotateXYZ(inputs: Inputs.Manifold.RotateXYZDto<Manifold3D.Manifold>): Manifold3D.Manifold;
81
121
  /**
82
- * Transforms a manifold shape by using the 4x4 transformation matrix
83
- * @param inputs manifold and transformation matrix
84
- * @returns Transformed manifold shape
122
+ * Applies a 4x4 matrix to a solid.
123
+ *
124
+ * The matrix is column-major, 16 numbers with the translation at indexes 12 to 14; the kernel
125
+ * reads it as a 3x4 affine transform and ignores the last row.
126
+ * @param inputs - The solid and the matrix
127
+ * @returns The transformed solid
85
128
  * @group matrix
86
129
  * @shortname transform
87
130
  * @drawable true
131
+ * @example
132
+ * ```typescript
133
+ * const moved = await bitbybit.manifold.manifold.transforms.transform({ manifold: cube, transform: matrix });
134
+ * ```
88
135
  */
89
136
  transform(inputs: Inputs.Manifold.TransformDto<Manifold3D.Manifold>): Manifold3D.Manifold;
90
137
  /**
91
- * Transforms a manifold shape by using the 4x4 transformation matrixes
92
- * @param inputs manifold and transformation matrixes
93
- * @returns Transformed manifold shape
138
+ * Applies a list of 4x4 matrices to a solid one after another, first to last, and returns the
139
+ * final result.
140
+ *
141
+ * An empty list throws an error.
142
+ * @param inputs - The solid and the matrices
143
+ * @returns The solid after all the matrices
94
144
  * @group matrix
95
145
  * @shortname transforms
96
146
  * @drawable true
147
+ * @example
148
+ * ```typescript
149
+ * const placed = await bitbybit.manifold.manifold.transforms.transforms({ manifold: cube, transforms: [turn, move] });
150
+ * ```
97
151
  */
98
152
  transforms(inputs: Inputs.Manifold.TransformsDto<Manifold3D.Manifold>): Manifold3D.Manifold;
99
153
  /**
100
- * Move the vertices of this Manifold (creating a new one) according to any
101
- * arbitrary input function. It is easy to create a function that warps a
102
- * geometrically valid object into one which overlaps, but that is not checked
103
- * here, so it is up to the user to choose their function with discretion.
104
- * @param inputs manifold and warp function
105
- * @returns Warped manifold shape
154
+ * Moves every vertex of a solid with a function of your own that changes the vertex position in
155
+ * place, for bends, tapers and other free deformations.
156
+ *
157
+ * The mesh connectivity stays the same and nothing checks that the result still makes sense, so
158
+ * a function that folds the surface through itself gives a broken solid.
159
+ * @param inputs - The solid and the function that moves each vertex
160
+ * @returns The warped solid
106
161
  * @group transforms
107
162
  * @shortname warp
108
163
  * @drawable true
164
+ * @example
165
+ * ```typescript
166
+ * const bent = await bitbybit.manifold.manifold.transforms.warp({
167
+ * manifold: cube,
168
+ * warpFunc: (vert) => { vert[0] += vert[2] * 0.2; },
169
+ * });
170
+ * ```
109
171
  */
110
172
  warp(inputs: Inputs.Manifold.ManifoldWarpDto<Manifold3D.Manifold>): Manifold3D.Manifold;
111
173
  }
@@ -1,61 +1,85 @@
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
+ * Moving, turning, scaling, mirroring and warping Manifold solids. The kernel combines transforms
3
+ * lazily, so chaining them is cheap; angles are in degrees, and rotations turn about the origin, X
4
+ * first, then Y, then Z. Every method returns a new solid.
4
5
  */
5
6
  export class ManifoldTransforms {
6
7
  constructor(_wasm) {
7
8
  }
8
9
  /**
9
- * Scales a manifold shape with 3D vector
10
- * @param inputs manifold and scale vector
11
- * @returns Scaled manifold shape
10
+ * Scales a solid by a separate factor along X, Y and Z, about the origin.
11
+ * @param inputs - The solid and the three factors
12
+ * @returns The scaled solid
12
13
  * @group transforms
13
14
  * @shortname scale 3d
14
15
  * @drawable true
16
+ * @example
17
+ * ```typescript
18
+ * const stretched = await bitbybit.manifold.manifold.transforms.scale3D({ manifold: cube, vector: [1, 2, 1] });
19
+ * ```
15
20
  */
16
21
  scale3D(inputs) {
17
22
  return inputs.manifold.scale(inputs.vector);
18
23
  }
19
24
  /**
20
- * Scales a manifold shape with single factor
21
- * @param inputs manifold and scale factor
22
- * @returns Scaled manifold shape
25
+ * Scales a solid by a factor per axis, about the origin; it takes the same inputs as `scale3D`,
26
+ * so use equal factors for a uniform scale.
27
+ * @param inputs - The solid and the three factors
28
+ * @returns The scaled solid
23
29
  * @group transforms
24
30
  * @shortname scale uniform
25
31
  * @drawable true
32
+ * @example
33
+ * ```typescript
34
+ * const bigger = await bitbybit.manifold.manifold.transforms.scale({ manifold: cube, vector: [2, 2, 2] });
35
+ * ```
26
36
  */
27
37
  scale(inputs) {
28
38
  return inputs.manifold.scale(inputs.vector);
29
39
  }
30
40
  /**
31
- * Mirrors a manifold shape over a plane defined by a normal vector
32
- * @param inputs manifold and normal vector
33
- * @returns Mirrored manifold shape
41
+ * Mirrors a solid across the plane through the origin with the given normal.
42
+ *
43
+ * A zero-length normal gives an empty solid.
44
+ * @param inputs - The solid and the normal of the mirror plane
45
+ * @returns The mirrored solid
34
46
  * @group transforms
35
47
  * @shortname mirror
36
48
  * @drawable true
49
+ * @example
50
+ * ```typescript
51
+ * const other = await bitbybit.manifold.manifold.transforms.mirror({ manifold: shape, normal: [1, 0, 0] });
52
+ * ```
37
53
  */
38
54
  mirror(inputs) {
39
55
  return inputs.manifold.mirror(inputs.normal);
40
56
  }
41
57
  /**
42
- * Translates a manifold shape along the vector
43
- * @param inputs manifold and trnaslation vector
44
- * @returns Translated manifold shape
58
+ * Moves a solid by a vector, in model units.
59
+ * @param inputs - The solid and the vector to move it by
60
+ * @returns The moved solid
45
61
  * @group transforms
46
62
  * @shortname translate
47
63
  * @drawable true
64
+ * @example
65
+ * ```typescript
66
+ * const moved = await bitbybit.manifold.manifold.transforms.translate({ manifold: cube, vector: [10, 0, 0] });
67
+ * ```
48
68
  */
49
69
  translate(inputs) {
50
70
  return inputs.manifold.translate(inputs.vector);
51
71
  }
52
72
  /**
53
- * Translates a manifold shape along by multiple vectors
54
- * @param inputs manifold and trnaslation vectors
55
- * @returns Translated manifold shapes
73
+ * Makes one moved copy of a solid per vector, for laying out repeats.
74
+ * @param inputs - The solid and the vectors to move copies by
75
+ * @returns One moved copy per vector, in the same order
56
76
  * @group multiple
57
77
  * @shortname translate by vectors
58
78
  * @drawable true
79
+ * @example
80
+ * ```typescript
81
+ * const row = await bitbybit.manifold.manifold.transforms.translateByVectors({ manifold: cube, vectors: [[0, 0, 0], [10, 0, 0], [20, 0, 0]] });
82
+ * ```
59
83
  */
60
84
  translateByVectors(inputs) {
61
85
  return inputs.vectors.map(vector => {
@@ -63,56 +87,86 @@ export class ManifoldTransforms {
63
87
  });
64
88
  }
65
89
  /**
66
- * Translates a manifold shape along x, y, z
67
- * @param inputs manifold and trnaslation coordinates
68
- * @returns Translated manifold shape
90
+ * Moves a solid by separate distances along X, Y and Z, in model units.
91
+ * @param inputs - The solid and the three distances
92
+ * @returns The moved solid
69
93
  * @group transforms
70
94
  * @shortname translate xyz
71
95
  * @drawable true
96
+ * @example
97
+ * ```typescript
98
+ * const moved = await bitbybit.manifold.manifold.transforms.translateXYZ({ manifold: cube, x: 10, y: 0, z: 5 });
99
+ * ```
72
100
  */
73
101
  translateXYZ(inputs) {
74
102
  return inputs.manifold.translate(inputs.x, inputs.y, inputs.z);
75
103
  }
76
104
  /**
77
- * Rotates a manifold shape along the vector containing euler angles
78
- * @param inputs manifold and rotation vector
79
- * @returns Rotated manifold shape
105
+ * Rotates a solid about the origin by Euler angles in degrees: first about X, then Y, then Z.
106
+ *
107
+ * Multiples of 90 degrees are exact, with no rounding error.
108
+ * @param inputs - The solid and the three angles in degrees
109
+ * @returns The rotated solid
80
110
  * @group transforms
81
111
  * @shortname rotate
82
112
  * @drawable true
113
+ * @example
114
+ * ```typescript
115
+ * const turned = await bitbybit.manifold.manifold.transforms.rotate({ manifold: cube, vector: [0, 0, 45] });
116
+ * ```
83
117
  */
84
118
  rotate(inputs) {
85
119
  return inputs.manifold.rotate(inputs.vector);
86
120
  }
87
121
  /**
88
- * Rotates a manifold shape along the x y z euler angles
89
- * @param inputs manifold and rotation eulers
90
- * @returns Rotated manifold shape
122
+ * Rotates a solid about the origin by separate angles in degrees about X, then Y, then Z.
123
+ *
124
+ * Multiples of 90 degrees are exact, with no rounding error.
125
+ * @param inputs - The solid and the three angles in degrees
126
+ * @returns The rotated solid
91
127
  * @group transforms
92
128
  * @shortname rotate xyz
93
129
  * @drawable true
130
+ * @example
131
+ * ```typescript
132
+ * const turned = await bitbybit.manifold.manifold.transforms.rotateXYZ({ manifold: cube, x: 0, y: 0, z: 45 });
133
+ * ```
94
134
  */
95
135
  rotateXYZ(inputs) {
96
136
  return inputs.manifold.rotate(inputs.x, inputs.y, inputs.z);
97
137
  }
98
138
  /**
99
- * Transforms a manifold shape by using the 4x4 transformation matrix
100
- * @param inputs manifold and transformation matrix
101
- * @returns Transformed manifold shape
139
+ * Applies a 4x4 matrix to a solid.
140
+ *
141
+ * The matrix is column-major, 16 numbers with the translation at indexes 12 to 14; the kernel
142
+ * reads it as a 3x4 affine transform and ignores the last row.
143
+ * @param inputs - The solid and the matrix
144
+ * @returns The transformed solid
102
145
  * @group matrix
103
146
  * @shortname transform
104
147
  * @drawable true
148
+ * @example
149
+ * ```typescript
150
+ * const moved = await bitbybit.manifold.manifold.transforms.transform({ manifold: cube, transform: matrix });
151
+ * ```
105
152
  */
106
153
  transform(inputs) {
107
154
  return inputs.manifold.transform(inputs.transform);
108
155
  }
109
156
  /**
110
- * Transforms a manifold shape by using the 4x4 transformation matrixes
111
- * @param inputs manifold and transformation matrixes
112
- * @returns Transformed manifold shape
157
+ * Applies a list of 4x4 matrices to a solid one after another, first to last, and returns the
158
+ * final result.
159
+ *
160
+ * An empty list throws an error.
161
+ * @param inputs - The solid and the matrices
162
+ * @returns The solid after all the matrices
113
163
  * @group matrix
114
164
  * @shortname transforms
115
165
  * @drawable true
166
+ * @example
167
+ * ```typescript
168
+ * const placed = await bitbybit.manifold.manifold.transforms.transforms({ manifold: cube, transforms: [turn, move] });
169
+ * ```
116
170
  */
117
171
  transforms(inputs) {
118
172
  let currentShape = inputs.manifold;
@@ -131,15 +185,23 @@ export class ManifoldTransforms {
131
185
  return res;
132
186
  }
133
187
  /**
134
- * Move the vertices of this Manifold (creating a new one) according to any
135
- * arbitrary input function. It is easy to create a function that warps a
136
- * geometrically valid object into one which overlaps, but that is not checked
137
- * here, so it is up to the user to choose their function with discretion.
138
- * @param inputs manifold and warp function
139
- * @returns Warped manifold shape
188
+ * Moves every vertex of a solid with a function of your own that changes the vertex position in
189
+ * place, for bends, tapers and other free deformations.
190
+ *
191
+ * The mesh connectivity stays the same and nothing checks that the result still makes sense, so
192
+ * a function that folds the surface through itself gives a broken solid.
193
+ * @param inputs - The solid and the function that moves each vertex
194
+ * @returns The warped solid
140
195
  * @group transforms
141
196
  * @shortname warp
142
197
  * @drawable true
198
+ * @example
199
+ * ```typescript
200
+ * const bent = await bitbybit.manifold.manifold.transforms.warp({
201
+ * manifold: cube,
202
+ * warpFunc: (vert) => { vert[0] += vert[2] * 0.2; },
203
+ * });
204
+ * ```
143
205
  */
144
206
  warp(inputs) {
145
207
  return inputs.manifold.warp(inputs.warpFunc);