author | Radek Brich <radek.brich@devl.cz> |
Sun, 09 Dec 2007 23:10:58 +0100 | |
branch | pyrit |
changeset 34 | 28f6e8b9d5d1 |
parent 29 | 574c34441a1c |
child 41 | c1080cb5bd6d |
permissions | -rw-r--r-- |
29 | 1 |
from raytracer import Triangle, NormalVertex |
2 |
||
3 |
def LoadWavefrontObjFile(rt, filename, mat, scale): |
|
4 |
vertices = [] |
|
5 |
fp = file(filename) |
|
6 |
while True: |
|
7 |
ln = fp.readline() |
|
8 |
if ln == "": |
|
9 |
break; |
|
10 |
ln = ln.split() |
|
11 |
if ln[0] == "v": |
|
12 |
v = [scale*float(x) for x in ln[1:4]] |
|
13 |
vertices.append(tuple(v)) |
|
14 |
if ln[0] == "f": |
|
15 |
f = [vertices[int(x)-1] for x in ln[1:4]] |
|
16 |
face = Triangle(NormalVertex(f[0]), NormalVertex(f[1]), NormalVertex(f[2]), mat) |
|
17 |
rt.addshape(face) |