Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qopenxrinputmanager_p.h
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
4#ifndef QQUICK3DXINPUTMANAGER_OPENXR_P_H
5#define QQUICK3DXINPUTMANAGER_OPENXR_P_H
6
7#include <QObject>
8
9#include <openxr/openxr.h>
10#include <functional>
12#include <QtQuick3DXr/private/qtquick3dxrglobal_p.h>
13
14#include <private/qquick3dmodel_p.h>
15
16//
17// W A R N I N G
18// -------------
19//
20// This file is not part of the Qt API. It exists purely as an
21// implementation detail. This header file may change from version to
22// version without notice, or even be removed.
23//
24// We mean it.
25//
26
28
32
34{
36 Q_DECLARE_PUBLIC(QQuick3DXrInputManager)
37public:
40
41 void init(XrInstance instance, XrSession session);
42 void teardown();
43
44 bool isValid() const { return m_initialized; }
45
47
49
50 void pollActions();
51 void updatePoses(XrTime predictedDisplayTime, XrSpace appSpace);
52 void updateHandtracking(XrTime predictedDisplayTime, XrSpace appSpace, bool aimExtensionEnabled);
53
54 XrSpace handSpace(Hand hand);
55 bool isHandActive(Hand hand);
56 bool isHandTrackerActive(Hand hand);
57
58 void setPosePosition(Hand hand, const QVector3D &position);
59 void setPoseRotation(Hand hand, const QQuaternion &rotation);
60
63
65
66 // NOTE: Static for now...
67 qsizetype getPokeJointIndex() const { return qsizetype(XR_HAND_JOINT_INDEX_TIP_EXT); }
68
69 PFN_xrCreateHandTrackerEXT xrCreateHandTrackerEXT_;
70 PFN_xrDestroyHandTrackerEXT xrDestroyHandTrackerEXT_;
71 PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT_;
72
73 PFN_xrGetHandMeshFB xrGetHandMeshFB_;
74
75 XrHandTrackerEXT handTracker[2] = {XR_NULL_HANDLE, XR_NULL_HANDLE};
76
77 XrHandJointLocationEXT jointLocations[2][XR_HAND_JOINT_COUNT_EXT];
78 XrHandJointVelocityEXT jointVelocities[2][XR_HAND_JOINT_COUNT_EXT];
79
80private:
81 void setupHandModelInternal(QQuick3DXrHandModel *model, Hand hand);
82
83 void setupHandTracking();
84 bool queryHandMesh(Hand hand);
85 void setupActions();
86 void destroyActions();
87 [[nodiscard]] bool checkXrResult(const XrResult &result);
88 bool resolveXrFunction(const char *name, PFN_xrVoidFunction *function);
89 void setPath(XrPath &path, const QByteArray &pathString);
90
91 void createAction(XrActionType type,
92 const char *name,
93 const char *localizedName,
94 int numSubactions,
95 XrPath *subactionPath,
96 XrAction &action);
97 void getBoolInputState(XrActionStateGetInfo &getInfo, const XrAction &action, std::function<void(bool)> setter);
98 void getFloatInputState(XrActionStateGetInfo &getInfo, const XrAction &action, std::function<void(float)> setter);
99
100 QQuick3DXrInputManager *q_ptr = nullptr;
101
102 XrInstance m_instance{XR_NULL_HANDLE};
103 XrSession m_session{XR_NULL_HANDLE};
104
105 enum SubPathSelector {NoSubPath = 0, LeftHandSubPath = 1, RightHandSubPath = 2, BothHandsSubPath = 3};
106
107 struct QXRHandComponentPath
108 {
109 XrPath paths[2] = {{}, {}};
110 QByteArray componentPathString;
111 };
112 QXRHandComponentPath makeHandInputPaths(const QByteArrayView path);
113 XrPath makeInputPath(const QByteArrayView path);
114
115 struct InputActionInfo {
117 const char *shortName;
118 const char *localizedName;
119 XrActionType type;
120 };
121
122 QList<InputActionInfo> m_handInputActionDefs;
123
124 struct HandActions {
125 XrAction gripPoseAction{XR_NULL_HANDLE};
126 XrAction aimPoseAction{XR_NULL_HANDLE};
127 XrAction hapticAction{XR_NULL_HANDLE};
128 };
129
130 // Input State
131 XrActionSet m_actionSet{XR_NULL_HANDLE};
132 XrPath m_handSubactionPath[2];
133 XrSpace m_handGripSpace[2];
134 XrSpace m_handAimSpace[2];
135
136 QQuick3DXrHandInput *m_handInputState[2];
137 HandActions m_handActions;
138 XrAction m_inputActions[QQuick3DXrInputAction::NumActions] = {};
139
140 uint m_aimStateFlags[2] = {};
141 bool m_initialized = false;
142 bool m_validAimStateFromUpdatePoses[2] = {false, false};
143
144 // Hand Mesh Data
145 struct HandMeshData {
146 QVector<XrVector3f> vertexPositions;
147 QVector<XrVector3f> vertexNormals;
148 QVector<XrVector2f> vertexUVs;
149 QVector<XrVector4sFB> vertexBlendIndices;
150 QVector<XrVector4f> vertexBlendWeights;
151 QVector<int16_t> indices;
152 XrPosef jointBindPoses[XR_HAND_JOINT_COUNT_EXT];
153 XrHandJointEXT jointParents[XR_HAND_JOINT_COUNT_EXT];
154 float jointRadii[XR_HAND_JOINT_COUNT_EXT];
155 } m_handMeshData[2];
156
157
158 struct HandGeometryData {
159 QQuick3DGeometry *geometry = nullptr;
160 } m_handGeometryData[2];
161
162 QQuick3DGeometry *createHandMeshGeometry(const HandMeshData &handMeshData);
163 void createHandModelData(Hand hand);
164 friend class QOpenXrHandModel;
165};
166
168
169#endif // QQUICK3DXINPUTMANAGER_OPENXR_P_H
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qobject.h:103
The QQuaternion class represents a quaternion consisting of a vector and scalar.
\qmltype Geometry \inherits Object3D \inqmlmodule QtQuick3D \instantiates QQuick3DGeometry
void init(XrInstance instance, XrSession session)
XrHandJointVelocityEXT jointVelocities[2][XR_HAND_JOINT_COUNT_EXT]
QQuick3DXrInputManagerPrivate(QQuick3DXrInputManager &manager)
void updatePoses(XrTime predictedDisplayTime, XrSpace appSpace)
PFN_xrDestroyHandTrackerEXT xrDestroyHandTrackerEXT_
QQuick3DXrHandInput * rightHandInput() const
static QQuick3DXrInputManagerPrivate * get(QQuick3DXrInputManager *inputManager)
void setPosePosition(Hand hand, const QVector3D &position)
void setPoseRotation(Hand hand, const QQuaternion &rotation)
void setupHandModel(QQuick3DXrHandModel *model)
PFN_xrCreateHandTrackerEXT xrCreateHandTrackerEXT_
QQuick3DXrHandInput * leftHandInput() const
XrHandJointLocationEXT jointLocations[2][XR_HAND_JOINT_COUNT_EXT]
PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT_
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
Combined button and popup list for selecting options.
GLenum GLuint id
[7]
GLenum GLsizei const void * pathString
GLenum type
GLsizei const GLuint * paths
GLuint name
GLsizei GLenum const void * indices
GLsizei const GLchar *const * path
GLuint64EXT * result
[6]
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_OBJECT
ptrdiff_t qsizetype
Definition qtypes.h:165
unsigned int uint
Definition qtypes.h:34
QSqlQueryModel * model
[16]
QNetworkAccessManager manager