Fixed the SLA layer preview.
This commit is contained in:
parent
8003dd4991
commit
2fe27a29e0
3 changed files with 44 additions and 70 deletions
|
@ -350,6 +350,11 @@ public:
|
||||||
}
|
}
|
||||||
const PrintObjects& objects() const { return m_objects; }
|
const PrintObjects& objects() const { return m_objects; }
|
||||||
|
|
||||||
|
const SLAPrintConfig& print_config() const { return m_print_config; }
|
||||||
|
const SLAPrinterConfig& printer_config() const { return m_printer_config; }
|
||||||
|
const SLAMaterialConfig& material_config() const { return m_material_config; }
|
||||||
|
|
||||||
|
|
||||||
std::string output_filename() const override;
|
std::string output_filename() const override;
|
||||||
|
|
||||||
const SLAPrintStatistics& print_statistics() const { return m_print_statistics; }
|
const SLAPrintStatistics& print_statistics() const { return m_print_statistics; }
|
||||||
|
|
|
@ -4971,24 +4971,20 @@ void GLCanvas3D::_render_sla_slices() const
|
||||||
{
|
{
|
||||||
const SLAPrintObject* obj = print_objects[i];
|
const SLAPrintObject* obj = print_objects[i];
|
||||||
|
|
||||||
double shift_z = obj->get_current_elevation();
|
|
||||||
double min_z = clip_min_z - shift_z;
|
|
||||||
double max_z = clip_max_z - shift_z;
|
|
||||||
|
|
||||||
SlaCap::ObjectIdToTrianglesMap::iterator it_caps_bottom = m_sla_caps[0].triangles.find(i);
|
SlaCap::ObjectIdToTrianglesMap::iterator it_caps_bottom = m_sla_caps[0].triangles.find(i);
|
||||||
SlaCap::ObjectIdToTrianglesMap::iterator it_caps_top = m_sla_caps[1].triangles.find(i);
|
SlaCap::ObjectIdToTrianglesMap::iterator it_caps_top = m_sla_caps[1].triangles.find(i);
|
||||||
{
|
{
|
||||||
if (it_caps_bottom == m_sla_caps[0].triangles.end())
|
if (it_caps_bottom == m_sla_caps[0].triangles.end())
|
||||||
it_caps_bottom = m_sla_caps[0].triangles.emplace(i, SlaCap::Triangles()).first;
|
it_caps_bottom = m_sla_caps[0].triangles.emplace(i, SlaCap::Triangles()).first;
|
||||||
if (! m_sla_caps[0].matches(min_z)) {
|
if (! m_sla_caps[0].matches(clip_min_z)) {
|
||||||
m_sla_caps[0].z = min_z;
|
m_sla_caps[0].z = clip_min_z;
|
||||||
it_caps_bottom->second.object.clear();
|
it_caps_bottom->second.object.clear();
|
||||||
it_caps_bottom->second.supports.clear();
|
it_caps_bottom->second.supports.clear();
|
||||||
}
|
}
|
||||||
if (it_caps_top == m_sla_caps[1].triangles.end())
|
if (it_caps_top == m_sla_caps[1].triangles.end())
|
||||||
it_caps_top = m_sla_caps[1].triangles.emplace(i, SlaCap::Triangles()).first;
|
it_caps_top = m_sla_caps[1].triangles.emplace(i, SlaCap::Triangles()).first;
|
||||||
if (! m_sla_caps[1].matches(max_z)) {
|
if (! m_sla_caps[1].matches(clip_max_z)) {
|
||||||
m_sla_caps[1].z = max_z;
|
m_sla_caps[1].z = clip_max_z;
|
||||||
it_caps_top->second.object.clear();
|
it_caps_top->second.object.clear();
|
||||||
it_caps_top->second.supports.clear();
|
it_caps_top->second.supports.clear();
|
||||||
}
|
}
|
||||||
|
@ -5008,61 +5004,40 @@ void GLCanvas3D::_render_sla_slices() const
|
||||||
std::vector<InstanceTransform> instance_transforms;
|
std::vector<InstanceTransform> instance_transforms;
|
||||||
for (const SLAPrintObject::Instance& inst : instances)
|
for (const SLAPrintObject::Instance& inst : instances)
|
||||||
{
|
{
|
||||||
instance_transforms.push_back({ to_3d(unscale(inst.shift), shift_z), Geometry::rad2deg(inst.rotation) });
|
instance_transforms.push_back({ to_3d(unscale(inst.shift), 0.), Geometry::rad2deg(inst.rotation) });
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((bottom_obj_triangles.empty() || bottom_sup_triangles.empty() || top_obj_triangles.empty() || top_sup_triangles.empty()) && obj->is_step_done(slaposIndexSlices))
|
if ((bottom_obj_triangles.empty() || bottom_sup_triangles.empty() || top_obj_triangles.empty() || top_sup_triangles.empty()) && obj->is_step_done(slaposIndexSlices))
|
||||||
{
|
{
|
||||||
// FIXME: is this all right (by Tamas)?
|
double initial_layer_height = print->material_config().initial_layer_height.value;
|
||||||
auto slice_range = obj->get_slice_records(coord_t(min_z / SCALING_FACTOR),
|
LevelID key_zero = obj->get_slice_records().begin()->key();
|
||||||
coord_t(max_z / SCALING_FACTOR));
|
LevelID key_low = LevelID((clip_min_z - initial_layer_height) / SCALING_FACTOR) + key_zero;
|
||||||
const ExPolygons& obj_bottom = obj->get_slices_from_record(slice_range.begin(), soModel);
|
LevelID key_high = LevelID((clip_max_z - initial_layer_height) / SCALING_FACTOR) + key_zero;
|
||||||
const ExPolygons& obj_top = obj->get_slices_from_record(std::prev(slice_range.end()), soModel);
|
auto slice_range = obj->get_slice_records(key_low - LevelID(SCALED_EPSILON), key_high - LevelID(SCALED_EPSILON));
|
||||||
const ExPolygons& sup_bottom = obj->get_slices_from_record(slice_range.begin(), soSupport);
|
auto it_low = slice_range.begin();
|
||||||
const ExPolygons& sup_top = obj->get_slices_from_record(std::prev(slice_range.end()), soSupport);
|
auto it_high = std::prev(slice_range.end());
|
||||||
|
|
||||||
|
if (! it_low.is_end() && it_low->key() < key_low + LevelID(SCALED_EPSILON)) {
|
||||||
|
const ExPolygons& obj_bottom = obj->get_slices_from_record(it_low, soModel);
|
||||||
|
const ExPolygons& sup_bottom = obj->get_slices_from_record(it_low, soSupport);
|
||||||
// calculate model bottom cap
|
// calculate model bottom cap
|
||||||
if (bottom_obj_triangles.empty() && !obj_bottom.empty())
|
if (bottom_obj_triangles.empty() && !obj_bottom.empty())
|
||||||
bottom_obj_triangles = triangulate_expolygons_3d(obj_bottom, min_z, true);
|
bottom_obj_triangles = triangulate_expolygons_3d(obj_bottom, clip_min_z, true);
|
||||||
|
|
||||||
// calculate support bottom cap
|
// calculate support bottom cap
|
||||||
if (bottom_sup_triangles.empty() && !sup_bottom.empty())
|
if (bottom_sup_triangles.empty() && !sup_bottom.empty())
|
||||||
bottom_sup_triangles = triangulate_expolygons_3d(sup_bottom, min_z, true);
|
bottom_sup_triangles = triangulate_expolygons_3d(sup_bottom, clip_min_z, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! it_high.is_end() && it_high->key() < key_high + LevelID(SCALED_EPSILON)) {
|
||||||
|
const ExPolygons& obj_top = obj->get_slices_from_record(it_high, soModel);
|
||||||
|
const ExPolygons& sup_top = obj->get_slices_from_record(it_high, soSupport);
|
||||||
// calculate model top cap
|
// calculate model top cap
|
||||||
if (top_obj_triangles.empty() && !obj_top.empty())
|
if (top_obj_triangles.empty() && !obj_top.empty())
|
||||||
top_obj_triangles = triangulate_expolygons_3d(obj_top, max_z, false);
|
top_obj_triangles = triangulate_expolygons_3d(obj_top, clip_max_z, false);
|
||||||
|
|
||||||
// calculate support top cap
|
// calculate support top cap
|
||||||
if (top_sup_triangles.empty() && !sup_top.empty())
|
if (top_sup_triangles.empty() && !sup_top.empty())
|
||||||
top_sup_triangles = triangulate_expolygons_3d(sup_top, max_z, false);
|
top_sup_triangles = triangulate_expolygons_3d(sup_top, clip_max_z, false);
|
||||||
|
}
|
||||||
// const std::vector<ExPolygons>& model_slices = obj->get_model_slices();
|
|
||||||
// const std::vector<ExPolygons>& support_slices = obj->get_support_slices();
|
|
||||||
|
|
||||||
// const SLAPrintObject::SliceIndex& index = obj->get_slice_index();
|
|
||||||
// SLAPrintObject::SliceIndex::const_iterator it_min_z = std::find_if(index.begin(), index.end(), [min_z](const SLAPrintObject::SliceIndex::value_type& id) -> bool { return std::abs(min_z - id.first) < EPSILON; });
|
|
||||||
// SLAPrintObject::SliceIndex::const_iterator it_max_z = std::find_if(index.begin(), index.end(), [max_z](const SLAPrintObject::SliceIndex::value_type& id) -> bool { return std::abs(max_z - id.first) < EPSILON; });
|
|
||||||
|
|
||||||
// if (it_min_z != index.end())
|
|
||||||
// {
|
|
||||||
// // calculate model bottom cap
|
|
||||||
// if (bottom_obj_triangles.empty() && (it_min_z->second.model_slices_idx < model_slices.size()))
|
|
||||||
// bottom_obj_triangles = triangulate_expolygons_3d(model_slices[it_min_z->second.model_slices_idx], min_z, true);
|
|
||||||
// // calculate support bottom cap
|
|
||||||
// if (bottom_sup_triangles.empty() && (it_min_z->second.support_slices_idx < support_slices.size()))
|
|
||||||
// bottom_sup_triangles = triangulate_expolygons_3d(support_slices[it_min_z->second.support_slices_idx], min_z, true);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (it_max_z != index.end())
|
|
||||||
// {
|
|
||||||
// // calculate model top cap
|
|
||||||
// if (top_obj_triangles.empty() && (it_max_z->second.model_slices_idx < model_slices.size()))
|
|
||||||
// top_obj_triangles = triangulate_expolygons_3d(model_slices[it_max_z->second.model_slices_idx], max_z, false);
|
|
||||||
// // calculate support top cap
|
|
||||||
// if (top_sup_triangles.empty() && (it_max_z->second.support_slices_idx < support_slices.size()))
|
|
||||||
// top_sup_triangles = triangulate_expolygons_3d(support_slices[it_max_z->second.support_slices_idx], max_z, false);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bottom_obj_triangles.empty() || !top_obj_triangles.empty() || !bottom_sup_triangles.empty() || !top_sup_triangles.empty())
|
if (!bottom_obj_triangles.empty() || !top_obj_triangles.empty() || !bottom_sup_triangles.empty() || !top_sup_triangles.empty())
|
||||||
|
|
|
@ -769,19 +769,17 @@ void Preview::load_print_as_sla()
|
||||||
unsigned int n_layers = 0;
|
unsigned int n_layers = 0;
|
||||||
const SLAPrint* print = m_process->sla_print();
|
const SLAPrint* print = m_process->sla_print();
|
||||||
|
|
||||||
std::set<double> zs;
|
std::vector<double> zs;
|
||||||
|
double initial_layer_height = print->material_config().initial_layer_height.value;
|
||||||
for (const SLAPrintObject* obj : print->objects())
|
for (const SLAPrintObject* obj : print->objects())
|
||||||
{
|
|
||||||
double shift_z = obj->get_current_elevation();
|
|
||||||
if (obj->is_step_done(slaposIndexSlices))
|
if (obj->is_step_done(slaposIndexSlices))
|
||||||
{
|
{
|
||||||
auto slicerecords = obj->get_slice_records();
|
auto slicerecords = obj->get_slice_records();
|
||||||
|
auto low_coord = slicerecords.begin()->key();
|
||||||
for (auto& rec : slicerecords)
|
for (auto& rec : slicerecords)
|
||||||
{
|
zs.emplace_back(initial_layer_height + (rec.key() - low_coord) * SCALING_FACTOR);
|
||||||
zs.insert(shift_z + /*rec.slice_level()*/ rec.key() * SCALING_FACTOR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
sort_remove_duplicates(zs);
|
||||||
|
|
||||||
n_layers = (unsigned int)zs.size();
|
n_layers = (unsigned int)zs.size();
|
||||||
if (n_layers == 0)
|
if (n_layers == 0)
|
||||||
|
@ -796,11 +794,7 @@ void Preview::load_print_as_sla()
|
||||||
show_hide_ui_elements("none");
|
show_hide_ui_elements("none");
|
||||||
|
|
||||||
if (n_layers > 0)
|
if (n_layers > 0)
|
||||||
{
|
update_sliders(zs);
|
||||||
std::vector<double> layer_zs;
|
|
||||||
std::copy(zs.begin(), zs.end(), std::back_inserter(layer_zs));
|
|
||||||
update_sliders(layer_zs);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_loaded = true;
|
m_loaded = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue