pmndrs / react-three-offscreen

📺 Offscreen worker canvas for react-three-fiber
https://offscreen.pmnd.rs
MIT License
456 stars 19 forks source link

Cannot use Canvas callbacks #3

Closed samevision closed 1 year ago

samevision commented 1 year ago

Hi,

I noticed that setting a function for the Canvas prop onCreated for example leads to this error:

DataCloneError: Failed to execute 'postMessage' on 'Worker': ()=>{
    ...

How is it possible to use it?

Best

drcmda commented 1 year ago

canvas is running completely off the main thread, there are no callbacks between the two threads, except messaging channels that you yourself manage (postmessage, broadcast, shared arraybuffer)

// Scene.jsx
export default function Scene() {
  const state = useThree()
  useLayoutEffect(() => {
    // ... in here, "state" contains the initial root state
  }, [])
  return (
    <mesh />
    ...
samevision commented 1 year ago

I see. Thanks.