mauri Posted April 27, 2016 Share Posted April 27, 2016 Hi, I am new to this forum and I really love this. I have been playing with babylon.js now for a year and really enjoying the framework. Mostly I have found answers to my problems here or on the playground. Now I just can't solve this issue. I have a model which you can upload new picture (.jpq) through web site. I upload the picture to server ( new picture replaces the old one e.g. table1.jpg) What I have been doing is reloading the page after upload. But now I would like to do this without upload. I kind of managed to do this: var scene = engine.scenes[0]; scene.materials.forEach(function (thematerial) { if (typeof (thematerial.diffuseTexture) != 'undefined') { var newfilelocation = thematerial.diffuseTexture.url; thematerial.diffuseTexture.hasAlpha = true; thematerial.diffuseTexture = new BABYLON.Texture(newfilelocation, scene, true, true, 3, null, null, null, true); } }); This reloads materials and I can see result as I want to. But after this I also would like to take a snapshot and upload that picture to server. BABYLON.Tools.CreateScreenshot(engine, scene.cameras[0], { width: cw, height: ch }); I have got this to work put after updating the mesh (materials) the picture materials are all black. Is there a way to avoid this? I guess this is to do with the last buffer parameter = true, but this is the only way I have managed to reload the mesh materials? Screenshot works fine if I hook it up to button and use it there right after upload and without loading the page... I hope this makes sence Mauri Quote Link to comment Share on other sites More sharing options...
RaananW Posted April 27, 2016 Share Posted April 27, 2016 Hi Mauri, you will need to wait at least one frame for the textures to actually load. this is why they are black. you could do that in a callback running after the rendering was done, something like this: scene.registerAfterRender(function screenshot() { //TAKE SCREENSHOT scene.unregisterAfterRender(screenshot); }); So it will be executed after the scene rendered, and only one time. And sorry, just have to ask - why are you checking if the type of the diffuse texture is != undefined? It will be enough to simply check if it exists, using if(material.diffuseTexture) { //do something } And just a small note - you might want to dispose the old texture before creating a new one. before creating the new texture, call thematerial.diffuseTexture.dispose() to clear up the resources. Quote Link to comment Share on other sites More sharing options...
mauri Posted April 27, 2016 Author Share Posted April 27, 2016 Thanks RaananW !!! You instructions were perfect and I got this to work really nice now. I have been trying this out a lot. I am very happy. And you are also correct about 'undefined' It's kind of copy paste / error from my submaterial / material examination.... my bad. Mauri GameMonetize and RaananW 2 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.