demos/triangles_monkey.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 from raytracer import Raytracer, Light, Sphere, Triangle, NormalVertex, Material
     3 from pyrit import *
     4 from objreader import LoadWavefrontObjFile
     4 from objreader import LoadWavefrontObjFile
     5 import Image
       
     6 
     5 
     7 rt = Raytracer()
     6 rt = Raytracer()
     8 mat = Material(colour=(0.9, 0.9, 0.9))
     7 top = KdTree()
     9 LoadWavefrontObjFile(rt, "../models/obj/monkey.obj", mat, 1.5)
     8 rt.setTop(top)
       
     9 rt.setCamera(Camera())
    10 
    10 
    11 light = Light(position=(-5.0, 2.0, 8.0), colour=(0.9, 0.3, 0.6))
    11 light = Light(position=(-5.0, 2.0, 8.0), colour=(0.9, 0.3, 0.6))
    12 rt.addLight(light)
    12 rt.addLight(light)
    13 
    13 
    14 imagesize = (800, 600)
    14 mat = Material(colour=(0.9, 0.9, 0.9))
    15 data = rt.render(imagesize)
    15 LoadWavefrontObjFile(rt, "../models/obj/monkey.obj", mat, 1.5)
    16 img = Image.fromstring("RGB", imagesize, data)
    16 top.optimize()
    17 img.save('triangles_monkey.png')
    17 
       
    18 sampler = DefaultSampler(800, 600)
       
    19 rt.setSampler(sampler)
       
    20 rt.render()
       
    21 sampler.getPixmap().writePNG('triangles_monkey.png')