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/Add-on/DrawSpline.ts

55 lines
1.5 KiB

import { Vector3 } from 'three';
import { app } from '../ApplicationServices/Application';
import { Spline } from '../DatabaseServices/Spline';
import { Command } from '../Editor/CommandMachine';
import { PromptStatus } from '../Editor/PromptResult';
export class DrawSpline implements Command
{
async exec()
{
app.m_Editor.m_CommandStore.Prompt("请输入一个点:");
let ptRes = await app.m_Editor.GetPoint({ Msg: "请输入第一个点:" });
if (ptRes.Status != PromptStatus.OK)
return;
let ptLast = ptRes.Value;
let pts: Vector3[] = [ptLast];
let spline = new Spline(pts);
while (true)
{
ptLast = ptLast.clone();
pts.push(ptLast);
if (pts.length === 2)
{
app.m_Database.ModelSpace.Append(spline);
}
app.m_Editor.m_CommandStore.Prompt("请输入点2:");
ptRes = await app.m_Editor.GetPoint({
Msg: "请输入点2:",
BasePoint: ptLast,
AllowDrawRubberBand: true,
KeyWordList: [{ msg: "放弃", key: "U" }],
Callback: (v) =>
{
ptLast.copy(v);
spline.Points = pts;
}
});
if (ptRes.Status == PromptStatus.OK)
{
ptLast = ptRes.Value;
continue;
}
else
{
break;
}
}
}
}