From 356537e0b03a9ce620d18e9bac4f82ca0c6f4860 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Wed, 26 Jun 2024 13:49:25 +0200 Subject: [PATCH 1/2] Function for checking if an object is solid --- packages/base/src/3dview/mainview.tsx | 3 +++ packages/occ-worker/src/occparser.ts | 37 +++++++++++++++++++++++++++ packages/opencascade/build.yml | 14 ++++++++-- packages/schema/src/interfaces.ts | 1 + 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/packages/base/src/3dview/mainview.tsx b/packages/base/src/3dview/mainview.tsx index 3588f6e2..013a810d 100644 --- a/packages/base/src/3dview/mainview.tsx +++ b/packages/base/src/3dview/mainview.tsx @@ -583,6 +583,7 @@ export class MainView extends React.Component { this._meshGroup = new THREE.Group(); + console.log(payload); Object.entries(payload).forEach(([objName, data]) => { const selected = selectedNames.includes(objName); const output = buildShape({ @@ -737,6 +738,7 @@ export class MainView extends React.Component { this.setState(old => ({ ...old, loading: false })); } } + private async _requestRender( sender: MainViewModel, renderData: { @@ -790,6 +792,7 @@ export class MainView extends React.Component { }); } } + private _updatePointers(refLength): void { this._pointerGeometry = new THREE.SphereGeometry(refLength / 10, 32, 32); diff --git a/packages/occ-worker/src/occparser.ts b/packages/occ-worker/src/occparser.ts index 8e571ed7..f3d25708 100644 --- a/packages/occ-worker/src/occparser.ts +++ b/packages/occ-worker/src/occparser.ts @@ -51,6 +51,7 @@ export class OccParser { jcObject, faceList, edgeList: [...edgeList, ...wireList], + isSolid: this._isSolid(occShape), meta: metadata }; }); @@ -58,6 +59,42 @@ export class OccParser { return threejsData; } + private _isSolid(shape: OCC.TopoDS_Shape) { + console.log('try checking is solid'); + if (shape.ShapeType() == this._occ.TopAbs_ShapeEnum.TopAbs_SOLID || shape.ShapeType() == this._occ.TopAbs_ShapeEnum.TopAbs_SHELL) { + console.log('1'); + try { + const classifier = new this._occ.BRepClass3d_SolidClassifier(); + console.log('2'); + classifier.Load(shape); + + console.log('3'); + // Define a point (doesn't need to be specific, as we only care if it's closed) + const point = new this._occ.gp_Pnt(); + console.log('4'); + classifier.Perform(point, 0); + + console.log('5'); + // Check if the point is inside, on the boundary, or outside the solid + if (classifier.State() == this._occ.TopAbs_State.TopAbs_IN || classifier.State() == this._occ.TopAbs_State.TopAbs_ON) { + console.log('6'); + return true; // The solid is closed + } + } catch (e) { + if (typeof e === 'number') { + const exceptionData = this._occ.OCJS.getStandard_FailureData(e); + console.log( + `That didn't work because: ${exceptionData.GetMessageString()}` + ); + } else { + console.log('Unkown error'); + } + } + } + console.log('61'); + return false; + } + private _shouldComputeEdge(obj: IJCadObject): boolean { if (obj.shape === 'Part::Any' && obj.parameters?.Type === 'STL') { return false; diff --git a/packages/opencascade/build.yml b/packages/opencascade/build.yml index 12675082..a3aa86b5 100644 --- a/packages/opencascade/build.yml +++ b/packages/opencascade/build.yml @@ -21,6 +21,8 @@ mainBuild: - symbol: BRepBuilderAPI_MakeVertex - symbol: BRepBuilderAPI_MakeWire - symbol: BRepBuilderAPI_ModifyShape + - symbol: BRepClass3d_SClassifier + - symbol: BRepClass3d_SolidClassifier - symbol: BRepFilletAPI_LocalOperation - symbol: BRepFilletAPI_MakeChamfer - symbol: BRepFilletAPI_MakeFillet @@ -69,12 +71,14 @@ mainBuild: - symbol: Message_ProgressRange - symbol: NCollection_BaseList - symbol: NCollection_BaseMap + - symbol: OCJS - symbol: Poly_Array1OfTriangle - symbol: Poly_Connect - symbol: Poly_PolygonOnTriangulation - symbol: Poly_Triangle - symbol: Poly_Triangulation - symbol: RWStl + - symbol: Standard_Failure - symbol: Standard_Transient - symbol: StdPrs_ToolTriangulatedShape - symbol: STEPControl_Reader @@ -83,6 +87,7 @@ mainBuild: - symbol: TColStd_Array1OfInteger - symbol: TopAbs_Orientation - symbol: TopAbs_ShapeEnum + - symbol: TopAbs_State - symbol: TopExp - symbol: TopExp_Explorer - symbol: TopLoc_Location @@ -103,9 +108,7 @@ mainBuild: - symbol: XSControl_Reader emccFlags: - "-flto" - - "-fexceptions" - "-O3" - - "-sDISABLE_EXCEPTION_CATCHING=1" - "-sEXPORT_ES6=1" - "-sUSE_ES6_IMPORT_META=0" - "-sEXPORTED_RUNTIME_METHODS=['FS']" @@ -115,3 +118,10 @@ mainBuild: - "-sLLD_REPORT_UNDEFINED" - "--no-entry" - "-sENVIRONMENT='web'" +additionalCppCode: | + class OCJS { + public: + static Standard_Failure* getStandard_FailureData(intptr_t exceptionPtr) { + return reinterpret_cast(exceptionPtr); + } + }; diff --git a/packages/schema/src/interfaces.ts b/packages/schema/src/interfaces.ts index e7a417c3..5de253eb 100644 --- a/packages/schema/src/interfaces.ts +++ b/packages/schema/src/interfaces.ts @@ -209,6 +209,7 @@ export interface IParsedShape { jcObject: IJCadObject; faceList: Array; edgeList: Array; + isSolid: boolean; meta?: IDict; guiData?: IDict; } From 186e55b3d4d578f6f4d91db22319ab04871d2b44 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:21:24 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- packages/occ-worker/src/occparser.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/occ-worker/src/occparser.ts b/packages/occ-worker/src/occparser.ts index f3d25708..0b1a3422 100644 --- a/packages/occ-worker/src/occparser.ts +++ b/packages/occ-worker/src/occparser.ts @@ -61,7 +61,10 @@ export class OccParser { private _isSolid(shape: OCC.TopoDS_Shape) { console.log('try checking is solid'); - if (shape.ShapeType() == this._occ.TopAbs_ShapeEnum.TopAbs_SOLID || shape.ShapeType() == this._occ.TopAbs_ShapeEnum.TopAbs_SHELL) { + if ( + shape.ShapeType() == this._occ.TopAbs_ShapeEnum.TopAbs_SOLID || + shape.ShapeType() == this._occ.TopAbs_ShapeEnum.TopAbs_SHELL + ) { console.log('1'); try { const classifier = new this._occ.BRepClass3d_SolidClassifier(); @@ -76,7 +79,10 @@ export class OccParser { console.log('5'); // Check if the point is inside, on the boundary, or outside the solid - if (classifier.State() == this._occ.TopAbs_State.TopAbs_IN || classifier.State() == this._occ.TopAbs_State.TopAbs_ON) { + if ( + classifier.State() == this._occ.TopAbs_State.TopAbs_IN || + classifier.State() == this._occ.TopAbs_State.TopAbs_ON + ) { console.log('6'); return true; // The solid is closed }