mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-22 00:14:31 +01:00
engine api work
This commit is contained in:
parent
6956ffda32
commit
c9b1d3d292
21 changed files with 188 additions and 98 deletions
|
|
@ -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' {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
||||
|
|
|
|||
104
modules/engine/api.ts
Normal file
104
modules/engine/api.ts
Normal file
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -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";
|
||||
4
modules/engine/data/handle.ts
Normal file
4
modules/engine/data/handle.ts
Normal file
|
|
@ -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;
|
||||
35
modules/engine/data/primitiveData.ts
Normal file
35
modules/engine/data/primitiveData.ts
Normal file
|
|
@ -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;
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
8
modules/geom/curves/nurbsCurveData.ts
Normal file
8
modules/geom/curves/nurbsCurveData.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import {Vec3} from "math/vec";
|
||||
|
||||
export interface NurbsCurveData {
|
||||
degree: number,
|
||||
controlPoints: Vec3[],
|
||||
knots: number[],
|
||||
weights: number[]
|
||||
}
|
||||
|
|
@ -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) {
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
||||
|
|
|
|||
9
modules/geom/surfaces/nurbsSurfaceData.ts
Normal file
9
modules/geom/surfaces/nurbsSurfaceData.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import {Vec3} from "math/vec";
|
||||
|
||||
export interface NurbsSurfaceData {
|
||||
degreeU: number,
|
||||
degreeV: number,
|
||||
controlPoints: Vec3[][],
|
||||
knots: number[][],
|
||||
weights: number[][]
|
||||
}
|
||||
|
|
@ -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;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
46
web/app/cad/craft/engine/engine.d.ts
vendored
46
web/app/cad/craft/engine/engine.d.ts
vendored
|
|
@ -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 {
|
||||
|
||||
|
||||
}
|
||||
2
web/app/cad/craft/engine/handle.d.ts
vendored
2
web/app/cad/craft/engine/handle.d.ts
vendored
|
|
@ -1,2 +0,0 @@
|
|||
|
||||
export type Handle = number;
|
||||
Loading…
Reference in a new issue