Skip to content

Instantly share code, notes, and snippets.

@nicoptere
Created April 14, 2017 15:06
Show Gist options
  • Save nicoptere/687452d09448c51ddc56aa7caa427f69 to your computer and use it in GitHub Desktop.
Save nicoptere/687452d09448c51ddc56aa7caa427f69 to your computer and use it in GitHub Desktop.
converts a THREE.geometry to OBJ
var str = "# object mesh \n";
g.toIndexed();
var vs = g.getAttribute("position").array;
var ind = g.getIndex().array;
var precision = 6;
for( var i = 0 ; i < vs.length; i+=3 ){
str += "v " + vs[i].toFixed(precision) + " " + vs[i+1].toFixed(precision) + " " + vs[i+2].toFixed(precision)+ "\n";
}
str +="# " + (ind.length / 3 ) +" vertices";
str += "\n";
str += "g mesh";
for( i = 0 ; i < ind.length; i+=3 ){
str += "f " + ind[i] + " " + ind[ i + 2 ] + " " + ind[ i + 1 ]+ "\n";
}
str +="# " + (ind.length / 3 ) +" faces";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment