当前位置: 首页 > news >正文

LeapMotion第2代 Unity示范代码(桌面开发)

一、官方地址:

官网:https://www.ultraleap.com/
驱动下载:https://leap2.ultraleap.com/downloads/leap-motion-controller-2/
docs地址:https://docs.ultraleap.com/xr-and-tabletop/tabletop/unity/getting-started/index.html
unity开发地址(Demo下载):https://docs.ultraleap.com/xr-and-tabletop/tabletop/unity/getting-started/index.html
unity开发代码:https://docs.ultraleap.com/xr-and-tabletop/xr/unity/plugin/features/scripting-fundamentals.html


二、安装驱动

地址:https://www.sogou.com/tx?ie=utf-8&query=<%2Fb>&hdq=sogou-addr-cc9657884708170e&sourceid=6_01_03

在这里插入图片描述
在这里插入图片描述
这样说明已经安装成功


三、安装TouchFree

Ultraleap的TouchFree软件使用手部跟踪数据来生成屏幕光标,用户可以无接触地控制该光标。这种非接触式手势控制允许与信息亭和数字显示器进行简单、直观和卫生的交互。

  • 下载
    在这里插入图片描述
  • 安装完成后,进行配置
    在这里插入图片描述
    在这里插入图片描述
  • 根据设备安放情况,选择
    在这里插入图片描述
  • 接着,把手指悬空点在绿色的圈圈上,并按下空格,这里需要2次这样操作
    在这里插入图片描述
  • 配置完成,看到手指已经有光标跟随了,手指往前戳下,代表点击
  • 在小图标上,点击Start TouchFree,这样功能就永久启动起来了
    在这里插入图片描述

touchfree模式,不用要开发,就可实验手势点击功能,由官方直接提供


四、Unity安装LeapMotion插件

https://docs.ultraleap.com/xr-and-tabletop/tabletop/unity/getting-started/index.html

  • 安装包(能科学上网,速度更快)
    在这里插入图片描述
  • 打开Capsule Hands场景进行测试
    在这里插入图片描述
  • 测试出来手掌就成功了
    在这里插入图片描述

五、Unity安装LeapMotion最基础开发

1. 识别哪只手进入
  • 新建一个场景 LeapMotion
  • 建立一个Service Provider Desktop
    在这里插入图片描述
  • 建立一个LeapMotion的cs脚本
using UnityEngine;
using Leap;public class LeapMotion : MonoBehaviour
{public LeapProvider leapProvider;private void OnEnable(){leapProvider.OnHandFound += OnHandFound;leapProvider.OnHandLost += OnHandLost;leapProvider.OnUpdateFrame += OnUpdateFrame;}private void OnDisable(){leapProvider.OnHandFound -= OnHandFound;leapProvider.OnHandLost -= OnHandLost;leapProvider.OnUpdateFrame -= OnUpdateFrame;}private void OnHandFound(Chirality hand){if (hand == Chirality.Left){Debug.Log("发现左手");}else if (hand == Chirality.Right) {Debug.Log("发现右手");}}private void OnHandLost(Chirality hand){if (hand == Chirality.Left){Debug.Log("左手消失");}else if (hand == Chirality.Right){Debug.Log("右手消失");}}void OnUpdateFrame(Frame frame){foreach (var hand in frame.Hands){if (hand.IsLeft){//获取左手Hand _leftHand = frame.GetHand(Chirality.Left);OnUpdateHand(_leftHand);}else if (hand.IsRight) {// 获取右手Hand _rightHand = frame.GetHand(Chirality.Right);OnUpdateHand(_rightHand);}}}void OnUpdateHand(Hand _hand){if (_hand.IsLeft){Debug.Log("左手");}else if (_hand.IsRight) {Debug.Log("右手");}}
}
  • 建立一个LeapMotion对象,把脚本拖入场景,运行测试
    在这里插入图片描述

该脚本识别出了哪只手进入或离开,并实时获取那只手,后面需要进一步获取手的更多信息

2. 获取手的位置与角度
  • 五个指头的英文,Thumb大拇指,Index食指,Middle中指,Ring无名指,Pinky小指

Frames API:https://docs.ultraleap.com/api-reference/unity-api/class/class_leap_1_1_frame.html#class-Leap.Frame
Hand API:https://docs.ultraleap.com/api-reference/unity-api/class/class_leap_1_1_hand.html#class-Leap.Hand
Finger API:https://docs.ultraleap.com/api-reference/unity-api/class/class_leap_1_1_finger.html#class-Leap.Finger

  • 获取代码
    void OnUpdateFrame(Frame frame){foreach (var hand in frame.Hands){if (hand.IsLeft){//获取左手Hand _leftHand = frame.GetHand(Chirality.Left);OnUpdateHand(_leftHand);}else if (hand.IsRight) {// 获取右手Hand _rightHand = frame.GetHand(Chirality.Right);OnUpdateHand(_rightHand);}}}void OnUpdateHand(Hand _hand){Finger _index = _hand.GetFinger(Finger.FingerType.INDEX);if (_hand.IsLeft){Debug.Log("左手");}else if (_hand.IsRight) {Debug.Log("右手");}Debug.Log("手掌位置" + _hand.PalmPosition.ToString());Debug.Log("手掌角度" + _hand.PalmarAxis().ToString());Debug.Log("手指位置" + _index.TipPosition.ToString());Debug.Log("手指方向-向量" + _index.Direction.ToString());}
3. 获取手是否捏了下,拇指与食指触碰 和 获取是否握拳

LeapMotion对于捏和握拳有特别的检测器,分别是PinchDetector 捏检测器,GrabDetector 握拳检测器

  • 建立一个检测器的对象,里面有左右手对象
    在这里插入图片描述
  • 在左右手里,分别加入检测器
    在这里插入图片描述
  • 代码:
using UnityEngine;
using Leap;public class LeapMotion : MonoBehaviour
{public LeapProvider leapProvider;public PinchDetector leftPinchDetector;public PinchDetector rightPinchDetector;public GrabDetector leftGrabDetector;public GrabDetector rightGrabDetector;private void OnEnable(){leapProvider.OnHandFound += OnHandFound;leapProvider.OnHandLost += OnHandLost;leapProvider.OnUpdateFrame += OnUpdateFrame;leftPinchDetector.onActionStart += LeftHandPinchStart;leftPinchDetector.onAction += LeftHandPinching;leftPinchDetector.onActionEnd += LeftHandPinchEnd;rightPinchDetector.onActionStart += RightHandPinchStart;rightPinchDetector.onAction += RightHandPinching;rightPinchDetector.onActionEnd += RightHandPinchEnd;leftGrabDetector.onActionStart += LeftHandGrapStart;leftGrabDetector.onActionEnd += LeftHandGrabEnd;rightGrabDetector.onActionStart += RightHandGrabStart;rightGrabDetector.onActionEnd += RightHandGrabEnd;}private void OnDisable(){leapProvider.OnHandFound -= OnHandFound;leapProvider.OnHandLost -= OnHandLost;leapProvider.OnUpdateFrame -= OnUpdateFrame;leftPinchDetector.onActionStart -= LeftHandPinchStart;leftPinchDetector.onAction -= LeftHandPinching;leftPinchDetector.onActionEnd -= LeftHandPinchEnd;rightPinchDetector.onActionStart -= RightHandPinchStart;rightPinchDetector.onAction -= RightHandPinching;rightPinchDetector.onActionEnd -= RightHandPinchEnd;leftGrabDetector.onActionStart -= LeftHandGrapStart;leftGrabDetector.onActionEnd -= LeftHandGrabEnd;rightGrabDetector.onActionStart -= RightHandGrabStart;rightGrabDetector.onActionEnd -= RightHandGrabEnd;}private void OnHandFound(Chirality hand){if (hand == Chirality.Left){Debug.Log("发现左手");}else if (hand == Chirality.Right){Debug.Log("发现右手");}}private void OnHandLost(Chirality hand){if (hand == Chirality.Left){Debug.Log("左手消失");}else if (hand == Chirality.Right){Debug.Log("右手消失");}}void OnUpdateFrame(Frame frame){foreach (var hand in frame.Hands){if (hand.IsLeft){//获取左手Hand _leftHand = frame.GetHand(Chirality.Left);OnUpdateHand(_leftHand);}else if (hand.IsRight) {// 获取右手Hand _rightHand = frame.GetHand(Chirality.Right);OnUpdateHand(_rightHand);}}}void OnUpdateHand(Hand _hand){Finger _index = _hand.GetFinger(Finger.FingerType.INDEX);if (_hand.IsLeft){Debug.Log("左手");}else if (_hand.IsRight){Debug.Log("右手");}Debug.Log("手掌位置" + _hand.PalmPosition.ToString());Debug.Log("手掌角度" + _hand.PalmarAxis().ToString());Debug.Log("手指位置" + _index.TipPosition.ToString());Debug.Log("手指方向-向量" + _index.Direction.ToString());}private void RightHandGrabEnd(Hand hand){Debug.Log("Right 抓拳");}private void RightHandGrabStart(Hand hand){Debug.Log("Right 抓拳放开");}private void LeftHandGrabEnd(Hand hand){Debug.Log("Left 抓拳");}private void LeftHandGrapStart(Hand hand){Debug.Log("Left 抓拳放开");}private void RightHandPinchEnd(Hand hand){Debug.Log("Right 捏放开");}private void RightHandPinching(Hand hand){Debug.Log("Right 捏住移动中");}private void RightHandPinchStart(Hand hand){Debug.Log("Righ 捏住");}private void LeftHandPinchEnd(Hand hand){Debug.Log("Left 捏放开");}private void LeftHandPinching(Hand hand){Debug.Log("Left 捏住移动中");}private void LeftHandPinchStart(Hand hand){Debug.Log("Left 捏住");}
}

六、结束语

2代的LeapMotion对长距离传输信号更加友好,好像也提供了大面积手势识别的融合方案,感谢一起学习
源代码:https://download.csdn.net/download/qq_17523181/90379338


http://www.mrgr.cn/news/90637.html

相关文章:

  • 大疆无人机需要的kml文件如何制作kml导出(大疆KML文件)
  • 宏基传奇swift edge偶尔开机BIOS重置
  • 细说STM32F407单片机RTC的备份寄存器原理及使用方法
  • 算法刷题-链表系列-移除链表、设计链表、翻转列表
  • 从 X86 到 ARM :工控机迁移中的核心问题剖析
  • 本地生活服务平台开发进入发展热潮
  • Java IO流详解
  • 二次封装axios解决异步通信痛点
  • #渗透测试#批量漏洞挖掘#致远互联AnalyticsCloud 分析云 任意文件读取
  • 【一文读懂】HTTP与Websocket协议
  • 【07】trait特性
  • 综合与时序分析的设计约束(4)—— 异常
  • ARM64 Trust Firmware [一]
  • 编码格式大全解释以及相关编码特性
  • LTSPICE仿真电路:(二十三)单端信号转差分信号的简单仿真
  • MybatisPlus常用增删改查
  • springcloud集成gateway
  • (Windows | Linux)ssh访问服务器报错:no matching key exchange method found
  • #渗透测试#批量漏洞挖掘#Crocus系统—Download 文件读取
  • 用于处理元素的全屏显示和退出全屏操作--useFullScreen
  • React进阶之React核心源码解析(一)
  • 【CXX】0 Rust与C ++的互操作利器:CXX库介绍与示例
  • 【Linux】Ubuntu Linux 系统——Python集成开发环境
  • C语言中printf()函数,格式输出符
  • C++ ——基础进阶
  • Spring Boot整合DeepSeek实现AI对话(API调用和本地部署)