Open stripuramallu3 opened 1 year ago
dom and canvas run into two different threads, it's up to you how you bridge that. broadcasts maybe, but there's no conventional way.
Thank you! Was hoping there was a better/conventional way
It would be so beautiful to pass a ref
to the worker canvas and manipulate it from the main thread.
if you guys have any ideas go ahead, would love to have a standard interface of some sort. i have never used broadcasts before but it's gotta be something that works both in a worker and in a main thread.
Does that also mean that <Html>
from drei doesn't work in offscreen canvas? I tried it and it doesn't show any HTML elements.
To get this working, we can patch @react-three/offscreen@0.0.8
as follows:
(component: React.FunctionComponent
| React.ComponentClass
): void; ```
Finally, restructure the project a bit:
// create-worker.js
// separate file fixes HMR
export const worker = new Worker(new URL('./worker.jsx', import.meta.url), { type: 'module' });
// App.jsx
import { worker } from "./create-worker";
// ...
return (
<Canvas
fallback={<Scene testProp="hello, world! (fallback)" />}
worker={worker}
sceneProps={{ foo: "hello, world!" }}
/>
);
// worker.jsx
import { render } from '@react-three/offscreen';
import Scene from "./Scene";
// Send component instead of ReactElement
render(Scene);
Does that also mean that
<Html>
from drei doesn't work in offscreen canvas? I tried it and it doesn't show any HTML elements.
How have you dealt with this so far? @mhmdjaw
Could an example be provided where the Scene component has to receive props (for example for the mesh position)? How does the worker.jsx file to pass the props to the Scene?