fix: lighting toggler no longer fires on unload

This commit is contained in:
TrèsAbhi committed 2025-10-04 22:05:36 -05:00
1 parent e7fe3a4baf
commit 889a92e98b
1 file changed
+10 -2
@@ -19,6 +19,7 @@ const TARGET_FRAME_RATE = 30;
export function Lighting() {
const [cast, setCast] = useState(true);
const t0 = useRef(0);
const topLight = useRef<SpotLight>(null!);
const frontLight = useRef<SpotLight>(null!);
@@ -28,8 +29,15 @@ export function Lighting() {
const last = useRef<number>(0);
const samples = useRef<number[]>([]);
useFrame(({ clock }) => {
if (!cast || clock.elapsedTime < TARGET_FRAME_RATE * N) return;
useFrame(({ clock, frameloop }) => {
if (frameloop === "never") {
t0.current = clock.elapsedTime;
samples.current = [];
return;
}
if (!cast || clock.elapsedTime - t0.current < TARGET_FRAME_RATE * N) {
return;
}
const dt = clock.elapsedTime - last.current;
last.current = clock.elapsedTime;