-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSAC_Functions.py
More file actions
299 lines (245 loc) · 15.3 KB
/
SAC_Functions.py
File metadata and controls
299 lines (245 loc) · 15.3 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# ##### BEGIN GPL LICENSE BLOCK #####
#
# <Adds plenty of new features to Blenders camera and compositor>
# Copyright (C) <2023> <Kevin Lorengel>
#
# 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 3
# 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.
# Alternatively, see <https://www.gnu.org/licenses/>.
#
# ##### END GPL LICENSE BLOCK #####
import bpy
import os
import math
from .SAC_Settings import SAC_Settings
def load_effect_previews():
pcoll_effects = bpy.utils.previews.new()
my_icons_dir = os.path.join(os.path.dirname(__file__), "icons")
for item_type, _, _ in SAC_Settings.effect_types:
icon_path = os.path.join(my_icons_dir, f"{item_type}.png")
pcoll_effects.load(item_type, icon_path, 'IMAGE')
return pcoll_effects
def load_bokeh_previews():
pcoll_bokeh = bpy.utils.previews.new()
my_icons_dir = os.path.join(os.path.dirname(__file__), "bokeh")
for item_type, _ in SAC_Settings.bokeh_types:
icon_path = os.path.join(my_icons_dir, f"{item_type}.jpg")
pcoll_bokeh.load(item_type, icon_path, 'IMAGE')
return pcoll_bokeh
def load_filter_previews():
pcoll_filter = bpy.utils.previews.new()
my_icons_dir = os.path.join(os.path.dirname(__file__), "filters")
for item_type, _ in SAC_Settings.filter_types:
icon_path = os.path.join(my_icons_dir, f"{item_type}.png")
pcoll_filter.load(item_type, icon_path, 'IMAGE')
return pcoll_filter
def load_gradient_previews():
pcoll_gradient = bpy.utils.previews.new()
my_icons_dir = os.path.join(os.path.dirname(__file__), "gradients")
for item_type, _ in SAC_Settings.gradient_types:
icon_path = os.path.join(my_icons_dir, f"{item_type}.png")
pcoll_gradient.load(item_type, icon_path, 'IMAGE')
return pcoll_gradient
def enum_previews_from_directory_effects(self, context):
"""Dynamic list of available previews."""
enum_items = []
if context is None:
return enum_items
pcoll_effects = bpy.types.Scene.effect_previews
for i, (item_type, name, _) in enumerate(SAC_Settings.effect_types):
icon = pcoll_effects[item_type].icon_id
enum_items.append((item_type, name, "", icon, i))
return enum_items
def enum_previews_from_directory_bokeh(self, context):
"""Dynamic list of available previews."""
enum_items = []
if context is None:
return enum_items
pcoll_bokeh = bpy.types.Scene.bokeh_previews
for i, (item_type, name) in enumerate(SAC_Settings.bokeh_types):
icon = pcoll_bokeh[item_type].icon_id
enum_items.append((item_type, name, "", icon, i))
return enum_items
def enum_previews_from_directory_filter(self, context):
"""Dynamic list of available previews."""
enum_items = []
if context is None:
return enum_items
pcoll_filter = bpy.types.Scene.filter_previews
for i, (item_type, name) in enumerate(SAC_Settings.filter_types):
icon = pcoll_filter[item_type].icon_id
enum_items.append((item_type, name, "", icon, i))
return enum_items
def enum_previews_from_directory_gradient(self, context):
"""Dynamic list of available previews."""
enum_items = []
if context is None:
return enum_items
pcoll_gradient = bpy.types.Scene.gradient_previews
for i, (item_type, name) in enumerate(SAC_Settings.gradient_types):
icon = pcoll_gradient[item_type].icon_id
enum_items.append((item_type, name, "", icon, i))
return enum_items
def link_nodes(node_tree, node1, node1_output, node2, node2_input):
node_tree.links.new(node1.outputs[node1_output], node2.inputs[node2_input])
def load_image_once(image_path, image_name):
image = bpy.data.images.get(image_name)
if image is None:
image = bpy.data.images.load(image_path)
return image
def create_dot_texture():
texture = bpy.data.textures.get(".SAC Dot Screen")
if texture is None:
texture = bpy.data.textures.new(name=".SAC Dot Screen", type='MAGIC')
texture.noise_depth = 1 # Depth
texture.turbulence = 6.0 # Turbulence
texture.use_color_ramp = True
texture.color_ramp.interpolation = 'CONSTANT'
texture.color_ramp.elements[1].position = 0.65
def mute_update(self, context):
bpy.data.node_groups[".SAC Effects"].nodes[f"{self.EffectGroup}_{self.ID}"].mute = self.mute
def active_effect_update(self, context):
settings = context.scene.sac_settings
try:
item = context.scene.sac_effect_list[self.sac_effect_list_index]
except IndexError:
return
node_name = f"{item.EffectGroup}_{item.ID}"
node_group_name = f".{node_name}"
# Bokeh
if item.EffectGroup == "SAC_BOKEH":
settings.Effects_Bokeh_MaxSize = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Bokeh_Blur"].blur_max
settings.Effects_Bokeh_Range = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Bokeh_Range"].inputs[1].default_value
settings.Effects_Bokeh_Offset = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Bokeh_Offset"].inputs[1].default_value
settings.Effects_Bokeh_Rotation = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Bokeh_Rotation"].inputs[1].default_value
settings.Effects_Bokeh_Procedural_Flaps = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Bokeh_Procedural"].flaps
settings.Effects_Bokeh_Procedural_Angle = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Bokeh_Procedural"].angle
settings.Effects_Bokeh_Procedural_Rounding = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Bokeh_Procedural"].rounding
settings.Effects_Bokeh_Procedural_Catadioptric = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Bokeh_Procedural"].catadioptric
settings.Effects_Bokeh_Procedural_Shift = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Bokeh_Procedural"].shift
if bpy.data.node_groups[node_group_name].nodes["SAC Effects_Bokeh_Switch"].check == True:
settings.Effects_Bokeh_Type = "PROCEDURAL"
else:
if bpy.data.node_groups[node_group_name].nodes["SAC Effects_Bokeh_ImageSwitch"].check == True:
settings.Effects_Bokeh_Type = "CUSTOM"
else:
settings.Effects_Bokeh_Type = "CAMERA"
# Chromatic Aberration
elif item.EffectGroup == "SAC_CHROMATICABERRATION":
settings.Effects_ChromaticAberration_Amount = bpy.data.node_groups[node_group_name].nodes["SAC Effects_ChromaticAberration"].inputs[2].default_value
# Duotone
elif item.EffectGroup == "SAC_DUOTONE":
# Color 1
settings.Effects_Duotone_Color1[0] = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Duotone_Colors"].inputs[1].default_value[0]
settings.Effects_Duotone_Color1[1] = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Duotone_Colors"].inputs[1].default_value[1]
settings.Effects_Duotone_Color1[2] = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Duotone_Colors"].inputs[1].default_value[2]
# Color 2
settings.Effects_Duotone_Color2[0] = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Duotone_Colors"].inputs[2].default_value[0]
settings.Effects_Duotone_Color2[1] = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Duotone_Colors"].inputs[2].default_value[1]
settings.Effects_Duotone_Color2[2] = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Duotone_Colors"].inputs[2].default_value[2]
# Blend
settings.Effects_Duotone_Blend = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Duotone_Blend"].inputs[0].default_value
# Emboss
elif item.EffectGroup == "SAC_EMBOSS":
settings.Effects_Emboss_Strength = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Emboss"].inputs[0].default_value
# Film Grain
elif item.EffectGroup == "SAC_FILMGRAIN":
settings.Filmgrain_strength = bpy.data.node_groups[node_group_name].nodes["SAC Effects_FilmGrain_Strength"].inputs[0].default_value
settings.Filmgrain_dustproportion = bpy.data.node_groups[node_group_name].nodes["SAC Effects_FilmGrain_Blur"].sigma_color
settings.Filmgrain_size = bpy.data.node_groups[node_group_name].nodes["SAC Effects_FilmGrain_Blur"].iterations
# Fish Eye
elif item.EffectGroup == "SAC_FISHEYE":
settings.Effects_Fisheye = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Fisheye"].inputs[1].default_value
# Fog Glow
elif item.EffectGroup == "SAC_FOGGLOW":
settings.Effects_FogGlow_Strength = bpy.data.node_groups[node_group_name].nodes["SAC Effects_FogGlowStrength"].inputs[0].default_value
settings.Effects_FogGlow_Threshold = bpy.data.node_groups[node_group_name].nodes["SAC Effects_FogGlow"].threshold
settings.Effects_FogGlow_Size = bpy.data.node_groups[node_group_name].nodes["SAC Effects_FogGlow"].size
# Ghost
elif item.EffectGroup == "SAC_GHOST":
settings.Effects_Ghosts_Strength = bpy.data.node_groups[node_group_name].nodes["SAC Effects_GhostsStrength"].inputs[0].default_value
settings.Effects_Ghosts_Threshold = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Ghosts"].threshold
settings.Effects_Ghosts_Count = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Ghosts"].iterations
settings.Effects_Ghosts_Distortion = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Ghosts"].color_modulation
# Gradient Map
elif item.EffectGroup == "SAC_GRADIENTMAP":
settings.Effects_GradientMap_blend = bpy.data.node_groups[node_group_name].nodes["SAC Effects_GradientMap_Mix"].inputs[0].default_value
# Halftone
elif item.EffectGroup == "SAC_HALFTONE":
settings.Effects_Halftone_value = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Halftone_Value"].outputs[0].default_value
settings.Effects_Halftone_delta = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Halftone_Delta"].outputs[0].default_value
settings.Effects_Halftone_size = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Halftone_SizeSave"].outputs[0].default_value
# Infrared
elif item.EffectGroup == "SAC_INFRARED":
settings.Effects_Infrared_Blend = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Infrared_Mix"].inputs[0].default_value
settings.Effects_Infrared_Offset = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Infrared_Add"].inputs[1].default_value
# ISO Noise
elif item.EffectGroup == "SAC_ISONOISE":
settings.ISO_strength = bpy.data.node_groups[node_group_name].nodes["SAC Effects_ISO_Add"].inputs[0].default_value
settings.ISO_size = bpy.data.node_groups[node_group_name].nodes["SAC Effects_ISO_Despeckle"].inputs[0].default_value
# Mosaic
elif item.EffectGroup == "SAC_MOSAIC":
settings.Effects_Pixelate_PixelSize = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Pixelate_Size"].inputs[0].default_value
# Negative
elif item.EffectGroup == "SAC_NEGATIVE":
settings.Effects_Negative = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Negative"].inputs[0].default_value
# Overlay
elif item.EffectGroup == "SAC_OVERLAY":
settings.Effects_Overlay_Strength = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Overlay"].inputs[0].default_value
# Perspective Shift
elif item.EffectGroup == "SAC_PERSPECTIVESHIFT":
if bpy.data.node_groups[node_group_name].nodes["SAC Effects_PerspectiveShift_CornerPin"].inputs[1].default_value[0] > 0:
settings.Effects_PerspectiveShift_Horizontal = bpy.data.node_groups[node_group_name].nodes["SAC Effects_PerspectiveShift_CornerPin"].inputs[1].default_value[0] * 2
else:
settings.Effects_PerspectiveShift_Horizontal = -bpy.data.node_groups[node_group_name].nodes["SAC Effects_PerspectiveShift_CornerPin"].inputs[3].default_value[0] * 2
if bpy.data.node_groups[node_group_name].nodes["SAC Effects_PerspectiveShift_CornerPin"].inputs[3].default_value[1] > 0:
settings.Effects_PerspectiveShift_Vertical = bpy.data.node_groups[node_group_name].nodes["SAC Effects_PerspectiveShift_CornerPin"].inputs[3].default_value[1] * 2
else:
settings.Effects_PerspectiveShift_Vertical = -bpy.data.node_groups[node_group_name].nodes["SAC Effects_PerspectiveShift_CornerPin"].inputs[4].default_value[1] * 2
# Posterize
elif item.EffectGroup == "SAC_POSTERIZE":
settings.Effects_Posterize_Steps = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Posterize"].inputs[1].default_value
# Streaks
elif item.EffectGroup == "SAC_STREAKS":
settings.Effects_Streaks_Strength = bpy.data.node_groups[node_group_name].nodes["SAC Effects_StreaksStrength"].inputs[0].default_value
settings.Effects_Streaks_Threshold = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Streaks"].threshold
settings.Effects_Streaks_Count = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Streaks"].streaks
settings.Effects_Streaks_Length = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Streaks"].iterations
settings.Effects_Streaks_Fade = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Streaks"].fade
settings.Effects_Streaks_Angle = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Streaks"].angle_offset
settings.Effects_Streaks_Distortion = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Streaks"].color_modulation
# Vignette
elif item.EffectGroup == "SAC_VIGNETTE":
settings.Effects_Vignette_Intensity = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Viginette_Intensity"].inputs[0].default_value
settings.Effects_Vignette_Roundness = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Viginette_Roundness"].inputs[0].default_value
settings.Effects_Vignette_Feather = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Viginette_Directional_Blur"].zoom
settings.Effects_Vignette_Midpoint = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Viginette_Midpoint"].inputs[0].default_value
# Warp
elif item.EffectGroup == "SAC_WARP":
settings.Effects_Warp = bpy.data.node_groups[node_group_name].nodes["SAC Effects_Warp"].zoom
def frames_to_time(frames, fps):
frames_abs = math.ceil(abs(frames))
total_seconds = frames_abs // fps
minutes = total_seconds // 60
seconds = total_seconds % 60
excess_frames = int(frames_abs % fps)
if frames >= 0:
return f"{minutes:02}m:{seconds:02}s+{excess_frames:02}f"
return f"-{minutes:02}m:{seconds:02}s+{excess_frames:02}f"
def hex_to_rgb(value):
value = value.lstrip('#')
r = round(int(value[0:2], 16)/255, 3)
g = round(int(value[2:4], 16)/255, 3)
b = round(int(value[4:6], 16)/255, 3)
return (r, g, b, 1.0)