diff options
-rw-r--r-- | share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp | 6 | ||||
-rw-r--r-- | share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/selectionboxgeometry.cpp | 20 |
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 |