demos/dragon.py
author Radek Brich <radek.brich@devl.cz>
Sat, 29 Mar 2008 18:01:45 +0100
branchpyrit
changeset 57 1e92c21b9a61
parent 29 574c34441a1c
child 60 a23b5089b9c3
permissions -rwxr-xr-x
new python demo: boxes
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
import sys
24
d0d76e8a5203 new C++ demo: realtime_dragon.cc
Radek Brich <radek.brich@devl.cz>
parents: 19
diff changeset
     7
sys.path.append(open('ModulePath').read().strip())
18
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
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
    10
from plyreader import LoadStanfordPlyFile
18
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
import Image
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
rt = Raytracer()
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
mat = Material(colour=(0.9, 0.9, 0.9))
29
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
    15
LoadStanfordPlyFile(rt, "../models/dragon/dragon_vrip_res2.ply",
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
    16
	mat, smooth=True, 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
    17
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
light1 = Light(position=(-5.0, 2.0, 8.0), colour=(0.9, 0.3, 0.2))
b8232edee786 tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    19
rt.addlight(light1)
b8232edee786 tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    20
b8232edee786 tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    21
light2 = Light(position=(3.0, 0.0, 9.0), colour=(0.0, 1.0, 0.2))
b8232edee786 tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents: 24
diff changeset
    22
rt.addlight(light2)
18
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
imagesize = (800, 600)
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
data = rt.render(imagesize)
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
img = Image.fromstring("RGB", imagesize, data)
25b7c445cf61 new demo: dragon.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
img.save('dragon.png')