Files
AnyImage/src/snapform/panel.py
nan d694980da7 feat: Add BEN2 background removal functionality and integrate into SnapForm
- Introduced BEN2 model for background removal in the panel and properties.
- Updated runtime to handle background removal commands and model downloads.
- Implemented background removal logic in worker, including image processing and saving results.
- Enhanced tests to cover new background removal features and ensure proper integration.
- Updated version to 0.9.28 to reflect new features and improvements.
2026-08-03 20:18:00 +08:00

122 lines
3.9 KiB
Python

import bpy
from .models import BEN2_MODEL, MODELS
from .operators import active_job
from .runtime import model_ready, runtime_ready
class RuntimeModelsPanel(bpy.types.Panel):
bl_label = "Setup"
bl_idname = "SNAPFORM_PT_runtime_models"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "SnapForm"
def draw(self, _context):
layout = self.layout
running = active_job() is not None
if not runtime_ready():
layout.label(text="Runtime is not installed", icon="ERROR")
install_row = layout.row()
install_row.enabled = not running
operator = install_row.operator(
"snapform.run_job",
text="Install Runtime",
icon="IMPORT",
)
operator.job_type = "INSTALL_RUNTIME"
for model in MODELS.values():
self._draw_model(layout, model, running)
self._draw_model(layout, BEN2_MODEL, running)
def _draw_model(self, layout, model, running):
row = layout.row(align=True)
row.label(text=model.label)
if model_ready(model.key):
row.label(text="Ready", icon="CHECKMARK")
else:
download_row = row.row(align=True)
download_row.enabled = runtime_ready() and not running
operator = download_row.operator(
"snapform.run_job",
text="Download",
icon="IMPORT",
)
operator.job_type = "DOWNLOAD_MODEL"
operator.model_key = model.key
class DebugPanel(bpy.types.Panel):
bl_label = "Debug"
bl_idname = "SNAPFORM_PT_debug"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "SnapForm"
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
layout = self.layout
settings = context.scene.snapform_settings
layout.prop(settings, "export_format")
model_property = (
"gs_model" if settings.export_format == "gs_ply" else "model"
)
layout.prop(settings, model_property)
layout.prop(settings, "input_path")
input_path = bpy.path.abspath(settings.input_path)
if input_path.lower().endswith(
(
".mp4",
".mov",
".avi",
".mkv",
".webm",
".m4v",
".mts",
".mpg",
".mpeg",
)
):
layout.prop(settings, "video_frames")
layout.prop(settings, "device")
layout.prop(settings, "process_res")
layout.prop(settings, "process_res_method")
layout.prop(settings, "use_ray_pose")
layout.prop(settings, "ref_view_strategy")
if settings.export_format == "glb":
glb_box = layout.box()
glb_box.label(text="GLB Settings")
glb_box.prop(settings, "conf_thresh_percentile")
glb_box.prop(settings, "num_max_points")
glb_box.prop(settings, "show_cameras")
elif settings.export_format == "gs_ply":
ply_box = layout.box()
ply_box.label(text="PLY (3DGS) Settings")
ply_box.prop(settings, "gs_views_interval")
export_row = layout.row()
export_row.enabled = active_job() is None
operator = export_row.operator(
"snapform.run_job",
text="Export",
icon="EXPORT",
)
operator.job_type = "RECONSTRUCT"
background_box = layout.box()
background_box.label(text="BEN2 Background Removal")
background_box.prop(settings, "background_input_path")
background_row = background_box.row()
background_row.enabled = active_job() is None
operator = background_row.operator(
"snapform.run_job",
text="Remove Background",
icon="IMAGE_ALPHA",
)
operator.job_type = "REMOVE_BACKGROUND"