From 719457b0152724eb836396382bcaeb0dc6ffe4bd Mon Sep 17 00:00:00 2001 From: ZoeLeeFZ Date: Tue, 24 Mar 2020 19:52:05 +0800 Subject: [PATCH] =?UTF-8?q?!861=20=E4=BC=98=E5=8C=96:=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E6=8D=95=E6=8D=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DatabaseServices/3DSolid/ExtrudeHole.ts | 2 + src/DatabaseServices/3DSolid/SweepSolid.ts | 38 +++++-------------- .../Entity/CompositeEntity.ts | 8 +--- 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/src/DatabaseServices/3DSolid/ExtrudeHole.ts b/src/DatabaseServices/3DSolid/ExtrudeHole.ts index 6323daa54..69c57202e 100644 --- a/src/DatabaseServices/3DSolid/ExtrudeHole.ts +++ b/src/DatabaseServices/3DSolid/ExtrudeHole.ts @@ -123,6 +123,8 @@ export class ExtrudeHole extends Hole pts.push( ...contour.GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) ); + if (snapMode === ObjectSnapMode.Mid) + pts.push(...contour.GetStretchPoints().map(p => p.add(this.Normal.multiplyScalar(-this.Height / 2)))); return pts; } default: diff --git a/src/DatabaseServices/3DSolid/SweepSolid.ts b/src/DatabaseServices/3DSolid/SweepSolid.ts index 15a32401a..faba83f9e 100644 --- a/src/DatabaseServices/3DSolid/SweepSolid.ts +++ b/src/DatabaseServices/3DSolid/SweepSolid.ts @@ -1,7 +1,6 @@ import { BufferGeometry, Float32BufferAttribute, Line3, LineSegments, Matrix3, Matrix4, Mesh, Object3D, Vector3 } from "three"; import { Line2 } from "three/examples/jsm/lines/Line2"; import { LineMaterial } from "three/examples/jsm/lines/LineMaterial"; -import { arrayLast } from "../../Common/ArrayExt"; import { ColorMaterial } from '../../Common/ColorPalette'; import { DisposeThreeObj } from '../../Common/Dispose'; import { Log } from "../../Common/Log"; @@ -211,7 +210,7 @@ export class SweepSolid extends Entity } get BoundingBox() { - return new Box3Ext().setFromPoints(this.GetEndPoints()); + return new Box3Ext().setFromPoints(this.GetEndPoint()); } get OBB(): OBB { @@ -229,7 +228,7 @@ export class SweepSolid extends Entity switch (snapMode) { case ObjectSnapMode.End: - return this.GetEndPoint2(); + return this.GetEndPoint(); case ObjectSnapMode.Mid: case ObjectSnapMode.Cen: case ObjectSnapMode.Nea: @@ -264,27 +263,6 @@ export class SweepSolid extends Entity p.applyMatrix4(this._Matrix); return pts; } - private GetEndPoints() - { - let pts = this._PathCurve.GetStretchPoints(); - for (let p of pts) - p.applyMatrix4(this._Matrix); - let roMat = new Matrix4().extractRotation(this.OCS); - let z = this._PathCurve.GetFistDeriv(0).normalize().applyMatrix4(roMat); - let y = this.Normal; - let x = z.clone().cross(y); - let mat = new Matrix4().makeBasis(x, y, z); - mat.setPosition(this._PathCurve.StartPoint.applyMatrix4(this.OCS)); - - z = this._PathCurve.GetFistDeriv(this._PathCurve.EndParam).normalize().applyMatrix4(roMat); - x = z.clone().cross(y); - let mat2 = new Matrix4().makeBasis(x, y, z); - mat2.setPosition(arrayLast(pts)); - - let p2 = this._Contour.GetStretchPoints().map(p => p.applyMatrix4(mat)); - let p3 = this._Contour.GetStretchPoints().map(p => p.applyMatrix4(mat2)); - return [...pts, ...p2, ...p3]; - } private UpdateEndMtx(dir: Vector3, pos: Vector3) { let y = this.Normal; @@ -294,7 +272,7 @@ export class SweepSolid extends Entity tempMatrix1.makeBasis(x, y, z); tempMatrix1.setPosition(pos.applyMatrix4(this.OCS)); } - private GetEndPoint2() + private GetEndPoint() { let conPts = this._Contour.GetStretchPoints(); let cus: Curve[]; @@ -303,6 +281,8 @@ export class SweepSolid extends Entity else cus = [this._PathCurve]; + let roMat = new Matrix4().extractRotation(this.OCS); + const pts: Vector3[] = []; for (let i = 0; i < cus.length; i++) @@ -329,14 +309,16 @@ export class SweepSolid extends Entity if (l2) { - let d2 = l2.GetFistDeriv(0).normalize(); + let d2 = l2.GetFistDeriv(0).normalize().applyMatrix4(roMat); + d1.applyMatrix4(roMat); d2.add(d1).normalize(); if (isParallelTo(d1, d2)) continue; + p.copy(l1.EndPoint); //角平分线的平面; - let plane = new PlaneExt(d2, p); + let plane = new PlaneExt(d2, p.applyMatrix4(this.OCS)); let ps = conPts.map(p => p.clone().applyMatrix4(tempMatrix1)); - pts.push(...ps.map(p => plane.intersectLine(new Line3(p, p.clone().add(d1)), new Vector3(), true))); + pts.push(...ps.map(p => plane.intersectLine(new Line3(p.clone().sub(d1.clone().multiplyScalar(-100)), p.clone().add(d1)), new Vector3(), true))); } else { diff --git a/src/DatabaseServices/Entity/CompositeEntity.ts b/src/DatabaseServices/Entity/CompositeEntity.ts index d4207a2c1..5109894cb 100644 --- a/src/DatabaseServices/Entity/CompositeEntity.ts +++ b/src/DatabaseServices/Entity/CompositeEntity.ts @@ -1,7 +1,5 @@ import { Matrix3, Object3D, Vector3 } from "three"; import { arraySortByNumber, arraySum } from "../../Common/ArrayExt"; -import { DisposeThreeObj } from "../../Common/Dispose"; -import { tempMatrix1 } from "../../Common/Matrix4Utils"; import { Object3DRemoveAll } from "../../Common/Dispose"; import { ObjectSnapMode } from "../../Editor/ObjectSnapMode"; import { RenderType } from "../../GraphicsSystem/RenderType"; @@ -103,11 +101,7 @@ export class CompositeEntity extends Entity let pts: Vector3[] = []; for (let e of this.Entitys) { - let oldOcs = (e)._Matrix; - tempMatrix1.multiplyMatrices(this._Matrix, oldOcs); - (e)._Matrix = tempMatrix1; - pts.push(...e.GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform)); - (e)._Matrix = oldOcs; + pts.push(...e.Clone().ApplyMatrix(this.OCS).GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform)); } return pts; }