# Problem of Thin Instance

**URL:** <https://forum.babylonjs.com/t/problem-of-thin-instance/53039>\
**Category:** Questions\
**Tags:** thininstances\
**Created:** [August 27, 2024, 2:39pm UTC](https://forum.babylonjs.com/t/problem-of-thin-instance/53039 "2024-08-27T14:39:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harilala](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/harilala/32/34148_2.png) [@Harilala](https://forum.babylonjs.com/u/Harilala)\
**Post date:** [August 27, 2024, 2:39pm UTC](https://forum.babylonjs.com/t/problem-of-thin-instance/53039/1 "2024-08-27T14:39:59Z")

</div>

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:

```auto
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 🙂

 ![Capture d’écran (46)](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/4/34b03e7c282fbbf36cf4d2552076ba825103aa7f.jpeg)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [August 27, 2024, 4:04pm UTC](https://forum.babylonjs.com/t/problem-of-thin-instance/53039/2 "2024-08-27T16:04:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CrashMaster](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/crashmaster/32/23662_2.png) [@CrashMaster](https://forum.babylonjs.com/u/CrashMaster)\
**Post date:** [August 28, 2024, 7:44am UTC](https://forum.babylonjs.com/t/problem-of-thin-instance/53039/3 "2024-08-28T07:44:53Z")

</div>

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

> [@Field of grass?](https://forum.babylonjs.com/t/field-of-grass/29023/):
>
> Prefacing this question by saying I have no idea what I’m doing. Been reading for a few days about how I could make a field of grass, and curious if my conclusion is roughly right. As far as I can tell, there is no geometry shader, but if there was then this would be a good option. The other methods are: [this method](https://babylonjs.medium.com/infinite-grassland-ray-traced-rare-semi-uniform-entity-manifolds-for-rendering-countless-discreta-36630d72fc6) thin instances/solid particle system to place pieces of grass. Then for wind blowing across a field, using a shader to handle the motion, or animating the texture, node material, …

---

<div class="post-metadata">

**Author:** ![Harilala](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/harilala/32/34148_2.png) [@Harilala](https://forum.babylonjs.com/u/Harilala)\
**Post date:** [August 28, 2024, 9:29am UTC](https://forum.babylonjs.com/t/problem-of-thin-instance/53039/4 "2024-08-28T09:29:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Harilala](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/harilala/32/34148_2.png) [@Harilala](https://forum.babylonjs.com/u/Harilala)\
**Post date:** [August 28, 2024, 9:30am UTC](https://forum.babylonjs.com/t/problem-of-thin-instance/53039/5 "2024-08-28T09:30:59Z")

</div>

Okay, I’ll put it in the Playground.

---

<div class="post-metadata">

**Author:** ![Harilala](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/harilala/32/34148_2.png) [@Harilala](https://forum.babylonjs.com/u/Harilala)\
**Post date:** [August 28, 2024, 1:30pm UTC](https://forum.babylonjs.com/t/problem-of-thin-instance/53039/6 "2024-08-28T13:30:29Z")

</div>

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