BoneMorph_.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using UnityEngine;
  5. public class BoneMorph_
  6. {
  7. public void Init()
  8. {
  9. if (this.bones != null)
  10. {
  11. for (int i = this.bones.Count - 1; i >= 0; i--)
  12. {
  13. BoneMorphLocal boneMorphLocal = this.bones[i];
  14. if (boneMorphLocal.linkT != null)
  15. {
  16. boneMorphLocal.linkT.localPosition = boneMorphLocal.pos;
  17. }
  18. }
  19. }
  20. this.bones = new List<BoneMorphLocal>();
  21. }
  22. public void Uninit()
  23. {
  24. this.m_listBoneMorphPos.Clear();
  25. this.m_listBoneMorphScl.Clear();
  26. }
  27. public void InitBoneMorphEdit(Transform t, MPN f_mpn, TBody.SlotID f_slot)
  28. {
  29. if (f_mpn == MPN.head && f_slot == TBody.SlotID.head)
  30. {
  31. Transform transform = CMT.SearchObjName(t, "Mayupos", false);
  32. if (transform != null)
  33. {
  34. this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "MayuY");
  35. this.m_listBoneMorphPos.Add(new BoneMorph_.BoneMorphPos("MayuY", transform));
  36. }
  37. Transform transform2 = CMT.SearchObjName(t, "Eye_L", false);
  38. if (transform2 != null)
  39. {
  40. this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosXL");
  41. this.m_listBoneMorphPos.Add(new BoneMorph_.BoneMorphPos("EyeBallPosXL", transform2));
  42. this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosYL");
  43. this.m_listBoneMorphPos.Add(new BoneMorph_.BoneMorphPos("EyeBallPosYL", transform2, new Vector3(0.00325f, -0.005f, 0f), new Vector3(0f, 0.004f, 0f)));
  44. this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclXL");
  45. this.m_listBoneMorphScl.Add(new BoneMorph_.BoneMorphScl("EyeBallSclXL", transform2, new Vector3(0f, -0.3f, -0.3f), new Vector3(0f, 0.1f, 0.1f)));
  46. this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclYL");
  47. this.m_listBoneMorphScl.Add(new BoneMorph_.BoneMorphScl("EyeBallSclYL", transform2, new Vector3(0f, -0.3f, -0.3f), new Vector3(0f, 0.1f, 0.1f)));
  48. }
  49. Transform transform3 = CMT.SearchObjName(t, "Eye_R", false);
  50. if (transform3 != null)
  51. {
  52. this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosXR");
  53. this.m_listBoneMorphPos.Add(new BoneMorph_.BoneMorphPos("EyeBallPosXR", transform3));
  54. this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosYR");
  55. this.m_listBoneMorphPos.Add(new BoneMorph_.BoneMorphPos("EyeBallPosYR", transform3, new Vector3(0.00325f, 0.005f, 0f), new Vector3(0f, -0.004f, 0f)));
  56. this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclXR");
  57. this.m_listBoneMorphScl.Add(new BoneMorph_.BoneMorphScl("EyeBallSclXR", transform3, new Vector3(0f, -0.3f, -0.3f), new Vector3(0f, 0.1f, 0.1f)));
  58. this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclYR");
  59. this.m_listBoneMorphScl.Add(new BoneMorph_.BoneMorphScl("EyeBallSclYR", transform3, new Vector3(0f, -0.3f, -0.3f), new Vector3(0f, 0.1f, 0.1f)));
  60. }
  61. }
  62. }
  63. public void DelBoneMorphEdit(MPN f_mpn, TBody.SlotID f_slot)
  64. {
  65. if (f_mpn == MPN.head && f_slot == TBody.SlotID.head)
  66. {
  67. this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "MayuY");
  68. this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosXL");
  69. this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosYL");
  70. this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclXL");
  71. this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclXR");
  72. this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosXR");
  73. this.m_listBoneMorphPos.RemoveAll((BoneMorph_.BoneMorphPos f) => f.strPropName == "EyeBallPosYR");
  74. this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclYL");
  75. this.m_listBoneMorphScl.RemoveAll((BoneMorph_.BoneMorphScl f) => f.strPropName == "EyeBallSclYR");
  76. }
  77. }
  78. private void AddRoot_lp(Transform t, int level = 0, float Kahanshin = 0f)
  79. {
  80. string name = t.name;
  81. if (name.Contains("Thigh"))
  82. {
  83. Kahanshin = 1f;
  84. }
  85. BoneMorphLocal boneMorphLocal = null;
  86. List<BoneMorph.BoneProp> list = null;
  87. if (BoneMorph.dic2.TryGetValue(name, out list))
  88. {
  89. for (int i = 0; i < list.Count; i++)
  90. {
  91. BoneMorph.BoneProp boneProp = list[i];
  92. if (boneMorphLocal == null)
  93. {
  94. boneMorphLocal = new BoneMorphLocal();
  95. boneMorphLocal.atr = 0L;
  96. boneMorphLocal.linkT = t;
  97. boneMorphLocal.pos = t.localPosition;
  98. boneMorphLocal.Kahanshin = Kahanshin;
  99. }
  100. int nIndex = boneProp.nIndex;
  101. if (boneProp.bExistM)
  102. {
  103. boneMorphLocal.atr |= 1L << nIndex;
  104. boneMorphLocal.vecs_min[nIndex] = boneProp.vMinM;
  105. boneMorphLocal.vecs_max[nIndex] = boneProp.vMaxM;
  106. }
  107. if (boneProp.bExistP)
  108. {
  109. boneMorphLocal.atr |= 1L << nIndex + 32;
  110. boneMorphLocal.vecs_min[nIndex + 32] = boneProp.vMinP;
  111. boneMorphLocal.vecs_max[nIndex + 32] = boneProp.vMaxP;
  112. }
  113. boneMorphLocal.props.Add(boneProp.strProp);
  114. }
  115. }
  116. if (boneMorphLocal != null)
  117. {
  118. this.bones.Add(boneMorphLocal);
  119. }
  120. for (int j = 0; j < t.childCount; j++)
  121. {
  122. this.AddRoot_lp(t.GetChild(j), level + 1, Kahanshin);
  123. }
  124. }
  125. public void AddRoot(Transform root)
  126. {
  127. this.AddRoot_lp(root, 0, 0f);
  128. }
  129. public void ChangeMorphPosValue(string strPropName, string f_strBoneName, Vector3 f_fAddMin, Vector3 f_fAddMax)
  130. {
  131. BoneMorph_.BoneMorphPos boneMorphPos = this.m_listBoneMorphPos.Find((BoneMorph_.BoneMorphPos f) => f.strPropName == strPropName && f.trBone.name == f_strBoneName);
  132. if (boneMorphPos != null)
  133. {
  134. boneMorphPos.m_vAddMin = boneMorphPos.trBone.localPosition + f_fAddMin;
  135. boneMorphPos.m_vAddMax = boneMorphPos.trBone.localPosition + f_fAddMax;
  136. }
  137. }
  138. public void ChangeMorphSclValue(string strPropName, string f_strBoneName, Vector3 f_fAddMin, Vector3 f_fAddMax)
  139. {
  140. BoneMorph_.BoneMorphScl boneMorphScl = this.m_listBoneMorphScl.Find((BoneMorph_.BoneMorphScl f) => f.strPropName == strPropName && f.trBone.name == f_strBoneName);
  141. if (boneMorphScl != null)
  142. {
  143. boneMorphScl.m_vAddMin = boneMorphScl.trBone.localScale + f_fAddMin;
  144. boneMorphScl.m_vAddMax = boneMorphScl.trBone.localScale + f_fAddMax;
  145. }
  146. }
  147. public void Blend()
  148. {
  149. for (int i = this.bones.Count - 1; i >= 0; i--)
  150. {
  151. BoneMorphLocal boneMorphLocal = this.bones[i];
  152. Vector3 vector = new Vector3(1f, 1f, 1f);
  153. Vector3 vector2 = boneMorphLocal.pos;
  154. for (int j = 0; j < BoneMorph.PropNames.Length; j++)
  155. {
  156. float num = 1f;
  157. if (j == 0)
  158. {
  159. num = this.SCALE_Kubi;
  160. }
  161. if (j == 1)
  162. {
  163. num = this.SCALE_Ude;
  164. }
  165. if (j == 2)
  166. {
  167. num = this.SCALE_EyeX;
  168. }
  169. if (j == 3)
  170. {
  171. num = this.SCALE_EyeY;
  172. }
  173. if (j == 4)
  174. {
  175. num = this.Postion_EyeX * (0.5f + this.Postion_EyeY * 0.5f);
  176. }
  177. if (j == 5)
  178. {
  179. num = this.Postion_EyeY;
  180. }
  181. if (j == 6)
  182. {
  183. num = this.SCALE_HeadX;
  184. }
  185. if (j == 7)
  186. {
  187. num = this.SCALE_HeadY;
  188. }
  189. if (j == 8)
  190. {
  191. num = this.SCALE_DouPer;
  192. if (boneMorphLocal.Kahanshin == 0f)
  193. {
  194. num = 1f - num;
  195. }
  196. }
  197. if (j == 9)
  198. {
  199. num = this.SCALE_Sintyou;
  200. }
  201. if (j == 10)
  202. {
  203. num = this.SCALE_Koshi;
  204. }
  205. if (j == 11)
  206. {
  207. num = this.SCALE_Kata;
  208. }
  209. if (j == 12)
  210. {
  211. num = this.SCALE_West;
  212. }
  213. if ((boneMorphLocal.atr & 1L << j) != 0L)
  214. {
  215. vector = Vector3.Scale(vector, Vector3.Lerp(boneMorphLocal.vecs_min[j], boneMorphLocal.vecs_max[j], num));
  216. }
  217. if ((boneMorphLocal.atr & 1L << 32 + j) != 0L)
  218. {
  219. vector2 = Vector3.Scale(vector2, Vector3.Lerp(boneMorphLocal.vecs_min[j + 32], boneMorphLocal.vecs_max[j + 32], num));
  220. }
  221. }
  222. if (boneMorphLocal.linkT.name.Contains("Thigh_SCL_"))
  223. {
  224. this.SnityouOutScale = Mathf.Pow(vector.x, 0.9f);
  225. }
  226. boneMorphLocal.linkT.localPosition = vector2;
  227. boneMorphLocal.linkT.localScale = vector;
  228. }
  229. for (int k = 0; k < this.m_listBoneMorphPos.Count; k++)
  230. {
  231. BoneMorph_.BoneMorphPos boneMorphPos = this.m_listBoneMorphPos[k];
  232. if (boneMorphPos.strPropName == "MayuY")
  233. {
  234. boneMorphPos.trBone.localPosition = ((this.POS_MayuY > 0.5f) ? Vector3.Lerp(boneMorphPos.m_vDefPos, boneMorphPos.m_vAddMax, (this.POS_MayuY - 0.5f) / 0.5f) : Vector3.Lerp(boneMorphPos.m_vAddMin, boneMorphPos.m_vDefPos, this.POS_MayuY / 0.5f));
  235. }
  236. else if (boneMorphPos.strPropName == "EyeBallPosYL" || boneMorphPos.strPropName == "EyeBallPosYR")
  237. {
  238. boneMorphPos.trBone.localPosition = ((this.EyeBallPosY > 0.5f) ? Vector3.Lerp(boneMorphPos.m_vDefPos, boneMorphPos.m_vAddMax, (this.EyeBallPosY - 0.5f) / 0.5f) : Vector3.Lerp(boneMorphPos.m_vAddMin, boneMorphPos.m_vDefPos, this.EyeBallPosY / 0.5f));
  239. }
  240. }
  241. for (int l = 0; l < this.m_listBoneMorphScl.Count; l++)
  242. {
  243. BoneMorph_.BoneMorphScl boneMorphScl = this.m_listBoneMorphScl[l];
  244. if (boneMorphScl.strPropName == "EyeBallSclXL" || boneMorphScl.strPropName == "EyeBallSclXR")
  245. {
  246. float z = (this.EyeBallSclX >= 0.5f) ? Mathf.Lerp(boneMorphScl.m_vDefScl.z, boneMorphScl.m_vAddMax.z, (this.EyeBallSclX - 0.5f) / 0.5f) : Mathf.Lerp(boneMorphScl.m_vAddMin.z, boneMorphScl.m_vDefScl.z, this.EyeBallSclX / 0.5f);
  247. Vector3 localScale = boneMorphScl.trBone.localScale;
  248. localScale.z = z;
  249. boneMorphScl.trBone.localScale = localScale;
  250. }
  251. else if (boneMorphScl.strPropName == "EyeBallSclYL" || boneMorphScl.strPropName == "EyeBallSclYR")
  252. {
  253. float y = (this.EyeBallSclY >= 0.5f) ? Mathf.Lerp(boneMorphScl.m_vDefScl.y, boneMorphScl.m_vAddMax.y, (this.EyeBallSclY - 0.5f) / 0.5f) : Mathf.Lerp(boneMorphScl.m_vAddMin.y, boneMorphScl.m_vDefScl.y, this.EyeBallSclY / 0.5f);
  254. Vector3 localScale2 = boneMorphScl.trBone.localScale;
  255. localScale2.y = y;
  256. boneMorphScl.trBone.localScale = localScale2;
  257. }
  258. }
  259. }
  260. private TextAsset textUserDef1;
  261. public float SCALE_Sintyou = 1f;
  262. public float SCALE_Koshi = 1f;
  263. public float SCALE_DouPer;
  264. public float SCALE_Kata = 1f;
  265. public float SCALE_West = 1f;
  266. public float SCALE_EyeX = 1f;
  267. public float SCALE_EyeY = 1f;
  268. public float Postion_EyeX = 1f;
  269. public float Postion_EyeY = 1f;
  270. public float EyeBallPosX = 0.5f;
  271. public float EyeBallPosY = 0.5f;
  272. public float EyeBallSclX = 0.5f;
  273. public float EyeBallSclY = 0.5f;
  274. public float SCALE_Kubi = 1f;
  275. public float SCALE_Ude = 1f;
  276. public float SCALE_HeadX = 1f;
  277. public float SCALE_HeadY = 1f;
  278. public float POS_MayuY = 0.5f;
  279. public List<BoneMorphLocal> bones;
  280. public float SnityouOutScale = 1f;
  281. private bool m_bMayuOffs;
  282. private List<BoneMorph_.BoneMorphPos> m_listBoneMorphPos = new List<BoneMorph_.BoneMorphPos>();
  283. private List<BoneMorph_.BoneMorphScl> m_listBoneMorphScl = new List<BoneMorph_.BoneMorphScl>();
  284. private static StringBuilder sbMinM = new StringBuilder(32);
  285. private static StringBuilder sbMinP = new StringBuilder(32);
  286. private static StringBuilder sbMaxM = new StringBuilder(32);
  287. private static StringBuilder sbMaxP = new StringBuilder(32);
  288. private class BoneMorphPos
  289. {
  290. public BoneMorphPos(string f_strPropName, Transform f_trBone)
  291. {
  292. this.strPropName = f_strPropName;
  293. this.trBone = f_trBone;
  294. this.m_vAddMin = (this.m_vAddMax = (this.m_vDefPos = f_trBone.localPosition));
  295. }
  296. public BoneMorphPos(string f_strPropName, Transform f_trBone, Vector3 f_vAddMin, Vector3 f_vAddMax)
  297. {
  298. this.strPropName = f_strPropName;
  299. this.trBone = f_trBone;
  300. this.m_vDefPos = f_trBone.localPosition;
  301. this.m_vAddMin = this.m_vDefPos + f_vAddMin;
  302. this.m_vAddMax = this.m_vDefPos + f_vAddMax;
  303. }
  304. public string strPropName;
  305. public Transform trBone;
  306. public Vector3 m_vDefPos;
  307. public Vector3 m_vAddMin;
  308. public Vector3 m_vAddMax;
  309. }
  310. private class BoneMorphScl
  311. {
  312. public BoneMorphScl(string f_strPropName, Transform f_trBone)
  313. {
  314. this.strPropName = f_strPropName;
  315. this.trBone = f_trBone;
  316. this.m_vAddMin = (this.m_vAddMax = (this.m_vDefScl = f_trBone.localScale));
  317. }
  318. public BoneMorphScl(string f_strPropName, Transform f_trBone, Vector3 f_vAddMin, Vector3 f_vAddMax)
  319. {
  320. this.strPropName = f_strPropName;
  321. this.trBone = f_trBone;
  322. this.m_vDefScl = f_trBone.localScale;
  323. this.m_vAddMin = this.m_vDefScl + f_vAddMin;
  324. this.m_vAddMax = this.m_vDefScl + f_vAddMax;
  325. }
  326. public string strPropName;
  327. public Transform trBone;
  328. public Vector3 m_vDefScl;
  329. public Vector3 m_vAddMin;
  330. public Vector3 m_vAddMax;
  331. }
  332. }