首页 文章

无论如何都要检测交互引擎中哪一部分手触摸对象(Leap Motion和Unity3D)

提问于
浏览
0

我正在尝试构建一个应用程序,其中包括使用跳跃运动交互引擎来移动单位3d中的对象 . 但是,我还需要找出哪些手指在与物体相互作用时接触物体 . 无论如何我能做到吗?提前致谢!!

1 回答

  • 1

    严格来说,交互引擎的Grasping逻辑必须检查这一点才能启动或释放grasps,但它没有友好的API来访问这些信息 .

    表达这一点的更方便的方法,即使它不是最有效的方式,也可以检测手与交互对象相交并检查每个指尖与对象之间的距离 .

    与给定的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);
            }
          }
        }
      }
    
    }
    

相关问题