-
Notifications
You must be signed in to change notification settings - Fork 10
/
loom.py
6289 lines (5246 loc) · 246 KB
/
loom.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
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ##### 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 #####
import bpy
import re
import os
import errno
import subprocess
import blend_render_info
import rna_keymap_ui
import webbrowser
from bpy.app.handlers import persistent
from bpy_extras.io_utils import ImportHelper, ExportHelper
from bl_operators.presets import AddPresetBase
from bl_ui.utils import PresetPanel
from contextlib import suppress
from numpy import arange, around, isclose
from itertools import count, groupby
from time import strftime
from sys import platform
bl_info = {
"name": "Loom",
"description": "Image sequence rendering, encoding and playback",
"author": "Christian Brinkmann (p2or)",
"version": (0, 9, 4),
"blender": (3, 6, 0),
"doc_url": "https://github.com/p2or/blender-loom",
"tracker_url": "https://github.com/p2or/blender-loom/issues",
"support": "COMMUNITY",
"category": "Render"
}
# -------------------------------------------------------------------
# Helper
# -------------------------------------------------------------------
def filter_frames(frame_input, increment=1, filter_individual=False):
""" Filter frame input & convert it to a set of frames """
def float_filter(st):
try:
return float(st)
except ValueError:
return None
def int_filter(flt):
try:
return int(flt) if flt.is_integer() else None
except ValueError:
return None
numeric_pattern = r"""
[\^\!]? \s*? # Exclude option
[-+]? # Negative or positive number
(?:
# Range & increment 1-2x2, 0.0-0.1x.02
(?: \d* \.? \d+ \s? \- \s? \d* \.? \d+ \s? [x%] \s? [-+]? \d* \.? \d+ )
|
# Range 1-2, 0.0-0.1 etc
(?: \d* \.? \d+ \s? \- \s? [-+]? \d* \.? \d+ )
|
# .1 .12 .123 etc 9.1 etc 98.1 etc
(?: \d* \. \d+ )
|
# 1. 12. 123. etc 1 12 123 etc
(?: \d+ \.? )
)
"""
range_pattern = r"""
([-+]? \d*? \.? [0-9]+ \b) # Start frame
(\s*? \- \s*?) # Minus
([-+]? \d* \.? [0-9]+) # End frame
( (\s*? [x%] \s*? )( [-+]? \d* \.? [0-9]+ \b ) )? # Increment
"""
exclude_pattern = r"""
[\^\!] \s*? # Exclude option
([-+]? \d* \.? \d+)$ # Int or Float
"""
rx_filter = re.compile(numeric_pattern, re.VERBOSE)
rx_group = re.compile(range_pattern, re.VERBOSE)
rx_exclude = re.compile(exclude_pattern, re.VERBOSE)
input_filtered = rx_filter.findall(frame_input)
if not input_filtered: return None
""" Option to add a ^ or ! at the beginning to exclude frames """
if not filter_individual:
first_exclude_item = next((i for i, v in enumerate(input_filtered) if "^" in v or "!" in v), None)
if first_exclude_item:
input_filtered = input_filtered[:first_exclude_item] + \
[elem if elem.startswith(("^", "!")) else "^" + elem.lstrip(' ') \
for elem in input_filtered[first_exclude_item:]]
""" Find single values as well as all ranges & compile frame list """
frame_list, exclude_list, conform_list = [], [], []
conform_flag = False
for item in input_filtered:
frame = float_filter(item)
if frame is not None: # Single floats
frame_list.append(frame)
if conform_flag: conform_list.append(frame)
else: # Ranges & items to exclude
exclude_item = rx_exclude.search(item)
range_item = rx_group.search(item)
if exclude_item: # Single exclude items like ^-3 or ^10
exclude_list.append(float_filter(exclude_item.group(1)))
if filter_individual: conform_flag = True
elif range_item: # Ranges like 1-10, 20-10, 1-3x0.1, ^2-7 or ^-3--1
start = min(float_filter(range_item.group(1)), float_filter(range_item.group(3)))
end = max(float_filter(range_item.group(1)), float_filter(range_item.group(3)))
step = increment if not range_item.group(4) else float_filter(range_item.group(6))
if start < end: # Build the range & add all items to list
frame_range = around(arange(start, end, step), decimals=5).tolist()
if item.startswith(("^", "!")):
if filter_individual: conform_flag = True
exclude_list.extend(frame_range)
if isclose(step, (end - frame_range[-1])):
exclude_list.append(end)
else:
frame_list.extend(frame_range)
if isclose(step, (end - frame_range[-1])):
frame_list.append(end)
if conform_flag:
conform_list.extend(frame_range)
if isclose(step, (end - frame_range[-1])):
conform_list.append(end)
elif start == end: # Not a range, add start frame
if not item.startswith(("^", "!")):
frame_list.append(start)
else:
exclude_list.append(start)
if filter_individual:
exclude_list = sorted(set(exclude_list).difference(conform_list))
float_frames = sorted(set(frame_list).difference(exclude_list))
""" Return integers whenever possible """
int_frames = [int_filter(frame) for frame in float_frames]
return float_frames if None in int_frames else int_frames
def version_number(file_path, number, delimiter="_", min_lead=2):
"""Replace or add a version string by given number"""
match = re.search(r'v(\d+)', file_path)
if match:
g = match.group(1)
n = str(int(number)).zfill(len(g))
return file_path.replace(match.group(0), "v{v}".format(v=n))
else:
lead_zeros = str(int(number)).zfill(min_lead)
version = "{dl}v{lz}{dl}".format(dl=delimiter, lz=lead_zeros)
ext = (".png",".jpg",".jpeg","jpg",".exr",".dpx",".tga",".tif",".tiff",".cin")
if "#" in file_path:
dash = file_path.find("#")
head, tail = file_path[:dash], file_path[dash:]
if head.endswith(delimiter):
head = head.rstrip(delimiter)
return "{h}{v}{t}".format(h=head, v=version, t=tail)
elif file_path.endswith(ext):
head, extension = os.path.splitext(file_path)
if head.endswith(delimiter):
head = head.rstrip(delimiter)
return "{fp}{v}{ex}".format(fp=head, v=version[:-1], ex=extension)
else:
if file_path.endswith(delimiter):
file_path = file_path.rstrip(delimiter)
return "{fp}{v}".format(fp=file_path, v=version)
def render_version(self, context):
context.area.tag_redraw()
scene = context.scene
render = scene.render
""" Replace the render path """
render.filepath = version_number(
render.filepath,
scene.loom.output_render_version)
""" Replace file output """
if not scene.render.use_compositing or \
not scene.loom.output_sync_comp or \
not scene.node_tree:
return
output_nodes = [n for n in scene.node_tree.nodes if n.type=='OUTPUT_FILE']
for out_node in output_nodes:
""" Set base path only """
if "LAYER" in out_node.format.file_format:
out_node.base_path = version_number(
out_node.base_path,
scene.loom.output_render_version)
else:
""" Set the base path """
out_node.base_path = version_number(
out_node.base_path,
scene.loom.output_render_version)
""" Set all slots """
for out_file in out_node.file_slots:
out_file.path = version_number(
out_file.path,
scene.loom.output_render_version)
return None
def isevaluable(s):
try:
eval(s)
return True
except:
return False
def replace_globals(s, debug=False):
"""Replace string by given global entries"""
vars = bpy.context.preferences.addons[__name__].preferences.global_variable_coll
for key, val in vars.items():
if not debug:
if key.startswith("$") and not key.isspace():
if val.expr and not val.expr.isspace():
if isevaluable(val.expr):
s = s.replace(key, str(eval(val.expr)))
else:
s = s.replace(key, "NO-{}".format(key.replace("$", "")))
else:
print (key, val, val.expr)
return s
def user_globals(context):
"""Determine whether globals used in the scene"""
scn = context.scene
vars = context.preferences.addons[__name__].preferences.global_variable_coll
if any(ext in scn.render.filepath for ext in vars.keys()):
return True
if scn.use_nodes and len(scn.node_tree.nodes) > 0:
tree = scn.node_tree
nodes = (n for n in tree.nodes if n.type=='OUTPUT_FILE')
for node in nodes:
if any(ext in node.base_path for ext in vars.keys()):
return True
if "LAYER" in node.format.file_format:
for slot in node.layer_slots:
if any(ext in slot.name for ext in vars.keys()):
return True
else:
for slot in node.file_slots:
if any(ext in slot.path for ext in vars.keys()):
return True
return False
# -------------------------------------------------------------------
# Preferences & Scene Properties
# -------------------------------------------------------------------
class LOOM_PG_globals(bpy.types.PropertyGroup):
# name: bpy.props.StringProperty()
expr: bpy.props.StringProperty(name="Python Expression")
class LOOM_UL_globals(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
split = layout.split(factor=0.2)
eval_icon = 'FILE_SCRIPT' if isevaluable(item.expr) else 'ERROR'
var_icon = 'RADIOBUT_ON' if item.name.startswith("$") else 'RADIOBUT_OFF'
split.prop(item, "name", text="", emboss=False, translate=False, icon=var_icon)
split.prop(item, "expr", text="", emboss=True, translate=False, icon=eval_icon)
def invoke(self, context, event):
pass
class LOOM_PG_project_directories(bpy.types.PropertyGroup):
# name: bpy.props.StringProperty()
creation_flag: bpy.props.BoolProperty()
class LOOM_UL_directories(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
split = layout.split(factor=0.05)
split.label(text="{:02d}".format(index+1))
row = split.row(align=True)
row.prop(item, "name", text="", icon='FILE_FOLDER') # emboss=False
row.prop(item, "creation_flag", text="", icon='RADIOBUT_ON' if item.creation_flag else 'RADIOBUT_OFF')#, emboss=False)
def invoke(self, context, event):
pass
class LOOM_AP_preferences(bpy.types.AddonPreferences):
bl_idname = __name__
terminal: bpy.props.EnumProperty(
name="Terminal",
items=(
("win-default", "Windows Default Terminal", "", 1),
("osx-default", "OSX Default Terminal", "", 2),
("x-terminal-emulator", "X Terminal Emulator", "", 3),
("xfce4-terminal", "Xfce4 Terminal", "", 4),
("xterm", "xterm", "", 5)))
xterm_flag: bpy.props.BoolProperty(
name="Use Xterm (Terminal Fallback)",
description="Serves as fallback for OSX and others",
default=False)
bash_file: bpy.props.StringProperty(
name="Bash file",
description = "Filepath to temporary bash or bat file")
bash_flag: bpy.props.BoolProperty(
name="Force Bash File",
description="Force using bash file instead of individual arguments",
default=False)
render_dialog_width: bpy.props.IntProperty(
name="Render Dialog Width",
description = "Width of Image Sequence Render Dialog",
subtype='PIXEL',
default=450, min=400)
encode_dialog_width: bpy.props.IntProperty(
name="Encoding/Rename Dialog Width",
description = "Width of Encoding and Rename Dialog",
subtype='PIXEL',
default=650, min=400)
project_dialog_width: bpy.props.IntProperty(
name="Project Dialog Width",
description = "Width of Project Dialog",
subtype='PIXEL',
default=650, min=400)
timeline_extensions: bpy.props.BoolProperty(
name="Timeline Extensions",
description="Do not display Loom operators in the Timeline",
default=False)
output_extensions: bpy.props.BoolProperty(
name="Output Panel Extensions",
description="Do not display all File Output nodes and the final Output Path in the Output Panel",
default=False)
log_render: bpy.props.BoolProperty(
name="Logging (Required for Playback)",
description="If enabled render output properties will be saved",
default=True)
log_render_limit: bpy.props.IntProperty(
name="Log Limit",
default=3)
playblast_flag: bpy.props.BoolProperty(
name="Playblast (Experimental)",
description="Playback rendered sequences",
default=False)
user_player: bpy.props.BoolProperty(
name="Default Animation Player",
description="Use default player (User Preferences > File Paths)",
default=False)
ffmpeg_path: bpy.props.StringProperty(
name="FFmpeg Binary",
description="Path to ffmpeg",
maxlen=1024,
subtype='FILE_PATH')
snapshot_directory: bpy.props.StringProperty(
name="Snapshot Directory",
description="Path of the Snapshot directory",
maxlen=1024,
default="//temp",
subtype='DIR_PATH')
default_codec: bpy.props.StringProperty(
name="User Codec",
description = "Default user codec")
batch_dialog_width: bpy.props.IntProperty(
name="Batch Dialog Width",
description="Width of Batch Render Dialog",
subtype='PIXEL',
default=750, min=600, max=1800)
batch_dialog_rows: bpy.props.IntProperty(
name="Number of Rows",
description="Number of Rows",
min=7, max=40,
default=9)
batch_paths_flag: bpy.props.BoolProperty(
name="Display File Paths",
description="Display File paths")
batch_path_col_width: bpy.props.FloatProperty(
name="Path Column Width",
description="Width of path column in list",
default=0.6, min=0.3, max=0.8)
batch_name_col_width: bpy.props.FloatProperty(
name="Name Column Width",
description="Width of name column in list",
default=0.45, min=0.3, max=0.8)
render_background: bpy.props.BoolProperty(
name="Render in Background",
description="Do not activate the Console",
default=False)
global_variable_coll: bpy.props.CollectionProperty(
name="Global Variables",
type=LOOM_PG_globals)
global_variable_idx: bpy.props.IntProperty(
name="Index",
default=0)
expression: bpy.props.StringProperty(
name="Expression",
description = "Test Expression",
options={'SKIP_SAVE'})
project_directory_coll: bpy.props.CollectionProperty(
name="Project Folders",
type=LOOM_PG_project_directories)
project_coll_idx: bpy.props.IntProperty(
name="Index",
default=0)
render_presets_path: bpy.props.StringProperty(
subtype = "FILE_PATH",
default = bpy.utils.user_resource(
'SCRIPTS',
path=os.path.join("presets", "loom", "render_presets")))
render_display_type: bpy.props.EnumProperty(
name="Render Display Type",
description="Location where rendered images will be displayed to",
items=[ ('NONE', "Keep User Interface", ""),
('AREA', "Image Editor", ""),
('WINDOW', "New Window", "")
],
default='WINDOW'
)
display_general: bpy.props.BoolProperty(
default=True)
display_globals: bpy.props.BoolProperty(
default=False)
display_directories: bpy.props.BoolProperty(
default=False)
display_presets: bpy.props.BoolProperty(
default=False)
display_advanced: bpy.props.BoolProperty(
default=False)
display_hotkeys: bpy.props.BoolProperty(
default=True)
def draw_state(self, prop):
return 'RADIOBUT_OFF' if not prop else 'RADIOBUT_ON'
def draw(self, context):
split_width = 0.5
layout = self.layout
""" General """
box_general = layout.box()
row = box_general.row()
row.prop(self, "display_general",
icon="TRIA_DOWN" if self.display_general else "TRIA_RIGHT",
icon_only=True, emboss=False)
row.label(text="General")
if self.display_general:
split = box_general.split(factor=split_width)
col = split.column()
col.prop(self, "render_dialog_width")
col.prop(self, "batch_dialog_width")
col = split.column()
col.prop(self, "project_dialog_width")
col.prop(self, "encode_dialog_width")
split = box_general.split(factor=split_width)
col = split.column()
col.prop(self, "timeline_extensions", toggle=True, icon=self.draw_state(not self.timeline_extensions))
col.prop(self, "output_extensions", toggle=True, icon=self.draw_state(not self.output_extensions))
col = split.column()
col.prop(self, "playblast_flag", toggle=True, icon=self.draw_state(self.playblast_flag))
upl = col.column()
upl.prop(self, "user_player", toggle=True, icon=self.draw_state(self.user_player))
upl.enabled = self.playblast_flag
box_general.row().prop(self, "ffmpeg_path")
box_general.row()
""" Globals """
box_globals = layout.box()
row = box_globals.row()
row.prop(self, "display_globals",
icon="TRIA_DOWN" if self.display_globals else "TRIA_RIGHT",
icon_only=True, emboss=False)
row.label(text="Globals (File Output)")
if self.display_globals:
row = box_globals.row()
row.template_list(
listtype_name = "LOOM_UL_globals",
list_id = "",
dataptr = self,
propname = "global_variable_coll",
active_dataptr = self,
active_propname = "global_variable_idx",
rows=6)
col = row.column(align=True)
col.operator(LOOM_OT_globals_ui.bl_idname, icon='ADD', text="").action = 'ADD'
col.operator(LOOM_OT_globals_ui.bl_idname, icon='REMOVE', text="").action = 'REMOVE'
col.separator()
col.operator("wm.save_userpref", text="", icon="CHECKMARK")
#row = box_globals.row()
#row.operator("wm.save_userpref", text="Save Globals", icon="CHECKMARK")
col.separator()
exp_box = box_globals.box()
row = exp_box.row()
row.label(text='Expression Tester')
row = exp_box.row()
split = row.split(factor=0.2)
split.label(text="Expression:", icon='FILE_SCRIPT')
split.prop(self, "expression", text="")
if not self.expression or self.expression.isspace():
eval_info = "Nothing to evaluate"
else:
eval_info = eval(self.expression) if isevaluable(self.expression) else "0"
row = exp_box.row()
split = row.split(factor=0.2)
split.label(text="Result:", icon='FILE_VOLUME')
split.label(text="{}".format(eval_info))
box_globals.row()
""" Project Directories """
box_dirs = layout.box()
row = box_dirs.row()
row.prop(self, "display_directories",
icon="TRIA_DOWN" if self.display_directories else "TRIA_RIGHT",
icon_only=True, emboss=False)
row.label(text="Project Directories")
if self.display_directories:
row = box_dirs.row()
row.template_list(
listtype_name = "LOOM_UL_directories",
list_id = "",
dataptr = self,
propname = "project_directory_coll",
active_dataptr = self,
active_propname = "project_coll_idx",
rows=6)
col = row.column(align=True)
col.operator(LOOM_OT_directories_ui.bl_idname, icon='ADD', text="").action = 'ADD'
col.operator(LOOM_OT_directories_ui.bl_idname, icon='REMOVE', text="").action = 'REMOVE'
box_dirs.row()
""" Advanced """
box_advanced = layout.box()
row = box_advanced.row()
row.prop(self, "display_advanced",
icon="TRIA_DOWN" if self.display_advanced else "TRIA_RIGHT",
icon_only=True, emboss=False)
row.label(text="Advanced Settings")
if self.display_advanced:
split = box_advanced.split(factor=split_width)
lft = split.column() # Left
fsh = lft.column(align=True)
txt = "Force generating .bat file" if platform.startswith('win32') else "Force generating .sh file"
lft.prop(self, "bash_flag", text=txt, toggle=True, icon=self.draw_state(self.bash_flag))
rsh = lft.row(align=True)
txt = "Delete temporary .bat Files" if platform.startswith('win32') else "Delete temporary .sh files"
rsh.operator(LOOM_OT_delete_bash_files.bl_idname, text=txt, icon="FILE_SCRIPT")
script_folder = bpy.utils.script_path_user()
rsh.operator(LOOM_OT_open_folder.bl_idname, icon="DISK_DRIVE", text="").folder_path = script_folder
rgt = split.column() # Right
rbg = rgt.column(align=True)
rbg.prop(self, "render_background", toggle=True, icon=self.draw_state(self.render_background))
rgt.column(align=True)
xtm = rgt.row(align=True)
xtm.prop(self, "xterm_flag", toggle=True, icon=self.draw_state(self.xterm_flag))
wp = xtm.operator(LOOM_OT_openURL.bl_idname, icon='HELP', text="")
wp.description = "Open the Wikipedia page about Xterm"
wp.url = "https://en.wikipedia.org/wiki/Xterm"
""" Linux/OSX specific properties """
#if not platform.startswith('win32'):
# rsh.enabled = False
""" OSX specific properties """
if platform.startswith('darwin'):
fsh.enabled = False
rbg.enabled = True
box_advanced.row()
box_advanced.row().prop(self, "snapshot_directory")
box_advanced.row()
""" Hotkeys """
box_hotkeys = layout.box()
row = box_hotkeys.row()
row.prop(self, "display_hotkeys",
icon="TRIA_DOWN" if self.display_hotkeys else "TRIA_RIGHT",
icon_only=True, emboss=False)
row.label(text="Hotkeys")
if self.display_hotkeys:
split = box_hotkeys.split()
col = split.column()
kc_usr = bpy.context.window_manager.keyconfigs.user
km_usr = kc_usr.keymaps.get('Screen')
if not user_keymap_ids: # Ouch, Todo!
for kmi_usr in km_usr.keymap_items:
for km_addon, kmi_addon in addon_keymaps:
if kmi_addon.compare(kmi_usr):
user_keymap_ids.append(kmi_usr.id)
for kmi_usr in km_usr.keymap_items: # user hotkeys by namespace
if kmi_usr.idname.startswith("loom."):
col.context_pointer_set("keymap", km_usr)
rna_keymap_ui.draw_kmi([], kc_usr, km_usr, kmi_usr, col, 0)
box_hotkeys.row()
""" Reset Prefs """
layout.operator(LOOM_OT_preferences_reset.bl_idname, icon='RECOVER_LAST')
class LOOM_OT_preferences_reset(bpy.types.Operator):
"""Reset Add-on Preferences"""
bl_idname = "loom.reset_preferences"
bl_label = "Reset Loom Preferences"
bl_options = {"INTERNAL"}
def execute(self, context):
prefs = context.preferences.addons[__name__].preferences
props = prefs.__annotations__.keys()
for p in props:
prefs.property_unset(p)
""" Restore Globals """
for key, value in global_var_defaults.items():
gvi = prefs.global_variable_coll.add()
gvi.name = key
gvi.expr = value
""" Project Directories """
for key, value in project_directories.items():
di = prefs.project_directory_coll.add()
di.name = value
di.creation_flag = True
""" Restore default keys by keymap ids """
kc_usr = context.window_manager.keyconfigs.user
km_usr = kc_usr.keymaps.get('Screen')
for i in user_keymap_ids:
kmi = km_usr.keymap_items.from_id(i)
if kmi:
km_usr.restore_item_to_default(kmi)
return {'FINISHED'}
class LOOM_OT_globals_ui(bpy.types.Operator):
"""Move global variables up and down, add and remove"""
bl_idname = "loom.globals_action"
bl_label = "Global Actions"
bl_options = {'REGISTER', 'INTERNAL'}
action: bpy.props.EnumProperty(
items=(
('REMOVE', "Remove", ""),
('ADD', "Add", "")))
def invoke(self, context, event):
prefs = context.preferences.addons[__name__].preferences
idx = prefs.global_variable_idx
try:
item = prefs.global_variable_coll[idx]
except IndexError:
pass
else:
if self.action == 'REMOVE':
info = 'Item "%s" removed from list' % (prefs.global_variable_coll[idx].name)
prefs.global_variable_idx -= 1
prefs.global_variable_coll.remove(idx)
if prefs.global_variable_idx < 0: prefs.global_variable_idx = 0
self.report({'INFO'}, info)
if self.action == 'ADD':
item = prefs.global_variable_coll.add()
prefs.global_variable_idx = len(prefs.global_variable_coll)-1
info = '"%s" added to list' % (item.name)
self.report({'INFO'}, info)
return {"FINISHED"}
class LOOM_OT_directories_ui(bpy.types.Operator):
"""Move items up and down, add and remove"""
bl_idname = "loom.directory_action"
bl_label = "Directory Actions"
bl_options = {'REGISTER', 'INTERNAL'}
action: bpy.props.EnumProperty(
items=(
('REMOVE', "Remove", ""),
('ADD', "Add", "")))
def invoke(self, context, event):
prefs = context.preferences.addons[__name__].preferences
idx = prefs.project_coll_idx
try:
item = prefs.project_directory_coll[idx]
except IndexError:
pass
else:
if self.action == 'REMOVE':
info = 'Item "%s" removed from list' % (prefs.project_directory_coll[idx].name)
prefs.project_coll_idx -= 1
prefs.project_directory_coll.remove(idx)
if prefs.project_coll_idx < 0: prefs.project_coll_idx = 0
if self.action == 'ADD':
item = prefs.project_directory_coll.add()
item.creation_flag = True
prefs.project_coll_idx = len(prefs.project_directory_coll)-1
return {"FINISHED"}
def render_preset_callback(scene, context):
items = [('EMPTY', "Current Render Settings", "")]
preset_path = context.preferences.addons[__name__].preferences.render_presets_path
if os.path.exists(preset_path):
for f in os.listdir(preset_path):
if not f.startswith(".") and f.endswith(".py"):
fn, ext = os.path.splitext(f)
#d = bpy.path.display_name(os.path.join(rndr_presets_path, f))
items.append((f, "'{}' Render Preset".format(fn), ""))
return items
class LOOM_PG_render(bpy.types.PropertyGroup):
# name: bpy.props.StringProperty()
render_id: bpy.props.IntProperty()
start_time: bpy.props.StringProperty()
start_frame: bpy.props.StringProperty()
end_frame: bpy.props.StringProperty()
file_path: bpy.props.StringProperty()
padded_zeros: bpy.props.IntProperty()
image_format: bpy.props.StringProperty()
class LOOM_PG_batch_render(bpy.types.PropertyGroup):
# name: bpy.props.StringProperty()
rid: bpy.props.IntProperty()
path: bpy.props.StringProperty()
frame_start: bpy.props.IntProperty()
frame_end: bpy.props.IntProperty()
scene: bpy.props.StringProperty()
frames: bpy.props.StringProperty(name="Frames")
encode_flag: bpy.props.BoolProperty(default=False)
input_filter: bpy.props.BoolProperty(default=False)
class LOOM_PG_preset_flags(bpy.types.PropertyGroup):
include_engine_settings: bpy.props.BoolProperty(
name="Engine Settings", # Currently not exposed to the user
description="Store 'Render Engine' settings",
default=True)
include_resolution: bpy.props.BoolProperty(
name="Resolution",
description="Store current 'Format' settings")
include_output_path: bpy.props.BoolProperty(
name="Output Path",
description="Store current 'Output Path'")
include_file_format: bpy.props.BoolProperty(
name="File Format",
description="Store current 'File Format' settings")
include_scene_settings: bpy.props.BoolProperty(
name="Scene Settings",
description="Store current 'Scene' settings")
include_passes: bpy.props.BoolProperty(
name="Passes",
description="Store current 'Passes' settings")
include_color_management: bpy.props.BoolProperty(
name="Color Management",
description="Store current 'Color Management' settings")
include_metadata: bpy.props.BoolProperty(
name="Metadata",
description="Store current 'Metadata' settings")
include_post_processing: bpy.props.BoolProperty(
name="Post Processing", # Currently not exposed to the user
description="Store current 'Post Processing' settings",
default=True)
class LOOM_PG_slots(bpy.types.PropertyGroup):
# name: bpy.props.StringPropery()
orig: bpy.props.StringProperty()
repl: bpy.props.StringProperty()
class LOOM_PG_paths(bpy.types.PropertyGroup):
# name: bpy.props.StringPropery()
id: bpy.props.IntProperty()
orig: bpy.props.StringProperty()
repl: bpy.props.StringProperty()
slts: bpy.props.CollectionProperty(name="Slot Collection", type=LOOM_PG_slots)
class LOOM_PG_scene_settings(bpy.types.PropertyGroup):
frame_input: bpy.props.StringProperty(
name="Frames to render",
description="Specify a range or single frames to render")
filter_input: bpy.props.BoolProperty(
name="Filter individual elements",
description="Isolate numbers after exclude chars (^, !)",
default=False)
command_line: bpy.props.BoolProperty(
name="Render using Command Line",
description="Send frames to command line (background process)",
default=False)
is_rendering: bpy.props.BoolProperty(
name="Render Flag",
description="Determine whether Loom is rendering",
default=False)
override_render_settings: bpy.props.BoolProperty(
name="Override render settings",
description="Force to render with specified settings",
default=False)
threads: bpy.props.IntProperty(
name="CPU Threads",
description="Number of CPU threads to use simultaneously while rendering",
min=1)
sequence_encode: bpy.props.StringProperty(
name="Image Sequence",
description="Image sequence to encode",
maxlen=1024)
movie_path: bpy.props.StringProperty(
name="Movie",
description="Movie file output path",
maxlen=1024)
sequence_rename: bpy.props.StringProperty(
name="Sequence Name",
description="New sequence name for renaming",
maxlen=1024)
lost_frames: bpy.props.StringProperty(
name="Missing Frames",
description="Missing Frames of the given sequence",
default="",
options={'SKIP_SAVE'})
render_collection: bpy.props.CollectionProperty(
name="Render Collection",
type=LOOM_PG_render)
batch_scan_folder: bpy.props.StringProperty(
name="Folder",
description="Folder to search for .blend files",
maxlen=1024)
batch_render_idx: bpy.props.IntProperty(
name="Collection Index",
description="Collection Index")
batch_render_coll: bpy.props.CollectionProperty(
name="Batch Render Collection",
type=LOOM_PG_batch_render)
output_render_version: bpy.props.IntProperty(
name = "Render Version",
description="Change the given version number within the output path",
default=1,
min=1,
update=render_version)
output_sync_comp: bpy.props.BoolProperty(
name="Sync Compositor",
description="Keep version number of all file output nodes in sync",
default=True)
comp_image_settings: bpy.props.BoolProperty(
name="Display Image Settings",
description="Display image settings of each file output node",
default=False)
project_directory: bpy.props.StringProperty(
name="Project Directory",
description="Stores the path to the project directory",
maxlen=1024)
path_collection: bpy.props.CollectionProperty(
name="Globals Path Collection",
type=LOOM_PG_paths)
scene_selection: bpy.props.BoolProperty(
name="Limit by Object Selection",
description="Only add keyframes assigned to the object(s) in selection",
default=False)
ignore_scene_range: bpy.props.BoolProperty(
name="Ignore Scene Range",
description="Do not consider the frame range of the scene",
default=False)
all_markers_flag: bpy.props.BoolProperty(
name="All Markers",
description="Add all markers to the list",
default=False)
render_preset_flags: bpy.props.PointerProperty(
type=LOOM_PG_preset_flags)
custom_render_presets: bpy.props.EnumProperty(
name="Render Preset",
description="Select a custom render preset",
items=render_preset_callback,
options={'SKIP_SAVE'})
meta_note: bpy.props.StringProperty(
name="Note",
description="Stores the value of the stamp note")
flipbook_flag: bpy.props.BoolProperty(
name="Render Flipbook",
description="Render the contents of the viewport",
default=False,
options={'SKIP_SAVE'})
# -------------------------------------------------------------------
# UI Operators
# -------------------------------------------------------------------
class LOOM_OT_render_threads(bpy.types.Operator):
"""Set all available threads"""
bl_idname = "loom.available_threads"
bl_label = "Reset Threads"
bl_options = {'INTERNAL'}