-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
57 lines (50 loc) · 1.39 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"github.com/unixpickle/model3d/model2d"
"github.com/unixpickle/model3d/model3d"
"github.com/unixpickle/model3d/render3d"
)
const (
PrintSize = 4
PrintThickness = 0.3
TextThickness = 0.1
)
func main() {
img := model2d.MustReadBitmap("text.png", nil).FlipY()
bmpSolid := model2d.BitmapToSolid(img)
bmpSolid = model2d.ScaleSolid(bmpSolid, PrintSize/float64(img.Width))
fullSolid := model3d.JoinedSolid{
&TextSolid{
Text: bmpSolid,
},
HersheyKissSolid{Center: model3d.Coord3D{X: 0.8, Y: PrintSize - 0.9,
Z: PrintThickness}},
HersheyKissSolid{Center: model3d.Coord3D{X: PrintSize / 2, Y: PrintSize - 0.7,
Z: PrintThickness}},
HersheyKissSolid{Center: model3d.Coord3D{X: PrintSize - 0.8, Y: PrintSize - 0.9,
Z: PrintThickness}},
}
m := model3d.MarchingCubesSearch(fullSolid, 0.01, 8).Blur(-1, -1, -1, -1, -1)
m = m.FlattenBase(0)
m.SaveGroupedSTL("kiss.stl")
render3d.SaveRandomGrid("rendering.png", m, 3, 3, 300, nil)
}
type TextSolid struct {
Text model2d.Solid
}
func (t *TextSolid) Min() model3d.Coord3D {
return model3d.XYZ(0, 0, 0)
}
func (t *TextSolid) Max() model3d.Coord3D {
return model3d.XYZ(PrintSize, PrintSize, TextThickness+PrintThickness)
}
func (t *TextSolid) Contains(c model3d.Coord3D) bool {
if !model3d.InBounds(t, c) {
return false
}
if !t.Text.Contains(c.XY()) {
return c.Z < PrintThickness
} else {
return true
}
}