mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-25 18:02:23 +01:00
defeature by edge
This commit is contained in:
parent
7c9d0c2999
commit
d5a448cecb
2 changed files with 54 additions and 7 deletions
|
|
@ -1,11 +1,37 @@
|
|||
import {Shell} from "brep/topo/shell";
|
||||
import {Vertex} from "brep/topo/vertex";
|
||||
import {EdgeGraph} from "brep/operations/boolean";
|
||||
import {HalfEdge} from "brep/topo/edge";
|
||||
import {Edge, HalfEdge} from "brep/topo/edge";
|
||||
import {Plane} from "geom/impl/plane";
|
||||
import {DEFLECTION} from "../../../../web/app/cad/craft/e0/common";
|
||||
import {DEFLECTION, E0_TOLERANCE} from "../../../../web/app/cad/craft/e0/common";
|
||||
import {EngineAPI_V1, GenericResponse} from "engine/api";
|
||||
|
||||
export function defeatureByEdge(shell: Shell, edge: Edge, engine: EngineAPI_V1): GenericResponse {
|
||||
|
||||
const graph = new EdgeGraph();
|
||||
for (let e of shell.edges) {
|
||||
graph.add(e.halfEdge1);
|
||||
graph.add(e.halfEdge2);
|
||||
}
|
||||
|
||||
const notSourceEdge = (he: HalfEdge) => he.edge !== edge;
|
||||
|
||||
const edges1: HalfEdge[] = graph.vertexToEdge.get(edge.halfEdge1.vertexA);
|
||||
const [a, b] = edges1.filter(notSourceEdge).map(e => e.vertexB.point);
|
||||
|
||||
const edges2: HalfEdge[] = graph.vertexToEdge.get(edge.halfEdge1.vertexB);
|
||||
const [c] = edges2.filter(notSourceEdge).map(e => e.vertexB.point);
|
||||
|
||||
let plane = Plane.by3Points(a, b, c);
|
||||
|
||||
if (plane.normal.multiply(plane.w).minus(edge.halfEdge1.vertexA.point).dot(plane.normal) > 1) {
|
||||
plane = plane.invert();
|
||||
}
|
||||
plane.w += E0_TOLERANCE;
|
||||
|
||||
return cutOff(shell, plane, engine);
|
||||
}
|
||||
|
||||
export function defeatureByVertex(shell: Shell, vertex: Vertex, engine: EngineAPI_V1): GenericResponse {
|
||||
|
||||
const graph = new EdgeGraph();
|
||||
|
|
@ -22,6 +48,12 @@ export function defeatureByVertex(shell: Shell, vertex: Vertex, engine: EngineAP
|
|||
plane = plane.invert();
|
||||
}
|
||||
|
||||
return cutOff(shell, plane, engine);
|
||||
}
|
||||
|
||||
|
||||
function cutOff(shell: Shell, plane: Plane, engine: EngineAPI_V1) {
|
||||
|
||||
return engine.splitByPlane({
|
||||
deflection: DEFLECTION,
|
||||
shape: shell.data.externals.ptr,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import {readBrep, writeBrep} from "brep/io/brepIO";
|
|||
import {PRIMITIVE_TYPES} from "engine/data/primitiveData";
|
||||
import {pullFace} from "brep/operations/directMod/pullFace";
|
||||
import {DefeatureFaceWizard} from "./craft/defeature/DefeatureFaceWizard";
|
||||
import {defeatureByVertex} from "brep/operations/directMod/defeaturing";
|
||||
import {defeatureByVertex, defeatureByEdge} from "brep/operations/directMod/defeaturing";
|
||||
import {BooleanType} from "engine/api";
|
||||
import { testEdgeSplit } from 'brep/operations/directMod/edgeSplit';
|
||||
|
||||
|
|
@ -239,6 +239,20 @@ export function runSandbox(ctx: ApplicationContext) {
|
|||
});
|
||||
}
|
||||
|
||||
function testRemoveEdge() {
|
||||
|
||||
const boxData = ctx.craftEngine.modellingEngine.loadModel(writeBrep(exposure.brep.primitives.box(500, 500, 500)));
|
||||
const box = readShellEntityFromJson(boxData);
|
||||
services.exposure.addOnScene(box);
|
||||
box.edges.forEach(e => e.ext.view.picker.onMouseClick = () => {
|
||||
ctx.craftService.models$.update((models) => {
|
||||
const [cube] = models;
|
||||
const result = defeatureByEdge(cube.brepShell, e.brepEdge, ctx.craftEngine.modellingEngine);
|
||||
const mShell = readShellEntityFromJson(result);
|
||||
return [mShell];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function test5() {
|
||||
|
||||
|
|
@ -591,10 +605,11 @@ export function runSandbox(ctx: ApplicationContext) {
|
|||
if (ready) {
|
||||
// testEdgeSplit(ctx);
|
||||
//testVertexMoving(ctx);
|
||||
test4();
|
||||
// testSplitFace();
|
||||
// testRemoveFaces();
|
||||
// testRemoveVertex();
|
||||
test4();
|
||||
//testSplitFace();
|
||||
//testRemoveFaces();
|
||||
//testRemoveVertex();
|
||||
testRemoveEdge();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue