重构rotate功能 支持新的图形对象,.

pull/690040/MERGE
ChenX 7 years ago
parent 0621c148b1
commit 2ebe13edc6

@ -1,18 +1,18 @@
import * as THREE from 'three';
import { app } from '../ApplicationServices/Application';
import { Entity } from '../DatabaseServices/Entity';
import { Command } from '../Editor/CommandMachine';
import { PromptStatus } from '../Editor/PromptResult';
import { CADFile } from '../DatabaseServices/CADFile';
export class Command_Rotate implements Command
{
async exec()
{
if (app.m_Viewer.m_OutlinePass.selectedObjects.length === 0)
{
app.m_Editor.m_CommandStore.Prompt("未选择对象:");
let ss = await app.m_Editor.GetSelection({ Msg: "请选择需要旋转的对象:", UseSelect: true });
if (ss.Status != PromptStatus.OK)
return;
}
app.m_Editor.m_CommandStore.Prompt("请输入第一个点:");
let ptRes = await app.m_Editor.GetPoint();
@ -21,16 +21,21 @@ export class Command_Rotate implements Command
let pt1 = ptRes.Value;
app.m_Editor.m_CommandStore.Prompt("请输入第二个点:");
let an = 0;
let enMap = new Map<Entity, CADFile>();
for (let en of ss.SelectSet.SelectEntityList)
{
let f = new CADFile();
en.WriteFile(f);
enMap.set(en, f);
}
ptRes = await app.m_Editor.GetPoint({
Callback: (p: THREE.Vector3) =>
{
let rov = p.clone().sub(pt1);
let newan = Math.atan2(rov.y, rov.x);
if (!newan)
{
return;
}
let moveMat = new THREE.Matrix4();
moveMat.makeTranslation(pt1.x, pt1.y, pt1.z);
@ -38,22 +43,23 @@ export class Command_Rotate implements Command
moveMatInv.getInverse(moveMat);
let roMat = new THREE.Matrix4();
roMat.makeRotationAxis(new THREE.Vector3(0, 0, 1), newan - an);
roMat.makeRotationAxis(new THREE.Vector3(0, 0, 1), newan);
app.m_Viewer.m_OutlinePass.selectedObjects.forEach(o =>
for (let en of ss.SelectSet.SelectEntityList)
{
o.applyMatrix(moveMatInv);
o.applyMatrix(roMat);
o.applyMatrix(moveMat);
})
let f = enMap.get(en);
f.Reset();
en.ReadFile(f);
an = newan;
en.ApplyMatrix(moveMatInv);
en.ApplyMatrix(roMat);
en.ApplyMatrix(moveMat);
}
},
BasePoint: pt1,
AllowDrawRubberBand: true
});
if (ptRes.Status != PromptStatus.OK) return;
}
}
}

Loading…
Cancel
Save