Merge branch 'et_adaptive_layer_height_2' of https://github.com/prusa3d/PrusaSlicer
This commit is contained in:
commit
89c42063de
@ -37,15 +37,14 @@ void SlicingAdaptive::prepare()
|
|||||||
m_mesh = m_object->raw_mesh();
|
m_mesh = m_object->raw_mesh();
|
||||||
const ModelInstance* first_instance = m_object->instances.front();
|
const ModelInstance* first_instance = m_object->instances.front();
|
||||||
m_mesh.transform(first_instance->get_matrix(), first_instance->is_left_handed());
|
m_mesh.transform(first_instance->get_matrix(), first_instance->is_left_handed());
|
||||||
for (stl_facet& facet : m_mesh.stl.facet_start)
|
|
||||||
{
|
|
||||||
facet.normal.normalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1) Collect faces from mesh.
|
// 1) Collect faces from mesh.
|
||||||
m_faces.reserve(m_mesh.stl.stats.number_of_facets);
|
m_faces.reserve(m_mesh.stl.stats.number_of_facets);
|
||||||
for (const stl_facet& face : m_mesh.stl.facet_start)
|
for (stl_facet& face : m_mesh.stl.facet_start)
|
||||||
|
{
|
||||||
|
face.normal.normalize();
|
||||||
m_faces.emplace_back(&face);
|
m_faces.emplace_back(&face);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
// 1) Collect faces of all meshes.
|
// 1) Collect faces of all meshes.
|
||||||
int nfaces_total = 0;
|
int nfaces_total = 0;
|
||||||
@ -58,14 +57,10 @@ void SlicingAdaptive::prepare()
|
|||||||
#endif // ENABLE_ADAPTIVE_LAYER_HEIGHT_PROFILE
|
#endif // ENABLE_ADAPTIVE_LAYER_HEIGHT_PROFILE
|
||||||
|
|
||||||
// 2) Sort faces lexicographically by their Z span.
|
// 2) Sort faces lexicographically by their Z span.
|
||||||
std::sort(m_faces.begin(), m_faces.end(), [](const stl_facet *f1, const stl_facet *f2) {
|
std::sort(m_faces.begin(), m_faces.end(), [](const stl_facet *f1, const stl_facet *f2) { return face_z_span(f1) < face_z_span(f2); });
|
||||||
std::pair<float, float> span1 = face_z_span(f1);
|
|
||||||
std::pair<float, float> span2 = face_z_span(f2);
|
|
||||||
return span1 < span2;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 3) Generate Z components of the facet normals.
|
// 3) Generate Z components of the facet normals.
|
||||||
m_face_normal_z.assign(m_faces.size(), 0.f);
|
m_face_normal_z.assign(m_faces.size(), 0.0f);
|
||||||
for (size_t iface = 0; iface < m_faces.size(); ++ iface)
|
for (size_t iface = 0; iface < m_faces.size(); ++ iface)
|
||||||
m_face_normal_z[iface] = m_faces[iface]->normal(2);
|
m_face_normal_z[iface] = m_faces[iface]->normal(2);
|
||||||
}
|
}
|
||||||
@ -88,7 +83,7 @@ float SlicingAdaptive::cusp_height(float z, float cusp_value, int ¤t_facet
|
|||||||
if (! first_hit) {
|
if (! first_hit) {
|
||||||
first_hit = true;
|
first_hit = true;
|
||||||
current_facet = ordered_id;
|
current_facet = ordered_id;
|
||||||
}
|
}
|
||||||
// skip touching facets which could otherwise cause small cusp values
|
// skip touching facets which could otherwise cause small cusp values
|
||||||
if (zspan.second <= z + EPSILON)
|
if (zspan.second <= z + EPSILON)
|
||||||
continue;
|
continue;
|
||||||
@ -115,7 +110,7 @@ float SlicingAdaptive::cusp_height(float z, float cusp_value, int ¤t_facet
|
|||||||
|
|
||||||
// Compute cusp-height for this facet and check against height.
|
// Compute cusp-height for this facet and check against height.
|
||||||
float normal_z = m_face_normal_z[ordered_id];
|
float normal_z = m_face_normal_z[ordered_id];
|
||||||
float cusp = (normal_z == 0.0f) ? (float)m_slicing_params.max_layer_height : abs(cusp_value / normal_z);
|
float cusp = (normal_z == 0.0f) ? (float)m_slicing_params.max_layer_height : std::abs(cusp_value / normal_z);
|
||||||
|
|
||||||
float z_diff = zspan.first - z;
|
float z_diff = zspan.first - z;
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ void GLCanvas3D::LayersEditing::render_overlay(const GLCanvas3D& canvas) const
|
|||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
if (imgui.button(_(L("Smooth"))))
|
if (imgui.button(_(L("Smooth"))))
|
||||||
wxPostEvent((wxEvtHandler*)canvas.get_wxglcanvas(), HeightProfileSmoothEvent(EVT_GLCANVAS_SMOOTH_LAYER_HEIGHT_PROFILE, m_smooth_params ));
|
wxPostEvent((wxEvtHandler*)canvas.get_wxglcanvas(), HeightProfileSmoothEvent(EVT_GLCANVAS_SMOOTH_LAYER_HEIGHT_PROFILE, m_smooth_params));
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SetCursorPosX(text_align);
|
ImGui::SetCursorPosX(text_align);
|
||||||
@ -640,6 +640,7 @@ void GLCanvas3D::LayersEditing::reset_layer_height_profile(GLCanvas3D& canvas)
|
|||||||
#if ENABLE_ADAPTIVE_LAYER_HEIGHT_PROFILE
|
#if ENABLE_ADAPTIVE_LAYER_HEIGHT_PROFILE
|
||||||
void GLCanvas3D::LayersEditing::adaptive_layer_height_profile(GLCanvas3D& canvas, float cusp)
|
void GLCanvas3D::LayersEditing::adaptive_layer_height_profile(GLCanvas3D& canvas, float cusp)
|
||||||
{
|
{
|
||||||
|
this->update_slicing_parameters();
|
||||||
m_layer_height_profile = layer_height_profile_adaptive(*m_slicing_parameters, *m_model_object, cusp);
|
m_layer_height_profile = layer_height_profile_adaptive(*m_slicing_parameters, *m_model_object, cusp);
|
||||||
const_cast<ModelObject*>(m_model_object)->layer_height_profile = m_layer_height_profile;
|
const_cast<ModelObject*>(m_model_object)->layer_height_profile = m_layer_height_profile;
|
||||||
m_layers_texture.valid = false;
|
m_layers_texture.valid = false;
|
||||||
@ -648,6 +649,8 @@ void GLCanvas3D::LayersEditing::adaptive_layer_height_profile(GLCanvas3D& canvas
|
|||||||
|
|
||||||
void GLCanvas3D::LayersEditing::smooth_layer_height_profile(GLCanvas3D& canvas, const HeightProfileSmoothingParams& smoothing_params)
|
void GLCanvas3D::LayersEditing::smooth_layer_height_profile(GLCanvas3D& canvas, const HeightProfileSmoothingParams& smoothing_params)
|
||||||
{
|
{
|
||||||
|
this->update_slicing_parameters();
|
||||||
|
|
||||||
m_layer_height_profile = smooth_height_profile(m_layer_height_profile, *m_slicing_parameters, smoothing_params);
|
m_layer_height_profile = smooth_height_profile(m_layer_height_profile, *m_slicing_parameters, smoothing_params);
|
||||||
const_cast<ModelObject*>(m_model_object)->layer_height_profile = m_layer_height_profile;
|
const_cast<ModelObject*>(m_model_object)->layer_height_profile = m_layer_height_profile;
|
||||||
m_layers_texture.valid = false;
|
m_layers_texture.valid = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user