Files
blitzkit/src/app/tools/tankopedia/[id]/components/Control.tsx
T

18 lines
675 B
TypeScript
Raw Normal View History

2024-01-03 12:21:30 -06:00
import { OrbitControls } from '@react-three/drei';
import { useThree } from '@react-three/fiber';
2024-01-04 13:37:36 -06:00
import { useEffect, useRef } from 'react';
2024-01-03 12:21:30 -06:00
import { OrbitControls as OrbitControlsClass } from 'three-stdlib';
2024-01-04 13:06:40 -06:00
import { useTankopedia } from '../../../../../stores/tankopedia';
2024-01-03 12:21:30 -06:00
2024-01-04 13:37:36 -06:00
export function Controls() {
2024-01-03 12:21:30 -06:00
const camera = useThree((state) => state.camera);
const orbitControls = useRef<OrbitControlsClass>(null);
2024-01-04 13:06:40 -06:00
const enabled = useTankopedia((state) => state.model.controlsEnabled);
2024-01-03 12:21:30 -06:00
useEffect(() => {
2024-01-04 13:37:36 -06:00
camera.position.set(-5, 4, -20);
orbitControls.current?.target.set(0, 1.5, 0);
}, []);
2024-01-03 12:21:30 -06:00
return <OrbitControls ref={orbitControls} enabled={enabled} />;
}