Skip to content

Commit

Permalink
Merge branch 'ms_multiple_beds_autoslice'
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmatena committed Dec 13, 2024
2 parents da10a4f + 3896ddc commit 3db367b
Show file tree
Hide file tree
Showing 16 changed files with 666 additions and 231 deletions.
1 change: 1 addition & 0 deletions bundled_deps/imgui/imgui/imconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ namespace ImGui
const wchar_t PrintIdle = 0x2812;
const wchar_t PrintRunning = 0x2813;
const wchar_t PrintFinished = 0x2814;
const wchar_t WarningMarkerDisabled = 0x2815;
// void MyFunction(const char* name, const MyMatrix44& v);
}

70 changes: 70 additions & 0 deletions resources/icons/notification_warning_grey.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/numbers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/libslic3r/MultipleBeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ MultipleBeds s_multiple_beds;
bool s_reload_preview_after_switching_beds = false;
bool s_beds_just_switched = false;

bool is_sliceable(const PrintStatus status) {
if (status == PrintStatus::empty) {
return false;
}
if (status == PrintStatus::invalid) {
return false;
}
if (status == PrintStatus::outside) {
return false;
}
return true;
}

namespace BedsGrid {
Index grid_coords_abs2index(GridCoords coords) {
coords = {std::abs(coords.x()), std::abs(coords.y())};
Expand Down
14 changes: 14 additions & 0 deletions src/libslic3r/MultipleBeds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ inline std::vector<unsigned> s_bed_selector_thumbnail_texture_ids;
inline std::array<bool, MAX_NUMBER_OF_BEDS> s_bed_selector_thumbnail_changed;
inline bool bed_selector_updated{false};

enum class PrintStatus {
idle,
running,
finished,
outside,
invalid,
empty,
toolpath_outside
};

bool is_sliceable(const PrintStatus status);

inline std::array<PrintStatus, MAX_NUMBER_OF_BEDS> s_print_statuses;

class MultipleBeds {
public:
MultipleBeds() = default;
Expand Down
53 changes: 53 additions & 0 deletions src/slic3r/GUI/3DBed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,58 @@ void Bed3D::render(GLCanvas3D& canvas, const Transform3d& view_matrix, const Tra
mat.translate(s_multiple_beds.get_bed_translation(i));
render_internal(canvas, mat, projection_matrix, bottom, scale_factor, show_texture, false, is_thumbnail || i == bed_to_highlight);
}

if (m_digits_models.empty()) {
for (size_t i = 0; i < 10; ++i) {
GLModel::Geometry g;
g.format.vertex_layout = GLModel::Geometry::EVertexLayout::P3T2;
const double digit_part = 94./1024.;
g.add_vertex(Vec3f(0, 0, 0), Vec2f(digit_part * i, 1.));
g.add_vertex(Vec3f(1, 0, 0), Vec2f(digit_part * (i+1), 1.));
g.add_vertex(Vec3f(1, 1, 0), Vec2f(digit_part * (i+1), 0));
g.add_vertex(Vec3f(0, 1, 0), Vec2f(digit_part * i, 0));
g.add_triangle(0, 1, 3);
g.add_triangle(3, 1, 2);
m_digits_models.emplace_back(std::make_unique<GLModel>());
m_digits_models.back()->init_from(std::move(g));
m_digits_models.back()->set_color(ColorRGBA(0.5f, 0.5f, 0.5f, 0.5f));
}
m_digits_texture = std::make_unique<GLTexture>();
m_digits_texture->load_from_file(resources_dir() + "/icons/numbers.png", true, GLTexture::ECompressionType::None, false);
m_digits_texture->send_compressed_data_to_gpu();
}
if (!is_thumbnail && s_multiple_beds.get_number_of_beds() > 1) {
GLShaderProgram* shader = wxGetApp().get_shader("flat_texture");
shader->start_using();
shader->set_uniform("projection_matrix", projection_matrix);
glsafe(::glEnable(GL_BLEND));
glsafe(::glEnable(GL_DEPTH_TEST));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
glsafe(::glBindTexture(GL_TEXTURE_2D, m_digits_texture->get_id()));

const BoundingBoxf bb = this->build_volume().bounding_volume2d();

for (int i : beds_to_render) {
if (i + 1 >= m_digits_models.size())
break;

double size_x = std::max(10., std::min(bb.size().x(), bb.size().y()) * 0.11);
double aspect = 1.2;
Transform3d mat = view_matrix;
mat.translate(Vec3d(bb.min.x(), bb.min.y(), 0.));
mat.translate(s_multiple_beds.get_bed_translation(i));
if (build_volume().type() != BuildVolume::Type::Circle)
mat.translate(Vec3d(0.3 * size_x, 0.3 * size_x, 0.));
mat.translate(Vec3d(0., 0., 0.5));
mat.scale(Vec3d(size_x, size_x * aspect, 1.));

shader->set_uniform("view_model_matrix", mat);
m_digits_models[i + 1]->render();
}
glsafe(::glBindTexture(GL_TEXTURE_2D, 0));
glsafe(::glDisable(GL_DEPTH_TEST));
shader->stop_using();
}
}

void Bed3D::render_for_picking(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor)
Expand Down Expand Up @@ -421,6 +473,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas, const Transform3d& v
else if (m_texture.unsent_compressed_data_available()) {
// sends to gpu the already available compressed levels of the main texture
m_texture.send_compressed_data_to_gpu();
wxQueueEvent(wxGetApp().plater(), new SimpleEvent(EVT_REGENERATE_BED_THUMBNAILS));

// the temporary texture is not needed anymore, reset it
if (m_temp_texture.get_id() != 0)
Expand Down
3 changes: 3 additions & 0 deletions src/slic3r/GUI/3DBed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Bed3D

float m_scale_factor{ 1.0f };

std::vector<std::unique_ptr<GLModel>> m_digits_models;
std::unique_ptr<GLTexture> m_digits_texture;

public:
Bed3D() = default;
~Bed3D() = default;
Expand Down
Loading

0 comments on commit 3db367b

Please sign in to comment.