forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user