-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaterial.py
66 lines (53 loc) · 2.25 KB
/
material.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# material definitions
from OpenGL.GL import *
from matrix import Vector4
from Select import SelectState
NEXT_MAT_COUNT = 0
COLORS = ( Vector4( 1.0, 0.1, 0.1, 1.0 ),
Vector4( 1.0, 0.5, 0.1, 1.0 ),
Vector4( 1.0, 1.0, 0.1, 1.0 ),
Vector4( 0.5, 1.0, 0.1, 1.0 ),
Vector4( 0.1, 1.0, 0.1, 1.0 ),
Vector4( 0.1, 1.0, 0.5, 1.0 ),
Vector4( 0.1, 1.0, 1.0, 1.0 ),
Vector4( 0.1, 0.5, 1.0, 1.0 ),
Vector4( 0.1, 0.1, 1.0, 1.0 ),
Vector4( 0.5, 0.1, 1.0, 1.0 ),
Vector4( 1.0, 0.1, 1.0, 1.0 ),
Vector4( 1.0, 0.1, 0.5, 1.0 ) )
def getNextMaterial():
'''Simple function for returning materials from a set'''
global NEXT_MAT_COUNT
mat = Material()
mat.diffuse = COLORS[ NEXT_MAT_COUNT % len( COLORS ) ]
NEXT_MAT_COUNT += 1
return mat
class Material:
SELECT_AMBIENT = Vector4( 0.95, 0.95, 0.95, 0.0 )
def __init__( self ):
'''Constructor.
Defaults to a white material with no ambient.
'''
self.diffuse = Vector4( 1.0, 1.0, 1.0, 1.0 )
self.ambient = Vector4( 0.0, 0.0, 0.0, 0.0 )
def setGLHidden( self, selectState ):
'''Sets the material's properites to an opengl context for hidden wireframe.
@param: selectState The selected state of the object this
material is applied to.
'''
if ( selectState == SelectState.DRAW ):
glColor3f( 1.0, 1.0, 1.0 )
elif ( selectState == SelectState.SELECT ):
glColor3f( 0.3, 1.0, 0.3 )
def setGLSolid( self, selectState ):
'''Sets this material's properties to an opengl context.
@param: selectState The selected state of the object this
material is applied to.
'''
if ( selectState == SelectState.DRAW ):
glMaterialfv( GL_FRONT, GL_DIFFUSE, self.diffuse.data )
glMaterialfv( GL_FRONT, GL_AMBIENT, self.ambient.data )
elif ( selectState == SelectState.SELECT ):
glMaterialfv( GL_FRONT, GL_DIFFUSE, self.SELECT_AMBIENT.data )
glMaterialfv( GL_FRONT, GL_AMBIENT, self.SELECT_AMBIENT.data )
setGL = setGLSolid