Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 42 additions & 41 deletions src/libslic3r/AppConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,6 @@ void AppConfig::set_defaults()
#endif // _WIN32
}

if (get("use_perspective_camera").empty())
set_bool("use_perspective_camera", true);

#ifdef SUPPORT_FREE_CAMERA
if (get("use_free_camera").empty())
set_bool("use_free_camera", false);
#endif

#ifdef SUPPORT_REVERSE_MOUSE_ZOOM
if (get("reverse_mouse_wheel_zoom").empty())
set_bool("reverse_mouse_wheel_zoom", false);
#endif
if (get("enable_append_color_by_sync_ams").empty())
set_bool("enable_append_color_by_sync_ams", true);
if (get("enable_merge_color_by_sync_ams").empty())
Expand All @@ -183,8 +171,6 @@ void AppConfig::set_defaults()
if (get("export_sources_full_pathnames").empty())
set_bool("export_sources_full_pathnames", false);

if (get("zoom_to_mouse").empty())
set_bool("zoom_to_mouse", false);
if (get("show_shells_in_preview").empty())
set_bool("show_shells_in_preview", true);
if (get("enable_text_styles").empty())
Expand Down Expand Up @@ -217,6 +203,48 @@ void AppConfig::set_defaults()
set("3d_middle_tooltip_offset_y", "0.0");
if (get("cancel_glmultidraw").empty())
set_bool("cancel_glmultidraw", false);

// 3D camera view options

if (get("use_perspective_camera").empty())
set_bool("use_perspective_camera", true);
if (get("use_free_camera").empty())
set_bool("use_free_camera", false);
if (get("zoom_to_mouse").empty())
set_bool("zoom_to_mouse", false);
if (get("reverse_mouse_wheel_zoom").empty())
set_bool("reverse_mouse_wheel_zoom", false);
// Rotation speed adjustment ratio
if (get("view_rotate_speed_factor").empty())
set("view_rotate_speed_factor", "0.8");
// Which mouse button is used to rotate 3D view: left|mid|right|aux1|aux2
if (get("view_rotate_mb").empty())
set("view_rotate_mb", "left");
// Which mouse button is used to pan 3D view: any|left|mid|right|aux1|aux2
// Value is exclusive with "view_rotate_mb" (should not be set to same button).
// "any" legacy setting means either right and/or mid btns, whichever aren't used for rotation.
if (get("view_pan_mb").empty())
set("view_pan_mb", "any");
// Which camera rotation type is used when no modifiers are pressed: plate|center|selection|cursor|target
// \sa Camera::RotationFocusType
if (get("view_rotate_mode_nomod").empty())
set("view_rotate_mode_nomod", "plate");
// Which camera rotation type is used when CTRL (Win/Linux) or CMD (Mac) is pressed.
if (get("view_rotate_mode_ctrl").empty())
set("view_rotate_mode_ctrl", "center");
// Which camera rotation type is used when ALT/OPT is pressed.
if (get("view_rotate_mode_alt").empty())
set("view_rotate_mode_alt", "selection");

// Remove legacy camera control options
erase("app", "keyboard_supported");
erase("app", "mouse_supported");
erase("app", "rotate_view");
erase("app", "move_view");
erase("app", "zoom_view");
erase("app", "precise_control");
erase("app", "mouse_wheel");

//#ifdef SUPPORT_SHOW_HINTS
if (get("show_hints").empty())
set_bool("show_hints", false);
Expand Down Expand Up @@ -370,41 +398,14 @@ void AppConfig::set_defaults()
set_bool("sync_user_preset", false);
}

if (get("keyboard_supported").empty()) {
set("keyboard_supported", std::string("none/alt/control/shift"));
}

if (get("mouse_supported").empty()) {
set("mouse_supported", "mouse left/mouse middle/mouse right");
}

if (get("privacy_version").empty()) {
set("privacy_version", "00.00.00.00");
}

if (get("rotate_view").empty()) {
set("rotate_view", "none/mouse left");
}

if (get("move_view").empty()) {
set("move_view", "none/mouse left");
}

if (get("zoom_view").empty()) {
set("zoom_view", "none/mouse left");
}

if (get("precise_control").empty()) {
set("precise_control", "none/mouse left");
}

if (get("download_path").empty()) {
set("download_path", "");
}

if (get("mouse_wheel").empty()) {
set("mouse_wheel", "0"); }

// helio options
if (get("helio_enable").empty()) {
set_bool("helio_enable", false);
Expand Down
76 changes: 30 additions & 46 deletions src/slic3r/GUI/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,12 @@ void Camera::debug_render()
imgui.begin(std::string("Camera statistics"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);

std::string type = get_type_as_string();
if (wxGetApp().plater()->get_mouse3d_controller().connected()
#ifdef SUPPORT_FREE_CAMERA
|| (wxGetApp().app_config->get("use_free_camera") == "1")
#endif
)
if (wxGetApp().app_config->get_bool("use_free_camera"))
type += "/free";
else
type += "/constrained";
if (wxGetApp().plater()->get_mouse3d_controller().connected())
type += " (3D mouse)";

Vec3f position = get_position().cast<float>();
Vec3f target = m_target.cast<float>();
Expand Down Expand Up @@ -478,7 +476,7 @@ void Camera::debug_render()
ImGui::PopStyleVar(3);
}

void Camera::rotate_on_sphere_with_target(double delta_azimut_rad, double delta_zenit_rad, bool apply_limits, Vec3d target)
void Camera::rotate_on_sphere_with_target(double delta_azimut_rad, double delta_zenit_rad, bool apply_limits, const Vec3d& target)
{
m_zenit += Geometry::rad2deg(delta_zenit_rad);
if (apply_limits) {
Expand All @@ -492,8 +490,8 @@ void Camera::rotate_on_sphere_with_target(double delta_azimut_rad, double delta_
}
}

Vec3d translation = m_view_matrix.translation() + m_view_rotation * target;
auto rot_z = Eigen::AngleAxisd(delta_azimut_rad, Vec3d::UnitZ());
const Vec3d translation = m_view_matrix.translation() + m_view_rotation * target;
const auto rot_z = Eigen::AngleAxisd(delta_azimut_rad, Vec3d::UnitZ());
m_view_rotation *= rot_z * Eigen::AngleAxisd(delta_zenit_rad, rot_z.inverse() * get_dir_right());
m_view_rotation.normalize();
m_view_matrix.fromPositionOrientationScale(m_view_rotation * (-target) + translation, m_view_rotation, Vec3d(1., 1., 1.));
Expand All @@ -502,37 +500,37 @@ void Camera::rotate_on_sphere_with_target(double delta_azimut_rad, double delta_

void Camera::rotate_on_sphere(double delta_azimut_rad, double delta_zenit_rad, bool apply_limits)
{
m_zenit += Geometry::rad2deg(delta_zenit_rad);
if (apply_limits) {
if (m_zenit > 90.0f) {
delta_zenit_rad -= Geometry::deg2rad(m_zenit - 90.0f);
m_zenit = 90.0f;
}
else if (m_zenit < -90.0f) {
delta_zenit_rad -= Geometry::deg2rad(m_zenit + 90.0f);
m_zenit = -90.0f;
}
}

const Vec3d translation = m_view_matrix.translation() + m_view_rotation * m_target;
const auto rot_z = Eigen::AngleAxisd(delta_azimut_rad, Vec3d::UnitZ());
m_view_rotation *= rot_z * Eigen::AngleAxisd(delta_zenit_rad, rot_z.inverse() * get_dir_right());
m_view_rotation.normalize();
m_view_matrix.fromPositionOrientationScale(m_view_rotation * (- m_target) + translation, m_view_rotation, Vec3d(1., 1., 1.));
rotate_on_sphere_with_target(delta_azimut_rad, delta_zenit_rad, apply_limits, m_target);
}

//BBS rotate with target
void Camera::rotate_local_with_target(const Vec3d& rotation_rad, Vec3d target)
// Virtual trackball, rotate around an axis while looking at given target, where the eucledian norm of the axis gives the rotation angle in radians.
void Camera::rotate_local_with_target(const Vec3d& rotation_rad, const Vec3d& target)
{
double angle = rotation_rad.norm();
if (std::abs(angle) > EPSILON) {
Vec3d translation = m_view_matrix.translation() + m_view_rotation * target;
Vec3d axis = m_view_rotation.conjugate() * rotation_rad.normalized();
const Vec3d translation = m_view_matrix.translation() + m_view_rotation * target;
const Vec3d axis = m_view_rotation.conjugate() * rotation_rad.normalized();
m_view_rotation *= Eigen::Quaterniond(Eigen::AngleAxisd(angle, axis));
m_view_rotation.normalize();
m_view_matrix.fromPositionOrientationScale(m_view_rotation * (-target) + translation, m_view_rotation, Vec3d(1., 1., 1.));
update_zenit();
}
m_view_matrix.fromPositionOrientationScale(m_view_rotation * (-target) + translation, m_view_rotation, Vec3d(1., 1., 1.));
update_zenit();
}
}

// Virtual trackball, rotate around current camera target.
// This overload is currently only used by 3D mouse input.
void Camera::rotate_local_around_target(const Vec3d& rotation_rad)
{
rotate_local_with_target(rotation_rad, m_target);

// If tilt exceeds constrained camera limits, automatically enable the free camera UI option.
// This will smooth out any future transition to a different control method, like mouse.
// The view and option can be reset by the user with a shortcut or menu selection.
if (m_update_config_on_free_rot_change && get_dir_up()(2) < -EPSILON) {
m_update_config_on_free_rot_change = false;
wxGetApp().app_config->set_bool("use_free_camera", true);
wxGetApp().plater()->update_camera_manipulation_settings();
}
}

void Camera::calc_horizontal_rotate_rad(float &rotation_rad) {
Expand All @@ -547,20 +545,6 @@ void Camera::calc_horizontal_rotate_rad(float &rotation_rad) {
}
}

// Virtual trackball, rotate around an axis, where the eucledian norm of the axis gives the rotation angle in radians.
void Camera::rotate_local_around_target(const Vec3d& rotation_rad)
{
const double angle = rotation_rad.norm();
if (std::abs(angle) > EPSILON) {
const Vec3d translation = m_view_matrix.translation() + m_view_rotation * m_target;
const Vec3d axis = m_view_rotation.conjugate() * rotation_rad.normalized();
m_view_rotation *= Eigen::Quaterniond(Eigen::AngleAxisd(angle, axis));
m_view_rotation.normalize();
m_view_matrix.fromPositionOrientationScale(m_view_rotation * (-m_target) + translation, m_view_rotation, Vec3d(1., 1., 1.));
update_zenit();
}
}

void Camera::set_rotation(const Transform3d &rotation)
{
const Vec3d translation = m_view_matrix.translation() + m_view_rotation * m_target;
Expand Down
13 changes: 10 additions & 3 deletions src/slic3r/GUI/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct Camera
private:
EType m_type{ EType::Perspective };
bool m_update_config_on_type_change_enabled{ false };
bool m_update_config_on_free_rot_change{ true };
Vec3d m_target{ Vec3d::Zero() };
float m_zenit{ 45.0f };
double m_zoom{ 1.0 };
Expand Down Expand Up @@ -144,8 +145,8 @@ struct Camera
void translate_world(const Vec3d& displacement) { set_target(m_target + displacement); }

// BBS rotate the camera on a sphere having center == target
void rotate_on_sphere_with_target(double delta_azimut_rad, double delta_zenit_rad, bool apply_limits, Vec3d target);
void rotate_local_with_target(const Vec3d& rotation_rad, Vec3d target);
void rotate_on_sphere_with_target(double delta_azimut_rad, double delta_zenit_rad, bool apply_limits, const Vec3d& target);
void rotate_local_with_target(const Vec3d& rotation_rad, const Vec3d& target);
void calc_horizontal_rotate_rad(float &rotation_rad);
// rotate the camera on a sphere having center == m_target and radius == m_distance
// using the given variations of spherical coordinates
Expand All @@ -160,8 +161,14 @@ struct Camera
bool is_looking_front() const { return abs(get_dir_up().dot(Vec3d::UnitZ())-1) < 0.001; }
// forces camera right vector to be parallel to XY plane
void recover_from_free_camera() {
if (std::abs(get_dir_right()(2)) > EPSILON)
// First condition happens with unconstrained mouse rotations when going past the constrained stopping points.
// Second condition may happen after using a 3D mouse controller.
if (get_dir_up()(2) < -EPSILON || std::abs(get_dir_right()(2)) > EPSILON) {
update_target();
look_at(get_position(), m_target, Vec3d::UnitZ());
}
// Set flag to monitor 3D mouse movements for toggling to free camera mode. \sa rotate_local_around_target()
m_update_config_on_free_rot_change = true;
}

void look_at(const Vec3d& position, const Vec3d& target, const Vec3d& up);
Expand Down
Loading
Loading