Refactor and enhance DA3 and BEN2 debug panels, introduce mesh export functionality
- Renamed DA3 and BEN2 debug panels for clarity and consistency. - Added a new function to draw DA3 input settings to reduce code duplication. - Implemented mesh export functionality, including confidence thresholding and edge filtering. - Updated export format options to include new mesh type and adjusted related properties. - Enhanced job handling to move generated inputs into job root and manage temporary directories. - Improved error handling and file management during export processes. - Added unit tests for new mesh functionality and ensured existing tests cover changes.
This commit is contained in:
@@ -6,6 +6,7 @@ import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import uuid
|
||||
@@ -34,9 +35,12 @@ DEFAULT_STORAGE_ROOT = Path.home() / ".snapform"
|
||||
JOB_FOLDER_NAMES = {
|
||||
"INSTALL_RUNTIME": "install-runtime",
|
||||
"DOWNLOAD_MODEL": "download-model",
|
||||
"IMAGE_DEPTH": "depth-plane",
|
||||
"IMAGE_BACKGROUND": "remove-background",
|
||||
"ORIGINAL_FRAMES": "depth-plane",
|
||||
"RECONSTRUCT": "export-reconstruction",
|
||||
"IMAGE_DEPTH": "generate-depth-plane",
|
||||
"REMOVE_BACKGROUND": "remove-background",
|
||||
"IMAGE_BACKGROUND": "remove-image-background",
|
||||
"ORIGINAL_BACKGROUND": "generate-original-depth-plane",
|
||||
"ORIGINAL_FRAMES": "extract-original-frames",
|
||||
}
|
||||
|
||||
|
||||
@@ -196,15 +200,37 @@ def jobs_directory():
|
||||
|
||||
|
||||
def temporary_input_path():
|
||||
path = jobs_directory() / "inputs"
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
return path / f"{uuid.uuid4().hex}.png"
|
||||
directory = Path(tempfile.mkdtemp(prefix="snapform-input-"))
|
||||
return directory / "input.png"
|
||||
|
||||
|
||||
def temporary_input_directory():
|
||||
path = jobs_directory() / "inputs" / f"{uuid.uuid4().hex}"
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
return path
|
||||
return Path(tempfile.mkdtemp(prefix="snapform-input-"))
|
||||
|
||||
|
||||
def move_input_into_job(input_path, job_directory):
|
||||
"""Move a Blender-generated input copy into the flat job directory."""
|
||||
input_path = Path(input_path)
|
||||
job_directory = Path(job_directory)
|
||||
if input_path.is_file():
|
||||
destination = job_directory / "input.png"
|
||||
input_path.replace(destination)
|
||||
try:
|
||||
input_path.parent.rmdir()
|
||||
except OSError:
|
||||
pass
|
||||
return destination
|
||||
if not input_path.is_dir():
|
||||
raise ValueError(f"Temporary input does not exist: {input_path}")
|
||||
for source in input_path.iterdir():
|
||||
if not source.is_file():
|
||||
raise ValueError(f"Temporary input contains a directory: {source}")
|
||||
destination = job_directory / source.name
|
||||
if destination.exists():
|
||||
raise ValueError(f"Job input filename already exists: {source.name}")
|
||||
source.replace(destination)
|
||||
input_path.rmdir()
|
||||
return job_directory
|
||||
|
||||
|
||||
def job_folder_name(job_type):
|
||||
@@ -213,7 +239,7 @@ def job_folder_name(job_type):
|
||||
|
||||
|
||||
def new_job_paths(job_type):
|
||||
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S-%f")
|
||||
stem = f"{job_folder_name(job_type)}_{timestamp}"
|
||||
directory = jobs_directory() / stem
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
@@ -824,6 +850,12 @@ def reconstruct_request(
|
||||
"ref_view_strategy": settings.ref_view_strategy,
|
||||
"remove_background_model_dir": "",
|
||||
"background_depth_distance": float(background_depth_distance),
|
||||
"mesh_filter_edges": bool(
|
||||
getattr(settings, "mesh_filter_edges", True)
|
||||
),
|
||||
"mesh_max_edge_length": float(
|
||||
getattr(settings, "mesh_max_edge_length", 0.1)
|
||||
),
|
||||
}
|
||||
if remove_background or background_depth_distance > 0.0:
|
||||
parameters["remove_background_model_dir"] = str(
|
||||
|
||||
Reference in New Issue
Block a user