geom-parse-obj

stable

Parse Wavefront .obj geometry file.

Notes:

Usage

NPM

parseObj(str)

Parameters:
str - UTF8 encoded string with the contents of OBJ file

Returns:
geometry or [geometry, geometry, ...] (depending if groups are present inside the file)

geometry = {
  positions: [[x, y, z], [x, y, z], ...], // array of positions
  normals: [[x, y, z], [x, y, z], ...], // array of normals
  uvs: [[u, v], [u, v], ...], // array of tex coords
  cells: [[i, j, k], [i, j, k], ...] // array of triangles or polygons
}

Example

var parseObj = require('geom-parse-obj');
var fs = require('fs')
var objStr = fs.readFileSync(__dirname + '/geometry.obj', 'utf8')
var obj = parseObj(objStr)
console.log(obj.positions) // -> [[0, 0, 0], [1, 0, 1], ...]

See also

parse-obj by Mikola Lysenko

License

MIT, see LICENSE.md for details.