【m】添加图像识别
This commit is contained in:
@@ -3,126 +3,129 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Rokid.UXR.Interaction;
|
||||
|
||||
public abstract class GestureBase : MonoBehaviour
|
||||
namespace Stary.Evo.RKTools
|
||||
{
|
||||
private GestureBean leftBean = null;
|
||||
private GestureBean rightBean = null;
|
||||
|
||||
protected void OnEnable()
|
||||
public abstract class GestureBase : MonoBehaviour
|
||||
{
|
||||
GesEventInput.OnTrackedSuccess += OnTrackedSuccess;
|
||||
GesEventInput.OnTrackedFailed += OnTrackedFailed;
|
||||
GesEventInput.OnRenderHand += OnRenderHand;
|
||||
private GestureBean leftBean = null;
|
||||
private GestureBean rightBean = null;
|
||||
|
||||
protected void OnEnable()
|
||||
{
|
||||
GesEventInput.OnTrackedSuccess += OnTrackedSuccess;
|
||||
GesEventInput.OnTrackedFailed += OnTrackedFailed;
|
||||
GesEventInput.OnRenderHand += OnRenderHand;
|
||||
}
|
||||
|
||||
protected void OnDisable()
|
||||
{
|
||||
GesEventInput.OnTrackedSuccess -= OnTrackedSuccess;
|
||||
GesEventInput.OnTrackedFailed -= OnTrackedFailed;
|
||||
GesEventInput.OnRenderHand -= OnRenderHand;
|
||||
}
|
||||
|
||||
protected void FixedUpdate()
|
||||
{
|
||||
if (leftBean != null)
|
||||
{
|
||||
GestureType type = GesEventInput.Instance.GetGestureType(HandType.LeftHand);
|
||||
Vector3 handForward = GetSkeletonPose(SkeletonIndexFlag.PALM, HandType.LeftHand).forward;
|
||||
GestureLeftSuccess(type, handForward);
|
||||
}
|
||||
else
|
||||
{
|
||||
GestureLeftFail();
|
||||
}
|
||||
|
||||
if (rightBean != null)
|
||||
{
|
||||
GestureType type = GesEventInput.Instance.GetGestureType(HandType.RightHand);
|
||||
Vector3 handForward = GetSkeletonPose(SkeletonIndexFlag.PALM, HandType.RightHand).forward;
|
||||
GestureRightSuccess(type, handForward);
|
||||
}
|
||||
else
|
||||
{
|
||||
GestureRightFail();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTrackedSuccess(HandType handType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnTrackedFailed(HandType handType)
|
||||
{
|
||||
if (handType == HandType.None)
|
||||
{
|
||||
leftBean = null;
|
||||
rightBean = null;
|
||||
}
|
||||
|
||||
if (handType == HandType.RightHand)
|
||||
{
|
||||
rightBean = null;
|
||||
}
|
||||
|
||||
if (handType == HandType.LeftHand)
|
||||
{
|
||||
leftBean = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRenderHand(HandType handType, GestureBean gestureBean)
|
||||
{
|
||||
if (handType == HandType.RightHand)
|
||||
{
|
||||
rightBean = gestureBean;
|
||||
}
|
||||
|
||||
if (handType == HandType.LeftHand)
|
||||
{
|
||||
leftBean = gestureBean;
|
||||
}
|
||||
|
||||
if (handType == HandType.None)
|
||||
{
|
||||
rightBean = null;
|
||||
leftBean = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取骨架点位置
|
||||
/// </summary>
|
||||
/// <param name="index">骨架序号</param>
|
||||
/// <param name="hand">哪只手</param>
|
||||
/// <returns></returns>
|
||||
public Pose GetSkeletonPose(SkeletonIndexFlag index, HandType hand)
|
||||
{
|
||||
return GesEventInput.Instance.GetSkeletonPose(index, hand);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取手地朝向
|
||||
/// </summary>
|
||||
/// <param name="handType">哪只手</param>
|
||||
/// <returns></returns>
|
||||
public Vector3 GetHandForward(HandType handType)
|
||||
{
|
||||
Vector3 handForward = (GetSkeletonPose(SkeletonIndexFlag.MIDDLE_FINGER_MCP, handType).position -
|
||||
GetSkeletonPose(SkeletonIndexFlag.WRIST, handType).position);
|
||||
return handForward;
|
||||
}
|
||||
|
||||
|
||||
#region 需要被重写的方法
|
||||
|
||||
public abstract void GestureLeftSuccess(GestureType gestureType, Vector3 handForward);
|
||||
public abstract void GestureRightSuccess(GestureType gestureType, Vector3 handForward);
|
||||
public abstract void GestureLeftFail();
|
||||
public abstract void GestureRightFail();
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
protected void OnDisable()
|
||||
{
|
||||
GesEventInput.OnTrackedSuccess -= OnTrackedSuccess;
|
||||
GesEventInput.OnTrackedFailed -= OnTrackedFailed;
|
||||
GesEventInput.OnRenderHand -= OnRenderHand;
|
||||
}
|
||||
|
||||
protected void FixedUpdate()
|
||||
{
|
||||
if (leftBean!=null)
|
||||
{
|
||||
GestureType type= GesEventInput.Instance.GetGestureType(HandType.LeftHand);
|
||||
Vector3 handForward = GetSkeletonPose(SkeletonIndexFlag.PALM, HandType.LeftHand).forward;
|
||||
GestureLeftSuccess(type,handForward);
|
||||
}
|
||||
else
|
||||
{
|
||||
GestureLeftFail();
|
||||
}
|
||||
|
||||
if (rightBean != null)
|
||||
{
|
||||
GestureType type= GesEventInput.Instance.GetGestureType(HandType.RightHand);
|
||||
Vector3 handForward = GetSkeletonPose(SkeletonIndexFlag.PALM, HandType.RightHand).forward;
|
||||
GestureRightSuccess(type,handForward);
|
||||
}
|
||||
else
|
||||
{
|
||||
GestureRightFail();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTrackedSuccess(HandType handType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnTrackedFailed(HandType handType)
|
||||
{
|
||||
if (handType == HandType.None)
|
||||
{
|
||||
leftBean = null;
|
||||
rightBean = null;
|
||||
}
|
||||
|
||||
if (handType == HandType.RightHand)
|
||||
{
|
||||
rightBean = null;
|
||||
}
|
||||
|
||||
if (handType == HandType.LeftHand)
|
||||
{
|
||||
leftBean = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRenderHand(HandType handType, GestureBean gestureBean)
|
||||
{
|
||||
if (handType == HandType.RightHand)
|
||||
{
|
||||
rightBean = gestureBean;
|
||||
}
|
||||
|
||||
if (handType == HandType.LeftHand)
|
||||
{
|
||||
leftBean = gestureBean;
|
||||
}
|
||||
|
||||
if (handType == HandType.None)
|
||||
{
|
||||
rightBean = null;
|
||||
leftBean = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取骨架点位置
|
||||
/// </summary>
|
||||
/// <param name="index">骨架序号</param>
|
||||
/// <param name="hand">哪只手</param>
|
||||
/// <returns></returns>
|
||||
public Pose GetSkeletonPose(SkeletonIndexFlag index, HandType hand)
|
||||
{
|
||||
return GesEventInput.Instance.GetSkeletonPose(index, hand);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取手地朝向
|
||||
/// </summary>
|
||||
/// <param name="handType">哪只手</param>
|
||||
/// <returns></returns>
|
||||
public Vector3 GetHandForward(HandType handType)
|
||||
{
|
||||
Vector3 handForward = (GetSkeletonPose(SkeletonIndexFlag.MIDDLE_FINGER_MCP, handType).position -
|
||||
GetSkeletonPose(SkeletonIndexFlag.WRIST, handType).position);
|
||||
return handForward;
|
||||
}
|
||||
|
||||
|
||||
#region 需要被重写的方法
|
||||
|
||||
public abstract void GestureLeftSuccess(GestureType gestureType, Vector3 handForward);
|
||||
public abstract void GestureRightSuccess(GestureType gestureType, Vector3 handForward);
|
||||
public abstract void GestureLeftFail();
|
||||
public abstract void GestureRightFail();
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user