Refactor depth surface handling and unify depth sampling rules
- Removed the `always_vertex` parameter from `build_surface_camera` to streamline depth sampling for cutouts and ensure consistent behavior across depth plane and panorama. - Updated depth sampling logic to ensure that all free boundary points, including the original frame of the depth plane, use neighboring face depth instead of their own texture sampling. - Adjusted the depth mask deletion process to operate on faces rather than points, eliminating the need for additional cleanup of dangling edges. - Ensured that the cutout rules are consistently applied across all relevant nodes, removing exceptions and simplifying the logic. - Updated tests to verify the new behavior, ensuring that cutout points follow the depth of adjacent faces and that the original frame maintains its depth sampling. - Refactored geometry handling in multiple depth-related nodes to improve clarity and maintainability.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
from .nodes import evaluate_field, group_input
|
||||
from .depth_surface import _math
|
||||
from .smoothing import edge_boundary_field, expand_smooth
|
||||
from .smoothing import edge_boundary_field, pinned_smooth
|
||||
|
||||
|
||||
def boundary_influence(group, protected=False, *, boundary=None):
|
||||
@@ -92,9 +92,10 @@ def cut_boundary_influence(group, split_boundary, protected=False, *, outline_sc
|
||||
|
||||
|
||||
def smooth_cut_boundary(group, geometry, split_boundary=False, *, protected=False, outline_scale=0.1, boundary=None):
|
||||
"""Move boundary vertices toward the smoothed position through split and outline influence."""
|
||||
"""Move boundary vertices toward the pinned position through split and outline influence."""
|
||||
influence = cut_boundary_influence(
|
||||
group, split_boundary, protected, outline_scale=outline_scale, boundary=boundary,
|
||||
)
|
||||
# The support band depends on topology, which stays unchanged in the loop.
|
||||
return expand_smooth(group, geometry, "Boundary Smooth", influence)
|
||||
iterations = group_input(group.nodes, {"Boundary Smooth"}).outputs["Boundary Smooth"]
|
||||
return pinned_smooth(group, geometry, iterations, influence)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Face separation and connected thickness for Depth Surface assets."""
|
||||
|
||||
from .nodes import evaluate_field, store_float_attribute, store_boolean_attribute, remove_attribute_pattern, sample_field
|
||||
from .smoothing import edge_boundary_field
|
||||
|
||||
|
||||
CUT_ATTRIBUTE = "_o_anyimage_depth_cut"
|
||||
@@ -275,21 +276,24 @@ def split_depth_surface(group, geometry, face_camera, strength, reference_depth,
|
||||
return choose.outputs["Output"], face_camera, cut
|
||||
|
||||
|
||||
def build_surface_camera(group, original, separated, cut_vertex, strength, *, always_vertex=None):
|
||||
"""Change cut depth along the original ray, preserving every other vertex."""
|
||||
enabled = group.nodes.new("GeometryNodeSwitch")
|
||||
def build_surface_camera(group, original, separated, cut_vertex, strength):
|
||||
"""Take cut depth from the adjacent face sample along each unchanged ray.
|
||||
|
||||
Depth Split edges and every open boundary left by Depth Mask deletion share
|
||||
one replacement, so each cut edge sits on the surface it belongs to.
|
||||
"""
|
||||
nodes, links = group.nodes, group.links
|
||||
cut_boundary = evaluate_field(group, edge_boundary_field(nodes, links), "BOOLEAN", "POINT")
|
||||
enabled = nodes.new("GeometryNodeSwitch")
|
||||
enabled.input_type = "BOOLEAN"
|
||||
group.links.new(_math(group, "GREATER_THAN", strength, 0.0), enabled.inputs["Switch"])
|
||||
links.new(_math(group, "GREATER_THAN", strength, 0.0), enabled.inputs["Switch"])
|
||||
enabled.inputs["False"].default_value = False
|
||||
group.links.new(cut_vertex, enabled.inputs["True"])
|
||||
if always_vertex is not None:
|
||||
combined = group.nodes.new("FunctionNodeBooleanMath")
|
||||
combined.operation = "OR"
|
||||
group.links.new(enabled.outputs["Output"], combined.inputs[0])
|
||||
group.links.new(always_vertex, combined.inputs[1])
|
||||
enabled = combined.outputs["Boolean"]
|
||||
else:
|
||||
enabled = enabled.outputs["Output"]
|
||||
links.new(cut_vertex, enabled.inputs["True"])
|
||||
combined = nodes.new("FunctionNodeBooleanMath")
|
||||
combined.operation = "OR"
|
||||
links.new(enabled.outputs["Output"], combined.inputs[0])
|
||||
links.new(cut_boundary, combined.inputs[1])
|
||||
enabled = combined.outputs["Boolean"]
|
||||
original_axes = group.nodes.new("ShaderNodeSeparateXYZ")
|
||||
separated_axes = group.nodes.new("ShaderNodeSeparateXYZ")
|
||||
group.links.new(original, original_axes.inputs[0])
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
"""Build shared boundary fields and iterative smoothing."""
|
||||
from .nodes import group_input, sample_field
|
||||
"""Build shared boundary fields and pinned position smoothing."""
|
||||
from .nodes import evaluate_field, sample_field
|
||||
|
||||
|
||||
def edge_boundary_field(nodes, links):
|
||||
"""Report the points sitting on an open or loose boundary."""
|
||||
vertex_neighbors = nodes.new("GeometryNodeInputMeshVertexNeighbors")
|
||||
loose_vertex = nodes.new("FunctionNodeCompare")
|
||||
loose_vertex.data_type = "INT"
|
||||
@@ -40,54 +41,46 @@ def edge_boundary_field(nodes, links):
|
||||
return is_boundary.outputs["Boolean"]
|
||||
|
||||
|
||||
def expand_smooth(group, geometry, iterations_name, influence):
|
||||
def _multiply(group, a, b):
|
||||
node = group.nodes.new("ShaderNodeMath")
|
||||
node.operation = "MULTIPLY"
|
||||
for index, value in enumerate((a, b)):
|
||||
if isinstance(value, (int, float)):
|
||||
node.inputs[index].default_value = value
|
||||
else:
|
||||
group.links.new(value, node.inputs[index])
|
||||
return node.outputs[0]
|
||||
|
||||
|
||||
def _boundary_target(group, geometry, current, boundary_points):
|
||||
"""Blur the boundary strip alone and sample it back onto every point."""
|
||||
nodes = group.nodes
|
||||
links = group.links
|
||||
iteration_controls = group_input(nodes, {iterations_name})
|
||||
repeat_output = nodes.new("GeometryNodeRepeatOutput")
|
||||
repeat_input = nodes.new("GeometryNodeRepeatInput")
|
||||
repeat_input.pair_with_output(repeat_output)
|
||||
links.new(
|
||||
iteration_controls.outputs[iterations_name],
|
||||
repeat_input.inputs["Iterations"],
|
||||
)
|
||||
|
||||
boundary_field = edge_boundary_field(nodes, links)
|
||||
boundary_points = nodes.new("GeometryNodeFieldOnDomain")
|
||||
boundary_points.data_type = "BOOLEAN"
|
||||
boundary_points.domain = "POINT"
|
||||
links.new(boundary_field, boundary_points.inputs["Value"])
|
||||
|
||||
boundary_geometry = nodes.new("GeometryNodeSeparateGeometry")
|
||||
boundary_geometry.domain = "POINT"
|
||||
links.new(repeat_input.outputs["Geometry"], boundary_geometry.inputs["Geometry"])
|
||||
links.new(boundary_points.outputs["Value"], boundary_geometry.inputs["Selection"])
|
||||
links.new(geometry, repeat_input.inputs["Geometry"])
|
||||
nearest_boundary = nodes.new("GeometryNodeSampleNearest")
|
||||
nearest_boundary.domain = "POINT"
|
||||
# Both boundary meshes keep the same compact index order: only positions change.
|
||||
source_boundary = nodes.new("GeometryNodeSeparateGeometry")
|
||||
source_boundary.domain = "POINT"
|
||||
links.new(geometry, source_boundary.inputs["Geometry"])
|
||||
links.new(boundary_points.outputs["Value"], source_boundary.inputs["Selection"])
|
||||
links.new(source_boundary.outputs["Selection"], nearest_boundary.inputs["Geometry"])
|
||||
source_position = nodes.new("GeometryNodeInputPosition").outputs["Position"]
|
||||
fixed_position = sample_field(group, geometry, source_position, "FLOAT_VECTOR")
|
||||
links.new(fixed_position, nearest_boundary.inputs["Sample Position"])
|
||||
|
||||
position = nodes.new("GeometryNodeInputPosition")
|
||||
smooth_all = nodes.new("GeometryNodeBlurAttribute")
|
||||
smooth_all.data_type = "FLOAT_VECTOR"
|
||||
smooth_all.inputs["Iterations"].default_value = 1
|
||||
smooth_all.inputs["Weight"].default_value = 1.0
|
||||
links.new(position.outputs["Position"], smooth_all.inputs["Value"])
|
||||
|
||||
links.new(current, boundary_geometry.inputs["Geometry"])
|
||||
links.new(boundary_points, boundary_geometry.inputs["Selection"])
|
||||
boundary_position = nodes.new("GeometryNodeInputPosition")
|
||||
smooth_boundary = nodes.new("GeometryNodeBlurAttribute")
|
||||
smooth_boundary.data_type = "FLOAT_VECTOR"
|
||||
smooth_boundary.inputs["Iterations"].default_value = 1
|
||||
smooth_boundary.inputs["Weight"].default_value = 0.5
|
||||
links.new(boundary_position.outputs["Position"], smooth_boundary.inputs["Value"])
|
||||
|
||||
nearest_boundary = nodes.new("GeometryNodeSampleNearest")
|
||||
nearest_boundary.domain = "POINT"
|
||||
# Both boundary meshes keep the same compact index order: only positions change,
|
||||
# so the lookup can stay anchored on the untouched input geometry.
|
||||
source_boundary = nodes.new("GeometryNodeSeparateGeometry")
|
||||
source_boundary.domain = "POINT"
|
||||
links.new(geometry, source_boundary.inputs["Geometry"])
|
||||
links.new(boundary_points, source_boundary.inputs["Selection"])
|
||||
links.new(source_boundary.outputs["Selection"], nearest_boundary.inputs["Geometry"])
|
||||
fixed_position = sample_field(
|
||||
group, geometry, boundary_position.outputs["Position"], "FLOAT_VECTOR"
|
||||
)
|
||||
links.new(fixed_position, nearest_boundary.inputs["Sample Position"])
|
||||
|
||||
sample_boundary = nodes.new("GeometryNodeSampleIndex")
|
||||
sample_boundary.data_type = "FLOAT_VECTOR"
|
||||
sample_boundary.domain = "POINT"
|
||||
@@ -95,26 +88,90 @@ def expand_smooth(group, geometry, iterations_name, influence):
|
||||
links.new(boundary_geometry.outputs["Selection"], sample_boundary.inputs["Geometry"])
|
||||
links.new(smooth_boundary.outputs["Value"], sample_boundary.inputs["Value"])
|
||||
links.new(nearest_boundary.outputs["Index"], sample_boundary.inputs["Index"])
|
||||
return sample_boundary.outputs["Value"]
|
||||
|
||||
choose_boundary = nodes.new("GeometryNodeSwitch")
|
||||
choose_boundary.input_type = "VECTOR"
|
||||
links.new(boundary_points.outputs["Value"], choose_boundary.inputs["Switch"])
|
||||
links.new(smooth_all.outputs["Value"], choose_boundary.inputs["False"])
|
||||
links.new(sample_boundary.outputs["Value"], choose_boundary.inputs["True"])
|
||||
|
||||
current_position = nodes.new("GeometryNodeInputPosition")
|
||||
mix_position = nodes.new("ShaderNodeMix")
|
||||
mix_position.data_type = "VECTOR"
|
||||
links.new(influence, mix_position.inputs[0])
|
||||
links.new(current_position.outputs["Position"], mix_position.inputs[4])
|
||||
links.new(choose_boundary.outputs["Output"], mix_position.inputs[5])
|
||||
def pinned_smooth(
|
||||
group,
|
||||
geometry,
|
||||
iterations,
|
||||
region,
|
||||
weight=1.0,
|
||||
movement=None,
|
||||
pin_boundary=True,
|
||||
pin_sharp=True,
|
||||
):
|
||||
"""Smooth positions toward a pinned target inside an influence region.
|
||||
|
||||
``pin_boundary`` sends boundary points to a boundary-only blur so an outline
|
||||
is never dragged inward. ``pin_sharp`` lowers the weight of creases through
|
||||
the sharpness of the normal field. Junction bands keep the sharpness weight
|
||||
without the boundary rule, where the influenced points are not a boundary.
|
||||
"""
|
||||
nodes, links = group.nodes, group.links
|
||||
repeat_output = nodes.new("GeometryNodeRepeatOutput")
|
||||
repeat_input = nodes.new("GeometryNodeRepeatInput")
|
||||
repeat_input.pair_with_output(repeat_output)
|
||||
links.new(iterations, repeat_input.inputs["Iterations"])
|
||||
links.new(geometry, repeat_input.inputs["Geometry"])
|
||||
current = repeat_input.outputs["Geometry"]
|
||||
|
||||
position = nodes.new("GeometryNodeInputPosition")
|
||||
smooth_all = nodes.new("GeometryNodeBlurAttribute")
|
||||
smooth_all.data_type = "FLOAT_VECTOR"
|
||||
smooth_all.inputs["Iterations"].default_value = 1
|
||||
smooth_all.inputs["Weight"].default_value = 1.0
|
||||
links.new(position.outputs["Position"], smooth_all.inputs["Value"])
|
||||
target = smooth_all.outputs["Value"]
|
||||
if pin_boundary:
|
||||
boundary_points = evaluate_field(
|
||||
group, edge_boundary_field(nodes, links), "BOOLEAN", "POINT"
|
||||
)
|
||||
choose = nodes.new("GeometryNodeSwitch")
|
||||
choose.input_type = "VECTOR"
|
||||
links.new(boundary_points, choose.inputs["Switch"])
|
||||
links.new(smooth_all.outputs["Value"], choose.inputs["False"])
|
||||
links.new(
|
||||
_boundary_target(group, geometry, current, boundary_points),
|
||||
choose.inputs["True"],
|
||||
)
|
||||
target = choose.outputs["Output"]
|
||||
|
||||
if pin_sharp:
|
||||
normal = nodes.new("GeometryNodeInputNormal")
|
||||
smooth_normal = nodes.new("GeometryNodeBlurAttribute")
|
||||
smooth_normal.data_type = "FLOAT_VECTOR"
|
||||
smooth_normal.inputs["Iterations"].default_value = 10
|
||||
smooth_normal.inputs["Weight"].default_value = 1.0
|
||||
links.new(normal.outputs["Normal"], smooth_normal.inputs["Value"])
|
||||
coherence = nodes.new("ShaderNodeVectorMath")
|
||||
coherence.operation = "LENGTH"
|
||||
links.new(smooth_normal.outputs["Value"], coherence.inputs[0])
|
||||
weight = _multiply(group, weight, coherence.outputs["Value"])
|
||||
weight = _multiply(group, weight, region)
|
||||
|
||||
difference = nodes.new("ShaderNodeVectorMath")
|
||||
difference.operation = "SUBTRACT"
|
||||
links.new(target, difference.inputs[0])
|
||||
links.new(position.outputs["Position"], difference.inputs[1])
|
||||
offset = nodes.new("ShaderNodeVectorMath")
|
||||
offset.operation = "SCALE"
|
||||
links.new(difference.outputs[0], offset.inputs[0])
|
||||
links.new(weight, offset.inputs[3])
|
||||
if movement is not None:
|
||||
masked = nodes.new("ShaderNodeVectorMath")
|
||||
masked.operation = "MULTIPLY"
|
||||
links.new(offset.outputs[0], masked.inputs[0])
|
||||
masked.inputs[1].default_value = movement
|
||||
offset = masked
|
||||
set_position = nodes.new("GeometryNodeSetPosition")
|
||||
links.new(repeat_input.outputs["Geometry"], set_position.inputs["Geometry"])
|
||||
links.new(mix_position.outputs["Result"], set_position.inputs["Position"])
|
||||
links.new(current, set_position.inputs["Geometry"])
|
||||
links.new(offset.outputs[0], set_position.inputs["Offset"])
|
||||
links.new(set_position.outputs["Geometry"], repeat_output.inputs["Geometry"])
|
||||
|
||||
enabled = nodes.new("GeometryNodeSwitch")
|
||||
enabled.input_type = "GEOMETRY"
|
||||
links.new(iteration_controls.outputs[iterations_name], enabled.inputs["Switch"])
|
||||
links.new(iterations, enabled.inputs["Switch"])
|
||||
links.new(geometry, enabled.inputs["False"])
|
||||
links.new(repeat_output.outputs["Geometry"], enabled.inputs["True"])
|
||||
return enabled.outputs["Output"]
|
||||
|
||||
@@ -1,21 +1,10 @@
|
||||
"""Remove invalid vertices and the wire edges left by point deletion."""
|
||||
"""Delete the faces the depth mask excludes."""
|
||||
|
||||
|
||||
def delete_invalid_points(group, geometry, invalid):
|
||||
def delete_invalid_faces(group, geometry, invalid):
|
||||
nodes, links = group.nodes, group.links
|
||||
delete = nodes.new("GeometryNodeDeleteGeometry")
|
||||
delete.domain, delete.mode = "POINT", "ALL"
|
||||
delete.domain, delete.mode = "FACE", "ALL"
|
||||
links.new(geometry, delete.inputs["Geometry"])
|
||||
links.new(invalid, delete.inputs["Selection"])
|
||||
neighbors = nodes.new("GeometryNodeInputMeshEdgeNeighbors")
|
||||
wire = nodes.new("FunctionNodeCompare")
|
||||
wire.data_type, wire.operation = "INT", "EQUAL"
|
||||
a = next(socket for socket in wire.inputs if socket.identifier == "A_INT")
|
||||
b = next(socket for socket in wire.inputs if socket.identifier == "B_INT")
|
||||
b.default_value = 0
|
||||
links.new(neighbors.outputs["Face Count"], a)
|
||||
cleanup = nodes.new("GeometryNodeDeleteGeometry")
|
||||
cleanup.domain, cleanup.mode = "EDGE", "ALL"
|
||||
links.new(delete.outputs["Geometry"], cleanup.inputs["Geometry"])
|
||||
links.new(wire.outputs["Result"], cleanup.inputs["Selection"])
|
||||
return cleanup.outputs["Geometry"]
|
||||
return delete.outputs["Geometry"]
|
||||
|
||||
Reference in New Issue
Block a user