author | Radek Brich <radek.brich@devl.cz> |
Fri, 28 Mar 2008 23:30:04 +0100 | |
branch | pyrit |
changeset 52 | a6413a3d741d |
parent 41 | c1080cb5bd6d |
child 75 | 20dee9819b17 |
permissions | -rw-r--r-- |
41
c1080cb5bd6d
fix possible division by zero in ccdemos/common_ply.h
Radek Brich <radek.brich@devl.cz>
parents:
29
diff
changeset
|
1 |
# Wavefron .obj file loader |
c1080cb5bd6d
fix possible division by zero in ccdemos/common_ply.h
Radek Brich <radek.brich@devl.cz>
parents:
29
diff
changeset
|
2 |
|
29 | 3 |
from raytracer import Triangle, NormalVertex |
4 |
||
5 |
def LoadWavefrontObjFile(rt, filename, mat, scale): |
|
6 |
vertices = [] |
|
7 |
fp = file(filename) |
|
8 |
while True: |
|
9 |
ln = fp.readline() |
|
10 |
if ln == "": |
|
11 |
break; |
|
12 |
ln = ln.split() |
|
13 |
if ln[0] == "v": |
|
14 |
v = [scale*float(x) for x in ln[1:4]] |
|
15 |
vertices.append(tuple(v)) |
|
16 |
if ln[0] == "f": |
|
17 |
f = [vertices[int(x)-1] for x in ln[1:4]] |
|
18 |
face = Triangle(NormalVertex(f[0]), NormalVertex(f[1]), NormalVertex(f[2]), mat) |
|
19 |
rt.addshape(face) |