首页 > 解决方案 > 重置 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);
        }
    }
}

检测到地板并创建无限平面,但随后检测到桌面并在该更大高度检测到无限平面。这意味着将不再注册地板,因为上平面总是阻挡摄像机对下平面的视线。返回下平面的唯一方法是将相机物理移动到上平面下方,这样相机视图中就没有平面了。

标签: c#iosunity3daugmented-reality

解决方案


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.

Source: https://docs.unity3d.com/Packages/com.unity.xr.arsubsystems@2.1/api/UnityEngine.XR.ARSubsystems.TrackableType.html


推荐阅读