VR模拟真人动作
来源:互联网 发布:广东省电信工程知乎 编辑:程序博客网 时间:2024/04/28 21:44
首先,感恩大神的分享,没有前人之路,后来者想要乘凉就难了。
借鉴大神的地址:http://www.gad.qq.com/article/detail/27127
一、准备
1.设备 HTC Vive追踪器(Tracker X3,Controller X2):一套HTC Vive设备有两个手柄和一个追踪器,再订两个追踪器即可 2.插件 ①Unity的 Assets Store里面插件,搜索“Final IK”就能找到(直接买太贵,还好大神无私) ②当然,还需要在 Assets Store里下载SteamVR Plugin这个插件(接触过VR的应该都知道)
二、思路
1.IK,也就是逆向运动学,这个插件用来保持关节弯曲的正确2.怎么区分追踪器?①HTC Vive能识别15个设备(定位器+追踪器),根据Valve.VR.ETrackedDeviceClass的实例判断设备类型,然后用SteamVR_TrackedObject.isValid判断设备是否可用。若可用,则获取其index。②先根据Y轴方向上值的大小判断脚1、脚2,腰,手1,手2;然后以头盔为参照,若 脚1 - 脚2 的向量方向为头盔右方,则脚1为右脚,手同理。3.怎么让模型动作同步?不能直接把设备设为四个关节的运动目标。因为脚上和腰部的追踪器不可能与模型关节点重合,而且,旋转的角度也有一个差值。新建五个物体,识别的时候让这五个物体的rotation为关节点的rotation,再将其设为追踪器的子节点。
三、实现
贴出识别追踪器的代码:
/* * CheckTrackers/InitPositions的子对象为 手腕、脚踝、腰,将其拖到模型的相应位置上 * 使用协程CheckTrackers()开始检测追踪器,orderedList存储得出的部位index */using System.Collections;using System.Collections.Generic;using UnityEngine;[DisallowMultipleComponent]public class GetTrackers : MonoBehaviour{ public Dictionary<int, Transform> trackerTrans = new Dictionary<int, Transform>();//存储追踪器index和transform public List<int> orderedList = new List<int>();//存储追踪器的index public Transform[] originBodyTrans = new Transform[5];//四肢+腰(跟随的目标) public Transform bodyRightTrans;//得到头盔右向坐标,以区分左右追踪器 [SerializeField] private GameObject trackers;//父节点,获取追踪器 //顺序为: 右脚、左脚、腰、右手、左手 private SteamVR_TrackedObject[] trackerArray; private Dictionary<int, Transform> devicesIndexArray = new Dictionary<int, Transform>();//存储识别的追踪器 public static GetTrackers instance; // Use this for initialization void Awake() { instance = this; trackerArray = trackers.GetComponentsInChildren<SteamVR_TrackedObject>(); for (int i = 0; i < trackerArray.Length; i++) { trackerTrans[(int)(trackerArray[i].index)] = trackerArray[i].transform;//获取15个子节点的属性 } } /// <summary> /// 开始检测追踪器 /// </summary> /// <returns></returns> public IEnumerator CheckTrackers() { while (true) { yield return new WaitForFixedUpdate(); for (int i = (int)SteamVR_TrackedObject.EIndex.Device1; i < (int)SteamVR_TrackedObject.EIndex.Device15; i++) { Valve.VR.ETrackedDeviceClass deviceClass = Valve.VR.OpenVR.System.GetTrackedDeviceClass((uint)i); if (deviceClass == Valve.VR.ETrackedDeviceClass.Controller || deviceClass == Valve.VR.ETrackedDeviceClass.GenericTracker)//手柄或追踪器 { for (int m = 0; m < trackerArray.Length; m++) { if ((int)trackerArray[m].index == i && trackerArray[m].isValid) { if (!devicesIndexArray.ContainsKey(i)) { devicesIndexArray.Add(i, trackerTrans[i]);//添加到字典 orderedList.Add(i);//将key的顺序添加到数组 Debug.Log(deviceClass.ToString() + i + ": " + trackerTrans[i].position.y); } if (devicesIndexArray.Count == 5)//若有五个追踪器 { yield return StartCoroutine(BindingTrickersToModel());//以位置区分追踪器 yield break;//结束循环 } } } } } } } /// <summary> /// 确定追踪器对应的关节 /// </summary> /// <param name="devicesIndexArray">存储追踪器的index</param> /// <returns></returns> IEnumerator BindingTrickersToModel() { yield return null; //根据Y,先区分手脚腰 //1、2脚 3腰 4、5手 for (int i = 0; i < orderedList.Count - 1; i++) { for (int j = orderedList.Count - 1; j > i; j--) { float y1 = devicesIndexArray[orderedList[i]].position.y; float y2 = devicesIndexArray[orderedList[j]].position.y; if (y1 > y2) { var temp = orderedList[i]; orderedList[i] = orderedList[j]; orderedList[j] = temp; } } } //水平方向向量 Vector3 footVector = devicesIndexArray[orderedList[0]].position - devicesIndexArray[orderedList[1]].position; footVector.y = 0; Vector3 handVector = devicesIndexArray[orderedList[3]].position - devicesIndexArray[orderedList[4]].position; handVector.y = 0; if (Vector3.Angle(new Vector3(bodyRightTrans.right.x, 0, bodyRightTrans.right.z), footVector) > 90) { //0 右 1 左 Debug.Log("0<-->1"); var temp = orderedList[0]; orderedList[0] = orderedList[1]; orderedList[1] = temp; } if (Vector3.Angle(new Vector3(bodyRightTrans.right.x, 0, bodyRightTrans.right.z), handVector) > 90) { //3 右 4 左 Debug.Log("3<-->4"); var temp = orderedList[3]; orderedList[3] = orderedList[4]; orderedList[4] = temp; } Debug.LogFormat("fr:{0},fl:{1},t:{2},hr:{3},hl:{4}", orderedList[0], orderedList[1], orderedList[2], orderedList[3], orderedList[4]); devicesIndexArray.Clear();//清空字典 }}
阅读全文
1 0
- VR模拟真人动作
- Motion camera 真人动作捕捉器
- c# 模拟键盘动作
- jquery模拟鼠标点击动作
- 外挂编程-动作模拟技术
- Direct3D中模拟机械手动作
- jquery模拟下拉框动作
- monkeyrunner 模拟测试用户动作
- 添加模拟power key 动作
- jquery模拟鼠标点击动作
- JAVA 模拟多用户提交动作
- Python-模拟鼠标键盘动作
- JavaScript模拟手势翻页动作
- 这次是真的带你飞——映墨:国内首家投资拍摄真人实景极限运动VR视频
- VR 触摸板模拟上下左右按键
- 4.5兼模拟卡牌动作和动作组合
- MFC定时器 模拟键盘动作 CreateProcess
- 使用SendInput模拟键盘和鼠标动作
- eclipse中格式化代码快捷键Ctrl+Shift+F失效的解决办法
- Eclipse导入git上的maven web项目
- eclipse中格式化代码快捷键Ctrl+Shift+F失效的解决办法
- 三分钟了解JAVA设计模式之模板方法模式
- 模拟实现C库的memmove和memcpy
- VR模拟真人动作
- session和cookie作用原理,区别
- Kernel TCP连接处理
- yield break 与 yield return
- python3语法之多线程
- php有效防止同一用户多次登录
- 多线程编程基础
- R语言画正态分布
- B