forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -206,6 +206,7 @@ Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SelectionBox {
|
SelectionBox {
|
||||||
|
id: selectionBox
|
||||||
view3D: editView
|
view3D: editView
|
||||||
targetNode: viewWindow.selectedNode
|
targetNode: viewWindow.selectedNode
|
||||||
}
|
}
|
||||||
@@ -378,8 +379,10 @@ Window {
|
|||||||
togglable: false
|
togglable: false
|
||||||
|
|
||||||
onSelectedChanged: {
|
onSelectedChanged: {
|
||||||
if (selected)
|
if (selected) {
|
||||||
cameraControl.fitObject(viewWindow.selectedNode, editView.camera.rotation);
|
var targetNode = viewWindow.selectedNode ? selectionBox.model : null;
|
||||||
|
cameraControl.fitObject(targetNode, editView.camera.rotation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,7 +394,7 @@ Window {
|
|||||||
width: 100
|
width: 100
|
||||||
height: width
|
height: width
|
||||||
editCameraCtrl: cameraControl
|
editCameraCtrl: cameraControl
|
||||||
selectedNode : viewWindow.selectedNode
|
selectedNode : viewWindow.selectedNode ? selectionBox.model : null
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
|
@@ -32,6 +32,7 @@ Node {
|
|||||||
|
|
||||||
property View3D view3D
|
property View3D view3D
|
||||||
property Node targetNode: null
|
property Node targetNode: null
|
||||||
|
property alias model: selectionBoxModel
|
||||||
|
|
||||||
SelectionBoxGeometry {
|
SelectionBoxGeometry {
|
||||||
id: selectionBoxGeometry
|
id: selectionBoxGeometry
|
||||||
|
@@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
#ifdef QUICK3D_MODULE
|
#ifdef QUICK3D_MODULE
|
||||||
|
|
||||||
|
#include "selectionboxgeometry.h"
|
||||||
|
|
||||||
#include <QtQuick3D/private/qquick3dorthographiccamera_p.h>
|
#include <QtQuick3D/private/qquick3dorthographiccamera_p.h>
|
||||||
#include <QtQuick3D/private/qquick3dperspectivecamera_p.h>
|
#include <QtQuick3D/private/qquick3dperspectivecamera_p.h>
|
||||||
#include <QtQuick3D/private/qquick3dobject_p_p.h>
|
#include <QtQuick3D/private/qquick3dobject_p_p.h>
|
||||||
@@ -154,8 +156,15 @@ QVector4D GeneralHelper::fitObjectToCamera(QQuick3DCamera *camera, float default
|
|||||||
if (window) {
|
if (window) {
|
||||||
auto context = QSSGRenderContextInterface::getRenderContextInterface(quintptr(window));
|
auto context = QSSGRenderContextInterface::getRenderContextInterface(quintptr(window));
|
||||||
if (!context.isNull()) {
|
if (!context.isNull()) {
|
||||||
|
QSSGBounds3 bounds;
|
||||||
|
auto geometry = qobject_cast<SelectionBoxGeometry *>(modelNode->geometry());
|
||||||
|
if (geometry) {
|
||||||
|
bounds = geometry->bounds();
|
||||||
|
} else {
|
||||||
auto bufferManager = context->bufferManager();
|
auto bufferManager = context->bufferManager();
|
||||||
QSSGBounds3 bounds = renderModel->getModelBounds(bufferManager);
|
bounds = renderModel->getModelBounds(bufferManager);
|
||||||
|
}
|
||||||
|
|
||||||
QVector3D center = bounds.center();
|
QVector3D center = bounds.center();
|
||||||
const QVector3D e = bounds.extents();
|
const QVector3D e = bounds.extents();
|
||||||
const QVector3D s = targetObject->sceneScale();
|
const QVector3D s = targetObject->sceneScale();
|
||||||
@@ -164,8 +173,8 @@ QVector4D GeneralHelper::fitObjectToCamera(QQuick3DCamera *camera, float default
|
|||||||
maxExtent *= maxScale;
|
maxExtent *= maxScale;
|
||||||
|
|
||||||
// Adjust lookAt to look directly at the center of the object bounds
|
// Adjust lookAt to look directly at the center of the object bounds
|
||||||
QMatrix4x4 m = targetObject->sceneTransform();
|
lookAt = renderModel->globalTransform.map(center);
|
||||||
lookAt = m.map(center);
|
lookAt.setZ(-lookAt.z()); // Render node transforms have inverted z
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,6 @@
|
|||||||
#include <QtQuick3DRuntimeRender/private/qssgrendermodel_p.h>
|
#include <QtQuick3DRuntimeRender/private/qssgrendermodel_p.h>
|
||||||
#include <QtQuick3DRuntimeRender/private/qssgrendercontextcore_p.h>
|
#include <QtQuick3DRuntimeRender/private/qssgrendercontextcore_p.h>
|
||||||
#include <QtQuick3DRuntimeRender/private/qssgrenderbuffermanager_p.h>
|
#include <QtQuick3DRuntimeRender/private/qssgrenderbuffermanager_p.h>
|
||||||
#include <QtQuick3DUtils/private/qssgbounds3_p.h>
|
|
||||||
#include <QtQuick3D/private/qquick3dmodel_p.h>
|
#include <QtQuick3D/private/qquick3dmodel_p.h>
|
||||||
#include <QtQuick3D/private/qquick3dobject_p_p.h>
|
#include <QtQuick3D/private/qquick3dobject_p_p.h>
|
||||||
#include <QtQuick/qquickwindow.h>
|
#include <QtQuick/qquickwindow.h>
|
||||||
@@ -74,6 +73,11 @@ bool QmlDesigner::Internal::SelectionBoxGeometry::isEmpty() const
|
|||||||
return m_isEmpty;
|
return m_isEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSSGBounds3 SelectionBoxGeometry::bounds() const
|
||||||
|
{
|
||||||
|
return m_bounds;
|
||||||
|
}
|
||||||
|
|
||||||
void SelectionBoxGeometry::setTargetNode(QQuick3DNode *targetNode)
|
void SelectionBoxGeometry::setTargetNode(QQuick3DNode *targetNode)
|
||||||
{
|
{
|
||||||
if (m_targetNode == targetNode)
|
if (m_targetNode == targetNode)
|
||||||
@@ -166,6 +170,8 @@ QSSGRenderGraphObject *SelectionBoxGeometry::updateSpatialNode(QSSGRenderGraphOb
|
|||||||
geometry->setPrimitiveType(QSSGRenderGeometry::Lines);
|
geometry->setPrimitiveType(QSSGRenderGeometry::Lines);
|
||||||
geometry->setBounds(minBounds, maxBounds);
|
geometry->setBounds(minBounds, maxBounds);
|
||||||
|
|
||||||
|
m_bounds = QSSGBounds3(minBounds, maxBounds);
|
||||||
|
|
||||||
bool empty = minBounds.isNull() && maxBounds.isNull();
|
bool empty = minBounds.isNull() && maxBounds.isNull();
|
||||||
if (m_isEmpty != empty) {
|
if (m_isEmpty != empty) {
|
||||||
m_isEmpty = empty;
|
m_isEmpty = empty;
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include <QtQuick3D/private/qquick3dnode_p.h>
|
#include <QtQuick3D/private/qquick3dnode_p.h>
|
||||||
#include <QtQuick3D/private/qquick3dgeometry_p.h>
|
#include <QtQuick3D/private/qquick3dgeometry_p.h>
|
||||||
#include <QtQuick3D/private/qquick3dviewport_p.h>
|
#include <QtQuick3D/private/qquick3dviewport_p.h>
|
||||||
|
#include <QtQuick3DUtils/private/qssgbounds3_p.h>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -51,6 +52,8 @@ public:
|
|||||||
QQuick3DViewport *view3D() const;
|
QQuick3DViewport *view3D() const;
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
|
|
||||||
|
QSSGBounds3 bounds() const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setTargetNode(QQuick3DNode *targetNode);
|
void setTargetNode(QQuick3DNode *targetNode);
|
||||||
void setRootNode(QQuick3DNode *rootNode);
|
void setRootNode(QQuick3DNode *rootNode);
|
||||||
@@ -76,6 +79,7 @@ private:
|
|||||||
QQuick3DNode *m_rootNode = nullptr;
|
QQuick3DNode *m_rootNode = nullptr;
|
||||||
bool m_isEmpty = true;
|
bool m_isEmpty = true;
|
||||||
QVector<QMetaObject::Connection> m_connections;
|
QVector<QMetaObject::Connection> m_connections;
|
||||||
|
QSSGBounds3 m_bounds;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user