UNPKG

@bitbybit-dev/occt

Version:

Bit By Bit Developers CAD algorithms using OpenCascade Technology kernel. Run in Node and in Browser.

132 lines (131 loc) 6.4 kB
export class OCCTSolid { constructor(occ, och) { this.occ = occ; this.och = och; } fromClosedShell(inputs) { return this.och.solidsService.fromClosedShell(inputs); } createBox(inputs) { return this.och.solidsService.createBox(inputs); } createCube(inputs) { return this.och.solidsService.createCube(inputs); } createBoxFromCorner(inputs) { return this.och.solidsService.createBoxFromCorner(inputs); } createCylinder(inputs) { return this.och.solidsService.createCylinder(inputs); } createCylindersOnLines(inputs) { return this.och.solidsService.createCylindersOnLines(inputs); } createSphere(inputs) { return this.och.solidsService.createSphere(inputs); } createCone(inputs) { return this.och.solidsService.createCone(inputs); } createIBeamProfileSolid(inputs) { const wire = this.och.wiresService.createIBeamProfileWire(inputs); const face = this.och.facesService.createFaceFromWire({ shape: wire, planar: true }); return this.extrudeFaceToSolid(face, inputs.direction, inputs.extrusionLengthFront, inputs.extrusionLengthBack); } createHBeamProfileSolid(inputs) { const wire = this.och.wiresService.createHBeamProfileWire(inputs); const face = this.och.facesService.createFaceFromWire({ shape: wire, planar: true }); return this.extrudeFaceToSolid(face, inputs.direction, inputs.extrusionLengthFront, inputs.extrusionLengthBack); } createTBeamProfileSolid(inputs) { const wire = this.och.wiresService.createTBeamProfileWire(inputs); const face = this.och.facesService.createFaceFromWire({ shape: wire, planar: true }); return this.extrudeFaceToSolid(face, inputs.direction, inputs.extrusionLengthFront, inputs.extrusionLengthBack); } createUBeamProfileSolid(inputs) { const wire = this.och.wiresService.createUBeamProfileWire(inputs); const face = this.och.facesService.createFaceFromWire({ shape: wire, planar: true }); return this.extrudeFaceToSolid(face, inputs.direction, inputs.extrusionLengthFront, inputs.extrusionLengthBack); } createStarSolid(inputs) { const wire = this.och.wiresService.createStarWire(inputs); const face = this.och.facesService.createFaceFromWire({ shape: wire, planar: true }); return this.extrudeFaceToSolid(face, inputs.direction, inputs.extrusionLengthFront, inputs.extrusionLengthBack); } createNGonSolid(inputs) { const wire = this.och.wiresService.createNGonWire(inputs); const face = this.och.facesService.createFaceFromWire({ shape: wire, planar: true }); return this.extrudeFaceToSolid(face, inputs.direction, inputs.extrusionLengthFront, inputs.extrusionLengthBack); } createParallelogramSolid(inputs) { const wire = this.och.wiresService.createParallelogramWire(inputs); const face = this.och.facesService.createFaceFromWire({ shape: wire, planar: true }); return this.extrudeFaceToSolid(face, inputs.direction, inputs.extrusionLengthFront, inputs.extrusionLengthBack); } createHeartSolid(inputs) { const wire = this.och.wiresService.createHeartWire(inputs); const face = this.och.facesService.createFaceFromWire({ shape: wire, planar: true }); return this.extrudeFaceToSolid(face, inputs.direction, inputs.extrusionLengthFront, inputs.extrusionLengthBack); } createChristmasTreeSolid(inputs) { const wire = this.och.wiresService.createChristmasTreeWire(inputs); const face = this.och.facesService.createFaceFromWire({ shape: wire, planar: true }); return this.extrudeFaceToSolid(face, inputs.direction, inputs.extrusionLengthFront, inputs.extrusionLengthBack); } createLPolygonSolid(inputs) { const wire = this.och.wiresService.createLPolygonWire(inputs); const face = this.och.facesService.createFaceFromWire({ shape: wire, planar: true }); return this.extrudeFaceToSolid(face, inputs.direction, inputs.extrusionLengthFront, inputs.extrusionLengthBack); } extrudeFaceToSolid(face, direction, lengthFront, lengthBack) { // Normalize direction const length = Math.sqrt(Math.pow(direction[0], 2) + Math.pow(direction[1], 2) + Math.pow(direction[2], 2)); const normalizedDir = [ direction[0] / length, direction[1] / length, direction[2] / length ]; // Create forward extrusion const frontVec = new this.occ.gp_Vec_4(normalizedDir[0] * lengthFront, normalizedDir[1] * lengthFront, normalizedDir[2] * lengthFront); const frontPrism = new this.occ.BRepPrimAPI_MakePrism_1(face, frontVec, false, true); let result = frontPrism.Shape(); frontPrism.delete(); frontVec.delete(); // If there's backward extrusion, add it if (lengthBack > 0) { const backVec = new this.occ.gp_Vec_4(-normalizedDir[0] * lengthBack, -normalizedDir[1] * lengthBack, -normalizedDir[2] * lengthBack); const backPrism = new this.occ.BRepPrimAPI_MakePrism_1(face, backVec, false, true); const backShape = backPrism.Shape(); backPrism.delete(); backVec.delete(); // Fuse the two solids const fused = this.och.booleansService.union({ shapes: [result, backShape], keepEdges: false }); result.delete(); backShape.delete(); result = fused; } face.delete(); return this.och.converterService.getActualTypeOfShape(result); } getSolidSurfaceArea(inputs) { return this.och.solidsService.getSolidSurfaceArea(inputs); } getSolidVolume(inputs) { return this.och.solidsService.getSolidVolume(inputs); } getSolidsVolumes(inputs) { return this.och.solidsService.getSolidsVolumes(inputs); } getSolidCenterOfMass(inputs) { return this.och.solidsService.getSolidCenterOfMass(inputs); } getSolidsCentersOfMass(inputs) { return this.och.solidsService.getSolidsCentersOfMass(inputs); } getSolids(inputs) { return this.och.solidsService.getSolids(inputs); } filterSolidPoints(inputs) { return this.och.solidsService.filterSolidPoints(inputs); } }