mirror of
https://github.com/blender/blender
synced 2026-09-29 04:37:17 +03:00
Tests: Geometry Nodes: Add regression tests for dynamics assets
Two simple tests for the dynamics assets. Also replace the specific simulation test Python code with a test for a specific custom property on the scene which tells the test code to run through the frame range before applying modifiers. Pull Request: https://projects.blender.org/blender/blender/pulls/159118
This commit is contained in:
parent
aacbf2815e
commit
c24df3a6af
13 changed files with 42 additions and 69 deletions
|
|
@ -3,6 +3,7 @@
|
|||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
|
||||
#include "BLI_array.hh"
|
||||
|
|
@ -328,7 +329,8 @@ static bool values_different(const T value1,
|
|||
* \returns false if the attributes don't line up.
|
||||
*/
|
||||
template<typename T>
|
||||
static bool update_set_ids(MutableSpan<int> set_ids,
|
||||
static bool update_set_ids(StringRef name,
|
||||
MutableSpan<int> set_ids,
|
||||
const Span<T> values1,
|
||||
const Span<T> values2,
|
||||
const Span<int> sorted_to_values1,
|
||||
|
|
@ -348,6 +350,9 @@ static bool update_set_ids(MutableSpan<int> set_ids,
|
|||
const T value2 = values2[sorted_to_values2[i]];
|
||||
if (values_different(value1, value2, value_threshold, component_i)) {
|
||||
/* They should be the same after sorting. */
|
||||
std::cout << "Attribute different: " << name << "\n";
|
||||
std::cout << " 1: " << value1 << "\n";
|
||||
std::cout << " 2: " << value2 << "\n";
|
||||
return false;
|
||||
}
|
||||
if ((values_different(previous, value1, value_threshold, component_i) &&
|
||||
|
|
@ -452,7 +457,8 @@ static bool sort_edges(const Span<int2> edges1,
|
|||
ordered_edges1.as_span(),
|
||||
ordered_edges2.as_span(),
|
||||
0);
|
||||
const bool edges_match = update_set_ids(edges.set_ids,
|
||||
const bool edges_match = update_set_ids("ORDERED_EDGES",
|
||||
edges.set_ids,
|
||||
ordered_edges1.as_span(),
|
||||
ordered_edges2.as_span(),
|
||||
edges.from_sorted1,
|
||||
|
|
@ -536,7 +542,8 @@ static bool sort_faces_based_on_corners(const IndexMapping &corners,
|
|||
smallest_corner_ids1.as_span(),
|
||||
smallest_corner_ids2.as_span(),
|
||||
0);
|
||||
const bool faces_line_up = update_set_ids(faces.set_ids,
|
||||
const bool faces_line_up = update_set_ids("CORNER_IDS",
|
||||
faces.set_ids,
|
||||
smallest_corner_ids1.as_span(),
|
||||
smallest_corner_ids2.as_span(),
|
||||
faces.from_sorted1,
|
||||
|
|
@ -666,7 +673,8 @@ static std::optional<GeoMismatch> sort_domain_using_attributes(
|
|||
for (const int component_i : IndexRange(num_loops)) {
|
||||
sort_per_set_based_on_attributes(
|
||||
maps.set_sizes, maps.from_sorted1, maps.from_sorted2, values1, values2, component_i);
|
||||
const bool attributes_line_up = update_set_ids(maps.set_ids,
|
||||
const bool attributes_line_up = update_set_ids(name,
|
||||
maps.set_ids,
|
||||
values1,
|
||||
values2,
|
||||
maps.from_sorted1,
|
||||
|
|
@ -1019,7 +1027,8 @@ static bool sort_curves(const OffsetIndices<int> offset_indices1,
|
|||
curve_point_counts1.as_span(),
|
||||
curve_point_counts2.as_span(),
|
||||
0);
|
||||
const bool curves_sizes_match = update_set_ids(curves.set_ids,
|
||||
const bool curves_sizes_match = update_set_ids("CURVE_IDS",
|
||||
curves.set_ids,
|
||||
curve_point_counts1.as_span(),
|
||||
curve_point_counts2.as_span(),
|
||||
curves.from_sorted1,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:3adf87160ecd32e8b9536dd561337ea08f2280e125bee8ada9fea2d091be2c66
|
||||
size 1193460
|
||||
oid sha256:d2b8849530be53694b803b6d5fc3550204591b9466c21002c4c832441d639545
|
||||
size 1262109
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:41c1c57687fcefea217b4279f8533b653795c7437e39fdf0d643bcb60f525c00
|
||||
size 196568
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:5caea846c0f05dabe2c4f1117c2db9f8abadf6f8a88d254e564490b43adba2e6
|
||||
size 307624
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:0a685a680c4a4018176a6c403444716bb6893bc1d5f068712eba13dd7d13d667
|
||||
size 1147162
|
||||
oid sha256:8f1bfad7b03b7ebddf726f9728fe342629f82b8e1d647b55144f784c56a8825d
|
||||
size 1208927
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:934c210c174795b3ff0f0200fb943bca940602def2be5d043bc06a805e039779
|
||||
size 1044326
|
||||
oid sha256:7077733189b9bfe421baf0dcb98bcd5cca58adbec447b1951dde74708fbc1952
|
||||
size 1112419
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:493c51152bd51099f427ec35e457c079e9cbf980d4d6dce074925636e863cecd
|
||||
size 1148428
|
||||
oid sha256:99c5bdfb4a9e559001d7c6e01abdb3b234f1557d249e7b370e3ef35b198be8a9
|
||||
size 1200030
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:9c74d3f1303e4f91105c75fdcf17b7d222dc0239c5c42ddbac0b27984be34fde
|
||||
size 1105951
|
||||
oid sha256:293f50b938bbbf4ef4fb88769bbb9a1c99d353f82d4d4b1cc056c0530129654b
|
||||
size 1123626
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:ce7fe8e7475202fcfa1c9b2fd6d88b4d12055ed0a7e8b0b2775b616c9e819597
|
||||
size 1055067
|
||||
oid sha256:5d83a86542c402114f49a92ffb110eb8bdfa0c87f5302676b27a8bbfa58d9eba
|
||||
size 1123200
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:a33bf199602e1d9b1bd4af174da6707f1e083648fe5a83552081bea287b5b707
|
||||
size 1117533
|
||||
oid sha256:775af7dca68c8b367d9824522550dc3910092e3cbcb818fc2afc237346fa2931
|
||||
size 1184915
|
||||
|
|
|
|||
|
|
@ -1275,6 +1275,7 @@ if(TEST_SRC_DIR_EXISTS)
|
|||
mesh/split_edges
|
||||
mesh/triangulate
|
||||
points
|
||||
simulation
|
||||
texture
|
||||
utilities
|
||||
vector
|
||||
|
|
@ -1304,15 +1305,6 @@ if(TEST_SRC_DIR_EXISTS)
|
|||
endforeach()
|
||||
endforeach()
|
||||
|
||||
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()
|
||||
endif()
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2009-2022 Blender Authors
|
||||
#
|
||||
# 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))
|
||||
|
|
@ -823,39 +823,22 @@ class BlendFileTest(MeshTest):
|
|||
self.allow_index_change = True
|
||||
|
||||
def apply_operations(self, evaluated_test_object_name):
|
||||
|
||||
BlendFileTest.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("No modifiers are added to test object.")
|
||||
for modifier in modifiers_list:
|
||||
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)
|
||||
if scene.get("use_playback"):
|
||||
frame_start = scene.frame_start
|
||||
frame_end = scene.frame_end
|
||||
for frame in range(frame_start, frame_end + 1):
|
||||
scene.frame_set(frame)
|
||||
|
||||
for modifier in modifiers_list:
|
||||
print(modifier.name)
|
||||
bpy.ops.object.modifier_apply(modifier=modifier.name)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue