demos/bunny.py
branchpyrit
changeset 95 ca7d4c665531
parent 90 f6a72eb99631
equal deleted inserted replaced
94:4c8abb8977dc 95:ca7d4c665531
     7 from plyreader import LoadStanfordPlyFile
     7 from plyreader import LoadStanfordPlyFile
     8 
     8 
     9 rt = Raytracer()
     9 rt = Raytracer()
    10 top = KdTree()
    10 top = KdTree()
    11 rt.setTop(top)
    11 rt.setTop(top)
    12 rt.setCamera(Camera())
    12 rt.setCamera(Camera(eye=(4,2,3.5),lookat=(0.5,0.5,-3)))
       
    13 rt.setBgColour((0.5, 0.5, 0.2))
    13 
    14 
    14 #rt.ambientocclusion(samples=100, distance=16.0, angle=0.5)
    15 mat = Material(colour=(0.4, 0.5, 0.9))
    15 
    16 mat.setTransmissivity(0.95, 1.5)
    16 mat = Material(colour=(0.9, 0.9, 0.9))
    17 mat.setReflectivity(0)
    17 mat.setTransmissivity(0.8)
       
    18 mat.setSmooth(True)
    18 mat.setSmooth(True)
    19 LoadStanfordPlyFile(rt, "../models/ply/bunny/bun_zipper.ply",
    19 LoadStanfordPlyFile(rt, "../models/ply/bunny/bun_zipper.ply",
    20 	mat, scale=(-29.0, 29.0, 29.0), trans=(-1,-2.5,-3))
    20 	mat, scale=(-29.0, 29.0, 29.0), trans=(-1,-2.5,-3))
    21 
    21 
    22 mat0 = Material(colour=(0.1, 0.2, 0.6))
    22 mat0 = Material(colour=(0.3, 0.5, 1.0))
    23 box1 = Box(L=(-20.0, -1.7, -20.0), H=(20.0, -1.5, 20.0), material=mat0)
    23 floor = Box(L=(-20.0, -1.7, -20.0), H=(20.0, -1.5, 20.0), material=mat0)
    24 rt.addShape(box1)
    24 rt.addShape(floor)
    25 
    25 
    26 mat1 = Material(colour=(0.5, 0.5, 0.2))
    26 mat1 = Material(colour=(0.5, 0.5, 0.2))
    27 mat1.setReflectivity(0.0)
    27 mat1.setReflectivity(0.0)
    28 box2 = Box(L=(-20.0, -20.0, -10.0), H=(20.0, 20.0, -12.0), material=mat1)
    28 wall = Box(L=(-20.0, -20.0, -10.0), H=(20.0, 20.0, -12.0), material=mat1)
    29 rt.addShape(box2)
    29 rt.addShape(wall)
    30 
    30 
    31 light = Light(position=(-5.0, 3.0, 10.0), colour=(0.8, 0.5, 0.6))
    31 light = Light(position=(-5.0, 3.0, 10.0), colour=(0.8, 0.5, 0.6))
    32 #light.castshadows(0)
       
    33 rt.addLight(light)
    32 rt.addLight(light)
    34 
    33 
    35 light2 = Light(position=(4.0, 1.0, 10.0), colour=(0.5, 0.55, 0.7))
    34 light2 = Light(position=(4.0, 1.0, 10.0), colour=(0.5, 0.55, 0.7))
    36 #light2.castshadows(0)
       
    37 rt.addLight(light2)
    35 rt.addLight(light2)
    38 
    36 
    39 top.optimize()
    37 top.optimize()
    40 
    38 
    41 sampler = DefaultSampler(800, 600)
    39 sampler = DefaultSampler(800, 600)
       
    40 sampler.setOversample(1)
    42 rt.setSampler(sampler)
    41 rt.setSampler(sampler)
    43 rt.render()
    42 rt.render()
    44 sampler.getPixmap().writePNG('bunny.png')
    43 sampler.getPixmap().writePNG('bunny.png')