Qt Quick 3D Xr
简介
扩展现实(XR)是一个术语,包括虚拟现实(VR)、增强现实(AR)和混合现实(MR)。这些技术可创造身临其境的体验,改变用户对周围世界的感知。Qt Quick 3D Xr 模块提供了用于开发 XR 应用程序的 API,Qt Quick 3D ,适用于各种设备和平台。
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 文件中添加一些函数。
在项目的 CMakeLists 文件中添加此行,即可指定自定义AndroidManifest.xml
并确保其被使用:
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。
快速链接
平台和工具链 | 开始使用 | 应用程序接口参考 |
示例 | 工具和集成开发环境 | 开发 XR 应用程序 |
© 2025 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.