2019-10-17 18:27:57 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2019 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
**
|
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "quick3dnodeinstance.h"
|
|
|
|
#include "qt5nodeinstanceserver.h"
|
2021-12-02 15:00:20 +02:00
|
|
|
#include "qt5informationnodeinstanceserver.h"
|
2022-02-02 17:56:16 +02:00
|
|
|
#include "quickitemnodeinstance.h"
|
|
|
|
#include "../editor3d/generalhelper.h"
|
2019-10-17 18:27:57 +02:00
|
|
|
|
|
|
|
#include <qmlprivategate.h>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QQmlExpression>
|
|
|
|
#include <QQmlProperty>
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#ifdef QUICK3D_MODULE
|
2022-02-02 17:56:16 +02:00
|
|
|
#include <private/qquick3dobject_p.h>
|
2019-10-17 18:27:57 +02:00
|
|
|
#include <private/qquick3dnode_p.h>
|
2019-11-29 17:28:11 +02:00
|
|
|
#include <private/qquick3dmodel_p.h>
|
2019-10-17 18:27:57 +02:00
|
|
|
#include <private/qquick3dnode_p_p.h>
|
2021-12-02 15:00:20 +02:00
|
|
|
#include <private/qquick3drepeater_p.h>
|
2021-12-10 13:08:58 +02:00
|
|
|
#include <private/qquick3dloader_p.h>
|
2022-01-24 15:23:34 +02:00
|
|
|
#if defined(QUICK3D_ASSET_UTILS_MODULE) && QT_VERSION > QT_VERSION_CHECK(6, 2, 0)
|
|
|
|
#include <private/qquick3druntimeloader_p.h>
|
|
|
|
#endif
|
2022-02-02 17:56:16 +02:00
|
|
|
#include <private/qquickstategroup_p.h>
|
2019-10-17 18:27:57 +02:00
|
|
|
#endif
|
|
|
|
|
2022-02-02 17:56:16 +02:00
|
|
|
|
2019-10-17 18:27:57 +02:00
|
|
|
namespace QmlDesigner {
|
|
|
|
namespace Internal {
|
|
|
|
|
2022-02-15 16:12:13 +01:00
|
|
|
const QRectF preview3dBoundingRect(0, 0, 640, 480);
|
|
|
|
|
2019-10-17 18:27:57 +02:00
|
|
|
Quick3DNodeInstance::Quick3DNodeInstance(QObject *node)
|
|
|
|
: ObjectNodeInstance(node)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Quick3DNodeInstance::~Quick3DNodeInstance()
|
|
|
|
{
|
2022-02-02 17:56:16 +02:00
|
|
|
delete m_dummyRootView;
|
2019-10-17 18:27:57 +02:00
|
|
|
}
|
|
|
|
|
2019-10-24 15:17:47 +03:00
|
|
|
void Quick3DNodeInstance::initialize(const ObjectNodeInstance::Pointer &objectNodeInstance,
|
|
|
|
InstanceContainer::NodeFlags flags)
|
|
|
|
{
|
2021-12-02 15:00:20 +02:00
|
|
|
#ifdef QUICK3D_MODULE
|
2021-12-10 13:08:58 +02:00
|
|
|
QObject *obj = object();
|
|
|
|
auto repObj = qobject_cast<QQuick3DRepeater *>(obj);
|
|
|
|
auto loadObj = qobject_cast<QQuick3DLoader *>(obj);
|
2022-01-24 15:23:34 +02:00
|
|
|
#if defined(QUICK3D_ASSET_UTILS_MODULE) && QT_VERSION > QT_VERSION_CHECK(6, 2, 0)
|
|
|
|
auto runLoadObj = qobject_cast<QQuick3DRuntimeLoader *>(obj);
|
|
|
|
if (repObj || loadObj || runLoadObj) {
|
|
|
|
#else
|
2021-12-10 13:08:58 +02:00
|
|
|
if (repObj || loadObj) {
|
2022-01-24 15:23:34 +02:00
|
|
|
#endif
|
2021-12-02 15:00:20 +02:00
|
|
|
if (auto infoServer = qobject_cast<Qt5InformationNodeInstanceServer *>(nodeInstanceServer())) {
|
2021-12-10 13:08:58 +02:00
|
|
|
if (repObj) {
|
|
|
|
QObject::connect(repObj, &QQuick3DRepeater::objectAdded,
|
|
|
|
infoServer, &Qt5InformationNodeInstanceServer::handleDynamicAddObject);
|
2022-01-24 15:23:34 +02:00
|
|
|
#if defined(QUICK3D_ASSET_UTILS_MODULE) && QT_VERSION > QT_VERSION_CHECK(6, 2, 0)
|
|
|
|
} else if (runLoadObj) {
|
|
|
|
QObject::connect(runLoadObj, &QQuick3DRuntimeLoader::statusChanged,
|
|
|
|
infoServer, &Qt5InformationNodeInstanceServer::handleDynamicAddObject);
|
|
|
|
#endif
|
2021-12-10 13:08:58 +02:00
|
|
|
} else {
|
|
|
|
QObject::connect(loadObj, &QQuick3DLoader::loaded,
|
|
|
|
infoServer, &Qt5InformationNodeInstanceServer::handleDynamicAddObject);
|
|
|
|
}
|
2021-12-02 15:00:20 +02:00
|
|
|
}
|
|
|
|
}
|
2022-02-02 17:56:16 +02:00
|
|
|
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
// In case this is the scene root, we need to create a dummy View3D for the scene
|
|
|
|
// in preview puppets
|
2022-02-15 16:12:13 +01:00
|
|
|
if (instanceId() == 0 && (!nodeInstanceServer()->isInformationServer())) {
|
2022-02-02 17:56:16 +02:00
|
|
|
auto helper = new QmlDesigner::Internal::GeneralHelper();
|
|
|
|
engine()->rootContext()->setContextProperty("_generalHelper", helper);
|
|
|
|
|
|
|
|
QQmlComponent component(engine());
|
|
|
|
component.loadUrl(QUrl("qrc:/qtquickplugin/mockfiles/qt6/ModelNode3DImageView.qml"));
|
|
|
|
m_dummyRootView = qobject_cast<QQuickItem *>(component.create());
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(
|
|
|
|
m_dummyRootView, "createViewForNode",
|
|
|
|
Q_ARG(QVariant, QVariant::fromValue(object())));
|
|
|
|
|
|
|
|
nodeInstanceServer()->setRootItem(m_dummyRootView);
|
|
|
|
}
|
2022-02-15 16:12:13 +01:00
|
|
|
#endif // QT_VERSION
|
|
|
|
#endif // QUICK3D_MODULE
|
2019-10-24 15:17:47 +03:00
|
|
|
ObjectNodeInstance::initialize(objectNodeInstance, flags);
|
|
|
|
}
|
|
|
|
|
2022-02-02 17:56:16 +02:00
|
|
|
QImage Quick3DNodeInstance::renderImage() const
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
if (!isRootNodeInstance() || !m_dummyRootView)
|
|
|
|
return {};
|
|
|
|
|
2022-02-15 16:12:13 +01:00
|
|
|
QSize size = preview3dBoundingRect.size().toSize();
|
2022-02-02 17:56:16 +02:00
|
|
|
nodeInstanceServer()->quickWindow()->resize(size);
|
|
|
|
m_dummyRootView->setSize(size);
|
|
|
|
|
|
|
|
// Just render the window once to update spatial nodes
|
|
|
|
nodeInstanceServer()->renderWindow();
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(m_dummyRootView, "fitToViewPort", Qt::DirectConnection);
|
|
|
|
|
|
|
|
QRectF renderBoundingRect = m_dummyRootView->boundingRect();
|
|
|
|
QImage renderImage;
|
|
|
|
|
|
|
|
if (QuickItemNodeInstance::unifiedRenderPath()) {
|
|
|
|
renderImage = nodeInstanceServer()->grabWindow();
|
|
|
|
renderImage = renderImage.copy(renderBoundingRect.toRect());
|
|
|
|
} else {
|
|
|
|
renderImage = nodeInstanceServer()->grabItem(m_dummyRootView);
|
|
|
|
}
|
|
|
|
|
|
|
|
// When grabbing an offscreen window the device pixel ratio is 1
|
|
|
|
renderImage.setDevicePixelRatio(1);
|
|
|
|
|
|
|
|
return renderImage;
|
|
|
|
#endif
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage Quick3DNodeInstance::renderPreviewImage(const QSize &previewImageSize) const
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
if (!isRootNodeInstance() || !m_dummyRootView)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
nodeInstanceServer()->quickWindow()->resize(previewImageSize);
|
|
|
|
m_dummyRootView->setSize(previewImageSize);
|
|
|
|
|
|
|
|
// Just render the window once to update spatial nodes
|
|
|
|
nodeInstanceServer()->renderWindow();
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(m_dummyRootView, "fitToViewPort", Qt::DirectConnection);
|
|
|
|
|
|
|
|
QRectF previewItemBoundingRect = boundingRect();
|
|
|
|
|
|
|
|
if (previewItemBoundingRect.isValid()) {
|
|
|
|
const QSize size = previewImageSize;
|
|
|
|
if (m_dummyRootView->isVisible()) {
|
|
|
|
QImage image;
|
|
|
|
image = nodeInstanceServer()->grabWindow();
|
|
|
|
image = image.copy(previewItemBoundingRect.toRect());
|
|
|
|
image = image.scaledToWidth(size.width());
|
|
|
|
return image;
|
|
|
|
} else {
|
|
|
|
QImage transparentImage(size, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
transparentImage.fill(Qt::transparent);
|
|
|
|
return transparentImage;
|
|
|
|
}
|
|
|
|
}
|
2022-02-10 16:50:43 +01:00
|
|
|
#else
|
|
|
|
Q_UNUSED(previewImageSize)
|
2022-02-02 17:56:16 +02:00
|
|
|
#endif
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Quick3DNodeInstance::isRenderable() const
|
|
|
|
{
|
|
|
|
return m_dummyRootView;
|
|
|
|
}
|
|
|
|
|
2022-02-15 16:12:13 +01:00
|
|
|
bool Quick3DNodeInstance::hasContent() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-02 17:56:16 +02:00
|
|
|
QRectF Quick3DNodeInstance::boundingRect() const
|
|
|
|
{
|
2022-02-15 16:12:13 +01:00
|
|
|
//The information server has no m_dummyRootView therefore we use the hardcoded value
|
|
|
|
if (nodeInstanceServer()->isInformationServer())
|
|
|
|
return preview3dBoundingRect;
|
|
|
|
|
2022-02-02 17:56:16 +02:00
|
|
|
if (m_dummyRootView)
|
|
|
|
return m_dummyRootView->boundingRect();
|
|
|
|
return ObjectNodeInstance::boundingRect();
|
|
|
|
}
|
|
|
|
|
2022-02-15 16:12:13 +01:00
|
|
|
QRectF Quick3DNodeInstance::contentItemBoundingBox() const
|
|
|
|
{
|
|
|
|
return boundingRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointF Quick3DNodeInstance::position() const
|
|
|
|
{
|
|
|
|
return QPointF(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Quick3DNodeInstance::size() const
|
|
|
|
{
|
|
|
|
return boundingRect().size();
|
|
|
|
}
|
|
|
|
|
2022-02-02 17:56:16 +02:00
|
|
|
QList<ServerNodeInstance> Quick3DNodeInstance::stateInstances() const
|
|
|
|
{
|
|
|
|
QList<ServerNodeInstance> instanceList;
|
|
|
|
#ifdef QUICK3D_MODULE
|
|
|
|
if (auto obj3D = quick3DNode()) {
|
|
|
|
const QList<QQuickState *> stateList = QQuick3DObjectPrivate::get(obj3D)->_states()->states();
|
|
|
|
for (QQuickState *state : stateList) {
|
|
|
|
if (state && nodeInstanceServer()->hasInstanceForObject(state))
|
|
|
|
instanceList.append(nodeInstanceServer()->instanceForObject(state));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return instanceList;
|
|
|
|
}
|
|
|
|
|
2022-02-15 16:12:13 +01:00
|
|
|
QQuickItem *Quick3DNodeInstance::contentItem() const
|
|
|
|
{
|
|
|
|
return m_dummyRootView;
|
|
|
|
}
|
|
|
|
|
2019-10-17 18:27:57 +02:00
|
|
|
Qt5NodeInstanceServer *Quick3DNodeInstance::qt5NodeInstanceServer() const
|
|
|
|
{
|
|
|
|
return qobject_cast<Qt5NodeInstanceServer *>(nodeInstanceServer());
|
|
|
|
}
|
|
|
|
|
|
|
|
QQuick3DNode *Quick3DNodeInstance::quick3DNode() const
|
|
|
|
{
|
2019-10-21 14:54:54 +02:00
|
|
|
#ifdef QUICK3D_MODULE
|
2019-10-17 18:27:57 +02:00
|
|
|
return qobject_cast<QQuick3DNode *>(object());
|
2019-10-21 14:54:54 +02:00
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
2019-10-17 18:27:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Quick3DNodeInstance::Pointer Quick3DNodeInstance::create(QObject *object)
|
|
|
|
{
|
|
|
|
Pointer instance(new Quick3DNodeInstance(object));
|
|
|
|
instance->populateResetHashes();
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2020-10-09 11:14:14 +02:00
|
|
|
void Quick3DNodeInstance::setHiddenInEditor(bool b)
|
2019-10-17 18:27:57 +02:00
|
|
|
{
|
2020-10-09 11:14:14 +02:00
|
|
|
ObjectNodeInstance::setHiddenInEditor(b);
|
2019-10-17 18:27:57 +02:00
|
|
|
#ifdef QUICK3D_MODULE
|
|
|
|
QQuick3DNodePrivate *privateNode = QQuick3DNodePrivate::get(quick3DNode());
|
2020-10-09 11:14:14 +02:00
|
|
|
if (privateNode)
|
2019-10-17 18:27:57 +02:00
|
|
|
privateNode->setIsHiddenInEditor(b);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
} // namespace QmlDesigner
|
|
|
|
|