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
qquick3dxrview_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 QQUICK3DXRVIEW_P_H
5#define QQUICK3DXRVIEW_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18
19#include <QtCore/QObject>
20#include <QtQml/QQmlEngine>
21#include <QtQml/qqml.h>
22
23#include <QtQuick3D/private/qquick3dviewport_p.h>
24#include <QtQuick3D/private/qquick3dnode_p.h>
25#include <QtQuick3D/private/qquick3dsceneenvironment_p.h>
26#include <QtQuick3D/private/qquick3dpickresult_p.h>
27
28#include <QtQuick3DXr/private/qquick3dxrmanager_p.h>
29#include <QtQuick3DXr/private/qquick3dxrorigin_p.h>
30#include <QtQuick3DXr/private/qquick3dxrruntimeinfo_p.h>
31
33
34class QQuick3DXrItem;
35
36class Q_QUICK3DXR_EXPORT QQuick3DXrView : public QQuick3DNode
37{
38 Q_OBJECT
39
40 Q_PROPERTY(QQuick3DXrOrigin *xrOrigin READ xrOrigin WRITE setXROrigin NOTIFY xrOriginChanged)
41 Q_PROPERTY(QQuick3DSceneEnvironment *environment READ environment WRITE setEnvironment NOTIFY environmentChanged)
42 Q_PROPERTY(bool passthroughSupported READ passthroughSupported CONSTANT)
43 Q_PROPERTY(bool passthroughEnabled READ passthroughEnabled WRITE setPassthroughEnabled NOTIFY passthroughEnabledChanged FINAL)
44 Q_PROPERTY(QQuick3DXrRuntimeInfo *runtimeInfo READ runtimeInfo CONSTANT)
45 Q_PROPERTY(bool quitOnSessionEnd READ isQuitOnSessionEndEnabled WRITE setQuitOnSessionEnd NOTIFY quitOnSessionEndChanged FINAL)
46 Q_PROPERTY(QQuick3DRenderStats *renderStats READ renderStats CONSTANT)
47 Q_PROPERTY(FoveationLevel fixedFoveation READ fixedFoveation WRITE setFixedFoveation NOTIFY fixedFoveationChanged FINAL)
48 Q_PROPERTY(ReferenceSpace referenceSpace READ referenceSpace WRITE setReferenceSpace NOTIFY referenceSpaceChanged FINAL)
49 Q_PROPERTY(bool depthSubmissionEnabled READ depthSubmissionEnabled WRITE setDepthSubmissionEnabled NOTIFY depthSubmissionEnabledChanged FINAL)
50 Q_PROPERTY(bool multiViewRenderingSupported READ isMultiViewRenderingSupported CONSTANT)
51 Q_PROPERTY(bool multiViewRenderingEnabled READ multiViewRenderingEnabled NOTIFY multiViewRenderingEnabledChanged FINAL)
52 QML_NAMED_ELEMENT(XrView)
53 QML_ADDED_IN_VERSION(6, 8)
54
55public:
56 enum FoveationLevel {
57 NoFoveation = 0,
58 LowFoveation = 1,
59 MediumFoveation = 2,
60 HighFoveation = 3
61 };
62 Q_ENUM(FoveationLevel)
63
64 enum class ReferenceSpace {
65 ReferenceSpaceUnknown,
66 ReferenceSpaceLocal,
67 ReferenceSpaceStage,
68 ReferenceSpaceLocalFloor
69 };
70 Q_ENUM(ReferenceSpace)
71
72 using TouchTarget = std::variant<std::monostate, QQuick3DXrItem*, QQuick3DModel*>;
73 struct TouchState
74 {
75 int pointId = -1;
76 TouchTarget target;
77 bool grabbed = false;
78 bool pressed = false;
79 qreal touchDistance = 1e6;
80 qreal touchDepth = 0;
81 QPointF cursorPos;
82 QVector3D previous; // Finger position when timer was started
83 QElapsedTimer timer;
84 QVector3D surfacePoint;
85 QVector3D normal;
86 QVector2D uvPosition;
87 };
88
89 explicit QQuick3DXrView();
90 ~QQuick3DXrView();
91
92 QQuick3DXrOrigin *xrOrigin() const;
93 QQuick3DSceneEnvironment *environment() const;
94
95 bool passthroughSupported() const;
96 bool passthroughEnabled() const;
97
98 FoveationLevel fixedFoveation() const;
99 void setFixedFoveation(FoveationLevel level);
100
101 QQuick3DXrRuntimeInfo *runtimeInfo() const;
102
103 bool isQuitOnSessionEndEnabled() const;
104
105 QQuick3DRenderStats *renderStats() const;
106
107 Q_INVOKABLE QQuick3DPickResult rayPick(const QVector3D &origin, const QVector3D &direction) const;
108 Q_INVOKABLE QList<QQuick3DPickResult> rayPickAll(const QVector3D &origin, const QVector3D &direction) const;
109 Q_REVISION(6, 11) Q_INVOKABLE QQuick3DPickResult rayPick(const QVector3D &origin, const QVector3D &direction, QQuick3DModel *model) const;
110 Q_REVISION(6, 11) Q_INVOKABLE QQuick3DPickResult closestPointPick(const QVector3D &origin, float radius, QQuick3DModel *model = nullptr) const;
111
112 Q_INVOKABLE void setTouchpoint(QQuickItem *target, const QPointF &position, int pointId, bool active);
113 Q_INVOKABLE QVector3D processTouch(const QVector3D &pos, int pointId);
114 Q_INVOKABLE QVariantMap touchpointState(int pointId) const;
115
116 ReferenceSpace referenceSpace() const;
117 void setReferenceSpace(ReferenceSpace newReferenceSpace);
118
119 bool depthSubmissionEnabled() const;
120
121 void registerXrItem(QQuick3DXrItem *newXrItem);
122 void unregisterXrItem(QQuick3DXrItem *xrItem);
123
124 bool isMultiViewRenderingSupported() const;
125 bool multiViewRenderingEnabled() const;
126
127 QQuick3DXrManager *xrManager() { return &m_xrManager; }
128
129public Q_SLOTS:
130 void setEnvironment(QQuick3DSceneEnvironment * environment);
131 void setPassthroughEnabled(bool enable);
132 void setQuitOnSessionEnd(bool enable);
133 void setDepthSubmissionEnabled(bool enable);
134 void setXROrigin(QQuick3DXrOrigin *newXrOrigin);
135
136private Q_SLOTS:
137 void updateViewportGeometry();
138 void handleSessionEnded();
139 void handleClearColorChanged();
140 void handleAAChanged();
141 bool init();
142
143Q_SIGNALS:
144 void initializeFailed(const QString &errorString);
145 void sessionEnded();
146 void xrOriginChanged();
147 void environmentChanged(QQuick3DSceneEnvironment * environment);
148 void passthroughEnabledChanged();
149 void quitOnSessionEndChanged();
150 void fixedFoveationChanged();
151 void frameReady(); // tooling
152 void referenceSpaceChanged();
153 void depthSubmissionEnabledChanged();
154 void multiViewRenderingEnabledChanged();
155
156private:
157 friend class QQuick3DXrViewPrivate;
158 // The XrView does not expose the View3D in its public interface. This is intentional.
159 QQuick3DViewport *view3d() const;
160
161 bool handleVirtualTouch(TouchTarget target, const QVector3D &pos, TouchState *touchState, QVector3D *offset);
162
163 QPointer<QQuick3DSceneEnvironment> m_pendingSceneEnvironment;
164 QQuick3DXrManager m_xrManager;
165 mutable QQuick3DXrRuntimeInfo m_xrRuntimeInfo;
166 bool m_quitOnSessionEnd = true;
167 bool m_inDestructor = false;
168 bool m_isInitialized = false;
169
170 friend class QQuick3DXrVirtualMouse;
171 QList<QQuick3DXrItem *> m_xrItems;
172 struct XrTouchStates;
173 XrTouchStates *m_touchStates = nullptr;
174 QQuick3DXrOrigin *m_xrOrigin = nullptr;
175};
176
177class Q_QUICK3DXR_EXPORT QQuick3DXrViewPrivate
178{
179 QQuick3DXrViewPrivate() = delete;
180public:
181 [[nodiscard]] static QQuick3DViewport *getView3d(QQuick3DXrView *view);
182};
183
184QT_END_NAMESPACE
185
186#endif // QQUICK3DXRVIEW_P_H
Combined button and popup list for selecting options.
QtQuick3DXr::Hand handForController(QQuick3DXrController::Controller controller)
QtQuick3DXr::HandPoseSpace pose_cast(QQuick3DXrController::HandPoseSpace poseSpace)