forked from qt-creator/qt-creator
QmlDesigner: Fix navigator preview of Models
Now we resolve absolute source url for our preview model, so it will always find the custom mesh files. Also always use the Node type preview if the instance is a component, even if the root node is Model. This ensures the preview works properly in case there are child nodes inside the component. Fixes: QDS-6204 Change-Id: I48ef273e5a5dca13abe25816b5edf0be7dd217ff Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -37,7 +37,7 @@ View3D {
|
|||||||
function fitToViewPort()
|
function fitToViewPort()
|
||||||
{
|
{
|
||||||
// The magic number is the distance from camera default pos to origin
|
// The magic number is the distance from camera default pos to origin
|
||||||
_generalHelper.calculateNodeBoundsAndFocusCamera(theCamera, importScene, root,
|
_generalHelper.calculateNodeBoundsAndFocusCamera(theCamera, sourceModel, root,
|
||||||
1040);
|
1040);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ View3D {
|
|||||||
|
|
||||||
Model {
|
Model {
|
||||||
id: model
|
id: model
|
||||||
source: sourceModel.source
|
source: _generalHelper.resolveAbsoluteSourceUrl(sourceModel)
|
||||||
geometry: sourceModel.geometry
|
geometry: sourceModel.geometry
|
||||||
|
|
||||||
materials: [
|
materials: [
|
||||||
|
@@ -42,6 +42,7 @@
|
|||||||
#include <QtQuick3DRuntimeRender/private/qssgrendermodel_p.h>
|
#include <QtQuick3DRuntimeRender/private/qssgrendermodel_p.h>
|
||||||
#include <QtQuick3DUtils/private/qssgbounds3_p.h>
|
#include <QtQuick3DUtils/private/qssgbounds3_p.h>
|
||||||
#include <QtQuick3DUtils/private/qssgutils_p.h>
|
#include <QtQuick3DUtils/private/qssgutils_p.h>
|
||||||
|
#include <QtQml/qqml.h>
|
||||||
#include <QtQuick/qquickwindow.h>
|
#include <QtQuick/qquickwindow.h>
|
||||||
#include <QtQuick/qquickitem.h>
|
#include <QtQuick/qquickitem.h>
|
||||||
#include <QtCore/qmath.h>
|
#include <QtCore/qmath.h>
|
||||||
@@ -93,6 +94,26 @@ QString GeneralHelper::generateUniqueName(const QString &nameRoot)
|
|||||||
return QStringLiteral("%1_%2").arg(nameRoot).arg(count);
|
return QStringLiteral("%1_%2").arg(nameRoot).arg(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolves absolute model source path
|
||||||
|
QUrl GeneralHelper::resolveAbsoluteSourceUrl(const QQuick3DModel *sourceModel)
|
||||||
|
{
|
||||||
|
if (!sourceModel)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
const QUrl source = sourceModel->source();
|
||||||
|
if (source.hasFragment()) {
|
||||||
|
// Fragment is part of the url separated by '#', check if it is an index or primitive
|
||||||
|
bool isNumber = false;
|
||||||
|
source.fragment().toInt(&isNumber);
|
||||||
|
// If it wasn't an index, then it was a primitive and we can return it as-is
|
||||||
|
if (!isNumber)
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QQmlContext *context = qmlContext(sourceModel);
|
||||||
|
return context ? context->resolvedUrl(source) : source;
|
||||||
|
}
|
||||||
|
|
||||||
void GeneralHelper::orbitCamera(QQuick3DCamera *camera, const QVector3D &startRotation,
|
void GeneralHelper::orbitCamera(QQuick3DCamera *camera, const QVector3D &startRotation,
|
||||||
const QVector3D &lookAtPoint, const QVector3D &pressPos,
|
const QVector3D &lookAtPoint, const QVector3D &pressPos,
|
||||||
const QVector3D ¤tPos)
|
const QVector3D ¤tPos)
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QQuaternion>
|
#include <QQuaternion>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QUrl>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QVector3D>
|
#include <QVector3D>
|
||||||
#include <QtQuick3D/private/qquick3dpickresult_p.h>
|
#include <QtQuick3D/private/qquick3dpickresult_p.h>
|
||||||
@@ -58,6 +59,7 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE void requestOverlayUpdate();
|
Q_INVOKABLE void requestOverlayUpdate();
|
||||||
Q_INVOKABLE QString generateUniqueName(const QString &nameRoot);
|
Q_INVOKABLE QString generateUniqueName(const QString &nameRoot);
|
||||||
|
Q_INVOKABLE QUrl resolveAbsoluteSourceUrl(const QQuick3DModel *sourceModel);
|
||||||
|
|
||||||
Q_INVOKABLE void orbitCamera(QQuick3DCamera *camera, const QVector3D &startRotation,
|
Q_INVOKABLE void orbitCamera(QQuick3DCamera *camera, const QVector3D &startRotation,
|
||||||
const QVector3D &lookAtPoint, const QVector3D &pressPos,
|
const QVector3D &lookAtPoint, const QVector3D &pressPos,
|
||||||
|
@@ -1091,9 +1091,15 @@ void Qt5InformationNodeInstanceServer::doRenderModelNode3DImageView()
|
|||||||
m_modelNode3DImageViewData.window->resize(renderSize);
|
m_modelNode3DImageViewData.window->resize(renderSize);
|
||||||
m_modelNode3DImageViewData.rootItem->setSize(renderSize);
|
m_modelNode3DImageViewData.rootItem->setSize(renderSize);
|
||||||
|
|
||||||
|
if (createdFromComponent) {
|
||||||
|
QMetaObject::invokeMethod(
|
||||||
|
m_modelNode3DImageViewData.rootItem, "createViewForNode",
|
||||||
|
Q_ARG(QVariant, objectToVariant(instanceObj)));
|
||||||
|
} else {
|
||||||
QMetaObject::invokeMethod(
|
QMetaObject::invokeMethod(
|
||||||
m_modelNode3DImageViewData.rootItem, "createViewForObject",
|
m_modelNode3DImageViewData.rootItem, "createViewForObject",
|
||||||
Q_ARG(QVariant, objectToVariant(instanceObj)));
|
Q_ARG(QVariant, objectToVariant(instanceObj)));
|
||||||
|
}
|
||||||
|
|
||||||
// Need to render twice, first render updates spatial nodes
|
// Need to render twice, first render updates spatial nodes
|
||||||
for (int i = 0; i < 2; ++i) {
|
for (int i = 0; i < 2; ++i) {
|
||||||
|
Reference in New Issue
Block a user