Magic Leap (Unity on a Mac) by Example: Part 2

John Tucker
Coinmonks
2 min readJun 25, 2018

--

Interacting with hand (left and right) gestures through the Magic Leap API is particularly simple.

This article is part of the series starting with Magic Leap (Unity on a Mac) by Example: Part 1.

Update: Wrote this in Lumin SDK 0.14.0 earlier this week, but just upgraded to 0.15.0. While there were some breaking changes, the performance of the simulator is night and day better (pretty much usable now). Updated article with changes.

The full examples in this series are available to download.

Hand Tracking (previously known as Gestures)

This example demonstrates interacting with hands (left and right) with eight different gestures (aka, keyposes), e.g., point, fist, etc. Making one of the gestures with your left hand colors a respective square blue; right hand red and both hands magenta.

note: In the change between v0.14.0 and v.0.15.0, gestures got renamed to keyposes (didn’t fully change the all the variable names in the example).

note: This example, is a simplified version of an example provided by Magic Leap on this topic. In particular, this example has all the code in a single file and the canvas does not track the camera.

note: Another interesting thing about their example is that it uses code that is labeled CoreComponents, e.g., it uses two of them (HandTracking.cs and HeadposeCanvas.cs). At first, I thought to use these in my projects but after some thought, I realized that these are NOT a reliable API but really just example code.

Assets/src/hand_tracking/Gesture.cs

Observations:

  • Much like the previous example, we use MLHands.start and MLHands.stop in the Awake and OnDestroy methods; including disabling the script if MLHands.start fails.
  • One big change between v0.14.0 and v0.15.0 is that you have to enable the keyposes before using them; this is because adding keyposes makes it more difficult for the Magic Leap hardware to discern them.
  • In addition to reading the gesture, you get a confidence (0f to 1f) value; 1f being 100% confident.
  • The private variables, _lastLeftGesture and _lastRightGesture, are used to only trigger updates when the gestures change.
  • As before, private variable _first is used to initialize _lastLeftGesture and _lastRightGesture on the first update.

Next Steps

That is about it for gestures, we will move onto the plane detection API in the next article Magic Leap (Unity on a Mac) by Example: Part 3.

--

--

John Tucker
Coinmonks

Broad infrastructure, development, and soft-skill background