Demonstrate how to use the sparse SpatialMap uploaded into the database (e.g. created from SpatialMap_SparseSpatialMap sample).

  • Demonstrate how to localize sparse SpatialMap and put virtual objects onto SpatialMap


Server access information is required when using sparse spatial map, which can be get from SpatialMap page in EasyAR develop center. There are two ways to set this information in Unity.

One is global configuration, all scenes using global spatial map configuration will use this value. Select <EasyAR -> Change Global Spatial Map Service Config> in Unity menu and enter the information in Inspector get from develop center.

../../_images/image_62.png ../../_images/image_62_1.png

Another is local configuration in the scene, it is only valid to the current scene.


Map information is also required, which can be get from SpatialMap page in EasyAR develop center after create and upload from sample SpatialMap_SparseSpatialMap.


How to Use

Mark 1: Display system status and operation hint.

There will be point cloud displayed in the scene. The cube will be placed and moved on the cloud when drag. Two finger pinch will scale the cube.

How It Works

Localize sparse spatial map in the scene

Sparse spatial map in the sample runs in localize mode.

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


Use SparseSpatialMapWorkerFrameFilter.Localizer.startLocalization to start localization.


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.


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

Sparse spatial map events

Map events are used for custom operations, the sample use the events to output some information. You can delete them if they are not used, and you can use the events to handle your game logic.

Notice: load map (only the first time each map) will trigger a download in this sample. Statistical request count will be increased (more details on EasyAR website). Map cache is used after a successful download. Map cache will be cleared if SparseSpatialMapManager.clear is called or app uninstalled.

MapController.MapLoad += (map, status, error) =>
    GUIPopup.EnqueueMessage("Load map {name = " + map.Name + ", id = " + map.ID + "} into " + + Environment.NewLine +
        " => " + status + (string.IsNullOrEmpty(error) ? "" : " <" + error + ">"), status ? 3 : 5);

MapController.MapLocalized += () =>
    GUIPopup.EnqueueMessage("Localized map {name = " + MapController.MapInfo.Name + "}", 3);

MapController.MapStopLocalize += () =>
    GUIPopup.EnqueueMessage("Stopped localize map {name = " + MapController.MapInfo.Name + "}", 3);