Is there a way to combine react-three-fiber and regular three.js in a single app? #1626
-
Use cases for this:
Is there a way to do this? Can I have R3F controlling some parts of the canvas, but also have a regular game loop on the side that's rendering other stuff? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
of course, r3f just sets up renderer+cam+scene for you, and you get to write jsx, but nothing would stop you doing this: function Foo() {
const [scene] = useState(() => new THREE.Scene())
const state = useThree()
useEffect(() => {
// ... your plain three code here
scene.add(your result)
function resize() {
// state.viewport and state.size have the correct sizes
}
window.addEventListener("onClick", () => ...
function loop() {
requestAnimationFrame(raf)
scene.render(state.gl, camera)
}
loop()
}, [])
return <primitive object={scene} />
}
<Canvas frameloop="never">
<Foo /> as you see you can already start using some helpers, like the GL instance, or responsive width/height
honestly i dont think that usecase exists. r3f is native three, even the jsx you write is native three. having tools like useEffect, useMemo, useFrame, suspense and so on allows you to categorize imperative code and effects, which will always make it easier than having to manage a long blob of un-integrated code. you will always have to write imperative code and shaders, but this is exactly what r3f allows you to do, but in a clean and safe manner. after two years of working on and with this lib (at work, cad system), i have yet to see a single usecase that would be easier in plain three - imo it does not exist. |
Beta Was this translation helpful? Give feedback.
of course, r3f just sets up renderer+cam+scene for you, and you get to write jsx, but nothing would stop you doing this:
as you see you can already start using some helpers…