Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3dxrhandmodel.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
9
10#if defined(Q_OS_VISIONOS)
11# include "visionos/qquick3dxrinputmanager_visionos_p.h"
12#else
13# include "openxr/qopenxrinputmanager_p.h"
14#endif
15
17
18/*!
19 \qmltype XrHandModel
20 \inherits Model
21 \inqmlmodule QtQuick3D.Xr
22 \brief Represents a 3D model for a hand.
23
24 Contains an animated 3D model that tracks the user's hands.
25
26 XrHandModel is only visible when hand tracking is active.
27
28 \note XrHandModel depends on hand-tracking data from the underlying
29 system and is, therefore, not available on all platforms.
30
31 \section1 Platform Notes
32
33 \section2 Apple Vision Pro
34
35 The Apple Vision Pro will overlay video of the user's hands directly,
36 and the XrHandModel will not have any content.
37
38 \section2 Meta devices
39
40 This required the following feature and permission lines to be added
41 in the AndroidManifest.qml file of your project.
42
43 \badcode
44 <uses-permission android:name="com.oculus.permission.HAND_TRACKING" />
45 <uses-feature android:name="oculus.software.handtracking" android:required="false" />
46 \endcode
47
48 Use \c true instead of \c false in the \c uses-feature tag if your app's interaction
49 is implemented only for hands.
50*/
51
56
57void QQuick3DXrHandModel::updatePose()
58{
59 if (auto *skin = QQuick3DModel::skin()) {
60 auto jointListProp = skin->joints();
61 int count = jointListProp.count(&jointListProp);
62 const auto positions = m_handTracker->jointPositions();
63 const auto rotations = m_handTracker->jointRotations();
64 for (int i = 0; i < count; ++i) {
65 auto *joint = jointListProp.at(&jointListProp, i);
66 joint->setPosition(positions.at(i));
67 joint->setRotation(rotations.at(i));
68 }
69 } else {
70 static bool warned = false;
71 if (!warned) {
72 qWarning() << "No skin available for hand model";
73 warned = true;
74 }
75 }
76}
77
78void QQuick3DXrHandModel::setupModel()
79{
80 if (m_initialized) {
81 qWarning() << "XrHandModel does not support changing hand";
82 return;
83 }
85 if (m_hand == RightHand)
86 m_handTracker = inputMan->rightHandInput();
87 else if (m_hand == LeftHand)
88 m_handTracker = inputMan->leftHandInput();
89 if (!m_handTracker)
90 return;
91
93
94 connect(m_handTracker, &QQuick3DXrHandInput::jointDataUpdated, this, &QQuick3DXrHandModel::updatePose);
95 connect(m_handTracker, &QQuick3DXrHandInput::isHandTrackingChanged, this, [this](){
96 setVisible(m_handTracker->isHandTrackingActive());
97 });
98 setVisible(m_handTracker->isActive());
99 m_initialized = true;
100}
101
103{
104 setupModel();
105 QQuick3DModel::componentComplete();
106}
107
108/*!
109 \qmlproperty enumeration XrHandModel::hand
110 \brief Specifies which hand the model is showing
111
112 \value XrHandModel.LeftHand The left hand.
113 \value XrHandModel.RightHand The right hand.
114 \value XrHandModel.Unknown No hand is shown.
115
116 \default XrHandModel.Unknown
117
118 The value of this property is compatible with \l{XrController::controller}{XrController.controller}.
119
120 \warning This property must be set when the XrHandModel is constructed.
121 Changing hands later is not currently supported.
122*/
123
125{
126 return m_hand;
127}
128
129void QQuick3DXrHandModel::setHand(Hand newHand)
130{
131 if (m_hand == newHand)
132 return;
133 m_hand = newHand;
134 emit handChanged();
135}
136QT_END_NAMESPACE
QObject * parent
Definition qobject.h:73
void isHandTrackingChanged()
Hand hand() const
\qmlproperty enumeration XrHandModel::hand
void setHand(Hand newHand)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
static QQuick3DXrInputManagerPrivate * get(QQuick3DXrInputManager *inputManager)
void setupHandModel(QQuick3DXrHandModel *model)
QQuick3DXrHandInput * leftHandInput() const
QQuick3DXrHandInput * rightHandInput() const
static QQuick3DXrInputManager * instance()
Combined button and popup list for selecting options.