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,12 +1,12 @@
"""Verify point culling removes its dangling wire geometry."""
"""Verify face culling removes the faces the depth mask excludes."""
import bpy
from tools.nodes.common.nodes import interface_socket
from tools.nodes.common.validity import delete_invalid_points
from tools.nodes.common.nodes import compare_node, interface_socket
from tools.nodes.common.validity import delete_invalid_faces
def test_point_culling_removes_wire_edges_without_removing_adjacent_surface():
def test_face_culling_removes_invalid_faces_without_leaving_wire_geometry():
bpy.ops.wm.read_factory_settings(use_empty=True)
mesh = bpy.data.meshes.new("Two Quads")
mesh.from_pydata([(0, 0, 0), (1, 0, 0), (2, 0, 0),
@@ -14,17 +14,14 @@ def test_point_culling_removes_wire_edges_without_removing_adjacent_surface():
[(0, 1, 4, 3), (1, 2, 5, 4)])
obj = bpy.data.objects.new("Surface", mesh)
bpy.context.collection.objects.link(obj)
group = bpy.data.node_groups.new("Point Culling", "GeometryNodeTree")
group = bpy.data.node_groups.new("Face Culling", "GeometryNodeTree")
interface_socket(group, "Geometry", "INPUT", "NodeSocketGeometry")
interface_socket(group, "Geometry", "OUTPUT", "NodeSocketGeometry")
inlet = group.nodes.new("NodeGroupInput")
outlet = group.nodes.new("NodeGroupOutput")
index = group.nodes.new("GeometryNodeInputIndex")
invalid = group.nodes.new("ShaderNodeMath")
invalid.operation = "LESS_THAN"
invalid.inputs[1].default_value = 1
group.links.new(index.outputs[0], invalid.inputs[0])
geometry = delete_invalid_points(group, inlet.outputs["Geometry"], invalid.outputs[0])
invalid = compare_node(group, "LESS_THAN", index.outputs["Index"], 1, data_type="INT")
geometry = delete_invalid_faces(group, inlet.outputs["Geometry"], invalid)
group.links.new(geometry, outlet.inputs["Geometry"])
modifier = obj.modifiers.new("Cull", "NODES")
modifier.node_group = group