BlackMojito Posted December 22, 2017 Share Posted December 22, 2017 I am currently working on importing an OBJ files into my Scene. It seems that the onSuccess callback for BABYLON.SceneLoader.ImportMesh is done before the material are loading. I have a special process for all the imported materials. So my question is do I have a chance (callback) for process the loaded materials? In the below code, the if (originalMaterial...) line is never hit but I can enter the _parseMTL function when I load OBJ and the materials can be correctly rendered. importModel(rootUrl: string, sceneFileName: string): void { let onModelImport = (meshes: BABYLON.AbstractMesh[]) => { for (let mesh of meshes) { this._selectionManager.enableHighlight(mesh); let originalMaterial = mesh.material; if (originalMaterial instanceof BABYLON.StandardMaterial) { let key = MaterialManager.materialKeyString(rootUrl + sceneFileName, originalMaterial.name); let cachedMaterial = this._materialManager.getMaterial(key); if (cachedMaterial) { mesh.material = cachedMaterial; } else { let enhancedMaterial = this._materialManager.enhanceStandardMaterial(key, originalMaterial as BABYLON.StandardMaterial); mesh.material = enhancedMaterial; } } } }; this._renderScene.importModel(rootUrl, sceneFileName, onModelImport); this.parseSceneOptions(); } Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 22, 2017 Share Posted December 22, 2017 Hello, OBJ is an interesting beast as geometry and materials are separated files You can rely on scene.executeWhenReady(func(){}) to start rendering when everything is ready 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.