summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick3d/imports/render/qt3dquick3drenderplugin.cpp2
-rw-r--r--src/render/frontend/qlevelofdetail.h4
-rw-r--r--src/render/frontend/qlevelofdetailswitch.cpp126
-rw-r--r--src/render/frontend/qlevelofdetailswitch.h69
-rw-r--r--src/render/frontend/qrenderaspect.cpp2
-rw-r--r--src/render/frontend/render-frontend.pri2
-rw-r--r--tests/manual/lod/main.qml39
7 files changed, 240 insertions, 4 deletions
diff --git a/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp b/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp
index 5ca889943..8330ce8bc 100644
--- a/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp
+++ b/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp
@@ -56,6 +56,7 @@
#include <Qt3DRender/qfilterkey.h>
#include <Qt3DRender/qlayer.h>
#include <Qt3DRender/qlevelofdetail.h>
+#include <Qt3DRender/qlevelofdetailswitch.h>
#include <Qt3DRender/qboundingsphere.h>
#include <Qt3DRender/qabstractlight.h>
#include <Qt3DRender/qspotlight.h>
@@ -194,6 +195,7 @@ void Qt3DQuick3DRenderPlugin::registerTypes(const char *uri)
Qt3DRender::Quick::registerExtendedType<Qt3DRender::QGeometry, Qt3DRender::Render::Quick::Quick3DGeometry>("QGeometry", "Qt3D.Render/Geometry", uri, 2, 0, "Geometry");
qmlRegisterType<Qt3DRender::QGeometryRenderer>(uri, 2, 0, "GeometryRenderer");
qmlRegisterType<Qt3DRender::QLevelOfDetail>(uri, 2, 2, "LevelOfDetail");
+ qmlRegisterType<Qt3DRender::QLevelOfDetailSwitch>(uri, 2, 2, "LevelOfDetailSwitch");
qmlRegisterType<Qt3DRender::QBoundingSphere>(uri, 2, 2, "BoundingSphere");
// Mesh
diff --git a/src/render/frontend/qlevelofdetail.h b/src/render/frontend/qlevelofdetail.h
index 677169f02..f3325aea0 100644
--- a/src/render/frontend/qlevelofdetail.h
+++ b/src/render/frontend/qlevelofdetail.h
@@ -94,11 +94,11 @@ Q_SIGNALS:
protected:
explicit QLevelOfDetail(QLevelOfDetailPrivate &dd, Qt3DCore::QNode *parent = nullptr);
+ Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE;
+ void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) Q_DECL_OVERRIDE;
private:
Q_DECLARE_PRIVATE(QLevelOfDetail)
- Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE;
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) Q_DECL_OVERRIDE;
Q_PRIVATE_SLOT(d_func(), void _q_radiusChanged(float))
Q_PRIVATE_SLOT(d_func(), void _q_centerChanged(const QVector3D&))
};
diff --git a/src/render/frontend/qlevelofdetailswitch.cpp b/src/render/frontend/qlevelofdetailswitch.cpp
new file mode 100644
index 000000000..9a63343ed
--- /dev/null
+++ b/src/render/frontend/qlevelofdetailswitch.cpp
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** 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 "qlevelofdetailswitch.h"
+#include "qlevelofdetail_p.h"
+#include "qglobal.h"
+#include <Qt3DCore/QEntity>
+#include <Qt3DCore/qpropertyupdatedchange.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+/*!
+ \class Qt3DRender::QLevelOfDetailSwitch
+ \inmodule Qt3DRender
+ \inherits Qt3DRender::QLevelOfDetail
+ \since 5.9
+ \brief Provides a way of enabling child entities based on distance or screen size.
+
+ This component is assigned to an entity. When the entity changes distance relative
+ to the camera, the QLevelOfDetailSwitch will disable all the child entities except
+ the one matching index Qt3DRender::QLevelOfDetailSwitch::currentIndex.
+*/
+
+/*!
+ \qmltype LevelOfDetailSwitch
+ \instantiates Qt3DRender::QLevelOfDetailSwitch
+ \inherits Component3D
+ \inqmlmodule Qt3D.Render
+ \since 5.9
+ \brief Provides a way of enabling child entities based on distance or screen size.
+
+ This component is assigned to an entity. When the entity changes distance relative
+ to the camera, the LevelOfDetailSwitch will disable all the child entities except
+ the one matching index \l LevelOfDetailSwitch::currentIndex.
+
+ \sa LevelOfDetail
+*/
+
+/*! \fn Qt3DRender::QLevelOfDetailSwitch::QLevelOfDetailSwitch(Qt3DCore::QNode *parent)
+ Constructs a new QLevelOfDetailSwitch with the specified \a parent.
+ */
+QLevelOfDetailSwitch::QLevelOfDetailSwitch(QNode *parent)
+ : QLevelOfDetail(parent)
+{
+ Q_D(QLevelOfDetail);
+ d->m_currentIndex = -1;
+}
+
+/*! \internal */
+QLevelOfDetailSwitch::~QLevelOfDetailSwitch()
+{
+}
+
+/*! \internal */
+QLevelOfDetailSwitch::QLevelOfDetailSwitch(QLevelOfDetailPrivate &dd, QNode *parent)
+ : QLevelOfDetail(dd, parent)
+{
+}
+
+/*! \internal */
+void QLevelOfDetailSwitch::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change)
+{
+ Q_D(QLevelOfDetail);
+ Qt3DCore::QPropertyUpdatedChangePtr e = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(change);
+ if (e->type() == Qt3DCore::PropertyUpdated) {
+ if (e->propertyName() == QByteArrayLiteral("currentIndex")) {
+ int ndx = e->value().value<int>();
+ d->m_currentIndex = ndx;
+ emit currentIndexChanged(ndx);
+
+ int entityIndex = 0;
+ for (Qt3DCore::QEntity *entity : entities()) {
+ for (Qt3DCore::QNode *childNode : entity->childNodes()) {
+ Qt3DCore::QEntity *childEntity = qobject_cast<Qt3DCore::QEntity *>(childNode);
+ if (childEntity) {
+ childEntity->setEnabled(entityIndex == ndx);
+ entityIndex++;
+ }
+ }
+ break; // only work on the first entity, LOD should not be shared
+ }
+ }
+ }
+}
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/frontend/qlevelofdetailswitch.h b/src/render/frontend/qlevelofdetailswitch.h
new file mode 100644
index 000000000..6ab905171
--- /dev/null
+++ b/src/render/frontend/qlevelofdetailswitch.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** 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 QT3DRENDER_QLEVELOFDETAILSWITCH_H
+#define QT3DRENDER_QLEVELOFDETAILSWITCH_H
+
+#include <Qt3DRender/qlevelofdetail.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+class QT3DRENDERSHARED_EXPORT QLevelOfDetailSwitch : public QLevelOfDetail
+{
+ Q_OBJECT
+
+public:
+ explicit QLevelOfDetailSwitch(Qt3DCore::QNode *parent = nullptr);
+ ~QLevelOfDetailSwitch();
+
+protected:
+ explicit QLevelOfDetailSwitch(QLevelOfDetailPrivate &dd, Qt3DCore::QNode *parent = nullptr);
+ void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) Q_DECL_OVERRIDE;
+
+private:
+ Q_DECLARE_PRIVATE(QLevelOfDetail)
+};
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
+
+#endif // QT3DRENDER_QLEVELOFDETAILSWITCH_H
diff --git a/src/render/frontend/qrenderaspect.cpp b/src/render/frontend/qrenderaspect.cpp
index 7bddecadf..762321d0b 100644
--- a/src/render/frontend/qrenderaspect.cpp
+++ b/src/render/frontend/qrenderaspect.cpp
@@ -52,6 +52,7 @@
#include <Qt3DRender/qlayer.h>
#include <Qt3DRender/qlayerfilter.h>
#include <Qt3DRender/qlevelofdetail.h>
+#include <Qt3DRender/qlevelofdetailswitch.h>
#include <Qt3DRender/qmaterial.h>
#include <Qt3DRender/qmesh.h>
#include <Qt3DRender/qparameter.h>
@@ -192,6 +193,7 @@ void QRenderAspectPrivate::registerBackendTypes()
q->registerBackendType<Qt3DRender::QCameraLens>(QSharedPointer<Render::NodeFunctor<Render::CameraLens, Render::CameraManager> >::create(m_renderer));
q->registerBackendType<QLayer>(QSharedPointer<Render::NodeFunctor<Render::Layer, Render::LayerManager> >::create(m_renderer));
q->registerBackendType<QLevelOfDetail>(QSharedPointer<Render::NodeFunctor<Render::LevelOfDetail, Render::LevelOfDetailManager> >::create(m_renderer));
+ q->registerBackendType<QLevelOfDetailSwitch>(QSharedPointer<Render::NodeFunctor<Render::LevelOfDetail, Render::LevelOfDetailManager> >::create(m_renderer));
q->registerBackendType<QSceneLoader>(QSharedPointer<Render::RenderSceneFunctor>::create(m_renderer, m_nodeManagers->sceneManager()));
q->registerBackendType<QRenderTarget>(QSharedPointer<Render::NodeFunctor<Render::RenderTarget, Render::RenderTargetManager> >::create(m_renderer));
q->registerBackendType<QRenderTargetOutput>(QSharedPointer<Render::NodeFunctor<Render::RenderTargetOutput, Render::AttachmentManager> >::create(m_renderer));
diff --git a/src/render/frontend/render-frontend.pri b/src/render/frontend/render-frontend.pri
index 649b3d673..0e78f9cff 100644
--- a/src/render/frontend/render-frontend.pri
+++ b/src/render/frontend/render-frontend.pri
@@ -11,6 +11,7 @@ HEADERS += \
$$PWD/qlayer_p.h \
$$PWD/qlevelofdetail.h \
$$PWD/qlevelofdetail_p.h \
+ $$PWD/qlevelofdetailswitch.h \
$$PWD/qrendertarget.h \
$$PWD/qrendertarget_p.h \
$$PWD/sphere_p.h \
@@ -35,6 +36,7 @@ SOURCES += \
$$PWD/sphere.cpp \
$$PWD/qlayer.cpp \
$$PWD/qlevelofdetail.cpp \
+ $$PWD/qlevelofdetailswitch.cpp \
$$PWD/qrendertarget.cpp \
$$PWD/qcamera.cpp \
$$PWD/qcameralens.cpp \
diff --git a/tests/manual/lod/main.qml b/tests/manual/lod/main.qml
index aea87f653..8d9c8722a 100644
--- a/tests/manual/lod/main.qml
+++ b/tests/manual/lod/main.qml
@@ -115,7 +115,7 @@ Entity {
},
Transform {
scale: 1.5
- translation: Qt.vector3d(-5, 0, 0)
+ translation: Qt.vector3d(0, 0, 0)
rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45)
},
PhongMaterial {
@@ -145,7 +145,7 @@ Entity {
LevelOfDetailLoader {
components: [ Transform {
scale: .5
- translation: Qt.vector3d(5, 0, 0)
+ translation: Qt.vector3d(-8, 0, 0)
} ]
camera: camera
@@ -156,6 +156,41 @@ Entity {
}
}
+ Entity {
+ components: [
+ Transform {
+ translation: transform.translation
+ }
+ ]
+
+ Entity {
+ components: [
+ Transform {
+ scale: .5
+ translation: Qt.vector3d(8, 0, 0)
+ },
+ LevelOfDetailSwitch {
+ camera: camera
+ thresholds: [20, 35, 50, 65]
+ thresholdType: LevelOfDetail.DistanceToCamera
+ }
+ ]
+
+ SphereEntity {
+ enabled: false
+ }
+ CylinderEntity {
+ enabled: false
+ }
+ ConeEntity {
+ enabled: false
+ }
+ CuboidEntity {
+ enabled: false
+ }
+ }
+ }
+
QQ2.SequentialAnimation {
QQ2.Vector3dAnimation {
target: transform