Refinements

This commit is contained in:
tamasmeszaros 2022-10-21 16:59:00 +02:00
parent 9bc3410474
commit 2a8c9d7462
4 changed files with 46 additions and 40 deletions

View File

@ -46,6 +46,14 @@ std::vector<ExPolygons> slice_csgmesh_ex(
break;
}
}
for (ExPolygons &slice : ret) {
auto it = std::remove_if(slice.begin(), slice.end(), [](const ExPolygon &p){
return p.area() < double(SCALED_EPSILON) * double(SCALED_EPSILON);
});
slice.erase(it, slice.end());
}
}
return ret;

View File

@ -792,13 +792,6 @@ bool SLAPrint::is_step_done(SLAPrintObjectStep step) const
SLAPrintObject::SLAPrintObject(SLAPrint *print, ModelObject *model_object)
: Inherited(print, model_object)
// , m_transformed_rmesh([this](TriangleMesh &obj) {
//// obj = m_model_object->raw_mesh();
//// if (!obj.empty()) {
//// obj.transform(m_trafo);
//// }
// obj = transformed_mesh_csg(*this);
// })
{}
SLAPrintObject::~SLAPrintObject() {}
@ -1056,7 +1049,8 @@ const TriangleMesh& SLAPrintObject::pad_mesh() const
return EMPTY_MESH;
}
const TriangleMesh &SLAPrintObject::get_mesh_to_print() const {
const TriangleMesh &SLAPrintObject::get_mesh_to_print() const
{
const TriangleMesh *ret = nullptr;
int s = SLAPrintObjectStep::slaposCount;
@ -1068,7 +1062,7 @@ const TriangleMesh &SLAPrintObject::get_mesh_to_print() const {
}
if (!ret)
ret = &m_transformed_rmesh;
ret = &EMPTY_MESH;
return *ret;
}
@ -1158,4 +1152,29 @@ void SLAPrint::StatusReporter::operator()(SLAPrint & p,
p.set_status(int(std::round(st)), msg, flags);
}
namespace csg {
inline bool operator==(const VoxelizeParams &a, const VoxelizeParams &b)
{
std::hash<Slic3r::csg::VoxelizeParams> h;
return h(a) == h(b);
}
VoxelGridPtr get_voxelgrid(const CSGPartForStep &part, const VoxelizeParams &p)
{
VoxelGridPtr &ret = part.gridcache[p];
if (!ret) {
ret = mesh_to_grid(*csg::get_mesh(part),
csg::get_transform(part),
p.voxel_scale(),
p.exterior_bandwidth(),
p.interior_bandwidth());
}
return clone(*ret);
}
} // namespace csg
} // namespace Slic3r

View File

@ -91,27 +91,7 @@ struct CSGPartForStep : public csg::CSGPart
namespace csg {
inline bool operator==(const VoxelizeParams &a, const VoxelizeParams &b)
{
std::hash<Slic3r::csg::VoxelizeParams> h;
return h(a) == h(b);
}
inline VoxelGridPtr get_voxelgrid(const CSGPartForStep &part,
const VoxelizeParams &p)
{
VoxelGridPtr &ret = part.gridcache[p];
if (!ret) {
ret = mesh_to_grid(*csg::get_mesh(part),
csg::get_transform(part),
p.voxel_scale(),
p.exterior_bandwidth(),
p.interior_bandwidth());
}
return clone(*ret);
}
VoxelGridPtr get_voxelgrid(const CSGPartForStep &part, const VoxelizeParams &p);
} // namespace csg
@ -372,7 +352,7 @@ private:
std::vector<float> m_model_height_levels;
// Caching the transformed (m_trafo) raw mesh of the object
TriangleMesh m_transformed_rmesh;
// TriangleMesh m_transformed_rmesh;
struct SupportData
{

View File

@ -194,10 +194,6 @@ struct csg_inserter {
void SLAPrint::Steps::mesh_assembly(SLAPrintObject &po)
{
po.m_mesh_to_slice.clear();
po.m_transformed_rmesh = po.m_model_object->raw_mesh();
po.m_transformed_rmesh.transform(po.trafo());
csg::model_to_csgmesh(*po.model_object(), po.trafo(),
csg_inserter{po.m_mesh_to_slice, slaposAssembly},
csg::mpartsPositive | csg::mpartsNegative);
@ -265,8 +261,11 @@ void SLAPrint::Steps::drill_holes(SLAPrintObject &po)
csg_inserter{po.m_mesh_to_slice, slaposDrillHoles},
csg::mpartsDrillHoles);
auto r = po.m_mesh_to_slice.equal_range(slaposDrillHoles);
// update preview mesh
generate_preview(po, slaposDrillHoles);
if (r.first != r.second)
generate_preview(po, slaposDrillHoles);
}
template<class Pred>
@ -374,8 +373,7 @@ void SLAPrint::Steps::slice_model(SLAPrintObject &po)
auto thr = [this]() { m_print->throw_if_canceled(); };
auto &slice_grid = po.m_model_height_levels;
Range csgrange = {po.m_mesh_to_slice.begin(), po.m_mesh_to_slice.end()};
po.m_model_slices = slice_csgmesh_ex(csgrange, slice_grid, params, thr);
po.m_model_slices = slice_csgmesh_ex(range(po.m_mesh_to_slice), slice_grid, params, thr);
auto mit = slindex_it;
for (size_t id = 0;
@ -387,7 +385,8 @@ void SLAPrint::Steps::slice_model(SLAPrintObject &po)
// We apply the printer correction offset here.
apply_printer_corrections(po, soModel);
generate_preview(po, slaposObjectSlice);
// po.m_preview_meshes[slaposObjectSlice] = po.get_mesh_to_print();
// report_status(-2, "", SlicingStatus::RELOAD_SLA_PREVIEW);
}
static void filter_support_points_by_modifiers(
@ -448,7 +447,7 @@ void SLAPrint::Steps::support_points(SLAPrintObject &po)
if (!po.m_supportdata)
po.m_supportdata =
std::make_unique<SLAPrintObject::SupportData>(
po.m_preview_meshes[slaposObjectSlice]
po.get_mesh_to_print()
);
po.m_supportdata->input.zoffset = csgmesh_positive_bb(po.m_mesh_to_slice)