From aa0c3bf2e3082295bd58b3d2712a3a8594f69afe Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 12 Oct 2018 10:09:16 +0200 Subject: [PATCH 1/6] Added helper functions to generate 3d transforms --- src/libslic3r/Geometry.cpp | 17 +++++++++++++++++ src/libslic3r/Geometry.hpp | 15 +++++++++++++++ src/libslic3r/Model.cpp | 22 +++++++--------------- src/slic3r/GUI/3DScene.cpp | 9 +++------ src/slic3r/GUI/GLCanvas3D.cpp | 16 ++++------------ 5 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/libslic3r/Geometry.cpp b/src/libslic3r/Geometry.cpp index 87b4e223d4..5d7b936795 100644 --- a/src/libslic3r/Geometry.cpp +++ b/src/libslic3r/Geometry.cpp @@ -1166,4 +1166,21 @@ MedialAxis::retrieve_endpoint(const VD::cell_type* cell) const } } +void assemble_transform(Transform3d& transform, const Vec3d& translation, const Vec3d& rotation, const Vec3d& scale) +{ + transform = Transform3d::Identity(); + transform.translate(translation); + transform.rotate(Eigen::AngleAxisd(rotation(2), Vec3d::UnitZ())); + transform.rotate(Eigen::AngleAxisd(rotation(1), Vec3d::UnitY())); + transform.rotate(Eigen::AngleAxisd(rotation(0), Vec3d::UnitX())); + transform.scale(scale); +} + +Transform3d assemble_transform(const Vec3d& translation, const Vec3d& rotation, const Vec3d& scale) +{ + Transform3d transform; + assemble_transform(transform, translation, rotation, scale); + return transform; +} + } } diff --git a/src/libslic3r/Geometry.hpp b/src/libslic3r/Geometry.hpp index 3698b996fd..57b9cad02f 100644 --- a/src/libslic3r/Geometry.hpp +++ b/src/libslic3r/Geometry.hpp @@ -157,6 +157,21 @@ class MedialAxis { const Point& retrieve_endpoint(const VD::cell_type* cell) const; }; +// Sets the given transform by assembling the given transformations in the following order: +// 1) scale +// 2) rotate X +// 3) rotate Y +// 4) rotate Z +// 5) translate +void assemble_transform(Transform3d& transform, const Vec3d& translation = Vec3d::Zero(), const Vec3d& rotation = Vec3d::Zero(), const Vec3d& scale = Vec3d::Ones()); + +// Returns the transform obtained by assembling the given transformations in the following order: +// 1) scale +// 2) rotate X +// 3) rotate Y +// 4) rotate Z +// 5) translate +Transform3d assemble_transform(const Vec3d& translation = Vec3d::Zero(), const Vec3d& rotation = Vec3d::Zero(), const Vec3d& scale = Vec3d::Ones()); } } #endif diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index e0cf14a57d..8ced1018db 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -1185,22 +1185,14 @@ void ModelInstance::transform_polygon(Polygon* polygon) const Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale) const { +#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM + Vec3d translation = dont_translate ? Vec3d::Zero() : m_offset; + Vec3d rotation = dont_rotate ? Vec3d::Zero() : m_rotation; + Vec3d scale = dont_scale ? Vec3d::Ones() : m_scaling_factor; + return Geometry::assemble_transform(translation, rotation, scale); +#else Transform3d m = Transform3d::Identity(); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - if (!dont_translate) - m.translate(m_offset); - - if (!dont_rotate) - { - m.rotate(Eigen::AngleAxisd(m_rotation(2), Vec3d::UnitZ())); - m.rotate(Eigen::AngleAxisd(m_rotation(1), Vec3d::UnitY())); - m.rotate(Eigen::AngleAxisd(m_rotation(0), Vec3d::UnitX())); - } - - if (!dont_scale) - m.scale(m_scaling_factor); -#else if (!dont_translate) m.translate(Vec3d(offset(0), offset(1), 0.0)); @@ -1209,9 +1201,9 @@ Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, b if (!dont_scale) m.scale(scaling_factor); -#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM return m; +#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } } diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 92e9039115..07f9b0fda4 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -389,14 +389,11 @@ const Transform3f& GLVolume::world_matrix() const { if (m_world_matrix_dirty) { +#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM + m_world_matrix = Geometry::assemble_transform(m_offset, m_rotation, m_scaling_factor).cast(); +#else m_world_matrix = Transform3f::Identity(); m_world_matrix.translate(m_offset.cast()); -#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - m_world_matrix.rotate(Eigen::AngleAxisf((float)m_rotation(2), Vec3f::UnitZ())); - m_world_matrix.rotate(Eigen::AngleAxisf((float)m_rotation(1), Vec3f::UnitY())); - m_world_matrix.rotate(Eigen::AngleAxisf((float)m_rotation(0), Vec3f::UnitX())); - m_world_matrix.scale(m_scaling_factor.cast()); -#else m_world_matrix.rotate(Eigen::AngleAxisf((float)m_rotation, Vec3f::UnitZ())); m_world_matrix.scale((float)m_scaling_factor); #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index a2067bbf3e..0925488704 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -10,6 +10,7 @@ #include "../../libslic3r/ClipperUtils.hpp" #include "../../libslic3r/PrintConfig.hpp" #include "../../libslic3r/GCode/PreviewData.hpp" +#include "../../libslic3r/Geometry.hpp" #include "GUI_App.hpp" #include "GUI_ObjectList.hpp" #include "GUI_ObjectManipulation.hpp" @@ -1144,17 +1145,14 @@ GLCanvas3D::Selection::VolumeCache::VolumeCache(const Vec3d& position, const Vec , m_rotation(rotation) , m_scaling_factor(scaling_factor) { - m_rotation_matrix = Transform3d::Identity(); - m_rotation_matrix.rotate(Eigen::AngleAxisd(m_rotation(2), Vec3d::UnitZ())); - m_rotation_matrix.rotate(Eigen::AngleAxisd(m_rotation(1), Vec3d::UnitY())); - m_rotation_matrix.rotate(Eigen::AngleAxisd(m_rotation(0), Vec3d::UnitX())); + m_rotation_matrix = Geometry::assemble_transform(Vec3d::Zero(), m_rotation); } GLCanvas3D::Selection::Selection() : m_volumes(nullptr) , m_model(nullptr) , m_mode(Instance) - , m_type(Invalid) + , m_type(Empty) , m_valid(false) , m_bounding_box_dirty(true) { @@ -1409,13 +1407,7 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation) if (!m_valid) return; - Transform3d m = Transform3d::Identity(); - if (rotation(2) != 0.0f) - m.rotate(Eigen::AngleAxisd(rotation(2), Vec3d::UnitZ())); - else if (rotation(1) != 0.0f) - m.rotate(Eigen::AngleAxisd(rotation(1), Vec3d::UnitY())); - else if (rotation(0) != 0.0f) - m.rotate(Eigen::AngleAxisd(rotation(0), Vec3d::UnitX())); + Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), rotation); bool single_full_instance = is_single_full_instance(); From d843f1a76fe753d7ffdc6c53ed06f46a015d7139 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Thu, 11 Oct 2018 15:19:53 +0200 Subject: [PATCH 2/6] Fix resources dir location, add wxWidgets to Windows deps build script --- CMakeLists.txt | 26 ++++++++++++++-- doc/deps-build/windows/slic3r-makedeps.ps1 | 32 ++++++++++++++++++-- resources/localization/CMakeLists.txt | 8 ----- src/slic3r.cpp | 35 +++++++++------------- 4 files changed, 67 insertions(+), 34 deletions(-) delete mode 100644 resources/localization/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f4e89283b..b0f908e906 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.2) include("version.inc") set(SLIC3R_RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources") +file(TO_NATIVE_PATH "${SLIC3R_RESOURCES_DIR}" SLIC3R_RESOURCES_DIR_WIN) if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "No build type selected, default to Release") @@ -214,8 +215,29 @@ if (NOT GLEW_FOUND) endif () include_directories(${GLEW_INCLUDE_DIRS}) -# l10n -add_subdirectory(resources/localization) +# Resources and l10n +set(L10N_DIR "${SLIC3R_RESOURCES_DIR}/localization") +add_custom_target(pot + # FIXME: file list stale + COMMAND xgettext --keyword=L --from-code=UTF-8 --debug + -f "${L10N_DIR}/list.txt" + -o "${L10N_DIR}/Slic3rPE.pot" + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMENT "Generate pot file from strings in the source tree" +) +if (MSVC) + file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/src/resources" WIN_RESOURCES_SYMLINK) + add_custom_target(resources_symlink ALL + COMMAND if not exist "${WIN_RESOURCES_SYMLINK}" ( mklink /J "${WIN_RESOURCES_SYMLINK}" "${SLIC3R_RESOURCES_DIR_WIN}" ) + VERBATIM + ) +else () + add_custom_target(resources_symlink ALL + COMMAND ln -sf "${SLIC3R_RESOURCES_DIR}" "${CMAKE_BINARY_DIR}/resources" + VERBATIM + ) +endif() + # libslic3r, Slic3r GUI and the slic3r executable. add_subdirectory(src) diff --git a/doc/deps-build/windows/slic3r-makedeps.ps1 b/doc/deps-build/windows/slic3r-makedeps.ps1 index e256d61e42..228244d0b4 100644 --- a/doc/deps-build/windows/slic3r-makedeps.ps1 +++ b/doc/deps-build/windows/slic3r-makedeps.ps1 @@ -40,6 +40,8 @@ $BOOST = 'boost_1_63_0' $CURL = 'curl-7.58.0' $TBB_SHA = 'a0dc9bf76d0120f917b641ed095360448cabc85b' $TBB = "tbb-$TBB_SHA" +$WXWIDGETS_VER = "3.1.1" +$WXWIDGETS = "wxWidgets-$WXWIDGETS_VER" try @@ -72,13 +74,21 @@ echo 'Downloading sources ...' if (!(Test-Path "$BOOST.zip")) { $webclient.DownloadFile("https://dl.bintray.com/boostorg/release/1.63.0/source/$BOOST.zip", "$BOOST.zip") } if (!(Test-Path "$TBB.zip")) { $webclient.DownloadFile("https://github.com/wjakob/tbb/archive/$TBB_SHA.zip", "$TBB.zip") } if (!(Test-Path "$CURL.zip")) { $webclient.DownloadFile("https://curl.haxx.se/download/$CURL.zip", ".\$CURL.zip") } +if (!(Test-Path "$WXWIDGETS.zip")) { $webclient.DownloadFile("https://github.com/wxWidgets/wxWidgets/releases/download/v$WXWIDGETS_VER/$WXWIDGETS.zip", ".\$WXWIDGETS.zip") } # Unpack sources: echo 'Unpacking ...' -if (!(Test-Path $BOOST)) { [IO.Compression.ZipFile]::ExtractToDirectory("$BOOST.zip", '.') } -if (!(Test-Path $TBB)) { [IO.Compression.ZipFile]::ExtractToDirectory("$TBB.zip", '.') } -if (!(Test-Path $CURL)) { [IO.Compression.ZipFile]::ExtractToDirectory("$CURL.zip", '.') } +if (!(Test-Path "$BOOST")) { [IO.Compression.ZipFile]::ExtractToDirectory("$BOOST.zip", '.') } +if (!(Test-Path "$TBB")) { [IO.Compression.ZipFile]::ExtractToDirectory("$TBB.zip", '.') } +if (!(Test-Path "$CURL")) { [IO.Compression.ZipFile]::ExtractToDirectory("$CURL.zip", '.') } +if (!(Test-Path "$WXWIDGETS")) { [IO.Compression.ZipFile]::ExtractToDirectory("$WXWIDGETS.zip", "$WXWIDGETS") } + + +# Patch PNG in wxWidgets +# PNG prefix is not applied properly to two functions +$pngprefix_h = "$WXWIDGETS\src\png\pngprefix.h" +"#define png_write_eXIf wx_png_write_eXIf`n#define png_handle_eXIf wx_png_handle_eXIf`n`n" + (Get-Content $pngprefix_h | Out-String) | Set-Content $pngprefix_h # Build libraries: @@ -127,6 +137,22 @@ Copy-Item -R -Force ..\builds\libcurl-*-winssl\include\* "$destdir\usr\local\inc Copy-Item -R -Force ..\builds\libcurl-*-winssl\lib\* "$destdir\usr\local\lib\" popd +# Build wxWidgets +pushd "$WXWIDGETS" +pushd "build\msw" +$target_cpu_opt = ("", "TARGET_CPU=X64")[!$b32] +$lib_dir = ("vc_lib", "vc_x64_lib")[!$b32] +nmake /f makefile.vc ` + BUILD=release ` + SHARED=0 ` + UNICODE=1 ` + USE_GUI=1 ` + "$target_cpu_opt" +popd +Copy-Item -R -Force include\* "$destdir\usr\local\include\" +Copy-Item -R -Force "lib\$lib_dir" "$destdir\usr\local\lib\" +popd + echo "" echo "All done!" diff --git a/resources/localization/CMakeLists.txt b/resources/localization/CMakeLists.txt deleted file mode 100644 index 8a7fba068f..0000000000 --- a/resources/localization/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -set(L10N_DIR "${PROJECT_SOURCE_DIR}/resources/localization") -add_custom_target(pot - COMMAND xgettext --keyword=L --from-code=UTF-8 --debug - -f "${L10N_DIR}/list.txt" - -o "${L10N_DIR}/Slic3rPE.pot" - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - COMMENT "Generate pot file from strings in the source tree" -) diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 296d994147..03e337db56 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -70,31 +70,24 @@ int main(int argc, char **argv) } boost::filesystem::path path_to_binary = boost::filesystem::system_complete(argv[0]); - boost::filesystem::path path_resources = path_to_binary.parent_path(); + // Path from the Slic3r binary to its resources. - path_resources /= (path_to_binary.stem().string() == "slic3r-gui") ? - // Running from the build directory: -// "../../resources" : // ? #ys_FIXME - "../../../resources" : // ! #ys_FIXME - // Running from an installation directory: #ifdef __APPLE__ - // The application is packed in the .dmg archive as 'Slic3r.app/Contents/MacOS/Slic3r' - // The resources are packed to 'Slic3r.app/Contents/Resources' - "../Resources" + // The application is packed in the .dmg archive as 'Slic3r.app/Contents/MacOS/Slic3r' + // The resources are packed to 'Slic3r.app/Contents/Resources' + boost::filesystem::path path_resources = path_to_binary.parent_path() / "../Resources"; +#elif defined _WIN32 + // The application is packed in the .zip archive in the root, + // The resources are packed to 'resources' + // Path from Slic3r binary to resources: + boost::filesystem::path path_resources = path_to_binary.parent_path() / "resources"; #else - #ifdef _WIN32 - // The application is packed in the .zip archive in the root, - // The resources are packed to 'resources' - // Path from Slic3r binary to resources: - "resources" - #else - // The application is packed in the .tar.bz archive (or in AppImage) as 'bin/slic3r', - // The resources are packed to 'resources' - // Path from Slic3r binary to resources: - "../resources" - #endif + // The application is packed in the .tar.bz archive (or in AppImage) as 'bin/slic3r', + // The resources are packed to 'resources' + // Path from Slic3r binary to resources: + boost::filesystem::path path_resources = path_to_binary.parent_path() / "../resources"; #endif - ; + set_resources_dir(path_resources.string()); set_var_dir((path_resources / "icons").string()); set_local_dir((path_resources / "localization").string()); From 9bb93cc4f4675ab0e9b0a5d77d3d19f2fc086848 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 12 Oct 2018 12:19:57 +0200 Subject: [PATCH 3/6] Added helper functions to extract euler angles from 3d transforms --- src/libslic3r/Format/3mf.cpp | 42 ++++++++++++++--------------------- src/libslic3r/Geometry.cpp | 34 ++++++++++++++++++++++++++++ src/libslic3r/Geometry.hpp | 8 +++++++ src/slic3r/GUI/GLCanvas3D.cpp | 23 ++----------------- 4 files changed, 61 insertions(+), 46 deletions(-) diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index 90817fadc9..4d749eb568 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -2,6 +2,7 @@ #include "../Model.hpp" #include "../Utils.hpp" #include "../GCode.hpp" +#include "../Geometry.hpp" #include "3mf.hpp" @@ -1253,7 +1254,7 @@ namespace Slic3r { // translation #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - Vec3d offset(transform(0, 3), transform(1, 3), transform(2, 3)); + Vec3d offset = transform.matrix().block(0, 3, 3, 1); #else double offset_x = transform(0, 3); double offset_y = transform(1, 3); @@ -1261,50 +1262,41 @@ namespace Slic3r { #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // scale - double sx = ::sqrt(sqr(transform(0, 0)) + sqr(transform(1, 0)) + sqr(transform(2, 0))); - double sy = ::sqrt(sqr(transform(0, 1)) + sqr(transform(1, 1)) + sqr(transform(2, 1))); - double sz = ::sqrt(sqr(transform(0, 2)) + sqr(transform(1, 2)) + sqr(transform(2, 2))); + Eigen::Matrix m3x3 = transform.matrix().block(0, 0, 3, 3); + Vec3d scale(m3x3.col(0).norm(), m3x3.col(1).norm(), m3x3.col(2).norm()); // invalid scale value, return - if ((sx == 0.0) || (sy == 0.0) || (sz == 0.0)) + if ((scale(0) == 0.0) || (scale(1) == 0.0) || (scale(2) == 0.0)) return; #if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM // non-uniform scale value, return - if ((std::abs(sx - sy) > 0.00001) || (std::abs(sx - sz) > 0.00001)) + if ((std::abs(scale(0) - scale(1)) > 0.00001) || (std::abs(scale(0) - scale(2)) > 0.00001)) return; #endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - double inv_sx = 1.0 / sx; - double inv_sy = 1.0 / sy; - double inv_sz = 1.0 / sz; - - Eigen::Matrix m3x3; - m3x3 << transform(0, 0) * inv_sx, transform(0, 1) * inv_sy, transform(0, 2) * inv_sz, - transform(1, 0) * inv_sx, transform(1, 1) * inv_sy, transform(1, 2) * inv_sz, - transform(2, 0) * inv_sx, transform(2, 1) * inv_sy, transform(2, 2) * inv_sz; + // remove scale + m3x3.col(0).normalize(); + m3x3.col(1).normalize(); + m3x3.col(2).normalize(); #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - Vec3d angles = m3x3.eulerAngles(2, 1, 0); - Vec3d rotation(angles(2), angles(1), angles(0)); + Vec3d rotation = Slic3r::Geometry::extract_euler_angles(m3x3); instance.set_offset(offset); - instance.set_scaling_factor(Vec3d(sx, sy, sz)); + instance.set_scaling_factor(scale); instance.set_rotation(rotation); #else - Eigen::AngleAxisd rotation; - rotation.fromRotationMatrix(m3x3); + Vec3d rotation = Slic3r::Geometry::extract_euler_angles(m3x3); - // invalid rotation axis, we currently handle only rotations around Z axis - if ((rotation.angle() != 0.0) && (rotation.axis() != Vec3d::UnitZ()) && (rotation.axis() != -Vec3d::UnitZ())) + // invalid rotation, we currently handle only rotations around Z axis + if ((rotation(0) != 0.0) || (rotation(1) != 0.0)) return; - double angle_z = (rotation.axis() == Vec3d::UnitZ()) ? rotation.angle() : -rotation.angle(); - instance.offset(0) = offset_x; instance.offset(1) = offset_y; - instance.scaling_factor = sx; - instance.rotation = angle_z; + instance.scaling_factor = scale(0); + instance.rotation = rotation(2); #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM } diff --git a/src/libslic3r/Geometry.cpp b/src/libslic3r/Geometry.cpp index 5d7b936795..c45f087919 100644 --- a/src/libslic3r/Geometry.cpp +++ b/src/libslic3r/Geometry.cpp @@ -1183,4 +1183,38 @@ Transform3d assemble_transform(const Vec3d& translation, const Vec3d& rotation, return transform; } +Vec3d extract_euler_angles(const Eigen::Matrix& rotation_matrix) +{ + // see: https://www.learnopencv.com/rotation-matrix-to-euler-angles/ + double sy = ::sqrt(sqr(rotation_matrix(0, 0)) + sqr(rotation_matrix(1, 0))); + + Vec3d angles = Vec3d::Zero(); + + if (sy >= 1e-6) + { + angles(0) = ::atan2(rotation_matrix(2, 1), rotation_matrix(2, 2)); + angles(1) = ::atan2(-rotation_matrix(2, 0), sy); + angles(2) = ::atan2(rotation_matrix(1, 0), rotation_matrix(0, 0)); + } + else + { + angles(0) = ::atan2(-rotation_matrix(1, 2), rotation_matrix(1, 1)); + angles(1) = ::atan2(-rotation_matrix(2, 0), sy); + angles(2) = 0.0; + } + + return angles; +} + +Vec3d extract_euler_angles(const Transform3d& transform) +{ + // use only the non-translational part of the transform + Eigen::Matrix m = transform.matrix().block(0, 0, 3, 3); + // remove scale + m.col(0).normalize(); + m.col(1).normalize(); + m.col(2).normalize(); + return extract_euler_angles(m); +} + } } diff --git a/src/libslic3r/Geometry.hpp b/src/libslic3r/Geometry.hpp index 57b9cad02f..35f59bdfd7 100644 --- a/src/libslic3r/Geometry.hpp +++ b/src/libslic3r/Geometry.hpp @@ -172,6 +172,14 @@ void assemble_transform(Transform3d& transform, const Vec3d& translation = Vec3d // 4) rotate Z // 5) translate Transform3d assemble_transform(const Vec3d& translation = Vec3d::Zero(), const Vec3d& rotation = Vec3d::Zero(), const Vec3d& scale = Vec3d::Ones()); + +// Returns the euler angles extracted from the given rotation matrix +// Warning -> The matrix should not contain any scale or shear !!! +Vec3d extract_euler_angles(const Eigen::Matrix& rotation_matrix); + +// Returns the euler angles extracted from the given affine transform +// Warning -> The transform should not contain any shear !!! +Vec3d extract_euler_angles(const Transform3d& transform); } } #endif diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 0925488704..2df47519c5 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1413,33 +1413,14 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation) for (unsigned int i : m_list) { - Vec3d radius = m * (m_cache.volumes_data[i].get_position() - m_cache.dragging_center); - (*m_volumes)[i]->set_offset(m_cache.dragging_center + radius); - if (single_full_instance) (*m_volumes)[i]->set_rotation(rotation); else { Eigen::Matrix new_rotation_matrix = (m * m_cache.volumes_data[i].get_rotation_matrix()).matrix().block(0, 0, 3, 3); - // extracts euler angles from the composed transformation - // not using Eigen eulerAngles() method because it returns weird results - // see: https://www.learnopencv.com/rotation-matrix-to-euler-angles/ - double sy = ::sqrt(sqr(new_rotation_matrix(0, 0)) + sqr(new_rotation_matrix(1, 0))); - - Vec3d angles = Vec3d::Zero(); - if (sy >= 1e-6) - { - angles(0) = ::atan2(new_rotation_matrix(2, 1), new_rotation_matrix(2, 2)); - angles(1) = ::atan2(-new_rotation_matrix(2, 0), sy); - angles(2) = ::atan2(new_rotation_matrix(1, 0), new_rotation_matrix(0, 0)); - } - else - { - angles(0) = ::atan2(-new_rotation_matrix(1, 2), new_rotation_matrix(1, 1)); - angles(1) = ::atan2(-new_rotation_matrix(2, 0), sy); - angles(2) = 0.0; - } + Vec3d angles = Geometry::extract_euler_angles(new_rotation_matrix); + (*m_volumes)[i]->set_offset(m_cache.dragging_center + m * (m_cache.volumes_data[i].get_position() - m_cache.dragging_center)); (*m_volumes)[i]->set_rotation(Vec3d(angles(0), angles(1), angles(2))); } } From 59208d79bece36e993e9be8a16fe6d0d9d0c3fde Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 12 Oct 2018 14:23:34 +0200 Subject: [PATCH 4/6] Modified rendering of gizmo scale 3D --- src/slic3r/GUI/GLGizmo.cpp | 85 +++++++------------------------------- src/slic3r/GUI/GLGizmo.hpp | 3 -- 2 files changed, 14 insertions(+), 74 deletions(-) diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index ced0ca85bd..706fd07394 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -709,7 +709,6 @@ GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent) : GLGizmoBase(parent) , m_scale(Vec3d::Ones()) , m_starting_scale(Vec3d::Ones()) - , m_show_starting_box(false) { } @@ -752,7 +751,6 @@ void GLGizmoScale3D::on_start_dragging(const BoundingBoxf3& box) if (m_hover_id != -1) { m_starting_drag_position = m_grabbers[m_hover_id].center; - m_show_starting_box = true; m_starting_box = BoundingBoxf3(box.min - OffsetVec, box.max + OffsetVec); } } @@ -817,10 +815,10 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const ::memcpy((void*)m_grabbers[5].color, (const void*)&AXES_COLOR[2], 3 * sizeof(float)); // uniform - m_grabbers[6].center = Vec3d(m_box.min(0), m_box.min(1), m_box.min(2)); - m_grabbers[7].center = Vec3d(m_box.max(0), m_box.min(1), m_box.min(2)); - m_grabbers[8].center = Vec3d(m_box.max(0), m_box.max(1), m_box.min(2)); - m_grabbers[9].center = Vec3d(m_box.min(0), m_box.max(1), m_box.min(2)); + m_grabbers[6].center = Vec3d(m_box.min(0), m_box.min(1), center(2)); + m_grabbers[7].center = Vec3d(m_box.max(0), m_box.min(1), center(2)); + m_grabbers[8].center = Vec3d(m_box.max(0), m_box.max(1), center(2)); + m_grabbers[9].center = Vec3d(m_box.min(0), m_box.max(1), center(2)); for (int i = 6; i < 10; ++i) { ::memcpy((void*)m_grabbers[i].color, (const void*)m_highlight_color, 3 * sizeof(float)); @@ -830,9 +828,6 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const if (m_hover_id == -1) { - // draw box - ::glColor3fv(m_base_color); - render_box(m_box); // draw connections if (m_grabbers[0].enabled && m_grabbers[1].enabled) { @@ -849,20 +844,16 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const ::glColor3fv(m_grabbers[4].color); render_grabbers_connection(4, 5); } + ::glColor3fv(m_base_color); + render_grabbers_connection(6, 7); + render_grabbers_connection(7, 8); + render_grabbers_connection(8, 9); + render_grabbers_connection(9, 6); // draw grabbers render_grabbers(m_box); } else if ((m_hover_id == 0) || (m_hover_id == 1)) { - // draw starting box - if (m_show_starting_box) - { - ::glColor3fv(m_base_color); - render_box(m_starting_box); - } - // draw current box - ::glColor3fv(m_drag_color); - render_box(m_box); // draw connection ::glColor3fv(m_grabbers[0].color); render_grabbers_connection(0, 1); @@ -872,15 +863,6 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const } else if ((m_hover_id == 2) || (m_hover_id == 3)) { - // draw starting box - if (m_show_starting_box) - { - ::glColor3fv(m_base_color); - render_box(m_starting_box); - } - // draw current box - ::glColor3fv(m_drag_color); - render_box(m_box); // draw connection ::glColor3fv(m_grabbers[2].color); render_grabbers_connection(2, 3); @@ -890,15 +872,6 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const } else if ((m_hover_id == 4) || (m_hover_id == 5)) { - // draw starting box - if (m_show_starting_box) - { - ::glColor3fv(m_base_color); - render_box(m_starting_box); - } - // draw current box - ::glColor3fv(m_drag_color); - render_box(m_box); // draw connection ::glColor3fv(m_grabbers[4].color); render_grabbers_connection(4, 5); @@ -908,15 +881,12 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const } else if (m_hover_id >= 6) { - // draw starting box - if (m_show_starting_box) - { - ::glColor3fv(m_base_color); - render_box(m_starting_box); - } - // draw current box + // draw connection ::glColor3fv(m_drag_color); - render_box(m_box); + render_grabbers_connection(6, 7); + render_grabbers_connection(7, 8); + render_grabbers_connection(8, 9); + render_grabbers_connection(9, 6); // draw grabbers for (int i = 6; i < 10; ++i) { @@ -932,33 +902,6 @@ void GLGizmoScale3D::on_render_for_picking(const BoundingBoxf3& box) const render_grabbers_for_picking(box); } -void GLGizmoScale3D::render_box(const BoundingBoxf3& box) const -{ - // bottom face - ::glBegin(GL_LINE_LOOP); - ::glVertex3f((GLfloat)box.min(0), (GLfloat)box.min(1), (GLfloat)box.min(2)); - ::glVertex3f((GLfloat)box.min(0), (GLfloat)box.max(1), (GLfloat)box.min(2)); - ::glVertex3f((GLfloat)box.max(0), (GLfloat)box.max(1), (GLfloat)box.min(2)); - ::glVertex3f((GLfloat)box.max(0), (GLfloat)box.min(1), (GLfloat)box.min(2)); - ::glEnd(); - - // top face - ::glBegin(GL_LINE_LOOP); - ::glVertex3f((GLfloat)box.min(0), (GLfloat)box.min(1), (GLfloat)box.max(2)); - ::glVertex3f((GLfloat)box.min(0), (GLfloat)box.max(1), (GLfloat)box.max(2)); - ::glVertex3f((GLfloat)box.max(0), (GLfloat)box.max(1), (GLfloat)box.max(2)); - ::glVertex3f((GLfloat)box.max(0), (GLfloat)box.min(1), (GLfloat)box.max(2)); - ::glEnd(); - - // vertical edges - ::glBegin(GL_LINES); - ::glVertex3f((GLfloat)box.min(0), (GLfloat)box.min(1), (GLfloat)box.min(2)); ::glVertex3f((GLfloat)box.min(0), (GLfloat)box.min(1), (GLfloat)box.max(2)); - ::glVertex3f((GLfloat)box.min(0), (GLfloat)box.max(1), (GLfloat)box.min(2)); ::glVertex3f((GLfloat)box.min(0), (GLfloat)box.max(1), (GLfloat)box.max(2)); - ::glVertex3f((GLfloat)box.max(0), (GLfloat)box.max(1), (GLfloat)box.min(2)); ::glVertex3f((GLfloat)box.max(0), (GLfloat)box.max(1), (GLfloat)box.max(2)); - ::glVertex3f((GLfloat)box.max(0), (GLfloat)box.min(1), (GLfloat)box.min(2)); ::glVertex3f((GLfloat)box.max(0), (GLfloat)box.min(1), (GLfloat)box.max(2)); - ::glEnd(); -} - void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2) const { unsigned int grabbers_count = (unsigned int)m_grabbers.size(); diff --git a/src/slic3r/GUI/GLGizmo.hpp b/src/slic3r/GUI/GLGizmo.hpp index 0ad40a8b39..aab16773f5 100644 --- a/src/slic3r/GUI/GLGizmo.hpp +++ b/src/slic3r/GUI/GLGizmo.hpp @@ -277,7 +277,6 @@ class GLGizmoScale3D : public GLGizmoBase Vec3d m_starting_scale; Vec3d m_starting_drag_position; - bool m_show_starting_box; BoundingBoxf3 m_starting_box; public: @@ -302,7 +301,6 @@ public: protected: virtual bool on_init(); virtual void on_start_dragging(const BoundingBoxf3& box); - virtual void on_stop_dragging() { m_show_starting_box = false; } virtual void on_update(const Linef3& mouse_ray); #if ENABLE_GIZMOS_RESET virtual void on_process_double_click(); @@ -311,7 +309,6 @@ protected: virtual void on_render_for_picking(const BoundingBoxf3& box) const; private: - void render_box(const BoundingBoxf3& box) const; void render_grabbers_connection(unsigned int id_1, unsigned int id_2) const; void do_scale_x(const Linef3& mouse_ray); From 76052d33bf7a1fb119b0c1982bb09fede59e1d24 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 12 Oct 2018 15:43:29 +0200 Subject: [PATCH 5/6] New selection -> scaling wip --- src/slic3r/GUI/GLCanvas3D.cpp | 109 +++++++++++++++++++--- src/slic3r/GUI/GLCanvas3D.hpp | 4 +- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 6 +- src/slic3r/GUI/GUI_ObjectManipulation.hpp | 2 +- 4 files changed, 105 insertions(+), 16 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 2df47519c5..86ec79da81 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1409,19 +1409,46 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation) Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), rotation); - bool single_full_instance = is_single_full_instance(); - for (unsigned int i : m_list) { - if (single_full_instance) + if (is_single_full_instance()) (*m_volumes)[i]->set_rotation(rotation); else { - Eigen::Matrix new_rotation_matrix = (m * m_cache.volumes_data[i].get_rotation_matrix()).matrix().block(0, 0, 3, 3); - Vec3d angles = Geometry::extract_euler_angles(new_rotation_matrix); + Eigen::Matrix new_matrix = (m * m_cache.volumes_data[i].get_rotation_matrix()).matrix().block(0, 0, 3, 3); + Vec3d new_rotation = Geometry::extract_euler_angles(new_matrix); (*m_volumes)[i]->set_offset(m_cache.dragging_center + m * (m_cache.volumes_data[i].get_position() - m_cache.dragging_center)); - (*m_volumes)[i]->set_rotation(Vec3d(angles(0), angles(1), angles(2))); + (*m_volumes)[i]->set_rotation(new_rotation); + } + } + + if (m_mode == Instance) + _synchronize_unselected_instances(); + + m_bounding_box_dirty = true; +} + +void GLCanvas3D::Selection::scale(const Vec3d& scale) +{ + if (!m_valid) + return; + + Transform3d m = Transform3d::Identity(); + m.scale(scale); + + for (unsigned int i : m_list) + { + if (is_single_full_instance()) + (*m_volumes)[i]->set_scaling_factor(scale); + else + { + Eigen::Matrix new_matrix = (m * m_cache.volumes_data[i].get_rotation_matrix()).matrix().block(0, 0, 3, 3); + // extracts scaling factors from the composed transformation + Vec3d new_scale(new_matrix.col(0).norm(), new_matrix.col(1).norm(), new_matrix.col(2).norm()); + + (*m_volumes)[i]->set_offset(m_cache.dragging_center + m * (m_cache.volumes_data[i].get_position() - m_cache.dragging_center)); + (*m_volumes)[i]->set_scaling_factor(new_scale); } } @@ -2652,8 +2679,8 @@ wxDEFINE_EVENT(EVT_GLCANVAS_WIPETOWER_MOVED, Vec3dEvent); wxDEFINE_EVENT(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, Event); wxDEFINE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>); -wxDEFINE_EVENT(EVT_GIZMO_SCALE, Vec3dEvent); #if !ENABLE_EXTENDED_SELECTION +wxDEFINE_EVENT(EVT_GIZMO_SCALE, Vec3dEvent); wxDEFINE_EVENT(EVT_GIZMO_ROTATE, Vec3dEvent); #endif // !ENABLE_EXTENDED_SELECTION wxDEFINE_EVENT(EVT_GIZMO_FLATTEN, Vec3dEvent); @@ -3209,6 +3236,11 @@ void GLCanvas3D::update_gizmos_data() #if ENABLE_EXTENDED_SELECTION bool enable_move_z = !m_selection.is_wipe_tower(); m_gizmos.enable_grabber(Gizmos::Move, 2, enable_move_z); + bool enable_scale_xyz = m_selection.is_single_full_instance(); + for (int i = 0; i < 6; ++i) + { + m_gizmos.enable_grabber(Gizmos::Scale, i, enable_scale_xyz); + } if (m_selection.is_single_full_instance()) { @@ -3791,11 +3823,21 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) case Gizmos::Scale: { #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM +#if ENABLE_EXTENDED_SELECTION + m_regenerate_volumes = false; + m_selection.scale(m_gizmos.get_scale()); + _on_scale(); +#else post_event(Vec3dEvent(EVT_GIZMO_SCALE, m_gizmos.get_scale())); +#endif // ENABLE_EXTENDED_SELECTION #else m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale()); #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM +#if ENABLE_EXTENDED_SELECTION + wxGetApp().obj_manipul()->update_settings_value(m_selection); +#else wxGetApp().obj_manipul()->update_scale_values(); +#endif // ENABLE_EXTENDED_SELECTION m_dirty = true; break; } @@ -3804,8 +3846,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #if ENABLE_EXTENDED_SELECTION m_regenerate_volumes = false; - const Vec3d& rotation = m_gizmos.get_rotation(); - m_selection.rotate(rotation); + m_selection.rotate(m_gizmos.get_rotation()); _on_rotate(); #else post_event(Vec3dEvent(EVT_GIZMO_ROTATE, std::move(m_gizmos.get_rotation()))); @@ -4135,15 +4176,17 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) case Gizmos::Scale: { #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM -#if ENABLE_EXTENDED_SELECTION -#else // Apply new temporary scale factors +#if ENABLE_EXTENDED_SELECTION + m_selection.scale(m_gizmos.get_scale()); + wxGetApp().obj_manipul()->update_settings_value(m_selection); +#else const Vec3d& scale = m_gizmos.get_scale(); for (GLVolume* v : volumes) { v->set_scaling_factor(scale); } - wxGetApp().obj_manipul()->update_scale_values(scale); + wxGetApp().obj_manipul()->update_scale_value(scale); #endif // ENABLE_EXTENDED_SELECTION #else // Apply new temporary scale factor @@ -4159,6 +4202,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) case Gizmos::Rotate: { #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM + // Apply new temporary rotations #if ENABLE_EXTENDED_SELECTION m_selection.rotate(m_gizmos.get_rotation()); wxGetApp().obj_manipul()->update_settings_value(m_selection); @@ -4345,7 +4389,10 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) case Gizmos::Scale: { #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - post_event(Vec3dEvent(EVT_GIZMO_SCALE, m_gizmos.get_scale())); +#if ENABLE_EXTENDED_SELECTION + m_regenerate_volumes = false; + _on_scale(); +#endif // ENABLE_EXTENDED_SELECTION #else m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale()); #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM @@ -6473,6 +6520,42 @@ void GLCanvas3D::_on_rotate() // schedule_background_process } + +void GLCanvas3D::_on_scale() +{ + if (m_model == nullptr) + return; + + std::set> done; // prevent scaling instances twice + const Selection::IndicesList& selection = m_selection.get_volume_idxs(); + + for (unsigned int i : selection) + { + const GLVolume* v = m_volumes.volumes[i]; + int object_idx = v->object_idx(); + if (object_idx >= 1000) + continue; + + int instance_idx = v->instance_idx(); + + // prevent rotating instances twice + std::pair done_id(object_idx, instance_idx); + if (done.find(done_id) != done.end()) + continue; + + done.insert(done_id); + + // Rotate instances. + ModelObject* model_object = m_model->objects[object_idx]; + if (model_object != nullptr) + { + model_object->instances[instance_idx]->set_scaling_factor(v->get_scaling_factor()); + model_object->invalidate_bounding_box(); + } + } + + // schedule_background_process +} #else void GLCanvas3D::_on_move(const std::vector& volume_idxs) { diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index d556ea54d5..828e24fa6a 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -115,8 +115,8 @@ wxDECLARE_EVENT(EVT_GLCANVAS_WIPETOWER_MOVED, Vec3dEvent); wxDECLARE_EVENT(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, Event); wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>); -wxDECLARE_EVENT(EVT_GIZMO_SCALE, Vec3dEvent); #if !ENABLE_EXTENDED_SELECTION +wxDECLARE_EVENT(EVT_GIZMO_SCALE, Vec3dEvent); wxDECLARE_EVENT(EVT_GIZMO_ROTATE, Vec3dEvent); #endif // !ENABLE_EXTENDED_SELECTION wxDECLARE_EVENT(EVT_GIZMO_FLATTEN, Vec3dEvent); @@ -491,6 +491,7 @@ public: void translate(const Vec3d& displacement); void rotate(const Vec3d& rotation); + void scale(const Vec3d& scale); void render(bool show_indirect_selection) const; @@ -939,6 +940,7 @@ private: #if ENABLE_EXTENDED_SELECTION void _on_move(); void _on_rotate(); + void _on_scale(); #else void _on_move(const std::vector& volume_idxs); #endif // ENABLE_EXTENDED_SELECTION diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index 5eb90054c0..6eff84d92e 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -274,6 +274,7 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); update_position_value(volume->get_offset()); update_rotation_value(volume->get_rotation()); + update_scale_value(volume->get_scaling_factor()); m_og->enable(); } else @@ -285,6 +286,7 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); update_position_value(volume->get_offset()); update_rotation_value(volume->get_rotation()); + update_scale_value(volume->get_scaling_factor()); m_og->enable(); } else if (selection.is_wipe_tower()) @@ -293,6 +295,7 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); update_position_value(volume->get_offset()); update_rotation_value(volume->get_rotation()); + update_scale_value(volume->get_scaling_factor()); m_og->enable(); } else if (selection.is_modifier()) @@ -301,6 +304,7 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); update_position_value(volume->get_offset()); update_rotation_value(volume->get_rotation()); + update_scale_value(volume->get_scaling_factor()); m_og->enable(); } else @@ -420,7 +424,7 @@ void ObjectManipulation::update_position_value(const Vec3d& position) } #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM -void ObjectManipulation::update_scale_values(const Vec3d& scaling_factor) +void ObjectManipulation::update_scale_value(const Vec3d& scaling_factor) { // this is temporary // to be able to update the values as size diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.hpp b/src/slic3r/GUI/GUI_ObjectManipulation.hpp index 7cd5fce276..c0cd701603 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.hpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.hpp @@ -62,7 +62,7 @@ public: // update scale values after scale unit changing or "gizmos" void update_scale_values(); #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM - void update_scale_values(const Vec3d& scaling_factor); + void update_scale_value(const Vec3d& scaling_factor); #else void update_scale_values(double scaling_factor); #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM From 35c7c418e95399f8e2f1d7b4a4548b04534b663b Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 12 Oct 2018 16:18:37 +0200 Subject: [PATCH 6/6] Small refactoring into GLGizmoBase::Grabber --- src/slic3r/GUI/GLGizmo.cpp | 35 ++++++++++++++++++++--------------- src/slic3r/GUI/GLGizmo.hpp | 6 +++--- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index 706fd07394..d5d7b39e98 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -118,7 +118,7 @@ GLGizmoBase::Grabber::Grabber() color[2] = 1.0f; } -void GLGizmoBase::Grabber::render(bool hover, const BoundingBoxf3& box) const +void GLGizmoBase::Grabber::render(bool hover, float size) const { float render_color[3]; if (hover) @@ -130,13 +130,12 @@ void GLGizmoBase::Grabber::render(bool hover, const BoundingBoxf3& box) const else ::memcpy((void*)render_color, (const void*)color, 3 * sizeof(float)); - render(box, render_color, true); + render(size, render_color, true); } -void GLGizmoBase::Grabber::render(const BoundingBoxf3& box, const float* render_color, bool use_lighting) const +void GLGizmoBase::Grabber::render(float size, const float* render_color, bool use_lighting) const { - float max_size = (float)box.max_size(); - float half_size = dragging ? max_size * SizeFactor * DraggingScaleFactor : max_size * SizeFactor; + float half_size = dragging ? size * SizeFactor * DraggingScaleFactor : size * SizeFactor; half_size = std::max(half_size, MinHalfSize); if (use_lighting) @@ -300,15 +299,19 @@ float GLGizmoBase::picking_color_component(unsigned int id) const void GLGizmoBase::render_grabbers(const BoundingBoxf3& box) const { + float size = (float)box.max_size(); + for (int i = 0; i < (int)m_grabbers.size(); ++i) { if (m_grabbers[i].enabled) - m_grabbers[i].render((m_hover_id == i), box); + m_grabbers[i].render((m_hover_id == i), size); } } void GLGizmoBase::render_grabbers_for_picking(const BoundingBoxf3& box) const { + float size = (float)box.max_size(); + for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i) { if (m_grabbers[i].enabled) @@ -316,7 +319,7 @@ void GLGizmoBase::render_grabbers_for_picking(const BoundingBoxf3& box) const m_grabbers[i].color[0] = 1.0f; m_grabbers[i].color[1] = 1.0f; m_grabbers[i].color[2] = picking_color_component(i); - m_grabbers[i].render_for_picking(box); + m_grabbers[i].render_for_picking(size); } } } @@ -826,6 +829,8 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const ::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f); + float box_max_size = (float)m_box.max_size(); + if (m_hover_id == -1) { // draw connections @@ -858,8 +863,8 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const ::glColor3fv(m_grabbers[0].color); render_grabbers_connection(0, 1); // draw grabbers - m_grabbers[0].render(true, m_box); - m_grabbers[1].render(true, m_box); + m_grabbers[0].render(true, box_max_size); + m_grabbers[1].render(true, box_max_size); } else if ((m_hover_id == 2) || (m_hover_id == 3)) { @@ -867,8 +872,8 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const ::glColor3fv(m_grabbers[2].color); render_grabbers_connection(2, 3); // draw grabbers - m_grabbers[2].render(true, m_box); - m_grabbers[3].render(true, m_box); + m_grabbers[2].render(true, box_max_size); + m_grabbers[3].render(true, box_max_size); } else if ((m_hover_id == 4) || (m_hover_id == 5)) { @@ -876,8 +881,8 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const ::glColor3fv(m_grabbers[4].color); render_grabbers_connection(4, 5); // draw grabbers - m_grabbers[4].render(true, m_box); - m_grabbers[5].render(true, m_box); + m_grabbers[4].render(true, box_max_size); + m_grabbers[5].render(true, box_max_size); } else if (m_hover_id >= 6) { @@ -890,7 +895,7 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const // draw grabbers for (int i = 6; i < 10; ++i) { - m_grabbers[i].render(true, m_box); + m_grabbers[i].render(true, box_max_size); } } } @@ -1132,7 +1137,7 @@ void GLGizmoMove3D::on_render(const BoundingBoxf3& box) const ::glEnd(); // draw grabber - m_grabbers[m_hover_id].render(true, box); + m_grabbers[m_hover_id].render(true, box.max_size()); } } diff --git a/src/slic3r/GUI/GLGizmo.hpp b/src/slic3r/GUI/GLGizmo.hpp index aab16773f5..ef04112826 100644 --- a/src/slic3r/GUI/GLGizmo.hpp +++ b/src/slic3r/GUI/GLGizmo.hpp @@ -34,11 +34,11 @@ protected: Grabber(); - void render(bool hover, const BoundingBoxf3& box) const; - void render_for_picking(const BoundingBoxf3& box) const { render(box, color, false); } + void render(bool hover, float size) const; + void render_for_picking(float size) const { render(size, color, false); } private: - void render(const BoundingBoxf3& box, const float* render_color, bool use_lighting) const; + void render(float size, const float* render_color, bool use_lighting) const; void render_face(float half_size) const; };