diff --git a/src/BambuStudio.cpp b/src/BambuStudio.cpp index 852394c60..69c16175d 100644 --- a/src/BambuStudio.cpp +++ b/src/BambuStudio.cpp @@ -4969,7 +4969,7 @@ int CLI::run(int argc, char **argv) // continue; for (int instance_idx = 0; instance_idx < (int)model_object.instances.size(); ++ instance_idx) { const ModelInstance &model_instance = *model_object.instances[instance_idx]; - glvolume_collection.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, "volume", true, false, true); + glvolume_collection.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, "volume", true, false, true, false); //glvolume_collection.volumes.back()->geometry_id = key.geometry_id; std::string color = filament_color?filament_color->get_at(volume_extruder_id - 1):"#00FF00FF"; @@ -5843,7 +5843,7 @@ int CLI::run(int argc, char **argv) // continue; for (int instance_idx = 0; instance_idx < (int)model_object.instances.size(); ++ instance_idx) { const ModelInstance &model_instance = *model_object.instances[instance_idx]; - glvolume_collection.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, "volume", true, false, true); + glvolume_collection.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, "volume", true, false, true, false); //glvolume_collection.volumes.back()->geometry_id = key.geometry_id; std::string color = filament_color?filament_color->get_at(volume_extruder_id - 1):"#00FF00FF"; diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index f355ecaad..d17f586b0 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -632,10 +632,6 @@ bool GLVolume::simplify_mesh(const TriangleMesh &mesh, GLIndexedVertexArray &va, bool GLVolume::simplify_mesh(const indexed_triangle_set &_its, GLIndexedVertexArray &va, LOD_LEVEL lod) const { if (_its.indices.size() == 0 || _its.vertices.size() == 0) { return false; } - bool enable_lod = GUI::wxGetApp().app_config->get("enable_lod") == "true"; - if (!enable_lod) { - return false; - } auto its = std::make_unique(_its); auto m_state = std::make_unique(); if (lod == LOD_LEVEL::MIDDLE) { @@ -1244,12 +1240,13 @@ std::vector GLVolumeCollection::load_object( int obj_idx, const std::vector &instance_idxs, const std::string &color_by, - bool opengl_initialized) + bool opengl_initialized, + bool lod_enabled) { std::vector volumes_idx; for (int volume_idx = 0; volume_idx < int(model_object->volumes.size()); ++volume_idx) for (int instance_idx : instance_idxs) - volumes_idx.emplace_back(this->GLVolumeCollection::load_object_volume(model_object, obj_idx, volume_idx, instance_idx, color_by, opengl_initialized)); + volumes_idx.emplace_back(this->GLVolumeCollection::load_object_volume(model_object, obj_idx, volume_idx, instance_idx, color_by, opengl_initialized, false, lod_enabled)); return volumes_idx; } @@ -1261,7 +1258,8 @@ int GLVolumeCollection::load_object_volume( const std::string &color_by, bool opengl_initialized, bool in_assemble_view, - bool use_loaded_id) + bool use_loaded_id, + bool lod_enabled) { const ModelVolume *model_volume = model_object->volumes[volume_idx]; const int extruder_id = model_volume->extruder_id(); @@ -1306,10 +1304,21 @@ int GLVolumeCollection::load_object_volume( #if ENABLE_SMOOTH_NORMALS v.indexed_vertex_array->load_mesh(mesh, true); #else - if (v.indexed_vertex_array_middle == nullptr) { v.indexed_vertex_array_middle = std::make_shared(); } - v.simplify_mesh(mesh, *v.indexed_vertex_array_middle, LOD_LEVEL::MIDDLE); // include finalize_geometry - if (v.indexed_vertex_array_small == nullptr) { v.indexed_vertex_array_small = std::make_shared(); } - v.simplify_mesh(mesh, *v.indexed_vertex_array_small, LOD_LEVEL::SMALL); + if (lod_enabled) { + if (v.indexed_vertex_array_middle == nullptr) + { + v.indexed_vertex_array_middle = std::make_shared(); + } + + v.simplify_mesh(mesh, *v.indexed_vertex_array_middle, LOD_LEVEL::MIDDLE); // include finalize_geometry + + if (v.indexed_vertex_array_small == nullptr) + { + v.indexed_vertex_array_small = std::make_shared(); + } + v.simplify_mesh(mesh, *v.indexed_vertex_array_small, LOD_LEVEL::SMALL); + } + v.indexed_vertex_array->load_mesh(mesh); #endif // ENABLE_SMOOTH_NORMALS v.indexed_vertex_array->finalize_geometry(opengl_initialized); diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index 500240e9e..2be906094 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -673,7 +673,8 @@ public: int obj_idx, const std::vector &instance_idxs, const std::string &color_by, - bool opengl_initialized); + bool opengl_initialized, + bool lod_enabled); int load_object_volume( const ModelObject *model_object, @@ -683,7 +684,8 @@ public: const std::string &color_by, bool opengl_initialized, bool in_assemble_view = false, - bool use_loaded_id = false); + bool use_loaded_id = false, + bool lod_enabled = true); // Load SLA auxiliary GLVolumes (for support trees or pad). void load_object_auxiliary( diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 0d5b357a2..d2af27d5e 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -3167,6 +3167,7 @@ void GCodeViewer::load_shells(const Print& print, bool initialized, bool force_p // BBS: fix the issue that object_idx is not assigned as index of Model.objects array int object_count = 0; const ModelObjectPtrs& model_objs = wxGetApp().model().objects; + bool enable_lod = GUI::wxGetApp().app_config->get("enable_lod") == "true"; for (const PrintObject* obj : print.objects()) { const ModelObject* model_obj = obj->model_object(); @@ -3193,7 +3194,7 @@ void GCodeViewer::load_shells(const Print& print, bool initialized, bool force_p instance_ids.resize(instance_index); size_t current_volumes_count = m_shells.volumes.volumes.size(); - m_shells.volumes.load_object(model_obj, object_idx, instance_ids, "object", initialized); + m_shells.volumes.load_object(model_obj, object_idx, instance_ids, "object", initialized, enable_lod); // adjust shells' z if raft is present const SlicingParameters& slicing_parameters = obj->slicing_parameters(); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 9c72ec4c6..fa99e7a06 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2253,22 +2253,22 @@ void GLCanvas3D::set_volumes_z_range(const std::array& range) m_volumes.set_range(range[0] - 1e-6, range[1] + 1e-6); } -std::vector GLCanvas3D::load_object(const ModelObject& model_object, int obj_idx, std::vector instance_idxs) +std::vector GLCanvas3D::load_object(const ModelObject& model_object, int obj_idx, std::vector instance_idxs, bool lod_enabled) { if (instance_idxs.empty()) { for (unsigned int i = 0; i < model_object.instances.size(); ++i) { instance_idxs.emplace_back(i); } } - return m_volumes.load_object(&model_object, obj_idx, instance_idxs, m_color_by, m_initialized); + return m_volumes.load_object(&model_object, obj_idx, instance_idxs, m_color_by, m_initialized, lod_enabled); } -std::vector GLCanvas3D::load_object(const Model& model, int obj_idx) +std::vector GLCanvas3D::load_object(const Model& model, int obj_idx, bool lod_enabled) { if (0 <= obj_idx && obj_idx < (int)model.objects.size()) { const ModelObject* model_object = model.objects[obj_idx]; if (model_object != nullptr) - return load_object(*model_object, obj_idx, std::vector()); + return load_object(*model_object, obj_idx, std::vector(), lod_enabled); } return std::vector(); @@ -2556,6 +2556,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re } } m_volumes.volumes = std::move(glvolumes_new); + bool enable_lod = GUI::wxGetApp().app_config->get("enable_lod") == "true"; for (unsigned int obj_idx = 0; obj_idx < (unsigned int)m_model->objects.size(); ++ obj_idx) { const ModelObject &model_object = *m_model->objects[obj_idx]; for (int volume_idx = 0; volume_idx < (int)model_object.volumes.size(); ++ volume_idx) { @@ -2576,7 +2577,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re // Note the index of the loaded volume, so that we can reload the main model GLVolume with the hollowed mesh // later in this function. it->volume_idx = m_volumes.volumes.size(); - m_volumes.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, m_color_by, m_initialized, m_canvas_type == ECanvasType::CanvasAssembleView); + m_volumes.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, m_color_by, m_initialized, m_canvas_type == ECanvasType::CanvasAssembleView, false, enable_lod); m_volumes.volumes.back()->geometry_id = key.geometry_id; update_object_list = true; } else { diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 2b0095998..7d3ff743a 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -911,8 +911,8 @@ public: std::vector& get_custom_gcode_per_print_z() { return m_gcode_viewer.get_custom_gcode_per_print_z(); } size_t get_gcode_extruders_count() { return m_gcode_viewer.get_extruders_count(); } - std::vector load_object(const ModelObject& model_object, int obj_idx, std::vector instance_idxs); - std::vector load_object(const Model& model, int obj_idx); + std::vector load_object(const ModelObject& model_object, int obj_idx, std::vector instance_idxs, bool lod_enabled); + std::vector load_object(const Model& model, int obj_idx, bool lod_enabled); void mirror_selection(Axis axis); diff --git a/src/slic3r/Utils/CalibUtils.cpp b/src/slic3r/Utils/CalibUtils.cpp index fc985368c..98243d4f0 100644 --- a/src/slic3r/Utils/CalibUtils.cpp +++ b/src/slic3r/Utils/CalibUtils.cpp @@ -1125,7 +1125,7 @@ bool CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &f const ModelVolume &model_volume = *model_object.volumes[volume_idx]; for (int instance_idx = 0; instance_idx < (int)model_object.instances.size(); ++ instance_idx) { const ModelInstance &model_instance = *model_object.instances[instance_idx]; - glvolume_collection.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, "volume", true, false, true); + glvolume_collection.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, "volume", true, false, true, false); glvolume_collection.volumes.back()->set_render_color( new_color[0], new_color[1], new_color[2], new_color[3]); glvolume_collection.volumes.back()->set_color(new_color); //glvolume_collection.volumes.back()->printable = model_instance.printable;