Pick a model part for selective changes

Hi,

i’m looking for a way to select model part of scene by clicking and highlight and after that i want to hide the specific part by clicking a button. I saw some examples in documentation that works fine with materials hove or, but i can’t find the same with model part … I tried to mix some code, and i’m not too far.
here the link to my test: https://codepen.io/matt8629/pen/mdWEOKE?editors=1111
I don’t why half of the time i pick the model the console log type “undefined” for ID and name…

is there a way to pick and select the name and id from clicked part?
i saw that there is the list (getNodeMap) but there are a lot of parts, it’s not good for me

Thanks

HI @animdrops, I’ve taken a look at your code. The pick event only returns the instanceID of the picked object (and coords, normal and material). You need to find the object name yourself. A good place to start is the result of the getNodeMap function, as you mention. It’s quite easy to get the node from the nodeMap object. I’ve updated your example: https://codepen.io/klaasnienhuis/pen/ExWyzzJ?editors=0011

There’s one thing I don’t understand. Clicking on some objects does not give a result. For instance, the red cover on top of the engine does not return an instanceID. Perhaps someone at Sketchfab knows (@james?)

it’ the one use case of the pick/click option { pick; slow }
(complex animated model where we need to compute much more data, so it’s not the default)

1 Like

Thanks @paul_sketch, that helped.
@animdrops I’ve updated the codepen: https://codepen.io/klaasnienhuis/pen/ExWyzzJ?editors=0011. It should meet your requirements.

Hi @klaasnienhuis, hi @paul_sketch
thank you very much for yours valuable advice! Now works fine!

A killer features (for me) could be to change the material (emitColor in this example) only to specific instanceID but i suppose it’s not possible to do from code…

Anyway thanks for help!

Hi @animdrops, glad to help. It’s fairly straightforward to only allow material changes for specific instanceID’s. Just add a check before doing the change. However, keep in mind that if a material is shared between multiple objects, the material is changed on each of these objects. It’s easier to look at the material names in those cases.