mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-23 06:33:57 -06:00
Tech ENABLE_SINKING_CONTOURS -> Improved generation of sinking contours and color set to white
This commit is contained in:
parent
f1cd3e22c4
commit
d821fcba2d
2 changed files with 37 additions and 42 deletions
|
@ -290,6 +290,16 @@ void GLIndexedVertexArray::render(
|
||||||
#if ENABLE_SINKING_CONTOURS
|
#if ENABLE_SINKING_CONTOURS
|
||||||
const float GLVolume::SinkingContours::HalfWidth = 0.25f;
|
const float GLVolume::SinkingContours::HalfWidth = 0.25f;
|
||||||
|
|
||||||
|
void GLVolume::SinkingContours::render()
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
|
||||||
|
glsafe(::glPushMatrix());
|
||||||
|
glsafe(::glTranslated(m_shift.x(), m_shift.y(), m_shift.z()));
|
||||||
|
m_model.render();
|
||||||
|
glsafe(::glPopMatrix());
|
||||||
|
}
|
||||||
|
|
||||||
void GLVolume::SinkingContours::update()
|
void GLVolume::SinkingContours::update()
|
||||||
{
|
{
|
||||||
if (m_parent.is_sinking() && !m_parent.is_below_printbed()) {
|
if (m_parent.is_sinking() && !m_parent.is_below_printbed()) {
|
||||||
|
@ -301,26 +311,27 @@ void GLVolume::SinkingContours::update()
|
||||||
const TriangleMesh& mesh = GUI::wxGetApp().plater()->model().objects[m_parent.object_idx()]->volumes[m_parent.volume_idx()]->mesh();
|
const TriangleMesh& mesh = GUI::wxGetApp().plater()->model().objects[m_parent.object_idx()]->volumes[m_parent.volume_idx()]->mesh();
|
||||||
assert(mesh.has_shared_vertices());
|
assert(mesh.has_shared_vertices());
|
||||||
|
|
||||||
MeshSlicingParams slicing_params;
|
|
||||||
slicing_params.trafo = m_parent.world_matrix();
|
|
||||||
Polygons polygons = slice_mesh(mesh.its, 0.0f, slicing_params);
|
|
||||||
|
|
||||||
m_model.reset();
|
m_model.reset();
|
||||||
GUI::GLModel::InitializationData init_data;
|
GUI::GLModel::InitializationData init_data;
|
||||||
for (const Polygon& polygon : polygons) {
|
MeshSlicingParams slicing_params;
|
||||||
const Polygons outer_polys = offset(polygon, float(scale_(HalfWidth)));
|
slicing_params.trafo = m_parent.world_matrix();
|
||||||
const Polygons inner_polys = offset(polygon, -float(scale_(HalfWidth)));
|
Polygons polygons = union_(slice_mesh(mesh.its, 0.0f, slicing_params));
|
||||||
|
for (Polygon& polygon : polygons) {
|
||||||
|
if (polygon.is_clockwise())
|
||||||
|
polygon.reverse();
|
||||||
|
Polygons outer_polys = offset(polygon, float(scale_(HalfWidth)));
|
||||||
|
assert(outer_polys.size() == 1);
|
||||||
if (outer_polys.empty())
|
if (outer_polys.empty())
|
||||||
// no outer contour, skip
|
// no outer contour, skip
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const ExPolygons diff_polys_ex = diff_ex(outer_polys, inner_polys);
|
ExPolygon expoly(std::move(outer_polys.front()));
|
||||||
|
expoly.holes = offset(polygon, -float(scale_(HalfWidth)));
|
||||||
|
polygons_reverse(expoly.holes);
|
||||||
|
|
||||||
for (const ExPolygon& poly : diff_polys_ex) {
|
|
||||||
GUI::GLModel::InitializationData::Entity entity;
|
GUI::GLModel::InitializationData::Entity entity;
|
||||||
entity.type = GUI::GLModel::PrimitiveType::Triangles;
|
entity.type = GUI::GLModel::PrimitiveType::Triangles;
|
||||||
const std::vector<Vec3d> triangulation = triangulate_expolygon_3d(poly);
|
const std::vector<Vec3d> triangulation = triangulate_expolygon_3d(expoly);
|
||||||
for (const Vec3d& v : triangulation) {
|
for (const Vec3d& v : triangulation) {
|
||||||
entity.positions.emplace_back(v.cast<float>() + Vec3f(0.0f, 0.0f, 0.015f)); // add a small positive z to avoid z-fighting
|
entity.positions.emplace_back(v.cast<float>() + Vec3f(0.0f, 0.0f, 0.015f)); // add a small positive z to avoid z-fighting
|
||||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||||
|
@ -333,9 +344,8 @@ void GLVolume::SinkingContours::update()
|
||||||
}
|
}
|
||||||
init_data.entities.emplace_back(entity);
|
init_data.entities.emplace_back(entity);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
m_model.init_from(init_data);
|
m_model.init_from(init_data);
|
||||||
set_color(m_parent.render_color);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_shift = box.center() - m_old_box.center();
|
m_shift = box.center() - m_old_box.center();
|
||||||
|
@ -343,21 +353,6 @@ void GLVolume::SinkingContours::update()
|
||||||
else
|
else
|
||||||
m_model.reset();
|
m_model.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLVolume::SinkingContours::set_color(const std::array<float, 4>& color)
|
|
||||||
{
|
|
||||||
m_model.set_color(-1, { 1.0f - color[0], 1.0f - color[1], 1.0f - color[2], color[3] });
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLVolume::SinkingContours::render()
|
|
||||||
{
|
|
||||||
update();
|
|
||||||
|
|
||||||
glsafe(::glPushMatrix());
|
|
||||||
glsafe(::glTranslated(m_shift.x(), m_shift.y(), m_shift.z()));
|
|
||||||
m_model.render();
|
|
||||||
glsafe(::glPopMatrix());
|
|
||||||
}
|
|
||||||
#endif // ENABLE_SINKING_CONTOURS
|
#endif // ENABLE_SINKING_CONTOURS
|
||||||
|
|
||||||
const std::array<float, 4> GLVolume::SELECTED_COLOR = { 0.0f, 1.0f, 0.0f, 1.0f };
|
const std::array<float, 4> GLVolume::SELECTED_COLOR = { 0.0f, 1.0f, 0.0f, 1.0f };
|
||||||
|
@ -602,7 +597,6 @@ bool GLVolume::is_below_printbed() const
|
||||||
#if ENABLE_SINKING_CONTOURS
|
#if ENABLE_SINKING_CONTOURS
|
||||||
void GLVolume::render_sinking_contours()
|
void GLVolume::render_sinking_contours()
|
||||||
{
|
{
|
||||||
m_sinking_contours.set_color(render_color);
|
|
||||||
m_sinking_contours.render();
|
m_sinking_contours.render();
|
||||||
}
|
}
|
||||||
#endif // ENABLE_SINKING_CONTOURS
|
#endif // ENABLE_SINKING_CONTOURS
|
||||||
|
|
|
@ -292,9 +292,10 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SinkingContours(GLVolume& volume) : m_parent(volume) {}
|
SinkingContours(GLVolume& volume) : m_parent(volume) {}
|
||||||
void update();
|
|
||||||
void set_color(const std::array<float, 4>& color);
|
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void update();
|
||||||
};
|
};
|
||||||
|
|
||||||
SinkingContours m_sinking_contours;
|
SinkingContours m_sinking_contours;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue