demos/dragon.py
author Radek Brich <radek.brich@devl.cz>
Tue, 22 Apr 2008 13:33:12 +0200
branchpyrit
changeset 77 dbe8438d5dca
parent 75 20dee9819b17
child 90 f6a72eb99631
permissions -rwxr-xr-x
rewrite subsampling from old code to DefaultSampler render in phases, clean workers after each phase
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/python
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
# this demo needs dragon model from
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
# http://graphics.stanford.edu/data/3Dscanrep/
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
from raytracer import Raytracer, Light, Sphere, Triangle, Material
29
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
     7
from plyreader import LoadStanfordPlyFile
18
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
import Image
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
rt = Raytracer()
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
mat = Material(colour=(0.9, 0.9, 0.9))
69
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    12
mat.setSmooth(True)
62
07c2f8084719 more SConscript tweaking, make model preparation work again
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    13
LoadStanfordPlyFile(rt, "../models/ply/dragon/dragon_vrip_res2.ply",
69
303583d2fb97 move "smooth" attribute from Triangle to Material
Radek Brich <radek.brich@devl.cz>
parents: 62
diff changeset
    14
	mat, scale=(-29.0, 29.0, -29.0), trans=(0.0, -3.6, 0.0))
18
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
25
b8232edee786 tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    16
light1 = Light(position=(-5.0, 2.0, 8.0), colour=(0.9, 0.3, 0.2))
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
    17
rt.addLight(light1)
25
b8232edee786 tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    18
b8232edee786 tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    19
light2 = Light(position=(3.0, 0.0, 9.0), colour=(0.0, 1.0, 0.2))
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 69
diff changeset
    20
rt.addLight(light2)
18
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
imagesize = (800, 600)
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
data = rt.render(imagesize)
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
img = Image.fromstring("RGB", imagesize, data)
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
img.save('dragon.png')