diff --git a/src/GUI/Plater/Plate3D.cpp b/src/GUI/Plater/Plate3D.cpp index 185d06e6c..6750a8897 100644 --- a/src/GUI/Plater/Plate3D.cpp +++ b/src/GUI/Plater/Plate3D.cpp @@ -31,9 +31,8 @@ void Plate3D::mouse_up(wxMouseEvent &e){ for(const PlaterObject &object: objects){ const auto &modelobj = model->objects.at(object.identifier); for(ModelInstance *instance: modelobj->instances){ - uint size = modelobj->volumes.size(); + uint size = modelobj->volumes.size(); if(i <= moving_volume && moving_volume < i+size){ - instance->offset.translate(volumes.at(i).origin); modelobj->update_bounding_box(); on_instances_moved(); @@ -47,6 +46,7 @@ void Plate3D::mouse_up(wxMouseEvent &e){ } Scene3D::mouse_up(e); } + void Plate3D::mouse_move(wxMouseEvent &e){ if(!e.Dragging()){ pos = Point(e.GetX(),e.GetY()); @@ -61,7 +61,7 @@ void Plate3D::mouse_move(wxMouseEvent &e){ for(const PlaterObject &object: objects){ const auto &modelobj = model->objects.at(object.identifier); for(ModelInstance *instance: modelobj->instances){ - uint size = modelobj->volumes.size(); + uint size = modelobj->volumes.size(); if(i <= moving_volume && moving_volume < i+size){ for(ModelVolume* volume: modelobj->volumes){ volumes.at(i).origin.translate(old.vector_to(current)); @@ -79,15 +79,18 @@ void Plate3D::mouse_move(wxMouseEvent &e){ } } - void Plate3D::update(){ volumes.clear(); for(const PlaterObject &object: objects){ const auto &modelobj = model->objects.at(object.identifier); for(ModelInstance *instance: modelobj->instances){ for(ModelVolume* volume: modelobj->volumes){ - volumes.push_back(load_object(*volume,*instance)); - } + TriangleMesh copy = volume->mesh; + instance->transform_mesh(©); + GLVertexArray model; + model.load_mesh(copy); + volumes.push_back(Volume{ wxColor(200,200,200), Pointf3(0,0,0), model, copy.bounding_box()}); + } } } color_volumes(); @@ -110,7 +113,7 @@ void Plate3D::color_volumes(){ rendervolume.color = ui_settings->color->COLOR_PARTS(); } i++; - } + } } } } @@ -122,6 +125,7 @@ void Plate3D::before_render(){ } // Color each volume a different color, render and test which color is beneath the mouse. + //glDisable(GL_MULTISAMPLE) if ($self->{can_multisample}); glDisable(GL_LIGHTING); uint i = 1; @@ -135,7 +139,6 @@ void Plate3D::before_render(){ GLubyte color[4] = {0,0,0,0}; glReadPixels(pos.x, GetSize().GetHeight()- pos.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, color); - // Handle the hovered volume uint index = (color[0]<<16) + (color[1]<<8) + color[2]; hover = false; @@ -149,7 +152,7 @@ void Plate3D::before_render(){ const auto &modelobj = model->objects.at(object.identifier); if(k <= hover_volume && hover_volume < k+modelobj->instances.size()*modelobj->volumes.size()){ hover_object = k; - break; + break; } k++; } diff --git a/src/GUI/Plater/Plate3D.hpp b/src/GUI/Plater/Plate3D.hpp index f83dbc292..605ce9d65 100644 --- a/src/GUI/Plater/Plate3D.hpp +++ b/src/GUI/Plater/Plate3D.hpp @@ -14,23 +14,34 @@ namespace Slic3r { namespace GUI { class Plate3D : public Scene3D { public: + Plate3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config); + + /// Called to regenerate rendered volumes from the model void update(); + /// Registered function to fire when objects are selected. std::function on_select_object {}; + /// Registered function to fire when an instance is moved. std::function on_instances_moved {}; + void selection_changed(){Refresh();} - Plate3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config); -protected: + protected: + // Render each volume as a different color and check what color is beneath + // the mouse to detemine the hovered volume void before_render(); + + // Mouse events are needed to handle selecting and moving objects void mouse_up(wxMouseEvent &e); void mouse_move(wxMouseEvent &e); void mouse_down(wxMouseEvent &e); + private: void color_volumes(); Point pos, move_start; bool hover = false, mouse = false, moving = false; uint hover_volume, hover_object, moving_volume; + std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config; diff --git a/src/GUI/Scene3D.cpp b/src/GUI/Scene3D.cpp index 110d06eb4..cb4b059bd 100644 --- a/src/GUI/Scene3D.cpp +++ b/src/GUI/Scene3D.cpp @@ -25,13 +25,7 @@ Scene3D::Scene3D(wxWindow* parent, const wxSize& size) : this->Bind(wxEVT_RIGHT_UP, [this](wxMouseEvent &e) { this->mouse_up(e); }); this->Bind(wxEVT_MIDDLE_DCLICK, [this](wxMouseEvent &e) { this->mouse_dclick(e); }); this->Bind(wxEVT_MOUSEWHEEL, [this](wxMouseEvent &e) { this->mouse_wheel(e); }); -/* - if (user_drawn_background) { - this->Bind(wxEVT_ERASE_BACKGROUND, [this](wxEraseEvent& e){ }); - } - - this->Bind(wxEVT_CHAR, [this](wxKeyEvent &e) { this->nudge_key(e);}); - */ + Points p; const coord_t w = scale_(200), z = 0; p.push_back(Point(z,z)); @@ -497,12 +491,4 @@ void Scene3D::repaint(wxPaintEvent& e) { } -Volume Scene3D::load_object(ModelVolume &mv, ModelInstance &mi){ - TriangleMesh copy = mv.mesh; - mi.transform_mesh(©); - GLVertexArray model; - model.load_mesh(copy); - return Volume{ wxColor(200,200,200), Pointf3(0,0,0), model, copy.bounding_box()}; -} - } } // Namespace Slic3r::GUI diff --git a/src/GUI/Scene3D.hpp b/src/GUI/Scene3D.hpp index 02daa984a..21dd47108 100644 --- a/src/GUI/Scene3D.hpp +++ b/src/GUI/Scene3D.hpp @@ -25,31 +25,48 @@ public: Scene3D(wxWindow* parent, const wxSize& size); private: wxGLContext* glContext; - bool init = false, dirty = true, dragging = false; + + // Camera settings float zoom = 5.0f, phi = 0.0f, theta = 0.0f; - Point drag_start = Point(0,0); Pointf3 _camera_target = Pointf3(0.0f,0.0f,0.0f); + + // Optional point used for dragging calculations + bool dragging = false; + Point drag_start = Point(0,0); + + // Bed Stuff std::vector bed_verts, grid_verts; Points bed_shape; BoundingBox bed_bound; - void resize(); - void repaint(wxPaintEvent &e); - void init_gl(); + + void repaint(wxPaintEvent &e); // Redraws every frame + + bool dirty = true; // Resize needs to be called before render + void resize(); // Handle glViewport and projection matrices + + bool init = false; // Has opengl been initted + void init_gl(); // Handles lights and materials + + // Useded in repaint void draw_background(); void draw_ground(); void draw_axes(Pointf3 center, float length, int width, bool alwaysvisible); + protected: - Linef3 mouse_ray(Point win); - void draw_volumes(); - virtual void mouse_up(wxMouseEvent &e); + Linef3 mouse_ray(Point win); // Utility for backtracking from window coordinates + void draw_volumes(); // Draws volumes (for use in before_render) + void set_bed_shape(Points _bed_shape); + + std::vector volumes; + Volume load_object(ModelVolume &mv, ModelInstance &mi); + + // Virtual methods to override + virtual void mouse_up(wxMouseEvent &e); virtual void mouse_move(wxMouseEvent &e); virtual void mouse_dclick(wxMouseEvent &e); virtual void mouse_wheel(wxMouseEvent &e); virtual void before_render(){}; virtual void after_render(){}; - Volume load_object(ModelVolume &mv, ModelInstance &mi); - void set_bed_shape(Points _bed_shape); - std::vector volumes; }; } } // Namespace Slic3r::GUI