2 |
2 |
3 import sys |
3 import sys |
4 sys.path.append(open('ModulePath').read().strip()) |
4 sys.path.append(open('ModulePath').read().strip()) |
5 |
5 |
6 from raytracer import Raytracer, Light, Sphere, Triangle, NormalVertex, Material |
6 from raytracer import Raytracer, Light, Sphere, Triangle, NormalVertex, Material |
|
7 from objreader import LoadWavefrontObjFile |
7 import Image |
8 import Image |
8 |
|
9 def LoadWavefrontObjFile(rt, mat, filename): |
|
10 vertices = [] |
|
11 fp = file(filename) |
|
12 while True: |
|
13 ln = fp.readline() |
|
14 if ln == "": |
|
15 break; |
|
16 ln = ln.split() |
|
17 if ln[0] == "v": |
|
18 v = [1.5*float(x) for x in ln[1:4]] |
|
19 vertices.append(tuple(v)) |
|
20 if ln[0] == "f": |
|
21 f = [vertices[int(x)-1] for x in ln[1:4]] |
|
22 face = Triangle(NormalVertex(f[0]), NormalVertex(f[1]), NormalVertex(f[2]), mat) |
|
23 rt.addshape(face) |
|
24 |
9 |
25 rt = Raytracer() |
10 rt = Raytracer() |
26 mat = Material(colour=(0.9, 0.9, 0.9)) |
11 mat = Material(colour=(0.9, 0.9, 0.9)) |
27 LoadWavefrontObjFile(rt, mat, "sphere.obj") |
12 LoadWavefrontObjFile(rt, "sphere.obj", mat, 1.5) |
28 |
13 |
29 light1 = Light(position=(0.0, 2.0, 6.0), colour=(0.9, 0.3, 0.6)) |
14 light1 = Light(position=(0.0, 2.0, 6.0), colour=(0.9, 0.3, 0.6)) |
30 light1.castshadows(False); |
15 light1.castshadows(False); |
31 rt.addlight(light1) |
16 rt.addlight(light1) |
32 |
17 |