Refactor comparison operations in geometry nodes

- Introduced a new `compare_node` function to streamline comparison operations across various geometry nodes.
- Replaced instances of mathematical comparison nodes with the new `compare_node` function in multiple files, enhancing code readability and maintainability.
- Updated related logic in cutout, depth surface, and image processing groups to utilize the new comparison method.
- Ensured consistent handling of boolean logic through the introduction of a `boolean_node` function for combining boolean inputs.
This commit is contained in:
2026-09-16 21:42:02 +08:00
parent c62ec2cd48
commit 78bbff6351
19 changed files with 282 additions and 200 deletions

View File

@@ -5,7 +5,7 @@ import bpy
from ..common.validity import delete_invalid_faces
from ..common.nodes import group_input as _group_input, interface_socket as _interface_socket
from ..common.nodes import prepare_node_group, float_input, evaluate_field
from ..common.nodes import compare_node, prepare_node_group, float_input, evaluate_field
from ..common.boundary_smoothing import smooth_boundary_camera, smooth_cut_boundary
from ..common.depth_surface import (
_math, project_depth_surface, thicken_depth_surface,
@@ -51,7 +51,7 @@ def build_image_depth_plane_group(image_plane_group):
validity_threshold = _interface_socket(group, "Mask Threshold", "INPUT", "NodeSocketFloat", parent=options)
validity_threshold.description = "Set the minimum depth mask value treated as valid. Higher values exclude more partially valid boundary areas."
validity_threshold.default_value = 0.9
validity_threshold.min_value, validity_threshold.max_value = 0.0, 1.0
validity_threshold.min_value, validity_threshold.max_value = 0.0, 0.99
validity_threshold.subtype = "FACTOR"
float_input(group, "Reference Depth", 1.0, subtype="DISTANCE", parent=options)
data = group.interface.new_panel(name="Data", default_closed=True)
@@ -97,15 +97,15 @@ def build_image_depth_plane_group(image_plane_group):
links.new(texture.outputs["Color"], channels.inputs["Color"])
invalid = nodes.new("FunctionNodeCompare")
invalid.data_type, invalid.operation = "FLOAT", "LESS_THAN"
links.new(threshold_input.outputs["Mask Threshold"], invalid.inputs["B"])
links.new(channels.outputs["Alpha"], invalid.inputs["A"])
links.new(threshold_input.outputs["Mask Threshold"], invalid.inputs["B"])
# Image Plane's normalized UV rectangle retains its original outline after cuts.
uv_axes = nodes.new("ShaderNodeSeparateXYZ")
links.new(uv.outputs["Attribute"], uv_axes.inputs[0])
u, v = uv_axes.outputs["X"], uv_axes.outputs["Y"]
margin = _math(group, "MINIMUM", _math(group, "MINIMUM", u, v),
_math(group, "MINIMUM", _math(group, "SUBTRACT", 1, u), _math(group, "SUBTRACT", 1, v)))
original_boundary = evaluate_field(group, _math(group, "LESS_THAN", margin, 1e-6), "BOOLEAN", "POINT")
original_boundary = evaluate_field(group, compare_node(group, "LESS_THAN", margin, 1e-6), "BOOLEAN", "POINT")
protected = plane.outputs["Geometry"]
culled = delete_invalid_faces(group, protected, invalid.outputs["Result"])
cull_controls = _group_input(nodes, {"Depth Mask"})
@@ -139,13 +139,10 @@ def build_image_depth_plane_group(image_plane_group):
group, surface, shell_input.outputs["Thickness"],
normal_smooth=100,
)
positive = nodes.new("ShaderNodeMath")
positive.operation = "GREATER_THAN"
links.new(shell_input.outputs["Thickness"], positive.inputs[0])
positive.inputs[1].default_value = 0
positive = compare_node(group, "GREATER_THAN", shell_input.outputs["Thickness"], 0)
choose = nodes.new("GeometryNodeSwitch")
choose.input_type = "GEOMETRY"
links.new(positive.outputs[0], choose.inputs["Switch"])
links.new(positive, choose.inputs["Switch"])
links.new(surface, choose.inputs["False"])
links.new(shell["geometry"], choose.inputs["True"])
smooth = nodes.new("GeometryNodeSetShadeSmooth")