Files
AnyImage/tests/tools/nodes/test_validity.py
nan 78bbff6351 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.
2026-09-16 21:42:02 +08:00

38 lines
1.7 KiB
Python

"""Verify face culling removes the faces the depth mask excludes."""
import bpy
from tools.nodes.common.nodes import compare_node, interface_socket
from tools.nodes.common.validity import delete_invalid_faces
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),
(0, 1, 0), (1, 1, 0), (2, 1, 0)], [],
[(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("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 = 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
evaluated = obj.evaluated_get(bpy.context.evaluated_depsgraph_get())
result = evaluated.to_mesh()
try:
assert len(result.polygons) == 1
assert len(result.edges) == 4
assert {tuple(vertex.co) for vertex in result.vertices} == {
(1, 0, 0), (2, 0, 0), (1, 1, 0), (2, 1, 0),
}
finally:
evaluated.to_mesh_clear()