Gui: Fix alignment direction for transformed objects

This commit is contained in:
Bas Ruigrok
2024-08-04 16:13:19 +02:00
parent e9fc6fb89a
commit beddb57ae8

View File

@@ -127,9 +127,9 @@
#include "Utilities.h"
FC_LOG_LEVEL_INIT("3DViewer",true,true)
FC_LOG_LEVEL_INIT("3DViewer", true, true)
//#define FC_LOGGING_CB
// #define FC_LOGGING_CB
using namespace Gui;
@@ -3352,7 +3352,7 @@ void View3DInventorViewer::alignToSelection()
return;
}
const auto selection = Selection().getSelection();
const auto selection = Selection().getSelection(nullptr, ResolveMode::NoResolve);
// Empty selection
if (selection.empty()) {
@@ -3367,13 +3367,18 @@ void View3DInventorViewer::alignToSelection()
// Get the geo feature
App::GeoFeature* geoFeature = nullptr;
App::ElementNamePair elementName;
App::GeoFeature::resolveElement(selection[0].pObject, selection[0].SubName, elementName, false, App::GeoFeature::ElementNameType::Normal, nullptr, nullptr, &geoFeature);
App::GeoFeature::resolveElement(selection[0].pObject, selection[0].SubName, elementName, true, App::GeoFeature::ElementNameType::Normal, nullptr, nullptr, &geoFeature);
if (!geoFeature) {
return;
}
const auto globalPlacement = App::GeoFeature::getGlobalPlacement(selection[0].pResolvedObject, selection[0].pObject, elementName.oldName);
const auto rotation = globalPlacement.getRotation() * geoFeature->Placement.getValue().getRotation().inverse();
const auto geoFeatureSubName = Base::Tools::splitSubName(elementName.oldName).back();
Base::Vector3d direction;
if (geoFeature->getCameraAlignmentDirection(direction, selection[0].SubName)) {
if (geoFeature->getCameraAlignmentDirection(direction, geoFeatureSubName.c_str())) {
rotation.multVec(direction, direction);
const auto orientation = SbRotation(SbVec3f(0, 0, 1), Base::convertTo<SbVec3f>(direction));
setCameraOrientation(orientation);
}