Skip to content

Commit 8096d33

Browse files
committed
Code review #1
1 parent 51a5d13 commit 8096d33

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

pywavefront/material.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ def __init__(self, name, is_default=False):
5454
self.emissive = [0., 0., 0., 1.]
5555
self.transparency = 1.0
5656
self.shininess = 0.
57+
self.optical_density = 1.0
58+
# Multiple illumination models are available, per material. These are enumerated as follows:
59+
# 0. Color on and Ambient off
60+
# 1. Color on and Ambient on
61+
# 2. Highlight on
62+
# 3. Reflection on and Ray trace on
63+
# 4. Transparency: Glass on, Reflection: Ray trace on
64+
# 5. Reflection: Fresnel on and Ray trace on
65+
# 6. Transparency: Refraction on, Reflection: Fresnel off and Ray trace on
66+
# 7. Transparency: Refraction on, Reflection: Fresnel on and Ray trace on
67+
# 8. Reflection on and Ray trace off
68+
# 9. Transparency: Glass on, Reflection: Ray trace off
69+
# 10. Casts shadows onto invisible surfaces
70+
self.illumination_model = 0
71+
5772
self.texture = None # diffuse
5873
self.texture_ambient = None
5974
self.texture_specular_color = None
@@ -217,7 +232,7 @@ def parse_map_Ns(self):
217232

218233
@auto_consume
219234
def parse_map_d(self):
220-
"""Aplha map"""
235+
"""Alpha map"""
221236
Kd = os.path.join(self.dir, " ".join(self.values[1:]))
222237
self.this_material.set_texture_alpha(Kd)
223238

@@ -232,8 +247,8 @@ def parse_bump(self):
232247

233248
@auto_consume
234249
def parse_Ni(self):
235-
pass
250+
self.this_material.optical_density = float(self.values[1])
236251

237252
@auto_consume
238253
def parse_illum(self):
239-
pass
254+
self.this_material.illumination_model = float(self.values[1])

test/simple_parsetest.mtl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Kd 0.1 0.1 0.1
66
Ks 0.2 0.2 0.2
77
d 1.0
88
Tr 0.0
9+
illum 2
10+
Ni 0.75
911
map_Kd kd.png
1012
map_Ka ka.png
1113
map_Ks ks.png

test/test_material.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ def setUp(self):
1717

1818
def testSetTexture(self):
1919
"""Running set_texture should set a texture."""
20-
self.assertEqual(self.material.texture.__class__, pywavefront.texture.Texture)
21-
self.assertEqual(self.material.texture_ambient.__class__, pywavefront.texture.Texture)
20+
self.assertEqual(self.material.texture.__class__,
21+
pywavefront.texture.Texture)
22+
self.assertEqual(self.material.texture_ambient.__class__,
23+
pywavefront.texture.Texture)
2224

2325
self.assertEqual(self.material.texture.path, prepend_dir('4x4.png'))
2426
self.assertEqual(self.material.texture_ambient.path, prepend_dir('4x4.png'))

test/test_parser.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ def setUp(self):
158158

159159
def testMtlName(self):
160160
"""Parsing an obj file with known material names should set those names."""
161-
print(self.materials)
162161
self.assertIn('Material.simple', self.materials.keys())
163162
self.assertIn('Material2.simple', self.materials.keys())
164163

@@ -184,6 +183,12 @@ def testMtlSpecular(self):
184183
def testMtlTransparency(self):
185184
self.assertEqual(self.material1.transparency, 1.0)
186185

186+
def testMtlIllum(self):
187+
self.assertEqual(self.material1.illumination_model, 2)
188+
189+
def testMtlNi(self):
190+
self.assertEqual(self.material1.optical_density, 0.75)
191+
187192
def testTextures(self):
188193
self.assertEqual(self.material1.texture.path, prepend_dir('kd.png'))
189194
self.assertEqual(self.material1.texture_ambient.path, prepend_dir('ka.png'))

0 commit comments

Comments
 (0)