summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2019-11-22 16:53:36 +0200
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2019-11-25 08:48:08 +0000
commit6ee83b4c19eceba502079ae20a906e9201a9b403 (patch)
tree45d8f406e273db93af956578a955c1722a20fd2b
parente0af519d1a662731a838dc2eb4264f87d4ea0f1f (diff)
downloadqt-creator-6ee83b4c19eceba502079ae20a906e9201a9b403.tar.gz
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 <thomas.hartmann@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
-rw-r--r--share/qtcreator/qml/qmlpuppet/mockfiles/EditView3D.qml9
-rw-r--r--share/qtcreator/qml/qmlpuppet/mockfiles/SelectionBox.qml1
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp17
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.cpp8
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.h4
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 7af8cf0cba..bf1bfebf86 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 08de0a7ae1..524f568889 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 f5c7c6e656..850a440a12 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 <QtQuick3D/private/qquick3dorthographiccamera_p.h>
#include <QtQuick3D/private/qquick3dperspectivecamera_p.h>
#include <QtQuick3D/private/qquick3dobject_p_p.h>
@@ -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<SelectionBoxGeometry *>(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 db6218c331..7770061923 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.cpp
@@ -31,7 +31,6 @@
#include <QtQuick3DRuntimeRender/private/qssgrendermodel_p.h>
#include <QtQuick3DRuntimeRender/private/qssgrendercontextcore_p.h>
#include <QtQuick3DRuntimeRender/private/qssgrenderbuffermanager_p.h>
-#include <QtQuick3DUtils/private/qssgbounds3_p.h>
#include <QtQuick3D/private/qquick3dmodel_p.h>
#include <QtQuick3D/private/qquick3dobject_p_p.h>
#include <QtQuick/qquickwindow.h>
@@ -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 ef472a5113..08a28cec06 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.h
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.h
@@ -30,6 +30,7 @@
#include <QtQuick3D/private/qquick3dnode_p.h>
#include <QtQuick3D/private/qquick3dgeometry_p.h>
#include <QtQuick3D/private/qquick3dviewport_p.h>
+#include <QtQuick3DUtils/private/qssgbounds3_p.h>
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<QMetaObject::Connection> m_connections;
+ QSSGBounds3 m_bounds;
};
}