This file contains 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 characters
var extrude = require('extrude-by-path') | |
var matScale = require('gl-mat4/scale') | |
var toStl = require('serialize-stl') | |
function createCirclePath (r, fn) { | |
var circle = [] | |
for (var i = 0; i <= fn; i++) { | |
var theta = Math.PI*2/fn*i | |
circle.push([r * Math.cos(theta), r * Math.sin(theta), 0, theta + 0.15]) | |
} | |
return circle | |
} | |
function createFunnel (opts) { | |
opts = opts || {} | |
var fn = opts.resolution || 40 | |
var bh = opts.bellHeight || 6 | |
var slope = opts.slope || 0.7 | |
var sl = opts.spoutLength || 2 | |
var r = opts.radius || 5.5 | |
var t = opts.thickness || 0.3 | |
return extrude({ | |
positions: [ | |
[0,0],[-slope*bh,bh],[-slope*bh,bh+sl], | |
[-slope*bh-t,bh+sl],[-slope*bh-t,bh-t],[-t,0] | |
], | |
edges: [[0,1],[1,2],[2,3],[3,4],[4,5],[5,0]], | |
path: createCirclePath(r, fn), | |
closed: true, | |
caps: false | |
}) | |
} | |
function scale (mesh, vec) { | |
for (let vert of mesh.positions) { | |
matScale(vert, vert, vec) | |
} | |
return mesh | |
} | |
var mesh = createFunnel() | |
scale(mesh, [ 5, 5, 5 ]) | |
var stl = toStl(mesh.cells, mesh.positions) | |
process.stdout.write(stl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment