From 6ee83b4c19eceba502079ae20a906e9201a9b403 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 22 Nov 2019 16:53:36 +0200 Subject: [PATCH] QmlDesigner: Center on selection box when fit tool is used in 3D Edit Instead of centering edit camera on selected object, center it on the selection box, which includes child objects. Change-Id: I7315a4bcfffc74e72a2b21d0a04fc99ee9f4f3c3 Reviewed-by: Thomas Hartmann Reviewed-by: Mahmoud Badri --- .../qml/qmlpuppet/mockfiles/EditView3D.qml | 9 ++++++--- .../qml/qmlpuppet/mockfiles/SelectionBox.qml | 1 + .../qml2puppet/editor3d/generalhelper.cpp | 17 +++++++++++++---- .../editor3d/selectionboxgeometry.cpp | 8 +++++++- .../qml2puppet/editor3d/selectionboxgeometry.h | 4 ++++ 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml index 7af8cf0cbad..bf1bfebf861 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml @@ -206,6 +206,7 @@ Window { } SelectionBox { + id: selectionBox view3D: editView targetNode: viewWindow.selectedNode } @@ -378,8 +379,10 @@ Window { togglable: false onSelectedChanged: { - if (selected) - cameraControl.fitObject(viewWindow.selectedNode, editView.camera.rotation); + if (selected) { + var targetNode = viewWindow.selectedNode ? selectionBox.model : null; + cameraControl.fitObject(targetNode, editView.camera.rotation); + } } } } @@ -391,7 +394,7 @@ Window { width: 100 height: width editCameraCtrl: cameraControl - selectedNode : viewWindow.selectedNode + selectedNode : viewWindow.selectedNode ? selectionBox.model : null } Column { diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/SelectionBox.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/SelectionBox.qml index 08de0a7ae12..524f5688899 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/SelectionBox.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/SelectionBox.qml @@ -32,6 +32,7 @@ Node { property View3D view3D property Node targetNode: null + property alias model: selectionBoxModel SelectionBoxGeometry { id: selectionBoxGeometry diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp index f5c7c6e6566..850a440a129 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp @@ -26,6 +26,8 @@ #ifdef QUICK3D_MODULE +#include "selectionboxgeometry.h" + #include #include #include @@ -154,8 +156,15 @@ QVector4D GeneralHelper::fitObjectToCamera(QQuick3DCamera *camera, float default if (window) { auto context = QSSGRenderContextInterface::getRenderContextInterface(quintptr(window)); if (!context.isNull()) { - auto bufferManager = context->bufferManager(); - QSSGBounds3 bounds = renderModel->getModelBounds(bufferManager); + QSSGBounds3 bounds; + auto geometry = qobject_cast(modelNode->geometry()); + if (geometry) { + bounds = geometry->bounds(); + } else { + auto bufferManager = context->bufferManager(); + bounds = renderModel->getModelBounds(bufferManager); + } + QVector3D center = bounds.center(); const QVector3D e = bounds.extents(); const QVector3D s = targetObject->sceneScale(); @@ -164,8 +173,8 @@ QVector4D GeneralHelper::fitObjectToCamera(QQuick3DCamera *camera, float default maxExtent *= maxScale; // Adjust lookAt to look directly at the center of the object bounds - QMatrix4x4 m = targetObject->sceneTransform(); - lookAt = m.map(center); + lookAt = renderModel->globalTransform.map(center); + lookAt.setZ(-lookAt.z()); // Render node transforms have inverted z } } } diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.cpp index db6218c3319..77700619237 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -74,6 +73,11 @@ bool QmlDesigner::Internal::SelectionBoxGeometry::isEmpty() const return m_isEmpty; } +QSSGBounds3 SelectionBoxGeometry::bounds() const +{ + return m_bounds; +} + void SelectionBoxGeometry::setTargetNode(QQuick3DNode *targetNode) { if (m_targetNode == targetNode) @@ -166,6 +170,8 @@ QSSGRenderGraphObject *SelectionBoxGeometry::updateSpatialNode(QSSGRenderGraphOb geometry->setPrimitiveType(QSSGRenderGeometry::Lines); geometry->setBounds(minBounds, maxBounds); + m_bounds = QSSGBounds3(minBounds, maxBounds); + bool empty = minBounds.isNull() && maxBounds.isNull(); if (m_isEmpty != empty) { m_isEmpty = empty; diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.h index ef472a51130..08a28cec06c 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.h @@ -30,6 +30,7 @@ #include #include #include +#include namespace QmlDesigner { namespace Internal { @@ -51,6 +52,8 @@ public: QQuick3DViewport *view3D() const; bool isEmpty() const; + QSSGBounds3 bounds() const; + public Q_SLOTS: void setTargetNode(QQuick3DNode *targetNode); void setRootNode(QQuick3DNode *rootNode); @@ -76,6 +79,7 @@ private: QQuick3DNode *m_rootNode = nullptr; bool m_isEmpty = true; QVector m_connections; + QSSGBounds3 m_bounds; }; }