From d252813be6d237c6d353b46a8b1681974d8a08fd Mon Sep 17 00:00:00 2001 From: ChenX Date: Mon, 24 Jun 2019 23:25:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DatabaseServices/Lights/AmbientLight.ts | 14 +++--- .../Lights/DirectionalLight.ts | 30 ++++++------- .../Lights/HemisphereLight.ts | 4 +- src/DatabaseServices/Lights/Light.ts | 45 +++++++++---------- src/DatabaseServices/Lights/PointLight.ts | 14 +++--- src/DatabaseServices/Lights/RectAreaLight.ts | 39 ++++++++-------- src/DatabaseServices/Lights/SpotLight.ts | 10 ++--- 7 files changed, 76 insertions(+), 80 deletions(-) diff --git a/src/DatabaseServices/Lights/AmbientLight.ts b/src/DatabaseServices/Lights/AmbientLight.ts index 6b17e42ac..869f15918 100644 --- a/src/DatabaseServices/Lights/AmbientLight.ts +++ b/src/DatabaseServices/Lights/AmbientLight.ts @@ -1,16 +1,18 @@ -import * as THREE from "three"; -import { Object3D } from "three"; +import { AmbientLight as TAmbientLight, Object3D } from "three"; +import { RenderType } from "../../GraphicsSystem/RenderType"; import { Factory } from "../CADFactory"; import { Light } from "./Light"; -import { RenderType } from "../../GraphicsSystem/RenderType"; @Factory export class AmbientLight extends Light { - protected m_Intensity = 2; + protected _Intensity = 2; protected InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D { - let light = new THREE.AmbientLight(this.Color, this.m_Intensity); - return light; + if (renderType === RenderType.Physical) + { + let light = new TAmbientLight(this.Color, this._Intensity); + return light; + } } } diff --git a/src/DatabaseServices/Lights/DirectionalLight.ts b/src/DatabaseServices/Lights/DirectionalLight.ts index 70014aaac..a107c9f69 100644 --- a/src/DatabaseServices/Lights/DirectionalLight.ts +++ b/src/DatabaseServices/Lights/DirectionalLight.ts @@ -12,33 +12,33 @@ import { Light } from "./Light"; @Factory export class DirectionalLight extends Light { - private m_Target = new Vector3(); - protected m_ShowHelper = false; + private _Target = new Vector3(); + protected _ShowHelper = false; get Target() { - return this.m_Target.clone(); + return this._Target.clone(); } set Target(p: Vector3) { this.WriteAllObjectRecord(); if (!equalv3(p, this.Position)) { - this.m_Target.copy(p); + this._Target.copy(p); this.Update(); } } ApplyMatrix(m: Matrix4) { super.ApplyMatrix(m); - this.m_Target.applyMatrix4(m); + this._Target.applyMatrix4(m); this.Update(UpdateDraw.Geometry); return this; } GetGripPoints(): Array { if (this.ShowHelper) - return [this.Position, this.m_Target]; + return [this.Position, this._Target]; else return []; } @@ -55,7 +55,7 @@ export class DirectionalLight extends Light // if (renderType !== RenderType.Physical) return; let lightGroup = new Group(); - let light = new TDirectionalLight(this.m_LightColor, this.m_Intensity); + let light = new TDirectionalLight(this._LightColor, this._Intensity); light.castShadow = true; light.shadow.camera.far = 100000; light.shadow.camera.left = -1500; @@ -77,23 +77,23 @@ export class DirectionalLight extends Light let light = en.children[0] as TDirectionalLight; super.UpdateDrawObject(type, light); - light.target.position.copy(this.m_Target); + light.target.position.copy(this._Target); light.target.updateMatrix(); light.target.updateMatrixWorld(true); en.updateMatrixWorld(true); let helper = en.children[1] as DirectionalLightHelper; - helper.visible = this.m_ShowHelper; - if (this.m_ShowHelper) + helper.visible = this._ShowHelper; + if (this._ShowHelper) { helper.update(); helper.matrix = light.matrix; - helper.lightPlane.lookAt(this.m_Target); + helper.lightPlane.lookAt(this._Target); //@ts-ignore - helper.targetLine.lookAt(this.m_Target); + helper.targetLine.lookAt(this._Target); //@ts-ignore - helper.targetLine.scale.z = this.m_Target.distanceTo(this.Position); + helper.targetLine.scale.z = this._Target.distanceTo(this.Position); } } @@ -101,12 +101,12 @@ export class DirectionalLight extends Light { super._ReadFile(file); let ver = file.Read(); - this.m_Target.fromArray(file.Read()); + this._Target.fromArray(file.Read()); } WriteFile(file: CADFiler) { super.WriteFile(file); file.Write(1);//ver - file.Write(this.m_Target.toArray()); + file.Write(this._Target.toArray()); } } diff --git a/src/DatabaseServices/Lights/HemisphereLight.ts b/src/DatabaseServices/Lights/HemisphereLight.ts index 8aaf1469d..8091f62d9 100644 --- a/src/DatabaseServices/Lights/HemisphereLight.ts +++ b/src/DatabaseServices/Lights/HemisphereLight.ts @@ -9,7 +9,7 @@ import { CADFiler } from "../CADFiler"; export class HemisphereLight extends Light { private m_GroundColor = new THREE.Color(); - protected m_Intensity = 0.5; + protected _Intensity = 0.5; get GroundColor() { return this.m_GroundColor; @@ -23,7 +23,7 @@ export class HemisphereLight extends Light } protected InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D { - let light = new THREE.HemisphereLight(this.Color, this.m_LightColor); + let light = new THREE.HemisphereLight(this.Color, this._LightColor); return light; } UpdateDrawObject(type: RenderType, en: Object3D) diff --git a/src/DatabaseServices/Lights/Light.ts b/src/DatabaseServices/Lights/Light.ts index d32c9ca13..d30159cfd 100644 --- a/src/DatabaseServices/Lights/Light.ts +++ b/src/DatabaseServices/Lights/Light.ts @@ -1,13 +1,12 @@ -import * as THREE from 'three'; -import { Color, Vector3, Object3D } from 'three'; -import { Factory } from '../CADFactory'; -import { CADFiler } from '../CADFiler'; -import { Entity } from '../Entity/Entity'; +import { Color, Object3D, Vector3 } from 'three'; +import { UpdateDraw } from '../../Common/Status'; import { ObjectSnapMode } from '../../Editor/ObjectSnapMode'; import { MoveMatrix } from '../../Geometry/GeUtils'; import { RenderType } from '../../GraphicsSystem/RenderType'; -import { UpdateDraw } from '../../Common/Status'; +import { Factory } from '../CADFactory'; +import { CADFiler } from '../CADFiler'; import { CADObject } from '../CADObject'; +import { Entity } from '../Entity/Entity'; /** * 灯光实体基类 @@ -15,9 +14,9 @@ import { CADObject } from '../CADObject'; @Factory export class Light extends Entity { - protected m_Intensity: number = 2; //强度 - protected m_LightColor: Color = new Color(0xffffff); - protected m_ShowHelper = false; + protected _Intensity: number = 2; //强度 + protected _LightColor: Color = new Color(0xffffff); + protected _ShowHelper = false; Clone() { @@ -35,22 +34,22 @@ export class Light extends Entity } get Color() { - return this.m_LightColor; + return this._LightColor; } set Color(color: Color) { this.WriteAllObjectRecord(); - this.m_LightColor = color; + this._LightColor = color; this.Update(); } get ShowHelper() { - return this.m_ShowHelper; + return this._ShowHelper; } set ShowHelper(v: boolean) { this.WriteAllObjectRecord(); - this.m_ShowHelper = v; + this._ShowHelper = v; this.Update(); } GetObjectSnapPoints( @@ -78,34 +77,34 @@ export class Light extends Entity } UpdateDrawObject(type: RenderType, en: Object3D) { - (en as THREE.Light).intensity = this.m_Intensity; - (en as THREE.Light).color = this.m_LightColor; + (en as THREE.Light).intensity = this._Intensity; + (en as THREE.Light).color = this._LightColor; } get Intensity() { - return this.m_Intensity; + return this._Intensity; } set Intensity(v: number) { this.WriteAllObjectRecord(); - this.m_Intensity = v; + this._Intensity = v; this.Update(); } protected _ReadFile(file: CADFiler) { super._ReadFile(file); let ver = file.Read(); - this.m_LightColor = new Color(file.Read()); - this.m_Intensity = file.Read(); - this.m_ShowHelper = file.Read(); + this._LightColor = new Color(file.Read()); + this._Intensity = file.Read(); + this._ShowHelper = file.Read(); } //对象将自身数据写入到文件. WriteFile(file: CADFiler) { super.WriteFile(file); file.Write(1); - file.Write(this.m_LightColor.getStyle()); - file.Write(this.m_Intensity); - file.Write(this.m_ShowHelper); + file.Write(this._LightColor.getStyle()); + file.Write(this._Intensity); + file.Write(this._ShowHelper); } } diff --git a/src/DatabaseServices/Lights/PointLight.ts b/src/DatabaseServices/Lights/PointLight.ts index b034654e2..4ffdb5c1a 100644 --- a/src/DatabaseServices/Lights/PointLight.ts +++ b/src/DatabaseServices/Lights/PointLight.ts @@ -1,5 +1,4 @@ -import * as THREE from 'three'; -import { Mesh, Object3D } from 'three'; +import { Mesh, Object3D, PointLight as TPointLight, SphereGeometry, MeshBasicMaterial } from 'three'; import { Factory } from '../CADFactory'; import { CADFiler } from '../CADFiler'; import { Light } from './Light'; @@ -7,9 +6,6 @@ import { RenderType } from '../../GraphicsSystem/RenderType'; /** * 点光源 - * - * @class PointLight - * @extends {Light} */ @Factory export class PointLight extends Light @@ -53,19 +49,19 @@ export class PointLight extends Light } protected InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D { - let ptLight = new THREE.PointLight(this.m_LightColor, this.m_Intensity, this.m_Distance, this.m_Decay); + let ptLight = new TPointLight(this._LightColor, this._Intensity, this.m_Distance, this.m_Decay); ptLight.castShadow = true; ptLight.shadow.camera.far = 10000; //绘制灯光助手 - let lightGeo = new THREE.SphereGeometry(50); - let geoMat = new THREE.MeshBasicMaterial({ color: this.m_LightColor }); + let lightGeo = new SphereGeometry(50); + let geoMat = new MeshBasicMaterial({ color: this._LightColor }); ptLight.add(new Mesh(lightGeo, geoMat)); return ptLight; } UpdateDrawObject(type: RenderType, en: Object3D) { super.UpdateDrawObject(type, en); - let ptLight = en as THREE.PointLight; + let ptLight = en as TPointLight; ptLight.distance = this.m_Distance; ptLight.decay = this.m_Decay; } diff --git a/src/DatabaseServices/Lights/RectAreaLight.ts b/src/DatabaseServices/Lights/RectAreaLight.ts index f81e7c782..a748ddc5d 100644 --- a/src/DatabaseServices/Lights/RectAreaLight.ts +++ b/src/DatabaseServices/Lights/RectAreaLight.ts @@ -1,18 +1,17 @@ -import * as THREE from "three"; -import { Object3D, Vector3, Matrix4, RectAreaLightHelper } from "three"; -import { Factory } from "../CADFactory"; -import { Light } from "./Light"; +import { BoxBufferGeometry, Group, Matrix4, Mesh, MeshBasicMaterial, Object3D, PlaneBufferGeometry, RectAreaLight as TRectAreaLight, RectAreaLightHelper, Vector3 } from "three"; +import { UpdateDraw } from "../../Common/Status"; import { RenderType } from "../../GraphicsSystem/RenderType"; +import { Factory } from "../CADFactory"; import { CADFiler } from "../CADFiler"; -import { UpdateDraw } from "../../Common/Status"; +import { Light } from "./Light"; @Factory export class RectAreaLight extends Light { private m_Width: number = 1; private m_Height: number = 1; - protected m_ShowHelper = true; - protected m_Intensity = 3; + protected _ShowHelper = true; + protected _Intensity = 3; private m_Target = new Vector3(); get Target() @@ -66,18 +65,18 @@ export class RectAreaLight extends Light } protected InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D { - let lightGroup = new THREE.Group(); + let lightGroup = new Group(); - let light = new THREE.RectAreaLight(this.Color, this.m_Intensity, this.m_Width, this.m_Height); + let light = new TRectAreaLight(this.Color, this._Intensity, this.m_Width, this.m_Height); //绘制灯光助手 - let rectLightMesh = new THREE.Mesh(new THREE.PlaneBufferGeometry(), new THREE.MeshBasicMaterial({ color: this.m_LightColor })); + let rectLightMesh = new Mesh(new PlaneBufferGeometry(), new MeshBasicMaterial({ color: this._LightColor })); light.add(rectLightMesh); let helper = new RectAreaLightHelper(light); // 灯光目标点 - let box = new THREE.Mesh(new THREE.BoxBufferGeometry(50, 50, 50), new THREE.MeshBasicMaterial({ color: this.m_LightColor })); + let box = new Mesh(new BoxBufferGeometry(50, 50, 50), new MeshBasicMaterial({ color: this._LightColor })); lightGroup.add(light, helper, box); lightGroup.matrixAutoUpdate = false; @@ -88,29 +87,29 @@ export class RectAreaLight extends Light } UpdateDrawObject(type: RenderType, en: Object3D) { - let lg = en.children[0] as THREE.RectAreaLight; + let lg = en.children[0] as TRectAreaLight; super.UpdateDrawObject(type, lg); lg.width = this.m_Width; lg.height = this.m_Height; lg.lookAt(this.m_Target); - let mesh = lg.children[0] as THREE.Mesh; - mesh.visible = this.m_ShowHelper; + let mesh = lg.children[0] as Mesh; + mesh.visible = this._ShowHelper; mesh.scale.x = lg.width; mesh.scale.y = lg.height; - (mesh.material as THREE.MeshBasicMaterial).color = this.m_LightColor; + (mesh.material as MeshBasicMaterial).color = this._LightColor; let helper = en.children[1] as RectAreaLightHelper; - helper.visible = this.m_ShowHelper; - if (this.m_ShowHelper) + helper.visible = this._ShowHelper; + if (this._ShowHelper) { helper.matrix = lg.matrix; helper.update(); helper.lookAt(this.m_Target); } - let box = en.children[2] as THREE.Mesh; - box.visible = this.m_ShowHelper; - if (this.m_ShowHelper) + let box = en.children[2] as Mesh; + box.visible = this._ShowHelper; + if (this._ShowHelper) { box.matrix.identity(); box.applyMatrix(new Matrix4().setPosition(this.Target.applyMatrix4(this.OCSInv))); diff --git a/src/DatabaseServices/Lights/SpotLight.ts b/src/DatabaseServices/Lights/SpotLight.ts index 8a8a207b6..228624587 100644 --- a/src/DatabaseServices/Lights/SpotLight.ts +++ b/src/DatabaseServices/Lights/SpotLight.ts @@ -28,7 +28,7 @@ export class SpotLight extends Light // 聚光锥的半影衰减百分比。在0和1之间的值。 默认值 — 0.0。 private m_Penumbra: number = 0; private m_Target = new Vector3(); - protected m_ShowHelper = true; + protected _ShowHelper = true; get Target() { @@ -141,14 +141,14 @@ export class SpotLight extends Light // if (renderType !== RenderType.Physical) return; let lightGroup = new Group(); - let light = new TSpotLight(this.m_LightColor, this.m_Intensity, this.m_Distance, this.m_Angle, this.m_Penumbra, this.m_Decay); + let light = new TSpotLight(this._LightColor, this._Intensity, this.m_Distance, this.m_Angle, this.m_Penumbra, this.m_Decay); light.castShadow = true; light.shadow.camera.far = this.m_Distance; //绘制灯光助手 let lightGeo = new ConeGeometry(50, 80, 60); lightGeo.applyMatrix(new Matrix4().makeRotationX(Math.PI / 2)); lightGeo.applyMatrix(new Matrix4().makeRotationY(Math.PI)); - let geoMat = new MeshBasicMaterial({ color: this.m_LightColor }); + let geoMat = new MeshBasicMaterial({ color: this._LightColor }); let l = new Line( BufferGeometryUtils.CreateFromPts([new Vector3(), this.Target.applyMatrix4(this.OCSInv)]), ColorMaterial.RubberBandMaterial); let con = new Mesh(lightGeo, geoMat); @@ -190,8 +190,8 @@ export class SpotLight extends Light } let helper = en.children[1] as SpotLightHelper; - helper.visible = this.m_ShowHelper; - if (this.m_ShowHelper) + helper.visible = this._ShowHelper; + if (this._ShowHelper) { helper.matrix = light.matrix; helper.update();