Janx Posted May 22, 2017 Share Posted May 22, 2017 (edited) Hi, I want to clone meshes that I load with the obj loader. The problem seems to be that the material is assigned somewhat later, so when I clone the mesh directly in the callback from the SceneLoader.ImportMesh function, it has no material. If I make another clone from the very same instance some time later, it has material. For example this would lead to no material in the clone: BABYLON.SceneLoader.ImportMesh("", this.serverUrl, encodeURIComponent(fileName + ".obj"), this.scene, (mesh) => { meshContainer = mesh.clone(name, undefined, false); resolve(meshContainer); } while this would: BABYLON.SceneLoader.ImportMesh("", this.serverUrl, encodeURIComponent(fileName + ".obj"), this.scene, (mesh) => { setTimeout(() => { meshContainer = mesh.clone(name, undefined, false); resolve(meshContainer); }, 100); } (It is wrapped inside a Promise) Is this an expected behaviour? Is it possible to get the callback when everything is loaded completely? Many thanks, Cheers, janx Edited May 29, 2017 by Janx solved Quote Link to comment Share on other sites More sharing options...
brianzinn Posted May 23, 2017 Share Posted May 23, 2017 I get the same thing. If I apply a material after the first completion callback, those materials are overwritten with blender materials, if the materials were exported from blender. I have seen other posts where people were waiting for second callback, but I was only getting one and materials were not ready. Quote Link to comment Share on other sites More sharing options...
Gijs Posted May 24, 2017 Share Posted May 24, 2017 It's expected behavior: I don't know what the best option is to get a callback Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted May 26, 2017 Share Posted May 26, 2017 Try putting your code in scene.executeWhenReady BABYLON.SceneLoader.ImportMesh("", this.serverUrl, encodeURIComponent(fileName + ".obj"), this.scene, (mesh) => { scene.executeWhenReady( function() { meshContainer = mesh.clone(name, undefined, false); resolve(meshContainer); }); }); (code needs to be adapted to be able to reach scene, mesh, etc) Janx and Dad72 2 Quote Link to comment Share on other sites More sharing options...
Janx Posted May 29, 2017 Author Share Posted May 29, 2017 Thanks @Vousk-prod.. Works like a charm. 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.