与给定的InteractionBehaviour相交的所有InteractionControllers都可以通过其 contactingControllers 属性访问;使用Leap tools for Unity中包含的 Query 库,您可以毫不费力地将一堆交互式控制器引用转换为一堆Leap Hands,然后执行检查:
using Leap.Unity;
using Leap.Unity.Interaction;
using Leap.Unity.Query;
using UnityEngine;
public class QueryFingertips : MonoBehaviour {
public InteractionBehaviour intObj;
private Collider[] _collidersBuffer = new Collider[16];
private float _fingertipRadius = 0.01f; // 1 cm
void FixedUpdate() {
foreach (var contactingHand in intObj.contactingControllers
.Query()
.Select(controller => controller.intHand)
.Where(intHand => intHand != null)
.Select(intHand => intHand.leapHand)) {
foreach (var finger in contactingHand.Fingers) {
var fingertipPosition = finger.TipPosition.ToVector3();
// If the distance from the fingertip and the object is less
// than the 'fingertip radius', the fingertip is touching the object.
if (intObj.GetHoverDistance(fingertipPosition) < _fingertipRadius) {
Debug.Log("Found collision for fingertip: " + finger.Type);
}
}
}
}
}
1 回答
严格来说,交互引擎的Grasping逻辑必须检查这一点才能启动或释放grasps,但它没有友好的API来访问这些信息 .
表达这一点的更方便的方法,即使它不是最有效的方式,也可以检测手与交互对象相交并检查每个指尖与对象之间的距离 .
与给定的InteractionBehaviour相交的所有InteractionControllers都可以通过其
contactingControllers
属性访问;使用Leap tools for Unity中包含的Query
库,您可以毫不费力地将一堆交互式控制器引用转换为一堆Leap Hands,然后执行检查: