!861 优化:实体捕捉

pull/861/MERGE
ZoeLeeFZ 5 years ago committed by ChenX
parent 932c886f51
commit 719457b015

@ -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:

@ -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
{

@ -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 = (<CompositeEntity>e)._Matrix;
tempMatrix1.multiplyMatrices(this._Matrix, oldOcs);
(<CompositeEntity>e)._Matrix = tempMatrix1;
pts.push(...e.GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform));
(<CompositeEntity>e)._Matrix = oldOcs;
pts.push(...e.Clone().ApplyMatrix(this.OCS).GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform));
}
return pts;
}

Loading…
Cancel
Save