#Hololens – Detect user hand interactions using #HoloToolkit (update!)

Hello!

During the last few months HoloToolkit has changed a lot. These changes make some of the examples that I have written as non-valid posts. In today’s post, I’ll quickly explain how to implement detection of hands with the current version of HoloToolkit.

We start with the basics with these steps

 

  1. Create a 3D project in Unity3D
  2. Configure project to support HoloLens projects
  3. Clean Scene elements
  4. Import HoloToolkit package
  5. Add
    1. HololensCamera
    2. SpatialMapping
    3. CursorWithFeedback
  6. Add Empty element, Managers
    1. Add existing scripts
      1. Gaze Managers
      2. Gaze Stabilizer
      3. Input Manager
  7. Add Empty element, HoloCollection
    1. Add 3D elements
      1. Cube
        1. Position, x:0 y:0 z:2
        2. Rotation, x:0 y:0 z:0
        3. Scale, x:0.3 y:0.3 z:0.3
      2. AnchorText (from HoloToolkit)
        1. Position, x:0 y:0.35 z:2
        2. Rotation, x:0 y:0 z:0
        3. Scale, x:0.3 y:0.3 z:0.3
  8. Into the Manager collection
    1. Add script Text Debug Manager (later on the post)
      1. Drag the Anchor Text (7.1.2) into the Anchor Debug Text Property

This is the process creating a basic Hololens project. Now let’s create a script that detects any of the user actions with his hands. This script will display these actions in the AnchorText which I have added to the collection of holograms in debug mode.

For this example, I will call the script “TextDebugManager.cs“. The same code is as follows

 

using HoloToolkit.Unity.InputModule;
using UnityEngine;

public class TextDebugManager : MonoBehaviour, IHoldHandler, IInputHandler
{

 public TextMesh AnchorDebugText;
 private string _debugTextHold = "";
 private string _debugTextInput = "";
 
 void Update()
 {
   UpdateText();
 }

 private void UpdateText()
 {
   if (AnchorDebugText != null)
     AnchorDebugText.text = string.Format(
       "Hold: {0}\nInput: {1}", _debugTextHold, _debugTextInput);
 }

 public void OnHoldStarted(HoldEventData eventData)
 {
   _debugTextHold = "OnHoldStarted";
 }

 public void OnHoldCompleted(HoldEventData eventData)
 {
   _debugTextHold = "OnHoldCompleted";
 }

 public void OnHoldCanceled(HoldEventData eventData)
 {
   _debugTextHold = "OnHoldCanceled";
 }

 public void OnInputUp(InputEventData eventData)
 {
   _debugTextInput = "OnInputUp";
 }

 public void OnInputDown(InputEventData eventData)
 {
   _debugTextInput = "OnInputDown";
 }
}

Within the class I implemented interfaces “IHoldHandle” and “IInputHandler“. Then be shown the operations be interfaces in the Update() of the script. In this way, we can implement a model of Debug PPP of Hololens in a quick way, and in this case, to capture the interactions of the user about the holograms.

Greetings @ TorontoEl Bruno

References

Advertisements

12 thoughts on “#Hololens – Detect user hand interactions using #HoloToolkit (update!)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s