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

ops/2025/2/19 9:18:05/

一、官方地址:

官网: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.PalmVelocity.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.PalmVelocity.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.ppmy.cn/ops/158241.html

相关文章

DevExpress WPF中文教程:Grid - 如何创建未绑定列?

DevExpress WPF拥有120个控件和库&#xff0c;将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpress WPF能创建有着强大互动功能的XAML基础应用程序&#xff0c;这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案。 无论是Office办公软件…

左移架构 -- 从攒批,湖仓到使用数据流的实时数据产品

编辑导读: 这篇文章翻译自 Kai Waehner的 《The Shift Left Architecture – From Batch and Lakehouse to Real-Time Data Products with Data Streaming》。文章通过数据产品的概念引出了如何创建可重复使用的数据产品使企业能够从当前和未来的数据中获得价值。基于构建数据产…

vue2 多页面pdf预览

使用pdfjs-dist预览pdf&#xff0c;实现预加载&#xff0c;滚动条翻页。pdfjs的版本很重要&#xff0c;换了好多版本&#xff0c;终于有一个能用的 node 20.18.1 "pdfjs-dist": "^2.2.228", vue页面代码如下 <template><div v-loading"loa…

全面理解-什么是尾递归优化?

尾递归&#xff08;Tail Recursion&#xff09; 是一种特殊的递归形式&#xff0c;其特点是递归调用是函数的 最后一步操作。尾递归可以被编译器优化为迭代形式&#xff0c;从而避免递归调用带来的栈溢出问题&#xff0c;并提升性能。 以下是尾递归的详细说明和优化原理&#…

【进阶】JVM篇

为什么学习jvm 1、面试的需要 学过java的程序员对jvm应该不陌生&#xff0c;程序员为什么要学习jvm呢&#xff1f;其实不懂jvm也可以照样写出优质的代码&#xff0c;但是不懂jvm会被大厂的面试官虐的体无完肤。 2、高级程序员需要了解 jvm作用 jvm负责把编译后的字节码转换…

redis之lua实现原理

文章目录 创建并修改Lua环境Lua环境协作组件伪客户端lua scripts字典 EVAL命令的实现定义脚本函数执行脚本函数 EVALSHA命令的实现脚本管理命令的实现SCRIPT FLUSHSCRIPTEXISTSSCRIPT LOADSCRIPT KILL 脚本复制复制 EVAL命令、SCRIPT FLUSH命令和SCRIPT LOAD命令* 复制EVALSHA命…

sql盲注脚本

在sqli-labs中的第8题无回显可以尝试盲注的手法获取数据 发现页面加载了3秒左右可以进行盲注 布尔盲注数据库名 import requestsdef inject_database(url):datanamefor i in range(1,15):low 32high 128mid (low high) // 2while low < high:path "id1 and asci…

华为HCNA(华为认证网络工程师)大纲

华为HCNA&#xff08;华为认证网络工程师&#xff09;是华为认证体系中的基础级别认证&#xff0c;主要面向刚进入网络行业的工程师&#xff0c;旨在验证其对网络基础知识的理解和技能。以下是HCNA的大纲内容&#xff0c;供参考&#xff1a; 文章目录 1. 网络基础网络概念&…