demos/objreader.py
author Radek Brich <radek.brich@devl.cz>
Tue, 29 Apr 2008 23:31:08 +0200
branchpyrit
changeset 90 f6a72eb99631
parent 75 20dee9819b17
permissions -rw-r--r--
rename Python module from 'raytracer' to 'pyrit' improve Python binding: - new objects: Container, Octree, KdTree, Shape, Pixmap, Sampler, DefaultSampler - all shapes are now subclasses of Shape - clean, remove redundant Getattr's - Raytracer render method now just wraps C++ method without doing any additional work adjust all demos for changes in Python binding, remove PIL dependency add demo_PIL.py as a example of pyrit + PIL usage render_nff.py now either loads file given as a argument or reads input from stdin otherwise fix bug in pixmap float to char conversion
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
90
f6a72eb99631 rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents: 75
diff changeset
     3
from pyrit import Triangle, NormalVertex
29
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
def LoadWavefrontObjFile(rt, filename, mat, scale):
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
	vertices = []
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
	fp = file(filename)
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
	while True:
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
		ln = fp.readline()
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
		if ln == "":
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
			break;
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
		ln = ln.split()
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
		if ln[0] == "v":
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
			v = [scale*float(x) for x in ln[1:4]]
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
			vertices.append(tuple(v))
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
		if ln[0] == "f":
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
			f = [vertices[int(x)-1] for x in ln[1:4]]
574c34441a1c new C++ demo: realtime_bunny
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
			face = Triangle(NormalVertex(f[0]), NormalVertex(f[1]), NormalVertex(f[2]), mat)
75
20dee9819b17 unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents: 41
diff changeset
    19
			rt.addShape(face)