# How to save mesh imported via 3dmloader as mesh object?

**URL:** <https://discourse.threejs.org/t/how-to-save-mesh-imported-via-3dmloader-as-mesh-object/22348>\
**Category:** Questions\
**Tags:** raycasting, loaders\
**Created:** [January 12, 2021, 2:59pm UTC](https://discourse.threejs.org/t/how-to-save-mesh-imported-via-3dmloader-as-mesh-object/22348 "2021-01-12T14:59:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![oat](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/oat/32/21429_2.png) [@oat](https://discourse.threejs.org/u/oat)\
**Post date:** [January 12, 2021, 2:59pm UTC](https://discourse.threejs.org/t/how-to-save-mesh-imported-via-3dmloader-as-mesh-object/22348/1 "2021-01-12T14:59:01Z")

</div>

I imported a Rhino3d mesh object via 3dmloader, as shown below. May I ask how to assign it as a **mesh object** so that I can use it later, e.g., applying raycaster on it? It seems that `child.geometry` only gives me the first instance of the mesh. Thanks.

```
// load 3dm files
const loader = new Rhino3dmLoader(); 
loader.setLibraryPath( '/jsm/libs/rhino3dm/' ); 

loader.load('./models/building.3dm', 
            function ( object ) {
                object.traverse ( 
                    function( child ) { 
                        if ( child instanceof THREE.Mesh ) { 
                            child.material = meshMaterial_b; 
                        } 
                    } 
                ); 
                scene.add( object );
                // control.attach( object ); 
                // scene.add( control ); 
            } );
```

---

<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:** [January 12, 2021, 3:02pm UTC](https://discourse.threejs.org/t/how-to-save-mesh-imported-via-3dmloader-as-mesh-object/22348/2 "2021-01-12T15:02:04Z")

</div>

It’s probably best if you save a reference to the entire object. A mesh can consist of a hierarchy of meshes so you want to use all of them for raycasting.

The object reference can then be use by passing it to [Raycaster.intersectObject()](https://threejs.org/docs/index.html#api/en/core/Raycaster.intersectObject). You only have to make sure to set the second parameter to `true` so all descendants of the mesh are checked, too.

---

<div class="post-metadata">

**Author:** ![oat](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/oat/32/21429_2.png) [@oat](https://discourse.threejs.org/u/oat)\
**Post date:** [January 13, 2021, 10:42am UTC](https://discourse.threejs.org/t/how-to-save-mesh-imported-via-3dmloader-as-mesh-object/22348/3 "2021-01-13T10:42:00Z")

</div>

Thanks, @Mugen87 May I ask how to “save a reference to the entire object”?

---

<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:** [January 13, 2021, 11:32am UTC](https://discourse.threejs.org/t/how-to-save-mesh-imported-via-3dmloader-as-mesh-object/22348/4 "2021-01-13T11:32:37Z")

</div>

Something like this:

```javascript
// load 3dm files
const loader = new Rhino3dmLoader(); 
loader.setLibraryPath( '/jsm/libs/rhino3dm/' ); 

let myObject;

loader.load('./models/building.3dm', 
  function ( object ) {
      object.traverse ( 
          function( child ) { 
              if ( child instanceof THREE.Mesh ) { 
                  child.material = meshMaterial_b; 
              } 
          } 
      ); 
      scene.add( object );

      myObject = object;
  } );

```
