1 #!/usr/bin/python |
1 #!/usr/bin/python |
2 |
2 |
3 # read nff data from standart input and render image to render_nff.png |
3 # read nff data from standart input and render image to render_nff.png |
4 # see http://tog.acm.org/resources/SPD/ |
4 # see http://tog.acm.org/resources/SPD/ |
5 # only spheres and triangles are implemented |
5 # cylinders are not implemented |
6 |
6 |
7 from raytracer import Raytracer, Camera, Light, Material, Sphere, NormalVertex, Triangle |
7 from raytracer import Raytracer, Camera, Light, Material, Sphere, NormalVertex, Triangle |
8 from math import pi |
8 from math import pi |
9 import sys, Image |
9 import sys, Image |
10 |
10 |
70 vertex = (float(ln[0]), float(ln[1]), float(ln[2])) |
70 vertex = (float(ln[0]), float(ln[1]), float(ln[2])) |
71 vertices.append(NormalVertex(vertex)) |
71 vertices.append(NormalVertex(vertex)) |
72 rt.addshape(Triangle(vertices[0], vertices[1], vertices[2], mat)) |
72 rt.addshape(Triangle(vertices[0], vertices[1], vertices[2], mat)) |
73 for i in range(vertex_count)[3:]: |
73 for i in range(vertex_count)[3:]: |
74 rt.addshape(Triangle(vertices[0], vertices[i-1], vertices[i], mat)) |
74 rt.addshape(Triangle(vertices[0], vertices[i-1], vertices[i], mat)) |
|
75 elif ln[0] == 'pp': # Polygonal patch |
|
76 mat.setSmooth(True) |
|
77 vertex_count = int(ln[1]) |
|
78 vertices = [] |
|
79 for i in range(vertex_count): |
|
80 ln = f.readline().split() |
|
81 vertex = (float(ln[0]), float(ln[1]), float(ln[2])) |
|
82 normal = (float(ln[3]), float(ln[4]), float(ln[5])) |
|
83 vertices.append(NormalVertex(vertex, normal)) |
|
84 rt.addshape(Triangle(vertices[0], vertices[1], vertices[2], mat)) |
|
85 for i in range(vertex_count)[3:]: |
|
86 rt.addshape(Triangle(vertices[0], vertices[i-1], vertices[i], mat)) |
75 else: |
87 else: |
76 print "Not implemented:", line |
88 print "Not implemented:", line |
77 f.close() |
89 f.close() |
78 |
90 |
79 data = rt.render(imagesize) |
91 data = rt.render(imagesize) |