diff --git a/d3/model/basemodel.py b/d3/model/basemodel.py index cd0cc3e..ef0ee46 100644 --- a/d3/model/basemodel.py +++ b/d3/model/basemodel.py @@ -218,6 +218,8 @@ class ModelParser: for face in part.faces: v1 = Vertex.from_points(self.vertices[face.a.vertex], self.vertices[face.b.vertex]) v2 = Vertex.from_points(self.vertices[face.a.vertex], self.vertices[face.c.vertex]) + v1.normalize() + v2.normalize() cross = Vertex.cross_product(v1, v2) self.normals[face.a.vertex] += cross self.normals[face.b.vertex] += cross diff --git a/d3/model/formats/ply.py b/d3/model/formats/ply.py index c9c8cee..84dac30 100644 --- a/d3/model/formats/ply.py +++ b/d3/model/formats/ply.py @@ -189,6 +189,9 @@ class PLY_ASCII_ContentParser: def parse_line(self, string): + if string == '': + return + if self.current_element is None: self.current_element = self.parent.elements[0] diff --git a/viewer.py b/viewer.py index e245ba8..e4f7025 100755 --- a/viewer.py +++ b/viewer.py @@ -72,8 +72,22 @@ def main(args): # Load and parse the model log('Loading model...', file=sys.stderr, end='') + sys.stderr.flush() model = load_model(args.input, up_conversion) - log(' done! (' + str(sum(map(lambda x: len(x.faces), model.parts))) + ' faces)\nInitialiazing OpenGL Context', file=sys.stderr, end='') + + # Compute normals if not already computed + if len(model.normals) == 0: + log(' done! (' + str(sum(map(lambda x: len(x.faces), model.parts))) + ' faces)\nComputing normals...', file=sys.stderr, end='') + sys.stderr.flush() + model.generate_vertex_normals() + + # Generate vbos for smooth rendering + log(' done!\nGenerating vbos...', file=sys.stderr, end='') + sys.stderr.flush() + model.generate_vbos() + + log(' done!\nInitialiazing OpenGL Context', file=sys.stderr, end='') + sys.stderr.flush() camera = Camera(Vector(0,0,5), Vector(0,0,0)) controls = OrbitControls() @@ -100,21 +114,14 @@ def main(args): log(' done!\nInitializing OpenGL textures...', file=sys.stderr, end='') + sys.stderr.flush() # Initializes OpenGL textures model.init_textures() - # Compute normals if not already computed - if len(model.normals) == 0: - log(' done!\nComputing normals...', file=sys.stderr, end='') - model.generate_vertex_normals() - - # Generate vbos for smooth rendering - log(' done!\nGenerating vbos...', file=sys.stderr, end='') - model.generate_vbos() - shader = Shader() - log(' Done!\nReady!', file=sys.stderr) + log(' done!\nReady!', file=sys.stderr) + sys.stderr.flush() while running: for event in pg.event.get():