Space Tracker

Related documentations
MAXSCAN

Space Tracker imports 3D spatial models and maps which are created and saved through MAXSCAN. Afterward, it augments 3D contents on the scanned environment.
After recognizing targets and obtaining initial pose from MAXST AR SDK, it uses ARCore/ARKit for tracking.
Since ARCore/ARKit 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 Unit.

  2. Create the new scene.

  3. Delete the default Main Camera and add Assets > MaxstAR > Prefabs >ARCamera, SpaceTrackable to your scene.

    prefab

    ※ If you build an application, you must add a License Key to ARCamera.

  4. Create an empty object and add 'Assets > MaxstARSamples > Scripts >SpaceTrackerSample' as a component. sample

  5. Place the files generated by MAXSCAN in Assets > StreamingAssets > MaxstAR, then drag the map file into SpaceTrackable's Inspector to set up the map file and 3D file. Press the Load button to load the 3D spatial model from the 3D file into Unity.

    ※ If the map file is not placed under the StreamingAssets folder, the map file is not recognized.
    ※ If you have run texturing in MAXSCAN, you will need to have the texture file and the mtl file in the same folder as the obj file to load a normal 3D spatial model.

    map_setting

  6. After loading the 3D spatial model, in Scene View and Game View, you can see the space scanned by MAXSCAN on top of the scanned space.

    after_load

  7. right-click in the Hierachy pane and select UI > Legacy > Text to create a Text and type in the phrase "Move Your Device." Then select Space Tracker Sample and drag the Text to add it to the Guide View in the Inspector window.

    guide_view

  8. Select the Space Tracker Sample and drag the ARCamera to add it to the AR Camera in the Inspector window.

    arcamera

  9. Select the Space Tracker Sample and drag the Asset > MaxstAR > OcclusionMaterial from the Project window to add it to the Occlusion Material in the Inspector window.

    occlusion

  10. Set Occlusion Culling by dragging the spatial model to Occlusion Objects.

    inspector

    • Occlusion Culling: Allows objects behind a space to be occluded. It uses mesh information to determine the order in which objects are visible, effectively implementing Occlusion Culling.
  11. Places the virtual object under SpaceTrackable in the Hierarchy View. In the Maxst SDK, maxst_cube is placed under by default.

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

Set Map

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

>SpaceTrackerSample.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);
            TrackerManager.GetInstance().LoadTrackerData();
        }
        else if (trackable.Value.StorageType == StorageType.StreamingAssets)
        {
            if (Application.platform == RuntimePlatform.Android)
            {
                StartCoroutine(MaxstARUtil.ExtractAssets(trackable.Value.TrackerDataFileName, (filePah) =>
                {
                    TrackerManager.GetInstance().AddTrackerData(filePah, false);
                    TrackerManager.GetInstance().LoadTrackerData();
                }));
            }
            else
            {
                TrackerManager.GetInstance().AddTrackerData(Application.streamingAssetsPath + "/" + trackable.Value.TrackerDataFileName);
                TrackerManager.GetInstance().LoadTrackerData();
            }
        }
    }

    TrackerManager.GetInstance().LoadTrackerData();
}

When calling addTrackerData(), you must pass the path to the map (mmap) in the parameters.


*Note* - Map Compatibility Starting with MAXSCAN 1.1.0 or later, the file format for mmaps has changed. mmaps created in MAXSCAN 1.1.0 or later are supported by AR SDK 6.1.x or later.
In AR SDK 6.1, you can load both maps generated by Maxscan 1.0 and maps generated by Maxscan 1.1 and later. To recognize multiple targets, you must use maps generated by MAXSCAN 1.1.0 or later.

Set Package

If you are using a multi-space map, packaging it in a mmpkg file will greatly improve map loading speed and recognition speed.
Create a mmpkg with MapPackager, call AddTrackerData() to register the package file, and call LoadTrackerData() to make the target object ready for tracking. See the following code for how to set up an space package.


>SpaceTrackerSample.cs

private IEnumerator AddTrackerData()
{
    string packagePath = ... // The file must exist in the streaming asset.

    yield return new WaitForEndOfFrame();

    if (Application.platform == RuntimePlatform.Android)
    {
        List<string> fileList = new List<string>();
        yield return StartCoroutine(MaxstARUtil.ExtractAssets(packagePath, fileList));
        TrackerManager.GetInstance().AddTrackerData(fileList[0], false);
    }
    else
    {
        TrackerManager.GetInstance().AddTrackerData(Application.streamingAssetsPath + "/" + packagePath);
    }

    TrackerManager.GetInstance().LoadTrackerData();
}

※ Space Package(mmpkg) is available from AR SDK 6.1.0.
※ Only mmaps created in MAXSCAN 1.1.0 or later can be packaged as mmpkg. ※ Only one mmpkg can be added to Object Tracker.

Add / Replace Map

  1. Use MAXSCAN 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.

To start / stop Tracker after loading the map, refer to the following code.

>SpaceTrackerSample.cs

void Start()
{
    ...
        CameraDevice.GetInstance().SetARCoreTexture();
        CameraDevice.GetInstance().SetFusionEnable();
        CameraDevice.GetInstance().Start();
        TrackerManager.GetInstance().StartTracker(TrackerManager.TRACKER_TYPE_SPACE);
        AddTrackerData();
    ...
}

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.

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

        if (!spaceTrackablesMap.ContainsKey(trackable.GetName()))
        {
            return;
        }

        spaceTrackablesMap[trackable.GetName()].OnTrackSuccess(trackable.GetId(), trackable.GetName(), trackable.GetPose(arCamera));
    }
}