Change a mesh color by clicking on it (and revert when clicking on background)

Hello,

I’m in the process of creating a project that is an explainer for the 2022 F1 regulation volumes. These have been drawn in CAD and then imported to separate meshes using ImportMeshAsync.

What I need to do next is to add some functionality so that when one of these individual meshes is clicked on it changes color and then some other items appear (dimensions, text etc.). Then when the user clicks off the mesh onto the background, or onto another mesh, it reverts to its original color and the additional items disappear. I think once the functionality is there just for the color change I can add all of the extra bits but thus far I can’t get the behavior I want.

The bottom block of code in the repro changes the color but it does it for all of the meshes not individual items. Also I am not sure if this approach will allow the more bespoke behavior of showing and hiding other information relevant to that one individual mesh. It almost feels as though I will need a separate if loop for each individual mesh as opposed to this block behaviour?

The repro below has the base loading of meshes plus the initial attempt at functionality. Any help would be greatly appreciated.

PS - if the mesh loading method needs to be different to achieve this then please let me know. I have tried other methods but this seemed to be the quickest.

Best,
Sy

It seems that instead of changing the material, you simply change the color of the material. This results in changing the color for all the meshes since they all share the same material :smiley:

Here’s a working PG with comments

3 Likes

That’s great thanks!