mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-13 20:56:11 +01:00
feat: controls
This commit is contained in:
1 parent
ff66d99fc6
commit
b745ad2fa7
2 files changed
+35
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import { OrbitControls } from '@react-three/drei';
|
||||
import { useThree } from '@react-three/fiber';
|
||||
import { RefObject, useEffect, useRef } from 'react';
|
||||
import { Box3, Object3D } from 'three';
|
||||
import { OrbitControls as OrbitControlsClass } from 'three-stdlib';
|
||||
|
||||
interface ControlsProps {
|
||||
enabled: boolean;
|
||||
fit: RefObject<Object3D>;
|
||||
}
|
||||
|
||||
export function Controls({ enabled, fit }: ControlsProps) {
|
||||
const camera = useThree((state) => state.camera);
|
||||
const orbitControls = useRef<OrbitControlsClass>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const box = new Box3().setFromObject(fit.current!);
|
||||
|
||||
orbitControls.current?.target.set(0, (box.min.y + box.max.y) / 2, 0);
|
||||
camera.position.set(-5, (box.min.y + box.max.y) / 2, -15);
|
||||
}, [fit.current]);
|
||||
|
||||
return <OrbitControls ref={orbitControls} enabled={enabled} />;
|
||||
}
|
||||
Reference in new issue
Block a user