I messed around with POV-ray a bit about five years ago and recently tried to resurrect some of that code.
There's a recipe for a POV-ray - Python API by Simon Burton out on ActiveState that I wanted to try.
Here is the shape I was trying to re-create with the Python API:
Literally, an Easter egg, a bit involved, but not overly complex. The egg shape is borrowed from Friedrich Lohmüller's POV-ray site.
There is a simple example in the API which I've slightly modified to make a partially lit sphere:
# renamed recipe as pypov
import pypov as pov
file = pov.File('test2.pov', 'colors.inc')
cam = pov.Camera(location = (0, 1, -5), look_at = (0, -0.5, 2))
sphere = pov.Sphere((0, 0, 0), 1.5, pov.Texture(pov.Pigment(color = 'Blue')))
light = pov.LightSource((2, 4, -3), color = 'White')
file.write(cam, sphere, light)
This, after its output is run through POV-ray, yields this:
It won't win any animation awards, but it's pretty nonetheless.
The code for Lohmüller's egg shape looks like this:
# renamed recipe as pypov
import pypov as pov
file = pov.File('test3.pov', 'colors.inc')
cam = pov.Camera(location = (0, 1, -5), look_at = (0, -0.5, 2))
sphereupper = pov.Sphere((0, 0, 0), 1.0, pov.Texture(pov.Pigment(color = 'Blue')), scale = (1, 1.55, 1))
slabupper = pov.Box((-1, -1.55, -1), (1, 0, 1))
diffupper = pov.Difference(sphereupper, slabupper)
spherelower = pov.Sphere((0, 0, 0), 1.0, pov.Texture(pov.Pigment(color = 'Blue')), scale = (1, 1.15, 1))
slablower = pov.Box((-1, 0, -1), (1, 1.15, 1))
difflower = pov.Difference(spherelower, slablower)
union = pov.Union(difflower, diffupper, translate = (0, 0.55, 0), scale = 1.0)
light = pov.LightSource((2, 4, -3), color = 'White')
light2 = pov.LightSource((-2, -4, -3), color = 'White')
file.write(cam, union, light, light2)
and the output looks like this:
That is about as far as I got with the Python API. The problems I was having were related to trying to shoehorn my POV-ray code into the API. I added an Object class for the purpose of assigning attributes to predefined shapes. The problem there is that you can't use the same keyword more than once (translate, then rotate, then translate again).
Going forward I plan to work with simpler shapes (merging two parts instead of 50 or so). Also, I'll need to leverage what the API offers against working within its limitations. It will not be a one to one code translation between POV-ray and Python.
No comments:
Post a Comment