Skip to content

Instantly share code, notes, and snippets.

@mappum
Created October 13, 2016 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mappum/f8940d3fccd44ca047297881d5ad44ba to your computer and use it in GitHub Desktop.
Save mappum/f8940d3fccd44ca047297881d5ad44ba to your computer and use it in GitHub Desktop.
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