9#include <QtQuick3DUtils/private/qssgassert_p.h>
10#include <QtQuick3DUtils/private/qssgutils_p.h>
21QQuick3DXrAnchorManager::QQuick3DXrAnchorManager(
QObject *parent)
26QQuick3DXrAnchorManager::~QQuick3DXrAnchorManager()
35 m_anchorsByUuid.
insert(anchor->uuid(), anchor);
43 anchor->deleteLater();
45 qWarning() <<
"Anchor not found for removal: " << uuid;
59 m_anchors = m_anchorsByUuid.
values();
99 size_t foundIndex = 0;
115 static const QQuaternion s_rot90X = QQuaternion::fromEulerAngles({-90.0f, 0.0f, 0.0f});
117 simd_float4x4 originFromAnchorTransform = ar_anchor_get_origin_from_anchor_transform(planeAnchor);
118 QMatrix4x4 transform{originFromAnchorTransform.columns[0].x, originFromAnchorTransform.columns[1].x, originFromAnchorTransform.columns[2].x, originFromAnchorTransform.columns[3].x,
119 originFromAnchorTransform.columns[0].y, originFromAnchorTransform.columns[1].y, originFromAnchorTransform.columns[2].y, originFromAnchorTransform.columns[3].y,
120 originFromAnchorTransform.columns[0].z, originFromAnchorTransform.columns[1].z, originFromAnchorTransform.columns[2].z, originFromAnchorTransform.columns[3].z,
121 0.0f, 0.0f, 0.0f, 1.0f};
123 ar_plane_classification_t classification = ar_plane_anchor_get_plane_classification(planeAnchor);
131 ar_plane_geometry_t planeGeometry = ar_plane_anchor_get_geometry(planeAnchor);
132 ar_plane_extent_t planeExtent = ar_plane_geometry_get_plane_extent(planeGeometry);
134 const float width = ar_plane_extent_get_width(planeExtent);
135 const float height = ar_plane_extent_get_height(planeExtent);
144 rot = rot * s_rot90X;
156 QSSG_ASSERT_X(context !=
nullptr,
"Context is null!",
return);
163 if (removed_anchors) {
164 ar_plane_anchors_enumerate_anchors_f(removed_anchors, context, [](
void *context, ar_plane_anchor_t planeAnchor) ->
bool {
169 unsigned char identifier[16] {};
170 ar_anchor_get_identifier(planeAnchor, identifier);
173 qWarning() <<
"Invalid UUID for anchor";
178 that->removeAnchor(uuid);
186 ar_plane_anchors_enumerate_anchors_f(added_anchors, context, [](
void *context, ar_plane_anchor_t planeAnchor) ->
bool {
193 unsigned char identifier[16] {};
194 ar_anchor_get_identifier(planeAnchor, identifier);
197 qWarning() <<
"Invalid UUID for anchor";
205 that->addAnchor(anchor);
212 if (updated_anchors) {
213 ar_plane_anchors_enumerate_anchors_f(updated_anchors, context, [](
void *context, ar_plane_anchor_t planeAnchor) ->
bool {
218 unsigned char identifier[16] {};
219 ar_anchor_get_identifier(planeAnchor, identifier);
222 qWarning() <<
"Invalid UUID for anchor";
234 that->addAnchor(anchor);
237 that->updateAnchor(anchor);
244 that->populateAnchorsList();
249 QSSG_ASSERT_X(!m_isInitialized,
"Anchor manager already initialized",
return);
251 m_isPlaneDetectionSupported = (m_requestedAnchorType == AnchorType::Plane) && ar_plane_detection_provider_is_supported();
252 if (m_isPlaneDetectionSupported) {
253 ar_plane_detection_configuration_t planeDetectionConfiguration = ar_plane_detection_configuration_create();
254 m_planeDetectionProvider = ar_plane_detection_provider_create(planeDetectionConfiguration);
255 ar_plane_detection_provider_set_update_handler_f(m_planeDetectionProvider, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
this, &planeUpdateHandler);
256 ar_data_providers_add_data_provider(dataProviders, m_planeDetectionProvider);
258 qWarning(
"Plane detection is not supported on this platform.");
262void QQuick3DXrAnchorManager::initAnchorManager()
264 QSSG_ASSERT_X(!m_isInitialized,
"Anchor manager already initialized",
return);
266 m_isInitialized = m_isPlaneDetectionSupported;
288 return m_anchors.
size();
QList< T > values() const
Returns a list containing all the values in the hash, in an arbitrary order.
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
qsizetype size() const noexcept
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
bool moveToThread(QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
Changes the thread affinity for this object and its children and returns true on success.
The QQuaternion class represents a quaternion consisting of a vector and scalar.
static QQuick3DXrAnchorManager * instance()
void updateAnchor(QQuick3DXrSpatialAnchor *anchor)
void anchorRemoved(QUuid uuid)
void populateAnchorsList()
const QList< QQuick3DXrSpatialAnchor * > & anchors() const
void anchorAdded(QQuick3DXrSpatialAnchor *anchor)
void removeAnchor(QUuid uuid)
qsizetype anchorCount() const
void anchorUpdated(QQuick3DXrSpatialAnchor *anchor)
void requestSceneCapture()
void setClassificationString(const QString &newClassificationString)
void setBounds2D(const QVector2D &offset, const QVector2D &extent)
void setRotation(const QQuaternion &newRotation)
Classification classification
void setClassification(Classification newClassification)
void setPosition(const QVector3D &newPosition)
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QUuid fromRfc4122(QByteArrayView) noexcept
Creates a QUuid object from the binary representation of the UUID, as specified by RFC 4122 section 4...
The QVector2D class represents a vector or vertex in 2D space.
The QVector3D class represents a vector or vertex in 3D space.
bool Q_QUICK3DUTILS_EXPORT decompose(const QMatrix4x4 &m, QVector3D &position, QVector3D &scale, QQuaternion &rotation)
Combined button and popup list for selecting options.
bool isValidUuid(const quint8(&uuid)[N])
GLint GLsizei GLsizei height
GLuint GLenum GLenum transform
GLenum GLenum GLenum GLenum GLenum scale
static const AnchorClassificationMap & getAnchorClassificationName(ar_plane_classification_t classification, bool *identified=nullptr)
static constexpr size_t anchorClassificationStart
static void updateAnchorProperties(QQuick3DXrSpatialAnchor &anchor, ar_plane_anchor_t planeAnchor)
static const AnchorClassificationMap anchorClassificationMap[]
struct ar_data_providers_s * ar_data_providers_t
struct ar_plane_anchors_s * ar_plane_anchors_t
#define QSSG_DEBUG_COND(cond)
#define QSSG_ASSERT_X(cond, msg, action)
#define Q_UNIMPLEMENTED()
ar_plane_classification_t classification
const char classificationName[16]
QQuick3DXrSpatialAnchor::Classification label
AnchorClassifcation classificationEnum