demos/bunny.py
branchpyrit
changeset 90 f6a72eb99631
parent 75 20dee9819b17
child 95 ca7d4c665531
equal deleted inserted replaced
89:fcf1487b398b 90:f6a72eb99631
     1 #!/usr/bin/python
     1 #!/usr/bin/python
     2 
     2 
     3 # this demo needs bunny model from
     3 # this demo needs bunny model from
     4 # http://graphics.stanford.edu/data/3Dscanrep/
     4 # http://graphics.stanford.edu/data/3Dscanrep/
     5 
     5 
     6 from raytracer import Raytracer, Light, Box, Triangle, Material
     6 from pyrit import *
     7 from plyreader import LoadStanfordPlyFile
     7 from plyreader import LoadStanfordPlyFile
     8 import Image
       
     9 
     8 
    10 rt = Raytracer()
     9 rt = Raytracer()
       
    10 top = KdTree()
       
    11 rt.setTop(top)
       
    12 rt.setCamera(Camera())
       
    13 
    11 #rt.ambientocclusion(samples=100, distance=16.0, angle=0.5)
    14 #rt.ambientocclusion(samples=100, distance=16.0, angle=0.5)
    12 
    15 
    13 mat = Material(colour=(0.9, 0.9, 0.9))
    16 mat = Material(colour=(0.9, 0.9, 0.9))
    14 mat.setTransmissivity(0.8)
    17 mat.setTransmissivity(0.8)
    15 mat.setSmooth(True)
    18 mat.setSmooth(True)
    31 
    34 
    32 light2 = Light(position=(4.0, 1.0, 10.0), colour=(0.5, 0.55, 0.7))
    35 light2 = Light(position=(4.0, 1.0, 10.0), colour=(0.5, 0.55, 0.7))
    33 #light2.castshadows(0)
    36 #light2.castshadows(0)
    34 rt.addLight(light2)
    37 rt.addLight(light2)
    35 
    38 
    36 imagesize = (800, 600)
    39 top.optimize()
    37 data = rt.render(imagesize)
    40 
    38 img = Image.fromstring("RGB", imagesize, data)
    41 sampler = DefaultSampler(800, 600)
    39 img.save('bunny.png')
    42 rt.setSampler(sampler)
       
    43 rt.render()
       
    44 sampler.getPixmap().writePNG('bunny.png')