diff --git a/src/DatabaseServices/Lights/DirectionalLight.ts b/src/DatabaseServices/Lights/DirectionalLight.ts index 10448b310..fc119f624 100644 --- a/src/DatabaseServices/Lights/DirectionalLight.ts +++ b/src/DatabaseServices/Lights/DirectionalLight.ts @@ -1,6 +1,6 @@ import { DirectionalLight as TDirectionalLight, Group, MathUtils, Matrix3, Matrix4, Object3D, Vector2, Vector3 } from "three"; import { UpdateDraw } from "../../Common/Status"; -import { equalv3 } from "../../Geometry/GeUtils"; +import { equaln, equalv3 } from "../../Geometry/GeUtils"; import { RenderType } from "../../GraphicsSystem/RenderType"; import { AutoRecord } from "../AutoRecord"; import { Factory } from "../CADFactory"; @@ -65,6 +65,32 @@ export class DirectionalLight extends Light this.Update(); } } + + get SunPosition() { return super.Position; } + set SunPosition(p: Vector3) + { + if ( + equaln(p.x, this._Matrix.elements[12]) + && equaln(p.y, this._Matrix.elements[13]) + && equaln(p.z, this._Matrix.elements[14]) + ) + return; + + this.WriteAllObjectRecord(); + this._Matrix.setPosition(p); + this.Update(UpdateDraw.Geometry); + } + + get Position() { return super.Position; } + set Position(p: Vector3) + { + console.error("不支持的用法! 错误的设计"); + let bak = this._Target.toArray(); + super.Position = p; + this._Target.fromArray(bak); + this.Update(UpdateDraw.Geometry); + } + get WebIntensity() { let x = this._Intensity / 150; @@ -92,7 +118,7 @@ export class DirectionalLight extends Light if (indexList[0] === 0) this.Position = this.Position.add(vec); else - this.Target = this.Target.add(vec); + this._Target.add((vec)); } protected InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D { diff --git a/src/UI/Components/RightPanel/SunLightGui.tsx b/src/UI/Components/RightPanel/SunLightGui.tsx index 3c2cf791f..dc6cfcb21 100644 --- a/src/UI/Components/RightPanel/SunLightGui.tsx +++ b/src/UI/Components/RightPanel/SunLightGui.tsx @@ -188,7 +188,7 @@ export default class SunLightGui extends Component rotate = MathUtils.degToRad(safeEval(rotate.toString())); pos = new Vector3(DefaultDist.dist * Math.cos(elevation), 0, DefaultDist.dist * Math.sin(elevation)); pos.applyMatrix4(new Matrix4().makeRotationZ(rotate)).add(app.Database.SunLight.Target); - app.Database.SunLight.Position = pos; + app.Database.SunLight.SunPosition = pos; CalcSunShadowCameraExtents(app.Database.SunLight, false); app.Viewer.UpdateRender(); diff --git a/src/UI/Store/RightPanelStore/LightStore.ts b/src/UI/Store/RightPanelStore/LightStore.ts index 1582d631b..95b483d53 100644 --- a/src/UI/Store/RightPanelStore/LightStore.ts +++ b/src/UI/Store/RightPanelStore/LightStore.ts @@ -661,7 +661,7 @@ export class RightPlaneLightStore implements IConfigStore sunLight.Color = new Color(cof.option.SunLightColor); sunLight.Temperature = cof.option.SunLightTemperature; - sunLight.Position = pos; + sunLight.SunPosition = pos; CalcSunShadowCameraExtents(app.Database.SunLight, false); app.Viewer.UpdateRender();