Completed
Push — master ( d4b024...323fb3 )
by
unknown
58s
created

ed2d.Material.addTextures()   C

Complexity

Conditions 8

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 8
dl 0
loc 16
rs 6.6666
1
# Cook-Torance for diffuseType and Blinn-Phong
2
# Figure out specular and frensel stuff
3
# Emission?
4
# Need to setup so it can send outputs to a shader
5
# Inputs need to be defined a lot better
6
from ed2d import texture
7
from ed2d import files
8
9
class Material(object):
10
    def __init__(self, program):
11
        self.diffuse = None
12
        self.idiffuse = 0 # Intensity parameter
13
14
        self.ambient = None
15
        self.iambient = 0 # Intensity parameter
16
17
        self.specular = None
18
        self.roughness = None
19
20
        # This is the diffuse textures
21
        self.albedoLayers = {}
22
23
        self.diffuseType = None
24
        self.specularType = None
25
26
        self.normalMap = None
27
        self.specularMap = None
28
        self.displacementMap = None
29
30
        # Assign the shader that will render the Material
31
        self.program = program
32
33
    def setDiffuseColor(self, r, g, b, intensity):
34
        ''' Sets the diffuse color of a material. '''
35
        self.diffuse = [r, g, b]
36
        self.idiffuse = intensity
37
38
    def setAmbientColor(self, r, g, b, intensity):
39
        ''' Sets the ambient color of a material. '''
40
        self.ambient = [r, g, b]
41
        self.iambient = intensity
42
43
    def setSpecularColor(self, r, g, b, roughness):
44
        ''' Sets the specular color and roughness of a material. '''
45
        self.specular = [r, g, b]
46
        self.roughness = roughness
47
48
    def setDiffuseType(self, shader):
49
        pass
50
51
    def setSpecularType(self, shader):
52
        pass
53
54
    def addTextures(self, textureDict):
55
        # Format is {A: [albedo0, albedo1, ...], N: [normal1, normal2, ...], S: [specular1, specular2, ...]}
56
        # This will replace the crap underneath this function
57
        for key, value in textureDict.iteritems():
58
            if key is 'A':
59
                for i in range(len(value)):
60
                    imagePath = files.resolve_path('data', 'images', value[i])
61
                    self.albedoLayers['Layer' + i] = texture.Texture(imagePath, self.program)
62
            if key is 'N':
63
                for i in range(len(value)):
64
                    imagePath = files.resolve_path('data', 'images', value[i])
65
                    self.normalMapLayers['Layer' + i] = texture.Texture(imagePath, self.program)
66
            if key is 'S':
67
                for i in range(len(value)):
68
                    imagePath = files.resolve_path('data', 'images', value[i])
69
                    self.specularMapLayers['Layer' + i] = texture.Texture(imagePath, self.program)
70