summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2019-12-04 14:09:07 +0200
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2019-12-04 14:24:53 +0000
commitf021680513fc95d979c4bbf36fa86b5c87f6ff44 (patch)
tree82a02e0e32c188d5a82570dd91be0648f9cc5ed1 /share
parentb5499f0360f4be35b32f3060e86cddeb101326d9 (diff)
downloadqt-creator-f021680513fc95d979c4bbf36fa86b5c87f6ff44.tar.gz
QmlDesigner: Fix selection box size calculations
Selection box for zero size items ended up being infinite, which broke some functionality like fit to camera. Now boxes should be correctly zero sized for non-model items. This also fixes issues with parent box size if it has zero size children. Change-Id: I3c8fae3ee971fbb0cf9e0de2615c107ce97a76f8 Fixes: QDS-1287 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'share')
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp6
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.cpp20
2 files changed, 21 insertions, 5 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp
index 150b8e9ab1..84e28ac4ec 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp
@@ -149,7 +149,8 @@ QVector4D GeneralHelper::focusObjectToCamera(QQuick3DCamera *camera, float defau
QVector3D lookAt = targetObject ? targetObject->scenePosition() : QVector3D();
// Get object bounds
- qreal maxExtent = 200.;
+ const qreal defaultExtent = 200.;
+ qreal maxExtent = defaultExtent;
if (auto modelNode = qobject_cast<QQuick3DModel *>(targetObject)) {
auto targetPriv = QQuick3DObjectPrivate::get(targetObject);
if (auto renderModel = static_cast<QSSGRenderModel *>(targetPriv->spatialNode)) {
@@ -173,6 +174,9 @@ QVector4D GeneralHelper::focusObjectToCamera(QQuick3DCamera *camera, float defau
maxExtent = qSqrt(qreal(e.x() * e.x() + e.y() * e.y() + e.z() * e.z()));
maxExtent *= maxScale;
+ if (maxExtent < 0.0001)
+ maxExtent = defaultExtent;
+
// Adjust lookAt to look directly at the center of the object bounds
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 1fb4f445a6..17b101326e 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.cpp
@@ -43,6 +43,8 @@ namespace Internal {
static const float floatMin = std::numeric_limits<float>::lowest();
static const float floatMax = std::numeric_limits<float>::max();
+static const QVector3D maxVec = QVector3D(floatMax, floatMax, floatMax);
+static const QVector3D minVec = QVector3D(floatMin, floatMin, floatMin);
SelectionBoxGeometry::SelectionBoxGeometry()
: QQuick3DGeometry()
@@ -136,8 +138,8 @@ QSSGRenderGraphObject *SelectionBoxGeometry::updateSpatialNode(QSSGRenderGraphOb
QByteArray vertexData;
QByteArray indexData;
- QVector3D minBounds = QVector3D(floatMax, floatMax, floatMax);
- QVector3D maxBounds = QVector3D(floatMin, floatMin, floatMin);
+ QVector3D minBounds = maxVec;
+ QVector3D maxBounds = minVec;
if (m_targetNode) {
auto rootPriv = QQuick3DObjectPrivate::get(m_rootNode);
@@ -165,6 +167,8 @@ QSSGRenderGraphObject *SelectionBoxGeometry::updateSpatialNode(QSSGRenderGraphOb
}
} else {
// Fill some dummy data so geometry won't get rejected
+ minBounds = {};
+ maxBounds = {};
appendVertexData(QMatrix4x4(), vertexData, indexData, minBounds, maxBounds);
}
@@ -207,8 +211,8 @@ void SelectionBoxGeometry::getBounds(
trackNodeChanges(node);
}
- QVector3D localMinBounds = QVector3D(floatMax, floatMax, floatMax);
- QVector3D localMaxBounds = QVector3D(floatMin, floatMin, floatMin);
+ QVector3D localMinBounds = maxVec;
+ QVector3D localMaxBounds = minVec;
// Find bounds for children
QVector<QVector3D> minBoundsVec;
@@ -277,6 +281,14 @@ void SelectionBoxGeometry::getBounds(
}
}
}
+ } else {
+ combineMinBounds(localMinBounds, {});
+ combineMaxBounds(localMaxBounds, {});
+ }
+
+ if (localMaxBounds == minVec) {
+ localMinBounds = {};
+ localMaxBounds = {};
}
// Transform local space bounding box to parent space