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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-stl-model-viewer

v1.0.2

Published

A React component for viewing STL files.

Downloads

209

Readme

react-stl-model-viewer

A reusable React component for inspecting STL meshes in the browser. It supports loading from remote URLs or uploaded files, face highlighting, orbit controls, and a face-selection workflow that flattens the chosen triangle onto the build plane while reporting the resulting orientation.

Features

  • Drop-in <StlModelViewer /> component with a dark, modern presentation
  • Load STL files from modelUrl or a user-provided File/Blob
  • Hover feedback and selectable faces rendered with vertex colours
  • Face selection rotates the object so the selected triangle lies flat on the ground plane
  • Orientation callback returns quaternion, Euler angles, and translation offsets
  • Visible bounding-box helper and opt-in face selection toggle
  • Optional grid/axes helpers and fully configurable colours

Installation

npm install react-stl-model-viewer three @react-three/fiber @react-three/drei

All runtime dependencies (react, react-dom, three, @react-three/fiber, and @react-three/drei) are declared as peer dependencies so your application controls the versions.

Usage

import { useState } from 'react'
import { StlModelViewer, type FaceSelectionEvent } from 'react-stl-model-viewer'

const MODEL_URL =
  'https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/models/stl/binary/pr2_head_pan.stl'

export function Example() {
  const [orientation, setOrientation] = useState<FaceSelectionEvent['orientation'] | null>(null)

  return (
    <div style={{ width: '640px', height: '480px' }}>
      <StlModelViewer
        modelUrl={MODEL_URL}
        onFaceSelect={(event) => setOrientation(event.orientation)}
      />
      {orientation ? (
        <pre>{JSON.stringify(orientation, null, 2)}</pre>
      ) : (
        <p>Select a face to receive orientation data.</p>
      )}
    </div>
  )
}

Component Props

| Prop | Type | Description | | ---- | ---- | ----------- | | modelUrl | string | Remote URL to an STL asset. Ignored when file is provided. | | file | File | Blob | Local STL file source (object URL managed internally). | | baseColor | string | Hex colour for unselected faces. Defaults to #d1d5db. | | highlightColor | string | Hex colour used while hovering a face. Defaults to #f97316. | | backgroundColor | string | Renderer background colour. Defaults to #0b1120. | | orbitControls | boolean | Toggle orbit controls (defaults to true). | | showGrid | boolean | Show or hide the ground grid helper (defaults to true). | | showAxes | boolean | Show or hide an axes helper (defaults to false). | | enableFaceSelection | boolean | Disable to turn off hover highlighting and face alignment (defaults to true). | | modelUpAxis | 'x' | 'y' | 'z' | '-x' | '-y' | '-z' | Which axis represents "up" in the STL file. Defaults to 'y'. | | initialRotation | [number, number, number] | Optional initial rotation Euler angles [x, y, z] to apply before centering/grounding. | | onFaceSelect | (event: FaceSelectionEvent) => void | Invoked when a face is clicked and flattened. | | onLoad | (info: { boundingBox }) => void | Called once the STL geometry loads, returning min/max/size vectors. |

FaceSelectionEvent exposes the selected face index, the world-space normal before rotation, and the orientation snapshot (quaternion, Euler angles in radians, and position).

Demos

The repository ships with a couple of ready-to-run demo components inside src/examples/:

  • BasicViewer – loads a remote STL and reports orientation snapshots after face selection.
  • InteractiveControls – showcases toggles for grid/axes/orbit controls and swaps between ASCII/Binary STL sources.
  • FileUploadViewer – drag-and-drop uploader that previews a local STL.

These examples are plain React components that you can render in any host app. They are also handy references when integrating the package into your own design tools.

Development

  • npm run dev – playground demo with hot reload (src/App.tsx)
  • npm run build – bundles the package (ESM + CJS) and emits TypeScript declarations
  • npm run lint – ESLint with type-aware rules

The dist/ directory contains the publishable artifacts after a successful build.