!2269 修复:SweepSolid端点获取方式更改

pull/2281/MERGE
林伟强 1 year ago committed by ChenX
parent 38cabe1a76
commit 98137dd2e6

@ -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 { Line2 } from "three/examples/jsm/lines/Line2";
import { LineGeometry } from "three/examples/jsm/lines/LineGeometry"; import { LineGeometry } from "three/examples/jsm/lines/LineGeometry";
import { arrayRemoveDuplicateBySort } from "../../Common/ArrayExt";
import { ColorMaterial } from '../../Common/ColorPalette'; import { ColorMaterial } from '../../Common/ColorPalette';
import { DisposeThreeObj, Object3DRemoveAll } from '../../Common/Dispose'; import { DisposeThreeObj, Object3DRemoveAll } from '../../Common/Dispose';
import { Log, LogType } from "../../Common/Log"; import { Log, LogType } from "../../Common/Log";
import { tempMatrix1 } from "../../Common/Matrix4Utils"; import { tempMatrix1 } from "../../Common/Matrix4Utils";
import { UpdateDraw } from "../../Common/Status"; import { UpdateDraw } from "../../Common/Status";
import { ObjectSnapMode } from "../../Editor/ObjectSnapMode"; import { ObjectSnapMode } from "../../Editor/ObjectSnapMode";
import { equaln, equalv3, isParallelTo, MoveMatrix } from '../../Geometry/GeUtils'; import { AsVector3, MoveMatrix, equaln, equalv3, isParallelTo } from '../../Geometry/GeUtils';
import { SweepGeometry } from '../../Geometry/SweepGeometry'; import { ProjectionToPlane, SweepGeometry } from '../../Geometry/SweepGeometry';
import { RenderType } from "../../GraphicsSystem/RenderType"; import { RenderType } from "../../GraphicsSystem/RenderType";
import { Factory } from "../CADFactory"; import { Factory } from "../CADFactory";
import { CADFiler } from '../CADFiler'; import { CADFiler } from '../CADFiler';
@ -18,8 +19,6 @@ import { Line } from "../Entity/Line";
import { Polyline } from '../Entity/Polyline'; import { Polyline } from '../Entity/Polyline';
import { IsPointInPolyLine } from '../PointInPolyline'; import { IsPointInPolyLine } from '../PointInPolyline';
import { Spline } from "../Spline"; import { Spline } from "../Spline";
import { FixIndex } from './../../Common/Utils';
import { PlaneExt } from './../../Geometry/Plane';
@Factory @Factory
export class SweepSolid extends Entity export class SweepSolid extends Entity
@ -348,71 +347,48 @@ export class SweepSolid extends Entity
tempMatrix1.makeBasis(x, y, z); tempMatrix1.makeBasis(x, y, z);
tempMatrix1.setPosition(pos.applyMatrix4(this.OCS)); tempMatrix1.setPosition(pos.applyMatrix4(this.OCS));
} }
//端点捕捉时提供端点
private GetEndPoint() private GetEndPoint()
{ {
let conPts = this._Contour.GetStretchPoints(); //路径点表
let cus: Curve[]; let pathPts2d = this._PathCurve.Shape.getPoints(4);
if (this._PathCurve instanceof Polyline) let pathPts = pathPts2d.map(AsVector3);
cus = this._PathCurve.Explode() as Curve[]; arrayRemoveDuplicateBySort(pathPts, equalv3);
else
cus = [this._PathCurve];
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 shapePts3d = shapePts2d.map(AsVector3);
let l1 = cus[i];
let l2: Curve; for (let p of shapePts3d)
if (this._PathCurve.IsClose) p.applyMatrix4(this.Contour.OCSNoClone);
{
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 p = l1.EndPoint; let pts: Vector3[] = [];//端点
let d1 = l1.GetFistDeriv(1).normalize();
this.UpdateEndMtx(d1.clone(), p);
if (l2) //遍历路径节点
for (let i = 1; i < pathPts.length; i++)
{
if (i === pathPts.length - 1)
{ {
let d2 = l2.GetFistDeriv(0).normalize().applyMatrix4(roMat); if (this._PathCurve.IsClose)
d1.applyMatrix4(roMat); pts.push(...ProjectionToPlane(shapePts3d, this._PathCurve.Normal, pathPts[i], pathPts[i - 1], pathPts[1]));
d2.add(d1).normalize(); else
if (isParallelTo(d1, d2)) pts.push(...ProjectionToPlane(shapePts3d, this._PathCurve.Normal, pathPts[i], pathPts[i - 1]));
{
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)));
} }
else else
{ pts.push(...ProjectionToPlane(shapePts3d, this._PathCurve.Normal, pathPts[i], pathPts[i - 1], pathPts[i + 1]));
pts.push(...conPts.map(p => p.clone().applyMatrix4(tempMatrix1)));
}
} }
for (let p of pts) p.applyMatrix4(this.OCSNoClone);
return pts; return pts;
} }
private GetMidPoints() private GetMidPoints()
{ {
let conPts = this._Contour.GetStretchPoints(); let conPts = this._Contour.GetStretchPoints();

@ -2,9 +2,9 @@ import { Face3, Geometry, Line3, Matrix4, ShapeUtils, Vector2, Vector3 } from "t
import { arrayRemoveDuplicateBySort } from "../Common/ArrayExt"; import { arrayRemoveDuplicateBySort } from "../Common/ArrayExt";
import { Curve } from "../DatabaseServices/Entity/Curve"; import { Curve } from "../DatabaseServices/Entity/Curve";
import { Polyline } from "../DatabaseServices/Entity/Polyline"; import { Polyline } from "../DatabaseServices/Entity/Polyline";
import { FixIndex } from "../Nest/Common/Util";
import { AsVector3, equalv3 } from "./GeUtils"; import { AsVector3, equalv3 } from "./GeUtils";
import { PlaneExt } from "./Plane"; import { PlaneExt } from "./Plane";
import { FixIndex } from "../Nest/Common/Util";
/** /**
* 使,线线. * 使,线线.
@ -205,7 +205,7 @@ export class SweepGeometry extends Geometry
* @param {Vector3} [nextP] * @param {Vector3} [nextP]
* @returns * @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[]; let pts: Vector3[];
if (!preP && nextP) if (!preP && nextP)

Loading…
Cancel
Save