demos/car.py
author Radek Brich <radek.brich@devl.cz>
Fri, 04 Apr 2008 13:54:47 +0200
branchpyrit
changeset 59 64e456ab823d
parent 58 cfe98f5c0ae9
child 60 a23b5089b9c3
permissions -rwxr-xr-x
add color support to lwo reader python binding for Camera
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/python
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
import sys
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
sys.path.append(open('ModulePath').read().strip())
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
     6
from raytracer import Raytracer, Light, Sphere, Triangle, Material, Camera
58
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
from lworeader import LoadLightwaveLwoFile
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
import Image
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
     9
from math import *
58
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
rt = Raytracer()
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
    12
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
    13
cam = Camera(eye=(0.,5.,8.))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
    14
rotx=0.3
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
    15
cam.rotate((cos(rotx),-sin(rotx),0.,0.))
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
    16
rt.setcamera(cam)
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
    17
58
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
mat = Material(colour=(0.9, 0.9, 0.9))
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
    19
LoadLightwaveLwoFile(rt, "../models/car/Nissan300ZX.lwo", mat, smooth=False, scale=0.4)
58
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
59
64e456ab823d add color support to lwo reader
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
    21
light = Light(position=(-5.0, 2.0, 8.0), colour=(0.7, 0.7, 0.7))
58
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
rt.addlight(light)
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
imagesize = (800, 600)
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
data = rt.render(imagesize)
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
img = Image.fromstring("RGB", imagesize, data)
cfe98f5c0ae9 new python demo: car.py
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
img.save('car.png')