Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquick3dxrspatialanchor.cpp
Go to the documentation of this file.
1
// Copyright (C) 2024 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
6
#
include
"qquick3dxrspatialanchor_p.h"
7
8
#
if
defined
(
Q_OS_VISIONOS
)
9
#
include
"visionos/qquick3dxranchormanager_visionos_p.h"
10
#
else
11
#
include
"openxr/qquick3dxranchormanager_openxr_p.h"
12
#
endif
13
14
QT_BEGIN_NAMESPACE
15
16
/*!
17
\qmltype XrSpatialAnchor
18
\inherits QtObject
19
\inqmlmodule QtQuick3D.Xr
20
\brief Tracks a specific location or object in real space.
21
22
This type represents a spatial anchor that tracks
23
a specific location or object in real space. It provides information about
24
the anchor's position, rotation, classification, and bounds.
25
26
Spatial anchors are accessed through an \l XrSpatialAnchorListModel.
27
28
\note The system provides Anchor objects. They cannot be created in QML.
29
30
See the \l{Qt Quick 3D - XR Spatial Anchors Example} for how to use this type.
31
32
\section1 Platform notes
33
34
\section2 Meta Quest Devices
35
36
This API makes use of the Meta Quest Scene and Spatial Anchor APIs.
37
You need to add the following permissions to your app's \c AndroidManifest.xml file:
38
39
\badcode
40
<uses-permission android:name="com.oculus.permission.USE_ANCHOR_API"/>
41
<uses-permission android:name="com.oculus.permission.USE_SCENE"/>
42
\endcode
43
44
\note You need to manually set up a Space before running an app, or anchors will
45
not be available.
46
*/
47
48
/*!
49
\qmlproperty enumeration XrSpatialAnchor::Classification
50
\ingroup xr-anchors
51
\brief The classification of the spatial anchor.
52
\readonly
53
54
The Classification enum provides a set of predefined category types that describe
55
the purpose or context of a spatial anchor.
56
57
\value Classification.Unknown The label has not been set or identified.
58
\value Classification.Wall The anchor represents a wall.
59
\value Classification.Ceiling The anchor represents a ceiling.
60
\value Classification.Floor The anchor represents a floor.
61
\value Classification.Table The anchor represents a table.
62
\value Classification.Seat The anchor represents a seat.
63
\value Classification.Window The anchor represents a window.
64
\value Classification.Door The anchor represents a door.
65
\value Classification.Other The anchor was not identified as any of the above types. See: \l classificationString
66
67
The following table shows the mapping between the classification type in \qxr,
68
OpenXR, and VisionOS. If the classification type from the system falls outside of the defined types,
69
then the \e Type is set to \c Other, and the system type is provided by the \l classificationString property.
70
71
\note The classification string can also be \c{Other}.
72
73
\table
74
\header
75
\li Type
76
\li OpenXR
77
\li VisionOS
78
\li Description
79
\row
80
\li Unknown
81
\li -
82
\li -
83
\li The label has not been set or identified.
84
\row
85
\li Wall
86
\li WALL_FACE
87
\li Wall
88
\li The anchor represents a wall.
89
\row
90
\li Ceiling
91
\li CEILING
92
\li Ceiling
93
\li The anchor represents a ceiling.
94
\row
95
\li Floor
96
\li FLOOR
97
\li Floor
98
\li The anchor represents a floor.
99
\row
100
\li Table
101
\li TABLE
102
\li Table
103
\li The anchor represents a table.
104
\row
105
\li Seat
106
\li COUCH
107
\li Seat
108
\li The anchor represents a seat.
109
\row
110
\li Window
111
\li WINDOW_FRAME
112
\li Window
113
\li The anchor represents a window.
114
\row
115
\li Door
116
\li DOOR_FRAME
117
\li Door
118
\li The anchor represents a door.
119
\row
120
\li Other
121
\li -
122
\li -
123
\li The anchor represents something else. See: \l classificationString
124
\endtable
125
*/
126
127
QQuick3DXrSpatialAnchor::QQuick3DXrSpatialAnchor(QtQuick3DXr::XrSpaceId space, QUuid &uuid, QObject *parent)
128
: QObject(parent)
129
, m_space(space)
130
, m_uuid(uuid)
131
{
132
}
133
134
QQuick3DXrSpatialAnchor
::~
QQuick3DXrSpatialAnchor
()
135
{
136
}
137
138
/*!
139
\qmlproperty vector3d XrSpatialAnchor::offset3D
140
\brief The 3D offset of the spatial anchor.
141
\readonly
142
143
This property provides the 3D offset of the anchor's bounds (in meters) from the anchor's \l position.
144
145
\sa offset3D, has3DBounds
146
*/
147
148
QVector3D
QQuick3DXrSpatialAnchor
::
offset3D
()
const
149
{
150
return
m_offset3D;
151
}
152
153
void
QQuick3DXrSpatialAnchor
::
setOffset3D
(
const
QVector3D &newOffset)
154
{
155
if
(m_offset3D == newOffset)
156
return
;
157
m_offset3D = newOffset;
158
emit offset3DChanged();
159
}
160
161
/*!
162
\qmlproperty vector3d XrSpatialAnchor::extent3D
163
\brief The 3D extent of the spatial anchor.
164
\readonly
165
166
This property specifies the spatial anchor's volume in three dimensions (width, height, and depth).
167
It is valid when \l has3DBounds is \c true.
168
169
\sa offset3D, has3DBounds
170
*/
171
172
QVector3D
QQuick3DXrSpatialAnchor
::
extent3D
()
const
173
{
174
return
m_extent3D;
175
}
176
177
void
QQuick3DXrSpatialAnchor
::
setExtent3D
(
const
QVector3D &newExtent)
178
{
179
if
(m_extent3D == newExtent)
180
return
;
181
m_extent3D = newExtent;
182
emit extent3DChanged();
183
}
184
185
/*!
186
\qmlproperty vector3d XrSpatialAnchor::position
187
\brief The position of the spatial anchor.
188
189
\readonly
190
This property returns the 3D position (in meters) of the spatial anchor's origin within the
191
session's coordinate system.
192
*/
193
194
QVector3D
QQuick3DXrSpatialAnchor
::
position
()
const
195
{
196
return
m_position;
197
}
198
199
void
QQuick3DXrSpatialAnchor
::
setPosition
(
const
QVector3D &newPosition)
200
{
201
if
(m_position == newPosition)
202
return
;
203
m_position = newPosition;
204
emit positionChanged();
205
}
206
207
/*!
208
\qmlproperty quaternion XrSpatialAnchor::rotation
209
\brief The orientation of the spatial anchor.
210
\readonly
211
212
This property provides the spatial anchor's rotation (as a quaternion).
213
*/
214
215
QQuaternion
QQuick3DXrSpatialAnchor
::
rotation
()
const
216
{
217
return
m_rotation;
218
}
219
220
void
QQuick3DXrSpatialAnchor
::
setRotation
(
const
QQuaternion &newRotation)
221
{
222
if
(m_rotation == newRotation)
223
return
;
224
m_rotation = newRotation;
225
emit rotationChanged();
226
}
227
228
/*!
229
\qmlproperty enumeration XrSpatialAnchor::classification
230
\brief The classification type of the spatial anchor.
231
\readonly
232
233
This property returns the \l {XrSpatialAnchor::Classification}{classification type} for this anchor
234
(for example,\c Table or \c Floor) describing the anchor's purpose or context.
235
236
\note The classification type coming from the system might not be in the set of labels
237
defined by the \l Classification enum, in which case the type will be set to \c Other
238
and the \l classificationString property will contain the original label.
239
240
\sa classificationString
241
*/
242
243
QQuick3DXrSpatialAnchor
::
Classification
QQuick3DXrSpatialAnchor
::
classification
()
const
244
{
245
return
m_classification;
246
}
247
248
void
QQuick3DXrSpatialAnchor
::
setClassification
(Classification newClassification)
249
{
250
if
(m_classification == newClassification)
251
return
;
252
m_classification = newClassification;
253
emit classificationChanged();
254
}
255
256
/*!
257
\qmlproperty string XrSpatialAnchor::classificationString
258
\brief The classification type of the spatial anchor as a string.
259
\readonly
260
261
This property returns the classification type as a string if one exists.
262
If the classification type is not in the set of types defined by the \l Classification enums, the
263
label is set to \c Other, and this property can be used to access the type as it was reported by
264
the system.
265
266
\note This string can be empty or change, depending on the system and how the anchor gets classified.
267
268
\sa classification
269
*/
270
271
QString
QQuick3DXrSpatialAnchor
::
classificationString
()
const
272
{
273
return
m_classificationString;
274
}
275
276
void
QQuick3DXrSpatialAnchor
::
setClassificationString
(
const
QString &newClassificationString)
277
{
278
if
(m_classificationString == newClassificationString)
279
return
;
280
m_classificationString = newClassificationString;
281
emit classificationStringChanged();
282
}
283
284
/*!
285
\qmlproperty bool XrSpatialAnchor::has2DBounds
286
\brief Indicates whether the spatial anchor has 2D bounds.
287
\readonly
288
289
This property holds \c true if the spatial anchor has 2D bounds,
290
described by \l offset2D and \l extent2D, indicating that it
291
represents a flat surface (for example, a floor or wall).
292
293
Otherwise, it returns false.
294
\sa offset2D, extent2D, has3DBounds
295
*/
296
297
bool
QQuick3DXrSpatialAnchor
::
has2DBounds
()
const
298
{
299
return
m_has2DBounds;
300
}
301
302
void
QQuick3DXrSpatialAnchor
::
setBounds2D
(
const
QVector2D &offset,
const
QVector2D &extent)
303
{
304
if
(qFuzzyCompare(m_offset2D, offset) && qFuzzyCompare(m_extent2D, extent))
305
return
;
306
307
m_offset2D = offset;
308
m_extent2D = extent;
309
310
// FIXME: verify
311
m_has2DBounds =
true
;
312
313
emit has2DBoundsChanged();
314
}
315
316
/*!
317
\qmlproperty bool XrSpatialAnchor::has3DBounds
318
\brief Indicates whether the spatial anchor has 3D bounds.
319
\readonly
320
321
This property returns \c true if the spatial anchor has 3D bounds, indicating
322
that it represents a volume (for example, a table or a cupboard).
323
The bounds are described by \l offset3D and \l extent3D.
324
325
Otherwise, it returns \c false.
326
\sa offset3D, extent3D, has2DBounds
327
*/
328
329
330
bool
QQuick3DXrSpatialAnchor
::
has3DBounds
()
const
331
{
332
return
m_has3DBounds;
333
}
334
335
void
QQuick3DXrSpatialAnchor
::
setBounds3D
(
const
QVector3D &offset,
const
QVector3D &extent)
336
{
337
if
(qFuzzyCompare(m_offset3D, offset) && qFuzzyCompare(m_extent3D, extent))
338
return
;
339
340
m_offset3D = offset;
341
m_extent3D = extent;
342
343
// FIXME: Store the 3D bounds and verify
344
m_has3DBounds =
true
;
345
346
emit has3DBoundsChanged();
347
}
348
349
/*!
350
\qmlproperty vector2d XrSpatialAnchor::offset2D
351
\brief The 2D offset of the spatial anchor.
352
353
\readonly
354
This property holds the offset of the anchor's bounds within
355
the X/Z plane. It is valid when \l has2DBounds is \c true.
356
357
\sa has2DBounds, extent2D
358
*/
359
360
QVector2D
QQuick3DXrSpatialAnchor
::
offset2D
()
const
361
{
362
return
m_offset2D;
363
}
364
365
/*!
366
\qmlproperty vector2d XrSpatialAnchor::extent2D
367
\brief The 2D extent of the spatial anchor.
368
\readonly
369
370
This property holds the spatial anchor's size in two dimensions (width and height) within
371
the X/Z plane. It is valid when \l has2DBounds is \c true.
372
373
\sa has2DBounds, offset2D
374
*/
375
376
QVector2D
QQuick3DXrSpatialAnchor
::
extent2D
()
const
377
{
378
return
m_extent2D;
379
}
380
381
/*!
382
\qmlproperty string XrSpatialAnchor::identifier
383
\brief A unique identifier for this spatial anchor.
384
\readonly
385
386
This property holds a unique identifier associated with the
387
spatial anchor. This is the same identifier referenced by a \l XrSpatialAnchorListModel.
388
*/
389
390
QString
QQuick3DXrSpatialAnchor
::
identifier
()
const
391
{
392
return
QString::fromLatin1(m_uuid.toRfc4122());
393
}
394
395
QSet
<
QUuid
>
QQuick3DXrSpatialAnchor
::
roomLayoutUuids
()
const
396
{
397
return
m_roomLayoutUuids;
398
}
399
400
void
QQuick3DXrSpatialAnchor
::
setRoomLayoutUuids
(
const
QSet<QUuid> &newRoomLayoutUuids)
401
{
402
m_roomLayoutUuids = newRoomLayoutUuids;
403
}
404
405
QSet
<
QUuid
>
QQuick3DXrSpatialAnchor
::
spaceContainerUuids
()
const
406
{
407
return
m_spaceContainerUuids;
408
}
409
410
void
QQuick3DXrSpatialAnchor
::
setSpaceContainerUuids
(
const
QSet<QUuid> &newSpaceContainerUuids)
411
{
412
m_spaceContainerUuids = newSpaceContainerUuids;
413
}
414
415
QT_END_NAMESPACE
QQuick3DXrSpatialAnchor
Definition
qquick3dxrspatialanchor_p.h:35
QQuick3DXrSpatialAnchor::spaceContainerUuids
QSet< QUuid > spaceContainerUuids() const
Definition
qquick3dxrspatialanchor.cpp:405
QQuick3DXrSpatialAnchor::setExtent3D
void setExtent3D(const QVector3D &newExtent)
Definition
qquick3dxrspatialanchor.cpp:177
QQuick3DXrSpatialAnchor::~QQuick3DXrSpatialAnchor
~QQuick3DXrSpatialAnchor() override
Definition
qquick3dxrspatialanchor.cpp:134
QQuick3DXrSpatialAnchor::offset3D
QVector3D offset3D() const
\qmlproperty vector3d XrSpatialAnchor::offset3D
Definition
qquick3dxrspatialanchor.cpp:148
QQuick3DXrSpatialAnchor::position
QVector3D position() const
\qmlproperty vector3d XrSpatialAnchor::position
Definition
qquick3dxrspatialanchor.cpp:194
QQuick3DXrSpatialAnchor::setClassificationString
void setClassificationString(const QString &newClassificationString)
Definition
qquick3dxrspatialanchor.cpp:276
QQuick3DXrSpatialAnchor::setBounds3D
void setBounds3D(const QVector3D &offset, const QVector3D &extent)
Definition
qquick3dxrspatialanchor.cpp:335
QQuick3DXrSpatialAnchor::setBounds2D
void setBounds2D(const QVector2D &offset, const QVector2D &extent)
Definition
qquick3dxrspatialanchor.cpp:302
QQuick3DXrSpatialAnchor::identifier
QString identifier() const
\qmlproperty string XrSpatialAnchor::identifier
Definition
qquick3dxrspatialanchor.cpp:390
QQuick3DXrSpatialAnchor::setRotation
void setRotation(const QQuaternion &newRotation)
Definition
qquick3dxrspatialanchor.cpp:220
QQuick3DXrSpatialAnchor::has2DBounds
bool has2DBounds() const
\qmlproperty bool XrSpatialAnchor::has2DBounds
Definition
qquick3dxrspatialanchor.cpp:297
QQuick3DXrSpatialAnchor::setSpaceContainerUuids
void setSpaceContainerUuids(const QSet< QUuid > &newSpaceContainerUuids)
Definition
qquick3dxrspatialanchor.cpp:410
QQuick3DXrSpatialAnchor::setRoomLayoutUuids
void setRoomLayoutUuids(const QSet< QUuid > &newRoomLayoutUuids)
Definition
qquick3dxrspatialanchor.cpp:400
QQuick3DXrSpatialAnchor::extent3D
QVector3D extent3D() const
\qmlproperty vector3d XrSpatialAnchor::extent3D
Definition
qquick3dxrspatialanchor.cpp:172
QQuick3DXrSpatialAnchor::classification
Classification classification() const
\qmlproperty enumeration XrSpatialAnchor::classification
Definition
qquick3dxrspatialanchor.cpp:243
QQuick3DXrSpatialAnchor::rotation
QQuaternion rotation() const
\qmlproperty quaternion XrSpatialAnchor::rotation
Definition
qquick3dxrspatialanchor.cpp:215
QQuick3DXrSpatialAnchor::extent2D
QVector2D extent2D() const
\qmlproperty vector2d XrSpatialAnchor::extent2D
Definition
qquick3dxrspatialanchor.cpp:376
QQuick3DXrSpatialAnchor::roomLayoutUuids
QSet< QUuid > roomLayoutUuids() const
Definition
qquick3dxrspatialanchor.cpp:395
QQuick3DXrSpatialAnchor::setClassification
void setClassification(Classification newClassification)
Definition
qquick3dxrspatialanchor.cpp:248
QQuick3DXrSpatialAnchor::setOffset3D
void setOffset3D(const QVector3D &newOffset)
Definition
qquick3dxrspatialanchor.cpp:153
QQuick3DXrSpatialAnchor::setPosition
void setPosition(const QVector3D &newPosition)
Definition
qquick3dxrspatialanchor.cpp:199
QQuick3DXrSpatialAnchor::has3DBounds
bool has3DBounds() const
\qmlproperty bool XrSpatialAnchor::has3DBounds
Definition
qquick3dxrspatialanchor.cpp:330
QQuick3DXrSpatialAnchor::classificationString
QString classificationString() const
\qmlproperty string XrSpatialAnchor::classificationString
Definition
qquick3dxrspatialanchor.cpp:271
QQuick3DXrSpatialAnchor::offset2D
QVector2D offset2D() const
\qmlproperty vector2d XrSpatialAnchor::offset2D
Definition
qquick3dxrspatialanchor.cpp:360
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtquick3d
src
xr
quick3dxr
qquick3dxrspatialanchor.cpp
Generated on
for Qt by
1.18.0