Fix crash in 3d preview
This commit is contained in:
@@ -878,6 +878,9 @@ void GLVolume::render_mmu_texture_preview(const Transform3d &view_matrix,
|
||||
if (!use_original_mesh_texture_preview && mmuseg_texture_preview_models.empty() && mmuseg_vertex_color_preview_models.empty())
|
||||
return;
|
||||
|
||||
if (GUI::wxGetApp().plater() == nullptr)
|
||||
return;
|
||||
|
||||
if (this->is_left_handed())
|
||||
glFrontFace(GL_CW);
|
||||
glsafe(::glCullFace(GL_BACK));
|
||||
@@ -1686,9 +1689,9 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo
|
||||
for (unsigned int i = 0; i < (unsigned int)volumes.size(); ++i) {
|
||||
GLVolume* volume = volumes[i];
|
||||
bool is_transparent = volume->render_color.is_transparent();
|
||||
auto tempGlwipeTowerVolume = dynamic_cast<GLWipeTowerVolume *>(volume);
|
||||
if (tempGlwipeTowerVolume) {
|
||||
is_transparent = tempGlwipeTowerVolume->IsTransparent();
|
||||
if (volume->is_wipe_tower) {
|
||||
GLWipeTowerVolume *wipe_tower_volume = static_cast<GLWipeTowerVolume *>(volume);
|
||||
is_transparent = wipe_tower_volume->IsTransparent();
|
||||
}
|
||||
if (((type == GLVolumeCollection::ERenderType::Opaque && !is_transparent) ||
|
||||
(type == GLVolumeCollection::ERenderType::Transparent && is_transparent) ||
|
||||
@@ -1845,6 +1848,11 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type,
|
||||
else
|
||||
volume.first->render();
|
||||
|
||||
#if ENABLE_ENVIRONMENT_MAP
|
||||
if (use_environment_texture)
|
||||
glsafe(::glBindTexture(GL_TEXTURE_2D, 0));
|
||||
#endif // ENABLE_ENVIRONMENT_MAP
|
||||
|
||||
const int texture_preview_print_volume_type =
|
||||
volume.first->partly_inside && partly_inside_enable ? static_cast<int>(m_print_volume.type) : -1;
|
||||
const std::array<float, 4> texture_preview_clipping_plane = {
|
||||
@@ -1853,15 +1861,20 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type,
|
||||
float(m_clipping_plane[2]),
|
||||
float(m_clipping_plane[3])
|
||||
};
|
||||
const bool render_model_texture_preview =
|
||||
volume.first->object_idx() >= 0 && volume.first->volume_idx() >= 0 && !volume.first->is_wipe_tower &&
|
||||
!volume.first->is_modifier && !volume.first->is_extrusion_path;
|
||||
shader->stop_using();
|
||||
volume.first->render_mmu_texture_preview(view_matrix,
|
||||
projection_matrix,
|
||||
m_z_range,
|
||||
texture_preview_clipping_plane,
|
||||
texture_preview_print_volume_type,
|
||||
m_print_volume.data,
|
||||
m_print_volume.zs);
|
||||
if (GLWipeTowerVolume *wipe_tower_volume = dynamic_cast<GLWipeTowerVolume *>(volume.first)) {
|
||||
if (render_model_texture_preview)
|
||||
volume.first->render_mmu_texture_preview(view_matrix,
|
||||
projection_matrix,
|
||||
m_z_range,
|
||||
texture_preview_clipping_plane,
|
||||
texture_preview_print_volume_type,
|
||||
m_print_volume.data,
|
||||
m_print_volume.zs);
|
||||
if (volume.first->is_wipe_tower) {
|
||||
GLWipeTowerVolume *wipe_tower_volume = static_cast<GLWipeTowerVolume *>(volume.first);
|
||||
wipe_tower_volume->render_prime_tower_image_preview(view_matrix,
|
||||
projection_matrix,
|
||||
m_z_range,
|
||||
@@ -1872,11 +1885,6 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type,
|
||||
}
|
||||
shader->start_using();
|
||||
|
||||
#if ENABLE_ENVIRONMENT_MAP
|
||||
if (use_environment_texture)
|
||||
glsafe(::glBindTexture(GL_TEXTURE_2D, 0));
|
||||
#endif // ENABLE_ENVIRONMENT_MAP
|
||||
|
||||
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||
}
|
||||
@@ -2231,6 +2239,9 @@ void GLVolumeCollection::reset_outside_state()
|
||||
|
||||
void GLVolumeCollection::update_colors_by_extruder(const DynamicPrintConfig *config, bool is_update_alpha)
|
||||
{
|
||||
if (config == nullptr)
|
||||
return;
|
||||
|
||||
|
||||
using ColorItem = std::pair<std::string, ColorRGBA>;
|
||||
std::vector<ColorItem> colors;
|
||||
|
||||
@@ -1623,7 +1623,7 @@ struct Sidebar::priv
|
||||
wxScrolledWindow* m_scrolledWindow_filament_content;
|
||||
wxStaticLine* m_staticline2;
|
||||
StaticBox* m_panel_texture_mapping_title = nullptr;
|
||||
wxPanel* m_panel_texture_mapping_content = nullptr;
|
||||
wxScrolledWindow* m_panel_texture_mapping_content = nullptr;
|
||||
wxBoxSizer* m_sizer_texture_mapping_content = nullptr;
|
||||
ScalableButton* m_texture_mapping_icon = nullptr;
|
||||
wxStaticText* m_staticText_texture_mapping = nullptr;
|
||||
@@ -3440,7 +3440,9 @@ Sidebar::Sidebar(Plater *parent)
|
||||
spliter_texture_2->SetLineColour("#CECECE");
|
||||
scrolled_sizer->Add(spliter_texture_2, 0, wxEXPAND);
|
||||
|
||||
p->m_panel_texture_mapping_content = new wxPanel(p->scrolled, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
|
||||
p->m_panel_texture_mapping_content = new wxScrolledWindow(p->scrolled, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
|
||||
p->m_panel_texture_mapping_content->SetScrollRate(0, 5);
|
||||
p->m_panel_texture_mapping_content->ShowScrollbars(wxSHOW_SB_NEVER, wxSHOW_SB_DEFAULT);
|
||||
p->m_panel_texture_mapping_content->SetBackgroundColour(wxGetApp().dark_mode() ? wxColour(45, 45, 49) : wxColour(255, 255, 255));
|
||||
p->m_sizer_texture_mapping_content = new wxBoxSizer(wxVERTICAL);
|
||||
p->m_sizer_texture_mapping_content->AddSpacer(FromDIP(SidebarProps::ContentMargin()));
|
||||
@@ -5082,6 +5084,18 @@ void Sidebar::update_texture_mapping_panel(bool sync_manager)
|
||||
return;
|
||||
content_sizer->Clear(true);
|
||||
content_sizer->AddSpacer(FromDIP(SidebarProps::ContentMargin()));
|
||||
auto update_texture_mapping_area_height = [this]() {
|
||||
if (p->m_panel_texture_mapping_content == nullptr || p->m_panel_texture_mapping_content->GetSizer() == nullptr)
|
||||
return;
|
||||
const int max_height = FromDIP(260);
|
||||
p->m_panel_texture_mapping_content->SetMaxSize(wxSize(-1, max_height));
|
||||
p->m_panel_texture_mapping_content->Layout();
|
||||
p->m_panel_texture_mapping_content->FitInside();
|
||||
wxSize min_size = p->m_panel_texture_mapping_content->GetSizer()->GetMinSize();
|
||||
if (min_size.y > max_height)
|
||||
min_size.y = max_height;
|
||||
p->m_panel_texture_mapping_content->SetMinSize(wxSize(-1, std::max(FromDIP(1), min_size.y)));
|
||||
};
|
||||
|
||||
if (p->m_btn_add_texture_map != nullptr)
|
||||
p->m_btn_add_texture_map->Enable(num_physical >= 2);
|
||||
@@ -5122,7 +5136,7 @@ void Sidebar::update_texture_mapping_panel(bool sync_manager)
|
||||
empty_label->SetForegroundColour(summary_fg);
|
||||
empty_label->Wrap(FromDIP(360));
|
||||
content_sizer->Add(empty_label, 0, wxALL | wxEXPAND, FromDIP(12));
|
||||
p->m_panel_texture_mapping_content->Layout();
|
||||
update_texture_mapping_area_height();
|
||||
m_scrolled_sizer->Layout();
|
||||
Layout();
|
||||
return;
|
||||
@@ -5330,7 +5344,7 @@ void Sidebar::update_texture_mapping_panel(bool sync_manager)
|
||||
}
|
||||
evt.Skip();
|
||||
});
|
||||
auto update_pattern_visibility = [this, editor_sizer, mode_row, contrast_row, offset_btn, advanced_btn, surface_choice, row, editor]() {
|
||||
auto update_pattern_visibility = [this, editor_sizer, mode_row, contrast_row, offset_btn, advanced_btn, surface_choice, row, editor, update_texture_mapping_area_height]() {
|
||||
const bool image_texture = surface_choice == nullptr || surface_choice->GetSelection() == 0;
|
||||
editor_sizer->Show(mode_row, image_texture, true);
|
||||
editor_sizer->Show(contrast_row, image_texture, true);
|
||||
@@ -5340,7 +5354,7 @@ void Sidebar::update_texture_mapping_panel(bool sync_manager)
|
||||
advanced_btn->Show(image_texture);
|
||||
editor->Layout();
|
||||
row->Layout();
|
||||
p->m_panel_texture_mapping_content->Layout();
|
||||
update_texture_mapping_area_height();
|
||||
m_scrolled_sizer->Layout();
|
||||
Layout();
|
||||
};
|
||||
@@ -5480,7 +5494,7 @@ void Sidebar::update_texture_mapping_panel(bool sync_manager)
|
||||
update_texture_mapping_panel(false);
|
||||
});
|
||||
|
||||
auto toggle_editor = [this, zone_index, editor, row]() {
|
||||
auto toggle_editor = [this, zone_index, editor, row, update_texture_mapping_area_height]() {
|
||||
if (editor == nullptr)
|
||||
return;
|
||||
if (editor->IsShown()) {
|
||||
@@ -5491,7 +5505,7 @@ void Sidebar::update_texture_mapping_panel(bool sync_manager)
|
||||
p->m_expanded_texture_mapping_rows.insert(zone_index);
|
||||
}
|
||||
row->Layout();
|
||||
p->m_panel_texture_mapping_content->Layout();
|
||||
update_texture_mapping_area_height();
|
||||
m_scrolled_sizer->Layout();
|
||||
Layout();
|
||||
};
|
||||
@@ -5543,7 +5557,7 @@ void Sidebar::update_texture_mapping_panel(bool sync_manager)
|
||||
}
|
||||
|
||||
content_sizer->AddSpacer(FromDIP(2));
|
||||
p->m_panel_texture_mapping_content->Layout();
|
||||
update_texture_mapping_area_height();
|
||||
m_scrolled_sizer->Layout();
|
||||
Layout();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user