Skip to content

Commit 93c99df

Browse files
committed
✨ feat: add simplifyShape
1 parent 35f35fc commit 93c99df

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

cpp/src/factory.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <Geom_BezierCurve.hxx>
3333
#include <ShapeAnalysis_Edge.hxx>
3434
#include <ShapeAnalysis_WireOrder.hxx>
35+
#include <ShapeUpgrade_UnifySameDomain.hxx>
3536
#include <TopoDS.hxx>
3637
#include <TopoDS_Shape.hxx>
3738
#include <gp_Ax2.hxx>
@@ -429,6 +430,21 @@ class ShapeFactory {
429430
return ShapeResult { makeThickSolid.Shape(), true, "" };
430431
}
431432

433+
static ShapeResult simplifyShape(
434+
const TopoDS_Shape& shape,
435+
const Standard_Boolean theUnifyEdges,
436+
const Standard_Boolean theUnifyFaces)
437+
{
438+
if (!theUnifyEdges && !theUnifyFaces) {
439+
return ShapeResult { shape, true, "" };
440+
}
441+
442+
ShapeUpgrade_UnifySameDomain anUnifier(shape, theUnifyEdges, theUnifyFaces, Standard_True);
443+
anUnifier.Build();
444+
445+
return ShapeResult { anUnifier.Shape(), true, "" };
446+
}
447+
432448
static ShapeResult booleanOperate(BRepAlgoAPI_BooleanOperation& boolOperater, const ShapeArray& args,
433449
const ShapeArray& tools)
434450
{
@@ -442,7 +458,6 @@ class ShapeFactory {
442458
if (!boolOperater.IsDone()) {
443459
return ShapeResult { TopoDS_Shape(), false, "Failed to build boolean operation" };
444460
}
445-
boolOperater.SimplifyResult();
446461

447462
return ShapeResult { boolOperater.Shape(), true, "" };
448463
}
@@ -555,6 +570,7 @@ EMSCRIPTEN_BINDINGS(ShapeFactory)
555570
.class_function("solid", &ShapeFactory::solid)
556571
.class_function("makeThickSolidBySimple", &ShapeFactory::makeThickSolidBySimple)
557572
.class_function("makeThickSolidByJoin", &ShapeFactory::makeThickSolidByJoin)
573+
.class_function("simplifyShape", &ShapeFactory::simplifyShape)
558574
.class_function("booleanCommon", &ShapeFactory::booleanCommon)
559575
.class_function("booleanCut", &ShapeFactory::booleanCut)
560576
.class_function("booleanFuse", &ShapeFactory::booleanFuse)

packages/chili-wasm/lib/chili-wasm.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ interface EmbindModule {
586586
ShapeResult: {};
587587
ShapeFactory: {
588588
makeThickSolidBySimple(_0: TopoDS_Shape, _1: number): ShapeResult;
589+
simplifyShape(_0: TopoDS_Shape, _1: boolean, _2: boolean): ShapeResult;
589590
curveProjection(_0: TopoDS_Shape, _1: TopoDS_Shape, _2: gp_Dir): ShapeResult;
590591
polygon(_0: Array<Vector3>): ShapeResult;
591592
bezier(_0: Array<Vector3>, _1: Array<number>): ShapeResult;
-192 Bytes
Binary file not shown.

packages/chili-wasm/src/factory.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,12 @@ export class ShapeFactory implements IShapeFactory {
274274
);
275275
}
276276
booleanFuse(shape1: IShape[], shape2: IShape[]): Result<IShape> {
277-
return convertShapeResult(
278-
wasm.ShapeFactory.booleanFuse(ensureOccShape(shape1), ensureOccShape(shape2)),
279-
);
277+
const fused = wasm.ShapeFactory.booleanFuse(ensureOccShape(shape1), ensureOccShape(shape2));
278+
if (!fused.isOk) {
279+
return Result.err(fused.error);
280+
}
281+
282+
return convertShapeResult(wasm.ShapeFactory.simplifyShape(fused.shape, true, true));
280283
}
281284
combine(shapes: IShape[]): Result<ICompound> {
282285
return convertShapeResult(wasm.ShapeFactory.combine(ensureOccShape(shapes))) as Result<ICompound>;

0 commit comments

Comments
 (0)