[page:Loader] →

# [name]

A loader for Rhinoceros 3d files and objects.
Rhinoceros is a 3D modeler used to create, edit, analyze, document, render, animate, and translate NURBS curves, surfaces, breps, extrusions, point clouds, as well as polygon meshes and SubD objects. [link:https://github.com/mcneel/rhino3dm rhino3dm.js] is compiled to WebAssembly from the open source geometry library [link:https://github.com/mcneel/opennurbs openNURBS]. The loader currently uses [link:https://www.npmjs.com/package/rhino3dm/v/8.4.0 rhino3dm.js 8.4.0.]

## Import

[name] is an add-on, and must be imported explicitly. See [link:#manual/introduction/Installation Installation / Addons].

`import { Rhino3dmLoader } from 'three/addons/loaders/3DMLoader.js';`

## Supported Conversions

The [name] converts Rhino objects to the following three.js types:

3dm type | three.js type
--- | ---
Point | [page:Points Points]
PointSet / PointCloud | [page:Points Points]
TextDot | [page:Sprite Sprite]
Curve | [page:Line Line] 1
Mesh | [page:Mesh Mesh]
Extrusion | [page:Mesh Mesh] 2
BREP | [page:Mesh Mesh] 2
SubD | [page:Mesh Mesh] 3
InstanceReferences | [page:Object3D Object3D]
DirectionalLight | [page:DirectionalLight DirectionalLight]
PointLight | [page:PointLight PointLight]
RectangularLight | [page:RectAreaLight RectAreaLight]
SpotLight | [page:SpotLight SpotLight]
File3dm | [page:Object3D Object3D] 4
Material / Physically Based Material | [page:MeshPhysicalMaterial MeshPhysicalMaterial]

### Notes:

1 NURBS curves are discretized to a hardcoded resolution.

2 Types which are based on BREPs and NURBS surfaces are represented with their "Render Mesh". Render meshes might not be associated with these objects if they have not been displayed in an appropriate display mode in Rhino (i.e. "Shaded", "Rendered", etc), or are created programmatically, for example, via Grasshopper or directly with the rhino3dm library. As of rhino3dm.js@8.0.0-beta2, BrepFace and Extrusions can be assigned a mesh representation, but these must be generated by the user.

3 SubD objects are represented by subdividing their control net.

4 Whether a Rhino Document (File3dm) is loaded or parsed, the returned object is an [page:Object3D Object3D] with all Rhino objects (File3dmObject) as children. File3dm layers and other file level properties are added to the resulting object's userData.

5 All resulting three.js objects have useful properties from the Rhino object (i.e. layer index, name, etc.) populated in their userData object.

6 Rhino and Three.js have a different coordinate system. Upon import, you should rotate the resulting [page:Object3D Object3D] by -90º in x or set the THREE.Object3D.DEFAULT_UP at the beginning of your application: `THREE.Object3D.DEFAULT_UP.set( 0, 0, 1 );` Keep in mind that this will affect the orientation of all of the Object3Ds in your application.

## Examples

[example:webgl_loader_3dm]

## Constructor

### Rhino3dmLoader( [param:LoadingManager manager] )

[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].

Creates a new Rhino3dmLoader.

## Properties

See the base [page:Loader] class for common properties.

## Methods

See the base [page:Loader] class for common methods.

### [method:Object3D load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

[page:String url] — A string containing the path/URL of the `.3dm` file.
[page:Function onLoad] — A function to be called after the loading is successfully completed.
[page:Function onProgress] — (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, that contains .[page:Integer total] and .[page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
[page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives error as an argument.

Begin loading from url and call the `onLoad` function with the resulting Object3d.

`// Instantiate a loader const loader = new Rhino3dmLoader(); // Specify path to a folder containing WASM/JS libraries or a CDN. // For example, /jsm/libs/rhino3dm/ is the location of the library inside the three.js repository // loader.setLibraryPath( '/path_to_library/rhino3dm/' ); loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/rhino3dm@8.4.0/' ); // Load a 3DM file loader.load( // resource URL 'model.3dm', // called when the resource is loaded function ( object ) { scene.add( object ); }, // called as loading progresses function ( xhr ) { console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' ); }, // called when loading has errors function ( error ) { console.log( 'An error happened' ); } );`

### [method:Object3D parse]( [param:ArrayBuffer buffer], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )

[page:ArrayBuffer buffer] — An ArrayBuffer representing the Rhino `File3dm` document.
[page:Function onLoad] — A function to be called after the loading is successfully completed.
[page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives error as an argument.

Parse a File3dm ArrayBuffer and call the `onLoad` function with the resulting Object3d. See [link:https://github.com/mcneel/rhino-developer-samples/tree/8/rhino3dm/js/SampleParse3dmObjects this example] for further reference.

`import rhino3dm from 'https://cdn.jsdelivr.net/npm/rhino3dm@8.4.0' // Instantiate a loader const loader = new Rhino3dmLoader(); // Specify path to a folder containing WASM/JS libraries or a CDN. loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/rhino3dm@8.4.0' ); const rhino = await rhino3dm(); console.log('Loaded rhino3dm.'); // create Rhino Document and add a point to it const doc = new rhino.File3dm(); const ptA = [0, 0, 0]; const point = new rhino.Point( ptA ); doc.objects().add( point, null ); // create a copy of the doc.toByteArray data to get an ArrayBuffer const buffer = new Uint8Array( doc.toByteArray() ).buffer; loader.parse( buffer, function ( object ) { scene.add( object ); } );`

### [method:this setLibraryPath]( [param:String value] )

[page:String value] — Path to folder containing the JS and WASM libraries.

`// Instantiate a loader const loader = new Rhino3dmLoader(); // Specify path to a folder containing the WASM/JS library: loader.setLibraryPath( '/path_to_library/rhino3dm/' ); // or from a CDN: loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/rhino3dm@8.4.0' );`

### [method:this setWorkerLimit]( [param:Number workerLimit] )

[page:Number workerLimit] - Maximum number of workers to be allocated. Default is 4.

Sets the maximum number of [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers Web Workers] to be used during decoding. A lower limit may be preferable if workers are also for other tasks in the application.

### [method:this dispose]()

Disposes of the loader resources and deallocates memory.

## Source

[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/3DMLoader.js examples/jsm/loaders/3DMLoader.js]