initial experimentation

This commit is contained in:
PavelMikus 2022-02-18 17:40:33 +01:00
parent 888f45c0d3
commit df554623bd
4 changed files with 87 additions and 0 deletions

View File

@ -47,6 +47,7 @@ set(SLIC3R_GUI_SOURCES
GUI/Gizmos/GLGizmoSlaSupports.hpp
GUI/Gizmos/GLGizmoFdmSupports.cpp
GUI/Gizmos/GLGizmoFdmSupports.hpp
GUI/Gizmos/Experiment.cpp
GUI/Gizmos/GLGizmoFlatten.cpp
GUI/Gizmos/GLGizmoFlatten.hpp
GUI/Gizmos/GLGizmoCut.cpp

View File

@ -0,0 +1,77 @@
#include "libslic3r/Model.hpp"
#include <algorithm>
#include "slic3r/GUI/GLCanvas3D.hpp"
#include "slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp"
#include "libslic3r/TriangleSelector.hpp"
namespace Slic3r::GUI {
//TODO close in seprate namespace
struct Triangle {
stl_triangle_vertex_indices indices;
Vec3f normal;
size_t index_in_its;
Vec3i neighbours;
float min_z;
//members updated during algorithm
size_t area { 0 };
};
struct SupportPlacerMesh {
indexed_triangle_set mesh;
std::vector<Triangle> triangles;
std::vector<size_t> triangle_indexes_by_z;
explicit SupportPlacerMesh(indexed_triangle_set &&mesh) :
mesh(mesh) {
auto neighbours = its_face_neighbors_par(mesh);
auto min_z_point = [](const size_t &t_index) {
const auto &t = triangles[t_index];
return std::min(mesh.vertices[t.indices.z()].z(),
std::min(mesh.vertices[t.indices.x()].z(), mesh.vertices[t.indices.y()].z()));
};
for (size_t face_index = 0; face_index < mesh.indices; ++face_index) {
Vec3f normal = its_face_normal(mesh, face_index);
triangles.push_back(Triangle { mesh.indices[face_index], normal, face_index, neighbours[face_index],
min_z_point(face_index) });
triangle_indexes_by_z.push_back(face_index);
}
std::sort(triangle_indexes_by_z.begin(), triangle_indexes_by_z.end(),
[&](const size_t &left, const size_t &right) {
return triangles[left].min_z < triangles[right].min_z;
});
}
void assign_areas() {
size_t next_to_process = 0;
while (next_to_process < triangles.size()) {
if (triangles[next_to_process].area > 0){
//already done, skip
continue;
}
}
}
};
void do_experimental_support_placement(indexed_triangle_set mesh,
const TriangleSelectorGUI *selector) {
SupportPlacerMesh support_placer { std::move(mesh) };
support_placer.assign_areas();
}
}

View File

@ -347,6 +347,12 @@ void GLGizmoFdmSupports::select_facets_by_angle(float threshold_deg, bool block)
float dot_limit = limit.dot(down);
indexed_triangle_set mesh_triangles = mv->mesh().its;
its_transform(mesh_triangles, mi->get_matrix(true));
do_experimental_support_placement(std::move(mesh_triangles), m_triangle_selectors[mesh_id].get());
if (false) {
// Now calculate dot product of vert_direction and facets' normals.
int idx = 0;
const indexed_triangle_set &its = mv->mesh().its;
@ -357,6 +363,7 @@ void GLGizmoFdmSupports::select_facets_by_angle(float threshold_deg, bool block)
}
++ idx;
}
}
}
Plater::TakeSnapshot snapshot(wxGetApp().plater(), block ? _L("Block supports by angle")

View File

@ -3,6 +3,8 @@
#include "GLGizmoPainterBase.hpp"
#include "Experiment.cpp"
namespace Slic3r::GUI {
class GLGizmoFdmSupports : public GLGizmoPainterBase