Jump to content

Is there a callback function for materials when loading a file?


Recommended Posts

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) {

                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);


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...