mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-07 17:04:58 +01:00
translation API
This commit is contained in:
parent
0b9526ad64
commit
871dcbf8fc
6 changed files with 136 additions and 94 deletions
|
|
@ -4,6 +4,7 @@ import {Vec3} from "math/vec";
|
||||||
import {PrimitiveData} from "engine/data/primitiveData";
|
import {PrimitiveData} from "engine/data/primitiveData";
|
||||||
import {EdgeTessellation, FaceTessellation, Tessellation2D} from "engine/tessellation";
|
import {EdgeTessellation, FaceTessellation, Tessellation2D} from "engine/tessellation";
|
||||||
import {BrepInputData} from "engine/data/brepInputData";
|
import {BrepInputData} from "engine/data/brepInputData";
|
||||||
|
import {Matrix3x4FlatData} from "math/matrix";
|
||||||
|
|
||||||
export enum BooleanType {
|
export enum BooleanType {
|
||||||
UNION = 1,
|
UNION = 1,
|
||||||
|
|
@ -372,11 +373,12 @@ export interface EngineAPI_V1 {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load arbitrary BREP data into the engine
|
* Load arbitrary BREP data into the engine
|
||||||
|
* See example at @BrepInputData
|
||||||
*/
|
*/
|
||||||
loadModel(brep: BrepInputData): BrepOutputData;
|
loadModel(brep: BrepInputData): BrepOutputData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load arbitrary BREP data into the engine
|
* Load arbitrary BREP data into the engine.
|
||||||
*/
|
*/
|
||||||
tessellate(request: {
|
tessellate(request: {
|
||||||
|
|
||||||
|
|
@ -398,6 +400,23 @@ export interface EngineAPI_V1 {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applying transformation matrix
|
||||||
|
*/
|
||||||
|
transform(request: {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Engine object reference ot transform
|
||||||
|
*/
|
||||||
|
model: Handle,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transformation matrix represented as a flat array
|
||||||
|
*/
|
||||||
|
matrix: Matrix3x4FlatData;
|
||||||
|
|
||||||
|
}): BrepOutputData;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EngineSession {
|
export interface EngineSession {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {SurfaceData} from "./surfaceData";
|
||||||
import {CurveData} from "./curveData";
|
import {CurveData} from "./curveData";
|
||||||
import {Vec3} from "math/vec";
|
import {Vec3} from "math/vec";
|
||||||
|
|
||||||
|
|
||||||
export interface BrepInputData {
|
export interface BrepInputData {
|
||||||
|
|
||||||
vertices: {
|
vertices: {
|
||||||
|
|
@ -31,3 +32,96 @@ export interface BrepInputData {
|
||||||
}[];
|
}[];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const CubeExample: () => BrepInputData = () => ({
|
||||||
|
vertices: {
|
||||||
|
A: [0,0,500],
|
||||||
|
B: [500,0,500],
|
||||||
|
C: [500,500,500],
|
||||||
|
D: [0,500,500],
|
||||||
|
|
||||||
|
AA: [0,0,0],
|
||||||
|
BB: [500,0,0],
|
||||||
|
CC: [500,500,0],
|
||||||
|
DD: [0,500,0]
|
||||||
|
},
|
||||||
|
|
||||||
|
// curves: {},
|
||||||
|
surfaces: {
|
||||||
|
top: {
|
||||||
|
TYPE: 'PLANE',
|
||||||
|
normal: [0,0,1],
|
||||||
|
origin: [0,0,500]
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
TYPE: 'PLANE',
|
||||||
|
normal: [0,0,-1],
|
||||||
|
origin: [0,0,0]
|
||||||
|
},
|
||||||
|
wall1: {
|
||||||
|
TYPE: 'PLANE',
|
||||||
|
normal: [0,-1,0],
|
||||||
|
origin: [0,0,0]
|
||||||
|
},
|
||||||
|
wall2: {
|
||||||
|
TYPE: 'PLANE',
|
||||||
|
normal: [1,0,0],
|
||||||
|
origin: [500,0,0]
|
||||||
|
},
|
||||||
|
wall3: {
|
||||||
|
TYPE: 'PLANE',
|
||||||
|
normal: [0,1,0],
|
||||||
|
origin: [0,500,0]
|
||||||
|
},
|
||||||
|
wall4: {
|
||||||
|
TYPE: 'PLANE',
|
||||||
|
normal: [-1,0,0],
|
||||||
|
origin: [0,0,0]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
edges: {
|
||||||
|
AB: {a: 'A', b: 'B'},
|
||||||
|
BC: {a: 'B', b: 'C'},
|
||||||
|
CD: {a: 'C', b: 'D'},
|
||||||
|
DA: {a: 'D', b: 'A'},
|
||||||
|
|
||||||
|
AA_BB: {a: 'AA', b: 'BB'},
|
||||||
|
BB_CC: {a: 'BB', b: 'CC'},
|
||||||
|
CC_DD: {a: 'CC', b: 'DD'},
|
||||||
|
DD_AA: {a: 'DD', b: 'AA'},
|
||||||
|
|
||||||
|
A_AA: {a: 'A', b: 'AA'},
|
||||||
|
B_BB: {a: 'B', b: 'BB'},
|
||||||
|
C_CC: {a: 'C', b: 'CC'},
|
||||||
|
D_DD: {a: 'D', b: 'DD'},
|
||||||
|
},
|
||||||
|
|
||||||
|
faces: [
|
||||||
|
{
|
||||||
|
surface: 'top',
|
||||||
|
loops: [['AB', 'BC', 'CD', 'DA']]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
surface: 'bottom',
|
||||||
|
loops: [['AA_BB', 'BB_CC', 'CC_DD', 'DD_AA']]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
surface: 'wall1',
|
||||||
|
loops: [['AB', 'B_BB', 'AA_BB', 'A_AA']]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
surface: 'wall2',
|
||||||
|
loops: [['BC', 'C_CC', 'BB_CC', 'B_BB']]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
surface: 'wall3',
|
||||||
|
loops: [['CD', 'D_DD', 'CC_DD', 'C_CC']]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
surface: 'wall4',
|
||||||
|
loops: [['DA', 'A_AA', 'DD_AA', 'D_DD']]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -61,4 +61,8 @@ export class GenericWASMEngine_V1 implements EngineAPI_V1 {
|
||||||
return callEngine(params, Module._SPI_tessellate);
|
return callEngine(params, Module._SPI_tessellate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transform(params) {
|
||||||
|
return callEngine(params, Module._SPI_transform);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
1
modules/engine/impl/wasm/externals.d.ts
vendored
1
modules/engine/impl/wasm/externals.d.ts
vendored
|
|
@ -14,4 +14,5 @@ declare var Module: {
|
||||||
_SPI_fillet: Function;
|
_SPI_fillet: Function;
|
||||||
_SPI_loadModel: Function;
|
_SPI_loadModel: Function;
|
||||||
_SPI_tessellate: Function;
|
_SPI_tessellate: Function;
|
||||||
|
_SPI_transform: Function;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import Vector, {AXIS} from "math/vector";
|
||||||
import {Vec3} from "math/vec";
|
import {Vec3} from "math/vec";
|
||||||
|
|
||||||
export type Matrix3x4Data = [[number, number, number, number], [number, number, number, number], [number, number, number, number]];
|
export type Matrix3x4Data = [[number, number, number, number], [number, number, number, number], [number, number, number, number]];
|
||||||
|
export type Matrix3x4FlatData = [number, number, number, number, number, number, number, number, number, number, number, number];
|
||||||
|
|
||||||
export class Matrix3x4 {
|
export class Matrix3x4 {
|
||||||
|
|
||||||
|
|
@ -166,6 +167,14 @@ export class Matrix3x4 {
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
toFlatArray(): Matrix3x4FlatData {
|
||||||
|
return [
|
||||||
|
this.mxx, this.mxy, this.mxz, this.tx,
|
||||||
|
this.myx, this.myy, this.myz, this.ty,
|
||||||
|
this.mzx, this.mzy, this.mzz, this.tz
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
invert(): Matrix3x4 {
|
invert(): Matrix3x4 {
|
||||||
return this.__invert(new Matrix3x4());
|
return this.__invert(new Matrix3x4());
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,11 @@ import NurbsSurface from 'geom/surfaces/nurbsSurface';
|
||||||
import {createOctreeFromSurface, traverseOctree} from "voxels/octree";
|
import {createOctreeFromSurface, traverseOctree} from "voxels/octree";
|
||||||
import {Matrix3x4} from 'math/matrix';
|
import {Matrix3x4} from 'math/matrix';
|
||||||
import {AXIS, ORIGIN} from "math/vector";
|
import {AXIS, ORIGIN} from "math/vector";
|
||||||
import {BrepInputData} from "engine/data/brepInputData";
|
import {BrepInputData, CubeExample} from "engine/data/brepInputData";
|
||||||
import {Vec3} from "math/vec";
|
import {Vec3} from "math/vec";
|
||||||
import {ApplicationContext} from "context";
|
import {ApplicationContext} from "context";
|
||||||
import {readShellEntityFromJson} from "./scene/wrappers/entityIO";
|
import {readShellEntityFromJson} from "./scene/wrappers/entityIO";
|
||||||
|
import {DEG_RAD} from "math/commons";
|
||||||
|
|
||||||
export function runSandbox(ctx: ApplicationContext) {
|
export function runSandbox(ctx: ApplicationContext) {
|
||||||
|
|
||||||
|
|
@ -285,100 +286,14 @@ export function runSandbox(ctx: ApplicationContext) {
|
||||||
|
|
||||||
function testLoadBrep() {
|
function testLoadBrep() {
|
||||||
|
|
||||||
const box: BrepInputData = {
|
const box: BrepInputData = CubeExample();
|
||||||
vertices: {
|
|
||||||
A: [0,0,500],
|
|
||||||
B: [500,0,500],
|
|
||||||
C: [500,500,500],
|
|
||||||
D: [0,500,500],
|
|
||||||
|
|
||||||
AA: [0,0,0],
|
let data = ctx.craftEngine.modellingEngine.loadModel(box);
|
||||||
BB: [500,0,0],
|
|
||||||
CC: [500,500,0],
|
|
||||||
DD: [0,500,0]
|
|
||||||
},
|
|
||||||
|
|
||||||
// curves: {},
|
data = ctx.craftEngine.modellingEngine.transform({
|
||||||
surfaces: {
|
model: data.ptr,
|
||||||
top: {
|
matrix: Matrix3x4.rotateMatrix(45 * DEG_RAD, AXIS.Y, ORIGIN).toFlatArray()
|
||||||
TYPE: 'PLANE',
|
});
|
||||||
normal: [0,0,1],
|
|
||||||
origin: [0,0,500]
|
|
||||||
},
|
|
||||||
bottom: {
|
|
||||||
TYPE: 'PLANE',
|
|
||||||
normal: [0,0,-1],
|
|
||||||
origin: [0,0,0]
|
|
||||||
},
|
|
||||||
wall1: {
|
|
||||||
TYPE: 'PLANE',
|
|
||||||
normal: [0,-1,0],
|
|
||||||
origin: [0,0,0]
|
|
||||||
},
|
|
||||||
wall2: {
|
|
||||||
TYPE: 'PLANE',
|
|
||||||
normal: [1,0,0],
|
|
||||||
origin: [500,0,0]
|
|
||||||
},
|
|
||||||
wall3: {
|
|
||||||
TYPE: 'PLANE',
|
|
||||||
normal: [0,1,0],
|
|
||||||
origin: [0,500,0]
|
|
||||||
},
|
|
||||||
wall4: {
|
|
||||||
TYPE: 'PLANE',
|
|
||||||
normal: [-1,0,0],
|
|
||||||
origin: [0,0,0]
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
edges: {
|
|
||||||
AB: {a: 'A', b: 'B'},
|
|
||||||
BC: {a: 'B', b: 'C'},
|
|
||||||
CD: {a: 'C', b: 'D'},
|
|
||||||
DA: {a: 'D', b: 'A'},
|
|
||||||
|
|
||||||
AA_BB: {a: 'AA', b: 'BB'},
|
|
||||||
BB_CC: {a: 'BB', b: 'CC'},
|
|
||||||
CC_DD: {a: 'CC', b: 'DD'},
|
|
||||||
DD_AA: {a: 'DD', b: 'AA'},
|
|
||||||
|
|
||||||
A_AA: {a: 'A', b: 'AA'},
|
|
||||||
B_BB: {a: 'B', b: 'BB'},
|
|
||||||
C_CC: {a: 'C', b: 'CC'},
|
|
||||||
D_DD: {a: 'D', b: 'DD'},
|
|
||||||
},
|
|
||||||
|
|
||||||
faces: [
|
|
||||||
{
|
|
||||||
surface: 'top',
|
|
||||||
loops: [['AB', 'BC', 'CD', 'DA']]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
surface: 'bottom',
|
|
||||||
loops: [['AA_BB', 'BB_CC', 'CC_DD', 'DD_AA']]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
surface: 'wall1',
|
|
||||||
loops: [['AB', 'B_BB', 'AA_BB', 'A_AA']]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
surface: 'wall2',
|
|
||||||
loops: [['BC', 'C_CC', 'BB_CC', 'B_BB']]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
surface: 'wall3',
|
|
||||||
loops: [['CD', 'D_DD', 'CC_DD', 'C_CC']]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
surface: 'wall4',
|
|
||||||
loops: [['DA', 'A_AA', 'DD_AA', 'D_DD']]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
const data = ctx.craftEngine.modellingEngine.loadModel(box);
|
|
||||||
|
|
||||||
const tessellation = ctx.craftEngine.modellingEngine.tessellate({
|
const tessellation = ctx.craftEngine.modellingEngine.tessellate({
|
||||||
model: data.ptr,
|
model: data.ptr,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue