更新 精简代码

pull/2/head
ChenX 7 years ago
parent f1b6fa7b8d
commit 780d13f767

@ -288,21 +288,21 @@ export class DrawSpline implements Command
{ {
app.m_Editor.m_CommandStore.Prompt("请输入一个点:"); app.m_Editor.m_CommandStore.Prompt("请输入一个点:");
let ptRes = await app.m_Editor.GetPoint({ Msg: "请输入第一个点:" }); let ptRes = await app.m_Editor.GetPoint({ Msg: "请输入第一个点:" });
if (ptRes.Status != PromptStatus.OK) if (ptRes.Status != PromptStatus.OK)
{
return; return;
}
let i = 0;
let p1 = ptRes.Value; let p1 = ptRes.Value;
let pts = [];
let ptLast = new Vector2(p1.x, p1.y); let ptLast = new Vector2(p1.x, p1.y);
pts.push(ptLast); let pts = [ptLast];
let spline = new Spline(pts); let spline = new Spline(pts);
app.m_Database.ModelSpace.Append(spline);
app.m_Editor.AddNoSnapEntity(spline.Draw(RenderType.Wireframe));
while (true) while (true)
{ {
ptLast = ptLast.clone();
pts.push(ptLast);
app.m_Editor.m_CommandStore.Prompt("请输入点2:"); app.m_Editor.m_CommandStore.Prompt("请输入点2:");
ptRes = await app.m_Editor.GetPoint({ ptRes = await app.m_Editor.GetPoint({
Msg: "请输入点2:", Msg: "请输入点2:",
@ -311,20 +311,14 @@ export class DrawSpline implements Command
KeyWordList: [{ msg: "放弃", key: "U" }], KeyWordList: [{ msg: "放弃", key: "U" }],
Callback: (v) => Callback: (v) =>
{ {
let p = new Vector2(v.x, v.y); ptLast.set(v.x, v.y);
let tmpPts = pts.slice(0); spline.Points = pts;
tmpPts.push(p);
spline.Points = tmpPts;
} }
}); });
if (ptRes.Status == PromptStatus.OK) if (ptRes.Status == PromptStatus.OK)
{ {
ptLast = new Vector2(ptRes.Value.x, ptRes.Value.y);
app.m_Database.ModelSpace.Append(spline);
pts.push(ptLast);
p1 = ptRes.Value; p1 = ptRes.Value;
spline.Points = pts;
continue; continue;
} }
else else
@ -332,8 +326,6 @@ export class DrawSpline implements Command
break; break;
} }
} }
} }
} }
export class DrawTest implements Command export class DrawTest implements Command

@ -16,6 +16,11 @@ export class ObjectCollection<T> extends CADObject
//添加一个对象进入集合,这个集合存在db中,那么将自动分配id. //添加一个对象进入集合,这个集合存在db中,那么将自动分配id.
Append(obj: CADObject) Append(obj: CADObject)
{ {
if (obj.Id)
{
console.warn("同一个对象不能重复加入图纸!");
return;
}
if (this._db && !obj.Id) if (this._db && !obj.Id)
{ {
obj.InitObjectId(this._db); obj.InitObjectId(this._db);

@ -1,16 +1,19 @@
import { Entity } from "./Entity"; import { Geometry, Vector2 } from 'three';
import { Vector2, Geometry } from "three"; import * as THREE from 'three';
import * as THREE from "three";
import { RenderType } from "../GraphicsSystem/Enum";
import { ColorMaterial } from "../Common/ColorPalette";
import { ColorMaterial } from '../Common/ColorPalette';
import { RenderType } from '../GraphicsSystem/Enum';
import { Factory } from './CADFactory';
import { Entity } from './Entity';
@Factory
export class Spline extends Entity export class Spline extends Entity
{ {
m_Points: Vector2[]; private m_Points: Vector2[];
constructor(points: Vector2[]) constructor(points?: Vector2[])
{ {
super(); super();
this.m_Points = points; this.m_Points = points || [];
} }
get Points() get Points()
{ {
@ -25,7 +28,6 @@ export class Spline extends Entity
{ {
let obj = super.Draw(renderType); let obj = super.Draw(renderType);
if (obj) return obj; if (obj) return obj;
// let line = new THREE.Line(geo);
let curve = new THREE.SplineCurve(this.Points); let curve = new THREE.SplineCurve(this.Points);
let points = curve.getPoints(1000); let points = curve.getPoints(1000);
let geometry = new THREE.Geometry().setFromPoints(points); let geometry = new THREE.Geometry().setFromPoints(points);

Loading…
Cancel
Save