From 5aa50327b2c7a2ebb6b02447be43db393d820e2f Mon Sep 17 00:00:00 2001 From: "Val Erastov (xibyte)" Date: Tue, 4 Aug 2020 22:54:29 -0700 Subject: [PATCH] add location support to the engine's API --- modules/engine/api.ts | 57 ++++++++++++++++++- modules/engine/data/brepInputData.ts | 3 +- .../engine/impl/wasm/GenericWASMEngine_V1.ts | 15 +++++ modules/engine/impl/wasm/externals.d.ts | 4 ++ web/app/cad/sandbox.ts | 22 ++++++- 5 files changed, 98 insertions(+), 3 deletions(-) diff --git a/modules/engine/api.ts b/modules/engine/api.ts index 6e837000..47a5881b 100644 --- a/modules/engine/api.ts +++ b/modules/engine/api.ts @@ -406,7 +406,7 @@ export interface EngineAPI_V1 { transform(request: { /** - * Engine object reference ot transform + * Engine object reference to transform */ model: Handle, @@ -417,6 +417,61 @@ export interface EngineAPI_V1 { }): BrepOutputData; + /** + * Sets the location for a model. Unlike the transform this method doesn't update the original geometry + * but virtually moves/rotates the model. + */ + setLocation(request: { + + /** + * Engine object reference + */ + model: Handle, + + /** + * Location matrix represented as a flat array + */ + matrix: Matrix3x4FlatData; + + }): void; + + /** + * Gets the location assign to the model + * @see setLocation method + */ + getLocation(request: { + + /** + * Engine object reference + */ + model: Handle, + + }): Matrix3x4FlatData; + + /** + * Returns the model's data + */ + getModelData(request: { + + /** + * Engine object reference + */ + model: Handle, + + }): BrepOutputData; + + /** + * Deletes a given model from memory + */ + dispose(request: { + + /** + * Engine object reference + */ + model: Handle, + + }): void; + } export interface EngineSession { diff --git a/modules/engine/data/brepInputData.ts b/modules/engine/data/brepInputData.ts index 17bada00..cc3f22a9 100644 --- a/modules/engine/data/brepInputData.ts +++ b/modules/engine/data/brepInputData.ts @@ -100,7 +100,8 @@ export const CubeExample: () => BrepInputData = () => ({ faces: [ { surface: 'top', - loops: [['AB', 'BC', 'CD', 'DA']] + loops: [ + ['AB', 'BC', 'CD', 'DA']] }, { surface: 'bottom', diff --git a/modules/engine/impl/wasm/GenericWASMEngine_V1.ts b/modules/engine/impl/wasm/GenericWASMEngine_V1.ts index 262e04e8..c0c226f0 100644 --- a/modules/engine/impl/wasm/GenericWASMEngine_V1.ts +++ b/modules/engine/impl/wasm/GenericWASMEngine_V1.ts @@ -65,4 +65,19 @@ export class GenericWASMEngine_V1 implements EngineAPI_V1 { return callEngine(params, Module._SPI_transform); } + getLocation(params) { + return callEngine(params, Module._SPI_getLocation); + } + + setLocation(params) { + return callEngine(params, Module._SPI_setLocation); + } + + getModelData(params) { + return callEngine(params, Module._SPI_getModelData); + } + + dispose(params) { + return callEngine(params, Module._SPI_dispose); + } } \ No newline at end of file diff --git a/modules/engine/impl/wasm/externals.d.ts b/modules/engine/impl/wasm/externals.d.ts index 615ecf8e..123b441d 100644 --- a/modules/engine/impl/wasm/externals.d.ts +++ b/modules/engine/impl/wasm/externals.d.ts @@ -15,4 +15,8 @@ declare var Module: { _SPI_loadModel: Function; _SPI_tessellate: Function; _SPI_transform: Function; + _SPI_getLocation: Function; + _SPI_setLocation: Function; + _SPI_getModelData: Function; + _SPI_dispose: Function; }; diff --git a/web/app/cad/sandbox.ts b/web/app/cad/sandbox.ts index 52805d83..4bb338b5 100644 --- a/web/app/cad/sandbox.ts +++ b/web/app/cad/sandbox.ts @@ -290,18 +290,38 @@ export function runSandbox(ctx: ApplicationContext) { let data = ctx.craftEngine.modellingEngine.loadModel(box); - data = ctx.craftEngine.modellingEngine.transform({ + ctx.craftEngine.modellingEngine.setLocation({ model: data.ptr, matrix: Matrix3x4.rotateMatrix(45 * DEG_RAD, AXIS.Y, ORIGIN).toFlatArray() }); + data = ctx.craftEngine.modellingEngine.getModelData({ + model: data.ptr, + }); + const tessellation = ctx.craftEngine.modellingEngine.tessellate({ model: data.ptr, deflection: 3 }); + const location = ctx.craftEngine.modellingEngine.getLocation({ + model: data.ptr + }); + + console.log("Location: ->>> "); + console.log(location); + + console.log("Tesselation: ->>> "); console.log(tessellation); + // ctx.craftEngine.modellingEngine.dispose({ + // model: data.ptr + // }); + // + // ctx.craftEngine.modellingEngine.getLocation({ + // model: data.ptr + // }); + const mBrepShell = readShellEntityFromJson(data);