demos/bunny.py
author Radek Brich <radek.brich@devl.cz>
Sun, 09 Dec 2007 23:10:58 +0100
branchpyrit
changeset 34 28f6e8b9d5d1
parent 31 b4e09433934a
child 38 5d043eeb09d9
permissions -rwxr-xr-x
quaternion moved to extra header file updated headers in all sources
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/python
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
# this demo needs bunny model from
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
# http://graphics.stanford.edu/data/3Dscanrep/
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
import sys
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
sys.path.append(open('ModulePath').read().strip())
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
     9
from raytracer import Raytracer, Light, Box, Triangle, NormalVertex, Material
29
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
    10
from plyreader import LoadStanfordPlyFile
26
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
import Image
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
rt = Raytracer()
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    14
#rt.ambientocclusion(samples=100, distance=16.0, angle=0.5)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    15
26
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
mat = Material(colour=(0.9, 0.9, 0.9))
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    17
mat.setTransmissivity(0.8)
29
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
    18
LoadStanfordPlyFile(rt, "../models/bunny/bun_zipper.ply",
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    19
	mat, smooth=True, scale=(-29.0, 29.0, 29.0), trans=(-1,-2.5,-3))
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    20
34
28f6e8b9d5d1 quaternion moved to extra header file
Radek Brich <radek.brich@devl.cz>
parents: 31
diff changeset
    21
mat0 = Material(colour=(0.1, 0.2, 1.0))
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    22
box1 = Box(L=(-20.0, -1.7, -20.0), H=(20.0, -1.5, 20.0), material=mat0)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    23
rt.addshape(box1)
26
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
34
28f6e8b9d5d1 quaternion moved to extra header file
Radek Brich <radek.brich@devl.cz>
parents: 31
diff changeset
    25
mat1 = Material(colour=(0.5, 0.2, 0.1))
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    26
mat1.setReflectivity(0.0)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    27
box2 = Box(L=(-20.0, -20.0, -10.0), H=(20.0, 20.0, -12.0), material=mat1)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    28
rt.addshape(box2)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    29
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    30
light = Light(position=(-5.0, 3.0, 10.0), colour=(0.9, 0.3, 0.6))
26
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
rt.addlight(light)
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    33
light2 = Light(position=(4.0, 1.0, 10.0), colour=(0.2, 0.9, 0.5))
26
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
rt.addlight(light2)
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
imagesize = (800, 600)
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
data = rt.render(imagesize)
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
img = Image.fromstring("RGB", imagesize, data)
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
img.save('bunny.png')