npm

Need private packages and team management tools?Check out npm Orgs. »

rhino3dm

0.8.1 • Public • Published

rhino3dm.js

rhino3dm.js is a javascript library with associated web assembly (rhino3dm.wasm) that is OpenNURBS plus additional C++ to javascript bindings compiled to web assembly. The library based on OpenNURBS with a RhinoCommon style. The libraries will run on on all major browsers as well as node.js.

CircleCI


Usage

Rhino3dm.js requires two files rhino3dm.wasm and rhino3dm.js. It is easiest to simply reference the latest build directly from our servers:

<html>
  <!-- stuff -->
  <body>
    <script type="text/javascript" src="https://files.mcneel.com/rhino3dm/js/latest/rhino3dm.js"></script> 
    <script>
      // NOTE: the rhino3dm library is compiled with the MODULARIZE
      // option to avoid collisions with other web assemblies
      // here's one way of using it...
      rhino3dm.then((Module) => {
        sphere = new Module.Sphere([1,2,3], 12)
        // more stuff
      })
      // even more stuff
    </script> 
    <!-- you get the idea -->
  </body>
</html>

Download the files

If it would be better to download a static build locally, download the latest build of the two files:

Place these in the same folder. The rhino3dm.js references the rhino3d.wasm.

Note: A list of builds is available on our Circleci project. You can replace latest with dujour/BUILD_NUMBER if you know what you're looking for!

Node.js

rhino3dm.js is available on npm; try npm install rhino3dm.

$ node
> rhino3dm = require('rhino3dm')() // note the trailing "()"
> sphere = new rhino3dm.Sphere([1,2,3,], 12)

It takes a moment to load the ~5 MB wasm file – this happens asycnhronously. Unlike interactive usage, when scripting with rhino3dm you can use the fact that the rhino3dm() function returns a Promise.

script.js
rhino3dm = require('rhino3dm')
 
rhino3dm().then((rhino) => {
  sphere = new rhino.Sphere([1,2,3,], 12)
  console.log(sphere.radius)
})

API Docs

The latest rhino3dm.js API Documentation

Examples

There a few samples are available in the Github Repo Samples folder

An advanced sample creates a 3dm file viewer in a web browser. The html+javascript to create the viewer is around 300 lines (including comments) and runs on all browsers including mobile devices.

rhino3dm.js is used to read a 3dm file and create an instance of a File3dm class in the browser’s memory. It then walks through the objects in the model and calls compute.rhino3d.com to create meshes and isocurves for the polysurface. These meshes and isocurves are then added to a three.js scene for display.

Here's another example of rhino3dm.js, this time running in one of Observable's live notebooks. Dive right in an tweak the code!

Build from source

If the pre-compiled libraries above do not work in your situation, you can compile the libraries from their source. For detailed instructions go to rhino3dm.js and rhino3dm.wasm

Keywords

install

npm i rhino3dm

Downloadsweekly downloads

34

version

0.8.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
Report a vulnerability