Skip to content

Commit 5810a38

Browse files
author
monkstone
committed
Adding Cornell Box in python
1 parent 0342763 commit 5810a38

File tree

5 files changed

+409
-11
lines changed

5 files changed

+409
-11
lines changed

raytracing/cornell_box.pov

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
2+
// Persistence Of Vision Ray Tracer Scene Description pov_fib
3+
// pov_fib: Generated by tracer.py
4+
// tracer.py is based on http://code.activestate.com/recipes/205451/ (r1)
5+
// For PovRAY Version: 3.7 (includes radiosity)
6+
// Date: September 2011
7+
// Auth: Martin Prout
8+
// +width 800 +height 600 for basic_scene example
9+
#version 3.7;
10+
global_settings{
11+
assumed_gamma 1.0
12+
radiosity{
13+
pretrace_start 0.04
14+
pretrace_end 0.01
15+
count 200
16+
recursion_limit 3
17+
nearest_count 10
18+
error_bound 0.5
19+
}
20+
}
21+
22+
#include "colors.inc"
23+
24+
#include "skies.inc"
25+
26+
#declare LightColor=<1,0.67,0.21>;
27+
#declare N=3; //Divisions per side
28+
#declare DX=13/N; //Dimensions of sub patches
29+
#declare DZ=10.5/N;
30+
#declare SubPatch=
31+
light_source{
32+
<27.8,54.88,27.95>
33+
color LightColor*7
34+
area_light DX*x, DZ*z, 4, 4 jitter adaptive 0
35+
spotlight radius -90 falloff 90 tightness 1 point_at <27.8,0,27.95> //for cosine falloff
36+
fade_power 2 fade_distance (DX+DZ)/2
37+
}
38+
#declare i=0;#while (i<N)
39+
#declare j=0;#while (j<N)
40+
light_source{SubPatch translate<i*DX-(13-DX)/2,0,j*DZ-(10.5-DZ)/2>}
41+
#declare j=j+1;#end
42+
#declare i=i+1;#end
43+
camera
44+
{
45+
direction <0, 0, 1>
46+
right <-1, 0, 0>
47+
angle 39.5
48+
up <0, 1, 0>
49+
location <27.8, 27.3, -80>
50+
}
51+
52+
box
53+
{
54+
<21.3, 54.87, 33.2>, <34.3, 54.88, 22.7>
55+
no_shadow
56+
pigment
57+
{
58+
rgb <1, 1, 1>
59+
}
60+
finish
61+
{
62+
diffuse 0
63+
emission 0.78
64+
}
65+
}
66+
67+
union
68+
{
69+
triangle
70+
{
71+
<55.28, 0.0, 0.0>, <0.0, 0.0, 0.0>, <0.0, 0.0, 55.92>
72+
}
73+
triangle
74+
{
75+
<55.28, 0.0, 0.0>, <0.0, 0.0, 55.92>, <54.96, 0.0, 55.92>
76+
}
77+
triangle
78+
{
79+
<55.6, 54.88, 0.0>, <55.6, 54.88, 55.92>, <0.0, 54.88, 55.92>
80+
}
81+
triangle
82+
{
83+
<55.6, 54.88, 0.0>, <0.0, 54.88, 55.92>, <0.0, 54.88, 0.0>
84+
}
85+
triangle
86+
{
87+
<0.0, 54.88, 55.92>, <55.6, 54.88, 55.92>, <54.96, 0.0, 55.92>
88+
}
89+
triangle
90+
{
91+
<0.0, 54.88, 55.92>, <54.96, 0.0, 55.92>, <0.0, 0.0, 55.92>
92+
}
93+
texture
94+
{
95+
pigment
96+
{
97+
rgb <1, 1, 1>
98+
}
99+
finish
100+
{
101+
diffuse 0.75
102+
ambient 0
103+
}
104+
}
105+
}
106+
107+
union
108+
{
109+
triangle
110+
{
111+
<0.0, 54.88, 0.0>, <0.0, 54.88, 55.92>, <0.0, 0.0, 55.92>
112+
}
113+
triangle
114+
{
115+
<0.0, 54.88, 0.0>, <0.0, 0.0, 55.92>, <0.0, 0.0, 0.0>
116+
}
117+
texture
118+
{
119+
pigment
120+
{
121+
rgb <0.025, 0.236, 0.025>
122+
}
123+
finish
124+
{
125+
diffuse 0.75
126+
ambient 0
127+
}
128+
}
129+
}
130+
131+
union
132+
{
133+
triangle
134+
{
135+
<55.28, 0.0, 0.0>, <54.96, 0.0, 55.92>, <55.6, 54.88, 55.92>
136+
}
137+
triangle
138+
{
139+
<55.28, 0.0, 0.0>, <55.6, 54.88, 55.92>, <55.6, 54.88, 0.0>
140+
}
141+
texture
142+
{
143+
pigment
144+
{
145+
rgb <0.57, 0.025, 0.025>
146+
}
147+
finish
148+
{
149+
diffuse 0.75
150+
ambient 0
151+
}
152+
}
153+
}
154+
155+
union
156+
{
157+
triangle
158+
{
159+
<13.0, 16.5, 6.5>, <8.2, 16.5, 22.5>, <24.0, 16.5, 27.2>
160+
}
161+
triangle
162+
{
163+
<13.0, 16.5, 6.5>, <24.0, 16.5, 27.2>, <29.0, 16.5, 11.4>
164+
}
165+
triangle
166+
{
167+
<29.0, 0.0, 11.4>, <29.0, 16.5, 11.4>, <24.0, 16.5, 27.2>
168+
}
169+
triangle
170+
{
171+
<29.0, 0.0, 11.4>, <24.0, 16.5, 27.2>, <24.0, 0.0, 27.2>
172+
}
173+
triangle
174+
{
175+
<13.0, 0.0, 6.5>, <13.0, 16.5, 6.5>, <29.0, 16.5, 11.4>
176+
}
177+
triangle
178+
{
179+
<13.0, 0.0, 6.5>, <29.0, 16.5, 11.4>, <29.0, 0.0, 11.4>
180+
}
181+
triangle
182+
{
183+
<8.2, 0.0, 22.5>, <8.2, 16.5, 22.5>, <13.0, 16.5, 6.5>
184+
}
185+
triangle
186+
{
187+
<8.2, 0.0, 22.5>, <13.0, 16.5, 6.5>, <13.0, 0.0, 6.5>
188+
}
189+
triangle
190+
{
191+
<24.0, 0.0, 27.2>, <24.0, 16.5, 27.2>, <8.2, 16.5, 22.5>
192+
}
193+
triangle
194+
{
195+
<24.0, 0.0, 27.2>, <8.2, 16.5, 22.5>, <8.2, 0.0, 22.5>
196+
}
197+
texture
198+
{
199+
pigment
200+
{
201+
rgb <1, 1, 1>
202+
}
203+
finish
204+
{
205+
diffuse 0.75
206+
ambient 0
207+
}
208+
}
209+
}
210+
211+
union
212+
{
213+
triangle
214+
{
215+
<42.3, 33.0, 24.7>, <26.5, 33.0, 29.6>, <31.4, 33.0, 45.6>
216+
}
217+
triangle
218+
{
219+
<42.3, 33.0, 24.7>, <31.4, 33.0, 45.6>, <47.2, 33.0, 40.6>
220+
}
221+
triangle
222+
{
223+
<42.3, 0.0, 24.7>, <42.3, 33.0, 24.7>, <47.2, 33.0, 40.6>
224+
}
225+
triangle
226+
{
227+
<42.3, 0.0, 24.7>, <47.2, 33.0, 40.6>, <47.2, 0.0, 40.6>
228+
}
229+
triangle
230+
{
231+
<47.2, 0.0, 40.6>, <47.2, 33.0, 40.6>, <31.4, 33.0, 45.6>
232+
}
233+
triangle
234+
{
235+
<47.2, 0.0, 40.6>, <31.4, 33.0, 45.6>, <31.4, 0.0, 45.6>
236+
}
237+
triangle
238+
{
239+
<31.4, 0.0, 45.6>, <31.4, 33.0, 45.6>, <26.5, 33.0, 29.6>
240+
}
241+
triangle
242+
{
243+
<31.4, 0.0, 45.6>, <26.5, 33.0, 29.6>, <26.5, 0.0, 29.6>
244+
}
245+
triangle
246+
{
247+
<26.5, 0.0, 29.6>, <26.5, 33.0, 29.6>, <42.3, 33.0, 24.7>
248+
}
249+
triangle
250+
{
251+
<26.5, 0.0, 29.6>, <42.3, 33.0, 24.7>, <42.3, 0.0, 24.7>
252+
}
253+
texture
254+
{
255+
pigment
256+
{
257+
rgb <1, 1, 1>
258+
}
259+
finish
260+
{
261+
diffuse 0.75
262+
ambient 0
263+
}
264+
}
265+
}
266+

raytracing/cornell_box.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
"""
2+
cornell_box.py
3+
Object Orientated Cornell Box, some elements fudged by plain text copying mainly
4+
using a modified recipe (http://code.activestate.com/recipes/205451/ (r1)) as the
5+
interface
6+
"""
7+
from povwriter import *
8+
9+
LC ='LightColor=<1,0.67,0.21>;'
10+
N = 'N=3; //Divisions per side'
11+
DX = 'DX=13/N; //Dimensions of sub patches'
12+
DZ = 'DZ=10.5/N;'
13+
14+
SP = """SubPatch=
15+
light_source{
16+
<27.8,54.88,27.95>
17+
color LightColor*7
18+
area_light DX*x, DZ*z, 4, 4 jitter adaptive 0
19+
spotlight radius -90 falloff 90 tightness 1 point_at <27.8,0,27.95> //for cosine falloff
20+
fade_power 2 fade_distance (DX+DZ)/2
21+
}"""
22+
23+
I0 = 'i=0;#while (i<N)'
24+
J0 = ' j=0;#while (j<N)'
25+
UF = ' light_source{SubPatch translate<i*DX-(13-DX)/2,0,j*DZ-(10.5-DZ)/2>}'
26+
JE = ' j=j+1;#end'
27+
IE = 'i=i+1;#end'
28+
29+
class CornellBox(object):
30+
"""
31+
Cornell box mainly as an object, except for the lights which are bit complicated
32+
"""
33+
def __init__(self):
34+
self.scene = POVFile("cornell_box.pov", "colors.inc", "skies.inc")
35+
36+
self.cam = Camera(
37+
location = (27.8, 27.3, -80),
38+
direction = (0, 0, 1),
39+
up = (0, 1, 0),
40+
right = (-1, 0, 0),
41+
angle = 39.5
42+
)
43+
# light patch
44+
self.skylight = Box ((21.3, 54.87, 33.2), (34.3, 54.88, 22.7), 'no_shadow',
45+
Pigment(rgb = (1, 1, 1)), Finish(emission = 0.78, diffuse = 0))
46+
# Floor, Ceiling, Backwall
47+
self.cornell_box = Union(
48+
# Floor
49+
Triangle((55.28, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 55.92)),
50+
Triangle((55.28, 0.0, 0.0), (0.0, 0.0, 55.92), (54.96, 0.0, 55.92)),
51+
# Ceiling
52+
Triangle((55.60, 54.88, 0.0), (55.60, 54.88, 55.92), (0.0, 54.88, 55.92)),
53+
Triangle((55.60, 54.88, 0.0), (0.0, 54.88, 55.92), (0.0, 54.88, 0.0)),
54+
# Backwall
55+
Triangle((0.0, 54.88, 55.92), (55.60, 54.88, 55.92), (54.96, 0.0, 55.92)),
56+
Triangle((0.0, 54.88, 55.92), (54.96, 0.0, 55.92), (0.0, 0.0, 55.92)),
57+
Texture(Pigment(rgb = (1, 1, 1)), Finish(diffuse=0.75, ambient = 0))
58+
)
59+
60+
# Right wall
61+
self.right_wall = Union (
62+
Triangle((0.0, 54.88, 0.0), (0.0, 54.88, 55.92), (0.0, 0.0, 55.92)),
63+
Triangle((0.0, 54.88, 0.0), (0.0, 0.0, 55.92), (0.0, 0.0, 0.0)),
64+
Texture(Pigment(rgb = (0.025, 0.236, 0.025)), Finish(diffuse=0.75, ambient = 0))
65+
)
66+
67+
# Left wall
68+
self.left_wall = Union (
69+
Triangle((55.28, 0.0, 0.0), (54.96, 0.0, 55.92), (55.60, 54.88, 55.92)),
70+
Triangle((55.28, 0.0, 0.0), (55.60, 54.88, 55.92), (55.60, 54.88, 0.0)),
71+
Texture(Pigment(rgb = (0.57, 0.025, 0.025)), Finish(diffuse=0.75, ambient = 0))
72+
)
73+
74+
75+
self.short_box = Union (
76+
#Short block
77+
Triangle((13.00, 16.50, 6.50), (8.20, 16.50, 22.50), (24.00, 16.50, 27.20)),
78+
Triangle((13.00, 16.50, 6.50), (24.00, 16.50, 27.20), (29.00, 16.50, 11.40)),
79+
Triangle((29.00, 0.0, 11.40), (29.00, 16.50, 11.40), (24.00, 16.50, 27.20)),
80+
Triangle((29.00, 0.0, 11.40), (24.00, 16.50, 27.20), (24.00, 0.0, 27.20)),
81+
Triangle((13.00, 0.0, 6.50), (13.00, 16.50, 6.50), (29.00, 16.50, 11.40)),
82+
Triangle((13.00, 0.0, 6.50), (29.00, 16.50, 11.40), (29.00, 0.0, 11.40)),
83+
Triangle((8.20, 0.0, 22.50), (8.20, 16.50, 22.50), (13.00, 16.50, 6.50)),
84+
Triangle((8.20, 0.0, 22.50), (13.00, 16.50, 6.50), (13.00, 0.0, 6.50)),
85+
Triangle((24.00, 0.0, 27.20), (24.00, 16.50, 27.20), (8.20, 16.50, 22.50)),
86+
Triangle((24.00, 0.0, 27.20), (8.20, 16.50, 22.50), (8.20, 0.0, 22.50)),
87+
Texture(Pigment(rgb = (1, 1, 1)), Finish(diffuse=0.75, ambient = 0))
88+
89+
)
90+
91+
self.tall_box = Union (
92+
#Tall block
93+
Triangle((42.30, 33.00, 24.70), (26.50, 33.00, 29.60), (31.40, 33.00, 45.60)),
94+
Triangle((42.30, 33.00, 24.70), (31.40, 33.00, 45.60), (47.20, 33.00, 40.60)),
95+
Triangle((42.30, 0.0, 24.70), (42.30, 33.00, 24.70), (47.20, 33.00, 40.60)),
96+
Triangle((42.30, 0.0, 24.70), (47.20, 33.00, 40.60), (47.20, 0.0, 40.60)),
97+
Triangle((47.20, 0.0, 40.60), (47.20, 33.00, 40.60), (31.40, 33.00, 45.60)),
98+
Triangle((47.20, 0.0, 40.60), (31.40, 33.00, 45.60), (31.40, 0.0, 45.60)),
99+
Triangle((31.40, 0.0, 45.60), (31.40, 33.00, 45.60), (26.50, 33.00, 29.60)),
100+
Triangle((31.40, 0.0, 45.60), (26.50, 33.00, 29.60), (26.50, 0.0, 29.60)),
101+
Triangle((26.50, 0.0, 29.60), (26.50, 33.00, 29.60), (42.30, 33.00, 24.70)),
102+
Triangle((26.50, 0.0, 29.60), (42.30, 33.00, 24.70), (42.30, 0.0, 24.70)),
103+
Texture(Pigment(rgb = (1, 1, 1)), Finish(diffuse=0.75, ambient = 0))
104+
)
105+
106+
107+
def writePovray(self):
108+
self.scene.declare(LC)
109+
self.scene.declare(N)
110+
self.scene.declare(DX)
111+
self.scene.declare(DZ)
112+
self.scene.declare(SP)
113+
self.scene.declare(I0)
114+
self.scene.declare(J0)
115+
self.scene.unformatted(UF)
116+
self.scene.declare(JE)
117+
self.scene.declare(IE)
118+
self.scene.write(self.cam, self.skylight, self.cornell_box, self.right_wall, self.left_wall,
119+
self.short_box, self.tall_box)
120+
121+
122+
def main():
123+
myScene = CornellBox()
124+
myScene.writePovray()
125+
126+
if __name__ == "__main__":
127+
main()

raytracing/povwriter/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from povwriter import *

0 commit comments

Comments
 (0)