demos/triangles_sphere.py
branchpyrit
changeset 28 ffe83ca074f3
parent 22 76b7bd51d64a
child 29 574c34441a1c
equal deleted inserted replaced
27:e9bb83c2b8b9 28:ffe83ca074f3
     1 #!/usr/bin/python
     1 #!/usr/bin/python
     2 
     2 
     3 import sys
     3 import sys
     4 sys.path.append(open('ModulePath').read().strip())
     4 sys.path.append(open('ModulePath').read().strip())
     5 
     5 
     6 from raytracer import Raytracer, Light, Sphere, Triangle, Material
     6 from raytracer import Raytracer, Light, Sphere, Triangle, NormalVertex, Material
     7 import Image
     7 import Image
     8 
     8 
     9 def LoadWavefrontObjFile(rt, mat, filename):
     9 def LoadWavefrontObjFile(rt, mat, filename):
    10 	vertices = []
    10 	vertices = []
    11 	fp = file(filename)
    11 	fp = file(filename)
    17 		if ln[0] == "v":
    17 		if ln[0] == "v":
    18 			v = [1.5*float(x) for x in ln[1:4]]
    18 			v = [1.5*float(x) for x in ln[1:4]]
    19 			vertices.append(tuple(v))
    19 			vertices.append(tuple(v))
    20 		if ln[0] == "f":
    20 		if ln[0] == "f":
    21 			f = [vertices[int(x)-1] for x in ln[1:4]]
    21 			f = [vertices[int(x)-1] for x in ln[1:4]]
    22 			face = Triangle(f[0], f[1], f[2], mat)
    22 			face = Triangle(NormalVertex(f[0]), NormalVertex(f[1]), NormalVertex(f[2]), mat)
    23 			rt.addshape(face)
    23 			rt.addshape(face)
    24 
    24 
    25 rt = Raytracer()
    25 rt = Raytracer()
    26 mat = Material(colour=(0.9, 0.9, 0.9))
    26 mat = Material(colour=(0.9, 0.9, 0.9))
    27 LoadWavefrontObjFile(rt, mat, "sphere.obj")
    27 LoadWavefrontObjFile(rt, mat, "sphere.obj")