This example shows how to rendering a vector field defined on a surface mesh.
27#include <easy3d/viewer/viewer.h>
28#include <easy3d/core/surface_mesh.h>
29#include <easy3d/renderer/drawable_lines.h>
30#include <easy3d/renderer/renderer.h>
31#include <easy3d/util/resource.h>
32#include <easy3d/util/initializer.h>
42int main(
int argc,
char **argv) {
48 Viewer viewer(EXAMPLE_TITLE);
51 const std::string file_name = resource::directory() +
"/data/sphere.obj";
52 auto mesh =
dynamic_cast<SurfaceMesh *
>(viewer.add_model(file_name,
true));
54 LOG(ERROR) <<
"failed to load model. Please make sure the file exists and format is correct.";
60 const Box3 &box = mesh->bounding_box();
64 mesh->update_face_normals();
65 auto normals = mesh->get_face_property<
vec3>(
"f:normal");
68 std::vector<vec3> points;
69 for (
auto f : mesh->faces()) {
72 for (
auto v : mesh->vertices(f)) {
73 center += mesh->position(v);
77 const vec3 s = center / count;
78 const vec3 t = s + normals[f] * length;
84 auto drawable = mesh->renderer()->add_lines_drawable(
"normals");
86 drawable->update_vertex_buffer(points);
89 drawable->set_uniform_coloring(
vec4(0.0f, 1.0f, 0.0f, 1.0f));
92 drawable->set_line_width(3.0f);
95 mesh->renderer()->get_lines_drawable(
"edges")->set_visible(
true);
const Point & min_point() const
Return the coordinates of the min corner (const version).
Definition box.h:106
const Point & max_point() const
Return the coordinates of the max corner (const version).
Definition box.h:117
A halfedge data structure for polygonal meshes of 2-manifold.
Definition surface_mesh.h:51
The built-in Easy3D viewer.
Definition viewer.h:63
Definition collider.cpp:182