-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.py
More file actions
executable file
·66 lines (52 loc) · 1.47 KB
/
Copy pathrender.py
File metadata and controls
executable file
·66 lines (52 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
import poly
import sys
import pickle
if (len(sys.argv) < 4):
quit()
file = sys.argv[1]
x_pix = int(sys.argv[2])
y_pix = int(sys.argv[3])
meanp = (y_pix * x_pix)**0.5
camerap = poly.point([0.0, 0.0, -10.0])
camerav = poly.vector(poly.point([0, 0, 0]), poly.point([0.0, 0.0, 1.0]))
zoom = 1.0
light1 = (poly.point([0.0, 10, -4]), 200)
lights = [light1]
mesh = poly.mesh()
mesh.load_raw(file)
def calc_pixelpoint(x, y):
dx = float(x)/meanp - 0.5
dy = float(y)/meanp - 0.5
xv = poly.vector(poly.point([0, 0, 0]), poly.point([1, 0, 0]))
yv = poly.vector(poly.point([0, 0, 0]), poly.point([0, -1, 0]))
pixel = camerap.sum(camerav.mult(zoom)).sum(xv.mult(dx)).sum(yv.mult(dy))
return pixel
def shade(scol, mesh, lights):
clr = 0
for light in lights:
lray = poly.ray(light[0], scol[1])
lcol = mesh.test_collision(lray)
if (lcol[0] > 0 and lcol[0] < 0.9999):
clr = clr + 0.000000001
else:
refl = lray.direction.skalar(scol[2].plane.h)/(lray.direction.abs()*scol[2].plane.h.abs())
clr = clr + light[1] * abs(refl)
return int(clr)
def render(mesh, x_pix, y_pix):
x = x_pix
y = y_pix
lines = []
for line_nr in range(y):
line = []
for pix in range(x):
sray = poly.ray(camerap, calc_pixelpoint(pix, line_nr))
col = mesh.test_collision(sray)
if (col[0] > 0):
line.append(shade(col, mesh, lights))
else:
line.append(0)
lines.append(line)
return lines
pic = render(mesh, x_pix, y_pix)
pickle.dump(pic, open(file+".MrayS", "wb"))