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

**URL:** <https://discourse.threejs.org/t/requesting-help-with-showing-object-in-reflector-but-hiding-it-from-environment-in-hubs/17370>\
**Category:** Questions\
**Tags:** reflector\
**Created:** [July 24, 2020, 5:00pm UTC](https://discourse.threejs.org/t/requesting-help-with-showing-object-in-reflector-but-hiding-it-from-environment-in-hubs/17370 "2020-07-24T17:00:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![daCking15](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@daCking15](https://discourse.threejs.org/u/daCking15)\
**Post date:** [July 24, 2020, 5:00pm UTC](https://discourse.threejs.org/t/requesting-help-with-showing-object-in-reflector-but-hiding-it-from-environment-in-hubs/17370/1 "2020-07-24T17:00:19Z")

</div>

I replaced the code:

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

```

in [Reflector.js](https://github.com/mrdoob/three.js/blob/9c1cbd8ed86b99ed46c748ee51d31d804e625bfa/examples/jsm/objects/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](https://github.com/mozilla/hubs/blob/913de9e2ce67bda4f249b2b26acfa6d29b2c3b8c/src/components/camera-tool.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.

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/a/ad84fd960f1d538c92a5e214a8b2306be4a59302.jpeg)

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [July 26, 2020, 9:38am UTC](https://discourse.threejs.org/t/requesting-help-with-showing-object-in-reflector-but-hiding-it-from-environment-in-hubs/17370/2 "2020-07-26T09:38:22Z")

</div>

I’m afraid what you are trying to do requires a modification of `Reflector`. However, this can easily be achieved with [THREE.Layers](https://threejs.org/docs/index.html#api/en/core/Object3D.layers).

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

```auto
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.

```auto
mesh.layers.set( 1 );

```

Full example: [https://jsfiddle.net/oqakydzw/](https://jsfiddle.net/oqakydzw/)

---

<div class="post-metadata">

**Author:** ![daCking15](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@daCking15](https://discourse.threejs.org/u/daCking15)\
**Post date:** [July 26, 2020, 10:08pm UTC](https://discourse.threejs.org/t/requesting-help-with-showing-object-in-reflector-but-hiding-it-from-environment-in-hubs/17370/3 "2020-07-26T22:08:21Z")

</div>

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:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/5/5356e2fd35be2ebf557652e27a679c35f4f1a46d.png)

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.

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [July 27, 2020, 12:15pm UTC](https://discourse.threejs.org/t/requesting-help-with-showing-object-in-reflector-but-hiding-it-from-environment-in-hubs/17370/4 "2020-07-27T12:15:41Z")

</div>

> [@daCking15](#):
>
> it did not work like in the jsfiddle

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

---

<div class="post-metadata">

**Author:** ![daCking15](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@daCking15](https://discourse.threejs.org/u/daCking15)\
**Post date:** [July 27, 2020, 11:51pm UTC](https://discourse.threejs.org/t/requesting-help-with-showing-object-in-reflector-but-hiding-it-from-environment-in-hubs/17370/5 "2020-07-27T23:51:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [July 28, 2020, 9:09am UTC](https://discourse.threejs.org/t/requesting-help-with-showing-object-in-reflector-but-hiding-it-from-environment-in-hubs/17370/6 "2020-07-28T09:09:28Z")

</div>

Not in context of rendering.

---

<div class="post-metadata">

**Author:** ![Slayvin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/slayvin/32/12482_2.png) [@Slayvin](https://discourse.threejs.org/u/Slayvin)\
**Post date:** [August 1, 2020, 7:34am UTC](https://discourse.threejs.org/t/requesting-help-with-showing-object-in-reflector-but-hiding-it-from-environment-in-hubs/17370/7 "2020-08-01T07:34:29Z")

</div>

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?
