Adding a texture

The dynamic texture does not apply to the model. Not sure what am I doing wring.

var engine = new BABYLON.Engine(canvas, true);
var scene = new BABYLON.Scene(engine);

function chnageTexture(){
  var mesh = scene.getMeshByName(m);  
  var texture = new BABYLON.DynamicTexture("dynamic texture", document.getElementById("canvas1"), scene);
  var textureContext = texture.getContext();
  var mat = new BABYLON.StandardMaterial("mat", scene);
  mat.diffuseTexture = texture;
  mesh.material = mat;
}

Is this because I’m using a canvas that is already existing? The examples in the documentation show how to draw a canvas and apply on the fly.

This should work :slight_smile:
Is there any error on the console? If your canvas contains tainted data you will not be able to use it

1 Like

Thank you @Deltakosh :slight_smile:
After googling for many hours I figured it out… it was an issue with the .hasAlpha . It’s all good now! I’m new to babylonjs and relay enthusiastic about what it can do. I’m trying to build an application with it… :slight_smile:

I have a quick question. I’d very much appreciate if you could share your thoughts on this. IN my application I am thinking of allowing the user to generate textures at run time (canvas) and at the end to be able to send it via email. I am having doubts about whether to use base64 or Blob. While I was googling to find out about the performance of each one, I learned that using base64 has some performance issues on mobiles. So what I want to know in your opinion what would be the best way to handle the images (base64 for the textures and sending a image of the 3d to the server for emailing)?

Blob will let you store binary data directly but honestly unless you generate 100 images per frame base64 will perfectly do the job :slight_smile:

1 Like

Thank you very much @Deltakosh :slight_smile: :slight_smile:

1 Like