SpatialMap_Sparse_ImageTarget

Demonstrate how to use sparse SpatialMap and image tracking together.

How to Use

../../_images/image_43.png
Mark 1: Display system status and operation hint.

How It Works

Use sparse spatial map and image tracking together

To use sparse spatial map and image tracking together, just put them under the same ARSession.

../../_images/image_s13_1.png

In addition, ARSession must can choose motion tracking feature and run on devices support motion tracking.

../../_images/image_s13_4.png

Build sparse spatial map in the scene

Sparse spatial map in the sample runs in build mode. You can reference SpatialMap_Sparse_Localizing for how to use sparse spatial map in localize mode.

To run sparse spatial map in build mode, a SparseSpatialMapController should exist with Source Type set to Map Builder, and Map Worker set to the SparseSpatialMapWorkerFrameFilter in the session.

../../_images/image_s13_2.png

Objects under world root

WorldRoot is designed to do these things,

  • Control show/hide of objects when tracking status change.

  • Move together against camera according to ARSession.CenterMode.

You can ignore WorldRoot If you can make sure all above is handled by yourself.

In this sample, WorldRootController.ActiveControl is set to ActiveControlStrategy.HideWhenNotTracking, so the cube will hide when tracking fails.

../../_images/image_s13_3.png

Move object on sparse spatial map

You can perform hit test on the sparse spatial map and move cube to the returned point.

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;
    }
}