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

js-3d-model-viewer

v0.2.2

Published

An easy to use viewer to display 3D models in the browser.

Downloads

3,988

Readme

Javascript 3D Model Viewer

A web viewer to display 3D models in the browser.

Demo

How to run

Get this library as a dependency:

npm install js-3d-model-viewer

Then run this snippet after the HTML of your page is loaded:

import modelPlayer from 'js-3d-model-viewer'
const viewerElement = document.getElementById('viewer')
const opts = {
  grid: true,
  trackball: false,
  background: 'rgb(100, 100, 100)'
}
const scene = modelPlayer.prepareScene(viewerElement, opts)
modelPlayer.loadObject(scene, './assets/sample.obj') // Urls are fine here.
// Alternatively you can load a .glb file
modelPlayer.loadGlb(scene, './assets/sample.glb') // Urls are fine here.

You're done!

If you want to go fullscreen, you can do it like this:

const viewerElement = document.getElementById('viewer')
const fullScreenButton = document.getElementById('fullscreen-button')
fullScreenButton.addEventListener('click', () => {
  modelPlayer.goFullScreen(viewerElement)
})

If you want to enable the underlying Thee.js cache:

modelPlayer.enableCache()
// modelPlayer.disableCache()

Development status

  • Currently the viewer supports only .obj and .glb files.
  • Unit tests are missing

Technologies

This viewer is based on Three.js

Development environment

First install dependencies:

npm i

All the code is in the src/index.js file. Once you did your changes you have to run the dev build:

npm run build

Then you can test it with the demo page by starting a static webserver:

npm run serve

You can see the result in the browser by connecting to http://localhost:9080.

To build the projects for production you have to run the following command:

npm run build

You will obtained a minified version of the sources in the dist folder.

Resources

  • Tutorial: https://manu.ninja/webgl-3d-model-viewer-using-three-js/
  • Obj loader: https://threejs.org/docs/#examples/loaders/OBJLoader
  • Sketchfab viewer: https://sketchfab.com/developers/viewer

About authors

This viewer is written by CG Wire, a company based in France. We help animations studios to manage their production and build pipeline efficiently.

We apply software craftmanship principles as much as possible. We love coding and consider that strong quality and good developer experience matter a lot. Our extensive experience allows studios to get better at doing software and focus more on the artistic work.

Visit cg-wire.com for more information.

CGWire Logo