|
1 #!/usr/bin/python |
|
2 |
|
3 from pyrit import * |
|
4 from lworeader import LoadLightwaveLwoFile |
|
5 from plyreader import LoadStanfordPlyFile |
|
6 from math import * |
|
7 from time import time |
|
8 |
|
9 rt = Raytracer() |
|
10 top = KdTree() |
|
11 rt.setTop(top) |
|
12 rt.setBgColour((0.2,0.3,0.8)) |
|
13 cam = Camera(eye=(-8,3,4),lookat=(0,-0.5,1)) |
|
14 rt.setCamera(cam) |
|
15 |
|
16 carmodel = "../models/lwo/Nissan300ZX.lwo" |
|
17 bunnymodel = "../models/ply/bunny/bun_zipper.ply" |
|
18 |
|
19 print "Loading file", carmodel |
|
20 facenum = LoadLightwaveLwoFile(rt, carmodel, scale=0.4) |
|
21 print "Loaded", facenum, "faces" |
|
22 |
|
23 matbunny = Material(colour=(0.4, 0.5, 0.9)) |
|
24 matbunny.setTransmissivity(0.65, 1.3) |
|
25 matbunny.setReflectivity(0.3) |
|
26 matbunny.setSmooth(True) |
|
27 |
|
28 print "Loading file", bunnymodel |
|
29 facenum = LoadStanfordPlyFile(rt, bunnymodel, |
|
30 matbunny, scale=(20.0, 20.0, -20.0), trans=(-1,-1.8,3.5)) |
|
31 print "Loaded", facenum, "faces" |
|
32 |
|
33 mat = Material(colour=(0.5, 0.5, 0.5)) |
|
34 ground = Box(L=(-10,-2,-10), H=(10,-1.2,10), material=mat) |
|
35 rt.addShape(ground) |
|
36 |
|
37 lwall = Box(L=(-10,-2,-4), H=(10,10,-3), material=mat) |
|
38 rt.addShape(lwall) |
|
39 |
|
40 mat = Material(colour=(0.5, 0.5, 0.5)) |
|
41 mat.setReflectivity(0.7) |
|
42 backwall = Box(L=(8,-2, -10), H=(10,10,10), material=mat) |
|
43 rt.addShape(backwall) |
|
44 |
|
45 light1 = Light(position=(-5.0, 20.0, 8.0), colour=(0.9, 0.9, 0.9)) |
|
46 rt.addLight(light1) |
|
47 light2 = Light(position=(5.0, 10.0, 10.0), colour=(0.9, 0.7, 0.7)) |
|
48 rt.addLight(light2) |
|
49 |
|
50 t1 = time() |
|
51 top.optimize() |
|
52 t2 = time() |
|
53 print "kd-tree built in", (t2-t1), "s" |
|
54 |
|
55 sampler = DefaultSampler(1024, 768) |
|
56 sampler.setOversample(1) |
|
57 rt.setSampler(sampler) |
|
58 |
|
59 t1 = time() |
|
60 rt.render() |
|
61 t2 = time() |
|
62 print "rendered in", (t2-t1), "s" |
|
63 |
|
64 sampler.getPixmap().writePNG('bench.png') |