There are 8 models, I click on one model to change the color, and the other model’s color goes back to the original color, like the selected state, I don’t know how to achieve this effect, because these models are added dynamically, right
Impossible to know the problem from just an image. Please repro the issue in a playground.
https://www.babylonjs-playground.com/#F7ZZJF#32
I want to click on the model to change the color, and the other models to return to the original color, just like the ones in 3d software, but now just click on one to change the color
https://www.babylonjs-playground.com/#F7ZZJF#32
I want to click on the model to change the color, and the other models to return to the original color, just like the ones in the 3d software, but now I just click on one to change the color, and the other models also change the color
I am a beginner, but I think I know what your problem is. The skull is using a standard material and you are changing it to your own material on click, but never removing it. All the skulls that get clicked on get set to use the same material so they will all have that same material’s colour.
As I understand it, you have various options here. You could achive this effect by swapping materials or by adding some sort of light that only shines on the last selected mesh.
Here’s what I would try to do:You could create two materials and create a function which swaps one material for another on click, changes the material of the last clicked mesh back to a default material and stores the last clicked mesh in a variable.
Here is an updated playground: https://www.babylonjs-playground.com/#F7ZZJF#34
As I said I am a beginner, so maybe other people have a better solution, but this seems to work ok.
@Richard you are spot on !!!
- Thanks for helping me out