!1718 增强:灯源可开关,底部工具栏增加一键开关

pull/1717/MERGE
林三 3 years ago committed by ChenX
parent e3006337a8
commit 3ac03e0d0a

@ -7,6 +7,7 @@ import { Light } from "./Light";
export class AmbientLight extends Light export class AmbientLight extends Light
{ {
protected _Intensity = 0.9; protected _Intensity = 0.9;
protected _OpenLight = true;//开灯
protected InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D protected InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D
{ {
let light = new TAmbientLight(this.Color, this._Intensity); let light = new TAmbientLight(this.Color, this._Intensity);

@ -24,6 +24,7 @@ export class DirectionalLight extends Light
OnlyRenderType = true; OnlyRenderType = true;
private _Target = new Vector3(); private _Target = new Vector3();
protected _ShowHelper = false; protected _ShowHelper = false;
protected _OpenLight = true;//开灯
constructor() constructor()
{ {

@ -12,6 +12,7 @@ export class HemisphereLight extends Light
protected _Intensity = 1; protected _Intensity = 1;
@AutoRecord AutoExposure = false;//自动曝光 @AutoRecord AutoExposure = false;//自动曝光
@AutoRecord ExposureCompensation = 1;//默认为1 @AutoRecord ExposureCompensation = 1;//默认为1
protected _OpenLight = true;//开灯
get GroundColor() { return this._GroundColor; } get GroundColor() { return this._GroundColor; }

@ -27,6 +27,8 @@ export class Light extends Entity
@AutoRecord SpecularScale = 1;//高光度范围 默认1 (物理) @AutoRecord SpecularScale = 1;//高光度范围 默认1 (物理)
protected _CaseShadow = true;//投射阴影 protected _CaseShadow = true;//投射阴影
protected _OpenLight = Light.DefaultOpenLight;//开灯
static DefaultOpenLight = false;
Clone() Clone()
{ {
@ -43,6 +45,15 @@ export class Light extends Entity
this.Update(); this.Update();
} }
get OpenLight() { return this._OpenLight; }
set OpenLight(v: boolean)
{
if (v === this._OpenLight) return;
this._OpenLight = v;
this.Update();
}
//因为有set 所以必须11对应 //因为有set 所以必须11对应
get Position() get Position()
{ {
@ -103,6 +114,7 @@ export class Light extends Entity
{ {
en.intensity = this.WebIntensity; en.intensity = this.WebIntensity;
en.color = this._LightColor; en.color = this._LightColor;
en.visible = this.OpenLight;
} }
get Intensity() get Intensity()
{ {

@ -1,10 +1,11 @@
import { Light as TLight, Mesh, MeshBasicMaterial, Object3D, PointLight as TPointLight, SphereGeometry } from 'three'; import { Group, Mesh, MeshBasicMaterial, Object3D, PointLight as TPointLight, SphereGeometry } from 'three';
import { HostApplicationServices } from '../../ApplicationServices/HostApplicationServices'; import { HostApplicationServices } from '../../ApplicationServices/HostApplicationServices';
import { RenderType } from '../../GraphicsSystem/RenderType'; import { RenderType } from '../../GraphicsSystem/RenderType';
import { AutoRecord } from '../AutoRecord'; import { AutoRecord } from '../AutoRecord';
import { Factory } from '../CADFactory'; import { Factory } from '../CADFactory';
import { CADFiler } from '../CADFiler'; import { CADFiler } from '../CADFiler';
import { Light } from './Light'; import { Light } from './Light';
import { PointLightHelper } from './PointLightHelper';
/** /**
* *
@ -31,6 +32,7 @@ export class PointLight extends Light
//LocalLightComponent //LocalLightComponent
//Radius:number 没设置这个 //Radius:number 没设置这个
@AutoRecord AttenuationRadius = 300; //衰减半径 10-1000 @AutoRecord AttenuationRadius = 300; //衰减半径 10-1000
protected _ShowHelper = true;
constructor() constructor()
{ {
@ -68,6 +70,7 @@ export class PointLight extends Light
protected InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D protected InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D
{ {
let lightGroup = new Group();
let ptLight = new TPointLight(this._LightColor, this.WebIntensity, this._Distance, this._Decay); let ptLight = new TPointLight(this._LightColor, this.WebIntensity, this._Distance, this._Decay);
ptLight.castShadow = HostApplicationServices.UseShadow; ptLight.castShadow = HostApplicationServices.UseShadow;
@ -77,14 +80,29 @@ export class PointLight extends Light
let lightGeo = new SphereGeometry(50); let lightGeo = new SphereGeometry(50);
let geoMat = new MeshBasicMaterial({ color: this._LightColor }); let geoMat = new MeshBasicMaterial({ color: this._LightColor });
ptLight.add(new Mesh(lightGeo, geoMat)); ptLight.add(new Mesh(lightGeo, geoMat));
return ptLight;
let helper = new PointLightHelper(ptLight.distance / 4, this.Color);
lightGroup.add(ptLight, helper);
lightGroup.matrixAutoUpdate = false;
lightGroup.matrix.copy(this._Matrix);
lightGroup.updateMatrixWorld(true);
this.UpdateDrawObject(renderType, lightGroup);
return lightGroup;
} }
UpdateDrawObject(type: RenderType, en: TLight) UpdateDrawObject(type: RenderType, en: Object3D)
{ {
super.UpdateDrawObject(type, en); let ptLight = en.children[0] as TPointLight;
let ptLight = en as TPointLight; super.UpdateDrawObject(type, ptLight);
ptLight.distance = this._Distance; ptLight.distance = this._Distance;
ptLight.decay = this._Decay; ptLight.decay = this._Decay;
let helper = en.children[1] as PointLightHelper;
helper.visible = this._ShowHelper;
if (this._ShowHelper)
helper.color = this.Color;
helper.update();
} }

@ -0,0 +1,96 @@
import { BufferGeometry, Color, CylinderBufferGeometry, Float32BufferAttribute, LineBasicMaterial, LineSegments, MathUtils, Matrix4, Mesh, MeshBasicMaterial, Object3D, PointLight, SphereBufferGeometry, Vector3 } from 'three';
export class PointLightHelper extends Object3D
{
light: PointLight;
color: Color | string | number;
material: LineBasicMaterial;
cone: LineSegments[];
mesh: Mesh[];
constructor(distance: number, color?: Color | string | number)
{
const geometry = new BufferGeometry();
const positions = [];
for (let i = 0, j = 1, l = 32; i < l; i++, j++)
{
const p1 = (i / l) * Math.PI * 2;
const p2 = (j / l) * Math.PI * 2;
positions.push(
Math.cos(p1) * distance, Math.sin(p1) * distance, 0,
Math.cos(p2) * distance, Math.sin(p2) * distance, 0
);
}
geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
super();
this.color = color;
this.matrixAutoUpdate = false;
this.material = new LineBasicMaterial({ fog: false });;
this.cone = [];
this.mesh = [];
this.cone[0] = new LineSegments(geometry, this.material[0]);
this.cone[1] = this.cone[0].clone();
let moveMatInv = new Matrix4().getInverse(this.matrix);
let roMat = new Matrix4().makeRotationAxis(new Vector3(0, 1, 0), MathUtils.degToRad(60));
let mtx = this.matrix.clone().multiply(roMat).multiply(moveMatInv);
this.cone[1].applyMatrix4(mtx);
this.cone[2] = this.cone[1].clone();
this.cone[2].applyMatrix4(mtx);
let cylinderRoMat = new Matrix4().makeRotationAxis(new Vector3(1, 0, 0), MathUtils.degToRad(90));
let cylinderMtx = this.matrix.clone().multiply(cylinderRoMat).multiply(moveMatInv);
let cylinderGeometry = new CylinderBufferGeometry(40, 40, 80, 32); //灯泡圆柱
this.mesh[0] = new Mesh(cylinderGeometry, new MeshBasicMaterial({ color: 0xFFEAAD }));
this.mesh[0].applyMatrix4(cylinderMtx);
this.mesh[0].position.add(new Vector3(0, 0, 50));
this.mesh[0].updateMatrix();
let sphereBufferGeometry = new SphereBufferGeometry(75, 32, 32); //灯泡球体
this.mesh[1] = new Mesh(sphereBufferGeometry, this.material);
this.mesh[1].position.sub(new Vector3(0, 0, 30));
this.mesh[1].updateMatrix();
this.add(this.cone[0], this.cone[1], this.cone[2], this.mesh[0], this.mesh[1]);
}
dispose()
{
this.material.dispose();
this.cone[0].geometry.dispose();
//@ts-ignore
this.cone[0].material.dispose();
this.cone[1].geometry.dispose();
//@ts-ignore
this.cone[1].material.dispose();
this.cone[2].geometry.dispose();
//@ts-ignore
this.cone[2].material.dispose();
this.mesh[0].geometry.dispose();
//@ts-ignore
this.mesh[0].material.dispose();
this.mesh[1].geometry.dispose();
//@ts-ignore
this.mesh[1].material.dispose();
}
update()
{
//@ts-ignore
this.mesh[1].material.color.set(this.color).multiplyScalar(0.9);
}
}

@ -29,7 +29,6 @@ export class RectAreaLight extends Light
@AutoRecord BarnDoorLength: number = 20;//0-100 挡光板长度 @AutoRecord BarnDoorLength: number = 20;//0-100 挡光板长度
@AutoRecord SourceTexture: ObjectId;//Texture 源纹理 默认无 可以追加一张贴图 @AutoRecord SourceTexture: ObjectId;//Texture 源纹理 默认无 可以追加一张贴图
protected _ShowHelper = true; protected _ShowHelper = true;
get Target() get Target()
{ {
return this._Target.clone(); return this._Target.clone();

@ -1,5 +1,6 @@
import { Button, Menu, MenuItem, Popover } from "@blueprintjs/core"; import { Button, Menu, MenuItem, Popover } from "@blueprintjs/core";
import { observable } from "mobx";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import * as React from "react"; import * as React from "react";
import { app } from "../ApplicationServices/Application"; import { app } from "../ApplicationServices/Application";
@ -7,6 +8,7 @@ import { Entity } from "../DatabaseServices/Entity/Entity";
import { Light } from "../DatabaseServices/Lights/Light"; import { Light } from "../DatabaseServices/Lights/Light";
import { DownPanelStore, LightDataModeType, LightsData } from "../UI/Store/DownPanelStore"; import { DownPanelStore, LightDataModeType, LightsData } from "../UI/Store/DownPanelStore";
import { CommandWrap } from "./CommandMachine"; import { CommandWrap } from "./CommandMachine";
import { userConfig } from "./UserConfig";
/** /**
* . * .
@ -14,20 +16,21 @@ import { CommandWrap } from "./CommandMachine";
@observer @observer
export class LightsMenu extends React.Component<{ GetLightType: (ent: Entity) => string; }> export class LightsMenu extends React.Component<{ GetLightType: (ent: Entity) => string; }>
{ {
public state = { @observable isOpenMenu = false;
isOpenMenu: false,
};
render() render()
{ {
return ( return (
<Popover <Popover
isOpen={this.state.isOpenMenu ? true : undefined} isOpen={this.isOpenMenu && userConfig.lightHelper}
modifiers={{ arrow: { enabled: false } }} modifiers={{ arrow: { enabled: false } }}
onClosed={this.Close} onClosed={this.Close}
> >
<Button <Button
style={{ fontSize: "11px", textAlign: "center", minHeight: "15px", height: "15px", lineHeight: "1px" }} style={{ fontSize: "11px", textAlign: "center", minHeight: "15px", height: "15px", lineHeight: "1px" }}
text="灯光助手" text="灯光助手"
disabled={!userConfig.lightHelper}
onClick={() => { this.isOpenMenu = !this.isOpenMenu; }}
/> />
{this.RenderMenu()} {this.RenderMenu()}
</Popover > </Popover >
@ -75,6 +78,17 @@ export class LightsMenu extends React.Component<{ GetLightType: (ent: Entity) =>
if (downStore.lightsData[0].enable) if (downStore.lightsData[0].enable)
downStore.lightsData[0].enable = false; downStore.lightsData[0].enable = false;
} }
else if (data.mode !== LightDataModeType.A && data.enable)
{
let isAllTrue = true;
for (let data of downStore.lightsData)
{
if (data.mode === LightDataModeType.A || data.enable)
continue;
isAllTrue = false;
}
if (isAllTrue) downStore.lightsData[0].enable = true;
}
if (data.mode === LightDataModeType.A && data.enable) //选"全部"打勾时,所灯光ui打勾 if (data.mode === LightDataModeType.A && data.enable) //选"全部"打勾时,所灯光ui打勾
{ {
for (let data of downStore.lightsData) for (let data of downStore.lightsData)

@ -123,6 +123,7 @@ export class UserConfig implements IConfigStore
@observable lightHelper: boolean = false; //是否显示灯光助手 @observable lightHelper: boolean = false; //是否显示灯光助手
@observable isShowSkyBox: boolean = false;//是否显示天空球,仅在透视相机下显示 @observable isShowSkyBox: boolean = false;//是否显示天空球,仅在透视相机下显示
@observable openLightConfig: boolean = false; //画灯光前是否打开配置 @observable openLightConfig: boolean = false; //画灯光前是否打开配置
@observable oneKeyOpenLight: boolean = false; //一键开关灯光(通电/不通电)
constructor() constructor()
{ {
this.Init(); this.Init();

@ -9,6 +9,7 @@ import { Post, RequestStatus } from '../../Common/Request';
import { Entity } from '../../DatabaseServices/Entity/Entity'; import { Entity } from '../../DatabaseServices/Entity/Entity';
import { DirectionalLight } from '../../DatabaseServices/Lights/DirectionalLight'; import { DirectionalLight } from '../../DatabaseServices/Lights/DirectionalLight';
import { Light } from '../../DatabaseServices/Lights/Light'; import { Light } from '../../DatabaseServices/Lights/Light';
import { PointLight } from '../../DatabaseServices/Lights/PointLight';
import { RectAreaLight } from '../../DatabaseServices/Lights/RectAreaLight'; import { RectAreaLight } from '../../DatabaseServices/Lights/RectAreaLight';
import { SpotLight } from '../../DatabaseServices/Lights/SpotLight'; import { SpotLight } from '../../DatabaseServices/Lights/SpotLight';
import { commandMachine, CommandWrap } from '../../Editor/CommandMachine'; import { commandMachine, CommandWrap } from '../../Editor/CommandMachine';
@ -270,6 +271,21 @@ export class DownPanel extends React.Component<{ store?: DownPanelStore; }, {}>
await userConfigStore.SaveConfig(BoardModalType.UserConfig, userConfig); await userConfigStore.SaveConfig(BoardModalType.UserConfig, userConfig);
return; return;
} }
if (key === "oneKeyOpenLight")
{
userConfig.oneKeyOpenLight = !userConfig.oneKeyOpenLight;
Light.DefaultOpenLight = userConfig.oneKeyOpenLight;
CommandWrap(() =>
{
for (let light of app.Database.Lights.Entitys)
{
if (light instanceof SpotLight || light instanceof RectAreaLight || light instanceof PointLight)
(light as Light).OpenLight = userConfig.oneKeyOpenLight;
}
}, userConfig.oneKeyOpenLight ? "一键开灯" : "一键关灯");
e.currentTarget.blur();
return;
}
this.props.store[key] = e.currentTarget.checked; this.props.store[key] = e.currentTarget.checked;
if (!app.Viewer.isLayout) if (!app.Viewer.isLayout)
@ -307,6 +323,8 @@ export class DownPanel extends React.Component<{ store?: DownPanelStore; }, {}>
return LightDataModeType.R; return LightDataModeType.R;
else if (ent instanceof DirectionalLight) else if (ent instanceof DirectionalLight)
return LightDataModeType.D; return LightDataModeType.D;
else if (ent instanceof PointLight)
return LightDataModeType.P;
} }
componentDidMount() componentDidMount()
{ {
@ -465,8 +483,23 @@ export class DownPanel extends React.Component<{ store?: DownPanelStore; }, {}>
> >
<LightsMenu GetLightType={this.GetLightType} /> <LightsMenu GetLightType={this.GetLightType} />
</Switch> </Switch>
</div> <div style={switchStyle}>
<Tooltip
content="注意:开启灯光效果会造成性能下降(卡顿)"
position={Position.TOP}
>
<Switch
label='灯光光照'
checked={userConfig.oneKeyOpenLight}
data-key="oneKeyOpenLight"
onChange={this.handleChange}
alignIndicator={Alignment.RIGHT}
style={switchStyle}
/>
</Tooltip>
</div > </div >
</div>
</div>
); );
} }
} }

@ -48,7 +48,8 @@ export enum LightDataModeType
A = "AllLight", A = "AllLight",
S = "SpotLight", S = "SpotLight",
R = "RectAreaLight", R = "RectAreaLight",
D = "DirectionalLight" D = "DirectionalLight",
P = "PointLight",
} }
/** /**
@ -135,6 +136,11 @@ export class DownPanelStore
name: "射灯", name: "射灯",
enable: true enable: true
}, },
{
mode: LightDataModeType.P,
name: "点光源",
enable: true
},
{ {
mode: LightDataModeType.R, mode: LightDataModeType.R,
name: "矩形灯", name: "矩形灯",

@ -118,7 +118,7 @@ export class SpotLightModel extends React.Component<{ store: LightStore; configS
<div className={Classes.DIALOG_BODY}> <div className={Classes.DIALOG_BODY}>
{ {
(this.props.LightType === BoardModalType.PointLight) || <div style={{ height: 25 }}> <div style={{ height: 25 }}>
<Switch <Switch
checked={lightData.ShowHelper} checked={lightData.ShowHelper}
label="显示灯光助手" label="显示灯光助手"

@ -13,6 +13,7 @@ import { GetIndexDBID } from "../../Common/Utils";
import { CADFiler } from "../../DatabaseServices/CADFiler"; import { CADFiler } from "../../DatabaseServices/CADFiler";
import { CommandServer } from "../../DatabaseServices/CommandServer"; import { CommandServer } from "../../DatabaseServices/CommandServer";
import { FileServer } from "../../DatabaseServices/FileServer"; import { FileServer } from "../../DatabaseServices/FileServer";
import { Light } from "../../DatabaseServices/Lights/Light";
import { LimitCommand } from "../../Editor/CommandRegister"; import { LimitCommand } from "../../Editor/CommandRegister";
import { userConfig } from "../../Editor/UserConfig"; import { userConfig } from "../../Editor/UserConfig";
import { RenderType } from "../../GraphicsSystem/RenderType"; import { RenderType } from "../../GraphicsSystem/RenderType";
@ -133,6 +134,8 @@ export class UserConfigStore extends Singleton
//更新背景 //更新背景
app.Viewer.Renderer.setClearColor(userConfig.SystemConfig.background); app.Viewer.Renderer.setClearColor(userConfig.SystemConfig.background);
Light.DefaultOpenLight = userConfig.oneKeyOpenLight;
} }
else else
{ {

Loading…
Cancel
Save