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.

Revisions

  1. nicoptere created this gist Apr 14, 2017.
    19 changes: 19 additions & 0 deletions toOBJ
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@


    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";