区域描述:学习

Local Area Description: Learning

我刚开始学习一些关于 Google Tango 的东西,我在理解如何实施局部区域描述学习方面遇到了一些麻烦。我遵循了文档中的操作指南之一,即在 AR 中放置虚拟对象的指南,我希望该应用程序记住放置这些小猫的位置。我将附加来自 Unity 的场景和我尝试为 AreaDEscription 启用 SaveCurrent 方法的脚本。 The scene from Unity 以下代码主要来自操作指南,我在其中尝试创建另一个线程来保存当前 AreaDescription

public class KittyUIController : MonoBehaviour
{
Thread thread;
public GameObject m_kitten;
private TangoPointCloud m_pointCloud;

void Start()
{
    m_pointCloud = FindObjectOfType<TangoPointCloud>();
    thread = new Thread(Thread123);
}

void Update()
{
    if (Input.touchCount == 1)
    {
        // Trigger place kitten function when single touch ended.
        Touch t = Input.GetTouch(0);
        if (t.phase == TouchPhase.Ended)
        {
            PlaceKitten(t.position);
            thread.Start();
        }
    }
}

void PlaceKitten(Vector2 touchPosition)
{
    // Find the plane.
    Camera cam = Camera.main;
    Vector3 planeCenter;
    Plane plane;
    if (!m_pointCloud.FindPlane(cam, touchPosition, out planeCenter, out plane))
    {
        Debug.Log("cannot find plane.");
        return;
    }

    // Place kitten on the surface, and make it always face the camera.
    if (Vector3.Angle(plane.normal, Vector3.up) < 30.0f)
    {
        Vector3 up = plane.normal;
        Vector3 right = Vector3.Cross(plane.normal, cam.transform.forward).normalized;
        Vector3 forward = Vector3.Cross(right, plane.normal).normalized;
        Instantiate(m_kitten, planeCenter, Quaternion.LookRotation(forward, up));
    }
    else
    {
        Debug.Log("surface is too steep for kitten to stand on.");
    }
}

void Thread123()
{
    AreaDescription.SaveCurrent();
}

public void OnApplicationQuit()
{
    thread.Abort();
}

}

我没有足够的声誉点数来发表评论,所以我 post 在这里回答。您应该提供有关哪些有效,哪些无效的更多详细信息。

首先,从this page, because you need to set up AreaLearning properly in your App. Then, examine this code和相应的AreaLearning场景示例开始,这就是您需要做的所有事情。

一些既不在教程也不在代码中的东西,但让它工作非常重要的是你需要检查 [=37= 的 "Tango AR Pose Controller" 中的 "Use Area Description" ] prefab(或者Tango Camera,如果你使用的是最新SDK的prefab),否则你的对象将不会被放置在ADF基础框架上。

如果我必须总结一下,工作流程是:

  1. 加载现有的 ADF(是否处于学习模式)或开始学习新的。
  2. 如果加载现有的 ADF,则重新定位(如果您在学习模式下加载 ADF,这可能需要更长的时间)
  3. 重新定位后,加载 xml 存储您的对象(在您的 cas 中的小猫)。 XML 通常与 ADF 的 UUID 同名,并存储在 Application.persistentDataPath(Android/data/com.YourApp/files)中。所有加载的对象都将放置在 ADF 基础框架上。
  4. 对于您放置的每只新小猫,记录放置时的时间戳。此时间戳将允许您恢复放置小猫时的帧与 ADF 基础帧之间的转换。
  5. 当您保存到 XML 时,由于转换,您将能够保存小猫关于 ADF 基本框架的坐标(在示例中,转换是在 _UpdateMarkersForLoopClosures 中计算的)。

在示例中,他们在保存后重新加载场景,因此他们返回到 AreaDescriptionPicker 屏幕,但您可以决定如何执行此操作。

我真的不知道该说什么了。希望这有帮助。