mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-02 04:40:39 +08:00
Implemented make_thumbnail and transform_thumbnail; neither is tested yet.
This commit is contained in:
parent
1074b04326
commit
76b86c807b
@ -2,49 +2,50 @@
|
|||||||
|
|
||||||
#include "Geometry.hpp"
|
#include "Geometry.hpp"
|
||||||
#include "ExPolygon.hpp"
|
#include "ExPolygon.hpp"
|
||||||
|
#include "libslic3r.h"
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
Slic3r::ExPolygonCollection& PlaterObject::make_thumbnail(const Slic3r::Model& model, int obj_index) {
|
Slic3r::ExPolygonCollection& PlaterObject::make_thumbnail(const Slic3r::Model& model, int obj_idx) {
|
||||||
|
|
||||||
// make method idempotent
|
// make method idempotent
|
||||||
this->thumbnail.clear();
|
this->thumbnail.expolygons.clear();
|
||||||
|
|
||||||
auto mesh {model.objects[obj_index]->raw_mesh()};
|
auto mesh {model.objects[obj_idx]->raw_mesh()};
|
||||||
auto model_instance {model.objects[obj_idx]->instances[0]};
|
auto model_instance {model.objects[obj_idx]->instances[0]};
|
||||||
|
|
||||||
// Apply any x/y rotations and scaling vector if this came from a 3MF object.
|
// Apply any x/y rotations and scaling vector if this came from a 3MF object.
|
||||||
mesh.rotate_x(model_instance.x_rotation);
|
mesh.rotate_x(model_instance->x_rotation);
|
||||||
mesh.rotate_y(model_instance.y_rotation);
|
mesh.rotate_y(model_instance->y_rotation);
|
||||||
mesh.scale_xyz(model_instance.scaling_vector);
|
mesh.scale(model_instance->scaling_vector);
|
||||||
|
|
||||||
if (mesh.facets_count <= 5000) {
|
if (mesh.facets_count() <= 5000) {
|
||||||
auto area_threshold {Slic3r::Geometry::scale(1)};
|
auto area_threshold {scale_(1.0)};
|
||||||
ExPolygons tmp {};
|
ExPolygons tmp {};
|
||||||
std::copy_if(tmp.end(), mesh.horizontal_projection().begin(), mesh.horizontal_projection().end(), [=](const ExPolygon& p) { return p.area() >= area_threshold; } ); // return all polys bigger than the area
|
std::copy_if(tmp.end(), mesh.horizontal_projection().begin(), mesh.horizontal_projection().end(), [=](const ExPolygon& p) { return p.area() >= area_threshold; } ); // return all polys bigger than the area
|
||||||
this->thumbnail.append(tmp);
|
this->thumbnail.append(tmp);
|
||||||
this->thumbnail.simplify(0.5);
|
this->thumbnail.simplify(0.5);
|
||||||
} else {
|
} else {
|
||||||
auto convex_hull {Slic3r::ExPolygon(mesh.convex_hull)};
|
auto convex_hull {Slic3r::ExPolygon(mesh.convex_hull())};
|
||||||
this->thumbnail.append(convex_hull);
|
this->thumbnail.append(convex_hull);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this->thumbnail;
|
return this->thumbnail;
|
||||||
}
|
}
|
||||||
Slic3r::ExPolygonCollection& PlaterObject::transform_thumbnail(Slic3r::Model model, int obj_idx) {
|
Slic3r::ExPolygonCollection& PlaterObject::transform_thumbnail(const Slic3r::Model& model, int obj_idx) {
|
||||||
if (this->thumbnail.expolygons.size() == 0) return this->thumbnail;
|
if (this->thumbnail.expolygons.size() == 0) return this->thumbnail;
|
||||||
|
|
||||||
const auto& model_object {model.objects[obj_idx] };
|
const auto& model_object {model.objects[obj_idx] };
|
||||||
const auto& model_instance {model_object.instances[0]};
|
const auto& model_instance {model_object->instances[0]};
|
||||||
|
|
||||||
// the order of these transformations MUST be the same everywhere, including
|
// the order of these transformations MUST be the same everywhere, including
|
||||||
// in Slic3r::Print->add_model_object()
|
// in Slic3r::Print->add_model_object()
|
||||||
auto t {this->thumbnail};
|
auto t {this->thumbnail};
|
||||||
t.rotate(model_instance.rotation(), Slic3r::Point(0,0));
|
t.rotate(model_instance->rotation, Slic3r::Point(0,0));
|
||||||
t.scale(model_instance.scaling_factor());
|
t.scale(model_instance->scaling_factor);
|
||||||
|
|
||||||
this->transformed_thumbnail = t;
|
this->transformed_thumbnail = t;
|
||||||
|
return this->transformed_thumbnail;
|
||||||
}
|
}
|
||||||
|
|
||||||
} } // Namespace Slic3r::GUI
|
} } // Namespace Slic3r::GUI
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ExPolygonCollection.hpp"
|
#include "ExPolygonCollection.hpp"
|
||||||
|
#include "Model.hpp"
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
@ -26,8 +27,8 @@ public:
|
|||||||
bool selected {false};
|
bool selected {false};
|
||||||
int selected_instance {-1};
|
int selected_instance {-1};
|
||||||
|
|
||||||
Slic3r::ExPolygonCollection& make_thumbnail(Slic3r::Model model, int obj_index);
|
Slic3r::ExPolygonCollection& make_thumbnail(const Slic3r::Model& model, int obj_idx);
|
||||||
Slic3r::ExPolygonCollection& transform_thumbnail(Slic3r::Model model, int obj_index);
|
Slic3r::ExPolygonCollection& transform_thumbnail(const Slic3r::Model& model, int obj_idx);
|
||||||
};
|
};
|
||||||
|
|
||||||
}} // Namespace Slic3r::GUI
|
}} // Namespace Slic3r::GUI
|
||||||
|
Loading…
x
Reference in New Issue
Block a user