Can not make a mesh blink because it is an InstancedMesh

Just to confirm @Deltakosh, @sebavan the things I have found that InstancedMesh can not do that I could not find in the documentation. Also Is there a list of things that can not be set to an InstancedMesh, but are in its interface?

An InsancedMesh can not have

mesh.material =

because it has no setter.

An InstancedMesh has a renderOnline setter, but it can not have a

mesh.renderOutline = true

for the same reason as the blink.

It has a renderOverlay setter but it can not have

mesh.renderOverlay = true

On the debug trying to display the normals will result in exception bellow because there is no material setter:

Uncaught TypeError: Cannot set property material of [object Object] which has only a getter
    at t.displayNormals (babylon.inspector.bundle.js:31)
    at Object.onSelect (babylon.inspector.bundle.js:31)
    at t.onChange (babylon.inspector.bundle.js:31)
    at onChange (babylon.inspector.bundle.js:31)
    at Object.<anonymous> (babylon.inspector.bundle.js:51)
    at C (babylon.inspector.bundle.js:51)
    at babylon.inspector.bundle.js:51
    at x (babylon.inspector.bundle.js:51)
    at T (babylon.inspector.bundle.js:51)
    at Array.forEach (<anonymous>)

Trying to display the vertex colors will result in exception below for the same reason:

Uncaught TypeError: Cannot set property material of [object Object] which has only a getter
    at t.displayVertexColors (babylon.inspector.bundle.js:31)
    at Object.onSelect (babylon.inspector.bundle.js:31)
    at t.onChange (babylon.inspector.bundle.js:31)
    at onChange (babylon.inspector.bundle.js:31)
    at Object.<anonymous> (babylon.inspector.bundle.js:51)
    at C (babylon.inspector.bundle.js:51)
    at babylon.inspector.bundle.js:51
    at x (babylon.inspector.bundle.js:51)
    at T (babylon.inspector.bundle.js:51)
    at Array.forEach (<anonymous>)

But render vertex normals will work correctly.

Thanks for the summary! Yes this is correct. The price for performance is definitely less flexibility
I’ll fix the inspector to avoid displaying the debug options that do not work

I will also move the renderoutline and overlay down to mesh

That would make it more clear.

Do you also happen to have any data on the performance differences between Mesh and InstancedMesh? I am thinking of removing the InstancedMesh(s) and replacing them with normal Mesh and it would be good to know what we would be loosing on our scene. We tried recently to load a scene with 3B triangles and probably InstancedMesh could help us here, but for our current scene I would like to justify the lost flexibility.

A number of searches on “babylon instancedmesh performance”, “babylon instancedmesh to mesh comparison” got me a number of tutorials on how to optimize but little about what instancedmesh bring to the table.

It is massive! InstanceMesh are drawn in one draw call :slight_smile: (I mean one draw call in total for all instances) vs 1 draw call PER mesh

I accept that. I think it should be huge, I suppose it is huge, I’ve seen some examples in the playground that perform well, but I have found zero evidence to justify the time spend on the implementation of loading a gltf, pointing the mouse to mesh and highlighting this mesh and only this mesh.

I could run a few test on my machine, but it would take a lot of time to setup them and I will get only the results on my machine, probably the colleagues machines also. Which is not very representative and I am not sure I know enough about BabylonJS to properly do it. That’s why I am looking for a more broad analysis of how huge is huge and not as a general ‘geometry instances’ approach where I’ve read some nvidia and opengl articles on performance, but specifically BabylonJS implementation.

not sure it fits your need, but there’s an alternative in some cases to instances called the SPS : Solid Particle System - Babylon.js Documentation

Not sure to get what you need :slight_smile: Instances are the way to go if you can. They are worth the time spent to use them

I was working on the example and I am still trying to make an “InstancedMesh blink” (change from original color to Red to originalColor and repeat this 3 times).

I’ve managed to register instanced buffers but I can not change the color of a single InstancedMesh.

Here is my idea:
Iterate over all the source and instanced meshes and register a buffer. Set the color to be the original color of the mesh. In this way all the instanced meshes will have a registered buffer, all the source meshes will have a registered buffer.

Am I thinking in the right direction?

newScene.rootNodes[0].getChildMeshes().forEach((mesh) => {
    if(mesh.getClassName() == "InstancedMesh") {
        let color;
        if (!mesh.sourceMesh.instancedBuffers) {
            mesh.sourceMesh.registerInstancedBuffer("color",4)
            color = mesh.sourceMesh.material. ... how to get the color of the source mesh?;
            mesh.sourceMesh.instancedBuffers.color = color;
        }
        mesh.instancedBuffers.color = color;
    }
})

But I can not get the ‘color’ of the insancedMesh material because it is a PBRMaterial and I can get any of the ‘albedoColor’,‘ambientColor’, ‘emissiveColor’, ‘reflectionColor’, ‘reflectivityColor’ and I can set any of them, but this will change how the InstancedMesh looks like, because we are loosing color information.

If I manage to somehow get a ‘Color’ of the PBRMaterial and set this color to the buffers, that I should be able to do

const iMesh = scene.getMeshByID("");
iMesh.instancedBuffer.color = BABYLON.Color3.Red()

and this should set the color for this mesh to Red.

Than to animate it I could do

const animation = new BABYLON.Animation("a", "instancedBuffer.color", frames, BABYLON.Animation.ANIMATIONTYPE_COLOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);

and this animation will change the value of ‘instancedBuffer.color’ for this iMesh. Right?

  1. How could I get a ‘color’ property of PBRMaterial that I should set to the buffer?
  2. Is BABYLON.Animation(“a”, “instancedBuffer.color”…) expected to work and to animate only the color of this particular iMesh?

Thanks

  1. The color here is a multiplicative color that gets applied to the material. So by default just set it to white (so you will see no difference)
  2. Yep This is correct

Thanks for the support. I could not get it working this week and I all together dropped it. I decided to just draw a bounding box around my mesh instead of making it blink/highlight. I had to create a new LinesMesh and I am displaying/blinking the lines mesh when I want to highlight/blink the mesh. Not great, not terrible, but I have to move on with other things on the scene for now. Probably will return again to this in a few months.

Here is with animations:
https://www.babylonjs-playground.com/#YPABS1#16

1 Like

Is it a success?

No. Still using the implementation I’ve done on 19 of october. Since them we have moved to other things in our project and we are living without blinking. We still don’t have the resource to properly address the implementation