Advanced API - Getting Started

The Advanced API can be accessed with the Tobii XR SDK if you have a Tobii Ocumen license.

By following this getting started guide, you will have a scene where spheres adjust to the size of your pupils, by adjusting the luminosity of the scene.

For a full overview of what the Advanced API contains, see the API Reference page.

The recorded participant has an eye condition making his left pupil not react properly to light changes.

Table of Contents


Compatibility

HMD COMPATIBLE
HTC VIVE Pro Eye No
Pico Neo 2 Eye Yes

Step 1: Set up your headset

Make sure you are up and running with your Pico Neo 2 Eye and have downloaded and imported the latest PicoVR Unity SDK and Tobii XR SDK.

See our Pico Neo 2 Eye Getting Started guide for more information.

Step 2: Get a license

The Advanced API requires a Tobii Ocumen license.

If you have a license file, put it in a Resources folder in your Unity project.

Make sure the license file is named TobiiOcumenLicense.bytes

Step 3: Set up your scene

  1. Create a new scene and add the Pvr_UnitySDK prefab, found in PicoMobileSDK > Pvr_UnitySDK > Prefabs.

  2. Remove the Main Camera game object from your scene.

  3. Enable the Eye Tracking option in the Pvr_UnitySdkEyeManager script which is attached to the Head of the Pvr_UnitySDK prefab.

  1. Create two spheres, name them LeftPupil and RightPupil

  2. Position the LeftPupil at (-4, 0, 15).

  1. Position the RightPupil at (4, 0, 15).
  1. Create a new material, name it PupilColor and drag it to both LeftPupil and RightPupil game objects.

Change the color of PupilColor to grey (R:100, G:100, B:100).

Step 4: Add the TobiiXR Initializer prefab to your scene

The prefab can be found in TobiiXR > Prefabs.

Step 5: Create AdjustToPupil script

Create a new script called AdjustToPupil and add it to both the LeftPupil and RightPupil game objects.

Add the following code:

using Tobii.XR;
using UnityEngine;

public class AdjustToPupil : MonoBehaviour
{
	public bool IsLeftPupil;

	void Awake()
	{
		transform.SetParent(Camera.main.transform, false);
	}

	void Update () 
	{
		// Fetch the latest pupil data.
		var latestData = TobiiXR.Advanced.LatestData;
		var isPupilValid = IsLeftPupil ? latestData.Left.PupilDiameterValid : latestData.Right.PupilDiameterValid;
		var pupilDiameter = IsLeftPupil ? latestData.Left.PupilDiameter : latestData.Right.PupilDiameter;

		// Scale the sphere according to the pupil diameter of the user.
		if (isPupilValid)
		{
			transform.localScale = Vector3.one * pupilDiameter;
		}
	}
}

Step 6: Tick the IsLeftPupil bool

Enable the IsLeftPupil bool for the LeftPupil game object.

Step 7: Create AdjustLuminosity script

Create a new game object, rename it LuminosityManager and then create and attach a script called AdjustLuminosity to it.

Add the following code:

using UnityEngine;

public class AdjustLuminosity : MonoBehaviour {

    private Camera[] _cameras;

    void Awake ()
    {
        _cameras = Camera.allCameras;

        // Set the cameras to use a solid color as background, and set it to black.
        foreach (var sceneCamera in _cameras)
        {
            sceneCamera.clearFlags = CameraClearFlags.SolidColor;
            sceneCamera.backgroundColor = Color.black;
        }
    }

    /// <summary>
    /// Updates the background color of the cameras, lerping between black and white.
    /// </summary>
    private void Update()
    {
        var speed = 0.5f;
        var sine = Mathf.Sin(Time.timeSinceLevelLoad * speed); // Generate value between -1 and +1 on a sine curve.
        var translation = sine + 0.5f; // Adjust that value to be between -0.5 to +1.5.
        var newColor = Mathf.Clamp(translation, 0, 1); // Clamp value between 0 and +1, will pause at both ends for missing .5f.

        foreach (var sceneCamera in _cameras)
        {
            sceneCamera.backgroundColor = new Color(newColor, newColor, newColor);
        }
    }
}

Step 8: Build & Run

Build the application and deploy it to your Pico Neo 2 Eye headset.