【问题标题】:Spatial Anchor : await CreateAnchorAsync stays stuck空间锚点:等待 CreateAnchorAsync 卡住
【发布时间】:2022-12-20 20:36:13
【问题描述】:

我正在尝试将锚点保存到 Azure 空间锚点云。此应用程序可在 HoloLens(正在运行)上使用,现在我正在尝试使其在 Android 上运行。

问题
当我尝试保存锚点时,代码停留在await _spatialAnchorManager.CreateAnchorAsync(cloudSpatialAnchor);

    private async Task CreateAnchor(Vector3 position)
    {
        //Create Anchor GameObject. We will use ASA to save the position and the rotation of this GameObject.
        if (!InputDevices.GetDeviceAtXRNode(XRNode.Head).TryGetFeatureValue(CommonUsages.devicePosition, out Vector3 headPosition))
        {
            headPosition = Vector3.zero;
        }

        Quaternion orientationTowardsHead = Quaternion.LookRotation(position - headPosition, Vector3.up);

        GameObject anchorGameObject = GameObject.Instantiate(_CubePrefab);

        anchorGameObject.GetComponent<MeshRenderer>().material.color = Color.white;
        anchorGameObject.transform.position = position;
        anchorGameObject.transform.rotation = orientationTowardsHead;
        anchorGameObject.transform.localScale = Vector3.one * 0.1f;

        //Add and configure ASA components
        CloudNativeAnchor cloudNativeAnchor = anchorGameObject.AddComponent<CloudNativeAnchor>();

        if (cloudNativeAnchor.CloudAnchor == null)
        {
            await cloudNativeAnchor.NativeToCloud();
        }

        CloudSpatialAnchor cloudAnchor = cloudNativeAnchor.CloudAnchor;

        // Then we create a new local cloud anchor
        CloudSpatialAnchor cloudSpatialAnchor = new CloudSpatialAnchor();
        // Now we set the local cloud anchor's position to the native XR anchor's position
        cloudSpatialAnchor.LocalAnchor = await anchorGameObject.FindNativeAnchor().GetPointer();
        // Check to see if we got the local XR anchor pointer
        if (cloudSpatialAnchor.LocalAnchor == IntPtr.Zero)
        {
            return;
        }
  
        //Collect Environment Data
        /*while (!_spatialAnchorManager.IsReadyForCreate) // debug 20.12.2022
        {
            float createProgress = _spatialAnchorManager.SessionStatus.RecommendedForCreateProgress;
            UnityEngine.Debug.Log($"ASA - Move your device to capture more environment data: {createProgress:0%}");
        }*/
        try
        {
            // Now that the cloud spatial anchor has been prepared, we can try the actual save here.
            await _spatialAnchorManager.CreateAnchorAsync(cloudSpatialAnchor);
            bool saveSucceeded = cloudSpatialAnchor != null;
            if (!saveSucceeded)
            {
                return;
            }
            _foundOrCreatedAnchorGameObjects.Add(anchorGameObject);
            _createdAnchorIDs.Add(cloudSpatialAnchor.Identifier);
            anchorGameObject.GetComponent<MeshRenderer>().material.color = Color.green;
        }
        catch (Exception exception)
        {
            UnityEngine.Debug.LogException(exception);
        }
    }

以前我有一个 while 循环以确保 SessionStatus.RecommendedForCreateProgress 具有正确的值,但它最终阻止了我的应用程序,所以我评论了它。在 HoloLens 上我没有这个问题,所以我可以让 while 循环。我不认为这是我无法保存主播的原因

我试过的
我试图取消对 while 循环的注释,但应用程序开始冻结,因为它卡在其中。

问题
我该如何解决这个问题,代码停留在await _spatialAnchorManager.CreateAnchorAsync(cloudSpatialAnchor); 上并且没有抛出任何错误,它只是停留在卡住状态

【问题讨论】:

    标签: android unity3d azure-spatial-anchors


    【解决方案1】:

    答案很简单,尽管它可以在 HoloLens 上运行,但在 Android 上你必须有 SessionStatus.RecommendedForCreateProgress &gt;= 1 如果你想能够执行 _spatialAnchorManager.CreateAnchorAsync(cloudSpatialAnchor);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-08
      相关资源
      最近更新 更多