Change UV coordinatesIndex for only one mesh

Hello Everyone,

How can I change the UV map for one mesh and not all meshes with the same material?

Here is an example:

I have the monkey and cube which use the same material. They have different colors because the UV maps point to different areas in an image, using this technique:

When I do this:
suzanne.material.albedoTexture.coordinatesIndex = 1;
the monkey uses the second UV map and changes color as expected, but I do not want the box to change.

Is there a way to change the monkey UV and not the box?

Comment out this line and you can see the original color blue of the box, which I want to remain while the monkey changes:
suzanne.material.albedoTexture.coordinatesIndex = 1;

You must create a new material and a new texture if you want to use an albedo texture with a different coordinate index:

1 Like

The new texture will use the cache so not real worry to have there :slight_smile:

Thanks everyone. If I create a new material with the same image in Blender it would accomplish the same thing as cloning it with code, correct?

For flat color, low poly scenes, is there much advantage in Babylonjs to doing colors with this image and UV method as seen in the video? Or would just choosing a color with the picker be about the same in terms of performance? (Blender to GLB)

I don’t know Blender, so I can’t tell if it will optimize the export by using a single material because both materials are the same in reality… You should give it a try.

For a single flat color, it is better to use an albedo color instead of a texture, as you will save the texture memory (even if it’s not much). But in the video they don’t use a single color for the mesh, so there’s no way around using a texture.