Qt Quick 3D Xr

简介
扩展现实(XR)是一个涵盖虚拟现实(VR)、增强现实(AR)和混合现实(MR)的统称。这些技术能够创造身临其境的体验,从而改变用户对周围世界的感知。Qt Quick 3D Xr 模块提供了 API,支持开发者利用Qt Quick 3D 在各种设备和平台上开发 XR 应用程序。
Qt Quick 3D 与Qt Quick 3D XR 应用程序的区别
入口点
从开发者的角度来看,Qt Quick 3D 与Qt Quick 3D XR 应用程序的主要区别在于场景的入口点,并且必须了解现实世界的单位和追踪数据。
在Qt Quick 3D 中,一个最简单的应用程序通常由摄像头、光源和 3D 模型组成。这些元素的位置和尺寸是在场景坐标系中定义的,该坐标系是任意的,开发者可以根据应用程序的需求自行定义。
View3D {
width: 1280
height: 720
PerspectiveCamera {
position: Qt.vector3d(0, 200, 300)
}
DirectionalLight {
}
Node {
id: sceneRoot
Model {
id: model
position: Qt.vector3d(0, -200, 0)
source: "#Cylinder"
materials: [ PrincipledMaterial {
baseColor: "red"
}]
}
}
}在 XR 应用程序中,定义场景时需考虑现实世界单位和追踪数据。摄像机的位置和方向由设备决定;如果是头戴式显示器(HMD),则由用户的头部位置和方向决定。 场景的单位应与现实世界单位一致。例如,您希望一扇门或一张桌子在现实世界和虚拟世界中的尺寸保持一致。
XrView {
DirectionalLight {
}
xrOrigin: XrOrigin {
XrController {
id: rightController
controller: XrController.ControllerRight
}
XrController {
id: leftController
controller: XrController.ControllerLeft
}
}
Node {
id: sceneRoot
Model {
id: floor
source: ":meshes/floor.mesh"
materials: [ PrincipledMaterial {
baseColor: "green"
}]
}
Model {
id: table
property real height: 0.7
position: Qt.vector3d(0, height - 2.5, 0)
source: ":meshes/table.mesh"
materials: PrincipledMaterial {
baseColor: "white"
}
}
Model {
id: monitor
source: ":meshes/monitor.mesh"
y: table.height
XrItem {
id: theScreen
y: monitor.yOffset + height
x: -width / 2
width: monitor.width
height: monitor.height
contentItem: ScreenContent {}
}
}
}
}其他 CMake 函数
如所有Qt Quick 3D Xr 示例中的 CmakeLists.txt 文件所示,您需要在项目顶层的 CMakeLists 文件中添加一些函数。
要指定自定义的AndroidManifest.xml 并确保其被正确调用,请在项目的 CMakeLists 文件中添加以下代码行:
if(ANDROID)
set_property(TARGET xr_simple APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/android)
endif()有关配置AndroidManifest.xml 的更多详细信息,请参阅“Meta Quest 3 入门”页面中的相关章节。
CMakeLists.txt 的更改也适用于 visionOS,在该环境中我们会包含MacOSXBundleInfo.plist.in 文件:
if (APPLE AND CMAKE_SYSTEM_NAME STREQUAL "visionOS")
set_target_properties(xr_simple PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER io.qt.xr_simple
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/visionos/MacOSXBundleInfo.plist.in
)
endif()接下来该怎么做?
请查阅《Meta Quest 3 入门指南》或《Apple Vision Pro 入门指南》,了解如何开始使用您的特定设备。有关支持的平台和设备的更多信息,请参阅“支持的平台”页面。
如果您正在寻找特定的Qt Quick 3D XR API,请查阅《API Reference 》,或尝试其中一个Qt Quick 3D XR示例,这些示例演示了如何使用Qt Quick 3D XR API。
快速链接
| 平台和工具链 | 入门指南 | API 参考 |
| 示例 | 工具和集成开发环境 | 开发 XR 应用程序 |
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.