Demonstrate how to build sparse SpatialMap.
How to Use¶
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¶
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.
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);