15#include <lagrange/scene/Scene.h>
16#include <lagrange/testing/check_meshes_equal.h>
19#include <lagrange/utils/warnoff.h>
20#include <catch2/catch_test_macros.hpp>
21#include <lagrange/utils/warnon.h>
24namespace lagrange::testing {
42template <
typename Scalar,
typename Index>
43void check_scenes_equal(
const scene::Scene<Scalar, Index>& a,
const scene::Scene<Scalar, Index>& b)
45 REQUIRE(a.name == b.name);
48 REQUIRE(a.meshes.size() == b.meshes.size());
49 for (
size_t i = 0; i < a.meshes.size(); ++i) {
50 check_meshes_equal(a.meshes[i], b.meshes[i]);
54 REQUIRE(a.root_nodes.size() == b.root_nodes.size());
55 for (
size_t i = 0; i < a.root_nodes.size(); ++i) {
56 REQUIRE(a.root_nodes[i] == b.root_nodes[i]);
60 REQUIRE(a.nodes.size() == b.nodes.size());
61 for (
size_t i = 0; i < a.nodes.size(); ++i) {
62 const auto& na = a.nodes[i];
63 const auto& nb = b.nodes[i];
64 REQUIRE(na.name == nb.name);
65 REQUIRE(na.transform.matrix().isApprox(nb.transform.matrix(), 0.f));
66 REQUIRE(na.parent == nb.parent);
67 REQUIRE(na.children.size() == nb.children.size());
68 for (
size_t j = 0; j < na.children.size(); ++j) {
69 REQUIRE(na.children[j] == nb.children[j]);
71 REQUIRE(na.meshes.size() == nb.meshes.size());
72 for (
size_t j = 0; j < na.meshes.size(); ++j) {
73 REQUIRE(na.meshes[j].mesh == nb.meshes[j].mesh);
74 REQUIRE(na.meshes[j].materials.size() == nb.meshes[j].materials.size());
75 for (
size_t k = 0; k < na.meshes[j].materials.size(); ++k) {
76 REQUIRE(na.meshes[j].materials[k] == nb.meshes[j].materials[k]);
79 REQUIRE(na.cameras.size() == nb.cameras.size());
80 for (
size_t j = 0; j < na.cameras.size(); ++j) {
81 REQUIRE(na.cameras[j] == nb.cameras[j]);
83 REQUIRE(na.lights.size() == nb.lights.size());
84 for (
size_t j = 0; j < na.lights.size(); ++j) {
85 REQUIRE(na.lights[j] == nb.lights[j]);
90 REQUIRE(a.images.size() == b.images.size());
91 for (
size_t i = 0; i < a.images.size(); ++i) {
92 REQUIRE(a.images[i].name == b.images[i].name);
93 REQUIRE(a.images[i].image.width == b.images[i].image.width);
94 REQUIRE(a.images[i].image.height == b.images[i].image.height);
95 REQUIRE(a.images[i].image.num_channels == b.images[i].image.num_channels);
96 REQUIRE(a.images[i].image.element_type == b.images[i].image.element_type);
97 REQUIRE(a.images[i].image.data == b.images[i].image.data);
98 REQUIRE(a.images[i].uri == b.images[i].uri);
102 REQUIRE(a.textures.size() == b.textures.size());
103 for (
size_t i = 0; i < a.textures.size(); ++i) {
104 const auto& ta = a.textures[i];
105 const auto& tb = b.textures[i];
106 REQUIRE(ta.name == tb.name);
107 REQUIRE(ta.image == tb.image);
108 REQUIRE(ta.mag_filter == tb.mag_filter);
109 REQUIRE(ta.min_filter == tb.min_filter);
110 REQUIRE(ta.wrap_u == tb.wrap_u);
111 REQUIRE(ta.wrap_v == tb.wrap_v);
112 REQUIRE(ta.scale.isApprox(tb.scale, 0.f));
113 REQUIRE(ta.offset.isApprox(tb.offset, 0.f));
114 REQUIRE(ta.rotation == tb.rotation);
118 REQUIRE(a.materials.size() == b.materials.size());
119 for (
size_t i = 0; i < a.materials.size(); ++i) {
120 const auto& ma = a.materials[i];
121 const auto& mb = b.materials[i];
122 REQUIRE(ma.name == mb.name);
123 REQUIRE(ma.base_color_value.isApprox(mb.base_color_value, 0.f));
124 REQUIRE(ma.emissive_value.isApprox(mb.emissive_value, 0.f));
125 REQUIRE(ma.metallic_value == mb.metallic_value);
126 REQUIRE(ma.roughness_value == mb.roughness_value);
127 REQUIRE(ma.alpha_mode == mb.alpha_mode);
128 REQUIRE(ma.alpha_cutoff == mb.alpha_cutoff);
129 REQUIRE(ma.normal_scale == mb.normal_scale);
130 REQUIRE(ma.occlusion_strength == mb.occlusion_strength);
131 REQUIRE(ma.double_sided == mb.double_sided);
132 REQUIRE(ma.base_color_texture.index == mb.base_color_texture.index);
133 REQUIRE(ma.base_color_texture.texcoord == mb.base_color_texture.texcoord);
134 REQUIRE(ma.emissive_texture.index == mb.emissive_texture.index);
135 REQUIRE(ma.metallic_roughness_texture.index == mb.metallic_roughness_texture.index);
136 REQUIRE(ma.normal_texture.index == mb.normal_texture.index);
137 REQUIRE(ma.occlusion_texture.index == mb.occlusion_texture.index);
141 REQUIRE(a.lights.size() == b.lights.size());
142 for (
size_t i = 0; i < a.lights.size(); ++i) {
143 const auto& la = a.lights[i];
144 const auto& lb = b.lights[i];
145 REQUIRE(la.name == lb.name);
146 REQUIRE(la.type == lb.type);
147 REQUIRE(la.position.isApprox(lb.position, 0.f));
148 REQUIRE(la.direction.isApprox(lb.direction, 0.f));
149 REQUIRE(la.up.isApprox(lb.up, 0.f));
150 REQUIRE(la.intensity == lb.intensity);
151 REQUIRE(la.attenuation_constant == lb.attenuation_constant);
152 REQUIRE(la.attenuation_linear == lb.attenuation_linear);
153 REQUIRE(la.attenuation_quadratic == lb.attenuation_quadratic);
154 REQUIRE(la.attenuation_cubic == lb.attenuation_cubic);
155 REQUIRE(la.range == lb.range);
156 REQUIRE(la.color_diffuse.isApprox(lb.color_diffuse, 0.f));
157 REQUIRE(la.color_specular.isApprox(lb.color_specular, 0.f));
158 REQUIRE(la.color_ambient.isApprox(lb.color_ambient, 0.f));
159 REQUIRE(la.angle_inner_cone == lb.angle_inner_cone);
160 REQUIRE(la.angle_outer_cone == lb.angle_outer_cone);
161 REQUIRE(la.size.isApprox(lb.size, 0.f));
165 REQUIRE(a.cameras.size() == b.cameras.size());
166 for (
size_t i = 0; i < a.cameras.size(); ++i) {
167 const auto& ca = a.cameras[i];
168 const auto& cb = b.cameras[i];
169 REQUIRE(ca.name == cb.name);
170 REQUIRE(ca.type == cb.type);
171 REQUIRE(ca.position.isApprox(cb.position, 0.f));
172 REQUIRE(ca.up.isApprox(cb.up, 0.f));
173 REQUIRE(ca.look_at.isApprox(cb.look_at, 0.f));
174 REQUIRE(ca.near_plane == cb.near_plane);
175 REQUIRE(ca.far_plane.has_value() == cb.far_plane.has_value());
176 if (ca.far_plane.has_value()) {
177 REQUIRE(ca.far_plane.value() == cb.far_plane.value());
179 REQUIRE(ca.orthographic_width == cb.orthographic_width);
180 REQUIRE(ca.aspect_ratio == cb.aspect_ratio);
181 REQUIRE(ca.horizontal_fov == cb.horizontal_fov);
185 REQUIRE(a.skeletons.size() == b.skeletons.size());
186 for (
size_t i = 0; i < a.skeletons.size(); ++i) {
187 REQUIRE(a.skeletons[i].meshes.size() == b.skeletons[i].meshes.size());
188 for (
size_t j = 0; j < a.skeletons[i].meshes.size(); ++j) {
189 REQUIRE(a.skeletons[i].meshes[j] == b.skeletons[i].meshes[j]);
194 REQUIRE(a.animations.size() == b.animations.size());
195 for (
size_t i = 0; i < a.animations.size(); ++i) {
196 REQUIRE(a.animations[i].name == b.animations[i].name);