Ultraleap 3Di示例Interactable Objects组件分析

2024-01-27 06:36

本文主要是介绍Ultraleap 3Di示例Interactable Objects组件分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

该示例代码位置如下:
在这里插入图片描述
分析如下:
在这里插入图片描述
Hover Enabled:悬停功能,手放在这个模型上,会触发我们手放在这个模型上的悬停功能。此时当手靠近模型的时候,手的模型的颜色会发生改变,反之,则不会改变。
Contact Enabled:触摸功能,与场景物体产生碰撞的功能。
Grasping Enabled:抓取功能,手是否具有抓取功能,是否会抓取起物体。
在这里插入图片描述
Hover Activation Radius:触发悬停半径,超过这个范围将不会触发悬停
Touch Activation Radius:抓取半径,超过这个范围将不会触发抓取
Multi Grasp Holding Mode:多个人同时抓取,

  • Preserve Pose Per Controller:如果要实现Multi Grasp Holding Mode,我们必须要这个物体允许可以被多个人同时抓取,即被多个手同时抓取,就要求物体开启属性才可以,找到可以交互的物体,挂载组件Interaction Behavior(Script),在下拉栏中选中Allow Multi Grasp;同时,该手还需要有Interaction Manager 这个组件。此时,物体就可以与手发生HoverContactGrasping
    在这里插入图片描述
    在这里插入图片描述
  • Reinitialize On Any Release:进行切换,自行体验二者的不同。

Interaction Objects
物体设置:在这里插入图片描述
Ignore Hover Mode:忽略Hover
Ignore Primary Hover:忽略主悬停
Ignore Contact:忽略碰撞
Ignore Grapsing:忽略抓取
Move Objext When Grasp:抓取的物体是否跟着一起动
在这里插入图片描述
Use Hover 悬停
Use Primary Hover 主悬停
悬停可以有很多,主悬停只有一个。当手在两个物体上悬停,优先选择主悬停。

挂载在物体上的脚本SimpleInteractionGlow.cs

/******************************************************************************* Copyright (C) Ultraleap, Inc. 2011-2024.                                   **                                                                            ** Use subject to the terms of the Apache License 2.0 available at            ** http://www.apache.org/licenses/LICENSE-2.0, or another agreement           ** between Ultraleap and you, your company or other organization.             *******************************************************************************/using Leap.Unity;
using Leap.Unity.Interaction;
using UnityEngine;namespace Leap.Unity.InteractionEngine.Examples
{/// <summary>/// This simple script changes the color of an InteractionBehaviour as/// a function of its distance to the palm of the closest hand that is/// hovering nearby./// </summary>[AddComponentMenu("")][RequireComponent(typeof(InteractionBehaviour))]public class SimpleInteractionGlow : MonoBehaviour{[Tooltip("If enabled, the object will lerp to its hoverColor when a hand is nearby.")]public bool useHover = true;[Tooltip("If enabled, the object will use its primaryHoverColor when the primary hover of an InteractionHand.")]public bool usePrimaryHover = false;[Header("InteractionBehaviour Colors")]public Color defaultColor = Color.Lerp(Color.black, Color.white, 0.1F);public Color suspendedColor = Color.red;public Color hoverColor = Color.Lerp(Color.black, Color.white, 0.7F);public Color primaryHoverColor = Color.Lerp(Color.black, Color.white, 0.8F);[Header("InteractionButton Colors")][Tooltip("This color only applies if the object is an InteractionButton or InteractionSlider.")]public Color pressedColor = Color.white;private Material[] _materials;private InteractionBehaviour _intObj;[SerializeField]private Rend[] rends;[System.Serializable]public class Rend{public int materialID = 0;public Renderer renderer;}void Start(){// 1、获取自身的InteractionBehaviour组件_intObj = GetComponent<InteractionBehaviour>();if (rends.Length > 0){_materials = new Material[rends.Length];for (int i = 0; i < rends.Length; i++){_materials[i] = rends[i].renderer.materials[rends[i].materialID];}}}void Update(){if (_materials != null){// The target color for the Interaction object will be determined by various simple state checks.Color targetColor = defaultColor;// "Primary hover" is a special kind of hover state that an InteractionBehaviour can// only have if an InteractionHand's thumb, index, or middle finger is closer to it// than any other interaction object.// 2、判断isPrimaryHovered是否为True,如果是,则表示我们的手放在了物体上,并且触发悬停。usePrimaryHover选项限制,需要勾选才触发if (_intObj.isPrimaryHovered && usePrimaryHover){targetColor = primaryHoverColor;// 2.1、变为设置好的颜色}else{// Of course, any number of objects can be hovered by any number of InteractionHands.// InteractionBehaviour provides an API for accessing various interaction-related// state information such as the closest hand that is hovering nearby, if the object// is hovered at all.// 3、判断isHovered 是否为Trueif (_intObj.isHovered && useHover){float glow = _intObj.closestHoveringControllerDistance.Map(0F, 0.2F, 1F, 0.0F);targetColor = Color.Lerp(defaultColor, hoverColor, glow);}}// 3、判断isSuspended是否暂停,如果是则改变颜色if (_intObj.isSuspended){// If the object is held by only one hand and that holding hand stops tracking, the// object is "suspended." InteractionBehaviour provides suspension callbacks if you'd// like the object to, for example, disappear, when the object is suspended.// Alternatively you can check "isSuspended" at any time.targetColor = suspendedColor;}// We can also check the depressed-or-not-depressed state of InteractionButton objects// and assign them a unique color in that case.if (_intObj is InteractionButton && (_intObj as InteractionButton).isPressed){targetColor = pressedColor;}// Lerp actual material color to the target color.for (int i = 0; i < _materials.Length; i++){_materials[i].color = Color.Lerp(_materials[i].color, targetColor, 30F * Time.deltaTime);// 2.2、 改变颜色}}}}
}

这篇关于Ultraleap 3Di示例Interactable Objects组件分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/649342

相关文章

Spring Boot中的路径变量示例详解

《SpringBoot中的路径变量示例详解》SpringBoot中PathVariable通过@PathVariable注解实现URL参数与方法参数绑定,支持多参数接收、类型转换、可选参数、默认值及... 目录一. 基本用法与参数映射1.路径定义2.参数绑定&nhttp://www.chinasem.cnbs

Spring StateMachine实现状态机使用示例详解

《SpringStateMachine实现状态机使用示例详解》本文介绍SpringStateMachine实现状态机的步骤,包括依赖导入、枚举定义、状态转移规则配置、上下文管理及服务调用示例,重点解... 目录什么是状态机使用示例什么是状态机状态机是计算机科学中的​​核心建模工具​​,用于描述对象在其生命

PostgreSQL中rank()窗口函数实用指南与示例

《PostgreSQL中rank()窗口函数实用指南与示例》在数据分析和数据库管理中,经常需要对数据进行排名操作,PostgreSQL提供了强大的窗口函数rank(),可以方便地对结果集中的行进行排名... 目录一、rank()函数简介二、基础示例:部门内员工薪资排名示例数据排名查询三、高级应用示例1. 每

使用Python删除Excel中的行列和单元格示例详解

《使用Python删除Excel中的行列和单元格示例详解》在处理Excel数据时,删除不需要的行、列或单元格是一项常见且必要的操作,本文将使用Python脚本实现对Excel表格的高效自动化处理,感兴... 目录开发环境准备使用 python 删除 Excphpel 表格中的行删除特定行删除空白行删除含指定

MySQL中的LENGTH()函数用法详解与实例分析

《MySQL中的LENGTH()函数用法详解与实例分析》MySQLLENGTH()函数用于计算字符串的字节长度,区别于CHAR_LENGTH()的字符长度,适用于多字节字符集(如UTF-8)的数据验证... 目录1. LENGTH()函数的基本语法2. LENGTH()函数的返回值2.1 示例1:计算字符串

Android kotlin中 Channel 和 Flow 的区别和选择使用场景分析

《Androidkotlin中Channel和Flow的区别和选择使用场景分析》Kotlin协程中,Flow是冷数据流,按需触发,适合响应式数据处理;Channel是热数据流,持续发送,支持... 目录一、基本概念界定FlowChannel二、核心特性对比数据生产触发条件生产与消费的关系背压处理机制生命周期

SpringBoot线程池配置使用示例详解

《SpringBoot线程池配置使用示例详解》SpringBoot集成@Async注解,支持线程池参数配置(核心数、队列容量、拒绝策略等)及生命周期管理,结合监控与任务装饰器,提升异步处理效率与系统... 目录一、核心特性二、添加依赖三、参数详解四、配置线程池五、应用实践代码说明拒绝策略(Rejected

SQL中如何添加数据(常见方法及示例)

《SQL中如何添加数据(常见方法及示例)》SQL全称为StructuredQueryLanguage,是一种用于管理关系数据库的标准编程语言,下面给大家介绍SQL中如何添加数据,感兴趣的朋友一起看看吧... 目录在mysql中,有多种方法可以添加数据。以下是一些常见的方法及其示例。1. 使用INSERT I

SpringBoot中SM2公钥加密、私钥解密的实现示例详解

《SpringBoot中SM2公钥加密、私钥解密的实现示例详解》本文介绍了如何在SpringBoot项目中实现SM2公钥加密和私钥解密的功能,通过使用Hutool库和BouncyCastle依赖,简化... 目录一、前言1、加密信息(示例)2、加密结果(示例)二、实现代码1、yml文件配置2、创建SM2工具

MySQL 定时新增分区的实现示例

《MySQL定时新增分区的实现示例》本文主要介绍了通过存储过程和定时任务实现MySQL分区的自动创建,解决大数据量下手动维护的繁琐问题,具有一定的参考价值,感兴趣的可以了解一下... mysql创建好分区之后,有时候会需要自动创建分区。比如,一些表数据量非常大,有些数据是热点数据,按照日期分区MululbU