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

相关文章

Java调用DeepSeek API的最佳实践及详细代码示例

《Java调用DeepSeekAPI的最佳实践及详细代码示例》:本文主要介绍如何使用Java调用DeepSeekAPI,包括获取API密钥、添加HTTP客户端依赖、创建HTTP请求、处理响应、... 目录1. 获取API密钥2. 添加HTTP客户端依赖3. 创建HTTP请求4. 处理响应5. 错误处理6.

Android 悬浮窗开发示例((动态权限请求 | 前台服务和通知 | 悬浮窗创建 )

《Android悬浮窗开发示例((动态权限请求|前台服务和通知|悬浮窗创建)》本文介绍了Android悬浮窗的实现效果,包括动态权限请求、前台服务和通知的使用,悬浮窗权限需要动态申请并引导... 目录一、悬浮窗 动态权限请求1、动态请求权限2、悬浮窗权限说明3、检查动态权限4、申请动态权限5、权限设置完毕后

Springboot中分析SQL性能的两种方式详解

《Springboot中分析SQL性能的两种方式详解》文章介绍了SQL性能分析的两种方式:MyBatis-Plus性能分析插件和p6spy框架,MyBatis-Plus插件配置简单,适用于开发和测试环... 目录SQL性能分析的两种方式:功能介绍实现方式:实现步骤:SQL性能分析的两种方式:功能介绍记录

在 Spring Boot 中使用 @Autowired和 @Bean注解的示例详解

《在SpringBoot中使用@Autowired和@Bean注解的示例详解》本文通过一个示例演示了如何在SpringBoot中使用@Autowired和@Bean注解进行依赖注入和Bean... 目录在 Spring Boot 中使用 @Autowired 和 @Bean 注解示例背景1. 定义 Stud

oracle DBMS_SQL.PARSE的使用方法和示例

《oracleDBMS_SQL.PARSE的使用方法和示例》DBMS_SQL是Oracle数据库中的一个强大包,用于动态构建和执行SQL语句,DBMS_SQL.PARSE过程解析SQL语句或PL/S... 目录语法示例注意事项DBMS_SQL 是 oracle 数据库中的一个强大包,它允许动态地构建和执行

Python中顺序结构和循环结构示例代码

《Python中顺序结构和循环结构示例代码》:本文主要介绍Python中的条件语句和循环语句,条件语句用于根据条件执行不同的代码块,循环语句用于重复执行一段代码,文章还详细说明了range函数的使... 目录一、条件语句(1)条件语句的定义(2)条件语句的语法(a)单分支 if(b)双分支 if-else(

最长公共子序列问题的深度分析与Java实现方式

《最长公共子序列问题的深度分析与Java实现方式》本文详细介绍了最长公共子序列(LCS)问题,包括其概念、暴力解法、动态规划解法,并提供了Java代码实现,暴力解法虽然简单,但在大数据处理中效率较低,... 目录最长公共子序列问题概述问题理解与示例分析暴力解法思路与示例代码动态规划解法DP 表的构建与意义动

Python中Markdown库的使用示例详解

《Python中Markdown库的使用示例详解》Markdown库是一个用于处理Markdown文本的Python工具,这篇文章主要为大家详细介绍了Markdown库的具体使用,感兴趣的... 目录一、背景二、什么是 Markdown 库三、如何安装这个库四、库函数使用方法1. markdown.mark

MySQL数据库函数之JSON_EXTRACT示例代码

《MySQL数据库函数之JSON_EXTRACT示例代码》:本文主要介绍MySQL数据库函数之JSON_EXTRACT的相关资料,JSON_EXTRACT()函数用于从JSON文档中提取值,支持对... 目录前言基本语法路径表达式示例示例 1: 提取简单值示例 2: 提取嵌套值示例 3: 提取数组中的值注意

CSS3中使用flex和grid实现等高元素布局的示例代码

《CSS3中使用flex和grid实现等高元素布局的示例代码》:本文主要介绍了使用CSS3中的Flexbox和Grid布局实现等高元素布局的方法,通过简单的两列实现、每行放置3列以及全部代码的展示,展示了这两种布局方式的实现细节和效果,详细内容请阅读本文,希望能对你有所帮助... 过往的实现方法是使用浮动加