demos/buddha.py
branchpyrit
changeset 90 f6a72eb99631
parent 75 20dee9819b17
equal deleted inserted replaced
89:fcf1487b398b 90:f6a72eb99631
     1 #!/usr/bin/python
     1 #!/usr/bin/python
     2 
     2 
     3 # this demo needs buddha model from
     3 # this demo needs buddha model from
     4 # http://graphics.stanford.edu/data/3Dscanrep/
     4 # http://graphics.stanford.edu/data/3Dscanrep/
     5 
     5 
     6 from raytracer import Raytracer, Light, Sphere, 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 
       
    14 light = Light(position=(-5.0, 2.0, 8.0), colour=(0.9, 0.3, 0.6))
       
    15 rt.addLight(light)
       
    16 
    11 mat = Material(colour=(0.9, 0.9, 0.9))
    17 mat = Material(colour=(0.9, 0.9, 0.9))
    12 mat.setSmooth(True)
    18 mat.setSmooth(True)
    13 LoadStanfordPlyFile(rt, "../models/ply/happy/happy_vrip_res2.ply",
    19 LoadStanfordPlyFile(rt, "../models/ply/happy/happy_vrip_res2.ply",
    14 	mat, scale=20.0, trans=(0,-3,0))
    20 	mat, scale=20.0, trans=(0,-3,0))
       
    21 top.optimize()
    15 
    22 
    16 light = Light(position=(-5.0, 2.0, 8.0), colour=(0.9, 0.3, 0.6))
    23 sampler = DefaultSampler(800, 600)
    17 rt.addLight(light)
    24 rt.setSampler(sampler)
    18 
    25 rt.render()
    19 imagesize = (800, 600)
    26 sampler.getPixmap().writePNG('buddha.png')
    20 data = rt.render(imagesize)
       
    21 img = Image.fromstring("RGB", imagesize, data)
       
    22 img.save('buddha.png')