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.
This commit is contained in:
@@ -298,9 +298,52 @@ class ImageDepthTest(unittest.TestCase):
|
||||
original_source = inspect.getsource(
|
||||
self.image_depth.build_image_depth_plane
|
||||
)
|
||||
self.assertIn("depth_name = depth_data_name(source_object)", estimate_source)
|
||||
self.assertIn(
|
||||
"depth_name = depth_name or depth_data_name(source_object)",
|
||||
estimate_source,
|
||||
)
|
||||
self.assertIn("depth_data_name(source_object)", original_source)
|
||||
|
||||
def test_removed_background_name_uses_source_image_base_name(self):
|
||||
source_object = SimpleNamespace(
|
||||
data=SimpleNamespace(name="img.png"),
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
self.image_depth.removed_background_data_name(source_object),
|
||||
"img.rb",
|
||||
)
|
||||
source_object.data.name = "img.png.001"
|
||||
self.assertEqual(
|
||||
self.image_depth.removed_background_data_name(source_object),
|
||||
"img.001.rb",
|
||||
)
|
||||
|
||||
def test_depth_name_override_keeps_original_base_name(self):
|
||||
source = inspect.getsource(self.image_depth.build_depth_plane)
|
||||
|
||||
self.assertIn(
|
||||
"depth_name = depth_name or depth_data_name(source_object)",
|
||||
source,
|
||||
)
|
||||
self.assertIn(
|
||||
"color_image if color_image is not None else source_object.data",
|
||||
source,
|
||||
)
|
||||
|
||||
def test_original_depth_background_only_changes_material_color(self):
|
||||
source = inspect.getsource(self.image_depth.build_image_depth_plane)
|
||||
|
||||
self.assertIn("texture.image = source_object.data", source)
|
||||
self.assertIn(
|
||||
"source_object.data if displacement_via == \"MATERIAL\" else None",
|
||||
source,
|
||||
)
|
||||
self.assertIn(
|
||||
"color_image if color_image is not None else source_object.data",
|
||||
source,
|
||||
)
|
||||
|
||||
def test_material_uses_source_object_name(self):
|
||||
da3_source = inspect.getsource(self.image_depth.build_depth_plane)
|
||||
image_source = inspect.getsource(
|
||||
@@ -319,7 +362,10 @@ class ImageDepthTest(unittest.TestCase):
|
||||
self.image_depth.build_depth_plane
|
||||
)
|
||||
|
||||
self.assertIn("depth_name = depth_data_name(source_object)", source)
|
||||
self.assertIn(
|
||||
"depth_name = depth_name or depth_data_name(source_object)",
|
||||
source,
|
||||
)
|
||||
self.assertIn("create_depth_image(\n depth_name,", source)
|
||||
self.assertIn("bpy.data.textures.new(\n depth_name,", source)
|
||||
self.assertIn('texture.extension = "EXTEND"', source)
|
||||
@@ -385,6 +431,42 @@ class ImageDepthTest(unittest.TestCase):
|
||||
)
|
||||
self.assertIn("set_displacement_only(material)", source)
|
||||
|
||||
def test_unshaded_material_uses_alpha_mixed_emission(self):
|
||||
source = inspect.getsource(self.image_depth.create_material)
|
||||
|
||||
unshaded_start = source.index("if unshaded:")
|
||||
shaded_start = source.index("else:", unshaded_start)
|
||||
displacement_start = source.index(
|
||||
"if displacement_image is not None:",
|
||||
shaded_start,
|
||||
)
|
||||
unshaded_source = source[unshaded_start:shaded_start]
|
||||
shaded_source = source[shaded_start:displacement_start]
|
||||
|
||||
self.assertIn('nodes.new("ShaderNodeEmission")', unshaded_source)
|
||||
self.assertIn(
|
||||
'nodes.new("ShaderNodeBsdfTransparent")',
|
||||
unshaded_source,
|
||||
)
|
||||
self.assertIn('nodes.new("ShaderNodeMixShader")', unshaded_source)
|
||||
self.assertIn(
|
||||
'color_texture.outputs["Color"]',
|
||||
unshaded_source,
|
||||
)
|
||||
self.assertIn('emission.inputs["Color"]', unshaded_source)
|
||||
self.assertIn('color_texture.outputs["Alpha"]', unshaded_source)
|
||||
self.assertIn('mix_shader.inputs["Fac"]', unshaded_source)
|
||||
self.assertIn('transparent.outputs["BSDF"]', unshaded_source)
|
||||
self.assertIn('mix_shader.inputs[1]', unshaded_source)
|
||||
self.assertIn('emission.outputs["Emission"]', unshaded_source)
|
||||
self.assertIn('mix_shader.inputs[2]', unshaded_source)
|
||||
self.assertIn('mix_shader.outputs["Shader"]', unshaded_source)
|
||||
self.assertNotIn("ShaderNodeBsdfPrincipled", unshaded_source)
|
||||
self.assertNotIn("ShaderNodeBump", unshaded_source)
|
||||
self.assertNotIn("ShaderNodeFloatCurve", unshaded_source)
|
||||
self.assertIn("ShaderNodeBsdfPrincipled", shaded_source)
|
||||
self.assertGreater(displacement_start, unshaded_start)
|
||||
|
||||
def test_displacement_values_follow_depth_source(self):
|
||||
estimate_source = inspect.getsource(
|
||||
self.image_depth.build_depth_plane
|
||||
@@ -434,6 +516,7 @@ class ImageDepthTest(unittest.TestCase):
|
||||
'if displacement_via == "MATERIAL" else None',
|
||||
source,
|
||||
)
|
||||
self.assertIn("unshaded=unshaded", source)
|
||||
|
||||
def test_surface_displacement_is_set_to_displacement_only(self):
|
||||
class Material:
|
||||
|
||||
Reference in New Issue
Block a user