Space Tracker

Related documentations
Maxst AR Scanner

Space Tracker imports 3D spatial models and maps which are created and saved through Maxst AR Scanner. Afterward, it augments 3D contents on the scanned environment.
After recognizing targets and obtaining initial pose from MAXST AR SDK, it uses Nreal SLAM for tracking.
Since Nreal SLAM of Space Tracker learns the environment around the targets, tracking is sustained even if the targets get out of the camera frame or have little features.

Make Space Tracker Scene
Set Map
Add / Replace Map
Start / Stop Tracker
Use Tracking Information

Make Space Tracker Scene

  1. Install MAXST AR SDK For Unity, MAXSTARSDK_FOR_NRSDK, and NRSDKForUnity_Release.

  2. Create a new scene.

  3. To build on mobile, please enter License Key in Assets > Resources > MaxstAR >Configuration in the Project window.

  4. Delete the Main Camera, then add the NRCameraRig and NRInput from the Assets > NRSDK > Prefabs, Assets > MaxstAR > Prefabs, and add a SpaceTrackable to the scene for each.

  5. Delete the Main Camera, then add Assets > NRSDK > Prefabs > NRCameraRig, NRInput, and Assets > NRSDK > Prefabs > SpaceTrackable to the scene.

  6. go to Assets > NRSDK > Prefabs > NRCameraRig, NRInput, Assets > MaxstAR > Prefabs > SpaceTrackable to your scene.

    Prefab SpacePrefab

  7. Create an empty object and add 'Assets > MaxstARSamples > Scripts > spaceTrackerSample' as a component.

    SpaceSample

  8. Place the files you uploaded from Maxst AR Scanner in Assets > StreamingAssets and drag the scan directory (the parent directory of the mmap) into SpaceTrackable's Inspector to set up the mmap. Then click the Load button to load the 3D spatial model.

    ※ If the map file is not placed under the StreamingAssets folder, the map file is not recognized.

    map_setting

  9. After loading the 3D space model, in Scene View and Game View, you can see the space scanned by Maxst AR Scanner on top of the scanned space.

    after_load

  10. Places the virtual object under SpaceTrackable in the Hierarchy View. In the Maxst SDK, maxst_cube is placed under by default.

  11. Use the 3D spatial model to place virtual content in the appropriate locations.

    arrangement

Set Map

By callingaddTrackerData() to register the map file and callingloadTrackerData(), Space can be tracked. To set a map, refer to the following code.

>SpaceTrackerSampleForNreal.cs

private void AddTrackerData()
{
    foreach (var trackable in spaceTrackablesMap)
    {
        if (trackable.Value.TrackerDataFileName.Length == 0)
        {
            continue;
        }

        if (trackable.Value.StorageType == StorageType.AbsolutePath)
        {
            TrackerManager.GetInstance().AddTrackerData(trackable.Value.TrackerDataFileName);
        }
        else
        {
            if (Application.platform == RuntimePlatform.Android)
            {
                TrackerManager.GetInstance().AddTrackerData(trackable.Value.TrackerDataFileName, true);
            }
            else
            {
                TrackerManager.GetInstance().AddTrackerData(Application.streamingAssetsPath + "/" + trackable.Value.TrackerDataFileName);
            }
        }
    }

    TrackerManager.GetInstance().LoadTrackerData();
}

Add / Replace Map

  1. Use Maxst AR Scanner to create maps and 3D file.
  2. Copy the transferred files to the desired path.
  3. Set up a map.
  4. If you have a previously registered map file, you can call TrackerManager.GetInstance().RemoveTrackerData() and then call AddTrackerData() and LoadTrackerData().
  5. Call trackableBehaviour.LoadObj() to load the 3D spatial model.

Start / Stop Tracker

TrackerManager.getInstance().isFusionSupported() This function checks whether or not your device supports Fusion. Return value is bool type. If true, it supports the device in use. If it is false, it does not support the device.
TrackerManager.getInstance().GetFusionTrackingState(); Pass the tracking status of the current Fusion.
The return value is an int of -1, which means that tracking isn't working properly, and 1 means that it's working properly.

After loading the map, refer to the following code to start / stop the tracker.

>SpaceTrackerSampleForNreal.cs

void Start()
{
    ...
    CameraDevice.GetInstance().SetARCoreTexture();
    TrackerManager.GetInstance().StartTracker(TrackerManager.TRACKER_TYPE_SPACE);
    TrackerManager.GetInstance().AddTrackerData("SpaceTarget/map_20230420.mmap", true);
    TrackerManager.GetInstance().LoadTrackerData();
    ...
}

void OnApplicationPause(bool pause)
{
    ...
    TrackerManager.GetInstance().StopTracker();
    ...
}

void OnDestroy()
{
    TrackerManager.GetInstance().StopTracker();
    TrackerManager.GetInstance().DestroyTracker();
    ...
}

Use Tracking Information

To use the Tracking information, refer to the following code.

>SpaceTrackerSampleForNreal.cs

void Update()
{
    ...
    TrackingState state = TrackerManager.GetInstance().UpdateTrackingState();
    TrackingResult trackingResult = state.GetTrackingResult(); 

    for (int i = 0; i < trackingResult.GetCount(); i++)
    {
        Trackable trackable = trackingResult.GetTrackable(i);
        spaceTrackablesMap[trackable.GetName()].OnTrackSuccess(trackable.GetId(), trackable.GetName(), trackable.GetNRealPose());
    }
}