demos/objreader.py
author Radek Brich <radek.brich@devl.cz>
Wed, 09 Apr 2008 16:51:14 +0200
branchpyrit
changeset 63 440e1ae80459
parent 41 c1080cb5bd6d
child 75 20dee9819b17
permissions -rw-r--r--
add many SCons targets (see DEVNOTES) make automatic model downloading work again remove Makefiles -- now obsolete and hardly maintainable

# Wavefron .obj file loader

from raytracer import Triangle, NormalVertex

def LoadWavefrontObjFile(rt, filename, mat, scale):
	vertices = []
	fp = file(filename)
	while True:
		ln = fp.readline()
		if ln == "":
			break;
		ln = ln.split()
		if ln[0] == "v":
			v = [scale*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)