forked from Ocupe/Projectors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
57 lines (45 loc) · 1.42 KB
/
helper.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
# Standard Lib imports
from random import uniform, random, uniform
# Blender imports
import bpy
import colorsys
FALLBACK_WARNING = 'Falling back to pre 2.8 Blender Python API: {}'
ADDON_ID = 'protor_{}'
def random_color(alpha=False):
""" Return a high contrast random color. """
h = random()
s = 1
v = 1
rgb = list(colorsys.hsv_to_rgb(h, s, v))
if alpha:
rgb.append(1)
return rgb
def get_projectors(context, only_selected=False):
""" Get all or only the selected projectors from the scene. """
objs = context.selected_objects if only_selected else context.scene.objects
projectors = []
for obj in objs:
if obj.type == 'CAMERA' and obj.name.startswith('Projector'):
if only_selected:
if obj.select_get():
projectors.append(obj)
else:
projectors.append(obj)
return projectors
def get_projector(context):
""" Return selected Projector or None if no projector is selected. """
projectors = get_projectors(context, only_selected=True)
if len(projectors) == 1:
return projectors[0]
else:
return None
def auto_offset():
offset = 0
def inner(node_width=None, y=None, gap=None):
nonlocal offset
offset += node_width if node_width else 0
y = y if y else 0
gap = gap if gap else 60
offset += gap
return offset, y
return inner