demos/bunny.py
author Radek Brich <radek.brich@devl.cz>
Fri, 11 Apr 2008 00:13:59 +0200
branchpyrit
changeset 66 c5b89d16497a
parent 62 07c2f8084719
child 69 303583d2fb97
permissions -rwxr-xr-x
fixed ICC detection
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
38
5d043eeb09d9 realtime_dragon demo: now fullsize model + octree
Radek Brich <radek.brich@devl.cz>
parents: 34
diff changeset
     6
from raytracer import Raytracer, Light, Box, Triangle, Material
29
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents: 28
diff changeset
     7
from plyreader import LoadStanfordPlyFile
26
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
import Image
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
rt = Raytracer()
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    11
#rt.ambientocclusion(samples=100, distance=16.0, angle=0.5)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    12
26
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
mat = Material(colour=(0.9, 0.9, 0.9))
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    14
mat.setTransmissivity(0.8)
62
07c2f8084719 more SConscript tweaking, make model preparation work again
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
    15
LoadStanfordPlyFile(rt, "../models/ply/bunny/bun_zipper.ply",
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    16
	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
    17
46
6493fb65f0b1 Doxygen
Radek Brich <radek.brich@devl.cz>
parents: 40
diff changeset
    18
mat0 = Material(colour=(0.1, 0.2, 0.6))
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    19
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
    20
rt.addshape(box1)
26
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
46
6493fb65f0b1 Doxygen
Radek Brich <radek.brich@devl.cz>
parents: 40
diff changeset
    22
mat1 = Material(colour=(0.5, 0.5, 0.2))
31
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    23
mat1.setReflectivity(0.0)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    24
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
    25
rt.addshape(box2)
b4e09433934a refraction
Radek Brich <radek.brich@devl.cz>
parents: 29
diff changeset
    26
46
6493fb65f0b1 Doxygen
Radek Brich <radek.brich@devl.cz>
parents: 40
diff changeset
    27
light = Light(position=(-5.0, 3.0, 10.0), colour=(0.8, 0.5, 0.6))
40
929aad02c5f2 Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents: 38
diff changeset
    28
#light.castshadows(0)
26
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
rt.addlight(light)
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
46
6493fb65f0b1 Doxygen
Radek Brich <radek.brich@devl.cz>
parents: 40
diff changeset
    31
light2 = Light(position=(4.0, 1.0, 10.0), colour=(0.5, 0.55, 0.7))
40
929aad02c5f2 Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents: 38
diff changeset
    32
#light2.castshadows(0)
26
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
rt.addlight(light2)
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
imagesize = (800, 600)
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
data = rt.render(imagesize)
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
img = Image.fromstring("RGB", imagesize, data)
9073320e9f4c new demo: bunny.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
img.save('bunny.png')