WIP: Plater
This commit is contained in:
parent
08c6905751
commit
9021bd07a3
5 changed files with 155 additions and 71 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include "GLToolbar.hpp"
|
#include "GLToolbar.hpp"
|
||||||
#include "callback.hpp"
|
#include "callback.hpp"
|
||||||
|
|
||||||
|
class wxWindow;
|
||||||
class wxTimer;
|
class wxTimer;
|
||||||
class wxSizeEvent;
|
class wxSizeEvent;
|
||||||
class wxIdleEvent;
|
class wxIdleEvent;
|
||||||
|
|
|
@ -827,6 +827,31 @@ void GLCanvas3DManager::register_action_selectbyparts_callback(wxGLCanvas* canva
|
||||||
it->second->register_action_selectbyparts_callback(callback);
|
it->second->register_action_selectbyparts_callback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GLCanvas3DManager::can_multisample()
|
||||||
|
{
|
||||||
|
int wxVersion = wxMAJOR_VERSION * 10000 + wxMINOR_VERSION * 100 + wxRELEASE_NUMBER;
|
||||||
|
const AppConfig* app_config = GUI::get_app_config();
|
||||||
|
bool enable_multisample = app_config != nullptr
|
||||||
|
&& app_config->get("use_legacy_opengl") != "1"
|
||||||
|
&& wxVersion >= 30003;
|
||||||
|
|
||||||
|
// if multisample is not enabled or supported by the graphic card, remove it from the attributes list
|
||||||
|
return enable_multisample && wxGLCanvas::IsExtensionSupported("WGL_ARB_multisample");
|
||||||
|
// <<< Alternative method: but IsDisplaySupported() seems not to work
|
||||||
|
// bool return enable_multisample && wxGLCanvas::IsDisplaySupported(attribList);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxGLCanvas* GLCanvas3DManager::create_wxglcanvas(wxWindow *parent)
|
||||||
|
{
|
||||||
|
int attribList[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 24, WX_GL_SAMPLE_BUFFERS, GL_TRUE, WX_GL_SAMPLES, 4, 0 };
|
||||||
|
|
||||||
|
if (! can_multisample()) {
|
||||||
|
attribList[4] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new wxGLCanvas(parent, wxID_ANY, attribList);
|
||||||
|
}
|
||||||
|
|
||||||
GLCanvas3DManager::CanvasesMap::iterator GLCanvas3DManager::_get_canvas(wxGLCanvas* canvas)
|
GLCanvas3DManager::CanvasesMap::iterator GLCanvas3DManager::_get_canvas(wxGLCanvas* canvas)
|
||||||
{
|
{
|
||||||
return (canvas == nullptr) ? m_canvases.end() : m_canvases.find(canvas);
|
return (canvas == nullptr) ? m_canvases.end() : m_canvases.find(canvas);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class wxWindow;
|
||||||
class wxGLCanvas;
|
class wxGLCanvas;
|
||||||
class wxGLContext;
|
class wxGLContext;
|
||||||
|
|
||||||
|
@ -186,6 +187,8 @@ public:
|
||||||
void register_action_layersediting_callback(wxGLCanvas* canvas, void* callback);
|
void register_action_layersediting_callback(wxGLCanvas* canvas, void* callback);
|
||||||
void register_action_selectbyparts_callback(wxGLCanvas* canvas, void* callback);
|
void register_action_selectbyparts_callback(wxGLCanvas* canvas, void* callback);
|
||||||
|
|
||||||
|
static bool can_multisample();
|
||||||
|
static wxGLCanvas* create_wxglcanvas(wxWindow *parent);
|
||||||
private:
|
private:
|
||||||
CanvasesMap::iterator _get_canvas(wxGLCanvas* canvas);
|
CanvasesMap::iterator _get_canvas(wxGLCanvas* canvas);
|
||||||
CanvasesMap::const_iterator _get_canvas(wxGLCanvas* canvas) const;
|
CanvasesMap::const_iterator _get_canvas(wxGLCanvas* canvas) const;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "GUI.hpp"
|
#include "GUI.hpp"
|
||||||
#include "AppConfig.hpp"
|
#include "AppConfig.hpp"
|
||||||
#include "3DScene.hpp"
|
#include "3DScene.hpp"
|
||||||
|
#include "GLCanvas3DManager.hpp"
|
||||||
#include "../../libslic3r/GCode/PreviewData.hpp"
|
#include "../../libslic3r/GCode/PreviewData.hpp"
|
||||||
#include "PresetBundle.hpp"
|
#include "PresetBundle.hpp"
|
||||||
|
|
||||||
|
@ -57,24 +58,26 @@ bool Preview::init(wxNotebook* notebook, DynamicPrintConfig* config, Print* prin
|
||||||
if (!Create(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize))
|
if (!Create(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int attribList[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 24, WX_GL_SAMPLE_BUFFERS, GL_TRUE, WX_GL_SAMPLES, 4, 0 };
|
// int attribList[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 24, WX_GL_SAMPLE_BUFFERS, GL_TRUE, WX_GL_SAMPLES, 4, 0 };
|
||||||
|
|
||||||
int wxVersion = wxMAJOR_VERSION * 10000 + wxMINOR_VERSION * 100 + wxRELEASE_NUMBER;
|
// int wxVersion = wxMAJOR_VERSION * 10000 + wxMINOR_VERSION * 100 + wxRELEASE_NUMBER;
|
||||||
const AppConfig* app_config = GUI::get_app_config();
|
// const AppConfig* app_config = GUI::get_app_config();
|
||||||
bool enable_multisample = (app_config != nullptr) && (app_config->get("use_legacy_opengl") != "1") && (wxVersion >= 30003);
|
// bool enable_multisample = (app_config != nullptr) && (app_config->get("use_legacy_opengl") != "1") && (wxVersion >= 30003);
|
||||||
|
|
||||||
// if multisample is not enabled or supported by the graphic card, remove it from the attributes list
|
// // if multisample is not enabled or supported by the graphic card, remove it from the attributes list
|
||||||
bool can_multisample = enable_multisample && wxGLCanvas::IsExtensionSupported("WGL_ARB_multisample");
|
// bool can_multisample = enable_multisample && wxGLCanvas::IsExtensionSupported("WGL_ARB_multisample");
|
||||||
// bool can_multisample = enable_multisample && wxGLCanvas::IsDisplaySupported(attribList); // <<< Alternative method: but IsDisplaySupported() seems not to work
|
// // bool can_multisample = enable_multisample && wxGLCanvas::IsDisplaySupported(attribList); // <<< Alternative method: but IsDisplaySupported() seems not to work
|
||||||
if (!can_multisample)
|
// if (!can_multisample)
|
||||||
attribList[4] = 0;
|
// attribList[4] = 0;
|
||||||
|
|
||||||
m_canvas = new wxGLCanvas(this, wxID_ANY, attribList);
|
// m_canvas = new wxGLCanvas(this, wxID_ANY, attribList);
|
||||||
if (m_canvas == nullptr)
|
// if (m_canvas == nullptr)
|
||||||
return false;
|
// return false;
|
||||||
|
|
||||||
|
m_canvas = GLCanvas3DManager::create_wxglcanvas(this);
|
||||||
|
|
||||||
_3DScene::add_canvas(m_canvas);
|
_3DScene::add_canvas(m_canvas);
|
||||||
_3DScene::allow_multisample(m_canvas, can_multisample);
|
_3DScene::allow_multisample(m_canvas, GLCanvas3DManager::can_multisample());
|
||||||
_3DScene::enable_shader(m_canvas, true);
|
_3DScene::enable_shader(m_canvas, true);
|
||||||
_3DScene::set_config(m_canvas, m_config);
|
_3DScene::set_config(m_canvas, m_config);
|
||||||
_3DScene::set_print(m_canvas, m_print);
|
_3DScene::set_print(m_canvas, m_print);
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <wx/filedlg.h>
|
#include <wx/filedlg.h>
|
||||||
#include <wx/dnd.h>
|
#include <wx/dnd.h>
|
||||||
#include <wx/progdlg.h>
|
#include <wx/progdlg.h>
|
||||||
|
#include <wx/wupdlock.h>
|
||||||
|
|
||||||
#include "libslic3r/PrintConfig.hpp"
|
#include "libslic3r/PrintConfig.hpp"
|
||||||
#include "libslic3r/Model.hpp"
|
#include "libslic3r/Model.hpp"
|
||||||
|
@ -25,11 +26,11 @@
|
||||||
#include "libslic3r/GCode/PreviewData.hpp"
|
#include "libslic3r/GCode/PreviewData.hpp"
|
||||||
#include "libslic3r/Utils.hpp"
|
#include "libslic3r/Utils.hpp"
|
||||||
#include "libslic3r/Polygon.hpp"
|
#include "libslic3r/Polygon.hpp"
|
||||||
// #include "libslic3r/BoundingBox.hpp"
|
|
||||||
#include "GUI.hpp"
|
#include "GUI.hpp"
|
||||||
#include "GUI_App.hpp"
|
#include "GUI_App.hpp"
|
||||||
#include "MainFrame.hpp"
|
#include "MainFrame.hpp"
|
||||||
#include "3DScene.hpp"
|
#include "3DScene.hpp"
|
||||||
|
#include "GUI_ObjectParts.hpp"
|
||||||
#include "GLToolbar.hpp"
|
#include "GLToolbar.hpp"
|
||||||
#include "GUI_Preview.hpp"
|
#include "GUI_Preview.hpp"
|
||||||
#include "Tab.hpp"
|
#include "Tab.hpp"
|
||||||
|
@ -422,8 +423,10 @@ struct Plater::priv
|
||||||
void update(bool force_autocenter = false);
|
void update(bool force_autocenter = false);
|
||||||
void update_ui_from_settings();
|
void update_ui_from_settings();
|
||||||
ProgressStatusBar* statusbar();
|
ProgressStatusBar* statusbar();
|
||||||
|
std::string get_config(const std::string &key) const;
|
||||||
|
BoundingBox bed_shape_bb() const;
|
||||||
std::vector<size_t> load_files(const std::vector<fs::path> &input_files);
|
std::vector<size_t> load_files(const std::vector<fs::path> &input_files);
|
||||||
size_t load_model_objects(const ModelObjectPtrs &model_objects);
|
std::vector<size_t> load_model_objects(const ModelObjectPtrs &model_objects);
|
||||||
|
|
||||||
void on_notebook_changed(wxBookCtrlEvent &);
|
void on_notebook_changed(wxBookCtrlEvent &);
|
||||||
void on_select_preset(wxCommandEvent &);
|
void on_select_preset(wxCommandEvent &);
|
||||||
|
@ -451,7 +454,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
|
||||||
})),
|
})),
|
||||||
notebook(new wxNotebook(q, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_BOTTOM)),
|
notebook(new wxNotebook(q, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_BOTTOM)),
|
||||||
sidebar(new Sidebar(q)),
|
sidebar(new Sidebar(q)),
|
||||||
canvas3D(new wxGLCanvas(notebook, wxID_ANY, gl_attrs))
|
canvas3D(GLCanvas3DManager::create_wxglcanvas(notebook))
|
||||||
{
|
{
|
||||||
background_process.set_print(&print);
|
background_process.set_print(&print);
|
||||||
background_process.set_gcode_preview_data(&gcode_preview_data);
|
background_process.set_gcode_preview_data(&gcode_preview_data);
|
||||||
|
@ -459,6 +462,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
|
||||||
background_process.set_finished_event(EVT_PROCESS_COMPLETED);
|
background_process.set_finished_event(EVT_PROCESS_COMPLETED);
|
||||||
|
|
||||||
_3DScene::add_canvas(canvas3D);
|
_3DScene::add_canvas(canvas3D);
|
||||||
|
_3DScene::allow_multisample(canvas3D, GLCanvas3DManager::can_multisample());
|
||||||
notebook->AddPage(canvas3D, _(L("3D")));
|
notebook->AddPage(canvas3D, _(L("3D")));
|
||||||
preview = new GUI::Preview(notebook, config, &print, &gcode_preview_data);
|
preview = new GUI::Preview(notebook, config, &print, &gcode_preview_data);
|
||||||
|
|
||||||
|
@ -466,11 +470,11 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
|
||||||
_3DScene::enable_picking(canvas3D, true);
|
_3DScene::enable_picking(canvas3D, true);
|
||||||
_3DScene::enable_moving(canvas3D, true);
|
_3DScene::enable_moving(canvas3D, true);
|
||||||
// XXX: more config from 3D.pm
|
// XXX: more config from 3D.pm
|
||||||
// Slic3r::GUI::_3DScene::set_select_by($self, 'object');
|
_3DScene::set_select_by(canvas3D, "object");
|
||||||
// Slic3r::GUI::_3DScene::set_drag_by($self, 'instance');
|
_3DScene::set_drag_by(canvas3D, "instance");
|
||||||
// Slic3r::GUI::_3DScene::set_model($self, $model);
|
_3DScene::set_model(canvas3D, &model);
|
||||||
// Slic3r::GUI::_3DScene::set_print($self, $print);
|
_3DScene::set_print(canvas3D, &print);
|
||||||
// Slic3r::GUI::_3DScene::set_config($self, $config);
|
_3DScene::set_config(canvas3D, config);
|
||||||
_3DScene::enable_gizmos(canvas3D, true);
|
_3DScene::enable_gizmos(canvas3D, true);
|
||||||
_3DScene::enable_toolbar(canvas3D, true);
|
_3DScene::enable_toolbar(canvas3D, true);
|
||||||
_3DScene::enable_shader(canvas3D, true);
|
_3DScene::enable_shader(canvas3D, true);
|
||||||
|
@ -527,6 +531,9 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
|
||||||
// Drop target:
|
// Drop target:
|
||||||
q->SetDropTarget(new PlaterDropTarget(q)); // if my understanding is right, wxWindow takes the owenership
|
q->SetDropTarget(new PlaterDropTarget(q)); // if my understanding is right, wxWindow takes the owenership
|
||||||
|
|
||||||
|
// Setting of global access pointers
|
||||||
|
// FIXME: We really should get rid of these once Perl code is gone...
|
||||||
|
set_objects_from_model(model);
|
||||||
// TODO: ?
|
// TODO: ?
|
||||||
// # Send sizers/buttons to C++
|
// # Send sizers/buttons to C++
|
||||||
// Slic3r::GUI::set_objects_from_perl( $self->{scrolled_window_panel},
|
// Slic3r::GUI::set_objects_from_perl( $self->{scrolled_window_panel},
|
||||||
|
@ -560,7 +567,26 @@ std::vector<int> Plater::priv::collect_selections()
|
||||||
|
|
||||||
void Plater::priv::update(bool force_autocenter)
|
void Plater::priv::update(bool force_autocenter)
|
||||||
{
|
{
|
||||||
// TODO
|
|
||||||
|
wxWindowUpdateLocker freeze_guard(q);
|
||||||
|
if (get_config("autocenter") == "1" || force_autocenter) {
|
||||||
|
// auto *bed_shape_opt = config->opt<ConfigOptionPoints>("bed_shape");
|
||||||
|
// const auto bed_shape = Slic3r::Polygon::new_scale(bed_shape_opt->values);
|
||||||
|
// const BoundingBox bed_shape_bb = bed_shape.bounding_box();
|
||||||
|
const Vec2d bed_center = bed_shape_bb().center().cast<double>();
|
||||||
|
model.center_instances_around_point(bed_center);
|
||||||
|
}
|
||||||
|
|
||||||
|
// stop_background_process(); // TODO
|
||||||
|
print.reload_model_instances();
|
||||||
|
|
||||||
|
const auto selections = collect_selections();
|
||||||
|
_3DScene::set_objects_selections(canvas3D, selections);
|
||||||
|
_3DScene::reload_scene(canvas3D, false);
|
||||||
|
preview->reset_gcode_preview_data();
|
||||||
|
preview->reload_print();
|
||||||
|
|
||||||
|
// schedule_background_process(); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plater::priv::update_ui_from_settings()
|
void Plater::priv::update_ui_from_settings()
|
||||||
|
@ -578,6 +604,18 @@ ProgressStatusBar* Plater::priv::statusbar()
|
||||||
return main_frame->m_statusbar;
|
return main_frame->m_statusbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Plater::priv::get_config(const std::string &key) const
|
||||||
|
{
|
||||||
|
return wxGetApp().app_config->get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
BoundingBox Plater::priv::bed_shape_bb() const
|
||||||
|
{
|
||||||
|
const auto *bed_shape_opt = config->opt<ConfigOptionPoints>("bed_shape");
|
||||||
|
const auto bed_shape = Slic3r::Polygon::new_scale(bed_shape_opt->values);
|
||||||
|
return bed_shape.bounding_box();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_files)
|
std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_files)
|
||||||
{
|
{
|
||||||
if (input_files.size() < 1) { return std::vector<size_t>(); }
|
if (input_files.size() < 1) { return std::vector<size_t>(); }
|
||||||
|
@ -599,7 +637,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_
|
||||||
dlg.Pulse();
|
dlg.Pulse();
|
||||||
|
|
||||||
auto *new_model = one_by_one ? nullptr : new Slic3r::Model();
|
auto *new_model = one_by_one ? nullptr : new Slic3r::Model();
|
||||||
std::vector<size_t> obj_idx; // XXX: ?
|
std::vector<size_t> obj_idxs;
|
||||||
|
|
||||||
for (size_t i = 0; i < input_files.size(); i++) {
|
for (size_t i = 0; i < input_files.size(); i++) {
|
||||||
const auto &path = input_files[i];
|
const auto &path = input_files[i];
|
||||||
|
@ -656,6 +694,8 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_
|
||||||
// TODO:
|
// TODO:
|
||||||
// push @obj_idx, $self->load_model_objects(@{$model->objects});
|
// push @obj_idx, $self->load_model_objects(@{$model->objects});
|
||||||
// obj_idx.push_back(load_model_objects(model.objects);
|
// obj_idx.push_back(load_model_objects(model.objects);
|
||||||
|
auto loaded_idxs = load_model_objects(model.objects);
|
||||||
|
obj_idxs.insert(obj_idxs.end(), loaded_idxs.begin(), loaded_idxs.end());
|
||||||
} else {
|
} else {
|
||||||
// This must be an .stl or .obj file, which may contain a maximum of one volume.
|
// This must be an .stl or .obj file, which may contain a maximum of one volume.
|
||||||
for (const ModelObject* model_object : model.objects) {
|
for (const ModelObject* model_object : model.objects) {
|
||||||
|
@ -677,54 +717,38 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_
|
||||||
// TODO:
|
// TODO:
|
||||||
// push @obj_idx, $self->load_model_objects(@{$new_model->objects});
|
// push @obj_idx, $self->load_model_objects(@{$new_model->objects});
|
||||||
// obj_idx.push_back(load_model_objects(new_model->objects);
|
// obj_idx.push_back(load_model_objects(new_model->objects);
|
||||||
|
auto loaded_idxs = load_model_objects(model.objects);
|
||||||
|
obj_idxs.insert(obj_idxs.end(), loaded_idxs.begin(), loaded_idxs.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGetApp().app_config->update_skein_dir(input_files[input_files.size() - 1].parent_path().string());
|
wxGetApp().app_config->update_skein_dir(input_files[input_files.size() - 1].parent_path().string());
|
||||||
// XXX: Plater.pm had @loaded_files, but didn't seem to fill them with the filenames...
|
// XXX: Plater.pm had @loaded_files, but didn't seem to fill them with the filenames...
|
||||||
statusbar()->set_status_text(_(L("Loaded")));
|
statusbar()->set_status_text(_(L("Loaded")));
|
||||||
return obj_idx;
|
return obj_idxs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: move to Point.hpp
|
// TODO: move to Point.hpp
|
||||||
// inline Vec3crd to_3d(const Vec2crd &pt2, coord_t z) { return Vec3crd(pt2(0), pt2(1), z); }
|
Vec3d to_3d(const Vec2d &v, double z) { return Vec3d(v(0), v(1), z); }
|
||||||
// inline Vec3i64 to_3d(const Vec2i64 &pt2, int64_t z) { return Vec3i64(pt2(0), pt2(1), z); }
|
Vec3f to_3d(const Vec2f &v, float z) { return Vec3f(v(0), v(1), z); }
|
||||||
// inline Vec3f to_3d(const Vec2f &pt2, float z) { return Vec3f (pt2(0), pt2(1), z); }
|
Vec3i64 to_3d(const Vec2i64 &v, float z) { return Vec3i64(v(0), v(1), z); }
|
||||||
// inline Vec3d to_3d(const Vec2d &pt2, double z) { return Vec3d (pt2(0), pt2(1), z); }
|
Vec3crd to_3d(const Point &p, coord_t z) { return Vec3crd(p(0), p(1), z); }
|
||||||
// typedef Eigen::Matrix<coord_t, 2, 1, Eigen::DontAlign> Vec2crd;
|
|
||||||
template<class T> Eigen::Matrix<T, 3, 1, Eigen::DontAlign> to_3d(const Eigen::Matrix<T, 2, 1, Eigen::DontAlign> &m, T z)
|
|
||||||
{
|
|
||||||
return Eigen::Matrix<T, 3, 1, Eigen::DontAlign>(m(0), m(1), z);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3crd to_3d(const Point &p, coord_t z)
|
std::vector<size_t> Plater::priv::load_model_objects(const ModelObjectPtrs &model_objects)
|
||||||
{
|
{
|
||||||
return Vec3crd(p(0), p(1), z);
|
const BoundingBox bed_shape = bed_shape_bb();
|
||||||
}
|
const Vec3d bed_center = to_3d(bed_shape.center().cast<double>(), 0.0);
|
||||||
|
const Vec3d bed_size = to_3d(bed_shape.size().cast<double>(), 1.0);
|
||||||
size_t Plater::priv::load_model_objects(const ModelObjectPtrs &model_objects)
|
|
||||||
{
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
auto *bed_shape_opt = config->opt<ConfigOptionPoints>("bed_shape");
|
|
||||||
const auto bed_shape = Slic3r::Polygon::new_scale(bed_shape_opt->values);
|
|
||||||
const BoundingBox bed_shape_bb = bed_shape.bounding_box();
|
|
||||||
// const Point bed_center_2 = bed_shape_bb.center();
|
|
||||||
// const Vec3d bed_center(bed_center_2(0), bed_center_2(1), 0.0);
|
|
||||||
// const Vec3d bed_center = to_3d(bed_shape_bb.center(), 0).cast<double>();
|
|
||||||
const Vec3d bed_center = to_3d<double>(bed_shape_bb.center().cast<double>(), 0.0);
|
|
||||||
const Vec2d bed_size = bed_shape_bb.size().cast<double>();
|
|
||||||
|
|
||||||
bool need_arrange = false;
|
bool need_arrange = false;
|
||||||
bool scaled_down = false;
|
bool scaled_down = false;
|
||||||
// my @obj_idx = (); // XXX
|
std::vector<size_t> obj_idxs;
|
||||||
std::vector<size_t> obj_idx;
|
|
||||||
|
|
||||||
for (const ModelObject *model_object : model_objects) {
|
for (ModelObject *model_object : model_objects) {
|
||||||
auto *object = model.add_object(*model_object);
|
auto *object = model.add_object(*model_object);
|
||||||
std::string object_name = object->name.empty() ? fs::path(object->input_file).filename().string() : object->name;
|
std::string object_name = object->name.empty() ? fs::path(object->input_file).filename().string() : object->name;
|
||||||
objects.emplace_back(std::move(object_name));
|
objects.emplace_back(std::move(object_name));
|
||||||
obj_idx.push_back(objects.size() - 1);
|
obj_idxs.push_back(objects.size() - 1);
|
||||||
|
|
||||||
if (model_object->instances.size() == 0) {
|
if (model_object->instances.size() == 0) {
|
||||||
// if object has no defined position(s) we need to rearrange everything after loading
|
// if object has no defined position(s) we need to rearrange everything after loading
|
||||||
|
@ -736,26 +760,54 @@ size_t Plater::priv::load_model_objects(const ModelObjectPtrs &model_objects)
|
||||||
instance->set_offset(bed_center);
|
instance->set_offset(bed_center);
|
||||||
}
|
}
|
||||||
|
|
||||||
// my $size = $o->bounding_box->size;
|
const Vec3d size = object->bounding_box().size();
|
||||||
// const auto size = object->bounding_box().size();
|
const Vec3d ratio = size.cwiseQuotient(bed_size);
|
||||||
// my $ratio = max($size->x / unscale($bed_size->x), $size->y / unscale($bed_size->y));
|
const double max_ratio = std::max(ratio(0), ratio(1));
|
||||||
// size.cwiseQuotient(bed_size);
|
if (max_ratio > 10000) {
|
||||||
// const auto = size / bed_size;
|
// the size of the object is too big -> this could lead to overflow when moving to clipper coordinates,
|
||||||
// const auto ratio = std::max(size.x / Slic3r::unscale(bed_size(0)), size.y / Slic3r::unscale(bed_size(1)));
|
// so scale down the mesh
|
||||||
// if ($ratio > 10000) {
|
// const Vec3d inverse = ratio.cwiseInverse();
|
||||||
// # the size of the object is too big -> this could lead to overflow when moving to clipper coordinates,
|
// object->scale(inverse);
|
||||||
// # so scale down the mesh
|
object->scale(ratio.cwiseInverse());
|
||||||
// $o->scale_xyz(Slic3r::Pointf3->new(1/$ratio, 1/$ratio, 1/$ratio));
|
scaled_down = true;
|
||||||
// $scaled_down = 1;
|
} else if (max_ratio > 5) {
|
||||||
// }
|
const Vec3d inverse = ratio.cwiseInverse();
|
||||||
// elsif ($ratio > 5) {
|
for (ModelInstance *instance : model_object->instances) {
|
||||||
// $_->set_scaling_factor(1/$ratio) for @{$o->instances};
|
instance->set_scaling_factor(inverse);
|
||||||
// $scaled_down = 1;
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw 0;
|
// if user turned autocentering off, automatic arranging would disappoint them
|
||||||
return 0;
|
if (get_config("autocenter") != "1") {
|
||||||
|
need_arrange = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scaled_down) {
|
||||||
|
GUI::show_info(q,
|
||||||
|
_(L("Your object appears to be too large, so it was automatically scaled down to fit your print bed.")),
|
||||||
|
_(L("Object too large?")));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const size_t idx : obj_idxs) {
|
||||||
|
const PlaterObject &object = objects[idx];
|
||||||
|
ModelObject *model_object = model.objects[idx];
|
||||||
|
|
||||||
|
// FIXME: ObjetParts not initialized (via add_frequently_changed_parameters)
|
||||||
|
// GUI::add_object_to_list(object.name, model_object);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (need_arrange) {
|
||||||
|
// arrange(); // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
_3DScene::zoom_to_volumes(canvas3D);
|
||||||
|
// TODO
|
||||||
|
// $self->object_list_changed;
|
||||||
|
// $self->schedule_background_process;
|
||||||
|
|
||||||
|
return obj_idxs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plater::priv::on_notebook_changed(wxBookCtrlEvent&)
|
void Plater::priv::on_notebook_changed(wxBookCtrlEvent&)
|
||||||
|
|
Loading…
Add table
Reference in a new issue