Thininstance from abstract mesh not possible?

Hello,

I was looking at the thin instances examples1 and I tried locally with a different to import and only my original mesh is displayed but it doesn’t work.

My IDE tells me “Property ‘thinInstanceSetBuffer’ does not exist on type ‘AbstractMesh’”

Here is the code:

{
        var r = await SceneLoader.ImportMeshAsync( "", "/server", "my.glb", scene );
        let box = r.meshes[0];
        var numPerSide = 40,
            size = 100,
            ofst = size / ( numPerSide - 1 );
        var m = Matrix.Identity();
        //
        var col = 0, index = 0;
        let instanceCount = numPerSide * numPerSide * numPerSide;
        let matricesData = new Float32Array( 16 * instanceCount );
        let colorData = new Float32Array( 4 * instanceCount );

        for ( var x = 0; x < numPerSide; x++ ){
                m.m[12] = -size / 2 + ofst * x;

                for ( var y = 0; y < numPerSide; y++ ){
                        m.m[13] = -size / 2 + ofst * y;

                        for ( var z = 0; z < numPerSide; z++ ){
                                m.m[14] = -size / 2 + ofst * z;

                                m.copyToArray( matricesData, index * 16 );

                                var coli = Math.floor( col );

                                colorData[index * 4 + 0] = ( ( coli & 0xff0000 ) >> 16 ) / 255;
                                colorData[index * 4 + 1] = ( ( coli & 0x00ff00 ) >> 8 ) / 255;
                                colorData[index * 4 + 2] = ( ( coli & 0x0000ff ) >> 0 ) / 255;
                                colorData[index * 4 + 3] = 1.0;

                                index++;
                                col += 0xffffff / instanceCount;
                        }
                }
        }

        box.thinInstanceSetBuffer( "matrix", matricesData, 16, true );
        //r.thinInstanceSetBuffer( "matrix", matricesData, 16, true );
}

Only the first line has a change.

Positioning my mesh manually, without instance, with position.{x,y,z} works without issue.
I even tried with different meshes and same thing.

I don’t know what is going on.

Can you help me ?

Thanks :slightly_smiling_face:

can you share your PG?

I believe let box = r.meshes[0]; is not correct and box will be the root node.
try with let box = r.meshes[1];

1 Like