mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-18 02:35:55 +08:00
Fix of assertation from sinking contour
assertation at: GLModel::init_from(Slic3r::GUI::GLModel::Geometry && data) Line 407 It is called from: GLVolume::SinkingContours::update() Line 357 polygons(defined on line 344) are empty. --> also init_data will be empty.
This commit is contained in:
parent
af663a81e1
commit
cbc138a525
@ -324,64 +324,73 @@ void GLVolume::SinkingContours::update()
|
|||||||
const int object_idx = m_parent.object_idx();
|
const int object_idx = m_parent.object_idx();
|
||||||
const Model& model = GUI::wxGetApp().plater()->model();
|
const Model& model = GUI::wxGetApp().plater()->model();
|
||||||
|
|
||||||
if (0 <= object_idx && object_idx < int(model.objects.size()) && m_parent.is_sinking() && !m_parent.is_below_printbed()) {
|
if (object_idx < 0 ||
|
||||||
const BoundingBoxf3& box = m_parent.transformed_convex_hull_bounding_box();
|
object_idx >= int(model.objects.size()) ||
|
||||||
if (!m_old_box.size().isApprox(box.size()) || m_old_box.min.z() != box.min.z()) {
|
!m_parent.is_sinking() ||
|
||||||
m_old_box = box;
|
m_parent.is_below_printbed()){
|
||||||
m_shift = Vec3d::Zero();
|
|
||||||
|
|
||||||
const TriangleMesh& mesh = model.objects[object_idx]->volumes[m_parent.volume_idx()]->mesh();
|
|
||||||
|
|
||||||
m_model.reset();
|
|
||||||
GUI::GLModel::Geometry init_data;
|
|
||||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
|
||||||
init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Triangles, GUI::GLModel::Geometry::EVertexLayout::P3 };
|
|
||||||
init_data.color = ColorRGBA::WHITE();
|
|
||||||
unsigned int vertices_counter = 0;
|
|
||||||
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
|
|
||||||
MeshSlicingParams slicing_params;
|
|
||||||
slicing_params.trafo = m_parent.world_matrix();
|
|
||||||
const Polygons polygons = union_(slice_mesh(mesh.its, 0.0f, slicing_params));
|
|
||||||
for (const ExPolygon& expoly : diff_ex(expand(polygons, float(scale_(HalfWidth))), shrink(polygons, float(scale_(HalfWidth))))) {
|
|
||||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
|
||||||
const std::vector<Vec3d> triangulation = triangulate_expolygon_3d(expoly);
|
|
||||||
init_data.reserve_vertices(init_data.vertices_count() + triangulation.size());
|
|
||||||
init_data.reserve_indices(init_data.indices_count() + triangulation.size());
|
|
||||||
for (const Vec3d& v : triangulation) {
|
|
||||||
init_data.add_vertex((Vec3f)(v.cast<float>() + 0.015f * Vec3f::UnitZ())); // add a small positive z to avoid z-fighting
|
|
||||||
++vertices_counter;
|
|
||||||
if (vertices_counter % 3 == 0)
|
|
||||||
init_data.add_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_model.init_from(std::move(init_data));
|
|
||||||
#else
|
|
||||||
GUI::GLModel::Geometry::Entity entity;
|
|
||||||
entity.type = GUI::GLModel::EPrimitiveType::Triangles;
|
|
||||||
const std::vector<Vec3d> triangulation = triangulate_expolygon_3d(expoly);
|
|
||||||
entity.positions.reserve(entity.positions.size() + triangulation.size());
|
|
||||||
entity.normals.reserve(entity.normals.size() + triangulation.size());
|
|
||||||
entity.indices.reserve(entity.indices.size() + triangulation.size() / 3);
|
|
||||||
for (const Vec3d& v : triangulation) {
|
|
||||||
entity.positions.emplace_back(v.cast<float>() + 0.015f * Vec3f::UnitZ()); // add a small positive z to avoid z-fighting
|
|
||||||
entity.normals.emplace_back(Vec3f::UnitZ());
|
|
||||||
const size_t positions_count = entity.positions.size();
|
|
||||||
if (positions_count % 3 == 0) {
|
|
||||||
entity.indices.emplace_back(positions_count - 3);
|
|
||||||
entity.indices.emplace_back(positions_count - 2);
|
|
||||||
entity.indices.emplace_back(positions_count - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
init_data.entities.emplace_back(entity);
|
|
||||||
}
|
|
||||||
m_model.init_from(init_data);
|
|
||||||
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_shift = box.center() - m_old_box.center();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_model.reset();
|
m_model.reset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const BoundingBoxf3& box = m_parent.transformed_convex_hull_bounding_box();
|
||||||
|
if (m_old_box.size().isApprox(box.size()) &&
|
||||||
|
m_old_box.min.z() == box.min.z()){
|
||||||
|
// Fix it !!! It is not working all the time
|
||||||
|
m_shift = box.center() - m_old_box.center();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_old_box = box;
|
||||||
|
m_shift = Vec3d::Zero();
|
||||||
|
|
||||||
|
const TriangleMesh& mesh = model.objects[object_idx]->volumes[m_parent.volume_idx()]->mesh();
|
||||||
|
|
||||||
|
m_model.reset();
|
||||||
|
GUI::GLModel::Geometry init_data;
|
||||||
|
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||||
|
init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Triangles, GUI::GLModel::Geometry::EVertexLayout::P3 };
|
||||||
|
init_data.color = ColorRGBA::WHITE();
|
||||||
|
unsigned int vertices_counter = 0;
|
||||||
|
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
|
||||||
|
MeshSlicingParams slicing_params;
|
||||||
|
slicing_params.trafo = m_parent.world_matrix();
|
||||||
|
const Polygons polygons = union_(slice_mesh(mesh.its, 0.0f, slicing_params));
|
||||||
|
if (polygons.empty()) return;
|
||||||
|
|
||||||
|
for (const ExPolygon& expoly : diff_ex(expand(polygons, float(scale_(HalfWidth))), shrink(polygons, float(scale_(HalfWidth))))) {
|
||||||
|
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||||
|
const std::vector<Vec3d> triangulation = triangulate_expolygon_3d(expoly);
|
||||||
|
init_data.reserve_vertices(init_data.vertices_count() + triangulation.size());
|
||||||
|
init_data.reserve_indices(init_data.indices_count() + triangulation.size());
|
||||||
|
for (const Vec3d& v : triangulation) {
|
||||||
|
init_data.add_vertex((Vec3f)(v.cast<float>() + 0.015f * Vec3f::UnitZ())); // add a small positive z to avoid z-fighting
|
||||||
|
++vertices_counter;
|
||||||
|
if (vertices_counter % 3 == 0)
|
||||||
|
init_data.add_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_model.init_from(std::move(init_data));
|
||||||
|
#else
|
||||||
|
GUI::GLModel::Geometry::Entity entity;
|
||||||
|
entity.type = GUI::GLModel::EPrimitiveType::Triangles;
|
||||||
|
const std::vector<Vec3d> triangulation = triangulate_expolygon_3d(expoly);
|
||||||
|
entity.positions.reserve(entity.positions.size() + triangulation.size());
|
||||||
|
entity.normals.reserve(entity.normals.size() + triangulation.size());
|
||||||
|
entity.indices.reserve(entity.indices.size() + triangulation.size() / 3);
|
||||||
|
for (const Vec3d& v : triangulation) {
|
||||||
|
entity.positions.emplace_back(v.cast<float>() + 0.015f * Vec3f::UnitZ()); // add a small positive z to avoid z-fighting
|
||||||
|
entity.normals.emplace_back(Vec3f::UnitZ());
|
||||||
|
const size_t positions_count = entity.positions.size();
|
||||||
|
if (positions_count % 3 == 0) {
|
||||||
|
entity.indices.emplace_back(positions_count - 3);
|
||||||
|
entity.indices.emplace_back(positions_count - 2);
|
||||||
|
entity.indices.emplace_back(positions_count - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
init_data.entities.emplace_back(entity);
|
||||||
|
}
|
||||||
|
m_model.init_from(init_data);
|
||||||
|
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_SHOW_NON_MANIFOLD_EDGES
|
#if ENABLE_SHOW_NON_MANIFOLD_EDGES
|
||||||
|
Loading…
x
Reference in New Issue
Block a user