demos/dragon.py
branchpyrit
changeset 90 f6a72eb99631
parent 75 20dee9819b17
child 98 64638385798a
equal deleted inserted replaced
89:fcf1487b398b 90:f6a72eb99631
     1 #!/usr/bin/python
     1 #!/usr/bin/python
     2 
     2 
     3 # this demo needs dragon model from
     3 # this demo needs dragon 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 
    11 mat = Material(colour=(0.9, 0.9, 0.9))
    14 mat = Material(colour=(0.9, 0.9, 0.9))
    12 mat.setSmooth(True)
    15 mat.setSmooth(True)
    13 LoadStanfordPlyFile(rt, "../models/ply/dragon/dragon_vrip_res2.ply",
    16 LoadStanfordPlyFile(rt, "../models/ply/dragon/dragon_vrip_res2.ply",
    14 	mat, scale=(-29.0, 29.0, -29.0), trans=(0.0, -3.6, 0.0))
    17 	mat, scale=(-29.0, 29.0, -29.0), trans=(0.0, -3.6, 0.0))
    15 
    18 
    17 rt.addLight(light1)
    20 rt.addLight(light1)
    18 
    21 
    19 light2 = Light(position=(3.0, 0.0, 9.0), colour=(0.0, 1.0, 0.2))
    22 light2 = Light(position=(3.0, 0.0, 9.0), colour=(0.0, 1.0, 0.2))
    20 rt.addLight(light2)
    23 rt.addLight(light2)
    21 
    24 
    22 imagesize = (800, 600)
    25 top.optimize()
    23 data = rt.render(imagesize)
    26 
    24 img = Image.fromstring("RGB", imagesize, data)
    27 sampler = DefaultSampler(800, 600)
    25 img.save('dragon.png')
    28 rt.setSampler(sampler)
       
    29 rt.render()
       
    30 sampler.getPixmap().writePNG('dragon.png')