Merge remote-tracking branch 'origin/et_6dof_camera'

This commit is contained in:
Enrico Turri 2020-01-17 15:01:24 +01:00
commit 8840cb0905
14 changed files with 360 additions and 72 deletions

View File

@ -56,5 +56,7 @@
// Enable configurable paths export (fullpath or not) to 3mf and amf // Enable configurable paths export (fullpath or not) to 3mf and amf
#define ENABLE_CONFIGURABLE_PATHS_EXPORT_TO_3MF_AND_AMF (1 && ENABLE_2_2_0_BETA1) #define ENABLE_CONFIGURABLE_PATHS_EXPORT_TO_3MF_AND_AMF (1 && ENABLE_2_2_0_BETA1)
// Enable 6 degrees of freedom camera
#define ENABLE_6DOF_CAMERA (1 && ENABLE_2_2_0_BETA1)
#endif // _technologies_h_ #endif // _technologies_h_

View File

@ -260,7 +260,11 @@ Point Bed3D::point_projection(const Point& point) const
return m_polygon.point_projection(point); return m_polygon.point_projection(point);
} }
#if ENABLE_6DOF_CAMERA
void Bed3D::render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes) const
#else
void Bed3D::render(GLCanvas3D& canvas, float theta, float scale_factor, bool show_axes) const void Bed3D::render(GLCanvas3D& canvas, float theta, float scale_factor, bool show_axes) const
#endif // ENABLE_6DOF_CAMERA
{ {
m_scale_factor = scale_factor; m_scale_factor = scale_factor;
@ -271,9 +275,15 @@ void Bed3D::render(GLCanvas3D& canvas, float theta, float scale_factor, bool sho
switch (m_type) switch (m_type)
{ {
#if ENABLE_6DOF_CAMERA
case System: { render_system(canvas, bottom); break; }
default:
case Custom: { render_custom(canvas, bottom); break; }
#else
case System: { render_system(canvas, theta > 90.0f); break; } case System: { render_system(canvas, theta > 90.0f); break; }
default: default:
case Custom: { render_custom(canvas, theta > 90.0f); break; } case Custom: { render_custom(canvas, theta > 90.0f); break; }
#endif // ENABLE_6DOF_CAMERA
} }
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));

View File

@ -107,7 +107,11 @@ public:
bool contains(const Point& point) const; bool contains(const Point& point) const;
Point point_projection(const Point& point) const; Point point_projection(const Point& point) const;
#if ENABLE_6DOF_CAMERA
void render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes) const;
#else
void render(GLCanvas3D& canvas, float theta, float scale_factor, bool show_axes) const; void render(GLCanvas3D& canvas, float theta, float scale_factor, bool show_axes) const;
#endif // ENABLE_6DOF_CAMERA
private: private:
void calc_bounding_boxes() const; void calc_bounding_boxes() const;

View File

@ -87,6 +87,11 @@ void AppConfig::set_defaults()
if (get("use_perspective_camera").empty()) if (get("use_perspective_camera").empty())
set("use_perspective_camera", "1"); set("use_perspective_camera", "1");
#if ENABLE_6DOF_CAMERA
if (get("use_free_camera").empty())
set("use_free_camera", "0");
#endif // ENABLE_6DOF_CAMERA
// Remove legacy window positions/sizes // Remove legacy window positions/sizes
erase("", "main_frame_maximized"); erase("", "main_frame_maximized");
erase("", "main_frame_pos"); erase("", "main_frame_pos");

View File

@ -6,6 +6,11 @@
#endif // !ENABLE_THUMBNAIL_GENERATOR #endif // !ENABLE_THUMBNAIL_GENERATOR
#include "GUI_App.hpp" #include "GUI_App.hpp"
#include "AppConfig.hpp" #include "AppConfig.hpp"
#if ENABLE_CAMERA_STATISTICS
#if ENABLE_6DOF_CAMERA
#include "Mouse3DController.hpp"
#endif // ENABLE_6DOF_CAMERA
#endif // ENABLE_CAMERA_STATISTICS
#include <GL/glew.h> #include <GL/glew.h>
@ -34,18 +39,27 @@ double Camera::FrustrumZMargin = 10.0;
double Camera::MaxFovDeg = 60.0; double Camera::MaxFovDeg = 60.0;
Camera::Camera() Camera::Camera()
#if ENABLE_6DOF_CAMERA
: requires_zoom_to_bed(false)
#else
: phi(45.0f) : phi(45.0f)
, requires_zoom_to_bed(false) , requires_zoom_to_bed(false)
, inverted_phi(false) , inverted_phi(false)
#endif // ENABLE_6DOF_CAMERA
, m_type(Perspective) , m_type(Perspective)
, m_target(Vec3d::Zero()) , m_target(Vec3d::Zero())
#if !ENABLE_6DOF_CAMERA
, m_theta(45.0f) , m_theta(45.0f)
#endif // !ENABLE_6DOF_CAMERA
, m_zoom(1.0) , m_zoom(1.0)
, m_distance(DefaultDistance) , m_distance(DefaultDistance)
, m_gui_scale(1.0) , m_gui_scale(1.0)
, m_view_matrix(Transform3d::Identity()) , m_view_matrix(Transform3d::Identity())
, m_projection_matrix(Transform3d::Identity()) , m_projection_matrix(Transform3d::Identity())
{ {
#if ENABLE_6DOF_CAMERA
set_default_orientation();
#endif // ENABLE_6DOF_CAMERA
} }
std::string Camera::get_type_as_string() const std::string Camera::get_type_as_string() const
@ -91,6 +105,9 @@ void Camera::select_next_type()
void Camera::set_target(const Vec3d& target) void Camera::set_target(const Vec3d& target)
{ {
#if ENABLE_6DOF_CAMERA
translate_world(target - m_target);
#else
BoundingBoxf3 test_box = m_scene_box; BoundingBoxf3 test_box = m_scene_box;
test_box.translate(-m_scene_box.center()); test_box.translate(-m_scene_box.center());
// We may let this factor be customizable // We may let this factor be customizable
@ -101,8 +118,10 @@ void Camera::set_target(const Vec3d& target)
m_target(0) = clamp(test_box.min(0), test_box.max(0), target(0)); m_target(0) = clamp(test_box.min(0), test_box.max(0), target(0));
m_target(1) = clamp(test_box.min(1), test_box.max(1), target(1)); m_target(1) = clamp(test_box.min(1), test_box.max(1), target(1));
m_target(2) = clamp(test_box.min(2), test_box.max(2), target(2)); m_target(2) = clamp(test_box.min(2), test_box.max(2), target(2));
#endif // ENABLE_6DOF_CAMERA
} }
#if !ENABLE_6DOF_CAMERA
void Camera::set_theta(float theta, bool apply_limit) void Camera::set_theta(float theta, bool apply_limit)
{ {
if (apply_limit) if (apply_limit)
@ -114,6 +133,7 @@ void Camera::set_theta(float theta, bool apply_limit)
m_theta += 360.0f; m_theta += 360.0f;
} }
} }
#endif // !ENABLE_6DOF_CAMERA
void Camera::update_zoom(double delta_zoom) void Camera::update_zoom(double delta_zoom)
{ {
@ -123,14 +143,33 @@ void Camera::update_zoom(double delta_zoom)
void Camera::set_zoom(double zoom) void Camera::set_zoom(double zoom)
{ {
// Don't allow to zoom too far outside the scene. // Don't allow to zoom too far outside the scene.
double zoom_min = calc_zoom_to_bounding_box_factor(m_scene_box, (int)m_viewport[2], (int)m_viewport[3]); double zoom_min = min_zoom();
if (zoom_min > 0.0) if (zoom_min > 0.0)
zoom = std::max(zoom, zoom_min * 0.7); zoom = std::max(zoom, zoom_min);
// Don't allow to zoom too close to the scene. // Don't allow to zoom too close to the scene.
m_zoom = std::min(zoom, 100.0); m_zoom = std::min(zoom, max_zoom());
} }
#if ENABLE_6DOF_CAMERA
void Camera::select_view(const std::string& direction)
{
if (direction == "iso")
set_default_orientation();
else if (direction == "left")
m_view_matrix = look_at(m_target - m_distance * Vec3d::UnitX(), m_target, Vec3d::UnitZ());
else if (direction == "right")
m_view_matrix = look_at(m_target + m_distance * Vec3d::UnitX(), m_target, Vec3d::UnitZ());
else if (direction == "top")
m_view_matrix = look_at(m_target + m_distance * Vec3d::UnitZ(), m_target, Vec3d::UnitY());
else if (direction == "bottom")
m_view_matrix = look_at(m_target - m_distance * Vec3d::UnitZ(), m_target, -Vec3d::UnitY());
else if (direction == "front")
m_view_matrix = look_at(m_target - m_distance * Vec3d::UnitY(), m_target, Vec3d::UnitZ());
else if (direction == "rear")
m_view_matrix = look_at(m_target + m_distance * Vec3d::UnitY(), m_target, Vec3d::UnitZ());
}
#else
bool Camera::select_view(const std::string& direction) bool Camera::select_view(const std::string& direction)
{ {
const float* dir_vec = nullptr; const float* dir_vec = nullptr;
@ -159,6 +198,7 @@ bool Camera::select_view(const std::string& direction)
else else
return false; return false;
} }
#endif // ENABLE_6DOF_CAMERA
double Camera::get_fov() const double Camera::get_fov() const
{ {
@ -180,20 +220,26 @@ void Camera::apply_viewport(int x, int y, unsigned int w, unsigned int h) const
void Camera::apply_view_matrix() const void Camera::apply_view_matrix() const
{ {
#if !ENABLE_6DOF_CAMERA
double theta_rad = Geometry::deg2rad(-(double)m_theta); double theta_rad = Geometry::deg2rad(-(double)m_theta);
double phi_rad = Geometry::deg2rad((double)phi); double phi_rad = Geometry::deg2rad((double)phi);
double sin_theta = ::sin(theta_rad); double sin_theta = ::sin(theta_rad);
Vec3d camera_pos = m_target + m_distance * Vec3d(sin_theta * ::sin(phi_rad), sin_theta * ::cos(phi_rad), ::cos(theta_rad)); Vec3d camera_pos = m_target + m_distance * Vec3d(sin_theta * ::sin(phi_rad), sin_theta * ::cos(phi_rad), ::cos(theta_rad));
#endif // !ENABLE_6DOF_CAMERA
glsafe(::glMatrixMode(GL_MODELVIEW)); glsafe(::glMatrixMode(GL_MODELVIEW));
glsafe(::glLoadIdentity()); glsafe(::glLoadIdentity());
#if ENABLE_6DOF_CAMERA
glsafe(::glMultMatrixd(m_view_matrix.data()));
#else
glsafe(::glRotatef(-m_theta, 1.0f, 0.0f, 0.0f)); // pitch glsafe(::glRotatef(-m_theta, 1.0f, 0.0f, 0.0f)); // pitch
glsafe(::glRotatef(phi, 0.0f, 0.0f, 1.0f)); // yaw glsafe(::glRotatef(phi, 0.0f, 0.0f, 1.0f)); // yaw
glsafe(::glTranslated(-camera_pos(0), -camera_pos(1), -camera_pos(2))); glsafe(::glTranslated(-camera_pos(0), -camera_pos(1), -camera_pos(2)));
glsafe(::glGetDoublev(GL_MODELVIEW_MATRIX, m_view_matrix.data())); glsafe(::glGetDoublev(GL_MODELVIEW_MATRIX, m_view_matrix.data()));
#endif // ENABLE_6DOF_CAMERA
} }
void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double far_z) const void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double far_z) const
@ -300,7 +346,11 @@ void Camera::zoom_to_box(const BoundingBoxf3& box, int canvas_w, int canvas_h)
{ {
m_zoom = zoom; m_zoom = zoom;
// center view around box center // center view around box center
#if ENABLE_6DOF_CAMERA
set_target(box.center());
#else
m_target = box.center(); m_target = box.center();
#endif // ENABLE_6DOF_CAMERA
} }
} }
@ -313,7 +363,11 @@ void Camera::zoom_to_volumes(const GLVolumePtrs& volumes, int canvas_w, int canv
{ {
m_zoom = zoom; m_zoom = zoom;
// center view around the calculated center // center view around the calculated center
#if ENABLE_6DOF_CAMERA
set_target(center);
#else
m_target = center; m_target = center;
#endif // ENABLE_6DOF_CAMERA
} }
} }
#endif // ENABLE_THUMBNAIL_GENERATOR #endif // ENABLE_THUMBNAIL_GENERATOR
@ -325,6 +379,12 @@ void Camera::debug_render() const
imgui.begin(std::string("Camera statistics"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); imgui.begin(std::string("Camera statistics"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
std::string type = get_type_as_string(); std::string type = get_type_as_string();
#if ENABLE_6DOF_CAMERA
if (wxGetApp().plater()->get_mouse3d_controller().is_running() || (wxGetApp().app_config->get("use_free_camera") == "1"))
type += "/free";
else
type += "/constrained";
#endif // ENABLE_6DOF_CAMERA
Vec3f position = get_position().cast<float>(); Vec3f position = get_position().cast<float>();
Vec3f target = m_target.cast<float>(); Vec3f target = m_target.cast<float>();
float distance = (float)get_distance(); float distance = (float)get_distance();
@ -360,6 +420,50 @@ void Camera::debug_render() const
} }
#endif // ENABLE_CAMERA_STATISTICS #endif // ENABLE_CAMERA_STATISTICS
#if ENABLE_6DOF_CAMERA
void Camera::translate_world(const Vec3d& displacement)
{
Vec3d new_target = validate_target(m_target + displacement);
Vec3d new_displacement = new_target - m_target;
if (!new_displacement.isApprox(Vec3d::Zero()))
{
m_target += new_displacement;
m_view_matrix.translate(-new_displacement);
}
}
void Camera::rotate_on_sphere(double delta_azimut_rad, double delta_zenit_rad)
{
Vec3d target = m_target;
translate_world(-target);
m_view_matrix.rotate(Eigen::AngleAxisd(delta_zenit_rad, get_dir_right()));
m_view_matrix.rotate(Eigen::AngleAxisd(delta_azimut_rad, Vec3d::UnitZ()));
translate_world(target);
}
void Camera::rotate_local_around_target(const Vec3d& rotation_rad)
{
rotate_local_around_pivot(rotation_rad, m_target);
}
void Camera::rotate_local_around_pivot(const Vec3d& rotation_rad, const Vec3d& pivot)
{
// we use a copy of the pivot because a reference to the current m_target may be passed in (see i.e. rotate_local_around_target())
// and m_target is modified by the translate_world() calls
Vec3d center = pivot;
translate_world(-center);
m_view_matrix.rotate(Eigen::AngleAxisd(rotation_rad(0), get_dir_right()));
m_view_matrix.rotate(Eigen::AngleAxisd(rotation_rad(1), get_dir_up()));
m_view_matrix.rotate(Eigen::AngleAxisd(rotation_rad(2), get_dir_forward()));
translate_world(center);
}
double Camera::min_zoom() const
{
return 0.7 * calc_zoom_to_bounding_box_factor(m_scene_box, (int)m_viewport[2], (int)m_viewport[3]);
}
#endif // ENABLE_6DOF_CAMERA
std::pair<double, double> Camera::calc_tight_frustrum_zs_around(const BoundingBoxf3& box) const std::pair<double, double> Camera::calc_tight_frustrum_zs_around(const BoundingBoxf3& box) const
{ {
std::pair<double, double> ret; std::pair<double, double> ret;
@ -540,6 +644,63 @@ void Camera::set_distance(double distance) const
apply_view_matrix(); apply_view_matrix();
} }
#if ENABLE_6DOF_CAMERA
Transform3d Camera::look_at(const Vec3d& position, const Vec3d& target, const Vec3d& up) const
{
Vec3d unit_z = (position - target).normalized();
Vec3d unit_x = up.cross(unit_z).normalized();
Vec3d unit_y = unit_z.cross(unit_x).normalized();
Transform3d matrix;
matrix(0, 0) = unit_x(0);
matrix(0, 1) = unit_x(1);
matrix(0, 2) = unit_x(2);
matrix(0, 3) = -unit_x.dot(position);
matrix(1, 0) = unit_y(0);
matrix(1, 1) = unit_y(1);
matrix(1, 2) = unit_y(2);
matrix(1, 3) = -unit_y.dot(position);
matrix(2, 0) = unit_z(0);
matrix(2, 1) = unit_z(1);
matrix(2, 2) = unit_z(2);
matrix(2, 3) = -unit_z.dot(position);
matrix(3, 0) = 0.0;
matrix(3, 1) = 0.0;
matrix(3, 2) = 0.0;
matrix(3, 3) = 1.0;
return matrix;
}
void Camera::set_default_orientation()
{
double theta_rad = Geometry::deg2rad(-45.0);
double phi_rad = Geometry::deg2rad(45.0);
double sin_theta = ::sin(theta_rad);
Vec3d camera_pos = m_target + m_distance * Vec3d(sin_theta * ::sin(phi_rad), sin_theta * ::cos(phi_rad), ::cos(theta_rad));
m_view_matrix = Transform3d::Identity();
m_view_matrix.rotate(Eigen::AngleAxisd(theta_rad, Vec3d::UnitX())).rotate(Eigen::AngleAxisd(phi_rad, Vec3d::UnitZ())).translate(-camera_pos);
}
Vec3d Camera::validate_target(const Vec3d& target) const
{
BoundingBoxf3 test_box = m_scene_box;
test_box.translate(-m_scene_box.center());
// We may let this factor be customizable
static const double ScaleFactor = 1.5;
test_box.scale(ScaleFactor);
test_box.translate(m_scene_box.center());
return Vec3d(std::clamp(target(0), test_box.min(0), test_box.max(0)),
std::clamp(target(1), test_box.min(1), test_box.max(1)),
std::clamp(target(2), test_box.min(2), test_box.max(2)));
}
#endif // ENABLE_6DOF_CAMERA
} // GUI } // GUI
} // Slic3r } // Slic3r

View File

@ -30,21 +30,29 @@ struct Camera
Num_types Num_types
}; };
#if !ENABLE_6DOF_CAMERA
float phi; float phi;
bool requires_zoom_to_bed;
bool inverted_phi; bool inverted_phi;
#endif // !ENABLE_6DOF_CAMERA
bool requires_zoom_to_bed;
private: private:
EType m_type; EType m_type;
Vec3d m_target; Vec3d m_target;
#if !ENABLE_6DOF_CAMERA
float m_theta; float m_theta;
#endif // !ENABLE_6DOF_CAMERA
double m_zoom; double m_zoom;
// Distance between camera position and camera target measured along the camera Z axis // Distance between camera position and camera target measured along the camera Z axis
mutable double m_distance; mutable double m_distance;
mutable double m_gui_scale; mutable double m_gui_scale;
mutable std::array<int, 4> m_viewport; mutable std::array<int, 4> m_viewport;
#if ENABLE_6DOF_CAMERA
Transform3d m_view_matrix;
#else
mutable Transform3d m_view_matrix; mutable Transform3d m_view_matrix;
#endif // ENABLE_6DOF_CAMERA
mutable Transform3d m_projection_matrix; mutable Transform3d m_projection_matrix;
mutable std::pair<double, double> m_frustrum_zs; mutable std::pair<double, double> m_frustrum_zs;
@ -66,17 +74,24 @@ public:
double get_distance() const { return m_distance; } double get_distance() const { return m_distance; }
double get_gui_scale() const { return m_gui_scale; } double get_gui_scale() const { return m_gui_scale; }
#if !ENABLE_6DOF_CAMERA
float get_theta() const { return m_theta; } float get_theta() const { return m_theta; }
void set_theta(float theta, bool apply_limit); void set_theta(float theta, bool apply_limit);
#endif // !ENABLE_6DOF_CAMERA
double get_zoom() const { return m_zoom; } double get_zoom() const { return m_zoom; }
double get_inv_zoom() const { assert(m_zoom != 0.0); return 1.0 / m_zoom; }
void update_zoom(double delta_zoom); void update_zoom(double delta_zoom);
void set_zoom(double zoom); void set_zoom(double zoom);
const BoundingBoxf3& get_scene_box() const { return m_scene_box; } const BoundingBoxf3& get_scene_box() const { return m_scene_box; }
void set_scene_box(const BoundingBoxf3& box) { m_scene_box = box; } void set_scene_box(const BoundingBoxf3& box) { m_scene_box = box; }
#if ENABLE_6DOF_CAMERA
void select_view(const std::string& direction);
#else
bool select_view(const std::string& direction); bool select_view(const std::string& direction);
#endif // ENABLE_6DOF_CAMERA
const std::array<int, 4>& get_viewport() const { return m_viewport; } const std::array<int, 4>& get_viewport() const { return m_viewport; }
const Transform3d& get_view_matrix() const { return m_view_matrix; } const Transform3d& get_view_matrix() const { return m_view_matrix; }
@ -110,6 +125,27 @@ public:
void debug_render() const; void debug_render() const;
#endif // ENABLE_CAMERA_STATISTICS #endif // ENABLE_CAMERA_STATISTICS
#if ENABLE_6DOF_CAMERA
// translate the camera in world space
void translate_world(const Vec3d& displacement);
// rotate the camera on a sphere having center == m_target and radius == m_distance
// using the given variations of spherical coordinates
void rotate_on_sphere(double delta_azimut_rad, double delta_zenit_rad);
// rotate the camera around three axes parallel to the camera local axes and passing through m_target
void rotate_local_around_target(const Vec3d& rotation_rad);
// rotate the camera around three axes parallel to the camera local axes and passing through the given pivot point
void rotate_local_around_pivot(const Vec3d& rotation_rad, const Vec3d& pivot);
// returns true if the camera z axis (forward) is pointing in the negative direction of the world z axis
bool is_looking_downward() const { return get_dir_forward().dot(Vec3d::UnitZ()) < 0.0; }
double max_zoom() const { return 100.0; }
double min_zoom() const;
#endif // ENABLE_6DOF_CAMERA
private: private:
// returns tight values for nearZ and farZ plane around the given bounding box // returns tight values for nearZ and farZ plane around the given bounding box
// the camera MUST be outside of the bounding box in eye coordinate of the given box // the camera MUST be outside of the bounding box in eye coordinate of the given box
@ -121,6 +157,12 @@ private:
double calc_zoom_to_bounding_box_factor(const BoundingBoxf3& box, int canvas_w, int canvas_h) const; double calc_zoom_to_bounding_box_factor(const BoundingBoxf3& box, int canvas_w, int canvas_h) const;
#endif // ENABLE_THUMBNAIL_GENERATOR #endif // ENABLE_THUMBNAIL_GENERATOR
void set_distance(double distance) const; void set_distance(double distance) const;
#if ENABLE_6DOF_CAMERA
Transform3d look_at(const Vec3d& position, const Vec3d& target, const Vec3d& up) const;
void set_default_orientation();
Vec3d validate_target(const Vec3d& target) const;
#endif // ENABLE_6DOF_CAMERA
}; };
} // GUI } // GUI

View File

@ -354,8 +354,7 @@ Rect GLCanvas3D::LayersEditing::get_bar_rect_viewport(const GLCanvas3D& canvas)
float half_w = 0.5f * (float)cnv_size.get_width(); float half_w = 0.5f * (float)cnv_size.get_width();
float half_h = 0.5f * (float)cnv_size.get_height(); float half_h = 0.5f * (float)cnv_size.get_height();
float zoom = (float)canvas.get_camera().get_zoom(); float inv_zoom = (float)canvas.get_camera().get_inv_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
return Rect((half_w - thickness_bar_width(canvas)) * inv_zoom, half_h * inv_zoom, half_w * inv_zoom, -half_h * inv_zoom); return Rect((half_w - thickness_bar_width(canvas)) * inv_zoom, half_h * inv_zoom, half_w * inv_zoom, -half_h * inv_zoom);
} }
@ -847,8 +846,7 @@ void GLCanvas3D::WarningTexture::render(const GLCanvas3D& canvas) const
if ((m_id > 0) && (m_original_width > 0) && (m_original_height > 0) && (m_width > 0) && (m_height > 0)) if ((m_id > 0) && (m_original_width > 0) && (m_original_height > 0) && (m_width > 0) && (m_height > 0))
{ {
const Size& cnv_size = canvas.get_canvas_size(); const Size& cnv_size = canvas.get_canvas_size();
float zoom = (float)canvas.get_camera().get_zoom(); float inv_zoom = (float)canvas.get_camera().get_inv_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float left = (-0.5f * (float)m_original_width) * inv_zoom; float left = (-0.5f * (float)m_original_width) * inv_zoom;
float top = (-0.5f * (float)cnv_size.get_height() + (float)m_original_height + 2.0f) * inv_zoom; float top = (-0.5f * (float)cnv_size.get_height() + (float)m_original_height + 2.0f) * inv_zoom;
float right = left + (float)m_original_width * inv_zoom; float right = left + (float)m_original_width * inv_zoom;
@ -1210,8 +1208,7 @@ void GLCanvas3D::LegendTexture::render(const GLCanvas3D& canvas) const
if ((m_id > 0) && (m_original_width > 0) && (m_original_height > 0) && (m_width > 0) && (m_height > 0)) if ((m_id > 0) && (m_original_width > 0) && (m_original_height > 0) && (m_width > 0) && (m_height > 0))
{ {
const Size& cnv_size = canvas.get_canvas_size(); const Size& cnv_size = canvas.get_canvas_size();
float zoom = (float)canvas.get_camera().get_zoom(); float inv_zoom = (float)canvas.get_camera().get_inv_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float left = (-0.5f * (float)cnv_size.get_width()) * inv_zoom; float left = (-0.5f * (float)cnv_size.get_width()) * inv_zoom;
float top = (0.5f * (float)cnv_size.get_height()) * inv_zoom; float top = (0.5f * (float)cnv_size.get_height()) * inv_zoom;
float right = left + (float)m_original_width * inv_zoom; float right = left + (float)m_original_width * inv_zoom;
@ -1664,8 +1661,14 @@ void GLCanvas3D::zoom_to_selection()
void GLCanvas3D::select_view(const std::string& direction) void GLCanvas3D::select_view(const std::string& direction)
{ {
#if ENABLE_6DOF_CAMERA
m_camera.select_view(direction);
if (m_canvas != nullptr)
m_canvas->Refresh();
#else
if (m_camera.select_view(direction) && (m_canvas != nullptr)) if (m_camera.select_view(direction) && (m_canvas != nullptr))
m_canvas->Refresh(); m_canvas->Refresh();
#endif // ENABLE_6DOF_CAMERA
} }
void GLCanvas3D::update_volumes_colors_by_extruder() void GLCanvas3D::update_volumes_colors_by_extruder()
@ -1722,10 +1725,12 @@ void GLCanvas3D::render()
GLfloat position_top[4] = { -0.5f, -0.5f, 1.0f, 0.0f }; GLfloat position_top[4] = { -0.5f, -0.5f, 1.0f, 0.0f };
glsafe(::glLightfv(GL_LIGHT0, GL_POSITION, position_top)); glsafe(::glLightfv(GL_LIGHT0, GL_POSITION, position_top));
#if !ENABLE_6DOF_CAMERA
float theta = m_camera.get_theta(); float theta = m_camera.get_theta();
if (theta > 180.f) if (theta > 180.f)
// absolute value of the rotation // absolute value of the rotation
theta = 360.f - theta; theta = 360.f - theta;
#endif // !ENABLE_6DOF_CAMERA
wxGetApp().imgui()->new_frame(); wxGetApp().imgui()->new_frame();
@ -1750,7 +1755,11 @@ void GLCanvas3D::render()
_render_objects(); _render_objects();
_render_sla_slices(); _render_sla_slices();
_render_selection(); _render_selection();
#if ENABLE_6DOF_CAMERA
_render_bed(!m_camera.is_looking_downward(), true);
#else
_render_bed(theta, true); _render_bed(theta, true);
#endif // ENABLE_6DOF_CAMERA
#if ENABLE_RENDER_SELECTION_CENTER #if ENABLE_RENDER_SELECTION_CENTER
_render_selection_center(); _render_selection_center();
@ -3067,7 +3076,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
// we do not want to translate objects if the user just clicked on an object while pressing shift to remove it from the selection and then drag // we do not want to translate objects if the user just clicked on an object while pressing shift to remove it from the selection and then drag
if (m_selection.contains_volume(get_first_hover_volume_idx())) if (m_selection.contains_volume(get_first_hover_volume_idx()))
{ {
#if ENABLE_6DOF_CAMERA
if (std::abs(m_camera.get_dir_forward()(2)) < EPSILON)
#else
if (m_camera.get_theta() == 90.0f) if (m_camera.get_theta() == 90.0f)
#endif // ENABLE_6DOF_CAMERA
{ {
// side view -> move selected volumes orthogonally to camera view direction // side view -> move selected volumes orthogonally to camera view direction
Linef3 ray = mouse_ray(pos); Linef3 ray = mouse_ray(pos);
@ -3127,9 +3140,18 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
if (m_hover_volume_idxs.empty() && m_mouse.is_start_position_3D_defined()) if (m_hover_volume_idxs.empty() && m_mouse.is_start_position_3D_defined())
{ {
const Vec3d& orig = m_mouse.drag.start_position_3D; const Vec3d& orig = m_mouse.drag.start_position_3D;
#if ENABLE_6DOF_CAMERA
double x = Geometry::deg2rad(pos(0) - orig(0)) * (double)TRACKBALLSIZE;
double y = Geometry::deg2rad(pos(1) - orig(1)) * (double)TRACKBALLSIZE;
if (wxGetApp().plater()->get_mouse3d_controller().is_running() || (wxGetApp().app_config->get("use_free_camera") == "1"))
m_camera.rotate_local_around_target(Vec3d(y, x, 0.0));
else
m_camera.rotate_on_sphere(x, y);
#else
float sign = m_camera.inverted_phi ? -1.0f : 1.0f; float sign = m_camera.inverted_phi ? -1.0f : 1.0f;
m_camera.phi += sign * ((float)pos(0) - (float)orig(0)) * TRACKBALLSIZE; m_camera.phi += sign * ((float)pos(0) - (float)orig(0)) * TRACKBALLSIZE;
m_camera.set_theta(m_camera.get_theta() - ((float)pos(1) - (float)orig(1)) * TRACKBALLSIZE, wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptSLA); m_camera.set_theta(m_camera.get_theta() - ((float)pos(1) - (float)orig(1)) * TRACKBALLSIZE, wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptSLA);
#endif // ENABLE_6DOF_CAMERA
m_dirty = true; m_dirty = true;
} }
m_mouse.drag.start_position_3D = Vec3d((double)pos(0), (double)pos(1), 0.0); m_mouse.drag.start_position_3D = Vec3d((double)pos(0), (double)pos(1), 0.0);
@ -3179,9 +3201,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
if (!evt.ShiftDown() && m_picking_enabled) if (!evt.ShiftDown() && m_picking_enabled)
deselect_all(); deselect_all();
} }
#if !ENABLE_6DOF_CAMERA
else if (evt.LeftUp() && m_mouse.dragging) else if (evt.LeftUp() && m_mouse.dragging)
// Flips X mouse deltas if bed is upside down // Flips X mouse deltas if bed is upside down
m_camera.inverted_phi = (m_camera.get_dir_up()(2) < 0.0); m_camera.inverted_phi = (m_camera.get_dir_up()(2) < 0.0);
#endif // !ENABLE_6DOF_CAMERA
else if (evt.RightUp()) else if (evt.RightUp())
{ {
m_mouse.position = pos.cast<double>(); m_mouse.position = pos.cast<double>();
@ -3786,6 +3810,9 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, bool
Camera camera; Camera camera;
camera.set_type(Camera::Ortho); camera.set_type(Camera::Ortho);
#if ENABLE_6DOF_CAMERA
camera.set_scene_box(scene_bounding_box());
#endif // ENABLE_6DOF_CAMERA
camera.zoom_to_volumes(visible_volumes, thumbnail_data.width, thumbnail_data.height); camera.zoom_to_volumes(visible_volumes, thumbnail_data.width, thumbnail_data.height);
camera.apply_viewport(0, 0, thumbnail_data.width, thumbnail_data.height); camera.apply_viewport(0, 0, thumbnail_data.width, thumbnail_data.height);
camera.apply_view_matrix(); camera.apply_view_matrix();
@ -3836,7 +3863,11 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, bool
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
if (show_bed) if (show_bed)
#if ENABLE_6DOF_CAMERA
_render_bed(!camera.is_looking_downward(), false);
#else
_render_bed(camera.get_theta(), false); _render_bed(camera.get_theta(), false);
#endif // ENABLE_6DOF_CAMERA
if (transparent_background) if (transparent_background)
glsafe(::glClearColor(1.0f, 1.0f, 1.0f, 1.0f)); glsafe(::glClearColor(1.0f, 1.0f, 1.0f, 1.0f));
@ -4789,8 +4820,7 @@ void GLCanvas3D::_render_main_toolbar() const
#endif // ENABLE_RETINA_GL #endif // ENABLE_RETINA_GL
Size cnv_size = get_canvas_size(); Size cnv_size = get_canvas_size();
float zoom = (float)m_camera.get_zoom(); float inv_zoom = (float)m_camera.get_inv_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float top = 0.5f * (float)cnv_size.get_height() * inv_zoom; float top = 0.5f * (float)cnv_size.get_height() * inv_zoom;
float left = -0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width()) * inv_zoom; float left = -0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width()) * inv_zoom;
@ -4816,8 +4846,7 @@ void GLCanvas3D::_render_undoredo_toolbar() const
#endif // ENABLE_RETINA_GL #endif // ENABLE_RETINA_GL
Size cnv_size = get_canvas_size(); Size cnv_size = get_canvas_size();
float zoom = (float)m_camera.get_zoom(); float inv_zoom = (float)m_camera.get_inv_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float top = 0.5f * (float)cnv_size.get_height() * inv_zoom; float top = 0.5f * (float)cnv_size.get_height() * inv_zoom;
float left = (m_main_toolbar.get_width() - 0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width())) * inv_zoom; float left = (m_main_toolbar.get_width() - 0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width())) * inv_zoom;
@ -4839,8 +4868,7 @@ void GLCanvas3D::_render_view_toolbar() const
#endif // ENABLE_RETINA_GL #endif // ENABLE_RETINA_GL
Size cnv_size = get_canvas_size(); Size cnv_size = get_canvas_size();
float zoom = (float)m_camera.get_zoom(); float inv_zoom = (float)m_camera.get_inv_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
// places the toolbar on the bottom-left corner of the 3d scene // places the toolbar on the bottom-left corner of the 3d scene
float top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar.get_height()) * inv_zoom; float top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar.get_height()) * inv_zoom;

View File

@ -69,8 +69,7 @@ namespace GUI {
return; return;
const Camera& camera = canvas.get_camera(); const Camera& camera = canvas.get_camera();
float zoom = (float)camera.get_zoom(); float inv_zoom = (float)camera.get_inv_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
Size cnv_size = canvas.get_canvas_size(); Size cnv_size = canvas.get_canvas_size();
float cnv_half_width = 0.5f * (float)cnv_size.get_width(); float cnv_half_width = 0.5f * (float)cnv_size.get_width();

View File

@ -653,8 +653,7 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC
{ {
// NB: mouse_pos is already scaled appropriately // NB: mouse_pos is already scaled appropriately
float zoom = (float)parent.get_camera().get_zoom(); float inv_zoom = (float)parent.get_camera().get_inv_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float factor = m_layout.scale * inv_zoom; float factor = m_layout.scale * inv_zoom;
Size cnv_size = parent.get_canvas_size(); Size cnv_size = parent.get_canvas_size();
@ -758,8 +757,7 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan
{ {
// NB: mouse_pos is already scaled appropriately // NB: mouse_pos is already scaled appropriately
float zoom = (float)parent.get_camera().get_zoom(); float inv_zoom = (float)parent.get_camera().get_inv_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float factor = m_layout.scale * inv_zoom; float factor = m_layout.scale * inv_zoom;
Size cnv_size = parent.get_canvas_size(); Size cnv_size = parent.get_canvas_size();
@ -875,8 +873,7 @@ int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3
{ {
// NB: mouse_pos is already scaled appropriately // NB: mouse_pos is already scaled appropriately
float zoom = (float)parent.get_camera().get_zoom(); float inv_zoom = (float)parent.get_camera().get_inv_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float factor = m_layout.scale * inv_zoom; float factor = m_layout.scale * inv_zoom;
Size cnv_size = parent.get_canvas_size(); Size cnv_size = parent.get_canvas_size();
@ -949,8 +946,7 @@ int GLToolbar::contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D&
{ {
// NB: mouse_pos is already scaled appropriately // NB: mouse_pos is already scaled appropriately
float zoom = (float)parent.get_camera().get_zoom(); float inv_zoom = (float)parent.get_camera().get_inv_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float factor = m_layout.scale * inv_zoom; float factor = m_layout.scale * inv_zoom;
Size cnv_size = parent.get_canvas_size(); Size cnv_size = parent.get_canvas_size();
@ -1102,8 +1098,7 @@ void GLToolbar::render_horizontal(const GLCanvas3D& parent) const
int tex_width = m_icons_texture.get_width(); int tex_width = m_icons_texture.get_width();
int tex_height = m_icons_texture.get_height(); int tex_height = m_icons_texture.get_height();
float zoom = (float)parent.get_camera().get_zoom(); float inv_zoom = (float)parent.get_camera().get_inv_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float factor = inv_zoom * m_layout.scale; float factor = inv_zoom * m_layout.scale;
float scaled_icons_size = m_layout.icons_size * factor; float scaled_icons_size = m_layout.icons_size * factor;
@ -1151,8 +1146,7 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent) const
int tex_width = m_icons_texture.get_width(); int tex_width = m_icons_texture.get_width();
int tex_height = m_icons_texture.get_height(); int tex_height = m_icons_texture.get_height();
float zoom = (float)parent.get_camera().get_zoom(); float inv_zoom = (float)parent.get_camera().get_inv_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float factor = inv_zoom * m_layout.scale; float factor = inv_zoom * m_layout.scale;
float scaled_icons_size = m_layout.icons_size * factor; float scaled_icons_size = m_layout.icons_size * factor;

View File

@ -850,7 +850,7 @@ void GLGizmosManager::do_render_overlay() const
float cnv_w = (float)m_parent.get_canvas_size().get_width(); float cnv_w = (float)m_parent.get_canvas_size().get_width();
float cnv_h = (float)m_parent.get_canvas_size().get_height(); float cnv_h = (float)m_parent.get_canvas_size().get_height();
float zoom = (float)m_parent.get_camera().get_zoom(); float zoom = (float)m_parent.get_camera().get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; float inv_zoom = (float)m_parent.get_camera().get_inv_zoom();
float height = get_scaled_total_height(); float height = get_scaled_total_height();
float width = get_scaled_total_width(); float width = get_scaled_total_width();

View File

@ -154,7 +154,8 @@ bool Mouse3DController::State::apply(Camera& camera)
{ {
const Vec3d& translation = m_translation.queue.front(); const Vec3d& translation = m_translation.queue.front();
#if ENABLE_3DCONNEXION_Y_AS_ZOOM #if ENABLE_3DCONNEXION_Y_AS_ZOOM
camera.set_target(camera.get_target() + m_translation_params.scale * (translation(0) * camera.get_dir_right() + translation(2) * camera.get_dir_up())); double zoom_factor = camera.min_zoom() / camera.get_zoom();
camera.set_target(camera.get_target() + zoom_factor * m_translation_params.scale * (translation(0) * camera.get_dir_right() + translation(2) * camera.get_dir_up()));
if (translation(1) != 0.0) if (translation(1) != 0.0)
camera.update_zoom(m_zoom_params.scale * translation(1) / std::abs(translation(1))); camera.update_zoom(m_zoom_params.scale * translation(1) / std::abs(translation(1)));
#else #else
@ -166,12 +167,17 @@ bool Mouse3DController::State::apply(Camera& camera)
if (has_rotation()) if (has_rotation())
{ {
#if ENABLE_6DOF_CAMERA
Vec3d rotation = (m_rotation_params.scale * m_rotation.queue.front()).cast<double>();
camera.rotate_local_around_target(Vec3d(Geometry::deg2rad(rotation(0)), Geometry::deg2rad(-rotation(2)), Geometry::deg2rad(-rotation(1))));
#else
const Vec3f& rotation = m_rotation.queue.front(); const Vec3f& rotation = m_rotation.queue.front();
float theta = m_rotation_params.scale * rotation(0); float theta = m_rotation_params.scale * rotation(0);
float phi = m_rotation_params.scale * rotation(2); float phi = m_rotation_params.scale * rotation(2);
float sign = camera.inverted_phi ? -1.0f : 1.0f; float sign = camera.inverted_phi ? -1.0f : 1.0f;
camera.phi += sign * phi; camera.phi += sign * phi;
camera.set_theta(camera.get_theta() + theta, wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptSLA); camera.set_theta(camera.get_theta() + theta, wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() != ptSLA);
#endif // ENABLE_6DOF_CAMERA
m_rotation.queue.pop(); m_rotation.queue.pop();
ret = true; ret = true;
} }
@ -628,12 +634,12 @@ bool Mouse3DController::connect_device()
BOOST_LOG_TRIVIAL(info) << "Path................: '" << path << "'"; BOOST_LOG_TRIVIAL(info) << "Path................: '" << path << "'";
// get device parameters from the config, if present // get device parameters from the config, if present
double translation_speed = 1.0; double translation_speed = 4.0;
float rotation_speed = 1.0; float rotation_speed = 4.0;
double translation_deadzone = State::DefaultTranslationDeadzone; double translation_deadzone = State::DefaultTranslationDeadzone;
float rotation_deadzone = State::DefaultRotationDeadzone; float rotation_deadzone = State::DefaultRotationDeadzone;
#if ENABLE_3DCONNEXION_Y_AS_ZOOM #if ENABLE_3DCONNEXION_Y_AS_ZOOM
double zoom_speed = 1.0; double zoom_speed = 2.0;
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM #endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
wxGetApp().app_config->get_mouse_device_translation_speed(m_device_str, translation_speed); wxGetApp().app_config->get_mouse_device_translation_speed(m_device_str, translation_speed);
wxGetApp().app_config->get_mouse_device_translation_deadzone(m_device_str, translation_deadzone); wxGetApp().app_config->get_mouse_device_translation_deadzone(m_device_str, translation_deadzone);
@ -643,12 +649,12 @@ bool Mouse3DController::connect_device()
wxGetApp().app_config->get_mouse_device_zoom_speed(m_device_str, zoom_speed); wxGetApp().app_config->get_mouse_device_zoom_speed(m_device_str, zoom_speed);
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM #endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
// clamp to valid values // clamp to valid values
m_state.set_translation_scale(State::DefaultTranslationScale* std::clamp(translation_speed, 0.1, 10.0)); m_state.set_translation_scale(State::DefaultTranslationScale * std::clamp(translation_speed, 0.1, 10.0));
m_state.set_translation_deadzone(std::clamp(translation_deadzone, 0.0, State::MaxTranslationDeadzone)); m_state.set_translation_deadzone(std::clamp(translation_deadzone, 0.0, State::MaxTranslationDeadzone));
m_state.set_rotation_scale(State::DefaultRotationScale* std::clamp(rotation_speed, 0.1f, 10.0f)); m_state.set_rotation_scale(State::DefaultRotationScale * std::clamp(rotation_speed, 0.1f, 10.0f));
m_state.set_rotation_deadzone(std::clamp(rotation_deadzone, 0.0f, State::MaxRotationDeadzone)); m_state.set_rotation_deadzone(std::clamp(rotation_deadzone, 0.0f, State::MaxRotationDeadzone));
#if ENABLE_3DCONNEXION_Y_AS_ZOOM #if ENABLE_3DCONNEXION_Y_AS_ZOOM
m_state.set_zoom_scale(State::DefaultZoomScale* std::clamp(zoom_speed, 0.1, 10.0)); m_state.set_zoom_scale(State::DefaultZoomScale * std::clamp(zoom_speed, 0.1, 10.0));
#endif // ENABLE_3DCONNEXION_Y_AS_ZOOM #endif // ENABLE_3DCONNEXION_Y_AS_ZOOM
} }
#if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT #if ENABLE_3DCONNEXION_DEVICES_DEBUG_OUTPUT
@ -855,9 +861,15 @@ bool Mouse3DController::handle_packet_translation(const DataPacket& packet)
bool Mouse3DController::handle_packet_rotation(const DataPacket& packet, unsigned int first_byte) bool Mouse3DController::handle_packet_rotation(const DataPacket& packet, unsigned int first_byte)
{ {
double deadzone = (double)m_state.get_rotation_deadzone(); double deadzone = (double)m_state.get_rotation_deadzone();
#if ENABLE_6DOF_CAMERA
Vec3f rotation((float)convert_input(packet[first_byte + 0], packet[first_byte + 1], deadzone),
(float)convert_input(packet[first_byte + 2], packet[first_byte + 3], deadzone),
(float)convert_input(packet[first_byte + 4], packet[first_byte + 5], deadzone));
#else
Vec3f rotation(-(float)convert_input(packet[first_byte + 0], packet[first_byte + 1], deadzone), Vec3f rotation(-(float)convert_input(packet[first_byte + 0], packet[first_byte + 1], deadzone),
(float)convert_input(packet[first_byte + 2], packet[first_byte + 3], deadzone), (float)convert_input(packet[first_byte + 2], packet[first_byte + 3], deadzone),
-(float)convert_input(packet[first_byte + 4], packet[first_byte + 5], deadzone)); -(float)convert_input(packet[first_byte + 4], packet[first_byte + 5], deadzone));
#endif // ENABLE_6DOF_CAMERA
if (!rotation.isApprox(Vec3f::Zero())) if (!rotation.isApprox(Vec3f::Zero()))
{ {

View File

@ -19,16 +19,11 @@ PreferencesDialog::PreferencesDialog(wxWindow* parent) :
void PreferencesDialog::build() void PreferencesDialog::build()
{ {
auto app_config = get_app_config(); auto app_config = get_app_config();
m_optgroup = std::make_shared<ConfigOptionsGroup>(this, _(L("General"))); m_optgroup_general = std::make_shared<ConfigOptionsGroup>(this, _(L("General")));
m_optgroup->label_width = 40; m_optgroup_general->label_width = 40;
m_optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) { m_optgroup_general->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
m_values[opt_key] = boost::any_cast<bool>(value) ? "1" : "0"; m_values[opt_key] = boost::any_cast<bool>(value) ? "1" : "0";
};
if (opt_key == "use_custom_toolbar_size") {
m_icon_size_sizer->ShowItems(boost::any_cast<bool>(value));
this->layout();
}
};
// TODO // TODO
// $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new( // $optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
@ -47,7 +42,7 @@ void PreferencesDialog::build()
"instead of the one containing the input files."); "instead of the one containing the input files.");
def.set_default_value(new ConfigOptionBool{ app_config->has("remember_output_path") ? app_config->get("remember_output_path") == "1" : true }); def.set_default_value(new ConfigOptionBool{ app_config->has("remember_output_path") ? app_config->get("remember_output_path") == "1" : true });
Option option(def, "remember_output_path"); Option option(def, "remember_output_path");
m_optgroup->append_single_option_line(option); m_optgroup_general->append_single_option_line(option);
def.label = L("Auto-center parts"); def.label = L("Auto-center parts");
def.type = coBool; def.type = coBool;
@ -55,7 +50,7 @@ void PreferencesDialog::build()
"around the print bed center."); "around the print bed center.");
def.set_default_value(new ConfigOptionBool{ app_config->get("autocenter") == "1" }); def.set_default_value(new ConfigOptionBool{ app_config->get("autocenter") == "1" });
option = Option (def,"autocenter"); option = Option (def,"autocenter");
m_optgroup->append_single_option_line(option); m_optgroup_general->append_single_option_line(option);
def.label = L("Background processing"); def.label = L("Background processing");
def.type = coBool; def.type = coBool;
@ -63,7 +58,7 @@ void PreferencesDialog::build()
"as they\'re loaded in order to save time when exporting G-code."); "as they\'re loaded in order to save time when exporting G-code.");
def.set_default_value(new ConfigOptionBool{ app_config->get("background_processing") == "1" }); def.set_default_value(new ConfigOptionBool{ app_config->get("background_processing") == "1" });
option = Option (def,"background_processing"); option = Option (def,"background_processing");
m_optgroup->append_single_option_line(option); m_optgroup_general->append_single_option_line(option);
// Please keep in sync with ConfigWizard // Please keep in sync with ConfigWizard
def.label = L("Check for application updates"); def.label = L("Check for application updates");
@ -71,7 +66,7 @@ void PreferencesDialog::build()
def.tooltip = L("If enabled, PrusaSlicer will check for the new versions of itself online. When a new version becomes available a notification is displayed at the next application startup (never during program usage). This is only a notification mechanisms, no automatic installation is done."); def.tooltip = L("If enabled, PrusaSlicer will check for the new versions of itself online. When a new version becomes available a notification is displayed at the next application startup (never during program usage). This is only a notification mechanisms, no automatic installation is done.");
def.set_default_value(new ConfigOptionBool(app_config->get("version_check") == "1")); def.set_default_value(new ConfigOptionBool(app_config->get("version_check") == "1"));
option = Option (def, "version_check"); option = Option (def, "version_check");
m_optgroup->append_single_option_line(option); m_optgroup_general->append_single_option_line(option);
#if ENABLE_CONFIGURABLE_PATHS_EXPORT_TO_3MF_AND_AMF #if ENABLE_CONFIGURABLE_PATHS_EXPORT_TO_3MF_AND_AMF
// Please keep in sync with ConfigWizard // Please keep in sync with ConfigWizard
@ -80,7 +75,7 @@ void PreferencesDialog::build()
def.tooltip = L("If enabled, allows the Reload from disk command to automatically find and load the files when invoked."); def.tooltip = L("If enabled, allows the Reload from disk command to automatically find and load the files when invoked.");
def.set_default_value(new ConfigOptionBool(app_config->get("export_sources_full_pathnames") == "1")); def.set_default_value(new ConfigOptionBool(app_config->get("export_sources_full_pathnames") == "1"));
option = Option(def, "export_sources_full_pathnames"); option = Option(def, "export_sources_full_pathnames");
m_optgroup->append_single_option_line(option); m_optgroup_general->append_single_option_line(option);
#endif // ENABLE_CONFIGURABLE_PATHS_EXPORT_TO_3MF_AND_AMF #endif // ENABLE_CONFIGURABLE_PATHS_EXPORT_TO_3MF_AND_AMF
// Please keep in sync with ConfigWizard // Please keep in sync with ConfigWizard
@ -89,7 +84,7 @@ void PreferencesDialog::build()
def.tooltip = L("If enabled, Slic3r downloads updates of built-in system presets in the background. These updates are downloaded into a separate temporary location. When a new preset version becomes available it is offered at application startup."); def.tooltip = L("If enabled, Slic3r downloads updates of built-in system presets in the background. These updates are downloaded into a separate temporary location. When a new preset version becomes available it is offered at application startup.");
def.set_default_value(new ConfigOptionBool(app_config->get("preset_update") == "1")); def.set_default_value(new ConfigOptionBool(app_config->get("preset_update") == "1"));
option = Option (def, "preset_update"); option = Option (def, "preset_update");
m_optgroup->append_single_option_line(option); m_optgroup_general->append_single_option_line(option);
def.label = L("Suppress \" - default - \" presets"); def.label = L("Suppress \" - default - \" presets");
def.type = coBool; def.type = coBool;
@ -97,7 +92,7 @@ void PreferencesDialog::build()
"selections once there are any other valid presets available."); "selections once there are any other valid presets available.");
def.set_default_value(new ConfigOptionBool{ app_config->get("no_defaults") == "1" }); def.set_default_value(new ConfigOptionBool{ app_config->get("no_defaults") == "1" });
option = Option (def,"no_defaults"); option = Option (def,"no_defaults");
m_optgroup->append_single_option_line(option); m_optgroup_general->append_single_option_line(option);
def.label = L("Show incompatible print and filament presets"); def.label = L("Show incompatible print and filament presets");
def.type = coBool; def.type = coBool;
@ -105,7 +100,7 @@ void PreferencesDialog::build()
"even if they are marked as incompatible with the active printer"); "even if they are marked as incompatible with the active printer");
def.set_default_value(new ConfigOptionBool{ app_config->get("show_incompatible_presets") == "1" }); def.set_default_value(new ConfigOptionBool{ app_config->get("show_incompatible_presets") == "1" });
option = Option (def,"show_incompatible_presets"); option = Option (def,"show_incompatible_presets");
m_optgroup->append_single_option_line(option); m_optgroup_general->append_single_option_line(option);
#if __APPLE__ #if __APPLE__
def.label = L("Use Retina resolution for the 3D scene"); def.label = L("Use Retina resolution for the 3D scene");
@ -114,28 +109,55 @@ void PreferencesDialog::build()
"If you are experiencing 3D performance problems, disabling this option may help."); "If you are experiencing 3D performance problems, disabling this option may help.");
def.set_default_value(new ConfigOptionBool{ app_config->get("use_retina_opengl") == "1" }); def.set_default_value(new ConfigOptionBool{ app_config->get("use_retina_opengl") == "1" });
option = Option (def, "use_retina_opengl"); option = Option (def, "use_retina_opengl");
m_optgroup->append_single_option_line(option); m_optgroup_general->append_single_option_line(option);
#endif #endif
def.label = L("Use perspective camera"); m_optgroup_camera = std::make_shared<ConfigOptionsGroup>(this, _(L("Camera")));
def.type = coBool; m_optgroup_camera->label_width = 40;
def.tooltip = L("If enabled, use perspective camera. If not enabled, use orthographic camera."); m_optgroup_camera->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
def.set_default_value(new ConfigOptionBool{ app_config->get("use_perspective_camera") == "1" }); m_values[opt_key] = boost::any_cast<bool>(value) ? "1" : "0";
option = Option(def, "use_perspective_camera"); };
m_optgroup->append_single_option_line(option);
def.label = L("Use perspective camera");
def.type = coBool;
def.tooltip = L("If enabled, use perspective camera. If not enabled, use orthographic camera.");
def.set_default_value(new ConfigOptionBool{ app_config->get("use_perspective_camera") == "1" });
option = Option(def, "use_perspective_camera");
m_optgroup_camera->append_single_option_line(option);
#if ENABLE_6DOF_CAMERA
def.label = L("Use free camera");
def.type = coBool;
def.tooltip = L("If enabled, use free camera. If not enabled, use constrained camera.");
def.set_default_value(new ConfigOptionBool(app_config->get("use_free_camera") == "1"));
option = Option(def, "use_free_camera");
m_optgroup_camera->append_single_option_line(option);
#endif // ENABLE_6DOF_CAMERA
m_optgroup_gui = std::make_shared<ConfigOptionsGroup>(this, _(L("GUI")));
m_optgroup_gui->label_width = 40;
m_optgroup_gui->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
m_values[opt_key] = boost::any_cast<bool>(value) ? "1" : "0";
if (opt_key == "use_custom_toolbar_size") {
m_icon_size_sizer->ShowItems(boost::any_cast<bool>(value));
this->layout();
}
};
def.label = L("Use custom size for toolbar icons"); def.label = L("Use custom size for toolbar icons");
def.type = coBool; def.type = coBool;
def.tooltip = L("If enabled, you can change size of toolbar icons manually."); def.tooltip = L("If enabled, you can change size of toolbar icons manually.");
def.set_default_value(new ConfigOptionBool{ app_config->get("use_custom_toolbar_size") == "1" }); def.set_default_value(new ConfigOptionBool{ app_config->get("use_custom_toolbar_size") == "1" });
option = Option (def,"use_custom_toolbar_size"); option = Option(def, "use_custom_toolbar_size");
m_optgroup->append_single_option_line(option); m_optgroup_gui->append_single_option_line(option);
create_icon_size_slider(); create_icon_size_slider();
m_icon_size_sizer->ShowItems(app_config->get("use_custom_toolbar_size") == "1"); m_icon_size_sizer->ShowItems(app_config->get("use_custom_toolbar_size") == "1");
auto sizer = new wxBoxSizer(wxVERTICAL); auto sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(m_optgroup->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); sizer->Add(m_optgroup_general->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
sizer->Add(m_optgroup_camera->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
sizer->Add(m_optgroup_gui->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
SetFont(wxGetApp().normal_font()); SetFont(wxGetApp().normal_font());
@ -167,7 +189,9 @@ void PreferencesDialog::accept()
void PreferencesDialog::on_dpi_changed(const wxRect &suggested_rect) void PreferencesDialog::on_dpi_changed(const wxRect &suggested_rect)
{ {
m_optgroup->msw_rescale(); m_optgroup_general->msw_rescale();
m_optgroup_camera->msw_rescale();
m_optgroup_gui->msw_rescale();
msw_buttons_rescale(this, em_unit(), { wxID_OK, wxID_CANCEL }); msw_buttons_rescale(this, em_unit(), { wxID_OK, wxID_CANCEL });
@ -192,7 +216,7 @@ void PreferencesDialog::create_icon_size_slider()
m_icon_size_sizer = new wxBoxSizer(wxHORIZONTAL); m_icon_size_sizer = new wxBoxSizer(wxHORIZONTAL);
wxWindow* parent = m_optgroup->ctrl_parent(); wxWindow* parent = m_optgroup_gui->ctrl_parent();
if (isOSX) if (isOSX)
// For correct rendering of the slider and value label under OSX // For correct rendering of the slider and value label under OSX
@ -240,8 +264,9 @@ void PreferencesDialog::create_icon_size_slider()
win->SetBackgroundStyle(wxBG_STYLE_PAINT); win->SetBackgroundStyle(wxBG_STYLE_PAINT);
} }
m_optgroup->sizer->Add(m_icon_size_sizer, 0, wxEXPAND | wxALL, em); m_optgroup_gui->sizer->Add(m_icon_size_sizer, 0, wxEXPAND | wxALL, em);
} }
} // GUI } // GUI
} // Slic3r } // Slic3r

View File

@ -15,8 +15,10 @@ class ConfigOptionsGroup;
class PreferencesDialog : public DPIDialog class PreferencesDialog : public DPIDialog
{ {
std::map<std::string, std::string> m_values; std::map<std::string, std::string> m_values;
std::shared_ptr<ConfigOptionsGroup> m_optgroup; std::shared_ptr<ConfigOptionsGroup> m_optgroup_general;
wxSizer* m_icon_size_sizer; std::shared_ptr<ConfigOptionsGroup> m_optgroup_camera;
std::shared_ptr<ConfigOptionsGroup> m_optgroup_gui;
wxSizer* m_icon_size_sizer;
bool isOSX {false}; bool isOSX {false};
public: public:
PreferencesDialog(wxWindow* parent); PreferencesDialog(wxWindow* parent);

View File

@ -2004,7 +2004,11 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) co
const float max_y = box.max(1) + Margin; const float max_y = box.max(1) + Margin;
// view dependend order of rendering to keep correct transparency // view dependend order of rendering to keep correct transparency
#if ENABLE_6DOF_CAMERA
bool camera_on_top = wxGetApp().plater()->get_camera().is_looking_downward();
#else
bool camera_on_top = wxGetApp().plater()->get_camera().get_theta() <= 90.0f; bool camera_on_top = wxGetApp().plater()->get_camera().get_theta() <= 90.0f;
#endif // ENABLE_6DOF_CAMERA
float z1 = camera_on_top ? min_z : max_z; float z1 = camera_on_top ? min_z : max_z;
float z2 = camera_on_top ? max_z : min_z; float z2 = camera_on_top ? max_z : min_z;