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

View File

@ -43,7 +43,9 @@ private:
void set_its(indexed_triangle_set &its);
void create_gui_cfg();
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
static bool exist_volume(ModelVolume *volume);