diff --git a/src/Add-on/Align.ts b/src/Add-on/Align.ts index f1af5a677..39f8e3a91 100644 --- a/src/Add-on/Align.ts +++ b/src/Add-on/Align.ts @@ -4,7 +4,7 @@ import { PromptStatus } from "../Editor/PromptResult"; import { Entity } from './../DatabaseServices/Entity/Entity'; import { JigUtils } from './../Editor/JigUtils'; 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 { Vector3 } from 'three'; import { matrixScale } from "../Common/Matrix4Utils"; @@ -39,21 +39,25 @@ export class Align implements Command let v11 = po1.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(); - if (isParallelTo(roAxis, ents[0].Normal)) - roAxis.copy(ents[0].Normal); - let roInv = new Matrix4().extractRotation(ents[0].SpaceOCSInv); - let rAng = angleTo(v12.applyMatrix4(roInv), vo12.applyMatrix4(roInv)); - let roMtx = new Matrix4().makeRotationAxis(roAxis, rAng); + + + let rAng = 0; + let roMtx = new Matrix4(); + if (!equalv3(roAxis, ZeroVec)) + { + rAng = angleTo(v12, vo12, roAxis); + roMtx.makeRotationAxis(roAxis, rAng); + } let ptRes = await app.Editor.GetPoint({ Msg: "选择第三个目标源点<继续>", AllowNone: true, }); - let canScale = false; - let scaleMtx = new Matrix4(); + // let canScale = false; + // let scaleMtx = new Matrix4(); let roMat2: Matrix4; if (ptRes.Status === PromptStatus.OK) { @@ -63,33 +67,32 @@ export class Align implements Command if (!po3) return; JigUtils.Draw(new Line(p3, po3)); - let v13 = p3.clone().sub(p1).applyMatrix4(roInv); - let vo13 = po3.clone().sub(po1).applyMatrix4(roInv); + let v13 = p3.clone().sub(p1); + let vo13 = po3.clone().sub(po1); let d1 = v13.cross(v12).normalize().applyMatrix4(roMtx); let d2 = vo13.cross(vo12).normalize(); if (!equalv3(d1, d2)) { - vo12 = po2.clone().sub(po1); - roMat2 = new Matrix4().makeRotationAxis(vo12.normalize(), angleTo(d2, d1)); + roMat2 = new Matrix4().makeRotationAxis(vo12, angleTo(d1, d2, vo12)); } } else if (ptRes.Status === PromptStatus.None) { - let keyRes = await app.Editor.GetKeyWords({ - Msg: "是否基于对齐点缩放对象", - Default: "N", - KeyWordList: [{ msg: "是", key: "Y" }, { msg: "否", key: "N" }] - }); - canScale = keyRes.StringResult === "Y"; - scaleMtx = matrixScale(vo12.length() / v12.length(), p1); + // let keyRes = await app.Editor.GetKeyWords({ + // Msg: "是否基于对齐点缩放对象", + // Default: "N", + // KeyWordList: [{ msg: "是", key: "Y" }, { msg: "否", key: "N" }] + // }); + // canScale = keyRes.StringResult === "Y"; + // scaleMtx = matrixScale(vo12.length() / v12.length(), p1); } else return; for (let en of ents) { - if (canScale) - en.ApplyMatrix(scaleMtx); + // if (canScale) + // en.ApplyMatrix(scaleMtx); en.Position = en.Position.sub(p1); en.ApplyMatrix(roMtx); if (roMat2) diff --git a/src/Geometry/GeUtils.ts b/src/Geometry/GeUtils.ts index 32f4baaa2..c006683a7 100644 --- a/src/Geometry/GeUtils.ts +++ b/src/Geometry/GeUtils.ts @@ -117,6 +117,9 @@ export function angleTo(v1: Vector3, v2: Vector3, ref: Vector3 = new Vector3(0, { if (!ref.equals(new Vector3(0, 0, 1))) { + ref = ref.clone(); + v1 = v1.clone(); + v2 = v2.clone(); //任意轴坐标系. 使用相机的构造矩阵. ref.multiplyScalar(-1); let up = getLoocAtUpVec(ref);