增加椭圆类

pull/2/head
Zoe 7 years ago
parent 5c06c7d26b
commit 40aa1a8017

@ -7,6 +7,7 @@ import { Line } from '../DatabaseServices/Line';
import { Command } from '../Editor/CommandMachine';
import { PromptStatus } from '../Editor/PromptResult';
import { RenderType } from '../GraphicsSystem/Enum';
import { Ellipse } from '../DatabaseServices/Ellipse';
export class DrawLine implements Command
{
@ -140,7 +141,7 @@ void main() {
}
*/
console.log(); export class DrawRect implements Command
export class DrawRect implements Command
{
async exec()
{
@ -208,7 +209,7 @@ export class DrawCircle implements Command
{
async exec()
{
let cir = new Circle(app.m_Editor.m_MouseCtrl.m_CurMousePointWCS.clone(), 1e-3);
let cir = new Circle();
app.m_Editor.m_CommandStore.Prompt("指定圆的圆心:");
app.m_Editor.UpdateScreen();
let ptRes = await app.m_Editor.GetPoint({
@ -229,14 +230,57 @@ export class DrawCircle implements Command
let disRes = await app.m_Editor.GetDistance({
Msg: "指定圆的半径:",
BasePoint: ptRes.Value,
Callback: (v) => cir.Radius = v,
Callback: (v) => cir.RadX = v,
});
if (disRes.Status === PromptStatus.OK)
cir.Radius = disRes.Value;
cir.RadX = disRes.Value;
app.m_Database.hm.EndCmd();
}
}
export class DrawEllipse implements Command
{
async exec()
{
app.m_Editor.m_CommandStore.Prompt("指定椭圆中心:");
app.m_Editor.UpdateScreen();
let ptRes = await app.m_Editor.GetPoint({
Msg: "指定椭圆中心",
});
if (ptRes.Status != PromptStatus.OK)
return;
let radX = await app.m_Editor.GetPoint({
Msg: "指定轴端点:",
BasePoint: ptRes.Value,
AllowDrawRubberBand: true,
});
let disVec = radX.Value.sub(ptRes.Value);
let ellipseDist = radX.Value.distanceTo(ptRes.Value);
let ellipse = new Ellipse(ptRes.Value, ellipseDist, 0, Math.atan2(disVec.y, disVec.x));
// ellipse.Angle = Math.atan2(disVec.y, disVec.x);
app.m_Database.ModelSpace.Append(ellipse);
app.m_Editor.AddNoSnapEntity(ellipse.Draw(RenderType.Wireframe));
let radY = await app.m_Editor.GetDistance({
Msg: "指定轴端点:",
BasePoint: ptRes.Value,
Callback: (v) => ellipse.RadY = v,
});
if (radX.Status === PromptStatus.OK)
ellipse.RadY = radY.Value;
app.m_Database.hm.EndCmd();
}
}
export class DrawTest implements Command
{
async exec()

@ -6,83 +6,85 @@ import { RenderType } from '../GraphicsSystem/Enum';
import { Factory } from './CADFactory';
import { CADFile } from './CADFile';
import { Entity } from './Entity';
import { Ellipse } from './Ellipse';
@Factory
export class Circle extends Entity
export class Circle extends Ellipse
{
constructor(center?: Vector3, radius?: number)
constructor()
{
super();
this.m_Center = center ? center.clone() : new Vector3();
this.m_Radius = radius ? radius : 1e-6;
// this.m_Center = center ? center.clone() : new Vector3();
// this.m_Radius = radius ? radius : 1e-6;
this.RadY = this.RadX;
}
private m_Center: Vector3;
private m_Radius: number;
get Center()
{
return this.m_Center.clone();
}
set Center(v: Vector3)
{
this.WriteAllObjectRecord();
this.m_Center.copy(v);
}
get Radius()
{
return this.m_Radius;
}
set Radius(v: number)
{
this.WriteAllObjectRecord();
this.m_Radius = v <= 0 ? 1e-19 : v;
this.Update();
}
Draw(renderType: RenderType): THREE.Object3D
{
let obj = super.Draw(renderType);
if (obj) return obj;
// private m_Center: Vector3;
// private m_Radius: number;
// get Center()
// {
// return this.m_Center.clone();
// }
// set Center(v: Vector3)
// {
// this.WriteAllObjectRecord();
// this.m_Center.copy(v);
// }
// get Radius()
// {
// return this.m_Radius;
// }
// set Radius(v: number)
// {
// this.WriteAllObjectRecord();
// this.m_Radius = v <= 0 ? 1e-19 : v;
// this.Update();
// }
// Draw(renderType: RenderType): THREE.Object3D
// {
// let obj = super.Draw(renderType);
// if (obj) return obj;
let curve = new EllipseCurve(
this.m_Center.x, this.m_Center.y, // ax, aY
this.m_Radius, this.m_Radius, // xRadius, yRadius
0, 2 * Math.PI, // aStartAngle, aEndAngle
false, // aClockwise
0 // aRotation
);
let geometry = new Geometry().setFromPoints(curve.getPoints(60));
let circleObj = new THREE.Line(geometry, ColorMaterial.GetLineMaterial(this.m_Color));
this.m_DrawEntity.set(renderType, circleObj);
circleObj.userData = this;
return circleObj;
}
Update()
{
for (let [, obj] of this.m_DrawEntity)
{
let geo = obj["geometry"] as Geometry;
// let curve = new EllipseCurve(
// this.m_Center.x, this.m_Center.y, // ax, aY
// this.m_Radius, this.m_Radius, // xRadius, yRadius
// 0, 2 * Math.PI, // aStartAngle, aEndAngle
// false, // aClockwise
// 0 // aRotation
// );
// let geometry = new Geometry().setFromPoints(curve.getPoints(60));
// let circleObj = new THREE.Line(geometry, ColorMaterial.GetLineMaterial(this.m_Color));
// this.m_DrawEntity.set(renderType, circleObj);
// circleObj.userData = this;
// return circleObj;
// }
// Update()
// {
// for (let [, obj] of this.m_DrawEntity)
// {
// let geo = obj["geometry"] as Geometry;
let curve = new EllipseCurve(
this.m_Center.x, this.m_Center.y, // ax, aY
this.m_Radius, this.m_Radius, // xRadius, yRadius
0, 2 * Math.PI, // aStartAngle, aEndAngle
false, // aClockwise
0 // aRotation
);
// let curve = new EllipseCurve(
// this.m_Center.x, this.m_Center.y, // ax, aY
// this.m_Radius, this.m_Radius, // xRadius, yRadius
// 0, 2 * Math.PI, // aStartAngle, aEndAngle
// false, // aClockwise
// 0 // aRotation
// );
geo.setFromPoints(curve.getPoints(60));
// geo.setFromPoints(curve.getPoints(60));
geo.verticesNeedUpdate = true;
geo.computeBoundingSphere();
}
}
// geo.verticesNeedUpdate = true;
// geo.computeBoundingSphere();
// }
// }
GetStretchPoints(): Array<Vector3>
{
return [
this.m_Center.clone().add(new Vector3(0, this.m_Radius)),
this.m_Center.clone().add(new Vector3(0, -this.m_Radius)),
this.m_Center.clone().add(new Vector3(-this.m_Radius, 0)),
this.m_Center.clone().add(new Vector3(this.m_Radius, 0)),
this.Center.clone().add(new Vector3(0, this.RadX)),
this.Center.clone().add(new Vector3(0, -this.RadX)),
this.Center.clone().add(new Vector3(-this.RadX, 0)),
this.Center.clone().add(new Vector3(this.RadX, 0)),
]
}
MoveStretchPoints(indexList: Array<number>, vec: Vector3)
@ -94,7 +96,7 @@ export class Circle extends Entity
if (p)
{
p.add(vec);
this.Radius = p.distanceTo(this.m_Center);
this.RadX = p.distanceTo(this.Center);
}
}
}
@ -108,16 +110,16 @@ export class Circle extends Entity
{
super.ReadFile(file);
let ver = file.Read();
this.m_Center.fromArray(file.Read());
this.m_Radius = file.Read();
this.Center.fromArray(file.Read());
this.RadX = file.Read();
}
//对象将自身数据写入到文件.
WriteFile(file: CADFile)
{
super.WriteFile(file);
file.Write(1);
file.Write(this.m_Center.toArray());
file.Write(this.m_Radius);
file.Write(this.Center.toArray());
file.Write(this.RadX);
}
//#endregion
}

@ -0,0 +1,134 @@
import { Factory } from "./CADFactory";
import { Entity } from "./Entity";
import { Vector3, Geometry } from "three";
import { RenderType } from "../GraphicsSystem/Enum";
import { ColorMaterial } from "../Common/ColorPalette";
import * as THREE from "three";
import { cZAxis } from "../Geometry/GeUtils";
@Factory
export class Ellipse extends Entity
{
private m_Center: Vector3;
private m_RadX: number;
private m_RadY: number;
private m_Angle: number;
constructor(center?: Vector3, radX?: number, radY?: number, angle?: number)
{
super()
this.m_Center = center || new Vector3();
this.m_RadX = radX || 0;
this.m_RadY = radY || 0;
this.m_Angle = angle || 0;
}
get Center()
{
return this.m_Center;
}
set Center(v: Vector3)
{
this.WriteAllObjectRecord();
this.m_Center = v;
this.Update();
}
get RadX()
{
return this.m_RadX;
}
set RadX(v: number)
{
this.WriteAllObjectRecord();
this.m_RadX = v;
this.Update();
}
get RadY()
{
return this.m_RadY;
}
set RadY(v: number)
{
this.WriteAllObjectRecord();
this.m_RadY = v;
this.Update();
}
get Angle()
{
return this.m_Angle;
}
set Angle(v: number)
{
this.WriteAllObjectRecord();
this.m_Angle = v;
this.Update();
}
createCurve()
{
return new THREE.EllipseCurve(
this.m_Center.x, this.m_Center.y, // ax, aY
this.m_RadX, this.m_RadY, // xRadius, yRadius
0, 2 * Math.PI, // aStartAngle, aEndAngle
false, // aClockwise
this.m_Angle // aRotation
);
}
Draw(renderType: RenderType): THREE.Object3D
{
let obj = super.Draw(renderType);
if (obj) return obj;
let curve = this.createCurve();
let geometry = new Geometry().setFromPoints(curve.getPoints(60));
let ellipseObj = new THREE.Line(geometry, ColorMaterial.GetLineMaterial(this.m_Color));
this.m_DrawEntity.set(renderType, ellipseObj);
ellipseObj.userData = this;
return ellipseObj;
}
Update()
{
for (let [, obj] of this.m_DrawEntity)
{
let geo = obj["geometry"] as Geometry;
let curve = this.createCurve();
geo.setFromPoints(curve.getPoints(60));
geo.verticesNeedUpdate = true;
geo.computeBoundingSphere();
}
}
GetStretchPoints(): Array<Vector3>
{
let tmpMat4 = new THREE.Matrix4();
tmpMat4.makeRotationZ(this.Angle);
return [
this.m_Center.clone().add(new Vector3(this.m_RadX, 0).applyMatrix4(tmpMat4)),
this.m_Center.clone().add(new Vector3(-this.m_RadX, 0).applyMatrix4(tmpMat4)),
this.m_Center.clone().add(new Vector3(0, -this.m_RadY).applyMatrix4(tmpMat4)),
this.m_Center.clone().add(new Vector3(0, this.m_RadY).applyMatrix4(tmpMat4)),
this.m_Center.clone()
]
}
MoveStretchPoints(indexList: Array<number>, vec: Vector3)
{
let pts = this.GetStretchPoints();
if (indexList.length > 0)
{
let p = pts[indexList[0]];
if (p) p.add(vec);
if (indexList[0] === 1 || indexList[0] === 0)
{
this.RadX = p.distanceTo(this.m_Center);
} else if (indexList[0] === 2 || indexList[0] === 3)
{
this.RadY = p.distanceTo(this.m_Center);
} else
{
this.Center = p;
}
}
}
}

@ -1,7 +1,7 @@
// import { Command_DrawBoard } from '../Add-on/DrawBoard';
// import { DrawFloor } from '../Add-on/DrawFloor';
import { DrawGripStretch } from '../Add-on/DrawGripStretch';
import { DrawCircle, DrawLine, DrawRect, DrawSphere, DrawTest, ZoomE } from '../Add-on/DrawLine';
import { DrawCircle, DrawLine, DrawRect, DrawSphere, DrawTest, ZoomE, DrawEllipse } from '../Add-on/DrawLine';
import { DrawCircle0 } from '../Add-on/DrawZeroCircle';
import { Command_Erase } from '../Add-on/Erase';
import { Fbx } from '../Add-on/loadfbx';
@ -27,6 +27,7 @@ export function registerCommand()
commandMachine.RegisterCommand("ze", new ZoomE())
commandMachine.RegisterCommand("rec", new DrawRect())
commandMachine.RegisterCommand("c", new DrawCircle())
commandMachine.RegisterCommand("el", new DrawEllipse())
commandMachine.RegisterCommand("t", new DrawTest())
commandMachine.RegisterCommand("m", new Command_Move())

@ -72,14 +72,18 @@ export default class SoucePanel extends React.Component<SoucePanelProps, SoucePa
}>
<ul className="ul-unstyle">
{
this.state.text.map(() =>
this.state.text.map((v, i) =>
{
return (
<li className="pt-card pt-elevation-0" style={{
<li
className="pt-card pt-elevation-0"
style={{
display: "flex",
width: "100 %",
padding: 0
}}>
}}
key={i}
>
<div
className="pt-card pt-elevation-0 pt-interactive"
style={{

Loading…
Cancel
Save