-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
124 lines (108 loc) · 4.48 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
import bpy
bl_info = {
"name": "Cinebars",
"description": "Add fake-letterboxing without changing the resolution of your video.",
"author": "ZoomTen",
"version": (0, 0, 4),
"blender": (2, 80, 0),
"wiki_url": "https://github.com/ZoomTen/blender-vse-cinebars",
"tracker_url": "https://github.com/ZoomTen/blender-vse-cinebars/issues",
"location": "Video Sequencer > Misc > Cinebars",
"category": "Sequencer"
}
# vars
class cbVals(bpy.types.PropertyGroup):
ratio_x: bpy.props.FloatProperty(
name="ratio_x",
description="Horizontal ratio",
default=16.0
)
ratio_y: bpy.props.FloatProperty(
name="ratio_y",
description="Vertical ratio",
default=9.0
)
# funcs
def msgbox(message = "", title = "info", icon = 'INFO'):
def draw(self, context):
self.layout.label(text=message)
bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)
def main(context):
# get render resolution
rsx = bpy.context.scene.render.resolution_x
rsy = bpy.context.scene.render.resolution_y
# get target AR
target_rsx = context.scene.cb_ratios.ratio_x
target_rsy = context.scene.cb_ratios.ratio_y
if target_rsx/target_rsy == rsx/rsy:
msgbox("Source ratio is the same as destination ratio!")
return 0
bpy.ops.sequencer.effect_strip_add(frame_start=bpy.context.scene.frame_start,
frame_end=bpy.context.scene.frame_end,
type="COLOR")
color = context.scene.sequence_editor.active_strip
bpy.ops.sequencer.effect_strip_add(type="TRANSFORM")
bar = context.scene.sequence_editor.active_strip
bar.name = "cinebars "+str('%.2f' % target_rsx)+":"+str('%.2f' % target_rsy)
# wide ratio
if target_rsx/target_rsy > rsx/rsy:
bar.scale_start_y = (1-((rsx/target_rsx*target_rsy)/rsy))/2
bar.translate_start_y= 50 - (bar.scale_start_y*50)
bar.blend_type='ALPHA_OVER'
bpy.ops.sequencer.duplicate_move(
SEQUENCER_OT_duplicate={"mode":'TRANSLATION'},
TRANSFORM_OT_seq_slide={"value":(2,1)}
)
otherbar = context.scene.sequence_editor.active_strip
otherbar.use_flip_y = True
otherbar.blend_type='ALPHA_OVER'
color.mute = True
# i would make them into a metastrip but there isn't a function for
# that apparently
# tall / square ratio
if target_rsx/target_rsy < rsx/rsy:
bar.scale_start_x = (1-((rsy/target_rsy*target_rsx)/rsx))/2
bar.translate_start_x= 50 - (bar.scale_start_x*50)
bar.blend_type='ALPHA_OVER'
bpy.ops.sequencer.duplicate_move(
TRANSFORM_OT_seq_slide={"value":(2,1)}
)
otherbar = context.scene.sequence_editor.active_strip
otherbar.use_flip_x = True
otherbar.blend_type='ALPHA_OVER'
color.mute = True
# i would make them into a metastrip but there isn't a function for
# that which doesn't require selections apparently
# actions
class cbMake(bpy.types.Operator):
bl_idname = "sequencer.cb_make"
bl_label = "Make Cinebars"
def execute(self, context):
main(context)
return {'FINISHED'}
# ui
class cbPanel(bpy.types.Panel):
bl_space_type = "SEQUENCE_EDITOR"
bl_region_type = "UI"
bl_label = "Cinebars"
bl_idname = "CNB_PT_cbPanel"
def draw(self, context):
l = self.layout
l.prop(context.scene.cb_ratios, "ratio_x", text="Horizontal ratio")
l.prop(context.scene.cb_ratios, "ratio_y", text="Vertical ratio")
l.operator('sequencer.cb_make',
text='Generate Cinebars Strips',
icon='FILE_TICK')
# addon registry
def register():
bpy.utils.register_class(cbVals)
bpy.utils.register_class(cbMake)
bpy.utils.register_class(cbPanel)
bpy.types.Scene.cb_ratios = bpy.props.PointerProperty(type=cbVals)
def unregister():
del bpy.types.Scene.cb_ratios
bpy.utils.unregister_class(cbPanel)
bpy.utils.unregister_class(cbMake)
bpy.utils.unregister_class(cbVals)
if __name__ == "__main__":
register()