MCPcopy Index your code
hub / github.com/fogleman/ln / LoadBinarySTL

Function LoadBinarySTL

ln/stl.go:21–47  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

19}
20
21func LoadBinarySTL(path string) (*Mesh, error) {
22 fmt.Printf("Loading STL (Binary): %s\n", path)
23 file, err := os.Open(path)
24 if err != nil {
25 return nil, err
26 }
27 defer file.Close()
28 header := STLHeader{}
29 if err := binary.Read(file, binary.LittleEndian, &header); err != nil {
30 return nil, err
31 }
32 count := int(header.Count)
33 triangles := make([]*Triangle, count)
34 for i := 0; i < count; i++ {
35 d := STLTriangle{}
36 if err := binary.Read(file, binary.LittleEndian, &d); err != nil {
37 return nil, err
38 }
39 t := Triangle{}
40 t.V1 = Vector{float64(d.V1[0]), float64(d.V1[1]), float64(d.V1[2])}
41 t.V2 = Vector{float64(d.V2[0]), float64(d.V2[1]), float64(d.V2[2])}
42 t.V3 = Vector{float64(d.V3[0]), float64(d.V3[1]), float64(d.V3[2])}
43 t.UpdateBoundingBox()
44 triangles[i] = &t
45 }
46 return NewMesh(triangles), nil
47}
48
49func SaveBinarySTL(path string, mesh *Mesh) error {
50 file, err := os.Create(path)

Callers

nothing calls this directly

Calls 2

UpdateBoundingBoxMethod · 0.95
NewMeshFunction · 0.85

Tested by

no test coverage detected