diff --git a/src/Add-on/DrawLight/DrawPointLight.ts b/src/Add-on/DrawLight/DrawPointLight.ts index 1cabc43ba..1d3cec05c 100644 --- a/src/Add-on/DrawLight/DrawPointLight.ts +++ b/src/Add-on/DrawLight/DrawPointLight.ts @@ -1,8 +1,14 @@ import { app } from '../../ApplicationServices/Application'; +import { EntityUpdateWrap } from '../../Common/EntityUpdateWrap'; import { PointLight } from '../../DatabaseServices/Lights/PointLight'; import { Command } from '../../Editor/CommandMachine'; import { JigUtils } from '../../Editor/JigUtils'; import { PromptStatus } from '../../Editor/PromptResult'; +import { BoardModalType } from '../../UI/Components/Board/BoardModal'; +import { ModalState } from '../../UI/Components/Modal/ModalInterface'; +import { LightStore, PointLightStore } from '../../UI/Store/RightPanelStore/LightStore'; +import { SpotLightModel } from '../../UI/Store/RightPanelStore/SpotLightMOdel'; + export class DrawPointLight implements Command { async exec() @@ -40,6 +46,24 @@ export class DrawPointLight2 implements Command async exec() { let light = JigUtils.Draw(new PointLight()); + let lightStore = LightStore.GetInstance(); + lightStore.IsDrawLight = true; + lightStore.InitLightData(light); + let configStore = PointLightStore.GetInstance(); + app.Editor.ModalManage.RenderModal(SpotLightModel, { store: lightStore, LightType: BoardModalType.PointLight, configStore: configStore, isNotModify: true }); + + setTimeout(() => + { + app.Editor.UpdateScreen();//保证灯光被画出来 + }, 30); + + let state = await app.Editor.ModalManage.Wait(); + if (state.Status !== ModalState.Ok) return; + + EntityUpdateWrap(light, () => + { + light.CaseShadow = lightStore.lightData.CaseShadow; + }); let ptRes = await app.Editor.GetPoint({ Msg: "选择点光源位置", diff --git a/src/Add-on/DrawLight/DrawRectAreaLight.ts b/src/Add-on/DrawLight/DrawRectAreaLight.ts index 1e6ae588f..417006ff2 100644 --- a/src/Add-on/DrawLight/DrawRectAreaLight.ts +++ b/src/Add-on/DrawLight/DrawRectAreaLight.ts @@ -1,9 +1,14 @@ import { app } from "../../ApplicationServices/Application"; +import { EntityUpdateWrap } from "../../Common/EntityUpdateWrap"; import { RectAreaLight } from "../../DatabaseServices/Lights/RectAreaLight"; import { Command } from "../../Editor/CommandMachine"; import { JigUtils } from "../../Editor/JigUtils"; import { PromptStatus } from "../../Editor/PromptResult"; import { midPoint } from "../../Geometry/GeUtils"; +import { BoardModalType } from "../../UI/Components/Board/BoardModal"; +import { ModalState } from "../../UI/Components/Modal/ModalInterface"; +import { LightStore, RectAreaLightStore } from "../../UI/Store/RightPanelStore/LightStore"; +import { SpotLightModel } from "../../UI/Store/RightPanelStore/SpotLightMOdel"; export class DrawRectAreaLight implements Command { @@ -13,10 +18,34 @@ export class DrawRectAreaLight implements Command if (rectRes.Status === PromptStatus.OK) { let light = JigUtils.Draw(new RectAreaLight()); - light.ApplyMatrix(app.Editor.UCSMatrix); - light.Position = midPoint(rectRes.Point1WCS, rectRes.Point2WCS); - light.Width = Math.abs(rectRes.Width); - light.Height = Math.abs(rectRes.Height); + + EntityUpdateWrap(light, () => + { + light.Width = Math.abs(rectRes.Width); + light.Height = Math.abs(rectRes.Height); + light.ApplyMatrix(app.Editor.UCSMatrix); + light.Position = midPoint(rectRes.Point1WCS, rectRes.Point2WCS); + }); + + let lightStore = LightStore.GetInstance(); + lightStore.IsDrawLight = true; + lightStore.InitLightData(light); + let configStore = RectAreaLightStore.GetInstance(); + app.Editor.ModalManage.RenderModal(SpotLightModel, { store: lightStore, LightType: BoardModalType.RectAreaLight, configStore: configStore, isNotModify: true }); + + setTimeout(() => + { + app.Editor.UpdateScreen();//保证灯光被画出来 + }, 30); + + let state = await app.Editor.ModalManage.Wait(); + if (state.Status !== ModalState.Ok) return; + EntityUpdateWrap(light, () => + { + light.CaseShadow = lightStore.lightData.CaseShadow; + light.ShowHelper = lightStore.lightData.ShowHelper; + }); + app.Database.Lights.Append(light); } } diff --git a/src/Add-on/DrawLight/DrawSpotLight.ts b/src/Add-on/DrawLight/DrawSpotLight.ts index 6d6711503..3482088a8 100644 --- a/src/Add-on/DrawLight/DrawSpotLight.ts +++ b/src/Add-on/DrawLight/DrawSpotLight.ts @@ -1,9 +1,14 @@ import { MathUtils, Matrix4, Vector3 } from "three"; import { app } from "../../ApplicationServices/Application"; +import { EntityUpdateWrap } from "../../Common/EntityUpdateWrap"; import { SpotLight } from "../../DatabaseServices/Lights/SpotLight"; import { Command } from "../../Editor/CommandMachine"; import { JigUtils } from "../../Editor/JigUtils"; import { PromptStatus } from "../../Editor/PromptResult"; +import { BoardModalType } from "../../UI/Components/Board/BoardModal"; +import { ModalState } from "../../UI/Components/Modal/ModalInterface"; +import { LightStore, SpotLightStore } from "../../UI/Store/RightPanelStore/LightStore"; +import { SpotLightModel } from "../../UI/Store/RightPanelStore/SpotLightMOdel"; export class DrawSpotLight implements Command { @@ -11,18 +16,32 @@ export class DrawSpotLight implements Command { let mtx = new Matrix4; let light = JigUtils.Draw(new SpotLight()); + let lightStore = LightStore.GetInstance(); + lightStore.IsDrawLight = true; + lightStore.InitLightData(light); + let configStore = SpotLightStore.GetInstance(); + + app.Editor.ModalManage.RenderModal(SpotLightModel, { store: lightStore, LightType: BoardModalType.SpotLight, configStore: configStore, isNotModify: true }); + + setTimeout(() => + { + app.Editor.UpdateScreen();//保证灯光被画出来 + }, 30); + + let state = await app.Editor.ModalManage.Wait(); + if (state.Status !== ModalState.Ok) return; + + EntityUpdateWrap(light, () => + { + light.CaseShadow = lightStore.lightData.CaseShadow; + light.ShowHelper = lightStore.lightData.ShowHelper; + }); + let ptRes = await app.Editor.GetPoint({ Msg: "选择光源位置", - Raycast: true, - Callback: (p, i) => + Callback: p => { - if (i?.face?.normal) - { - light.Target = i.face.normal.clone().applyMatrix4(mtx.copy(i.object.matrixWorld).setPosition(0, 0, 0)).multiplyScalar(300).add(p); - light.Position = p.clone().add(i.face.normal.clone().multiplyScalar(10)); - } - else - light.Position = p; + light.Position = p; } }); @@ -75,6 +94,27 @@ export class DrawSpotLight2 implements Command async exec() { let light = JigUtils.Draw(new SpotLight()); + let lightStore = LightStore.GetInstance(); + lightStore.IsDrawLight = true; + lightStore.InitLightData(light); + let configStore = SpotLightStore.GetInstance(); + app.Editor.ModalManage.RenderModal(SpotLightModel, { store: lightStore, LightType: BoardModalType.SpotLight, configStore: configStore, isNotModify: true }); + + setTimeout(() => + { + app.Editor.UpdateScreen();//保证灯光被画出来 + }, 30); + + let state = await app.Editor.ModalManage.Wait(); + if (state.Status !== ModalState.Ok) return; + + EntityUpdateWrap(light, () => + { + light.CaseShadow = lightStore.lightData.CaseShadow; + light.ShowHelper = lightStore.lightData.ShowHelper; + light.ApplyMatrix(app.Editor.UCSMatrix); + }); + let ptRes = await app.Editor.GetPoint({ Msg: "选择射灯位置", Callback: p => this.update(light, p), diff --git a/src/Common/EntityUpdateWrap.ts b/src/Common/EntityUpdateWrap.ts new file mode 100644 index 000000000..1ce34d55b --- /dev/null +++ b/src/Common/EntityUpdateWrap.ts @@ -0,0 +1,10 @@ +import { Entity } from "../DatabaseServices/Entity/Entity"; + +export function EntityUpdateWrap(ent: Entity, exec: Function) +{ + let bak = ent.AutoUpdate; + ent.AutoUpdate = false; + exec(); + ent.DeferUpdate(); + ent.AutoUpdate = bak; +} diff --git a/src/DatabaseServices/Lights/PointLight.ts b/src/DatabaseServices/Lights/PointLight.ts index d6885d7da..9d034e145 100644 --- a/src/DatabaseServices/Lights/PointLight.ts +++ b/src/DatabaseServices/Lights/PointLight.ts @@ -24,7 +24,7 @@ export class PointLight extends Light private _Decay: number = 0.45; //PointLightComponent - @AutoRecord SourceRadius = 0;//源半径 范围0-300 + @AutoRecord SourceRadius = 10;//源半径 范围0-300 @AutoRecord SoftSourceRadius = 0;//软源半径 范围0-300 @AutoRecord SourceLength = 0;//源长度 默认0 范围0-1000 diff --git a/src/DatabaseServices/Lights/RectAreaLight.ts b/src/DatabaseServices/Lights/RectAreaLight.ts index c743ce12b..c2f523cdc 100644 --- a/src/DatabaseServices/Lights/RectAreaLight.ts +++ b/src/DatabaseServices/Lights/RectAreaLight.ts @@ -162,19 +162,15 @@ export class RectAreaLight extends Light light.color.copy(this.Color); // light.castShadow = true;//threejs没有支持这个影子 - if (this._ShowHelper) + let help: RectAreaLightHelper; + if (obj.children.length === 1) { - let help: RectAreaLightHelper; - if (obj.children.length === 1) - { - help = new RectAreaLightHelper(light, light.color); - obj.add(help); - } - else - help = obj.children[1] as RectAreaLightHelper; - - help.updateMatrixWorld(); + help = new RectAreaLightHelper(light, light.color); + obj.add(help); } + else + help = obj.children[1] as RectAreaLightHelper; + help.visible = this._ShowHelper; } protected _ReadFile(file: CADFiler) diff --git a/src/Editor/DbClick/DbClick.ts b/src/Editor/DbClick/DbClick.ts index c4f63ff14..d19e01334 100644 --- a/src/Editor/DbClick/DbClick.ts +++ b/src/Editor/DbClick/DbClick.ts @@ -15,6 +15,7 @@ import { HardwareCompositeEntity } from "../../DatabaseServices/Hardware/Hardwar import { HardwareTopline } from "../../DatabaseServices/Hardware/HardwareTopline"; import { DirectionalLight } from "../../DatabaseServices/Lights/DirectionalLight"; import { Light } from "../../DatabaseServices/Lights/Light"; +import { PointLight } from "../../DatabaseServices/Lights/PointLight"; import { RectAreaLight } from "../../DatabaseServices/Lights/RectAreaLight"; import { SpotLight } from "../../DatabaseServices/Lights/SpotLight"; import { Text } from "../../DatabaseServices/Text/Text"; @@ -31,9 +32,10 @@ import { CompositeMatalPanel } from "../../UI/Components/RightPanel/CompositeMet import { RightTabId } from "../../UI/Components/RightPanel/RightPanel"; import { ToplineMetalsPanel } from "../../UI/Components/RightPanel/ToplineMetalsPanel"; import { AppToaster } from "../../UI/Components/Toaster"; +import { IConfigStore } from "../../UI/Store/BoardStore"; import { EntityStore } from "../../UI/Store/EntityStore"; import { compositeMetalsOptionStore, toplineMetalsStore } from "../../UI/Store/RightPanelStore/HardwareStore"; -import { LightStore } from "../../UI/Store/RightPanelStore/LightStore"; +import { LightStore, PointLightStore, RectAreaLightStore, SpotLightStore } from "../../UI/Store/RightPanelStore/LightStore"; import { RightPanelStore } from "../../UI/Store/RightPanelStore/RightPanelStore"; import { SpotLightModel } from "../../UI/Store/RightPanelStore/SpotLightMOdel"; import { CommandWrap } from "../CommandMachine"; @@ -79,6 +81,15 @@ export class DbClickManager extends Singleton if (pickEnt instanceof Light) { + + const width = 500; + const height = 500; + let lightStore = LightStore.GetInstance(); + lightStore.IsDrawLight = false; + lightStore.InitLightData(pickEnt); + let lightType: BoardModalType; + let configStore: IConfigStore; + if (pickEnt instanceof DirectionalLight) { let rightStore = RightPanelStore.GetInstance(); @@ -86,17 +97,27 @@ export class DbClickManager extends Singleton rightStore.m_TabId = RightTabId.Scene; return; } - const width = 500; - const height = 500; - let lightStore = LightStore.GetInstance(); - lightStore.InitLightData(pickEnt); - let isPointLight = pickEnt instanceof SpotLight || pickEnt instanceof RectAreaLight; + else if (pickEnt instanceof SpotLight) + { + lightType = BoardModalType.SpotLight; + configStore = SpotLightStore.GetInstance(); + } + else if (pickEnt instanceof RectAreaLight) + { + lightType = BoardModalType.RectAreaLight; + configStore = RectAreaLightStore.GetInstance(); + } + else if (pickEnt instanceof PointLight) + { + lightType = BoardModalType.PointLight; + configStore = PointLightStore.GetInstance(); + } let p = app.Viewer.WorldToScreen(pickEnt.Position); CADModal.ModalOldPosition.left = `${Math.min(p.x + app.Viewer.canvasContainer.offsetLeft + 10, window.innerWidth - width)}px`; CADModal.ModalOldPosition.top = `${Math.min(p.y + app.Viewer.canvasContainer.offsetTop + 10, window.innerHeight - height)}px`; app.Editor.ModalManage.RenderModeless(SpotLightModel, - { store: lightStore, isPointLight: isPointLight }, { position: ModalPosition.Old }); + { store: lightStore, configStore: configStore, LightType: lightType }, { position: ModalPosition.Old }); } else if (pickEnt instanceof Text) { diff --git a/src/Editor/DefaultConfig.ts b/src/Editor/DefaultConfig.ts index d6ef44c39..0d6569494 100644 --- a/src/Editor/DefaultConfig.ts +++ b/src/Editor/DefaultConfig.ts @@ -5,7 +5,7 @@ import { IUpdateBoardInfosOption } from "../UI/Components/Board/UpdateBoardInfoi import { EMetalsType, ICompHardwareOption, ICylMetalsOption, IExtMetalsOption, IToplineOption } from "../UI/Components/RightPanel/RightPanelInterface"; import { IKuGangDrawOption } from "../UI/Components/Template/TemplateInterface"; import { ECompareType, IBoardFindOption } from "../UI/Store/BoardFindInterface"; -import { BehindBoardOption, BehindHeightPositon, BoardProcessOption, BoardType, BrRelativePos, ClosingStripOption, ComposingType, CurtailType, FaceDirection, IBatchModifyPanelOption, IBoardBatchCurtailOption, LayerBoardOption, LayerNailOption, LinesType, ModifyTextsConfigOption, PointLightOption, RadioType, SideBoardOption, SingleBoardOption, StripType, TBBoardOption, VerticalBoardOption, Viewport2ConfigOption, Viewport3ConfigOption, Viewport4ConfigOption, ViewportConfigOption } from "../UI/Store/BoardInterface"; +import { BehindBoardOption, BehindHeightPositon, BoardProcessOption, BoardType, BrRelativePos, ClosingStripOption, ComposingType, CurtailType, FaceDirection, IBatchModifyPanelOption, IBoardBatchCurtailOption, LayerBoardOption, LayerNailOption, LinesType, ModifyTextsConfigOption, PointLightOption, RadioType, RectAreaLightOption, RightPlaneLightOption, SideBoardOption, SingleBoardOption, SpotLightOption, StripType, TBBoardOption, VerticalBoardOption, Viewport2ConfigOption, Viewport3ConfigOption, Viewport4ConfigOption, ViewportConfigOption } from "../UI/Store/BoardInterface"; import { DoorPosType, HandleHorPos, HandleVePos, IDoorConfigOption, IDrawerConfigOption } from "../UI/Store/DoorInterface"; import { IHSOption } from "../UI/Store/HSInterface"; import { ELatticeArrayType, ILatticeOption } from "../UI/Store/LatticeInterface"; @@ -188,22 +188,75 @@ export const DefaultModifyTextsOption: ModifyTextsConfigOption = { }; Object.freeze(DefaultModifyTextsOption); + export const DefaultPointLightOption: PointLightOption = { version: 1, - distance: 5000, - intensity: 100, lightColor: "#FFFFFF", temperature: 6500, - indirectLightingIntensity: 1, - showHelper: true, - specularScale: 1, - caseShado: true, - sourceRadius: 0, - softSourceRadius: 0, - sourceLength: 0, + Intensity: 100, + IndirectLightingIntensity: 1, + SpecularScale: 1, + SourceRadius: 10, + SoftSourceRadius: 0, + SourceLength: 0, + CaseShadow: true, }; Object.freeze(DefaultPointLightOption); +export const DefaultSpotLightOption: SpotLightOption = { + version: 1, + lightColor: "#FFFFFF", + temperature: 6500, + Intensity: 100, + IndirectLightingIntensity: 1, + SpecularScale: 1, + SourceRadius: 0, + SoftSourceRadius: 0, + SourceLength: 0, + Angle: 40, + InnerConeAngle: 0, + AttenuationRadius: 300, + CaseShadow: true, + ShowHelper: true, +}; +Object.freeze(DefaultSpotLightOption); + +export const DefaultRectAreaLightOption: RectAreaLightOption = { + version: 1, + lightColor: "#FFFFFF", + temperature: 6500, + Intensity: 100, + IndirectLightingIntensity: 1, + SpecularScale: 1, + AttenuationRadius: 300, + Width: 150, + Height: 150, + BarnDoorAngle: 90, + BarnDoorLength: 20, + CaseShadow: true, + ShowHelper: true, +}; +Object.freeze(DefaultRectAreaLightOption); + +export const DefaultRightPlaneLightOption: RightPlaneLightOption = { + version: 1, + ShowHemiLight: true, + ShowSunLight: true, + SkyLightColor: "#FFFFFF", + SkyLightIntensity: 1, + SkyLightIndirectLightingIntensity: 1, + SunLightIntensity: 50, + SunLightIndirectLightingIntensity: 1, + SunLightColor: "#FFFFFF", + SunLightTemperature: 6500, + SunLightElevationDeg: 60, + SunLightRotateDeg: 300, + ShowExposure: true, + AutoExposure: false, + ExposureCompensation: 0 +}; +Object.freeze(DefaultRightPlaneLightOption); + export const DefaultSingleBoardOption: SingleBoardOption = { version: 1, name: "层板", diff --git a/src/UI/Components/Board/BoardModal.tsx b/src/UI/Components/Board/BoardModal.tsx index 16c3d2107..77e2d96df 100644 --- a/src/UI/Components/Board/BoardModal.tsx +++ b/src/UI/Components/Board/BoardModal.tsx @@ -63,6 +63,9 @@ export enum BoardModalType AutoHoleFaceSetting = "AutoHoleFaceSetting",//自动孔面设置 EditViewSetting = "EditViewSetting",//编辑视口配置 PointLight = "PointLight",//点灯光配置 + SpotLight = "SpotLight",//射灯配置 + RectAreaLight = "RectAreaLight",//矩形灯配置 + RightPlaneLight = "RightPlaneLight",//右侧栏灯光配置 } export interface BoardModalProps { diff --git a/src/UI/Components/Board/UserConfig.tsx b/src/UI/Components/Board/UserConfig.tsx index eed85dca6..c5f5420c4 100644 --- a/src/UI/Components/Board/UserConfig.tsx +++ b/src/UI/Components/Board/UserConfig.tsx @@ -45,6 +45,7 @@ interface IConfigProps store: IConfigStore; isUpdate?: boolean; isExpImp?: boolean; + isNotModify?: boolean; //是否显示保存和删除配置按钮 otherConfig?: () => AnyObject; configurationType?: string; } @@ -117,6 +118,10 @@ export class UserConfig extends React.Component{ if (!this.props.isUpdate) { + if (confNames.length === 0) + { + await this.handleInitConfig(); + } this.props.store.configName = ""; return; } @@ -188,22 +193,26 @@ export class UserConfig extends React.Component{ >} /> } /> -