!783 对齐取消缩放和优化

pull/783/MERGE
ZoeLeeFZ 5 years ago committed by ChenX
parent 985820863b
commit c2d3172692

@ -4,7 +4,7 @@ import { PromptStatus } from "../Editor/PromptResult";
import { Entity } from './../DatabaseServices/Entity/Entity'; import { Entity } from './../DatabaseServices/Entity/Entity';
import { JigUtils } from './../Editor/JigUtils'; import { JigUtils } from './../Editor/JigUtils';
import { Line } from "../DatabaseServices/Entity/Line"; import { Line } from "../DatabaseServices/Entity/Line";
import { angleTo, equalv3, isParallelTo } from './../Geometry/GeUtils'; import { angleTo, equalv3, isParallelTo, ZeroVec } from './../Geometry/GeUtils';
import { Matrix4 } from 'three'; import { Matrix4 } from 'three';
import { Vector3 } from 'three'; import { Vector3 } from 'three';
import { matrixScale } from "../Common/Matrix4Utils"; import { matrixScale } from "../Common/Matrix4Utils";
@ -39,21 +39,25 @@ export class Align implements Command
let v11 = po1.clone().sub(p1); let v11 = po1.clone().sub(p1);
let v12 = p2.clone().sub(p1); let v12 = p2.clone().sub(p1);
let vo12 = po2.clone().sub(po1); let vo12 = po2.clone().sub(po1).normalize();
let roAxis = v12.clone().cross(vo12).normalize(); let roAxis = v12.clone().cross(vo12).normalize();
if (isParallelTo(roAxis, ents[0].Normal))
roAxis.copy(ents[0].Normal);
let roInv = new Matrix4().extractRotation(ents[0].SpaceOCSInv); let rAng = 0;
let rAng = angleTo(v12.applyMatrix4(roInv), vo12.applyMatrix4(roInv)); let roMtx = new Matrix4();
let roMtx = new Matrix4().makeRotationAxis(roAxis, rAng); if (!equalv3(roAxis, ZeroVec))
{
rAng = angleTo(v12, vo12, roAxis);
roMtx.makeRotationAxis(roAxis, rAng);
}
let ptRes = await app.Editor.GetPoint({ let ptRes = await app.Editor.GetPoint({
Msg: "选择第三个目标源点<继续>", Msg: "选择第三个目标源点<继续>",
AllowNone: true, AllowNone: true,
}); });
let canScale = false; // let canScale = false;
let scaleMtx = new Matrix4(); // let scaleMtx = new Matrix4();
let roMat2: Matrix4; let roMat2: Matrix4;
if (ptRes.Status === PromptStatus.OK) if (ptRes.Status === PromptStatus.OK)
{ {
@ -63,33 +67,32 @@ export class Align implements Command
if (!po3) return; if (!po3) return;
JigUtils.Draw(new Line(p3, po3)); JigUtils.Draw(new Line(p3, po3));
let v13 = p3.clone().sub(p1).applyMatrix4(roInv); let v13 = p3.clone().sub(p1);
let vo13 = po3.clone().sub(po1).applyMatrix4(roInv); let vo13 = po3.clone().sub(po1);
let d1 = v13.cross(v12).normalize().applyMatrix4(roMtx); let d1 = v13.cross(v12).normalize().applyMatrix4(roMtx);
let d2 = vo13.cross(vo12).normalize(); let d2 = vo13.cross(vo12).normalize();
if (!equalv3(d1, d2)) if (!equalv3(d1, d2))
{ {
vo12 = po2.clone().sub(po1); roMat2 = new Matrix4().makeRotationAxis(vo12, angleTo(d1, d2, vo12));
roMat2 = new Matrix4().makeRotationAxis(vo12.normalize(), angleTo(d2, d1));
} }
} }
else if (ptRes.Status === PromptStatus.None) else if (ptRes.Status === PromptStatus.None)
{ {
let keyRes = await app.Editor.GetKeyWords({ // let keyRes = await app.Editor.GetKeyWords({
Msg: "是否基于对齐点缩放对象", // Msg: "是否基于对齐点缩放对象",
Default: "N", // Default: "N",
KeyWordList: [{ msg: "是", key: "Y" }, { msg: "否", key: "N" }] // KeyWordList: [{ msg: "是", key: "Y" }, { msg: "否", key: "N" }]
}); // });
canScale = keyRes.StringResult === "Y"; // canScale = keyRes.StringResult === "Y";
scaleMtx = matrixScale(vo12.length() / v12.length(), p1); // scaleMtx = matrixScale(vo12.length() / v12.length(), p1);
} }
else return; else return;
for (let en of ents) for (let en of ents)
{ {
if (canScale) // if (canScale)
en.ApplyMatrix(scaleMtx); // en.ApplyMatrix(scaleMtx);
en.Position = en.Position.sub(p1); en.Position = en.Position.sub(p1);
en.ApplyMatrix(roMtx); en.ApplyMatrix(roMtx);
if (roMat2) if (roMat2)

@ -117,6 +117,9 @@ export function angleTo(v1: Vector3, v2: Vector3, ref: Vector3 = new Vector3(0,
{ {
if (!ref.equals(new Vector3(0, 0, 1))) if (!ref.equals(new Vector3(0, 0, 1)))
{ {
ref = ref.clone();
v1 = v1.clone();
v2 = v2.clone();
//任意轴坐标系. 使用相机的构造矩阵. //任意轴坐标系. 使用相机的构造矩阵.
ref.multiplyScalar(-1); ref.multiplyScalar(-1);
let up = getLoocAtUpVec(ref); let up = getLoocAtUpVec(ref);

Loading…
Cancel
Save