#How to get and store 2D context of Canvas in react-three-fiber?
20 messages · Page 1 of 1 (latest)
Thanks for your reply. I am using only one canvas now. I want to get 2d context of it.
I believe that r3f will automatically grab a 3d context for the canvas, so you can't get a 2d one.
It makes sense. So what can I do?
Well, for one you could certainly implement the ribbon drawing in 3d; it might in some ways be even easier than in 2d.
Let me try 🙂 thanks.
But how to get context concisely?
I tried getContext("3d") in RibbonDraw but failed.
Would you mind if I DM to you?
I'm not familiar enough with R3F, unfortunately, to be much specific help here. :/
Though I believe what you want is "webgl", not "3d": https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
can you clarify the objective more?
what do you mean 2d "context"? the visual scene context i assume, not the context of a project itself?
we manage a lot of both in ot sketch - so if i can be of help lmk
Thanks for your kind interest. I have a Vue app using Three.js to create a such effect.
But I want to convert it to React and Typescript. In vue, creating canvas and getting context is done really easy in <script> tag. Here is the code.
this._canvas = document.createElement("canvas");
this._context = this._canvas.getContext("2d");
In Typescript, I created Ribbons component using react-three-fiber as you can see in the original post. To draw ribbon sections, I have to get the 2D context of canvas, I suppose.
To make a long story short, how can I draw 2D lines on react-three-fiber context?
like this?
i still don't really have my head around what you're trying to do...especially this part
I created Canvas from react-three-fiber and tried to get 2D context of the canvas in child component - RibbonDraw.
i don't understand what you mean by 2d and RibbonDraw - is it a ribbon being drawn completely away from r3f?