demos/texture.py
author Radek Brich <radek.brich@devl.cz>
Thu, 15 May 2008 00:07:25 +0200
branchpyrit
changeset 96 9eb71e76c7fd
permissions -rwxr-xr-x
added Python binding for material.h classes added raytracermodule.h header file for declarations updated car.py demo added texture.py demo (based on spheres_glass.py) all remaining 'centre' changed to more common 'center' added some more const's to material.h
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
96
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/python
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
from pyrit import *
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
rt = Raytracer()
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
top = KdTree()
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
rt.setTop(top)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
rt.setCamera(Camera(eye=(10,4,-6),lookat=(10,3.5,0)))
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
light1 = Light(position=(10.0, 7.0, 3.0), colour=(0.9, 0.3, 0.6))
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
rt.addLight(light1)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
light2 = Light(position=(8.0, 5.0, 1.0), colour=(0.7, 1.0, 0.3))
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
rt.addLight(light2)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
light3 = Light(position=(12.0, 8.0, -1.0), colour=(0.8, 0.9, 1.0))
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
rt.addLight(light3)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
mat0 = Material()
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
mat0.setTexture(CloudTexture(5, LinearColourMap((0.0, 0.0, 0.5), (0.5, 1.0, 1.0))))
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
mat0.setReflectivity(0.0)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
box = Box(L=(-10.0, 0.0, 50.0), H=(30.0, 1.0, -1.0), material=mat0)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
rt.addShape(box)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
mat1 = Material(colour=(1.0, 0.2, 0.1))
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
mat1.setReflectivity(0.7)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
bigsphere = Sphere(center=(12.0, 4.0, 6.0), radius=2.5, material=mat1)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
rt.addShape(bigsphere)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
mat2 = Material(colour=(0.1, 0.4, 0.2))
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
mat2.setReflectivity(0.6)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
smallsphere = Sphere(center=(6.5, 3.5, 8.0), radius=2.0, material=mat2)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
rt.addShape(smallsphere)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
mat3 = Material(colour=(0.9, 0.9, 1.0))
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
mat3.setPhong(0.2, 1.0, 0.2)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
mat3.setTransmissivity(0.88)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
mat3.setReflectivity(0.1)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
for i in range(10):
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
	sph = Sphere(center=(5.0+i, 1.5, 4.0), radius=0.5, material=mat3)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
	rt.addShape(sph)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
top.optimize()
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    45
sampler = DefaultSampler(800, 600)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    46
sampler.setOversample(1)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    47
rt.setSampler(sampler)
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    48
rt.render()
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    49
sampler.getPixmap().writePNG('texture.png')