Skip to content

Commit 2b4ba90

Browse files
committed
meshmontage (wip)
1 parent 5ab0897 commit 2b4ba90

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

cmd/meshmontage/main.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"math"
7+
8+
. "github.com/fogleman/fauxgl"
9+
kingpin "gopkg.in/alecthomas/kingpin.v2"
10+
)
11+
12+
var (
13+
// scale = kingpin.Flag("scale", "Scale factor.").Short('s').Required().Float64()
14+
axisX = kingpin.Flag("x", "Use X axis.").Short('x').Bool()
15+
axisY = kingpin.Flag("y", "Use Y axis.").Short('y').Bool()
16+
axisZ = kingpin.Flag("z", "Use Z axis.").Short('z').Bool()
17+
rows = kingpin.Flag("rows", "Number of rows.").Short('r').Int()
18+
output = kingpin.Flag("output", "Output STL file.").Short('o').Required().String()
19+
files = kingpin.Arg("files", "Models to process.").Required().ExistingFiles()
20+
)
21+
22+
func main() {
23+
kingpin.Parse()
24+
25+
var meshes []*Mesh
26+
27+
for _, filename := range *files {
28+
fmt.Println(filename)
29+
30+
mesh, err := LoadMesh(filename)
31+
if err != nil {
32+
log.Fatal(err)
33+
}
34+
35+
meshes = append(meshes, mesh)
36+
37+
// mesh.Transform(Scale(V(*scale, *scale, *scale)))
38+
39+
// dir, file := filepath.Split(filename)
40+
// name := strings.TrimSuffix(file, filepath.Ext(file))
41+
// name = *prefix + name + *suffix + ".stl"
42+
43+
// if *output != "" {
44+
// dir = *output
45+
// }
46+
47+
// outputFilename := filepath.Join(dir, name)
48+
// fmt.Printf(" => %s\n", outputFilename)
49+
// if err := mesh.SaveSTL(outputFilename); err != nil {
50+
// log.Fatal(err)
51+
// }
52+
}
53+
54+
maxSize := meshes[0].BoundingBox().Size()
55+
for _, mesh := range meshes {
56+
maxSize = maxSize.Max(mesh.BoundingBox().Size())
57+
}
58+
maxSize = maxSize.MulScalar(1.05)
59+
60+
n := len(meshes)
61+
numRows := int(math.Ceil(math.Sqrt(float64(n))))
62+
if *rows > 0 {
63+
numRows = *rows
64+
}
65+
66+
combined := NewTriangleMesh(nil)
67+
for i, mesh := range meshes {
68+
row := i / numRows
69+
col := i % numRows
70+
var x, y, z float64
71+
if *axisX {
72+
y = float64(row) * maxSize.Y
73+
z = float64(col) * maxSize.Z
74+
} else if *axisY {
75+
x = float64(row) * maxSize.X
76+
z = float64(col) * maxSize.Z
77+
} else {
78+
x = float64(row) * maxSize.X
79+
y = float64(col) * maxSize.Y
80+
}
81+
mesh.MoveTo(V(x, y, z), V(0.5, 0.5, 0.5))
82+
combined.Add(mesh)
83+
}
84+
85+
combined.SaveSTL(*output)
86+
}

0 commit comments

Comments
 (0)