Merge branch 'dev_native' of https://github.com/prusa3d/Slic3r into dev_native

This commit is contained in:
YuSanka 2018-10-15 10:54:20 +02:00
commit 27fea879d3
15 changed files with 314 additions and 219 deletions

View File

@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.2)
include("version.inc") include("version.inc")
set(SLIC3R_RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources") 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) if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type selected, default to Release") message(STATUS "No build type selected, default to Release")
@ -214,8 +215,29 @@ if (NOT GLEW_FOUND)
endif () endif ()
include_directories(${GLEW_INCLUDE_DIRS}) include_directories(${GLEW_INCLUDE_DIRS})
# l10n # Resources and l10n
add_subdirectory(resources/localization) 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. # libslic3r, Slic3r GUI and the slic3r executable.
add_subdirectory(src) add_subdirectory(src)

View File

@ -40,6 +40,8 @@ $BOOST = 'boost_1_63_0'
$CURL = 'curl-7.58.0' $CURL = 'curl-7.58.0'
$TBB_SHA = 'a0dc9bf76d0120f917b641ed095360448cabc85b' $TBB_SHA = 'a0dc9bf76d0120f917b641ed095360448cabc85b'
$TBB = "tbb-$TBB_SHA" $TBB = "tbb-$TBB_SHA"
$WXWIDGETS_VER = "3.1.1"
$WXWIDGETS = "wxWidgets-$WXWIDGETS_VER"
try 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 "$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 "$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 "$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: # Unpack sources:
echo 'Unpacking ...' echo 'Unpacking ...'
if (!(Test-Path $BOOST)) { [IO.Compression.ZipFile]::ExtractToDirectory("$BOOST.zip", '.') } if (!(Test-Path "$BOOST")) { [IO.Compression.ZipFile]::ExtractToDirectory("$BOOST.zip", '.') }
if (!(Test-Path $TBB)) { [IO.Compression.ZipFile]::ExtractToDirectory("$TBB.zip", '.') } if (!(Test-Path "$TBB")) { [IO.Compression.ZipFile]::ExtractToDirectory("$TBB.zip", '.') }
if (!(Test-Path $CURL)) { [IO.Compression.ZipFile]::ExtractToDirectory("$CURL.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: # 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\" Copy-Item -R -Force ..\builds\libcurl-*-winssl\lib\* "$destdir\usr\local\lib\"
popd 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 ""
echo "All done!" echo "All done!"

View File

@ -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"
)

View File

@ -2,6 +2,7 @@
#include "../Model.hpp" #include "../Model.hpp"
#include "../Utils.hpp" #include "../Utils.hpp"
#include "../GCode.hpp" #include "../GCode.hpp"
#include "../Geometry.hpp"
#include "3mf.hpp" #include "3mf.hpp"
@ -1253,7 +1254,7 @@ namespace Slic3r {
// translation // translation
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #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 #else
double offset_x = transform(0, 3); double offset_x = transform(0, 3);
double offset_y = transform(1, 3); double offset_y = transform(1, 3);
@ -1261,50 +1262,41 @@ namespace Slic3r {
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// scale // scale
double sx = ::sqrt(sqr(transform(0, 0)) + sqr(transform(1, 0)) + sqr(transform(2, 0))); Eigen::Matrix<double, 3, 3, Eigen::DontAlign> m3x3 = transform.matrix().block(0, 0, 3, 3);
double sy = ::sqrt(sqr(transform(0, 1)) + sqr(transform(1, 1)) + sqr(transform(2, 1))); Vec3d scale(m3x3.col(0).norm(), m3x3.col(1).norm(), m3x3.col(2).norm());
double sz = ::sqrt(sqr(transform(0, 2)) + sqr(transform(1, 2)) + sqr(transform(2, 2)));
// invalid scale value, return // 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; return;
#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// non-uniform scale value, return // 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; return;
#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
double inv_sx = 1.0 / sx; // remove scale
double inv_sy = 1.0 / sy; m3x3.col(0).normalize();
double inv_sz = 1.0 / sz; m3x3.col(1).normalize();
m3x3.col(2).normalize();
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> 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;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d angles = m3x3.eulerAngles(2, 1, 0); Vec3d rotation = Slic3r::Geometry::extract_euler_angles(m3x3);
Vec3d rotation(angles(2), angles(1), angles(0));
instance.set_offset(offset); instance.set_offset(offset);
instance.set_scaling_factor(Vec3d(sx, sy, sz)); instance.set_scaling_factor(scale);
instance.set_rotation(rotation); instance.set_rotation(rotation);
#else #else
Eigen::AngleAxisd rotation; Vec3d rotation = Slic3r::Geometry::extract_euler_angles(m3x3);
rotation.fromRotationMatrix(m3x3);
// invalid rotation axis, we currently handle only rotations around Z axis // invalid rotation, we currently handle only rotations around Z axis
if ((rotation.angle() != 0.0) && (rotation.axis() != Vec3d::UnitZ()) && (rotation.axis() != -Vec3d::UnitZ())) if ((rotation(0) != 0.0) || (rotation(1) != 0.0))
return; return;
double angle_z = (rotation.axis() == Vec3d::UnitZ()) ? rotation.angle() : -rotation.angle();
instance.offset(0) = offset_x; instance.offset(0) = offset_x;
instance.offset(1) = offset_y; instance.offset(1) = offset_y;
instance.scaling_factor = sx; instance.scaling_factor = scale(0);
instance.rotation = angle_z; instance.rotation = rotation(2);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }

View File

@ -1166,4 +1166,55 @@ 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;
}
Vec3d extract_euler_angles(const Eigen::Matrix<double, 3, 3, Eigen::DontAlign>& 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<double, 3, 3, Eigen::DontAlign> 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);
}
} } } }

View File

@ -157,6 +157,29 @@ class MedialAxis {
const Point& retrieve_endpoint(const VD::cell_type* cell) const; 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());
// 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<double, 3, 3, Eigen::DontAlign>& 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 #endif

View File

@ -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 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(); 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) if (!dont_translate)
m.translate(Vec3d(offset(0), offset(1), 0.0)); 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) if (!dont_scale)
m.scale(scaling_factor); m.scale(scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
return m; return m;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
} }

View File

@ -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_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 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__ #ifdef __APPLE__
// The application is packed in the .dmg archive as 'Slic3r.app/Contents/MacOS/Slic3r' // The application is packed in the .dmg archive as 'Slic3r.app/Contents/MacOS/Slic3r'
// The resources are packed to 'Slic3r.app/Contents/Resources' // The resources are packed to 'Slic3r.app/Contents/Resources'
"../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 #else
#ifdef _WIN32 // The application is packed in the .tar.bz archive (or in AppImage) as 'bin/slic3r',
// The application is packed in the .zip archive in the root, // The resources are packed to 'resources'
// The resources are packed to 'resources' // Path from Slic3r binary to resources:
// Path from Slic3r binary to resources: boost::filesystem::path path_resources = path_to_binary.parent_path() / "../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
#endif #endif
;
set_resources_dir(path_resources.string()); set_resources_dir(path_resources.string());
set_var_dir((path_resources / "icons").string()); set_var_dir((path_resources / "icons").string());
set_local_dir((path_resources / "localization").string()); set_local_dir((path_resources / "localization").string());

View File

@ -389,14 +389,11 @@ const Transform3f& GLVolume::world_matrix() const
{ {
if (m_world_matrix_dirty) 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<float>();
#else
m_world_matrix = Transform3f::Identity(); m_world_matrix = Transform3f::Identity();
m_world_matrix.translate(m_offset.cast<float>()); m_world_matrix.translate(m_offset.cast<float>());
#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<float>());
#else
m_world_matrix.rotate(Eigen::AngleAxisf((float)m_rotation, Vec3f::UnitZ())); m_world_matrix.rotate(Eigen::AngleAxisf((float)m_rotation, Vec3f::UnitZ()));
m_world_matrix.scale((float)m_scaling_factor); m_world_matrix.scale((float)m_scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM

View File

@ -10,6 +10,7 @@
#include "../../libslic3r/ClipperUtils.hpp" #include "../../libslic3r/ClipperUtils.hpp"
#include "../../libslic3r/PrintConfig.hpp" #include "../../libslic3r/PrintConfig.hpp"
#include "../../libslic3r/GCode/PreviewData.hpp" #include "../../libslic3r/GCode/PreviewData.hpp"
#include "../../libslic3r/Geometry.hpp"
#include "GUI_App.hpp" #include "GUI_App.hpp"
#include "GUI_ObjectList.hpp" #include "GUI_ObjectList.hpp"
#include "GUI_ObjectManipulation.hpp" #include "GUI_ObjectManipulation.hpp"
@ -1144,17 +1145,14 @@ GLCanvas3D::Selection::VolumeCache::VolumeCache(const Vec3d& position, const Vec
, m_rotation(rotation) , m_rotation(rotation)
, m_scaling_factor(scaling_factor) , m_scaling_factor(scaling_factor)
{ {
m_rotation_matrix = Transform3d::Identity(); m_rotation_matrix = Geometry::assemble_transform(Vec3d::Zero(), m_rotation);
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()));
} }
GLCanvas3D::Selection::Selection() GLCanvas3D::Selection::Selection()
: m_volumes(nullptr) : m_volumes(nullptr)
, m_model(nullptr) , m_model(nullptr)
, m_mode(Instance) , m_mode(Instance)
, m_type(Invalid) , m_type(Empty)
, m_valid(false) , m_valid(false)
, m_bounding_box_dirty(true) , m_bounding_box_dirty(true)
{ {
@ -1409,46 +1407,48 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation)
if (!m_valid) if (!m_valid)
return; return;
Transform3d m = Transform3d::Identity(); Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), rotation);
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()));
bool single_full_instance = is_single_full_instance();
for (unsigned int i : m_list) for (unsigned int i : m_list)
{ {
Vec3d radius = m * (m_cache.volumes_data[i].get_position() - m_cache.dragging_center); if (is_single_full_instance())
(*m_volumes)[i]->set_offset(m_cache.dragging_center + radius);
if (single_full_instance)
(*m_volumes)[i]->set_rotation(rotation); (*m_volumes)[i]->set_rotation(rotation);
else else
{ {
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> new_rotation_matrix = (m * m_cache.volumes_data[i].get_rotation_matrix()).matrix().block(0, 0, 3, 3); Eigen::Matrix<double, 3, 3, Eigen::DontAlign> new_matrix = (m * m_cache.volumes_data[i].get_rotation_matrix()).matrix().block(0, 0, 3, 3);
// extracts euler angles from the composed transformation Vec3d new_rotation = Geometry::extract_euler_angles(new_matrix);
// 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(); (*m_volumes)[i]->set_offset(m_cache.dragging_center + m * (m_cache.volumes_data[i].get_position() - m_cache.dragging_center));
if (sy >= 1e-6) (*m_volumes)[i]->set_rotation(new_rotation);
{ }
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;
}
(*m_volumes)[i]->set_rotation(Vec3d(angles(0), angles(1), angles(2))); 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<double, 3, 3, Eigen::DontAlign> 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);
} }
} }
@ -2679,8 +2679,8 @@ wxDEFINE_EVENT(EVT_GLCANVAS_WIPETOWER_MOVED, Vec3dEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, Event<bool>); wxDEFINE_EVENT(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, Event<bool>);
wxDEFINE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>); wxDEFINE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>);
wxDEFINE_EVENT(EVT_GIZMO_SCALE, Vec3dEvent);
#if !ENABLE_EXTENDED_SELECTION #if !ENABLE_EXTENDED_SELECTION
wxDEFINE_EVENT(EVT_GIZMO_SCALE, Vec3dEvent);
wxDEFINE_EVENT(EVT_GIZMO_ROTATE, Vec3dEvent); wxDEFINE_EVENT(EVT_GIZMO_ROTATE, Vec3dEvent);
#endif // !ENABLE_EXTENDED_SELECTION #endif // !ENABLE_EXTENDED_SELECTION
wxDEFINE_EVENT(EVT_GIZMO_FLATTEN, Vec3dEvent); wxDEFINE_EVENT(EVT_GIZMO_FLATTEN, Vec3dEvent);
@ -3236,6 +3236,11 @@ void GLCanvas3D::update_gizmos_data()
#if ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION
bool enable_move_z = !m_selection.is_wipe_tower(); bool enable_move_z = !m_selection.is_wipe_tower();
m_gizmos.enable_grabber(Gizmos::Move, 2, enable_move_z); 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()) if (m_selection.is_single_full_instance())
{ {
@ -3818,11 +3823,21 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
case Gizmos::Scale: case Gizmos::Scale:
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #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())); post_event(Vec3dEvent(EVT_GIZMO_SCALE, m_gizmos.get_scale()));
#endif // ENABLE_EXTENDED_SELECTION
#else #else
m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale()); m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale());
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #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(); wxGetApp().obj_manipul()->update_scale_values();
#endif // ENABLE_EXTENDED_SELECTION
m_dirty = true; m_dirty = true;
break; break;
} }
@ -3831,8 +3846,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
#if ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION
m_regenerate_volumes = false; m_regenerate_volumes = false;
const Vec3d& rotation = m_gizmos.get_rotation(); m_selection.rotate(m_gizmos.get_rotation());
m_selection.rotate(rotation);
_on_rotate(); _on_rotate();
#else #else
post_event(Vec3dEvent(EVT_GIZMO_ROTATE, std::move(m_gizmos.get_rotation()))); post_event(Vec3dEvent(EVT_GIZMO_ROTATE, std::move(m_gizmos.get_rotation())));
@ -4162,15 +4176,17 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
case Gizmos::Scale: case Gizmos::Scale:
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
#if ENABLE_EXTENDED_SELECTION
#else
// Apply new temporary scale factors // 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(); const Vec3d& scale = m_gizmos.get_scale();
for (GLVolume* v : volumes) for (GLVolume* v : volumes)
{ {
v->set_scaling_factor(scale); v->set_scaling_factor(scale);
} }
wxGetApp().obj_manipul()->update_scale_values(scale); wxGetApp().obj_manipul()->update_scale_value(scale);
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
#else #else
// Apply new temporary scale factor // Apply new temporary scale factor
@ -4186,6 +4202,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
case Gizmos::Rotate: case Gizmos::Rotate:
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// Apply new temporary rotations
#if ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION
m_selection.rotate(m_gizmos.get_rotation()); m_selection.rotate(m_gizmos.get_rotation());
wxGetApp().obj_manipul()->update_settings_value(m_selection); wxGetApp().obj_manipul()->update_settings_value(m_selection);
@ -4372,7 +4389,10 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
case Gizmos::Scale: case Gizmos::Scale:
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #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 #else
m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale()); m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale());
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
@ -6500,6 +6520,42 @@ void GLCanvas3D::_on_rotate()
// schedule_background_process // schedule_background_process
} }
void GLCanvas3D::_on_scale()
{
if (m_model == nullptr)
return;
std::set<std::pair<int, int>> 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<int, int> 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 #else
void GLCanvas3D::_on_move(const std::vector<int>& volume_idxs) void GLCanvas3D::_on_move(const std::vector<int>& volume_idxs)
{ {

View File

@ -115,8 +115,8 @@ wxDECLARE_EVENT(EVT_GLCANVAS_WIPETOWER_MOVED, Vec3dEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, Event<bool>); wxDECLARE_EVENT(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, Event<bool>);
wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>); wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>);
wxDECLARE_EVENT(EVT_GIZMO_SCALE, Vec3dEvent);
#if !ENABLE_EXTENDED_SELECTION #if !ENABLE_EXTENDED_SELECTION
wxDECLARE_EVENT(EVT_GIZMO_SCALE, Vec3dEvent);
wxDECLARE_EVENT(EVT_GIZMO_ROTATE, Vec3dEvent); wxDECLARE_EVENT(EVT_GIZMO_ROTATE, Vec3dEvent);
#endif // !ENABLE_EXTENDED_SELECTION #endif // !ENABLE_EXTENDED_SELECTION
wxDECLARE_EVENT(EVT_GIZMO_FLATTEN, Vec3dEvent); wxDECLARE_EVENT(EVT_GIZMO_FLATTEN, Vec3dEvent);
@ -491,6 +491,7 @@ public:
void translate(const Vec3d& displacement); void translate(const Vec3d& displacement);
void rotate(const Vec3d& rotation); void rotate(const Vec3d& rotation);
void scale(const Vec3d& scale);
void render(bool show_indirect_selection) const; void render(bool show_indirect_selection) const;
@ -939,6 +940,7 @@ private:
#if ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION
void _on_move(); void _on_move();
void _on_rotate(); void _on_rotate();
void _on_scale();
#else #else
void _on_move(const std::vector<int>& volume_idxs); void _on_move(const std::vector<int>& volume_idxs);
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION

View File

@ -118,7 +118,7 @@ GLGizmoBase::Grabber::Grabber()
color[2] = 1.0f; 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]; float render_color[3];
if (hover) if (hover)
@ -130,13 +130,12 @@ void GLGizmoBase::Grabber::render(bool hover, const BoundingBoxf3& box) const
else else
::memcpy((void*)render_color, (const void*)color, 3 * sizeof(float)); ::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 ? size * SizeFactor * DraggingScaleFactor : size * SizeFactor;
float half_size = dragging ? max_size * SizeFactor * DraggingScaleFactor : max_size * SizeFactor;
half_size = std::max(half_size, MinHalfSize); half_size = std::max(half_size, MinHalfSize);
if (use_lighting) if (use_lighting)
@ -300,15 +299,19 @@ float GLGizmoBase::picking_color_component(unsigned int id) const
void GLGizmoBase::render_grabbers(const BoundingBoxf3& box) 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) for (int i = 0; i < (int)m_grabbers.size(); ++i)
{ {
if (m_grabbers[i].enabled) 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 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) for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i)
{ {
if (m_grabbers[i].enabled) 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[0] = 1.0f;
m_grabbers[i].color[1] = 1.0f; m_grabbers[i].color[1] = 1.0f;
m_grabbers[i].color[2] = picking_color_component(i); m_grabbers[i].color[2] = picking_color_component(i);
m_grabbers[i].render_for_picking(box); m_grabbers[i].render_for_picking(size);
} }
} }
} }
@ -709,7 +712,6 @@ GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent)
: GLGizmoBase(parent) : GLGizmoBase(parent)
, m_scale(Vec3d::Ones()) , m_scale(Vec3d::Ones())
, m_starting_scale(Vec3d::Ones()) , m_starting_scale(Vec3d::Ones())
, m_show_starting_box(false)
{ {
} }
@ -752,7 +754,6 @@ void GLGizmoScale3D::on_start_dragging(const BoundingBoxf3& box)
if (m_hover_id != -1) if (m_hover_id != -1)
{ {
m_starting_drag_position = m_grabbers[m_hover_id].center; 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); m_starting_box = BoundingBoxf3(box.min - OffsetVec, box.max + OffsetVec);
} }
} }
@ -817,10 +818,10 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
::memcpy((void*)m_grabbers[5].color, (const void*)&AXES_COLOR[2], 3 * sizeof(float)); ::memcpy((void*)m_grabbers[5].color, (const void*)&AXES_COLOR[2], 3 * sizeof(float));
// uniform // uniform
m_grabbers[6].center = Vec3d(m_box.min(0), m_box.min(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), m_box.min(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), m_box.min(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), m_box.min(2)); m_grabbers[9].center = Vec3d(m_box.min(0), m_box.max(1), center(2));
for (int i = 6; i < 10; ++i) for (int i = 6; i < 10; ++i)
{ {
::memcpy((void*)m_grabbers[i].color, (const void*)m_highlight_color, 3 * sizeof(float)); ::memcpy((void*)m_grabbers[i].color, (const void*)m_highlight_color, 3 * sizeof(float));
@ -828,11 +829,10 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f); ::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f);
float box_max_size = (float)m_box.max_size();
if (m_hover_id == -1) if (m_hover_id == -1)
{ {
// draw box
::glColor3fv(m_base_color);
render_box(m_box);
// draw connections // draw connections
if (m_grabbers[0].enabled && m_grabbers[1].enabled) if (m_grabbers[0].enabled && m_grabbers[1].enabled)
{ {
@ -849,78 +849,53 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
::glColor3fv(m_grabbers[4].color); ::glColor3fv(m_grabbers[4].color);
render_grabbers_connection(4, 5); 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 // draw grabbers
render_grabbers(m_box); render_grabbers(m_box);
} }
else if ((m_hover_id == 0) || (m_hover_id == 1)) 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 // draw connection
::glColor3fv(m_grabbers[0].color); ::glColor3fv(m_grabbers[0].color);
render_grabbers_connection(0, 1); render_grabbers_connection(0, 1);
// draw grabbers // draw grabbers
m_grabbers[0].render(true, m_box); m_grabbers[0].render(true, box_max_size);
m_grabbers[1].render(true, m_box); m_grabbers[1].render(true, box_max_size);
} }
else if ((m_hover_id == 2) || (m_hover_id == 3)) 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 // draw connection
::glColor3fv(m_grabbers[2].color); ::glColor3fv(m_grabbers[2].color);
render_grabbers_connection(2, 3); render_grabbers_connection(2, 3);
// draw grabbers // draw grabbers
m_grabbers[2].render(true, m_box); m_grabbers[2].render(true, box_max_size);
m_grabbers[3].render(true, m_box); m_grabbers[3].render(true, box_max_size);
} }
else if ((m_hover_id == 4) || (m_hover_id == 5)) 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 // draw connection
::glColor3fv(m_grabbers[4].color); ::glColor3fv(m_grabbers[4].color);
render_grabbers_connection(4, 5); render_grabbers_connection(4, 5);
// draw grabbers // draw grabbers
m_grabbers[4].render(true, m_box); m_grabbers[4].render(true, box_max_size);
m_grabbers[5].render(true, m_box); m_grabbers[5].render(true, box_max_size);
} }
else if (m_hover_id >= 6) else if (m_hover_id >= 6)
{ {
// draw starting box // draw connection
if (m_show_starting_box)
{
::glColor3fv(m_base_color);
render_box(m_starting_box);
}
// draw current box
::glColor3fv(m_drag_color); ::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 // draw grabbers
for (int i = 6; i < 10; ++i) for (int i = 6; i < 10; ++i)
{ {
m_grabbers[i].render(true, m_box); m_grabbers[i].render(true, box_max_size);
} }
} }
} }
@ -932,33 +907,6 @@ void GLGizmoScale3D::on_render_for_picking(const BoundingBoxf3& box) const
render_grabbers_for_picking(box); 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 void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2) const
{ {
unsigned int grabbers_count = (unsigned int)m_grabbers.size(); unsigned int grabbers_count = (unsigned int)m_grabbers.size();
@ -1189,7 +1137,7 @@ void GLGizmoMove3D::on_render(const BoundingBoxf3& box) const
::glEnd(); ::glEnd();
// draw grabber // draw grabber
m_grabbers[m_hover_id].render(true, box); m_grabbers[m_hover_id].render(true, box.max_size());
} }
} }

View File

@ -34,11 +34,11 @@ protected:
Grabber(); Grabber();
void render(bool hover, const BoundingBoxf3& box) const; void render(bool hover, float size) const;
void render_for_picking(const BoundingBoxf3& box) const { render(box, color, false); } void render_for_picking(float size) const { render(size, color, false); }
private: 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; void render_face(float half_size) const;
}; };
@ -277,7 +277,6 @@ class GLGizmoScale3D : public GLGizmoBase
Vec3d m_starting_scale; Vec3d m_starting_scale;
Vec3d m_starting_drag_position; Vec3d m_starting_drag_position;
bool m_show_starting_box;
BoundingBoxf3 m_starting_box; BoundingBoxf3 m_starting_box;
public: public:
@ -302,7 +301,6 @@ public:
protected: protected:
virtual bool on_init(); virtual bool on_init();
virtual void on_start_dragging(const BoundingBoxf3& box); 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); virtual void on_update(const Linef3& mouse_ray);
#if ENABLE_GIZMOS_RESET #if ENABLE_GIZMOS_RESET
virtual void on_process_double_click(); virtual void on_process_double_click();
@ -311,7 +309,6 @@ protected:
virtual void on_render_for_picking(const BoundingBoxf3& box) const; virtual void on_render_for_picking(const BoundingBoxf3& box) const;
private: private:
void render_box(const BoundingBoxf3& box) const;
void render_grabbers_connection(unsigned int id_1, unsigned int id_2) const; void render_grabbers_connection(unsigned int id_1, unsigned int id_2) const;
void do_scale_x(const Linef3& mouse_ray); void do_scale_x(const Linef3& mouse_ray);

View File

@ -274,6 +274,7 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
update_position_value(volume->get_offset()); update_position_value(volume->get_offset());
update_rotation_value(volume->get_rotation()); update_rotation_value(volume->get_rotation());
update_scale_value(volume->get_scaling_factor());
m_og->enable(); m_og->enable();
} }
else 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()); const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
update_position_value(volume->get_offset()); update_position_value(volume->get_offset());
update_rotation_value(volume->get_rotation()); update_rotation_value(volume->get_rotation());
update_scale_value(volume->get_scaling_factor());
m_og->enable(); m_og->enable();
} }
else if (selection.is_wipe_tower()) 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()); const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
update_position_value(volume->get_offset()); update_position_value(volume->get_offset());
update_rotation_value(volume->get_rotation()); update_rotation_value(volume->get_rotation());
update_scale_value(volume->get_scaling_factor());
m_og->enable(); m_og->enable();
} }
else if (selection.is_modifier()) 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()); const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
update_position_value(volume->get_offset()); update_position_value(volume->get_offset());
update_rotation_value(volume->get_rotation()); update_rotation_value(volume->get_rotation());
update_scale_value(volume->get_scaling_factor());
m_og->enable(); m_og->enable();
} }
else else
@ -420,7 +424,7 @@ void ObjectManipulation::update_position_value(const Vec3d& position)
} }
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #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 // this is temporary
// to be able to update the values as size // to be able to update the values as size

View File

@ -62,7 +62,7 @@ public:
// update scale values after scale unit changing or "gizmos" // update scale values after scale unit changing or "gizmos"
void update_scale_values(); void update_scale_values();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void update_scale_values(const Vec3d& scaling_factor); void update_scale_value(const Vec3d& scaling_factor);
#else #else
void update_scale_values(double scaling_factor); void update_scale_values(double scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM