From 80ce29f248bfbcba0d6f4c565b0846a11c2c4b42 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Mon, 13 Nov 2023 11:48:40 +0100 Subject: [PATCH] Update OCC build --- .../extension.webpack.config.js | 4 - .../src/worker/actions.ts | 186 +----------------- .../jupytercad-extension/src/worker/occapi.ts | 64 +++--- .../src/worker/occparser.ts | 53 +++-- .../src/worker/operatorcache.ts | 10 +- .../jupytercad-extension/src/worker/types.ts | 4 +- .../jupytercad-extension/src/worker/worker.ts | 8 +- packages/jupytercad-opencascade/build.yml | 2 + ...encascade.js => build_opencascade_wasm.js} | 2 +- .../jupytercad-opencascade/lib/index.d.ts | 3 + packages/jupytercad-opencascade/lib/index.js | 9 + packages/jupytercad-opencascade/package.json | 18 +- yarn.lock | 19 +- 13 files changed, 120 insertions(+), 262 deletions(-) rename packages/jupytercad-opencascade/{build_opencascade.js => build_opencascade_wasm.js} (97%) create mode 100644 packages/jupytercad-opencascade/lib/index.d.ts create mode 100644 packages/jupytercad-opencascade/lib/index.js diff --git a/packages/jupytercad-extension/extension.webpack.config.js b/packages/jupytercad-extension/extension.webpack.config.js index eab97fc4..0a036540 100644 --- a/packages/jupytercad-extension/extension.webpack.config.js +++ b/packages/jupytercad-extension/extension.webpack.config.js @@ -3,10 +3,6 @@ const path = require('path'); const occPath = [ __dirname, - '../', - '../', - 'node_modules', - '@jupytercad/jupytercad-opencascade', 'lib', '*.wasm' ]; diff --git a/packages/jupytercad-extension/src/worker/actions.ts b/packages/jupytercad-extension/src/worker/actions.ts index 94af2a7e..85bf303b 100644 --- a/packages/jupytercad-extension/src/worker/actions.ts +++ b/packages/jupytercad-extension/src/worker/actions.ts @@ -1,9 +1,5 @@ import { IJCadObject } from '../_interface/jcad'; -import { - Handle_Poly_Triangulation, - OpenCascadeInstance, - TopoDS_Shape -} from '@jupytercad/jupytercad-opencascade'; +import { OCC } from '@jupytercad/jupytercad-opencascade'; import { IDict, WorkerAction } from '../types'; import { IJCadContent } from '../_interface/jcad'; @@ -11,189 +7,15 @@ import { BrepFile, ShapesFactory } from './occapi'; import { IOperatorArg, IOperatorFuncOutput } from './types'; import { OccParser } from './occparser'; -let occ: OpenCascadeInstance; +let occ: OCC.OpenCascadeInstance; -export function getOcc(): OpenCascadeInstance { +export function getOcc(): OCC.OpenCascadeInstance { if (!occ) { - occ = (self as any).occ as OpenCascadeInstance; + occ = (self as any).occ as OCC.OpenCascadeInstance; } return occ; } -interface IFace { - vertex_coord: Array; - uv_coord: Array; - normal_coord: Array; - tri_indexes: Array; - number_of_triangles: number; -} - -/** - * Convert OpenCascade shapes into `THREE` compatible data types. - * - * @param {Array} shapeData - * @returns {{ - * faceList: any[]; - * edgeList: any[]; - * }} - */ -export function shapeToThree( - shapeData: Array<{ occShape: TopoDS_Shape; jcObject: IJCadObject }> -): { - faceList: any[]; - edgeList: any[]; -} { - const oc = getOcc(); - const maxDeviation = 0.5; - const faceList: Array = []; - const edgeList = []; - const triangulations: Array = []; - shapeData.forEach(data => { - const { occShape: shape, jcObject } = data; - if (!jcObject.visible) { - return; - } - new oc.BRepMesh_IncrementalMesh_2( - shape, - maxDeviation, - false, - maxDeviation * 5, - true - ); - - const expl = new oc.TopExp_Explorer_2( - shape, - oc.TopAbs_ShapeEnum.TopAbs_FACE as any, - oc.TopAbs_ShapeEnum.TopAbs_SHAPE as any - ); - expl.Init( - shape, - oc.TopAbs_ShapeEnum.TopAbs_FACE as any, - oc.TopAbs_ShapeEnum.TopAbs_SHAPE as any - ); - while (expl.More()) { - const face = oc.TopoDS.Face_1(expl.Current()); - const aLocation = new oc.TopLoc_Location_1(); - const myT = oc.BRep_Tool.Triangulation(face, aLocation); - if (myT.IsNull()) { - console.error('Encountered Null Face!'); - return; - } - const thisFace: IFace = { - vertex_coord: [], - uv_coord: [], - normal_coord: [], - tri_indexes: [], - number_of_triangles: 0 - }; - const pc = new oc.Poly_Connect_2(myT); - const nodes = myT.get().Nodes(); - - thisFace.vertex_coord = new Array(nodes.Length() * 3); - for (let i = 0; i < nodes.Length(); i++) { - const p = nodes.Value(i + 1).Transformed(aLocation.Transformation()); - thisFace.vertex_coord[i * 3 + 0] = p.X(); - thisFace.vertex_coord[i * 3 + 1] = p.Y(); - thisFace.vertex_coord[i * 3 + 2] = p.Z(); - } - // Write UV buffer - const orient = face.Orientation_1(); - if (myT.get().HasUVNodes()) { - // Get UV Bounds - let UMin = 0, - UMax = 0, - VMin = 0, - VMax = 0; - - const UVNodes = myT.get().UVNodes(), - UVNodesLength = UVNodes.Length(); - thisFace.uv_coord = new Array(UVNodesLength * 2); - for (let i = 0; i < UVNodesLength; i++) { - const p = UVNodes.Value(i + 1); - const x = p.X(), - y = p.Y(); - thisFace.uv_coord[i * 2 + 0] = x; - thisFace.uv_coord[i * 2 + 1] = y; - - // Compute UV Bounds - if (i === 0) { - UMin = x; - UMax = x; - VMin = y; - VMax = y; - } - if (x < UMin) { - UMin = x; - } else if (x > UMax) { - UMax = x; - } - if (y < VMin) { - VMin = y; - } else if (y > VMax) { - VMax = y; - } - } - - // Normalize each face's UVs to 0-1 - for (let i = 0; i < UVNodesLength; i++) { - let x = thisFace.uv_coord[i * 2 + 0], - y = thisFace.uv_coord[i * 2 + 1]; - - x = (x - UMin) / (UMax - UMin); - y = (y - VMin) / (VMax - VMin); - if (orient !== oc.TopAbs_Orientation.TopAbs_FORWARD) { - x = 1.0 - x; - } - - thisFace.uv_coord[i * 2 + 0] = x; - thisFace.uv_coord[i * 2 + 1] = y; - } - } - // Write normal buffer - const myNormal = new oc.TColgp_Array1OfDir_2( - nodes.Lower(), - nodes.Upper() - ); - // let SST = new oc.StdPrs_ToolTriangulatedShape(); - oc.StdPrs_ToolTriangulatedShape.Normal(face, pc, myNormal); - thisFace.normal_coord = new Array(myNormal.Length() * 3); - for (let i = 0; i < myNormal.Length(); i++) { - const d = myNormal.Value(i + 1).Transformed(aLocation.Transformation()); - thisFace.normal_coord[i * 3 + 0] = d.X(); - thisFace.normal_coord[i * 3 + 1] = d.Y(); - thisFace.normal_coord[i * 3 + 2] = d.Z(); - } - - // Write triangle buffer - const triangles = myT.get().Triangles(); - thisFace.tri_indexes = new Array(triangles.Length() * 3); - let validFaceTriCount = 0; - for (let nt = 1; nt <= myT.get().NbTriangles(); nt++) { - const t = triangles.Value(nt); - let n1 = t.Value(1); - let n2 = t.Value(2); - const n3 = t.Value(3); - if (orient !== oc.TopAbs_Orientation.TopAbs_FORWARD) { - const tmp = n1; - n1 = n2; - n2 = tmp; - } - - thisFace.tri_indexes[validFaceTriCount * 3 + 0] = n1 - 1; - thisFace.tri_indexes[validFaceTriCount * 3 + 1] = n2 - 1; - thisFace.tri_indexes[validFaceTriCount * 3 + 2] = n3 - 1; - validFaceTriCount++; - } - thisFace.number_of_triangles = validFaceTriCount; - faceList.push(thisFace); - triangulations.push(myT); - expl.Next(); - } - }); - - return { faceList, edgeList }; -} - function buildModel( model: IJCadContent ): { shapeData: IOperatorFuncOutput; jcObject: IJCadObject }[] { diff --git a/packages/jupytercad-extension/src/worker/occapi.ts b/packages/jupytercad-extension/src/worker/occapi.ts index 79951a33..cc068f60 100644 --- a/packages/jupytercad-extension/src/worker/occapi.ts +++ b/packages/jupytercad-extension/src/worker/occapi.ts @@ -1,4 +1,4 @@ -import { TopoDS_Shape } from '@jupytercad/jupytercad-opencascade'; +import { OCC } from '@jupytercad/jupytercad-opencascade'; import { v4 as uuid } from 'uuid'; import { IBox } from '../_interface/box'; @@ -21,13 +21,13 @@ import { toRad } from './utils'; import { IAny } from '../_interface/any'; function setShapePlacement( - shape: TopoDS_Shape, + shape: OCC.TopoDS_Shape, placement?: { Position: number[]; Axis: number[]; Angle: number; } -): TopoDS_Shape { +): OCC.TopoDS_Shape { if (!placement) { return shape; } @@ -48,11 +48,11 @@ function setShapePlacement( ) ); const loc = new oc.TopLoc_Location_2(trsf); - shape.Location_2(loc); + shape.Location_2(loc, true); return shape; } -function _Box(arg: IBox, _: IJCadContent): TopoDS_Shape | undefined { +function _Box(arg: IBox, _: IJCadContent): OCC.TopoDS_Shape | undefined { const { Length, Width, Height, Placement } = arg; const oc = getOcc(); const box = new oc.BRepPrimAPI_MakeBox_2(Length, Width, Height); @@ -60,7 +60,10 @@ function _Box(arg: IBox, _: IJCadContent): TopoDS_Shape | undefined { return setShapePlacement(shape, Placement); } -function _Cylinder(arg: ICylinder, _: IJCadContent): TopoDS_Shape | undefined { +function _Cylinder( + arg: ICylinder, + _: IJCadContent +): OCC.TopoDS_Shape | undefined { const { Radius, Height, Angle, Placement } = arg; const oc = getOcc(); const cylinder = new oc.BRepPrimAPI_MakeCylinder_2( @@ -72,7 +75,7 @@ function _Cylinder(arg: ICylinder, _: IJCadContent): TopoDS_Shape | undefined { return setShapePlacement(shape, Placement); } -function _Sphere(arg: ISphere, _: IJCadContent): TopoDS_Shape | undefined { +function _Sphere(arg: ISphere, _: IJCadContent): OCC.TopoDS_Shape | undefined { const { Radius, Angle1, Angle2, Angle3, Placement } = arg; const oc = getOcc(); const sphere = new oc.BRepPrimAPI_MakeSphere_4( @@ -85,7 +88,7 @@ function _Sphere(arg: ISphere, _: IJCadContent): TopoDS_Shape | undefined { return setShapePlacement(shape, Placement); } -function _Cone(arg: ICone, _: IJCadContent): TopoDS_Shape | undefined { +function _Cone(arg: ICone, _: IJCadContent): OCC.TopoDS_Shape | undefined { const { Radius1, Radius2, Height, Angle, Placement } = arg; const oc = getOcc(); const cone = new oc.BRepPrimAPI_MakeCone_2( @@ -98,7 +101,7 @@ function _Cone(arg: ICone, _: IJCadContent): TopoDS_Shape | undefined { return setShapePlacement(shape, Placement); } -function _Torus(arg: ITorus, _: IJCadContent): TopoDS_Shape | undefined { +function _Torus(arg: ITorus, _: IJCadContent): OCC.TopoDS_Shape | undefined { const { Radius1, Radius2, Angle1, Angle2, Angle3, Placement } = arg; const oc = getOcc(); const torus = new oc.BRepPrimAPI_MakeTorus_4( @@ -112,7 +115,7 @@ function _Torus(arg: ITorus, _: IJCadContent): TopoDS_Shape | undefined { return setShapePlacement(shape, Placement); } -function _Cut(arg: ICut, content: IJCadContent): TopoDS_Shape | undefined { +function _Cut(arg: ICut, content: IJCadContent): OCC.TopoDS_Shape | undefined { const { Placement, Base, Tool } = arg; const oc = getOcc(); const baseObject = content.objects.filter(obj => obj.name === Base); @@ -139,7 +142,11 @@ function _Cut(arg: ICut, content: IJCadContent): TopoDS_Shape | undefined { if (base && tool) { baseObject[0].visible = false; toolObject[0].visible = false; - const operator = new oc.BRepAlgoAPI_Cut_3(base.occShape, tool.occShape); + const operator = new oc.BRepAlgoAPI_Cut_3( + base.occShape, + tool.occShape, + new oc.Message_ProgressRange_1() + ); if (operator.IsDone()) { return setShapePlacement(operator.Shape(), Placement); } @@ -147,10 +154,13 @@ function _Cut(arg: ICut, content: IJCadContent): TopoDS_Shape | undefined { } } -function _Fuse(arg: IFuse, content: IJCadContent): TopoDS_Shape | undefined { +function _Fuse( + arg: IFuse, + content: IJCadContent +): OCC.TopoDS_Shape | undefined { const oc = getOcc(); const { Shapes, Placement } = arg; - const occShapes: TopoDS_Shape[] = []; + const occShapes: OCC.TopoDS_Shape[] = []; Shapes.forEach(Base => { const baseObject = content.objects.filter(obj => obj.name === Base); if (baseObject.length === 0) { @@ -168,7 +178,11 @@ function _Fuse(arg: IFuse, content: IJCadContent): TopoDS_Shape | undefined { } } }); - const operator = new oc.BRepAlgoAPI_Fuse_3(occShapes[0], occShapes[1]); + const operator = new oc.BRepAlgoAPI_Fuse_3( + occShapes[0], + occShapes[1], + new oc.Message_ProgressRange_1() + ); if (operator.IsDone()) { return setShapePlacement(operator.Shape(), Placement); } @@ -178,10 +192,10 @@ function _Fuse(arg: IFuse, content: IJCadContent): TopoDS_Shape | undefined { function _Intersection( arg: IIntersection, content: IJCadContent -): TopoDS_Shape | undefined { +): OCC.TopoDS_Shape | undefined { const oc = getOcc(); const { Shapes, Placement } = arg; - const occShapes: TopoDS_Shape[] = []; + const occShapes: OCC.TopoDS_Shape[] = []; Shapes.forEach(Base => { const baseObject = content.objects.filter(obj => obj.name === Base); if (baseObject.length === 0) { @@ -199,7 +213,11 @@ function _Intersection( } } }); - const operator = new oc.BRepAlgoAPI_Common_3(occShapes[0], occShapes[1]); + const operator = new oc.BRepAlgoAPI_Common_3( + occShapes[0], + occShapes[1], + new oc.Message_ProgressRange_1() + ); if (operator.IsDone()) { return setShapePlacement(operator.Shape(), Placement); } @@ -209,7 +227,7 @@ function _Intersection( export function _SketchObject( arg: ISketchObject, content: IJCadContent -): TopoDS_Shape | undefined { +): OCC.TopoDS_Shape | undefined { const oc = getOcc(); const builder = new oc.BRep_Builder(); const compound = new oc.TopoDS_Compound(); @@ -237,7 +255,7 @@ export function _SketchObject( function _Extrude( arg: IExtrusion, content: IJCadContent -): TopoDS_Shape | undefined { +): OCC.TopoDS_Shape | undefined { const { Base, Dir, LengthFwd, LengthRev, Placement, Solid } = arg; const oc = getOcc(); const baseObject = content.objects.filter(obj => obj.name === Base); @@ -266,7 +284,7 @@ function _Extrude( const mov = new oc.gp_Trsf_1(); mov.SetTranslation_1(dirVec.Multiplied(-LengthRev)); const loc = new oc.TopLoc_Location_2(mov); - baseCopy.Move(loc); + baseCopy.Move(loc, true); } if (Solid) { @@ -305,7 +323,7 @@ function _Extrude( export function _Any( arg: IAny, content: IJCadContent -): TopoDS_Shape | undefined { +): OCC.TopoDS_Shape | undefined { const { Shape, Placement } = arg; const result = _loadBrep({ content: Shape }); if (result) { @@ -313,7 +331,9 @@ export function _Any( } } -export function _loadBrep(arg: { content: string }): TopoDS_Shape | undefined { +export function _loadBrep(arg: { + content: string; +}): OCC.TopoDS_Shape | undefined { const oc = getOcc(); const fakeFileName = `${uuid()}.brep`; oc.FS.createDataFile('/', fakeFileName, arg.content, true, true, true); diff --git a/packages/jupytercad-extension/src/worker/occparser.ts b/packages/jupytercad-extension/src/worker/occparser.ts index e70c1ea2..ceb70c29 100644 --- a/packages/jupytercad-extension/src/worker/occparser.ts +++ b/packages/jupytercad-extension/src/worker/occparser.ts @@ -1,9 +1,5 @@ import { IDict, IParsedShape } from '../types'; -import { - Handle_Poly_Triangulation, - OpenCascadeInstance, - TopoDS_Shape -} from '@jupytercad/jupytercad-opencascade'; +import { OCC } from '@jupytercad/jupytercad-opencascade'; import { IJCadObject } from '../_interface/jcad'; import { IEdge, IFace } from '../types'; @@ -16,7 +12,7 @@ interface IShapeList { export class OccParser { private _shapeList: IShapeList[]; - private _occ: OpenCascadeInstance = (self as any).occ; + private _occ: OCC.OpenCascadeInstance = (self as any).occ; private _showEdge = true; constructor(shapeList: IShapeList[]) { this._shapeList = shapeList; @@ -55,7 +51,7 @@ export class OccParser { } private _build_wire_mesh( - shape: TopoDS_Shape, + shape: OCC.TopoDS_Shape, maxDeviation: number ): Array { const edgeList: Array = []; @@ -99,9 +95,9 @@ export class OccParser { return edgeList; } - private _build_face_mesh(shape: TopoDS_Shape): Array { + private _build_face_mesh(shape: OCC.TopoDS_Shape): Array { const faceList: Array = []; - const triangulations: Array = []; + const triangulations: Array = []; const oc = this._occ; const expl = new oc.TopExp_Explorer_2( shape, @@ -117,7 +113,7 @@ export class OccParser { while (expl.More()) { const face = oc.TopoDS.Face_1(expl.Current()); const aLocation = new oc.TopLoc_Location_1(); - const myT = oc.BRep_Tool.Triangulation(face, aLocation); + const myT = oc.BRep_Tool.Triangulation(face, aLocation, 0); if (myT.IsNull()) { console.error('Encountered Null Face!'); expl.Next(); @@ -130,11 +126,14 @@ export class OccParser { numberOfTriangles: 0 }; const pc = new oc.Poly_Connect_2(myT); - const nodes = myT.get().Nodes(); + const triangulation = myT.get(); + const nbNodes = triangulation.NbNodes(); - thisFace.vertexCoord = new Array(nodes.Length() * 3); - for (let i = 0; i < nodes.Length(); i++) { - const p = nodes.Value(i + 1).Transformed(aLocation.Transformation()); + thisFace.vertexCoord = new Array(nbNodes * 3); + for (let i = 0; i < nbNodes; i++) { + const p = triangulation + .Node(i + 1) + .Transformed(aLocation.Transformation()); thisFace.vertexCoord[i * 3 + 0] = p.X(); thisFace.vertexCoord[i * 3 + 1] = p.Y(); thisFace.vertexCoord[i * 3 + 2] = p.Z(); @@ -143,11 +142,7 @@ export class OccParser { const orient = face.Orientation_1(); // Write normal buffer - const myNormal = new oc.TColgp_Array1OfDir_2( - nodes.Lower(), - nodes.Upper() - ); - // let SST = new oc.StdPrs_ToolTriangulatedShape(); + const myNormal = new oc.TColgp_Array1OfDir_2(1, nbNodes); oc.StdPrs_ToolTriangulatedShape.Normal(face, pc, myNormal); thisFace.normalCoord = new Array(myNormal.Length() * 3); for (let i = 0; i < myNormal.Length(); i++) { @@ -157,12 +152,13 @@ export class OccParser { thisFace.normalCoord[i * 3 + 2] = d.Z(); } + const nbTriangles = triangulation.NbTriangles(); + // Write triangle buffer - const triangles = myT.get().Triangles(); - thisFace.triIndexes = new Array(triangles.Length() * 3); + thisFace.triIndexes = new Array(nbTriangles * 3); let validFaceTriCount = 0; for (let nt = 1; nt <= myT.get().NbTriangles(); nt++) { - const t = triangles.Value(nt); + const t = triangulation.Triangle(nt); let n1 = t.Value(1); let n2 = t.Value(2); const n3 = t.Value(3); @@ -184,7 +180,7 @@ export class OccParser { } return faceList; } - private _build_edge_mesh(shape: TopoDS_Shape): IEdge[] { + private _build_edge_mesh(shape: OCC.TopoDS_Shape): IEdge[] { const oc = this._occ; const edgeList: IEdge[] = []; const mapOfShape = new oc.TopTools_IndexedMapOfShape_1(); @@ -221,8 +217,9 @@ export class OccParser { if (!aLoc.IsIdentity()) { myTransf = aLoc.Transformation(); } + const poly = aPoly.get(); - nbNodesInFace = aPoly.get().NbNodes(); + nbNodesInFace = poly.NbNodes(); theEdge.numberOfCoords = nbNodesInFace; theEdge.vertexCoord = new Array(nbNodesInFace * 3); @@ -236,7 +233,7 @@ export class OccParser { } } else { const aFace = oc.TopoDS.Face_1(edgeMap.FindFromIndex(iEdge).First_1()); - const aPolyTria = oc.BRep_Tool.Triangulation(aFace, aLoc); + const aPolyTria = oc.BRep_Tool.Triangulation(aFace, aLoc, 0); if (!aLoc.IsIdentity()) { myTransf = aLoc.Transformation(); } @@ -253,12 +250,12 @@ export class OccParser { theEdge.vertexCoord = new Array(nbNodesInFace * 3); const indices = aPoly.get().Nodes(); - const nodeListOfFace = aPolyTria.get().Nodes(); + const nodeListOfFace = aPolyTria.get(); for (let jj = indices.Lower(); jj <= indices.Upper(); jj++) { - const v = nodeListOfFace.Value(indices.Value(jj)); + const v = nodeListOfFace.Node(indices.Value(jj)); v.Transform(myTransf); - const locIndex = jj - nodeListOfFace.Lower(); + const locIndex = jj - 1; theEdge.vertexCoord[locIndex * 3 + 0] = v.X(); theEdge.vertexCoord[locIndex * 3 + 1] = v.Y(); diff --git a/packages/jupytercad-extension/src/worker/operatorcache.ts b/packages/jupytercad-extension/src/worker/operatorcache.ts index 79cabca7..49888e12 100644 --- a/packages/jupytercad-extension/src/worker/operatorcache.ts +++ b/packages/jupytercad-extension/src/worker/operatorcache.ts @@ -1,4 +1,4 @@ -import { TopoDS_Shape } from '@jupytercad/jupytercad-opencascade'; +import { OCC } from '@jupytercad/jupytercad-opencascade'; import { IJCadContent, Parts, IShapeMetadata } from '../_interface/jcad'; import { IDict } from '../types'; @@ -7,7 +7,7 @@ import { getOcc } from './actions'; const SHAPE_CACHE = new Map< string, - { occShape: TopoDS_Shape; metadata?: IShapeMetadata | undefined } + { occShape: OCC.TopoDS_Shape; metadata?: IShapeMetadata | undefined } >(); const PRIMITIVE_OPERATORS = [ @@ -112,7 +112,7 @@ export function expand_operator( return expanded_args; } -export function shape_meta_data(shape: TopoDS_Shape): IShapeMetadata { +export function shape_meta_data(shape: OCC.TopoDS_Shape): IShapeMetadata { const occ = getOcc(); const system = new occ.GProp_GProps_1(); occ.BRepGProp.VolumeProperties_1(shape, system, false, false, false); @@ -144,13 +144,13 @@ export function shape_meta_data(shape: TopoDS_Shape): IShapeMetadata { } export function operatorCache( name: Parts | 'BrepFile', - ops: (args: T, content: IJCadContent) => TopoDS_Shape | undefined + ops: (args: T, content: IJCadContent) => OCC.TopoDS_Shape | undefined ) { return ( args: T, content: IJCadContent ): - | { occShape: TopoDS_Shape; metadata?: IShapeMetadata | undefined } + | { occShape: OCC.TopoDS_Shape; metadata?: IShapeMetadata | undefined } | undefined => { const expandedArgs = expand_operator(name, args, content); const hash = `${hashCode(JSON.stringify(expandedArgs))}`; diff --git a/packages/jupytercad-extension/src/worker/types.ts b/packages/jupytercad-extension/src/worker/types.ts index 267986cf..d8443deb 100644 --- a/packages/jupytercad-extension/src/worker/types.ts +++ b/packages/jupytercad-extension/src/worker/types.ts @@ -1,5 +1,5 @@ import { IJCadContent, IShapeMetadata } from '../_interface/jcad'; -import { TopoDS_Shape } from '@jupytercad/jupytercad-opencascade'; +import { OCC } from '@jupytercad/jupytercad-opencascade'; import { IBox } from '../_interface/box'; import { ICylinder } from '../_interface/cylinder'; import { ISphere } from '../_interface/sphere'; @@ -13,7 +13,7 @@ import { IExtrusion } from '../_interface/extrusion'; import { IAny } from '../_interface/any'; export interface IOperatorFuncOutput { - occShape: TopoDS_Shape; + occShape: OCC.TopoDS_Shape; metadata?: IShapeMetadata | undefined; } diff --git a/packages/jupytercad-extension/src/worker/worker.ts b/packages/jupytercad-extension/src/worker/worker.ts index 5fb3da33..e6893338 100644 --- a/packages/jupytercad-extension/src/worker/worker.ts +++ b/packages/jupytercad-extension/src/worker/worker.ts @@ -1,6 +1,4 @@ -import initOpenCascade, { - OpenCascadeInstance -} from '@jupytercad/jupytercad-opencascade'; +import { initializeOpenCascade, OCC } from '@jupytercad/jupytercad-opencascade'; import { WorkerAction, IWorkerMessage, @@ -10,11 +8,11 @@ import { } from '../types'; import WorkerHandler from './actions'; -let occ: OpenCascadeInstance; +let occ: OCC.OpenCascadeInstance; const ports: IDict = {}; console.log('Initializing OCC...'); -initOpenCascade().then(occInstance => { +initializeOpenCascade().then(occInstance => { console.log('Done!'); occ = occInstance; diff --git a/packages/jupytercad-opencascade/build.yml b/packages/jupytercad-opencascade/build.yml index 3227eea5..87e19657 100644 --- a/packages/jupytercad-opencascade/build.yml +++ b/packages/jupytercad-opencascade/build.yml @@ -63,6 +63,8 @@ mainBuild: - symbol: NCollection_BaseList - symbol: NCollection_BaseMap - symbol: Poly_Array1OfTriangle + - symbol: Poly_ArrayOfNodes + - symbol: Poly_ArrayOfUVNodes - symbol: Poly_Connect - symbol: Poly_PolygonOnTriangulation - symbol: Poly_Triangle diff --git a/packages/jupytercad-opencascade/build_opencascade.js b/packages/jupytercad-opencascade/build_opencascade_wasm.js similarity index 97% rename from packages/jupytercad-opencascade/build_opencascade.js rename to packages/jupytercad-opencascade/build_opencascade_wasm.js index 440f8510..2b428a65 100644 --- a/packages/jupytercad-opencascade/build_opencascade.js +++ b/packages/jupytercad-opencascade/build_opencascade_wasm.js @@ -10,7 +10,7 @@ const { const yaml = require('js-yaml'); const path = require('path'); -const IMAGE_NAME = 'donalffons/opencascade.js:2.0.0-beta.371bbb0'; +const IMAGE_NAME = 'donalffons/opencascade.js:2.0.0-beta.b5ff984'; const OPEN_CASCADE_DIR = 'lib'; const VERSION_FILE_NAME = 'jupytercad.opencascade.version'; const VERSION_FILE_PATH = path.join(OPEN_CASCADE_DIR, VERSION_FILE_NAME); diff --git a/packages/jupytercad-opencascade/lib/index.d.ts b/packages/jupytercad-opencascade/lib/index.d.ts new file mode 100644 index 00000000..7da2310b --- /dev/null +++ b/packages/jupytercad-opencascade/lib/index.d.ts @@ -0,0 +1,3 @@ +import { OpenCascadeInstance } from './jupytercad-opencascade.js'; +export * as OCC from './jupytercad-opencascade.js'; +export declare function initializeOpenCascade(): Promise; diff --git a/packages/jupytercad-opencascade/lib/index.js b/packages/jupytercad-opencascade/lib/index.js new file mode 100644 index 00000000..ac8a7c9a --- /dev/null +++ b/packages/jupytercad-opencascade/lib/index.js @@ -0,0 +1,9 @@ +import initOpenCascade from 'opencascade.js'; +import opencascade from './jupytercad.opencascade.js'; +import opencascadeWasm from './jupytercad.opencascade.wasm'; +export async function initializeOpenCascade() { + return initOpenCascade({ + mainJS: opencascade, + mainWasm: opencascadeWasm, + }); +} diff --git a/packages/jupytercad-opencascade/package.json b/packages/jupytercad-opencascade/package.json index 6df542ab..2ee0c0bd 100644 --- a/packages/jupytercad-opencascade/package.json +++ b/packages/jupytercad-opencascade/package.json @@ -15,27 +15,29 @@ "name": "JupyterCad contributors" }, "files": [ + "lib/index.js", + "lib/index.d.ts", "lib/jupytercad.opencascade.js", "lib/jupytercad.opencascade.d.ts", "lib/jupytercad.opencascade.wasm" ], - "main": "lib/jupytercad.opencascade.js", - "types": "lib/jupytercad.opencascade.d.ts", + "main": "lib/index.js", + "types": "lib/index.d.ts", "repository": { "type": "git", "url": "https://github.com/jupyter-cad/jupytercad.git" }, "scripts": { - "build": "node build_opencascade.js", - "build:prod": "node build_opencascade.js", - "clean": "rimraf ./lib", - "clean:all": "rimraf ./lib" + "build": "node build_opencascade_wasm.js", + "build:prod": "node build_opencascade_wasm.js" }, "devDependencies": { - "js-yaml": "^4.1.0", - "rimraf": "^3.0.2" + "js-yaml": "^4.1.0" }, "publishConfig": { "access": "public" + }, + "dependencies": { + "opencascade.js": "beta" } } diff --git a/yarn.lock b/yarn.lock index 09c0e93f..8c4b4cff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -969,7 +969,7 @@ __metadata: resolution: "@jupytercad/jupytercad-opencascade@workspace:packages/jupytercad-opencascade" dependencies: js-yaml: ^4.1.0 - rimraf: ^3.0.2 + opencascade.js: beta languageName: unknown linkType: soft @@ -9591,6 +9591,15 @@ __metadata: languageName: node linkType: hard +"opencascade.js@npm:beta": + version: 2.0.0-beta.b5ff984 + resolution: "opencascade.js@npm:2.0.0-beta.b5ff984" + peerDependencies: + ws: ^8.5.0 + checksum: 751fa25e3625497fb562d4c586e884020478b9c5aeae61c43ce10bac9a011826f5c7518c2126fc6b1f79792c83bbc4d43069bff40dfbee4e48137cb9a496424e + languageName: node + linkType: hard + "optionator@npm:^0.9.1": version: 0.9.3 resolution: "optionator@npm:0.9.3" @@ -12098,21 +12107,21 @@ __metadata: "typescript@patch:typescript@^3 || ^4#~builtin": version: 4.9.5 - resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin::version=4.9.5&hash=289587" + resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin::version=4.9.5&hash=23ec76" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 1f8f3b6aaea19f0f67cba79057674ba580438a7db55057eb89cc06950483c5d632115c14077f6663ea76fd09fce3c190e6414bb98582ec80aa5a4eaf345d5b68 + checksum: ab417a2f398380c90a6cf5a5f74badd17866adf57f1165617d6a551f059c3ba0a3e4da0d147b3ac5681db9ac76a303c5876394b13b3de75fdd5b1eaa06181c9d languageName: node linkType: hard "typescript@patch:typescript@^5#~builtin": version: 5.2.2 - resolution: "typescript@patch:typescript@npm%3A5.2.2#~builtin::version=5.2.2&hash=f3b441" + resolution: "typescript@patch:typescript@npm%3A5.2.2#~builtin::version=5.2.2&hash=85af82" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 0f4da2f15e6f1245e49db15801dbee52f2bbfb267e1c39225afdab5afee1a72839cd86000e65ee9d7e4dfaff12239d28beaf5ee431357fcced15fb08583d72ca + checksum: 07106822b4305de3f22835cbba949a2b35451cad50888759b6818421290ff95d522b38ef7919e70fb381c5fe9c1c643d7dea22c8b31652a717ddbd57b7f4d554 languageName: node linkType: hard