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