You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/src/Common/LightUtils.ts

36 lines
1.1 KiB

import { Box3, DirectionalLight as TDirLight, Mesh, OrthographicCamera } from "three";
import { app } from "../ApplicationServices/Application";
import { DirectionalLight } from "../DatabaseServices/Lights/DirectionalLight";
import { GetBox } from "../Geometry/GeUtils";
import { CameraUpdate } from "../GraphicsSystem/CameraUpdate";
let cameraUpdate = new CameraUpdate();
cameraUpdate.SetSize(2028, 2048);
let box = new Box3();
export function DirLightShadowArea(light: DirectionalLight, calcBox = true)
{
let direction = light.Position.clone().sub(light.Target).normalize();
cameraUpdate.LookAt(direction.negate());
if (calcBox)
{
box.makeEmpty();
//场景内的包围盒
for (let obj of app.Viewer.VisibleObjects)
if (obj instanceof Mesh)
box.union(GetBox(obj));
cameraUpdate.ZoomExtensBox3(box);
}
light.DrawObject.traverse(o =>
{
if (o instanceof TDirLight)
{
o.shadow.camera.copy(cameraUpdate.Camera as OrthographicCamera);
o.shadow.camera.updateProjectionMatrix();
}
});
}