Fix T71100: Node Wrangler creates nodes on linked node trees
[blender-addons.git] / render_ui_animation_render.py
blob4be30c842605b8ae518c2a007457f39adc8efe19
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 import bpy
5 bl_info = {
6 "name": "UI Animation Render",
7 "author": "Luca Rood",
8 "description": "Render animations of the Blender UI.",
9 "blender": (2, 80, 0),
10 "version": (0, 1, 0),
11 "location": "View3D > Sidebar > View Tab and Ctrl+Shift+F12",
12 "warning": "",
13 "category": "Render"
16 km = None
19 def draw_ui(prefs, layout):
20 layout.prop(prefs, "delay")
22 col = layout.column(align=True)
23 col.label(text="Animation Highlight:")
25 row = col.row()
26 row.prop(prefs, "anim_highlight", expand=True)
28 if prefs.anim_highlight == "replace":
29 split = col.split(factor=0.2)
30 split.label(text="Color")
31 row = split.row(align=True)
32 row.prop(prefs, "highlight_color", text="")
33 row.prop(prefs, "highlight_blend", text="Blend")
36 class UIAnimationRenderPreferences(bpy.types.AddonPreferences):
37 bl_idname = __name__
39 delay: bpy.props.FloatProperty(
40 name="Capture Delay",
41 description="How much time to wait (seconds) before capturing each frame, to allow the viewport to clean up",
42 default=0.5
45 anim_highlight: bpy.props.EnumProperty(
46 name="Animation Highlight",
47 description="What to do with the animated field highlight color",
48 items=[("keep", "Keep", "Keep the animated field highlight", 0),
49 ("hide", "Hide", "Hide the animated field highlight", 1),
50 ("replace", "Replace", "Replace the animated field highlight", 2)],
51 default="keep"
54 highlight_color: bpy.props.FloatVectorProperty(
55 name="Highlight Color",
56 description="Color to use for animated field highlights",
57 subtype='COLOR',
58 default=(1.0, 1.0, 1.0)
61 highlight_blend: bpy.props.FloatProperty(
62 name="Highlight Blend",
63 description="How much the highlight color influences the field color",
64 default=0.5
67 def draw(self, context):
68 draw_ui(self, self.layout)
71 class RenderScreen(bpy.types.Operator):
72 bl_idname = "render.render_screen"
73 bl_label = "Render Screen"
74 bl_description = "Capture the screen for each animation frame and write to the render output path"
76 _timer = None
77 _f_initial = 1
78 _theme_blend = 0.0
79 _theme_key = (0, 0, 0)
80 _theme_key_sel = (0, 0, 0)
81 _theme_anim = (0, 0, 0)
82 _theme_anim_sel = (0, 0, 0)
83 _theme_driven = (0, 0, 0)
84 _theme_driven_sel = (0, 0, 0)
86 def modal(self, context, event):
87 if event.type in {'RIGHTMOUSE', 'ESC'}:
88 self.stop(context)
89 return {'CANCELLED'}
91 if event.type == 'TIMER':
92 scene = context.scene
93 f_curr = scene.frame_current
95 bpy.ops.screen.screenshot(filepath=context.scene.render.frame_path(frame=f_curr))
97 if f_curr < scene.frame_end:
98 scene.frame_set(f_curr + 1)
99 else:
100 self.stop(context)
101 return {'FINISHED'}
103 return {'RUNNING_MODAL'}
105 def execute(self, context):
106 # Adjust animation highlight (theme)
107 prefs = context.preferences
108 addon_prefs = prefs.addons[__name__].preferences
109 theme = prefs.themes[0].user_interface.wcol_state
111 if addon_prefs.anim_highlight == "hide":
112 self._theme_blend = theme.blend
113 theme.blend = 0.0
114 elif addon_prefs.anim_highlight == "replace":
115 self._theme_blend = theme.blend
116 self._theme_key = theme.inner_key.copy()
117 self._theme_key_sel = theme.inner_key_sel.copy()
118 self._theme_anim = theme.inner_anim.copy()
119 self._theme_anim_sel = theme.inner_anim_sel.copy()
120 self._theme_driven = theme.inner_driven.copy()
121 self._theme_driven_sel = theme.inner_driven_sel.copy()
123 theme.blend = addon_prefs.highlight_blend
124 theme.inner_key = addon_prefs.highlight_color
125 theme.inner_key_sel = addon_prefs.highlight_color
126 theme.inner_anim = addon_prefs.highlight_color
127 theme.inner_anim_sel = addon_prefs.highlight_color
128 theme.inner_driven = addon_prefs.highlight_color
129 theme.inner_driven_sel = addon_prefs.highlight_color
131 # Set frame
132 scene = context.scene
133 self._f_initial = scene.frame_current
134 scene.frame_set(scene.frame_start)
136 # Start timer
137 wm = context.window_manager
138 self._timer = wm.event_timer_add(addon_prefs.delay, window=context.window)
139 wm.modal_handler_add(self)
140 return {'RUNNING_MODAL'}
142 def stop(self, context):
143 # Stop timer
144 wm = context.window_manager
145 wm.event_timer_remove(self._timer)
147 # Reset frame
148 context.scene.frame_set(self._f_initial)
150 # Reset theme
151 prefs = context.preferences
152 addon_prefs = prefs.addons[__name__].preferences
153 theme = prefs.themes[0].user_interface.wcol_state
155 if addon_prefs.anim_highlight == "hide":
156 theme.blend = self._theme_blend
157 elif addon_prefs.anim_highlight == "replace":
158 theme.blend = self._theme_blend
159 theme.inner_key = self._theme_key
160 theme.inner_key_sel = self._theme_key_sel
161 theme.inner_anim = self._theme_anim
162 theme.inner_anim_sel = self._theme_anim_sel
163 theme.inner_driven = self._theme_driven
164 theme.inner_driven_sel = self._theme_driven_sel
167 class VIEW3D_PT_ui_animation_render(bpy.types.Panel):
168 bl_space_type = 'VIEW_3D'
169 bl_region_type = 'UI'
170 bl_category = "View"
171 bl_label = "UI Animation Render"
172 bl_options = {'DEFAULT_CLOSED'}
174 def draw(self, context):
175 layout = self.layout
176 layout.use_property_split = False
178 prefs = context.preferences
179 addon_prefs = prefs.addons[__name__].preferences
181 layout.operator(RenderScreen.bl_idname)
182 draw_ui(addon_prefs, layout)
185 def register():
186 global km
188 bpy.utils.register_class(UIAnimationRenderPreferences)
189 bpy.utils.register_class(RenderScreen)
190 bpy.utils.register_class(VIEW3D_PT_ui_animation_render)
192 wm = bpy.context.window_manager
194 if wm.keyconfigs.addon:
195 km = wm.keyconfigs.addon.keymaps.new(name='Screen', space_type='EMPTY')
196 km.keymap_items.new('render.render_screen', 'F12', 'PRESS', shift=True, ctrl=True)
199 def unregister():
200 global km
202 bpy.utils.unregister_class(UIAnimationRenderPreferences)
203 bpy.utils.unregister_class(RenderScreen)
204 bpy.utils.unregister_class(VIEW3D_PT_ui_animation_render)
206 if km is not None:
207 wm = bpy.context.window_manager
208 wm.keyconfigs.addon.keymaps.remove(km)
209 km = None