Requesting help with showing object in Reflector, but hiding it from environment in hubs

I replaced the code:

	renderer.setRenderTarget( renderTarget );
	renderer.clear();
	renderer.render( scene, virtualCamera );

in Reflector.js with

    //Hide Head Code
    var playerHead = scene.getObjectByName("Head");
    if (playerHead){
      let scale = 1;
      playerHead.visible = true;
      playerHead.scale.set(scale, scale, scale);
      playerHead.updateMatrices(true, true);
      playerHead.updateMatrixWorld(true, true);

	  renderer.setRenderTarget(renderTarget);
	  renderer.clear();
	  renderer.render(scene, virtualCamera);

      scale = 0.00000001;
      playerHead.visible = false;
      playerHead.scale.set(scale, scale, scale);
      playerHead.updateMatrices(true, true);
      playerHead.updateMatrixWorld(true, true);

    }else{
      renderer.setRenderTarget(renderTarget);
	  renderer.clear();
	  renderer.render(scene, virtualCamera);
    }

in hopes of having the head reflected in the mirror, but not show up in the environment due to it getting in the way of the camera. This did not work as expected. This approach is based off of Mozilla Hubs: camera-tools.js lines 595 - 669. Mozilla Hubs currently runs r111. Any help would be appreciated! I am so close to having the mirror work in hubs.

I’m afraid what you are trying to do requires a modification of Reflector. However, this can easily be achieved with THREE.Layers.

Meaning you enable an additional layer for the reflector’s virtual camera.

virtualCamera.layers.enable( 1 );

In the next step, you move all objects to the above layer that you only want to render in the mirror.

mesh.layers.set( 1 );

Full example: https://jsfiddle.net/oqakydzw/

I appreciate the reply @Mugen87! I tried your approach and for some reason, it did not work like in the jsfiddle. I placed the first line of code in exactly the same spot and I placed the second line of code in Reflector.js as follows:

The object playerHead is a group, so I tried traversing the children and setting their layer as well, but I still am getting the same result. The head is still rendering in the scene and blocking the camera.

Do you get any errors? Or do you just see no effect at all?

There are no errors and I am not seeing any effect. Keep in mind this is r111. Has the layers functionality changed at all since then?

Not in context of rendering.

I think working with layers is the best approach here. Have you defined a layer for the cameras as well?

In the doc, it says:


.layers : Layers

The layer membership of the object. The object is only visible if it has at least one layer in common with the Camera in use. This property can also be used to filter out unwanted objects in ray-intersection tests when using Raycaster.


Also, if you make the head object not visible, why do you bother changing the scale?