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.Editor.Prompt("请输入一个点:"); let ptRes = await app.Editor.GetPoint({ Msg: "请输入第一个点:" }); if (ptRes.Status != PromptStatus.OK) return; let ptLast = ptRes.Point; let pts: Vector3[] = [ptLast]; let spline = new Spline(pts); while (true) { ptLast = ptLast.clone(); pts.push(ptLast); if (pts.length === 2) { app.Database.ModelSpace.Append(spline); } app.Editor.Prompt("请输入点2:"); ptRes = await app.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.Point; continue; } else { // 弹出预存点 pts.pop(); spline.Update(); break; } } } }