Pose Library: update for rename of asset_library to asset_library_ref
[blender-addons.git] / render_ui_animation_render.py
blob27d84a4a23ca3a9230aec16bfaa7aa00aafff91b
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 import bpy
21 bl_info = {
22 "name": "UI Animation Render",
23 "author": "Luca Rood",
24 "description": "Render animations of the Blender UI.",
25 "blender": (2, 80, 0),
26 "version": (0, 1, 0),
27 "location": "View3D > Sidebar > View Tab and Ctrl+Shift+F12",
28 "warning": "",
29 "category": "Render"
32 km = None
35 def draw_ui(prefs, layout):
36 layout.prop(prefs, "delay")
38 col = layout.column(align=True)
39 col.label(text="Animation Highlight:")
41 row = col.row()
42 row.prop(prefs, "anim_highlight", expand=True)
44 if prefs.anim_highlight == "replace":
45 split = col.split(factor=0.2)
46 split.label(text="Color")
47 row = split.row(align=True)
48 row.prop(prefs, "highlight_color", text="")
49 row.prop(prefs, "highlight_blend", text="Blend")
52 class UIAnimationRenderPreferences(bpy.types.AddonPreferences):
53 bl_idname = __name__
55 delay: bpy.props.FloatProperty(
56 name="Capture Delay",
57 description="How much time to wait (seconds) before capturing each frame, to allow the viewport to clean up",
58 default=0.5
61 anim_highlight: bpy.props.EnumProperty(
62 name="Animation Highlight",
63 description="What to do with the animated field highlight color",
64 items=[("keep", "Keep", "Keep the animated field highlight", 0),
65 ("hide", "Hide", "Hide the animated field highlight", 1),
66 ("replace", "Replace", "Replace the animated field highlight", 2)],
67 default="keep"
70 highlight_color: bpy.props.FloatVectorProperty(
71 name="Highlight Color",
72 description="Color to use for animated field highlights",
73 subtype='COLOR',
74 default=(1.0, 1.0, 1.0)
77 highlight_blend: bpy.props.FloatProperty(
78 name="Highlight Blend",
79 description="How much the highlight color influences the field color",
80 default=0.5
83 def draw(self, context):
84 draw_ui(self, self.layout)
87 class RenderScreen(bpy.types.Operator):
88 bl_idname = "render.render_screen"
89 bl_label = "Render Screen"
90 bl_description = "Capture the screen for each animation frame and write to the render output path"
92 _timer = None
93 _f_initial = 1
94 _theme_blend = 0.0
95 _theme_key = (0, 0, 0)
96 _theme_key_sel = (0, 0, 0)
97 _theme_anim = (0, 0, 0)
98 _theme_anim_sel = (0, 0, 0)
99 _theme_driven = (0, 0, 0)
100 _theme_driven_sel = (0, 0, 0)
102 def modal(self, context, event):
103 if event.type in {'RIGHTMOUSE', 'ESC'}:
104 self.stop(context)
105 return {'CANCELLED'}
107 if event.type == 'TIMER':
108 scene = context.scene
109 f_curr = scene.frame_current
111 bpy.ops.screen.screenshot(filepath=context.scene.render.frame_path(frame=f_curr))
113 if f_curr < scene.frame_end:
114 scene.frame_set(f_curr + 1)
115 else:
116 self.stop(context)
117 return {'FINISHED'}
119 return {'RUNNING_MODAL'}
121 def execute(self, context):
122 # Adjust animation highlight (theme)
123 prefs = context.preferences
124 addon_prefs = prefs.addons[__name__].preferences
125 theme = prefs.themes[0].user_interface.wcol_state
127 if addon_prefs.anim_highlight == "hide":
128 self._theme_blend = theme.blend
129 theme.blend = 0.0
130 elif addon_prefs.anim_highlight == "replace":
131 self._theme_blend = theme.blend
132 self._theme_key = theme.inner_key.copy()
133 self._theme_key_sel = theme.inner_key_sel.copy()
134 self._theme_anim = theme.inner_anim.copy()
135 self._theme_anim_sel = theme.inner_anim_sel.copy()
136 self._theme_driven = theme.inner_driven.copy()
137 self._theme_driven_sel = theme.inner_driven_sel.copy()
139 theme.blend = addon_prefs.highlight_blend
140 theme.inner_key = addon_prefs.highlight_color
141 theme.inner_key_sel = addon_prefs.highlight_color
142 theme.inner_anim = addon_prefs.highlight_color
143 theme.inner_anim_sel = addon_prefs.highlight_color
144 theme.inner_driven = addon_prefs.highlight_color
145 theme.inner_driven_sel = addon_prefs.highlight_color
147 # Set frame
148 scene = context.scene
149 self._f_initial = scene.frame_current
150 scene.frame_set(scene.frame_start)
152 # Start timer
153 wm = context.window_manager
154 self._timer = wm.event_timer_add(addon_prefs.delay, window=context.window)
155 wm.modal_handler_add(self)
156 return {'RUNNING_MODAL'}
158 def stop(self, context):
159 # Stop timer
160 wm = context.window_manager
161 wm.event_timer_remove(self._timer)
163 # Reset frame
164 context.scene.frame_set(self._f_initial)
166 # Reset theme
167 prefs = context.preferences
168 addon_prefs = prefs.addons[__name__].preferences
169 theme = prefs.themes[0].user_interface.wcol_state
171 if addon_prefs.anim_highlight == "hide":
172 theme.blend = self._theme_blend
173 elif addon_prefs.anim_highlight == "replace":
174 theme.blend = self._theme_blend
175 theme.inner_key = self._theme_key
176 theme.inner_key_sel = self._theme_key_sel
177 theme.inner_anim = self._theme_anim
178 theme.inner_anim_sel = self._theme_anim_sel
179 theme.inner_driven = self._theme_driven
180 theme.inner_driven_sel = self._theme_driven_sel
183 class VIEW3D_PT_ui_animation_render(bpy.types.Panel):
184 bl_space_type = 'VIEW_3D'
185 bl_region_type = 'UI'
186 bl_category = "View"
187 bl_label = "UI Animation Render"
188 bl_options = {'DEFAULT_CLOSED'}
190 def draw(self, context):
191 layout = self.layout
192 layout.use_property_split = False
194 prefs = context.preferences
195 addon_prefs = prefs.addons[__name__].preferences
197 layout.operator(RenderScreen.bl_idname)
198 draw_ui(addon_prefs, layout)
201 def register():
202 global km
204 bpy.utils.register_class(UIAnimationRenderPreferences)
205 bpy.utils.register_class(RenderScreen)
206 bpy.utils.register_class(VIEW3D_PT_ui_animation_render)
208 wm = bpy.context.window_manager
209 km = wm.keyconfigs.addon.keymaps.new(name='Screen', space_type='EMPTY')
210 km.keymap_items.new('render.render_screen', 'F12', 'PRESS', shift=True, ctrl=True)
213 def unregister():
214 global km
216 bpy.utils.unregister_class(UIAnimationRenderPreferences)
217 bpy.utils.unregister_class(RenderScreen)
218 bpy.utils.unregister_class(VIEW3D_PT_ui_animation_render)
220 if km is not None:
221 wm = bpy.context.window_manager
222 wm.keyconfigs.addon.keymaps.remove(km)
223 km = None