-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path__init__.py
4543 lines (4091 loc) · 187 KB
/
__init__.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 blf
import mathutils
import os
import glob
import gpu
from gpu_extras.batch import batch_for_shader
from math import pi
from bpy_extras.io_utils import ImportHelper, ExportHelper
from bpy_extras.image_utils import load_image
import bpy.utils.previews
bl_info = {
"name": "VSE Quick Titling",
"description": "Enables easy creation of simple title scenes in the VSE",
"author": "Hudson Barkley (Snu)",
"version": (0, 6, 5),
"blender": (4, 0, 0),
"location": "Sequencer Panels",
"wiki_url": "https://github.com/snuq/QuickTitling",
"category": "Sequencer"
}
animations = [
{
'name': 'Fade In And Out',
'variable': 'Alpha',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': 0,
'out_amount': 0,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'Random Flicker',
'variable': 'Alpha',
'animate_in': False,
'animate_out': False,
'in_length': 0,
'out_length': 0,
'in_offset': 0,
'out_offset': 0,
'in_amount': 0,
'out_amount': 0,
'cycle_x_scale': 0.1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'RANDOM'
},
{
'name': 'SPACER'
},
{
'name': 'X Slide From Right',
'variable': 'X Slide',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': 2,
'out_amount': 2,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'X Slide From Left',
'variable': 'X Slide',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': -2,
'out_amount': -2,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'X Cycle Slide Across',
'variable': 'X Slide',
'animate_in': False,
'animate_out': False,
'in_length': 0,
'out_length': 0,
'in_offset': 0,
'out_offset': 0,
'in_amount': 0,
'out_amount': 0,
'cycle_x_scale': 2,
'cycle_y_scale': 2,
'cycle_offset': 0,
'cycle_type': 'TANGENT'
},
{
'name': 'Y Slide Up And Down',
'variable': 'Y Slide',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': -1,
'out_amount': -1,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'Y Slide Down And Up',
'variable': 'Y Slide',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': 1,
'out_amount': 1,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'Y Cycle Slide Up',
'variable': 'Y Slide',
'animate_in': False,
'animate_out': False,
'in_length': 0,
'out_length': 0,
'in_offset': 0,
'out_offset': 0,
'in_amount': 0,
'out_amount': 0,
'cycle_x_scale': 2,
'cycle_y_scale': 2,
'cycle_offset': 0,
'cycle_type': 'TANGENT'
},
{
'name': 'Z Slide Forward And Back',
'variable': 'Z Slide',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': -2,
'out_amount': -2,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'Z Slide Back And Forward',
'variable': 'Z Slide',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': 2,
'out_amount': 2,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'Z Cycle Slide Forward',
'variable': 'Z Slide',
'animate_in': False,
'animate_out': False,
'in_length': 0,
'out_length': 0,
'in_offset': 0,
'out_offset': 0,
'in_amount': 0,
'out_amount': 0,
'cycle_x_scale': 2,
'cycle_y_scale': 2,
'cycle_offset': 0,
'cycle_type': 'TANGENT'
},
{
'name': 'SPACER'
},
{
'name': 'X Tilt Forward And Back',
'variable': 'X Rotate',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': -90,
'out_amount': -90,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'X Tilt Backward And Forward',
'variable': 'X Rotate',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': 90,
'out_amount': 90,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'X Tilt Wobble',
'variable': 'X Rotate',
'animate_in': False,
'animate_out': False,
'in_length': 0,
'out_length': 0,
'in_offset': 0,
'out_offset': 0,
'in_amount': 0,
'out_amount': 0,
'cycle_x_scale': 2,
'cycle_y_scale': 2,
'cycle_offset': 0,
'cycle_type': 'SINE'
},
{
'name': 'Y Turn Forward And Back',
'variable': 'Y Rotate',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': -90,
'out_amount': -90,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'Y Turn Backward And Forward',
'variable': 'Y Rotate',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': 90,
'out_amount': 90,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'Y Turn Wobble',
'variable': 'Y Rotate',
'animate_in': False,
'animate_out': False,
'in_length': 0,
'out_length': 0,
'in_offset': 0,
'out_offset': 0,
'in_amount': 0,
'out_amount': 0,
'cycle_x_scale': 2,
'cycle_y_scale': 2,
'cycle_offset': 0,
'cycle_type': 'SINE'
},
{
'name': 'Z Spin Forward And Back',
'variable': 'Z Rotate',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': 90,
'out_amount': 90,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'Z Spin Backward And Forward',
'variable': 'Z Rotate',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': -90,
'out_amount': -90,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'Z Spin Wobble',
'variable': 'Z Rotate',
'animate_in': False,
'animate_out': False,
'in_length': 0,
'out_length': 0,
'in_offset': 0,
'out_offset': 0,
'in_amount': 0,
'out_amount': 0,
'cycle_x_scale': 2,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'SINE'
},
{
'name': 'SPACER'
},
{
'name': 'Width Grow And Shrink',
'variable': 'Width',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': 0,
'out_amount': 0,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'Width Random Cycle',
'variable': 'Width',
'animate_in': False,
'animate_out': False,
'in_length': 0,
'out_length': 0,
'in_offset': 0,
'out_offset': 0,
'in_amount': 0,
'out_amount': 0,
'cycle_x_scale': 2,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'RANDOM'
},
{
'name': 'Height Grow And Shrink',
'variable': 'Height',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': 0,
'out_amount': 0,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'Height Random Cycle',
'variable': 'Height',
'animate_in': False,
'animate_out': False,
'in_length': 0,
'out_length': 0,
'in_offset': 0,
'out_offset': 0,
'in_amount': 0,
'out_amount': 0,
'cycle_x_scale': 2,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'RANDOM'
},
{
'name': 'Depth Grow And Shrink',
'variable': 'Depth',
'animate_in': True,
'animate_out': True,
'in_length': 15,
'out_length': 15,
'in_offset': 0,
'out_offset': 0,
'in_amount': 0,
'out_amount': 0,
'cycle_x_scale': 1,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'NONE'
},
{
'name': 'Depth Random Cycle',
'variable': 'Depth',
'animate_in': False,
'animate_out': False,
'in_length': 0,
'out_length': 0,
'in_offset': 0,
'out_offset': 0,
'in_amount': 0,
'out_amount': 0,
'cycle_x_scale': 2,
'cycle_y_scale': 1,
'cycle_offset': 0,
'cycle_type': 'RANDOM'
}
]
quicktitle_previews = bpy.utils.previews.new()
current_icon_id = 0
overlays = None
overlay_info = ''
keymap = None
def deselect_sequencer(context):
for sequence in context.scene.sequence_editor.sequences_all:
sequence.select = False
def find_load_image(path, load=True):
abs_path = bpy.path.abspath(path)
for image in bpy.data.images:
if bpy.path.abspath(image.filepath) == abs_path:
return image
if load:
return load_image(path)
else:
return None
def object_at_location(scene, x, y):
#Casts a ray from the camera to the given coordinates and returns the first object in that direction, or None
oldscene = bpy.context.window.scene
bpy.context.window.scene = scene #Since blender doesnt want to cast the ray properly while in another scene... bah.
camera = scene.camera
#since blender doesnt detect curve objects... go through and make low-poly copies of all curves, then delete them. bah.
title_copies = []
for title_object in scene.objects:
if title_object.type in ['CURVE', 'FONT']:
scale = title_object.scale
location = title_object.location
rotation = title_object.rotation_euler
old_resolution_u = title_object.data.resolution_u
old_bevel_resolution = title_object.data.bevel_resolution
title_object.data.resolution_u = 2
title_object.data.bevel_resolution = 0
#mesh = title_object.to_mesh(preserve_all_data_layers=True, depsgraph=bpy.context.view_layer.depsgraph)
mesh = bpy.data.meshes.new_from_object(title_object, preserve_all_data_layers=True, depsgraph=bpy.context.view_layer.depsgraph)
ob = bpy.data.objects.new(mesh.name+' Raycast', mesh)
scene.collection.objects.link(ob)
ob.scale = scale
ob.location = location
ob.rotation_euler = rotation
title_copies.append([mesh, ob, title_object])
title_object.data.resolution_u = old_resolution_u
title_object.data.bevel_resolution = old_bevel_resolution
direction = (mathutils.Vector((x, y, 0)) - camera.location).normalized()
bpy.context.view_layer.depsgraph.update()
data = scene.ray_cast(scene.view_layers[0].depsgraph, camera.location, direction)
if data[0]:
match_object = data[4]
else:
match_object = None
for copy in title_copies:
mesh, ob, title_object = copy
if data[0]:
if data[4] == ob:
match_object = title_object
scene.collection.objects.unlink(ob)
bpy.data.objects.remove(ob)
bpy.data.meshes.remove(mesh)
bpy.context.view_layer.depsgraph.update()
bpy.context.window.scene = oldscene
return match_object
def draw_line(sx, sy, ex, ey, width, color=(1.0, 1.0, 1.0, 1.0)):
del width
coords = [(sx, sy), (ex, ey)]
shader = gpu.shader.from_builtin('UNIFORM_COLOR')
batch = batch_for_shader(shader, 'LINES', {'pos': coords})
shader.bind()
shader.uniform_float('color', color)
batch.draw(shader)
def draw_text(x, y, size, text, color=(1.0, 1.0, 1.0, 1.0)):
font_id = 0
blf.color(font_id, *color)
blf.position(font_id, x, y, 0)
blf.size(font_id, size)
blf.draw(font_id, text)
def draw_box(left, bottom, right, top, color=(1.0, 1.0, 0.0, 1.0)):
coords = [(left, bottom), (left, top), (left, top), (right, top), (right, top), (right, bottom), (right, bottom), (left, bottom)]
shader = gpu.shader.from_builtin('UNIFORM_COLOR')
batch = batch_for_shader(shader, 'LINES', {'pos': coords})
shader.bind()
shader.uniform_float('color', color)
batch.draw(shader)
def add_overlay(self=None, context=None):
global overlays
if not overlays:
overlays = bpy.types.SpaceSequenceEditor.draw_handler_add(quicktitling_overlay, (), 'PREVIEW', 'POST_PIXEL')
add_keymap()
quicktitling_overlay()
def quicktitling_overlay():
quicktitle_sequence = titling_scene_selected()
if not quicktitle_sequence:
global overlays
global overlay_info
if overlays:
bpy.types.SpaceSequenceEditor.draw_handler_remove(overlays, 'PREVIEW')
overlays = None
remove_keymap()
else:
frame = bpy.context.scene.frame_current
if frame >= quicktitle_sequence.frame_final_start and frame <= quicktitle_sequence.frame_final_end:
area = bpy.context.area
space = area.spaces[0]
if space.display_mode == 'IMAGE':
scene = quicktitle_sequence.scene
preset = scene.quicktitler.current_quicktitle
try:
title_object_preset = preset.objects[preset.selected_object]
title_object_name = title_object_preset.internal_name
title_object = scene.objects[title_object_name]
except:
title_object = None
if title_object:
#Ensures that the title scene's frame is set to the viewed frame in the vse, needed for clicking title objects. Needs to be put here to give blender a chance to update the scene before a click.
new_frame = bpy.context.scene.frame_current - quicktitle_sequence.frame_start
if scene.frame_current != new_frame:
scene.frame_set(int(round(new_frame)))
for region in area.regions:
if region.type == 'PREVIEW':
break
view = region.view2d
min_x = title_object_preset.bbleft
max_x = title_object_preset.bbright
min_y = title_object_preset.bbbottom
max_y = title_object_preset.bbtop
left, bottom = view.view_to_region(min_x, min_y, clip=False)
right, top = view.view_to_region(max_x, max_y, clip=False)
if title_object_preset.type == 'TEXT' and title_object_preset.word_wrap:
#display text bounding box
camera_width = scene.render.resolution_x
wrap_width_per = title_object_preset.wrap_width
wrap_x_per = title_object_preset.x
wrap_width = wrap_width_per * camera_width
wrap_x = (wrap_x_per * (camera_width / 2)) - (wrap_width / 2)
w_left, very_bottom = view.view_to_region(wrap_x, 0, clip=False)
w_right, very_bottom = view.view_to_region(wrap_x + wrap_width, 0, clip=False)
draw_box(w_left, bottom, w_right, top, color=(.5, .5, 0, 1))
draw_box(left, bottom, right, top)
draw_text(10, 10, 15, overlay_info)
def clamp(x, minimum, maximum):
return max(minimum, min(x, maximum))
def update_bounds(title_object, title_object_preset, title_scene, scale_multiplier, pos_multiplier):
camera = title_scene.camera
camera_x = bpy.context.scene.render.resolution_x
camera_y = bpy.context.scene.render.resolution_y
bounds = camera_view_bounds_2d(title_scene, camera, title_object, title_object_preset, camera_x, camera_y, scale_multiplier, pos_multiplier)
title_object_preset.bbleft = bounds[0]
title_object_preset.bbbottom = bounds[1]
title_object_preset.bbright = bounds[2]
title_object_preset.bbtop = bounds[3]
def generate_matrix_world(ob, ob_preset):
scale_matrix = mathutils.Matrix.Scale(ob.scale[0], 4, (1, 0, 0)) @ mathutils.Matrix.Scale(ob.scale[1], 4, (0, 1, 0)) @ mathutils.Matrix.Scale(ob.scale[2], 4, (0, 0, 1))
rotation_matrix = mathutils.Matrix.Rotation(ob.rotation_euler[0], 4, 'X') @ mathutils.Matrix.Rotation(ob.rotation_euler[1], 4, 'Y') @ mathutils.Matrix.Rotation(ob.rotation_euler[2], 4, 'Z')
rotation_matrix.invert()
if ob_preset.type == 'CIRCLE':
#position is incorrect for circles... why??
loc_mult = 2.83
location_matrix = mathutils.Matrix.Translation((ob.location[0] * loc_mult, ob.location[1] * loc_mult, ob.location[2] * loc_mult))
else:
location_matrix = mathutils.Matrix.Translation(ob.location)
matrix = location_matrix @ scale_matrix @ rotation_matrix
return matrix
def camera_view_bounds_2d(scene, camera, title_object, title_object_preset, camera_x, camera_y, scale_multiplier, pos_multiplier):
if title_object.type == 'MESH':
#forget about the bounding box and just use the mesh itself
bbox = title_object.data.vertices
elif title_object.type == 'FONT':
#well what do you know, this bounding box actually works correctly!
bbox = title_object.bound_box
else:
#use the curve points
bbox = title_object.data.splines[0].points
xs = []
ys = []
#matrix = title_object.matrix_world
matrix = generate_matrix_world(title_object, title_object_preset)
for vert in bbox:
if title_object.type != 'FONT':
vert = vert.co
transformed_vert = matrix @ mathutils.Vector(vert)
xs.append(transformed_vert[0])
ys.append(transformed_vert[1])
multiplier = scale_multiplier
min_x = min(xs) / multiplier
max_x = max(xs) / multiplier
min_y = min(ys) / multiplier
max_y = max(ys) / multiplier
camera_x_half = (camera_x / 2)
camera_y_half = (camera_y / 2)
min_x_px = clamp(min_x * camera_x_half, -camera_x_half, camera_x_half)
max_x_px = clamp(max_x * camera_x_half, -camera_x_half, camera_x_half)
min_y_px = clamp(min_y * camera_x_half, -camera_y_half, camera_y_half)
max_y_px = clamp(max_y * camera_x_half, -camera_y_half, camera_y_half)
dimensions = [min_x_px, min_y_px, max_x_px, max_y_px]
return dimensions
def to_bool(value):
"""Function to convert various Non-Boolean true/false values to Boolean.
Inputs that return True are:
'Yes', 'yes', 'True', 'True', 'T', 't', '1', 1, 'Down', 'down'
Any other value returns a False.
"""
return str(value).lower() in ('yes', 'true', 't', '1', 'down')
def set_default(preset):
preset.name = get_default('name', class_type='Title')
preset.description = get_default('description', class_type='Title')
preset.z_scale = get_default('z_scale', class_type='Title')
preset.objects.clear()
preset.selected_object = 0
preset.enable_shadows = get_default('enable_shadows', class_type='Title')
preset.shadowlamp_internal_name = ""
preset.lampcenter_internal_name = ""
preset.shadowsize = get_default('shadowsize', class_type='Title')
preset.shadowamount = get_default('shadowamount', class_type='Title')
preset.shadowsoft = get_default('shadowsoft', class_type='Title')
preset.shadowx = get_default('shadowx', class_type='Title')
preset.shadowy = get_default('shadowy', class_type='Title')
preset.length = get_default('length', class_type='Title')
preset.lightscalex = get_default('lightscalex', class_type='Title')
preset.lightscaley = get_default('lightscaley', class_type='Title')
preset.lightx = get_default('lightx', class_type='Title')
preset.lighty = get_default('lighty', class_type='Title')
preset.lightrot = get_default('lightrot', class_type='Title')
def get_presets_directory():
script_file = os.path.realpath(__file__)
directory = os.path.dirname(script_file)
return directory+os.path.sep+'QuickTitling Presets'
def list_quicktitle_presets(scene):
presets = []
#Load up scene presets
for quicktitle in scene.quicktitler.quicktitles:
presets.append([quicktitle.name, 'SCENE'])
#load up builtin presets
preset_dir = get_presets_directory()
builtin_presets = glob.glob(preset_dir+os.path.sep+'*.xml')
for preset in builtin_presets:
preset_name = os.path.splitext(os.path.basename(preset))[0]
if preset_name != 'QuickTitling Export Example':
presets.append([preset_name, 'BUILTIN'])
return presets
def scene_quicktitle_from_name(quicktitles, name):
for quicktitle in quicktitles:
if quicktitle.name == name:
return quicktitle
return None
def get_default(value, class_type='Object'):
if class_type == 'Object':
return QuickTitleObject.bl_rna.properties[value].default
elif class_type == 'Animation':
return QuickTitleAnimation.bl_rna.properties[value].default
else: #class_type == 'Title'
return QuickTitle.bl_rna.properties[value].default
def load_quicktitle(filepath, preset):
#load a quicktitle preset from a given xml file
preset_location = os.path.dirname(bpy.path.abspath(filepath))
import xml.etree.cElementTree as Tree
tree = Tree.parse(filepath)
root = tree.getroot()
preset.name = root.findtext('name', default=os.path.splitext(bpy.path.basename(filepath))[0])
preset.description = root.findtext('description', default="")
preset.z_scale = abs(float(root.findtext('z_scale', default=str(get_default('z_scale', class_type='Title')))))
preset.length = abs(int(root.findtext('length', default=str(get_default('length', class_type='Title')))))
preset.shadowsize = abs(float(root.findtext('shadowsize', default=str(get_default('shadowsize', class_type='Title')))))
shadowamount = abs(float(root.findtext('shadowamount', default=str(get_default('shadowamount', class_type='Title')))))
if shadowamount > 1:
preset.shadowamount = 1
else:
preset.shadowamount = shadowamount
preset.shadowsoft = abs(float(root.findtext('shadowsoft', default=str(get_default('shadowsoft', class_type='Title')))))
preset.shadowx = float(root.findtext('shadowx', default=str(get_default('shadowx', class_type='Title'))))
preset.shadowy = float(root.findtext('shadowy', default=str(get_default('shadowy', class_type='Title'))))
preset.lightscalex = float(root.findtext('lightscalex', default=str(get_default('lightscalex', class_type='Title'))))
preset.lightscaley = float(root.findtext('lightscaley', default=str(get_default('lightscaley', class_type='Title'))))
preset.lightx = float(root.findtext('lightx', default=str(get_default('lightx', class_type='Title'))))
preset.lighty = float(root.findtext('lighty', default=str(get_default('lighty', class_type='Title'))))
preset.lightrot = float(root.findtext('lightrot', default=str(get_default('lightrot', class_type='Title'))))
objects = root.findall('objects')
preset.objects.clear()
for title_object in objects:
newobject = preset.objects.add()
newobject.name = title_object.findtext('name', default="")
object_type = title_object.findtext('type', default="TEXT")
if object_type in ['IMAGE', 'BOX', 'CIRCLE', 'TEXT']:
newobject.type = object_type
else:
newobject.type = 'BOX'
newobject.x = float(title_object.findtext('x', default=str(get_default('x'))))
newobject.y = float(title_object.findtext('y', default=str(get_default('y'))))
newobject.z = float(title_object.findtext('z', default=str(get_default('z'))))
newobject.rot_x = float(title_object.findtext('rot_x', default=str(get_default('rot_x'))))
newobject.rot_y = float(title_object.findtext('rot_y', default=str(get_default('rot_y'))))
newobject.rot_z = float(title_object.findtext('rot_z', default=str(get_default('rot_z'))))
scale = abs(float(title_object.findtext('scale', default=str(get_default('scale')))))
if scale > 0:
newobject.scale = scale
else:
newobject.scale = 1
width = abs(float(title_object.findtext('width', default=str(get_default('width')))))
if width > 0:
newobject.width = width
else:
newobject.width = 1
height = abs(float(title_object.findtext('height', default=str(get_default('height')))))
if height > 0:
newobject.height = height
else:
newobject.height = 1
shear = float(title_object.findtext('shear', default=str(get_default('shear'))))
if shear < -1:
shear = -1
if shear > 1:
shear = 1
newobject.shear = shear
newobject.cast_shadows = to_bool(title_object.findtext('cast_shadows', default=str(get_default('cast_shadows'))))
newobject.set_material = to_bool(title_object.findtext('set_material', default=str(get_default('set_material'))))
newobject.set_material_name = title_object.findtext('set_material_name', default=get_default('set_material_name'))
newobject.material = title_object.findtext('material', default=get_default('material'))
newobject.use_shadeless = to_bool(title_object.findtext('use_shadeless', default=str(get_default('use_shadeless'))))
alpha = abs(float(title_object.findtext('alpha', default=str(get_default('alpha')))))
if alpha > 1:
newobject.alpha = 1
else:
newobject.alpha = alpha
index_of_refraction = abs(float(title_object.findtext('index_of_refraction', default=str(get_default('index_of_refraction')))))
if index_of_refraction > 50:
newobject.index_of_refraction = 50
else:
newobject.index_of_refraction = index_of_refraction
transmission = abs(float(title_object.findtext('transmission', default=str(get_default('transmission')))))
if transmission > 1:
newobject.transmission = 1
else:
newobject.transmission = transmission
specular_intensity = abs(float(title_object.findtext('specular_intensity', default=str(get_default('specular_intensity')))))
if specular_intensity > 1:
newobject.specular_intensity = 1
else:
newobject.specular_intensity = specular_intensity
metallic = abs(float(title_object.findtext('metallic', default=str(get_default('metallic')))))
if metallic > 1:
newobject.metallic = 1
else:
newobject.metallic = metallic
roughness = abs(float(title_object.findtext('roughness', default=str(get_default('roughness')))))
if roughness > 1:
newobject.roughness = 1
else:
newobject.roughness = roughness
newobject.extrude = abs(float(title_object.findtext('extrude', default=str(get_default('extrude')))))
newobject.bevel = abs(float(title_object.findtext('bevel', default=str(get_default('bevel')))))
newobject.bevel_resolution = abs(int(title_object.findtext('bevel_resolution', default=str(get_default('bevel_resolution')))))
newobject.text = title_object.findtext('text', default=get_default('text'))
newobject.font = title_object.findtext('font', default=get_default('font'))
newobject.word_wrap = to_bool(title_object.findtext('word_wrap', default=str(get_default('word_wrap'))))
wrap_width = abs(float(title_object.findtext('wrap_width', default=str(get_default('wrap_width')))))
if wrap_width > 1:
newobject.wrap_width = 1
elif wrap_width < 0.01:
newobject.wrap_width = 0.01
else:
newobject.wrap_width = wrap_width
align = title_object.findtext('align', default=str(get_default('align')))
if align in ['LEFT', 'CENTER', 'RIGHT', 'JUSTIFY', 'FLUSH']:
newobject.align = align
else:
newobject.align = 'CENTER'
newobject.outline = to_bool(title_object.findtext('outline', default=str(get_default('outline'))))
newobject.outline_size = abs(float(title_object.findtext('outline_size', default=str(get_default('outline_size')))))
outline_alpha = abs(float(title_object.findtext('outline_alpha', default=str(get_default('outline_alpha')))))
if outline_alpha > 1:
outline_alpha = 1
newobject.outline_alpha = outline_alpha
outline_color = title_object.findtext('outline_diffuse_color', "0, 0, 0").replace(' ', '').replace('(', '').replace(')', '').split(',')
if len(outline_color) != 3:
newobject.outline_diffuse_color = (0, 0, 0)
else:
newobject.outline_diffuse_color = (int(outline_color[0]) / 255.0, int(outline_color[1]) / 255.0, int(outline_color[2]) / 255.0)
window_mapping = title_object.findtext('window_mapping', default=get_default('window_mapping'))
newobject.window_mapping = to_bool(window_mapping)
texture = title_object.findtext('texture', default=get_default('texture'))
if not os.path.isfile(os.path.abspath(bpy.path.abspath(texture))):
test_texture = os.path.join(preset_location, texture)
if os.path.isfile(test_texture):
texture = test_texture
newobject.texture = texture
alpha_texture = title_object.findtext('alpha_texture', default=get_default('alpha_texture'))
if not os.path.isfile(os.path.abspath(bpy.path.abspath(alpha_texture))):
test_texture = os.path.join(preset_location, alpha_texture)
if os.path.isfile(test_texture):
alpha_texture = test_texture
newobject.alpha_texture = alpha_texture
newobject.loop = to_bool(title_object.findtext('loop', default=str(get_default('loop'))))
newobject.frame_offset = abs(int(title_object.findtext('frame_offset', default=str(get_default('frame_offset')))))
frame_length = abs(int(title_object.findtext('frame_length', default=str(get_default('frame_length')))))
if frame_length > 1:
newobject.frame_length = frame_length
else:
newobject.frame_length = 1
diffuse_color = title_object.findtext('diffuse_color', default="255, 255, 255").replace(' ', '').replace('(', '').replace(')', '').split(',')
if len(diffuse_color) != 3:
newobject.diffuse_color = (1, 1, 1)
else:
newobject.diffuse_color = (int(diffuse_color[0]) / 255.0, int(diffuse_color[1]) / 255.0, int(diffuse_color[2]) / 255.0)
object_animations = title_object.findall('animations')
for animation in object_animations:
newanimation = newobject.animations.add()
newanimation.variable = animation.findtext('variable', default=str(get_default('variable', class_type='Animation')))
newanimation.animate_in = to_bool(animation.findtext('animate_in', default=str(get_default('animate_in', class_type='Animation'))))
newanimation.animate_out = to_bool(animation.findtext('animate_out', default=str(get_default('animate_out', class_type='Animation'))))
newanimation.in_length = abs(int(animation.findtext('in_length', default=str(get_default('in_length', class_type='Animation')))))
newanimation.out_length = abs(int(animation.findtext('out_length', default=str(get_default('out_length', class_type='Animation')))))
newanimation.in_offset = int(animation.findtext('in_offset', default=str(get_default('in_offset', class_type='Animation'))))
newanimation.out_offset = int(animation.findtext('out_offset', default=str(get_default('out_offset', class_type='Animation'))))
newanimation.in_amount = float(animation.findtext('in_amount', default=str(get_default('in_amount', class_type='Animation'))))
newanimation.out_amount = float(animation.findtext('out_amount', default=str(get_default('out_amount', class_type='Animation'))))
cycle_type = animation.findtext('cycle_type', default=get_default('cycle_type', class_type='Animation'))
if cycle_type not in ['NONE', 'SINE', 'TANGENT', 'RANDOM']:
cycle_type = 'NONE'
newanimation.cycle_type = cycle_type
newanimation.cycle_x_scale = abs(float(animation.findtext('cycle_x_scale', default=str(get_default('cycle_x_scale', class_type='Animation')))))
newanimation.cycle_y_scale = float(animation.findtext('cycle_y_scale', default=str(get_default('cycle_y_scale', class_type='Animation'))))
newanimation.cycle_offset = float(animation.findtext('cycle_offset', default=str(get_default('cycle_offset', class_type='Animation'))))
return preset
def get_current_object(quicktitle_preset=None):
#Get the current quicktitle preset object
if not quicktitle_preset:
quicktitle_preset = current_quicktitle()
if not quicktitle_preset:
return False
else:
current_object_index = quicktitle_preset.selected_object
current_object = quicktitle_preset.objects[current_object_index]
return current_object
def find_titling_scene():
#If the active sequence is a title scene, return that scene, otherwise return the current scene
selected = titling_scene_selected()
if selected:
return selected.scene
else:
return bpy.context.scene
def titling_scene_selected():
#determines if a titling scene is selected
sequence_editor = bpy.context.scene.sequence_editor
if hasattr(sequence_editor, 'active_strip'):
#there is an active strip
active_sequence = sequence_editor.active_strip
if active_sequence and active_sequence.select:
if active_sequence.type == 'SCENE':
#this is a scene strip
if 'QuickTitle:' in active_sequence.name:
#strip is named properly
return active_sequence
return None
def current_quicktitle(sequence=None):
#Function to return the current QuickTitle preset depending on what is selected in the sequencer
if not sequence:
sequence = titling_scene_selected()
if sequence and sequence.scene:
scene = sequence.scene
else:
scene = find_titling_scene()
return scene.quicktitler.current_quicktitle
def copy_object(oldobject, newobject):
newobject.name = oldobject.name
newobject.type = oldobject.type
newobject.x = oldobject.x
newobject.y = oldobject.y
newobject.z = oldobject.z
newobject.rot_x = oldobject.rot_x
newobject.rot_y = oldobject.rot_y
newobject.rot_z = oldobject.rot_z
newobject.scale = oldobject.scale