diff --git a/modules/brep/operations/directMod.ts b/modules/brep/operations/directMod/pullFace.ts similarity index 100% rename from modules/brep/operations/directMod.ts rename to modules/brep/operations/directMod/pullFace.ts diff --git a/modules/brep/operations/directMod/vertexMoving.ts b/modules/brep/operations/directMod/vertexMoving.ts new file mode 100644 index 00000000..59525338 --- /dev/null +++ b/modules/brep/operations/directMod/vertexMoving.ts @@ -0,0 +1,148 @@ +import { ApplicationContext } from "context"; +import { BrepInputData } from "engine/data/brepInputData"; +import CSys from "math/csys"; +import Vector, { AXIS } from "math/vector"; +import DatumObject3D from "../../../../web/app/cad/craft/datum/datumObject"; +import { readShellEntityFromJson } from "../../../../web/app/cad/scene/wrappers/entityIO"; + + +export function testVertexMoving(ctx: ApplicationContext) { + + + function step(cornerPoint) { + + ctx.craftService.models$.update((models) => { + const data = ctx.craftEngine.modellingEngine.loadModel(makeCube(cornerPoint)); + const mShell = readShellEntityFromJson(data); + return [mShell]; + }); + + } + + let datum3D = new DatumObject3D( + new CSys(new Vector(0,0,500), AXIS.X.copy(), AXIS.Y.copy(), AXIS.Z.copy()), + ctx.services.viewer); + + datum3D.onMove = (begin, end, delta) => { + step(end); + }; + ctx.services.cadScene.workGroup.add(datum3D); + + step(new Vector(0, 0, 500)); + + // data = ctx.craftEngine.modellingEngine.transform({ + // model: data.ptr, + // matrix: new Matrix3x4().scale(1,2,1).toFlatArray() + // }); + + // const shell = mShell.brepShell as Shell; + // // shell.transform(new Matrix3x4().scale(1,2,1)); + + // const scaledInput = writeBrep(shell); + // console.dir(scaledInput); + // let data2 = ctx.craftEngine.modellingEngine.loadModel(scaledInput); + + // const mShell2 = readShellEntityFromJson(data2); + + +} + + +function makeCube({x, y, z}): BrepInputData { + + return { + vertices: { + A: [x, y, z], + 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', + plate: true, + 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']] + }, + ] + + } +} diff --git a/modules/engine/data/brepInputData.ts b/modules/engine/data/brepInputData.ts index 4b7994ae..720379f6 100644 --- a/modules/engine/data/brepInputData.ts +++ b/modules/engine/data/brepInputData.ts @@ -39,7 +39,7 @@ export interface BrepInputData { export const CubeExample: () => BrepInputData = () => ({ vertices: { - A: [0,0,500], + A: [0,-100,750], B: [500,0,500], C: [500,500,500], D: [0,500,500], @@ -104,6 +104,7 @@ export const CubeExample: () => BrepInputData = () => ({ faces: [ { surface: 'top', + plate: true, loops: [ ['AB', 'BC', 'CD', 'DA']] }, diff --git a/web/app/cad/init/startApplication.js b/web/app/cad/init/startApplication.js index 54576ddb..6a5ceff4 100644 --- a/web/app/cad/init/startApplication.js +++ b/web/app/cad/init/startApplication.js @@ -36,7 +36,7 @@ import * as UIConfigPlugin from "../part/uiConfigPlugin"; import * as DebugPlugin from "../debugPlugin"; import * as ExpressionsPlugin from "../expressions/expressionsPlugin"; import * as PartOperationsPlugin from "../part/partOperationsPlugin"; -import * as LocationPlugin from "../location/locationPlugin"; +import * as LocationPlugin from "../location/LocationPlugin"; import * as AssemblyPlugin from "../assembly/assemblyPlugin"; export default function startApplication(callback) { diff --git a/web/app/cad/sandbox.ts b/web/app/cad/sandbox.ts index f4e3b243..9e8ec873 100644 --- a/web/app/cad/sandbox.ts +++ b/web/app/cad/sandbox.ts @@ -15,8 +15,9 @@ import {DEG_RAD} from "math/commons"; import {DEFLECTION, E0_TOLERANCE} from "./craft/e0/common"; import {readBrep, writeBrep} from "brep/io/brepIO"; import {PRIMITIVE_TYPES} from "engine/data/primitiveData"; -import {pullFace} from "brep/operations/directMod"; +import {pullFace} from "brep/operations/directMod/pullFace"; import {Shell} from "brep/topo/shell"; +import { testVertexMoving } from 'brep/operations/directMod/vertexMoving'; export function runSandbox(ctx: ApplicationContext) { @@ -102,15 +103,75 @@ export function runSandbox(ctx: ApplicationContext) { } function test3() { + + + let direction = [0, 0, 500]; + + let sketch = [[ + { + TYPE: PRIMITIVE_TYPES.SEGMENT, + a: [0, 0, 0], + b: [500, 0, 0], + }, + { + TYPE: PRIMITIVE_TYPES.SEGMENT, + a: [500, 0, 0], + b: [500, 500, 0], + }, + { + TYPE: PRIMITIVE_TYPES.SEGMENT, + a: [500, 500, 0], + b: [0, 500, 0], + }, + { + TYPE: PRIMITIVE_TYPES.SEGMENT, + a: [0, 500, 0], + b: [0, 0, 0], + }, + ]] + + let data = ctx.craftEngine.modellingEngine.extrude({ + vector: direction, + sketch: sketch, + tolerance: E0_TOLERANCE, + deflection: DEFLECTION + }) + + let box1 = readBrep(data); + +// const box1 = exposure.brep.primitives.box(500, 500, 500); + const box2 = exposure.brep.primitives.box(250, 250, 750, new Matrix3x4().translate(25, 25, 0)); + +// const box3 = exposure.brep.primitives.box(150, 600, 350, new Matrix3x4().translate(25, 25, -250)); + // let result = exposure.brep.bool.union(box1, box2); + let result = exposure.brep.bool.subtract(box1, box2); + result = exposure.brep.bool.subtract(result, box3); + // addShellOnScene(box1); + addShellOnScene(result); + } + + function test4() { const box1 = exposure.brep.primitives.box(500, 500, 500); const box2 = exposure.brep.primitives.box(250, 250, 750, new Matrix3x4().translate(25, 25, 0)); const box3 = exposure.brep.primitives.box(150, 600, 350, new Matrix3x4().translate(25, 25, -250)); // let result = exposure.brep.bool.union(box1, box2); let result = exposure.brep.bool.subtract(box1, box2); - result = exposure.brep.bool.subtract(result, box3); - // addShellOnScene(box1); - addShellOnScene(result); + + const serialized = writeBrep(result); + console.log("SERAIL:"); + console.log(serialized); + let fromSerialization = ctx.craftEngine.modellingEngine.loadModel(serialized); + + console.log("FROM:"); + console.log(fromSerialization); + + const mBrepShell2 = readShellEntityFromJson(fromSerialization); + + services.exposure.addOnScene(mBrepShell2); + + +// addShellOnScene(result); } function test5() { @@ -322,15 +383,15 @@ export function runSandbox(ctx: ApplicationContext) { // }); const mShell = readShellEntityFromJson(data); - const shell = mShell.brepShell as Shell; - shell.transform(new Matrix3x4().scale(1,2,1)); + // const shell = mShell.brepShell as Shell; + // // shell.transform(new Matrix3x4().scale(1,2,1)); - const scaledInput = writeBrep(shell); - console.dir(scaledInput); - let data2 = ctx.craftEngine.modellingEngine.loadModel(scaledInput); + // const scaledInput = writeBrep(shell); + // console.dir(scaledInput); + // let data2 = ctx.craftEngine.modellingEngine.loadModel(scaledInput); - const mShell2 = readShellEntityFromJson(data2); - services.exposure.addOnScene(mShell2); + // const mShell2 = readShellEntityFromJson(data2); + services.exposure.addOnScene(mShell); } function testLoadBrep() { @@ -462,8 +523,8 @@ export function runSandbox(ctx: ApplicationContext) { // window.voxelTest = voxelTest; ctx.streams.lifecycle.projectLoaded.attach(ready => { if (ready) { - nonUniformScale(); - + //testVertexMoving(ctx); + test4(); } });