How to reference the default webgl renderer and other useThree() aspects outside the Canvas? #592
Replies: 4 comments 5 replies
-
The renderer is created not in sync with the dom, you can of course use onCreated on the canvas, fetch gl there and set state it on the parent. |
Beta Was this translation helpful? Give feedback.
-
As for the colors, the canvas is probably srgb and the dom some other color space, or the other way round. It doesn't look like fog to me. Not sure how you can adapt another color space for screen captures |
Beta Was this translation helpful? Give feedback.
-
@BryanChrisBrown do you happen to have a sandbox or example of how you accomplished the screenshot button in the parent with a native DOM element? Thanks. |
Beta Was this translation helpful? Give feedback.
-
I tried BryanChrisBrown solution, but it only draws sprite that the function is in:
I am calling it from a parent component that is in under
I don't quiet understand this behaviour. I tried passing the gl, scene, camera as props from the parent, but it didn't help. It works when I initially toggle preserveDrawingBuffer on the Canvas component (but it gives 'smudged' effect). (I was using react-three-gui, but there the passed in gl, scene, camera doesn't get updated either in the useControl callback) How can I get the entire scene's screenshot while having preserveDrawingBuffer switched back to false? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
https://codesandbox.io/s/r3f-basic-demo-3pbpo?file=/src/index.js
I'm attempting to use a function to capture my threejs scene as a screenshot, I've gotten this functionality mostly working however, I'd like to have the button as a regular dom element, but so far have only been able to use it as an element inside the canvas, due to useThree() only working with the context of the canvas.
(note that the screenshot does not function in codesandbox, it does work properly via a localhost)
Is there a way I can link a 'regular' html button to the function I'm calling in my
ScreenshotButton
component?This is more of a react question than a react-three-fiber question, but I haven't been able to figure out the best way to handle this.
Also, a side question related to this:
When I take the screenshot, the output image has different colors than my main image on my webpage, you can see in the attached images that the trees are significantly darker in the output image. It seems to me like the fog isn't being taken into consideration, but I'm not sure what is causing this as I'm directly capturing the div itself.
Canvas in web browser

Exported Image

Beta Was this translation helpful? Give feedback.
All reactions