@@ -56,28 +56,28 @@ def same(v):
56
56
}
57
57
58
58
59
- def draw (instance ):
59
+ def draw (instance , lighting_enabled = True , textures_enabled = True ):
60
60
"""Generic draw function"""
61
61
# Draw Wavefront instance
62
62
if isinstance (instance , Wavefront ):
63
- draw_materials (instance .materials )
63
+ draw_materials (instance .materials , lighting_enabled = lighting_enabled , textures_enabled = textures_enabled )
64
64
# Draw single material
65
65
elif isinstance (instance , Material ):
66
- draw_material (instance )
66
+ draw_material (instance , lighting_enabled = lighting_enabled , textures_enabled = textures_enabled )
67
67
# Draw dict of materials
68
68
elif isinstance (instance , dict ):
69
- draw_materials (instance )
69
+ draw_materials (instance , lighting_enabled = lighting_enabled , textures_enabled = textures_enabled )
70
70
else :
71
71
raise ValueError ("Cannot figure out how to draw: {}" .format (instance ))
72
72
73
73
74
- def draw_materials (materials ):
74
+ def draw_materials (materials , lighting_enabled = True , textures_enabled = True ):
75
75
"""Draw a dict of meshes"""
76
76
for name , material in materials .items ():
77
- draw_material (material )
77
+ draw_material (material , lighting_enabled = lighting_enabled , textures_enabled = textures_enabled )
78
78
79
79
80
- def draw_material (material , face = GL_FRONT_AND_BACK ):
80
+ def draw_material (material , face = GL_FRONT_AND_BACK , lighting_enabled = True , textures_enabled = True ):
81
81
"""Draw a single material"""
82
82
if material .gl_floats is None :
83
83
material .gl_floats = (GLfloat * len (material .vertices ))(* material .vertices )
@@ -93,23 +93,27 @@ def draw_material(material, face=GL_FRONT_AND_BACK):
93
93
glEnable (GL_DEPTH_TEST )
94
94
glCullFace (GL_BACK )
95
95
96
- # Fall back to ambient texture if no diffuse
97
- texture = material .texture or material .texture_ambient
98
- if texture and material .has_uvs :
99
- bind_texture (texture )
100
- else :
101
- glDisable (GL_TEXTURE_2D )
102
-
103
- glMaterialfv (face , GL_DIFFUSE , gl_light (material .diffuse ))
104
- glMaterialfv (face , GL_AMBIENT , gl_light (material .ambient ))
105
- glMaterialfv (face , GL_SPECULAR , gl_light (material .specular ))
106
- glMaterialfv (face , GL_EMISSION , gl_light (material .emissive ))
107
- glMaterialf (face , GL_SHININESS , min (128.0 , material .shininess ))
108
- glEnable (GL_LIGHT0 )
109
-
110
- if material .has_normals :
111
- glEnable (GL_LIGHTING )
112
- else :
96
+ if textures_enabled :
97
+ # Fall back to ambient texture if no diffuse
98
+ texture = material .texture or material .texture_ambient
99
+ if texture and material .has_uvs :
100
+ bind_texture (texture )
101
+ else :
102
+ glDisable (GL_TEXTURE_2D )
103
+
104
+ if lighting_enabled :
105
+ glMaterialfv (face , GL_DIFFUSE , gl_light (material .diffuse ))
106
+ glMaterialfv (face , GL_AMBIENT , gl_light (material .ambient ))
107
+ glMaterialfv (face , GL_SPECULAR , gl_light (material .specular ))
108
+ glMaterialfv (face , GL_EMISSION , gl_light (material .emissive ))
109
+ glMaterialf (face , GL_SHININESS , min (128.0 , material .shininess ))
110
+ glEnable (GL_LIGHT0 )
111
+
112
+ if material .has_normals :
113
+ glEnable (GL_LIGHTING )
114
+ else :
115
+ glDisable (GL_LIGHTING )
116
+ else :
113
117
glDisable (GL_LIGHTING )
114
118
115
119
glInterleavedArrays (vertex_format , 0 , material .gl_floats )
0 commit comments