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
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
6
#
include
"qquick3dxrhandinput_p.h"
7
#
include
"qquick3dxrinputmanager_p.h"
8
#
include
"qquick3dxrhandmodel_p.h"
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
16
QT_BEGIN_NAMESPACE
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
56
QQuick3DXrHandModel
::
QQuick3DXrHandModel
(
QQuick3DNode
*
parent
)
57
:
QQuick3DModel
(
parent
)
58
{
59
}
60
61
void
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
82
void
QQuick3DXrHandModel
::setupModel()
83
{
84
if
(m_initialized) {
85
qWarning() <<
"XrHandModel does not support changing hand"
;
86
return
;
87
}
88
QQuick3DXrInputManager
*inputMan =
QQuick3DXrInputManager
::
instance
(
)
;
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
96
QQuick3DXrInputManagerPrivate
::
get
(
inputMan
)
->
setupHandModel
(
this
)
;
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
106
void
QQuick3DXrHandModel
::
componentComplete
()
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
*/
127
QQuick3DXrHandModel
::
Hand
QQuick3DXrHandModel
::
hand
()
const
128
{
129
return
m_hand;
130
}
131
132
void
QQuick3DXrHandModel
::
setHand
(Hand newHand)
133
{
134
if
(m_hand == newHand)
135
return
;
136
m_hand = newHand;
137
emit handChanged();
138
}
139
QT_END_NAMESPACE
QObjectData::parent
QObject * parent
Definition
qobject.h:74
QQuick3DNode
Definition
qquick3dnode_p.h:30
QQuick3DXrHandInput
Definition
qquick3dxrhandinput_p.h:31
QQuick3DXrHandInput::isHandTrackingActive
bool isHandTrackingActive() const
Definition
qquick3dxrhandinput.cpp:75
QQuick3DXrHandInput::isHandTrackingChanged
void isHandTrackingChanged()
QQuick3DXrHandInput::isActive
bool isActive() const
Definition
qquick3dxrhandinput.cpp:23
QQuick3DXrHandInput::jointDataUpdated
void jointDataUpdated()
QQuick3DXrHandModel
Definition
qquick3dxrhandmodel_p.h:35
QQuick3DXrHandModel::hand
Hand hand() const
\qmlproperty enumeration XrHandModel::hand
Definition
qquick3dxrhandmodel.cpp:127
QQuick3DXrHandModel::setHand
void setHand(Hand newHand)
Definition
qquick3dxrhandmodel.cpp:132
QQuick3DXrHandModel::componentComplete
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
Definition
qquick3dxrhandmodel.cpp:106
QQuick3DXrInputManagerPrivate
Definition
qopenxrinputmanager_p.h:38
QQuick3DXrInputManagerPrivate::get
static QQuick3DXrInputManagerPrivate * get(QQuick3DXrInputManager *inputManager)
Definition
qopenxrinputmanager.cpp:465
QQuick3DXrInputManagerPrivate::setupHandModel
void setupHandModel(QQuick3DXrHandModel *model)
Definition
qopenxrinputmanager.cpp:1002
QQuick3DXrInputManager
Definition
qquick3dxrinputmanager_p.h:33
QQuick3DXrInputManager::leftHandInput
QQuick3DXrHandInput * leftHandInput() const
Definition
qquick3dxrinputmanager.cpp:24
QQuick3DXrInputManager::rightHandInput
QQuick3DXrHandInput * rightHandInput() const
Definition
qquick3dxrinputmanager.cpp:30
QQuick3DXrInputManager::instance
static QQuick3DXrInputManager * instance()
Definition
qquick3dxrinputmanager.cpp:18
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtquick3d
src
xr
quick3dxr
qquick3dxrhandmodel.cpp
Generated on
for Qt by
1.18.0