ViveSoftware / ViveInputUtility-Unity

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

ViveRole -> BodyRole -> Foots #36

Open ziiCz opened 6 years ago

ziiCz commented 6 years ago

Hello!

I try to use the left foot and the right foot with Vive Trackers, but they are never assigned as foot. I use the BodyRole on them and assign the left and right foot on their GameObject.

This feature is operational or I forgot something?

Thank you in advance.

lawwong commented 6 years ago

Without bindings, BodyRole will only roughly mapping tracking devices according to their tracking position (related to hmd) whenever a controller or tracker is connected.

So either make sure your hmd and trackers are connected and in right position before game started playing, or call HTC.UnityPlugin.Vive.ViveRole.DefaultBodyRoleHandler.Refresh() manually to remapping BodyRole on demend.

But we recommended to use bindings anyway, is more convenience to setup tracking devices along with gears. Also see Binding Interface Release Note.

If you are using in product, you may not want to include our VIU style binding interface and binding config file, then you can design your own binding process for your user and apply those bindings manually by calling the following API:

HTC.UnityPlugin.Vive.ViveRole.GetMap<BodyRole>().BindDeviceToRole(string deviceSN, BodyRole role)
ziiCz commented 6 years ago

Yeah, I'm sure that my hmd and trackers are connected before game start.

I think the problem comes from the IsFoot() function from the BodyRole class. This function already returns false.

I don't want to use bindings. I need the configuration to be done automatically at startup.

This is why I want to use the BodyRole class without default bindings.

I have called the HTC.UnityPlugin.Vive.ViveRole.DefaultBodyRoleHandler.Refresh() function but there was no change.

lawwong commented 6 years ago

I see.

You can customize auto-mapping logic by implementing ViveRoleHandler\<EnumType> and replace the default handler by calling ViveRole.AssignMapHandler(). For Example:

using UnityEngine;
using HTC.UnityPlugin.Vive;

public class CustomBodyRoleHandler : ViveRole.MapHandler<BodyRole>
{
    // called when handler is assigned
    public override void OnInitialize() { RemapAll(); }
    // called when device connected or disconnected
    public override void OnConnectedDeviceChanged(uint deviceIndex, ETrackedDeviceClass deviceClass, string deviceSN, bool connected) { RemapAll(); }
    // called when binding changed (Ex. when ViveRole.GetMap<BodyRole>().BindRole called)
    public override void OnBindingChanged(MyEquipRole role, string deviceSN, bool bound) { RemapAll(); }
    // called when OpenVR TrackedDeviceRoleChanged event emitted
    public override void OnTrackedDeviceRoleChanged() { RemapAll(); }

    public void RemapAll()
    {
        // some auto mapping algorithm...
        // call protected function here to map/unmap relations
        // this.UnmappingAll() to unmap all relations
        // this.MappingRole(MyEquipRole role, uint deviceIndex) to map the role to the device
    }
}

public class BodyRoleHandlerReplacer : MonoBehaviour
{
    public readonly CustomBodyRoleHandler handler = new CustomBodyRoleHandler();

    public void Awake()
    {
        // Replacing DefaultBodyRoleHandler
        ViveRole.AssignMapHandler<BodyRole>(handler);
    }
}
lawwong commented 6 years ago

BTW, VIU only have roughly mapped BodyRole, may not work on certain cases. It will be very grateful if you share your BodyRoleHandler implementation to public.

ziiCz commented 6 years ago

We agree that the BodyRole does not work completely. No problem, if I find a good implementation I will share it. Thank you for your answers.