You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/src/Common/JigMove.ts

49 lines
1.5 KiB

import { Matrix4, Vector3 } from "three";
import { app } from "../ApplicationServices/Application";
import { Entity } from "../DatabaseServices/Entity/Entity";
import { PromptStatus } from "../Editor/PromptResult";
export async function JigMoveEntity(entitys: Entity[], pos = new Vector3): Promise<Matrix4 | undefined>
{
let mtx = new Matrix4();
let baseP = new Vector3();
while (true)
{
let ptRes = await app.Editor.GetPoint({
Msg: "点取位置",
KeyWordList: [{ key: "B", msg: "基点" }],
Callback: (p: Vector3) =>
{
mtx.setPosition(p.clone().sub(pos));
for (let e of entitys)
e.ApplyMatrix(mtx);
pos.copy(p);
}
});
if (ptRes.Status === PromptStatus.Keyword)
{
app.Editor.GetPointServices.snapServices.FilterErase = false;
let baseRes = await app.Editor.GetPoint({ Msg: "点取新基点:" });
app.Editor.GetPointServices.snapServices.FilterErase = true;
if (baseRes.Status === PromptStatus.OK)
{
let p = baseRes.Point;
baseP.add(p).sub(pos);
pos = p;
}
continue;
}
if (ptRes.Status === PromptStatus.OK)
{
mtx.setPosition(ptRes.Point.sub(pos));
for (let e of entitys)
e.ApplyMatrix(mtx);
mtx.setPosition(ptRes.Point.sub(baseP));
return mtx;
}
break;
}
}