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(); } }); }