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

threejs-model-loader

v0.1.0

Published

THREE.js Model Loader that delegates to the appropriate geometry loader

Downloads

39

Readme

threejs-model-loader

npm version lgtm code quality

THREE.js Model Loader for delegating to the appropriate geometry loader. Uses the file's extension to determine which THREE geometry loader to use.

Drag and drop example

THREE.ModelLoader

var loader = new THREE.ModelLoader();

// overriding the getLoader function so loaders can be
// loaded as-needed
loader.getLoader = function( loaderName, manager, loadercb ) {

    function createLoader() {

        return new THREE[ loaderName ]( manager );

    }

    if ( THREE[ loaderName ] == null ) {

        // fetch the loader script from the server and run it
        // if it's not already on the page
        fetch(`.../node_modules/three/examples/js/loaders/${ loaderName }.js`)
            .then(res => res.text())
            .then(tex => {

                eval( text );
                loadercb( createLoader() );

            });

    } else {

        loadercb( createLoader() );

    }

}

loader.load( '.../model.ply', res => {

    // res.model
    // res.originalResult
    // res.extension

} );

Functions

ModelLoader.load(path, onLoad, onProgress, onError, extOverride)

A function signature that mirrors all the THREE.js geometry loaders. An appriopriate loader is selected based on the file name.

If extOverride is set, then that extension is used to select the loader.

onLoad is passed an object with values

{
    model,         // THREE.js Object3D, Group, or Mesh that was loaded
    extension,     // The extension of the model that was loaded
    originalResult // The original result that the loader returned
}
ModelLoader.parse(data, ext, onLoad, onError)

Takes the data to parse into geometry and the associated file extension in ext.

The model is returned asynchronously in onLoad to support async fetching of the loaders.

See load for documentation on what the onLoad function is passed.

Override-able Methods

ModelLoader.getLoader(loaderName, manager, loadercb)

Function used to return an instance of a particular loader. Once the loader has been created, pass it into loadercb. See above code snippet for an example.

Members

ModelLoader.loaderClasses

Object with a map of loader name to loader class to instantiate. Used only for the default implementation of the getLoader function. Defaults to the available THREE object where loaders are typically available.

ModeLoader.loaderMap

List of extension to loaderName, used to select the loader for each extension. The list can be modified by adding and removing keys from the list. Every loader is expected to be found on the THREE object.

loader.loadMap[ 'obj' ] = 'OBJLoader';
delete loader.loadMap[ 'stl' ];

model-viewer Element

<!-- Register the Element -->
<script href=".../model-viewer-element.js" />
<script>customElements.define('model-viewer', ModelViewer)</script>

<body>
  <model-viewer src=".../path/to/model.ply" display-shadow ambient-color="red"></model-viewer>
</body>

Attributes

src

The url of the model to display.

display-shadow

Whether or not the render the shadow under the robot.

ambient-color

The color of the ambient light specified with css colors.

show-grid

Show a grid underneath the model.

auto-redraw

Automatically redraw the model every frame instead of waiting to be dirtied.

Functions

redraw()

Dirty the renderer so the element will redraw next frame.

Events

'model-change'

Fires when a model is going to load.

'model-loaded'

Fires when all the geometry has been fully loaded.

'error'

Fires when there's a problem loading the model.

Running the Example

Install Node.js and NPM.

Run npm install.

Run npm run server.

Visit localhost:9080/example/ to view the page.