OvrIK.cs 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using RootMotion.FinalIK;
  7. using UnityEngine;
  8. using wf;
  9. public class OvrIK : MonoBehaviour
  10. {
  11. public OvrIK()
  12. {
  13. Quaternion[,] array = new Quaternion[4, 15];
  14. array[0, 0] = new Quaternion(1.379457E-08f, -1.907173E-10f, -0.1001217f, 0.9949752f);
  15. array[0, 1] = new Quaternion(-3.348364E-08f, -2.288052E-09f, -0.05697599f, 0.9983756f);
  16. array[0, 2] = new Quaternion(0.4853954f, -0.1902075f, 0.1155978f, 0.8454878f);
  17. array[0, 3] = new Quaternion(-2.555888E-09f, 1.190041E-09f, -0.08838178f, 0.9960867f);
  18. array[0, 4] = new Quaternion(-3.708266E-09f, -4.232382E-11f, -0.1423017f, 0.9898233f);
  19. array[0, 5] = new Quaternion(0.005196964f, -0.009313619f, -0.07643344f, 0.9970177f);
  20. array[0, 6] = new Quaternion(1.469708E-09f, -2.337872E-09f, -0.08838177f, 0.9960867f);
  21. array[0, 7] = new Quaternion(-4.677417E-09f, -1.311283E-08f, -0.1086997f, 0.9940746f);
  22. array[0, 8] = new Quaternion(-0.001879324f, -0.005337666f, -0.0991221f, 0.9950592f);
  23. array[0, 9] = new Quaternion(-8.490085E-09f, -1.805363E-09f, -0.0796621f, 0.9968219f);
  24. array[0, 10] = new Quaternion(2.300491E-09f, 3.334659E-09f, -0.1239805f, 0.9922847f);
  25. array[0, 11] = new Quaternion(-0.006921342f, 0.001893361f, -0.09829046f, 0.9951319f);
  26. array[0, 12] = new Quaternion(-5.701029E-09f, -1.521331E-09f, -0.05449884f, 0.9985139f);
  27. array[0, 13] = new Quaternion(3.803335E-09f, -5.725684E-09f, -0.1423017f, 0.9898233f);
  28. array[0, 14] = new Quaternion(-0.01357147f, 0.02850812f, -0.08513741f, 0.9958689f);
  29. array[1, 0] = new Quaternion(6.932151E-09f, -2.730647E-09f, -0.3665012f, 0.9304176f);
  30. array[1, 1] = new Quaternion(-1.952852E-08f, -2.699741E-08f, -0.1618618f, 0.9868135f);
  31. array[1, 2] = new Quaternion(0.7708589f, -0.2672266f, 0.03713043f, 0.577051f);
  32. array[1, 3] = new Quaternion(9.870518E-10f, 1.579613E-09f, -0.5299194f, 0.8480481f);
  33. array[1, 4] = new Quaternion(-5.034789E-09f, -5.799267E-09f, -0.8191521f, 0.5735765f);
  34. array[1, 5] = new Quaternion(0.0478053f, -0.01974053f, -0.5880075f, 0.8072003f);
  35. array[1, 6] = new Quaternion(8.812074E-09f, -1.401741E-08f, -0.5299194f, 0.8480481f);
  36. array[1, 7] = new Quaternion(-1.043265E-08f, 1.477225E-09f, -0.7992581f, 0.6009881f);
  37. array[1, 8] = new Quaternion(-0.009090314f, -0.01649067f, -0.6061373f, 0.7951371f);
  38. array[1, 9] = new Quaternion(-2.784401E-08f, 1.160059E-08f, -0.5224781f, 0.8526527f);
  39. array[1, 10] = new Quaternion(1.204624E-08f, 8.771129E-09f, -0.8084095f, 0.5886205f);
  40. array[1, 11] = new Quaternion(-0.04368013f, 0.007996441f, -0.6048046f, 0.7951349f);
  41. array[1, 12] = new Quaternion(-3.325827E-08f, 2.027481E-09f, -0.5008097f, 0.8655574f);
  42. array[1, 13] = new Quaternion(4.887594E-09f, -3.295959E-08f, -0.8191521f, 0.5735765f);
  43. array[1, 14] = new Quaternion(-0.09800828f, 0.05454942f, -0.591058f, 0.7987924f);
  44. array[2, 0] = new Quaternion(-1.299039E-08f, 7.939377E-10f, -0.08632442f, 0.9962671f);
  45. array[2, 1] = new Quaternion(-1.412307E-08f, -4.882294E-09f, -0.05340298f, 0.9985731f);
  46. array[2, 2] = new Quaternion(-0.4710969f, 0.1764064f, 0.1206711f, 0.8557962f);
  47. array[2, 3] = new Quaternion(-1.785701E-09f, -1.246846E-08f, -0.06366991f, 0.9979711f);
  48. array[2, 4] = new Quaternion(-5.778726E-11f, -1.242248E-08f, -0.1014653f, 0.9948391f);
  49. array[2, 5] = new Quaternion(-0.002611603f, 0.001185287f, -0.04763259f, 0.9988608f);
  50. array[2, 6] = new Quaternion(1.790176E-09f, -1.245129E-08f, -0.0636699f, 0.9979711f);
  51. array[2, 7] = new Quaternion(5.652268E-09f, 1.780454E-09f, -0.06771687f, 0.9977046f);
  52. array[2, 8] = new Quaternion(0.001466242f, 0.004677885f, -0.07036161f, 0.9975095f);
  53. array[2, 9] = new Quaternion(7.64029E-09f, 7.058498E-09f, -0.05493468f, 0.99849f);
  54. array[2, 10] = new Quaternion(-2.104634E-09f, -7.598384E-09f, -0.08305829f, 0.9965447f);
  55. array[2, 11] = new Quaternion(0.004817214f, 0.003811401f, -0.0695642f, 0.9975586f);
  56. array[2, 12] = new Quaternion(2.864904E-09f, -1.440215E-08f, -0.02973721f, 0.9995578f);
  57. array[2, 13] = new Quaternion(-7.071282E-10f, -5.241497E-09f, -0.1014653f, 0.9948391f);
  58. array[2, 14] = new Quaternion(0.00861063f, -0.01516612f, -0.05657673f, 0.998246f);
  59. array[3, 0] = new Quaternion(7.66758E-09f, -1.102812E-08f, -0.3665012f, 0.9304176f);
  60. array[3, 1] = new Quaternion(-8.709043E-09f, -7.065411E-09f, -0.1618618f, 0.9868135f);
  61. array[3, 2] = new Quaternion(-0.7708589f, 0.2672265f, 0.03713048f, 0.577051f);
  62. array[3, 3] = new Quaternion(-8.292553E-09f, 7.889813E-10f, -0.5299194f, 0.8480481f);
  63. array[3, 4] = new Quaternion(6.103158E-09f, 4.273478E-09f, -0.8191521f, 0.5735765f);
  64. array[3, 5] = new Quaternion(-0.0478053f, 0.01974053f, -0.5880075f, 0.8072003f);
  65. array[3, 6] = new Quaternion(-1.288366E-08f, 7.501511E-09f, -0.5299194f, 0.8480481f);
  66. array[3, 7] = new Quaternion(1.786481E-08f, 1.343313E-08f, -0.7992581f, 0.6009881f);
  67. array[3, 8] = new Quaternion(0.009090304f, 0.01649068f, -0.6061373f, 0.7951371f);
  68. array[3, 9] = new Quaternion(1.513849E-08f, -3.815058E-09f, -0.5224782f, 0.8526527f);
  69. array[3, 10] = new Quaternion(-1.643181E-08f, -2.748009E-09f, -0.8084095f, 0.5886205f);
  70. array[3, 11] = new Quaternion(0.04368011f, -0.007996418f, -0.6048046f, 0.7951349f);
  71. array[3, 12] = new Quaternion(1.196498E-08f, -9.074872E-09f, -0.5008097f, 0.8655574f);
  72. array[3, 13] = new Quaternion(-4.887593E-09f, 3.295959E-08f, -0.8191521f, 0.5735765f);
  73. array[3, 14] = new Quaternion(0.09800829f, -0.0545494f, -0.5910579f, 0.7987924f);
  74. this.m_aryHandRot = array;
  75. this.m_listDefaultPose = new List<KeyValuePair<Transform, Transform>>();
  76. this.m_vPelvisPosOffs = Vector3.zero;
  77. this.m_vPelvisRotOffs = Vector3.zero;
  78. this.m_listTrackerMeshRnder = new List<MeshRenderer>();
  79. this.m_fEyeToCamThresholdAngle = -0.9f;
  80. this.m_bEyeTocam = true;
  81. this.offsy = -0.06f;
  82. this.m_nShincho = -1;
  83. this.m_nDouPer = -1;
  84. this.m_nKubiScl = -1;
  85. base..ctor();
  86. }
  87. public static OvrIK Instance
  88. {
  89. get
  90. {
  91. return OvrIK.m_this;
  92. }
  93. }
  94. public static bool IsVRIKMode
  95. {
  96. get
  97. {
  98. return OvrIK.m_this != null && (OvrIK.IsModeVRIK || OvrIK.m_coCalibrate != null);
  99. }
  100. }
  101. public static bool IsModeVRIK { get; set; }
  102. private void DefaultPose()
  103. {
  104. string[] array = new string[]
  105. {
  106. "Bip01",
  107. "Bip01 Pelvis",
  108. "Bip01 Spine",
  109. "Bip01 Spine0a",
  110. "Bip01 Spine1",
  111. "Bip01 Spine1a",
  112. "Bip01 Neck",
  113. "Bip01 Head",
  114. "Bip01 L Clavicle",
  115. "Bip01 L UpperArm",
  116. "Bip01 L Forearm",
  117. "Bip01 L Hand",
  118. "Bip01 L Finger0",
  119. "Bip01 L Finger01",
  120. "Bip01 L Finger02",
  121. "Bip01 L Finger1",
  122. "Bip01 L Finger11",
  123. "Bip01 L Finger12",
  124. "Bip01 L Finger2",
  125. "Bip01 L Finger21",
  126. "Bip01 L Finger22",
  127. "Bip01 L Finger3",
  128. "Bip01 L Finger31",
  129. "Bip01 L Finger32",
  130. "Bip01 L Finger4",
  131. "Bip01 L Finger41",
  132. "Bip01 L Finger42",
  133. "Bip01 R Clavicle",
  134. "Bip01 R UpperArm",
  135. "Bip01 R Forearm",
  136. "Bip01 R Hand",
  137. "Bip01 R Finger0",
  138. "Bip01 R Finger01",
  139. "Bip01 R Finger02",
  140. "Bip01 R Finger1",
  141. "Bip01 R Finger11",
  142. "Bip01 R Finger12",
  143. "Bip01 R Finger2",
  144. "Bip01 R Finger21",
  145. "Bip01 R Finger22",
  146. "Bip01 R Finger3",
  147. "Bip01 R Finger31",
  148. "Bip01 R Finger32",
  149. "Bip01 R Finger4",
  150. "Bip01 R Finger41",
  151. "Bip01 R Finger42",
  152. "Bip01 L Thigh",
  153. "Bip01 L Calf",
  154. "Bip01 L Foot",
  155. "Bip01 L Toe2",
  156. "Bip01 L Toe21",
  157. "Bip01 L Toe1",
  158. "Bip01 L Toe11",
  159. "Bip01 L Toe0",
  160. "Bip01 L Toe01",
  161. "Bip01 R Thigh",
  162. "Bip01 R Calf",
  163. "Bip01 R Foot",
  164. "Bip01 R Toe2",
  165. "Bip01 R Toe21",
  166. "Bip01 R Toe1",
  167. "Bip01 R Toe11",
  168. "Bip01 R Toe0",
  169. "Bip01 R Toe01"
  170. };
  171. this.m_maid.body0.m_Bones.transform.position = Vector3.zero;
  172. this.m_maid.body0.m_Bones.transform.rotation = Quaternion.identity;
  173. foreach (string text in array)
  174. {
  175. Transform transform = CMT.SearchObjName(this.m_maid.body0.m_Bones2.transform, text, true);
  176. Transform transform2 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, text, true);
  177. if (transform != null && transform2 != null)
  178. {
  179. transform2.localRotation = transform.localRotation;
  180. if (text == "Bip01")
  181. {
  182. transform2.localPosition = transform.localPosition;
  183. }
  184. }
  185. }
  186. Transform transform3 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Thigh", true);
  187. transform3.localRotation = Quaternion.Euler(4.194572f, 175.3248f, -30.72415f);
  188. Transform transform4 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Calf", true);
  189. transform4.localRotation = Quaternion.Euler(-4.30072f, -1.857178f, 27.6982f);
  190. Transform transform5 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Thigh", true);
  191. transform5.localRotation = Quaternion.Euler(2.152464f, -178.752f, -30.914f);
  192. Transform transform6 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Calf", true);
  193. transform6.localRotation = Quaternion.Euler(-4.30072f, 1.857178f, 27.6982f);
  194. }
  195. public Maid NowMaid
  196. {
  197. get
  198. {
  199. return this.m_maid;
  200. }
  201. }
  202. public Transform EyeTargetTrs
  203. {
  204. get
  205. {
  206. return this.m_trEyeTarget;
  207. }
  208. }
  209. public bool EyeToCam
  210. {
  211. get
  212. {
  213. return this.m_bEyeTocam;
  214. }
  215. set
  216. {
  217. this.m_bEyeTocam = value;
  218. }
  219. }
  220. public static ControllerShortcutWindow CreateUI()
  221. {
  222. if (OvrIK.m_goVRIKConfigUI == null)
  223. {
  224. UnityEngine.Object original = Resources.Load("OVR/CircleCommandUI/Parent Controller Shortcut Setter Window");
  225. OvrIK.m_goVRIKConfigUI = (UnityEngine.Object.Instantiate(original) as GameObject);
  226. GameObject gameObject = GameObject.Find("SystemUI Root");
  227. OvrIK.m_goVRIKConfigUI.transform.SetParent(gameObject.transform, false);
  228. }
  229. if (OvrIK.m_VRIKConfigCompo == null)
  230. {
  231. OvrIK.m_VRIKConfigCompo = OvrIK.m_goVRIKConfigUI.GetComponent<ControllerShortcutWindow>();
  232. }
  233. return OvrIK.m_VRIKConfigCompo;
  234. }
  235. public static void InitStart()
  236. {
  237. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
  238. if (maid != null)
  239. {
  240. OvrIK.m_this = maid.gameObject.GetComponent<OvrIK>();
  241. if (OvrIK.m_this == null)
  242. {
  243. OvrIK.m_this = maid.gameObject.AddComponent<OvrIK>();
  244. }
  245. if (!OvrIK.IsVRIKMode)
  246. {
  247. OvrIK.m_this.CalibrationStart();
  248. }
  249. }
  250. }
  251. public static void UninitEnd()
  252. {
  253. if (OvrIK.m_this != null)
  254. {
  255. OvrIK.m_this.Finish();
  256. }
  257. }
  258. public void CalibrationStart()
  259. {
  260. if (OvrIK.m_coCalibrate == null)
  261. {
  262. if (!this.Init())
  263. {
  264. return;
  265. }
  266. OvrIK.m_coCalibrate = base.StartCoroutine(this.CoCalibrate());
  267. }
  268. }
  269. private IEnumerator CoCalibrate()
  270. {
  271. yield return new WaitForSeconds(5f);
  272. this.Calibration();
  273. OvrIK.m_coCalibrate = null;
  274. yield break;
  275. }
  276. public void Finish()
  277. {
  278. if (OvrIK.m_coCalibrate != null)
  279. {
  280. base.StopCoroutine(OvrIK.m_coCalibrate);
  281. OvrIK.m_coCalibrate = null;
  282. }
  283. this.Uninit(true);
  284. }
  285. public void SelfShotCam()
  286. {
  287. if (this.m_coSelfShotCam != null)
  288. {
  289. this.m_coSelfShotCam.StartCountSnap();
  290. }
  291. }
  292. private void Uninit(bool bDestroyVRIKConfigUI = true)
  293. {
  294. OvrIK.IsModeVRIK = false;
  295. if (this.m_maid != null)
  296. {
  297. this.m_ik = this.m_maid.gameObject.GetComponent<VRIK>();
  298. if (this.m_ik != null)
  299. {
  300. UnityEngine.Object.Destroy(this.m_ik);
  301. Vector3 vector = GameMain.Instance.OvrMgr.OvrCamera.GetPos();
  302. vector += this.m_maid.transform.forward;
  303. GameMain.Instance.OvrMgr.OvrCamera.SetPos(vector);
  304. }
  305. this.m_ik = null;
  306. GameMain.Instance.OvrMgr.OvrCamera.HandVRIKMode = false;
  307. GameObject obj = this.m_maid.body0.GetSlot(1).obj;
  308. this.LayerCheck(obj, LayerMask.NameToLayer("Charactor"));
  309. GameObject obj2 = this.m_maid.body0.GetSlot(36).obj;
  310. this.LayerCheck(obj2, LayerMask.NameToLayer("Charactor"));
  311. GameObject obj3 = this.m_maid.body0.GetSlot(17).obj;
  312. this.LayerCheck(obj3, LayerMask.NameToLayer("Charactor"));
  313. Animation componentInChildren = this.m_maid.GetComponentInChildren<Animation>();
  314. if (componentInChildren != null)
  315. {
  316. componentInChildren.enabled = true;
  317. }
  318. if (this.m_aryBackAMTween != null)
  319. {
  320. foreach (AMTween amtween in this.m_aryBackAMTween)
  321. {
  322. if (amtween != null)
  323. {
  324. amtween.enabled = true;
  325. }
  326. }
  327. this.m_aryBackAMTween = null;
  328. }
  329. this.m_maid.boOffsetY = true;
  330. this.m_maid.SetMicLipSync(false);
  331. this.m_maid.SetPos(this.m_vBackPos);
  332. this.m_maid.SetRot(this.m_vBackRot);
  333. this.m_maid.body0.m_Bones.transform.localPosition = this.m_vBackRootPos;
  334. this.m_maid.body0.m_Bones.transform.localRotation = this.m_qBackRootRot;
  335. this.m_maid.SetAutoTwist(Maid.AutoTwist.ShoulderL, this.m_bBackAutoTwistShoulderL);
  336. this.m_maid.SetAutoTwist(Maid.AutoTwist.ShoulderR, this.m_bBackAutoTwistShoulderR);
  337. this.m_maid.SetAutoTwist(Maid.AutoTwist.WristL, this.m_bBackAutoTwistWristL);
  338. this.m_maid.SetAutoTwist(Maid.AutoTwist.WristR, this.m_bBackAutoTwistWristR);
  339. this.m_maid.SetAutoTwist(Maid.AutoTwist.ThighL, this.m_bBackAutoTwistThighL);
  340. this.m_maid.SetAutoTwist(Maid.AutoTwist.ThighR, this.m_bBackAutoTwistThighR);
  341. MaidColliderCollect.SuspendColliderAll(this.m_maid, true);
  342. this.m_maid.EyeToCamera(Maid.EyeMoveType.目と顔を向ける, 0f);
  343. this.m_maid = null;
  344. }
  345. this.m_listTrackerMeshRnder.Clear();
  346. this.m_listDefaultPose.Clear();
  347. if (this.m_goDefaultPoseParent != null)
  348. {
  349. UnityEngine.Object.Destroy(this.m_goDefaultPoseParent);
  350. }
  351. if (this.m_goIKTargetParent != null)
  352. {
  353. UnityEngine.Object.Destroy(this.m_goIKTargetParent);
  354. }
  355. if (this.m_trTargetOffsHead != null)
  356. {
  357. UnityEngine.Object.Destroy(this.m_trTargetOffsHead.gameObject);
  358. }
  359. if (this.m_trTargetOffsPelvis != null)
  360. {
  361. UnityEngine.Object.Destroy(this.m_trTargetOffsPelvis.gameObject);
  362. }
  363. if (this.m_trTargetOffsHandL != null)
  364. {
  365. UnityEngine.Object.Destroy(this.m_trTargetOffsHandL.gameObject);
  366. }
  367. if (this.m_trTargetOffsHandR != null)
  368. {
  369. UnityEngine.Object.Destroy(this.m_trTargetOffsHandR.gameObject);
  370. }
  371. if (this.m_trTargetOffsFootL != null)
  372. {
  373. UnityEngine.Object.Destroy(this.m_trTargetOffsFootL.gameObject);
  374. }
  375. if (this.m_trTargetOffsFootR != null)
  376. {
  377. UnityEngine.Object.Destroy(this.m_trTargetOffsFootR.gameObject);
  378. }
  379. if (this.m_trTargetOffsHeadTracker != null)
  380. {
  381. UnityEngine.Object.Destroy(this.m_trTargetOffsHeadTracker.gameObject);
  382. }
  383. if (this.m_self_shot_cam != null)
  384. {
  385. UnityEngine.Object.Destroy(this.m_self_shot_cam);
  386. }
  387. if (this.m_goMoni != null)
  388. {
  389. UnityEngine.Object.Destroy(this.m_goMoni);
  390. }
  391. if (this.m_FaceCompoL != null)
  392. {
  393. UnityEngine.Object.Destroy(this.m_FaceCompoL);
  394. }
  395. if (this.m_FaceCompoR != null)
  396. {
  397. UnityEngine.Object.Destroy(this.m_FaceCompoR);
  398. }
  399. if (this.m_coHandSignL != null)
  400. {
  401. UnityEngine.Object.Destroy(this.m_coHandSignL);
  402. }
  403. if (this.m_coHandSignR != null)
  404. {
  405. UnityEngine.Object.Destroy(this.m_coHandSignR);
  406. }
  407. if (this.m_coOtherCmdL != null)
  408. {
  409. UnityEngine.Object.Destroy(this.m_coOtherCmdL);
  410. }
  411. if (this.m_coOtherCmdR != null)
  412. {
  413. UnityEngine.Object.Destroy(this.m_coOtherCmdR);
  414. }
  415. if (bDestroyVRIKConfigUI && OvrIK.m_goVRIKConfigUI != null)
  416. {
  417. UnityEngine.Object.Destroy(OvrIK.m_goVRIKConfigUI);
  418. }
  419. GameMain.Instance.OvrMgr.OvrCamera.HandModelVisible = true;
  420. GameMain.Instance.OvrMgr.OvrCamera.SetCameraMask(CameraMain.CameraMask.OvrTouchLookObj, false);
  421. }
  422. private bool Init()
  423. {
  424. this.Uninit(false);
  425. this.m_maid = base.GetComponent<Maid>();
  426. NDebug.Assert(this.m_maid != null, "メイドが居ません。");
  427. if (!this.m_maid.Visible || this.m_maid.IsBusy || !this.m_maid.body0.isLoadedBody)
  428. {
  429. Debug.Log("OVRIK 未だメイドの準備ができていません。");
  430. return false;
  431. }
  432. Animation componentInChildren = this.m_maid.GetComponentInChildren<Animation>();
  433. componentInChildren.enabled = false;
  434. this.m_aryBackAMTween = this.m_maid.GetComponentsInChildren<AMTween>(true);
  435. if (this.m_aryBackAMTween != null)
  436. {
  437. foreach (AMTween amtween in this.m_aryBackAMTween)
  438. {
  439. if (amtween != null)
  440. {
  441. amtween.enabled = false;
  442. }
  443. }
  444. }
  445. this.m_bBackAutoTwistShoulderL = this.m_maid.body0.boAutoTwistShoulderL;
  446. this.m_bBackAutoTwistShoulderR = this.m_maid.body0.boAutoTwistShoulderR;
  447. this.m_bBackAutoTwistWristL = this.m_maid.body0.boAutoTwistWristL;
  448. this.m_bBackAutoTwistWristR = this.m_maid.body0.boAutoTwistWristR;
  449. this.m_bBackAutoTwistThighL = this.m_maid.body0.boAutoTwistThighL;
  450. this.m_bBackAutoTwistThighR = this.m_maid.body0.boAutoTwistThighR;
  451. this.m_maid.SetAutoTwistAll(true);
  452. this.m_vBackPos = this.m_maid.GetPos();
  453. this.m_vBackRot = this.m_maid.GetRot();
  454. this.m_vBackRootPos = this.m_maid.body0.m_Bones.transform.localPosition;
  455. this.m_qBackRootRot = this.m_maid.body0.m_Bones.transform.localRotation;
  456. this.m_maid.EyeToCamera(Maid.EyeMoveType.無し, 0f);
  457. this.m_maid.boOffsetY = false;
  458. this.DefaultPose();
  459. this.m_maid.SetPos(Vector3.zero);
  460. this.m_maid.SetRot(Vector3.zero);
  461. this.m_maid.SetMicLipSync(true);
  462. Transform transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Thigh", true);
  463. Quaternion localRotation = transform.localRotation;
  464. transform.localRotation = Quaternion.Euler(5.025288f, -179.97f, -9.849731f);
  465. Transform transform2 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Calf", true);
  466. Quaternion localRotation2 = transform2.localRotation;
  467. transform2.localRotation = Quaternion.Euler(-4.30072f, -1.857178f, 2.579935f);
  468. Transform transform3 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Thigh", true);
  469. Quaternion localRotation3 = transform3.localRotation;
  470. transform3.localRotation = Quaternion.Euler(5.025289f, -179.97f, -9.849731f);
  471. Transform transform4 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Calf", true);
  472. Quaternion localRotation4 = transform4.localRotation;
  473. transform4.localRotation = Quaternion.Euler(-4.30072f, 1.857178f, 2.579935f);
  474. Transform transform5 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Foot", true);
  475. this.m_maid.transform.position = new Vector3(0f, this.m_maid.transform.position.y - transform5.position.y + 0.13f, 0f);
  476. transform.localRotation = localRotation;
  477. transform2.localRotation = localRotation2;
  478. transform3.localRotation = localRotation3;
  479. transform4.localRotation = localRotation4;
  480. Transform t = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Hand", true);
  481. Transform t2 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Hand", true);
  482. this.m_trHandL = new Transform[this.m_strHandBoneNameL.Length];
  483. this.m_trHandR = new Transform[this.m_strHandBoneNameR.Length];
  484. for (int j = 0; j < this.m_strHandBoneNameL.Length; j++)
  485. {
  486. this.m_trHandL[j] = CMT.SearchObjName(t, this.m_strHandBoneNameL[j], true);
  487. this.m_trHandR[j] = CMT.SearchObjName(t2, this.m_strHandBoneNameR[j], true);
  488. }
  489. return true;
  490. }
  491. private void FindAndAddParent(Transform trChild, string f_strStopBone, bool f_bParentConnect = false)
  492. {
  493. if (trChild.name == f_strStopBone)
  494. {
  495. return;
  496. }
  497. GameObject gameObject = new GameObject(trChild.name);
  498. gameObject.transform.position = trChild.position;
  499. gameObject.transform.rotation = trChild.rotation;
  500. if (this.m_listDefaultPose.Count != 0 && f_bParentConnect)
  501. {
  502. this.m_listDefaultPose[this.m_listDefaultPose.Count - 1].Value.SetParent(gameObject.transform);
  503. }
  504. this.m_listDefaultPose.Add(new KeyValuePair<Transform, Transform>(trChild, gameObject.transform));
  505. if (trChild.parent != null)
  506. {
  507. this.FindAndAddParent(trChild.parent, f_strStopBone, true);
  508. }
  509. }
  510. private void LayerCheck(GameObject goParent, int nLayer)
  511. {
  512. if (goParent == null)
  513. {
  514. return;
  515. }
  516. try
  517. {
  518. for (int i = 0; i < goParent.transform.childCount; i++)
  519. {
  520. this.LayerCheck(goParent.transform.GetChild(i).gameObject, nLayer);
  521. }
  522. goParent.layer = nLayer;
  523. }
  524. catch (Exception message)
  525. {
  526. Debug.LogError(message);
  527. }
  528. }
  529. private void Calibration()
  530. {
  531. OvrIK.IsModeVRIK = true;
  532. MaidColliderCollect.SuspendColliderAll(this.m_maid, false);
  533. this.m_ik = this.m_maid.gameObject.GetComponent<VRIK>();
  534. if (this.m_ik == null)
  535. {
  536. this.m_ik = this.m_maid.gameObject.AddComponent<VRIK>();
  537. }
  538. OvrIK.m_conf = OvrIK.m_conf.Read();
  539. OvrIK.m_conf.Update(this.m_ik);
  540. this.m_fEyeToCamThresholdAngle = OvrIK.m_conf.m_fEyeToCamThresholdAngle;
  541. VRIK.References references = this.m_ik.references;
  542. string text = "Bip01";
  543. if (this.m_maid.boMAN)
  544. {
  545. text = "ManBip";
  546. }
  547. references.root = this.m_maid.body0.m_Bones.transform;
  548. references.pelvis = references.root.Find(text);
  549. references.spine = this.m_maid.body0.Spine;
  550. references.chest = this.m_maid.body0.Spine1a;
  551. references.neck = this.m_maid.body0.trsNeck;
  552. references.head = this.m_maid.body0.trsHead;
  553. references.leftShoulder = this.m_maid.body0.ClavicleL;
  554. references.leftUpperArm = this.m_maid.body0.UpperArmL;
  555. references.leftForearm = references.leftUpperArm.Find(text + " L Forearm");
  556. references.leftHand = references.leftForearm.Find(text + " L Hand");
  557. references.rightShoulder = this.m_maid.body0.ClavicleR;
  558. references.rightUpperArm = this.m_maid.body0.UpperArmR;
  559. references.rightForearm = references.rightUpperArm.Find(text + " R Forearm");
  560. references.rightHand = references.rightForearm.Find(text + " R Hand");
  561. references.leftThigh = this.m_maid.body0.Thigh_L;
  562. references.leftCalf = this.m_maid.body0.Calf_L;
  563. references.leftFoot = references.leftCalf.Find(text + " L Foot");
  564. references.rightThigh = this.m_maid.body0.Thigh_R;
  565. references.rightCalf = this.m_maid.body0.Calf_R;
  566. references.rightFoot = references.rightCalf.Find(text + " R Foot");
  567. this.m_ik.solver.leftLeg.positionWeight = 1f;
  568. this.m_ik.solver.leftLeg.rotationWeight = 1f;
  569. this.m_ik.solver.leftLeg.bendGoalWeight = 1f;
  570. this.m_ik.solver.rightLeg.positionWeight = 1f;
  571. this.m_ik.solver.rightLeg.rotationWeight = 1f;
  572. this.m_ik.solver.rightLeg.bendGoalWeight = 1f;
  573. this.m_ik.solver.plantFeet = false;
  574. if (this.m_goIKTargetParent != null)
  575. {
  576. UnityEngine.Object.Destroy(this.m_goIKTargetParent);
  577. }
  578. this.m_goIKTargetParent = new GameObject("VRIK Dummy Targets");
  579. Transform transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 Head", true);
  580. this.m_trTargetOffsHead = new GameObject("VRIK Target Offs Head").transform;
  581. this.m_trTargetOffsHead.position = transform.position;
  582. this.m_trTargetOffsHead.rotation = transform.rotation;
  583. this.m_trTargetOffsHead.SetParent(this.m_goIKTargetParent.transform, true);
  584. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01", true);
  585. this.m_trTargetOffsPelvis = new GameObject("VRIK Target Offs Pelvis").transform;
  586. this.m_trTargetOffsPelvis.position = transform.position;
  587. this.m_trTargetOffsPelvis.rotation = transform.rotation;
  588. this.m_trTargetOffsPelvis.SetParent(this.m_goIKTargetParent.transform, true);
  589. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Hand", true);
  590. this.m_trTargetOffsHandL = new GameObject("VRIK Target Offs Hand L").transform;
  591. this.m_trTargetOffsHandL.position = transform.position;
  592. this.m_trTargetOffsHandL.rotation = transform.rotation;
  593. this.m_trTargetOffsHandL.SetParent(this.m_goIKTargetParent.transform, true);
  594. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Hand", true);
  595. this.m_trTargetOffsHandR = new GameObject("VRIK Target Offs Hand R").transform;
  596. this.m_trTargetOffsHandR.position = transform.position;
  597. this.m_trTargetOffsHandR.rotation = transform.rotation;
  598. this.m_trTargetOffsHandR.SetParent(this.m_goIKTargetParent.transform, true);
  599. this.m_ik.solver.spine.headTarget = this.m_trTargetOffsHead;
  600. this.m_ik.solver.spine.pelvisTarget = this.m_trTargetOffsPelvis;
  601. this.m_ik.solver.leftArm.target = this.m_trTargetOffsHandL;
  602. this.m_ik.solver.rightArm.target = this.m_trTargetOffsHandR;
  603. this.m_ik.solver.spine.pelvisPositionOffset = this.m_vPelvisPosOffs;
  604. this.m_ik.solver.spine.pelvisRotationOffset = Quaternion.Euler(this.m_vPelvisRotOffs);
  605. this.m_ik.solver.spine.pelvisPositionWeight = 0f;
  606. this.m_ik.solver.spine.headClampWeight = 0f;
  607. this.m_ik.solver.spine.chestRotationWeight = 0.3f;
  608. this.m_ik.solver.spine.chestClampWeight = 0.5f;
  609. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Foot", true);
  610. this.m_trTargetOffsFootL = new GameObject("VRIK Target Offs Foot L").transform;
  611. this.m_trTargetOffsFootL.position = transform.position;
  612. this.m_trTargetOffsFootL.rotation = transform.rotation;
  613. this.m_trTargetOffsFootL.SetParent(this.m_goIKTargetParent.transform, true);
  614. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Foot", true);
  615. this.m_trTargetOffsFootR = new GameObject("VRIK Target Offs Foot R").transform;
  616. this.m_trTargetOffsFootR.position = transform.position;
  617. this.m_trTargetOffsFootR.rotation = transform.rotation;
  618. this.m_trTargetOffsFootR.SetParent(this.m_goIKTargetParent.transform, true);
  619. this.m_ik.solver.leftLeg.target = this.m_trTargetOffsFootL;
  620. this.m_ik.solver.rightLeg.target = this.m_trTargetOffsFootR;
  621. this.m_ik.UpdateSolverExternal();
  622. Transform transform2 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Thigh", true);
  623. transform2.localRotation = Quaternion.Euler(5.025288f, -179.97f, -9.849731f);
  624. Transform transform3 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Calf", true);
  625. transform3.localRotation = Quaternion.Euler(-4.30072f, -1.857178f, 2.579935f);
  626. Transform transform4 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Thigh", true);
  627. transform4.localRotation = Quaternion.Euler(5.025289f, -179.97f, -9.849731f);
  628. Transform transform5 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Calf", true);
  629. transform5.localRotation = Quaternion.Euler(-4.30072f, 1.857178f, 2.579935f);
  630. this.m_listDefaultPose.Clear();
  631. if (this.m_goDefaultPoseParent != null)
  632. {
  633. UnityEngine.Object.Destroy(this.m_goDefaultPoseParent);
  634. }
  635. this.m_goDefaultPoseParent = new GameObject("VRIK Default Pose Parent");
  636. Transform transform6 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01", true).transform;
  637. this.FindAndAddParent(CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Foot", true).transform, "Bip01", false);
  638. GameObject gameObject = new GameObject(transform6.name);
  639. gameObject.transform.SetParent(this.m_goDefaultPoseParent.transform, false);
  640. gameObject.transform.position = transform6.position;
  641. gameObject.transform.rotation = transform6.rotation;
  642. this.m_listDefaultPose[this.m_listDefaultPose.Count - 1].Value.SetParent(gameObject.transform, true);
  643. this.m_listDefaultPose.Add(new KeyValuePair<Transform, Transform>(transform6, gameObject.transform));
  644. this.FindAndAddParent(CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Eyepos_R", false).transform, "Bip01", false);
  645. this.m_listDefaultPose[this.m_listDefaultPose.Count - 1].Value.SetParent(gameObject.transform, true);
  646. this.m_trMaidDefaultPoseEyeR = this.m_listDefaultPose.Find((KeyValuePair<Transform, Transform> a) => a.Key.name == "Eyepos_R").Value;
  647. this.m_trMaidDefaultPoseFootR = this.m_listDefaultPose.Find((KeyValuePair<Transform, Transform> a) => a.Key.name == "Bip01 R Foot").Value;
  648. GameMain.Instance.OvrMgr.OvrCamera.HandModelVisible = false;
  649. Transform hand_trans = GameMain.Instance.OvrMgr.ovr_obj.left_controller.hand_trans;
  650. Transform hand_trans2 = GameMain.Instance.OvrMgr.ovr_obj.right_controller.hand_trans;
  651. this.m_FaceCompoL = hand_trans.gameObject.GetComponent<PhotoFaceDataShortcutParent>();
  652. if (this.m_FaceCompoL == null)
  653. {
  654. this.m_FaceCompoL = hand_trans.gameObject.AddComponent<PhotoFaceDataShortcutParent>();
  655. }
  656. this.m_FaceCompoL.Init(true);
  657. this.m_FaceCompoL.isEnableHandUI = false;
  658. this.m_FaceCompoR = hand_trans2.gameObject.GetComponent<PhotoFaceDataShortcutParent>();
  659. if (this.m_FaceCompoR == null)
  660. {
  661. this.m_FaceCompoR = hand_trans2.gameObject.AddComponent<PhotoFaceDataShortcutParent>();
  662. }
  663. this.m_FaceCompoR.Init(false);
  664. this.m_FaceCompoR.isEnableHandUI = false;
  665. this.m_coHandSignL = hand_trans.gameObject.GetComponent<HandSignShortcut>();
  666. if (this.m_coHandSignL == null)
  667. {
  668. this.m_coHandSignL = hand_trans.gameObject.AddComponent<HandSignShortcut>();
  669. }
  670. this.m_coHandSignL.Init(true);
  671. this.m_coHandSignL.isEnableHandUI = false;
  672. this.m_coHandSignR = hand_trans2.gameObject.GetComponent<HandSignShortcut>();
  673. if (this.m_coHandSignR == null)
  674. {
  675. this.m_coHandSignR = hand_trans2.gameObject.AddComponent<HandSignShortcut>();
  676. }
  677. this.m_coHandSignR.Init(false);
  678. this.m_coHandSignR.isEnableHandUI = false;
  679. this.m_coOtherCmdL = hand_trans.gameObject.GetComponent<OtherCommandShortcut>();
  680. if (this.m_coOtherCmdL == null)
  681. {
  682. this.m_coOtherCmdL = hand_trans.gameObject.AddComponent<OtherCommandShortcut>();
  683. }
  684. this.m_coOtherCmdL.Init(true);
  685. this.m_coOtherCmdL.isEnableHandUI = false;
  686. this.m_coOtherCmdR = hand_trans2.gameObject.GetComponent<OtherCommandShortcut>();
  687. if (this.m_coOtherCmdR == null)
  688. {
  689. this.m_coOtherCmdR = hand_trans2.gameObject.AddComponent<OtherCommandShortcut>();
  690. }
  691. this.m_coOtherCmdR.Init(false);
  692. this.m_coOtherCmdR.isEnableHandUI = false;
  693. if (OvrIK.m_goVRIKConfigUI == null)
  694. {
  695. UnityEngine.Object original = Resources.Load("OVR/CircleCommandUI/Parent Controller Shortcut Setter Window");
  696. OvrIK.m_goVRIKConfigUI = (UnityEngine.Object.Instantiate(original) as GameObject);
  697. GameObject gameObject2 = GameObject.Find("SystemUI Root");
  698. OvrIK.m_goVRIKConfigUI.transform.SetParent(gameObject2.transform, false);
  699. }
  700. if (OvrIK.m_VRIKConfigCompo == null)
  701. {
  702. OvrIK.m_VRIKConfigCompo = OvrIK.m_goVRIKConfigUI.GetComponent<ControllerShortcutWindow>();
  703. }
  704. OvrIK.m_VRIKConfigCompo.Init(this.m_FaceCompoR, this.m_FaceCompoL);
  705. OvrIK.m_VRIKConfigCompo.Open();
  706. GameMain.Instance.OvrMgr.OvrCamera.HandVRIKMode = true;
  707. if (this.m_ik == null)
  708. {
  709. Debug.LogError("未だVRIKが付いていません。");
  710. return;
  711. }
  712. this.m_maid = base.GetComponent<Maid>();
  713. NDebug.Assert(this.m_maid != null, "メイドが居ません。");
  714. this.m_maid.boOffsetY = false;
  715. GameObject obj = this.m_maid.body0.GetSlot(1).obj;
  716. this.LayerCheck(obj, LayerMask.NameToLayer("Face"));
  717. GameObject obj2 = this.m_maid.body0.GetSlot(36).obj;
  718. this.LayerCheck(obj2, LayerMask.NameToLayer("Face"));
  719. GameObject obj3 = this.m_maid.body0.GetSlot(17).obj;
  720. this.LayerCheck(obj3, LayerMask.NameToLayer("Face"));
  721. GameMain.Instance.OvrMgr.OvrCamera.SetCameraMask((CameraMain.CameraMask)LayerMask.NameToLayer("Face"), false);
  722. Transform transform7 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Eyepos_L", false);
  723. Transform transform8 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Eyepos_R", false);
  724. Vector3 vector = transform8.position + (transform7.position - transform8.position) * 0.5f;
  725. this.m_trPlayerDefaultPoseEye = new GameObject("Pair Player Eye").transform;
  726. this.m_trPlayerDefaultPoseEye.SetParent(this.m_goDefaultPoseParent.transform, false);
  727. this.m_trPlayerDefaultPoseEye.position = vector;
  728. GameMain.Instance.OvrMgr.OvrCamera.SetRealHeadPos(vector, false);
  729. GameMain.Instance.OvrMgr.OvrCamera.SetRealHeadRot(new Vector3(0f, 0f, 0f), true);
  730. Transform realHeadTransform = GameMain.Instance.OvrMgr.OvrCamera.GetRealHeadTransform();
  731. Transform hand_trans3 = GameMain.Instance.OvrMgr.ovr_obj.left_controller.hand_trans;
  732. Transform hand_trans4 = GameMain.Instance.OvrMgr.ovr_obj.right_controller.hand_trans;
  733. this.m_trTargetOffsHead.SetParent(realHeadTransform, false);
  734. this.m_trTargetOffsHead.localPosition = new Vector3(0f, -0.03f, -0.05f);
  735. this.m_trTargetOffsHead.localRotation = Quaternion.Euler(0f, -90f, -90f);
  736. this.m_trTargetOffsHandL.SetParent(hand_trans3, false);
  737. this.m_trTargetOffsHandL.localPosition = new Vector3(-0.014f, -0.032f, -0.106f);
  738. this.m_trTargetOffsHandL.localRotation = Quaternion.Euler(74.50851f, -128.3506f, 135.9052f);
  739. this.m_trTargetOffsHandR.SetParent(hand_trans4, false);
  740. this.m_trTargetOffsHandR.localPosition = new Vector3(0.014f, -0.032f, -0.106f);
  741. this.m_trTargetOffsHandR.localRotation = Quaternion.Euler(-83.64291f, 34.33916f, 46.03844f);
  742. this.m_ik.solver.spine.headTarget = this.m_trTargetOffsHead;
  743. this.m_ik.solver.leftArm.target = this.m_trTargetOffsHandL;
  744. this.m_ik.solver.rightArm.target = this.m_trTargetOffsHandR;
  745. AVRTrackingObjectsMgr trackingObjectsMgr = GameMain.Instance.OvrMgr.TrackingObjectsMgr;
  746. if (trackingObjectsMgr != null)
  747. {
  748. trackingObjectsMgr.Refresh();
  749. List<Transform> trackingObjects = trackingObjectsMgr.TrackingObjects;
  750. bool use1TrackerForHead = ControllerShortcutSettingData.config.use1TrackerForHead;
  751. int index = 0;
  752. int index2 = 1;
  753. int index3 = 2;
  754. int num = 2;
  755. int num2 = 3;
  756. if (use1TrackerForHead && 1 <= trackingObjects.Count)
  757. {
  758. Debug.Log("OvrIK トラッカーが1つ見つかりました。ヘッドトラッキングに使えます。");
  759. trackingObjects.Sort((Transform a, Transform b) => (b.transform.position.y - a.transform.position.y >= 0f) ? 1 : -1);
  760. Transform transform9 = trackingObjects[0];
  761. this.m_listTrackerMeshRnder.Add(transform9.GetComponent<MeshRenderer>());
  762. Transform transform10 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 Head", true);
  763. this.m_trTargetOffsHeadTracker = new GameObject("VRIK Target Offs Head Tracker").transform;
  764. this.m_trTargetOffsHeadTracker.position = transform10.position;
  765. this.m_trTargetOffsHeadTracker.rotation = transform10.rotation;
  766. this.m_trTargetOffsHeadTracker.SetParent(transform9, true);
  767. this.m_ik.solver.spine.headTarget = this.m_trTargetOffsHeadTracker;
  768. trackingObjects.Remove(transform);
  769. this.CheckHeadIsTracker();
  770. }
  771. if (num <= trackingObjects.Count)
  772. {
  773. trackingObjects.Sort((Transform a, Transform b) => (a.transform.position.y - b.transform.position.y >= 0f) ? 1 : -1);
  774. if (hand_trans3.position.y < trackingObjects[index].position.y || hand_trans3.position.y < trackingObjects[index2].position.y)
  775. {
  776. Debug.LogError("足のトラッカーは手より下になければなりません。");
  777. }
  778. if ((trackingObjects[index].position - trackingObjects[index2].position).magnitude < 0.1f)
  779. {
  780. Debug.LogError("足は10cm以上広げて下さい。");
  781. }
  782. Transform transform11;
  783. Transform transform12;
  784. if ((hand_trans3.position - trackingObjects[index].position).sqrMagnitude < (hand_trans3.position - trackingObjects[index2].position).sqrMagnitude)
  785. {
  786. transform11 = trackingObjects[index];
  787. transform12 = trackingObjects[index2];
  788. }
  789. else
  790. {
  791. transform11 = trackingObjects[index2];
  792. transform12 = trackingObjects[index];
  793. }
  794. this.m_listTrackerMeshRnder.Add(transform11.GetComponent<MeshRenderer>());
  795. this.m_listTrackerMeshRnder.Add(transform12.GetComponent<MeshRenderer>());
  796. this.m_ik.solver.spine.pelvisPositionOffset = this.m_vPelvisPosOffs;
  797. this.m_ik.solver.spine.pelvisRotationOffset = Quaternion.Euler(this.m_vPelvisRotOffs);
  798. this.m_ik.solver.spine.pelvisPositionWeight = 0f;
  799. this.m_ik.solver.spine.headClampWeight = 0f;
  800. this.m_ik.solver.spine.chestRotationWeight = 0.3f;
  801. this.m_ik.solver.spine.chestClampWeight = 0.5f;
  802. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 L Foot", true);
  803. this.m_trTargetOffsFootL.position = transform.position;
  804. this.m_trTargetOffsFootL.rotation = transform.rotation;
  805. this.m_trTargetOffsFootL.SetParent(transform11, true);
  806. this.m_vFootDefOffsLocalL = this.m_trTargetOffsFootL.localPosition;
  807. this.m_trTargetOffsFootLVecY = new GameObject("Y Vec").transform;
  808. this.m_trTargetOffsFootLVecY.SetParent(this.m_trTargetOffsFootL, false);
  809. this.m_trTargetOffsFootLVecY.localPosition = Vector3.zero;
  810. this.m_trTargetOffsFootLVecY.position += new Vector3(0f, -1f, 0f);
  811. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 R Foot", true);
  812. this.m_trTargetOffsFootR.position = transform.position;
  813. this.m_trTargetOffsFootR.rotation = transform.rotation;
  814. this.m_trTargetOffsFootR.SetParent(transform12, true);
  815. this.m_vFootDefOffsLocalR = this.m_trTargetOffsFootR.localPosition;
  816. this.m_trTargetOffsFootRVecY = new GameObject("Y Vec").transform;
  817. this.m_trTargetOffsFootRVecY.SetParent(this.m_trTargetOffsFootR, false);
  818. this.m_trTargetOffsFootRVecY.localPosition = Vector3.zero;
  819. this.m_trTargetOffsFootRVecY.position += new Vector3(0f, -1f, 0f);
  820. this.m_ik.solver.leftLeg.target = this.m_trTargetOffsFootL;
  821. this.m_ik.solver.rightLeg.target = this.m_trTargetOffsFootR;
  822. this.m_trPlayerDefaultPoseFoot = new GameObject("Pair Player Foot").transform;
  823. this.m_trPlayerDefaultPoseFoot.SetParent(this.m_trPlayerDefaultPoseEye, false);
  824. this.m_trPlayerDefaultPoseFoot.position = this.m_trTargetOffsFootL.position + (this.m_trTargetOffsFootR.position - this.m_trTargetOffsFootL.position) * 0.5f;
  825. this.m_ik.solver.spine.pelvisTarget = null;
  826. if (num2 <= trackingObjects.Count)
  827. {
  828. Transform transform13 = trackingObjects[index3];
  829. this.m_listTrackerMeshRnder.Add(transform13.GetComponent<MeshRenderer>());
  830. if (transform13.position.y >= hand_trans3.position.y)
  831. {
  832. Debug.LogError("腰は頭より下でなければなりません。");
  833. }
  834. if (transform13.position.y <= transform11.position.y || transform13.position.y <= transform12.position.y)
  835. {
  836. Debug.LogError("腰は両足より上でなければなりません。");
  837. }
  838. transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01", true);
  839. this.m_trTargetOffsPelvis.position = transform.position;
  840. this.m_trTargetOffsPelvis.rotation = transform.rotation;
  841. this.m_trTargetOffsPelvis.SetParent(transform13, true);
  842. float num3 = realHeadTransform.transform.position.y - (transform13.position.y - 0.2f);
  843. Transform transform14 = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, "Bip01 Pelvis", true);
  844. float num4 = vector.y - transform14.transform.position.y;
  845. float num5 = num4 - num3;
  846. this.m_ik.solver.spine.pelvisTarget = this.m_trTargetOffsPelvis;
  847. this.m_ik.solver.spine.pelvisPositionWeight = 1f;
  848. }
  849. this.m_bLegTracking = true;
  850. }
  851. else
  852. {
  853. Debug.Log("OvrIK トラッカーは" + num + "つ未満です。足のトラッキングは行いません。");
  854. this.m_bLegTracking = false;
  855. }
  856. }
  857. if (!this.m_bLegTracking)
  858. {
  859. this.m_ik.solver.leftLeg.rotationWeight = (this.m_ik.solver.rightLeg.rotationWeight = OvrIK.m_conf.leg_no_tracker_rot_weight);
  860. this.m_ik.solver.leftLeg.positionWeight = (this.m_ik.solver.rightLeg.positionWeight = OvrIK.m_conf.leg_no_tracker_pos_weight);
  861. }
  862. this.m_self_shot_cam = GameObject.Find("OvrSelfShotCamera");
  863. if (this.m_self_shot_cam == null)
  864. {
  865. this.m_coSelfShotCam = OvrSelfShotCamera.Create();
  866. this.m_self_shot_cam = this.m_coSelfShotCam.gameObject;
  867. this.m_trEyeTarget = this.m_coSelfShotCam.EyeTarget;
  868. this.m_rtMoniPlaneTex = this.m_coSelfShotCam.CamTex;
  869. }
  870. this.m_goMoni = GameObject.Find("OvrIKPlaneCamera");
  871. if (!this.m_goMoni)
  872. {
  873. this.m_goMoni = Utility.CreatePrefab(null, "OVR/OvrIKPlaneCamera", false);
  874. this.m_goMoni.name = "OvrIKPlaneCamera";
  875. this.m_trMoniPlane = this.m_goMoni.transform.Find("Plane").transform;
  876. }
  877. this.m_maid.EyeToCamera(Maid.EyeMoveType.目だけ向ける, 0f);
  878. }
  879. private void ReCalcShincho()
  880. {
  881. if (this.m_trMaidDefaultPoseEyeR == null || this.m_trPlayerDefaultPoseEye == null || this.m_trMaidDefaultPoseFootR == null || this.m_trPlayerDefaultPoseFoot == null || this.m_trTargetOffsFootL == null || this.m_trTargetOffsFootR == null)
  882. {
  883. return;
  884. }
  885. float num = this.m_trMaidDefaultPoseEyeR.position.y - this.m_trMaidDefaultPoseFootR.position.y;
  886. float num2 = this.m_trPlayerDefaultPoseEye.position.y - this.m_trPlayerDefaultPoseFoot.position.y;
  887. float d = num - num2 + this.offsy;
  888. this.m_trTargetOffsFootL.localPosition = this.m_vFootDefOffsLocalL;
  889. this.m_trTargetOffsFootR.localPosition = this.m_vFootDefOffsLocalR;
  890. this.m_trTargetOffsFootL.position += (this.m_trTargetOffsFootLVecY.position - this.m_trTargetOffsFootL.position).normalized * d;
  891. this.m_trTargetOffsFootR.position += (this.m_trTargetOffsFootRVecY.position - this.m_trTargetOffsFootR.position).normalized * d;
  892. }
  893. private void CheckHeadIsTracker()
  894. {
  895. bool flag = this.m_ik.solver.spine.headTarget == this.m_trTargetOffsHeadTracker;
  896. if (flag != this.m_isHeadIsTracker)
  897. {
  898. if (flag)
  899. {
  900. GameObject obj = this.m_maid.body0.GetSlot(1).obj;
  901. this.LayerCheck(obj, LayerMask.NameToLayer("Charactor"));
  902. GameObject obj2 = this.m_maid.body0.GetSlot(36).obj;
  903. this.LayerCheck(obj2, LayerMask.NameToLayer("Charactor"));
  904. GameObject obj3 = this.m_maid.body0.GetSlot(17).obj;
  905. this.LayerCheck(obj3, LayerMask.NameToLayer("Charactor"));
  906. }
  907. else
  908. {
  909. GameObject obj4 = this.m_maid.body0.GetSlot(1).obj;
  910. this.LayerCheck(obj4, LayerMask.NameToLayer("Face"));
  911. GameObject obj5 = this.m_maid.body0.GetSlot(36).obj;
  912. this.LayerCheck(obj5, LayerMask.NameToLayer("Face"));
  913. GameObject obj6 = this.m_maid.body0.GetSlot(17).obj;
  914. this.LayerCheck(obj6, LayerMask.NameToLayer("Face"));
  915. }
  916. this.m_isHeadIsTracker = flag;
  917. }
  918. }
  919. private void OnDisable()
  920. {
  921. this.Finish();
  922. }
  923. private void OnDestroy()
  924. {
  925. this.Finish();
  926. }
  927. private void Update()
  928. {
  929. if (Input.GetKeyUp(KeyCode.F9))
  930. {
  931. GameObject gameObject = GameObject.Find("TestMonitor");
  932. GameObject gameObject2 = GameObject.Find("TestMonitorR");
  933. if (gameObject != null)
  934. {
  935. UnityEngine.Object.Destroy(gameObject);
  936. UnityEngine.Object @object = Resources.Load("OVR/TestMonitorR");
  937. GameObject gameObject3 = UnityEngine.Object.Instantiate<GameObject>(@object as GameObject);
  938. gameObject3.name = @object.name;
  939. }
  940. if (gameObject2 != null)
  941. {
  942. UnityEngine.Object.Destroy(gameObject2);
  943. UnityEngine.Object object2 = Resources.Load("OVR/TestMonitor");
  944. GameObject gameObject4 = UnityEngine.Object.Instantiate<GameObject>(object2 as GameObject);
  945. gameObject4.name = object2.name;
  946. }
  947. }
  948. if (OvrIK.IsModeVRIK && (this.m_maid == null || !this.m_maid.Visible || !this.m_maid.body0.isLoadedBody))
  949. {
  950. this.Finish();
  951. }
  952. if (this.m_ik != null)
  953. {
  954. if (this.m_maid != null && !this.m_maid.IsBusy)
  955. {
  956. for (int i = 0; i < this.m_listDefaultPose.Count; i++)
  957. {
  958. KeyValuePair<Transform, Transform> item = this.m_listDefaultPose[i];
  959. if (item.Key == null)
  960. {
  961. Transform transform = CMT.SearchObjName(this.m_maid.body0.m_Bones.transform, item.Value.name, false);
  962. if (transform != null)
  963. {
  964. this.m_listDefaultPose[i] = new KeyValuePair<Transform, Transform>(transform, item.Value);
  965. }
  966. else
  967. {
  968. this.m_listDefaultPose.Remove(item);
  969. }
  970. }
  971. if (this.m_trMaidDefaultPoseEyeR == null)
  972. {
  973. Debug.Log("m_trMaidDefaultPoseEyeR");
  974. this.m_trMaidDefaultPoseEyeR = this.m_listDefaultPose.Find((KeyValuePair<Transform, Transform> a) => a.Key.name == "Eyepos_R").Value;
  975. }
  976. if (item.Key != null)
  977. {
  978. item.Value.localPosition = item.Key.localPosition;
  979. }
  980. }
  981. int value = this.m_maid.GetProp(MPN.sintyou).value;
  982. int value2 = this.m_maid.GetProp(MPN.DouPer).value;
  983. int value3 = this.m_maid.GetProp(MPN.KubiScl).value;
  984. if (this.m_nShincho != value || this.m_nDouPer != value2 || this.m_nKubiScl != value3)
  985. {
  986. this.m_nShincho = value;
  987. this.m_nDouPer = value2;
  988. this.m_nKubiScl = value3;
  989. }
  990. if (!this.m_bLegTracking)
  991. {
  992. Vector3 position = this.m_trTargetOffsHead.position;
  993. Vector3 floorPos = GameMain.Instance.OvrMgr.OvrCamera.GetFloorPos(position);
  994. Transform trTargetOffsFootR = this.m_trTargetOffsFootR;
  995. Vector3 position2 = new Vector3(position.x, floorPos.y, position.z);
  996. this.m_trTargetOffsFootL.position = position2;
  997. trTargetOffsFootR.position = position2;
  998. }
  999. }
  1000. this.m_ik.solver.spine.maintainPelvisPosition = ControllerShortcutSettingData.config.maintainPelvisPosition;
  1001. this.m_ik.solver.spine.bodyPosStiffness = ControllerShortcutSettingData.config.bodyPosStiffness;
  1002. this.m_ik.solver.spine.bodyRotStiffness = ControllerShortcutSettingData.config.bodyRotStiffness;
  1003. this.m_ik.solver.spine.chestRotationWeight = ControllerShortcutSettingData.config.chestRotationWeight;
  1004. this.m_ik.solver.spine.pelvisPositionOffset = this.m_vPelvisPosOffs;
  1005. this.m_ik.solver.spine.pelvisRotationOffset = Quaternion.Euler(this.m_vPelvisRotOffs);
  1006. if (this.m_ik.fixTransforms && this.m_ik.GetIKSolver().initiated)
  1007. {
  1008. this.m_ik.GetIKSolver().FixTransforms();
  1009. }
  1010. this.m_ik.UpdateSolverExternal();
  1011. if (this.m_goMoni != null)
  1012. {
  1013. if (this.m_trMoniPlane != null && this.m_rtMoniPlaneTex != null)
  1014. {
  1015. this.m_trMoniPlane.localScale = new Vector3((float)this.m_rtMoniPlaneTex.width / (float)this.m_rtMoniPlaneTex.height, 1f, 1f);
  1016. }
  1017. if (Input.GetKeyDown(KeyCode.Space))
  1018. {
  1019. this.m_goMoni.SetActive(!this.m_goMoni.activeSelf);
  1020. }
  1021. }
  1022. this.CheckHeadIsTracker();
  1023. if (this.m_trEyeTarget != null && this.m_maid != null)
  1024. {
  1025. Transform realHeadTransform = GameMain.Instance.OvrMgr.OvrCamera.GetRealHeadTransform();
  1026. float num = Vector3.Dot(this.m_trEyeTarget.forward, realHeadTransform.forward);
  1027. if (this.m_ik.solver.spine.headTarget == this.m_trTargetOffsHeadTracker)
  1028. {
  1029. num = Vector3.Dot(this.m_trEyeTarget.forward, this.m_trTargetOffsHeadTracker.up);
  1030. }
  1031. if (num < this.m_fEyeToCamThresholdAngle && this.m_bEyeTocam)
  1032. {
  1033. this.m_maid.EyeToCamera(Maid.EyeMoveType.目だけ向ける, 0f);
  1034. }
  1035. else
  1036. {
  1037. this.m_maid.EyeToCamera(Maid.EyeMoveType.無し, 0f);
  1038. }
  1039. }
  1040. for (int j = 0; j < this.m_listTrackerMeshRnder.Count; j++)
  1041. {
  1042. if (this.m_listTrackerMeshRnder[j] != null)
  1043. {
  1044. this.m_listTrackerMeshRnder[j].enabled = false;
  1045. }
  1046. }
  1047. if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyUp(KeyCode.F8))
  1048. {
  1049. if (this.m_trTargetOffsHeadTracker != null)
  1050. {
  1051. if (this.m_ik.solver.spine.headTarget == this.m_trTargetOffsHeadTracker)
  1052. {
  1053. this.m_ik.solver.spine.headTarget = this.m_trTargetOffsHead;
  1054. }
  1055. else
  1056. {
  1057. this.m_ik.solver.spine.headTarget = this.m_trTargetOffsHeadTracker;
  1058. }
  1059. }
  1060. else
  1061. {
  1062. Debug.Log("VRIK トラッカーがありませんので頭ターゲットに。");
  1063. }
  1064. }
  1065. }
  1066. }
  1067. public static List<string> UpdateGeneralModelFileList()
  1068. {
  1069. OvrIK.m_listFileList.Clear();
  1070. string fullPath = Path.GetFullPath(".\\");
  1071. string path = fullPath + "Model";
  1072. if (!Directory.Exists(path))
  1073. {
  1074. return OvrIK.m_listFileList;
  1075. }
  1076. string[] exts = new string[]
  1077. {
  1078. ".obj",
  1079. ".fbx",
  1080. ".dae",
  1081. ".stl",
  1082. ".x",
  1083. ".3ds"
  1084. };
  1085. string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
  1086. IEnumerable<string> source = from file in files
  1087. where exts.Any((string ext) => file.ToLower().EndsWith(ext))
  1088. select file;
  1089. OvrIK.m_listFileList = source.ToList<string>();
  1090. return OvrIK.m_listFileList;
  1091. }
  1092. public static void LoadGeneralModelFile(string f_strRead)
  1093. {
  1094. OvrIK.m_listGeneralModel.RemoveAll((GameObject o) => o == null);
  1095. GameObject gameObject = ImportCM.LoadGeneralModelFile(f_strRead);
  1096. if (gameObject != null)
  1097. {
  1098. MeshRenderer componentInChildren = gameObject.GetComponentInChildren<MeshRenderer>(true);
  1099. if (componentInChildren != null)
  1100. {
  1101. OvrGrabObj ovrGrabObj = gameObject.AddComponent<OvrGrabObj>();
  1102. Rigidbody rigidbody = gameObject.AddComponent<Rigidbody>();
  1103. rigidbody.useGravity = false;
  1104. rigidbody.isKinematic = true;
  1105. ovrGrabObj.m_trTarget = gameObject.transform;
  1106. string text = Path.GetFileName(f_strRead).ToLower();
  1107. if (text.Contains("_useg"))
  1108. {
  1109. rigidbody.useGravity = true;
  1110. rigidbody.isKinematic = false;
  1111. rigidbody.mass = 0.1f;
  1112. gameObject.layer = LayerMask.NameToLayer("OvrTouchLookObj");
  1113. GameMain.Instance.OvrMgr.OvrCamera.SetCameraMask(CameraMain.CameraMask.OvrTouchLookObj, true);
  1114. ovrGrabObj.m_bGrabToKinematic = true;
  1115. ovrGrabObj.m_fEaseRate = 60f;
  1116. ovrGrabObj.m_fGrabThrowRate = 1f;
  1117. }
  1118. if (text.Contains("_sphere"))
  1119. {
  1120. OvrIK.ColliderAutoAdjust(gameObject.AddComponent<SphereCollider>(), OvrIK.GetChildenMeshCombinedBounds(gameObject));
  1121. }
  1122. else if (text.Contains("_capsule"))
  1123. {
  1124. OvrIK.ColliderAutoAdjust(gameObject.AddComponent<CapsuleCollider>(), OvrIK.GetChildenMeshCombinedBounds(gameObject));
  1125. }
  1126. else if (text.Contains("_box"))
  1127. {
  1128. OvrIK.ColliderAutoAdjust(gameObject.AddComponent<BoxCollider>(), OvrIK.GetChildenMeshCombinedBounds(gameObject));
  1129. }
  1130. else if (text.Contains("_mesh"))
  1131. {
  1132. MeshCollider meshCollider = componentInChildren.gameObject.AddComponent<MeshCollider>();
  1133. meshCollider.inflateMesh = true;
  1134. meshCollider.skinWidth = 0.03f;
  1135. meshCollider.convex = true;
  1136. }
  1137. else if (text.Contains("_useg"))
  1138. {
  1139. OvrIK.ColliderAutoAdjust(gameObject.AddComponent<BoxCollider>(), OvrIK.GetChildenMeshCombinedBounds(gameObject));
  1140. }
  1141. else
  1142. {
  1143. MeshCollider meshCollider2 = componentInChildren.gameObject.AddComponent<MeshCollider>();
  1144. meshCollider2.inflateMesh = true;
  1145. meshCollider2.skinWidth = 0.03f;
  1146. meshCollider2.convex = true;
  1147. }
  1148. if (text.Contains("_trans"))
  1149. {
  1150. componentInChildren.sharedMaterial.shader = Shader.Find("CM3D2/Lighted_Trans");
  1151. }
  1152. else
  1153. {
  1154. componentInChildren.sharedMaterial.shader = Shader.Find("CM3D2/Lighted");
  1155. }
  1156. OvrObjAutoDestory ovrObjAutoDestory = gameObject.AddComponent<OvrObjAutoDestory>();
  1157. ovrObjAutoDestory.m_goTarget = gameObject;
  1158. OvrIK.m_listGeneralModel.Add(gameObject);
  1159. }
  1160. Transform realHeadTransform = GameMain.Instance.OvrMgr.OvrCamera.GetRealHeadTransform();
  1161. Vector3 position = new Vector3(realHeadTransform.forward.x, 0f, realHeadTransform.forward.z) * 2f + realHeadTransform.position;
  1162. gameObject.transform.position = position;
  1163. }
  1164. }
  1165. private static Bounds GetChildenMeshCombinedBounds(GameObject obj)
  1166. {
  1167. NDebug.AssertNull(obj);
  1168. Bounds result = default(Bounds);
  1169. MeshRenderer[] componentsInChildren = obj.GetComponentsInChildren<MeshRenderer>();
  1170. if (componentsInChildren == null || componentsInChildren.Length <= 0)
  1171. {
  1172. return result;
  1173. }
  1174. result = componentsInChildren[0].bounds;
  1175. for (int i = 1; i < componentsInChildren.Length; i++)
  1176. {
  1177. result.Encapsulate(componentsInChildren[i].bounds);
  1178. }
  1179. return result;
  1180. }
  1181. private static void ColliderAutoAdjust(SphereCollider col, Bounds bounds)
  1182. {
  1183. col.center = bounds.center;
  1184. col.radius = bounds.extents.x;
  1185. if (col.radius < bounds.extents.y)
  1186. {
  1187. col.radius = bounds.extents.y;
  1188. }
  1189. if (col.radius < bounds.extents.z)
  1190. {
  1191. col.radius = bounds.extents.z;
  1192. }
  1193. }
  1194. private static void ColliderAutoAdjust(BoxCollider col, Bounds bounds)
  1195. {
  1196. col.center = bounds.center;
  1197. col.size = bounds.size;
  1198. }
  1199. private static void ColliderAutoAdjust(CapsuleCollider col, Bounds bounds)
  1200. {
  1201. col.center = bounds.center;
  1202. int index = 0;
  1203. int num = 2;
  1204. if (bounds.extents[index] > bounds.extents[1])
  1205. {
  1206. index = 1;
  1207. }
  1208. if (bounds.extents[index] > bounds.extents[2])
  1209. {
  1210. index = 2;
  1211. }
  1212. if (bounds.extents[num] < bounds.extents[1])
  1213. {
  1214. num = 1;
  1215. }
  1216. if (bounds.extents[num] < bounds.extents[2])
  1217. {
  1218. num = 2;
  1219. }
  1220. col.radius = bounds.extents[index];
  1221. col.height = bounds.size[num];
  1222. col.direction = num;
  1223. }
  1224. public static void DestroyGeneralModelAll()
  1225. {
  1226. foreach (GameObject gameObject in OvrIK.m_listGeneralModel)
  1227. {
  1228. if (gameObject != null)
  1229. {
  1230. UnityEngine.Object.Destroy(gameObject);
  1231. }
  1232. }
  1233. OvrIK.m_listGeneralModel.Clear();
  1234. }
  1235. private static OvrIK m_this;
  1236. private VRIK m_ik;
  1237. private static OvrIK.OvrIkConfig m_conf = new OvrIK.OvrIkConfig();
  1238. private readonly string[] m_strHandBoneNameL = new string[]
  1239. {
  1240. "Bip01 L Finger02",
  1241. "Bip01 L Finger01",
  1242. "Bip01 L Finger0",
  1243. "Bip01 L Finger12",
  1244. "Bip01 L Finger11",
  1245. "Bip01 L Finger1",
  1246. "Bip01 L Finger22",
  1247. "Bip01 L Finger21",
  1248. "Bip01 L Finger2",
  1249. "Bip01 L Finger32",
  1250. "Bip01 L Finger31",
  1251. "Bip01 L Finger3",
  1252. "Bip01 L Finger42",
  1253. "Bip01 L Finger41",
  1254. "Bip01 L Finger4"
  1255. };
  1256. private readonly string[] m_strHandBoneNameR = new string[]
  1257. {
  1258. "Bip01 R Finger02",
  1259. "Bip01 R Finger01",
  1260. "Bip01 R Finger0",
  1261. "Bip01 R Finger12",
  1262. "Bip01 R Finger11",
  1263. "Bip01 R Finger1",
  1264. "Bip01 R Finger22",
  1265. "Bip01 R Finger21",
  1266. "Bip01 R Finger2",
  1267. "Bip01 R Finger32",
  1268. "Bip01 R Finger31",
  1269. "Bip01 R Finger3",
  1270. "Bip01 R Finger42",
  1271. "Bip01 R Finger41",
  1272. "Bip01 R Finger4"
  1273. };
  1274. private readonly Quaternion[,] m_aryHandRot;
  1275. private Maid m_maid;
  1276. private Transform m_trTargetOffsHead;
  1277. private Transform m_trTargetOffsPelvis;
  1278. private Transform m_trTargetOffsHandL;
  1279. private Transform m_trTargetOffsHandR;
  1280. private Transform m_trTargetOffsFootL;
  1281. private Transform m_trTargetOffsFootR;
  1282. private Transform m_trTargetOffsHeadTracker;
  1283. private Transform m_trTargetOffsFootLVecY;
  1284. private Transform m_trTargetOffsFootRVecY;
  1285. private GameObject m_goDefaultPoseParent;
  1286. private List<KeyValuePair<Transform, Transform>> m_listDefaultPose;
  1287. private Transform m_trMaidDefaultPoseEyeR;
  1288. private Transform m_trMaidDefaultPoseFootR;
  1289. private Transform m_trPlayerDefaultPoseEye;
  1290. private Transform m_trPlayerDefaultPoseFoot;
  1291. private Transform[] m_trHandL;
  1292. private Transform[] m_trHandR;
  1293. public Vector3 m_vPelvisPosOffs;
  1294. public Vector3 m_vPelvisRotOffs;
  1295. private GameObject m_goIKTargetParent;
  1296. private int m_nCensorNum;
  1297. public bool m_bLegTracking;
  1298. private static Coroutine m_coCalibrate = null;
  1299. private GameObject m_self_shot_cam;
  1300. private OvrSelfShotCamera m_coSelfShotCam;
  1301. private GameObject m_goMoni;
  1302. private Transform m_trMoniPlane;
  1303. private RenderTexture m_rtMoniPlaneTex;
  1304. private Transform m_trEyeTarget;
  1305. private PhotoFaceDataShortcutParent m_FaceCompoL;
  1306. private PhotoFaceDataShortcutParent m_FaceCompoR;
  1307. private HandSignShortcut m_coHandSignL;
  1308. private HandSignShortcut m_coHandSignR;
  1309. private OtherCommandShortcut m_coOtherCmdL;
  1310. private OtherCommandShortcut m_coOtherCmdR;
  1311. private static GameObject m_goVRIKConfigUI;
  1312. private static ControllerShortcutWindow m_VRIKConfigCompo;
  1313. private Vector3 m_vBackPos;
  1314. private Vector3 m_vBackRot;
  1315. private Vector3 m_vBackRootPos;
  1316. private Quaternion m_qBackRootRot;
  1317. private List<MeshRenderer> m_listTrackerMeshRnder;
  1318. public float m_fEyeToCamThresholdAngle;
  1319. private bool m_bEyeTocam;
  1320. private bool m_bBackAutoTwistShoulderL;
  1321. private bool m_bBackAutoTwistShoulderR;
  1322. private bool m_bBackAutoTwistWristL;
  1323. private bool m_bBackAutoTwistWristR;
  1324. private bool m_bBackAutoTwistThighL;
  1325. private bool m_bBackAutoTwistThighR;
  1326. private AMTween[] m_aryBackAMTween;
  1327. private bool m_isHeadIsTracker;
  1328. private Vector3 m_vFootDefOffsLocalL;
  1329. private Vector3 m_vFootDefOffsLocalR;
  1330. public float offsy;
  1331. private int m_nShincho;
  1332. private int m_nDouPer;
  1333. private int m_nKubiScl;
  1334. private static List<string> m_listFileList = new List<string>();
  1335. private static List<GameObject> m_listGeneralModel = new List<GameObject>();
  1336. [Serializable]
  1337. public class OvrIkConfig : ISerializationCallbackReceiver
  1338. {
  1339. public void OnBeforeSerialize()
  1340. {
  1341. this.m_nVersion = 1200;
  1342. }
  1343. public void OnAfterDeserialize()
  1344. {
  1345. }
  1346. public bool Write()
  1347. {
  1348. string contents = JsonUtility.ToJson(this, true);
  1349. string path = Path.GetFullPath(".\\") + "OvrIK.json";
  1350. try
  1351. {
  1352. File.WriteAllText(path, contents);
  1353. }
  1354. catch
  1355. {
  1356. Debug.LogError("OvrIK.json の書き込みに失敗。");
  1357. return false;
  1358. }
  1359. return true;
  1360. }
  1361. public OvrIK.OvrIkConfig Read()
  1362. {
  1363. string path = Path.GetFullPath(".\\") + "OvrIK.json";
  1364. if (!File.Exists(path))
  1365. {
  1366. this.Write();
  1367. }
  1368. string json;
  1369. try
  1370. {
  1371. json = File.ReadAllText(path);
  1372. }
  1373. catch
  1374. {
  1375. Debug.LogError("OvrIK.json の読込に失敗。");
  1376. return this;
  1377. }
  1378. return JsonUtility.FromJson<OvrIK.OvrIkConfig>(json);
  1379. }
  1380. public void Update(VRIK f_vrik)
  1381. {
  1382. f_vrik.solver.locomotion.weight = this.solver_locomotion_weight;
  1383. f_vrik.solver.locomotion.footDistance = this.solver_locomotion_footDistance;
  1384. f_vrik.solver.locomotion.stepThreshold = this.solver_locomotion_stepThreshold;
  1385. f_vrik.solver.locomotion.angleThreshold = this.solver_locomotion_angleThreshold;
  1386. f_vrik.solver.locomotion.comAngleMlp = this.solver_locomotion_comAngleMlp;
  1387. f_vrik.solver.locomotion.maxVelocity = this.solver_locomotion_maxVelocity;
  1388. f_vrik.solver.locomotion.velocityFactor = this.solver_locomotion_velocityFactor;
  1389. f_vrik.solver.locomotion.maxLegStretch = this.solver_locomotion_maxLegStretch;
  1390. f_vrik.solver.locomotion.rootSpeed = this.solver_locomotion_rootSpeed;
  1391. f_vrik.solver.locomotion.stepSpeed = this.solver_locomotion_stepSpeed;
  1392. }
  1393. private const string CONF_NAME = "OvrIK.json";
  1394. [SerializeField]
  1395. private int m_nVersion = 1200;
  1396. [SerializeField]
  1397. private float solver_locomotion_weight = 1f;
  1398. [SerializeField]
  1399. private float solver_locomotion_footDistance = 0.1f;
  1400. [SerializeField]
  1401. private float solver_locomotion_stepThreshold = 0.28f;
  1402. [SerializeField]
  1403. private float solver_locomotion_angleThreshold = 60f;
  1404. [SerializeField]
  1405. private float solver_locomotion_comAngleMlp = 1f;
  1406. [SerializeField]
  1407. private float solver_locomotion_maxVelocity = 0.4f;
  1408. [SerializeField]
  1409. private float solver_locomotion_velocityFactor = 0.4f;
  1410. [SerializeField]
  1411. private float solver_locomotion_maxLegStretch = 1f;
  1412. [SerializeField]
  1413. private float solver_locomotion_rootSpeed = 20f;
  1414. [SerializeField]
  1415. private float solver_locomotion_stepSpeed = 3f;
  1416. [SerializeField]
  1417. private bool m_bHeadIsTracker;
  1418. [SerializeField]
  1419. public float m_fEyeToCamThresholdAngle = -0.9f;
  1420. [SerializeField]
  1421. public float leg_no_tracker_pos_weight = 0.3f;
  1422. [SerializeField]
  1423. public float leg_no_tracker_rot_weight = 0.3f;
  1424. }
  1425. }