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

wavefront-obj-parser

v2.0.1

Published

Parse wavefront .obj files into json

Downloads

888

Readme

wavefront-obj-parser npm version Build Status

An api and cli for parsing wavefront .obj files into JSON

View live demo

View demo source

To Install

$ npm install --save wavefront-obj-parser

Running the demo locally

# Changes to the `src` and `demo` directories will live reload in your browser
$ npm run demo

CLI

The CLI will output stringified JSON to stdout

# parse from stdin
cat my-3d-model.obj | obj2json > my-3d-model.json

# parse from file
obj2json my-3d-model.obj > my-3d-model.json

API

var parseWFObj = require('wavefront-obj-parser')
var wavefrontString = fs.readFileSync('./my-3d-model.obj').toString('utf8')
var parsedJSON = parseWFObj(wavefrontString)

parseWFObj(wavefrontString) -> object

wavefrontString

Required

Type: string

A wavefront .obj in string format

Returned Object

The returned JSON object has the following one dimensional array properties:

var returnedObject = {
  // Parsed from `vn` lines
  vertexNormals: [...],
  // Parsed from `vt` lines
  vertexUVs: [...],
  // Parsed from `v` lines
  vertexPositions: [...],
  // These come from the `f` face lines
  vertexNormalIndices: [...],
  vertexUVIndices: [...],
  vertexPositionIndices: [...]
}

If you plan to use normals or UVs you'll want to run the data through something like expand-vertex-data.

This unwraps your data from being indexed across multiple properties (vertices, normals, uvs) to only being indexed based on vertices. You can only have one ELEMENT_ARRAY_BUFFER in WebGL so you can't make use of multiple indices.

TODO:

  • Handle files with missing values (i.e. no textures and normals)
  • If memory ever becomes an issue, allow line by line parsing by reading stream chunks and checking for \n

See Also

License

MIT