diff --git a/modules/brep/io/brepIO.ts b/modules/brep/io/brepIO.ts index 458bf6e8..3c63adb4 100644 --- a/modules/brep/io/brepIO.ts +++ b/modules/brep/io/brepIO.ts @@ -10,9 +10,9 @@ import NullSurface from 'geom/surfaces/nullSurface'; import BBox from 'math/bbox'; import NurbsCurve from 'geom/curves/nurbsCurve'; import BrepCurve from 'geom/curves/brepCurve'; -import {BREPData} from "../../../web/app/cad/craft/engine/brepData"; -import {ProductionInfo} from "../../../web/app/cad/craft/engine/productionInfo"; -import {Tessellation1D} from "../../../web/app/cad/craft/engine/tessellation"; +import {BREPData} from "engine/data/brepData"; +import {ProductionInfo} from "engine/productionInfo"; +import {Tessellation1D} from "engine/tessellation"; //Extensions for topo objects declare module '../topo/shell' { diff --git a/modules/brep/topo/edge.ts b/modules/brep/topo/edge.ts index 9a27db28..f75697b4 100644 --- a/modules/brep/topo/edge.ts +++ b/modules/brep/topo/edge.ts @@ -3,7 +3,7 @@ import {Vertex} from "./vertex"; import BrepCurve from "geom/curves/brepCurve"; import {Loop} from "./loop"; import Vector from "math/vector"; -import {Tessellation1D} from "../../../web/app/cad/craft/engine/tessellation"; +import {Tessellation1D} from "engine/tessellation"; export class Edge extends TopoObject { diff --git a/modules/engine/api.ts b/modules/engine/api.ts new file mode 100644 index 00000000..fd1232cd --- /dev/null +++ b/modules/engine/api.ts @@ -0,0 +1,104 @@ +import {OperationResult} from "../../web/app/cad/craft/craftPlugin"; +import {BREPData} from "./data/brepData"; +import {Handle} from "./data/handle"; +import {Vec3} from "math/vec"; +import {PrimitiveData} from "engine/data/primitiveData"; + +export enum BooleanType { + UNION = 1, + SUBTRACT, + INTERSECT, +} + +export interface OperationError { + error: boolean; + message?: string; +} + +export type BREPResponse = BREPData | OperationError + +export interface EngineAPI_V1 { + + /** + * Extrudes a set of 2d paths to 3d object along with the given direction + */ + extrude(params: { + + /** + * Extrude direction + */ + vector: Vec3; + + /** + * Sketch to be extruded. Can be thought as a set of wires in the occt terminology + */ + sketch: PrimitiveData[][]; + + /** + * Engine operation tolerance. + */ + tolerance: number; + + /** + * Tessellation detail parameter. + */ + deflection: number; + + /** + * extruded object can be used as a boolean modifier on a given shell + */ + boolean: { + + type: BooleanType; + + /** + * An operand on which the boolean operation will be performed + */ + operand: Handle; + } + + }): BREPResponse; + + boolean(params: { + + type: BooleanType; + + operandsA: Handle[], + + operandsB: Handle[], + + /** + * Engine operation tolerance. + */ + tolerance: number; + + /** + * Tessellation detail parameter. + */ + deflection: number; + + }): BREPResponse; + + createBox(params: {}): OperationResult; + + createSphere(params: {}): OperationResult; + + createCone(params: {}): OperationResult; + + createCylinder(params: {}): OperationResult; + + createTorus(params: {}): OperationResult; + + + stepImport(params: {}): OperationResult; + +} + +export interface EngineSession { + + load(): Handle; + + dispose(): void; + +} + diff --git a/web/app/cad/craft/engine/brepData.d.ts b/modules/engine/data/brepData.ts similarity index 87% rename from web/app/cad/craft/engine/brepData.d.ts rename to modules/engine/data/brepData.ts index 55c8d585..d85c6ff5 100644 --- a/web/app/cad/craft/engine/brepData.d.ts +++ b/modules/engine/data/brepData.ts @@ -1,5 +1,5 @@ -import {Tessellation1D, Tessellation2D} from "./tessellation"; -import {ProductionInfo} from "./productionInfo"; +import {Tessellation1D, Tessellation2D} from "../tessellation"; +import {ProductionInfo} from "../productionInfo"; import {Handle} from "./handle"; import {SurfaceBSplineData, SurfacePlaneData, SurfaceUnknownData} from "./surfaceData"; import {CurveBSplineData, CurveLineData, CurveUnknownData} from "./curveData"; diff --git a/web/app/cad/craft/engine/curveData.d.ts b/modules/engine/data/curveData.ts similarity index 100% rename from web/app/cad/craft/engine/curveData.d.ts rename to modules/engine/data/curveData.ts diff --git a/modules/engine/data/handle.ts b/modules/engine/data/handle.ts new file mode 100644 index 00000000..07b6b8ea --- /dev/null +++ b/modules/engine/data/handle.ts @@ -0,0 +1,4 @@ +/** + * Represents a notion of an internal reference of an engine. For example a pointer in web assembly code + */ +export type Handle = number; diff --git a/modules/engine/data/primitiveData.ts b/modules/engine/data/primitiveData.ts new file mode 100644 index 00000000..22424637 --- /dev/null +++ b/modules/engine/data/primitiveData.ts @@ -0,0 +1,35 @@ +import {Vec3} from "math/vec"; +import {NurbsCurveData} from "geom/curves/nurbsCurveData"; + +export enum PRIMITIVE_TYPES { + SEGMENT = 1, + B_SPLINE, + CIRCLE, + ARC +} + +export interface CirclePrimitiveData { + TYPE: PRIMITIVE_TYPES.CIRCLE; + c: Vec3; + r: number; + dir: Vec3; +} + +export interface ArcPrimitiveData { + TYPE: PRIMITIVE_TYPES.ARC; + a: Vec3; + b: Vec3; + tangent: Vec3; +} + +export interface BSplinePrimitiveData extends NurbsCurveData { + TYPE: PRIMITIVE_TYPES.B_SPLINE; +} + +export interface SegmentPrimitiveData extends NurbsCurveData { + TYPE: PRIMITIVE_TYPES.SEGMENT; + a: Vec3; + b: Vec3; +} + +export type PrimitiveData = SegmentPrimitiveData | CirclePrimitiveData | ArcPrimitiveData | BSplinePrimitiveData; \ No newline at end of file diff --git a/web/app/cad/craft/engine/surfaceData.d.ts b/modules/engine/data/surfaceData.ts similarity index 100% rename from web/app/cad/craft/engine/surfaceData.d.ts rename to modules/engine/data/surfaceData.ts diff --git a/web/app/cad/craft/engine/productionInfo.d.ts b/modules/engine/productionInfo.ts similarity index 100% rename from web/app/cad/craft/engine/productionInfo.d.ts rename to modules/engine/productionInfo.ts diff --git a/web/app/cad/craft/engine/tessellation.d.ts b/modules/engine/tessellation.ts similarity index 100% rename from web/app/cad/craft/engine/tessellation.d.ts rename to modules/engine/tessellation.ts diff --git a/modules/geom/curves/brepCurve.ts b/modules/geom/curves/brepCurve.ts index 2ed362b4..73f73bc3 100644 --- a/modules/geom/curves/brepCurve.ts +++ b/modules/geom/curves/brepCurve.ts @@ -6,7 +6,7 @@ import curveTess from "../impl/curve/curve-tess"; import Point from 'math/vector'; import Vector from 'math/vector'; import cache from "../impl/cache"; -import {Tessellation1D} from "../../../web/app/cad/craft/engine/tessellation"; +import {Tessellation1D} from "engine/tessellation"; import {Matrix3x4} from "math/matrix"; import {areEqual} from "math/equality"; import {Vec3} from "math/vec"; diff --git a/modules/geom/curves/nurbsCurve.ts b/modules/geom/curves/nurbsCurve.ts index e8aea8d1..9c662e19 100644 --- a/modules/geom/curves/nurbsCurve.ts +++ b/modules/geom/curves/nurbsCurve.ts @@ -1,8 +1,9 @@ import * as ext from '../impl/nurbs-ext'; -import {distinctKnots, NurbsCurveData} from '../impl/nurbs-ext'; +import {distinctKnots} from '../impl/nurbs-ext'; import {ParametricCurve} from "./parametricCurve"; import {Matrix3x4Data} from "math/matrix"; import {Vec3} from "math/vec"; +import {NurbsCurveData} from "geom/curves/nurbsCurveData"; //in fact the sketcher format diff --git a/modules/geom/curves/nurbsCurveData.ts b/modules/geom/curves/nurbsCurveData.ts new file mode 100644 index 00000000..e1280487 --- /dev/null +++ b/modules/geom/curves/nurbsCurveData.ts @@ -0,0 +1,8 @@ +import {Vec3} from "math/vec"; + +export interface NurbsCurveData { + degree: number, + controlPoints: Vec3[], + knots: number[], + weights: number[] +} \ No newline at end of file diff --git a/modules/geom/impl/nurbs-ext.ts b/modules/geom/impl/nurbs-ext.ts index c1d94978..a282c2ac 100644 --- a/modules/geom/impl/nurbs-ext.ts +++ b/modules/geom/impl/nurbs-ext.ts @@ -2,22 +2,7 @@ import * as vec from "math/vec"; import {eqEps, TOLERANCE, TOLERANCE_01, TOLERANCE_SQ} from '../tolerance'; import {fmin_bfgs} from "math/optim/bfgs"; import {areEqual} from "math/equality"; -import {Vec3} from "math/vec"; - -export interface NurbsCurveData { - degree: number, - controlPoints: Vec3[], - knots: number[], - weights: number[] -} - -export interface NurbsSurfaceData { - degreeU: number, - degreeV: number, - controlPoints: Vec3[][], - knots: number[][], - weights: number[][] -} +import {NurbsCurveData} from "geom/curves/nurbsCurveData"; export function curveStep(curve, u, tessTol, scale) { diff --git a/modules/geom/surfaces/nurbsSurface.ts b/modules/geom/surfaces/nurbsSurface.ts index 037d9fad..425b672c 100644 --- a/modules/geom/surfaces/nurbsSurface.ts +++ b/modules/geom/surfaces/nurbsSurface.ts @@ -1,4 +1,4 @@ -import {distinctKnots, NurbsSurfaceData} from '../impl/nurbs-ext'; +import {distinctKnots} from '../impl/nurbs-ext'; import cache from '../impl/cache'; import * as ext from '../impl/nurbs-ext'; import NurbsCurve from '../curves/nurbsCurve'; @@ -6,6 +6,7 @@ import {ParametricSurface, UV} from "./parametricSurface"; import {ParametricCurve} from "../curves/parametricCurve"; import {Matrix3x4Data} from "math/matrix"; import {Vec3} from "math/vec"; +import {NurbsSurfaceData} from "geom/surfaces/nurbsSurfaceData"; export default class NurbsSurface implements ParametricSurface { diff --git a/modules/geom/surfaces/nurbsSurfaceData.ts b/modules/geom/surfaces/nurbsSurfaceData.ts new file mode 100644 index 00000000..2f6c2b0c --- /dev/null +++ b/modules/geom/surfaces/nurbsSurfaceData.ts @@ -0,0 +1,9 @@ +import {Vec3} from "math/vec"; + +export interface NurbsSurfaceData { + degreeU: number, + degreeV: number, + controlPoints: Vec3[][], + knots: number[][], + weights: number[][] +} \ No newline at end of file diff --git a/web/app/cad/craft/e0/common.js b/web/app/cad/craft/e0/common.js index 886bbac1..d281dd9f 100644 --- a/web/app/cad/craft/e0/common.js +++ b/web/app/cad/craft/e0/common.js @@ -1,15 +1,4 @@ -export const BOOLEAN_TYPES = { - UNION : 1, - SUBTRACT: 2, - INTERSECT: 3 -}; - -export const CURVE_TYPES = { - SEGMENT: 1, - B_SPLINE: 2, - CIRCLE: 3, - ARC: 4 -}; +import {PRIMITIVE_TYPES} from "engine/data/primitiveData"; export const DEFLECTION = 2; export const E0_TOLERANCE = 1e-3; @@ -46,7 +35,7 @@ export function readSketchContour(contour, face) { if (s.isCurve) { if (s.constructor.name === 'Circle') { const dir = face.csys.z.data(); - path.push({TYPE: CURVE_TYPES.CIRCLE, c: tr.apply(s.c).data(), dir, r: s.r}); + path.push({TYPE: PRIMITIVE_TYPES.CIRCLE, c: tr.apply(s.c).data(), dir, r: s.r}); } else if (s.constructor.name === 'Arc') { let a = s.inverted ? s.b : s.a; let b = s.inverted ? s.a : s.b; @@ -55,14 +44,14 @@ export function readSketchContour(contour, face) { tangent._negate(); } path.push({ - TYPE: CURVE_TYPES.ARC, + TYPE: PRIMITIVE_TYPES.ARC, a: tr.apply(a).data(), b: tr.apply(b).data(), tangent: tangent.data() }); } else { let nurbs = s.toNurbs(face.csys).impl; - path.push(Object.assign({TYPE: CURVE_TYPES.B_SPLINE}, nurbs.serialize())); + path.push(Object.assign({TYPE: PRIMITIVE_TYPES.B_SPLINE}, nurbs.serialize())); } } else { let ab = [s.a, s.b]; @@ -70,7 +59,7 @@ export function readSketchContour(contour, face) { ab.reverse(); } ab = ab.map(v => tr.apply(v).data()); - path.push({TYPE: CURVE_TYPES.SEGMENT, a: ab[0], b: ab[1]}); + path.push({TYPE: PRIMITIVE_TYPES.SEGMENT, a: ab[0], b: ab[1]}); } path[path.length - 1].id = s.id; }); diff --git a/web/app/cad/craft/e0/craftMethods.js b/web/app/cad/craft/e0/craftMethods.js index c3e8fbc0..ce509886 100644 --- a/web/app/cad/craft/e0/craftMethods.js +++ b/web/app/cad/craft/e0/craftMethods.js @@ -1,15 +1,16 @@ import { - BOOLEAN_TYPES, DEFLECTION, E0_TOLERANCE, managedByE0, readShellData, readSketch, readSketchContour, shellsToPointers, + DEFLECTION, E0_TOLERANCE, managedByE0, readShellData, readSketch, readSketchContour, shellsToPointers, singleShellRespone, writeCsys } from './common'; import {callEngine} from './interact'; import {resolveExtrudeVector} from '../cutExtrude/cutExtrude'; import {MOpenFaceShell} from '../../model/mopenFace'; +import {BooleanType} from "engine/api"; export function boolean({type, operandsA, operandsB}) { let engineParams = { - type: BOOLEAN_TYPES[type], + type: BooleanType[type], operandsA: shellsToPointers(operandsA), operandsB: shellsToPointers(operandsB), tolerance: E0_TOLERANCE, @@ -78,9 +79,9 @@ export function stepImport(params) { function booleanBasedOperation(engineParams, params, impl) { engineParams.deflection = DEFLECTION; - if (params.boolean && BOOLEAN_TYPES[params.boolean.type] > 0) { + if (params.boolean && BooleanType[params.boolean.type] > 0) { engineParams.boolean = { - type: BOOLEAN_TYPES[params.boolean.type], + type: BooleanType[params.boolean.type], operands: shellsToPointers(params.boolean.operands), tolerance: E0_TOLERANCE, } @@ -121,7 +122,7 @@ function cutExtrude(isCut, request) { let {request: engineReq, face} = createExtrudeCommand(request, services, isCut); if (managedByE0(face.shell)) { engineReq.boolean = { - type: isCut ? BOOLEAN_TYPES.SUBTRACT : BOOLEAN_TYPES.UNION, + type: isCut ? BooleanType.SUBTRACT : BooleanType.UNION, operand: face.shell.brepShell.data.externals.ptr } } diff --git a/web/app/cad/craft/e0/operationHandler.js b/web/app/cad/craft/e0/operationHandler.js index 8162d4d9..21b3df85 100644 --- a/web/app/cad/craft/e0/operationHandler.js +++ b/web/app/cad/craft/e0/operationHandler.js @@ -1,4 +1,5 @@ -import {BOOLEAN_TYPES, DEFLECTION, E0_TOLERANCE, managedByE0, readSketch, singleShellRespone} from './common'; +import {DEFLECTION, E0_TOLERANCE, managedByE0, readSketch, singleShellRespone} from './common'; +import {BooleanType} from "engine/api"; import {callEngine} from './interact'; import {resolveExtrudeVector} from '../cutExtrude/cutExtrude'; @@ -10,7 +11,7 @@ export default function operationHandler(id, request, services) { let {request: engineReq, face} = createExtrudeCommand(request, services, isCut); if (managedByE0(face.shell)) { engineReq.boolean = { - type: isCut ? BOOLEAN_TYPES.SUBTRACT : BOOLEAN_TYPES.UNION, + type: isCut ? BooleanType.SUBTRACT : BooleanType.UNION, operand: face.shell.brepShell.data.externals.ptr } } @@ -77,9 +78,9 @@ function createRevolveCommand(request, {cadRegistry, sketchStorageService}) { deflection: DEFLECTION } }; - if (managedByE0(face.shell) && request.boolean && BOOLEAN_TYPES[request.boolean] > 0) { + if (managedByE0(face.shell) && request.boolean && BooleanType[request.boolean] > 0) { res.request.boolean = { - type: BOOLEAN_TYPES[request.boolean], + type: BooleanType[request.boolean], operand: face.shell.brepShell.data.externals.ptr } } diff --git a/web/app/cad/craft/engine/engine.d.ts b/web/app/cad/craft/engine/engine.d.ts deleted file mode 100644 index d8ef14b7..00000000 --- a/web/app/cad/craft/engine/engine.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import {OperationResult} from "../craftPlugin"; -import {BREPData} from "./brepData"; -import {Handle} from "./handle"; - -export interface ModellingError { - error: boolean; -} - -export type ModelResponse = BREPData | Error - -export interface ModelingEngine { - - extrude(params: { - - }): ModelResponse[]; - - createBox(params: {}): OperationResult; - - createSphere(params: {}): OperationResult; - - createCone(params: {}): OperationResult; - - createCylinder(params: {}): OperationResult; - - createTorus(params: {}): OperationResult; - - boolean(params: {}): OperationResult; - - stepImport(params: {}): OperationResult; - - - -} - -export interface EngineSession { - - load(): Handle; - - dispose(): void; - -} - -export interface CraftEngine { - - -} diff --git a/web/app/cad/craft/engine/handle.d.ts b/web/app/cad/craft/engine/handle.d.ts deleted file mode 100644 index ce9fed49..00000000 --- a/web/app/cad/craft/engine/handle.d.ts +++ /dev/null @@ -1,2 +0,0 @@ - -export type Handle = number;