demos/triangles_sphere.py
branchpyrit
changeset 29 574c34441a1c
parent 28 ffe83ca074f3
child 60 a23b5089b9c3
--- a/demos/triangles_sphere.py	Sat Dec 08 12:37:45 2007 +0100
+++ b/demos/triangles_sphere.py	Sat Dec 08 14:07:42 2007 +0100
@@ -4,27 +4,12 @@
 sys.path.append(open('ModulePath').read().strip())
 
 from raytracer import Raytracer, Light, Sphere, Triangle, NormalVertex, Material
+from objreader import LoadWavefrontObjFile
 import Image
 
-def LoadWavefrontObjFile(rt, mat, filename):
-	vertices = []
-	fp = file(filename)
-	while True:
-		ln = fp.readline()
-		if ln == "":
-			break;
-		ln = ln.split()
-		if ln[0] == "v":
-			v = [1.5*float(x) for x in ln[1:4]]
-			vertices.append(tuple(v))
-		if ln[0] == "f":
-			f = [vertices[int(x)-1] for x in ln[1:4]]
-			face = Triangle(NormalVertex(f[0]), NormalVertex(f[1]), NormalVertex(f[2]), mat)
-			rt.addshape(face)
-
 rt = Raytracer()
 mat = Material(colour=(0.9, 0.9, 0.9))
-LoadWavefrontObjFile(rt, mat, "sphere.obj")
+LoadWavefrontObjFile(rt, "sphere.obj", mat, 1.5)
 
 light1 = Light(position=(0.0, 2.0, 6.0), colour=(0.9, 0.3, 0.6))
 light1.castshadows(False);