Externally loaded GLBs not being masked?

Hello again!

So I’m also trying to load external GLB files from a URL, the loading itself seems to be working fine but I need those GLBs to be occluded by a mask object (which is a .glb file loaded from inside the app)

This is what I use to mask 3D objects

var meshInstances = this.entity.model.meshInstances;
var mat;
    for(var i = 0; i < meshInstances.length; i++) {
        mat = meshInstances[i].material;
        mat.redWrite = mat.greenWrite = mat.blueWrite = mat.alphaWrite = false; // don't render occluder to color
    } 

This works fine for .FBX files, but when I load in GLB files they seem to completely ignore the occluder, any ideas here?

I’ve set up a project here with a regular primitive where occlusion works and loaded in a free GLB that renders over the occluder, is there a material setting needed to be set on GLB loaded files?

(If you hit play mode in that project, you can move camera with left and right arrow keys to observe the occlusion)

I beleive the issue you have is related to the order in which the meshes are rendered, and not how you load the glb files.

For your scene, this is the order of rendering currently:

  • the animal
  • occluder (color channels disabled)
  • cube

and so the occluder only occludes meshes rendered after it.

You should user layers. Create an additional layer that renders first, before the world layer, and render the occluders in that layer.

2 Likes

That worked! @mvaligursky, I figured since it always worked with FBX on the same layer that there shouldn’t have been an issue but I guess layers slipped my mind. Thanks!