Simple example to apply a CanvasTexture #2288
-
Hello, I'm reaching out here because I tried to find a good and simple example of how I can apply a canvas as a texture to a cube with react-three-fiber. I found only one example online that uses typescript, that I don't want to use (I am a typescript noob). Does anyone have an idea? I leave my code so far here to give you a picture of what I want to do:
I'm thankful for any hints. I'm stuck since two days now and almost about to drop the project. :( |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Solved it. ;) |
Beta Was this translation helpful? Give feedback.
-
You can either create the canvas imperatively (document.createElement) or use a reference to a canvas you've added to the dom (OP's code). Once you have the canvas, you apply it to your geometry using In this example, I'm drawing the canvas in useFrame, but you can draw the canvas anywhere. Pass the reference to the canvas in using the https://codesandbox.io/s/canvas-animated-texture-10p7ws
|
Beta Was this translation helpful? Give feedback.
-
Hi, is it possible to see your complete code? Because i try but my geometry is always black.... |
Beta Was this translation helpful? Give feedback.
You can either create the canvas imperatively (document.createElement) or use a reference to a canvas you've added to the dom (OP's code).
Once you have the canvas, you apply it to your geometry using
<canvasMaterial />
In this example, I'm drawing the canvas in useFrame, but you can draw the canvas anywhere. Pass the reference to the canvas in using the
image
property.https://codesandbox.io/s/canvas-animated-texture-10p7ws