diff options
-rw-r--r-- | src/core/geometry/geometry.pri | 3 | ||||
-rw-r--r-- | src/core/geometry/qboundingvolume.cpp | 189 | ||||
-rw-r--r-- | src/core/geometry/qboundingvolume.h | 90 | ||||
-rw-r--r-- | src/core/geometry/qboundingvolume_p.h | 89 | ||||
-rw-r--r-- | src/render/geometry/qgeometryrenderer.cpp | 76 | ||||
-rw-r--r-- | src/render/geometry/qgeometryrenderer.h | 8 | ||||
-rw-r--r-- | src/render/geometry/qgeometryrenderer_p.h | 7 |
7 files changed, 408 insertions, 54 deletions
diff --git a/src/core/geometry/geometry.pri b/src/core/geometry/geometry.pri index 3425be857..eadf7ca0b 100644 --- a/src/core/geometry/geometry.pri +++ b/src/core/geometry/geometry.pri @@ -4,6 +4,8 @@ HEADERS += \ $$PWD/qabstractfunctor.h \ $$PWD/qattribute.h \ $$PWD/qattribute_p.h \ + $$PWD/qboundingvolume.h \ + $$PWD/qboundingvolume_p.h \ $$PWD/qbuffer.h \ $$PWD/qbuffer_p.h \ $$PWD/qgeometry_p.h \ @@ -15,6 +17,7 @@ HEADERS += \ SOURCES += \ $$PWD/qabstractfunctor.cpp \ $$PWD/qattribute.cpp \ + $$PWD/qboundingvolume.cpp \ $$PWD/qbuffer.cpp \ $$PWD/qgeometry.cpp \ $$PWD/qgeometryview.cpp diff --git a/src/core/geometry/qboundingvolume.cpp b/src/core/geometry/qboundingvolume.cpp new file mode 100644 index 000000000..4e261396a --- /dev/null +++ b/src/core/geometry/qboundingvolume.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 "qboundingvolume.h" +#include "qboundingvolume_p.h" +#include <Qt3DCore/private/corelogging_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { + +bool operator<(const QVector3D &a, const QVector3D &b) { + return a.x() < b.x() && a.y() < b.y() && a.z() < b.z(); +} + +QBoundingVolumePrivate::QBoundingVolumePrivate() + : QComponentPrivate() + , m_view(nullptr) + , m_implicitPointsValid(false) + , m_primaryProvider(true) +{ +} + +void QBoundingVolumePrivate::setImplicitBounds(const QVector3D &minPoint, const QVector3D &maxPoint, + const QVector3D ¢er, float radius) +{ + Q_Q(QBoundingVolume); + + if (!minPoint.isNull() && !maxPoint.isNull() && minPoint < maxPoint) { + if (m_implicitMinPoint != minPoint) { + m_implicitMinPoint = minPoint; + emit q->implicitMinPointChanged(m_implicitMinPoint); + } + if (m_implicitMaxPoint != maxPoint) { + m_implicitMaxPoint = maxPoint; + emit q->implicitMaxPointChanged(m_implicitMaxPoint); + } + m_implicitCenter = center; + m_implicitRadius = radius; + if (!m_implicitPointsValid) { + m_implicitPointsValid = true; + emit q->implicitPointsValidChanged(m_implicitPointsValid); + } + } else { + if (m_implicitPointsValid) { + m_implicitPointsValid = false; + emit q->implicitPointsValidChanged(m_implicitPointsValid); + } + } +} + +void QBoundingVolumePrivate::setView(QGeometryView *view) +{ + Q_Q(QBoundingVolume); + + if (m_view == view) + return; + + if (m_view) + unregisterDestructionHelper(m_view); + + if (view && !view->parent()) + view->setParent(q); + + m_view = view; + + // Ensures proper bookkeeping + if (m_view) + registerDestructionHelper(m_view, &QBoundingVolume::setView, m_view); + + emit q->viewChanged(view); +} + +QBoundingVolumePrivate *QBoundingVolumePrivate::get(QBoundingVolume *q) +{ + return q->d_func(); +} + +/*! + * \qmltype BoundingVolume + * \instantiates Qt3DCore::QBoundingVolume + * \inqmlmodule Qt3D.Core + * + * \brief + */ + +/*! + * \class Qt3DCore::QBoundingVolume + * \inheaderfile Qt3DCore/QBoundingVolume + * \inmodule Qt3DCore + * + * \inherits Qt3DCore::QNode + * + * \brief + */ + +/*! + * Constructs a new QBoundingVolume with \a parent. + */ +QBoundingVolume::QBoundingVolume(QNode *parent) + : QComponent(*new QBoundingVolumePrivate(), parent) +{ +} + +/*! + * \internal + */ +QBoundingVolume::QBoundingVolume(QBoundingVolumePrivate &dd, QNode *parent) + : QComponent(dd, parent) +{ +} + +/*! + * \internal + */ +QBoundingVolume::~QBoundingVolume() +{ +} + + +QGeometryView *QBoundingVolume::view() const +{ + Q_D(const QBoundingVolume); + return d->m_view; +} + +QVector3D QBoundingVolume::implicitMinPoint() const +{ + Q_D(const QBoundingVolume); + return d->m_implicitMinPoint; +} + +QVector3D QBoundingVolume::implicitMaxPoint() const +{ + Q_D(const QBoundingVolume); + return d->m_implicitMaxPoint; +} + +bool QBoundingVolume::areImplicitPointsValid() const +{ + Q_D(const QBoundingVolume); + return d->m_implicitPointsValid; +} + +void QBoundingVolume::setView(QGeometryView *view) +{ + Q_D(QBoundingVolume); + d->setView(view); +} + +} // namespace Qt3DCore + +QT_END_NAMESPACE diff --git a/src/core/geometry/qboundingvolume.h b/src/core/geometry/qboundingvolume.h new file mode 100644 index 000000000..58adf127f --- /dev/null +++ b/src/core/geometry/qboundingvolume.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 QT3DCORE_QBOUNDINGVOLUME_H +#define QT3DCORE_QBOUNDINGVOLUME_H + +#include <QtGui/qvector3d.h> +#include <Qt3DCore/qcomponent.h> +#include <Qt3DCore/qgeometryview.h> +#include <Qt3DCore/qt3dcore_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { + +class QBoundingVolumePrivate; + +class Q_3DCORESHARED_EXPORT QBoundingVolume : public Qt3DCore::QComponent +{ + Q_OBJECT + Q_PROPERTY(QGeometryView* view READ view WRITE setView NOTIFY viewChanged) + Q_PROPERTY(QVector3D implicitMinPoint READ implicitMinPoint NOTIFY implicitMinPointChanged) + Q_PROPERTY(QVector3D implicitMaxPoint READ implicitMaxPoint NOTIFY implicitMaxPointChanged) + Q_PROPERTY(bool implicitPointsValid READ areImplicitPointsValid NOTIFY implicitPointsValidChanged) +public: + explicit QBoundingVolume(Qt3DCore::QNode *parent = nullptr); + ~QBoundingVolume(); + + QGeometryView* view() const; + QVector3D implicitMinPoint() const; + QVector3D implicitMaxPoint() const; + bool areImplicitPointsValid() const; + +public Q_SLOTS: + void setView(QGeometryView *view); + +Q_SIGNALS: + void viewChanged(QGeometryView *view); + void implicitMinPointChanged(const QVector3D &implicitMinPoint); + void implicitMaxPointChanged(const QVector3D &implicitMaxPoint); + void implicitPointsValidChanged(bool implicitPointsValid); + +protected: + QBoundingVolume(QBoundingVolumePrivate &dd, Qt3DCore::QNode *parent = nullptr); + +private: + Q_DECLARE_PRIVATE(QBoundingVolume) +}; + +} // namespace Qt3DCore + +QT_END_NAMESPACE + +#endif // QT3DCORE_QBOUNDINGVOLUME_H diff --git a/src/core/geometry/qboundingvolume_p.h b/src/core/geometry/qboundingvolume_p.h new file mode 100644 index 000000000..eef65a3de --- /dev/null +++ b/src/core/geometry/qboundingvolume_p.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 QT3DCORE_QBOUNDINGVOLUME_P_H +#define QT3DCORE_QBOUNDINGVOLUME_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 <Qt3DCore/private/qnode_p.h> +#include <Qt3DCore/qt3dcore_global.h> +#include <private/qcomponent_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { +class QBoundingVolume; +class QGeometryView; + +class Q_3DCORESHARED_EXPORT QBoundingVolumePrivate : public Qt3DCore::QComponentPrivate +{ +public: + Q_DECLARE_PUBLIC(QBoundingVolume) + + QBoundingVolumePrivate(); + + void setImplicitBounds(const QVector3D &minPoint, const QVector3D &maxPoint, const QVector3D ¢er, float radius); + virtual void setView(QGeometryView *view); + + static QBoundingVolumePrivate *get(QBoundingVolume *q); + + QGeometryView *m_view; + QVector3D m_implicitMinPoint; + QVector3D m_implicitMaxPoint; + QVector3D m_implicitCenter; + float m_implicitRadius; + bool m_implicitPointsValid; + bool m_primaryProvider; +}; + +} // namespace Qt3DCore + +QT_END_NAMESPACE + +#endif // QT3DCORE_QBOUNDINGVOLUME_P_H diff --git a/src/render/geometry/qgeometryrenderer.cpp b/src/render/geometry/qgeometryrenderer.cpp index f9029f099..30ccd6079 100644 --- a/src/render/geometry/qgeometryrenderer.cpp +++ b/src/render/geometry/qgeometryrenderer.cpp @@ -49,7 +49,7 @@ using namespace Qt3DCore; namespace Qt3DRender { QGeometryRendererPrivate::QGeometryRendererPrivate() - : QComponentPrivate() + : Qt3DCore::QBoundingVolumePrivate() , m_instanceCount(1) , m_vertexCount(0) , m_indexOffset(0) @@ -61,14 +61,41 @@ QGeometryRendererPrivate::QGeometryRendererPrivate() , m_primitiveRestart(false) , m_geometry(nullptr) , m_primitiveType(QGeometryRenderer::Triangles) - , m_view(nullptr) { + m_primaryProvider = false; } QGeometryRendererPrivate::~QGeometryRendererPrivate() { } +void QGeometryRendererPrivate::setView(QGeometryView *view) +{ + Q_Q(QGeometryRenderer); + if (m_view == view) + return; + + if (m_view) + m_view->disconnect(q); + + QBoundingVolumePrivate::setView(view); + + // Ensures proper bookkeeping + if (m_view) { + QObject::connect(view, &QGeometryView::instanceCountChanged, q, [this]() { update(); }); + QObject::connect(view, &QGeometryView::vertexCountChanged, q, [this]() { update(); }); + QObject::connect(view, &QGeometryView::indexOffsetChanged, q, [this]() { update(); }); + QObject::connect(view, &QGeometryView::firstInstanceChanged, q, [this]() { update(); }); + QObject::connect(view, &QGeometryView::firstVertexChanged, q, [this]() { update(); }); + QObject::connect(view, &QGeometryView::indexBufferByteOffsetChanged, q, [this]() { update(); }); + QObject::connect(view, &QGeometryView::restartIndexValueChanged, q, [this]() { update(); }); + QObject::connect(view, &QGeometryView::verticesPerPatchChanged, q, [this]() { update(); }); + QObject::connect(view, &QGeometryView::primitiveRestartEnabledChanged, q, [this]() { update(); }); + QObject::connect(view, &QGeometryView::geometryChanged, q, [this]() { update(); }); + QObject::connect(view, &QGeometryView::primitiveTypeChanged, q, [this]() { update(); }); + } +} + /*! \qmltype GeometryRenderer \instantiates Qt3DRender::QGeometryRenderer @@ -200,7 +227,7 @@ QGeometryRendererPrivate::~QGeometryRendererPrivate() Constructs a new QGeometryRenderer with \a parent. */ QGeometryRenderer::QGeometryRenderer(QNode *parent) - : QComponent(*new QGeometryRendererPrivate(), parent) + : Qt3DCore::QBoundingVolume(*new QGeometryRendererPrivate(), parent) { } @@ -215,7 +242,7 @@ QGeometryRenderer::~QGeometryRenderer() \internal */ QGeometryRenderer::QGeometryRenderer(QGeometryRendererPrivate &dd, QNode *parent) - : QComponent(dd, parent) + : Qt3DCore::QBoundingVolume(dd, parent) { } @@ -340,12 +367,6 @@ QGeometryRenderer::PrimitiveType QGeometryRenderer::primitiveType() const return d->m_primitiveType; } -QGeometryView *QGeometryRenderer::view() const -{ - Q_D(const QGeometryRenderer); - return d->m_view; -} - void QGeometryRenderer::setInstanceCount(int instanceCount) { Q_D(QGeometryRenderer); @@ -466,41 +487,6 @@ void QGeometryRenderer::setPrimitiveType(QGeometryRenderer::PrimitiveType primit emit primitiveTypeChanged(primitiveType); } -void QGeometryRenderer::setView(QGeometryView *view) -{ - Q_D(QGeometryRenderer); - if (d->m_view == view) - return; - - if (d->m_view) { - d->unregisterDestructionHelper(d->m_view); - d->m_view->disconnect(this); - } - - if (view && !view->parent()) - view->setParent(this); - - d->m_view = view; - - // Ensures proper bookkeeping - if (d->m_view) { - d->registerDestructionHelper(d->m_view, &QGeometryRenderer::setView, d->m_view); - connect(view, &QGeometryView::instanceCountChanged, this, [d]() { d->update(); }); - connect(view, &QGeometryView::vertexCountChanged, this, [d]() { d->update(); }); - connect(view, &QGeometryView::indexOffsetChanged, this, [d]() { d->update(); }); - connect(view, &QGeometryView::firstInstanceChanged, this, [d]() { d->update(); }); - connect(view, &QGeometryView::firstVertexChanged, this, [d]() { d->update(); }); - connect(view, &QGeometryView::indexBufferByteOffsetChanged, this, [d]() { d->update(); }); - connect(view, &QGeometryView::restartIndexValueChanged, this, [d]() { d->update(); }); - connect(view, &QGeometryView::verticesPerPatchChanged, this, [d]() { d->update(); }); - connect(view, &QGeometryView::primitiveRestartEnabledChanged, this, [d]() { d->update(); }); - connect(view, &QGeometryView::geometryChanged, this, [d]() { d->update(); }); - connect(view, &QGeometryView::primitiveTypeChanged, this, [d]() { d->update(); }); - } - - emit viewChanged(view); -} - } // namespace Qt3DRender QT_END_NAMESPACE diff --git a/src/render/geometry/qgeometryrenderer.h b/src/render/geometry/qgeometryrenderer.h index 0eee34b86..14d8bbccc 100644 --- a/src/render/geometry/qgeometryrenderer.h +++ b/src/render/geometry/qgeometryrenderer.h @@ -40,7 +40,7 @@ #ifndef QT3DRENDER_QGEOMETRYRENDERER_H #define QT3DRENDER_QGEOMETRYRENDERER_H -#include <Qt3DCore/qcomponent.h> +#include <Qt3DCore/qboundingvolume.h> #include <Qt3DCore/qgeometry.h> #include <Qt3DCore/qgeometryview.h> #include <Qt3DRender/qt3drender_global.h> @@ -51,7 +51,7 @@ namespace Qt3DRender { class QGeometryRendererPrivate; -class Q_3DRENDERSHARED_EXPORT QGeometryRenderer : public Qt3DCore::QComponent +class Q_3DRENDERSHARED_EXPORT QGeometryRenderer : public Qt3DCore::QBoundingVolume { Q_OBJECT Q_PROPERTY(int instanceCount READ instanceCount WRITE setInstanceCount NOTIFY instanceCountChanged) @@ -65,7 +65,6 @@ class Q_3DRENDERSHARED_EXPORT QGeometryRenderer : public Qt3DCore::QComponent Q_PROPERTY(bool primitiveRestartEnabled READ primitiveRestartEnabled WRITE setPrimitiveRestartEnabled NOTIFY primitiveRestartEnabledChanged) Q_PROPERTY(Qt3DCore::QGeometry* geometry READ geometry WRITE setGeometry NOTIFY geometryChanged) Q_PROPERTY(PrimitiveType primitiveType READ primitiveType WRITE setPrimitiveType NOTIFY primitiveTypeChanged) - Q_PROPERTY(Qt3DCore::QGeometryView* view READ view WRITE setView NOTIFY viewChanged) public: explicit QGeometryRenderer(Qt3DCore::QNode *parent = nullptr); ~QGeometryRenderer(); @@ -100,7 +99,6 @@ public: bool primitiveRestartEnabled() const; Qt3DCore::QGeometry *geometry() const; PrimitiveType primitiveType() const; - Qt3DCore::QGeometryView *view() const; public Q_SLOTS: void setInstanceCount(int instanceCount); @@ -114,7 +112,6 @@ public Q_SLOTS: void setPrimitiveRestartEnabled(bool enabled); void setGeometry(Qt3DCore::QGeometry *geometry); void setPrimitiveType(PrimitiveType primitiveType); - void setView(Qt3DCore::QGeometryView *view); Q_SIGNALS: void instanceCountChanged(int instanceCount); @@ -128,7 +125,6 @@ Q_SIGNALS: void primitiveRestartEnabledChanged(bool primitiveRestartEnabled); void geometryChanged(Qt3DCore::QGeometry *geometry); void primitiveTypeChanged(PrimitiveType primitiveType); - void viewChanged(Qt3DCore::QGeometryView *view); protected: explicit QGeometryRenderer(QGeometryRendererPrivate &dd, Qt3DCore::QNode *parent = nullptr); diff --git a/src/render/geometry/qgeometryrenderer_p.h b/src/render/geometry/qgeometryrenderer_p.h index 5bacb74c4..6d195bf35 100644 --- a/src/render/geometry/qgeometryrenderer_p.h +++ b/src/render/geometry/qgeometryrenderer_p.h @@ -52,7 +52,7 @@ // #include <Qt3DCore/private/qgeometryfactory_p.h> -#include <Qt3DCore/private/qcomponent_p.h> +#include <Qt3DCore/private/qboundingvolume_p.h> #include <Qt3DRender/qgeometryrenderer.h> #include <Qt3DRender/private/qt3drender_global_p.h> #include <memory> @@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE namespace Qt3DRender { -class Q_3DRENDERSHARED_PRIVATE_EXPORT QGeometryRendererPrivate : public Qt3DCore::QComponentPrivate +class Q_3DRENDERSHARED_PRIVATE_EXPORT QGeometryRendererPrivate : public Qt3DCore::QBoundingVolumePrivate { public: QGeometryRendererPrivate(); @@ -69,6 +69,8 @@ public: Q_DECLARE_PUBLIC(QGeometryRenderer) + void setView(Qt3DCore::QGeometryView *view) override; + int m_instanceCount; int m_vertexCount; int m_indexOffset; @@ -81,7 +83,6 @@ public: Qt3DCore::QGeometry *m_geometry; QGeometryRenderer::PrimitiveType m_primitiveType; Qt3DCore::QGeometryFactoryPtr m_geometryFactory; - Qt3DCore::QGeometryView *m_view; }; } // namespace Qt3DRender |