@bitbybit-dev/manifold 1.6.2 → 1.8.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/dto-registry.js +3 -3
- package/lib/api/inputs/manifold-inputs.d.ts +36 -12
- package/lib/api/inputs/manifold-inputs.js +26 -15
- package/lib/api/manifold-service.d.ts +10 -0
- package/lib/api/manifold-service.js +15 -2
- package/lib/api/resolved-inputs/index.d.ts +3 -3
- package/lib/api/services/recipes/recipe-executor.d.ts +2 -2
- package/lib/api/services/recipes/recipe-executor.js +47 -66
- package/lib/api/services/recipes/recipe-meshes.d.ts +3 -2
- package/lib/api/services/recipes/recipe-meshes.js +27 -11
- package/lib/api/services/recipes/recipe-placing.d.ts +10 -0
- package/lib/api/services/recipes/recipe-placing.js +36 -0
- package/lib/api/services/recipes/recipe-reach.d.ts +5 -0
- package/lib/api/services/recipes/recipe-reach.js +414 -0
- package/lib/api/services/recipes/recipe-types.d.ts +42 -0
- package/lib/api/services/recipes/recipes.d.ts +10 -9
- package/lib/api/services/recipes/recipes.js +13 -11
- package/package.json +2 -2
package/lib/api/dto-registry.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// GENERATED by scripts/gen-dto-meta.mjs from the ManifoldService surface - do not edit; regenerate with `npm run gen:dto-meta`.
|
|
2
2
|
import { constraintKinds as k } from "@bitbybit-dev/base";
|
|
3
3
|
import * as Inputs from "./inputs";
|
|
4
|
-
const Manifold_BuildRecipeDto = { recipe: k.required(k.opaque), circularSegments: k.between(k.number, { min: 3 }), adjustZtoY: k.boolean, emptyWhenFailed: k.boolean };
|
|
5
|
-
const Manifold_BuildRecipeMeshesDto = { recipe: k.required(k.opaque), circularSegments: k.between(k.number, { min: 3 }), adjustZtoY: k.boolean, emptyWhenFailed: k.boolean, minSharpAngle: k.between(k.number, { min: 0, max: 180 }) };
|
|
4
|
+
const Manifold_BuildRecipeDto = { recipe: k.required(k.opaque), circularSegments: k.between(k.number, { min: 3 }), upAxis: k.oneOf(["keep", "zUpToYUp", "yUpToZUp"]), adjustZtoY: k.boolean, emptyWhenFailed: k.boolean };
|
|
5
|
+
const Manifold_BuildRecipeMeshesDto = { recipe: k.required(k.opaque), circularSegments: k.between(k.number, { min: 3 }), upAxis: k.oneOf(["keep", "zUpToYUp", "yUpToZUp"]), adjustZtoY: k.boolean, emptyWhenFailed: k.boolean, minSharpAngle: k.between(k.number, { min: 0, max: 180 }) };
|
|
6
6
|
const Manifold_CalculateCurvatureDto = { manifold: k.required(k.opaque), gaussianIdx: k.between(k.number, { min: 0 }), meanIdx: k.between(k.number, { min: 0 }) };
|
|
7
7
|
const Manifold_CalculateNormalsDto = { manifold: k.required(k.opaque), normalIdx: k.between(k.number, { min: 0 }), minSharpAngle: k.between(k.number, { min: 0 }) };
|
|
8
8
|
const Manifold_CircleDto = { radius: k.between(k.number, { min: 0 }), circularSegments: k.between(k.number, { min: 0 }) };
|
|
@@ -45,7 +45,7 @@ const Manifold_MirrorCrossSectionDto = { crossSection: k.required(k.opaque), nor
|
|
|
45
45
|
const Manifold_MirrorDto = { manifold: k.required(k.opaque), normal: k.vector3 };
|
|
46
46
|
const Manifold_OffsetDto = { crossSection: k.required(k.opaque), delta: k.number, joinType: k.oneOf(["Square", "Round", "Miter", "Bevel"]), miterLimit: k.between(k.number, { min: 2 }), circularSegments: k.between(k.number, { min: 0 }) };
|
|
47
47
|
const Manifold_RayCastDto = { manifold: k.required(k.opaque), origin: k.point3, endpoint: k.point3 };
|
|
48
|
-
const Manifold_RecipeSurfaceMeshesDto = { recipe: k.required(k.opaque), roots: k.list(k.number), adjustZtoY: k.boolean };
|
|
48
|
+
const Manifold_RecipeSurfaceMeshesDto = { recipe: k.required(k.opaque), roots: k.list(k.number), upAxis: k.oneOf(["keep", "zUpToYUp", "yUpToZUp"]), adjustZtoY: k.boolean };
|
|
49
49
|
const Manifold_RectangleDto = { length: k.between(k.number, { min: 0 }), height: k.between(k.number, { min: 0 }), center: k.boolean };
|
|
50
50
|
const Manifold_RevolveDto = { crossSection: k.required(k.opaque), revolveDegrees: k.between(k.number, { min: 0, exclusiveMin: true }), matchProfile: k.boolean, circularSegments: k.between(k.number, { min: 0 }) };
|
|
51
51
|
const Manifold_RotateCrossSectionDto = { crossSection: k.required(k.opaque), degrees: k.number };
|
|
@@ -1735,7 +1735,7 @@ export declare namespace Manifold {
|
|
|
1735
1735
|
* @beta
|
|
1736
1736
|
*/
|
|
1737
1737
|
class BuildRecipeDto {
|
|
1738
|
-
constructor(recipe?: Base.Recipe, circularSegments?: number, adjustZtoY?: boolean, emptyWhenFailed?: boolean);
|
|
1738
|
+
constructor(recipe?: Base.Recipe, circularSegments?: number, adjustZtoY?: boolean, emptyWhenFailed?: boolean, upAxis?: Base.upAxisConversionEnum);
|
|
1739
1739
|
/**
|
|
1740
1740
|
* The recipe: steps such as polygons, extrusions and cuts, and the roots to build from them, as
|
|
1741
1741
|
* a package that describes geometry as data writes it.
|
|
@@ -1752,9 +1752,17 @@ export declare namespace Manifold {
|
|
|
1752
1752
|
*/
|
|
1753
1753
|
circularSegments?: number | undefined;
|
|
1754
1754
|
/**
|
|
1755
|
-
*
|
|
1756
|
-
*
|
|
1757
|
-
* @default
|
|
1755
|
+
* `zUpToYUp` turns each solid a quarter turn about X so the recipe's Z points along Y, and
|
|
1756
|
+
* `(x, y, z)` becomes `(x, z, -y)`; `keep` leaves them. `yUpToZUp` is refused.
|
|
1757
|
+
* @default keep
|
|
1758
|
+
*/
|
|
1759
|
+
upAxis?: Base.upAxisConversionEnum | undefined;
|
|
1760
|
+
/**
|
|
1761
|
+
* When true, the solids turn as `upAxis` `zUpToYUp` does; false, its old default, decides nothing.
|
|
1762
|
+
* True wins over `upAxis` at its default; beside another chosen turn it is refused.
|
|
1763
|
+
* @deprecated Give `upAxis` instead; this flag goes in the next major version.
|
|
1764
|
+
* @default undefined
|
|
1765
|
+
* @optional true
|
|
1758
1766
|
*/
|
|
1759
1767
|
adjustZtoY?: boolean | undefined;
|
|
1760
1768
|
/**
|
|
@@ -1771,7 +1779,7 @@ export declare namespace Manifold {
|
|
|
1771
1779
|
* @beta
|
|
1772
1780
|
*/
|
|
1773
1781
|
class RecipeSurfaceMeshesDto {
|
|
1774
|
-
constructor(recipe?: Base.Recipe, roots?: number[], adjustZtoY?: boolean);
|
|
1782
|
+
constructor(recipe?: Base.Recipe, roots?: number[], adjustZtoY?: boolean, upAxis?: Base.upAxisConversionEnum);
|
|
1775
1783
|
/**
|
|
1776
1784
|
* The recipe: steps such as polygons, extrusions and triangle meshes, and the roots to build
|
|
1777
1785
|
* from them, as a package that describes geometry as data writes it.
|
|
@@ -1786,9 +1794,17 @@ export declare namespace Manifold {
|
|
|
1786
1794
|
*/
|
|
1787
1795
|
roots?: number[] | undefined;
|
|
1788
1796
|
/**
|
|
1789
|
-
*
|
|
1790
|
-
* `recipes.build` turns its solids
|
|
1791
|
-
* @default
|
|
1797
|
+
* Whether the meshes turn: `zUpToYUp` turns each a quarter turn about X so the recipe's Z points
|
|
1798
|
+
* along Y, as `recipes.build` turns its solids; `keep` leaves them. `yUpToZUp` is refused.
|
|
1799
|
+
* @default keep
|
|
1800
|
+
*/
|
|
1801
|
+
upAxis?: Base.upAxisConversionEnum | undefined;
|
|
1802
|
+
/**
|
|
1803
|
+
* When true, the meshes turn as `upAxis` `zUpToYUp` does; false, its old default, decides nothing.
|
|
1804
|
+
* True wins over `upAxis` at its default; beside another chosen turn it is refused.
|
|
1805
|
+
* @deprecated Give `upAxis` instead; this flag goes in the next major version.
|
|
1806
|
+
* @default undefined
|
|
1807
|
+
* @optional true
|
|
1792
1808
|
*/
|
|
1793
1809
|
adjustZtoY?: boolean | undefined;
|
|
1794
1810
|
}
|
|
@@ -1799,7 +1815,7 @@ export declare namespace Manifold {
|
|
|
1799
1815
|
* @beta
|
|
1800
1816
|
*/
|
|
1801
1817
|
class BuildRecipeMeshesDto {
|
|
1802
|
-
constructor(recipe?: Base.Recipe, circularSegments?: number, adjustZtoY?: boolean, emptyWhenFailed?: boolean, minSharpAngle?: number);
|
|
1818
|
+
constructor(recipe?: Base.Recipe, circularSegments?: number, adjustZtoY?: boolean, emptyWhenFailed?: boolean, minSharpAngle?: number, upAxis?: Base.upAxisConversionEnum);
|
|
1803
1819
|
/**
|
|
1804
1820
|
* The recipe: steps such as polygons, extrusions and cuts, and the roots to draw from them, as
|
|
1805
1821
|
* a package that describes geometry as data writes it.
|
|
@@ -1815,9 +1831,17 @@ export declare namespace Manifold {
|
|
|
1815
1831
|
*/
|
|
1816
1832
|
circularSegments?: number | undefined;
|
|
1817
1833
|
/**
|
|
1818
|
-
*
|
|
1819
|
-
* which is up when drawn
|
|
1820
|
-
* @default
|
|
1834
|
+
* Whether the placements turn: `zUpToYUp` turns each a quarter turn about X so the recipe's Z
|
|
1835
|
+
* points along Y, which is up when drawn; `keep` leaves them. `yUpToZUp` is refused.
|
|
1836
|
+
* @default keep
|
|
1837
|
+
*/
|
|
1838
|
+
upAxis?: Base.upAxisConversionEnum | undefined;
|
|
1839
|
+
/**
|
|
1840
|
+
* When true, the placements turn as `upAxis` `zUpToYUp` does; false, its old default, decides
|
|
1841
|
+
* nothing. True wins over `upAxis` at its default; beside another chosen turn it is refused.
|
|
1842
|
+
* @deprecated Give `upAxis` instead; this flag goes in the next major version.
|
|
1843
|
+
* @default undefined
|
|
1844
|
+
* @optional true
|
|
1821
1845
|
*/
|
|
1822
1846
|
adjustZtoY?: boolean | undefined;
|
|
1823
1847
|
/**
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
2
|
+
import { Base } from "./base-inputs";
|
|
1
3
|
// GENERATED by scripts/gen-inputs.mjs from the fragments in ./manifold/ - do not edit; edit a fragment and run `npm run gen:inputs`.
|
|
2
4
|
/**
|
|
3
5
|
* Every parameter object the Manifold kernel accepts. Manifold specialises in fast, reliably
|
|
@@ -1926,7 +1928,7 @@ export var Manifold;
|
|
|
1926
1928
|
* @beta
|
|
1927
1929
|
*/
|
|
1928
1930
|
class BuildRecipeDto {
|
|
1929
|
-
constructor(recipe, circularSegments, adjustZtoY, emptyWhenFailed) {
|
|
1931
|
+
constructor(recipe, circularSegments, adjustZtoY, emptyWhenFailed, upAxis) {
|
|
1930
1932
|
/**
|
|
1931
1933
|
* How many flat sides each circle of the recipe is divided into; more is rounder. The recipe
|
|
1932
1934
|
* leaves this to the kernel, so it is chosen here.
|
|
@@ -1937,11 +1939,11 @@ export var Manifold;
|
|
|
1937
1939
|
*/
|
|
1938
1940
|
this.circularSegments = 32;
|
|
1939
1941
|
/**
|
|
1940
|
-
*
|
|
1941
|
-
*
|
|
1942
|
-
* @default
|
|
1942
|
+
* `zUpToYUp` turns each solid a quarter turn about X so the recipe's Z points along Y, and
|
|
1943
|
+
* `(x, y, z)` becomes `(x, z, -y)`; `keep` leaves them. `yUpToZUp` is refused.
|
|
1944
|
+
* @default keep
|
|
1943
1945
|
*/
|
|
1944
|
-
this.
|
|
1946
|
+
this.upAxis = Base.upAxisConversionEnum.keep;
|
|
1945
1947
|
/**
|
|
1946
1948
|
* When true, a root that cannot be built, such as an open mesh, comes back empty, and an
|
|
1947
1949
|
* opening that cannot is left uncut; when false, both stop the build.
|
|
@@ -1960,6 +1962,9 @@ export var Manifold;
|
|
|
1960
1962
|
if (emptyWhenFailed !== undefined) {
|
|
1961
1963
|
this.emptyWhenFailed = emptyWhenFailed;
|
|
1962
1964
|
}
|
|
1965
|
+
if (upAxis !== undefined) {
|
|
1966
|
+
this.upAxis = upAxis;
|
|
1967
|
+
}
|
|
1963
1968
|
}
|
|
1964
1969
|
}
|
|
1965
1970
|
Manifold.BuildRecipeDto = BuildRecipeDto;
|
|
@@ -1970,13 +1975,13 @@ export var Manifold;
|
|
|
1970
1975
|
* @beta
|
|
1971
1976
|
*/
|
|
1972
1977
|
class RecipeSurfaceMeshesDto {
|
|
1973
|
-
constructor(recipe, roots, adjustZtoY) {
|
|
1978
|
+
constructor(recipe, roots, adjustZtoY, upAxis) {
|
|
1974
1979
|
/**
|
|
1975
|
-
*
|
|
1976
|
-
* `recipes.build` turns its solids
|
|
1977
|
-
* @default
|
|
1980
|
+
* Whether the meshes turn: `zUpToYUp` turns each a quarter turn about X so the recipe's Z points
|
|
1981
|
+
* along Y, as `recipes.build` turns its solids; `keep` leaves them. `yUpToZUp` is refused.
|
|
1982
|
+
* @default keep
|
|
1978
1983
|
*/
|
|
1979
|
-
this.
|
|
1984
|
+
this.upAxis = Base.upAxisConversionEnum.keep;
|
|
1980
1985
|
if (recipe !== undefined) {
|
|
1981
1986
|
this.recipe = recipe;
|
|
1982
1987
|
}
|
|
@@ -1986,6 +1991,9 @@ export var Manifold;
|
|
|
1986
1991
|
if (adjustZtoY !== undefined) {
|
|
1987
1992
|
this.adjustZtoY = adjustZtoY;
|
|
1988
1993
|
}
|
|
1994
|
+
if (upAxis !== undefined) {
|
|
1995
|
+
this.upAxis = upAxis;
|
|
1996
|
+
}
|
|
1989
1997
|
}
|
|
1990
1998
|
}
|
|
1991
1999
|
Manifold.RecipeSurfaceMeshesDto = RecipeSurfaceMeshesDto;
|
|
@@ -1996,7 +2004,7 @@ export var Manifold;
|
|
|
1996
2004
|
* @beta
|
|
1997
2005
|
*/
|
|
1998
2006
|
class BuildRecipeMeshesDto {
|
|
1999
|
-
constructor(recipe, circularSegments, adjustZtoY, emptyWhenFailed, minSharpAngle) {
|
|
2007
|
+
constructor(recipe, circularSegments, adjustZtoY, emptyWhenFailed, minSharpAngle, upAxis) {
|
|
2000
2008
|
/**
|
|
2001
2009
|
* How many flat sides each circle of the recipe is divided into; more is rounder.
|
|
2002
2010
|
* @default 32
|
|
@@ -2006,11 +2014,11 @@ export var Manifold;
|
|
|
2006
2014
|
*/
|
|
2007
2015
|
this.circularSegments = 32;
|
|
2008
2016
|
/**
|
|
2009
|
-
*
|
|
2010
|
-
* which is up when drawn
|
|
2011
|
-
* @default
|
|
2017
|
+
* Whether the placements turn: `zUpToYUp` turns each a quarter turn about X so the recipe's Z
|
|
2018
|
+
* points along Y, which is up when drawn; `keep` leaves them. `yUpToZUp` is refused.
|
|
2019
|
+
* @default keep
|
|
2012
2020
|
*/
|
|
2013
|
-
this.
|
|
2021
|
+
this.upAxis = Base.upAxisConversionEnum.keep;
|
|
2014
2022
|
/**
|
|
2015
2023
|
* When true, a root that cannot be built draws as its surface if it is triangles alone, else
|
|
2016
2024
|
* draws nothing; when false, it stops the build.
|
|
@@ -2040,6 +2048,9 @@ export var Manifold;
|
|
|
2040
2048
|
if (minSharpAngle !== undefined) {
|
|
2041
2049
|
this.minSharpAngle = minSharpAngle;
|
|
2042
2050
|
}
|
|
2051
|
+
if (upAxis !== undefined) {
|
|
2052
|
+
this.upAxis = upAxis;
|
|
2053
|
+
}
|
|
2043
2054
|
}
|
|
2044
2055
|
}
|
|
2045
2056
|
Manifold.BuildRecipeMeshesDto = BuildRecipeMeshesDto;
|
|
@@ -4,6 +4,7 @@ import { Manifold } from "./services/manifold/manifold";
|
|
|
4
4
|
import { CrossSection } from "./services/cross-section/cross-section";
|
|
5
5
|
import { Mesh } from "./services/mesh/mesh";
|
|
6
6
|
import { ManifoldRecipes } from "./services/recipes/recipes";
|
|
7
|
+
import type { BitbybitSettings } from "@bitbybit-dev/base";
|
|
7
8
|
/**
|
|
8
9
|
* The entry point to the Manifold kernel, a fast mesh-based solid modeler: `manifold` builds and
|
|
9
10
|
* changes solids, `crossSection` handles the flat outlines they are extruded and revolved from,
|
|
@@ -25,6 +26,15 @@ export declare class ManifoldService {
|
|
|
25
26
|
recipes: ManifoldRecipes;
|
|
26
27
|
private readonly wasm;
|
|
27
28
|
constructor(wasm: Manifold3D.ManifoldToplevel);
|
|
29
|
+
/**
|
|
30
|
+
* The settings this kernel works by, such as the coordinate system its numbers are in. Assign
|
|
31
|
+
* them once, before the calls they apply to: `manifold.settings = { coordinateSystem }`. With a
|
|
32
|
+
* coordinate system, `recipes` places what it builds in that system. A name that is no setting,
|
|
33
|
+
* or a value its setting does not take, is refused as an `InputError`. The settings read back
|
|
34
|
+
* are frozen, so they change only by assigning new ones.
|
|
35
|
+
*/
|
|
36
|
+
get settings(): BitbybitSettings;
|
|
37
|
+
set settings(settings: BitbybitSettings);
|
|
28
38
|
/**
|
|
29
39
|
* Turns a solid into plain mesh data, or a cross-section into its polygons, ready for drawing
|
|
30
40
|
* or export.
|
|
@@ -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 "@bitbybit-dev/base";
|
|
6
|
+
import { BaseBitByBit, checkedSettings } 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,20 @@ 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, this.base.recipes);
|
|
22
|
+
this.recipes = new ManifoldRecipes(wasm, this.base.recipes, () => this.base.settings);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The settings this kernel works by, such as the coordinate system its numbers are in. Assign
|
|
26
|
+
* them once, before the calls they apply to: `manifold.settings = { coordinateSystem }`. With a
|
|
27
|
+
* coordinate system, `recipes` places what it builds in that system. A name that is no setting,
|
|
28
|
+
* or a value its setting does not take, is refused as an `InputError`. The settings read back
|
|
29
|
+
* are frozen, so they change only by assigning new ones.
|
|
30
|
+
*/
|
|
31
|
+
get settings() {
|
|
32
|
+
return this.base.settings;
|
|
33
|
+
}
|
|
34
|
+
set settings(settings) {
|
|
35
|
+
this.base.settings = checkedSettings(settings);
|
|
23
36
|
}
|
|
24
37
|
/**
|
|
25
38
|
* Turns a solid into plain mesh data, or a cross-section into its polygons, ready for drawing
|
|
@@ -6,8 +6,8 @@ export * from "@bitbybit-dev/base/lib/api/resolved-inputs";
|
|
|
6
6
|
* the way `resolveDto` hands a DTO to the code that reads it.
|
|
7
7
|
*/
|
|
8
8
|
export declare namespace Manifold {
|
|
9
|
-
type BuildRecipeDto = WithDefaults<Inputs.Manifold.BuildRecipeDto, "circularSegments" | "
|
|
10
|
-
type BuildRecipeMeshesDto = WithDefaults<Inputs.Manifold.BuildRecipeMeshesDto, "circularSegments" | "
|
|
9
|
+
type BuildRecipeDto = WithDefaults<Inputs.Manifold.BuildRecipeDto, "circularSegments" | "upAxis" | "emptyWhenFailed">;
|
|
10
|
+
type BuildRecipeMeshesDto = WithDefaults<Inputs.Manifold.BuildRecipeMeshesDto, "circularSegments" | "upAxis" | "emptyWhenFailed" | "minSharpAngle">;
|
|
11
11
|
type CalculateCurvatureDto<T> = WithDefaults<Inputs.Manifold.CalculateCurvatureDto<T>, "gaussianIdx" | "meanIdx">;
|
|
12
12
|
type CalculateNormalsDto<T> = WithDefaults<Inputs.Manifold.CalculateNormalsDto<T>, "normalIdx" | "minSharpAngle">;
|
|
13
13
|
type CircleDto = WithDefaults<Inputs.Manifold.CircleDto, "radius" | "circularSegments">;
|
|
@@ -57,7 +57,7 @@ export declare namespace Manifold {
|
|
|
57
57
|
type RayCastDto<T> = WithDefaults<Inputs.Manifold.RayCastDto<T>, "origin" | "endpoint">;
|
|
58
58
|
type RecipeMeshesDto = Inputs.Manifold.RecipeMeshesDto;
|
|
59
59
|
type RecipeMeshPlacementDto = Inputs.Manifold.RecipeMeshPlacementDto;
|
|
60
|
-
type RecipeSurfaceMeshesDto = WithDefaults<Inputs.Manifold.RecipeSurfaceMeshesDto, "
|
|
60
|
+
type RecipeSurfaceMeshesDto = WithDefaults<Inputs.Manifold.RecipeSurfaceMeshesDto, "upAxis">;
|
|
61
61
|
type RectangleDto = WithDefaults<Inputs.Manifold.RectangleDto, "length" | "height" | "center">;
|
|
62
62
|
type RevolveDto<T> = WithDefaults<Inputs.Manifold.RevolveDto<T>, "revolveDegrees" | "matchProfile" | "circularSegments">;
|
|
63
63
|
type RotateCrossSectionDto<T> = WithDefaults<Inputs.Manifold.RotateCrossSectionDto<T>, "degrees">;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as Manifold3D from "manifold-3d";
|
|
2
2
|
import type { Base } from "@bitbybit-dev/base";
|
|
3
|
-
|
|
4
|
-
export declare function executeRecipe(wasm: Manifold3D.ManifoldToplevel, recipe: Base.Recipe, circularSegments: number,
|
|
3
|
+
import { type RootPlacing } from "./recipe-placing";
|
|
4
|
+
export declare function executeRecipe(wasm: Manifold3D.ManifoldToplevel, recipe: Base.Recipe, circularSegments: number, placing: RootPlacing, emptyWhenFailed: boolean): Manifold3D.Manifold[];
|
|
5
5
|
export declare function executeRecipeNodes(wasm: Manifold3D.ManifoldToplevel, recipe: Base.Recipe, circularSegments: number, emptyWhenFailed: boolean, nodes: readonly number[]): Map<number, Manifold3D.Manifold | undefined>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { loftMesh } from "./recipe-loft";
|
|
2
|
+
import { outlineOf, reachedThrough, releaseOutline } from "./recipe-reach";
|
|
2
3
|
import { manifoldOfMesh } from "../manifold-of-mesh";
|
|
3
4
|
import { degreesOf } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/scalars";
|
|
5
|
+
import { asTheRecipeSays } from "./recipe-placing";
|
|
4
6
|
const UNIT_HEIGHT = 1;
|
|
5
7
|
const FULL_TURN = 2 * Math.PI;
|
|
6
8
|
const MIN_REVOLVE_SEGMENTS = 3;
|
|
7
9
|
const POSITION_PROPERTIES = 3;
|
|
8
10
|
const FILL_RULE = "NonZero";
|
|
9
|
-
const AXES = 3;
|
|
10
11
|
const MAX_TOOL_PARTS = 64;
|
|
11
12
|
function isHalfSpace(value) {
|
|
12
13
|
return typeof value === "object" && value !== null && "op" in value;
|
|
@@ -55,18 +56,6 @@ function requiredInputsOf(node) {
|
|
|
55
56
|
return [];
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
|
-
function negatedWithoutNegativeZero(value) {
|
|
59
|
-
return 0 - value;
|
|
60
|
-
}
|
|
61
|
-
export function turnedZtoY(matrix) {
|
|
62
|
-
const [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p] = matrix;
|
|
63
|
-
return [
|
|
64
|
-
a, c, negatedWithoutNegativeZero(b), d,
|
|
65
|
-
e, g, negatedWithoutNegativeZero(f), h,
|
|
66
|
-
i, k, negatedWithoutNegativeZero(j), l,
|
|
67
|
-
m, o, negatedWithoutNegativeZero(n), p,
|
|
68
|
-
];
|
|
69
|
-
}
|
|
70
59
|
function isClockwise(ring) {
|
|
71
60
|
let twiceArea = 0;
|
|
72
61
|
for (let at = 0, previous = ring.length - 1; at < ring.length; previous = at++) {
|
|
@@ -75,11 +64,11 @@ function isClockwise(ring) {
|
|
|
75
64
|
return twiceArea < 0;
|
|
76
65
|
}
|
|
77
66
|
class RecipeExecutor {
|
|
78
|
-
constructor(wasm, recipe, circularSegments,
|
|
67
|
+
constructor(wasm, recipe, circularSegments, placing, emptyWhenFailed) {
|
|
79
68
|
this.wasm = wasm;
|
|
80
69
|
this.recipe = recipe;
|
|
81
70
|
this.circularSegments = circularSegments;
|
|
82
|
-
this.
|
|
71
|
+
this.placing = placing;
|
|
83
72
|
this.emptyWhenFailed = emptyWhenFailed;
|
|
84
73
|
this.built = [];
|
|
85
74
|
this.failed = new Set();
|
|
@@ -142,7 +131,7 @@ class RecipeExecutor {
|
|
|
142
131
|
placed(root, index) {
|
|
143
132
|
let placed;
|
|
144
133
|
try {
|
|
145
|
-
placed = this.solid(root.node).transform(this.
|
|
134
|
+
placed = this.solid(root.node).transform(this.placing(root.matrix));
|
|
146
135
|
expectNoError(placed.status(), root, index);
|
|
147
136
|
return placed;
|
|
148
137
|
}
|
|
@@ -292,30 +281,6 @@ class RecipeExecutor {
|
|
|
292
281
|
swept.delete();
|
|
293
282
|
}
|
|
294
283
|
}
|
|
295
|
-
reaching(tool, outside) {
|
|
296
|
-
const reach = this.recipe.tolerance;
|
|
297
|
-
const ofTool = tool.boundingBox();
|
|
298
|
-
const below = ofTool.min.map((side, axis) => Math.abs(side - outside.min[axis]) <= reach);
|
|
299
|
-
const above = ofTool.max.map((side, axis) => Math.abs(side - outside.max[axis]) <= reach);
|
|
300
|
-
if (!below.includes(true) && !above.includes(true)) {
|
|
301
|
-
return tool.translate([0, 0, 0]);
|
|
302
|
-
}
|
|
303
|
-
return tool.warp((vertex) => {
|
|
304
|
-
for (let axis = 0; axis < AXES; axis++) {
|
|
305
|
-
const drawn = vertex[axis];
|
|
306
|
-
const fromBelow = drawn - ofTool.min[axis];
|
|
307
|
-
const fromAbove = ofTool.max[axis] - drawn;
|
|
308
|
-
const down = below[axis] && fromBelow <= reach;
|
|
309
|
-
const up = above[axis] && fromAbove <= reach;
|
|
310
|
-
if (down && (!up || fromBelow <= fromAbove)) {
|
|
311
|
-
vertex[axis] = drawn - reach;
|
|
312
|
-
}
|
|
313
|
-
else if (up) {
|
|
314
|
-
vertex[axis] = drawn + reach;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
284
|
joinsParts(index) {
|
|
320
285
|
const node = this.recipe.nodes[index];
|
|
321
286
|
return node.op === "compound" || node.op === "union" || (node.op === "transform" && this.joinsParts(node.of));
|
|
@@ -372,29 +337,28 @@ class RecipeExecutor {
|
|
|
372
337
|
}
|
|
373
338
|
into.push(part);
|
|
374
339
|
}
|
|
375
|
-
reachedParts(index,
|
|
340
|
+
reachedParts(index, outline, into) {
|
|
376
341
|
const parts = this.toolParts(index);
|
|
377
342
|
try {
|
|
378
343
|
for (const part of parts) {
|
|
379
|
-
into.push(
|
|
344
|
+
into.push(reachedThrough(part, outline, this.recipe.tolerance));
|
|
380
345
|
}
|
|
381
346
|
}
|
|
382
347
|
finally {
|
|
383
348
|
parts.forEach(release);
|
|
384
349
|
}
|
|
385
350
|
}
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
351
|
+
trimmed(solid, tool) {
|
|
352
|
+
const [nx, ny, nz] = tool.normal;
|
|
353
|
+
const length = Math.hypot(nx, ny, nz);
|
|
354
|
+
const offset = (nx * tool.origin[0] + ny * tool.origin[1] + nz * tool.origin[2]) / length;
|
|
355
|
+
return solid.trimByPlane([-nx / length, -ny / length, -nz / length], -offset);
|
|
356
|
+
}
|
|
357
|
+
cut(solid, toolIndex, outline) {
|
|
394
358
|
const tools = [];
|
|
395
359
|
let reaching;
|
|
396
360
|
try {
|
|
397
|
-
this.reachedParts(toolIndex,
|
|
361
|
+
this.reachedParts(toolIndex, outline, tools);
|
|
398
362
|
reaching = this.wasm.Manifold.union(tools);
|
|
399
363
|
return solid.subtract(reaching);
|
|
400
364
|
}
|
|
@@ -404,18 +368,34 @@ class RecipeExecutor {
|
|
|
404
368
|
}
|
|
405
369
|
}
|
|
406
370
|
difference(node) {
|
|
407
|
-
let
|
|
371
|
+
let outline;
|
|
408
372
|
let current;
|
|
409
|
-
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
373
|
+
try {
|
|
374
|
+
for (const toolIndex of node.tools) {
|
|
375
|
+
const previous = current;
|
|
376
|
+
const solid = previous !== null && previous !== void 0 ? previous : this.solid(node.of);
|
|
377
|
+
const tool = this.built[toolIndex];
|
|
378
|
+
try {
|
|
379
|
+
if (isHalfSpace(tool)) {
|
|
380
|
+
current = this.trimmed(solid, tool);
|
|
381
|
+
if (outline) {
|
|
382
|
+
releaseOutline(outline);
|
|
383
|
+
}
|
|
384
|
+
outline = undefined;
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
outline !== null && outline !== void 0 ? outline : (outline = outlineOf(solid));
|
|
388
|
+
current = this.cut(solid, toolIndex, outline);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
finally {
|
|
392
|
+
release(previous);
|
|
393
|
+
}
|
|
416
394
|
}
|
|
417
|
-
|
|
418
|
-
|
|
395
|
+
}
|
|
396
|
+
finally {
|
|
397
|
+
if (outline) {
|
|
398
|
+
releaseOutline(outline);
|
|
419
399
|
}
|
|
420
400
|
}
|
|
421
401
|
return current;
|
|
@@ -426,12 +406,12 @@ class RecipeExecutor {
|
|
|
426
406
|
if (built.length === 0) {
|
|
427
407
|
return host.translate([0, 0, 0]);
|
|
428
408
|
}
|
|
429
|
-
const
|
|
409
|
+
const outline = outlineOf(host);
|
|
430
410
|
const tools = [];
|
|
431
411
|
let openings;
|
|
432
412
|
try {
|
|
433
413
|
for (const opening of built) {
|
|
434
|
-
this.reachedParts(opening,
|
|
414
|
+
this.reachedParts(opening, outline, tools);
|
|
435
415
|
}
|
|
436
416
|
openings = this.wasm.Manifold.union(tools);
|
|
437
417
|
return host.subtract(openings);
|
|
@@ -439,6 +419,7 @@ class RecipeExecutor {
|
|
|
439
419
|
finally {
|
|
440
420
|
tools.forEach(release);
|
|
441
421
|
release(openings);
|
|
422
|
+
releaseOutline(outline);
|
|
442
423
|
}
|
|
443
424
|
}
|
|
444
425
|
triangles(node, index) {
|
|
@@ -454,9 +435,9 @@ class RecipeExecutor {
|
|
|
454
435
|
}
|
|
455
436
|
}
|
|
456
437
|
}
|
|
457
|
-
export function executeRecipe(wasm, recipe, circularSegments,
|
|
458
|
-
return new RecipeExecutor(wasm, recipe, circularSegments,
|
|
438
|
+
export function executeRecipe(wasm, recipe, circularSegments, placing, emptyWhenFailed) {
|
|
439
|
+
return new RecipeExecutor(wasm, recipe, circularSegments, placing, emptyWhenFailed).run();
|
|
459
440
|
}
|
|
460
441
|
export function executeRecipeNodes(wasm, recipe, circularSegments, emptyWhenFailed, nodes) {
|
|
461
|
-
return new RecipeExecutor(wasm, recipe, circularSegments,
|
|
442
|
+
return new RecipeExecutor(wasm, recipe, circularSegments, asTheRecipeSays, emptyWhenFailed).solidsOf(nodes);
|
|
462
443
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type * as Manifold3D from "manifold-3d";
|
|
2
2
|
import type { Base } from "@bitbybit-dev/base";
|
|
3
|
-
import
|
|
3
|
+
import { Inputs as BaseInputs } from "@bitbybit-dev/base";
|
|
4
|
+
import { Recipes } from "@bitbybit-dev/base";
|
|
4
5
|
import type * as Inputs from "../../inputs";
|
|
5
6
|
import type * as Resolved from "../../resolved-inputs";
|
|
6
|
-
export declare function recipeMeshes(wasm: Manifold3D.ManifoldToplevel, recipes: Recipes, recipe: Base.Recipe, options: Omit<Resolved.Manifold.BuildRecipeMeshesDto, "recipe"
|
|
7
|
+
export declare function recipeMeshes(wasm: Manifold3D.ManifoldToplevel, recipes: Recipes, recipe: Base.Recipe, options: Omit<Resolved.Manifold.BuildRecipeMeshesDto, "recipe">, coordinateSystem?: BaseInputs.Base.coordinateSystemEnum): Inputs.Manifold.RecipeMeshesDto;
|
|
@@ -1,25 +1,40 @@
|
|
|
1
|
+
import { Inputs as BaseInputs } from "@bitbybit-dev/base";
|
|
2
|
+
import { Recipes } from "@bitbybit-dev/base";
|
|
1
3
|
import { creasedMeshData, positionsOf } from "../mesh-data";
|
|
2
|
-
import { executeRecipeNodes
|
|
4
|
+
import { executeRecipeNodes } from "./recipe-executor";
|
|
5
|
+
import { mirrorIntoModel, placedAmongMirrored, turnedFromZUp, turnedZtoY } from "./recipe-placing";
|
|
3
6
|
const IDENTITY = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
4
7
|
const NO_MESH = -1;
|
|
5
|
-
function placedBy(matrix,
|
|
6
|
-
return
|
|
8
|
+
function placedBy(matrix, zUp) {
|
|
9
|
+
return zUp ? turnedZtoY(matrix) : [...matrix];
|
|
7
10
|
}
|
|
8
|
-
function meshOf(solid, minSharpAngle) {
|
|
11
|
+
function meshOf(solid, minSharpAngle, mirror) {
|
|
9
12
|
if (solid.isEmpty()) {
|
|
10
13
|
return undefined;
|
|
11
14
|
}
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
if (mirror === undefined) {
|
|
16
|
+
const plain = solid.getMesh();
|
|
17
|
+
return creasedMeshData(positionsOf(plain), plain.triVerts, minSharpAngle);
|
|
18
|
+
}
|
|
19
|
+
const mirrored = solid.transform(mirror);
|
|
20
|
+
try {
|
|
21
|
+
const plain = mirrored.getMesh();
|
|
22
|
+
return creasedMeshData(positionsOf(plain), plain.triVerts, minSharpAngle);
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
mirrored.delete();
|
|
26
|
+
}
|
|
14
27
|
}
|
|
15
|
-
export function recipeMeshes(wasm, recipes, recipe, options) {
|
|
28
|
+
export function recipeMeshes(wasm, recipes, recipe, options, coordinateSystem) {
|
|
29
|
+
const zUp = turnedFromZUp(options.upAxis);
|
|
30
|
+
const mirror = mirrorIntoModel(coordinateSystem, zUp);
|
|
16
31
|
const sources = recipe.roots.map((root) => recipes.sourceOf({ recipe, node: root.node, matrix: root.matrix }));
|
|
17
32
|
const solids = executeRecipeNodes(wasm, recipe, options.circularSegments, options.emptyWhenFailed, [...new Set(sources.map((source) => source.node))]);
|
|
18
33
|
const meshes = [];
|
|
19
34
|
const meshOfNode = new Map();
|
|
20
35
|
try {
|
|
21
36
|
solids.forEach((solid, node) => {
|
|
22
|
-
const mesh = solid === undefined ? undefined : meshOf(solid, options.minSharpAngle);
|
|
37
|
+
const mesh = solid === undefined ? undefined : meshOf(solid, options.minSharpAngle, mirror);
|
|
23
38
|
if (mesh !== undefined) {
|
|
24
39
|
meshOfNode.set(node, meshes.push(mesh) - 1);
|
|
25
40
|
}
|
|
@@ -30,16 +45,17 @@ export function recipeMeshes(wasm, recipes, recipe, options) {
|
|
|
30
45
|
}
|
|
31
46
|
const placements = recipe.roots.map((root, index) => {
|
|
32
47
|
var _a;
|
|
33
|
-
return (Object.assign({ mesh: (_a = meshOfNode.get(sources[index].node)) !== null && _a !== void 0 ? _a : NO_MESH, matrix: placedBy(sources[index].matrix,
|
|
48
|
+
return (Object.assign({ mesh: (_a = meshOfNode.get(sources[index].node)) !== null && _a !== void 0 ? _a : NO_MESH, matrix: mirror === undefined ? placedBy(sources[index].matrix, zUp) : placedAmongMirrored(sources[index].matrix, mirror), tag: root.tag }, (root.group === undefined ? {} : { group: root.group })));
|
|
34
49
|
});
|
|
35
50
|
const failed = sources.flatMap((source, index) => solids.get(source.node) === undefined ? [index] : []);
|
|
36
|
-
|
|
51
|
+
const surfaces = new Recipes(() => (mirror === undefined || coordinateSystem === undefined ? {} : { coordinateSystem }));
|
|
52
|
+
surfaces.surfaceMeshes({ recipe, roots: failed, upAxis: mirror !== undefined && zUp ? BaseInputs.Base.upAxisConversionEnum.zUpToYUp : BaseInputs.Base.upAxisConversionEnum.keep }).forEach((surface, at) => {
|
|
37
53
|
if (surface === undefined) {
|
|
38
54
|
return;
|
|
39
55
|
}
|
|
40
56
|
const placement = placements[failed[at]];
|
|
41
57
|
placement.mesh = meshes.push(creasedMeshData(surface.positions, surface.indices, options.minSharpAngle)) - 1;
|
|
42
|
-
placement.matrix = placedBy(IDENTITY,
|
|
58
|
+
placement.matrix = mirror === undefined ? placedBy(IDENTITY, zUp) : [...IDENTITY];
|
|
43
59
|
});
|
|
44
60
|
return { meshes, placements };
|
|
45
61
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type * as Manifold3D from "manifold-3d";
|
|
2
|
+
import { Inputs as BaseInputs } from "@bitbybit-dev/base";
|
|
3
|
+
import type { Base } from "@bitbybit-dev/base";
|
|
4
|
+
export type RootPlacing = (matrix: Base.TransformMatrix) => Manifold3D.Mat4;
|
|
5
|
+
export declare const asTheRecipeSays: RootPlacing;
|
|
6
|
+
export declare function turnedFromZUp(upAxis: unknown): boolean;
|
|
7
|
+
export declare function turnedZtoY(matrix: Base.TransformMatrix): Manifold3D.Mat4;
|
|
8
|
+
export declare function mirrorIntoModel(coordinateSystem: BaseInputs.Base.coordinateSystemEnum | undefined, zUp: boolean): Base.TransformMatrix | undefined;
|
|
9
|
+
export declare function rootPlacingOf(coordinateSystem: BaseInputs.Base.coordinateSystemEnum | undefined, zUp: boolean): RootPlacing;
|
|
10
|
+
export declare function placedAmongMirrored(matrix: Base.TransformMatrix, mirror: Base.TransformMatrix): Base.TransformMatrix;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { checkedUpAxis, Inputs as BaseInputs } from "@bitbybit-dev/base";
|
|
2
|
+
import { followedBy } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/matrices";
|
|
3
|
+
import { meshMatrixInModel } from "@bitbybit-dev/base/lib/api/services/helpers/files/mesh-file-axes";
|
|
4
|
+
export const asTheRecipeSays = (matrix) => matrix;
|
|
5
|
+
export function turnedFromZUp(upAxis) {
|
|
6
|
+
const { keep, zUpToYUp } = BaseInputs.Base.upAxisConversionEnum;
|
|
7
|
+
return checkedUpAxis(upAxis, [keep, zUpToYUp]) === zUpToYUp;
|
|
8
|
+
}
|
|
9
|
+
function withoutNegativeZero(matrix) {
|
|
10
|
+
return matrix.map((value) => value + 0);
|
|
11
|
+
}
|
|
12
|
+
function negatedWithoutNegativeZero(value) {
|
|
13
|
+
return 0 - value;
|
|
14
|
+
}
|
|
15
|
+
export function turnedZtoY(matrix) {
|
|
16
|
+
const [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p] = matrix;
|
|
17
|
+
return [
|
|
18
|
+
a, c, negatedWithoutNegativeZero(b), d,
|
|
19
|
+
e, g, negatedWithoutNegativeZero(f), h,
|
|
20
|
+
i, k, negatedWithoutNegativeZero(j), l,
|
|
21
|
+
m, o, negatedWithoutNegativeZero(n), p,
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
export function mirrorIntoModel(coordinateSystem, zUp) {
|
|
25
|
+
return coordinateSystem === BaseInputs.Base.coordinateSystemEnum.leftHanded ? meshMatrixInModel(coordinateSystem, zUp) : undefined;
|
|
26
|
+
}
|
|
27
|
+
export function rootPlacingOf(coordinateSystem, zUp) {
|
|
28
|
+
const mirror = mirrorIntoModel(coordinateSystem, zUp);
|
|
29
|
+
if (mirror !== undefined) {
|
|
30
|
+
return (matrix) => withoutNegativeZero(followedBy(matrix, mirror));
|
|
31
|
+
}
|
|
32
|
+
return zUp ? turnedZtoY : asTheRecipeSays;
|
|
33
|
+
}
|
|
34
|
+
export function placedAmongMirrored(matrix, mirror) {
|
|
35
|
+
return withoutNegativeZero(followedBy(followedBy(mirror, matrix), mirror));
|
|
36
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type * as Manifold3D from "manifold-3d";
|
|
2
|
+
import type { CutOutline } from "./recipe-types";
|
|
3
|
+
export declare function outlineOf(solid: Manifold3D.Manifold): CutOutline;
|
|
4
|
+
export declare function releaseOutline(outline: CutOutline): void;
|
|
5
|
+
export declare function reachedThrough(tool: Manifold3D.Manifold, outline: CutOutline, reach: number): Manifold3D.Manifold;
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { add3, between3, cross2, cross3, distance2, dot3, length2, length3, scale3, subtract2, subtract3 } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/vectors";
|
|
2
|
+
import { axesAlong, axesToMatrix, pointToLocal, vectorToLocal } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/frame-axes";
|
|
3
|
+
import { rigidInverse } from "@bitbybit-dev/base/lib/api/services/helpers/geometry/matrices";
|
|
4
|
+
const AXES = 3;
|
|
5
|
+
const TRIANGLE_CORNERS = 3;
|
|
6
|
+
const BOX_VALUES = 2 * AXES;
|
|
7
|
+
const MIDDLE = 0.5;
|
|
8
|
+
const SAME_DIRECTION = 0.999999;
|
|
9
|
+
const ONE_PLANE = 0.999999999999;
|
|
10
|
+
const FARTHEST_SLIDE = 2;
|
|
11
|
+
const BEYOND = 1.001;
|
|
12
|
+
const FILLED = 0.999999999999;
|
|
13
|
+
const INDEXED_FROM = 256;
|
|
14
|
+
const SLICES_ALONG = 32;
|
|
15
|
+
const NOTHING_INDEXED = { axis: 0, sorted: new Uint32Array(0), least: new Float64Array(0), widest: 0, big: new Uint32Array(0) };
|
|
16
|
+
const ORIGIN = [0, 0, 0];
|
|
17
|
+
function pointAt(mesh, vert) {
|
|
18
|
+
const { numProp, vertProperties } = mesh;
|
|
19
|
+
return [vertProperties[vert * numProp], vertProperties[vert * numProp + 1], vertProperties[vert * numProp + 2]];
|
|
20
|
+
}
|
|
21
|
+
function pointsOf(mesh) {
|
|
22
|
+
return Array.from({ length: mesh.numVert }, (_, vert) => pointAt(mesh, vert));
|
|
23
|
+
}
|
|
24
|
+
function centredMesh(solid, centre) {
|
|
25
|
+
const centred = solid.translate(scale3(centre, -1));
|
|
26
|
+
try {
|
|
27
|
+
return centred.getMesh();
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
centred.delete();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function faceOf(mesh, tri) {
|
|
34
|
+
const corners = cornersOf(mesh.triVerts, tri).map((vert) => pointAt(mesh, vert));
|
|
35
|
+
const [a, b, c] = corners;
|
|
36
|
+
const spanned = cross3(subtract3(b, a), subtract3(c, a));
|
|
37
|
+
const twiceArea = length3(spanned);
|
|
38
|
+
if (!(twiceArea > 0)) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const normal = scale3(spanned, 1 / twiceArea);
|
|
42
|
+
return { normal, offset: dot3(normal, a), corners };
|
|
43
|
+
}
|
|
44
|
+
function fillsItsBox(solid, box) {
|
|
45
|
+
const size = subtract3(box.max, box.min);
|
|
46
|
+
return solid.volume() >= FILLED * size[0] * size[1] * size[2];
|
|
47
|
+
}
|
|
48
|
+
export function outlineOf(solid) {
|
|
49
|
+
const box = solid.boundingBox();
|
|
50
|
+
if (solid.isEmpty() || fillsItsBox(solid, box)) {
|
|
51
|
+
return { solid: undefined, box, centre: ORIGIN, mesh: undefined, boxes: new Float64Array(0), index: NOTHING_INDEXED };
|
|
52
|
+
}
|
|
53
|
+
const centre = between3(box.min, box.max, MIDDLE);
|
|
54
|
+
const mesh = centredMesh(solid, centre);
|
|
55
|
+
const { numProp, triVerts, vertProperties } = mesh;
|
|
56
|
+
const boxes = new Float64Array(mesh.numTri * BOX_VALUES);
|
|
57
|
+
for (let tri = 0; tri < mesh.numTri; tri++) {
|
|
58
|
+
for (let axis = 0; axis < AXES; axis++) {
|
|
59
|
+
let least = Infinity;
|
|
60
|
+
let most = -Infinity;
|
|
61
|
+
for (let corner = 0; corner < TRIANGLE_CORNERS; corner++) {
|
|
62
|
+
const value = vertProperties[triVerts[tri * TRIANGLE_CORNERS + corner] * numProp + axis];
|
|
63
|
+
least = Math.min(least, value);
|
|
64
|
+
most = Math.max(most, value);
|
|
65
|
+
}
|
|
66
|
+
boxes[tri * BOX_VALUES + axis] = least;
|
|
67
|
+
boxes[tri * BOX_VALUES + AXES + axis] = most;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { solid: solid.translate(ORIGIN), box, centre, mesh, boxes, index: indexedTriangles(boxes, mesh.numTri, box) };
|
|
71
|
+
}
|
|
72
|
+
function indexedTriangles(boxes, count, box) {
|
|
73
|
+
const size = subtract3(box.max, box.min);
|
|
74
|
+
const axis = size.indexOf(Math.max(...size));
|
|
75
|
+
const least = (tri) => boxes[tri * BOX_VALUES + axis];
|
|
76
|
+
const extent = (tri) => boxes[tri * BOX_VALUES + AXES + axis] - least(tri);
|
|
77
|
+
const all = Array.from({ length: count }, (_, tri) => tri);
|
|
78
|
+
const slice = count >= INDEXED_FROM ? size[axis] / SLICES_ALONG : -1;
|
|
79
|
+
const sorted = all.filter((tri) => extent(tri) <= slice).sort((first, second) => least(first) - least(second));
|
|
80
|
+
return {
|
|
81
|
+
axis,
|
|
82
|
+
sorted: Uint32Array.from(sorted),
|
|
83
|
+
least: Float64Array.from(sorted, least),
|
|
84
|
+
widest: sorted.reduce((widest, tri) => Math.max(widest, extent(tri)), 0),
|
|
85
|
+
big: Uint32Array.from(all.filter((tri) => !(extent(tri) <= slice))),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function countBelow(ascending, value, orEqual) {
|
|
89
|
+
let low = 0;
|
|
90
|
+
let high = ascending.length;
|
|
91
|
+
while (low < high) {
|
|
92
|
+
const middle = (low + high) >>> 1;
|
|
93
|
+
const before = orEqual ? ascending[middle] <= value : ascending[middle] < value;
|
|
94
|
+
if (before) {
|
|
95
|
+
low = middle + 1;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
high = middle;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return low;
|
|
102
|
+
}
|
|
103
|
+
function nearFaces(outline, low, high, margin) {
|
|
104
|
+
const { mesh, boxes, index } = outline;
|
|
105
|
+
const faces = [];
|
|
106
|
+
if (mesh === undefined) {
|
|
107
|
+
return faces;
|
|
108
|
+
}
|
|
109
|
+
const consider = (tri) => {
|
|
110
|
+
let meets = true;
|
|
111
|
+
for (let axis = 0; axis < AXES && meets; axis++) {
|
|
112
|
+
meets = boxes[tri * BOX_VALUES + axis] <= high[axis] + margin && low[axis] <= boxes[tri * BOX_VALUES + AXES + axis] + margin;
|
|
113
|
+
}
|
|
114
|
+
const face = meets ? faceOf(mesh, tri) : undefined;
|
|
115
|
+
if (face) {
|
|
116
|
+
faces.push(face);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const from = countBelow(index.least, low[index.axis] - margin - index.widest, false);
|
|
120
|
+
const to = countBelow(index.least, high[index.axis] + margin, true);
|
|
121
|
+
for (let at = from; at < to; at++) {
|
|
122
|
+
consider(index.sorted[at]);
|
|
123
|
+
}
|
|
124
|
+
index.big.forEach(consider);
|
|
125
|
+
return faces;
|
|
126
|
+
}
|
|
127
|
+
function axisDirection(axis, sign) {
|
|
128
|
+
return Array.from({ length: AXES }, (_, at) => (at === axis ? sign : 0));
|
|
129
|
+
}
|
|
130
|
+
function boxReach(ofTool, outside, reach) {
|
|
131
|
+
return {
|
|
132
|
+
below: ofTool.min.map((side, axis) => Math.abs(side - outside.min[axis]) <= reach),
|
|
133
|
+
above: ofTool.max.map((side, axis) => Math.abs(side - outside.max[axis]) <= reach),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function boxShift(vertex, ofTool, sides, reach) {
|
|
137
|
+
return vertex.map((drawn, axis) => {
|
|
138
|
+
const fromBelow = drawn - ofTool.min[axis];
|
|
139
|
+
const fromAbove = ofTool.max[axis] - drawn;
|
|
140
|
+
const down = sides.below[axis] && fromBelow <= reach;
|
|
141
|
+
const up = sides.above[axis] && fromAbove <= reach;
|
|
142
|
+
if (down && (!up || fromBelow <= fromAbove)) {
|
|
143
|
+
return -reach;
|
|
144
|
+
}
|
|
145
|
+
return up ? reach : 0;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function boxReached(tool, ofTool, sides, reach) {
|
|
149
|
+
if (!sides.below.includes(true) && !sides.above.includes(true)) {
|
|
150
|
+
return tool.translate([0, 0, 0]);
|
|
151
|
+
}
|
|
152
|
+
return tool.warp((vertex) => {
|
|
153
|
+
const shift = boxShift(vertex, ofTool, sides, reach);
|
|
154
|
+
for (let axis = 0; axis < AXES; axis++) {
|
|
155
|
+
vertex[axis] = vertex[axis] + shift[axis];
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function reachedBoxSides(outline, sides) {
|
|
160
|
+
const { box, centre } = outline;
|
|
161
|
+
const planes = [];
|
|
162
|
+
for (let axis = 0; axis < AXES; axis++) {
|
|
163
|
+
if (sides.below[axis]) {
|
|
164
|
+
planes.push({ normal: axisDirection(axis, -1), offset: centre[axis] - box.min[axis] });
|
|
165
|
+
}
|
|
166
|
+
if (sides.above[axis]) {
|
|
167
|
+
planes.push({ normal: axisDirection(axis, 1), offset: box.max[axis] - centre[axis] });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return planes;
|
|
171
|
+
}
|
|
172
|
+
function hostFacesNear(outline, ofTool, sides, reach) {
|
|
173
|
+
const { centre } = outline;
|
|
174
|
+
const onReachedSides = reachedBoxSides(outline, sides);
|
|
175
|
+
return nearFaces(outline, subtract3(ofTool.min, centre), subtract3(ofTool.max, centre), reach).filter((face) => !onReachedSides.some((side) => dot3(side.normal, face.normal) >= SAME_DIRECTION && Math.abs(side.offset - face.offset) <= reach));
|
|
176
|
+
}
|
|
177
|
+
function cornersOf(triVerts, tri) {
|
|
178
|
+
return [triVerts[tri * TRIANGLE_CORNERS], triVerts[tri * TRIANGLE_CORNERS + 1], triVerts[tri * TRIANGLE_CORNERS + 2]];
|
|
179
|
+
}
|
|
180
|
+
function regionsOf(triVerts, points) {
|
|
181
|
+
const count = triVerts.length / TRIANGLE_CORNERS;
|
|
182
|
+
const spans = Array.from({ length: count }, (_, tri) => {
|
|
183
|
+
const [a, b, c] = cornersOf(triVerts, tri).map((vert) => points[vert]);
|
|
184
|
+
return cross3(subtract3(b, a), subtract3(c, a));
|
|
185
|
+
});
|
|
186
|
+
const across = new Map();
|
|
187
|
+
for (let tri = 0; tri < count; tri++) {
|
|
188
|
+
const corners = cornersOf(triVerts, tri);
|
|
189
|
+
corners.forEach((from, at) => across.set(from * points.length + corners[(at + 1) % TRIANGLE_CORNERS], tri));
|
|
190
|
+
}
|
|
191
|
+
const regionOf = new Int32Array(count).fill(-1);
|
|
192
|
+
const regions = [];
|
|
193
|
+
for (let seed = 0; seed < count; seed++) {
|
|
194
|
+
if (regionOf[seed] >= 0) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const seedNormal = scale3(spans[seed], 1 / length3(spans[seed]));
|
|
198
|
+
const triangles = [seed];
|
|
199
|
+
regionOf[seed] = regions.length;
|
|
200
|
+
let spanned = spans[seed];
|
|
201
|
+
for (let next = 0; next < triangles.length; next++) {
|
|
202
|
+
const corners = cornersOf(triVerts, triangles[next]);
|
|
203
|
+
corners.forEach((from, at) => {
|
|
204
|
+
const other = across.get(corners[(at + 1) % TRIANGLE_CORNERS] * points.length + from);
|
|
205
|
+
if (other !== undefined && regionOf[other] < 0 && dot3(spans[other], seedNormal) >= ONE_PLANE * length3(spans[other])) {
|
|
206
|
+
regionOf[other] = regions.length;
|
|
207
|
+
triangles.push(other);
|
|
208
|
+
spanned = add3(spanned, spans[other]);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
const normal = scale3(spanned, 1 / length3(spanned));
|
|
213
|
+
regions.push({ normal, offset: dot3(normal, points[triVerts[seed * TRIANGLE_CORNERS]]), triangles });
|
|
214
|
+
}
|
|
215
|
+
return { regions, regionOf };
|
|
216
|
+
}
|
|
217
|
+
function farthestFrom(points, from) {
|
|
218
|
+
return points.reduce((farthest, point) => (distance2(point, from) > distance2(farthest, from) ? point : farthest), from);
|
|
219
|
+
}
|
|
220
|
+
function farthestPair(points) {
|
|
221
|
+
const start = farthestFrom(points, points[0]);
|
|
222
|
+
return [start, farthestFrom(points, start)];
|
|
223
|
+
}
|
|
224
|
+
function spansArea(points, reach) {
|
|
225
|
+
const [start, end] = farthestPair(points);
|
|
226
|
+
const across = subtract2(end, start);
|
|
227
|
+
const wide = reach * length2(across);
|
|
228
|
+
return points.some((point) => Math.abs(cross2(across, subtract2(point, start))) > wide);
|
|
229
|
+
}
|
|
230
|
+
function withinTriangle(point, corners, reach) {
|
|
231
|
+
const turn = Math.sign(cross2(subtract2(corners[1], corners[0]), subtract2(corners[2], corners[0])));
|
|
232
|
+
return corners.every((from, at) => {
|
|
233
|
+
const edge = subtract2(corners[(at + 1) % corners.length], from);
|
|
234
|
+
return (turn * cross2(edge, subtract2(point, from))) / length2(edge) >= -reach;
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function insidePoints(region, triVerts, points) {
|
|
238
|
+
return region.triangles.flatMap((tri) => {
|
|
239
|
+
const [a, b, c] = cornersOf(triVerts, tri).map((vert) => points[vert]);
|
|
240
|
+
const middleOfAb = between3(a, b, MIDDLE);
|
|
241
|
+
return [middleOfAb, between3(b, c, MIDDLE), between3(c, a, MIDDLE), between3(middleOfAb, c, MIDDLE)];
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function clearBeyond(region, triVerts, points, outline, allowance, reach) {
|
|
245
|
+
const axes = axesAlong(add3(outline.centre, scale3(region.normal, region.offset)), region.normal);
|
|
246
|
+
const footprint = region.triangles.map((tri) => cornersOf(triVerts, tri).map((vert) => {
|
|
247
|
+
const [across, along] = pointToLocal(axes, add3(points[vert], outline.centre));
|
|
248
|
+
return [across, along];
|
|
249
|
+
}));
|
|
250
|
+
const inFrame = outline.solid.transform(rigidInverse(axesToMatrix(axes)));
|
|
251
|
+
let section;
|
|
252
|
+
let overlap;
|
|
253
|
+
try {
|
|
254
|
+
section = inFrame.slice(BEYOND * reach);
|
|
255
|
+
overlap = section.intersect(footprint);
|
|
256
|
+
return overlap.area() <= allowance;
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
inFrame.delete();
|
|
260
|
+
section === null || section === void 0 ? void 0 : section.delete();
|
|
261
|
+
overlap === null || overlap === void 0 ? void 0 : overlap.delete();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
export function releaseOutline(outline) {
|
|
265
|
+
var _a;
|
|
266
|
+
(_a = outline.solid) === null || _a === void 0 ? void 0 : _a.delete();
|
|
267
|
+
}
|
|
268
|
+
function liesOnHost(region, triVerts, points, faces, outline, reach) {
|
|
269
|
+
const corners = [...new Set(region.triangles.flatMap((tri) => cornersOf(triVerts, tri)))].map((vert) => points[vert]);
|
|
270
|
+
const beneath = faces.filter((face) => dot3(face.normal, region.normal) >= SAME_DIRECTION && corners.every((corner) => Math.abs(dot3(face.normal, corner) - face.offset) <= reach));
|
|
271
|
+
if (beneath.length === 0) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
const axes = axesAlong(ORIGIN, region.normal);
|
|
275
|
+
const inPlane = (point) => {
|
|
276
|
+
const [across, along] = vectorToLocal(axes, point);
|
|
277
|
+
return [across, along];
|
|
278
|
+
};
|
|
279
|
+
const projected = corners.map(inPlane);
|
|
280
|
+
if (!spansArea(projected, reach)) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
const covering = beneath.map((face) => face.corners.map(inPlane));
|
|
284
|
+
const covered = [...projected, ...insidePoints(region, triVerts, points).map(inPlane)].every((point) => covering.some((triangle) => withinTriangle(point, triangle, reach)));
|
|
285
|
+
const [start, end] = farthestPair(projected);
|
|
286
|
+
return covered && clearBeyond(region, triVerts, points, outline, reach * distance2(start, end), reach);
|
|
287
|
+
}
|
|
288
|
+
function pushOf(plane, reach) {
|
|
289
|
+
return plane.pushed ? reach : 0;
|
|
290
|
+
}
|
|
291
|
+
function meetingMove(planes, reach) {
|
|
292
|
+
var _a;
|
|
293
|
+
const [first, second, third] = planes;
|
|
294
|
+
if (second === undefined) {
|
|
295
|
+
return scale3(first.normal, pushOf(first, reach));
|
|
296
|
+
}
|
|
297
|
+
const thirdNormal = (_a = third === null || third === void 0 ? void 0 : third.normal) !== null && _a !== void 0 ? _a : cross3(first.normal, second.normal);
|
|
298
|
+
const thirdPush = third === undefined ? 0 : pushOf(third, reach);
|
|
299
|
+
const crossOfFirst = cross3(second.normal, thirdNormal);
|
|
300
|
+
const crossOfSecond = cross3(thirdNormal, first.normal);
|
|
301
|
+
const crossOfThird = cross3(first.normal, second.normal);
|
|
302
|
+
const summed = add3(add3(scale3(crossOfFirst, pushOf(first, reach)), scale3(crossOfSecond, pushOf(second, reach))), scale3(crossOfThird, thirdPush));
|
|
303
|
+
return scale3(summed, 1 / dot3(first.normal, crossOfFirst));
|
|
304
|
+
}
|
|
305
|
+
function cornerMove(planes, reach) {
|
|
306
|
+
if (planes.length > AXES) {
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
const move = meetingMove(planes, reach);
|
|
310
|
+
return length3(move) <= FARTHEST_SLIDE * reach ? move : undefined;
|
|
311
|
+
}
|
|
312
|
+
function distinctRegions(at, normals, pushed) {
|
|
313
|
+
const distinct = [];
|
|
314
|
+
for (const region of at) {
|
|
315
|
+
const same = distinct.find((other) => dot3(normals[other], normals[region]) >= SAME_DIRECTION);
|
|
316
|
+
if (same === undefined) {
|
|
317
|
+
distinct.push(region);
|
|
318
|
+
}
|
|
319
|
+
else if (pushed[same] !== pushed[region]) {
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return distinct;
|
|
324
|
+
}
|
|
325
|
+
function planesOf(regions, normals, pushed) {
|
|
326
|
+
return regions.map((region) => ({ normal: normals[region], pushed: pushed[region] }));
|
|
327
|
+
}
|
|
328
|
+
function cornerPlanes(atCorner, normals, pushed, reach) {
|
|
329
|
+
return atCorner.map((at) => {
|
|
330
|
+
const distinct = distinctRegions(at, normals, pushed);
|
|
331
|
+
if (distinct === undefined) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
if (!distinct.some((region) => pushed[region])) {
|
|
335
|
+
return [];
|
|
336
|
+
}
|
|
337
|
+
return cornerMove(planesOf(distinct, normals, pushed), reach) === undefined ? undefined : distinct;
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
function hasFlushTriangle(triVerts, points, faces, reach) {
|
|
341
|
+
for (let tri = 0; tri < triVerts.length / TRIANGLE_CORNERS; tri++) {
|
|
342
|
+
const [a, b, c] = cornersOf(triVerts, tri).map((vert) => points[vert]);
|
|
343
|
+
const spanned = cross3(subtract3(b, a), subtract3(c, a));
|
|
344
|
+
const twiceArea = length3(spanned);
|
|
345
|
+
if (faces.some((face) => dot3(face.normal, spanned) >= SAME_DIRECTION * twiceArea && Math.abs(dot3(face.normal, a) - face.offset) <= reach)) {
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
function normalsOf(regions, triVerts, points) {
|
|
352
|
+
return regions.map((region) => {
|
|
353
|
+
const spanned = region.triangles.reduce((sum, tri) => {
|
|
354
|
+
const [a, b, c] = cornersOf(triVerts, tri).map((vert) => points[vert]);
|
|
355
|
+
return add3(sum, cross3(subtract3(b, a), subtract3(c, a)));
|
|
356
|
+
}, ORIGIN);
|
|
357
|
+
return scale3(spanned, 1 / length3(spanned));
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
function pushedFaces(triVerts, points, faces, outline, reach) {
|
|
361
|
+
const { regions, regionOf } = regionsOf(triVerts, points);
|
|
362
|
+
const pushed = regions.map((region) => liesOnHost(region, triVerts, points, faces, outline, reach));
|
|
363
|
+
if (!pushed.includes(true)) {
|
|
364
|
+
return undefined;
|
|
365
|
+
}
|
|
366
|
+
const atCorner = points.map(() => []);
|
|
367
|
+
regionOf.forEach((region, tri) => {
|
|
368
|
+
for (const corner of cornersOf(triVerts, tri)) {
|
|
369
|
+
if (region >= 0 && !atCorner[corner].includes(region)) {
|
|
370
|
+
atCorner[corner].push(region);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
const normals = regions.map((region) => region.normal);
|
|
375
|
+
let planesAt = cornerPlanes(atCorner, normals, pushed, reach);
|
|
376
|
+
while (planesAt.includes(undefined)) {
|
|
377
|
+
planesAt.forEach((planes, corner) => {
|
|
378
|
+
if (planes === undefined) {
|
|
379
|
+
atCorner[corner].forEach((region) => {
|
|
380
|
+
pushed[region] = false;
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
planesAt = cornerPlanes(atCorner, normals, pushed, reach);
|
|
385
|
+
}
|
|
386
|
+
return pushed.includes(true) ? { regions, planesAt: planesAt, pushed } : undefined;
|
|
387
|
+
}
|
|
388
|
+
export function reachedThrough(tool, outline, reach) {
|
|
389
|
+
const ofTool = tool.boundingBox();
|
|
390
|
+
const sides = boxReach(ofTool, outline.box, reach);
|
|
391
|
+
const faces = hostFacesNear(outline, ofTool, sides, reach);
|
|
392
|
+
if (faces.length === 0) {
|
|
393
|
+
return boxReached(tool, ofTool, sides, reach);
|
|
394
|
+
}
|
|
395
|
+
const mesh = centredMesh(tool, outline.centre);
|
|
396
|
+
const points = pointsOf(mesh);
|
|
397
|
+
const reached = hasFlushTriangle(mesh.triVerts, points, faces, reach) ? pushedFaces(mesh.triVerts, points, faces, outline, reach) : undefined;
|
|
398
|
+
if (reached === undefined) {
|
|
399
|
+
return boxReached(tool, ofTool, sides, reach);
|
|
400
|
+
}
|
|
401
|
+
return tool.warpBatch((verts, count) => {
|
|
402
|
+
const drawn = Array.from({ length: count }, (_, vert) => [verts[vert * AXES], verts[vert * AXES + 1], verts[vert * AXES + 2]]);
|
|
403
|
+
const centred = drawn.map((point) => subtract3(point, outline.centre));
|
|
404
|
+
const normals = normalsOf(reached.regions, mesh.triVerts, centred);
|
|
405
|
+
drawn.forEach((point, vert) => {
|
|
406
|
+
const planes = reached.planesAt[vert];
|
|
407
|
+
const move = planes.length === 0 ? ORIGIN : meetingMove(planesOf(planes, normals, reached.pushed), reach);
|
|
408
|
+
const shift = add3(move, boxShift(point, ofTool, sides, reach));
|
|
409
|
+
for (let axis = 0; axis < AXES; axis++) {
|
|
410
|
+
verts[vert * AXES + axis] = point[axis] + shift[axis];
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
}
|
|
@@ -2,3 +2,45 @@ import type * as Manifold3D from "manifold-3d";
|
|
|
2
2
|
import type { Base } from "@bitbybit-dev/base";
|
|
3
3
|
export type Built = Manifold3D.Manifold | Manifold3D.CrossSection | Base.RecipeHalfSpaceNode;
|
|
4
4
|
export type ProfileRings = readonly (readonly Manifold3D.Vec2[])[];
|
|
5
|
+
export interface FacePlane {
|
|
6
|
+
readonly normal: Manifold3D.Vec3;
|
|
7
|
+
readonly offset: number;
|
|
8
|
+
}
|
|
9
|
+
export interface OutlineFace extends FacePlane {
|
|
10
|
+
readonly corners: readonly Manifold3D.Vec3[];
|
|
11
|
+
}
|
|
12
|
+
export interface TriangleIndex {
|
|
13
|
+
readonly axis: number;
|
|
14
|
+
readonly sorted: Uint32Array;
|
|
15
|
+
readonly least: Float64Array;
|
|
16
|
+
readonly widest: number;
|
|
17
|
+
readonly big: Uint32Array;
|
|
18
|
+
}
|
|
19
|
+
export interface CutOutline {
|
|
20
|
+
readonly solid: Manifold3D.Manifold | undefined;
|
|
21
|
+
readonly box: Manifold3D.Box;
|
|
22
|
+
readonly centre: Manifold3D.Vec3;
|
|
23
|
+
readonly mesh: Manifold3D.Mesh | undefined;
|
|
24
|
+
readonly boxes: Float64Array;
|
|
25
|
+
readonly index: TriangleIndex;
|
|
26
|
+
}
|
|
27
|
+
export interface BoxReach {
|
|
28
|
+
readonly below: readonly boolean[];
|
|
29
|
+
readonly above: readonly boolean[];
|
|
30
|
+
}
|
|
31
|
+
export interface ToolRegion extends FacePlane {
|
|
32
|
+
readonly triangles: readonly number[];
|
|
33
|
+
}
|
|
34
|
+
export interface CornerPlane {
|
|
35
|
+
readonly normal: Manifold3D.Vec3;
|
|
36
|
+
readonly pushed: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface ToolRegions {
|
|
39
|
+
readonly regions: readonly ToolRegion[];
|
|
40
|
+
readonly regionOf: Int32Array;
|
|
41
|
+
}
|
|
42
|
+
export interface ReachedFaces {
|
|
43
|
+
readonly regions: readonly ToolRegion[];
|
|
44
|
+
readonly planesAt: readonly (readonly number[])[];
|
|
45
|
+
readonly pushed: readonly boolean[];
|
|
46
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as Manifold3D from "manifold-3d";
|
|
2
|
-
import type { Recipes } from "@bitbybit-dev/base";
|
|
2
|
+
import type { BitbybitSettings, Recipes } from "@bitbybit-dev/base";
|
|
3
3
|
import * as Inputs from "../../inputs/manifold-inputs";
|
|
4
4
|
/**
|
|
5
5
|
* Building recipes: solids described as data - polygons, circles, extrusions, turns and lofts, cuts,
|
|
@@ -12,14 +12,15 @@ import * as Inputs from "../../inputs/manifold-inputs";
|
|
|
12
12
|
*/
|
|
13
13
|
export declare class ManifoldRecipes {
|
|
14
14
|
private readonly recipes;
|
|
15
|
+
private readonly settings;
|
|
15
16
|
private manifold;
|
|
16
|
-
constructor(wasm: Manifold3D.ManifoldToplevel, recipes: Recipes);
|
|
17
|
+
constructor(wasm: Manifold3D.ManifoldToplevel, recipes: Recipes, settings?: () => BitbybitSettings);
|
|
17
18
|
/**
|
|
18
19
|
* Builds each root of a recipe as a solid placed by its matrix, in root order.
|
|
19
20
|
*
|
|
20
|
-
* Shared nodes are built once. An invalid recipe throws; a root the kernel cannot build
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* Shared nodes are built once. An invalid recipe throws; a root the kernel cannot build throws
|
|
22
|
+
* unless `emptyWhenFailed` is set. A cut ending within `tolerance` of a side of the bounding box,
|
|
23
|
+
* or of a face its end lies wholly on, goes through.
|
|
23
24
|
* @param inputs - The recipe, how finely circles are divided, and whether Z turns into Y
|
|
24
25
|
* @returns One solid per root, in root order
|
|
25
26
|
* @group build
|
|
@@ -28,7 +29,7 @@ export declare class ManifoldRecipes {
|
|
|
28
29
|
* @example
|
|
29
30
|
* ```typescript
|
|
30
31
|
* const recipe = await bitbybit.ifc.geometry.recipe({ model });
|
|
31
|
-
* const solids = await bitbybit.manifold.recipes.build({ recipe,
|
|
32
|
+
* const solids = await bitbybit.manifold.recipes.build({ recipe, upAxis: Bit.Inputs.Base.upAxisConversionEnum.zUpToYUp, emptyWhenFailed: true });
|
|
32
33
|
* ```
|
|
33
34
|
*/
|
|
34
35
|
build(inputs: Inputs.Manifold.BuildRecipeDto): Manifold3D.Manifold[];
|
|
@@ -46,7 +47,7 @@ export declare class ManifoldRecipes {
|
|
|
46
47
|
* @example
|
|
47
48
|
* ```typescript
|
|
48
49
|
* const recipe = await bitbybit.ifc.geometry.recipe({ model });
|
|
49
|
-
* const { meshes, placements } = await bitbybit.manifold.recipes.meshes({ recipe,
|
|
50
|
+
* const { meshes, placements } = await bitbybit.manifold.recipes.meshes({ recipe, upAxis: Bit.Inputs.Base.upAxisConversionEnum.zUpToYUp, emptyWhenFailed: true });
|
|
50
51
|
* ```
|
|
51
52
|
*/
|
|
52
53
|
meshes(inputs: Inputs.Manifold.BuildRecipeMeshesDto): Inputs.Manifold.RecipeMeshesDto;
|
|
@@ -63,10 +64,10 @@ export declare class ManifoldRecipes {
|
|
|
63
64
|
* @drawable true
|
|
64
65
|
* @example
|
|
65
66
|
* ```typescript
|
|
66
|
-
* const solids = await bitbybit.manifold.recipes.build({ recipe,
|
|
67
|
+
* const solids = await bitbybit.manifold.recipes.build({ recipe, upAxis: Bit.Inputs.Base.upAxisConversionEnum.zUpToYUp, emptyWhenFailed: true });
|
|
67
68
|
* const meshes = await bitbybit.manifold.manifold.manifoldsToMeshes({ manifolds: solids });
|
|
68
69
|
* const open = meshes.flatMap((mesh, index) => mesh.triVerts.length === 0 ? [index] : []);
|
|
69
|
-
* const surfaces = await bitbybit.manifold.recipes.surfaceMeshes({ recipe, roots: open,
|
|
70
|
+
* const surfaces = await bitbybit.manifold.recipes.surfaceMeshes({ recipe, roots: open, upAxis: Bit.Inputs.Base.upAxisConversionEnum.zUpToYUp });
|
|
70
71
|
* ```
|
|
71
72
|
*/
|
|
72
73
|
surfaceMeshes(inputs: Inputs.Manifold.RecipeSurfaceMeshesDto): Inputs.Manifold.DecomposedManifoldMeshDto[];
|
|
@@ -2,6 +2,7 @@ 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";
|
|
5
|
+
import { rootPlacingOf, turnedFromZUp } from "./recipe-placing";
|
|
5
6
|
const MIN_CIRCLE_SIDES = 3;
|
|
6
7
|
const MAX_SHARP_ANGLE = 180;
|
|
7
8
|
const POSITION_PROPERTIES = 3;
|
|
@@ -15,16 +16,17 @@ const POSITION_PROPERTIES = 3;
|
|
|
15
16
|
* @beta
|
|
16
17
|
*/
|
|
17
18
|
export class ManifoldRecipes {
|
|
18
|
-
constructor(wasm, recipes) {
|
|
19
|
+
constructor(wasm, recipes, settings = () => ({})) {
|
|
19
20
|
this.recipes = recipes;
|
|
21
|
+
this.settings = settings;
|
|
20
22
|
this.manifold = wasm;
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
25
|
* Builds each root of a recipe as a solid placed by its matrix, in root order.
|
|
24
26
|
*
|
|
25
|
-
* Shared nodes are built once. An invalid recipe throws; a root the kernel cannot build
|
|
26
|
-
*
|
|
27
|
-
*
|
|
27
|
+
* Shared nodes are built once. An invalid recipe throws; a root the kernel cannot build throws
|
|
28
|
+
* unless `emptyWhenFailed` is set. A cut ending within `tolerance` of a side of the bounding box,
|
|
29
|
+
* or of a face its end lies wholly on, goes through.
|
|
28
30
|
* @param inputs - The recipe, how finely circles are divided, and whether Z turns into Y
|
|
29
31
|
* @returns One solid per root, in root order
|
|
30
32
|
* @group build
|
|
@@ -33,7 +35,7 @@ export class ManifoldRecipes {
|
|
|
33
35
|
* @example
|
|
34
36
|
* ```typescript
|
|
35
37
|
* const recipe = await bitbybit.ifc.geometry.recipe({ model });
|
|
36
|
-
* const solids = await bitbybit.manifold.recipes.build({ recipe,
|
|
38
|
+
* const solids = await bitbybit.manifold.recipes.build({ recipe, upAxis: Bit.Inputs.Base.upAxisConversionEnum.zUpToYUp, emptyWhenFailed: true });
|
|
37
39
|
* ```
|
|
38
40
|
*/
|
|
39
41
|
build(inputs) {
|
|
@@ -42,7 +44,7 @@ export class ManifoldRecipes {
|
|
|
42
44
|
if (!Number.isSafeInteger(resolved.circularSegments) || resolved.circularSegments < MIN_CIRCLE_SIDES) {
|
|
43
45
|
throw new RangeError(`A circle needs at least ${MIN_CIRCLE_SIDES} sides, got ${resolved.circularSegments}`);
|
|
44
46
|
}
|
|
45
|
-
return executeRecipe(this.manifold, recipe, resolved.circularSegments, resolved.
|
|
47
|
+
return executeRecipe(this.manifold, recipe, resolved.circularSegments, rootPlacingOf(this.settings().coordinateSystem, turnedFromZUp(resolved.upAxis)), resolved.emptyWhenFailed);
|
|
46
48
|
}
|
|
47
49
|
/**
|
|
48
50
|
* Builds a recipe into the meshes its roots draw, each step several roots place meshed once in
|
|
@@ -58,7 +60,7 @@ export class ManifoldRecipes {
|
|
|
58
60
|
* @example
|
|
59
61
|
* ```typescript
|
|
60
62
|
* const recipe = await bitbybit.ifc.geometry.recipe({ model });
|
|
61
|
-
* const { meshes, placements } = await bitbybit.manifold.recipes.meshes({ recipe,
|
|
63
|
+
* const { meshes, placements } = await bitbybit.manifold.recipes.meshes({ recipe, upAxis: Bit.Inputs.Base.upAxisConversionEnum.zUpToYUp, emptyWhenFailed: true });
|
|
62
64
|
* ```
|
|
63
65
|
*/
|
|
64
66
|
meshes(inputs) {
|
|
@@ -70,7 +72,7 @@ export class ManifoldRecipes {
|
|
|
70
72
|
if (!(resolved.minSharpAngle >= 0 && resolved.minSharpAngle <= MAX_SHARP_ANGLE)) {
|
|
71
73
|
throw new RangeError(`minSharpAngle must be an angle from 0 to ${MAX_SHARP_ANGLE} degrees, got ${resolved.minSharpAngle}`);
|
|
72
74
|
}
|
|
73
|
-
return recipeMeshes(this.manifold, this.recipes, recipe, resolved);
|
|
75
|
+
return recipeMeshes(this.manifold, this.recipes, recipe, resolved, this.settings().coordinateSystem);
|
|
74
76
|
}
|
|
75
77
|
/**
|
|
76
78
|
* Gives the roots of a recipe made of triangle meshes alone as meshes, placed as `build` places
|
|
@@ -85,15 +87,15 @@ export class ManifoldRecipes {
|
|
|
85
87
|
* @drawable true
|
|
86
88
|
* @example
|
|
87
89
|
* ```typescript
|
|
88
|
-
* const solids = await bitbybit.manifold.recipes.build({ recipe,
|
|
90
|
+
* const solids = await bitbybit.manifold.recipes.build({ recipe, upAxis: Bit.Inputs.Base.upAxisConversionEnum.zUpToYUp, emptyWhenFailed: true });
|
|
89
91
|
* const meshes = await bitbybit.manifold.manifold.manifoldsToMeshes({ manifolds: solids });
|
|
90
92
|
* const open = meshes.flatMap((mesh, index) => mesh.triVerts.length === 0 ? [index] : []);
|
|
91
|
-
* const surfaces = await bitbybit.manifold.recipes.surfaceMeshes({ recipe, roots: open,
|
|
93
|
+
* const surfaces = await bitbybit.manifold.recipes.surfaceMeshes({ recipe, roots: open, upAxis: Bit.Inputs.Base.upAxisConversionEnum.zUpToYUp });
|
|
92
94
|
* ```
|
|
93
95
|
*/
|
|
94
96
|
surfaceMeshes(inputs) {
|
|
95
97
|
const resolved = resolveDto(Inputs.Manifold.RecipeSurfaceMeshesDto, inputs);
|
|
96
|
-
return this.recipes.surfaceMeshes({ recipe: resolved.recipe, roots: resolved.roots,
|
|
98
|
+
return this.recipes.surfaceMeshes({ recipe: resolved.recipe, roots: resolved.roots, upAxis: resolved.upAxis }).map((mesh) => {
|
|
97
99
|
var _a, _b;
|
|
98
100
|
return ({
|
|
99
101
|
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.8.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",
|
|
@@ -55,6 +55,6 @@
|
|
|
55
55
|
"type": "module",
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"manifold-3d": "3.5.4",
|
|
58
|
-
"@bitbybit-dev/base": "1.
|
|
58
|
+
"@bitbybit-dev/base": "1.8.0"
|
|
59
59
|
}
|
|
60
60
|
}
|