aboutsummaryrefslogtreecommitdiffstats
path: root/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2022-05-27 14:14:22 +0300
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2022-05-30 14:16:53 +0000
commit80ea026fd8e8dcdb5bda48f66e48a2fdf787b6be (patch)
tree53743f18a6e4fdc02b6b322579f36e48b9afdceb /share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d
parent46049bac323badde4d619df459d77f0e26cd16d8 (diff)
QmlDesigner: Refactor library icon generation for imported 3D assets
Previously, icon generation was done at import time, but that was wasteful, as we now have image cache backed icon generation available for component library icons. Added the few remaining missing bits to support icon generation for image cache and disabled the old icon generation implementation for Qt6. A few issues in fit algorithm for preview image generation were also uncovered and fixed to make icons render scene in comparable size to the old version. Qt5 imports still generate using old way since component library 3D previews generation doesn't work on Qt5. Fixes: QDS-6205 Change-Id: I5418fa19d86e81adcd184be023f1dfbc813d0bf5 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Samuel Ghinet <samuel.ghinet@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d')
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp31
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h2
2 files changed, 27 insertions, 6 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp
index 3b774c3f4a..7e843012be 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.cpp
@@ -308,7 +308,7 @@ QVector4D GeneralHelper::focusNodesToCamera(QQuick3DCamera *camera, float defaul
// and recalculating bounds for every frame is not a problem.
void GeneralHelper::calculateNodeBoundsAndFocusCamera(
QQuick3DCamera *camera, QQuick3DNode *node, QQuick3DViewport *viewPort,
- float defaultLookAtDistance)
+ float defaultLookAtDistance, bool closeUp)
{
QVector3D minBounds;
QVector3D maxBounds;
@@ -317,7 +317,9 @@ void GeneralHelper::calculateNodeBoundsAndFocusCamera(
QVector3D extents = maxBounds - minBounds;
QVector3D lookAt = minBounds + (extents / 2.f);
- float maxExtent = qMax(extents.x(), qMax(extents.y(), extents.z()));
+ float maxExtent = qSqrt(qreal(extents.x()) * qreal(extents.x())
+ + qreal(extents.y()) * qreal(extents.y())
+ + qreal(extents.z()) * qreal(extents.z()));
// Reset camera position to default zoom
QMatrix4x4 m = camera->sceneTransform();
@@ -328,9 +330,27 @@ void GeneralHelper::calculateNodeBoundsAndFocusCamera(
camera->setPosition(lookAt + newLookVector);
- float newZoomFactor = maxExtent / 725.f; // Divisor taken from focusNodesToCamera function
+ // CloseUp divisor is used for icon generation, where we can allow some extreme models to go
+ // slightly out of bounds for better results generally. The other divisor is used for other
+ // previews, where the image is larger to begin with and we would also like some margin
+ // between preview edge and the rendered model, so we can be more conservative with the zoom.
+ // The divisor values are empirically selected to provide nice result.
+ float divisor = closeUp ? 1250.f : 1050.f;
+ float newZoomFactor = maxExtent / divisor;
zoomCamera(viewPort, camera, 0, defaultLookAtDistance, lookAt, newZoomFactor, false);
+
+ if (auto perspectiveCamera = qobject_cast<QQuick3DPerspectiveCamera *>(camera)) {
+ // Fix camera near/far clips in case we are dealing with extreme zooms
+ const float cameraDist = qAbs((camera->position() - lookAt).length());
+ const float minDist = cameraDist - (maxExtent / 2.f);
+ const float maxDist = cameraDist + (maxExtent / 2.f);
+ if (minDist < perspectiveCamera->clipNear() || maxDist > perspectiveCamera->clipFar()) {
+ perspectiveCamera->setClipNear(minDist * 0.99);
+ perspectiveCamera->setClipFar(maxDist * 1.01);
+ }
+
+ }
}
// Aligns any cameras found in nodes list to a camera.
@@ -823,12 +843,13 @@ bool GeneralHelper::getBounds(QQuick3DViewport *view3D, QQuick3DNode *node, QVec
if (auto childNode = qobject_cast<QQuick3DNode *>(child)) {
QVector3D newMinBounds = minBounds;
QVector3D newMaxBounds = maxBounds;
- hasModel = getBounds(view3D, childNode, newMinBounds, newMaxBounds, true);
+ bool childHasModel = getBounds(view3D, childNode, newMinBounds, newMaxBounds, true);
// Ignore any subtrees that do not have Model in them as we don't need those
// for visual bounds calculations
- if (hasModel) {
+ if (childHasModel) {
minBoundsVec << newMinBounds;
maxBoundsVec << newMaxBounds;
+ hasModel = true;
}
}
}
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h
index 562848c772..98974cfda9 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/generalhelper.h
@@ -77,7 +77,7 @@ public:
bool closeUp = false);
Q_INVOKABLE void calculateNodeBoundsAndFocusCamera(QQuick3DCamera *camera, QQuick3DNode *node,
QQuick3DViewport *viewPort,
- float defaultLookAtDistance);
+ float defaultLookAtDistance, bool closeUp);
Q_INVOKABLE void alignCameras(QQuick3DCamera *camera, const QVariant &nodes);
Q_INVOKABLE QVector3D alignView(QQuick3DCamera *camera, const QVariant &nodes,
const QVector3D &lookAtPoint);