QmlPuppet: Fix multiselection 3D transformations when nodes have pivot

We simply need to store the scene position of the pivot point of the
node instead of node itself and work with that.

Fixes: QDS-4515
Change-Id: I99155636c52897794bea21b2db7f7d2d00059d91
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Miikka Heikkinen
2021-06-10 15:16:38 +03:00
parent 4e1ca8d3c5
commit 74f65abed0
2 changed files with 23 additions and 5 deletions

View File

@@ -41,6 +41,7 @@
#include <QtQuick3DRuntimeRender/private/qssgrenderbuffermanager_p.h>
#include <QtQuick3DRuntimeRender/private/qssgrendermodel_p.h>
#include <QtQuick3DUtils/private/qssgbounds3_p.h>
#include <QtQuick3DUtils/private/qssgutils_p.h>
#include <QtQuick/qquickwindow.h>
#include <QtQuick/qquickitem.h>
#include <QtCore/qmath.h>
@@ -403,11 +404,8 @@ void GeneralHelper::setMultiSelectionTargets(QQuick3DNode *multiSelectRootNode,
void GeneralHelper::resetMultiSelectionNode()
{
for (auto it = m_multiSelDataMap.begin(); it != m_multiSelDataMap.end(); ++it) {
it.value() = {it.key()->scenePosition(),
it.key()->scale(),
it.key()->rotation()};
}
for (auto it = m_multiSelDataMap.begin(); it != m_multiSelDataMap.end(); ++it)
it.value() = {pivotScenePosition(it.key()), it.key()->scale(), it.key()->rotation()};
m_multiSelNodeData = {};
if (!m_multiSelDataMap.isEmpty()) {
@@ -570,6 +568,25 @@ void GeneralHelper::handlePendingToolStateUpdate()
m_toolStatesPending.clear();
}
// Calculate scene position of the node's pivot point, which in practice is just the position
// of the node without applying the pivot offset.
QVector3D GeneralHelper::pivotScenePosition(QQuick3DNode *node) const
{
if (!node)
return {};
QQuick3DNode *parent = node->parentNode();
if (!parent)
return node->position();
QMatrix4x4 localTransform;
localTransform.translate(node->position());
const QMatrix4x4 sceneTransform = parent->sceneTransform() * localTransform;
return mat44::getPosition(sceneTransform);
}
}
}

View File

@@ -119,6 +119,7 @@ protected:
private:
void handlePendingToolStateUpdate();
QVector3D pivotScenePosition(QQuick3DNode *node) const;
QTimer m_overlayUpdateTimer;
QTimer m_toolStateUpdateTimer;