New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

wavefront-obj-parser

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wavefront-obj-parser

Parse wavefront .obj files into json

latest
Source
npmnpm
Version
2.0.1
Version published
Weekly downloads
29
26.09%
Maintainers
2
Weekly downloads
 
Created
Source

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

Keywords

wavefront

FAQs

Package last updated on 15 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts