handInfo.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 Quaternion rotation =Quaternion.identity;
  46. public Vector3 position = Vector3.zero;
  47. public Vector3 normal = Vector3.zero;//只能自算,手掌中法向量
  48. public Vector3 right = Vector3.zero;//只能自算,手掌right向量
  49. public Vector3 centerLocalPosition = Vector3.zero;//手掌中心点局部坐标
  50. public Vector3 centerPosition = Vector3.zero;//手掌中心点全局坐标
  51. public float zdeep = 0;
  52. public int findFrameCount = 0;//识别开始后共多少帧,丢失即复位
  53. public int frameCountValid = 10;//丢失后重新识别到frameCountValid帧连续有效才算识别
  54. protected Vector3 deltaOffset=Vector3.zero;
  55. public virtual Vector3 positionOffest {
  56. get {
  57. 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);
  58. }
  59. set {
  60. deltaOffset = value;
  61. }
  62. }
  63. private Vector3 _eulerAnglesOffset = new Vector3(-11,0,0);
  64. public Vector3 eulerAnglesOffset {
  65. get {
  66. //if(ShadowSystem.Instant && ShadowSystem.Instant.Device) {
  67. // return ShadowSystem.Instant.Device.CurrentDevice.RGBRotationOffset;
  68. //}
  69. if(Application.platform == RuntimePlatform.Android) {
  70. return _eulerAnglesOffset;
  71. }
  72. return Vector3.zero;
  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. }
  110. }