-
Notifications
You must be signed in to change notification settings - Fork 40
/
color_management_presets.py
136 lines (111 loc) · 4.51 KB
/
color_management_presets.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {"name": "Color Management Presets",
"description": "Presets support for Render > Color Management panel",
"author": "Jakub Uhlik",
"version": (0, 0, 1),
"blender": (2, 80, 0),
"location": "Properties > Render > Color Management",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "System", }
import os
import textwrap
import bpy
from bpy.types import Menu, Operator
from bpy.props import StringProperty
from bl_operators.presets import AddPresetBase
class CMP_MT_presets(Menu):
"""Color Management Presets List"""
bl_label = "Color Management Presets"
preset_subdir = "color_management"
preset_operator = "script.execute_preset"
draw = Menu.draw_preset
class CMP_OT_add(AddPresetBase, Operator):
"""Add / Remove Preset"""
bl_idname = 'color_management_presets.add'
bl_label = 'Add / Remove Preset'
preset_menu = 'CMP_MT_presets'
preset_subdir = 'color_management'
preset_defines = ['s = bpy.context.scene', ]
preset_values = ['s.display_settings.display_device',
's.view_settings.view_transform',
's.view_settings.exposure',
's.view_settings.gamma',
's.view_settings.look',
's.view_settings.use_curve_mapping',
's.sequencer_colorspace_settings.name', ]
def CMP_UI_draw(self, context, ):
l = self.layout
r = l.row(align=True)
r.menu('CMP_MT_presets', text=bpy.types.CMP_MT_presets.bl_label, )
r.operator('color_management_presets.add', text="", icon='ADD', )
r.operator('color_management_presets.add', text="", icon='REMOVE', ).remove_active = True
l.separator()
def default_presets():
d = {'filmic_high_contrast': ('sRGB', 'Filmic', 0.0, 1.0, 'Filmic - High Contrast', False, 'sRGB', ),
'filmic_medium_high_contrast': ('sRGB', 'Filmic', 0.0, 1.0, 'Filmic - Medium High Contrast', False, 'sRGB', ),
'standard': ('sRGB', 'Standard', 0.0, 1.0, 'None', False, 'sRGB', ), }
return d
def setup():
subdir = bpy.types.CMP_MT_presets.preset_subdir
path = os.path.join(bpy.utils.user_resource('SCRIPTS'), 'presets', subdir, )
preset_paths = bpy.utils.preset_paths(subdir)
if(path not in preset_paths):
if(not os.path.exists(path)):
os.makedirs(path)
preset_paths = bpy.utils.preset_paths(subdir)
found = []
for p in preset_paths:
files = [f for f in os.listdir(p) if os.path.isfile(os.path.join(p, f))]
for f in files:
if(f.endswith(".py")):
found.append(os.path.splitext(f)[0])
if(len(found) == 0):
d = default_presets()
t = textwrap.dedent('''\
import bpy
s = bpy.context.scene
s.display_settings.display_device = '{}'
s.view_settings.view_transform = '{}'
s.view_settings.exposure = {}
s.view_settings.gamma = {}
s.view_settings.look = '{}'
s.view_settings.use_curve_mapping = {}
s.sequencer_colorspace_settings.name = '{}'\
''')
for n, p in d.items():
s = t.format(*p)
with open(os.path.join(path, "{}.py".format(n)), mode='w', encoding='utf-8') as f:
f.write(s)
classes = (
CMP_MT_presets,
CMP_OT_add,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.RENDER_PT_color_management.prepend(CMP_UI_draw)
setup()
def unregister():
bpy.types.RENDER_PT_color_management.remove(CMP_UI_draw)
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()