c# - 重置 unity AR 会话以在 iOS 上找到可追踪的飞机
问题描述
当被 iOS 设备检测到时,可追踪平面变为无限。因此,始终会检测到相机镜头下方的最上面的平面。除了通过顶面降低相机外,没有办法回到下层。如何在视图中重置飞机?
使用 Unity 2018.3 和 AR Foundation 1.5.0-preview 6
private void UpdatePlacementPose()
{
var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));
var hits = new List<ARRaycastHit>();
arRaycast.Raycast(screenCenter, hits, UnityEngine.XR.ARSubsystems.TrackableType.Planes);
placementPoseIsValid = hits.Count > 0;
if (placementPoseIsValid)
{
placementPose = hits[0].pose;
var cameraForward = Camera.current.transform.forward;
var cameraBearing = new Vector3(cameraForward.x, 0, cameraForward.z).normalized;
placementPose.rotation = Quaternion.LookRotation(cameraBearing);
}
}
}
检测到地板并创建无限平面,但随后检测到桌面并在该更大高度检测到无限平面。这意味着将不再注册地板,因为上平面总是阻挡摄像机对下平面的视线。返回下平面的唯一方法是将相机物理移动到上平面下方,这样相机视图中就没有平面了。
解决方案
Change
UnityEngine.XR.ARSubsystems.TrackableType.Planes
To
UnityEngine.XR.ARSubsystems.TrackableType.PlaneWithinPolygon
Confusingly, the Planes enum value includes 4 different types of planes, including PlaneWithinInfinity, causing your undesired effect.
PlaneWithinPolygon will instead cause the AR Raycast to only detect hits within the boundaries of detected planes.
推荐阅读
- electron - Electron - 是否可以从互联网加载应用程序
- fastlane - 如何使用 fastlane 查询 REST API
- javascript - 如何将范围滑块的拇指附加到 div 的一角,以根据滑块的值调整该 div 的大小?
- postgresql - 存储在后端 Postgres(Sequelize)服务器中的日期和时间错误
- python - 如何在python中将文本附加到多个文件?
- css - SCSS 中每个类具有相同样式和特定属性的多个类
- css - 围绕固定点的 CSS 旋转
- jenkins - 在 Jenkins 管道中运行 kubectl patch statefulset
- react-native - 如何测试 ActivityIndicator 是否显示在反应原生组件单元测试中?
- oracle - 转换为分区表时的初始扩展区大小