mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-13 19:25:54 +08:00
Cleanup
This commit is contained in:
parent
2258fd5978
commit
40decdc405
@ -33,7 +33,6 @@ void Plate3D::mouse_up(wxMouseEvent &e){
|
||||
for(ModelInstance *instance: modelobj->instances){
|
||||
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());
|
||||
@ -79,14 +79,17 @@ 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()});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
@ -14,23 +14,34 @@ namespace Slic3r { namespace GUI {
|
||||
|
||||
class Plate3D : public Scene3D {
|
||||
public:
|
||||
Plate3D(wxWindow* parent, const wxSize& size, std::vector<PlaterObject>& _objects, std::shared_ptr<Model> _model, std::shared_ptr<Config> _config);
|
||||
|
||||
/// Called to regenerate rendered volumes from the model
|
||||
void update();
|
||||
|
||||
/// Registered function to fire when objects are selected.
|
||||
std::function<void (const unsigned int obj_idx)> on_select_object {};
|
||||
|
||||
/// Registered function to fire when an instance is moved.
|
||||
std::function<void ()> on_instances_moved {};
|
||||
|
||||
void selection_changed(){Refresh();}
|
||||
Plate3D(wxWindow* parent, const wxSize& size, std::vector<PlaterObject>& _objects, std::shared_ptr<Model> _model, std::shared_ptr<Config> _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<PlaterObject>& objects; //< reference to parent vector
|
||||
std::shared_ptr<Slic3r::Model> model;
|
||||
std::shared_ptr<Slic3r::Config> config;
|
||||
|
@ -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
|
||||
|
@ -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<float> 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();
|
||||
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<Volume> 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<Volume> volumes;
|
||||
};
|
||||
|
||||
} } // Namespace Slic3r::GUI
|
||||
|
Loading…
x
Reference in New Issue
Block a user