From 7c9d0c29999f87fc4fcbb3cdf3eb2828e7c08823 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Tue, 15 Dec 2020 02:26:14 -0800 Subject: [PATCH] edge split --- modules/brep/io/brepIO.ts | 4 ++++ modules/brep/topo/edge.ts | 48 +++++++++++++++++++++++++++++++++++++++ web/app/cad/sandbox.ts | 4 +++- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/modules/brep/io/brepIO.ts b/modules/brep/io/brepIO.ts index b86e486d..9e188d67 100644 --- a/modules/brep/io/brepIO.ts +++ b/modules/brep/io/brepIO.ts @@ -223,9 +223,13 @@ export function writeBrep(shell: Shell): BrepInputData { } + FACES: for (let face of shell.faces) { const loops = []; for (let loop of face.loops) { + if (loop.halfEdges.length == 0) { + continue FACES; + } loops.push(loop.halfEdges.map(he => edges.get(he.edge))); } diff --git a/modules/brep/topo/edge.ts b/modules/brep/topo/edge.ts index f75697b4..369deb85 100644 --- a/modules/brep/topo/edge.ts +++ b/modules/brep/topo/edge.ts @@ -4,6 +4,9 @@ import BrepCurve from "geom/curves/brepCurve"; import {Loop} from "./loop"; import Vector from "math/vector"; import {Tessellation1D} from "engine/tessellation"; +import _ from 'lodash'; +import {Point} from 'geom/point'; +import { BREPValidator } from 'brep/brep-validator'; export class Edge extends TopoObject { @@ -40,6 +43,32 @@ export class Edge extends TopoObject { Object.assign(clone.halfEdge2.data, this.halfEdge2.data); return clone; } + + splitByPoint(pt: Point) { + + const [c1, c2] = this.curve.split(pt); + + const e1 = Edge.fromCurve(c1); + const e2 = Edge.fromCurve(c2); + + this.halfEdge1.insertAfter(e1.halfEdge1); + e1.halfEdge1.insertAfter(e2.halfEdge1); + + let anchorIndex = this.halfEdge2.loop.halfEdges.indexOf(this.halfEdge2) - 1; + if (anchorIndex == -1) { + anchorIndex = this.halfEdge2.loop.halfEdges.length - 1; + } + + const anchor = this.halfEdge2.loop.halfEdges[anchorIndex]; + + anchor.insertAfter(e2.halfEdge2); + e2.halfEdge2.insertAfter(e1.halfEdge2); + + this.halfEdge2.delete(); + this.halfEdge1.delete(); + // const errors = BREPValidator.validate(this.halfEdge1.loop.face.shell); + // console.log(errors); + } } export class HalfEdge extends TopoObject { @@ -92,6 +121,25 @@ export class HalfEdge extends TopoObject { return res; } + insertAfter(he: HalfEdge) { + he.loop = this.loop; + const next = this.next; + this.next = he; + he.next = next; + next.prev = he; + he.prev = this; + const index = this.loop.halfEdges.indexOf(this); + this.loop.halfEdges.splice(index + 1, 0, he); + } + + delete() { + const next = this.next; + const prev = this.prev; + prev.next = next; + next.prev = prev; + _.pull(this.loop.halfEdges, this); + } + replace(he: HalfEdge) { if (this.edge.halfEdge1 === this) { this.edge.halfEdge1 = he; diff --git a/web/app/cad/sandbox.ts b/web/app/cad/sandbox.ts index e1e1e7c9..be00b145 100644 --- a/web/app/cad/sandbox.ts +++ b/web/app/cad/sandbox.ts @@ -17,6 +17,7 @@ import {pullFace} from "brep/operations/directMod/pullFace"; import {DefeatureFaceWizard} from "./craft/defeature/DefeatureFaceWizard"; import {defeatureByVertex} from "brep/operations/directMod/defeaturing"; import {BooleanType} from "engine/api"; +import { testEdgeSplit } from 'brep/operations/directMod/edgeSplit'; export function runSandbox(ctx: ApplicationContext) { @@ -588,7 +589,8 @@ export function runSandbox(ctx: ApplicationContext) { // window.voxelTest = voxelTest; ctx.streams.lifecycle.projectLoaded.attach(ready => { if (ready) { - // testVertexMoving(ctx); + // testEdgeSplit(ctx); + //testVertexMoving(ctx); test4(); // testSplitFace(); // testRemoveFaces();