(path string)
| 17 | } |
| 18 | |
| 19 | func LoadOBJ(path string) (*Mesh, error) { |
| 20 | file, err := os.Open(path) |
| 21 | if err != nil { |
| 22 | return nil, err |
| 23 | } |
| 24 | defer file.Close() |
| 25 | vs := make([]Vector, 1, 1024) // 1-based indexing |
| 26 | var triangles []*Triangle |
| 27 | scanner := bufio.NewScanner(file) |
| 28 | for scanner.Scan() { |
| 29 | line := scanner.Text() |
| 30 | fields := strings.Fields(line) |
| 31 | if len(fields) == 0 { |
| 32 | continue |
| 33 | } |
| 34 | keyword := fields[0] |
| 35 | args := fields[1:] |
| 36 | switch keyword { |
| 37 | case "v": |
| 38 | f := ParseFloats(args) |
| 39 | v := Vector{f[0], f[1], f[2]} |
| 40 | vs = append(vs, v) |
| 41 | case "f": |
| 42 | fvs := make([]int, len(args)) |
| 43 | for i, arg := range args { |
| 44 | vertex := strings.Split(arg+"//", "/") |
| 45 | fvs[i] = parseIndex(vertex[0], len(vs)) |
| 46 | } |
| 47 | for i := 1; i < len(fvs)-1; i++ { |
| 48 | i1, i2, i3 := 0, i, i+1 |
| 49 | t := NewTriangle(vs[fvs[i1]], vs[fvs[i2]], vs[fvs[i3]]) |
| 50 | triangles = append(triangles, t) |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | return NewMesh(triangles), scanner.Err() |
| 55 | } |
nothing calls this directly
no test coverage detected