jhadenfeldt Posted November 8, 2018 Share Posted November 8, 2018 I have a canvas and want to use it's content as a texture. I assume there is a way to use dynamicTexture for that, but couldn't find out a way to do that. I've created a demo here: https://codepen.io/anon/pen/mQVLaJ I'd like to use the content of the canvas ("Hello World") as the texture for the plane. (I know that I could write the text directly to the dynamicTexture. The text in the example is only for demo purposes. In my project it won't be text.) Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted November 8, 2018 Share Posted November 8, 2018 https://www.babylonjs-playground.com/#NYITDI#14 var canvas = document.getElementById("can"); var ctx = canvas.getContext("2d"); ctx.fillStyle = "#ffffff"; ctx.fillRect(0,0,150,150); ctx.fillStyle = "#FF0000"; ctx.fillRect(d,d,d,d); var embed = canvas.toDataURL('image/jpeg', 1.0); var img = document.createElement("img"); img.onload = function(){ var txt1 = new BABYLON.Texture(this.src, scene, true, true, BABYLON.Texture.BILINEAR_SAMPLINGMODE, null, null, this.src, true); plan.material.diffuseTexture = txt1; }; img.src = embed; jhadenfeldt 1 Quote Link to comment Share on other sites More sharing options...
jhadenfeldt Posted November 8, 2018 Author Share Posted November 8, 2018 Great, thank you so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.