kd-tree building - check all axes for best split, add additional shape-bbox check
extent Container bounds by Eps to fix invisible triangles on borders
new Camera constructor with more intuitive lookat/up vectors
fix camera axes (mirrored images)
better camera angle-of-view
change capitalization of addShape and addLight
#!/usr/bin/python# read nff data from standart input and render image to render_nff.png# see http://tog.acm.org/resources/SPD/# only spheres and triangles are implementedfrom raytracer import Raytracer, Camera, Light, Material, Sphere, NormalVertex, Trianglefrom math import piimport sys, Imagert = Raytracer()imagesize = (800, 600)mat = Material(colour=(1.0, 1.0, 1.0))f = sys.stdinwhile True: line = f.readline() if line == "": break; ln = line.split() if ln[0] == 'v': # Viewpoint location # from ln = f.readline().split() assert ln[0] == 'from' eye = (float(ln[1]), float(ln[2]), float(ln[3])) # at ln = f.readline().split() assert ln[0] == 'at' lookat = (float(ln[1]), float(ln[2]), float(ln[3])) # up ln = f.readline().split() assert ln[0] == 'up' up = (float(ln[1]), float(ln[2]), float(ln[3])) # angle ln = f.readline().split() assert ln[0] == 'angle' angle = float(ln[1]) # hither ln = f.readline().split() assert ln[0] == 'hither' hither = float(ln[1]) # resolution ln = f.readline().split() assert ln[0] == 'resolution' imagesize = (int(ln[1]), int(ln[2])) # set camera as specified cam = Camera(eye=eye, lookat=lookat, up=up) cam.setAngle(angle/180*pi) rt.setcamera(cam) elif ln[0] == 'b': # Background color rt.setbgcolour((float(ln[1]), float(ln[2]), float(ln[3]))) elif ln[0] == 'l': # Light pos = (float(ln[1]), float(ln[2]), float(ln[3])) rt.addlight(Light(position=pos)) elif ln[0] == 'f': # Fill color and shading parameters colour = (float(ln[1]), float(ln[2]), float(ln[3])) mat = Material(colour=colour) mat.setPhong(0,float(ln[4]),float(ln[5]),float(ln[6])) mat.setTransmissivity(float(ln[7]),float(ln[8])) elif ln[0] == 's': # Sphere center = (float(ln[1]), float(ln[2]), float(ln[3])) radius = float(ln[4]) rt.addshape(Sphere(centre=center, radius=radius, material=mat)) elif ln[0] == 'p': # Polygon vertex_count = int(ln[1]) vertices = [] for i in range(vertex_count): ln = f.readline().split() vertex = (float(ln[0]), float(ln[1]), float(ln[2])) vertices.append(NormalVertex(vertex)) rt.addshape(Triangle(vertices[0], vertices[1], vertices[2], mat)) for i in range(vertex_count)[3:]: rt.addshape(Triangle(vertices[0], vertices[i-1], vertices[i], mat)) else: print "Not implemented:", linef.close()data = rt.render(imagesize)img = Image.fromstring("RGB", imagesize, data)img.save('render_nff.png')