Completed
Push — master ( c8908d...454eb4 )
by
unknown
07:14
created

ed2d.Material.addProgram()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 3
rs 10
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):
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.normalMapLayers = {}
27
        self.specularMapLayers = {}
28
        self.displacementMapLayers = {}
29
30
        # Assign the shader that will render the Material
31
        self.program = None
32
33
    def addProgram(self, program):
34
        ''' Adds a program to the Material class. '''
35
        self.program = program
36
37
    def setDiffuseColor(self, r, g, b, intensity):
38
        ''' Sets the diffuse color of a material. '''
39
        self.diffuse = [r, g, b]
40
        self.idiffuse = intensity
41
42
    def setAmbientColor(self, r, g, b, intensity):
43
        ''' Sets the ambient color of a material. '''
44
        self.ambient = [r, g, b]
45
        self.iambient = intensity
46
47
    def setSpecularColor(self, r, g, b, roughness):
48
        ''' Sets the specular color and roughness of a material. '''
49
        self.specular = [r, g, b]
50
        self.roughness = roughness
51
52
    # Leave these like this for now till I figure out the shaders
53
    def setDiffuseType(self, shader):
54
        pass
55
56
    def setSpecularType(self, shader):
57
        pass
58
59
    def addTextures(self, textureDict):
60
        ''' Will add textures to the Material. It takes a dictionary as param. '''
61
        # Format is {A: [albedo0, albedo1, ...], N: [normal1, normal2, ...], S: [specular1, specular2, ...]}
62
        # This will replace the crap underneath this function
63
        for key, value in textureDict.iteritems():
64
            if key is 'A':
65
                for i in range(len(value)):
66
                    imagePath = files.resolve_path('data', 'images', value[i])
67
                    self.albedoLayers['Layer' + i] = texture.Texture(imagePath, self.program)
68
            if key is 'N':
69
                for i in range(len(value)):
70
                    imagePath = files.resolve_path('data', 'images', value[i])
71
                    self.normalMapLayers['Layer' + i] = texture.Texture(imagePath, self.program)
72
            if key is 'S':
73
                for i in range(len(value)):
74
                    imagePath = files.resolve_path('data', 'images', value[i])
75
                    self.specularMapLayers['Layer' + i] = texture.Texture(imagePath, self.program)
76