diff --git a/src/Geometry/DrillParse/BoardGetFace.ts b/src/Geometry/DrillParse/BoardGetFace.ts index ae66bd3f0..782218dca 100644 --- a/src/Geometry/DrillParse/BoardGetFace.ts +++ b/src/Geometry/DrillParse/BoardGetFace.ts @@ -56,7 +56,7 @@ export class BoardGetFace this.Faces.push(new Face({ type: BoardFaceType.NoSide, region: reg, - isRect: this.Board.IsRect, + isRect: this.Board.IsRect && !this.Board.BoardModeling.length, localBoard: this.Board, matrix4: ocs.clone().multiply( new Matrix4().setPosition(new Vector3(0, 0, thickness))), @@ -70,7 +70,7 @@ export class BoardGetFace this.Faces.push(new Face({ type: BoardFaceType.NoSide, localBoard: this.Board, - isRect: this.Board.IsRect, + isRect: this.Board.IsRect && !this.Board.BoardModeling.length, region: reg ? reg.Clone() : undefined, matrix4: new Matrix4().multiplyMatrices(ocs, mtx), length: this.Board.Width, diff --git a/src/Geometry/DrillParse/Face.ts b/src/Geometry/DrillParse/Face.ts index 61233ce58..61f83b297 100644 --- a/src/Geometry/DrillParse/Face.ts +++ b/src/Geometry/DrillParse/Face.ts @@ -10,6 +10,7 @@ import { BoolOpeartionType } from "../../GraphicsSystem/BoolOperateUtils"; import { Box3Ext } from "../Box"; import { XAxis, equaln } from "../GeUtils"; import { BoardFaceType } from "./BoardGetFace"; +import { IntersectSegment1ds, Segment1dJoin } from "./Sement1dUntils"; export interface BoardFaceParams { @@ -115,12 +116,60 @@ export class Face // TestDraw(toReg.Clone(), 2); isSuccess = sideReg.BooleanOper(toReg, BoolOpeartionType.Intersection); + + //碰到挖穿造型分段排钻 + let boardModeling = noSideFace.LocalBoard.BoardModeling; + if (boardModeling) + { + let boardThickness = noSideFace.LocalBoard.Thickness; + for (let modal of boardModeling) + { + if (boardThickness - modal.thickness > 1e-5) continue; + let modalReg = Region.CreateFromCurves([modal.shape.Outline.Curve]).ApplyMatrix(diffMtx); + isSuccess = sideReg.BooleanOper(modalReg, BoolOpeartionType.Subtract); + } + } + for (let s of sideReg.ShapeManager.ShapeList) { - let box = s.BoundingBox as Box3Ext; - retBoxs.push(box); - sizes.push(box.getSize(new Vector3())); + //求以X轴和Y=Thickness轴上的点 相互切割形成的矩形面 + const XLists: Segment1d[] = []; + const TLists: Segment1d[] = []; + const Thickness = s.BoundingBox.getSize(new Vector3).y; + + for (let cu of s.Outline.Shape.curves) + { + let pt1 = cu.getPoint(0); + let pt2 = cu.getPoint(1); + + let x1 = Math.abs(pt1.x); + let x2 = Math.abs(pt2.x); + + + if (equaln(pt1.y, 0) && equaln(pt2.y, 0)) + XLists.push([Math.min(x1, x2), Math.max(x1, x2)]); + + if (equaln(Math.abs(pt1.y), Thickness) && equaln(Math.abs(pt2.y), Thickness)) + TLists.push([Math.min(x1, x2), Math.max(x1, x2)]); + } + //合并可以相连的区间 如[0,100] + [100,200] = [0,200] + const XJoinLists: Segment1d[] = Segment1dJoin(XLists); + const TJoinLists: Segment1d[] = Segment1dJoin(TLists); + //X轴和厚度轴相交的区间 + const IntersectSegments = IntersectSegment1ds(XJoinLists, TJoinLists); + + //造型切割出来会有Position点 其他都是(0,0,0) + let startPt = new Vector3(s.Position.x); + + for (let segment of IntersectSegments) + { + let box = new Box3Ext(new Vector3(segment[0]).add(startPt), new Vector3(segment[1], Thickness).add(startPt)); + retBoxs.push(box); + sizes.push(box.getSize(new Vector3)); + } } + + if (!retBoxs.length) isSuccess = false; } else { diff --git a/src/Geometry/DrillParse/Sement1dUntils.ts b/src/Geometry/DrillParse/Sement1dUntils.ts new file mode 100644 index 000000000..9634db2d8 --- /dev/null +++ b/src/Geometry/DrillParse/Sement1dUntils.ts @@ -0,0 +1,64 @@ +import { Segment1d } from "../../Editor/TranstrolControl/ParseWalls"; +const FUZZ = 1e-5; + +//Segment1d列表中 合并相交的区间 +export function Segment1dJoin(segment: Segment1d[]): Segment1d[] +{ + if (segment.length < 2) + return segment; + + segment.sort((a, b) => a[0] - b[0]); + + const NewSegment: Segment1d[] = []; + + for (let i = 0; i < segment.length; i++) + { + let segment1 = segment[i]; + + if (i === segment.length - 1) + { + NewSegment.push(segment1); + break; + } + + for (let j = i + 1; j < segment.length; j++) + { + let segment2 = segment[j]; + if (segment2[0] < segment1[1] + FUZZ) + segment1 = [segment1[0], Math.max(segment1[1], segment2[1])]; + else + { + NewSegment.push(segment1); + break; + } + + if (j === segment.length - 1) + { + NewSegment.push(segment1); + i = segment.length - 1; + } + } + } + + return NewSegment; +} + +//获取多个区间列表相交的部分 +export function IntersectSegment1ds(segment1: Segment1d[], segment2: Segment1d[]): Segment1d[] +{ + const IntersectSegments: Segment1d[] = []; + + for (let s1 of segment1) + { + for (let s2 of segment2) + { + //[1,10] + [5,15] = [5,10] + if ((s2[0] > s1[0] - FUZZ && s2[0] < s1[1]) || (s1[0] > s2[0] - FUZZ && s1[0] < s2[1])) + { + IntersectSegments.push([Math.max(s1[0], s2[0]), Math.min(s1[1], s2[1])]); + } + } + } + + return IntersectSegments; +}