• Stars
    star
    472
  • Rank 90,714 (Top 2 %)
  • Language
    Python
  • License
    Other
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Photo-realistic 3D rendering with Python and POV-Ray

[logo]

Vapory

Vapory is a Python library to render photo-realistic 3D scenes with the free ray-tracing engine POV-Ray.

Here is how you would draw a purple sphere:

from vapory import *

camera = Camera( 'location', [0,2,-3], 'look_at', [0,1,2] )
light = LightSource( [2,4,-3], 'color', [1,1,1] )
sphere = Sphere( [0,1,2], 2, Texture( Pigment( 'color', [1,0,1] )))

scene = Scene( camera, objects= [light, sphere])
scene.render("purple_sphere.png", width=400, height=300)

Vapory enables to pipe the rendered images back into Python and integrates very well in the Python libraries ecosystem (see this blog post for examples)

Vapory is an open-source software originally written by Zulko, released under the MIT licence, and hosted on Github, where everyone is welcome to contribute or ask for support.

Installation

Vapory should work on any platform with Python 2.7+ or Python 3.

You first need to install POV-Ray. See here for the Windows binaries. For Linux/MacOS you must compile the source (tested on Ubuntu, it's easy).

If you have PIP installed you can :

(sudo) pip install vapory

If you have neither setuptools nor ez_setup installed the command above will fail, is this case type this before installing:

(sudo) pip install ez_setup

Vapory can also be installed manually by unzipping the source code in one directory and typing in a terminal:

(sudo) python setup.py install

Getting started

In Vapory you create a scene, and then render it:

from vapory import *

scene = Scene( camera = mycamera , # a Camera object
           objects= [light, sphere], # POV-Ray objects (items, lights)
           atmospheric = [fog], # Light-interacting objects
           included = ["colors.inc"]) # headers that POV-Ray may need

scene.render("my_scene.png", # output to a PNG image file
  width = 300, height=200, # in pixels. Determines the camera ratio.
  antialiasing = 0.01 # The nearer from zero, the more precise the image.
  quality=1) # quality=1 => no shadow/reflection, quality=10 is 'normal'

# passing 'ipython' as argument at the end of an IPython Notebook cell
# will display the picture in the IPython notebook.
scene.render('ipython', width=300, height=500)

# passing no 'file' arguments returns the rendered image as a RGB numpy array
image = scene.render(width=300, height=500)

Objects are defined by passing a list of arguments:

camera = Camera( 'location', [0,2,-3], 'look_at', [0,1,2] )

Keep in mind that this snippet will later be transformed into POV-Ray code by converting each argument to a string and placing them on different lines, to make a valid POV-Ray code

camera {
    location
    <0,1,0>
    look_at
    <0,0,0>
}

All the objects (Sphere, Box, Plane... with a few exceptions) work the same way. Therefore syntax of Vapory is the same as the syntax of POV-Ray. To learn how to use the different objects:

  • Have a look at the scenes in the examples folder
  • See the docstring of the different objects, which provides a basic example.
  • See the online POV-Ray documentation which will give you all the possible uses of each object (there can be many !). This documentation is easily accessible from Vapory, just type `Sphere.help(), Plane.help() etc., it will open it in your browser.
  • Finally, it is easy to find POV-Ray examples online and transcribe them back into Vapory.

Missing Features

For the moment a many features (Sphere, Fog, etc.) are implemented but not all of them (POV-Ray has a LOT of possible shapes and capabilities).

It is really easy to add new features, because they all basically do the same thing, are just empty classes. For instance here is how Camera is implemented:

class Camera(POVRayElement):
    """ Camera([type,]  'location', [x,y,z], 'look_at', [x,y,z]) """

Yep, that's all, but just the name of the class is sufficient for Vapory to understand that this will translate into POV-Ray code camera{...}. So in most case it shouldn't be difficult to create your own new feature. If you need a non-implemented feature to be included in the package, just open an issue or push a commit.

More Repositories

1

moviepy

Video editing with Python
Python
11,920
star
2

eagle.js

A hackable slideshow framework built with Vue.js
JavaScript
4,074
star
3

gizeh

Simple Vector Graphics for Python
Python
691
star
4

easyAI

Python artificial intelligence framework for games
Python
631
star
5

pianoputer

Use your computer keyboard as a "piano".
Python
321
star
6

picnic.py

Easy Python packages creation.
Python
256
star
7

twittcher

Python module to watch Twitter user pages or search-results.
Python
63
star
8

unroll

Python package for Piano roll transcription to sheet music
Python
57
star
9

eaglejs-demo

Demo slideshows for Eagle.js
Vue
44
star
10

Minimix

A minimalist sound mixer / instrument emulator written in python
Python
43
star
11

pompei

Mosaics generation from movie frames
Python
42
star
12

-sheet-music--Gerhswin-Limehouse-Nights

Sheet music transcription of a G. Gershwin Public Domain piano roll performance
LilyPond
27
star
13

ddeint

Scipy-based Delay Differential Equation (DDE) solver
Python
26
star
14

pianoputer.js

Javascript implementation of the Pianoputer. Right now, it's bad. Very bad.
JavaScript
24
star
15

gix

Create, share and remix GIFs online
Vue
21
star
16

vmfactory

The Viennese Maze Factory
Python
15
star
17

zulko.github.com

My personal blog on Github
HTML
12
star
18

gif-captioning-with-css

Let's add CSS animations to a GIF!
Vue
5
star
19

moviepy_matplotlib

For issue on matplotlib
Python
5
star
20

bricks_and_scissors

Blog on the computational side of synthetic biology and DNA manufacturing
HTML
4
star
21

--video-editing---Cup-Song-Covers-Mix

Source code for a video featuring 60 covers of the Cup Song
4
star
22

funsliders

Graphical sliders to manually explore any function's input
Python
4
star
23

pianola

A web MIDI piano player, built for roll transcription
Vue
3
star
24

dna_weaver_paper

Manuscript for DNA Weaver
TeX
3
star
25

kbmix

script-based / keyboard-controlled sound mixer
2
star
26

sheet-music--Gershwin-sweet-and-lowdown

Transcription of the Sweet and Lowdown piano roll by George Gershwin
LilyPond
2
star
27

sheet-music--hindustan

Piano transcription of "Hindustan" from a piano roll
LilyPond
2
star
28

-sheet-music--Romance-for-guitar

Piano arrangement of the Romance for guitar made famous by the movie Jeux Interdits
2
star
29

unroll-online

Web app for piano roll transcription
JavaScript
1
star
30

Web_tools

Python
1
star
31

FLOT-Demo

A FLOT.js demo
JavaScript
1
star
32

sheet-music--duet-for-the-right-hand

A little piano piece for the right hand alone (lilypond file)
LilyPond
1
star