Use a mesh to occlude part of another mesh

Hi guys, I’m just starting with BabylonJS and I would like to be able to occlude part of a mesh with another mesh, but I’m so newbie :frowning:
I have the following two meshes (created in Blender) glasses and head.
I want to use the head to occlude the glasses, so I would like to make the head invisible but the part of the glasses that are over the ears should not be rendered.
Any idea how can I do that? I really appreciate your help guys.

You can disable write color in mesh.onBeforeRenderObservable and reenable it in mesh.onAfterRenderObservable:

https://playground.babylonjs.com/#AAM6LK

It was suggested here Tweaking material in Sandbox in order to be occlusive yet invisible that a disableColorWrite property could be created for this, but I don’t think it has been done yet.

2 Likes

Thank you for the response, it works perfectly!