This commit is contained in:
Brian Beck 2025-11-26 14:43:40 -08:00
parent aeea7432c9
commit 825b21acfd
10 changed files with 6457 additions and 16 deletions

View file

@ -11,32 +11,31 @@ import {
import { Quaternion, Vector3 } from "three";
export function Camera({ object }: { object: ConsoleObject }) {
const { fov } = useSettings();
const { registerCamera, unregisterCamera } = useCameras();
const id = useId();
const dataBlock = getProperty(object, "dataBlock").value;
const [x, y, z] = useMemo(() => getPosition(object), [object]);
const position = useMemo(() => getPosition(object), [object]);
const q = useMemo(() => getRotation(object), [object]);
useEffect(() => {
if (dataBlock === "Observer") {
const camera = { id, position: new Vector3(x, y, z), rotation: q };
const camera = { id, position: new Vector3(...position), rotation: q };
registerCamera(camera);
return () => {
unregisterCamera(camera);
};
}
}, [id, dataBlock, registerCamera, unregisterCamera, x, y, z, q]);
}, [id, dataBlock, registerCamera, unregisterCamera, position, q]);
// Maps can define preset observer camera locations. You should be able to jump
// to an observer camera position and then fly around from that starting point
// But, we wouldn't want the user to take control of the actual camera's
// But, we wouldn't want the user to take control of the actual camera's
// position, because then if you want to cycle back through them again, the
// "fixed" camera location has moved. There are two approaches for fixing this:
// make Camera render an actual PerspectiveCamera, switch it when cycling,
// but clone a new "flying" camera when the user moves. The other is to not have
// multiple cameras at all, but rather update the one camera with fixed position
// information when cycling. This uses the latter approach.
// "fixed" camera location has moved. There are multiple approaches to fixing
// this: make Camera render an actual PerspectiveCamera, switch it when cycling,
// but clone a new "flying" camera when the user moves. The other is to not
// have multiple cameras at all, but rather update the default camera with
// new position information when cycling. This uses the latter approach.
return null;
}