Blender V4.3
stl_importer_tests.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
6
7#include "BKE_mesh.hh"
8#include "BKE_object.hh"
9
10#include "BLI_math_base.h"
12#include "BLI_string.h"
13
14#include "BLO_readfile.hh"
15
17
18#include "stl_import.hh"
19
20namespace blender::io::stl {
21
26
28 public:
38
39 void import_and_check(const char *path, const Expectation &expect)
40 {
41 if (!blendfile_load("io_tests" SEP_STR "blend_geometry" SEP_STR "all_quads.blend")) {
42 ADD_FAILURE();
43 return;
44 }
45
46 std::string stl_path = blender::tests::flags_test_asset_dir() +
47 SEP_STR "io_tests" SEP_STR "stl" SEP_STR + path;
48 STRNCPY(params.filepath, stl_path.c_str());
50
52
53 DEGObjectIterSettings deg_iter_settings{};
54 deg_iter_settings.depsgraph = depsgraph;
55 deg_iter_settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
58
59 constexpr bool print_result_scene = false;
60 if (print_result_scene) {
61 printf("Result was:\n");
62 DEG_OBJECT_ITER_BEGIN (&deg_iter_settings, object) {
63 printf(" {");
64 if (object->type == OB_MESH) {
65 Mesh *mesh = BKE_object_get_evaluated_mesh(object);
66 const Span<float3> positions = mesh->vert_positions();
67 printf("%i, %i, %i, %i, float3(%g, %g, %g), float3(%g, %g, %g)",
68 mesh->verts_num,
69 mesh->edges_num,
70 mesh->faces_num,
71 mesh->corners_num,
72 positions.first().x,
73 positions.first().y,
74 positions.first().z,
75 positions.last().x,
76 positions.last().y,
77 positions.last().z);
78 }
79 printf("},\n");
80 }
82 }
83
84 size_t object_index = 0;
85 DEG_OBJECT_ITER_BEGIN (&deg_iter_settings, object) {
86 ++object_index;
87 /* First object is from loaded scene. */
88 if (object_index == 1) {
89 continue;
90 }
91 EXPECT_V3_NEAR(object->loc, float3(0, 0, 0), 0.0001f);
92 EXPECT_V3_NEAR(object->rot, float3(M_PI_2, 0, 0), 0.0001f);
93 EXPECT_V3_NEAR(object->scale, float3(1, 1, 1), 0.0001f);
94 Mesh *mesh = BKE_object_get_evaluated_mesh(object);
95 EXPECT_EQ(mesh->verts_num, expect.verts_num);
96 EXPECT_EQ(mesh->edges_num, expect.edges_num);
97 EXPECT_EQ(mesh->faces_num, expect.faces_num);
98 EXPECT_EQ(mesh->corners_num, expect.corners_num);
99 const Span<float3> positions = mesh->vert_positions();
100 EXPECT_V3_NEAR(positions.first(), expect.vert_first, 0.0001f);
101 EXPECT_V3_NEAR(positions.last(), expect.vert_last, 0.0001f);
102 break;
103 }
105 }
106
108};
109
111{
112 Expectation expect = {8, 18, 12, 36, float3(1, 1, 1), float3(1, -1, 1)};
113 import_and_check("all_quads.stl", expect);
114}
115
116TEST_F(stl_importer_test, cubes_positioned)
117{
118 Expectation expect = {24, 54, 36, 108, float3(1, 1, 1), float3(5.49635f, 0.228398f, -1.11237f)};
119 import_and_check("cubes_positioned.stl", expect);
120}
121
122TEST_F(stl_importer_test, non_uniform_scale)
123{
124 Expectation expect = {140, 378, 252, 756, float3(0, 0, -0.3f), float3(-0.866025f, -1.5f, 0)};
125 import_and_check("non_uniform_scale.stl", expect);
126}
127
128} // namespace blender::io::stl
General operations, lookup, etc. for blender objects.
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
#define M_PI_2
#define STRNCPY(dst, src)
Definition BLI_string.h:593
external readfile function prototypes.
@ DAG_EVAL_VIEWPORT
#define DEG_OBJECT_ITER_BEGIN(settings_, instance_)
#define DEG_OBJECT_ITER_END
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
@ DEG_ITER_OBJECT_FLAG_VISIBLE
@ DEG_ITER_OBJECT_FLAG_DUPLI
@ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET
@ OB_MESH
@ IO_AXIS_Y
@ IO_AXIS_NEGATIVE_Z
virtual void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode)
bool blendfile_load(const char *filepath)
void import_and_check(const char *path, const Expectation &expect)
#define printf
void importer_main(const bContext *C, const STLImportParams &import_params)
TEST_F(STLExportTest, all_tris)
VecBase< float, 3 > float3
ViewLayer * cur_view_layer
eIOAxis up_axis
Definition IO_stl.hh:25
bool use_mesh_validate
Definition IO_stl.hh:29
float global_scale
Definition IO_stl.hh:28
eIOAxis forward_axis
Definition IO_stl.hh:24
char filepath[FILE_MAX]
Definition IO_stl.hh:23
bool use_facet_normal
Definition IO_stl.hh:26
bool use_scene_unit
Definition IO_stl.hh:27
#define SEP_STR
Definition unit.cc:39