Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Function for checking if an object is solid #372

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/base/src/3dview/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ export class MainView extends React.Component<IProps, IStates> {

this._meshGroup = new THREE.Group();

console.log(payload);
Object.entries(payload).forEach(([objName, data]) => {
const selected = selectedNames.includes(objName);
const output = buildShape({
Expand Down Expand Up @@ -737,6 +738,7 @@ export class MainView extends React.Component<IProps, IStates> {
this.setState(old => ({ ...old, loading: false }));
}
}

private async _requestRender(
sender: MainViewModel,
renderData: {
Expand Down Expand Up @@ -790,6 +792,7 @@ export class MainView extends React.Component<IProps, IStates> {
});
}
}

private _updatePointers(refLength): void {
this._pointerGeometry = new THREE.SphereGeometry(refLength / 10, 32, 32);

Expand Down
43 changes: 43 additions & 0 deletions packages/occ-worker/src/occparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,56 @@ export class OccParser {
jcObject,
faceList,
edgeList: [...edgeList, ...wireList],
isSolid: this._isSolid(occShape),
meta: metadata
};
});

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;
Expand Down
14 changes: 12 additions & 2 deletions packages/opencascade/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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']"
Expand All @@ -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<Standard_Failure*>(exceptionPtr);
}
};
1 change: 1 addition & 0 deletions packages/schema/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export interface IParsedShape {
jcObject: IJCadObject;
faceList: Array<IFace>;
edgeList: Array<IEdge>;
isSolid: boolean;
meta?: IDict;
guiData?: IDict;
}
Expand Down
Loading