Tech ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX - Render the selection bounding box in the current reference system

This commit is contained in:
enricoturri1966 2022-02-15 09:10:41 +01:00
parent 44252074b4
commit c1ce2ff68a
3 changed files with 68 additions and 0 deletions

View File

@ -82,6 +82,8 @@
#define ENABLE_WORLD_COORDINATE (1 && ENABLE_2_5_0_ALPHA1) #define ENABLE_WORLD_COORDINATE (1 && ENABLE_2_5_0_ALPHA1)
// Enable showing world coordinates of volumes' offset relative to the instance containing them // Enable showing world coordinates of volumes' offset relative to the instance containing them
#define ENABLE_WORLD_COORDINATE_VOLUMES_LOCAL_OFFSET (0 && ENABLE_WORLD_COORDINATE) #define ENABLE_WORLD_COORDINATE_VOLUMES_LOCAL_OFFSET (0 && ENABLE_WORLD_COORDINATE)
// Enable rendering the selection bounding box in the current reference system
#define ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX (1 && ENABLE_WORLD_COORDINATE)
#endif // _prusaslicer_technologies_h_ #endif // _prusaslicer_technologies_h_

View File

@ -1408,7 +1408,33 @@ void Selection::render(float scale_factor)
m_scale_factor = scale_factor; m_scale_factor = scale_factor;
// render cumulative bounding box of selected volumes // render cumulative bounding box of selected volumes
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX
BoundingBoxf3 box;
Transform3d trafo;
const ECoordinatesType coordinates_type = wxGetApp().obj_manipul()->get_coordinates_type();
if (coordinates_type == ECoordinatesType::World) {
box = get_bounding_box();
trafo = Transform3d::Identity();
}
else if (coordinates_type == ECoordinatesType::Local && is_single_volume_or_modifier()) {
const GLVolume& v = *get_volume(*get_volume_idxs().begin());
box = v.transformed_convex_hull_bounding_box(v.get_instance_transformation().get_matrix(true, true, false, true) * v.get_volume_transformation().get_matrix(true, true, false, true));
trafo = v.get_instance_transformation().get_matrix(false, false, true, false) * v.get_volume_transformation().get_matrix(false, false, true, false);
}
else {
const Selection::IndicesList& ids = get_volume_idxs();
for (unsigned int id : ids) {
const GLVolume& v = *get_volume(id);
box.merge(v.transformed_convex_hull_bounding_box(v.get_volume_transformation().get_matrix()));
}
box = box.transformed(get_volume(*ids.begin())->get_instance_transformation().get_matrix(true, true, false, true));
trafo = get_volume(*ids.begin())->get_instance_transformation().get_matrix(false, false, true, false);
}
render_bounding_box(box, trafo, ColorRGB::WHITE());
#else
render_bounding_box(get_bounding_box(), ColorRGB::WHITE()); render_bounding_box(get_bounding_box(), ColorRGB::WHITE());
#endif // ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX
#else #else
render_selected_volumes(); render_selected_volumes();
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
@ -1996,6 +2022,12 @@ void Selection::render_synchronized_volumes()
float color[3] = { 1.0f, 1.0f, 0.0f }; float color[3] = { 1.0f, 1.0f, 0.0f };
#endif // !ENABLE_GLBEGIN_GLEND_REMOVAL #endif // !ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX
const ECoordinatesType coordinates_type = wxGetApp().obj_manipul()->get_coordinates_type();
BoundingBoxf3 box;
Transform3d trafo;
#endif // ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX
for (unsigned int i : m_list) { for (unsigned int i : m_list) {
const GLVolume& volume = *(*m_volumes)[i]; const GLVolume& volume = *(*m_volumes)[i];
int object_idx = volume.object_idx(); int object_idx = volume.object_idx();
@ -2009,7 +2041,23 @@ void Selection::render_synchronized_volumes()
continue; continue;
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX
if (coordinates_type == ECoordinatesType::World) {
box = v.transformed_convex_hull_bounding_box();
trafo = Transform3d::Identity();
}
else if (coordinates_type == ECoordinatesType::Local) {
box = v.bounding_box();
trafo = v.world_matrix();
}
else {
box = v.transformed_convex_hull_bounding_box(v.get_volume_transformation().get_matrix());
trafo = v.get_instance_transformation().get_matrix();
}
render_bounding_box(box, trafo, ColorRGB::YELLOW());
#else
render_bounding_box(v.transformed_convex_hull_bounding_box(), ColorRGB::YELLOW()); render_bounding_box(v.transformed_convex_hull_bounding_box(), ColorRGB::YELLOW());
#endif // ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX
#else #else
render_bounding_box(v.transformed_convex_hull_bounding_box(), color); render_bounding_box(v.transformed_convex_hull_bounding_box(), color);
#endif // ENABLE_GLBEGIN_GLEND_REMOVAL #endif // ENABLE_GLBEGIN_GLEND_REMOVAL
@ -2018,7 +2066,11 @@ void Selection::render_synchronized_volumes()
} }
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX
void Selection::render_bounding_box(const BoundingBoxf3& box, const Transform3d& trafo, const ColorRGB& color)
#else
void Selection::render_bounding_box(const BoundingBoxf3& box, const ColorRGB& color) void Selection::render_bounding_box(const BoundingBoxf3& box, const ColorRGB& color)
#endif // ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX
{ {
#else #else
void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) const void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) const
@ -2037,6 +2089,7 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
const BoundingBoxf3& curr_box = m_box.get_bounding_box(); const BoundingBoxf3& curr_box = m_box.get_bounding_box();
if (!m_box.is_initialized() || !is_approx(box.min, curr_box.min) || !is_approx(box.max, curr_box.max)) { if (!m_box.is_initialized() || !is_approx(box.min, curr_box.min) || !is_approx(box.max, curr_box.max)) {
m_box.reset(); m_box.reset();
@ -2122,10 +2175,19 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con
if (shader == nullptr) if (shader == nullptr)
return; return;
#if ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX
glsafe(::glPushMatrix());
glsafe(::glMultMatrixd(trafo.data()));
#endif // ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX
shader->start_using(); shader->start_using();
m_box.set_color(to_rgba(color)); m_box.set_color(to_rgba(color));
m_box.render(); m_box.render();
shader->stop_using(); shader->stop_using();
#if ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX
glsafe(::glPopMatrix());
#endif // ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX
#else #else
::glBegin(GL_LINES); ::glBegin(GL_LINES);

View File

@ -398,7 +398,11 @@ private:
void set_bounding_boxes_dirty() { m_bounding_box.reset(); m_unscaled_instance_bounding_box.reset(); m_scaled_instance_bounding_box.reset(); } void set_bounding_boxes_dirty() { m_bounding_box.reset(); m_unscaled_instance_bounding_box.reset(); m_scaled_instance_bounding_box.reset(); }
void render_synchronized_volumes(); void render_synchronized_volumes();
#if ENABLE_GLBEGIN_GLEND_REMOVAL #if ENABLE_GLBEGIN_GLEND_REMOVAL
#if ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX
void render_bounding_box(const BoundingBoxf3& box, const Transform3d& trafo, const ColorRGB& color);
#else
void render_bounding_box(const BoundingBoxf3& box, const ColorRGB& color); void render_bounding_box(const BoundingBoxf3& box, const ColorRGB& color);
#endif // ENABLE_COORDINATE_DEPENDENT_SELECTION_BOX
#else #else
void render_selected_volumes() const; void render_selected_volumes() const;
void render_bounding_box(const BoundingBoxf3& box, float* color) const; void render_bounding_box(const BoundingBoxf3& box, float* color) const;