Drawering on a texture 2D canvas
Andrew Smith | 18 September, 2008 | 18:10
I’m gonna reply to Jeremy’s post a piece at a time, becuse I can’t keep it all in mind at once. First thing first, something he mentioned we should be able to do, and I thought we could do, but I couldn’t remember how: using a 2D canvas for a texture, but letting the user draw whatever on the said canvas.
The code from the Example usage section from Jeremy’s post can also be written the following way, and this already works with the library now (tested with a teapot). n is the model:
var c2d = scene.create2Dcanvas(128, 128);
var ctx = c2d.getContext('2d');
ctx.beginPath();
ctx.arc(75,75,50,0,Math.PI*2,true); // Outer circle
ctx.moveTo(110,75);
ctx.arc(75,75,35,0,Math.PI,false); // Mouth (clockwise)
ctx.moveTo(65,65);
ctx.arc(60,65,5,0,Math.PI*2,true); // Left eye
ctx.moveTo(95,65);
ctx.arc(90,65,5,0,Math.PI*2,true); // Right eye
ctx.stroke();
n.setTextureFromCanvas2D(c2d.id);
scene.getTextureManager().addTextureFromCanvas2D(c2d.id);
The other interesting suggestion Jeremy had was to make the texture an object, to deal with the multiple parameters. I’m gonna have a look at that now. 