ViveSoftware / ViveInputUtility-Unity

A toolkit that helps developing/prototyping VR apps.
http://u3d.as/uF7
Other
357 stars 81 forks source link

How to identify VR Hardware Make when Role binding in BodyRoles.cs #38

Open wirelessdreamer opened 6 years ago

wirelessdreamer commented 6 years ago

I'm borrowing a rift from a friend to make some software updates, the 1st issue I ran into when I started testing, is the controller angle is vastly different of a rift controller, compared to a vive. I've already created new objects to bind them to, but on rift controllers I want to on device init,bind them to the other objects in BodyRoles.cs I'm just not sure what variable to check for me to know if they should be bound to another device.

lawwong commented 6 years ago

The controller rotation is get from UnityEngine.XR, VIU doesn't change it. But OpenVR+OculusTouch does "correct" them. (Though I don't think there is a "correct" controller pose) Any suggestion about this issue? What first come into my mind is adding a boolean option under OculusSupport like "Align controller rotation with VIVE"? What do you think?

And for identifying hardware, VRModule.GetDeviceState(i).deviceModel reveals the device model known by VIU.

    public enum VRModuleDeviceModel
    {
        Unknown,
        ViveHMD,
        ViveController,
        ViveTracker,
        ViveBaseStation,
        OculusHMD,
        OculusTouchLeft,
        OculusTouchRight,
        OculusSensor,
        KnucklesLeft,
        KnucklesRight,
        DaydreamHMD,
        DaydreamController,
        ViveFocusHMD,
        ViveFocusFinch,
    }
wirelessdreamer commented 6 years ago

I'm more trying to find out, is this an rift controller or vive controller. I'm not having any trouble is device orientation. Full trigger press also doesn't seem to be reading from the rift. so what you posted should be all I need. Thanks again

wirelessdreamer commented 6 years ago

NullReferenceException: Object reference not set to an instance of an object

This is how I tried to do the checks, Based on the errors I saw I think its not the right way:

Debug.Log("Hardware model detected: " + VRModule.GetDeviceState(0).deviceModel);

        // right most device as right hand
        if (VRModule.GetDeviceState(0).deviceModel == VRModuleDeviceModel.OculusHMD)
        {
            MappingRoleIfUnbound(BodyRole.RiftRightHandGun, m_sortedDevices[0]);
        }
        else
        {
            MappingRoleIfUnbound(BodyRole.RightHandGun, m_sortedDevices[0]);
        }
        if (m_sortedDevices.Count == 1) { return; }

        // left most device as left hand
        if (VRModule.GetDeviceState(0).deviceModel == VRModuleDeviceModel.OculusHMD)
        {
            MappingRoleIfUnbound(BodyRole.RiftLeftHandGun, m_sortedDevices[index]);
        }
        else
        {
            MappingRoleIfUnbound(BodyRole.LeftHandGun, m_sortedDevices[index]);

        }
        if (m_sortedDevices.Count == 2) { return; }

        // middle one as hip
        MappingRoleIfUnbound(BodyRole.SmallOfBack, m_sortedDevices[index / 2]);
wirelessdreamer commented 5 years ago

In the previous comment the Null reference Exception is because deviceModel doesn't get set until after we're doing default role setup in the role binding modules. What is the right way to do this check when initiall setting up controllers so when we haven't explicitly mapped controllers to have them default to a per platform controller binding.

The problem i'm solving here is that the controller grip angles for each controller platform are different, so a different controller is created for each platform, and if we default all controllers to the vive controller default we have set up, the angle of the controller is off on rift and wrm controllers.

wirelessdreamer commented 5 years ago

I no longer reproduce the previous error, Devices are being detected properly on init.

The issue i'm seeing now with this section of code:

if(VRModule.GetDeviceState(0).deviceModel == VRModuleDeviceModel.OculusHMD) { Debug.Log("We see a rift"); MappingRoleIfUnbound(BodyRole.RiftRightHandGun, m_sortedDevices[0]); } else { Debug.Log("Not Rift"); MappingRoleIfUnbound(BodyRole.RightHandGun, m_sortedDevices[0]); }

when i programatically set the device role on init, the rotation set this way, as opposed to with the binding ingerface is off by about 5 degrees. I'm not sure what could be causing it.