You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
since you've added <div ref={localRef} {...props} /> to View.tx
Any r3f components created needs to be wrapped in View to be rendered, is there no way to add an r3f component that will be rendered across all app directory pages?
Thanks
The text was updated successfully, but these errors were encountered:
rohanrehman
changed the title
Sharing View / r3f components across Canvas / Scene.tsx ?
[Solved] Sharing View / r3f components across Canvas / Scene.tsx ?
Jul 15, 2024
this solution leverages drei View components and its latest docs.
Quick example off adding a Plane in the Scene that survives navigation while adjusting z index with tailwind to accommodate mouse event interaction of other Views rendered in rf3.Out.
import { Preload, Plane, View } from '@react-three/drei'
export default function Scene({ ...props }) {
// Everything defined in here will persist between route changes, only children are swapped
return (
<>
<View className='pointer-events-none absolute left-0 top-0 z-[-1] h-[600px] w-full bg-green-300'>
<Plane args={[2, 2]} position={[-2, 0, 0]} {...props} />
</View>
<Canvas {...props} onCreated={(state) => (state.gl.toneMapping = THREE.AgXToneMapping)}>
<View.Port />
<r3f.Out />
<Preload all />
</Canvas>
</>
)
}
@RenaudRohlinger great work on this!
Canvas is instantiated in Scene.txt
Keeping with framework conventions adding a View in the Scene to survive navigation returns an error.
Error: R3F: Div is not part of the THREE namespace! Did you forget to extend? See: https://docs.pmnd.rs/react-three-fiber/api/objects#using-3rd-party-objects-declaratively
since you've added
<div ref={localRef} {...props} />
to View.txAny r3f components created needs to be wrapped in View to be rendered, is there no way to add an r3f component that will be rendered across all app directory pages?
Thanks
The text was updated successfully, but these errors were encountered: