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

相关文章

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

Python函数作用域示例详解

《Python函数作用域示例详解》本文介绍了Python中的LEGB作用域规则,详细解析了变量查找的四个层级,通过具体代码示例,展示了各层级的变量访问规则和特性,对python函数作用域相关知识感兴趣... 目录一、LEGB 规则二、作用域实例2.1 局部作用域(Local)2.2 闭包作用域(Enclos

怎样通过分析GC日志来定位Java进程的内存问题

《怎样通过分析GC日志来定位Java进程的内存问题》:本文主要介绍怎样通过分析GC日志来定位Java进程的内存问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、GC 日志基础配置1. 启用详细 GC 日志2. 不同收集器的日志格式二、关键指标与分析维度1.

C++20管道运算符的实现示例

《C++20管道运算符的实现示例》本文简要介绍C++20管道运算符的使用与实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录标准库的管道运算符使用自己实现类似的管道运算符我们不打算介绍太多,因为它实际属于c++20最为重要的

Java中调用数据库存储过程的示例代码

《Java中调用数据库存储过程的示例代码》本文介绍Java通过JDBC调用数据库存储过程的方法,涵盖参数类型、执行步骤及数据库差异,需注意异常处理与资源管理,以优化性能并实现复杂业务逻辑,感兴趣的朋友... 目录一、存储过程概述二、Java调用存储过程的基本javascript步骤三、Java调用存储过程示

ModelMapper基本使用和常见场景示例详解

《ModelMapper基本使用和常见场景示例详解》ModelMapper是Java对象映射库,支持自动映射、自定义规则、集合转换及高级配置(如匹配策略、转换器),可集成SpringBoot,减少样板... 目录1. 添加依赖2. 基本用法示例:简单对象映射3. 自定义映射规则4. 集合映射5. 高级配置匹

MySQL中的表连接原理分析

《MySQL中的表连接原理分析》:本文主要介绍MySQL中的表连接原理分析,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、背景2、环境3、表连接原理【1】驱动表和被驱动表【2】内连接【3】外连接【4编程】嵌套循环连接【5】join buffer4、总结1、背景