@bitbybit-dev/manifold 1.1.1 → 1.2.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +14 -4
  2. package/index.js +0 -3
  3. package/lib/api/inputs/base-inputs.js +0 -1
  4. package/lib/api/inputs/manifold-inputs.d.ts +63 -23
  5. package/lib/api/inputs/manifold-inputs.js +114 -1
  6. package/lib/api/manifold-service.d.ts +30 -2
  7. package/lib/api/manifold-service.js +43 -22
  8. package/lib/api/services/cross-section/cross-section-booleans.d.ts +78 -2
  9. package/lib/api/services/cross-section/cross-section-booleans.js +86 -10
  10. package/lib/api/services/cross-section/cross-section-evaluate.d.ts +45 -2
  11. package/lib/api/services/cross-section/cross-section-evaluate.js +45 -2
  12. package/lib/api/services/cross-section/cross-section-operations.d.ts +71 -0
  13. package/lib/api/services/cross-section/cross-section-operations.js +71 -2
  14. package/lib/api/services/cross-section/cross-section-shapes.d.ts +39 -0
  15. package/lib/api/services/cross-section/cross-section-shapes.js +39 -0
  16. package/lib/api/services/cross-section/cross-section-transforms.d.ts +72 -2
  17. package/lib/api/services/cross-section/cross-section-transforms.js +72 -2
  18. package/lib/api/services/cross-section/cross-section.d.ts +53 -1
  19. package/lib/api/services/cross-section/cross-section.js +53 -5
  20. package/lib/api/services/index.js +1 -0
  21. package/lib/api/services/manifold/manifold-booleans.d.ts +116 -6
  22. package/lib/api/services/manifold/manifold-booleans.js +159 -48
  23. package/lib/api/services/manifold/manifold-evaluate.d.ts +133 -3
  24. package/lib/api/services/manifold/manifold-evaluate.js +135 -5
  25. package/lib/api/services/manifold/manifold-operations.d.ts +202 -1
  26. package/lib/api/services/manifold/manifold-operations.js +204 -3
  27. package/lib/api/services/manifold/manifold-shapes.d.ts +59 -0
  28. package/lib/api/services/manifold/manifold-shapes.js +78 -20
  29. package/lib/api/services/manifold/manifold-transforms.d.ts +97 -3
  30. package/lib/api/services/manifold/manifold-transforms.js +102 -6
  31. package/lib/api/services/manifold/manifold.d.ts +20 -0
  32. package/lib/api/services/manifold/manifold.js +20 -1
  33. package/lib/api/services/mesh/mesh-evaluate.d.ts +81 -3
  34. package/lib/api/services/mesh/mesh-evaluate.js +84 -6
  35. package/lib/api/services/mesh/mesh-operations.d.ts +24 -2
  36. package/lib/api/services/mesh/mesh-operations.js +24 -2
  37. package/lib/api/services/mesh/mesh.d.ts +4 -0
  38. package/lib/api/services/mesh/mesh.js +4 -1
  39. package/package.json +6 -45
  40. package/babel.config.cjs +0 -17
  41. package/babel.config.d.cts +0 -6
package/README.md CHANGED
@@ -41,7 +41,17 @@ Choose from 5 backend templates: Hono + SDK, Hono + REST, Node.js + SDK, Node.js
41
41
  | **Monorepo** | https://github.com/bitbybit-dev/bitbybit |
42
42
  | **NPM** | https://www.npmjs.com/package/@bitbybit-dev/manifold |
43
43
  | **Documentation** | https://learn.bitbybit.dev/learn/npm-packages/intro |
44
- | **Unit Test Coverage** | https://tests.bitbybit.dev/manifold |
44
+ | **API Reference** | https://docs.bitbybit.dev/classes/Bit.Manifold |
45
+ | **Unit Test Coverage** | https://github.com/bitbybit-dev/bitbybit/actions/workflows/verify.yml |
46
+
47
+ ### API reference
48
+
49
+ Every class, method and input type in this package is documented in the generated TypeScript API reference:
50
+
51
+ - [Manifold](https://docs.bitbybit.dev/classes/Bit.Manifold)
52
+ - [Manifold shapes](https://docs.bitbybit.dev/classes/Bit.ManifoldShapes)
53
+ - [Manifold booleans](https://docs.bitbybit.dev/classes/Bit.ManifoldBooleans)
54
+ - [Manifold input types](https://docs.bitbybit.dev/modules/Bit.Inputs.Manifold)
45
55
 
46
56
  ## Example Applications
47
57
 
@@ -58,10 +68,10 @@ Choose from 5 backend templates: Hono + SDK, Hono + REST, Node.js + SDK, Node.js
58
68
  npm run build-p
59
69
 
60
70
  # Run unit tests with coverage
61
- npm run test-c
71
+ npm run test:coverage
62
72
 
63
- # Run live unit tests with coverage on save
64
- npm run test-c-l
73
+ # Re-run them as you edit
74
+ npm run test:watch
65
75
  ```
66
76
 
67
77
  ## Bitbybit Platform
package/index.js CHANGED
@@ -1,4 +1 @@
1
- /*
2
- * Public API Surface of bitbybit-core
3
- */
4
1
  export * from "./lib";
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-namespace */
2
1
  /**
3
2
  * Re-export Base namespace from @bitbybit-dev/base.
4
3
  * Manifold package uses the same foundational types without additions.
@@ -1,40 +1,80 @@
1
1
  import { Base } from "./base-inputs";
2
+ /**
3
+ * Every parameter object the Manifold kernel accepts. Manifold specialises in fast, reliably
4
+ * watertight mesh booleans, so its DTOs carry manifold handles and the settings that keep results
5
+ * valid - segment counts, precision and the operands of a boolean.
6
+ *
7
+ * It also models in 2D: cross sections can be built, offset and booleaned in the plane, then extruded
8
+ * or revolved into solids, which is often the cheapest route to a profile-driven part. Names repeat
9
+ * across kernels: the CircleDto here is not the one in Inputs.OCCT.
10
+ */
2
11
  export declare namespace Manifold {
12
+ /**
13
+ * A handle to a solid living inside the Manifold kernel, not the geometry itself. The kernel runs
14
+ * as WebAssembly with its own memory, so what crosses back into JavaScript is this small
15
+ * reference. Pass it into the next operation to keep building, and dispose it when finished to
16
+ * release the kernel memory behind it.
17
+ */
3
18
  type ManifoldPointer = {
4
19
  hash: number;
5
20
  type: string;
6
21
  };
22
+ /**
23
+ * A handle to a 2D cross section inside the Manifold kernel. Cross sections are built, offset and
24
+ * booleaned in the plane, then extruded or revolved into solids - often the cheapest route to a
25
+ * profile-driven part.
26
+ */
7
27
  type CrossSectionPointer = {
8
28
  hash: number;
9
29
  type: string;
10
30
  };
31
+ /**
32
+ * A handle to raw mesh data inside the Manifold kernel, used when importing an existing mesh into
33
+ * the kernel or reading one back out.
34
+ */
11
35
  type MeshPointer = {
12
36
  hash: number;
13
37
  type: string;
14
38
  };
39
+ /**
40
+ * How overlapping and self-intersecting outlines decide what is inside. evenOdd alternates with
41
+ * each crossing, so a shape inside a shape becomes a hole; nonZero counts winding direction, so
42
+ * overlaps stay filled; positive and negative keep only regions with winding of that sign. If an
43
+ * imported outline fills wrongly, this is the setting to change first.
44
+ */
15
45
  enum fillRuleEnum {
16
46
  evenOdd = "EvenOdd",
17
47
  nonZero = "NonZero",
18
48
  positive = "Positive",
19
49
  negative = "Negative"
20
50
  }
51
+ /**
52
+ * How an offset fills the outside of a corner: square cuts it off flat, round arcs around it,
53
+ * miter extends both sides to a sharp point, bevel cuts a chamfer. Miter can produce very long
54
+ * spikes at tight angles, which is why square or round is the safer default.
55
+ */
21
56
  enum manifoldJoinTypeEnum {
22
57
  square = "Square",
23
58
  round = "Round",
24
59
  miter = "Miter",
25
60
  bevel = "Bevel"
26
61
  }
62
+ /**
63
+ * A Manifold solid taken apart into plain arrays - vertex properties, triangle indices and the
64
+ * run structure that groups them. The form the kernel hands back when geometry has to cross out of
65
+ * WebAssembly for rendering or export.
66
+ */
27
67
  class DecomposedManifoldMeshDto {
28
68
  numProp: number;
29
69
  vertProperties: Float32Array;
30
70
  triVerts: Uint32Array;
31
- mergeFromVert?: Uint32Array;
32
- mergeToVert?: Uint32Array;
33
- runIndex?: Uint32Array;
34
- runOriginalID?: Uint32Array;
35
- runTransform?: Float32Array;
36
- faceID?: Uint32Array;
37
- halfedgeTangent?: Float32Array;
71
+ mergeFromVert?: Uint32Array | undefined;
72
+ mergeToVert?: Uint32Array | undefined;
73
+ runIndex?: Uint32Array | undefined;
74
+ runOriginalID?: Uint32Array | undefined;
75
+ runTransform?: Float32Array | undefined;
76
+ faceID?: Uint32Array | undefined;
77
+ halfedgeTangent?: Float32Array | undefined;
38
78
  }
39
79
  class DrawManifoldOrCrossSectionDto<T, M> {
40
80
  /**
@@ -45,7 +85,7 @@ export declare namespace Manifold {
45
85
  * Manifold geometry
46
86
  * @default undefined
47
87
  */
48
- manifoldOrCrossSection?: T;
88
+ manifoldOrCrossSection?: T | undefined;
49
89
  /**
50
90
  * Face opacity value between 0 and 1
51
91
  * @default 1
@@ -59,7 +99,7 @@ export declare namespace Manifold {
59
99
  * @default undefined
60
100
  * @optional true
61
101
  */
62
- faceMaterial?: M;
102
+ faceMaterial?: M | undefined;
63
103
  /**
64
104
  * Hex colour string for face colour
65
105
  * @default #ff0000
@@ -116,13 +156,13 @@ export declare namespace Manifold {
116
156
  * Manifold geometry
117
157
  * @default undefined
118
158
  */
119
- manifoldsOrCrossSections?: T[];
159
+ manifoldsOrCrossSections?: T[] | undefined;
120
160
  /**
121
161
  * Face material
122
162
  * @default undefined
123
163
  * @optional true
124
164
  */
125
- faceMaterial?: M;
165
+ faceMaterial?: M | undefined;
126
166
  /**
127
167
  * Hex colour string for face colour
128
168
  * @default #ff0000
@@ -190,7 +230,7 @@ export declare namespace Manifold {
190
230
  /**
191
231
  * Points describing polygons
192
232
  */
193
- polygonPoints?: Base.Point3[][];
233
+ polygonPoints: Base.Point3[][];
194
234
  }
195
235
  class CrossSectionFromPolygonPointsDto {
196
236
  constructor(points?: Base.Point3[], fillRule?: fillRuleEnum, removeDuplicates?: boolean, tolerance?: number);
@@ -202,17 +242,17 @@ export declare namespace Manifold {
202
242
  * Fill rule for polygon interpretation
203
243
  * @default positive
204
244
  */
205
- fillRule?: fillRuleEnum;
245
+ fillRule?: fillRuleEnum | undefined;
206
246
  /**
207
247
  * Remove consecutive duplicate points before creating polygon
208
248
  * @default false
209
249
  */
210
- removeDuplicates?: boolean;
250
+ removeDuplicates?: boolean | undefined;
211
251
  /**
212
252
  * Tolerance for duplicate removal
213
253
  * @default 1e-7
214
254
  */
215
- tolerance?: number;
255
+ tolerance?: number | undefined;
216
256
  }
217
257
  class CrossSectionFromPolygonsPointsDto {
218
258
  constructor(polygonPoints?: Base.Point3[][], fillRule?: fillRuleEnum, removeDuplicates?: boolean, tolerance?: number);
@@ -224,17 +264,17 @@ export declare namespace Manifold {
224
264
  * Fill rule for polygon interpretation
225
265
  * @default positive
226
266
  */
227
- fillRule?: fillRuleEnum;
267
+ fillRule?: fillRuleEnum | undefined;
228
268
  /**
229
269
  * Remove consecutive duplicate points before creating polygons
230
270
  * @default false
231
271
  */
232
- removeDuplicates?: boolean;
272
+ removeDuplicates?: boolean | undefined;
233
273
  /**
234
274
  * Tolerance for duplicate removal
235
275
  * @default 1e-7
236
276
  */
237
- tolerance?: number;
277
+ tolerance?: number | undefined;
238
278
  }
239
279
  class CubeDto {
240
280
  constructor(center?: boolean, size?: number);
@@ -555,7 +595,7 @@ export declare namespace Manifold {
555
595
  * @maximum Infinity
556
596
  * @step 0.001
557
597
  */
558
- tolerance?: number;
598
+ tolerance?: number | undefined;
559
599
  }
560
600
  class ManifoldSetPropertiesDto<T> {
561
601
  constructor(manifold?: T, numProp?: number, propFunc?: (newProp: number[], position: Base.Vector3, oldProp: number[]) => void);
@@ -1246,7 +1286,7 @@ export declare namespace Manifold {
1246
1286
  /**
1247
1287
  * Optional normal index
1248
1288
  */
1249
- normalIdx?: number;
1289
+ normalIdx?: number | undefined;
1250
1290
  }
1251
1291
  class ManifoldsToMeshesDto<T> {
1252
1292
  constructor(manifolds?: T[], normalIdx?: number[]);
@@ -1257,7 +1297,7 @@ export declare namespace Manifold {
1257
1297
  /**
1258
1298
  * Optional normal indexes
1259
1299
  */
1260
- normalIdx?: number[];
1300
+ normalIdx?: number[] | undefined;
1261
1301
  }
1262
1302
  class DecomposeManifoldOrCrossSectionDto<T> {
1263
1303
  constructor(manifoldOrCrossSection?: T, normalIdx?: number);
@@ -1268,7 +1308,7 @@ export declare namespace Manifold {
1268
1308
  /**
1269
1309
  * Optional normal index
1270
1310
  */
1271
- normalIdx?: number;
1311
+ normalIdx?: number | undefined;
1272
1312
  }
1273
1313
  class ManifoldOrCrossSectionDto<T> {
1274
1314
  constructor(manifoldOrCrossSection?: T);
@@ -1293,6 +1333,6 @@ export declare namespace Manifold {
1293
1333
  /**
1294
1334
  * Optional normal indexes
1295
1335
  */
1296
- normalIdx?: number[];
1336
+ normalIdx?: number[] | undefined;
1297
1337
  }
1298
1338
  }
@@ -1,6 +1,21 @@
1
- // tslint:disable-next-line: no-namespace
1
+ // GENERATED by scripts/gen-inputs.mjs from the fragments in ./manifold/ - do not edit; edit a fragment and run `npm run gen:inputs`.
2
+ /**
3
+ * Every parameter object the Manifold kernel accepts. Manifold specialises in fast, reliably
4
+ * watertight mesh booleans, so its DTOs carry manifold handles and the settings that keep results
5
+ * valid - segment counts, precision and the operands of a boolean.
6
+ *
7
+ * It also models in 2D: cross sections can be built, offset and booleaned in the plane, then extruded
8
+ * or revolved into solids, which is often the cheapest route to a profile-driven part. Names repeat
9
+ * across kernels: the CircleDto here is not the one in Inputs.OCCT.
10
+ */
2
11
  export var Manifold;
3
12
  (function (Manifold) {
13
+ /**
14
+ * How overlapping and self-intersecting outlines decide what is inside. evenOdd alternates with
15
+ * each crossing, so a shape inside a shape becomes a hole; nonZero counts winding direction, so
16
+ * overlaps stay filled; positive and negative keep only regions with winding of that sign. If an
17
+ * imported outline fills wrongly, this is the setting to change first.
18
+ */
4
19
  let fillRuleEnum;
5
20
  (function (fillRuleEnum) {
6
21
  fillRuleEnum["evenOdd"] = "EvenOdd";
@@ -8,6 +23,11 @@ export var Manifold;
8
23
  fillRuleEnum["positive"] = "Positive";
9
24
  fillRuleEnum["negative"] = "Negative";
10
25
  })(fillRuleEnum = Manifold.fillRuleEnum || (Manifold.fillRuleEnum = {}));
26
+ /**
27
+ * How an offset fills the outside of a corner: square cuts it off flat, round arcs around it,
28
+ * miter extends both sides to a sharp point, bevel cuts a chamfer. Miter can produce very long
29
+ * spikes at tight angles, which is why square or round is the safer default.
30
+ */
11
31
  let manifoldJoinTypeEnum;
12
32
  (function (manifoldJoinTypeEnum) {
13
33
  manifoldJoinTypeEnum["square"] = "Square";
@@ -15,6 +35,11 @@ export var Manifold;
15
35
  manifoldJoinTypeEnum["miter"] = "Miter";
16
36
  manifoldJoinTypeEnum["bevel"] = "Bevel";
17
37
  })(manifoldJoinTypeEnum = Manifold.manifoldJoinTypeEnum || (Manifold.manifoldJoinTypeEnum = {}));
38
+ /**
39
+ * A Manifold solid taken apart into plain arrays - vertex properties, triangle indices and the
40
+ * run structure that groups them. The form the kernel hands back when geometry has to cross out of
41
+ * WebAssembly for rendering or export.
42
+ */
18
43
  class DecomposedManifoldMeshDto {
19
44
  }
20
45
  Manifold.DecomposedManifoldMeshDto = DecomposedManifoldMeshDto;
@@ -362,6 +387,14 @@ export var Manifold;
362
387
  * @step 0.1
363
388
  */
364
389
  this.radius = 1;
390
+ /**
391
+ * Circular segments of the sphere
392
+ * @default 32
393
+ * @minimum 0
394
+ * @maximum Infinity
395
+ * @step 1
396
+ */
397
+ this.circularSegments = 32;
365
398
  if (radius !== undefined) {
366
399
  this.radius = radius;
367
400
  }
@@ -538,6 +571,28 @@ export var Manifold;
538
571
  Manifold.CalculateNormalsDto = CalculateNormalsDto;
539
572
  class CalculateCurvatureDto {
540
573
  constructor(manifold) {
574
+ /**
575
+ * The property channel index in which to store the
576
+ * Gaussian curvature. An index < 0 will be ignored (stores nothing). The
577
+ * property set will be automatically expanded to include the channel
578
+ * index specified.
579
+ * @default 0
580
+ * @minimum 0
581
+ * @maximum Infinity
582
+ * @step 1
583
+ */
584
+ this.gaussianIdx = 0;
585
+ /**
586
+ * The property channel index in which to store the mean
587
+ * curvature. An index < 0 will be ignored (stores nothing). The property
588
+ * set will be automatically expanded to include the channel index
589
+ * specified. The mean curvature is a scalar value that describes the
590
+ * @default 1
591
+ * @minimum 0
592
+ * @maximum Infinity
593
+ * @step 1
594
+ */
595
+ this.meanIdx = 1;
541
596
  if (manifold !== undefined) {
542
597
  this.manifold = manifold;
543
598
  }
@@ -758,6 +813,14 @@ export var Manifold;
758
813
  Manifold.MeshDto = MeshDto;
759
814
  class MeshVertexIndexDto {
760
815
  constructor(mesh, vertexIndex) {
816
+ /**
817
+ * Vertex index
818
+ * @default 0
819
+ * @minimum 0
820
+ * @maximum Infinity
821
+ * @step 1
822
+ */
823
+ this.vertexIndex = 0;
761
824
  if (mesh !== undefined) {
762
825
  this.mesh = mesh;
763
826
  }
@@ -769,6 +832,14 @@ export var Manifold;
769
832
  Manifold.MeshVertexIndexDto = MeshVertexIndexDto;
770
833
  class MeshTriangleRunIndexDto {
771
834
  constructor(mesh, triangleRunIndex) {
835
+ /**
836
+ * Triangle run index
837
+ * @default 0
838
+ * @minimum 0
839
+ * @maximum Infinity
840
+ * @step 1
841
+ */
842
+ this.triangleRunIndex = 0;
772
843
  if (mesh !== undefined) {
773
844
  this.mesh = mesh;
774
845
  }
@@ -780,6 +851,14 @@ export var Manifold;
780
851
  Manifold.MeshTriangleRunIndexDto = MeshTriangleRunIndexDto;
781
852
  class MeshHalfEdgeIndexDto {
782
853
  constructor(mesh, halfEdgeIndex) {
854
+ /**
855
+ * Half edge index
856
+ * @default 0
857
+ * @minimum 0
858
+ * @maximum Infinity
859
+ * @step 1
860
+ */
861
+ this.halfEdgeIndex = 0;
783
862
  if (mesh !== undefined) {
784
863
  this.mesh = mesh;
785
864
  }
@@ -791,6 +870,14 @@ export var Manifold;
791
870
  Manifold.MeshHalfEdgeIndexDto = MeshHalfEdgeIndexDto;
792
871
  class MeshTriangleIndexDto {
793
872
  constructor(mesh, triangleIndex) {
873
+ /**
874
+ * Triangle index
875
+ * @default 0
876
+ * @minimum 0
877
+ * @maximum Infinity
878
+ * @step 1
879
+ */
880
+ this.triangleIndex = 0;
794
881
  if (mesh !== undefined) {
795
882
  this.mesh = mesh;
796
883
  }
@@ -871,6 +958,14 @@ export var Manifold;
871
958
  Manifold.ExtrudeDto = ExtrudeDto;
872
959
  class RevolveDto {
873
960
  constructor(crossSection, revolveDegrees, matchProfile, circularSegments) {
961
+ /**
962
+ * Extrude cross section shape
963
+ * @default 360
964
+ * @minimum 0
965
+ * @maximum Infinity
966
+ * @step 1
967
+ */
968
+ this.revolveDegrees = 360;
874
969
  /**
875
970
  * Default manifold library will adjust profile when generating revolved shape. We prefer it to be matching the profile by default. Set to false to use default manifold library behavior.
876
971
  * @default true
@@ -901,6 +996,16 @@ export var Manifold;
901
996
  Manifold.RevolveDto = RevolveDto;
902
997
  class OffsetDto {
903
998
  constructor(crossSection, delta, joinType, miterLimit, circularSegments) {
999
+ /**
1000
+ * Positive deltas will cause the expansion of outlining contours
1001
+ * to expand, and retraction of inner (hole) contours. Negative deltas will
1002
+ * have the opposite effect.
1003
+ * @default 1
1004
+ * @minimum -Infinity
1005
+ * @maximum Infinity
1006
+ * @step 0.1
1007
+ */
1008
+ this.delta = 1;
904
1009
  /**
905
1010
  * The join type specifying the treatment of contour joins
906
1011
  * (corners).
@@ -1021,6 +1126,14 @@ export var Manifold;
1021
1126
  Manifold.TranslateCrossSectionDto = TranslateCrossSectionDto;
1022
1127
  class RotateCrossSectionDto {
1023
1128
  constructor(crossSection, degrees) {
1129
+ /**
1130
+ * The rotation vector in eulers
1131
+ * @default 45
1132
+ * @minimum -Infinity
1133
+ * @maximum Infinity
1134
+ * @step 1
1135
+ */
1136
+ this.degrees = 45;
1024
1137
  if (crossSection !== undefined) {
1025
1138
  this.crossSection = crossSection;
1026
1139
  }
@@ -3,14 +3,42 @@ import * as Inputs from "./inputs";
3
3
  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
+ /**
7
+ * Contains various functions for Solid meshes from Manifold library https://github.com/elalish/manifold
8
+ * Thanks Manifold community for developing this kernel
9
+ */
6
10
  export declare class ManifoldService {
7
11
  plugins: any;
8
- crossSection: CrossSection;
9
12
  manifold: Manifold;
13
+ crossSection: CrossSection;
10
14
  private base;
11
15
  mesh: Mesh;
12
16
  constructor(wasm: Manifold3D.ManifoldToplevel);
13
- toPolygonPoints(inputs: Inputs.Manifold.ManifoldDto<Manifold3D.Manifold>): Inputs.Base.Mesh3;
17
+ /**
18
+ * Decomposes manifold or cross section shape into a mesh or simple polygons
19
+ * @param inputs Manifold shape or cross section
20
+ * @returns Decomposed mesh definition or simple polygons
21
+ * @group decompose
22
+ * @shortname decompose m or cs
23
+ * @drawable false
24
+ */
14
25
  decomposeManifoldOrCrossSection(inputs: Inputs.Manifold.DecomposeManifoldOrCrossSectionDto<Manifold3D.Manifold | Manifold3D.CrossSection>): Manifold3D.Mesh | Manifold3D.SimplePolygon[];
26
+ /**
27
+ * Turns manifold shape into a collection of polygon points representing the mesh.
28
+ * @param inputs Manifold shape
29
+ * @returns polygon points
30
+ * @group decompose
31
+ * @shortname to polygon points
32
+ * @drawable false
33
+ */
34
+ toPolygonPoints(inputs: Inputs.Manifold.ManifoldDto<Manifold3D.Manifold>): Inputs.Base.Mesh3;
35
+ /**
36
+ * Decomposes manifold or cross section shape into a mesh or simple polygons
37
+ * @param inputs Manifold shapes or cross sections
38
+ * @returns Decomposed mesh definitions or a list of simple polygons
39
+ * @group decompose
40
+ * @shortname decompose m's or cs's
41
+ * @drawable false
42
+ */
15
43
  decomposeManifoldsOrCrossSections(inputs: Inputs.Manifold.DecomposeManifoldsOrCrossSectionsDto<Manifold3D.Manifold | Manifold3D.CrossSection>): (Manifold3D.Mesh | Manifold3D.SimplePolygon[])[];
16
44
  }
@@ -2,27 +2,51 @@ import { Manifold } from "./services/manifold/manifold";
2
2
  import { CrossSection } from "./services/cross-section/cross-section";
3
3
  import { Mesh } from "./services/mesh/mesh";
4
4
  import { BaseBitByBit } from "../base";
5
- // Worker make an instance of this class itself
5
+ /**
6
+ * Contains various functions for Solid meshes from Manifold library https://github.com/elalish/manifold
7
+ * Thanks Manifold community for developing this kernel
8
+ */
6
9
  export class ManifoldService {
7
10
  constructor(wasm) {
8
11
  this.base = new BaseBitByBit();
9
- this.crossSection = new CrossSection(wasm, this.base);
10
12
  this.manifold = new Manifold(wasm);
13
+ this.crossSection = new CrossSection(wasm, this.base);
11
14
  this.mesh = new Mesh(wasm);
12
15
  }
16
+ /**
17
+ * Decomposes manifold or cross section shape into a mesh or simple polygons
18
+ * @param inputs Manifold shape or cross section
19
+ * @returns Decomposed mesh definition or simple polygons
20
+ * @group decompose
21
+ * @shortname decompose m or cs
22
+ * @drawable false
23
+ */
24
+ decomposeManifoldOrCrossSection(inputs) {
25
+ if (inputs.manifoldOrCrossSection.getMesh) {
26
+ return inputs.manifoldOrCrossSection.getMesh(inputs.normalIdx);
27
+ }
28
+ else {
29
+ return inputs.manifoldOrCrossSection.toPolygons();
30
+ }
31
+ }
32
+ /**
33
+ * Turns manifold shape into a collection of polygon points representing the mesh.
34
+ * @param inputs Manifold shape
35
+ * @returns polygon points
36
+ * @group decompose
37
+ * @shortname to polygon points
38
+ * @drawable false
39
+ */
13
40
  toPolygonPoints(inputs) {
14
- // Ensure the manifold is decomposed to access the mesh data.
15
- // The getMesh() method provides the necessary structure.
16
- if (inputs.manifold.getMesh) {
41
+ if (typeof inputs.manifold.getMesh === "function") {
17
42
  const mesh = inputs.manifold.getMesh();
18
43
  if (!mesh || !mesh.vertProperties || !mesh.triVerts || mesh.vertProperties.length === 0 || mesh.triVerts.length === 0) {
19
44
  console.warn("Manifold does not contain valid mesh data or is empty.");
20
45
  return [];
21
46
  }
22
- const vertProperties = mesh.vertProperties; // Float32Array [x1, y1, z1, [prop4...], x2, y2, z2, [prop4...]...]
23
- const triVerts = mesh.triVerts; // Uint32Array [idx1, idx2, idx3, idx4, idx5, idx6, ...]
24
- const numProp = mesh.numProp; // Number of properties per vertex
25
- // We need at least x, y, z data.
47
+ const vertProperties = mesh.vertProperties;
48
+ const triVerts = mesh.triVerts;
49
+ const numProp = mesh.numProp;
26
50
  if (numProp < 3) {
27
51
  throw new Error(`Cannot convert to PolygonPoints: Expected numProp >= 3 (for x, y, z), but found ${numProp}.`);
28
52
  }
@@ -37,14 +61,11 @@ export class ManifoldService {
37
61
  const index3 = triVerts[i + 2];
38
62
  if (index1 >= numVertices || index2 >= numVertices || index3 >= numVertices) {
39
63
  console.error(`Invalid vertex index found in triVerts at offset ${i}. Max index should be ${numVertices - 1}. Indices: ${index1}, ${index2}, ${index3}`);
40
- continue; // Skip this triangle
64
+ continue;
41
65
  }
42
- // Calculate the starting position of each vertex's data in vertProperties.
43
- // This calculation works regardless of numProp.
44
66
  const vert1Offset = index1 * numProp;
45
67
  const vert2Offset = index2 * numProp;
46
68
  const vert3Offset = index3 * numProp;
47
- // Extract only the first 3 properties (x, y, z) starting from the offset for each vertex.
48
69
  const point1 = [vertProperties[vert1Offset], vertProperties[vert1Offset + 1], vertProperties[vert1Offset + 2]];
49
70
  const point2 = [vertProperties[vert2Offset], vertProperties[vert2Offset + 1], vertProperties[vert2Offset + 2]];
50
71
  const point3 = [vertProperties[vert3Offset], vertProperties[vert3Offset + 1], vertProperties[vert3Offset + 2]];
@@ -54,17 +75,17 @@ export class ManifoldService {
54
75
  return polygons;
55
76
  }
56
77
  else {
57
- return undefined;
58
- }
59
- }
60
- decomposeManifoldOrCrossSection(inputs) {
61
- if (inputs.manifoldOrCrossSection.getMesh) {
62
- return inputs.manifoldOrCrossSection.getMesh(inputs.normalIdx);
63
- }
64
- else {
65
- return inputs.manifoldOrCrossSection.toPolygons();
78
+ throw new Error("Manifold has no mesh to convert");
66
79
  }
67
80
  }
81
+ /**
82
+ * Decomposes manifold or cross section shape into a mesh or simple polygons
83
+ * @param inputs Manifold shapes or cross sections
84
+ * @returns Decomposed mesh definitions or a list of simple polygons
85
+ * @group decompose
86
+ * @shortname decompose m's or cs's
87
+ * @drawable false
88
+ */
68
89
  decomposeManifoldsOrCrossSections(inputs) {
69
90
  return inputs.manifoldsOrCrossSections.map((manifoldOrCrossSection, index) => {
70
91
  const normalIdx = inputs.normalIdx ? inputs.normalIdx[index] : undefined;