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 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
Occlussion Culling
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. After uploading the scanned data from Maxst AR Scanner, download it from MyMenu > Space Tracker. Place the downloaded files 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

  6. After loading the 3D spatial model, in Scene View and Game View, you can see the space scanned by Maxst AR Scanneron 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. Places the virtual object under SpaceTrackable in the Hierarchy View.

    arrangement

  10. Disable the 3D spatial model.

  11. Build and run the app. ARKit/ARCore require an initial spatial recognition process. Move the camera until the "Move Your Device" text disappears. Then,point the camera at the target space and the virtual content will augment where you place it.

  12. SpaceTracker does not support testing in the Unity Editor environment.

Occlussion Culling

If you want to process Occlusion Culling without disabling the 3D spatial model, follow the steps below.

  1. Enable 3D spatial models.

  2. 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

  3. Drag the spatial model onto Occlusion Objects.

    inspector

    ※ Occlusion Culling: Objects that are behind a space can be processed so that they are obscured. By using mesh information to determine the order in which objects are visible, it effectively implements Occlusion Culling.

    ※ Occlusion Culling can cause performance degradation, so use with caution.

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 Maxst AR Scanner 1.1.0 or later, the file format for mmaps has changed. mmaps created in Maxst AR Scanner 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 Maxst AR Scanner 1.0 and maps generated by Maxst AR Scanner 1.1 and later. To recognize multiple targets, you must use maps generated by Maxst AR Scanner 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 Maxst AR Scanner 1.1.0 or later can be packaged as mmpkg. ※ Only one mmpkg can be added to Object Tracker.

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.

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));
    }
}