MCPcopy
hub / github.com/g3n/engine / loadTex

Method loadTex

loader/obj/obj.go:373–397  ·  view source on GitHub ↗

loadTex loads textures described in the material descriptor into the specified material

(mat *material.Material, desc *Material)

Source from the content-addressed store, hash-verified

371// loadTex loads textures described in the material descriptor into the
372// specified material
373func (dec *Decoder) loadTex(mat *material.Material, desc *Material) error {
374
375 // Checks if material descriptor specified texture
376 if desc.MapKd == "" {
377 return nil
378 }
379
380 // Get texture file path
381 // If texture file path is not absolute assumes it is relative
382 // to the directory of the material file
383 var texPath string
384 if filepath.IsAbs(desc.MapKd) {
385 texPath = desc.MapKd
386 } else {
387 texPath = filepath.Join(dec.mtlDir, desc.MapKd)
388 }
389
390 // Try to load texture from image file
391 tex, err := texture.NewTexture2DFromImage(texPath)
392 if err != nil {
393 return err
394 }
395 mat.AddTexture(tex)
396 return nil
397}
398
399// parse reads the lines from the specified reader and dispatch them
400// to the specified line parser.

Callers 1

NewMeshMethod · 0.95

Calls 2

NewTexture2DFromImageFunction · 0.92
AddTextureMethod · 0.80

Tested by

no test coverage detected