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

@@ -1,7 +1,10 @@
"""Clean cutout boundary triangles and taper the split thickness profile."""
from .depth_surface import _math
from .nodes import evaluate_field, group_input, read_float_attribute, sample_field, store_float_attribute
from .nodes import (
boolean_node, compare_node, evaluate_field, group_input,
read_float_attribute, sample_field, store_float_attribute,
)
from .smoothing import edge_boundary_field
from .boundary_smoothing import boundary_influence
@@ -10,9 +13,9 @@ def remove_boundary_triangles(group, geometry):
"""Remove all-boundary triangles once on the current topology."""
nodes, links = group.nodes, group.links
rim = evaluate_field(group, edge_boundary_field(nodes, links), "FLOAT", "POINT")
all_boundary = _math(group, "GREATER_THAN", evaluate_field(group, rim, "FLOAT", "FACE"), 0.99999)
all_boundary = compare_node(group, "GREATER_THAN", evaluate_field(group, rim, "FLOAT", "FACE"), 0.99999)
count = nodes.new("GeometryNodeInputMeshFaceNeighbors").outputs["Vertex Count"]
selected = _math(group, "MULTIPLY", all_boundary, _math(group, "COMPARE", count, 3))
selected = boolean_node(group, "AND", all_boundary, compare_node(group, "EQUAL", count, 3, data_type="INT"))
delete = nodes.new("GeometryNodeDeleteGeometry")
delete.domain, delete.mode = "FACE", "ALL"
links.new(geometry, delete.inputs["Geometry"])
@@ -41,9 +44,16 @@ def original_boundary_field(group, original, rim=None):
def taper_split_profile(group, geometry, original_boundary):
"""Taper balloon thickness through the shared two-ring influence builder."""
nodes = group.nodes
links = group.links
influence = boundary_influence(group, original_boundary)
controls = group_input(nodes, {"Depth Split"})
band = _math(group, "MULTIPLY", influence, _math(group, "GREATER_THAN", controls.outputs["Depth Split"], 0))
has_split = compare_node(group, "GREATER_THAN", controls.outputs["Depth Split"], 0)
band = nodes.new("GeometryNodeSwitch")
band.input_type = "FLOAT"
band.inputs["False"].default_value = 0.0
links.new(has_split, band.inputs["Switch"])
links.new(influence, band.inputs["True"])
band = band.outputs[0]
retained = _math(group, "SQRT", _math(group, "MAXIMUM", _math(group, "SUBTRACT", 1, band), 0))
profile = _math(group, "MULTIPLY", read_float_attribute(group, "o_balloon"), retained)
return store_float_attribute(group, geometry, "o_balloon", profile)