Hardware instancing of glb files

I am loading glb files from a server and instantiate them on entities via script.

Some entities use the same glb files, so until now my process was loading the asset and then assigning the model to all the entities using it.

Now I’m running into performance issues with lots of entities using the same models.

Reading on the documentation apparently there is a way to use hardware instancing.

How would i go about loading a glb file, turning it into an instance and then using that on lots of entities as a model?

Hi @HebelHuber ,

You can do that easily in code, check the following example on the process:


1 Like

Thanks for your answer, i already made some progress on this.

One question though.

In my tests I was iterating the meshInstances of my test objects to instance each, that worked.
Now with glb files I’m having trouble accessing the meshInstances.

I tried several combinations like this


How are you loading your GLB?

Testing on the GLB example project from the Tutorials and I can see that working:

In a very similar way, using a lot of the code from the example.
Seems like i have a bug on my side, gonna come back to report…


1 Like

are you perhaps importing fbx using “Import Hierarchy” asset setting? If so, the imported hierarchy of entities would not use model component but render component instead.

1 Like

This is the code I’m using

GlbLoadHelper.prototype.loadGLB = function()
    var blob = new Blob([this.asset.resource]);
    var url = URL.createObjectURL(blob);
    loadGlbContainerFromUrl(url, null, this.asset.name,(err, asset) =>
        if (err)
            console.log("Error loading model");
            this.entity.model.asset = asset.resource.model;

            // meshInstances is undefined
            console.log("LOADHELPER model_available",this.entity.model.meshInstances);
            this.app.fire("model_available", this); // the subscriber sets up instancing using the meshInstances

The mesh is showing in the camera, so the loading works.
Is it possible i have to wait one frame before accessing the meshInstances?
I have the feeling the mesh is not “ready”

If you try to access them like this what happens:


asset.resource.model.meshInstances returned undefined, but for some reason
this.entity.model.meshInstances works now.

I think it was a bug on my side, but can’t nail it down exactly right now.

Anyway, now it works as intended.

Thanks for your help!

1 Like