NewMaterial creates and returns a pointer to a new material from the specified material id/url in the dom
(id string)
| 37 | // NewMaterial creates and returns a pointer to a new material |
| 38 | // from the specified material id/url in the dom |
| 39 | func (d *Decoder) NewMaterial(id string) (material.IMaterial, error) { |
| 40 | |
| 41 | id = strings.TrimPrefix(id, "#") |
| 42 | // Looks for material with specified id |
| 43 | mat := findMaterial(&d.dom, id) |
| 44 | if mat == nil { |
| 45 | return nil, fmt.Errorf("Material id:%s not found", id) |
| 46 | } |
| 47 | |
| 48 | // Looks for associated effect |
| 49 | effect := findEffect(&d.dom, mat.InstanceEffect.Url) |
| 50 | if effect == nil { |
| 51 | return nil, fmt.Errorf("Effect id:%s not found", mat.InstanceEffect.Url) |
| 52 | } |
| 53 | |
| 54 | // Looks for ProfileCOMMON |
| 55 | pc := findProfileCOMMON(effect) |
| 56 | if pc == nil { |
| 57 | return nil, fmt.Errorf("ProfileCOMMON not found") |
| 58 | } |
| 59 | |
| 60 | switch se := pc.Technique.ShaderElement.(type) { |
| 61 | case *Blinn: |
| 62 | return d.newBlinnMaterial(se) |
| 63 | case *Constant: |
| 64 | return d.newConstantMaterial(se) |
| 65 | case *Lambert: |
| 66 | return d.newLambertMaterial(se) |
| 67 | case *Phong: |
| 68 | return d.newPhongMaterial(se) |
| 69 | default: |
| 70 | return nil, fmt.Errorf("Invalid shader element") |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // GetTexture2D returns a pointer to an instance of the Texture2D |
| 75 | // with the specified id in the Collada document and an error. |
no test coverage detected