mirrored from https://projects.blender.org/blender/blender-addons.git
-
Notifications
You must be signed in to change notification settings - Fork 189
/
render_ui_animation_render.py
211 lines (165 loc) · 6.66 KB
/
render_ui_animation_render.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
# SPDX-FileCopyrightText: 2020-2022 Blender Foundation
#
# SPDX-License-Identifier: GPL-2.0-or-later
import bpy
bl_info = {
"name": "UI Animation Render",
"author": "Luca Rood",
"description": "Render animations of the Blender UI.",
"blender": (2, 80, 0),
"version": (0, 1, 0),
"location": "View3D > Sidebar > View Tab and Ctrl+Shift+F12",
"warning": "",
"category": "Render"
}
km = None
def draw_ui(prefs, layout):
layout.prop(prefs, "delay")
col = layout.column(align=True)
col.label(text="Animation Highlight:")
row = col.row()
row.prop(prefs, "anim_highlight", expand=True)
if prefs.anim_highlight == "replace":
split = col.split(factor=0.2)
split.label(text="Color")
row = split.row(align=True)
row.prop(prefs, "highlight_color", text="")
row.prop(prefs, "highlight_blend", text="Blend")
class UIAnimationRenderPreferences(bpy.types.AddonPreferences):
bl_idname = __name__
delay: bpy.props.FloatProperty(
name="Capture Delay",
description="How much time to wait (seconds) before capturing each frame, to allow the viewport to clean up",
default=0.5
)
anim_highlight: bpy.props.EnumProperty(
name="Animation Highlight",
description="What to do with the animated field highlight color",
items=[("keep", "Keep", "Keep the animated field highlight", 0),
("hide", "Hide", "Hide the animated field highlight", 1),
("replace", "Replace", "Replace the animated field highlight", 2)],
default="keep"
)
highlight_color: bpy.props.FloatVectorProperty(
name="Highlight Color",
description="Color to use for animated field highlights",
subtype='COLOR',
default=(1.0, 1.0, 1.0)
)
highlight_blend: bpy.props.FloatProperty(
name="Highlight Blend",
description="How much the highlight color influences the field color",
default=0.5
)
def draw(self, context):
draw_ui(self, self.layout)
class RenderScreen(bpy.types.Operator):
bl_idname = "render.render_screen"
bl_label = "Render Screen"
bl_description = "Capture the screen for each animation frame and write to the render output path"
_timer = None
_f_initial = 1
_theme_blend = 0.0
_theme_key = (0, 0, 0)
_theme_key_sel = (0, 0, 0)
_theme_anim = (0, 0, 0)
_theme_anim_sel = (0, 0, 0)
_theme_driven = (0, 0, 0)
_theme_driven_sel = (0, 0, 0)
def modal(self, context, event):
if event.type in {'RIGHTMOUSE', 'ESC'}:
self.stop(context)
return {'CANCELLED'}
if event.type == 'TIMER':
scene = context.scene
f_curr = scene.frame_current
bpy.ops.screen.screenshot(filepath=context.scene.render.frame_path(frame=f_curr))
if f_curr < scene.frame_end:
scene.frame_set(f_curr + 1)
else:
self.stop(context)
return {'FINISHED'}
return {'RUNNING_MODAL'}
def execute(self, context):
# Adjust animation highlight (theme)
prefs = context.preferences
addon_prefs = prefs.addons[__name__].preferences
theme = prefs.themes[0].user_interface.wcol_state
if addon_prefs.anim_highlight == "hide":
self._theme_blend = theme.blend
theme.blend = 0.0
elif addon_prefs.anim_highlight == "replace":
self._theme_blend = theme.blend
self._theme_key = theme.inner_key.copy()
self._theme_key_sel = theme.inner_key_sel.copy()
self._theme_anim = theme.inner_anim.copy()
self._theme_anim_sel = theme.inner_anim_sel.copy()
self._theme_driven = theme.inner_driven.copy()
self._theme_driven_sel = theme.inner_driven_sel.copy()
theme.blend = addon_prefs.highlight_blend
theme.inner_key = addon_prefs.highlight_color
theme.inner_key_sel = addon_prefs.highlight_color
theme.inner_anim = addon_prefs.highlight_color
theme.inner_anim_sel = addon_prefs.highlight_color
theme.inner_driven = addon_prefs.highlight_color
theme.inner_driven_sel = addon_prefs.highlight_color
# Set frame
scene = context.scene
self._f_initial = scene.frame_current
scene.frame_set(scene.frame_start)
# Start timer
wm = context.window_manager
self._timer = wm.event_timer_add(addon_prefs.delay, window=context.window)
wm.modal_handler_add(self)
return {'RUNNING_MODAL'}
def stop(self, context):
# Stop timer
wm = context.window_manager
wm.event_timer_remove(self._timer)
# Reset frame
context.scene.frame_set(self._f_initial)
# Reset theme
prefs = context.preferences
addon_prefs = prefs.addons[__name__].preferences
theme = prefs.themes[0].user_interface.wcol_state
if addon_prefs.anim_highlight == "hide":
theme.blend = self._theme_blend
elif addon_prefs.anim_highlight == "replace":
theme.blend = self._theme_blend
theme.inner_key = self._theme_key
theme.inner_key_sel = self._theme_key_sel
theme.inner_anim = self._theme_anim
theme.inner_anim_sel = self._theme_anim_sel
theme.inner_driven = self._theme_driven
theme.inner_driven_sel = self._theme_driven_sel
class VIEW3D_PT_ui_animation_render(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "View"
bl_label = "UI Animation Render"
bl_options = {'DEFAULT_CLOSED'}
def draw(self, context):
layout = self.layout
layout.use_property_split = False
prefs = context.preferences
addon_prefs = prefs.addons[__name__].preferences
layout.operator(RenderScreen.bl_idname)
draw_ui(addon_prefs, layout)
def register():
global km
bpy.utils.register_class(UIAnimationRenderPreferences)
bpy.utils.register_class(RenderScreen)
bpy.utils.register_class(VIEW3D_PT_ui_animation_render)
wm = bpy.context.window_manager
if wm.keyconfigs.addon:
km = wm.keyconfigs.addon.keymaps.new(name='Screen', space_type='EMPTY')
km.keymap_items.new('render.render_screen', 'F12', 'PRESS', shift=True, ctrl=True)
def unregister():
global km
bpy.utils.unregister_class(UIAnimationRenderPreferences)
bpy.utils.unregister_class(RenderScreen)
bpy.utils.unregister_class(VIEW3D_PT_ui_animation_render)
if km is not None:
wm = bpy.context.window_manager
wm.keyconfigs.addon.keymaps.remove(km)
km = None