Fix. Allow simplify volume inside object, fix drawing wireframe

This commit is contained in:
Filip Sykala 2021-10-04 12:29:45 +02:00
parent 580f157d28
commit 39a98e97b4
2 changed files with 42 additions and 20 deletions

View File

@ -60,8 +60,9 @@ void GLGizmoSimplify::on_render_for_picking() {}
void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limit) void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limit)
{ {
create_gui_cfg(); create_gui_cfg();
int obj_index; const Selection &selection = m_parent.get_selection();
ModelVolume *act_volume = get_selected_volume(&obj_index); int obj_index = selection.get_object_idx();
ModelVolume *act_volume = get_volume(selection, wxGetApp().plater()->model());
if (act_volume == nullptr) { if (act_volume == nullptr) {
switch (m_state) { switch (m_state) {
case State::settings: close(); break; case State::settings: close(); break;
@ -427,17 +428,34 @@ bool GLGizmoSimplify::exist_volume(ModelVolume *volume) {
return false; return false;
} }
ModelVolume *GLGizmoSimplify::get_selected_volume(int *object_idx_ptr) const ModelVolume * GLGizmoSimplify::get_volume(const Selection &selection, Model &model)
{ {
const Selection &selection = m_parent.get_selection(); const Selection::IndicesList& idxs = selection.get_volume_idxs();
int object_idx = selection.get_object_idx(); if (idxs.empty()) return nullptr;
if (object_idx_ptr != nullptr) *object_idx_ptr = object_idx; // only one selected volume
if (object_idx < 0) return nullptr; if (idxs.size() != 1) return nullptr;
ModelObjectPtrs &objs = wxGetApp().plater()->model().objects; const GLVolume *selected_volume = selection.get_volume(*idxs.begin());
if (static_cast<int>(objs.size()) <= object_idx) return nullptr; if (selected_volume == nullptr) return nullptr;
ModelObject *obj = objs[object_idx];
if (obj->volumes.empty()) return nullptr; const GLVolume::CompositeID &cid = selected_volume->composite_id;
return obj->volumes.front(); const ModelObjectPtrs& objs = model.objects;
if (cid.object_id < 0 || objs.size() <= static_cast<size_t>(cid.object_id))
return nullptr;
const ModelObject* obj = objs[cid.object_id];
if (cid.volume_id < 0 || obj->volumes.size() <= static_cast<size_t>(cid.volume_id))
return nullptr;
return obj->volumes[cid.volume_id];
}
const ModelVolume *GLGizmoSimplify::get_volume(const GLVolume::CompositeID &cid, const Model &model)
{
const ModelObjectPtrs &objs = model.objects;
if (cid.object_id < 0 || objs.size() <= static_cast<size_t>(cid.object_id))
return nullptr;
const ModelObject *obj = objs[cid.object_id];
if (cid.volume_id < 0 || obj->volumes.size() <= static_cast<size_t>(cid.volume_id))
return nullptr;
return obj->volumes[cid.volume_id];
} }
void GLGizmoSimplify::init_wireframe() void GLGizmoSimplify::init_wireframe()
@ -479,14 +497,16 @@ void GLGizmoSimplify::render_wireframe() const
if (m_wireframe_VBO_id == 0 || m_wireframe_IBO_id == 0) return; if (m_wireframe_VBO_id == 0 || m_wireframe_IBO_id == 0) return;
if (!m_show_wireframe) return; if (!m_show_wireframe) return;
const GLVolume *selected_volume = m_parent.get_selection().get_volume(0); const auto& selection = m_parent.get_selection();
const auto& volume_idxs = selection.get_volume_idxs();
// check selected_volume == m_volume if (volume_idxs.empty() || volume_idxs.size() != 1) return;
const auto& cid = selected_volume->composite_id; const GLVolume *selected_volume = selection.get_volume(*volume_idxs.begin());
assert(wxGetApp().plater()->model().objects[cid.object_id]->volumes[cid.volume_id] == m_volume);
// check that selected model is wireframe initialized
const Transform3d trafo_matrix = m_parent.get_selection().get_volume(0)->world_matrix(); if (m_volume != get_volume(selected_volume->composite_id, *m_parent.get_model()))
return;
const Transform3d trafo_matrix = selected_volume->world_matrix();
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glMultMatrixd(trafo_matrix.data())); glsafe(::glMultMatrixd(trafo_matrix.data()));

View File

@ -43,7 +43,9 @@ private:
void set_its(indexed_triangle_set &its); void set_its(indexed_triangle_set &its);
void create_gui_cfg(); void create_gui_cfg();
void request_rerender(); void request_rerender();
ModelVolume *get_selected_volume(int *object_idx = nullptr) const; // move to global functions
static ModelVolume *get_volume(const Selection &selection, Model &model);
static const ModelVolume *get_volume(const GLVolume::CompositeID &cid, const Model &model);
// return false when volume was deleted // return false when volume was deleted
static bool exist_volume(ModelVolume *volume); static bool exist_volume(ModelVolume *volume);