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:
scene.setRenderingAutoClearDepthStencil(1, false);
scene.setRenderingAutoClearDepthStencil(2, false);
so that the zbuffer is not cleared between the rendering groups.
In this PG, the occluder (mesh C) is located in front of the green mesh, so this green mesh is not visible.
In this PG, the occluder is located behind the green mesh, so this green mesh is visible.
[EDIT] A more similar example to the jsfiddle: