npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rhino3dm

v8.6.1

Published

Node.js package based on OpenNURBS with a RhinoCommon style

Downloads

8,230

Readme

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.

For browser based applications, we also develop a 3dmLoader for the popular three.js WebGL library: https://threejs.org/examples/?q=3dm#webgl_loader_3dm

Usage

The easiest way to get started is to reference a specific version of the library using jsDelivr.

<!DOCTYPE html>

<body>

  <!-- Import maps polyfill -->
  <!-- Remove this when import maps will be widely supported -->
  <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>

  <script type="importmap">
      {
          "imports": {
            "rhino3dm":"https://cdn.jsdelivr.net/npm/[email protected]/rhino3dm.module.min.js"
          }
      }
  </script>

  <script type="module">

    import rhino3dm from 'rhino3dm'
    const rhino = await rhino3dm()
    const sphere = new rhino.Sphere( [1,2,3,], 12 )
    console.log(sphere.diameter)

  </script>

</body>

</html>

You can also download the files if you want to bake them into your site or application. You'll need the .wasm web assembly along with the .js (or .min.js) wrapper.

Node.js

rhino3dm.js is available on npm; try npm install rhino3dm. Note: the resulting webassembly binary (rhino3dm.wasm) is fairly large for browser based applications. We are working on ways to make this smaller.

Example node.js script:

import rhino3dm from 'rhino3dm'
const rhino = await rhino3dm()
const sphere = new rhino.Sphere([1,2,3,], 12)
console.log(sphere.diameter)

React.js

Similar to plain html, rhino3dm.js can be added as a script in index.js

// index.js
import { StrictMode } from "react";
import ReactDOM from "react-dom";

import App from "./App";

const rootElement = document.getElementById("root");

const script = document.createElement("script");
script.src = "https://cdn.jsdelivr.net/npm/[email protected]/rhino3dm.min.js";
script.addEventListener("load", () => {
  ReactDOM.render(
    <StrictMode>
      <App />
    </StrictMode>,
    rootElement
  );
});
document.body.appendChild(script);

Once loaded, rhino3dm can be referenced in any component with window.rhino3dm, keep in mind that the wasm file loads asycnhronously so any any calls to wasm methods need to happen inside .then() or using await

// App.js
import React, { useEffect, useState } from "react";
import "./styles.css";

export default function App() {
  const [sphere, setSphere] = useState(null);

  useEffect(() => {
    window.rhino3dm().then((Module) => {
      //creating a sphere using rhino3dm
      setSphere(new Module.Sphere([1, 2, 3], 16));
    });
  }, []);

  return <div className="App">{sphere && <p>{`sphere diameter is: ${sphere.diameter}`}</p>}</div>;
}

CodeSandbox of above react implementation can be found here

API Docs

The latest rhino3dm.js API Documentation

Examples

There a few samples are available in the Rhino Developer Samples repository

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