mirror of https://gitee.com/cf-fz/WebCAD.git
parent
494562ab0e
commit
d3ade0321d
@ -0,0 +1,69 @@
|
||||
import { Matrix4, Vector3 } from "three";
|
||||
import { app } from "../ApplicationServices/Application";
|
||||
import { Command } from "../Editor/CommandMachine";
|
||||
import { JigUtils } from "../Editor/JigUtils";
|
||||
import { PromptStatus } from "../Editor/PromptResult";
|
||||
import { MoveMatrix } from "../Geometry/GeUtils";
|
||||
|
||||
export class MirrorCommand implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let enRes = await app.m_Editor.GetSelection({
|
||||
Msg: "选择对象", UseSelect: true
|
||||
});
|
||||
if (enRes.Status === PromptStatus.Cancel)
|
||||
return;
|
||||
|
||||
let ens = enRes.SelectSet.SelectEntityList;
|
||||
let ptRes = await app.m_Editor.GetPoint({
|
||||
Msg: "选择镜像第一点"
|
||||
});
|
||||
if (ptRes.Status === PromptStatus.Cancel)
|
||||
return;
|
||||
|
||||
let p1 = ptRes.Value;
|
||||
let cloneEns = ens.map(en => JigUtils.Draw(en));
|
||||
ptRes = await app.m_Editor.GetPoint({
|
||||
Msg: "选择镜像第二点",
|
||||
BasePoint: p1,
|
||||
AllowDrawRubberBand: true,
|
||||
Callback: (v) =>
|
||||
{
|
||||
JigUtils.Restore();
|
||||
let rot = new Matrix4().makeRotationAxis(p1.clone().cross(v).normalize(), Math.PI / 2);
|
||||
let vec = v.clone().sub(p1).applyMatrix4(rot).normalize();
|
||||
let newMat = this.GetMirrorMat(vec);
|
||||
cloneEns.forEach(en =>
|
||||
{
|
||||
en.ApplyMatrix(MoveMatrix(p1.clone().negate()))
|
||||
.ApplyMatrix(newMat)
|
||||
.ApplyMatrix(MoveMatrix(p1))
|
||||
})
|
||||
}
|
||||
});
|
||||
if (ptRes.Status === PromptStatus.Cancel)
|
||||
return;
|
||||
|
||||
let kwRes = await app.m_Editor.GetKeyWords({
|
||||
Msg: "是否删除源对象",
|
||||
KeyWordList: [{ msg: "是", key: "Y" }, { msg: "否", key: "N" }]
|
||||
});
|
||||
if (kwRes.Status === PromptStatus.Cancel)
|
||||
return;
|
||||
|
||||
JigUtils.End();
|
||||
if (kwRes.StringResult === "Y")
|
||||
ens.forEach(en => en.Erase());
|
||||
cloneEns.forEach(en => app.m_Database.ModelSpace.Append(en));
|
||||
}
|
||||
GetMirrorMat(v: Vector3)
|
||||
{
|
||||
let mirrorMat = new Matrix4();
|
||||
let xAxis = new Vector3(1 - 2 * v.x ** 2, -2 * v.x * v.y, -2 * v.x * v.z);
|
||||
let yAxis = new Vector3(-2 * v.x * v.y, 1 - 2 * v.y ** 2, -2 * v.y * v.z);
|
||||
let zAxis = new Vector3(-2 * v.x * v.z, -2 * v.y * v.z, 1 - 2 * v.z ** 2);
|
||||
mirrorMat.makeBasis(xAxis, yAxis, zAxis);
|
||||
return mirrorMat;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue