forked from apertus-open-source-cinema/elmyra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
89 lines (60 loc) · 2.51 KB
/
common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""Utility methods to ensure dependencies, setup defaults, remove, append ..."""
from os import path
import json
import bpy
from addon_utils import check
LIBRARY_PATH = path.join(path.dirname(__file__), "lib", "elmyra")
def append_from_library(blend, directory, item):
blend_exp = "{0}.blend".format(blend)
# TODO: Which of the two now? Also: relative path without a reference location?
# filepath = "//" + path.join(blend_exp, directory, '')
filepath = path.join(LIBRARY_PATH, blend_exp, directory, '')
filename = item
directory = path.join(LIBRARY_PATH, blend_exp, directory, '')
bpy.ops.wm.append(filepath=filepath,
directory=directory,
filename=filename,
autoselect=False)
def ensure_addons():
# TODO: Persist addons being enabled as user settings (otherwise overhead!)
for addon in ('blend4web', 'render_freestyle_svg'):
is_enabled, is_loaded = check(addon)
if not is_enabled:
bpy.ops.wm.addon_enable(module=addon)
def get_view3d_context():
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
context = bpy.context.copy()
context['area'] = area
return context
def platform_library():
platform_library_path = 'library.json'
if path.exists(platform_library_path):
with open(platform_library_path) as file:
return json.loads(file.read())
else:
print("Platform library not found")
def remove_object(name):
bpy.ops.object.select_all(action="DESELECT")
bpy.data.objects[name].select = True
bpy.ops.object.delete()
def open_scene(blend_path):
bpy.ops.wm.open_mainfile(filepath=blend_path)
def empty_scene():
for obj in ["Cube", "Lamp", "Camera"]:
remove_object(obj)
def setup_scene_defaults():
bpy.context.scene.render.engine = "CYCLES"
bpy.context.scene.cycles.min_bounces = 1
bpy.context.scene.cycles.max_bounces = 2
bpy.context.scene.cycles.preview_samples = 12
bpy.context.scene.render.image_settings.file_format = 'PNG'
bpy.context.scene.render.image_settings.color_mode = 'RGBA'
bpy.context.scene.render.image_settings.compression = 0
bpy.context.scene.cycles.film_transparent = True
bpy.context.scene.use_nodes = True
# Multisampling for HDRI Lighting
bpy.context.scene.world.cycles.sample_as_light = True
bpy.context.scene.world.cycles.sample_map_resolution = 2048
for mat in bpy.data.materials:
mat.use_nodes = True