Leap抓取物体,在自带案例的基础上修改

1,可以直接使用自带的案例完成leap的手势交互。

copy

2, 手势的抓取不是很稳定,可以通过修改抓取的交互代码改进。

A 当手指的外置与物体的距离小于一定值时,将要抓取的物体变为手指的子物体。

    -------直接将手指的position赋给要交互的物体。

--------或者把其变为手指的子物体,但没有上面简单。

------------手指的位置获取,可以通过代码也可以通过拖动某一个手指的关节。

 

B 当物体到达要完成装配的目的的时,直接把目的地的位置赋给交互的零件。防止安装完成后零件又粘连在手指上,当到达目的地后同时把交互的脚本不打勾。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using Leap;
using Leap.Unity;

public class AutoA : MonoBehaviour {


    private LeapProvider mProvider;
    private Frame mFrame;

    Vector3 PinchPos = Vector3.zero;

    //part list
    private List<GameObject> PartList = new List<GameObject>();

    float disValue = 1.25f;
    float GraspdisValue = 2.0f;

    // aim position AP
    //aim Quaternion  AQ
    //1  04_LuoGan
    GameObject LuoGan04;
	Vector3 LuoGan04Aim = new Vector3(37.71f, 4.74f, -22.0f);
	Quaternion LuoGan04Qua = new Quaternion(0.0f, 0.0f, 0.0f, 0.0f);

	//2  04_LuoGan
	GameObject FangKuaiLuoMu02;
	Vector3 FKMAP = new Vector3(37.78f, 7.19f, -22.09f);
	Quaternion FKMAQ = new Quaternion(-0.488f, -0.5106f, -0.5f, 0.5f);

	//3 06_KuKouBan
	GameObject KuKouBan06;
	Vector3 KKBAP= new Vector3(29.181f, 8.025f, -21.9056f);
	Quaternion KKBAQ = new Quaternion(0.0066f, 0.7159f, -0.0064f, 0.6981f);




	// Use this for initialization
	void Start () {

        mProvider = FindObjectOfType<LeapProvider>() as LeapProvider;



        //1  04_LuoGan
        LuoGan04 = GameObject.Find ("04_LuoGan");
        PartList.Add(LuoGan04);
        //print (LuoGan04.name );

        //2  04_LuoGan
        FangKuaiLuoMu02 = GameObject.Find ("02_FangKuaiLuoMu");
        PartList.Add(FangKuaiLuoMu02);

        //print (LuoGan04.name );

        //3  06_KuKouBan
        KuKouBan06 = GameObject.Find ("06_HuKouBan");
        PartList.Add(KuKouBan06);







    }

    // Update is called once per frame
    void Update()
    {

        ///
        ///手势靠近零件时变为子物体,提高抓取的稳定性
        ///不自然的情况以后再处理

        mFrame = mProvider.CurrentFrame;//获取当前帧

        if (mFrame.Hands.Count > 0)
        {

            //print(2); 			
            if (mFrame.Hands.Count == 1)
            {

                foreach (var itemHands in mFrame.Hands)
                {
                    PinchPos = itemHands.GetPinchPosition();

                    foreach (var itemPart in PartList)
                    {
                        GraspParts(itemPart);
                    }



                }


            }
        }










        ///
        ///零件距离安装位置时自动吸附
        //1  04_LuoGan
        if (Mathf.Sqrt((LuoGan04.transform.localPosition - LuoGan04Aim).magnitude) < disValue + 0.35)
        {
            LuoGan04.transform.localPosition = LuoGan04Aim;
            LuoGan04.transform.localRotation = LuoGan04Qua;
            //避免装好后,不移动,更加稳定
            LuoGan04.GetComponent<Leap.Unity.Interaction.InteractionBehaviour>().enabled = false;
            // LuoGan04.GetComponent<SimpleInteractionGlow>().enabled = false;

        }

        //2 
        if (Mathf.Sqrt((FangKuaiLuoMu02.transform.localPosition - FKMAP).magnitude) < disValue)
        {
            FangKuaiLuoMu02.transform.localPosition = FKMAP;
            FangKuaiLuoMu02.transform.localRotation = FKMAQ;
            FangKuaiLuoMu02.GetComponent<Leap.Unity.Interaction.InteractionBehaviour>().enabled = false;
            // FangKuaiLuoMu02.GetComponent<SimpleInteractionGlow>().enabled = false;
        }

        //3
        if (Mathf.Sqrt((KuKouBan06.transform.localPosition - KKBAP).magnitude) < disValue)
        {
            KuKouBan06.transform.localPosition = KKBAP;
            KuKouBan06.transform.localRotation = KKBAQ;
            KuKouBan06.GetComponent<Leap.Unity.Interaction.InteractionBehaviour>().enabled = false;
            // KuKouBan06.GetComponent<SimpleInteractionGlow>().enabled = false;

        }





    }

    void GraspParts(GameObject part)
    {
        //1  04_LuoGan
        if (Mathf.Sqrt((part.transform.localPosition - PinchPos).magnitude) < GraspdisValue)
        {
            part.transform.localPosition = PinchPos;
        }

    }
              
             
}

可以让物体与手势相碰撞时让零件变为绿色,要修改 primary hover color

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值