28#include <easy3d/util/resource.h>
29#include <easy3d/util/initializer.h>
36int main(
int argc,
char **argv) {
40 ManipulationViewer 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 the 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
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/renderer/manipulator.h>
33#include <easy3d/renderer/manipulated_frame.h>
34#include <easy3d/util/file_system.h>
35#include <easy3d/util/setting.h>
41ManipulationViewer::ManipulationViewer(
const std::string &title)
42 :
Viewer(title), selected_model_(nullptr)
45 camera()->setViewDirection(
vec3(0, 0, -1));
46 camera()->setUpVector(
vec3(0, 1, 0));
49 "-------------------- Manipulator Viewer usage ---------------------\n"
50 "Press the left button to pick/unpick a model. \n"
51 "When a model is picked, using the mouse to manipulate it: \n"
52 " - ALT + left button: rotate the model \n"
53 " - ALT + right button: translate the model \n"
54 "------------------------------------------------------------------ \n";
58bool ManipulationViewer::mouse_press_event(
int x,
int y,
int button,
int modifiers) {
59 if (modifiers != MODIF_ALT) {
61 auto model = picker.pick(models(), x, y);
67 return Viewer::mouse_press_event(x, y, button, modifiers);
71bool ManipulationViewer::mouse_drag_event(
int x,
int y,
int dx,
int dy,
int button,
int modifiers) {
73 if (modifiers == MODIF_ALT && selected_model_) {
76 auto axis = ManipulatedFrame::NONE;
77 if (pressed_key_ == KEY_X) axis = ManipulatedFrame::HORIZONTAL;
78 else if (pressed_key_ == KEY_Y) axis = ManipulatedFrame::VERTICAL;
79 else if (pressed_key_ == KEY_O) axis = ManipulatedFrame::ORTHOGONAL;
85 frame->
action_translate(x, y, dx, dy, camera_, axis);
93 return Viewer::mouse_drag_event(x, y, dx, dy, button, modifiers);
98 for (
auto m : models()) {
99 m->renderer()->set_selected(m == model);
100 auto faces = m->renderer()->get_triangles_drawable(
"faces");
102 faces->set_uniform_coloring(
vec4(1, 0, 0, 1.0f));
104 faces->set_uniform_coloring(setting::surface_mesh_faces_color);
106 std::cout <<
"picked model: " << file_system::simple_name(model->
name()) << std::endl;
108 selected_model_ = model;
112 static_cast<void (ManipulationViewer::*)(
void) const
>(&ManipulationViewer::update));
118void ManipulationViewer::draw()
const {
120 for (
auto m : models()) {
121 if (m->renderer()->is_selected() && m->manipulator())
122 m->manipulator()->draw_frame(camera());
A Frame that can be rotated and translated using the mouse.
Definition: manipulated_frame.h:110
virtual void action_rotate(int mouse_x, int mouse_y, int mouse_dx, int mouse_dy, Camera *camera, ScreenAxis axis)
Definition: manipulated_frame.cpp:113
A manipulator is for manipulation of an object.
Definition: manipulator.h:62
ManipulatedFrame * frame()
Returns the manipulated frame.
Definition: manipulator.h:73
Manipulator * manipulator()
Gets the manipulator attached to this model.
Definition: model.h:105
const std::string & name() const
The name of a model.
Definition: model.h:60
void set_manipulator(Manipulator *manip)
Attaches a manipulator to this model.
Definition: model.h:102
Implementation of picking mechanism for set of models.
Definition: picker_model.h:48
int connect(std::function< void(Args...)> const &slot)
Connects a function to this signal.
Definition: signal.h:97