-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
42 lines (36 loc) · 1.01 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"flag"
"fmt"
"os"
"github.com/unixpickle/model3d/model2d"
"github.com/unixpickle/model3d/model3d"
)
func main() {
var smoothIters int
var mcDelta float64
var thickness float64
flag.IntVar(&smoothIters, "smooth-iters", 20, "2d mesh smoothing iterations")
flag.Float64Var(&mcDelta, "delta", 0.5, "marching cubes delta (pixels)")
flag.Float64Var(&thickness, "thickness", 10.0, "thickness of model (pixels)")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [flags] <input_image> <output.stl>\n", os.Args[0])
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, "Flags:")
fmt.Fprintln(os.Stderr)
flag.PrintDefaults()
fmt.Fprintln(os.Stderr)
}
flag.Parse()
if len(flag.Args()) != 2 {
flag.Usage()
os.Exit(1)
}
inFile, outFile := flag.Args()[0], flag.Args()[1]
mesh2d := model2d.MustReadBitmap(inFile, nil).FlipY().Mesh()
if smoothIters > 0 {
mesh2d = mesh2d.SmoothSq(smoothIters)
}
profile := model3d.ProfileMesh(mesh2d, 0, thickness)
profile.SaveGroupedSTL(outFile)
}