Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Little features and fixes (alpha mode and key arguments on objects) #36

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion vapory/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os

POVRAY_BINARY = ("povray.exe" if os.name=='nt' else "povray")
POVRAY_BINARY = os.environ.get('POVRAY_BINARY') or (
"povray.exe" if os.name == 'nt' else "povray"
)

GLOBAL_SCENE_SETTINGS = {
"charset" : "ascii",
Expand Down
7 changes: 6 additions & 1 deletion vapory/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def ppm_to_numpy(filename=None, buffer=None, byteorder='>'):

def render_povstring(string, outfile=None, height=None, width=None,
quality=None, antialiasing=None, remove_temp=True,
show_window=False, tempfile=None, includedirs=None):
show_window=False, tempfile=None, includedirs=None,
alpha=None, additional_args=None):

""" Renders the provided scene description with POV-Ray.

Expand Down Expand Up @@ -108,6 +109,10 @@ def render_povstring(string, outfile=None, height=None, width=None,
cmd.append('+L%s'%dir)
cmd.append("Output_File_Type=%s"%format_type)
cmd.append("+O%s"%outfile)
if alpha:
cmd.append("Output_Alpha=on")

cmd += additional_args or []
process = subprocess.Popen(cmd, stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
Expand Down
19 changes: 12 additions & 7 deletions vapory/vapory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import webbrowser # <= to open the POVRay help
from copy import deepcopy
from itertools import chain
import re
from .io import render_povstring

Expand Down Expand Up @@ -37,7 +38,7 @@ def __str__(self):
global_settings = ["global_settings{\n%s\n}"%("\n".join(
[str(e) for e in self.global_settings]))]
return '\n'.join([str(e)
for l in [included, declares, self.objects, [self.camera],
for l in [included, declares, defaults, self.objects, [self.camera],
self.atmospheric, global_settings]
for e in l])

Expand All @@ -50,15 +51,14 @@ def set_camera(self, new_camera):
return new

def add_objects(self, objs):

new = self.copy()
new.objects += objs
new.objects += objs
return new

def render(self, outfile=None, height=None, width=None,
quality=None, antialiasing=None, remove_temp=True,
auto_camera_angle=True, show_window=False, tempfile=None,
includedirs=None):
includedirs=None, alpha=None, additional_args=None):

""" Renders the scene to a PNG, a numpy array, or the IPython Notebook.

Expand All @@ -84,12 +84,17 @@ def render(self, outfile=None, height=None, width=None,

return render_povstring(str(self), outfile, height, width,
quality, antialiasing, remove_temp, show_window,
tempfile, includedirs)
tempfile, includedirs,
alpha=alpha,
additional_args=additional_args)


class POVRayElement:
def __init__(self, *args):
self.args = list(args)
def __init__(self, *args, **kwargs):
args = list(args)
# flat key arguments - Obj(value='x') -> Obj('value', 'x')
args += list(chain.from_iterable(kwargs.items()))
self.args = args

def copy(self):
return deepcopy(self)
Expand Down
2 changes: 1 addition & 1 deletion vapory/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.01"
__version__ = "0.1.02"