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 space model, in Scene View and Game View, you can see the space scanned by MAXSCAN on top of the scanned space.

    after_load

  7. Occlusion Culling is selected by default in the SpaceModel's Inspector. By enabling Occlusion Culling, you can handle objects behind the space being obscured.

    inspector

    ※ SpaceModel

    • When you load a 3D file into SpaceTrackable, a SpaceModel is automatically created under SpaceTrackable.

    • Occlusion Culling: Objects that are behind a space can be hidden. By using mesh information to determine the order in which objects are visible, we effectively implement occlusion culling.

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

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

    arrangement

Set Map

addTrackerData ()를 호출해서 맵 파일을 등록하고loadTrackerData()를 호출하면 공간을 Tracking 할 수 있는 상태가 됩니다. 맵을 설정하는 방법은 다음 코드를 참고하세요.

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

addTrackerData() 호출 시, 매개변수에는 맵(mmap)의 경로를 전달해 주어야 합니다.

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