1 #!/usr/bin/python |
1 #!/usr/bin/python |
2 |
2 |
3 from raytracer import Raytracer, Light, Sphere, Triangle, NormalVertex, Material |
3 from pyrit import * |
4 from objreader import LoadWavefrontObjFile |
4 from objreader import LoadWavefrontObjFile |
5 import Image |
|
6 |
5 |
7 rt = Raytracer() |
6 rt = Raytracer() |
8 mat = Material(colour=(0.9, 0.9, 0.9)) |
7 top = KdTree() |
9 LoadWavefrontObjFile(rt, "../models/obj/sphere.obj", mat, 1.5) |
8 rt.setTop(top) |
|
9 rt.setCamera(Camera()) |
10 |
10 |
11 light1 = Light(position=(0.0, 2.0, 6.0), colour=(0.9, 0.3, 0.6)) |
11 light1 = Light(position=(0.0, 2.0, 6.0), colour=(0.9, 0.3, 0.6)) |
12 light1.castShadows(False); |
12 light1.castShadows(False); |
13 rt.addLight(light1) |
13 rt.addLight(light1) |
14 |
14 |
15 light2 = Light(position=(-2.0, -5.0, 7.0), colour=(0.7, 1.0, 0.3)) |
15 light2 = Light(position=(-2.0, -5.0, 7.0), colour=(0.7, 1.0, 0.3)) |
16 light2.castShadows(False); |
16 light2.castShadows(False); |
17 rt.addLight(light2) |
17 rt.addLight(light2) |
18 |
18 |
19 imagesize = (800, 600) |
19 mat = Material(colour=(0.9, 0.9, 0.9)) |
20 data = rt.render(imagesize) |
20 LoadWavefrontObjFile(rt, "../models/obj/sphere.obj", mat, 1.5) |
21 img = Image.fromstring("RGB", imagesize, data) |
21 top.optimize() |
22 img.save('triangles_sphere.png') |
22 |
|
23 sampler = DefaultSampler(800, 600) |
|
24 rt.setSampler(sampler) |
|
25 rt.render() |
|
26 sampler.getPixmap().writePNG('triangles_sphere.png') |