1.0.0 • Published 11 years ago
serialize-wavefront-obj v1.0.0
serialize-wavefront-obj
Wavefront OBJ serializer
Serializes a mesh to a Wavefront OBJ string.
Supports vertex normals and UV coordinates. Doesn't support material libraries, nor multiple meshes embedded in the same file.
Install
$ npm install serialize-wavefront-objExample
var serializeOBJ = require('serialize-wavefront-obj');
var mesh = {
positions: [
[-1.0, 0.0, 0.0],
[ 0.0, 1.0, 0.0],
[ 1.0, 0.0, 0.0]
],
cells: [
[0, 1, 2]
]
};
var str = serializeOBJ(mesh.cells, mesh.positions/*, vertexNormals */);
console.log(str);
/*
v -1 0 0
v 0 1 0
v 1 0 0
f 1// 2// 3//
*/Usage
serializeOBJ(cells, positions[, vertexNormals, vertexUVs, faceNormals, faceUVs, name])
cellsmesh cells / facespositionsmesh vertex positionsvertexNormalsoptional vertex normals.vertexUVsoptional vertex UV coordinates.faceNormalsoptional array formated likecellsthat indicates the normal indices. Defaults tocellsif falsy andvertexNormalsis provided.faceUVsoptional array formated likecellsthat indicates the UV indices. Defaults tocellsif falsy andvertexUVsis provided.nameoptional mesh name. If specified outputs ano nameline at the beginning of the file.
Argument position is mandatory. Provide falsy values for optional args you do not wish to use.
1.0.0
11 years ago