Skip to content

Commit

Permalink
FDM supports gizmo 'autoset by angle' improvements:
Browse files Browse the repository at this point in the history
- Extra dialog for autosetting by angle in FDM supports gizmo was removed
- Highlighting facets by angle is now controlled by a slider in the main gizmo dialog
- User is allowed to paint even when using the slope highlighter
- The button to turn highlighted facets to blockers was removed, it made no sense
- Highlighted facets are now rendered in light blue
  • Loading branch information
lukasmatena committed Feb 8, 2021
1 parent 672ed99 commit cd1322c
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 183 deletions.
16 changes: 8 additions & 8 deletions resources/shaders/gouraud.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ varying vec3 delta_box_max;
varying float world_normal_z;
varying vec3 eye_normal;

vec3 slope_color()
{
return (world_normal_z > slope.normal_z - EPSILON) ? GREEN : RED;
}

void main()
{
if (any(lessThan(clipping_planes_dots, ZERO)))
discard;
vec3 color = slope.actived ? slope_color() : uniform_color.rgb;
vec3 color = uniform_color.rgb;
float alpha = uniform_color.a;
if (slope.actived && world_normal_z < slope.normal_z - EPSILON) {
color = vec3(0.7f, 0.7f, 1.f);
alpha = 1.f;
}
// if the fragment is outside the print volume -> use darker color
color = (any(lessThan(delta_box_min, ZERO)) || any(greaterThan(delta_box_max, ZERO))) ? mix(color, ZERO, 0.3333) : color;
#ifdef ENABLE_ENVIRONMENT_MAP
if (use_environment_tex)
gl_FragColor = vec4(0.45 * texture2D(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color * intensity.x, uniform_color.a);
gl_FragColor = vec4(0.45 * texture2D(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color * intensity.x, alpha);
else
#endif
gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, uniform_color.a);
gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha);
}
30 changes: 17 additions & 13 deletions src/libslic3r/TriangleSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,11 @@ void TriangleSelector::reset()
m_triangles.clear();
for (const stl_vertex& vert : m_mesh->its.vertices)
m_vertices.emplace_back(vert);
for (const stl_triangle_vertex_indices& ind : m_mesh->its.indices)
push_triangle(ind[0], ind[1], ind[2]);
for (size_t i=0; i<m_mesh->its.indices.size(); ++i) {
const stl_triangle_vertex_indices& ind = m_mesh->its.indices[i];
const Vec3f& normal = m_mesh->stl.facet_start[i].normal;
push_triangle(ind[0], ind[1], ind[2], normal);
}
m_orig_size_vertices = m_vertices.size();
m_orig_size_indices = m_triangles.size();
m_invalid_triangles = 0;
Expand All @@ -451,19 +454,20 @@ void TriangleSelector::set_edge_limit(float edge_limit)



void TriangleSelector::push_triangle(int a, int b, int c)
void TriangleSelector::push_triangle(int a, int b, int c, const Vec3f& normal)
{
for (int i : {a, b, c}) {
assert(i >= 0 && i < int(m_vertices.size()));
++m_vertices[i].ref_cnt;
}
m_triangles.emplace_back(a, b, c);
m_triangles.emplace_back(a, b, c, normal);
}


void TriangleSelector::perform_split(int facet_idx, EnforcerBlockerType old_state)
{
Triangle* tr = &m_triangles[facet_idx];
const Vec3f normal = tr->normal;

assert(tr->is_split());

Expand All @@ -483,8 +487,8 @@ void TriangleSelector::perform_split(int facet_idx, EnforcerBlockerType old_stat
m_vertices.emplace_back((m_vertices[verts_idxs[1]].v + m_vertices[verts_idxs[2]].v)/2.);
verts_idxs.insert(verts_idxs.begin()+2, m_vertices.size() - 1);

push_triangle(verts_idxs[0], verts_idxs[1], verts_idxs[2]);
push_triangle(verts_idxs[2], verts_idxs[3], verts_idxs[0]);
push_triangle(verts_idxs[0], verts_idxs[1], verts_idxs[2], normal);
push_triangle(verts_idxs[2], verts_idxs[3], verts_idxs[0], normal);
}

if (sides_to_split == 2) {
Expand All @@ -494,9 +498,9 @@ void TriangleSelector::perform_split(int facet_idx, EnforcerBlockerType old_stat
m_vertices.emplace_back((m_vertices[verts_idxs[0]].v + m_vertices[verts_idxs[3]].v)/2.);
verts_idxs.insert(verts_idxs.begin()+4, m_vertices.size() - 1);

push_triangle(verts_idxs[0], verts_idxs[1], verts_idxs[4]);
push_triangle(verts_idxs[1], verts_idxs[2], verts_idxs[4]);
push_triangle(verts_idxs[2], verts_idxs[3], verts_idxs[4]);
push_triangle(verts_idxs[0], verts_idxs[1], verts_idxs[4], normal);
push_triangle(verts_idxs[1], verts_idxs[2], verts_idxs[4], normal);
push_triangle(verts_idxs[2], verts_idxs[3], verts_idxs[4], normal);
}

if (sides_to_split == 3) {
Expand All @@ -507,10 +511,10 @@ void TriangleSelector::perform_split(int facet_idx, EnforcerBlockerType old_stat
m_vertices.emplace_back((m_vertices[verts_idxs[4]].v + m_vertices[verts_idxs[0]].v)/2.);
verts_idxs.insert(verts_idxs.begin()+5, m_vertices.size() - 1);

push_triangle(verts_idxs[0], verts_idxs[1], verts_idxs[5]);
push_triangle(verts_idxs[1], verts_idxs[2], verts_idxs[3]);
push_triangle(verts_idxs[3], verts_idxs[4], verts_idxs[5]);
push_triangle(verts_idxs[1], verts_idxs[3], verts_idxs[5]);
push_triangle(verts_idxs[0], verts_idxs[1], verts_idxs[5], normal);
push_triangle(verts_idxs[1], verts_idxs[2], verts_idxs[3], normal);
push_triangle(verts_idxs[3], verts_idxs[4], verts_idxs[5], normal);
push_triangle(verts_idxs[1], verts_idxs[3], verts_idxs[5], normal);
}

tr = &m_triangles[facet_idx]; // may have been invalidated
Expand Down
8 changes: 6 additions & 2 deletions src/libslic3r/TriangleSelector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ class TriangleSelector {
public:
// Use TriangleSelector::push_triangle to create a new triangle.
// It increments/decrements reference counter on vertices.
Triangle(int a, int b, int c)
Triangle(int a, int b, int c, const Vec3f& normal_)
: verts_idxs{a, b, c},
normal{normal_},
state{EnforcerBlockerType(0)},
number_of_splits{0},
special_side_idx{0},
Expand All @@ -73,6 +74,9 @@ class TriangleSelector {
// Indices into m_vertices.
std::array<int, 3> verts_idxs;

// Triangle normal (a shader might need it).
Vec3f normal;

// Is this triangle valid or marked to be removed?
bool valid{true};

Expand Down Expand Up @@ -158,7 +162,7 @@ class TriangleSelector {
void remove_useless_children(int facet_idx); // No hidden meaning. Triangles are meant.
bool is_pointer_in_triangle(int facet_idx) const;
bool is_edge_inside_cursor(int facet_idx) const;
void push_triangle(int a, int b, int c);
void push_triangle(int a, int b, int c, const Vec3f& normal);
void perform_split(int facet_idx, EnforcerBlockerType old_state);
};

Expand Down
Loading

0 comments on commit cd1322c

Please sign in to comment.