Select Invisible Mesh?

Hello everyone,

Is it possible to select a mesh that is not visible?
For instance, in the example below, could you somehow set sphere.isVisible = false and still get the “click” output?

https://www.babylonjs-playground.com/#83SAJ8#1

Option 1: Set the material to a transparent material:
https://www.babylonjs-playground.com/#83SAJ8#2

Option 2: Override the picking function to not skip over invisible meshes.

1 Like

Hello @morterra

Thanks for the suggestions! How could I override the picking function?
I found a thread that referenced mesh.isEnabled, but I didn’t have any success adding that :thinking:

You just need to set a custom predicate function in your pick that doesn’t sort invisible meshes

https://doc.babylonjs.com/api/classes/babylon.scene#pick
Something like:

mesh => { return mesh.isEnabled() && mesh.isPickable }
3 Likes

Hello again @morterra

Option 1 is definitely a great solution, and thanks for demonstrating it in the PG! I was asking about Option 2 because I wasn’t sure which option would be best for performance, but you explained that well in your other post, thanks.

Also, thanks @aWeirdo for helping out with this. Are there any performance advantages to either of the solutions (transparency vs. enabled)? I plan on trying both to see, but I’m wondering if anyone knows.

Thanks again to you both! :smiley: :+1:

Changing visibility/transparency, the mesh is still active, just not visible.

Setting enabled false, the mesh will be disabled, and i believe babylon will stop updating it in some ways :slight_smile:

2 Likes

I see, that makes sense.
Thanks!