Last active
November 17, 2021 17:32
-
-
Save paulkaplan/ab11c0c267e771d0d670 to your computer and use it in GitHub Desktop.
Revisions
-
paulkaplan renamed this gist
Oct 26, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
paulkaplan created this gist
Oct 26, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ // Written by Paul Kaplan var AsciiStlWriter = (function() { // ASCI STL files function stringifyVector(vec){ return ""+vec.x+" "+vec.y+" "+vec.z; } function stringifyVertex(vec){ return "vertex "+stringifyVector(vec)+" \n"; } function geometryToStlString(geom){ var vertices = geom.vertices; var tris = geom.faces; var stl = "solid pixel"; for(var i = 0; i<tris.length; i++){ stl += ("facet normal "+stringifyVector( tris[i].normal )+" \n"); stl += ("outer loop \n"); stl += stringifyVertex(vertices[tris[i].a]); stl += stringifyVertex(vertices[tris[i].b]); stl += stringifyVertex(vertices[tris[i].c]); stl += ("endloop \n"); stl += ("endfacet \n"); } stl += ("endsolid"); return stl } var save = function(geometry, filename) { var stlString = geometryToStlString(geometry); var blob = new Blob([stlString], {type: 'text/plain'}); saveAs(blob, filename); } that.save = save; return that; }());