Jump to content

Texture not changing


Recommended Posts

Hi all,


I'm going to try to describe my issue as best as I can since I'm not sure how to show it properly in a playground.


What I want to do is, allow a user to upload an image, that then gets converted into a texture that I place on a plane. What is happening is that the first image that is uploaded is displayed correctly in the scene, but when another image is uploaded, the same first image gets applied to the scene, and this keeps happening every time you try to add a new image to the scene.

I tried to locate the error by doing a couple of test:

- I used different images to see if they were the problem - they were not.

- I logged the plane, texture and material every time a new image were added and inspected that the right data for the image was in them - it was.

- I find the mesh after it has been created, print its texture and check the _buffer, which is set to the new image, but still the old image is showing.


I simply can't seem to find the error, but was wondering if it had something to do with how textures are caches, but still doesn't make much sense. Does anyone have any insight?


This is the function that is run whenever a "change" is detected on the <input type='file'> element:

function addImage(evt){
  if (this.files && this.files[0]) {
    var fileReader = new FileReader();

    fileReader.addEventListener("load", function(e) {
      var plane = new BABYLON.Mesh.CreatePlane("plane", 10.0, scene);
      plane.material = new BABYLON.StandardMaterial("texture", scene);
      plane.material.diffuseTexture = new BABYLON.Texture.LoadFromDataString("data:test", e.target.result, scene);
      plane.material.diffuseTexture.hasAlpha = true;
      plane.material.diffuseTexture.uScale = 1.0;
      plane.material.diffuseTexture.vScale = 1.0;

    fileReader.readAsDataURL( this.files[0] );


I appreciate any insight or tips of how to solve this issue.

Thank you!

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...