!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( pts.push(
...contour.GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform) ...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; return pts;
} }
default: default:

@ -1,7 +1,6 @@
import { BufferGeometry, Float32BufferAttribute, Line3, LineSegments, Matrix3, Matrix4, Mesh, Object3D, Vector3 } from "three"; import { BufferGeometry, Float32BufferAttribute, Line3, LineSegments, Matrix3, Matrix4, Mesh, Object3D, Vector3 } from "three";
import { Line2 } from "three/examples/jsm/lines/Line2"; import { Line2 } from "three/examples/jsm/lines/Line2";
import { LineMaterial } from "three/examples/jsm/lines/LineMaterial"; import { LineMaterial } from "three/examples/jsm/lines/LineMaterial";
import { arrayLast } from "../../Common/ArrayExt";
import { ColorMaterial } from '../../Common/ColorPalette'; import { ColorMaterial } from '../../Common/ColorPalette';
import { DisposeThreeObj } from '../../Common/Dispose'; import { DisposeThreeObj } from '../../Common/Dispose';
import { Log } from "../../Common/Log"; import { Log } from "../../Common/Log";
@ -211,7 +210,7 @@ export class SweepSolid extends Entity
} }
get BoundingBox() get BoundingBox()
{ {
return new Box3Ext().setFromPoints(this.GetEndPoints()); return new Box3Ext().setFromPoints(this.GetEndPoint());
} }
get OBB(): OBB get OBB(): OBB
{ {
@ -229,7 +228,7 @@ export class SweepSolid extends Entity
switch (snapMode) switch (snapMode)
{ {
case ObjectSnapMode.End: case ObjectSnapMode.End:
return this.GetEndPoint2(); return this.GetEndPoint();
case ObjectSnapMode.Mid: case ObjectSnapMode.Mid:
case ObjectSnapMode.Cen: case ObjectSnapMode.Cen:
case ObjectSnapMode.Nea: case ObjectSnapMode.Nea:
@ -264,27 +263,6 @@ export class SweepSolid extends Entity
p.applyMatrix4(this._Matrix); p.applyMatrix4(this._Matrix);
return pts; 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) private UpdateEndMtx(dir: Vector3, pos: Vector3)
{ {
let y = this.Normal; let y = this.Normal;
@ -294,7 +272,7 @@ 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 GetEndPoint2() private GetEndPoint()
{ {
let conPts = this._Contour.GetStretchPoints(); let conPts = this._Contour.GetStretchPoints();
let cus: Curve[]; let cus: Curve[];
@ -303,6 +281,8 @@ export class SweepSolid extends Entity
else else
cus = [this._PathCurve]; cus = [this._PathCurve];
let roMat = new Matrix4().extractRotation(this.OCS);
const pts: Vector3[] = []; const pts: Vector3[] = [];
for (let i = 0; i < cus.length; i++) for (let i = 0; i < cus.length; i++)
@ -329,14 +309,16 @@ export class SweepSolid extends Entity
if (l2) if (l2)
{ {
let d2 = l2.GetFistDeriv(0).normalize(); let d2 = l2.GetFistDeriv(0).normalize().applyMatrix4(roMat);
d1.applyMatrix4(roMat);
d2.add(d1).normalize(); d2.add(d1).normalize();
if (isParallelTo(d1, d2)) if (isParallelTo(d1, d2))
continue; 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)); 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 else
{ {

@ -1,7 +1,5 @@
import { Matrix3, Object3D, Vector3 } from "three"; import { Matrix3, Object3D, Vector3 } from "three";
import { arraySortByNumber, arraySum } from "../../Common/ArrayExt"; import { arraySortByNumber, arraySum } from "../../Common/ArrayExt";
import { DisposeThreeObj } from "../../Common/Dispose";
import { tempMatrix1 } from "../../Common/Matrix4Utils";
import { Object3DRemoveAll } from "../../Common/Dispose"; import { Object3DRemoveAll } from "../../Common/Dispose";
import { ObjectSnapMode } from "../../Editor/ObjectSnapMode"; import { ObjectSnapMode } from "../../Editor/ObjectSnapMode";
import { RenderType } from "../../GraphicsSystem/RenderType"; import { RenderType } from "../../GraphicsSystem/RenderType";
@ -103,11 +101,7 @@ export class CompositeEntity extends Entity
let pts: Vector3[] = []; let pts: Vector3[] = [];
for (let e of this.Entitys) for (let e of this.Entitys)
{ {
let oldOcs = (<CompositeEntity>e)._Matrix; pts.push(...e.Clone().ApplyMatrix(this.OCS).GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform));
tempMatrix1.multiplyMatrices(this._Matrix, oldOcs);
(<CompositeEntity>e)._Matrix = tempMatrix1;
pts.push(...e.GetObjectSnapPoints(snapMode, pickPoint, lastPoint, viewXform));
(<CompositeEntity>e)._Matrix = oldOcs;
} }
return pts; return pts;
} }

Loading…
Cancel
Save