I’m new with Babylon so it might be easy thing to do, but I couldn’t figure out how to do it.
Here is a playground that I’ve prepared: https://playground.babylonjs.com/#V9HGX4#1
I’m loading a scene that was exported from Unity. I want to have buildingMesh fully transparent and make parts of other meshes that are inside and behind builingMesh not visible. When I’m changing visibility of building mesh then all parts of meshes that are inside or behind the building mesh are displaying. Just can’t figure out what I should add to code to make it work how I want.
The problem is that all other meshes have intersections with buildingMesh - https://playground.babylonjs.com/#V9HGX4#4
I don’t know the way to hide just a part of mesh (except complex camera frustum tricks).
Much easier to do it by mesh names which you can define at model level.
On stackoverflow I’ve found similar problem as mine but in three.js, is there an equivalent of this feature in babylon?
I’ve edited the fiddle to look similar to my problem. The blue mesh is like mine buildingMesh that should be invisible: Edit fiddle - JSFiddle - Code Playground
You can use Material.disableColorWrite = false to draw an invisible object that will still occlude other objects and Mesh.renderingGroupId = X to order the meshes.
In the below PGs I have used renderingGroupId = 0 for all objects that should not be occluded, renderingGroupId = 1 for occluders and renderingGroupId = 2 for meshes that should be occluded. Also, you need to call: