react-three-fiber

Heads-up display (rendering multiple scenes)

useFrame allows components to hook into the render-loop, or even to take it over entirely. That makes it possible for one component to render over the content of another. The order of these operations is established by the priority you give it, higher priority means it renders first.

function Main() {
const scene = useRef()
const { camera } = useThree()
useFrame(({ gl }) => void ((gl.autoClear = true), gl.render(scene.current, camera)), 100)
return <scene ref={scene}>{/* ... */}</scene>
}
function HeadsUpDisplay() {
const scene = useRef()
const { camera } = useThree()
useFrame(({ gl }) => void ((gl.autoClear = false), gl.clearDepth(), gl.render(scene.current, camera)), 10)
return <scene ref={scene}>{/* ... */}</scene>
}
function App() {
const camera = useRef()
const { size, setDefaultCamera } = useThree()
useEffect(() => void setDefaultCamera(camera.current), [])
useFrame(() => camera.current.updateMatrixWorld())
return (
<>
<perspectiveCamera
ref={camera}
aspect={size.width / size.height}
radius={(size.width + size.height) / 4}
onUpdate={self => self.updateProjectionMatrix()}
/>
<Main />
<HeadsUpDisplay />
Edit this page on GitHub