45 assert ln[0] == 'resolution' |
45 assert ln[0] == 'resolution' |
46 imagesize = (int(ln[1]), int(ln[2])) |
46 imagesize = (int(ln[1]), int(ln[2])) |
47 # set camera as specified |
47 # set camera as specified |
48 cam = Camera(eye=eye, lookat=lookat, up=up) |
48 cam = Camera(eye=eye, lookat=lookat, up=up) |
49 cam.setAngle(angle/180*pi) |
49 cam.setAngle(angle/180*pi) |
50 rt.setcamera(cam) |
50 rt.setCamera(cam) |
51 elif ln[0] == 'b': # Background color |
51 elif ln[0] == 'b': # Background color |
52 rt.setbgcolour((float(ln[1]), float(ln[2]), float(ln[3]))) |
52 rt.setBgColour((float(ln[1]), float(ln[2]), float(ln[3]))) |
53 elif ln[0] == 'l': # Light |
53 elif ln[0] == 'l': # Light |
54 pos = (float(ln[1]), float(ln[2]), float(ln[3])) |
54 pos = (float(ln[1]), float(ln[2]), float(ln[3])) |
55 rt.addlight(Light(position=pos)) |
55 rt.addLight(Light(position=pos)) |
56 elif ln[0] == 'f': # Fill color and shading parameters |
56 elif ln[0] == 'f': # Fill color and shading parameters |
57 colour = (float(ln[1]), float(ln[2]), float(ln[3])) |
57 colour = (float(ln[1]), float(ln[2]), float(ln[3])) |
58 mat = Material(colour=colour) |
58 mat = Material(colour=colour) |
59 mat.setPhong(0,float(ln[4]),float(ln[5]),float(ln[6])) |
59 mat.setPhong(0,float(ln[4]),float(ln[5]),float(ln[6])) |
60 mat.setTransmissivity(float(ln[7]),float(ln[8])) |
60 mat.setTransmissivity(float(ln[7]),float(ln[8])) |
61 elif ln[0] == 's': # Sphere |
61 elif ln[0] == 's': # Sphere |
62 center = (float(ln[1]), float(ln[2]), float(ln[3])) |
62 center = (float(ln[1]), float(ln[2]), float(ln[3])) |
63 radius = float(ln[4]) |
63 radius = float(ln[4]) |
64 rt.addshape(Sphere(centre=center, radius=radius, material=mat)) |
64 rt.addShape(Sphere(centre=center, radius=radius, material=mat)) |
65 elif ln[0] == 'p': # Polygon |
65 elif ln[0] == 'p': # Polygon |
66 vertex_count = int(ln[1]) |
66 vertex_count = int(ln[1]) |
67 vertices = [] |
67 vertices = [] |
68 for i in range(vertex_count): |
68 for i in range(vertex_count): |
69 ln = f.readline().split() |
69 ln = f.readline().split() |
70 vertex = (float(ln[0]), float(ln[1]), float(ln[2])) |
70 vertex = (float(ln[0]), float(ln[1]), float(ln[2])) |
71 vertices.append(NormalVertex(vertex)) |
71 vertices.append(NormalVertex(vertex)) |
72 rt.addshape(Triangle(vertices[0], vertices[1], vertices[2], mat)) |
72 rt.addShape(Triangle(vertices[0], vertices[1], vertices[2], mat)) |
73 for i in range(vertex_count)[3:]: |
73 for i in range(vertex_count)[3:]: |
74 rt.addshape(Triangle(vertices[0], vertices[i-1], vertices[i], mat)) |
74 rt.addShape(Triangle(vertices[0], vertices[i-1], vertices[i], mat)) |
75 elif ln[0] == 'pp': # Polygonal patch |
75 elif ln[0] == 'pp': # Polygonal patch |
76 mat.setSmooth(True) |
76 mat.setSmooth(True) |
77 vertex_count = int(ln[1]) |
77 vertex_count = int(ln[1]) |
78 vertices = [] |
78 vertices = [] |
79 for i in range(vertex_count): |
79 for i in range(vertex_count): |
80 ln = f.readline().split() |
80 ln = f.readline().split() |
81 vertex = (float(ln[0]), float(ln[1]), float(ln[2])) |
81 vertex = (float(ln[0]), float(ln[1]), float(ln[2])) |
82 normal = (float(ln[3]), float(ln[4]), float(ln[5])) |
82 normal = (float(ln[3]), float(ln[4]), float(ln[5])) |
83 vertices.append(NormalVertex(vertex, normal)) |
83 vertices.append(NormalVertex(vertex, normal)) |
84 rt.addshape(Triangle(vertices[0], vertices[1], vertices[2], mat)) |
84 rt.addShape(Triangle(vertices[0], vertices[1], vertices[2], mat)) |
85 for i in range(vertex_count)[3:]: |
85 for i in range(vertex_count)[3:]: |
86 rt.addshape(Triangle(vertices[0], vertices[i-1], vertices[i], mat)) |
86 rt.addShape(Triangle(vertices[0], vertices[i-1], vertices[i], mat)) |
87 elif ln[0] == '#': # Comment |
87 elif ln[0] == '#': # Comment |
88 pass |
88 pass |
89 else: |
89 else: |
90 print "Not implemented:", line |
90 print "Not implemented:", line |
91 f.close() |
91 f.close() |