UNPKG

stl-exporter

Version:

Convert face-vertex, or polygon meshes to ascii and binary STLs

19 lines (17 loc) 1.06 kB
// Generated by CoffeeScript 1.12.7 (function() { module.exports = function(vertexCoordinates, faceVertexIndices, faceNormalCoordinates) { var i, j, ref, stl, stringifyFaceNormal, stringifyVector; stl = ''; stringifyFaceNormal = function(index) { return faceNormalCoordinates[index] + ' ' + faceNormalCoordinates[index + 1] + ' ' + faceNormalCoordinates[index + 2]; }; stringifyVector = function(index) { return vertexCoordinates[index * 3] + ' ' + vertexCoordinates[(index * 3) + 1] + ' ' + vertexCoordinates[(index * 3) + 2]; }; for (i = j = 0, ref = faceVertexIndices.length; j < ref; i = j += 3) { stl += '\t' + ("facet normal " + (stringifyFaceNormal(i)) + "\n") + '\t\t' + 'outer loop\n' + '\t\t\t' + ("vertex " + (stringifyVector(faceVertexIndices[i])) + "\n") + '\t\t\t' + ("vertex " + (stringifyVector(faceVertexIndices[i + 1])) + "\n") + '\t\t\t' + ("vertex " + (stringifyVector(faceVertexIndices[i + 2])) + "\n") + '\t\t' + 'endloop\n' + '\t' + 'endfacet\n'; } return stl; }; }).call(this);