handInfo.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. using UnityEngine;
  6. namespace SC.XR.Unity.Module_InputSystem.InputDeviceHand {
  7. public class handInfo {
  8. public handInfo(string configPath) {
  9. if(Application.platform == RuntimePlatform.Android) {
  10. try {
  11. CommonConfig config;
  12. config = new CommonConfig(configPath);
  13. float x = 0, y = 0, z = 0;
  14. string xx = config.GetLineValue(1);
  15. x = float.Parse(xx != null ? xx : "0");
  16. xx = config.GetLineValue(2);
  17. y = float.Parse(xx != null ? xx : "0");
  18. xx = config.GetLineValue(3);
  19. z = float.Parse(xx != null ? xx : "0");
  20. if(x > -10 && x < 10 && y > -10 && y < 10 && z > -10 && z < 10) {
  21. positionOffest = new Vector3(x, y, z);
  22. DebugMy.Log("Read "+ configPath + "" + x + " " + y + " " + z,this,true);
  23. }
  24. config = null;
  25. } catch(Exception e) {
  26. Debug.Log(e);
  27. }
  28. Vector3 data = Vector3.zero;
  29. if (API_Module_SDKConfiguration.HasKey("Module_InputSystem", "GreyHandOffsetX")) {
  30. data.x = API_Module_SDKConfiguration.GetFloat("Module_InputSystem", "GreyHandOffsetX", 0);
  31. data.x = (data.x > -10 && data.x < 10) ? data.x : 0;
  32. }
  33. if (API_Module_SDKConfiguration.HasKey("Module_InputSystem", "GreyHandOffsetY")) {
  34. data.y = API_Module_SDKConfiguration.GetFloat("Module_InputSystem", "GreyHandOffsetY", 0);
  35. data.y = (data.y > -10 && data.y < 10) ? data.y : 0;
  36. }
  37. if (API_Module_SDKConfiguration.HasKey("Module_InputSystem", "GreyHandOffsetZ")) {
  38. data.z = API_Module_SDKConfiguration.GetFloat("Module_InputSystem", "GreyHandOffsetZ", 0);
  39. data.z = (data.z > -10 && data.z < 10) ? data.z : 0;
  40. }
  41. positionOffest = data;
  42. DebugMy.Log("ReadFromConfig positionOffest: " + "X:" + data.x + " Y:" + data.y + " Z:" + data.z, this, true);
  43. }
  44. }
  45. public Vector3[] handVertices = new Vector3[778];
  46. public int[] handTriangles;
  47. public Quaternion rotation =Quaternion.identity;
  48. public Vector3 position = Vector3.zero;
  49. public Vector3 normal = Vector3.zero;//只能自算,手掌中法向量
  50. public Vector3 right = Vector3.zero;//只能自算,手掌right向量
  51. public Vector3 up = Vector3.zero;//只能自算,手掌up向量
  52. public Vector3 centerPosition = Vector3.zero;//手掌中心点全局坐标
  53. public Quaternion centerRotation = Quaternion.identity;//手掌中心点全局旋转
  54. public Vector3 MainGrabPosition;
  55. public Quaternion MainGrabRotation;
  56. public Vector3 MainTouchDetectCenterPosition;
  57. public float zdeep = 0;
  58. public int findFrameCount = 0;//识别开始后共多少帧,丢失即复位
  59. public int frameCountValid = 10;//丢失后重新识别到frameCountValid帧连续有效才算识别
  60. protected Vector3 deltaOffset=Vector3.zero;
  61. public virtual Vector3 positionOffest {
  62. get {
  63. return deltaOffset;//new Vector3(0.05f, 0.00f, 0.14f) + new Vector3(-0.025f, 0.00f, -0.14f) + Vector3.forward * zdeep + deltaOffset;//摄像头向下15度 //new Vector3(0, 0, 0.25f);z正常机器// new Vector3(0.280f,-0.10f,0f);
  64. }
  65. set {
  66. deltaOffset = value;
  67. }
  68. }
  69. private Vector3 _eulerAnglesOffset = new Vector3(0,0,0);
  70. public Vector3 eulerAnglesOffset {
  71. get {
  72. return _eulerAnglesOffset;
  73. }
  74. }
  75. public Vector3 localPosition = Vector3.zero;
  76. public bool isLost = false;//是否丢失手
  77. public float lostPercent = 0;//丢失的比例 0 - 1 范围
  78. public float lostTimer = 0.8f;//多久没识别到算丢失
  79. public Vector3 trend = Vector3.zero;//手势的趋势 食指指尖
  80. //[MarshalAs(UnmanagedType.ByValArray, SizeConst = 21, ArraySubType = UnmanagedType.Struct)]
  81. //public Vector3[] fingerPos = new Vector3[21];
  82. public fingerInfo[] finger = new fingerInfo[5] {
  83. new fingerInfo(){
  84. joint = new jointInfo[4]{
  85. new jointInfo(),new jointInfo(),new jointInfo(),new jointInfo(),
  86. }
  87. },
  88. new fingerInfo(){
  89. joint = new jointInfo[4]{
  90. new jointInfo(),new jointInfo(),new jointInfo(),new jointInfo(),
  91. }
  92. },
  93. new fingerInfo(){
  94. joint = new jointInfo[4]{
  95. new jointInfo(),new jointInfo(),new jointInfo(),new jointInfo(),
  96. }
  97. },
  98. new fingerInfo(){
  99. joint = new jointInfo[4]{
  100. new jointInfo(),new jointInfo(),new jointInfo(),new jointInfo(),
  101. }
  102. },
  103. new fingerInfo(){
  104. joint = new jointInfo[5]{
  105. new jointInfo(),new jointInfo(),new jointInfo(),new jointInfo(),new jointInfo(),
  106. }
  107. },
  108. };
  109. jointInfo emptyJoint = new jointInfo();
  110. public jointInfo GetJoint(FINGER finger,JOINT joint) {
  111. if (this.finger.Length >= (int)finger && this.finger[(int)finger].joint.Length >= (int)joint) {
  112. return this.finger[(int)finger].joint[(int)joint];
  113. }
  114. DebugMy.LogError("Joint index Error!",this);
  115. return emptyJoint;
  116. }
  117. /// <summary>
  118. /// 256 float
  119. /// </summary>
  120. public class Iv_velinfo {
  121. public float predict_time; //1
  122. public float timestamp; //1
  123. public float[] vel = new float[63]; // 2*63
  124. public float[] reserve = new float[128];//128
  125. }
  126. public Iv_velinfo iv_Velinfo = new Iv_velinfo();
  127. /// <summary>
  128. /// 512 float
  129. /// </summary>
  130. public class Iv_extinfo {
  131. public float ges_static_size;//1
  132. public float[] ges_static = new float[8];//8
  133. public float ges_dynamic_size;//1
  134. public float[] ges_dynamic = new float[8];//8
  135. public float[] output_info = new float[494];//494
  136. }
  137. public Iv_extinfo iv_extinfo = new Iv_extinfo();
  138. }
  139. }