!1677 功能:实现矩形光助手:挡板角度,挡板长度功能

pull/1695/MERGE
黄诗津 3 years ago committed by ChenX
parent 540f4265ba
commit 126df75a94

@ -603,7 +603,7 @@ function ConverRectAreaLight2Data(light: RectAreaLight)
ed.AttenuationRadius = light.AttenuationRadius; ed.AttenuationRadius = light.AttenuationRadius;
ed.BarnDoorAngle = light.BarnDoorAngle; ed.BarnDoorAngle = light.BarnDoorAngle;
ed.BarnDoorLength = light.BarnDoorLength; ed.BarnDoorLength = light.BarnDoorLength * 0.1;
ed.SourceTexture = light.SourceTexture; ed.SourceTexture = light.SourceTexture;
ed.IndirectLightingIntensity = light.IndirectLightingIntensity; ed.IndirectLightingIntensity = light.IndirectLightingIntensity;

@ -3,6 +3,7 @@ import { UpdateDraw } from "../../Common/Status";
import { Box3Ext } from "../../Geometry/Box"; import { Box3Ext } from "../../Geometry/Box";
import { equalv3, YAxis, ZeroVec } from "../../Geometry/GeUtils"; import { equalv3, YAxis, ZeroVec } from "../../Geometry/GeUtils";
import { RenderType } from "../../GraphicsSystem/RenderType"; import { RenderType } from "../../GraphicsSystem/RenderType";
import { equaln } from "../../Nest/Common/Util";
import { AutoRecord } from "../AutoRecord"; import { AutoRecord } from "../AutoRecord";
import { Factory } from "../CADFactory"; import { Factory } from "../CADFactory";
import { CADFiler } from "../CADFiler"; import { CADFiler } from "../CADFiler";
@ -25,8 +26,8 @@ export class RectAreaLight extends Light
@AutoRecord AttenuationRadius = 300; //衰减半径 10-1000 @AutoRecord AttenuationRadius = 300; //衰减半径 10-1000
//RectLightComponent extends LocalLightComponent //RectLightComponent extends LocalLightComponent
@AutoRecord BarnDoorAngle: number = 90;//0-90 挡光板角度 private _BarnDoorAngle: number = 0; //0-90 挡光板角度
@AutoRecord BarnDoorLength: number = 20;//0-100 挡光板长度 private _BarnDoorLength: number = 0; //0-100 挡光板长度
@AutoRecord SourceTexture: ObjectId;//Texture 源纹理 默认无 可以追加一张贴图 @AutoRecord SourceTexture: ObjectId;//Texture 源纹理 默认无 可以追加一张贴图
get Target() get Target()
@ -41,6 +42,63 @@ export class RectAreaLight extends Light
this.Update(UpdateDraw.Geometry); this.Update(UpdateDraw.Geometry);
} }
get Height() { return this._Height; }
set Height(v: number)
{
if (equaln(v, this._Height, 1e-2)) return;
this.WriteAllObjectRecord();
this._Height = v;
this.Update();
}
get Width() { return this._Width; }
set Width(v: number)
{
if (equaln(v, this._Width, 1e-2)) return;
this.WriteAllObjectRecord();
this._Width = v;
this.Update();
}
get BarnDoorAngle() { return this._BarnDoorAngle; }
set BarnDoorAngle(v: number)
{
if (equaln(this._BarnDoorAngle, v, 1e-2)) return;
this.WriteAllObjectRecord();
this._BarnDoorAngle = v;
this.Update();
}
get BarnDoorLength() { return this._BarnDoorLength; }
set BarnDoorLength(v: number)
{
if (equaln(this._BarnDoorLength, v, 1e-2)) return;
this.WriteAllObjectRecord();
this._BarnDoorLength = v;
this.Update();
}
get WebIntensity()
{
let x = this._Intensity / 2000;
x = Math.pow(x, 0.5);
return (x * 50) / (Math.PI);//流明转cd 文档是4pi
}
get BoundingBoxInOCS()
{
return new Box3Ext(new Vector3(-this._Width * 0.5, -this._Height * 0.5, 0), new Vector3(this._Width * 0.5, this._Height * 0.5, 0.01));
}
get BoundingBox()
{
return new Box3().setFromCenterAndSize(new Vector3(), new Vector3(this._Width, this._Height)).applyMatrix4(this._Matrix);
}
GetGripPoints(): Array<Vector3> GetGripPoints(): Array<Vector3>
{ {
let heightHalf = this._Height * 0.5; let heightHalf = this._Height * 0.5;
@ -57,6 +115,7 @@ export class RectAreaLight extends Light
]; ];
return pts; return pts;
} }
MoveGripPoints(indexList: number[], vec: Vector3) MoveGripPoints(indexList: number[], vec: Vector3)
{ {
let vecInv = vec.clone().applyMatrix4(this.OCSInv.setPosition(0, 0, 0)); let vecInv = vec.clone().applyMatrix4(this.OCSInv.setPosition(0, 0, 0));
@ -125,6 +184,7 @@ export class RectAreaLight extends Light
]; ];
return pts; return pts;
} }
MoveStretchPoints(ids: number[], vec: Vector3) MoveStretchPoints(ids: number[], vec: Vector3)
{ {
if (ids.length === 4) if (ids.length === 4)
@ -203,43 +263,6 @@ export class RectAreaLight extends Light
} }
} }
get Height()
{
return this._Height;
}
get Width()
{
return this._Width;
}
set Height(v: number)
{
this.WriteAllObjectRecord();
this._Height = v;
this.Update();
}
set Width(v: number)
{
this.WriteAllObjectRecord();
this._Width = v;
this.Update();
}
get WebIntensity()
{
let x = this._Intensity / 2000;
x = Math.pow(x, 0.5);
return (x * 50) / (Math.PI);//流明转cd 文档是4pi
}
get BoundingBoxInOCS()
{
return new Box3Ext(new Vector3(-this._Width * 0.5, -this._Height * 0.5, 0), new Vector3(this._Width * 0.5, this._Height * 0.5, 0.01));
}
get BoundingBox()
{
return new Box3().setFromCenterAndSize(new Vector3(), new Vector3(this._Width, this._Height)).applyMatrix4(this._Matrix);
}
protected InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D protected InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D
{ {
let lightGroup = new Group(); let lightGroup = new Group();
@ -266,6 +289,14 @@ export class RectAreaLight extends Light
} }
else else
help = obj.children[1] as RectAreaLightHelper; help = obj.children[1] as RectAreaLightHelper;
help.BarnDoorAngle = 90 - this.BarnDoorAngle;
help.BarnDoorLength = this.BarnDoorLength;
help.updataRange();
help.updateMatrixWorld();
help = obj.children[1] as RectAreaLightHelper;
help.visible = this._ShowHelper; help.visible = this._ShowHelper;
} }
@ -281,11 +312,10 @@ export class RectAreaLight extends Light
if (ver > 1) if (ver > 1)
{ {
this.AttenuationRadius = file.Read(); this.AttenuationRadius = file.Read();
this.BarnDoorAngle = file.Read(); this._BarnDoorAngle = file.Read();
this.BarnDoorLength = file.Read(); this._BarnDoorLength = file.Read();
this.SourceTexture = file.Read(); this.SourceTexture = file.Read();
} }
} }
//对象将自身数据写入到文件. //对象将自身数据写入到文件.
WriteFile(file: CADFiler) WriteFile(file: CADFiler)
@ -298,8 +328,8 @@ export class RectAreaLight extends Light
//ver2 //ver2
file.Write(this.AttenuationRadius); file.Write(this.AttenuationRadius);
file.Write(this.BarnDoorAngle); file.Write(this._BarnDoorAngle);
file.Write(this.BarnDoorLength); file.Write(this._BarnDoorLength);
file.Write(this.SourceTexture); file.Write(this.SourceTexture);
} }
} }

@ -9,45 +9,51 @@ export class RectAreaLightHelper extends Line
color: Color; color: Color;
material: LineBasicMaterial; material: LineBasicMaterial;
children: [Mesh]; children: [Mesh];
BarnDoorLength: number;
BarnDoorAngle: number;
private _posAtt: Float32BufferAttribute;
private _indexAtt: Float32BufferAttribute;
constructor(light: TRectAreaLight, color: Color) constructor(light: TRectAreaLight, color: Color)
{ {
const positions = [1, 1, 0, -1, 1, 0, -1, -1, 0, 1, -1, 0, 1, 1, 0, const positions = [1, 1, 0, -1, 1, 0, -1, -1, 0, 1, -1, 0, 1, 1, 0,
0.618, 0.618, 0, 0.618, 0.618, 0,
0.618, 0.618, -100, // 0.618, 0.618, -100,
0.618, 0.618, 0, // 0.618, 0.618, 0,
-0.618, 0.618, 0, -0.618, 0.618, 0,
-1, 1, 0, -1, 1, 0,
-0.618, 0.618, 0, -0.618, 0.618, 0,
-0.618, 0.618, -100, // -0.618, 0.618, -100,
-0.618, 0.618, 0, // -0.618, 0.618, 0,
-0.618, -0.618, 0, -0.618, -0.618, 0,
-1, -1, 0, -1, -1, 0,
-0.618, -0.618, 0, -0.618, -0.618, 0,
-0.618, -0.618, -100, // -0.618, -0.618, -100,
-0.618, -0.618, 0, // -0.618, -0.618, 0,
0.618, -0.618, 0, 0.618, -0.618, 0,
1, -1, 0, 1, -1, 0,
0.618, -0.618, 0, 0.618, -0.618, 0,
0.618, -0.618, -100, // 0.618, -0.618, -100,
0.618, -0.618, 0, // 0.618, -0.618, 0,
0.618, 0.618, 0 0.618, 0.618, 0
]; ];
const geometry = new BufferGeometry(); const geometry = new BufferGeometry();
geometry.setAttribute('position', new Float32BufferAttribute(positions, 3)); let posatt = new Float32BufferAttribute(positions, 3);
geometry.setAttribute('position', posatt);
geometry.computeBoundingSphere(); geometry.computeBoundingSphere();
const material = new LineBasicMaterial({ fog: false }); const material = new LineBasicMaterial({ fog: false });
super(geometry, material); super(geometry, material);
this._posAtt = posatt;
this.light = light; this.light = light;
this.color = color; // optional hardwired color for the helper this.color = color; // optional hardwired color for the helper
this.type = 'RectAreaLightHelper'; this.type = 'RectAreaLightHelper';
@ -56,7 +62,8 @@ export class RectAreaLightHelper extends Line
const positions2 = [1, 1, 0, -1, 1, 0, -1, -1, 0, 1, 1, 0, -1, -1, 0, 1, -1, 0]; const positions2 = [1, 1, 0, -1, 1, 0, -1, -1, 0, 1, 1, 0, -1, -1, 0, 1, -1, 0];
const geometry2 = new BufferGeometry(); const geometry2 = new BufferGeometry();
geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3)); this._indexAtt = new Float32BufferAttribute(positions2, 3);
geometry2.setAttribute('position', this._indexAtt);
geometry2.computeBoundingSphere(); geometry2.computeBoundingSphere();
this.add(new Mesh(geometry2, new MeshBasicMaterial({ side: BackSide, fog: false, transparent: true, opacity: 0.8 }))); this.add(new Mesh(geometry2, new MeshBasicMaterial({ side: BackSide, fog: false, transparent: true, opacity: 0.8 })));
@ -91,6 +98,44 @@ export class RectAreaLightHelper extends Line
this.children[0].matrixWorld.copy(this.matrixWorld); this.children[0].matrixWorld.copy(this.matrixWorld);
} }
updataRange()
{
let [n, w, h] = [1, 1, 1];
let t = Math.sin(this.BarnDoorAngle * Math.PI / 180) * this.BarnDoorLength;
let cosAngle = Math.cos(this.BarnDoorAngle * Math.PI / 180);
if (Math.floor(cosAngle * 1e5))
{
w = ((this.light.width + this.BarnDoorLength * 2) / this.light.width - 1) * cosAngle + 1;
h = ((this.light.height + this.BarnDoorLength * 2) / this.light.height - 1) * cosAngle + 1;
}
let positions = [w, h, -t, -w, h, -t, -w, -h, -t, w, -h, -t, w, h, -t,
n, n, 0,
-n, n, 0,
-w, h, -t,
-n, n, 0,
-n, -n, 0,
-w, -h, -t,
-n, -n, 0,
n, -n, 0,
w, -h, -t,
n, -n, 0,
n, n, 0
];
let positions2 = [w, h, -t, -w, h, -t, -w, -h, -t, w, h, -t, -w, -h, -t, w, -h, -t];
this._posAtt.copyArray(positions);
this._posAtt.needsUpdate = true;
this._indexAtt.copyArray(positions2);
this._indexAtt.needsUpdate = true;
}
dispose() dispose()
{ {
this.geometry.dispose(); this.geometry.dispose();

@ -478,6 +478,7 @@ export class InputAndSlider extends React.Component<{ pars: string[], store: Lig
this.props.store.lightData.Angle = value; this.props.store.lightData.Angle = value;
this.props.store.currentSelectEnt["Angle"] = MathUtils.degToRad(parseFloat(value)); this.props.store.currentSelectEnt["Angle"] = MathUtils.degToRad(parseFloat(value));
} }
this.props.store.currentSelectEnt.Update();
break; break;
case "Angle": case "Angle":
this.props.store.lightData.Angle = value; this.props.store.lightData.Angle = value;
@ -499,7 +500,6 @@ export class InputAndSlider extends React.Component<{ pars: string[], store: Lig
} }
if (userConfig.synchronousEnable) if (userConfig.synchronousEnable)
app.WebSocket.Send(JSON.stringify(Entitys2Data([this.props.store.currentSelectEnt]))); app.WebSocket.Send(JSON.stringify(Entitys2Data([this.props.store.currentSelectEnt])));
this.props.store.currentSelectEnt.Update();
app.Editor.UpdateScreen(); app.Editor.UpdateScreen();
} }

Loading…
Cancel
Save