分离shape生成.

pull/653835/MERGE
ChenX 7 years ago
parent d556549ba1
commit 1ce0b5cc54

@ -1,5 +1,5 @@
import { Object3D, ShapeGeometry, Vector2, Vector3 } from 'three';
import * as THREE from 'three';
import { Object3D, Shape, ShapeGeometry, Vector2, Vector3 } from 'three';
import { begin } from 'xaop';
import { CreateBoardUtil } from '../ApplicationServices/mesh/createBoard';
@ -21,7 +21,7 @@ const fuzz = 1e-8;
export class Region extends Entity
{
private m_CuList: Array<Curve> = [];
private m_Shape: THREE.Shape;
private m_Shape: Shape;
constructor(curveList?: Array<Curve>)
{
super();
@ -29,23 +29,37 @@ export class Region extends Entity
if (curveList)
this.m_CuList.push(...curveList);
}
get Shape(): Shape
{
if (!this.m_Shape) this.GeneralShape();
return this.m_Shape;
}
Draw(renderType: RenderType): Object3D
{
let obj = super.Draw(renderType);
if (obj) return obj;
this.m_Shape = new THREE.Shape();
this.GeneralShape();
let begin: Vector3;
let geometry = new ShapeGeometry(this.m_Shape, 60);
let mesh = new THREE.Mesh(geometry, ColorMaterial.GetLineMaterial(this.ColorIndex));
this.m_DrawEntity.set(renderType, mesh);
mesh.userData = this;
return mesh;
}
private GeneralShape()
{
this.m_Shape = new THREE.Shape();
let begin: Vector3;
if (this.m_CuList.length > 1)
{
let firstL = this.m_CuList[0];
let seconL = this.m_CuList[1];
if (firstL.StartPoint.distanceTo(seconL.StartPoint) < fuzz
|| firstL.StartPoint.distanceTo(seconL.EndPoint) < fuzz
)
|| firstL.StartPoint.distanceTo(seconL.EndPoint) < fuzz)
{
begin = firstL.EndPoint;
}
@ -55,15 +69,12 @@ export class Region extends Entity
}
this.m_Shape.moveTo(begin.x, begin.y);
}
for (let cu of this.m_CuList)
{
if (cu.EndPoint.distanceTo(begin) < fuzz)
cu.Reverse();
//设置起点
begin.copy(cu.EndPoint);
if (cu instanceof Line)
{
this.m_Shape.lineTo(begin.x, begin.y);
@ -93,12 +104,6 @@ export class Region extends Entity
this.m_Shape.absarc(cu.Center.x, cu.Center.y, cu.Radius, cu.StartAngle, cu.EndAngle, cu.IsClockWise);
}
}
let geometry = new ShapeGeometry(this.m_Shape, 60);
let mesh = new THREE.Mesh(geometry, ColorMaterial.GetLineMaterial(this.ColorIndex));
this.m_DrawEntity.set(renderType, mesh);
mesh.userData = this;
return mesh;
}
//在移动时应用矩阵变换

Loading…
Cancel
Save