MCPcopy Index your code
hub / github.com/g3n/engine / Decode

Function Decode

loader/obj/obj.go:96–121  ·  view source on GitHub ↗

Decode decodes the specified obj and mtl files returning a decoder object and an error. Passing an empty string (or otherwise invalid path) to mtlpath will cause the decoder to check the 'mtllib' file in the OBJ if present, and fall back to a default material as a last resort.

(objpath string, mtlpath string)

Source from the content-addressed store, hash-verified

94// to mtlpath will cause the decoder to check the 'mtllib' file in the OBJ if
95// present, and fall back to a default material as a last resort.
96func Decode(objpath string, mtlpath string) (*Decoder, error) {
97
98 // Opens obj file
99 fobj, err := os.Open(objpath)
100 if err != nil {
101 return nil, err
102 }
103 defer fobj.Close()
104
105 // Opens mtl file
106 // if mtlpath=="", then os.Open() will produce an error,
107 // causing fmtl to be nil
108 fmtl, err := os.Open(mtlpath)
109 defer fmtl.Close() // will produce (ignored) err if fmtl==nil
110
111 // if fmtl==nil, the io.Reader in DecodeReader() will be (T=*os.File, V=nil)
112 // which is NOT equal to plain nil or (io.Reader, nil) but will produce
113 // the desired result of passing nil to DecodeReader() per it's func comment.
114 dec, err := DecodeReader(fobj, fmtl)
115 if err != nil {
116 return nil, err
117 }
118
119 dec.mtlDir = filepath.Dir(objpath)
120 return dec, nil
121}
122
123// DecodeReader decodes the specified obj and mtl readers returning a decoder
124// object and an error if a problem was encoutered while parsing the OBJ.

Callers

nothing calls this directly

Calls 2

DecodeReaderFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected