From 3beb58165a4660106313f11f1f5b1eff9460c1c2 Mon Sep 17 00:00:00 2001 From: TinyNick Date: Mon, 17 Apr 2023 15:56:28 -0400 Subject: [PATCH 1/4] [Blender_Kitsu] Playblast: breakup render contextmanagers - Create multiple render decorators --- blender_kitsu/playblast/core.py | 126 +++++++++++++------------------- 1 file changed, 51 insertions(+), 75 deletions(-) diff --git a/blender_kitsu/playblast/core.py b/blender_kitsu/playblast/core.py index d7c48594..34e34f1b 100644 --- a/blender_kitsu/playblast/core.py +++ b/blender_kitsu/playblast/core.py @@ -4,8 +4,6 @@ from blender_kitsu import ( prefs, ) -# TODO refactor so these are nest-able and re-use code - @contextlib.contextmanager def override_render_format(self, context): """Overrides the render settings for playblast creation""" @@ -53,31 +51,26 @@ def override_render_path(self, context, render_file_path): # Filepath. rd.filepath = filepath +@contextlib.contextmanager +def override_hide_viewport_gizmos(self, context,): + sp = context.space_data + show_gizmo = sp.show_gizmo + try: + sp.show_gizmo = False + + yield + finally: + sp.show_gizmo = show_gizmo @contextlib.contextmanager -def override_render_settings(self, context, render_file_path): - """Overrides the render settings for playblast creation""" - addon_prefs = prefs.addon_prefs_get(context) +def override_metadata_stamp_settings(self, context,): rd = context.scene.render - sps = context.space_data.shading - sp = context.space_data # Get first last name for stamp note text. session = prefs.session_get(context) first_name = session.data.user["first_name"] last_name = session.data.user["last_name"] # Remember current render settings in order to restore them later. - # Filepath. - filepath = rd.filepath - - # Format render settings. - percentage = rd.resolution_percentage - file_format = rd.image_settings.file_format - ffmpeg_constant_rate = rd.ffmpeg.constant_rate_factor - ffmpeg_codec = rd.ffmpeg.codec - ffmpeg_format = rd.ffmpeg.format - ffmpeg_audio_codec = rd.ffmpeg.audio_codec - # Stamp metadata settings. metadata_input = rd.metadata_input use_stamp_date = rd.use_stamp_date @@ -99,34 +92,7 @@ def override_render_settings(self, context, render_file_path): stamp_foreground = rd.stamp_foreground stamp_background = rd.stamp_background use_stamp_labels = rd.use_stamp_labels - - # Space data settings. - shading_type = sps.type - shading_light = sps.light - studio_light = sps.studio_light - color_type = sps.color_type - background_type = sps.background_type - - show_backface_culling = sps.show_backface_culling - show_xray = sps.show_xray - show_shadows = sps.show_shadows - show_cavity = sps.show_cavity - show_object_outline = sps.show_object_outline - show_specular_highlight = sps.show_specular_highlight - - show_gizmo = sp.show_gizmo - try: - # Filepath. - rd.filepath = render_file_path - - # Format render settings. - rd.resolution_percentage = 100 - rd.image_settings.file_format = "FFMPEG" - rd.ffmpeg.constant_rate_factor = "HIGH" - rd.ffmpeg.codec = "H264" - rd.ffmpeg.format = "MPEG4" - rd.ffmpeg.audio_codec = "AAC" # Stamp metadata settings. rd.metadata_input = "SCENE" @@ -150,36 +116,9 @@ def override_render_settings(self, context, render_file_path): rd.stamp_background = (0, 0, 0, 0.25) rd.use_stamp_labels = True - # Space data settings. - sps.type = "SOLID" - sps.light = "STUDIO" - sps.studio_light = "Default" - sps.color_type = "MATERIAL" - sps.background_type = "THEME" - - sps.show_backface_culling = False - sps.show_xray = False - sps.show_shadows = False - sps.show_cavity = False - sps.show_object_outline = False - sps.show_specular_highlight = True - - sp.show_gizmo = False - yield finally: - # Filepath. - rd.filepath = filepath - - # Return the render settings to normal. - rd.resolution_percentage = percentage - rd.image_settings.file_format = file_format - rd.ffmpeg.codec = ffmpeg_codec - rd.ffmpeg.constant_rate_factor = ffmpeg_constant_rate - rd.ffmpeg.format = ffmpeg_format - rd.ffmpeg.audio_codec = ffmpeg_audio_codec - # Stamp metadata settings. rd.metadata_input = metadata_input rd.use_stamp_date = use_stamp_date @@ -201,7 +140,46 @@ def override_render_settings(self, context, render_file_path): rd.stamp_foreground = stamp_foreground rd.stamp_background = stamp_background rd.use_stamp_labels = use_stamp_labels + +@contextlib.contextmanager +def override_viewport_shading(self, context): + """Overrides the render settings for playblast creation""" + rd = context.scene.render + sps = context.space_data.shading + sp = context.space_data + # Space data settings. + shading_type = sps.type + shading_light = sps.light + studio_light = sps.studio_light + color_type = sps.color_type + background_type = sps.background_type + + show_backface_culling = sps.show_backface_culling + show_xray = sps.show_xray + show_shadows = sps.show_shadows + show_cavity = sps.show_cavity + show_object_outline = sps.show_object_outline + show_specular_highlight = sps.show_specular_highlight + + try: + # Space data settings. + sps.type = "SOLID" + sps.light = "STUDIO" + sps.studio_light = "Default" + sps.color_type = "MATERIAL" + sps.background_type = "THEME" + + sps.show_backface_culling = False + sps.show_xray = False + sps.show_shadows = False + sps.show_cavity = False + sps.show_object_outline = False + sps.show_specular_highlight = True + + yield + + finally: # Space data settings. sps.type = shading_type sps.light = shading_light @@ -214,6 +192,4 @@ def override_render_settings(self, context, render_file_path): sps.show_shadows = show_shadows sps.show_cavity = show_cavity sps.show_object_outline = show_object_outline - sps.show_specular_highlight = show_specular_highlight - - sp.show_gizmo = show_gizmo \ No newline at end of file + sps.show_specular_highlight = show_specular_highlight \ No newline at end of file -- 2.30.2 From 2b98285807ba51dde0b58dfb40acdf903e665ca5 Mon Sep 17 00:00:00 2001 From: TinyNick Date: Mon, 17 Apr 2023 15:58:17 -0400 Subject: [PATCH 2/4] [Blender_Kitsu] Playblast: fix hide overlays --- blender_kitsu/playblast/core.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/blender_kitsu/playblast/core.py b/blender_kitsu/playblast/core.py index 34e34f1b..806168d8 100644 --- a/blender_kitsu/playblast/core.py +++ b/blender_kitsu/playblast/core.py @@ -55,12 +55,16 @@ def override_render_path(self, context, render_file_path): def override_hide_viewport_gizmos(self, context,): sp = context.space_data show_gizmo = sp.show_gizmo + show_overlays = sp.overlay.show_overlays + try: sp.show_gizmo = False + sp.overlay.show_overlays = False yield finally: sp.show_gizmo = show_gizmo + sp.overlay.show_overlays = show_overlays @contextlib.contextmanager def override_metadata_stamp_settings(self, context,): -- 2.30.2 From b5cd25485b5ee6776726b06090c392b7dcf1b354 Mon Sep 17 00:00:00 2001 From: TinyNick Date: Mon, 17 Apr 2023 16:02:15 -0400 Subject: [PATCH 3/4] [Blender_Kitsu] Playblast Add playblast with contextmanagers - playblast_with_shading_settings() - playblast_user_shading_settings() --- blender_kitsu/playblast/core.py | 43 ++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/blender_kitsu/playblast/core.py b/blender_kitsu/playblast/core.py index 806168d8..2e268d02 100644 --- a/blender_kitsu/playblast/core.py +++ b/blender_kitsu/playblast/core.py @@ -1,3 +1,6 @@ +import bpy +from pathlib import Path + import contextlib from blender_kitsu import ( @@ -196,4 +199,42 @@ def override_viewport_shading(self, context): sps.show_shadows = show_shadows sps.show_cavity = show_cavity sps.show_object_outline = show_object_outline - sps.show_specular_highlight = show_specular_highlight \ No newline at end of file + sps.show_specular_highlight = show_specular_highlight + + +def playblast_with_shading_settings(self, context, file_path): + # Render and save playblast + with override_render_path(self, context, file_path): + with override_render_format(self, context,): + with override_metadata_stamp_settings(self, context): + with override_hide_viewport_gizmos(self, context): + with override_viewport_shading(self, context): + + # Get output path. + output_path = Path(file_path) + + # Ensure folder exists. + Path(context.scene.kitsu.playblast_dir).mkdir( + parents=True, exist_ok=True) + + # Make opengl render. + bpy.ops.render.opengl(animation=True) + return output_path + + +def playblast_user_shading_settings(self, context, file_path): + # Render and save playblast + with override_render_path(self, context, file_path): + with override_render_format(self, context,): + with override_metadata_stamp_settings(self, context): + with override_hide_viewport_gizmos(self, context): + # Get output path. + output_path = Path(file_path) + + # Ensure folder exists. + Path(context.scene.kitsu.playblast_dir).mkdir( + parents=True, exist_ok=True) + + # Make opengl render. + bpy.ops.render.opengl(animation=True) + return output_path -- 2.30.2 From 190505705a3075a844c94cd12d636a4d729525a3 Mon Sep 17 00:00:00 2001 From: TinyNick Date: Mon, 17 Apr 2023 16:03:20 -0400 Subject: [PATCH 4/4] [Blender_Kitsu] Playblast: Add option to pass current viewport shading options - Add to invoke Menu - Add prop to operator - Optionally render default shading --- blender_kitsu/playblast/ops.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/blender_kitsu/playblast/ops.py b/blender_kitsu/playblast/ops.py index 387344b9..a8f4e364 100644 --- a/blender_kitsu/playblast/ops.py +++ b/blender_kitsu/playblast/ops.py @@ -38,7 +38,7 @@ from blender_kitsu.types import ( TaskStatus, TaskType, ) -from blender_kitsu.playblast.core import override_render_settings +from blender_kitsu.playblast.core import playblast_with_shading_settings, playblast_user_shading_settings from blender_kitsu.playblast import opsdata logger = LoggerFactory.getLogger() @@ -63,6 +63,9 @@ class KITSU_OT_playblast_create(bpy.types.Operator): task_status: bpy.props.EnumProperty(items=cache.get_all_task_statuses_enum) # type: ignore + use_user_shading: bpy.props.BoolProperty( + name="Use Current Viewport Shading", default=True) + @classmethod def poll(cls, context: bpy.types.Context) -> bool: return bool( @@ -91,16 +94,14 @@ class KITSU_OT_playblast_create(bpy.types.Operator): context.window_manager.progress_update(0) # Render and save playblast - with override_render_settings(self, context, context.scene.kitsu.playblast_file): + if self.use_user_shading: + output_path = playblast_user_shading_settings( + self, context, context.scene.kitsu.playblast_file) + else: # Get output path. - output_path = Path(context.scene.kitsu.playblast_file) - - # Ensure folder exists. - Path(context.scene.kitsu.playblast_dir).mkdir(parents=True, exist_ok=True) - - # Make opengl render. - bpy.ops.render.opengl(animation=True) + output_path = playblast_with_shading_settings( + self, context, context.scene.kitsu.playblast_file) context.window_manager.progress_update(1) @@ -208,6 +209,8 @@ class KITSU_OT_playblast_create(bpy.types.Operator): row.prop(self, "task_status", text="Status") row = layout.row(align=True) row.prop(self, "comment") + row = layout.row(align=True) + row.prop(self, "use_user_shading") def _upload_playblast(self, context: bpy.types.Context, filepath: Path) -> None: # Get shot. -- 2.30.2