Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thibauts/serialize-wavefront-obj
Wavefront OBJ serializer
https://github.com/thibauts/serialize-wavefront-obj
Last synced: 2 months ago
JSON representation
Wavefront OBJ serializer
- Host: GitHub
- URL: https://github.com/thibauts/serialize-wavefront-obj
- Owner: thibauts
- License: mit
- Created: 2015-05-10T13:00:33.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-05-10T13:00:55.000Z (over 9 years ago)
- Last Synced: 2024-09-13T14:14:39.513Z (3 months ago)
- Language: JavaScript
- Size: 97.7 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
serialize-wavefront-obj
=======================
### Wavefront OBJ serializerSerializes a mesh to a [Wavefront OBJ](http://en.wikipedia.org/wiki/Wavefront_.obj_file) string.
Supports vertex normals and UV coordinates. Doesn't support material libraries, nor multiple meshes embedded in the same file.
Install
-------```bash
$ npm install serialize-wavefront-obj
```Example
-------```javascript
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])`
* `cells` mesh cells / faces
* `positions` mesh vertex positions
* `vertexNormals` optional vertex normals.
* `vertexUVs` optional vertex UV coordinates.
* `faceNormals` optional array formated like `cells` that indicates the normal indices. Defaults to `cells` if falsy and `vertexNormals` is provided.
* `faceUVs` optional array formated like `cells` that indicates the UV indices. Defaults to `cells` if falsy and `vertexUVs` is provided.
* `name` optional mesh name. If specified outputs an `o name` line at the beginning of the file.Argument position is mandatory. Provide falsy values for optional args you do not wish to use.