diff --git a/src/DatabaseServices/3DSolid/SweepSolid.ts b/src/DatabaseServices/3DSolid/SweepSolid.ts index a2e1310f0..24b85b24d 100644 --- a/src/DatabaseServices/3DSolid/SweepSolid.ts +++ b/src/DatabaseServices/3DSolid/SweepSolid.ts @@ -1,14 +1,15 @@ -import { Box3, BoxBufferGeometry, BufferGeometry, Float32BufferAttribute, InstancedInterleavedBuffer, InterleavedBufferAttribute, Line as TLine, Line3, LineSegments, Matrix3, Matrix4, Mesh, Object3D, Vector3 } from "three"; +import { Box3, BoxBufferGeometry, BufferGeometry, Float32BufferAttribute, InstancedInterleavedBuffer, InterleavedBufferAttribute, LineSegments, Matrix3, Matrix4, Mesh, Object3D, Line as TLine, Vector3 } from "three"; import { Line2 } from "three/examples/jsm/lines/Line2"; import { LineGeometry } from "three/examples/jsm/lines/LineGeometry"; +import { arrayRemoveDuplicateBySort } from "../../Common/ArrayExt"; import { ColorMaterial } from '../../Common/ColorPalette'; import { DisposeThreeObj, Object3DRemoveAll } from '../../Common/Dispose'; import { Log, LogType } from "../../Common/Log"; import { tempMatrix1 } from "../../Common/Matrix4Utils"; import { UpdateDraw } from "../../Common/Status"; import { ObjectSnapMode } from "../../Editor/ObjectSnapMode"; -import { equaln, equalv3, isParallelTo, MoveMatrix } from '../../Geometry/GeUtils'; -import { SweepGeometry } from '../../Geometry/SweepGeometry'; +import { AsVector3, MoveMatrix, equaln, equalv3, isParallelTo } from '../../Geometry/GeUtils'; +import { ProjectionToPlane, SweepGeometry } from '../../Geometry/SweepGeometry'; import { RenderType } from "../../GraphicsSystem/RenderType"; import { Factory } from "../CADFactory"; import { CADFiler } from '../CADFiler'; @@ -18,8 +19,6 @@ import { Line } from "../Entity/Line"; import { Polyline } from '../Entity/Polyline'; import { IsPointInPolyLine } from '../PointInPolyline'; import { Spline } from "../Spline"; -import { FixIndex } from './../../Common/Utils'; -import { PlaneExt } from './../../Geometry/Plane'; @Factory export class SweepSolid extends Entity @@ -348,71 +347,48 @@ export class SweepSolid extends Entity tempMatrix1.makeBasis(x, y, z); tempMatrix1.setPosition(pos.applyMatrix4(this.OCS)); } + + //端点捕捉时提供端点 private GetEndPoint() { - let conPts = this._Contour.GetStretchPoints(); - let cus: Curve[]; - if (this._PathCurve instanceof Polyline) - cus = this._PathCurve.Explode() as Curve[]; - else - cus = [this._PathCurve]; + //路径点表 + let pathPts2d = this._PathCurve.Shape.getPoints(4); + let pathPts = pathPts2d.map(AsVector3); + arrayRemoveDuplicateBySort(pathPts, equalv3); - let roMat = new Matrix4().extractRotation(this.OCS); + for (let p of pathPts) + p.applyMatrix4(this._PathCurve.OCS); - const pts: Vector3[] = []; + let shapePts2d = this.Contour.Shape.getPoints(4); + // if (!ShapeUtils.isClockWise(shapePts2d)) shapePts2d.reverse(); - for (let i = 0; i < cus.length; i++) - { - let l1 = cus[i]; - let l2: Curve; - if (this._PathCurve.IsClose) - { - l2 = cus[FixIndex(i + 1, cus.length)]; - } - else - { - l2 = cus[i + 1]; - if (i === 0) - { - this.UpdateEndMtx(l1.GetFistDeriv(0).normalize(), l1.StartPoint); - pts.push(...conPts.map(p => p.clone().applyMatrix4(tempMatrix1))); - } - } + //轮廓点表 + let shapePts3d = shapePts2d.map(AsVector3); + + for (let p of shapePts3d) + p.applyMatrix4(this.Contour.OCSNoClone); - let p = l1.EndPoint; - let d1 = l1.GetFistDeriv(1).normalize(); - this.UpdateEndMtx(d1.clone(), p); + let pts: Vector3[] = [];//端点 - if (l2) + //遍历路径节点 + for (let i = 1; i < pathPts.length; i++) + { + if (i === pathPts.length - 1) { - let d2 = l2.GetFistDeriv(0).normalize().applyMatrix4(roMat); - d1.applyMatrix4(roMat); - d2.add(d1).normalize(); - if (isParallelTo(d1, d2)) - { - if (l1 instanceof Line && l2 instanceof Line) - { - } - else - { - let ps = conPts.map(p => p.clone().applyMatrix4(tempMatrix1)); - pts.push(...ps); - } - continue; - } - p.copy(l1.EndPoint); - //角平分线的平面; - 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.clone().sub(d1.clone().multiplyScalar(-100)), p.clone().add(d1)), new Vector3(), true))); + if (this._PathCurve.IsClose) + pts.push(...ProjectionToPlane(shapePts3d, this._PathCurve.Normal, pathPts[i], pathPts[i - 1], pathPts[1])); + else + pts.push(...ProjectionToPlane(shapePts3d, this._PathCurve.Normal, pathPts[i], pathPts[i - 1])); } else - { - pts.push(...conPts.map(p => p.clone().applyMatrix4(tempMatrix1))); - } + pts.push(...ProjectionToPlane(shapePts3d, this._PathCurve.Normal, pathPts[i], pathPts[i - 1], pathPts[i + 1])); } + + for (let p of pts) p.applyMatrix4(this.OCSNoClone); + return pts; } + private GetMidPoints() { let conPts = this._Contour.GetStretchPoints(); diff --git a/src/Geometry/SweepGeometry.ts b/src/Geometry/SweepGeometry.ts index 44c6c7ff1..de0baa187 100644 --- a/src/Geometry/SweepGeometry.ts +++ b/src/Geometry/SweepGeometry.ts @@ -2,9 +2,9 @@ import { Face3, Geometry, Line3, Matrix4, ShapeUtils, Vector2, Vector3 } from "t import { arrayRemoveDuplicateBySort } from "../Common/ArrayExt"; import { Curve } from "../DatabaseServices/Entity/Curve"; import { Polyline } from "../DatabaseServices/Entity/Polyline"; +import { FixIndex } from "../Nest/Common/Util"; import { AsVector3, equalv3 } from "./GeUtils"; import { PlaneExt } from "./Plane"; -import { FixIndex } from "../Nest/Common/Util"; /** * 使用轮廓和扫描路径构建扫描几何体,实现衣柜中的顶线或者地脚线之类的实体. @@ -205,7 +205,7 @@ export class SweepGeometry extends Geometry * @param {Vector3} [nextP] 路径下一个点 * @returns 变换后的轮廓点表 */ -function ProjectionToPlane(contourPts: Vector3[], normal: Vector3, curP: Vector3, preP?: Vector3, nextP?: Vector3): Vector3[] +export function ProjectionToPlane(contourPts: Vector3[], normal: Vector3, curP: Vector3, preP?: Vector3, nextP?: Vector3): Vector3[] { let pts: Vector3[]; if (!preP && nextP)