Instance color & alpha for LinesMesh

I’m looking at applying different colors & alpha for my instanced LinesMeshes.
How should I apply color and alpha values for an instanced LinesMesh ?

In this playground sample, I tried to use registerInstancedBuffer() for LinesMesh. But it crashes if I uncomment Line number 19

I was able to clone a LinesMesh and apply color to the cloned mesh. But, I would get a performance hit if I’m cloning meshes.

Linesmesh - Instancing & Clone - Colors | Babylon.js Playground (

Adding @Evgeni_Popov who masters the art of buffers and instances :slight_smile:

Also may I ask why not relying on a lineSystem in your case instead of instances ? Creating A Line System | Babylon.js Documentation

You would probably save memory :slight_smile: basically having only 2 vertices positions per elements + colors vs a full matrix 4 per element + colors for instances

1 Like

This actually looks like a bug to me. I ll fix it in a sec, @Evgeni_Popov you can disregard :slight_smile:

Thanks for the info. I’ll check on Line System & see if it fits for all of my app operations like individual line (edge) picking & highlight, instance colors & alpha…

PR is up Fix create instance line mesh by sebavan · Pull Request #10807 · BabylonJS/Babylon.js · GitHub but the comment on instances vs line system might still be valid depending on your use case :slight_smile:


Thanks for the fix. I was able to apply colors & alpha for a Line instance with BabylonJS 5.0.0-alpha.38 version.

Here’s the updated playground sample
Linesmesh - Instancing & Clone - Colors | Babylon.js Playground (

I also noticed another console crash - If I set instance properties (color) to InstancedLinesMesh only while not allocating it for the original LinesMesh (comment line 19 & check), another console crash occurs.

It is a bug on the user side, so it is expected to crash: you have to create the buffer on the master mesh.

1 Like