我正在使用 AR 与 Vuforia 进行“室内导航”项目,我已使用“Vuforia Area Target Creator”应用程序扫描了地图。我已将区域目标导入到 unity,并创建了 NavMesh。我正在关注:https://library.vuforia.com/develop-area-targets/multiple-area-targets。我还创建了 NavMeshAgent 和目的地,但是当我运行项目时,区域目标重叠并且 NavMeshAgent 无法通过,问题是什么?
MultiArea 代码(如上面链接所述):
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
public class MultiArea : MonoBehaviour
{
#region PUBLIC_MEMBER_VARIABLES
public bool hideAugmentationsWhenNotTracked = true;
#endregion PUBLIC_MEMBER_VARIABLES
#region PRIVATE_MEMBER_VARS
/// <summary>
/// Trackable poses relative to the MultiArea root
/// </summary>
private readonly Dictionary<string, Matrix4x4> mPoses = new Dictionary<string, Matrix4x4>();
private bool m_Tracked = false;
#endregion PRIVATE_MEMBER_VARS
#region UNITY_MONOBEHAVIOUR_METHODS
// Start is called before the first frame update
void Start()
{
var areaTargets = GetComponentsInChildren<AreaTargetBehaviour>(includeInactive: true);
foreach (var at in areaTargets)
{
// Remember the relative pose of each AT to the group root node
var matrix = GetFromToMatrix(at.transform, transform);
mPoses[at.TargetName] = matrix;
Debug.Log("Original pose: " + at.TargetName + "\n" + matrix.ToString(""));
// Detach augmentation and re-parent it under the group root node
for (int i = at.transform.childCount - 1; i >= 0; i--)
{
var child = at.transform.GetChild(i);
child.SetParent(transform, worldPositionStays: true);
}
if (hideAugmentationsWhenNotTracked)
{
ShowAugmentations(false);
}
}
}
// Update is called once per frame
void Update()
{
if (!VuforiaApplication.Instance.IsRunning)
{
return;
}
// Find current "best tracked" Area Target
var atb = GetBestTrackedAreaTarget();
if (!atb)
{
if (m_Tracked)
{
m_Tracked = false;
if (hideAugmentationsWhenNotTracked)
{
ShowAugmentations(false);
}
}
return;
}
if (!m_Tracked)
{
m_Tracked = true;
ShowAugmentations(true);
}
if (GetGroupPoseFromAreaTarget(atb, out Matrix4x4 groupPose))
{
// set new group pose
transform.position = groupPose.GetColumn(3);
transform.rotation = Quaternion.LookRotation(groupPose.GetColumn(2), groupPose.GetColumn(1));
}
}
#endregion UNITY_MONOBEHAVIOUR_METHODS
#region PRIVATE_METHODS
private void ShowAugmentations(bool show)
{
var renderers = GetComponentsInChildren<Renderer>();
foreach (var rnd in renderers)
{
rnd.enabled = show;
}
}
private AreaTargetBehaviour GetBestTrackedAreaTarget()
{
var trackedAreaTargets = GetTrackedAreaTargets(includeLimited: true);
if (trackedAreaTargets.Count == 0)
{
return null;
}
// look for extended/tracked targets
foreach (var at in trackedAreaTargets)
{
if (at.TargetStatus.Status == Status.TRACKED ||
at.TargetStatus.Status == Status.EXTENDED_TRACKED)
{
return at;
}
}
// if no target in EXT/TRACKED was found,
// then fallback to any other target
// i.e. including LIMITED ones;
// just report the first in the list
return trackedAreaTargets[0];
}
private List<AreaTargetBehaviour> GetTrackedAreaTargets(bool includeLimited = false)
{
var trackedTargets = new List<AreaTargetBehaviour>();
var activeAreaTargets = FindObjectsOfType<AreaTargetBehaviour>();
foreach (var target in activeAreaTargets)
{
if (target.enabled &&
(target.TargetStatus.Status == Status.TRACKED ||
target.TargetStatus.Status == Status.EXTENDED_TRACKED ||
(includeLimited && target.TargetStatus.Status == Status.LIMITED)))
{
trackedTargets.Add(target);
}
}
return trackedTargets;
}
private bool GetGroupPoseFromAreaTarget(AreaTargetBehaviour atb, out Matrix4x4 groupPose)
{
groupPose = Matrix4x4.identity;
if (mPoses.TryGetValue(atb.TargetName, out Matrix4x4 areaTargetToGroup))
{
// Matrix of group root node w.r.t. AT
var groupToAreaTarget = areaTargetToGroup.inverse;
// Current atb matrix
var areaTargetToWorld = atb.transform.localToWorldMatrix;
groupPose = areaTargetToWorld * groupToAreaTarget;
return true;
}
return false;
}
private static Matrix4x4 GetFromToMatrix(Transform from, Transform to)
{
var m1 = from ? from.localToWorldMatrix : Matrix4x4.identity;
var m2 = to ? to.worldToLocalMatrix : Matrix4x4.identity;
return m2 * m1;
}
#endregion PRIVATE_METHODS
}
您可能将区域目标设置为静态,对吗? 区域目标应该始终移动,因此即使您使用导航网格,它们也不能是静态的。 尝试将其更改为“静态导航”,然后使用“导航”菜单再次烘焙。 参考链接: https://library.vuforia.com/develop-area-targets/using-unitys-navmesh-navigation-area-targets
您是否设法将导航线添加到多区域,因为这里说 noraml 导航不起作用,我们应该添加 navmesh 运行时生成器。
注意:为了向具有多个区域目标的此类设置添加导航,您可以使用 Unity 的运行时 NavMesh 生成,而不是使用将 NavMesh 应用于单个区域目标的 Vuforia NavMesh 指南。
如果你解决了这个问题,可以在这里分享吗