MapBuilding_Sparse_Dense

Demonstrate how to build sparse SpatialMap and dense SpatialMap together

How to Use

../../_images/image_34.png
Mark 1: Display system status and operation hint.
Mark 2: Switch where the cube will be placed (on sparse cloud point or dense mesh).

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

How It Works

Use sparse spatial map and dense spatial map together

To use sparse spatial map and dense spatial map together, just put them under the same ARSession, and use VIOCameraDevice instead of VideoCameraDevice.

../../_images/image_s7_1.png

Build sparse spatial map in the scene

Sparse spatial map in the sample runs in build mode. You can reference MapLocalizing_Sparse 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_s7_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_s7_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)
    {
        ...
        TouchControl.transform.position = sparse.LocalizedMap.transform.TransformPoint(point);
        break;
    }
}

Move object on dense spatial map

Raycast against the dense mesh blocks and move the cube on it.

Ray ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo))
{
    ...
    TouchControl.transform.position = hitInfo.point;
};