128 lines
3.7 KiB
Python
128 lines
3.7 KiB
Python
"""
|
|
VSE Panel for Face Mask controls.
|
|
|
|
Provides a sidebar panel in the Video Sequence Editor
|
|
for controlling mask generation and blur application.
|
|
"""
|
|
|
|
import bpy
|
|
from bpy.types import Panel
|
|
|
|
from ..core.async_generator import get_generator
|
|
|
|
|
|
class SEQUENCER_PT_face_mask(Panel):
|
|
"""Panel for face mask blur controls."""
|
|
|
|
bl_label = "Face Mask"
|
|
bl_idname = "SEQUENCER_PT_face_mask"
|
|
bl_space_type = 'SEQUENCE_EDITOR'
|
|
bl_region_type = 'UI'
|
|
bl_category = "Face Mask"
|
|
|
|
def draw(self, context):
|
|
layout = self.layout
|
|
wm = context.window_manager
|
|
seq_editor = context.scene.sequence_editor
|
|
# Note: Blender 5.0 uses 'strips' instead of 'sequences'
|
|
|
|
generator = get_generator()
|
|
|
|
# Show progress if generating
|
|
if generator.is_running:
|
|
self._draw_progress(layout, wm, generator)
|
|
return
|
|
|
|
# Show controls if strip selected
|
|
if seq_editor and seq_editor.active_strip:
|
|
strip = seq_editor.active_strip
|
|
|
|
if strip.type in {'MOVIE', 'IMAGE'}:
|
|
self._draw_generation_controls(layout, context, strip)
|
|
self._draw_blur_controls(layout, context, strip)
|
|
else:
|
|
layout.label(text="Select a video or image strip")
|
|
else:
|
|
layout.label(text="No strip selected")
|
|
|
|
def _draw_progress(self, layout, wm, generator):
|
|
"""Draw progress bar during generation."""
|
|
box = layout.box()
|
|
box.label(text="Generating Masks...", icon='RENDER_ANIMATION')
|
|
|
|
# Progress bar
|
|
progress = wm.mask_progress / max(wm.mask_total, 1)
|
|
box.progress(
|
|
factor=progress,
|
|
text=f"Frame {wm.mask_progress} / {wm.mask_total}",
|
|
)
|
|
|
|
# Cancel button
|
|
box.operator(
|
|
"sequencer.cancel_mask_generation",
|
|
text="Cancel",
|
|
icon='CANCEL',
|
|
)
|
|
|
|
def _draw_generation_controls(self, layout, context, strip):
|
|
"""Draw mask generation controls."""
|
|
box = layout.box()
|
|
box.label(text="Mask Generation", icon='MOD_MASK')
|
|
|
|
# Info about selected strip
|
|
row = box.row()
|
|
row.label(text=f"Strip: {strip.name}")
|
|
|
|
# Check for existing mask
|
|
seq_editor = context.scene.sequence_editor
|
|
mask_name = f"{strip.name}_mask"
|
|
has_mask = mask_name in seq_editor.strips
|
|
|
|
if has_mask:
|
|
row = box.row()
|
|
row.label(text="✓ Mask exists", icon='CHECKMARK')
|
|
|
|
# Generate button
|
|
op = box.operator(
|
|
"sequencer.generate_face_mask",
|
|
text="Generate Face Mask" if not has_mask else "Regenerate Mask",
|
|
icon='FACE_MAPS',
|
|
)
|
|
|
|
def _draw_blur_controls(self, layout, context, strip):
|
|
"""Draw blur application controls."""
|
|
box = layout.box()
|
|
box.label(text="Blur Application", icon='MATFLUID')
|
|
|
|
# Check for mask strip
|
|
seq_editor = context.scene.sequence_editor
|
|
mask_name = f"{strip.name}_mask"
|
|
has_mask = mask_name in seq_editor.strips
|
|
|
|
if not has_mask:
|
|
box.label(text="Generate a mask first", icon='INFO')
|
|
return
|
|
|
|
# Apply blur button
|
|
op = box.operator(
|
|
"sequencer.apply_mask_blur",
|
|
text="Apply Mask Blur",
|
|
icon='PROP_CON',
|
|
)
|
|
|
|
|
|
# Registration
|
|
classes = [
|
|
SEQUENCER_PT_face_mask,
|
|
]
|
|
|
|
|
|
def register():
|
|
for cls in classes:
|
|
bpy.utils.register_class(cls)
|
|
|
|
|
|
def unregister():
|
|
for cls in reversed(classes):
|
|
bpy.utils.unregister_class(cls)
|