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/drawable_points.h>
30#include <easy3d/renderer/drawable_lines.h>
31#include <easy3d/renderer/drawable_triangles.h>
32#include <easy3d/renderer/renderer.h>
33#include <easy3d/util/resource.h>
34#include <easy3d/util/initializer.h>
35
43
44
46
47
48
50 PointsDrawable *drawable = mesh->renderer()->add_points_drawable(
"vertices");
51 drawable->set_uniform_coloring(
vec4(1.0f, 0.0f, 0.0f, 1.0f));
52 drawable->set_point_size(24.0f);
54}
55
56
57
59 LinesDrawable *drawable = mesh->renderer()->add_lines_drawable(
"edges");
60 drawable->set_uniform_coloring(
vec4(1.0f, 0.67f, 0.5f, 1.0f));
62 drawable->set_line_width(6);
63}
64
65
66
68 auto points = mesh->get_vertex_property<
vec3>(
"v:point");
69 mesh->update_vertex_normals();
70 auto normals = mesh->get_vertex_property<
vec3>(
"v:normal");
71
72
73
74 float length = mesh->bounding_box().diagonal_length() * 0.15f;
75
76
77
78
79
80 std::vector<vec3> normal_points;
81 for (auto v : mesh->vertices()) {
82 const vec3 &s = points[v];
83 const vec3 &t = points[v] + normals[v] *
length;
84 normal_points.push_back(s);
85 normal_points.push_back(t);
86 }
87
88 LinesDrawable *drawable = mesh->renderer()->add_lines_drawable(
"normals");
89 drawable->update_vertex_buffer(normal_points);
90 drawable->set_uniform_coloring(
vec4(0.0f, 1.0f, 0.0f, 1.0f));
92 drawable->set_line_width(8);
93}
94
95
96
98 PointsDrawable *drawable = mesh->renderer()->add_points_drawable(
"vertices");
99 drawable->set_uniform_coloring(
vec4(1.0f, 0.0f, 0.0f, 1.0f));
100 drawable->set_point_size(24.0f);
102}
103
104
105int main(int argc, char **argv) {
106
108
109
110
111 Viewer viewer(EXAMPLE_TITLE);
112
113
115
116
117
118 auto mesh =
dynamic_cast<SurfaceMesh *
>(viewer.add_model(file_name,
false));
119 if (!mesh) {
120 LOG(ERROR) << "failed to load model. Please make sure the file exists and format is correct.";
121 return EXIT_FAILURE;
122 }
123
124
125
126 create_spheres(mesh);
127
128
129
130 create_cylinders(mesh);
131
132
133
134 create_cones(mesh);
135
136
137
138
140
141 const vec3 trans =
vec3(0, 1, 0) * mesh->bounding_box().diagonal_length() * 0.7f;
142 auto points = copy->get_vertex_property<
vec3>(
"v:point");
143 for (auto v : copy->vertices())
144 points[v] += trans;
145 viewer.add_model(std::shared_ptr<SurfaceMesh>(copy), false);
146
147 create_surfels(copy);
148
149
150
151
152 return viewer.run();
153}
154
The drawable for rendering a set of line segments, e.g., edges of a mesh, vector fields.
Definition drawable_lines.h:40
@ CYLINDER
The lines will be drawn as cylinders.
Definition drawable_lines.h:60
@ CONE
The lines will be drawn as cons.
Definition drawable_lines.h:61
The drawable for rendering a set of points, e.g., point clouds, vertices of a mesh.
Definition drawable_points.h:42
@ SURFEL
The points will be drawn as surfels/discs.
Definition drawable_points.h:63
@ SPHERE
The points will be drawn as spheres.
Definition drawable_points.h:62
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
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
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
T length(const Vec< N, T > &v)
Computes the length/magnitude of a vector.
Definition vec.h:289
Vec< 4, float > vec4
A 4D point/vector of float type.
Definition types.h:46