-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcommon.py
More file actions
108 lines (79 loc) · 2.67 KB
/
Copy pathcommon.py
File metadata and controls
108 lines (79 loc) · 2.67 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import bpy, os
from mathutils import Color
possible_dir_names = {
'ypanel',
'ypanel-master',
'yPanel',
'yPanel-master'
}
blend_type_items = (("MIX", "Mix", ""),
("ADD", "Add", ""),
("SUBTRACT", "Subtract", ""),
("MULTIPLY", "Multiply", ""),
("SCREEN", "Screen", ""),
("OVERLAY", "Overlay", ""),
("DIFFERENCE", "Difference", ""),
("DIVIDE", "Divide", ""),
("DARKEN", "Darken", ""),
("LIGHTEN", "Lighten", ""),
("HUE", "Hue", ""),
("SATURATION", "Saturation", ""),
("VALUE", "Value", ""),
("COLOR", "Color", ""),
("SOFT_LIGHT", "Soft Light", ""),
("LINEAR_LIGHT", "Linear Light", ""))
def get_active_material():
scene = bpy.context.scene
engine = scene.render.engine
obj = bpy.context.object
if not obj: return None
mat = obj.active_material
if engine in {'BLENDER_RENDER', 'BLENDER_GAME'}:
if mat and mat.use_nodes:
mat = mat.active_node_material
return mat
def in_active_layer(obj):
scene = bpy.context.scene
space = bpy.context.space_data
if space.type == 'VIEW_3D' and space.local_view:
return any([layer for layer in obj.layers_local_view if layer])
else:
return any([layer for i, layer in enumerate(obj.layers) if layer and scene.layers[i]])
def get_addon_filepath():
sep = os.sep
# Search for addon dirs
roots = bpy.utils.script_paths()
for root in roots:
if os.path.basename(root) != 'scripts': continue
filepath = root + sep + 'addons'
dirs = next(os.walk(filepath))[1]
folders = [x for x in dirs if x in possible_dir_names]
if folders:
return filepath + sep + folders[0] + sep
return 'ERROR: No path found for yPanel!'
def srgb_to_linear_per_element(e):
if e <= 0.03928:
return e/12.92
else:
return pow((e + 0.055) / 1.055, 2.4)
def linear_to_srgb_per_element(e):
if e > 0.0031308:
return 1.055 * (pow(e, (1.0 / 2.4))) - 0.055
else:
return 12.92 * e
def srgb_to_linear(inp):
if type(inp) == float:
return srgb_to_linear_per_element(inp)
elif type(inp) == Color:
c = inp.copy()
for i in range(3):
c[i] = srgb_to_linear_per_element(c[i])
return c
def linear_to_srgb(inp):
if type(inp) == float:
return linear_to_srgb_per_element(inp)
elif type(inp) == Color:
c = inp.copy()
for i in range(3):
c[i] = linear_to_srgb_per_element(c[i])
return c