Force Material binding

Hello!

I’m having an issue with Material binding.
The project I’m working on is a bit different than the usual (game/website/vizualisation): instead of having a render every frame, I’m calling the render call only when needed.

When I’m first creating the Scene I’m working on, I’m loading multiple textures, creating materials; and calling the render method when all my assets have been loaded, created and added to the scene.
The problem is that sometimes some of the materials are not binded yet (onBindObservable doesn’t fire).
I need to render multiple frame to have it fired.

Is there a way to manually force the binding; and make sure to call the render when everything will be able to be visible?
Or should I create a loop that will render the scene until everything is binded?

Thanks per advance for your help!

Have you tried to use the mesh.isReady() method, with true as a parameter?

Something like:

    function allMeshesReady() {
        for (let i = 0; i < scene.meshes.length; ++i) {
            if (!scene.meshes[i].isReady(true)) {
                return false;
            }
        }

        return true;
    }

Then something like (extract from my project):

const idTimer = setInterval(() => {
    if (allMeshesReady()) {
        clearInterval(idTimer);
        /* do whatever you want */
    }
}, 10);

It seems to work for me.

1 Like

Thanks! Very useful isReady( true ).
Implemented something similar with it and it solved my issue.