var testStl = function(file, compare, t) { file = path.join(stldir, file); var slicer = new MeshSlicePolygon(); fs.createReadStream(file) .pipe(stl.createParseStream()) .on('data', function(obj) { obj && obj.verts && slicer.addTriangle(obj.verts) }) .on('end', function() { var bounds = slicer.bounds t.equal(slicer.slice(bounds.max[2] + 0.1).length, 0) t.equal(slicer.slice(bounds.min[2] - 0.1).length, 0) for (var z = bounds.max[2]; z>bounds.min[2]+.1; z-=.1) { var res = slicer.slice(z); compare(res, z); } compare(slicer.slice(bounds.min[2]), bounds.min[2]); compare(slicer.slice(bounds.max[2]), bounds.max[2]); t.end(); }); };
#!/usr/bin/env node var stl = require('stl'); var argv = require('optimist').argv; var through = require('through2'); var path = require('path'); var fs = require('fs'); var parser = stl.createParseStream(); var source = process.stdin; if (argv._.length) { console.log(path.resolve(argv._[0])); source = require('fs').createReadStream( path.resolve(argv._[0]) ); } var first = true; source .pipe(parser) .pipe(through.obj(function(obj, enc, fn) { if (obj && obj.verts) { if (first) { this.push('['); first = false; } else { this.push(','); } // Flatten