Why instance.instancedBuffers.color it doesn't work on BJS version 5?

Hello everyone

My Block model is optimize with instance and work correctly in BJS version 4.2, but when I change it to version 5.0 the instance.instancedBuffers.color is not work. how can I solve this problem with version 5?
here is my PG: https://www.babylonjs-playground.com/#ZEZLAT#42

and also I used the following code for using instance:

const cube = new BABYLON.BoxBuilder.CreateBox(
      { height: 5, width: 5, depth: 12 },
    cube.alwaysSelectAsActiveMesh = true;
    const mat = new BABYLON.StandardMaterial("mat", scene);
    mat.specularColor = new BABYLON.Color3(0, 0, 0);

    cube.material = mat;

    cube.registerInstancedBuffer("color", 4);
    cube.instancedBuffers.color = new BABYLON.Color3(0.1, 0.2, 1);

    for (let i = 0; i < cubes.length; i++) {
      //   console.log(cubes[i]);

      let instance = cube.createInstance("cube" + cubes[i].key);

      instance.position.x = cubes[i].X;

      instance.position.y = cubes[i].Y;

      instance.position.z = cubes[i].Z;

      instance.instancedBuffers.color = new BABYLON.Color4(

      // mat.diffuseColor = new BABYLON.Color3.Lerp(color1, color2, cubes[i].G);

      avgX += cubes[i].X / cubes.length;
      avgY += cubes[i].Y / cubes.length;
      avgZ += cubes[i].Z / cubes.length;
    //   instance.alwaysSelectAsActiveMesh = true;


      //************** End Fetch Cubes **********/

This PR broke it:

@breakin Could you have a look at this? It seems your changes to InstancedMesh broke this PG:

The cubes should be red and green.


1 Like

I will look into it once there is a little bit less of christmas!
Excellent repro btw. From what I can tell it should not be something that was intentionally broken so let me figure out what what is wrong!


1 Like

We ll see with @Evgeni_Popov if we can find it today as it is a regression and I would prefer to get it fixed soon :slight_smile:

If not, we ll let you know and it could then wait your return from vacation.

1 Like

@Evgeni_Popov @sebavan @breakin Thank you so much for helping :pray: :pray:

Ok I found it and I ll push a fix in about 1 hour :slight_smile:

1 Like

Ah, was doing it too!

1 Like

PR on its way:

1 Like

NP we ll take yours it is way better. @breakin it will be a few changes cause a none negligeable part was not working anymore.

Nice fixes!

I guess that a new breaking change then is that (after the fix) mesh.getKinds != mesh.geometry.getKinds.

Do you need anything from me? Feels like you found the main problem and then some. I will test that sharing of buffers still work but seems that you didn’t undo the main idea behind my change.

Good work!

Yes, mesh.getVerticesDataKinds will potentially return a bigger array than geometry.getVerticesDataKinds but at least it will return the same array than before the PR, meaning an array with all the kinds, even the ones coming from the custom instance buffers: not doing it was a breaking change.

It’s the same reasoning for isVertexBufferUpdatable, isVerticesDataPresent, getVertexBuffer and getVerticesData: they will work for all kinds, even the ones coming from the custom instance buffers, as before the PR.

We didn’t change the main idea of the PR so it still should work as expected!

1 Like

Sounds good! I am happy you did the fixes given that you knew more places to fix stuff! Happy that you took the time to make it work instead of rollbacking my feature!

1 Like