From 2155e8df3b13b5612725d45c1c1724c802cdca02 Mon Sep 17 00:00:00 2001 From: Mathieu Lamarre Date: Mon, 22 Oct 2018 13:56:07 -0400 Subject: [PATCH 1/3] Fix IndexError in parse_vt --- pywavefront/obj.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pywavefront/obj.py b/pywavefront/obj.py index 3f4a0a8..594e39e 100644 --- a/pywavefront/obj.py +++ b/pywavefront/obj.py @@ -183,7 +183,7 @@ def parse_vt(self): # Since list() also consumes StopIteration we need to sanity check the line # to make sure the parser advances - if self.values[0] == "vt": + if self.values and self.values[0] == "vt": self.next_line() def consume_texture_coordinates(self): From d440b7d83f1fdc9440c218e44ca1f84a4403c111 Mon Sep 17 00:00:00 2001 From: Mathieu Lamarre Date: Mon, 22 Oct 2018 14:27:56 -0400 Subject: [PATCH 2/3] Fix other index error Happends for 0 vn or vt index --- pywavefront/obj.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pywavefront/obj.py b/pywavefront/obj.py index 594e39e..fd81ffb 100644 --- a/pywavefront/obj.py +++ b/pywavefront/obj.py @@ -396,8 +396,8 @@ def emit_vertex(vertex): idx = v_index, pos = self.wavefront.vertices[v_index][0:3] if has_colors else self.wavefront.vertices[v_index], color = self.wavefront.vertices[v_index][3:] if has_colors else (), - uv = self.tex_coords[t_index] if has_vt else (), - normal = self.normals[n_index] if has_vn else () + uv = self.tex_coords[t_index] if has_vt and t_index < len(self.tex_coords) else (), + normal = self.normals[n_index] if has_vn and n_index < len(self.normals) else () ) yield from emit_vertex(vcurrent) From e855c27f8bf2cc173353c8b6384d858f5136f801 Mon Sep 17 00:00:00 2001 From: Mathieu Lamarre Date: Wed, 31 Oct 2018 09:37:36 -0400 Subject: [PATCH 3/3] Add repro test cases --- test/simple_extra_empty_lines.obj | 35 +++++++++++++++++++++++++++++++ test/simple_zero_indices.obj | 26 +++++++++++++++++++++++ test/test_wavefront.py | 14 +++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 test/simple_extra_empty_lines.obj create mode 100644 test/simple_zero_indices.obj diff --git a/test/simple_extra_empty_lines.obj b/test/simple_extra_empty_lines.obj new file mode 100644 index 0000000..7a05579 --- /dev/null +++ b/test/simple_extra_empty_lines.obj @@ -0,0 +1,35 @@ +# Comment +mtllib simple.mtl +o Simple + +v 0.01 0.02 0.03 +v 0.04 0.05 0.06 +v 0.07 0.08 0.09 +v 0.11 0.12 0.13 + +vt 10 11 +vt 12 13 +vt 14 15 +vt 16 17 + +vn 20 21 22 + +usemtl Material.simple +f 2/3/1 1/2/1 3/1/1 +o SimpleB + +v 1.0 0.0 1.0 +v -1.0 0.0 1.0 +v 1.0 0.0 -1.0 +v -1.0 0.0 -1.0 + +vt 0.0 1.0 +vt 0.0 0.0 +vt 1.0 0.0 +vt 1.0 1.0 + +vn 0.0 1.0 -0.0 + +usemtl Material2.simple + +f 6/7/2 5/6/2 7/5/2 diff --git a/test/simple_zero_indices.obj b/test/simple_zero_indices.obj new file mode 100644 index 0000000..419598c --- /dev/null +++ b/test/simple_zero_indices.obj @@ -0,0 +1,26 @@ +# Comment +mtllib simple.mtl +o Simple +v 0.01 0.02 0.03 +v 0.04 0.05 0.06 +v 0.07 0.08 0.09 +v 0.11 0.12 0.13 +vt 10 11 +vt 12 13 +vt 14 15 +vt 16 17 +vn 20 21 22 +usemtl Material.simple +f 2/3/1 1/2/1 3/1/1 +o SimpleB +v 1.0 0.0 1.0 +v -1.0 0.0 1.0 +v 1.0 0.0 -1.0 +v -1.0 0.0 -1.0 +vt 0.0 1.0 +vt 0.0 0.0 +vt 1.0 0.0 +vt 1.0 1.0 +vn 0.0 1.0 -0.0 +usemtl Material2.simple +f 6/7/0 5/6/2 7/5/0 diff --git a/test/test_wavefront.py b/test/test_wavefront.py index e6a6337..feed6c9 100644 --- a/test/test_wavefront.py +++ b/test/test_wavefront.py @@ -70,3 +70,17 @@ def setUp(self): self.mesh_names = [None] self.material_names = ["default0"] self.meshes = pywavefront.Wavefront(prepend_dir('simple_no_object_no_mtl.obj')) + +class TestZeroFaceNormaIndex(TestWavefront): + def setUp(self): + # reset the obj file to new file with no mtl line + self.mesh_names = ['Simple', 'SimpleB'] + self.material_names = ['Material.simple', 'Material2.simple'] + self.meshes = pywavefront.Wavefront(prepend_dir('simple_zero_indices.obj')) + +class TestExtraSpace(TestWavefront): + def setUp(self): + # reset the obj file to new file with no mtl line + self.mesh_names = ['Simple', 'SimpleB'] + self.material_names = ['Material.simple', 'Material2.simple'] + self.meshes = pywavefront.Wavefront(prepend_dir('simple_extra_empty_lines.obj')) \ No newline at end of file