"Ready" vs "Loaded"

Hello,

I’m trying to measure various ways of optimizing a scene in BJS, with both textures and meshes. Specifically, I’m measuring the time it takes from when the first in a group of assets begins loading, to when all are loaded and rendered inside of a scene.

I’m wondering specifically how to measure when all assets (either meshes or textures) are fully loaded inside of a scene. I’ve noticed both have an “isReady” function and ready properties, though these can exist on assets that haven’t been assigned to a scene (IE a texture not applied to a mesh). Is the time it takes to apply meshes or textures to a scene trivial if they are ready? Otherwise, is there another way to measure once an asset is fully loaded and visible in a scene?

Thanks

cc @sebavan

isReady will also account for the required shader loading part.

I think @bghgary added a couple things to get access to the download and parse time separately on GLTF IIRC

For glTF, there are a few more events. Let me know if this is what you want and I can point you in the right direction for glTF loader.

I’d appreciate that, I’m using glb files and the loader.

If I understand what @sebavan is saying correctly though, the ready property is only true if an object that has been loaded and is fully visible in a scene? For both Textures and Meshes?

Yes, that is correct. If you want know whether a specific glTF object is ready (i.e., fully ready to render without missing textures, shaders, etc.), there are a few other flags/events you can set on the glTF loader to make that happen.

@bghgary Could you point me to what those would be? I mainly want to know if a mesh is fully loaded or ready to be loaded into a scene, regardless of textures. I’m currently using the mesh.onReady callback, though it doesn’t seem to work inside the ImportMeshAsync callback because the callback runs after the mesh is “ready”.

I’m not entirely clear what you mean by this, but I think you mean you want to know when a mesh is ready to be completely rendered (including textures, shaders, etc.).

Here is an example: Babylon.js Playground

By default, if you don’t set any options, the glTF loader will wait until all the textures are loaded before returning, but it will not wait for shaders to compile. The example above sets the compileMaterials flag which tells the loader to wait until the shader combinations needed to render this specific glTF are ready. Note there are a couple of other flags you might need to set if you use clip planes or use shadows. Setting these flags makes it such that there are no frames after the loader returns where the model doesn’t render fully.

1 Like