Calling Eye Tracking Calibration

On this page:

 

As for now, glia provides a standalone application for doing eye calibration that has been written using WMR API. This standalone app needs to get the VR focus to work and this will cause your application to lose the focus (or in the worst-case scenario) close. 

Unity

For unity what we will need to do is lost the VR focus before calling the Eye Tracking Calibration app and then reenabling vr to get our app back to the focus.

public void Calibration()
{
    string omniPath = System.Environment.GetEnvironmentVariable("HP_OMNICEPT_INSTALL");
    UnityEngine.XR.Management.XRGeneralSettings.Instance.Manager.StopSubsystems();
    UnityEngine.XR.Management.XRGeneralSettings.Instance.Manager.DeinitializeLoader();
    using (Process eyeCalProcess = new Process())
    {
        eyeCalProcess.StartInfo.UseShellExecute = false;
        eyeCalProcess.StartInfo.FileName =  $"{omniPath}\\..\\..\\HP Omnicept\\HP Omnicept Eye Tracking Calibration\\ETCal\\Binaries\\Win64\\ETCal-Win64-Shipping.exe";
        eyeCalProcess.StartInfo.CreateNoWindow = true;
        eyeCalProcess.Start();
        eyeCalProcess.WaitForExit();
    }
    string text = File.ReadAllText($"C:\\Users\\{Environment.UserName}\\AppData\\Local\\ETCal\\Saved\\etcallog.log");
    bool ok = text.Contains("Tobii Eye Calibration finished successfully");
    UnityEngine.Debug.LogError(ok);
    UnityEngine.XR.Management.XRGeneralSettings.Instance.Manager.InitializeLoaderSync();
    UnityEngine.XR.Management.XRGeneralSettings.Instance.Manager.StartSubsystems();
}

 

Unreal

 

Before calling calibration you need to disable the current pawn and instantiate a desktop pawn to avoid unreal trying to get back to a VR view. In this example, we block unreal until we end calibration but other async approaches can be used as well. 

.h

// (c) Copyright 2021 HP Development Company, L.P.

#pragma once

#include "IXRTrackingSystem.h"
#include "StereoRendering.h"
#include "IHeadMountedDisplay.h"

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "EyeCal.generated.h"


UCLASS()
class VRTOGGLE_API UEyeCal: public UBlueprintFunctionLibrary
{
GENERATED_BODY()
    UFUNCTION(BlueprintCallable, Category = "Glia")
        static bool OmniceptEyeCalibration();
	
};

 

.cpp

// (c) Copyright 2021 HP Development Company, L.P.


#include "EyeCal.h"


bool UEyeCal::OmniceptEyeCalibration() {
    if (GEngine) {
        GEngine->XRSystem->GetStereoRenderingDevice()->EnableStereo(false);
        GEngine->XRSystem->GetHMDDevice()->EnableHMD(false);
    }

    FString eyePath = FGenericPlatformMisc::GetEnvironmentVariable(TEXT("HP_OMNICEPT_INSTALL"));
    eyePath = eyePath.Append(TEXT("\\..\\..\\HP Omnicept\\HP Omnicept Eye Tracking Calibration\\ETCal\\Binaries\\Win64\\ETCal-Win64-Shipping.exe"));
    FProcHandle handle = FPlatformProcess::CreateProc(*eyePath, nullptr, true, false, false, nullptr, 0, nullptr, nullptr);
    
    if (handle.IsValid())
    {
        FPlatformProcess::WaitForProc(handle);
        

        if (GEngine) {
            GEngine->XRSystem->GetStereoRenderingDevice()->EnableStereo(true);
            GEngine->XRSystem->GetHMDDevice()->EnableHMD(true);
        }
        
        FString fileContent = "before";
        FString userName = UKismetSystemLibrary::GetPlatformUserName();
        FString filePath = "C:\\Users\\";
        filePath = filePath.Append(userName);
        filePath = filePath.Append("\\AppData\\Local\\ETCal\\Saved\\etcallog.log");

        FFileHelper::LoadFileToString(fileContent, *filePath);

        return fileContent.Contains("Tobii Eye Calibration finished successfully");
    }

    return false;
}