change in platter changed object:

call with object itself(do not use index to object list)
add recalculate object bounding box
add check whether object is not outside the bed
This commit is contained in:
Filip Sykala - NTB T15p 2023-10-25 18:16:51 +02:00
parent 9c054b05c1
commit 7b93b5e512
6 changed files with 70 additions and 95 deletions

View File

@ -716,21 +716,7 @@ void GLGizmoEmboss::volume_transformation_changed()
// inform slicing process that model changed
// SLA supports, processing
// ensure on bed
const ModelObjectPtrs objects = m_parent.get_model()->objects;
ModelObject *object = m_volume->get_object();
object->invalidate_bounding_box();
object->ensure_on_bed();
int obj_idx = -1;
for (int i = 0; i < objects.size(); i++)
if (objects[i]->id() == object->id()) {
obj_idx = i;
break;
}
wxGetApp().plater()->changed_object(obj_idx);
// Check outside bed
m_parent.requires_check_outside_state();
wxGetApp().plater()->changed_object(*m_volume->get_object());
}
// Show correct value of height & depth inside of inputs

View File

@ -339,21 +339,7 @@ void GLGizmoSVG::volume_transformation_changed()
// inform slicing process that model changed
// SLA supports, processing
// ensure on bed
const ModelObjectPtrs objects = m_parent.get_model()->objects;
ModelObject *object = m_volume->get_object();
object->invalidate_bounding_box();
object->ensure_on_bed();
int obj_idx = -1;
for (int i = 0; i < objects.size(); i++)
if (objects[i]->id() == object->id()) {
obj_idx = i;
break;
}
wxGetApp().plater()->changed_object(obj_idx);
// Check outside bed
m_parent.requires_check_outside_state();
wxGetApp().plater()->changed_object(*m_volume->get_object());
}
// Show correct value of height & depth inside of inputs
@ -716,6 +702,7 @@ void wu_draw_line_side(Linef line,
}
}
#ifdef MORE_DRAWING
// Wu's line algorithm - https://en.wikipedia.org/wiki/Xiaolin_Wu's_line_algorithm
void wu_draw_line(Linef line,
const std::function<void(int x, int y, float brightess)>& plot) {
@ -786,6 +773,36 @@ void wu_draw_line(Linef line,
}
}
void draw(const ExPolygonsWithIds &shapes_with_ids, unsigned max_size)
{
ImVec2 actual_pos = ImGui::GetCursorPos();
// draw shapes
BoundingBox bb;
for (const ExPolygonsWithId &shape : shapes_with_ids)
bb.merge(get_extents(shape.expoly));
Point bb_size = bb.size();
double scale = max_size / (double) std::max(bb_size.x(), bb_size.y());
ImVec2 win_offset = ImGui::GetWindowPos();
Point offset(win_offset.x + actual_pos.x, win_offset.y + actual_pos.y);
offset += bb_size / 2 * scale;
auto draw_polygon = [&scale, offset](Slic3r::Polygon p) {
p.scale(scale, -scale); // Y mirror
p.translate(offset);
ImGuiWrapper::draw(p);
};
for (const ExPolygonsWithId &shape : shapes_with_ids) {
for (const ExPolygon &expoly : shape.expoly) {
draw_polygon(expoly.contour);
for (const Slic3r::Polygon &hole : expoly.holes)
draw_polygon(hole);
}
}
}
#endif // MORE_DRAWING
template<unsigned int N> // N .. count of channels per pixel
void draw_side_outline(const ExPolygons &shape, const std::array<unsigned char, N> &color, std::vector<unsigned char> &data, size_t data_width, double scale)
{
@ -878,7 +895,7 @@ void draw_filled(const ExPolygons &shape, const std::array<unsigned char, N>& co
size_t offset = get_offset(x, y);
if (data[offset + N - 1] != 0)
return; // already setted by line
for (size_t i = 0; i < N; ++i)
for (int i = 0; i < N; ++i)
data[offset + i] = color[i];
};
@ -1372,35 +1389,6 @@ void GLGizmoSVG::draw_window()
draw_model_type();
}
}
namespace {
void draw(const ExPolygonsWithIds& shapes_with_ids, unsigned max_size)
{
ImVec2 actual_pos = ImGui::GetCursorPos();
// draw shapes
BoundingBox bb;
for (const ExPolygonsWithId &shape : shapes_with_ids)
bb.merge(get_extents(shape.expoly));
Point bb_size = bb.size();
double scale = max_size / (double) std::max(bb_size.x(), bb_size.y());
ImVec2 win_offset = ImGui::GetWindowPos();
Point offset(win_offset.x + actual_pos.x, win_offset.y + actual_pos.y);
offset += bb_size / 2 * scale;
auto draw_polygon = [&scale, offset](Slic3r::Polygon p) {
p.scale(scale, -scale); // Y mirror
p.translate(offset);
ImGuiWrapper::draw(p);
};
for (const ExPolygonsWithId &shape : shapes_with_ids) {
for (const ExPolygon &expoly : shape.expoly) {
draw_polygon(expoly.contour);
for (const Slic3r::Polygon &hole : expoly.holes)
draw_polygon(hole);
}
}
}
}
void GLGizmoSVG::draw_preview(){
// init texture when not initialized yet.

View File

@ -12,6 +12,7 @@
#include <libslic3r/Format/OBJ.hpp> // load_obj for default mesh
#include <libslic3r/CutSurface.hpp> // use surface cuts
#include <libslic3r/BuildVolume.hpp> // create object
#include <libslic3r/SLA/ReprojectPointsOnMesh.hpp>
#include "slic3r/GUI/Plater.hpp"
#include "slic3r/GUI/NotificationManager.hpp"
@ -419,8 +420,6 @@ void UpdateJob::update_volume(ModelVolume *volume, TriangleMesh &&mesh, const Da
volume->set_mesh(std::move(mesh));
volume->set_new_unique_id();
volume->calculate_convex_hull();
ModelObject *object = volume->get_object();
object->invalidate_bounding_box();
// write data from base into volume
base.write(*volume);
@ -434,17 +433,15 @@ void UpdateJob::update_volume(ModelVolume *volume, TriangleMesh &&mesh, const Da
update_name_in_list(*obj_list, *volume);
}
// Get object id to set object as changed
Plater* plater = app.plater();
ModelObjectPtrs objects = plater->model().objects;
int obj_idx = -1;
for (int i = 0; i < objects.size(); ++i)
if (objects[i]->id() == object->id()) {
obj_idx = i;
break;
}
assert(obj_idx >= 0);
plater->changed_object(obj_idx);
ModelObject *object = volume->get_object();
assert(object != nullptr);
if (object == nullptr)
return;
Plater *plater = app.plater();
if (plater->printer_technology() == ptSLA)
sla::reproject_points_and_holes(object);
plater->changed_object(*object);
}
/////////////////

View File

@ -7815,22 +7815,35 @@ void Plater::changed_mesh(int obj_idx)
p->schedule_background_process();
}
void Plater::changed_object(ModelObject &object){
assert(object.get_model() == &p->model); // is object from same model?
object.invalidate_bounding_box();
// recenter and re - align to Z = 0
object.ensure_on_bed(p->printer_technology != ptSLA);
if (p->printer_technology == ptSLA) {
// Update the SLAPrint from the current Model, so that the reload_scene()
// pulls the correct data, update the 3D scene.
p->update_restart_background_process(true, false);
} else
p->view3D->reload_scene(false);
// update print
p->schedule_background_process();
// Check outside bed
get_current_canvas3D()->requires_check_outside_state();
}
void Plater::changed_object(int obj_idx)
{
if (obj_idx < 0)
return;
// recenter and re - align to Z = 0
p->model.objects[obj_idx]->ensure_on_bed(p->printer_technology != ptSLA);
if (this->p->printer_technology == ptSLA) {
// Update the SLAPrint from the current Model, so that the reload_scene()
// pulls the correct data, update the 3D scene.
this->p->update_restart_background_process(true, false);
}
else
p->view3D->reload_scene(false);
// update print
this->p->schedule_background_process();
ModelObject *object = p->model.objects[obj_idx];
if (object == nullptr)
return;
changed_object(*object);
}
void Plater::changed_objects(const std::vector<size_t>& object_idxs)

View File

@ -298,6 +298,7 @@ public:
void clear_before_change_mesh(int obj_idx, const std::string &notification_msg);
void changed_mesh(int obj_idx);
void changed_object(ModelObject &object);
void changed_object(int obj_idx);
void changed_objects(const std::vector<size_t>& object_idxs);
void schedule_background_process(bool schedule = true);

View File

@ -359,16 +359,6 @@ bool face_selected_volume_to_camera(const Camera &camera, GLCanvas3D &canvas, co
if (volume.type() == ModelVolumeType::MODEL_PART)
object.ensure_on_bed();
//int obj_idx = -1;
//for (int i = 0; i < objects.size(); i++)
// if (objects[i]->id() == object.id()) {
// obj_idx = i;
// break;
// }
// object change !!!
// Plater::changed_object(obj_idx);
return true;
}