mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-24 17:21:11 -06:00
Fixed conflicts after merging with master
This commit is contained in:
commit
fef5a5252e
38 changed files with 835 additions and 126 deletions
|
|
@ -551,8 +551,10 @@ void FirmwareDialog::priv::perform_upload()
|
|||
// because the dialog ensures it doesn't exit before the background thread is done.
|
||||
auto q = this->q;
|
||||
|
||||
this->avrdude = avrdude
|
||||
.on_run([this]() {
|
||||
avrdude
|
||||
.on_run([this](AvrDude::Ptr avrdude) {
|
||||
this->avrdude = std::move(avrdude);
|
||||
|
||||
try {
|
||||
switch (this->hex_file.device) {
|
||||
case HexFile::DEV_MK3:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "GLCanvas3D.hpp"
|
||||
|
||||
#include "../../admesh/stl.h"
|
||||
#include "../../libslic3r/libslic3r.h"
|
||||
#include "../../slic3r/GUI/3DScene.hpp"
|
||||
#include "../../slic3r/GUI/GLShader.hpp"
|
||||
|
|
@ -1165,6 +1166,18 @@ bool GLCanvas3D::Gizmos::init(GLCanvas3D& parent)
|
|||
|
||||
m_gizmos.insert(GizmosMap::value_type(Rotate, gizmo));
|
||||
|
||||
gizmo = new GLGizmoFlatten(parent);
|
||||
if (gizmo == nullptr)
|
||||
return false;
|
||||
|
||||
if (!gizmo->init()) {
|
||||
_reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_gizmos.insert(GizmosMap::value_type(Flatten, gizmo));
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1414,11 +1427,32 @@ reinterpret_cast<GLGizmoRotate3D*>(it->second)->set_angle_z(angle_z);
|
|||
#endif // ENABLE_GIZMOS_3D
|
||||
}
|
||||
|
||||
Vec3d GLCanvas3D::Gizmos::get_flattening_normal() const
|
||||
{
|
||||
if (!m_enabled)
|
||||
return Vec3d::Zero();
|
||||
|
||||
GizmosMap::const_iterator it = m_gizmos.find(Flatten);
|
||||
return (it != m_gizmos.end()) ? reinterpret_cast<GLGizmoFlatten*>(it->second)->get_flattening_normal() : Vec3d::Zero();
|
||||
}
|
||||
|
||||
void GLCanvas3D::Gizmos::set_flattening_data(const ModelObject* model_object)
|
||||
{
|
||||
if (!m_enabled)
|
||||
return;
|
||||
|
||||
GizmosMap::const_iterator it = m_gizmos.find(Flatten);
|
||||
if (it != m_gizmos.end())
|
||||
reinterpret_cast<GLGizmoFlatten*>(it->second)->set_flattening_data(model_object);
|
||||
}
|
||||
|
||||
void GLCanvas3D::Gizmos::render_current_gizmo(const BoundingBoxf3& box) const
|
||||
{
|
||||
if (!m_enabled)
|
||||
return;
|
||||
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
|
||||
if (box.radius() > 0.0)
|
||||
_render_current_gizmo(box);
|
||||
}
|
||||
|
|
@ -2319,6 +2353,7 @@ void GLCanvas3D::update_gizmos_data()
|
|||
{
|
||||
m_gizmos.set_scale(model_instance->scaling_factor);
|
||||
m_gizmos.set_angle_z(model_instance->rotation);
|
||||
m_gizmos.set_flattening_data(model_object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2326,6 +2361,7 @@ void GLCanvas3D::update_gizmos_data()
|
|||
{
|
||||
m_gizmos.set_scale(1.0f);
|
||||
m_gizmos.set_angle_z(0.0f);
|
||||
m_gizmos.set_flattening_data(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2367,7 +2403,6 @@ void GLCanvas3D::render()
|
|||
_render_axes(false);
|
||||
}
|
||||
_render_objects();
|
||||
|
||||
if (!is_custom_bed) // textured bed needs to be rendered after objects
|
||||
{
|
||||
_render_axes(true);
|
||||
|
|
@ -2982,6 +3017,17 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||
update_gizmos_data();
|
||||
m_gizmos.start_dragging();
|
||||
m_mouse.drag.gizmo_volume_idx = _get_first_selected_volume_id(selected_object_idx);
|
||||
|
||||
if (m_gizmos.get_current_type() == Gizmos::Flatten) {
|
||||
// Rotate the object so the normal points downward:
|
||||
Vec3d normal = m_gizmos.get_flattening_normal();
|
||||
if (normal != Vec3d::Zero()) {
|
||||
Vec3d axis = normal(2) > 0.999f ? Vec3d::UnitX() : normal.cross(-Vec3d::UnitZ());
|
||||
float angle = -acos(-normal(2));
|
||||
m_on_gizmo_rotate_callback.call(angle, (float)axis(0), (float)axis(1), (float)axis(2));
|
||||
}
|
||||
}
|
||||
|
||||
m_dirty = true;
|
||||
}
|
||||
else if (toolbar_contains_mouse != -1)
|
||||
|
|
|
|||
|
|
@ -338,6 +338,7 @@ public:
|
|||
Undefined,
|
||||
Scale,
|
||||
Rotate,
|
||||
Flatten,
|
||||
Num_Types
|
||||
};
|
||||
|
||||
|
|
@ -382,7 +383,11 @@ public:
|
|||
float get_angle_z() const;
|
||||
void set_angle_z(float angle_z);
|
||||
|
||||
void set_flattening_data(const ModelObject* model_object);
|
||||
Vec3d get_flattening_normal() const;
|
||||
|
||||
void render_current_gizmo(const BoundingBoxf3& box) const;
|
||||
|
||||
void render_current_gizmo_for_picking_pass(const BoundingBoxf3& box) const;
|
||||
void render_overlay(const GLCanvas3D& canvas) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@
|
|||
#include "../../slic3r/GUI/GLCanvas3D.hpp"
|
||||
|
||||
#include <Eigen/Dense>
|
||||
#include "../../libslic3r/Geometry.hpp"
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
|
||||
static const float DEFAULT_BASE_COLOR[3] = { 0.625f, 0.625f, 0.625f };
|
||||
static const float DEFAULT_DRAG_COLOR[3] = { 1.0f, 1.0f, 1.0f };
|
||||
|
|
@ -163,7 +165,6 @@ GLGizmoBase::GLGizmoBase(GLCanvas3D& parent)
|
|||
, m_group_id(-1)
|
||||
, m_state(Off)
|
||||
, m_hover_id(-1)
|
||||
, m_is_container(false)
|
||||
{
|
||||
::memcpy((void*)m_base_color, (const void*)DEFAULT_BASE_COLOR, 3 * sizeof(float));
|
||||
::memcpy((void*)m_drag_color, (const void*)DEFAULT_DRAG_COLOR, 3 * sizeof(float));
|
||||
|
|
@ -172,7 +173,7 @@ GLGizmoBase::GLGizmoBase(GLCanvas3D& parent)
|
|||
|
||||
void GLGizmoBase::set_hover_id(int id)
|
||||
{
|
||||
if (m_is_container || (id < (int)m_grabbers.size()))
|
||||
if (m_grabbers.empty() || (id < (int)m_grabbers.size()))
|
||||
{
|
||||
m_hover_id = id;
|
||||
on_set_hover_id();
|
||||
|
|
@ -602,8 +603,6 @@ GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent)
|
|||
, m_y(parent, GLGizmoRotate::Y)
|
||||
, m_z(parent, GLGizmoRotate::Z)
|
||||
{
|
||||
m_is_container = true;
|
||||
|
||||
m_x.set_group_id(0);
|
||||
m_y.set_group_id(1);
|
||||
m_z.set_group_id(2);
|
||||
|
|
@ -1165,5 +1164,323 @@ double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3&
|
|||
return ratio;
|
||||
}
|
||||
|
||||
|
||||
GLGizmoFlatten::GLGizmoFlatten(GLCanvas3D& parent)
|
||||
: GLGizmoBase(parent)
|
||||
, m_normal(0.0, 0.0, 0.0)
|
||||
{
|
||||
}
|
||||
|
||||
bool GLGizmoFlatten::on_init()
|
||||
{
|
||||
std::string path = resources_dir() + "/icons/overlay/";
|
||||
|
||||
std::string filename = path + "layflat_off.png";
|
||||
if (!m_textures[Off].load_from_file(filename, false))
|
||||
return false;
|
||||
|
||||
filename = path + "layflat_hover.png";
|
||||
if (!m_textures[Hover].load_from_file(filename, false))
|
||||
return false;
|
||||
|
||||
filename = path + "layflat_on.png";
|
||||
if (!m_textures[On].load_from_file(filename, false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLGizmoFlatten::on_start_dragging()
|
||||
{
|
||||
if (m_hover_id != -1)
|
||||
m_normal = m_planes[m_hover_id].normal;
|
||||
}
|
||||
|
||||
void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const
|
||||
{
|
||||
// the dragged_offset is a vector measuring where was the object moved
|
||||
// with the gizmo being on. This is reset in set_flattening_data and
|
||||
// does not work correctly when there are multiple copies.
|
||||
if (!m_center) // this is the first bounding box that we see
|
||||
m_center.reset(new Vec3d(box.center()));
|
||||
|
||||
Vec3d dragged_offset = box.center() - *m_center;
|
||||
|
||||
bool blending_was_enabled = ::glIsEnabled(GL_BLEND);
|
||||
bool depth_test_was_enabled = ::glIsEnabled(GL_DEPTH_TEST);
|
||||
::glEnable(GL_BLEND);
|
||||
::glEnable(GL_DEPTH_TEST);
|
||||
|
||||
for (int i=0; i<(int)m_planes.size(); ++i) {
|
||||
if (i == m_hover_id)
|
||||
::glColor4f(0.9f, 0.9f, 0.9f, 0.75f);
|
||||
else
|
||||
::glColor4f(0.9f, 0.9f, 0.9f, 0.5f);
|
||||
|
||||
for (Vec2d offset : m_instances_positions) {
|
||||
offset += to_2d(dragged_offset);
|
||||
::glBegin(GL_POLYGON);
|
||||
for (const Vec3d& vertex : m_planes[i].vertices)
|
||||
::glVertex3f((GLfloat)(vertex(0) + offset(0)), (GLfloat)(vertex(1) + offset(1)), (GLfloat)vertex(2));
|
||||
::glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
if (!blending_was_enabled)
|
||||
::glDisable(GL_BLEND);
|
||||
if (!depth_test_was_enabled)
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const
|
||||
{
|
||||
static const GLfloat INV_255 = 1.0f / 255.0f;
|
||||
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
|
||||
for (unsigned int i = 0; i < m_planes.size(); ++i)
|
||||
{
|
||||
::glColor3f(1.0f, 1.0f, (254.0f - (float)i) * INV_255);
|
||||
for (const Vec2d& offset : m_instances_positions) {
|
||||
::glBegin(GL_POLYGON);
|
||||
for (const Vec3d& vertex : m_planes[i].vertices)
|
||||
::glVertex3f((GLfloat)(vertex(0) + offset(0)), (GLfloat)vertex(1) + offset(1), (GLfloat)vertex(2));
|
||||
::glEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO - remove and use Eigen instead
|
||||
static Vec3d super_rotation(Vec3d axis, float angle, const Vec3d& point)
|
||||
{
|
||||
axis.normalize();
|
||||
float x = (float)axis(0);
|
||||
float y = (float)axis(1);
|
||||
float z = (float)axis(2);
|
||||
float s = sin(angle);
|
||||
float c = cos(angle);
|
||||
float D = 1 - c;
|
||||
float matrix[3][3] = { { c + x*x*D, x*y*D - z*s, x*z*D + y*s },
|
||||
{ y*x*D + z*s, c + y*y*D, y*z*D - x*s },
|
||||
{ z*x*D - y*s, z*y*D + x*s, c + z*z*D } };
|
||||
float in[3] = { (float)point(0), (float)point(1), (float)point(2) };
|
||||
float out[3] = { 0, 0, 0 };
|
||||
|
||||
for (unsigned char i = 0; i<3; ++i)
|
||||
for (unsigned char j = 0; j<3; ++j)
|
||||
out[i] += matrix[i][j] * in[j];
|
||||
|
||||
return Vec3d((double)out[0], (double)out[1], (double)out[2]);
|
||||
}
|
||||
|
||||
void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object)
|
||||
{
|
||||
m_center.release(); // object is not being dragged (this would not be called otherwise) - we must forget about the bounding box position...
|
||||
m_model_object = model_object;
|
||||
|
||||
// ...and save the updated positions of the object instances:
|
||||
if (m_model_object && !m_model_object->instances.empty()) {
|
||||
m_instances_positions.clear();
|
||||
for (const auto* instance : m_model_object->instances)
|
||||
m_instances_positions.emplace_back(instance->offset);
|
||||
}
|
||||
|
||||
if (is_plane_update_necessary())
|
||||
update_planes();
|
||||
}
|
||||
|
||||
void GLGizmoFlatten::update_planes()
|
||||
{
|
||||
TriangleMesh ch;
|
||||
for (const ModelVolume* vol : m_model_object->volumes)
|
||||
ch.merge(vol->get_convex_hull());
|
||||
ch = ch.convex_hull_3d();
|
||||
ch.scale(m_model_object->instances.front()->scaling_factor);
|
||||
ch.rotate_z(m_model_object->instances.front()->rotation);
|
||||
|
||||
m_planes.clear();
|
||||
|
||||
// Now we'll go through all the facets and append Points of facets sharing the same normal:
|
||||
const int num_of_facets = ch.stl.stats.number_of_facets;
|
||||
std::vector<int> facet_queue(num_of_facets, 0);
|
||||
std::vector<bool> facet_visited(num_of_facets, false);
|
||||
int facet_queue_cnt = 0;
|
||||
const stl_normal* normal_ptr = nullptr;
|
||||
while (1) {
|
||||
// Find next unvisited triangle:
|
||||
int facet_idx = 0;
|
||||
for (; facet_idx < num_of_facets; ++ facet_idx)
|
||||
if (!facet_visited[facet_idx]) {
|
||||
facet_queue[facet_queue_cnt ++] = facet_idx;
|
||||
facet_visited[facet_idx] = true;
|
||||
normal_ptr = &ch.stl.facet_start[facet_idx].normal;
|
||||
m_planes.emplace_back();
|
||||
break;
|
||||
}
|
||||
if (facet_idx == num_of_facets)
|
||||
break; // Everything was visited already
|
||||
|
||||
while (facet_queue_cnt > 0) {
|
||||
int facet_idx = facet_queue[-- facet_queue_cnt];
|
||||
const stl_normal& this_normal = ch.stl.facet_start[facet_idx].normal;
|
||||
if (std::abs(this_normal(0) - (*normal_ptr)(0)) < 0.001 && std::abs(this_normal(1) - (*normal_ptr)(1)) < 0.001 && std::abs(this_normal(2) - (*normal_ptr)(2)) < 0.001) {
|
||||
stl_vertex* first_vertex = ch.stl.facet_start[facet_idx].vertex;
|
||||
for (int j=0; j<3; ++j)
|
||||
m_planes.back().vertices.emplace_back(first_vertex[j](0), first_vertex[j](1), first_vertex[j](2));
|
||||
|
||||
facet_visited[facet_idx] = true;
|
||||
for (int j = 0; j < 3; ++ j) {
|
||||
int neighbor_idx = ch.stl.neighbors_start[facet_idx].neighbor[j];
|
||||
if (! facet_visited[neighbor_idx])
|
||||
facet_queue[facet_queue_cnt ++] = neighbor_idx;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_planes.back().normal = Vec3d((double)(*normal_ptr)(0), (double)(*normal_ptr)(1), (double)(*normal_ptr)(2));
|
||||
|
||||
// if this is a just a very small triangle, remove it to speed up further calculations (it would be rejected anyway):
|
||||
if (m_planes.back().vertices.size() == 3 &&
|
||||
(m_planes.back().vertices[0] - m_planes.back().vertices[1]).norm() < 1.f
|
||||
|| (m_planes.back().vertices[0] - m_planes.back().vertices[2]).norm() < 1.f)
|
||||
m_planes.pop_back();
|
||||
}
|
||||
|
||||
// Now we'll go through all the polygons, transform the points into xy plane to process them:
|
||||
for (unsigned int polygon_id=0; polygon_id < m_planes.size(); ++polygon_id) {
|
||||
Pointf3s& polygon = m_planes[polygon_id].vertices;
|
||||
const Vec3d& normal = m_planes[polygon_id].normal;
|
||||
|
||||
// We are going to rotate about z and y to flatten the plane
|
||||
float angle_z = 0.f;
|
||||
float angle_y = 0.f;
|
||||
if (std::abs(normal(1)) > 0.001)
|
||||
angle_z = -atan2(normal(1), normal(0)); // angle to rotate so that normal ends up in xz-plane
|
||||
if (std::abs(normal(0)*cos(angle_z) - normal(1)*sin(angle_z)) > 0.001)
|
||||
angle_y = -atan2(normal(0)*cos(angle_z) - normal(1)*sin(angle_z), normal(2)); // angle to rotate to make normal point upwards
|
||||
else {
|
||||
// In case it already was in z-direction, we must ensure it is not the wrong way:
|
||||
angle_y = normal(2) > 0.f ? 0 : -PI;
|
||||
}
|
||||
|
||||
// Rotate all points to the xy plane:
|
||||
for (auto& vertex : polygon) {
|
||||
vertex = super_rotation(Vec3d::UnitZ(), angle_z, vertex);
|
||||
vertex = super_rotation(Vec3d::UnitY(), angle_y, vertex);
|
||||
}
|
||||
polygon = Slic3r::Geometry::convex_hull(polygon); // To remove the inner points
|
||||
|
||||
// We will calculate area of the polygon and discard ones that are too small
|
||||
// The limit is more forgiving in case the normal is in the direction of the coordinate axes
|
||||
const float minimal_area = (std::abs(normal(0)) > 0.999f || std::abs(normal(1)) > 0.999f || std::abs(normal(2)) > 0.999f) ? 1.f : 20.f;
|
||||
float& area = m_planes[polygon_id].area;
|
||||
area = 0.f;
|
||||
for (unsigned int i = 0; i < polygon.size(); i++) // Shoelace formula
|
||||
area += polygon[i](0)*polygon[i + 1 < polygon.size() ? i + 1 : 0](1) - polygon[i + 1 < polygon.size() ? i + 1 : 0](0)*polygon[i](1);
|
||||
area = std::abs(area / 2.f);
|
||||
if (area < minimal_area) {
|
||||
m_planes.erase(m_planes.begin()+(polygon_id--));
|
||||
continue;
|
||||
}
|
||||
|
||||
// We will shrink the polygon a little bit so it does not touch the object edges:
|
||||
Vec3d centroid = std::accumulate(polygon.begin(), polygon.end(), Vec3d(0.0, 0.0, 0.0));
|
||||
centroid /= (double)polygon.size();
|
||||
for (auto& vertex : polygon)
|
||||
vertex = 0.9f*vertex + 0.1f*centroid;
|
||||
|
||||
// Polygon is now simple and convex, we'll round the corners to make them look nicer.
|
||||
// The algorithm takes a vertex, calculates middles of respective sides and moves the vertex
|
||||
// towards their average (controlled by 'aggressivity'). This is repeated k times.
|
||||
// In next iterations, the neighbours are not always taken at the middle (to increase the
|
||||
// rounding effect at the corners, where we need it most).
|
||||
const unsigned int k = 10; // number of iterations
|
||||
const float aggressivity = 0.2f; // agressivity
|
||||
const unsigned int N = polygon.size();
|
||||
std::vector<std::pair<unsigned int, unsigned int>> neighbours;
|
||||
if (k != 0) {
|
||||
Pointf3s points_out(2*k*N); // vector long enough to store the future vertices
|
||||
for (unsigned int j=0; j<N; ++j) {
|
||||
points_out[j*2*k] = polygon[j];
|
||||
neighbours.push_back(std::make_pair((int)(j*2*k-k) < 0 ? (N-1)*2*k+k : j*2*k-k, j*2*k+k));
|
||||
}
|
||||
|
||||
for (unsigned int i=0; i<k; ++i) {
|
||||
// Calculate middle of each edge so that neighbours points to something useful:
|
||||
for (unsigned int j=0; j<N; ++j)
|
||||
if (i==0)
|
||||
points_out[j*2*k+k] = 0.5f * (points_out[j*2*k] + points_out[j==N-1 ? 0 : (j+1)*2*k]);
|
||||
else {
|
||||
float r = 0.2+0.3/(k-1)*i; // the neighbours are not always taken in the middle
|
||||
points_out[neighbours[j].first] = r*points_out[j*2*k] + (1-r) * points_out[neighbours[j].first-1];
|
||||
points_out[neighbours[j].second] = r*points_out[j*2*k] + (1-r) * points_out[neighbours[j].second+1];
|
||||
}
|
||||
// Now we have a triangle and valid neighbours, we can do an iteration:
|
||||
for (unsigned int j=0; j<N; ++j)
|
||||
points_out[2*k*j] = (1-aggressivity) * points_out[2*k*j] +
|
||||
aggressivity*0.5f*(points_out[neighbours[j].first] + points_out[neighbours[j].second]);
|
||||
|
||||
for (auto& n : neighbours) {
|
||||
++n.first;
|
||||
--n.second;
|
||||
}
|
||||
}
|
||||
polygon = points_out; // replace the coarse polygon with the smooth one that we just created
|
||||
}
|
||||
|
||||
// Transform back to 3D;
|
||||
for (auto& b : polygon) {
|
||||
b(0) += 0.1f; // raise a bit above the object surface to avoid flickering
|
||||
b = super_rotation(Vec3d::UnitY(), -angle_y, b);
|
||||
b = super_rotation(Vec3d::UnitZ(), -angle_z, b);
|
||||
}
|
||||
}
|
||||
|
||||
// We'll sort the planes by area and only keep the 255 largest ones (because of the picking pass limitations):
|
||||
std::sort(m_planes.rbegin(), m_planes.rend(), [](const PlaneData& a, const PlaneData& b) { return a.area < b.area; });
|
||||
m_planes.resize(std::min((int)m_planes.size(), 255));
|
||||
|
||||
// Planes are finished - let's save what we calculated it from:
|
||||
m_source_data.bounding_boxes.clear();
|
||||
for (const auto& vol : m_model_object->volumes)
|
||||
m_source_data.bounding_boxes.push_back(vol->get_convex_hull().bounding_box());
|
||||
m_source_data.scaling_factor = m_model_object->instances.front()->scaling_factor;
|
||||
m_source_data.rotation = m_model_object->instances.front()->rotation;
|
||||
const float* first_vertex = m_model_object->volumes.front()->get_convex_hull().first_vertex();
|
||||
m_source_data.mesh_first_point = Vec3d((double)first_vertex[0], (double)first_vertex[1], (double)first_vertex[2]);
|
||||
}
|
||||
|
||||
// Check if the bounding boxes of each volume's convex hull is the same as before
|
||||
// and that scaling and rotation has not changed. In that case we don't have to recalculate it.
|
||||
bool GLGizmoFlatten::is_plane_update_necessary() const
|
||||
{
|
||||
if (m_state != On || !m_model_object || m_model_object->instances.empty())
|
||||
return false;
|
||||
|
||||
if (m_model_object->volumes.size() != m_source_data.bounding_boxes.size()
|
||||
|| m_model_object->instances.front()->scaling_factor != m_source_data.scaling_factor
|
||||
|| m_model_object->instances.front()->rotation != m_source_data.rotation)
|
||||
return true;
|
||||
|
||||
// now compare the bounding boxes:
|
||||
for (unsigned int i=0; i<m_model_object->volumes.size(); ++i)
|
||||
if (m_model_object->volumes[i]->get_convex_hull().bounding_box() != m_source_data.bounding_boxes[i])
|
||||
return true;
|
||||
|
||||
const float* first_vertex = m_model_object->volumes.front()->get_convex_hull().first_vertex();
|
||||
Vec3d first_point((double)first_vertex[0], (double)first_vertex[1], (double)first_vertex[2]);
|
||||
if (first_point != m_source_data.mesh_first_point)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Vec3d GLGizmoFlatten::get_flattening_normal() const {
|
||||
Transform3d m = Transform3d::Identity();
|
||||
m.rotate(Eigen::AngleAxisd(-m_model_object->instances.front()->rotation, Vec3d::UnitZ()));
|
||||
Vec3d normal = m * m_normal;
|
||||
m_normal = Vec3d::Zero();
|
||||
return normal;
|
||||
}
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace Slic3r {
|
|||
|
||||
class BoundingBoxf3;
|
||||
class Linef3;
|
||||
class ModelObject;
|
||||
|
||||
namespace GUI {
|
||||
|
||||
|
|
@ -74,7 +75,6 @@ protected:
|
|||
float m_drag_color[3];
|
||||
float m_highlight_color[3];
|
||||
mutable std::vector<Grabber> m_grabbers;
|
||||
bool m_is_container;
|
||||
|
||||
public:
|
||||
explicit GLGizmoBase(GLCanvas3D& parent);
|
||||
|
|
@ -312,6 +312,54 @@ private:
|
|||
double calc_ratio(unsigned int preferred_plane_id, const Linef3& mouse_ray, const Vec3d& center) const;
|
||||
};
|
||||
|
||||
class GLGizmoFlatten : public GLGizmoBase
|
||||
{
|
||||
// This gizmo does not use grabbers. The m_hover_id relates to polygon managed by the class itself.
|
||||
|
||||
private:
|
||||
mutable Vec3d m_normal;
|
||||
|
||||
struct PlaneData {
|
||||
std::vector<Vec3d> vertices;
|
||||
Vec3d normal;
|
||||
float area;
|
||||
};
|
||||
struct SourceDataSummary {
|
||||
std::vector<BoundingBoxf3> bounding_boxes; // bounding boxes of convex hulls of individual volumes
|
||||
float scaling_factor;
|
||||
float rotation;
|
||||
Vec3d mesh_first_point;
|
||||
};
|
||||
|
||||
// This holds information to decide whether recalculation is necessary:
|
||||
SourceDataSummary m_source_data;
|
||||
|
||||
std::vector<PlaneData> m_planes;
|
||||
std::vector<Vec2d> m_instances_positions;
|
||||
mutable std::unique_ptr<Vec3d> m_center = nullptr;
|
||||
const ModelObject* m_model_object = nullptr;
|
||||
|
||||
void update_planes();
|
||||
bool is_plane_update_necessary() const;
|
||||
|
||||
public:
|
||||
explicit GLGizmoFlatten(GLCanvas3D& parent);
|
||||
|
||||
void set_flattening_data(const ModelObject* model_object);
|
||||
Vec3d get_flattening_normal() const;
|
||||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual void on_start_dragging();
|
||||
virtual void on_update(const Linef3& mouse_ray) {}
|
||||
virtual void on_render(const BoundingBoxf3& box) const;
|
||||
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
|
||||
virtual void on_set_state() {
|
||||
if (m_state == On && is_plane_update_necessary())
|
||||
update_planes();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
||||
|
|
|
|||
|
|
@ -313,13 +313,12 @@ const std::vector<std::string>& Preset::filament_options()
|
|||
{
|
||||
static std::vector<std::string> s_opts {
|
||||
"filament_colour", "filament_diameter", "filament_type", "filament_soluble", "filament_notes", "filament_max_volumetric_speed",
|
||||
"extrusion_multiplier", "filament_density", "filament_cost",
|
||||
"filament_loading_speed", "filament_load_time", "filament_unloading_speed", "filament_unload_time", "filament_toolchange_delay",
|
||||
"filament_cooling_moves", "filament_cooling_initial_speed", "filament_cooling_final_speed", "filament_ramming_parameters",
|
||||
"filament_minimal_purge_on_wipe_tower", "temperature", "first_layer_temperature", "bed_temperature", "first_layer_bed_temperature",
|
||||
"fan_always_on", "cooling", "min_fan_speed", "max_fan_speed", "bridge_fan_speed", "disable_fan_first_layers", "fan_below_layer_time",
|
||||
"slowdown_below_layer_time", "min_print_speed", "start_filament_gcode", "end_filament_gcode","compatible_printers", "compatible_printers_condition",
|
||||
"inherits"
|
||||
"extrusion_multiplier", "filament_density", "filament_cost", "filament_loading_speed", "filament_loading_speed_start", "filament_load_time",
|
||||
"filament_unloading_speed", "filament_unloading_speed_start", "filament_unload_time", "filament_toolchange_delay", "filament_cooling_moves",
|
||||
"filament_cooling_initial_speed", "filament_cooling_final_speed", "filament_ramming_parameters", "filament_minimal_purge_on_wipe_tower",
|
||||
"temperature", "first_layer_temperature", "bed_temperature", "first_layer_bed_temperature", "fan_always_on", "cooling", "min_fan_speed",
|
||||
"max_fan_speed", "bridge_fan_speed", "disable_fan_first_layers", "fan_below_layer_time", "slowdown_below_layer_time", "min_print_speed",
|
||||
"start_filament_gcode", "end_filament_gcode","compatible_printers", "compatible_printers_condition", "inherits"
|
||||
};
|
||||
return s_opts;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1290,7 +1290,9 @@ void TabFilament::build()
|
|||
optgroup->append_line(line);
|
||||
|
||||
optgroup = page->new_optgroup(_(L("Toolchange parameters with single extruder MM printers")));
|
||||
optgroup->append_single_option_line("filament_loading_speed");
|
||||
optgroup->append_single_option_line("filament_loading_speed_start");
|
||||
optgroup->append_single_option_line("filament_loading_speed");
|
||||
optgroup->append_single_option_line("filament_unloading_speed_start");
|
||||
optgroup->append_single_option_line("filament_unloading_speed");
|
||||
optgroup->append_single_option_line("filament_load_time");
|
||||
optgroup->append_single_option_line("filament_unload_time");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue