Hi all. Trying to make these buttons move the CameraControls from Drei.
I tried this, and it works. But I do not quite like this method because it’s causing a rerender of my whole scene everytime I change the controls.
My root component:
const [controls, setControls] = useState()
return (
<main className='h-full'>
<Topbar />
<section className='flex h-[92vh] flex-row flex-nowrap '>
<Toolbar />
{MODES_2D_VIEWER.includes(mode) ? <Viewer2D /> : <Viewer3D setControls={setControls} />}
</section>
<DirectionControls controls={controls} />
My scene where I assign the controls:
export function Scene3D({ setControls }: Props) {
...
const { cameraRef, controlsRef } = useCameraControls3D()
const controls = useThree((state) => state.controls)
useEffect(() => setControls(controls), [controls])
...
return (
<>
<CameraControls
makeDefault
ref={controlsRef}
/>
...
)
Component where the controls are moved with:
export function DirectionControls({controls}) {
return (
<button onClick={()=> controls.dolly(50)/>}
)
}
I think the ideal solution would be to somehow, place the DirectionControls
component within the Scene3D
so it could have acces to controls
as props. But judging by the errors I get when I try it, does not seem to be posible.