Jump to content

Load meshes progressively


r3dwolf
 Share

Recommended Posts

Thanks @JCPalmer and @JonhK

Obviously I disabled the loading screen and started the rendering cycle, but the meshes were still displayed only once the whole file had been processed.

Unfortunately it is not a .babylon file but a custom file that must be read sequentially.

I solved the problem by using an async function with a wait function (Promise) of 1ms each cycle(mesh)

Link to comment
Share on other sites

This might also have to do with textures which are done after geometry.  One other way to create the effect is to not start the render loop till ready, disable all meshes (in Blender you can disable in the .babylon file).  When everything is ready, start the render loop which enables one mesh disabled per render.  When none still disabled found, stop checking.

var allLoaded = false;
engine.runRenderLoop(function () {
     if (!allLoaded){
         var foundDisabled = true;
         for (var i = 0, n = scene.meshes.length; i < n; i++){
             if (!scene.meshes[i].isEnabled) {
                 scene.meshes[i].setEnabled = true;
                 foundDisabled  = true;
                 break;
             }
         }
         allLoaded = !foundDisabled;
     }
     scene.render();
});

 

Link to comment
Share on other sites

Thanks, @JCPalmer, that solution may be good in some cases but it is an aesthetic solution.

With the async function the meshes are loaded as soon as they are processed and therefore there is a perception of higher loading speed , which was my goal.

function sleep(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }

    async function MeshManagerLoadMeshes(binaryBuffer) {
        while (binaryBuffer.offset < binaryBuffer.buffer.length) {
            <read and parse mesh>
            await sleep(1);
        }
    }

 

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.

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

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...