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

Function LoadSTL

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

Source from the content-addressed store, hash-verified

76}
77
78func LoadSTL(path string) (*Mesh, error) {
79 fmt.Printf("Loading STL (ASCII): %s\n", path)
80 file, err := os.Open(path)
81 if err != nil {
82 return nil, err
83 }
84 defer file.Close()
85 var vertexes []Vector
86 scanner := bufio.NewScanner(file)
87 for scanner.Scan() {
88 line := scanner.Text()
89 fields := strings.Fields(line)
90 if len(fields) == 4 && fields[0] == "vertex" {
91 f := ParseFloats(fields[1:])
92 v := Vector{f[0], f[1], f[2]}
93 vertexes = append(vertexes, v)
94 }
95 }
96 var triangles []*Triangle
97 for i := 0; i < len(vertexes); i += 3 {
98 t := Triangle{}
99 t.V1 = vertexes[i+0]
100 t.V2 = vertexes[i+1]
101 t.V3 = vertexes[i+2]
102 t.UpdateBoundingBox()
103 triangles = append(triangles, &t)
104 }
105 return NewMesh(triangles), scanner.Err()
106}

Callers

nothing calls this directly

Calls 3

UpdateBoundingBoxMethod · 0.95
ParseFloatsFunction · 0.85
NewMeshFunction · 0.85

Tested by

no test coverage detected