-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
97 lines (84 loc) · 2.1 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"os"
"github.com/unixpickle/model3d/toolbox3d"
"github.com/unixpickle/model3d/model3d"
"github.com/unixpickle/model3d/render3d"
)
func main() {
var args Args
args.Add()
flag.Parse()
template, ok := FixedTemplates()[args.FixedTemplate]
if !ok {
fmt.Fprintln(os.Stderr, "unknown fixed template: "+args.FixedTemplate)
flag.Usage()
os.Exit(1)
}
log.Println("Searching for digit placements...")
placements := SearchPlacement(template, AllDigits(), 5)
if placements == nil {
panic("no way to place digits")
}
log.Println("Creating board...")
boardSolid := BoardSolid(&args, placements, 5)
board := model3d.MarchingCubesSearch(boardSolid, 0.01, 8)
board = board.EliminateCoplanar(1e-5)
board.SaveGroupedSTL("board.stl")
saveMesh := model3d.NewMesh()
renderModel := render3d.JoinedObject{render3d.Objectify(board, nil)}
for i, d := range placements {
log.Println("Creating digit", i+1, "...")
solid := DigitSolid(&args, d)
ax := &toolbox3d.AxisSqueeze{
Axis: toolbox3d.AxisY,
Min: 0.02,
Max: args.SegmentDepth - 0.02,
Ratio: 0.25,
}
mesh := model3d.MarchingCubesConj(solid, 0.01, 8, ax)
mesh = mesh.EliminateCoplanar(1e-5)
saveMesh.AddMesh(mesh)
color := render3d.NewColorRGB(rand.Float64(), rand.Float64(), rand.Float64())
object := render3d.Objectify(mesh,
func(c model3d.Coord3D, rc model3d.RayCollision) render3d.Color {
return color
})
renderModel = append(renderModel, object)
}
render3d.SaveRendering("rendering.png", renderModel, model3d.XYZ(2.5, -3, 6),
500, 500, nil)
saveMesh.SaveGroupedSTL("digits.stl")
}
func FixedDigits() []Digit {
// If you want to generate an arbitrary board, return nil.
// Fill in three squares along the diagonal.
// This makes the puzzle fairly difficult to solve.
return []Digit{
NewDigitContinuous([]Location{
{2, 2},
{2, 3},
{3, 3},
{3, 2},
{2, 2},
}),
NewDigitContinuous([]Location{
{0, 0},
{0, 1},
{1, 1},
{1, 0},
{0, 0},
}),
NewDigitContinuous([]Location{
{4, 4},
{4, 5},
{5, 5},
{5, 4},
{4, 4},
}),
}
}