@@ -56,28 +56,28 @@ def same(v):
5656}
5757
5858
59- def draw (instance ):
59+ def draw (instance , lighting_enabled = True , textures_enabled = True ):
6060 """Generic draw function"""
6161 # Draw Wavefront instance
6262 if isinstance (instance , Wavefront ):
63- draw_materials (instance .materials )
63+ draw_materials (instance .materials , lighting_enabled = lighting_enabled , textures_enabled = textures_enabled )
6464 # Draw single material
6565 elif isinstance (instance , Material ):
66- draw_material (instance )
66+ draw_material (instance , lighting_enabled = lighting_enabled , textures_enabled = textures_enabled )
6767 # Draw dict of materials
6868 elif isinstance (instance , dict ):
69- draw_materials (instance )
69+ draw_materials (instance , lighting_enabled = lighting_enabled , textures_enabled = textures_enabled )
7070 else :
7171 raise ValueError ("Cannot figure out how to draw: {}" .format (instance ))
7272
7373
74- def draw_materials (materials ):
74+ def draw_materials (materials , lighting_enabled = True , textures_enabled = True ):
7575 """Draw a dict of meshes"""
7676 for name , material in materials .items ():
77- draw_material (material )
77+ draw_material (material , lighting_enabled = lighting_enabled , textures_enabled = textures_enabled )
7878
7979
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 ):
8181 """Draw a single material"""
8282 if material .gl_floats is None :
8383 material .gl_floats = (GLfloat * len (material .vertices ))(* material .vertices )
@@ -93,23 +93,27 @@ def draw_material(material, face=GL_FRONT_AND_BACK):
9393 glEnable (GL_DEPTH_TEST )
9494 glCullFace (GL_BACK )
9595
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 :
113117 glDisable (GL_LIGHTING )
114118
115119 glInterleavedArrays (vertex_format , 0 , material .gl_floats )
0 commit comments