功能:实现扫略实体的最近点捕捉,修复非闭合的端点捕捉

pull/2771/MERGE
ChenX 4 months ago
parent 5069975acb
commit 35dca9946d

@ -1,7 +1,7 @@
import { Box3, BoxBufferGeometry, BufferGeometry, LineSegments, Matrix3, Matrix4, Mesh, Object3D, Line as TLine, Vector3 } from "three";
import { Box3, BoxBufferGeometry, BufferAttribute, BufferGeometry, Frustum, 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 { arrayPushArray, arrayRemoveDuplicateBySort } from "../../Common/ArrayExt";
import { ColorMaterial } from '../../Common/ColorPalette';
import { curveLinkGroup } from "../../Common/CurveUtils";
import { DisposeThreeObj, Object3DRemoveAll } from '../../Common/Dispose';
@ -10,6 +10,7 @@ import { tempMatrix1 } from "../../Common/Matrix4Utils";
import { UpdateDraw } from "../../Common/Status";
import { FixIndex } from "../../Common/Utils";
import { ObjectSnapMode } from "../../Editor/ObjectSnapMode";
import { SelectPick } from "../../Editor/SelectPick";
import { AsVector3, MoveMatrix, ZAxis, ZeroVec, equaln, equalv3, isParallelTo } from '../../Geometry/GeUtils';
import { ProjectionToPlane, SweepGeometry } from '../../Geometry/SweepGeometry';
import { RenderType } from "../../GraphicsSystem/RenderType";
@ -381,7 +382,8 @@ export class SweepSolid extends Entity
snapMode: ObjectSnapMode,
pickPoint: Vector3,
lastPoint: Vector3,
viewXform?: Matrix3
viewXform?: Matrix3,
frustum?: Frustum,
): Vector3[]
{
switch (snapMode)
@ -395,29 +397,52 @@ export class SweepSolid extends Entity
case ObjectSnapMode.Per:
case ObjectSnapMode.Tan:
{
if (Array.isArray(this._PathCurve))
let pts: Vector3[] = [];
//拷贝来自圆弧板最近点捕捉
if (snapMode === ObjectSnapMode.Nea)
{
const points: Vector3[] = [];
for (let path of this._PathCurve)
//这里实现对线框的快速捕捉
let edgeGeom = this.EdgeGeometry;
let pos = edgeGeom.getAttribute("position") as BufferAttribute;
let p1 = new Vector3;
let p2 = new Vector3;
let line = new Line(p1, p2);
line.ApplyMatrix(this.OCSNoClone);
let sel: SelectPick = frustum["_select_"];
for (let y = 0; y < pos.count; y += 2)
{
let contour = path.Clone();
contour.ApplyMatrix(this.OCS);
let pts = contour.GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform);
if (snapMode === ObjectSnapMode.Mid)
points.push(...pts, ...this.GetMidPoints());
else points.push(...pts);
p1.fromArray(pos.array, y * 3);
p2.fromArray(pos.array, (y + 1) * 3);
p1.applyMatrix4(this._Matrix);
p2.applyMatrix4(this._Matrix);
sel.WorldToScreenPoint(p1);
sel.WorldToScreenPoint(p2);
if (sel.IntersectLine(p1, p2))
{
p1.fromArray(pos.array, y * 3);
p2.fromArray(pos.array, (y + 1) * 3);
arrayPushArray(pts, line.GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform));
}
}
return points;
return pts;
}
else
let pathArr = Array.isArray(this._PathCurve) ? this._PathCurve : [this._PathCurve];
for (let path of pathArr)
{
let contour = this._PathCurve.Clone();
contour.ApplyMatrix(this.OCS);
let pts = contour.GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform);
let contour = path.Clone();
contour.ApplyMatrix(this.OCSNoClone);
arrayPushArray(pts, contour.GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform));
if (snapMode === ObjectSnapMode.Mid)
return [...pts, ...this.GetMidPoints()];
return pts;
arrayPushArray(pts, this.GetMidPoints());
}
return pts;
}
default:
break;
@ -545,6 +570,10 @@ export class SweepSolid extends Entity
let isClosePath = equalv3(pathPts[0], pathPts[pathPts.length - 1], 1e-3);
let pts: Vector3[] = [];//端点
if (!isClosePath)
pts.push(...ProjectionToPlane(shapePts3d, pathNormals[0], pathPts[0], undefined, pathPts[1]));
//遍历所有的路径节点进行顶点投射
for (let i = 1; i < pathPts.length; i++)
{

Loading…
Cancel
Save