清理GetPoint代码. 分离部分代码

pull/7/head
ChenX 7 years ago
parent 82005556b2
commit 8ebb513fb9

@ -36,104 +36,141 @@ export class Editor
} }
GetPoint(prompt?: GetPointPrompt): Promise<PromptPointResult> GetPoint(prompt?: GetPointPrompt): Promise<PromptPointResult>
{ {
prompt = prompt ? prompt : {};
this.m_App.m_CursorViewer.ToGetpoint(); this.m_App.m_CursorViewer.ToGetpoint();
this.m_InputState = InputState.GetPoint; this.m_InputState = InputState.GetPoint;
let retValue = new PromptPointResult(); let retValue = new PromptPointResult();
let removeSnap = this.Snap(prompt ? prompt.BasePoint : undefined); let removeCalls = []; //删除回调列表
removeCalls.push(this.Snap());
let res = new Promise<PromptPointResult>((resolve, reject) => let res = new Promise<PromptPointResult>((resolve, reject) =>
{ {
let line: Line, removeDrag; //如果有基点,那么绘制直线
if (prompt) if (prompt.BasePoint)
{ {
let p = this.m_MouseCtrl.m_CurMousePointWCS.clone(); let line = new Line(prompt.BasePoint, prompt.BasePoint);
if (prompt.Callback)
{
prompt.Callback(p);
}
if (prompt.BasePoint)
{
line = new Line(prompt.BasePoint, prompt.BasePoint);
this.m_App.m_Database.appendEntity(line); this.m_App.m_Database.appendEntity(line);
this.noSnapList.add(line.Draw(RenderType.Wireframe)); let drawObj = line.Draw(RenderType.Wireframe);
}
removeDrag = xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseMove, () =>
{
let p = app.m_CursorViewer.ptWcs;
app.m_Viewer.ScreenToWorld(p);
if (prompt.BasePoint) this.noSnapList.add(drawObj);
removeCalls.push(
() =>
{
this.m_App.m_Database.removeEntityId(line.objectId);
},
xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseMove, () =>
{ {
let p = this.GetNowPoint(prompt.BasePoint);
line.setEndPoint(p); line.setEndPoint(p);
} this.UpdateScreen();
if (prompt.Callback) })
);
}
if (prompt.Callback)
{
removeCalls.push(
xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseMove, () =>
{ {
let p = this.GetNowPoint(prompt.BasePoint);
prompt.Callback(p); prompt.Callback(p);
this.UpdateScreen();
})
);
}
//鼠标按下
removeCalls.push(
xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseDown, (e: MouseEvent) =>
{
if (e.button == MouseKey.Left)
{
retValue.Status = PromptStatus.OK;
retValue.Value = this.GetNowPoint(prompt.BasePoint);
_return();
} }
this.UpdateScreen();
}) })
} );
//键盘按下
removeCalls.push(
xaop.begin(this.m_KeyCtrl, this.m_KeyCtrl.OnKeyDown, (e: KeyboardEvent) =>
{
if (e.keyCode == 27)
{
retValue.Status = PromptStatus.Cancel;
_return();
}
else if (e.keyCode == 32)
{
retValue.Status = PromptStatus.None;
_return();
}
})
);
let dispose = () => //返回
let _return = () =>
{ {
if (line) this.m_App.m_CursorViewer.ToSelect();
this.m_App.m_Database.removeEntityId(line.objectId); this.m_InputState = InputState.None;
removeSnap();
this.noSnapList.clear(); this.noSnapList.clear();
this.m_App.m_CursorViewer.ToSelect(); for (let f of removeCalls)
this.m_InputState = InputState.None;
remove();
remove2();
if (prompt)
{ {
removeDrag(); f();
} }
resolve(retValue);
resolve(retValue);
this.UpdateScreen(); this.UpdateScreen();
} }
let remove = xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseDown, (e: MouseEvent) =>
{
if (e.button == MouseKey.Left)
{
retValue.Status = PromptStatus.OK;
retValue.Value = this.m_MouseCtrl.m_CurMousePointWCS;
let p = app.m_CursorViewer.ptWcs;
app.m_Viewer.ScreenToWorld(p);
retValue.Value = p;
dispose();
}
});
let remove2 = xaop.begin(this.m_KeyCtrl, this.m_KeyCtrl.OnKeyDown, (e: KeyboardEvent) =>
{
if (e.keyCode == 27)
{
retValue.Status = PromptStatus.Cancel;
dispose();
}
else if (e.keyCode == 32)
{
console.log("空格 退出");
retValue.Status = PromptStatus.None;
dispose();
}
})
}) })
return res; return res;
} }
/**
*
* , ,
*
* @private
* @param {THREE.Vector3} [basePoint]
* @returns {THREE.Vector3}
* @memberof Editor
*/
private GetNowPoint(basePoint?: THREE.Vector3): THREE.Vector3
{
if (this.m_App.m_CursorViewer.m_LastSnapPoint)
{
let retP = app.m_CursorViewer.ptWcs;
app.m_Viewer.ScreenToWorld(retP);
return retP;
}
if (basePoint)
{
let newP = this.AxisSnap(basePoint);
if (newP)
{
return newP;
}
}
return this.m_MouseCtrl.m_CurMousePointWCS.clone();
}
noSnapList = new Set<THREE.Object3D>(); noSnapList = new Set<THREE.Object3D>();
Snap(basePoint?: THREE.Vector3)
/**
* .
*
* @returns
* @memberof Editor
*/
Snap()
{ {
let testSnap = () => let testSnap = () =>
{ {
@ -179,39 +216,43 @@ export class Editor
} }
} }
} }
}
testSnap();
return xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseMove, testSnap);
}
if (basePoint) /**
{ *
let p = this.m_MouseCtrl.m_CurMousePointWCS.clone(); *
* @param {any} basePoint
let anV = p.clone().sub(basePoint); * @returns {THREE.Vector3}
let an = Math.atan2(anV.y, anV.x); * @memberof Editor
*/
AxisSnap(basePoint): THREE.Vector3
{
let wcs = this.m_MouseCtrl.m_CurMousePointWCS.clone();
if (an < 0) an += Math.PI * 2; //相差向量
let newan = GeUtils.fixAngle(an, Math.PI * 0.25); let subVec = wcs.clone().sub(basePoint);
let an = Math.atan2(subVec.y, subVec.x);
if (!GeUtils.equaln(newan, an, 0.001)) if (an < 0) an += Math.PI * 2;
{ let newan = GeUtils.fixAngle(an, Math.PI * 0.25);
//dis.
let v0 = new THREE.Vector3(0, 0, 0);
GeUtils.angle(v0, newan, 1);
let dis = v0.dot(p.sub(basePoint)); if (!GeUtils.equaln(newan, an, 0.001))
console.log(dis); {
//dis.
let v0 = new THREE.Vector3(0, 0, 0);
GeUtils.angle(v0, newan, 1);
let newP = basePoint.clone(); let dis = v0.dot(wcs.sub(basePoint));
GeUtils.angle(newP, newan, dis);
app.m_Viewer.WorldToScreen(newP); let retP = basePoint.clone();
app.m_CursorViewer.SerCursorPostion(newP); GeUtils.angle(retP, newan, dis);
app.m_CursorViewer.render();
return;
}
}
return retP;
} }
testSnap(); return undefined;
return xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseMove, testSnap);
} }
PointToScreen(pt: THREE.Vector3): THREE.Vector2 PointToScreen(pt: THREE.Vector3): THREE.Vector2

Loading…
Cancel
Save