demos/buddha.py
branchpyrit
changeset 29 574c34441a1c
parent 28 ffe83ca074f3
child 30 33f95441790e
--- a/demos/buddha.py	Sat Dec 08 12:37:45 2007 +0100
+++ b/demos/buddha.py	Sat Dec 08 14:07:42 2007 +0100
@@ -7,42 +7,13 @@
 sys.path.append(open('ModulePath').read().strip())
 
 from raytracer import Raytracer, Light, Sphere, Triangle, Material
+from plyreader import LoadStanfordPlyFile
 import Image
 
-def LoadStanfordPlyFile(rt, mat, filename, scale):
-	vertices = []
-	fp = file(filename)
-	# read header
-	tokens = (0,)
-	while (tokens[0] != "end_header"):
-		tokens = fp.readline().split()
-		if (tokens[0] == "element"):
-			if (tokens[1] == "vertex"):
-				vertex_num = int(tokens[2])
-			if (tokens[1] == "face"):
-				face_num = int(tokens[2])
-
-	# read vertices
-	while (vertex_num):
-		tokens = fp.readline().split()
-		v = [scale*float(x) for x in tokens[0:3]]
-		v[1] = v[1]-3
-		vertices.append(tuple(v))
-		vertex_num -= 1
-
-	# read faces
-	while (face_num):
-		tokens = fp.readline().split()
-		if (tokens[0] != "3"):
-			print "ply warning: faces of %d vertices not supported" % tokens[0]
-		f = [vertices[int(x)] for x in tokens[1:4]]
-		face = Triangle(NormalVertex(f[0]), NormalVertex(f[1]), NormalVertex(f[2]), mat)
-		rt.addshape(face)
-		face_num -= 1
-
 rt = Raytracer()
 mat = Material(colour=(0.9, 0.9, 0.9))
-LoadStanfordPlyFile(rt, mat ,"../models/happy/happy_vrip_res2.ply", 20.0)
+LoadStanfordPlyFile(rt, "../models/happy/happy_vrip_res2.ply",
+	mat, smooth=True, scale=20.0, trans=(-3,0,0))
 
 light = Light(position=(-5.0, 2.0, 8.0), colour=(0.9, 0.3, 0.6))
 rt.addlight(light)