Array to Wavefront OBJ
npm install array-to-wavefront-obj
Examples
var toOBJ = ; var vertices = -10 -10 00 10 -10 00 00 10 00;var normals = 00 00 10 00 00 10 00 00 10;var textures = 00 00 10 00 05 10;var indices = 0 1 2; var objStr = ;console;
prints the string
# Created by array-to-wavefront-obj, a free and open source
# OBJ serializer for JavaScript
v -1 -1 0
v 1 -1 0
v 0 1 0
vn 0 0 1
vn 0 0 1
vn 0 0 1
vt 0 0
vt 1 0
vt 0.5 1
f 1/1/1 2/2/2 3/3/3
If the textures array is empty, then we would wind up with the string:
# Created by array-to-wavefront-obj, a free and open source
# OBJ serializer for JavaScript
v -1 -1 0
v 1 -1 0
v 0 1 0
vn 0 0 1
vn 0 0 1
vn 0 0 1
f 1//1 2//2 3//3
It is also possible to specify different indices for the normals and the textures:
var toOBJ = ; var vertices = -10 -10 00 10 -10 00 00 10 00;var normals = 00 00 10 ;var textures = 00 00 10 00 05 10;var vertexIndices = 0 1 2;var textureIndices = 0 1 2;var normalIndices = 0 0 0; // use the first normal for all the vertices var objStr = ;console;
prints the string
# Created by array-to-wavefront-obj, a free and open source
# OBJ serializer for JavaScript
v -1 -1 0
v 1 -1 0
v 0 1 0
vn 0 0 1
vt 0 0
vt 1 0
vt 0.5 1
f 1/1/1 2/2/1 3/3/1