diff --git a/src/DatabaseServices/Lights/RectAreaLight.ts b/src/DatabaseServices/Lights/RectAreaLight.ts index 715fa9ea4..c743ce12b 100644 --- a/src/DatabaseServices/Lights/RectAreaLight.ts +++ b/src/DatabaseServices/Lights/RectAreaLight.ts @@ -1,5 +1,6 @@ -import { Group, Matrix4, Object3D, RectAreaLight as TRectAreaLight, Vector3 } from "three"; +import { Box3, Group, Matrix4, Object3D, RectAreaLight as TRectAreaLight, Vector3 } from "three"; import { UpdateDraw } from "../../Common/Status"; +import { equalv3, YAxis, ZeroVec } from "../../Geometry/GeUtils"; import { RenderType } from "../../GraphicsSystem/RenderType"; import { AutoRecord } from "../AutoRecord"; import { Factory } from "../CADFactory"; @@ -8,6 +9,8 @@ import { ObjectId } from "../ObjectId"; import { Light } from "./Light"; import { RectAreaLightHelper } from "./RectAreaLightHelper"; +const TARGET_DISTANCE = -1000; + @Factory export class RectAreaLight extends Light { @@ -25,7 +28,6 @@ export class RectAreaLight extends Light @AutoRecord BarnDoorAngle: number = 90;//0-90 挡光板角度 @AutoRecord BarnDoorLength: number = 20;//0-100 挡光板长度 @AutoRecord SourceTexture: ObjectId;//Texture 源纹理 默认无 可以追加一张贴图 - protected _ShowHelper = true; get Target() @@ -47,15 +49,73 @@ export class RectAreaLight extends Light } GetGripPoints(): Array { - return [this.Position, this._Target]; + let heightHalf = this._Height * 0.5; + let widthHalf = this.Width * 0.5; + let pos = this.Position; + + let pts: Vector3[] = [ + new Vector3(-widthHalf, -heightHalf, 0).applyMatrix4(this.OCSNoClone), + new Vector3(widthHalf, -heightHalf, 0).applyMatrix4(this.OCSNoClone), + new Vector3(widthHalf, heightHalf, 0).applyMatrix4(this.OCSNoClone), + new Vector3(-widthHalf, heightHalf, 0).applyMatrix4(this.OCSNoClone), + pos, + pos.clone().add(this.Normal.multiplyScalar(TARGET_DISTANCE)) + ]; + return pts; } MoveGripPoints(indexList: number[], vec: Vector3) { + let vecInv = vec.clone().applyMatrix4(this.OCSInv.setPosition(0, 0, 0)); + if (equalv3(vecInv, ZeroVec, 1e-4)) return; + this.WriteAllObjectRecord(); - if (indexList[0] === 0) + + let heightHalf = this._Height * 0.5; + let widthHalf = this.Width * 0.5; + let pts: Vector3[] = [ + new Vector3(-widthHalf, -heightHalf, 0), + new Vector3(widthHalf, -heightHalf, 0), + new Vector3(widthHalf, heightHalf, 0), + new Vector3(-widthHalf, heightHalf, 0), + ]; + + let i = indexList[0]; + if (i < 4) + { + pts[i].add(vecInv); + + let newBox = new Box3; + if (i === 0 || i === 2) + newBox.setFromPoints([pts[0], pts[2]]); + else + newBox.setFromPoints([pts[1], pts[3]]); + + //变量复用 + let size = newBox.getSize(new Vector3); + this._Width = size.x; + this._Height = size.y; + + //新的中心 + let center = newBox.getCenter(size); + center.setZ(0); + + center.applyMatrix4(this.OCSNoClone); + + this._Matrix.setPosition(center); + this.Update(); + } + else if (i === 4) + { this.Position = this.Position.add(vec); - else - this.Target = this.Target.add(vec); + this.Update(UpdateDraw.Matrix); + } + else if (i === 5) + { + let target = pts[0].setFromMatrixPosition(this._Matrix).add(this.Normal.multiplyScalar(TARGET_DISTANCE)).add(vec); + target.applyMatrix4(this.OCSInv).negate().applyMatrix4(this.OCSNoClone); + this._Matrix.lookAt(target, this.Position, YAxis); + this.Update(UpdateDraw.Matrix); + } } get Height() { @@ -92,6 +152,7 @@ export class RectAreaLight extends Light this.UpdateDrawObject(renderType, lightGroup); return lightGroup; } + UpdateDrawObject(type: RenderType, obj: Object3D) { let light = obj.children[0] as TRectAreaLight; @@ -99,10 +160,9 @@ export class RectAreaLight extends Light light.width = this._Width; light.height = this._Height; light.color.copy(this.Color); - light.lookAt(this._Target); // light.castShadow = true;//threejs没有支持这个影子 - if (this._ShowHelper || true) + if (this._ShowHelper) { let help: RectAreaLightHelper; if (obj.children.length === 1) @@ -115,12 +175,8 @@ export class RectAreaLight extends Light help.updateMatrixWorld(); } - else - { - if (obj.children.length > 1) - obj.children[1].visible = false; - } } + protected _ReadFile(file: CADFiler) { super._ReadFile(file); @@ -137,6 +193,7 @@ export class RectAreaLight extends Light this.BarnDoorLength = file.Read(); this.SourceTexture = file.Read(); } + } //对象将自身数据写入到文件. WriteFile(file: CADFiler)