Completed
Push — master ( f83d10...621f37 )
by
unknown
57s
created

ed2d.Material.__init__()   B

Complexity

Conditions 1

Size

Total Lines 27

Duplication

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