Tests: support simulation nodes regression tests
Geometry nodes supports simulation nodes which allows later frames to depend on previous frames. The existing geometry nodes regression tests only evaluated the node tree at a single frame and therefore couldn't test the correct behavior of simulations. This adds a new kind of regression test that evaluates the scene at multiple consecutive frames and then checks if the last frame matches. Pull Request: https://projects.blender.org/blender/blender/pulls/109046
This commit is contained in:
parent
9b1e518d4a
commit
9535248911
@ -746,6 +746,22 @@ foreach(geo_node_test ${geo_node_tests})
|
|||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
|
||||||
|
if(EXISTS "${TEST_SRC_DIR}/modeling/geometry_nodes/simulation/")
|
||||||
|
file(GLOB files "${TEST_SRC_DIR}/modeling/geometry_nodes/simulation/*.blend")
|
||||||
|
foreach(file ${files})
|
||||||
|
get_filename_component(filename ${file} NAME_WE)
|
||||||
|
add_blender_test(
|
||||||
|
geo_node_simulation_test_${filename}
|
||||||
|
${file}
|
||||||
|
--python ${TEST_PYTHON_DIR}/geo_node_sim_test.py
|
||||||
|
)
|
||||||
|
endforeach()
|
||||||
|
else()
|
||||||
|
message(STATUS "Directory named ${TEST_SRC_DIR}/modeling/geometry_nodes/simulation/ not found, disabling tests")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
if(WITH_OPENGL_DRAW_TESTS)
|
if(WITH_OPENGL_DRAW_TESTS)
|
||||||
if(NOT OPENIMAGEIO_IDIFF)
|
if(NOT OPENIMAGEIO_IDIFF)
|
||||||
message(STATUS "Disabling OpenGL draw tests because OIIO idiff does not exist")
|
message(STATUS "Disabling OpenGL draw tests because OIIO idiff does not exist")
|
||||||
|
17
tests/python/geo_node_sim_test.py
Normal file
17
tests/python/geo_node_sim_test.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2009-2022 Blender Foundation
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
from modules.mesh_test import GeoNodesSimulationTest
|
||||||
|
|
||||||
|
geo_node_test = GeoNodesSimulationTest("test_object", "expected_object", threshold=1e-4, frames_num=5)
|
||||||
|
result = geo_node_test.run_test()
|
||||||
|
|
||||||
|
# Telling `ctest` about the failed test by raising Exception.
|
||||||
|
if not result:
|
||||||
|
raise Exception("Failed {}".format(geo_node_test.test_name))
|
@ -749,6 +749,32 @@ class BlendFileTest(MeshTest):
|
|||||||
bpy.ops.object.modifier_apply(modifier=modifier.name)
|
bpy.ops.object.modifier_apply(modifier=modifier.name)
|
||||||
|
|
||||||
|
|
||||||
|
class GeoNodesSimulationTest(MeshTest):
|
||||||
|
"""
|
||||||
|
A mesh test that works similar to BlendFileTest but evaluates the scene at multiple
|
||||||
|
frames so that simulations can run.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, test_object_name, exp_object_name, *, frames_num, **kwargs):
|
||||||
|
super().__init__(test_object_name, exp_object_name, **kwargs)
|
||||||
|
self.frames_num = frames_num
|
||||||
|
|
||||||
|
def apply_operations(self, evaluated_test_object_name):
|
||||||
|
GeoNodesSimulationTest.apply_operations.__doc__ = MeshTest.apply_operations.__doc__
|
||||||
|
|
||||||
|
evaluated_test_object = bpy.data.objects[evaluated_test_object_name]
|
||||||
|
modifiers_list = evaluated_test_object.modifiers
|
||||||
|
if not modifiers_list:
|
||||||
|
raise Exception("The object has no modifiers.")
|
||||||
|
|
||||||
|
scene = bpy.context.scene
|
||||||
|
for frame in range(1, self.frames_num+1):
|
||||||
|
scene.frame_set(frame)
|
||||||
|
|
||||||
|
for modifier in modifiers_list:
|
||||||
|
bpy.ops.object.modifier_apply(modifier=modifier.name)
|
||||||
|
|
||||||
|
|
||||||
class RunTest:
|
class RunTest:
|
||||||
"""
|
"""
|
||||||
Helper class that stores and executes SpecMeshTest tests.
|
Helper class that stores and executes SpecMeshTest tests.
|
||||||
|
Loading…
Reference in New Issue
Block a user