Map controls
Using Drei’s map controls to pan around a scene. Fork on Codesandbox
Live example
Code
import React, { useRef } from "react";
import ReactDOM from "react-dom";
import { Canvas, useFrame } from "react-three-fiber";
import { MapControls, Stats } from "@react-three/drei";
import "./styles.css";
const Torus = () => {
const torusRef = useRef();
useFrame(() => {
torusRef.current.rotation.x += 0.03;
torusRef.current.rotation.y += 0.03;
});
return (
<mesh ref={torusRef}>
<torusGeometry args={[1, 0.2, 12, 36]} />
<meshStandardMaterial color={"red"} />
</mesh>
);
};
const App = () => {
return (
<Canvas
style=
camera=
>
<pointLight position={[5, 5, 5]} />
<Torus />
<MapControls />
<Stats />
</Canvas>
);
};
ReactDOM.render(<App />, document.getElementById("root"));
Running this example
Clone this repo, and then NPM install and NPM start from the relevant directory.
$ cd examples/cameras/mapcontrols-camera-up-def
$ npm install && npm run start