mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-03 20:13:59 -06:00
Merge branch 'tm_rotfinder'
This commit is contained in:
commit
7766c6ebc4
15 changed files with 929 additions and 293 deletions
|
@ -1,9 +1,15 @@
|
|||
// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro.
|
||||
#include "GLGizmoRotate.hpp"
|
||||
#include "slic3r/GUI/GLCanvas3D.hpp"
|
||||
#include "slic3r/GUI/ImGuiWrapper.hpp"
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/GUI/GUI.hpp"
|
||||
#include "libslic3r/PresetBundle.hpp"
|
||||
|
||||
#include "libslic3r/SLA/Rotfinder.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
@ -194,6 +200,64 @@ void GLGizmoRotate::on_render_for_picking() const
|
|||
glsafe(::glPopMatrix());
|
||||
}
|
||||
|
||||
|
||||
|
||||
GLGizmoRotate3D::RotoptimzeWindow::RotoptimzeWindow(ImGuiWrapper * imgui,
|
||||
State & state,
|
||||
const Alignment &alignment)
|
||||
: m_imgui{imgui}
|
||||
{
|
||||
imgui->begin(_L("Rotation"), ImGuiWindowFlags_NoMove |
|
||||
ImGuiWindowFlags_AlwaysAutoResize |
|
||||
ImGuiWindowFlags_NoCollapse);
|
||||
|
||||
// adjust window position to avoid overlap the view toolbar
|
||||
float win_h = ImGui::GetWindowHeight();
|
||||
float x = alignment.x, y = alignment.y;
|
||||
y = std::min(y, alignment.bottom_limit - win_h);
|
||||
ImGui::SetWindowPos(ImVec2(x, y), ImGuiCond_Always);
|
||||
|
||||
static constexpr const char * button_txt = L("Optimize orientation");
|
||||
static constexpr const char * slider_txt = L("Accuracy");
|
||||
|
||||
float button_width = imgui->calc_text_size(_(button_txt)).x;
|
||||
ImGui::PushItemWidth(100.);
|
||||
//if (imgui->button(_(button_txt))) {
|
||||
if (ImGui::ArrowButton(_(button_txt).c_str(), ImGuiDir_Down)){
|
||||
std::cout << "Blip" << std::endl;
|
||||
}
|
||||
|
||||
ImGui::SliderFloat(_(slider_txt).c_str(), &state.accuracy, 0.01f, 1.f, "%.1f");
|
||||
|
||||
static const std::vector<std::string> options = {
|
||||
_L("Least supports").ToStdString(),
|
||||
_L("Suface quality").ToStdString()
|
||||
};
|
||||
|
||||
// if (imgui->combo(_L("Choose method"), options, state.method) ) {
|
||||
// std::cout << "method: " << state.method << std::endl;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
GLGizmoRotate3D::RotoptimzeWindow::~RotoptimzeWindow()
|
||||
{
|
||||
m_imgui->end();
|
||||
}
|
||||
|
||||
void GLGizmoRotate3D::on_render_input_window(float x, float y, float bottom_limit)
|
||||
{
|
||||
if (wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptSLA)
|
||||
return;
|
||||
|
||||
// TODO:
|
||||
|
||||
// m_rotoptimizewin_state.mobj = ?;
|
||||
// RotoptimzeWindow popup{m_imgui, m_rotoptimizewin_state, {x, y, bottom_limit}};
|
||||
|
||||
}
|
||||
|
||||
void GLGizmoRotate::render_circle() const
|
||||
{
|
||||
::glBegin(GL_LINE_LOOP);
|
||||
|
|
|
@ -52,12 +52,12 @@ public:
|
|||
std::string get_tooltip() const override;
|
||||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual std::string on_get_name() const { return ""; }
|
||||
virtual void on_start_dragging();
|
||||
virtual void on_update(const UpdateData& data);
|
||||
virtual void on_render() const;
|
||||
virtual void on_render_for_picking() const;
|
||||
bool on_init() override;
|
||||
std::string on_get_name() const override { return ""; }
|
||||
void on_start_dragging() override;
|
||||
void on_update(const UpdateData& data) override;
|
||||
void on_render() const override;
|
||||
void on_render_for_picking() const override;
|
||||
|
||||
private:
|
||||
void render_circle() const;
|
||||
|
@ -94,46 +94,79 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual std::string on_get_name() const;
|
||||
virtual void on_set_state()
|
||||
bool on_init() override;
|
||||
std::string on_get_name() const override;
|
||||
void on_set_state() override
|
||||
{
|
||||
for (GLGizmoRotate& g : m_gizmos)
|
||||
g.set_state(m_state);
|
||||
}
|
||||
virtual void on_set_hover_id()
|
||||
void on_set_hover_id() override
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
m_gizmos[i].set_hover_id((m_hover_id == i) ? 0 : -1);
|
||||
}
|
||||
virtual void on_enable_grabber(unsigned int id)
|
||||
void on_enable_grabber(unsigned int id) override
|
||||
{
|
||||
if (id < 3)
|
||||
m_gizmos[id].enable_grabber(0);
|
||||
}
|
||||
virtual void on_disable_grabber(unsigned int id)
|
||||
void on_disable_grabber(unsigned int id) override
|
||||
{
|
||||
if (id < 3)
|
||||
m_gizmos[id].disable_grabber(0);
|
||||
}
|
||||
virtual bool on_is_activable() const;
|
||||
virtual void on_start_dragging();
|
||||
virtual void on_stop_dragging();
|
||||
virtual void on_update(const UpdateData& data)
|
||||
bool on_is_activable() const override;
|
||||
void on_start_dragging() override;
|
||||
void on_stop_dragging() override;
|
||||
void on_update(const UpdateData& data) override
|
||||
{
|
||||
for (GLGizmoRotate& g : m_gizmos)
|
||||
{
|
||||
g.update(data);
|
||||
}
|
||||
}
|
||||
virtual void on_render() const;
|
||||
virtual void on_render_for_picking() const
|
||||
void on_render() const override;
|
||||
void on_render_for_picking() const override
|
||||
{
|
||||
for (const GLGizmoRotate& g : m_gizmos)
|
||||
{
|
||||
g.render_for_picking();
|
||||
}
|
||||
}
|
||||
|
||||
void on_render_input_window(float x, float y, float bottom_limit) override;
|
||||
|
||||
private:
|
||||
|
||||
class RotoptimzeWindow {
|
||||
ImGuiWrapper *m_imgui = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
struct State {
|
||||
enum Metods { mMinSupportPoints, mLegacy };
|
||||
|
||||
float accuracy = 1.f;
|
||||
int method = mMinSupportPoints;
|
||||
ModelObject *mobj = nullptr;
|
||||
};
|
||||
|
||||
struct Alignment { float x, y, bottom_limit; };
|
||||
|
||||
RotoptimzeWindow(ImGuiWrapper * imgui,
|
||||
State & state,
|
||||
const Alignment &bottom_limit);
|
||||
|
||||
~RotoptimzeWindow();
|
||||
|
||||
RotoptimzeWindow(const RotoptimzeWindow&) = delete;
|
||||
RotoptimzeWindow(RotoptimzeWindow &&) = delete;
|
||||
RotoptimzeWindow& operator=(const RotoptimzeWindow &) = delete;
|
||||
RotoptimzeWindow& operator=(RotoptimzeWindow &&) = delete;
|
||||
};
|
||||
|
||||
RotoptimzeWindow::State m_rotoptimizewin_state = {};
|
||||
};
|
||||
|
||||
} // namespace GUI
|
||||
|
|
|
@ -425,10 +425,10 @@ bool ImGuiWrapper::combo(const wxString& label, const std::vector<std::string>&
|
|||
text(label);
|
||||
ImGui::SameLine();
|
||||
|
||||
int selection_out = -1;
|
||||
int selection_out = selection;
|
||||
bool res = false;
|
||||
|
||||
const char *selection_str = selection < (int)options.size() ? options[selection].c_str() : "";
|
||||
const char *selection_str = selection < int(options.size()) && selection >= 0 ? options[selection].c_str() : "";
|
||||
if (ImGui::BeginCombo("", selection_str)) {
|
||||
for (int i = 0; i < (int)options.size(); i++) {
|
||||
if (ImGui::Selectable(options[i].c_str(), i == selection)) {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "libslic3r/SLA/Rotfinder.hpp"
|
||||
#include "libslic3r/MinAreaBoundingBox.hpp"
|
||||
#include "libslic3r/Model.hpp"
|
||||
#include "libslic3r/SLAPrint.hpp"
|
||||
|
||||
#include "slic3r/GUI/Plater.hpp"
|
||||
|
||||
|
@ -12,26 +13,41 @@ namespace Slic3r { namespace GUI {
|
|||
void RotoptimizeJob::process()
|
||||
{
|
||||
int obj_idx = m_plater->get_selected_object_idx();
|
||||
if (obj_idx < 0) { return; }
|
||||
if (obj_idx < 0 || int(m_plater->sla_print().objects().size()) <= obj_idx)
|
||||
return;
|
||||
|
||||
ModelObject *o = m_plater->model().objects[size_t(obj_idx)];
|
||||
const SLAPrintObject *po = m_plater->sla_print().objects()[size_t(obj_idx)];
|
||||
|
||||
auto r = sla::find_best_rotation(
|
||||
*o,
|
||||
.005f,
|
||||
if (!o || !po) return;
|
||||
|
||||
TriangleMesh mesh = o->raw_mesh();
|
||||
mesh.require_shared_vertices();
|
||||
|
||||
// for (auto inst : o->instances) {
|
||||
// Transform3d tr = Transform3d::Identity();
|
||||
// tr.rotate(Eigen::AngleAxisd(inst->get_rotation(Z), Vec3d::UnitZ()));
|
||||
// tr.rotate(Eigen::AngleAxisd(inst->get_rotation(Y), Vec3d::UnitY()));
|
||||
// tr.rotate(Eigen::AngleAxisd(inst->get_rotation(X), Vec3d::UnitX()));
|
||||
|
||||
// double score = sla::get_model_supportedness(*po, tr);
|
||||
|
||||
// std::cout << "Model supportedness before: " << score << std::endl;
|
||||
// }
|
||||
|
||||
Vec2d r = sla::find_best_rotation(*po, 0.75f,
|
||||
[this](unsigned s) {
|
||||
if (s < 100)
|
||||
update_status(int(s),
|
||||
_(L("Searching for optimal orientation")));
|
||||
update_status(int(s), _(L("Searching for optimal orientation")));
|
||||
},
|
||||
[this]() { return was_canceled(); });
|
||||
[this] () { return was_canceled(); });
|
||||
|
||||
|
||||
double mindist = 6.0; // FIXME
|
||||
|
||||
if (!was_canceled()) {
|
||||
for(ModelInstance * oi : o->instances) {
|
||||
oi->set_rotation({r[X], r[Y], r[Z]});
|
||||
oi->set_rotation({r[X], r[Y], 0.});
|
||||
|
||||
auto trmatrix = oi->get_transformation().get_matrix();
|
||||
Polygon trchull = o->convex_hull_2d(trmatrix);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue