Changed operation order, normalise vectors before computing normals

This commit is contained in:
Thomas FORGIONE 2017-01-19 14:32:02 +01:00
parent 7720dcd6ba
commit 7836f327e0
No known key found for this signature in database
GPG Key ID: 2A210FFC062E00C3
3 changed files with 23 additions and 11 deletions

View File

@ -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

View File

@ -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]

View File

@ -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():