Skip to content

Commit

Permalink
Add meshscale
Browse files Browse the repository at this point in the history
  • Loading branch information
fogleman committed May 24, 2018
1 parent d606b59 commit d891179
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions cmd/meshscale/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"fmt"
"log"
"os"
"path/filepath"
"strings"

. "github.com/fogleman/fauxgl"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)

var (
scale = kingpin.Flag("scale", "Scale factor.").Short('s').Required().Float64()
prefix = kingpin.Flag("prefix", "Prefix to apply to each output filename.").Default("").String()
suffix = kingpin.Flag("suffix", "Suffix to apply to each output filename.").Default("").String()
output = kingpin.Flag("output", "Output directory.").Short('o').Default("").String()
files = kingpin.Arg("files", "Models to process.").Required().ExistingFiles()
)

func main() {
kingpin.Parse()

if *output != "" {
if err := os.MkdirAll(*output, 0755); err != nil {
log.Fatal(err)
}
}

for _, filename := range *files {
fmt.Println(filename)

mesh, err := LoadMesh(filename)
if err != nil {
log.Fatal(err)
}

mesh.Transform(Scale(V(*scale, *scale, *scale)))

dir, file := filepath.Split(filename)
name := strings.TrimSuffix(file, filepath.Ext(file))
name = *prefix + name + *suffix + ".stl"

if *output != "" {
dir = *output
}

outputFilename := filepath.Join(dir, name)
fmt.Printf(" => %s\n", outputFilename)
if err := mesh.SaveSTL(outputFilename); err != nil {
log.Fatal(err)
}
}
}

0 comments on commit d891179

Please sign in to comment.