This example shows how to render a scalar field defined on vertices of a mesh.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <easy3d/viewer/viewer.h>
28#include <easy3d/core/surface_mesh.h>
29#include <easy3d/renderer/renderer.h>
30#include <easy3d/renderer/drawable_triangles.h>
31#include <easy3d/renderer/texture_manager.h>
32#include <easy3d/fileio/surface_mesh_io.h>
33#include <easy3d/util/resource.h>
34#include <easy3d/util/initializer.h>
35
40
42
43
44int main(int argc, char **argv) {
45
47
49
50
51
52 Viewer viewer(EXAMPLE_TITLE);
53
54
55 auto mesh =
dynamic_cast<SurfaceMesh *
>(viewer.add_model(file_name));
56 if (!mesh) {
57 LOG(ERROR) << "failed to load model. Please make sure the file exists and format is correct.";
58 return EXIT_FAILURE;
59 }
60
61
62
63
64
65 auto elevation = mesh->add_vertex_property<float>("v:elevation");
66 for (auto v : mesh->vertices())
67 elevation[v] = mesh->position(v).z;
68
69
70 auto drawable = mesh->renderer()->get_triangles_drawable("faces");
71 drawable->set_scalar_coloring(
State::VERTEX,
"v:elevation",
nullptr, 0.0f, 0.0f);
72
73
74
75
76
77
78
79
80
81
82
83
84 return viewer.run();
85}
86
@ VERTEX
Property defined on vertices.
Definition state.h:69
A halfedge data structure for polygonal meshes of 2-manifold.
Definition surface_mesh.h:51
The built-in Easy3D viewer.
Definition viewer.h:63
std::string directory()
Returns the resource directory (containing color maps, shaders, textures, fonts, etc....
Definition collider.cpp:182
void initialize(bool info_to_stdout, bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition initializer.cpp:39