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. Like other tracked nodes, it
27 must be a child of the \l XrOrigin, because the joint poses that drive it are relative
28 to the origin.
29
30 \note XrHandModel depends on hand-tracking data from the underlying
31 system and is, therefore, not available on all platforms.
32
33 \section1 Platform Notes
34
35 \section2 Apple Vision Pro
36
37 The Apple Vision Pro will overlay video of the user's hands directly,
38 and the XrHandModel will not have any content.
39
40 \section2 Meta devices
41
42 This required the following feature and permission lines to be added
43 in the AndroidManifest.qml file of your project.
44
45 \badcode
46 <uses-permission android:name="com.oculus.permission.HAND_TRACKING" />
47 <uses-feature android:name="oculus.software.handtracking" android:required="false" />
48 \endcode
49
50 Use \c true instead of \c false in the \c uses-feature tag if your app's interaction
51 is implemented only for hands.
52
53 \sa {Coordinate Systems and Units in \qxr}
54*/
55
60
61void QQuick3DXrHandModel::updatePose()
62{
63 if (auto *skin = QQuick3DModel::skin()) {
64 auto jointListProp = skin->joints();
65 int count = jointListProp.count(&jointListProp);
66 const auto positions = m_handTracker->jointPositions();
67 const auto rotations = m_handTracker->jointRotations();
68 for (int i = 0; i < count; ++i) {
69 auto *joint = jointListProp.at(&jointListProp, i);
70 joint->setPosition(positions.at(i));
71 joint->setRotation(rotations.at(i));
72 }
73 } else {
74 static bool warned = false;
75 if (!warned) {
76 qWarning() << "No skin available for hand model";
77 warned = true;
78 }
79 }
80}
81
82void QQuick3DXrHandModel::setupModel()
83{
84 if (m_initialized) {
85 qWarning() << "XrHandModel does not support changing hand";
86 return;
87 }
89 if (m_hand == Hand::RightHand)
90 m_handTracker = inputMan->rightHandInput();
91 else if (m_hand == Hand::LeftHand)
92 m_handTracker = inputMan->leftHandInput();
93 if (!m_handTracker)
94 return;
95
97
98 connect(m_handTracker, &QQuick3DXrHandInput::jointDataUpdated, this, &QQuick3DXrHandModel::updatePose);
99 connect(m_handTracker, &QQuick3DXrHandInput::isHandTrackingChanged, this, [this](){
100 setVisible(m_handTracker->isHandTrackingActive());
101 });
102 setVisible(m_handTracker->isActive());
103 m_initialized = true;
104}
105
107{
108 setupModel();
109 QQuick3DModel::componentComplete();
110}
111
112/*!
113 \qmlproperty enumeration XrHandModel::hand
114 \brief Specifies which hand the model is showing
115
116 \value XrHandModel.LeftHand The left hand.
117 \value XrHandModel.RightHand The right hand.
118 \value XrHandModel.Unknown No hand is shown.
119
120 \default XrHandModel.Unknown
121
122 The value of this property is compatible with \l{XrController::controller}{XrController.controller}.
123
124 \warning This property must be set when the XrHandModel is constructed.
125 Changing hands later is not currently supported.
126*/
128{
129 return m_hand;
130}
131
132void QQuick3DXrHandModel::setHand(Hand newHand)
133{
134 if (m_hand == newHand)
135 return;
136 m_hand = newHand;
137 emit handChanged();
138}
139QT_END_NAMESPACE
QObject * parent
Definition qobject.h:74
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.