@bitbybit-dev/manifold 1.5.0 → 1.6.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.
- package/lib/api/manifold-service.js +2 -2
- package/lib/api/services/cross-section/cross-section-operations.js +30 -9
- package/lib/api/services/cross-section/cross-section.d.ts +1 -1
- package/lib/api/services/manifold/manifold-booleans.js +41 -23
- package/lib/api/services/manifold/manifold-shapes.js +3 -4
- package/lib/api/services/manifold/manifold-transforms.js +13 -8
- package/lib/api/services/manifold-of-mesh-types.d.ts +3 -0
- package/lib/api/services/manifold-of-mesh-types.js +1 -0
- package/lib/api/services/manifold-of-mesh.d.ts +2 -0
- package/lib/api/services/manifold-of-mesh.js +11 -0
- package/lib/api/services/mesh-data.js +1 -1
- package/lib/api/services/recipes/recipe-executor.js +12 -4
- package/lib/api/services/recipes/recipe-loft.js +3 -3
- package/lib/api/services/recipes/recipe-meshes.d.ts +2 -1
- package/lib/api/services/recipes/recipe-meshes.js +3 -4
- package/lib/api/services/recipes/recipes.constants.d.ts +0 -1
- package/lib/api/services/recipes/recipes.constants.js +0 -1
- package/lib/api/services/recipes/recipes.d.ts +3 -1
- package/lib/api/services/recipes/recipes.js +7 -6
- package/package.json +3 -3
- package/lib/base.d.ts +0 -15
- package/lib/base.js +0 -16
|
@@ -3,7 +3,7 @@ import { CrossSection } from "./services/cross-section/cross-section";
|
|
|
3
3
|
import { Mesh } from "./services/mesh/mesh";
|
|
4
4
|
import { ManifoldRecipes } from "./services/recipes/recipes";
|
|
5
5
|
import { creasedMeshData, positionsOf } from "./services/mesh-data";
|
|
6
|
-
import { BaseBitByBit } from "
|
|
6
|
+
import { BaseBitByBit } from "@bitbybit-dev/base";
|
|
7
7
|
/**
|
|
8
8
|
* The entry point to the Manifold kernel, a fast mesh-based solid modeler: `manifold` builds and
|
|
9
9
|
* changes solids, `crossSection` handles the flat outlines they are extruded and revolved from,
|
|
@@ -19,7 +19,7 @@ export class ManifoldService {
|
|
|
19
19
|
this.manifold = new Manifold(wasm);
|
|
20
20
|
this.crossSection = new CrossSection(wasm, this.base);
|
|
21
21
|
this.mesh = new Mesh(wasm);
|
|
22
|
-
this.recipes = new ManifoldRecipes(wasm);
|
|
22
|
+
this.recipes = new ManifoldRecipes(wasm, this.base.recipes);
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Turns a solid into plain mesh data, or a cross-section into its polygons, ready for drawing
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as Inputs from "../../inputs/manifold-inputs";
|
|
2
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";
|
|
3
|
+
import { isTransformMatrix, linearDeterminant } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/matrices";
|
|
4
|
+
import { pathTangents, roundedPath3, sweepMatrices, transportedAxes } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/paths";
|
|
5
5
|
import { loftMesh } from "../recipes/recipe-loft";
|
|
6
|
+
import { manifoldOfMesh } from "../manifold-of-mesh";
|
|
6
7
|
import { DEGENERATE_DETERMINANT, FULL_TURN, MIN_CIRCLE_SIDES, MIN_LOFT_FRAMES, NO_DIRECTION } from "./cross-section.constants";
|
|
7
8
|
function isPlacing(frame) {
|
|
8
9
|
return isTransformMatrix(frame) && frame[3] === 0 && frame[7] === 0 && frame[11] === 0 && frame[15] === 1 && Math.abs(linearDeterminant(frame)) > DEGENERATE_DETERMINANT;
|
|
@@ -55,7 +56,13 @@ export class CrossSectionOperations {
|
|
|
55
56
|
*/
|
|
56
57
|
extrude(inputs) {
|
|
57
58
|
const resolved = resolveDto(Inputs.Manifold.ExtrudeDto, inputs);
|
|
58
|
-
|
|
59
|
+
const extruded = resolved.crossSection.extrude(resolved.height, resolved.nDivisions, resolved.twistDegrees, [resolved.scaleTopX, resolved.scaleTopY], false);
|
|
60
|
+
if (!resolved.center) {
|
|
61
|
+
return extruded;
|
|
62
|
+
}
|
|
63
|
+
const centred = extruded.translate([0, 0, -resolved.height / 2]);
|
|
64
|
+
extruded.delete();
|
|
65
|
+
return centred;
|
|
59
66
|
}
|
|
60
67
|
/**
|
|
61
68
|
* Spins a cross-section around the Y axis into a solid, like a lathe; only the part of the
|
|
@@ -77,12 +84,12 @@ export class CrossSectionOperations {
|
|
|
77
84
|
revolve(inputs) {
|
|
78
85
|
const resolved = resolveDto(Inputs.Manifold.RevolveDto, inputs);
|
|
79
86
|
const res = resolved.crossSection.revolve(resolved.circularSegments, resolved.revolveDegrees);
|
|
80
|
-
if (resolved.matchProfile) {
|
|
81
|
-
return res.rotate([-90, 0, 0]);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
87
|
+
if (!resolved.matchProfile) {
|
|
84
88
|
return res;
|
|
85
89
|
}
|
|
90
|
+
const matched = res.rotate([-90, 0, 0]);
|
|
91
|
+
res.delete();
|
|
92
|
+
return matched;
|
|
86
93
|
}
|
|
87
94
|
/**
|
|
88
95
|
* Joins cross-sections placed by frames into a solid, each section to the next by straight
|
|
@@ -120,7 +127,7 @@ export class CrossSectionOperations {
|
|
|
120
127
|
throw new InputError(`A loft needs one cross-section, or one for each of its ${frames.length} frames`, "crossSections");
|
|
121
128
|
}
|
|
122
129
|
const sections = crossSections.map((crossSection) => crossSection.toPolygons());
|
|
123
|
-
return this.manifold
|
|
130
|
+
return manifoldOfMesh(this.manifold, loftMesh(this.manifold, sections, Float64Array.from(frames.flat()), undefined, "The loft"));
|
|
124
131
|
}
|
|
125
132
|
/**
|
|
126
133
|
* Carries a cross-section along a path of points into a solid, square to the path at every
|
|
@@ -211,7 +218,21 @@ export class CrossSectionOperations {
|
|
|
211
218
|
*/
|
|
212
219
|
compose(inputs) {
|
|
213
220
|
const { CrossSection } = this.manifold;
|
|
214
|
-
|
|
221
|
+
const builtFromPolygons = [];
|
|
222
|
+
try {
|
|
223
|
+
const sections = inputs.polygons.map((item) => {
|
|
224
|
+
if (item instanceof CrossSection) {
|
|
225
|
+
return item;
|
|
226
|
+
}
|
|
227
|
+
const section = new CrossSection(item);
|
|
228
|
+
builtFromPolygons.push(section);
|
|
229
|
+
return section;
|
|
230
|
+
});
|
|
231
|
+
return CrossSection.compose(sections);
|
|
232
|
+
}
|
|
233
|
+
finally {
|
|
234
|
+
builtFromPolygons.forEach((section) => section.delete());
|
|
235
|
+
}
|
|
215
236
|
}
|
|
216
237
|
/**
|
|
217
238
|
* Splits a cross-section into its separate, unconnected outlines, each with its own holes, the
|
|
@@ -5,7 +5,7 @@ import { CrossSectionOperations } from "./cross-section-operations";
|
|
|
5
5
|
import { CrossSectionTransforms } from "./cross-section-transforms";
|
|
6
6
|
import { CrossSectionBooleans } from "./cross-section-booleans";
|
|
7
7
|
import { CrossSectionEvaluate } from "./cross-section-evaluate";
|
|
8
|
-
import type { BaseBitByBit } from "
|
|
8
|
+
import type { BaseBitByBit } from "@bitbybit-dev/base";
|
|
9
9
|
/**
|
|
10
10
|
* Flat outlines in the Manifold kernel, the 2D shapes that `operations.extrude` and
|
|
11
11
|
* `operations.revolve` turn into solids and that `slice` and `project` cut out of them. A
|
|
@@ -1,5 +1,5 @@
|
|
|
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
3
|
/**
|
|
4
4
|
* Combining Manifold solids: fusing, cutting and intersecting two or many at once, and splitting a
|
|
5
5
|
* solid with another solid or a plane. Because the kernel works on closed triangle meshes, these
|
|
@@ -242,33 +242,45 @@ export class ManifoldBooleans {
|
|
|
242
242
|
*/
|
|
243
243
|
splitByPlaneOnOffsets(inputs) {
|
|
244
244
|
const resolved = resolveDto(Inputs.Manifold.SplitByPlaneOnOffsetsDto, inputs);
|
|
245
|
+
if (!Array.isArray(resolved.originOffsets)) {
|
|
246
|
+
throw new InputError("The offsets to split at must be a list of distances", "originOffsets");
|
|
247
|
+
}
|
|
245
248
|
const pieces = [];
|
|
246
249
|
const junk = [];
|
|
247
250
|
let remainder = resolved.manifold.asOriginal();
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
251
|
+
try {
|
|
252
|
+
resolved.originOffsets.forEach((offset) => {
|
|
253
|
+
if (!remainder) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const splitting = remainder;
|
|
257
|
+
remainder = undefined;
|
|
258
|
+
junk.push(splitting);
|
|
259
|
+
const halfs = splitting.splitByPlane(resolved.normal, offset);
|
|
260
|
+
if (halfs[1].isEmpty()) {
|
|
261
|
+
junk.push(halfs[1]);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
pieces.push(halfs[1]);
|
|
265
|
+
}
|
|
266
|
+
if (halfs[0].isEmpty()) {
|
|
267
|
+
junk.push(halfs[0]);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
remainder = halfs[0];
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
junk.push(...pieces);
|
|
276
|
+
throw error;
|
|
277
|
+
}
|
|
278
|
+
finally {
|
|
279
|
+
junk.forEach(j => j.delete());
|
|
280
|
+
}
|
|
268
281
|
if (remainder) {
|
|
269
282
|
pieces.push(remainder);
|
|
270
283
|
}
|
|
271
|
-
junk.forEach(j => j.delete());
|
|
272
284
|
return pieces;
|
|
273
285
|
}
|
|
274
286
|
/**
|
|
@@ -287,6 +299,12 @@ export class ManifoldBooleans {
|
|
|
287
299
|
*/
|
|
288
300
|
trimByPlane(inputs) {
|
|
289
301
|
const resolved = resolveDto(Inputs.Manifold.TrimByPlaneDto, inputs);
|
|
290
|
-
|
|
302
|
+
const original = resolved.manifold.asOriginal();
|
|
303
|
+
try {
|
|
304
|
+
return original.trimByPlane(resolved.normal, resolved.originOffset);
|
|
305
|
+
}
|
|
306
|
+
finally {
|
|
307
|
+
original.delete();
|
|
308
|
+
}
|
|
291
309
|
}
|
|
292
310
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Inputs from "../../inputs/manifold-inputs";
|
|
2
2
|
import { resolveDto } from "@bitbybit-dev/base";
|
|
3
|
+
import { manifoldOfMesh } from "../manifold-of-mesh";
|
|
3
4
|
const VERTEX_MERGE_TOLERANCE = 1e-7;
|
|
4
5
|
const snapToMergeGrid = (coordinate) => Math.round(coordinate / VERTEX_MERGE_TOLERANCE) || 0;
|
|
5
6
|
/**
|
|
@@ -29,8 +30,7 @@ export class ManifoldShapes {
|
|
|
29
30
|
* ```
|
|
30
31
|
*/
|
|
31
32
|
manifoldFromMesh(inputs) {
|
|
32
|
-
|
|
33
|
-
return new Manifold(inputs.mesh);
|
|
33
|
+
return manifoldOfMesh(this.manifold, inputs.mesh);
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Builds a solid from a list of triangles, each given as three points, merging points that
|
|
@@ -49,7 +49,6 @@ export class ManifoldShapes {
|
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
51
|
fromPolygonPoints(inputs) {
|
|
52
|
-
const { Manifold } = this.manifold;
|
|
53
52
|
const polygons = inputs.polygonPoints;
|
|
54
53
|
const vertexMap = new Map();
|
|
55
54
|
const uniqueVertexCoords = [];
|
|
@@ -86,7 +85,7 @@ export class ManifoldShapes {
|
|
|
86
85
|
meshDto.numProp = numProp;
|
|
87
86
|
meshDto.vertProperties = vertProperties;
|
|
88
87
|
meshDto.triVerts = triVerts;
|
|
89
|
-
return
|
|
88
|
+
return manifoldOfMesh(this.manifold, meshDto);
|
|
90
89
|
}
|
|
91
90
|
/**
|
|
92
91
|
* Creates a cube solid with the given side length.
|
|
@@ -178,17 +178,22 @@ export class ManifoldTransforms {
|
|
|
178
178
|
transforms(inputs) {
|
|
179
179
|
let currentShape = inputs.manifold;
|
|
180
180
|
const transformedShapes = [];
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
181
|
+
let res;
|
|
182
|
+
try {
|
|
183
|
+
inputs.transforms.forEach(transform => {
|
|
184
|
+
currentShape = currentShape.transform(transform);
|
|
185
|
+
transformedShapes.push(currentShape);
|
|
186
|
+
});
|
|
187
|
+
res = transformedShapes.pop();
|
|
188
|
+
}
|
|
189
|
+
finally {
|
|
190
|
+
transformedShapes.forEach(shape => {
|
|
191
|
+
shape.delete();
|
|
192
|
+
});
|
|
193
|
+
}
|
|
186
194
|
if (!res) {
|
|
187
195
|
throw new Error("At least one transform is required");
|
|
188
196
|
}
|
|
189
|
-
transformedShapes.forEach(shape => {
|
|
190
|
-
shape.delete();
|
|
191
|
-
});
|
|
192
197
|
return res;
|
|
193
198
|
}
|
|
194
199
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function manifoldOfMesh(wasm, mesh) {
|
|
2
|
+
const KernelManifold = Reflect.get(wasm.Manifold.prototype, "constructor");
|
|
3
|
+
const solid = new KernelManifold(mesh);
|
|
4
|
+
const status = solid.status();
|
|
5
|
+
if (status === "NoError") {
|
|
6
|
+
return solid;
|
|
7
|
+
}
|
|
8
|
+
solid.delete();
|
|
9
|
+
const ManifoldError = Reflect.get(wasm, "ManifoldError");
|
|
10
|
+
throw new ManifoldError(status);
|
|
11
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { creasedMesh } from "@bitbybit-dev/base/lib/api/services/helpers/mesh-normals";
|
|
1
|
+
import { creasedMesh } from "@bitbybit-dev/base/lib/api/services/helpers/mesh/mesh-normals";
|
|
2
2
|
const POSITION_SIZE = 3;
|
|
3
3
|
const WITH_NORMALS = 6;
|
|
4
4
|
export function positionsOf(mesh) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { loftMesh } from "./recipe-loft";
|
|
2
|
-
import {
|
|
2
|
+
import { manifoldOfMesh } from "../manifold-of-mesh";
|
|
3
|
+
import { degreesOf } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/scalars";
|
|
3
4
|
const UNIT_HEIGHT = 1;
|
|
4
5
|
const FULL_TURN = 2 * Math.PI;
|
|
5
6
|
const MIN_REVOLVE_SEGMENTS = 3;
|
|
@@ -46,6 +47,8 @@ function requiredInputsOf(node) {
|
|
|
46
47
|
return [node.profile];
|
|
47
48
|
case "loft":
|
|
48
49
|
return node.profiles;
|
|
50
|
+
case "brep":
|
|
51
|
+
return node.fallback === undefined ? [] : [node.fallback];
|
|
49
52
|
default:
|
|
50
53
|
return [];
|
|
51
54
|
}
|
|
@@ -198,6 +201,11 @@ class RecipeExecutor {
|
|
|
198
201
|
return this.revolve(node, index);
|
|
199
202
|
case "loft":
|
|
200
203
|
return this.loft(node, index);
|
|
204
|
+
case "brep":
|
|
205
|
+
if (node.fallback === undefined) {
|
|
206
|
+
throw new Error(`Recipe node ${index} describes faces on exact surfaces, which this kernel does not build, and gives no fallback to build instead`);
|
|
207
|
+
}
|
|
208
|
+
return this.solid(node.fallback).translate([0, 0, 0]);
|
|
201
209
|
}
|
|
202
210
|
}
|
|
203
211
|
revolve(node, index) {
|
|
@@ -223,7 +231,7 @@ class RecipeExecutor {
|
|
|
223
231
|
}
|
|
224
232
|
const normal = along[0] * across[1] - along[1] * across[0];
|
|
225
233
|
try {
|
|
226
|
-
const turned = this.wasm.Manifold.revolve(profile, Math.max(MIN_REVOLVE_SEGMENTS, Math.ceil((this.circularSegments * node.angle) / FULL_TURN)), node.angle
|
|
234
|
+
const turned = this.wasm.Manifold.revolve(profile, Math.max(MIN_REVOLVE_SEGMENTS, Math.ceil((this.circularSegments * node.angle) / FULL_TURN)), degreesOf(node.angle));
|
|
227
235
|
try {
|
|
228
236
|
return turned.transform([across[0], across[1], 0, 0, 0, 0, normal, 0, along[0], along[1], 0, 0, ox, oy, 0, 1]);
|
|
229
237
|
}
|
|
@@ -250,7 +258,7 @@ class RecipeExecutor {
|
|
|
250
258
|
loft(node, index) {
|
|
251
259
|
const frames = this.recipe.buffers.f64.subarray(node.frames[0], node.frames[0] + node.frames[1]);
|
|
252
260
|
const sections = node.profiles.map((profile) => this.profileRings(profile));
|
|
253
|
-
return this.wasm
|
|
261
|
+
return manifoldOfMesh(this.wasm, loftMesh(this.wasm, sections, frames, this.recipe.tolerance, `Recipe node ${index}`));
|
|
254
262
|
}
|
|
255
263
|
polygon(node) {
|
|
256
264
|
const { CrossSection } = this.wasm;
|
|
@@ -324,7 +332,7 @@ class RecipeExecutor {
|
|
|
324
332
|
const mesh = new this.wasm.Mesh({ numProp: POSITION_PROPERTIES, vertProperties: Float32Array.from(positions), triVerts: Uint32Array.from(indices) });
|
|
325
333
|
mesh.merge();
|
|
326
334
|
try {
|
|
327
|
-
return this.wasm
|
|
335
|
+
return manifoldOfMesh(this.wasm, mesh);
|
|
328
336
|
}
|
|
329
337
|
catch (error) {
|
|
330
338
|
throw new Error(`Recipe node ${index} is a triangle mesh that is not closed, so it cannot be built as a solid`, { cause: error });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { signedVolumeOf } from "@bitbybit-dev/base/lib/api/services/helpers/mesh-measures";
|
|
2
|
-
import { signedArea2 } from "@bitbybit-dev/base/lib/api/services/helpers/polygons";
|
|
3
|
-
import { cross3, length3 } from "@bitbybit-dev/base/lib/api/services/helpers/vectors";
|
|
1
|
+
import { signedVolumeOf } from "@bitbybit-dev/base/lib/api/services/helpers/mesh/mesh-measures";
|
|
2
|
+
import { signedArea2 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/polygons";
|
|
3
|
+
import { cross3, length3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
|
|
4
4
|
import { FLOAT32_THICKNESS, TRIANGLE_CORNERS } from "./recipes.constants";
|
|
5
5
|
const MATRIX_SIZE = 16;
|
|
6
6
|
const POSITION_PROPERTIES = 3;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type * as Manifold3D from "manifold-3d";
|
|
2
2
|
import type { Base } from "@bitbybit-dev/base";
|
|
3
|
+
import type { Recipes } from "@bitbybit-dev/base";
|
|
3
4
|
import type * as Inputs from "../../inputs";
|
|
4
5
|
import type * as Resolved from "../../resolved-inputs";
|
|
5
|
-
export declare function recipeMeshes(wasm: Manifold3D.ManifoldToplevel, recipe: Base.Recipe, options: Omit<Resolved.Manifold.BuildRecipeMeshesDto, "recipe">): Inputs.Manifold.RecipeMeshesDto;
|
|
6
|
+
export declare function recipeMeshes(wasm: Manifold3D.ManifoldToplevel, recipes: Recipes, recipe: Base.Recipe, options: Omit<Resolved.Manifold.BuildRecipeMeshesDto, "recipe">): Inputs.Manifold.RecipeMeshesDto;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { recipeSourceOf, recipeSurfaceMeshes } from "@bitbybit-dev/base";
|
|
2
1
|
import { creasedMeshData, positionsOf } from "../mesh-data";
|
|
3
2
|
import { executeRecipeNodes, turnedZtoY } from "./recipe-executor";
|
|
4
3
|
const IDENTITY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
@@ -13,8 +12,8 @@ function meshOf(solid, minSharpAngle) {
|
|
|
13
12
|
const plain = solid.getMesh();
|
|
14
13
|
return creasedMeshData(positionsOf(plain), plain.triVerts, minSharpAngle);
|
|
15
14
|
}
|
|
16
|
-
export function recipeMeshes(wasm, recipe, options) {
|
|
17
|
-
const sources = recipe.roots.map((root) =>
|
|
15
|
+
export function recipeMeshes(wasm, recipes, recipe, options) {
|
|
16
|
+
const sources = recipe.roots.map((root) => recipes.sourceOf({ recipe, node: root.node, matrix: root.matrix }));
|
|
18
17
|
const solids = executeRecipeNodes(wasm, recipe, options.circularSegments, options.emptyWhenFailed, [...new Set(sources.map((source) => source.node))]);
|
|
19
18
|
const meshes = [];
|
|
20
19
|
const meshOfNode = new Map();
|
|
@@ -34,7 +33,7 @@ export function recipeMeshes(wasm, recipe, options) {
|
|
|
34
33
|
return (Object.assign({ mesh: (_a = meshOfNode.get(sources[index].node)) !== null && _a !== void 0 ? _a : NO_MESH, matrix: placedBy(sources[index].matrix, options.adjustZtoY), tag: root.tag }, (root.group === undefined ? {} : { group: root.group })));
|
|
35
34
|
});
|
|
36
35
|
const failed = sources.flatMap((source, index) => solids.get(source.node) === undefined ? [index] : []);
|
|
37
|
-
|
|
36
|
+
recipes.surfaceMeshes({ recipe, roots: failed, adjustZtoY: false }).forEach((surface, at) => {
|
|
38
37
|
if (surface === undefined) {
|
|
39
38
|
return;
|
|
40
39
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type * as Manifold3D from "manifold-3d";
|
|
2
|
+
import type { Recipes } from "@bitbybit-dev/base";
|
|
2
3
|
import * as Inputs from "../../inputs/manifold-inputs";
|
|
3
4
|
/**
|
|
4
5
|
* Building recipes: solids described as data - polygons, circles, extrusions, turns and lofts, cuts,
|
|
@@ -10,8 +11,9 @@ import * as Inputs from "../../inputs/manifold-inputs";
|
|
|
10
11
|
* @beta
|
|
11
12
|
*/
|
|
12
13
|
export declare class ManifoldRecipes {
|
|
14
|
+
private readonly recipes;
|
|
13
15
|
private manifold;
|
|
14
|
-
constructor(wasm: Manifold3D.ManifoldToplevel);
|
|
16
|
+
constructor(wasm: Manifold3D.ManifoldToplevel, recipes: Recipes);
|
|
15
17
|
/**
|
|
16
18
|
* Builds each root of a recipe as a solid placed by its matrix, in root order.
|
|
17
19
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveDto } from "@bitbybit-dev/base";
|
|
2
2
|
import * as Inputs from "../../inputs/manifold-inputs";
|
|
3
3
|
import { executeRecipe } from "./recipe-executor";
|
|
4
4
|
import { recipeMeshes } from "./recipe-meshes";
|
|
@@ -15,7 +15,8 @@ const POSITION_PROPERTIES = 3;
|
|
|
15
15
|
* @beta
|
|
16
16
|
*/
|
|
17
17
|
export class ManifoldRecipes {
|
|
18
|
-
constructor(wasm) {
|
|
18
|
+
constructor(wasm, recipes) {
|
|
19
|
+
this.recipes = recipes;
|
|
19
20
|
this.manifold = wasm;
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
@@ -37,7 +38,7 @@ export class ManifoldRecipes {
|
|
|
37
38
|
*/
|
|
38
39
|
build(inputs) {
|
|
39
40
|
const resolved = resolveDto(Inputs.Manifold.BuildRecipeDto, inputs);
|
|
40
|
-
const recipe =
|
|
41
|
+
const recipe = this.recipes.read({ recipe: resolved.recipe });
|
|
41
42
|
if (!Number.isSafeInteger(resolved.circularSegments) || resolved.circularSegments < MIN_CIRCLE_SIDES) {
|
|
42
43
|
throw new RangeError(`A circle needs at least ${MIN_CIRCLE_SIDES} sides, got ${resolved.circularSegments}`);
|
|
43
44
|
}
|
|
@@ -62,14 +63,14 @@ export class ManifoldRecipes {
|
|
|
62
63
|
*/
|
|
63
64
|
meshes(inputs) {
|
|
64
65
|
const resolved = resolveDto(Inputs.Manifold.BuildRecipeMeshesDto, inputs);
|
|
65
|
-
const recipe =
|
|
66
|
+
const recipe = this.recipes.read({ recipe: resolved.recipe });
|
|
66
67
|
if (!Number.isSafeInteger(resolved.circularSegments) || resolved.circularSegments < MIN_CIRCLE_SIDES) {
|
|
67
68
|
throw new RangeError(`A circle needs at least ${MIN_CIRCLE_SIDES} sides, got ${resolved.circularSegments}`);
|
|
68
69
|
}
|
|
69
70
|
if (!(resolved.minSharpAngle >= 0 && resolved.minSharpAngle <= MAX_SHARP_ANGLE)) {
|
|
70
71
|
throw new RangeError(`minSharpAngle must be an angle from 0 to ${MAX_SHARP_ANGLE} degrees, got ${resolved.minSharpAngle}`);
|
|
71
72
|
}
|
|
72
|
-
return recipeMeshes(this.manifold, recipe, resolved);
|
|
73
|
+
return recipeMeshes(this.manifold, this.recipes, recipe, resolved);
|
|
73
74
|
}
|
|
74
75
|
/**
|
|
75
76
|
* Gives the roots of a recipe made of triangle meshes alone as meshes, placed as `build` places
|
|
@@ -92,7 +93,7 @@ export class ManifoldRecipes {
|
|
|
92
93
|
*/
|
|
93
94
|
surfaceMeshes(inputs) {
|
|
94
95
|
const resolved = resolveDto(Inputs.Manifold.RecipeSurfaceMeshesDto, inputs);
|
|
95
|
-
return
|
|
96
|
+
return this.recipes.surfaceMeshes({ recipe: resolved.recipe, roots: resolved.roots, adjustZtoY: resolved.adjustZtoY }).map((mesh) => {
|
|
96
97
|
var _a, _b;
|
|
97
98
|
return ({
|
|
98
99
|
numProp: POSITION_PROPERTIES,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitbybit-dev/manifold",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Bit By Bit Developers Manifold based CAD Library to Program Geometry",
|
|
5
5
|
"homepage": "https://docs.bitbybit.dev/classes/Bit.Manifold",
|
|
6
6
|
"main": "index.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"types": "./index.d.ts",
|
|
55
55
|
"type": "module",
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"manifold-3d": "3.5.
|
|
58
|
-
"@bitbybit-dev/base": "1.
|
|
57
|
+
"manifold-3d": "3.5.4",
|
|
58
|
+
"@bitbybit-dev/base": "1.6.0"
|
|
59
59
|
}
|
|
60
60
|
}
|
package/lib/base.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { TextBitByBit, Point, GeometryHelper, Transforms, Vector, MathBitByBit, MeshBitByBit, Polyline, Line, Lists, IoBitByBit } from "@bitbybit-dev/base";
|
|
2
|
-
export declare class BaseBitByBit {
|
|
3
|
-
readonly geometryHelper: GeometryHelper;
|
|
4
|
-
readonly vector: Vector;
|
|
5
|
-
readonly math: MathBitByBit;
|
|
6
|
-
readonly transforms: Transforms;
|
|
7
|
-
readonly lists: Lists;
|
|
8
|
-
readonly point: Point;
|
|
9
|
-
readonly line: Line;
|
|
10
|
-
readonly polyline: Polyline;
|
|
11
|
-
readonly mesh: MeshBitByBit;
|
|
12
|
-
readonly textService: TextBitByBit;
|
|
13
|
-
readonly io: IoBitByBit;
|
|
14
|
-
constructor();
|
|
15
|
-
}
|
package/lib/base.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { TextBitByBit, Point, GeometryHelper, Transforms, Vector, MathBitByBit, MeshBitByBit, Polyline, Line, Lists, IoBitByBit } from "@bitbybit-dev/base";
|
|
2
|
-
export class BaseBitByBit {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.geometryHelper = new GeometryHelper();
|
|
5
|
-
this.math = new MathBitByBit();
|
|
6
|
-
this.vector = new Vector(this.math, this.geometryHelper);
|
|
7
|
-
this.transforms = new Transforms(this.vector, this.math);
|
|
8
|
-
this.lists = new Lists();
|
|
9
|
-
this.point = new Point(this.geometryHelper, this.transforms, this.vector, this.lists);
|
|
10
|
-
this.line = new Line(this.vector, this.point, this.geometryHelper);
|
|
11
|
-
this.polyline = new Polyline(this.vector, this.point, this.line, this.geometryHelper);
|
|
12
|
-
this.textService = new TextBitByBit(this.point);
|
|
13
|
-
this.mesh = new MeshBitByBit(this.vector, this.polyline);
|
|
14
|
-
this.io = new IoBitByBit();
|
|
15
|
-
}
|
|
16
|
-
}
|