ValveSoftware / steamvr_unity_plugin

SteamVR Unity Plugin - Documentation at: https://valvesoftware.github.io/steamvr_unity_plugin/
BSD 3-Clause "New" or "Revised" License
1.04k stars 257 forks source link

Left Eye Position and Right Eye Position reported wrong when using XR Plugin #903

Open Shii2 opened 3 years ago

Shii2 commented 3 years ago

XR method device.TryGetFeatureValue(inputFeatureUsage, out position) returns wrong left and right eye position Y and Z coordinates when using XR OpenVR plugin. Tested with versions 2.7.1 and 2.7.2 No matter how I rotate and tilt headset Left and Right eye YZ coords always stays same and equal to Center Eye YZ coordinates. Issue does not appear when using Legacy VR system, only happens after switching project to XR plugin. Not sure if this is Unity issue or SteamVR plugin issue. Issue exists in Unity 2019.4.18f1, 2020.2.2f1 and 2021.1.0b4

Method code that can be used for testing:

    private bool TryGetEyeFeature(out Vector3 position, XRNode eye)
    {
        InputFeatureUsage<Vector3> inputFeatureUsage = CommonUsages.devicePosition;
        if (eye == XRNode.LeftEye)
            inputFeatureUsage = CommonUsages.leftEyePosition;
        else if (eye == XRNode.RightEye)
            inputFeatureUsage = CommonUsages.rightEyePosition;
        else if (eye == XRNode.CenterEye)
            inputFeatureUsage = CommonUsages.centerEyePosition;
        else if (eye == XRNode.Head)
            inputFeatureUsage = CommonUsages.devicePosition;

        InputDevice device = InputDevices.GetDeviceAtXRNode(XRNode.Head);
        if (device.isValid)
        {
            if (device.TryGetFeatureValue(inputFeatureUsage, out position))
                return true;
        }
        // This is the fail case
        position = Vector3.zero;
        return false;
    }

Attached two screenshots. First screenshot shows how values should look - this screenshot taken from project using Legacy VR system. Second screenshot shows what I get after switching to XR plugin. VRLegacyEyePosition XRPluginEyePosition

Shii2 commented 3 years ago

Issue still persists in SteamVR Plugin v2.7.3 and SteamVR 1.16.8 I contacted Unity about this bug and they answered that this is an issue in SteamVR Plugin or OpenVR XR plugin provided by SteamVR package. To reiterate, headset position tracked correctly, only left and right eye position reported wrong.

Tamulur commented 3 years ago

For now I'm using this workaround: after getting the position and rotation of the centerEye and the positions of the left and right eye, I do this:

float leftEyeDist = Vector3.Distance(playerEyeCenterXform.position, playerLeftEyeXform.position); float rightEyeDist = Vector3.Distance(playerEyeCenterXform.position, playerRightEyeXform.position);

playerLeftEyeXform.position = playerEyeCenterXform.position -leftEyeDist playerEyeCenterXform.right; playerRightEyeXform.position = playerEyeCenterXform.position +rightEyeDist playerEyeCenterXform.right;

Shii2 commented 3 years ago

Found how to properly fix this bug. Issue is in unity-xr-plugin. More info here: https://github.com/ValveSoftware/unity-xr-plugin/issues/86#issuecomment-930095636