[Blender_Kitsu] Playblast shot with user viewport settings #11
@ -1,11 +1,12 @@
|
|||||||
|
import bpy
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
|
|
||||||
from blender_kitsu import (
|
from blender_kitsu import (
|
||||||
prefs,
|
prefs,
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO refactor so these are nest-able and re-use code
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def override_render_format(self, context):
|
def override_render_format(self, context):
|
||||||
"""Overrides the render settings for playblast creation"""
|
"""Overrides the render settings for playblast creation"""
|
||||||
@ -53,31 +54,30 @@ def override_render_path(self, context, render_file_path):
|
|||||||
# Filepath.
|
# Filepath.
|
||||||
rd.filepath = filepath
|
rd.filepath = filepath
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
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
|
@contextlib.contextmanager
|
||||||
def override_render_settings(self, context, render_file_path):
|
def override_metadata_stamp_settings(self, context,):
|
||||||
"""Overrides the render settings for playblast creation"""
|
|
||||||
addon_prefs = prefs.addon_prefs_get(context)
|
|
||||||
rd = context.scene.render
|
rd = context.scene.render
|
||||||
sps = context.space_data.shading
|
|
||||||
sp = context.space_data
|
|
||||||
# Get first last name for stamp note text.
|
# Get first last name for stamp note text.
|
||||||
session = prefs.session_get(context)
|
session = prefs.session_get(context)
|
||||||
first_name = session.data.user["first_name"]
|
first_name = session.data.user["first_name"]
|
||||||
last_name = session.data.user["last_name"]
|
last_name = session.data.user["last_name"]
|
||||||
# Remember current render settings in order to restore them later.
|
# 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.
|
# Stamp metadata settings.
|
||||||
metadata_input = rd.metadata_input
|
metadata_input = rd.metadata_input
|
||||||
use_stamp_date = rd.use_stamp_date
|
use_stamp_date = rd.use_stamp_date
|
||||||
@ -99,34 +99,7 @@ def override_render_settings(self, context, render_file_path):
|
|||||||
stamp_foreground = rd.stamp_foreground
|
stamp_foreground = rd.stamp_foreground
|
||||||
stamp_background = rd.stamp_background
|
stamp_background = rd.stamp_background
|
||||||
use_stamp_labels = rd.use_stamp_labels
|
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:
|
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.
|
# Stamp metadata settings.
|
||||||
rd.metadata_input = "SCENE"
|
rd.metadata_input = "SCENE"
|
||||||
@ -150,36 +123,9 @@ def override_render_settings(self, context, render_file_path):
|
|||||||
rd.stamp_background = (0, 0, 0, 0.25)
|
rd.stamp_background = (0, 0, 0, 0.25)
|
||||||
rd.use_stamp_labels = True
|
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
|
yield
|
||||||
|
|
||||||
finally:
|
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.
|
# Stamp metadata settings.
|
||||||
rd.metadata_input = metadata_input
|
rd.metadata_input = metadata_input
|
||||||
rd.use_stamp_date = use_stamp_date
|
rd.use_stamp_date = use_stamp_date
|
||||||
@ -201,7 +147,46 @@ def override_render_settings(self, context, render_file_path):
|
|||||||
rd.stamp_foreground = stamp_foreground
|
rd.stamp_foreground = stamp_foreground
|
||||||
rd.stamp_background = stamp_background
|
rd.stamp_background = stamp_background
|
||||||
rd.use_stamp_labels = use_stamp_labels
|
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.
|
# Space data settings.
|
||||||
sps.type = shading_type
|
sps.type = shading_type
|
||||||
sps.light = shading_light
|
sps.light = shading_light
|
||||||
@ -216,4 +201,40 @@ def override_render_settings(self, context, render_file_path):
|
|||||||
sps.show_object_outline = show_object_outline
|
sps.show_object_outline = show_object_outline
|
||||||
sps.show_specular_highlight = show_specular_highlight
|
sps.show_specular_highlight = show_specular_highlight
|
||||||
|
|
||||||
sp.show_gizmo = show_gizmo
|
|
||||||
|
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
|
||||||
|
@ -38,7 +38,7 @@ from blender_kitsu.types import (
|
|||||||
TaskStatus,
|
TaskStatus,
|
||||||
TaskType,
|
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
|
from blender_kitsu.playblast import opsdata
|
||||||
|
|
||||||
logger = LoggerFactory.getLogger()
|
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
|
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
|
@classmethod
|
||||||
def poll(cls, context: bpy.types.Context) -> bool:
|
def poll(cls, context: bpy.types.Context) -> bool:
|
||||||
return bool(
|
return bool(
|
||||||
@ -91,16 +94,14 @@ class KITSU_OT_playblast_create(bpy.types.Operator):
|
|||||||
context.window_manager.progress_update(0)
|
context.window_manager.progress_update(0)
|
||||||
|
|
||||||
# Render and save playblast
|
# 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.
|
# Get output path.
|
||||||
output_path = Path(context.scene.kitsu.playblast_file)
|
output_path = playblast_with_shading_settings(
|
||||||
|
self, context, 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)
|
|
||||||
|
|
||||||
context.window_manager.progress_update(1)
|
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.prop(self, "task_status", text="Status")
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.prop(self, "comment")
|
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:
|
def _upload_playblast(self, context: bpy.types.Context, filepath: Path) -> None:
|
||||||
# Get shot.
|
# Get shot.
|
||||||
|
Loading…
Reference in New Issue
Block a user