Search Unity

How to use Navigation gesture via INavigationHandler, HoloToolkit ?

Discussion in 'VR' started by cgmagic, Dec 14, 2016.

  1. cgmagic

    cgmagic

    Joined:
    Oct 5, 2013
    Posts:
    12
    Trying to use https://github.com/Microsoft/HoloToolkit-Unity

    got Gazing working by using the IFocusable, Having problem with implementing INavigationHandler

    basically trying to achieve Navigation gesture, like: https://developer.microsoft.com/en-us/windows/holographic/holograms_211, but using the holoToolkit instead.

    How do I access, NavigationPosition.x in GesturesInput ?

    using UnityEngine;
    using HoloToolkit.Unity.InputModule;

    public class GestureAction : MonoBehaviour, INavigationHandler
    {

    public float RotationSensitivity = 10.0f;
    private Vector3 manipulationPreviousPosition;
    private float rotationFactor;
    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }

    private void PerformRotation()
    {
    // Trying to access NagivgationPosition.x but error !
    rotationFactor = GesturesInput.Instance.NavigationPosition.x* RotationSensitivity;
    transform.Rotate(new Vector3(0, -1 * rotationFactor, 0));
    }

    public void OnNavigationUpdated(NavigationEventData eventData)
    {
    PerformRotation();
    }

    public void OnNavigationStarted(NavigationEventData eventData)
    {
    Debug.Log("Hi");
    }

    public void OnNavigationCompleted(NavigationEventData eventData)
    {
    }

    public void OnNavigationCanceled(NavigationEventData eventData)
    {
    }

    }
     

    Attached Files:

    Last edited: Dec 14, 2016
  2. cgmagic

    cgmagic

    Joined:
    Oct 5, 2013
    Posts:
    12
    got it working at the end.

    public void OnNavigationUpdated(NavigationEventData eventData)
    {
    if (LogGesturesUpdateEvents)
    {
    rotationFactor = eventData.CumulativeDelta.x * RotationSensitivity;
    // 2.c: transform.Rotate along the Y axis using rotationFactor.
    transform.Rotate(new Vector3(0, -1 * rotationFactor, 0));
    }
    }
     
  3. lycheeyy

    lycheeyy

    Joined:
    Nov 14, 2016
    Posts:
    4
    Hello,I‘m very new in Unity and Hololens.
    A very simple and basic question: how to use this code? Do I need to create a new C# script in the inspector of my object that I want to rotate? Could you please help me with how to make the object rotate(Navigation),move(Manipulation),and explode the part of the object(Model Expansion). I just want my object has the same effect like in the academy tutorial210,211.
    Thanks a lot!
     
  4. cgmagic

    cgmagic

    Joined:
    Oct 5, 2013
    Posts:
    12
    Yes, you need to make a new script C#, and paste the code above into it. assign the script to the gameobject, it should work.
     
  5. Peter-Bickhofe

    Peter-Bickhofe

    Joined:
    Aug 31, 2014
    Posts:
    8
    Can i test this directly inside the unity playmode or do i have to build it to the device?
    Thx, Peter
     
  6. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    You can test it in play mode if you are using simulation in the editor under the emulation tab.
     
  7. pranavgadamsetty

    pranavgadamsetty

    Joined:
    Feb 16, 2017
    Posts:
    9
    @cgmagic , thanks for that solution. you made everything easier for me now


    Pranav
     
  8. StephenHodgson-Valorem

    StephenHodgson-Valorem

    Joined:
    Mar 8, 2017
    Posts:
    148
    Should work in the Editor as well without simulation nor emulation
     
  9. jvhgamer

    jvhgamer

    Joined:
    Jun 27, 2017
    Posts:
    36
    Hi cgmagic, firstly thanks for posting your solution.

    I'm attempting to create the most basic emulation of what you did. I've a blank project. Added a camera and configured it to work with the HoloLens. I then added a cube (object I'm testing rotation on), and a cursor (to detect when my hand is actually on the object). I then went to Window -> Holographic Emulation and set the Emulation Mode to "Simulate in Editor".

    Utilizing my cursor I can detect when I'm on the cube, however I can't seem to click&hold and move left/right to rotate the object.

    Hopefully I'm being descriptive enough about what I'm trying to do! Anyone, please any help is greatly appreciated.
    Fyi, I'm not sure if I'm just missing a script, or if there is something fundamentally not working.

    Oh, lastly, I'm using your version of GestureAction.cs. I don't have any other scripts, aside from my cursor script.

    EDIT: Forgot to mention as well that I had to comment out the control structure, if(LogGesturesUpdateEvents) as this doesn't exist for me.

    EDIT2: I noticed this is from the InputTest.cs script. I added that as well as GesturesInput.cs - still nothing..

    EDIT3: Still needing to comment out the LogGestures as it doesn't recognize it.

    Any possible way you could create a minimal project with only the needed scripts, a camera, an object to rotate, and an empty gameobject for any manager scripts (if needed) so that I can get a grasp on what I'm doing, it'd be absolutely amazing. If that's asking too much, which I completely understand, please would you provide any other scripts you necessary to get the rotation operational? Thanks!
     
    Last edited: Jul 17, 2017
  10. jvhgamer

    jvhgamer

    Joined:
    Jun 27, 2017
    Posts:
    36
    Anyone else know the necessary scripts to get cgmagic's solution working?
     
  11. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    221
  12. jvhgamer

    jvhgamer

    Joined:
    Jun 27, 2017
    Posts:
    36
    H̶o̶w̶ ̶i̶s̶ ̶a̶ ̶r̶e̶f̶e̶r̶e̶n̶c̶e̶ ̶t̶o̶ ̶t̶h̶e̶ ̶r̶e̶p̶o̶ ̶t̶h̶e̶ ̶b̶e̶s̶t̶ ̶p̶o̶s̶s̶i̶b̶l̶e̶ ̶p̶l̶a̶c̶e̶ ̶t̶o̶ ̶l̶o̶o̶k̶ ̶h̶a̶h̶a̶

    I'll see myself to the door
     
  13. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    221
    That's just where I tend to point people who ask about HoloToolkit here. I guess most people just look through issues or post a new one, or go to the Microsoft forums to ask around there.
     
  14. jvhgamer

    jvhgamer

    Joined:
    Jun 27, 2017
    Posts:
    36
    Haha the striketrough was meant to imply I bit my own tongue. Didn't see that it had an issues section to post on. Hopefully they are okay with questions not just bug issues
     
  15. jvhgamer

    jvhgamer

    Joined:
    Jun 27, 2017
    Posts:
    36
    Ok, got it working! Unfortunately the Tap and Hold gesture to enable the Navigation Handler only works for me in the Hololens. Anyone know how to get this working in the Editor??
     
  16. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    221
    Does holding the A button on a controller during simulation not work?
     
  17. jvhgamer

    jvhgamer

    Joined:
    Jun 27, 2017
    Posts:
    36
    It does not :(
     
  18. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    221
    Sorry, someone here is telling me I'm remembering button mapping for simulation horrendously wrong. Try right trigger?
     
  19. jvhgamer

    jvhgamer

    Joined:
    Jun 27, 2017
    Posts:
    36
    I'm sorry, maybe I misspoke before - I'm trying to get the navigation gesture to work in the Unity Editor. I'm using a mouse and a keyboard.
     
  20. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    221
    You need a controller for interacting in simulation to work right now.
     
  21. jvhgamer

    jvhgamer

    Joined:
    Jun 27, 2017
    Posts:
    36
    Hmmm. Interacting as in just navigation gestures? I can simulate air taps with left/right hand using the holo tool kit
     
  22. unity_andrewc

    unity_andrewc

    Unity Technologies

    Joined:
    Dec 14, 2015
    Posts:
    221
    Oh, I unfortunately haven't played around with the HoloToolkit much, so I don't know what additional functionality they might have for simulation. All I know is that for now, the out-of-box Unity support for simulation requires a controller.
     
  23. harymulyadi

    harymulyadi

    Joined:
    Sep 24, 2013
    Posts:
    1
    hey, do you already know how to Navigate in Unity Editor ? (what keys to be pressed on the keyboard/mouse)
    I need it and want to know that anyway..

    Thanks
     
  24. jvhgamer

    jvhgamer

    Joined:
    Jun 27, 2017
    Posts:
    36
    This was sometime ago, I can't say for sure. I can however provide my Navigation code. You'll need the HoloToolkit imported into your project and this script attached to the object (or parent) of the object you want to enact tap and hold gestures on.

    Code (CSharp):
    1. using UnityEngine;
    2. using HoloToolkit.Unity.InputModule;
    3.  
    4. public class NavigationTest : MonoBehaviour, INavigationHandler
    5. {
    6.     [Tooltip("Rotation max speed controls amount of rotation.")]
    7.     public float RotationSensitivity = 2.0f;
    8.  
    9.     private float rotationFactorX, rotationFactorY;
    10.  
    11.     public void OnNavigationStarted(NavigationEventData eventData)
    12.     {
    13.         Debug.Log("Navigation is started");
    14.  
    15.         // On Navigation started, clear the stack and push the object being 'Navigated' onto the stack
    16.         InputManager.Instance.ClearModalInputStack();
    17.  
    18.         InputManager.Instance.PushModalInputHandler(gameObject);
    19.     }
    20.     public void OnNavigationUpdated(NavigationEventData eventData)
    21.     {
    22.         rotationFactorX = eventData.CumulativeDelta.x * RotationSensitivity;
    23.  
    24.         rotationFactorY = eventData.CumulativeDelta.y * RotationSensitivity;
    25.  
    26.         //  Rotate by using the tap and hold gesture
    27.         //  Control structure to allow movement along only one axis at a time
    28.         if (System.Math.Abs(eventData.CumulativeDelta.x) > System.Math.Abs(eventData.CumulativeDelta.y))
    29.         {
    30.             /*  Moving your hand left or right along a horizontal plane
    31.                 to manipulate transform.Rotate along the Y axis */
    32.             transform.Rotate(new Vector3(0, -1 * rotationFactorX, 0));
    33.         }
    34.         else
    35.         {
    36.             /*  Moving your hand up or down along a vertical plane
    37.                 to manipulate transform.Rotate along the Z axis */
    38.             transform.Rotate(new Vector3(-1 * rotationFactorY, 0, 0));
    39.             //  If this control structure doesnt work, try setting the other value to zero instead
    40.         }
    41.  
    42.         Debug.Log("event X: " + eventData.CumulativeDelta.x);
    43.         Debug.Log("event Y: " + eventData.CumulativeDelta.y);
    44.     }
    45.     public void OnNavigationCompleted(NavigationEventData eventData)
    46.     {
    47.         Debug.Log("Navigation is completed");
    48.  
    49.         //  On Navigation completed or canceled, pop the object off the stack.
    50.         InputManager.Instance.PopModalInputHandler();
    51.  
    52.         /*  If the users gaze comes off the object, the rotation stops immediately
    53.             until the users gaze returns to the object. Utilizing the stack,
    54.             we can prevent this behavior and allow the rotation to continue even
    55.             when the users gaze comes off the object    */
    56.     }
    57.     public void OnNavigationCanceled(NavigationEventData eventData)
    58.     {
    59.         Debug.Log("Navigation is canceled");
    60.     }
    61. }