summaryrefslogtreecommitdiffstats
path: root/src/core/geometry
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2020-03-09 15:28:11 +0000
committerMike Krus <mike.krus@kdab.com>2020-04-23 14:18:22 +0100
commit9a2ab2f1c0dc7ffe83f3e22aa97951de216b4ef7 (patch)
treeb89fbf07593668f11544a2e937500fc3802489bf /src/core/geometry
parent60f42119fe5c341880f4576e0c9ad8d99ee277d5 (diff)
Add ability to override bounding data and trigger calculation
With this, can set min and max extents of a geometry renderer which will avoid calculating it from the real geometry. Can also trigger the computation from user code (via public API) if user doesn't want to wait for next frame to get the data. Change-Id: I821bfb7c9d710a77a2b87ec607b4ed35a0c7f236 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/core/geometry')
-rw-r--r--src/core/geometry/qboundingvolume.cpp54
-rw-r--r--src/core/geometry/qboundingvolume.h10
-rw-r--r--src/core/geometry/qboundingvolume_p.h3
3 files changed, 67 insertions, 0 deletions
diff --git a/src/core/geometry/qboundingvolume.cpp b/src/core/geometry/qboundingvolume.cpp
index 4e261396a..8f63e3d13 100644
--- a/src/core/geometry/qboundingvolume.cpp
+++ b/src/core/geometry/qboundingvolume.cpp
@@ -40,6 +40,7 @@
#include "qboundingvolume.h"
#include "qboundingvolume_p.h"
#include <Qt3DCore/private/corelogging_p.h>
+#include <Qt3DCore/private/calcboundingvolumejob_p.h>
QT_BEGIN_NAMESPACE
@@ -53,6 +54,7 @@ QBoundingVolumePrivate::QBoundingVolumePrivate()
: QComponentPrivate()
, m_view(nullptr)
, m_implicitPointsValid(false)
+ , m_explicitPointsValid(false)
, m_primaryProvider(true)
{
}
@@ -178,12 +180,64 @@ bool QBoundingVolume::areImplicitPointsValid() const
return d->m_implicitPointsValid;
}
+QVector3D QBoundingVolume::minPoint() const
+{
+ Q_D(const QBoundingVolume);
+ return d->m_minPoint;
+}
+
+QVector3D QBoundingVolume::maxPoint() const
+{
+ Q_D(const QBoundingVolume);
+ return d->m_maxPoint;
+}
+
void QBoundingVolume::setView(QGeometryView *view)
{
Q_D(QBoundingVolume);
d->setView(view);
}
+void QBoundingVolume::setMinPoint(const QVector3D &minPoint)
+{
+ Q_D(QBoundingVolume);
+ if (d->m_minPoint != minPoint) {
+ d->m_minPoint = minPoint;
+ d->m_explicitPointsValid = true;
+ d->markDirty(QScene::GeometryDirty);
+ emit minPointChanged(d->m_minPoint);
+ }
+}
+
+void QBoundingVolume::setMaxPoint(const QVector3D &maxPoint)
+{
+ Q_D(QBoundingVolume);
+ if (d->m_maxPoint != maxPoint) {
+ d->m_maxPoint = maxPoint;
+ d->m_explicitPointsValid = true;
+ d->markDirty(QScene::GeometryDirty);
+ emit maxPointChanged(d->m_maxPoint);
+ }
+}
+
+bool QBoundingVolume::updateImplicitBounds()
+{
+ Q_D(QBoundingVolume);
+ if (!d->m_view)
+ return false;
+
+ auto data = BoundingVolumeComputeData::fromView(d->m_view);
+ if (!data.valid())
+ return false;
+
+ auto res = data.compute();
+ if (!res.valid())
+ return false;
+
+ d->setImplicitBounds(res.m_min, res.m_max, res.m_center, res.m_radius);
+ return true;
+}
+
} // namespace Qt3DCore
QT_END_NAMESPACE
diff --git a/src/core/geometry/qboundingvolume.h b/src/core/geometry/qboundingvolume.h
index 58adf127f..dd061e1bb 100644
--- a/src/core/geometry/qboundingvolume.h
+++ b/src/core/geometry/qboundingvolume.h
@@ -58,6 +58,8 @@ class Q_3DCORESHARED_EXPORT QBoundingVolume : public Qt3DCore::QComponent
Q_PROPERTY(QVector3D implicitMinPoint READ implicitMinPoint NOTIFY implicitMinPointChanged)
Q_PROPERTY(QVector3D implicitMaxPoint READ implicitMaxPoint NOTIFY implicitMaxPointChanged)
Q_PROPERTY(bool implicitPointsValid READ areImplicitPointsValid NOTIFY implicitPointsValidChanged)
+ Q_PROPERTY(QVector3D minPoint READ minPoint WRITE setMinPoint NOTIFY minPointChanged)
+ Q_PROPERTY(QVector3D maxPoint READ maxPoint WRITE setMaxPoint NOTIFY maxPointChanged)
public:
explicit QBoundingVolume(Qt3DCore::QNode *parent = nullptr);
~QBoundingVolume();
@@ -66,15 +68,23 @@ public:
QVector3D implicitMinPoint() const;
QVector3D implicitMaxPoint() const;
bool areImplicitPointsValid() const;
+ QVector3D minPoint() const;
+ QVector3D maxPoint() const;
public Q_SLOTS:
void setView(QGeometryView *view);
+ void setMinPoint(const QVector3D &minPoint);
+ void setMaxPoint(const QVector3D &maxPoint);
+
+ bool updateImplicitBounds();
Q_SIGNALS:
void viewChanged(QGeometryView *view);
void implicitMinPointChanged(const QVector3D &implicitMinPoint);
void implicitMaxPointChanged(const QVector3D &implicitMaxPoint);
void implicitPointsValidChanged(bool implicitPointsValid);
+ void minPointChanged(QVector3D minPoint);
+ void maxPointChanged(QVector3D maxPoint);
protected:
QBoundingVolume(QBoundingVolumePrivate &dd, Qt3DCore::QNode *parent = nullptr);
diff --git a/src/core/geometry/qboundingvolume_p.h b/src/core/geometry/qboundingvolume_p.h
index eef65a3de..b724d43b2 100644
--- a/src/core/geometry/qboundingvolume_p.h
+++ b/src/core/geometry/qboundingvolume_p.h
@@ -77,8 +77,11 @@ public:
QVector3D m_implicitMinPoint;
QVector3D m_implicitMaxPoint;
QVector3D m_implicitCenter;
+ QVector3D m_minPoint;
+ QVector3D m_maxPoint;
float m_implicitRadius;
bool m_implicitPointsValid;
+ bool m_explicitPointsValid;
bool m_primaryProvider;
};