Skip to content

Commit 1cd6eef

Browse files
author
monkstone
committed
Replace union with Merge CornellBox
1 parent a46ff5a commit 1cd6eef

File tree

8 files changed

+184
-53
lines changed

8 files changed

+184
-53
lines changed

raytracing/BasicScene.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
cornell_box.py
3+
Author: Martin Prout September 2011, based on an original cornell.pov by Kari Kivisalo
4+
This O0 Cornell Box, uses 'raw' writing for more complicated PovRAY elements
5+
such as the non point light source, with a SubPatch.
6+
The povwriter module, a modified recipe (http://code.activestate.com/recipes/205451/ (r1))
7+
is the normal interface between python and PovRAY.
8+
"""
9+
10+
from povwriter import *
11+
12+
13+
14+
class BasicScene(object):
15+
"""
16+
Basic external scene
17+
Note the use of tuples to group scalar values for vector type
18+
"""
19+
def __init__(self, name, size):
20+
self.scene = POVFile(name, size, "colors.inc", "skies.inc")
21+
self.cam = Camera(location = (0, 2, -3), look_at = (0, 1, 2))
22+
self.sky = SkySphere("S_Cloud3")
23+
self.ground = Plane((0.0, 1.0, 0.0), 0.0,
24+
Texture(
25+
Pigment(color = "NeonBlue"),
26+
Finish(reflection = 0.15)
27+
)
28+
)
29+
self.light = LightSource( (2, 4, -3), color = "White")
30+
31+
def foreground(self):
32+
for i in xrange(4):
33+
self.scene.write(Sphere( ((i * 0.5), 0.25 + (i * 0.5), 2), 0.25,
34+
Texture(
35+
Pigment(
36+
color = "Yellow")
37+
)
38+
)
39+
)
40+
41+
42+
43+
def background(self):
44+
self.scene.write(self.cam, self.sky, self.light, self.ground)
45+
46+
def main():
47+
scene = BasicScene("basic_scene.pov", (800, 600))
48+
scene.background()
49+
scene.foreground()
50+
51+
if __name__ == "__main__":
52+
main()

raytracing/basic_scene.jpg

19.9 KB
Loading

raytracing/basic_scene.pov

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
// For PovRAY Version: 3.7 (includes radiosity)
66
// Date: September 2011
77
// Auth: Martin Prout
8-
// +width 800 +height 600 for basic_scene example
8+
9+
// width 800 height 600
10+
911
#version 3.7;
1012
global_settings{
1113
assumed_gamma 1.0
@@ -56,28 +58,51 @@ plane
5658
}
5759
}
5860

59-
triangle
61+
sphere
62+
{
63+
<0.0, 0.25, 2>, 0.25
64+
texture
65+
{
66+
pigment
67+
{
68+
color Yellow
69+
}
70+
}
71+
}
72+
73+
sphere
6074
{
61-
<0, 1, 2>, <1, 0, 1>, <0, 0, 0>
75+
<0.5, 0.75, 2>, 0.25
6276
texture
6377
{
6478
pigment
6579
{
66-
color Red
80+
color Yellow
81+
}
82+
}
83+
}
84+
85+
sphere
86+
{
87+
<1.0, 1.25, 2>, 0.25
88+
texture
89+
{
90+
pigment
91+
{
92+
color Yellow
6793
}
6894
}
6995
}
7096

71-
box
97+
sphere
7298
{
73-
<0, 1, 2>, <1, 0, 1>
99+
<1.5, 1.75, 2>, 0.25
74100
texture
75101
{
76102
pigment
77103
{
78104
color Yellow
79105
}
80106
}
81-
rotate <0, 10, 0>
82107
}
83108

raytracing/cornell_box.jpg

24 Bytes
Loading

raytracing/cornell_box.pov

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
// For PovRAY Version: 3.7 (includes radiosity)
66
// Date: September 2011
77
// Auth: Martin Prout
8-
// +width 800 +height 600 for basic_scene example
8+
9+
// width 300 height 300
10+
911
#version 3.7;
1012
global_settings{
1113
assumed_gamma 1.0
@@ -64,7 +66,7 @@ box
6466
}
6567
}
6668

67-
union
69+
merge
6870
{
6971
triangle
7072
{
@@ -104,7 +106,7 @@ union
104106
}
105107
}
106108

107-
union
109+
merge
108110
{
109111
triangle
110112
{
@@ -128,7 +130,7 @@ union
128130
}
129131
}
130132

131-
union
133+
merge
132134
{
133135
triangle
134136
{
@@ -152,7 +154,7 @@ union
152154
}
153155
}
154156

155-
union
157+
merge
156158
{
157159
triangle
158160
{
@@ -208,7 +210,7 @@ union
208210
}
209211
}
210212

211-
union
213+
merge
212214
{
213215
triangle
214216
{

raytracing/cornell_box.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
class CornellBox(object):
3333
"""
3434
Cornell box mainly as an object, except for the lights which are bit complicated
35+
300 x 300 is the default size, but we need to add the inc files here.
3536
"""
3637
def __init__(self):
3738
self.scene = POVFile("cornell_box.pov", (300, 300), "colors.inc", "skies.inc")
@@ -47,7 +48,7 @@ def __init__(self):
4748
self.skylight = Box ((21.3, 54.87, 33.2), (34.3, 54.88, 22.7), 'no_shadow',
4849
Pigment(rgb = (1, 1, 1)), Finish(emission = 0.78, diffuse = 0))
4950
# Floor, Ceiling, Backwall
50-
self.cornell_box = Union(
51+
self.cornell_box = Merge(
5152
# Floor
5253
Triangle((55.28, 0.0, 0.0), (0.0, 0.0, 0.0), (0.0, 0.0, 55.92)),
5354
Triangle((55.28, 0.0, 0.0), (0.0, 0.0, 55.92), (54.96, 0.0, 55.92)),
@@ -58,53 +59,52 @@ def __init__(self):
5859
Triangle((0.0, 54.88, 55.92), (55.60, 54.88, 55.92), (54.96, 0.0, 55.92)),
5960
Triangle((0.0, 54.88, 55.92), (54.96, 0.0, 55.92), (0.0, 0.0, 55.92)),
6061
Texture(Pigment(rgb = (1, 1, 1)), Finish(diffuse=0.75, ambient = 0))
61-
)
62+
)
6263

6364
# Right wall
64-
self.right_wall = Union (
65+
self.right_wall = Merge (
6566
Triangle((0.0, 54.88, 0.0), (0.0, 54.88, 55.92), (0.0, 0.0, 55.92)),
6667
Triangle((0.0, 54.88, 0.0), (0.0, 0.0, 55.92), (0.0, 0.0, 0.0)),
6768
Texture(Pigment(rgb = (0.025, 0.236, 0.025)), Finish(diffuse=0.75, ambient = 0))
6869
)
6970

7071
# Left wall
71-
self.left_wall = Union (
72+
self.left_wall = Merge (
7273
Triangle((55.28, 0.0, 0.0), (54.96, 0.0, 55.92), (55.60, 54.88, 55.92)),
7374
Triangle((55.28, 0.0, 0.0), (55.60, 54.88, 55.92), (55.60, 54.88, 0.0)),
7475
Texture(Pigment(rgb = (0.57, 0.025, 0.025)), Finish(diffuse=0.75, ambient = 0))
7576
)
7677

7778

78-
self.short_box = Union (
79-
#Short block
80-
Triangle((13.00, 16.50, 6.50), (8.20, 16.50, 22.50), (24.00, 16.50, 27.20)),
81-
Triangle((13.00, 16.50, 6.50), (24.00, 16.50, 27.20), (29.00, 16.50, 11.40)),
82-
Triangle((29.00, 0.0, 11.40), (29.00, 16.50, 11.40), (24.00, 16.50, 27.20)),
83-
Triangle((29.00, 0.0, 11.40), (24.00, 16.50, 27.20), (24.00, 0.0, 27.20)),
84-
Triangle((13.00, 0.0, 6.50), (13.00, 16.50, 6.50), (29.00, 16.50, 11.40)),
85-
Triangle((13.00, 0.0, 6.50), (29.00, 16.50, 11.40), (29.00, 0.0, 11.40)),
86-
Triangle((8.20, 0.0, 22.50), (8.20, 16.50, 22.50), (13.00, 16.50, 6.50)),
87-
Triangle((8.20, 0.0, 22.50), (13.00, 16.50, 6.50), (13.00, 0.0, 6.50)),
88-
Triangle((24.00, 0.0, 27.20), (24.00, 16.50, 27.20), (8.20, 16.50, 22.50)),
89-
Triangle((24.00, 0.0, 27.20), (8.20, 16.50, 22.50), (8.20, 0.0, 22.50)),
90-
Texture(Pigment(rgb = (1, 1, 1)), Finish(diffuse=0.75, ambient = 0))
91-
92-
)
79+
self.short_box = Merge (
80+
#Short block
81+
Triangle((13.00, 16.50, 6.50), (8.20, 16.50, 22.50), (24.00, 16.50, 27.20)),
82+
Triangle((13.00, 16.50, 6.50), (24.00, 16.50, 27.20), (29.00, 16.50, 11.40)),
83+
Triangle((29.00, 0.0, 11.40), (29.00, 16.50, 11.40), (24.00, 16.50, 27.20)),
84+
Triangle((29.00, 0.0, 11.40), (24.00, 16.50, 27.20), (24.00, 0.0, 27.20)),
85+
Triangle((13.00, 0.0, 6.50), (13.00, 16.50, 6.50), (29.00, 16.50, 11.40)),
86+
Triangle((13.00, 0.0, 6.50), (29.00, 16.50, 11.40), (29.00, 0.0, 11.40)),
87+
Triangle((8.20, 0.0, 22.50), (8.20, 16.50, 22.50), (13.00, 16.50, 6.50)),
88+
Triangle((8.20, 0.0, 22.50), (13.00, 16.50, 6.50), (13.00, 0.0, 6.50)),
89+
Triangle((24.00, 0.0, 27.20), (24.00, 16.50, 27.20), (8.20, 16.50, 22.50)),
90+
Triangle((24.00, 0.0, 27.20), (8.20, 16.50, 22.50), (8.20, 0.0, 22.50)),
91+
Texture(Pigment(rgb = (1, 1, 1)), Finish(diffuse=0.75, ambient = 0))
92+
)
9393

94-
self.tall_box = Union (
95-
#Tall block
96-
Triangle((42.30, 33.00, 24.70), (26.50, 33.00, 29.60), (31.40, 33.00, 45.60)),
97-
Triangle((42.30, 33.00, 24.70), (31.40, 33.00, 45.60), (47.20, 33.00, 40.60)),
98-
Triangle((42.30, 0.0, 24.70), (42.30, 33.00, 24.70), (47.20, 33.00, 40.60)),
99-
Triangle((42.30, 0.0, 24.70), (47.20, 33.00, 40.60), (47.20, 0.0, 40.60)),
100-
Triangle((47.20, 0.0, 40.60), (47.20, 33.00, 40.60), (31.40, 33.00, 45.60)),
101-
Triangle((47.20, 0.0, 40.60), (31.40, 33.00, 45.60), (31.40, 0.0, 45.60)),
102-
Triangle((31.40, 0.0, 45.60), (31.40, 33.00, 45.60), (26.50, 33.00, 29.60)),
103-
Triangle((31.40, 0.0, 45.60), (26.50, 33.00, 29.60), (26.50, 0.0, 29.60)),
104-
Triangle((26.50, 0.0, 29.60), (26.50, 33.00, 29.60), (42.30, 33.00, 24.70)),
105-
Triangle((26.50, 0.0, 29.60), (42.30, 33.00, 24.70), (42.30, 0.0, 24.70)),
106-
Texture(Pigment(rgb = (1, 1, 1)), Finish(diffuse=0.75, ambient = 0))
107-
)
94+
self.tall_box = Merge (
95+
#Tall block
96+
Triangle((42.30, 33.00, 24.70), (26.50, 33.00, 29.60), (31.40, 33.00, 45.60)),
97+
Triangle((42.30, 33.00, 24.70), (31.40, 33.00, 45.60), (47.20, 33.00, 40.60)),
98+
Triangle((42.30, 0.0, 24.70), (42.30, 33.00, 24.70), (47.20, 33.00, 40.60)),
99+
Triangle((42.30, 0.0, 24.70), (47.20, 33.00, 40.60), (47.20, 0.0, 40.60)),
100+
Triangle((47.20, 0.0, 40.60), (47.20, 33.00, 40.60), (31.40, 33.00, 45.60)),
101+
Triangle((47.20, 0.0, 40.60), (31.40, 33.00, 45.60), (31.40, 0.0, 45.60)),
102+
Triangle((31.40, 0.0, 45.60), (31.40, 33.00, 45.60), (26.50, 33.00, 29.60)),
103+
Triangle((31.40, 0.0, 45.60), (26.50, 33.00, 29.60), (26.50, 0.0, 29.60)),
104+
Triangle((26.50, 0.0, 29.60), (26.50, 33.00, 29.60), (42.30, 33.00, 24.70)),
105+
Triangle((26.50, 0.0, 29.60), (42.30, 33.00, 24.70), (42.30, 0.0, 24.70)),
106+
Texture(Pigment(rgb = (1, 1, 1)), Finish(diffuse=0.75, ambient = 0))
107+
)
108108

109109

110110
def writePovray(self):
@@ -119,7 +119,7 @@ def writePovray(self):
119119
self.scene.declare(JE)
120120
self.scene.declare(IE)
121121
self.scene.write(self.cam, self.skylight, self.cornell_box, self.right_wall, self.left_wall,
122-
self.short_box, self.tall_box)
122+
self.short_box, self.tall_box)
123123

124124

125125
def main():

raytracing/povwriter/BasicScene.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
cornell_box.py
3+
Author: Martin Prout September 2011, based on an original cornell.pov by Kari Kivisalo
4+
This O0 Cornell Box, uses 'raw' writing for more complicated PovRAY elements
5+
such as the non point light source, with a SubPatch.
6+
The povwriter module, a modified recipe (http://code.activestate.com/recipes/205451/ (r1))
7+
is the normal interface between python and PovRAY.
8+
"""
9+
10+
from povwriter import *
11+
12+
13+
14+
class BasicScene(object):
15+
"""
16+
Basic external scene
17+
Note the use of tuples to group scalar values for vector type
18+
"""
19+
def __init__(self, name, size):
20+
self.scene = POVFile(name, size, "colors.inc", "skies.inc")
21+
self.cam = Camera(location = (0, 2, -3), look_at = (0, 1, 2))
22+
self.sky = SkySphere("S_Cloud3")
23+
self.ground = Plane((0.0, 1.0, 0.0), 0.0,
24+
Texture(
25+
Pigment(color = "NeonBlue"),
26+
Finish(reflection = 0.15)
27+
)
28+
)
29+
self.sphere = Sphere( (0, 1, 2), 1,
30+
Texture(
31+
Pigment(
32+
color = "Yellow")
33+
)
34+
)
35+
self.light = LightSource( (2, 4, -3), color = "White")
36+
37+
def add_spheres(self):
38+
self.spheres = [10]
39+
for i in xrange(10):
40+
self.spheres[i] = Sphere( (0, i, 2), 1,
41+
Texture(
42+
Pigment(
43+
color = "Yellow")
44+
)
45+
)
46+
47+
48+
49+
def write_file(self):
50+
self.scene.write(self.cam, self.sky, self.light, self.ground, self.spheres)
51+
52+
def main():
53+
scene = BasicScene("basic_scene.pov", (800, 600))
54+
scene.write()

raytracing/povwriter/povwriter.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"""
55
__all__ = ['POVFile', 'Vector', 'Sphere', 'Box', 'Triangle', 'Pigment',
66
'Blob', 'Texture', 'Finish', 'Normal', 'Camera', 'LightSource', 'Torus',
7-
'Union', 'Intersection', 'Difference', 'SkySphere', 'Mesh', 'Plane']
7+
'Union', 'Intersection', 'Difference', 'SkySphere', 'Mesh', 'Plane',
8+
'Merge', 'Cylinder', 'Cone']
89
HEADER1 = """
9-
// Persistence Of Vision Ray Tracer Scene Description pov_fib
10-
// pov_fib: Generated by tracer.py
10+
// Persistence Of Vision Ray Tracer Scene Description pov_file
11+
// pov_file: Generated by tracer.py
1112
// tracer.py is based on http://code.activestate.com/recipes/205451/ (r1)
1213
// For PovRAY Version: 3.7 (includes radiosity)
1314
// Date: September 2011
@@ -28,9 +29,6 @@
2829
}
2930
"""
3031

31-
32-
33-
3432
class POVFile(object):
3533

3634
"""

0 commit comments

Comments
 (0)