feat(cutout): implement boundary padding for cutout textures

- Introduced a new `Boundary Padding` preference in the Cutout Tool with a default of 2 px and a configurable range of 1-4 px.
- Updated the Cutout client to establish inward mapping from the final Mask, sampling in a fixed direction and processing independent material RGBA and Depth.
- Enhanced the handling of RGBA and Depth during cutout operations, ensuring proper mapping and preservation of source data.
- Added tests to validate the new boundary padding functionality and its integration with existing cutout processes.

feat(geometry): remove overall mesh smoothing from geometry nodes

- Removed the `Smooth` input from several geometry node groups to eliminate unnecessary overall mesh smoothing.
- Retained `Smooth Weight` for depth nodes while removing it from Cutout and Relief Plane nodes.
- Ensured that boundary, normal, and fill smoothing behaviors remain intact and consistent.
- Updated tests and documentation to reflect the changes in node interfaces and behaviors.

feat(normals): scale tangent normals with depth

- Reused the existing `o_normal_reduction` attribute to adjust Tangent Normal strength based on the geometry's `Depth Scale`.
- Ensured that Tangent Normal strength is consistent with the geometry depth, preserving full strength for materials that do not provide the attribute.
- Updated tests to verify the correct behavior of normal strength adjustments in both Tangent and Object Space.
This commit is contained in:
2026-09-15 00:40:24 +08:00
parent ab282e4fdf
commit 591e62085a
93 changed files with 1915 additions and 2851 deletions

View File

@@ -5,10 +5,11 @@ import bpy
import numpy as np
import pytest
from anyimage.operators.cutout_tool.shape import NORMAL_REDUCTION_ATTRIBUTE_NAME
from tests.support.planes import surface, relief, evaluated
@pytest.mark.parametrize("subdivide", [0, 1, 3])
@pytest.mark.parametrize("subdivide", [0, 3])
def test_zero_depth_matches_plane_geometry_and_uv(surface, subdivide):
obj, set_value, plane, inputs, _ = surface
set_value("Subdivide", subdivide)
@@ -30,7 +31,7 @@ def test_zero_depth_matches_plane_geometry_and_uv(surface, subdivide):
assert projected[3:5] == regular[3:5]
@pytest.mark.parametrize("strength", [0, 0.5, 1, 2])
@pytest.mark.parametrize("strength", [0, 2])
def test_camera_projection_and_reference_depth(surface, strength):
obj, set_value, _, _, _ = surface
base = evaluated(obj)
@@ -51,6 +52,21 @@ def test_camera_projection_and_reference_depth(surface, strength):
np.tile((0, 0, 0.5 * strength), (len(shifted), 1)), atol=1e-6)
@pytest.mark.parametrize("depth_scale", [0.0, 2.0])
def test_relief_depth_scale_sets_normal_reduction(relief, depth_scale):
obj, set_value, *_ = relief
set_value("Depth Scale", depth_scale)
result = obj.evaluated_get(bpy.context.evaluated_depsgraph_get())
mesh = result.to_mesh()
try:
values = np.array([
value.value for value in mesh.attributes[NORMAL_REDUCTION_ATTRIBUTE_NAME].data
])
finally:
result.to_mesh_clear()
np.testing.assert_allclose(values, 1.0 - depth_scale)
@pytest.mark.parametrize("thickness", [0.000001, 0.2, 2.0])
def test_shell_keeps_front_and_closes_rectangular_boundary(surface, thickness):
obj, set_value, _, _, _ = surface
@@ -140,7 +156,7 @@ def test_relief_reads_z_and_keeps_the_base(relief, thickness):
assert obj.modifiers[0][inputs["Thickness"].identifier] == pytest.approx(thickness)
@pytest.mark.parametrize("reference", [0.5, 1.25, 2.0])
@pytest.mark.parametrize("reference", [0.5, 2.0])
def test_zero_thickness_relief_keeps_far_depth_at_object_space_zero(relief, reference):
obj, set_value, _, _, _ = relief
base = evaluated(obj)
@@ -156,6 +172,67 @@ def test_zero_thickness_relief_keeps_far_depth_at_object_space_zero(relief, refe
np.testing.assert_array_equal(result[2], base[2])
@pytest.mark.parametrize("reference", [0.0, 0.9])
def test_relief_far_depth_stops_at_thickness_height(relief, reference):
obj, set_value, _, _, image = relief
pixels = np.ones((8, 16, 4), dtype=np.float32)
pixels[..., 2] = 2.0
image.pixels.foreach_set(pixels.ravel())
image.update()
set_value("Uniform Scale", 0.5)
set_value("Reference Depth", reference)
set_value("Depth Scale", 2.0)
set_value("Thickness", 0.4)
points = evaluated(obj)[0]
assert points[:, 2].min() == pytest.approx(0.0)
assert points[:, 2].max() == pytest.approx(0.4)
def test_relief_offset_corrects_reference_before_direction_and_scale(relief):
obj, set_value, _, _, image = relief
pixels = np.ones((8, 16, 4), dtype=np.float32)
pixels[..., 2] = 2.0
image.pixels.foreach_set(pixels.ravel())
image.update()
set_value("Uniform Scale", 0.5)
set_value("Reference Depth", 1.0)
set_value("Depth Direction", (0.2, -0.1, 1.0))
set_value("Thickness", 0.0)
set_value("Depth Scale", 1.5)
set_value("Depth Offset", 1.0)
raised = evaluated(obj)[0]
set_value("Depth Offset", 0.5)
lowered = evaluated(obj)[0]
np.testing.assert_allclose(raised[:, 2] - lowered[:, 2], 0.75, atol=1e-6)
@pytest.mark.parametrize("offset", [-1.0, 1.0])
def test_zero_depth_scale_keeps_relief_at_depth_zero(relief, offset):
obj, set_value, _, _, _ = relief
set_value("Thickness", 0.4)
set_value("Depth Offset", offset)
set_value("Depth Scale", 0.0)
points = evaluated(obj)[0]
assert points[:, 2].min() == pytest.approx(0.0)
assert points[:, 2].max() == pytest.approx(0.4)
def test_negative_relief_offset_is_clamped_at_depth_zero(relief):
obj, set_value, _, _, image = relief
pixels = np.ones((8, 16, 4), dtype=np.float32)
pixels[..., 2] = 1.0
image.pixels.foreach_set(pixels.ravel())
image.update()
set_value("Uniform Scale", 1.0)
set_value("Reference Depth", 1.0)
set_value("Depth Offset", -0.5)
set_value("Depth Scale", 1.0)
set_value("Thickness", 0.3)
points = evaluated(obj)[0]
assert points[:, 2].min() == pytest.approx(0.0)
assert points[:, 2].max() == pytest.approx(0.3)
def test_curved_shell_smooths_normals_without_shrinking_thickness(surface):
from scipy.spatial import cKDTree
@@ -219,32 +296,6 @@ def test_relief_direction_adjusts_depth_and_keeps_base(relief, thickness, direct
np.testing.assert_array_equal(result[2], base[2])
@pytest.mark.parametrize("thickness", [0.0, 0.4])
def test_relief_smooth_preserves_topology_uv_and_materials(relief, thickness):
obj, set_value, _, _, image = relief
pixels = np.asarray(image.pixels[:], dtype=np.float32).reshape(8, 16, 4)
pixels[..., 2] += (np.arange(16) % 2) * 0.5
image.pixels.foreach_set(pixels.ravel())
image.update()
set_value("Thickness", thickness)
set_value("Reference Depth", 2.0)
set_value("Depth Scale", 1.0)
set_value("Depth Direction", (0.1, -0.1, 1))
base = evaluated(obj)
set_value("Smooth", 3)
result = evaluated(obj)
assert np.isfinite(result[0]).all()
assert np.max(abs(result[0] - base[0])) > 1e-4
assert result[1] == base[1]
np.testing.assert_array_equal(result[2], base[2])
assert result[3:] == base[3:]
set_value("Smooth Weight", 0.0)
np.testing.assert_allclose(evaluated(obj)[0], base[0], atol=1e-6)
set_value("Smooth Weight", 1.0)
set_value("Smooth", 0)
np.testing.assert_allclose(evaluated(obj)[0], base[0], atol=1e-6)
@pytest.mark.parametrize("pattern,threshold", [
("valid", 1.0), ("invalid", 0.0), ("invalid", 0.9),
("partial", 0.4), ("partial", 0.9), ("half", 0.9), ("stripe", 0.9),
@@ -299,28 +350,3 @@ def test_valid_only_precedes_closed_shell_generation(surface):
edges = Counter(tuple(sorted((a, b))) for face in faces for a, b in zip(face, (*face[1:], face[0])))
assert set(edges.values()) == {2}
assert np.isfinite(points).all() and np.isfinite(uv).all()
@pytest.mark.parametrize("thickness", [0.0, 0.2])
def test_depth_smooth_changes_positions_and_preserves_topology(surface, thickness):
obj, set_value, _, _, depth_image = surface
pixels = np.asarray(depth_image.pixels[:], dtype=np.float32).reshape(8, 16, 4)
pixels[..., 2] += (np.arange(16) % 2) * 0.3
pixels[:, :4, 3] = 0
depth_image.pixels.foreach_set(pixels.ravel())
depth_image.update()
set_value("Depth Scale", 1.0)
set_value("Thickness", thickness)
base = evaluated(obj)
set_value("Smooth", 3)
smoothed = evaluated(obj)
assert smoothed[1] == base[1]
np.testing.assert_allclose(smoothed[2], base[2])
assert smoothed[3:5] == base[3:5]
assert np.isfinite(smoothed[0]).all()
assert not np.allclose(smoothed[0], base[0])
set_value("Smooth Weight", 0.0)
np.testing.assert_allclose(evaluated(obj)[0], base[0], atol=1e-6)
set_value("Smooth Weight", 1.0)
set_value("Smooth", 0)
np.testing.assert_allclose(evaluated(obj)[0], base[0], atol=1e-6)