How-To: Draw in 3D space with Leap Motion + HTC Vive + Unity 5.3
Difficulty: novice, basic Unity knowledge
Duration: 10–15 minutes
This how-to will walk through the steps to get the PinchDrawDemo from latest Leap Motion release working with the HTC Vive in Unity 5.3. The PinchDrawDemo lets you draw in 3D space by making a pinch gesture touching your index and thumb with either hand. This functionality won’t work out of the box because Unity 5.3 doesn’t have native support for the Vive. Just a little tweaking is necessary :)
Note: We will not integrate the controllers for the HTC Vive.
What we need —
HTC Vive
Leap Motion Controller (ideally mounted on the Vive)
Unity 5.3.x — we built on latest stable version, didn’t want to use 5.4 Beta
Clean new Unity project
SteamVR — plugin from asset store
Leap Motion Orion 4.1 (Beta) — download and include in project https://developer.leapmotion.com/unity
Leap Motion Detection Examples v.1.0.1 — download and include in project https://developer.leapmotion.com/unity
Project Settings —
Edit > Project Settings > Player > make sure Virtual Reality Support is UNchecked
Tweaking the Demo Scene —
- Open the demo scene in Unity: In your new Unity project, open the PinchDrawDemo scene (LeapMotionModules > DetectionExamples > Scenes > PinchDrawDemo). We need to replace a camera and add a couple of scripts from the SteamVR library in order to get this scene working with the HTC Vive.
- Replace the camera: Locate the CameraRig prefab in SteamVR > Prefabs. Drag the CameraRig into the PinchDrawDemo Scene to view its children and expand it; find the Camera (eye) child under the Camera (head). In the Inspector, right click or use the settings menu on the Camera component to ‘Copy Component’.
Expand the LMHeadMountedRig in the Hierarchy and select the CenterEyeAnchor. Locate the camera component on the CenterEyeAnchor in the Inspector. Right click or use the settings menu on the camera to ‘Paste Component Values’.
Delete the CameraRig from the Scene.
- Add the scripts: On the CenterEyeAnchor, we need to add two scripts. Click ‘Add Component’ in the Inspector and search/select ‘SteamVR_Camera’ and ‘SteamVR_Camera Flip’. The CenterEyeAnchor should now have the following components:
Play the scene, and pinch your index and thumb together on either hand to start drawing in 3D space.
Allie Quintano is a developer at ThoughtWorks NYC working on enterprise VR applications.