How to change the colour of a mesh that has a texture?

Hi all,

Can anyone recommend a method whereby we can change the colour of a mesh that has a texture already? see the PG here:

Right now we are using the following to change the colour, but nothing happens :frowning:

mesh.material.diffuseColor = BABYLON.Color3.FromHexString("#f6dea6").toLinearSpace()

Thank you again for your help.

There are several things that comes to my mind:

  1. You use Instances that share material with your original mesh, if you want to set individual materials for each, you have so use Clones:
    Clones | Babylon.js Documentation

  2. Your meshes have PBRMaterials, so you will have to set albedoColor.
    Mastering PBR Materials | Babylon.js Documentation

  3. You use MultiMaterial, I guess you have to set material of submesh?
    Multi-Materials | Babylon.js Documentation

I.e. if you set MultiMaterial-flag to false on MergeMeshes and set albedoColor it works:

1 Like

Thanks @Takemura , I am trying to add a little brightness to the texture as well. My mind ran to the emissiveColor property but I can’t figure out how to vary this since it seems to blow up the texture with full color emission. Is there an alternative where I can say tweak this brightness level with the color.

Do you look for emissive intensity?

Example Code:

mesh.material.emissiveIntensity /= 2

Or directIntensity for diffuse & specular:

1 Like

@Takemura thanks for the help, I think in this case emissiveIntensity is the property I have been looking for. :heart:

It seems to me that even though I am now using clones, the materials are still shared.

You need to additionally clone the material.
The mesh clone will not clone the material.
PG:

fix row 80~81

2 Likes

As @Aze said you need to clone material too, because the materials are still linked (reference the same material object), so it will take material configuration of what you have set last.

1 Like