stl-parser
Basic STL parser for binary and ASCII flavors.
go get -v github.com/vandluke/stl-parser/stl
Example Code
func main() {
logPath := "stl-parser.log"
os.Remove(logPath)
file, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("ERROR: %v", err)
}
defer file.Close()
log.SetFlags(log.LstdFlags | log.Lshortfile)
log.SetOutput(file)
stlBinaryPath := "in/test_binary.stl"
stlAsciiPath := "in/test_ascii.stl"
binarySTLFile, err := stl.OpenSTL(stlBinaryPath)
if err != nil {
log.Fatalf("ERROR: %v", err)
}
asciiSTLFile, err := stl.OpenSTL(stlAsciiPath)
if err != nil {
log.Fatalf("ERROR: %v", err)
}
err = binarySTLFile.ReadSTL()
if err != nil {
log.Fatalf("ERROR: %v", err)
}
err = asciiSTLFile.ReadSTL()
if err != nil {
log.Fatalf("ERROR: %v", err)
}
err = stl.WriteSTL("out/new_test_binary.stl", stl.STL_BINARY, &binarySTLFile.Data)
if err != nil {
log.Fatalf("ERROR: %v", err)
}
err = stl.WriteSTL("out/new_test_ascii.stl", stl.STL_ASCII, &asciiSTLFile.Data)
if err != nil {
log.Fatalf("ERROR: %v", err)
}
binarySTLFile.Close()
asciiSTLFile.Close()
}
Structure for STL file from source code
type STLFile struct {
Flavor int
File *os.File
Data STLData
}
type STLData struct {
NumberOfTriangles int
Triangles [][4][3]float32
}