diff options
author | Kevin Ottens <kevin.ottens@kdab.com> | 2017-01-26 17:34:16 +0100 |
---|---|---|
committer | Kevin Ottens <kevin.ottens@kdab.com> | 2017-01-27 14:59:18 +0000 |
commit | a110e49dad9179e3cb8f1c0a4399e6a37104c194 (patch) | |
tree | 0e204680cad964c52e758f123ad47256ec236c96 /src/quick3d/quick3dextras | |
parent | bb2e0a0685c5e727faa987dc8b69ee195b029ce1 (diff) |
Port LevelOfDetailLoader to a C++ implementation
tests/manual/lod still works after the port
Change-Id: Idee18aa68724f726789bd74044a989c883dae579
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/quick3d/quick3dextras')
6 files changed, 470 insertions, 1 deletions
diff --git a/src/quick3d/quick3dextras/items/items.pri b/src/quick3d/quick3dextras/items/items.pri new file mode 100644 index 000000000..b6f5d1877 --- /dev/null +++ b/src/quick3d/quick3dextras/items/items.pri @@ -0,0 +1,8 @@ +HEADERS += \ + $$PWD/quick3dlevelofdetailloader_p.h \ + $$PWD/quick3dlevelofdetailloader_p_p.h + +SOURCES += \ + $$PWD/quick3dlevelofdetailloader.cpp + +INCLUDEPATH += $$PWD diff --git a/src/quick3d/quick3dextras/items/quick3dlevelofdetailloader.cpp b/src/quick3d/quick3dextras/items/quick3dlevelofdetailloader.cpp new file mode 100644 index 000000000..f3d3f4323 --- /dev/null +++ b/src/quick3d/quick3dextras/items/quick3dlevelofdetailloader.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "quick3dlevelofdetailloader_p_p.h" +#include <Qt3DRender/qboundingsphere.h> +#include <Qt3DRender/qcamera.h> +#include <Qt3DQuick/private/quick3dentityloader_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DExtras { +namespace Extras { +namespace Quick { + +Quick3DLevelOfDetailLoaderPrivate::Quick3DLevelOfDetailLoaderPrivate() + : QEntityPrivate() + , m_loader(new Qt3DCore::Quick::Quick3DEntityLoader) + , m_lod(new Qt3DRender::QLevelOfDetail) +{ +} + +Quick3DLevelOfDetailLoader::Quick3DLevelOfDetailLoader(QNode *parent) + : QEntity(*new Quick3DLevelOfDetailLoaderPrivate, parent) +{ + Q_D(Quick3DLevelOfDetailLoader); + d->m_loader->setParent(this); + d->m_loader->addComponent(d->m_lod); + + connect(d->m_lod, &Qt3DRender::QLevelOfDetail::cameraChanged, + this, &Quick3DLevelOfDetailLoader::cameraChanged); + connect(d->m_lod, &Qt3DRender::QLevelOfDetail::currentIndexChanged, + this, &Quick3DLevelOfDetailLoader::currentIndexChanged); + connect(d->m_lod, &Qt3DRender::QLevelOfDetail::thresholdTypeChanged, + this, &Quick3DLevelOfDetailLoader::thresholdTypeChanged); + connect(d->m_lod, &Qt3DRender::QLevelOfDetail::thresholdsChanged, + this, &Quick3DLevelOfDetailLoader::thresholdsChanged); + connect(d->m_lod, &Qt3DRender::QLevelOfDetail::volumeOverrideChanged, + this, &Quick3DLevelOfDetailLoader::volumeOverrideChanged); + connect(d->m_loader, &Qt3DCore::Quick::Quick3DEntityLoader::entityChanged, + this, &Quick3DLevelOfDetailLoader::entityChanged); + connect(d->m_loader, &Qt3DCore::Quick::Quick3DEntityLoader::sourceChanged, + this, &Quick3DLevelOfDetailLoader::sourceChanged); + + connect(this, &Quick3DLevelOfDetailLoader::enabledChanged, + d->m_lod, &Qt3DRender::QLevelOfDetail::setEnabled); + + auto applyCurrentSource = [this] { + Q_D(Quick3DLevelOfDetailLoader); + const auto index = currentIndex(); + if (index >= 0 && index < d->m_sources.size()) + d->m_loader->setSource(d->m_sources.at(index).toUrl()); + }; + + connect(this, &Quick3DLevelOfDetailLoader::sourcesChanged, + this, applyCurrentSource); + connect(this, &Quick3DLevelOfDetailLoader::currentIndexChanged, + this, applyCurrentSource); +} + +QVariantList Quick3DLevelOfDetailLoader::sources() const +{ + Q_D(const Quick3DLevelOfDetailLoader); + return d->m_sources; +} + +void Quick3DLevelOfDetailLoader::setSources(const QVariantList &sources) +{ + Q_D(Quick3DLevelOfDetailLoader); + if (d->m_sources != sources) { + d->m_sources = sources; + emit sourcesChanged(); + } +} + +Qt3DRender::QCamera *Quick3DLevelOfDetailLoader::camera() const +{ + Q_D(const Quick3DLevelOfDetailLoader); + return d->m_lod->camera(); +} + +void Quick3DLevelOfDetailLoader::setCamera(Qt3DRender::QCamera *camera) +{ + Q_D(Quick3DLevelOfDetailLoader); + d->m_lod->setCamera(camera); +} + +int Quick3DLevelOfDetailLoader::currentIndex() const +{ + Q_D(const Quick3DLevelOfDetailLoader); + return d->m_lod->currentIndex(); +} + +void Quick3DLevelOfDetailLoader::setCurrentIndex(int currentIndex) +{ + Q_D(Quick3DLevelOfDetailLoader); + d->m_lod->setCurrentIndex(currentIndex); +} + +Qt3DRender::QLevelOfDetail::ThresholdType Quick3DLevelOfDetailLoader::thresholdType() const +{ + Q_D(const Quick3DLevelOfDetailLoader); + return d->m_lod->thresholdType(); +} + +void Quick3DLevelOfDetailLoader::setThresholdType(Qt3DRender::QLevelOfDetail::ThresholdType thresholdType) +{ + Q_D(Quick3DLevelOfDetailLoader); + d->m_lod->setThresholdType(thresholdType); +} + +QVector<qreal> Quick3DLevelOfDetailLoader::thresholds() const +{ + Q_D(const Quick3DLevelOfDetailLoader); + return d->m_lod->thresholds(); +} + +void Quick3DLevelOfDetailLoader::setThresholds(const QVector<qreal> &thresholds) +{ + Q_D(Quick3DLevelOfDetailLoader); + d->m_lod->setThresholds(thresholds); +} + +Qt3DRender::QBoundingSphere *Quick3DLevelOfDetailLoader::volumeOverride() const +{ + Q_D(const Quick3DLevelOfDetailLoader); + return d->m_lod->volumeOverride(); +} + +void Quick3DLevelOfDetailLoader::setVolumeOverride(Qt3DRender::QBoundingSphere *volumeOverride) +{ + Q_D(Quick3DLevelOfDetailLoader); + d->m_lod->setVolumeOverride(volumeOverride); +} + +QObject *Quick3DLevelOfDetailLoader::entity() const +{ + Q_D(const Quick3DLevelOfDetailLoader); + return d->m_loader->entity(); +} + +QUrl Quick3DLevelOfDetailLoader::source() const +{ + Q_D(const Quick3DLevelOfDetailLoader); + return d->m_loader->source(); +} + +} // namespace Quick +} // namespace Extras +} // namespace Qt3DExtras + +QT_END_NAMESPACE + + diff --git a/src/quick3d/quick3dextras/items/quick3dlevelofdetailloader_p.h b/src/quick3d/quick3dextras/items/quick3dlevelofdetailloader_p.h new file mode 100644 index 000000000..1ef359fe7 --- /dev/null +++ b/src/quick3d/quick3dextras/items/quick3dlevelofdetailloader_p.h @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DEXTRAS_EXTRAS_QUICK_QUICK3DLEVELOFDETAILLOADER_P_H +#define QT3DEXTRAS_EXTRAS_QUICK_QUICK3DLEVELOFDETAILLOADER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DQuickExtras/private/qt3dquickextras_global_p.h> +#include <Qt3DCore/qentity.h> +#include <Qt3DRender/qlevelofdetail.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DExtras { +namespace Extras { +namespace Quick { + +class Quick3DLevelOfDetailLoaderPrivate; + +class QT3DQUICKEXTRASSHARED_PRIVATE_EXPORT Quick3DLevelOfDetailLoader : public Qt3DCore::QEntity +{ + Q_OBJECT + Q_PROPERTY(QVariantList sources READ sources WRITE setSources NOTIFY sourcesChanged) + + Q_PROPERTY(Qt3DRender::QCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) + Q_PROPERTY(Qt3DRender::QLevelOfDetail::ThresholdType thresholdType READ thresholdType WRITE setThresholdType NOTIFY thresholdTypeChanged) + Q_PROPERTY(QVector<qreal> thresholds READ thresholds WRITE setThresholds NOTIFY thresholdsChanged) + Q_PROPERTY(Qt3DRender::QBoundingSphere *volumeOverride READ volumeOverride WRITE setVolumeOverride NOTIFY volumeOverrideChanged) + + Q_PROPERTY(QObject *entity READ entity NOTIFY entityChanged) + Q_PROPERTY(QUrl source READ source NOTIFY sourceChanged) +public: + explicit Quick3DLevelOfDetailLoader(QNode *parent = 0); + + QVariantList sources() const; + void setSources(const QVariantList &sources); + + Qt3DRender::QCamera *camera() const; + void setCamera(Qt3DRender::QCamera *camera); + int currentIndex() const; + void setCurrentIndex(int currentIndex); + Qt3DRender::QLevelOfDetail::ThresholdType thresholdType() const; + void setThresholdType(Qt3DRender::QLevelOfDetail::ThresholdType thresholdType); + QVector<qreal> thresholds() const; + void setThresholds(const QVector<qreal> &thresholds); + Qt3DRender::QBoundingSphere *volumeOverride() const; + void setVolumeOverride(Qt3DRender::QBoundingSphere *volumeOverride); + + QObject *entity() const; + QUrl source() const; + +signals: + void sourcesChanged(); + void cameraChanged(); + void currentIndexChanged(); + void thresholdTypeChanged(); + void thresholdsChanged(); + void volumeOverrideChanged(); + void entityChanged(); + void sourceChanged(); + +private: + Q_DECLARE_PRIVATE(Quick3DLevelOfDetailLoader) +}; + +} // namespace Quick +} // namespace Extras +} // namespace Qt3DExtras + +QT_END_NAMESPACE + +#endif // QT3DEXTRAS_EXTRAS_QUICK_QUICK3DLEVELOFDETAILLOADER_P_H diff --git a/src/quick3d/quick3dextras/items/quick3dlevelofdetailloader_p_p.h b/src/quick3d/quick3dextras/items/quick3dlevelofdetailloader_p_p.h new file mode 100644 index 000000000..b123ea30b --- /dev/null +++ b/src/quick3d/quick3dextras/items/quick3dlevelofdetailloader_p_p.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DEXTRAS_EXTRAS_QUICK_QUICK3DLEVELOFDETAILLOADER_P_P_H +#define QT3DEXTRAS_EXTRAS_QUICK_QUICK3DLEVELOFDETAILLOADER_P_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "quick3dlevelofdetailloader_p.h" +#include <Qt3DCore/private/qentity_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { +namespace Quick { +class Quick3DEntityLoader; +} +} + +namespace Qt3DExtras { +namespace Extras { +namespace Quick { + +class Quick3DLevelOfDetailLoaderPrivate : public Qt3DCore::QEntityPrivate +{ +public: + Quick3DLevelOfDetailLoaderPrivate(); + + Q_DECLARE_PUBLIC(Quick3DLevelOfDetailLoader) + + QVariantList m_sources; + Qt3DCore::Quick::Quick3DEntityLoader *m_loader; + Qt3DRender::QLevelOfDetail *m_lod; +}; + +} // namespace Quick +} // namespace Extras +} // namespace Qt3DExtras + +QT_END_NAMESPACE + +#endif // QT3DEXTRAS_EXTRAS_QUICK_QUICK3DLEVELOFDETAILLOADER_P_P_H diff --git a/src/quick3d/quick3dextras/qt3dquickextras_global_p.h b/src/quick3d/quick3dextras/qt3dquickextras_global_p.h new file mode 100644 index 000000000..524393743 --- /dev/null +++ b/src/quick3d/quick3dextras/qt3dquickextras_global_p.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DQUICKEXTRAS_GLOBAL_P_H +#define QT3DQUICKEXTRAS_GLOBAL_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DQuickExtras/qt3dquickextras_global.h> +#include <QtQml/qqml.h> + +#define QT3DQUICKEXTRASSHARED_PRIVATE_EXPORT QT3DQUICKEXTRASSHARED_EXPORT + +QT_BEGIN_NAMESPACE + +QT_END_NAMESPACE + +#endif // QT3DQUICKEXTRAS_GLOBAL_P_H diff --git a/src/quick3d/quick3dextras/quick3dextras.pro b/src/quick3d/quick3dextras/quick3dextras.pro index 8965e9f5d..5b00d5dc3 100644 --- a/src/quick3d/quick3dextras/quick3dextras.pro +++ b/src/quick3d/quick3dextras/quick3dextras.pro @@ -1,7 +1,7 @@ TARGET = Qt3DQuickExtras MODULE = 3dquickextras -QT += core core-private qml qml-private 3dcore 3dinput 3dquick 3drender 3drender-private 3dlogic +QT += core core-private qml qml-private 3dcore 3dinput 3dquick 3dquick-private 3drender 3drender-private 3dlogic CONFIG -= precompile_header # Qt3D is free of Q_FOREACH - make sure it stays that way: @@ -18,9 +18,12 @@ SOURCES += \ HEADERS += \ qt3dquickextras_global.h \ + qt3dquickextras_global_p.h \ qt3dquickwindow.h # otherwise mingw headers do not declare common functions like ::strcasecmp win32-g++*:QMAKE_CXXFLAGS_CXX11 = -std=gnu++0x +include(./items/items.pri) + load(qt_module) |