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:
@@ -1279,7 +1279,7 @@ class AddonTest(unittest.TestCase):
|
||||
self.assertEqual(paths["status"].parent, paths["result"])
|
||||
self.assertEqual(paths["status"].stem, paths["result"].name)
|
||||
|
||||
def test_new_job_paths_uses_type_time_folder_name(self):
|
||||
def test_new_job_paths_uses_unique_action_object_names(self):
|
||||
runtime = importlib.import_module("snapform.runtime")
|
||||
with TemporaryDirectory() as directory:
|
||||
jobs_root = Path(directory)
|
||||
@@ -1300,15 +1300,41 @@ class AddonTest(unittest.TestCase):
|
||||
|
||||
self.assertRegex(
|
||||
depth_paths["result"].name,
|
||||
r"^depth-plane_\d{8}-\d{6}$",
|
||||
r"^generate-depth-plane_\d{8}-\d{6}-\d{6}$",
|
||||
)
|
||||
self.assertTrue(
|
||||
background_paths["result"].name.startswith(
|
||||
"remove-background_"
|
||||
"remove-image-background_"
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
frames_paths["result"].name.startswith("depth-plane_")
|
||||
frames_paths["result"].name.startswith(
|
||||
"extract-original-frames_"
|
||||
)
|
||||
)
|
||||
|
||||
def test_generated_inputs_are_moved_into_job_root(self):
|
||||
runtime = importlib.import_module("snapform.runtime")
|
||||
with TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
staging = root / "staging"
|
||||
staging.mkdir()
|
||||
(staging / "frame.0001.jpg").write_bytes(b"first")
|
||||
(staging / "frame.0002.jpg").write_bytes(b"second")
|
||||
job_directory = root / "job"
|
||||
job_directory.mkdir()
|
||||
|
||||
result = runtime.move_input_into_job(staging, job_directory)
|
||||
|
||||
self.assertEqual(result, job_directory)
|
||||
self.assertFalse(staging.exists())
|
||||
self.assertEqual(
|
||||
(job_directory / "frame.0001.jpg").read_bytes(),
|
||||
b"first",
|
||||
)
|
||||
self.assertEqual(
|
||||
(job_directory / "frame.0002.jpg").read_bytes(),
|
||||
b"second",
|
||||
)
|
||||
|
||||
def test_empty_image_start_frame_honors_image_user(self):
|
||||
@@ -1468,9 +1494,83 @@ class AddonTest(unittest.TestCase):
|
||||
|
||||
self.assertEqual(
|
||||
identifiers,
|
||||
["glb", "gs_ply", "depth_vis", "mini_npz"],
|
||||
["glb", "gs_ply", "depth_vis", "mini_npz", "mesh"],
|
||||
)
|
||||
self.assertEqual(export_format["default"], "glb")
|
||||
self.assertEqual(export_format["name"], "Output Type")
|
||||
self.assertEqual(
|
||||
[item[1] for item in export_format["items"]],
|
||||
[
|
||||
"Point Cloud (GLB)",
|
||||
"Gaussian Splats (PLY)",
|
||||
"Depth Preview (Images)",
|
||||
"Depth Data (NPZ)",
|
||||
"Textured Mesh (GLB)",
|
||||
],
|
||||
)
|
||||
|
||||
def test_mesh_is_a_da3_output_type(self):
|
||||
settings = SimpleNamespace(
|
||||
input_path="",
|
||||
export_format="mesh",
|
||||
model="BASE",
|
||||
gs_model="GIANT_1_1",
|
||||
process_res=504,
|
||||
process_res_method="upper_bound_resize",
|
||||
conf_thresh_percentile=40.0,
|
||||
num_max_points=1_000_000,
|
||||
show_cameras=True,
|
||||
gs_views_interval=1,
|
||||
video_frames=16,
|
||||
device="CPU",
|
||||
use_ray_pose=False,
|
||||
ref_view_strategy="saddle_balanced",
|
||||
)
|
||||
operator = self.addon.RunJob()
|
||||
operator.job_type = self.addon.operators.RECONSTRUCTION_JOB
|
||||
|
||||
with TemporaryDirectory() as directory:
|
||||
input_path = Path(directory) / "input.png"
|
||||
input_path.touch()
|
||||
settings.input_path = str(input_path)
|
||||
paths = {
|
||||
"log": Path(directory) / "job.log",
|
||||
"status": Path(directory) / "job.json",
|
||||
"result": Path(directory) / "result",
|
||||
}
|
||||
with patch.object(
|
||||
self.addon.runtime,
|
||||
"new_job_paths",
|
||||
return_value=paths,
|
||||
), patch.object(
|
||||
self.addon.runtime,
|
||||
"runtime_ready",
|
||||
return_value=True,
|
||||
), patch.object(
|
||||
self.addon.runtime,
|
||||
"model_ready",
|
||||
return_value=True,
|
||||
), patch.object(
|
||||
self.addon.runtime,
|
||||
"reconstruct_request",
|
||||
return_value=self.addon.runtime.HostJobRequest(
|
||||
{"job_id": "test"}
|
||||
),
|
||||
) as reconstruct:
|
||||
operator._prepare_command(None, settings)
|
||||
|
||||
self.assertEqual(reconstruct.call_args.args[1], "mesh")
|
||||
self.assertEqual(reconstruct.call_args.kwargs["model_key"], "BASE")
|
||||
|
||||
def test_confidence_threshold_is_a_bounded_percentage(self):
|
||||
confidence = self.addon.SnapFormSettings.__annotations__[
|
||||
"conf_thresh_percentile"
|
||||
]
|
||||
|
||||
self.assertEqual(confidence["name"], "Confidence Threshold")
|
||||
self.assertEqual(confidence["min"], 0.0)
|
||||
self.assertEqual(confidence["max"], 100.0)
|
||||
self.assertEqual(confidence["subtype"], "PERCENTAGE")
|
||||
|
||||
def test_gs_model_property_only_includes_gaussian_models(self):
|
||||
gs_model = self.addon.SnapFormSettings.__annotations__[
|
||||
@@ -1586,9 +1686,17 @@ class AddonTest(unittest.TestCase):
|
||||
"DEFAULT_CLOSED",
|
||||
self.addon.DebugPanel.bl_options,
|
||||
)
|
||||
for panel in (self.addon.Da3DebugPanel, self.addon.Ben2DebugPanel):
|
||||
panels = (
|
||||
self.addon.Da3OutputDebugPanel,
|
||||
self.addon.Ben2RemovalDebugPanel,
|
||||
)
|
||||
for panel in panels:
|
||||
self.assertEqual(panel.bl_parent_id, self.addon.DebugPanel.bl_idname)
|
||||
self.assertIn("DEFAULT_CLOSED", panel.bl_options)
|
||||
self.assertEqual(
|
||||
[panel.bl_label for panel in panels],
|
||||
["DA3 Output Test", "BEN2 Removal Test"],
|
||||
)
|
||||
|
||||
def test_host_panel_exposes_shared_host_state_and_controls(self):
|
||||
self.assertIn(self.addon.HostPanel, self.addon.CLASSES)
|
||||
|
||||
Reference in New Issue
Block a user