Quach90 Posted March 15, 2017 Share Posted March 15, 2017 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) { console.log(e.target.result); 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! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 15, 2017 Share Posted March 15, 2017 Hey the problem is certainly with the texture cache: each texture must have an unique name or else the cached version will be used. So you will have to use something like "data:test1", etc... to ensure that every new texture is actually loaded Quote Link to comment Share on other sites More sharing options...
Quach90 Posted March 15, 2017 Author Share Posted March 15, 2017 Great that worked, thanks! Just to be safe with future problems. Is this the case with everything? Meshes, materials etc? Is it important that they have unique names? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 16, 2017 Share Posted March 16, 2017 texture only so no worry! 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.