SpatialMap_Sparse_ImageTarget¶
演示如何同时使用稀疏空间地图和图像跟踪。
用法¶

标记1:显示系统状态和操作提示。
详解¶
同时使用稀疏空间地图和图像跟踪¶
为了同时使用稀疏空间地图和图像跟踪,只需要将它们放在同一个ARSession下面,并在session中使用 VIOCameraDevice 而不是 VideoCameraDevice。

在场景中构建sparse spatial map¶
在sample中Sparse spatial map使用build模式运行。如果需要sparse spatial map运行在定位模式,可以参考 MapLocalizing_Sparse 。
为使Sparse spatial map运行在build模式,session中需要有一个 SparseSpatialMapController 存在,且 Source Type 设为 Map Builder , Map Worker 设为session中的 SparseSpatialMapWorkerFrameFilter 。

世界中心下的物体¶
WorldRoot 可以用来实现这些功能,
在跟踪状态变化时控制物体显示和隐藏。
根据 ARSession.CenterMode 相对camera一起移动。
如果上面这些都有其它地方处理,那可以忽略 WorldRoot。
在这个sample中, WorldRootController.ActiveControl 设成 ActiveControlStrategy.HideWhenNotTracking ,这样cube会在跟踪失败时隐藏。

在sparse spatial map上移动物体¶
可以对sparse spatial map执行 hit test 并移动cube到返回的点。
var viewPoint = new Vector2(touch.position.x / Screen.width, touch.position.y / Screen.height);
if (sparse && sparse.LocalizedMap)
{
var points = sparse.LocalizedMap.HitTest(viewPoint);
foreach (var point in points)
{
onSparse = true;
TouchControl.transform.position = sparse.LocalizedMap.transform.TransformPoint(point);
break;
}
}