From 1ce0b5cc546b251983e7c7c7c6e95943c63879a5 Mon Sep 17 00:00:00 2001 From: ChenX Date: Mon, 26 Feb 2018 16:54:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=A6=BBshape=E7=94=9F=E6=88=90.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DatabaseServices/Region.ts | 37 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/DatabaseServices/Region.ts b/src/DatabaseServices/Region.ts index d4ce3b275..931a9eeca 100644 --- a/src/DatabaseServices/Region.ts +++ b/src/DatabaseServices/Region.ts @@ -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 = []; - private m_Shape: THREE.Shape; + private m_Shape: Shape; constructor(curveList?: Array) { 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; } //在移动时应用矩阵变换