Setting up a project in Unity 3D

Setting up a project in Unity 3D


The Leap Motion asset package includes in plugin files for using the Leap Motion device on Windows and Mac computers. This package includes Hand prefabs, scripts, and demo scenes to help you develop Leap Motion apps quickly.
Note: As of Unity 5.0, both the Pro and Personal versions of Unity support plugins. You no longer need to use a different asset package or different setup for the “free” version of Unity.
Get the Leap Motion asset package from: https://developer.leapmotion.com/downloads/unity.

Create a project

First, create a new Unity project in the usual way, i.e.:
  1. Open the Unity editor.
  2. Select File > New Project...
  3. Choose a name and save location.
  4. Click Create Project.
Then, import the Leap Motion asset package into the project:
  1. Select the Unity Assets > Import Package > Custom Package menu command.
  2. Locate the downloaded asset package and click Open.
    The assets are imported into your project.
If you are importing the assets into a project that already contains Leap Motion assets, it is recommended that you delete the old assets first (make a backup of your project). The Unity import process only adds new files and overwrites changed files. It does not remove obsolete files (and sometimes creates duplicates of existing files instead of overwriting them).

Adding Hands to a VR Scene

The LMHeadMountedRig must replace any existing camera rigs in your scene.
Place the LMHeadMountedRig prefab at the position of the users’s initial viewpoint in the scene. The hands in the scene are positioned at the same position as your real hands relative to the real Leap Motion device.
To add hands to a scene:
  1. In the Project panel, locate the LMHeadMountedRig prefab in Assets/LeapMotion/Prefabs
  2. Drag the LMHeadMountedRig prefab into the Scene view.
  3. Set the transform position to the desired location.
  4. Drag your desired Hand prefabs to the LeapHandController object within LMHeadMountedRig in the hierarchy view as a child objects. You should have separate right and left instances of the prefabs for both the graphics models and the physics models – 4 in all.
  5. Drag the instances of the hand prefab from the hierarchy view to the corresponding slots in the Hand Pool object under LeapHandController.
  6. Play the scene.
    You should see hands appear in the Game view when you put your hands over the Leap Motion device. If you don’t see hands, open the Visualizer from the Leap Motion control panel to make sure your Leap Motion device is connected and sending out tracking data. If the Unity hands are just out of view, you can pause the game and use the Scene view to locate them.
Note: To view a VR scene comfortably on a desktop monitor (i.e. when you have no HMD connected), temporarily change the Leap VR Camera Control object’s Order Type property to LEFT or RIGHT.
To enable passthrough images, enable the LeapImageRetreiver script on the CenterEyeAnchor GameObject and enable the QuadBackground GameObject under LeapHandController.

Adding Hands to a Scene

Place the LeapHandController prefab below the point at which you want the hands to appear. The hands in the scene are positioned at the same position as your real hands relative to the real Leap Motion device. You can change the Hand Movement Scale setting to allow the hands to move a within a larger volume.
To add hands to a scene:
  1. In the Project panel, locate the LeapHandController prefab in Assets/LeapMotion/Prefabs
  2. Drag the LeapHandController prefab into the Scene view.
  3. Set the transform position to the desired location.
    To see hands, the LeapHandController must be within the field of view of the camera.
  4. Drag your desired Hand prefabs to the LeapHandController in the hierarchy view as child objects. You should have separate right and left instances of the prefabs for both the graphics models and the physics models – 4 in all.
  5. Drag the instances of the hand prefab from the hierarchy view to the corresponding slots in the Hand Pool object under LeapHandController.
    Note: The CapsuleHand prefabs are designed for 1:1 scale only.
  6. Play the scene.
    You should see hands appear in the Game view when you put your hands over the Leap Motion device. If you don’t see hands, open the Visualizer from the Leap Motion control panel to make sure your Leap Motion device is connected and sending out tracking data. If the Unity hands are just out of view, you can pause the game and use the Scene view to locate them.

Accessing the Leap Motion API directly

In addition to the prefabs and scripts included in the asset package, you can write your own scripts to access tracking data from the Leap Motion API. The Leap Motion classes are defined in the Leap namespace. A basic MonoBehavior class that accesses the Leap Motion API will look something like the following (this script moves the object to which it is attached to just underneath the palm of the hand):
using UnityEngine;
using System.Collections.Generic;
using Leap;

public class LeapBehavior : MonoBehaviour {
    LeapProvider provider;

    void Start ()
    {
        provider = FindObjectOfType<LeapProvider>() as LeapProvider;
    }

    void Update ()
    {
        Frame frame = provider.CurrentFrame;
        foreach (Hand hand in frame.Hands)
        {
          if (hand.IsLeft)
          {
              transform.position = hand.PalmPosition.ToVector3() +
                                   hand.PalmNormal.ToVector3() *
                                  (transform.localScale.y * .5f + .02f);
              transform.rotation = hand.Basis.Rotation();
          }
       }
    }
}
The script, LeapUnityExtensions.cs in Assets/LeapMotion/Scripts/Utils, provides helpful extension functions for converting vectors and matrices from the Leap Motion API classes to the Unity API classes. The functions ToVector3() and Rotation() used above are defined in this script.
Note: In almost every case, you should get Frame objects from the scene’s LeapProvider object. The LeapProvider transforms the frame data into the proper frame of reference. If you get a frame from the Leap.Controller object, the data will still be in the Leap Motion frame of reference and will not match the hands displayed in the scene.

Resource https://developer.leapmotion.com/documentation/unity/devguide/Project_Setup.html

إرسال تعليق

أحدث أقدم