This example shows how to construct a mesh from its vertices and known connectivity.
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/core/surface_mesh.h>
28#include <easy3d/core/surface_mesh_builder.h>
29#include <easy3d/util/initializer.h>
30
35
37
38
39int main(int argc, char** argv) {
40
42
43
44
45
46
47
48
49
50 const int option = 2;
51
52
53
54
55
56
57
58
59
60
61
62
63
64 const std::vector<vec3> points = {
69 };
70
71
73
74 if (option == 1) {
75
80
81 mesh.add_triangle(v0, v1, v3);
82 mesh.add_triangle(v1, v2, v3);
83 mesh.add_triangle(v2, v0, v3);
84 mesh.add_triangle(v0, v2, v1);
85 }
86
87 else if (option == 2) {
88
95
101 }
102 else
103 LOG(ERROR) << "option must be 1 or 2";
104
105 std::cout << "#face: " << mesh.n_faces() << std::endl;
106 std::cout << "#vertex: " << mesh.n_vertices() << std::endl;
107 std::cout << "#edge: " << mesh.n_edges() << std::endl;
108
109 return EXIT_SUCCESS;
110}
111
A helper class for constructing manifold surface mesh models.
Definition surface_mesh_builder.h:55
void end_surface(bool log_issues=true)
Finalize surface construction.
Definition surface_mesh_builder.cpp:69
Face add_triangle(Vertex v1, Vertex v2, Vertex v3)
Add a new triangle face connecting vertices v1, v2, and v3.
Definition surface_mesh_builder.cpp:354
Vertex add_vertex(const vec3 &p)
Add a vertex to the mesh.
Definition surface_mesh_builder.cpp:228
void begin_surface()
Begin surface construction.
Definition surface_mesh_builder.cpp:54
A halfedge data structure for polygonal meshes of 2-manifold.
Definition surface_mesh.h:51
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
This type represents a vertex (internally it is basically an index).
Definition surface_mesh.h:135