mirror of https://gitee.com/cf-fz/WebCAD.git
parent
5c06c7d26b
commit
40aa1a8017
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue