From dcc7ef512d4275b69a774d2f169e64c7524f33dc Mon Sep 17 00:00:00 2001 From: "Val Erastov (xibyte)" Date: Wed, 9 Dec 2020 23:16:57 -0800 Subject: [PATCH] split face API --- modules/engine/api.ts | 45 +++++++++++++++++++ modules/engine/data/curveData.ts | 15 +++---- .../engine/impl/wasm/GenericWASMEngine_V1.ts | 4 ++ modules/engine/impl/wasm/externals.d.ts | 1 + web/app/cad/sandbox.ts | 31 ++++++++++++- 5 files changed, 86 insertions(+), 10 deletions(-) diff --git a/modules/engine/api.ts b/modules/engine/api.ts index 47a5881b..57ce8a1d 100644 --- a/modules/engine/api.ts +++ b/modules/engine/api.ts @@ -5,6 +5,7 @@ import {PrimitiveData} from "engine/data/primitiveData"; import {EdgeTessellation, FaceTessellation, Tessellation2D} from "engine/tessellation"; import {BrepInputData} from "engine/data/brepInputData"; import {Matrix3x4FlatData} from "math/matrix"; +import {CurveData} from "engine/data/curveData"; export enum BooleanType { UNION = 1, @@ -133,6 +134,50 @@ export interface EngineAPI_V1 { }): GenericResponse; + /** + * Split face by edge + */ + splitFace(params: { + + /** + * Base shape containing face to split + */ + shape: Handle; + + /** + * Face to split + */ + face: Handle; + + /** + * Splitting edge + */ + edge: { + + /** + * Curve definition + */ + curve: CurveData; + + /** + * Optional bounds for the splitting curve. If uMin supplied uMax should be supplied as well + */ + uMin?: number; + + /** + * Optional bounds for the splitting curve. If uMax supplied uMin should be supplied as well + */ + uMax?: number; + + }; + + /** + * Tessellation detail parameter + */ + deflection: number; + + + }): GenericResponse; /** * Lightweight loft operation returning only tessellation info. Meant to be used as a preview in wizards diff --git a/modules/engine/data/curveData.ts b/modules/engine/data/curveData.ts index 0d85beaf..16740c36 100644 --- a/modules/engine/data/curveData.ts +++ b/modules/engine/data/curveData.ts @@ -1,12 +1,8 @@ import {Vec3} from "math/vec"; -export interface CurveData { +export type CurveData = CurveBSplineData | CurveLineData | CurveUnknownData; - TYPE: string; - -} - -export interface CurveBSplineData extends CurveData { +export interface CurveBSplineData { TYPE: "B-SPLINE"; @@ -21,12 +17,15 @@ export interface CurveBSplineData extends CurveData { } -export interface CurveLineData extends CurveData { +export interface CurveLineData { TYPE: "LINE"; + a: Vec3; + b: Vec3; + } -export interface CurveUnknownData extends CurveData { +export interface CurveUnknownData { TYPE: "UNKNOWN"; diff --git a/modules/engine/impl/wasm/GenericWASMEngine_V1.ts b/modules/engine/impl/wasm/GenericWASMEngine_V1.ts index c0c226f0..3bec56f5 100644 --- a/modules/engine/impl/wasm/GenericWASMEngine_V1.ts +++ b/modules/engine/impl/wasm/GenericWASMEngine_V1.ts @@ -49,6 +49,10 @@ export class GenericWASMEngine_V1 implements EngineAPI_V1 { return callEngine(params, Module._SPI_revolve); } + splitFace(params) { + return callEngine(params, Module._SPI_splitFace); + } + stepImport(params) { return callEngine(params, Module._SPI_stepImport); } diff --git a/modules/engine/impl/wasm/externals.d.ts b/modules/engine/impl/wasm/externals.d.ts index 123b441d..cfdfbaf5 100644 --- a/modules/engine/impl/wasm/externals.d.ts +++ b/modules/engine/impl/wasm/externals.d.ts @@ -9,6 +9,7 @@ declare var Module: { _SPI_extrude: Function; _SPI_stepImport: Function; _SPI_revolve: Function; + _SPI_splitFace: Function; _SPI_loftPreview: Function; _SPI_loft: Function; _SPI_fillet: Function; diff --git a/web/app/cad/sandbox.ts b/web/app/cad/sandbox.ts index 9e8ec873..d9a5b0dc 100644 --- a/web/app/cad/sandbox.ts +++ b/web/app/cad/sandbox.ts @@ -171,6 +171,32 @@ export function runSandbox(ctx: ApplicationContext) { services.exposure.addOnScene(mBrepShell2); +// addShellOnScene(result); + } + + function testSplitFace() { + const box1 = exposure.brep.primitives.box(500, 500, 500); + + const serialized = writeBrep(box1); + const loaded = ctx.craftEngine.modellingEngine.loadModel(serialized); + const face = loaded.faces[0]; + const [e1, e2] = face.loops[0]; + + const splitted = ctx.craftEngine.modellingEngine.splitFace({ + deflection: DEFLECTION, + shape: loaded.ptr, + face: face.ptr, + edge: { + curve: { + TYPE: 'LINE', + a: [-250, -250, -250], + b: [ 250, -250, 250] + } + } + }) + + services.exposure.addOnScene(readShellEntityFromJson(splitted)); + // addShellOnScene(result); } @@ -523,8 +549,9 @@ export function runSandbox(ctx: ApplicationContext) { // window.voxelTest = voxelTest; ctx.streams.lifecycle.projectLoaded.attach(ready => { if (ready) { - //testVertexMoving(ctx); - test4(); + // testVertexMoving(ctx); + // test4(); + testSplitFace(); } });