The source file containing the main() function:
28#include <easy3d/util/resource.h>
29#include <easy3d/util/initializer.h>
36int main(
int argc,
char **argv) {
40 PickerViewer viewer(EXAMPLE_TITLE);
41 viewer.add_model(resource::directory() +
"/data/easy3d/easy3d_e.ply");
42 viewer.add_model(resource::directory() +
"/data/easy3d/easy3d_a.ply");
43 viewer.add_model(resource::directory() +
"/data/easy3d/easy3d_s.ply");
44 viewer.add_model(resource::directory() +
"/data/easy3d/easy3d_y.ply");
45 viewer.add_model(resource::directory() +
"/data/easy3d/easy3d_3.ply");
46 viewer.add_model(resource::directory() +
"/data/easy3d/easy3d_d.ply");
48 if (viewer.models().empty()) {
49 LOG(ERROR) <<
"failed to load model. Please make sure the file exists and format is correct.";
Definition: collider.cpp:182
void initialize(bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition: initializer.cpp:35
The header file of the viewer class:
27#ifndef EASY3D_TUTORIAL_PICKER_VIEWER_H
28#define EASY3D_TUTORIAL_PICKER_VIEWER_H
30#include <easy3d/viewer/viewer.h>
40 explicit PickerViewer(
const std::string &title);
43 bool mouse_press_event(
int x,
int y,
int button,
int modifiers)
override;
The base class of renderable 3D models.
Definition: model.h:49
The built-in Easy3D viewer.
Definition: viewer.h:61
The source file of the viewer class:
28#include <easy3d/gui/picker_model.h>
29#include <easy3d/core/model.h>
30#include <easy3d/renderer/drawable_triangles.h>
31#include <easy3d/renderer/renderer.h>
32#include <easy3d/util/file_system.h>
33#include <easy3d/util/setting.h>
39PickerViewer::PickerViewer(
const std::string &title)
42 camera()->setViewDirection(
vec3(0, 0, -1));
43 camera()->setUpVector(
vec3(0, 1, 0));
46 "------------ Picker Viewer usage ---------- \n"
47 "Press the left button to pick/unpick a model\n"
48 "------------------------------------------- \n";
52bool PickerViewer::mouse_press_event(
int x,
int y,
int button,
int modifiers) {
54 auto model = picker.pick(models(), x, y);
58 return Viewer::mouse_press_event(x, y, button, modifiers);
63 for (
auto m : models()) {
65 m->renderer()->set_selected(!m->renderer()->is_selected());
67 auto faces = m->renderer()->get_triangles_drawable(
"faces");
68 if (m->renderer()->is_selected())
69 faces->set_uniform_coloring(
vec4(1, 0, 0, 1.0f));
71 faces->set_uniform_coloring(setting::surface_mesh_faces_color);
73 std::cout <<
"picked model: " << file_system::simple_name(model->
name()) << std::endl;
const std::string & name() const
The name of a model.
Definition: model.h:60
Implementation of picking mechanism for set of models.
Definition: picker_model.h:48