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

Method NewTexture2D

loader/collada/material.go:96–147  ·  view source on GitHub ↗

NewTexture2D creates and returns a pointer to a new Texture2D from the specified sampler2D id/url in the dom

(id string)

Source from the content-addressed store, hash-verified

94// NewTexture2D creates and returns a pointer to a new Texture2D
95// from the specified sampler2D id/url in the dom
96func (d *Decoder) NewTexture2D(id string) (*texture.Texture2D, error) {
97
98 // Find newparam in all effects profiles with the specified id
99 np := findNewparam(&d.dom, id)
100 if np == nil {
101 return nil, fmt.Errorf("Texture id:%s not found", id)
102 }
103
104 // Checks if parameter is a Sampler2D
105 sampler2D, ok := np.ParameterType.(*Sampler2D)
106 if !ok {
107 return nil, fmt.Errorf("Texture id:%s is not a sampler2D", id)
108 }
109
110 // Get the parameter for the Sampler2D source
111 np = findNewparam(&d.dom, sampler2D.Source)
112 if np == nil {
113 return nil, fmt.Errorf("Sampler2D source:%s not found", id)
114 }
115
116 // Checks if parameter is a surface
117 surface, ok := np.ParameterType.(*Surface)
118 if !ok {
119 return nil, fmt.Errorf("Sampler2D source:%s is not a Surface", id)
120 }
121
122 // Checks if surface Init is InitFrom
123 initFrom, ok := surface.Init.(InitFrom)
124 if !ok {
125 return nil, fmt.Errorf("Surface:%s init is not InitFrom", sampler2D.Source)
126 }
127
128 // Find image
129 img := findImage(&d.dom, initFrom.Uri)
130 if img == nil {
131 return nil, fmt.Errorf("Image:%s not found", initFrom.Uri)
132 }
133
134 // Get image init from
135 imgInitFrom, ok := img.ImageSource.(InitFrom)
136 if !ok {
137 return nil, fmt.Errorf("Image:%s source is not InitFrom", initFrom.Uri)
138 }
139
140 // Builds image file path and try to create texture
141 filepath := filepath.Join(d.dirImages, filepath.Base(imgInitFrom.Uri))
142 tex, err := texture.NewTexture2DFromImage(filepath)
143 if err != nil {
144 return nil, err
145 }
146 return tex, nil
147}
148
149func (d *Decoder) newBlinnMaterial(se *Blinn) (material.IMaterial, error) {
150

Callers 1

GetTexture2DMethod · 0.95

Calls 3

NewTexture2DFromImageFunction · 0.92
findNewparamFunction · 0.85
findImageFunction · 0.85

Tested by

no test coverage detected