SpatialMap_Sparse_Dense_Building¶
Demonstrate how to build sparse SpatialMap and dense SpatialMap together
Reference: Motion Tracking and EasyAR Features.
How to Use¶
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.
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)
{
...
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;
};