Skip to main content
Version: Next

Implementing a Custom PoseTracker

VLSDK natively supports ARFoundation and ARDataset. However, if the platform does not support ARFoundation or you want to test using a method other than ARDataset, you can create and use your own PoseTracker.

Basic Structure

Create a class that inherits from ARCeye.PoseTracker in the desired location within your project. The created class should have the following structure:

using ARCeye;

public class MyPoseTracker : PoseTracker
{
// (Optional)
public override void OnCreate(Config config)
{
// Event called when the PoseTracker is created. You can modify the PoseTracker's settings by accessing the config.
}

// (Optional)
public override void RegisterFrameLoop()
{
// Event to register the loop event.
// If there is a loop that is called from within the module, such as the frameReceived event called by ARCameraManager in ARFoundation, override this method to register the loop event.
// If there is no module that calls the loop, you don't need to implement RegisterFrameLoop directly, and VLSDK's FrameLoopRunner will run its own loop.
// Executed when VLSDKManager's StartSession() is called.
}

// (Optional)
public override void UnregisterFrameLoop()
{
// Event to unregister the loop event. Executed when VLSDKManager's StopSession() is called.
}

// (Optional)
// Method to set the execution interval of FrameLoopRunner.
protected override float GetTargetFrameRate() => 0.1f;

// Method to create an ARFrame. Implement it according to your specific requirements.
public override ARFrame CreateARFrame()
{
ARFrame frame = new ARFrame();

/* ... */

return frame;
}
}

Loop Event

The Loop Event is a method executed every frame, similar to Unity's lifecycle event Update(). You must call the UpdateFrame(ARFrame) method using an ARFrame instance in the Loop Event. If the AR framework provides a loop event, you can register it as follows:

When the AR framework provides a loop event
using ARCeye;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;

public class MyPoseTracker : PoseTracker
{
// Example: In the case of ARFoundation.
private ARCameraManager m_CameraManager;
private ARCameraFrameEventArgs m_LastFrameEventArgs;

public override void OnCreate(Config config)
{
m_CameraManager = GameObject.FindObjectOfType<ARCameraManager>();
}

public override void RegisterFrameLoop()
{
m_CameraManager.frameReceived += OnCameraFrameReceived;
}

public override void UnregisterFrameLoop()
{
m_CameraManager.frameReceived -= OnCameraFrameReceived;
}

private void OnCameraFrameReceived(ARCameraFrameEventArgs eventArgs)
{
// !!! (Required) Call OnFrameLoop at the end of Loop Event. !!!
m_LastFrameEventArgs = eventArgs;
OnFrameLoop();
}

protected override ARFrame CreateARFrame()
{
return CreateARFrameFromEventArgs(m_LastFrameEventArgs);
}

public ARFrame CreateARFrameFromEventArgs(ARCameraFrameEventArgs eventArgs)
{
ARFrame frame = new ARFrame();

/* ...Create ARFrame using ARCameraFrameEventArgs... */

return frame;
}
}

For cases where there is no automatic event loop provided by ARFoundation or ARDataset, the FrameLoopRunner class is available to easily register and unregister Loop Events. You can use it as follows:

When the AR framework does not provide a loop event
using ARCeye;

public class MyPoseTracker : PoseTracker
{
public ARFrame CreateARFrame()
{
ARFrame frame = new ARFrame();

/* ...Create ARFrame every frame... */

return frame;
}
}