Can you turn a single block mesh in an OBJ file visible?

Hi There I am hoping there is an answer to this. I have a collection of blocks exported from Blender via a .OBJ file. At line 25 there is code that makes all the blocks invisible (comment it out to see the blocks).

I would like to be able to click any of the invisible blocks and turn them visible…is this possible?

Cheers.

Seems that is this case the simplest way is to set material.alpha = 0.

(click at any mesh, see also console)

If you need more complex functions you may set a custom predicate function in your pick:

Yes, I did the same. When working with imported meshes, I found it easy to simply act on the material. I did this in my scene. The good part is that you can also easily animate the effect (without having to import an animation with your mesh) by simply having one scene object using the same material (and you can make the object/mesh not visible. I did all of my snow accumulation effects on imported meshes using this method and it works well (and is very easy to handle).

1 Like

Hi labris, thanks for your reply.
I have to say first of all that I am new to programming and as a consequence I am trying to find simple solutions close to my understanding of how something may work.
Your solution works well… it’s a great solution…but I was still hoping to hide/show the mesh as I haven’t decided how the blocks are going to look, there may be more geometry involved.
Cheers.

Maybe meshes[i].visibility = 0; would be easier so you do not have to touch the material ?

@sebavan You are right as always :slight_smile: https://playground.babylonjs.com/#XMBIS9#5

So as I understand when mesh.isVisible = false it is not renderable; when mesh.visibility = 0 it is renderable but invisible.

yup it usually multiplies with the material opacity :slight_smile:

Actually, visibility = 0 is a special case that will throw the mesh early off the render pipeline and means the same thing than isVisible = false:

if (mesh.isVisible && mesh.visibility > 0 &&
   ((mesh.layerMask & this.activeCamera.layerMask) !== 0) &&
   (this._skipFrustumClipping || mesh.alwaysSelectAsActiveMesh
         || mesh.isInFrustum(this._frustumPlanes)
   )
) {

This is the main check that will put the mesh in the renderable list or not.

If visibility is strictly greater than 0 then it will be multiplied by the material alpha property as @sebavan said.

1 Like

Still when mesh.visibility = 0 it is pickable, and non-pickable when mesh.isVisible = false. Here is the example with visibility=0 - https://playground.babylonjs.com/#XMBIS9#6

Indeed. I guess the default pick predicate does not take into account the visibility property of the meshes.