Skip to content

Commit

Permalink
bufio.Writer for stl
Browse files Browse the repository at this point in the history
  • Loading branch information
fogleman committed Mar 15, 2017
1 parent f26bc6b commit d08ac98
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions stl.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ func SaveSTL(path string, mesh *Mesh) error {
return err
}
defer file.Close()
w := bufio.NewWriter(file)
header := STLHeader{}
header.Count = uint32(len(mesh.Triangles))
if err := binary.Write(file, binary.LittleEndian, &header); err != nil {
if err := binary.Write(w, binary.LittleEndian, &header); err != nil {
return err
}
for _, triangle := range mesh.Triangles {
Expand All @@ -124,9 +125,10 @@ func SaveSTL(path string, mesh *Mesh) error {
d.V3[0] = float32(triangle.V3.Position.X)
d.V3[1] = float32(triangle.V3.Position.Y)
d.V3[2] = float32(triangle.V3.Position.Z)
if err := binary.Write(file, binary.LittleEndian, &d); err != nil {
if err := binary.Write(w, binary.LittleEndian, &d); err != nil {
return err
}
}
w.Flush()
return nil
}

0 comments on commit d08ac98

Please sign in to comment.