Add tests for image layer, image plane, inventory, saved layout, commands, documentation, manifest, and packaging
- Implement tests for image layer functionality including alpha curve and depth layer behavior. - Create tests for image plane evaluation and modifier input handling. - Add tests to verify the saved asset inventory and its persistence. - Introduce tests for the documentation command to ensure correct project version deployment. - Validate the extension manifest structure and required permissions. - Develop tests for the packaging process, ensuring correct platform handling and dependency management. - Enhance image depth plane group functionality with new split threshold input and surface processing.
This commit is contained in:
106
tests/tools/nodes/test_image_plane.py
Normal file
106
tests/tools/nodes/test_image_plane.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import bpy
|
||||
|
||||
from anyimage.common.object import (
|
||||
modifier_input_identifier,
|
||||
set_modifier_input,
|
||||
)
|
||||
|
||||
from anyimage.operators.convert_to_plane.image_plane import (
|
||||
add_image_plane_processing,
|
||||
create_image_plane_mesh,
|
||||
)
|
||||
|
||||
|
||||
def evaluated_mesh(obj):
|
||||
bpy.context.view_layer.update()
|
||||
evaluated = obj.evaluated_get(bpy.context.evaluated_depsgraph_get())
|
||||
return evaluated, evaluated.to_mesh()
|
||||
|
||||
|
||||
def test_saved_image_plane_evaluation():
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
mesh = create_image_plane_mesh("Image Plane", (-1.0, 1.0, -0.5, 0.5))
|
||||
assert len(mesh.polygons) == 1
|
||||
material = bpy.data.materials.new("Image Plane Material")
|
||||
mesh.materials.append(material)
|
||||
obj = bpy.data.objects.new("Image Plane", mesh)
|
||||
bpy.context.scene.collection.objects.link(obj)
|
||||
modifier = add_image_plane_processing(obj)
|
||||
group = modifier.node_group
|
||||
assert group.name == "O Image Plane"
|
||||
assert group.is_modifier
|
||||
inputs = {
|
||||
item.name: item
|
||||
for item in group.interface.items_tree
|
||||
if item.item_type == "SOCKET" and item.in_out == "INPUT"
|
||||
}
|
||||
assert list(inputs) == ["Geometry", "Subdivide", "Thickness"]
|
||||
assert inputs["Subdivide"].default_value == 0
|
||||
assert inputs["Subdivide"].max_value == 10
|
||||
assert inputs["Thickness"].default_value == 0.0
|
||||
assert obj.data.materials[0] == material
|
||||
|
||||
evaluated, result = evaluated_mesh(obj)
|
||||
try:
|
||||
assert result.materials[0].original == material
|
||||
assert len(result.polygons) == 2
|
||||
assert len(result.vertices) == 6
|
||||
assert "UVMap" in result.attributes
|
||||
uv_values = {
|
||||
tuple(round(value, 6) for value in loop.uv)
|
||||
for loop in result.uv_layers["UVMap"].data
|
||||
}
|
||||
assert uv_values == {
|
||||
(0.0, 0.0),
|
||||
(0.5, 0.0),
|
||||
(1.0, 0.0),
|
||||
(0.0, 1.0),
|
||||
(0.5, 1.0),
|
||||
(1.0, 1.0),
|
||||
}
|
||||
assert all(abs(vertex.co.z) < 1e-6 for vertex in result.vertices)
|
||||
assert all(polygon.material_index == 0 for polygon in result.polygons)
|
||||
finally:
|
||||
evaluated.to_mesh_clear()
|
||||
|
||||
set_modifier_input(modifier, modifier_input_identifier(group, "Subdivide"), 3)
|
||||
obj.update_tag(refresh={"DATA"})
|
||||
evaluated, result = evaluated_mesh(obj)
|
||||
try:
|
||||
assert len(result.polygons) == 128
|
||||
assert len(result.vertices) == 153
|
||||
finally:
|
||||
evaluated.to_mesh_clear()
|
||||
|
||||
set_modifier_input(modifier, modifier_input_identifier(group, "Subdivide"), 2)
|
||||
set_modifier_input(modifier, modifier_input_identifier(group, "Thickness"), 1.2)
|
||||
obj.update_tag(refresh={"DATA"})
|
||||
evaluated, result = evaluated_mesh(obj)
|
||||
try:
|
||||
assert result.materials[0].original == material
|
||||
assert len(result.polygons) == 184
|
||||
z_values = [vertex.co.z for vertex in result.vertices]
|
||||
assert abs(min(z_values) + 0.6) < 1e-6
|
||||
assert abs(max(z_values) - 0.6) < 1e-6
|
||||
assert len({round(value, 6) for value in z_values}) == 6
|
||||
edge_users = {edge.key: 0 for edge in result.edges}
|
||||
for polygon in result.polygons:
|
||||
for edge_key in polygon.edge_keys:
|
||||
edge_users[edge_key] += 1
|
||||
assert all(users == 2 for users in edge_users.values())
|
||||
assert all(polygon.material_index == 0 for polygon in result.polygons)
|
||||
finally:
|
||||
evaluated.to_mesh_clear()
|
||||
|
||||
set_modifier_input(modifier, modifier_input_identifier(group, "Subdivide"), 0)
|
||||
set_modifier_input(modifier, modifier_input_identifier(group, "Thickness"), 0.01)
|
||||
obj.update_tag(refresh={"DATA"})
|
||||
evaluated, result = evaluated_mesh(obj)
|
||||
try:
|
||||
z_values = {round(vertex.co.z, 6) for vertex in result.vertices}
|
||||
assert len(z_values) >= 4
|
||||
finally:
|
||||
evaluated.to_mesh_clear()
|
||||
|
||||
if bpy.app.version >= (5, 0, 0):
|
||||
assert group.library is not None
|
||||
Reference in New Issue
Block a user