Problem of Thin Instance

Hello community,

I’m just starting out with Babylon.js and I need your help urgently, please: I’m currently working on my first 3D scene project, where I want to represent an emblematic place in my country (Allée des Baobab - Morondava, Madagascar), so I only need to represent trees and a savannah. However, without optimization, especially of the grass, my scene is too slow (less than 20 fps) and I’ve decided to use Thin Instance to do it. But I’m having trouble with this: I find the documentation and project examples too global. Here’s my function in charge of this optimization:

function loadGLTFwithThinInstance(scene, storage, filename, camera) {
    return new Promise((resolve, reject) => {
        BABYLON.SceneLoader.ImportMesh(“”, storage, filename, scene, function(meshes) {
            const baseMesh = meshes[0].clone(“grass”);
            if (baseMesh === null) throw new Error(“baseMesh is null”);
            baseMesh.makeGeometryUnique();
            baseMesh.isVisible = true;

            let instancesCount = meshes.length,
            bufferMatrices = new Float32Array(16 * instancesCount),
            dataMatrix = [];

            meshes.forEach(mesh => {
                dataMatrix.push(BABYLON.Matrix.Compose(
                    mesh.scaling,
                    mesh.rotationQuaternion || BABYLON.Quaternion.FromEulerAngles(mesh.rotation.x, mesh.rotation.y, mesh.rotation.z),
                    mesh.position
                ));
                mesh.dispose();
            });

            for(let index = 0; index < instancesCount; index++) {
                dataMatrix[index].copyToArray(bufferMatrices, index * 16);
            }

            baseMesh.thinInstanceSetBuffer(“matrix”, bufferMatrices, 16);

            console.log(baseMesh.thinInstanceCount);

            resolve(“Loading Success with Thin Instance”);
        });
    });
}

What do I have to do for the thin instance to work properly, knowing that I’ve modeled it on Blender as in this screenshot? Thanks in advance :slight_smile:

The best way to have help, will be to provide the community with a playground reproducing what you already tried.

For all things grass we have this thread that covers a lot of different methods:

Thank you very much, I was really desperate. I’ll see what I can come up with.

Okay, I’ll put it in the Playground.

It works very well, thank you very much for your help.

1 Like