Space Tracker iOS Tutorial

1. Overview
2. iOS Development
2.1 Create Instants
2.2 Start / Stop Tracker
2.3 Use Tracking Information
2.4 Set Map
2.5 Add / Replace Map
3. References
3.1 API Reference
3.2 Sample


1. Overview

Start developing MAXST ARSDKSpace Tracker on iOS Platform. Refer to Space Tracker Introduction for detailed information.

Generate 3D Mapfile of the target for Space Tracker via MAXSCAN.
The Space Tracker loads the map file and renders 3D space on it.

The Space Tracker loads the map file and renders 3D space on it.
After target recognition and initial poses are acquired through the MAXST SDK, use AR Kit for tracking.

Prerequisites
Space Tracker Introduction
MAXSCAN
Tracker Coordinate System

2. iOS Development

Start developing on xCode using Swift. Refer to Requirements & Supports to find out which devices are supported.

ARSDK has to properly integrate on iOS UIViewController. Refer to Life Cycle documents for detail.


2.1 Create Instants

SpaceTrackerViewController.swift

var trackingManager:MasTrackerManager = MasTrackerManager()

2.2 Start / Stop Tracker

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

trackingManager.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 the tracker after loading the map, refer to the following code.

SpaceTrackerViewController.swift

func startEngine() {
     ...

    if(trackingManager.isFusionSupported()) {
        trackingManager.start(.TRACKER_TYPE_SPACE)
        let spaceTrackerMapPath:String = Bundle.main.path(forResource: "space_map", ofType: "mmap", inDirectory: "data/SDKSample")!
        trackingManager.addTrackerData(spaceTrackerMapPath)
        trackingManager.loadTrackerData()
    }
}

@objc func resumeAR()
{
     ...
     trackingManager.start(.TRACKER_TYPE_SPACE)
}

@objc func pauseAR()
{
     trackingManager.stopTracker()
     ...
}

When calling addTrackerData(), you must pass the path to the mmap in the parameters.
Space_name is the filename of the mmap.


2.3 Use Tracking Information

You can use 3D mesh processing software (such as MeshLab) to load a 3D spatial model as a 3D file(.obj) to get the desired vertices.

SpacePosition

Using the found vertices and the setTranslate() function, you can augment the object to the desired location.

To use the tracking information, look at the following code.

SpaceTrackerViewController.swift

func draw(in view: MTKView) {
    ...
    let trackingState:MasTrackingState = trackingManager.updateTrackingState()
    let result:MasTrackingResult = trackingState.getTrackingResult()
    
    let backgroundImage:MasTrackedImage = trackingState.getImage()
    var backgroundProjectionMatrix:matrix_float4x4 = cameraDevice.getBackgroundPlaneProjectionMatrix()
    
    let projectionMatrix:matrix_float4x4 = cameraDevice.getProjectionMatrix()
    
    if let cameraQuad = backgroundCameraQuad {
        cameraQuad.setProjectionMatrix(projectionMatrix: backgroundProjectionMatrix)
        cameraQuad.draw(commandEncoder: commandEncoder, image: backgroundImage)
    }
    
    let trackingCount:Int32 = result.getCount()
    
    for i in stride(from: 0, to: trackingCount, by: 1) {
        let trackable:MasTrackable = result.getTrackable(i)
        let poseMatrix:matrix_float4x4 = trackable.getPose()
        
        textureCube.setProjectionMatrix(projectionMatrix: projectionMatrix)
        textureCube.setPoseMatrix(poseMatrix: poseMatrix)
        textureCube.setTranslation(x: 0.0, y: 0.0, z: -0.15)
        textureCube.setScale(x: 0.3, y: 0.3, z: 0.3)
        textureCube.draw(commandEncoder: commandEncoder)
    }
    ...
}

2.4 Set Map

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

SpaceTrackerViewController.swift

func startEngin() {
    ...
    trackingManager.addTrackerData(spaceTrackerMapPath)
    trackingManager.loadTrackerData()
}

2.5 Add / Replace Map

  1. Create a map file refer to MAXSCAN.

  2. Copy the received map file to the desired path.

  3. Set a map.

  4. If you have an existing map file, call function 'addTrackerData' and function 'loadTrackerData' after calling trackingManager.removeTrackerData()


3. References

These are additional references to developSpace Tracker


3.1 API Reference

Following documents explain classes and functions used to run Space tracker.

MaxstAR Class

TrackerManager Class

CameraDevice Class


3.2 Sample

For information regarding sample build and run of Space Tracker, refer to Sample

SpaceTrackerViewController.swift