# Hiding multiple objects with the same name?

**URL:** <https://discourse.threejs.org/t/hiding-multiple-objects-with-the-same-name/40263>\
**Category:** Questions\
**Tags:** lod\
**Created:** [July 12, 2022, 4:26pm UTC](https://discourse.threejs.org/t/hiding-multiple-objects-with-the-same-name/40263 "2022-07-12T16:26:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![UI\_UNICORN](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ui_unicorn/32/9842_2.png) [@UI\_UNICORN](https://discourse.threejs.org/u/UI_UNICORN)\
**Post date:** [July 12, 2022, 4:26pm UTC](https://discourse.threejs.org/t/hiding-multiple-objects-with-the-same-name/40263/1 "2022-07-12T16:26:26Z")

</div>

Hi so i’m trying to hide multiple tree meshes if they are a certain distance away but i can’t seem to do it? any idea’s:

```javascript
 scene.traverse(function(child) {
 
  for (let i = 0; i < child.length; i++) {
 

  if (child.name.includes('Tree')) {
       var distance = pl.position.distanceTo( child[i].position );
   if (distance >= 20)
   {
       child[i].visible = false;
       console.log('far', child[i]);
   }
   else {
       child[i].visible = true;
       console.log('close', child[i]);
   }
   
  }

  }
});

```

---

<div class="post-metadata">

**Author:** ![drcmda](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@drcmda](https://discourse.threejs.org/u/drcmda)\
**Post date:** [July 12, 2022, 5:25pm UTC](https://discourse.threejs.org/t/hiding-multiple-objects-with-the-same-name/40263/2 "2022-07-12T17:25:26Z")

</div>

[https://threejs.org/docs/index.html?q=lod#api/en/objects/LOD](https://threejs.org/docs/index.html?q=lod#api/en/objects/LOD)

you can get an impression of how it looks here [Re-using geometry and level of detail - CodeSandbox](https://codesandbox.io/s/re-using-geometry-and-level-of-detail-12nmp) the trick is to give it an empty mesh if you want it to disappear at a certain distance.

---

<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 13, 2022, 8:32am UTC](https://discourse.threejs.org/t/hiding-multiple-objects-with-the-same-name/40263/3 "2022-07-13T08:32:44Z")

</div>

When using `traverse()`, you automatically process all objects in the scene’s hierarchy. There is no need to additionally process the children of an object.

Besides, you don’t want to work with the local position of a 3D object. You should extract the position in _world space_ and then make your distance test. You can use [Object3D.getWorldPosition()](https://threejs.org/docs/index.html#api/en/core/Object3D.getWorldPosition) for this.

---

<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 13, 2022, 8:34am UTC](https://discourse.threejs.org/t/hiding-multiple-objects-with-the-same-name/40263/4 "2022-07-13T08:34:41Z")

</div>

BTW: The official `THREE.LOD` example with plain `three.js` looks like so: [three.js webgl - level of detail](https://threejs.org/examples/webgl_lod)
