THair1.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class THair1
  5. {
  6. public THair1(TBoneHair_ bonehair_, Transform t, Transform root_oya_, TBodyHit bh, THair1 p1 = null, THair1 p2 = null)
  7. {
  8. this.boDBL = (p1 != null);
  9. if (this.boDBL)
  10. {
  11. this.boDBL = true;
  12. this.pair = p1;
  13. this.pair2 = p2;
  14. }
  15. this.BodyHit = bh;
  16. this.bonehair = bonehair_;
  17. string text = t.name.ToLower();
  18. if (text.Contains("skirt"))
  19. {
  20. for (int i = 1; i <= 24; i++)
  21. {
  22. if (t.name.Contains(i.ToString("D2")))
  23. {
  24. this.SkirtIDX = i;
  25. break;
  26. }
  27. }
  28. }
  29. if (text.Contains("_h_"))
  30. {
  31. this.boHard = true;
  32. }
  33. this.root = t;
  34. this.root_oya = root_oya_;
  35. this.root_oya_eulerAngles = new Vector3(this.root_oya.eulerAngles.x, this.root_oya.eulerAngles.y, this.root_oya.eulerAngles.z);
  36. this.SoftG = new Vector3(0f, -0.003f, 0f);
  37. this.pair = null;
  38. this.hplist = new List<THp>();
  39. THp thp = new THp();
  40. thp.t = this.root_oya;
  41. THp prevSeg = thp;
  42. thp.PrevSeg = null;
  43. thp.defQ = thp.t.localRotation;
  44. thp.defLclPos_child = t.localPosition;
  45. thp.v = t.position;
  46. this.hplist.Add(thp);
  47. Vector3 b = t.position;
  48. if (p1 != null)
  49. {
  50. b = (p1.hplist[0].v + p2.hplist[0].v) * 0.5f;
  51. }
  52. Transform t_oya = this.root_oya;
  53. for (int j = 0; j < 30; j++)
  54. {
  55. if (t.childCount == 0)
  56. {
  57. break;
  58. }
  59. Transform child = t.GetChild(0);
  60. if (child == null)
  61. {
  62. break;
  63. }
  64. for (int k = 1; k <= this.HairDiv; k++)
  65. {
  66. THp thp2 = new THp();
  67. thp2.v = (child.position * (float)k + t.position * (float)(this.HairDiv - k)) / (float)this.HairDiv;
  68. if (p1 != null)
  69. {
  70. thp2.v = (p1.hplist[k].v + p1.hplist[k - 1].v + p2.hplist[k].v + p2.hplist[k - 1].v) * 0.25f;
  71. }
  72. if (bh.SphereCheck(thp2.v))
  73. {
  74. thp2.boUmari = true;
  75. }
  76. thp2.defLclPos_child = child.localPosition * (float)k / (float)this.HairDiv;
  77. Vector3 vector = t.TransformPoint(thp2.defLclPos_child);
  78. vector.y = 0f;
  79. thp2.vone = vector.normalized;
  80. thp2.mae = Mathf.Clamp(thp2.vone.z * 0.7f + 0.5f, 0f, 1f);
  81. thp2.WideCircleLen = (thp2.v - this.hplist[0].t.position).magnitude;
  82. thp2.len = (thp2.v - b).magnitude;
  83. thp2.lenxlen = thp2.len * thp2.len;
  84. thp2.SegLength = (t.position - thp2.v).magnitude;
  85. if (thp2.SegLength <= 0f)
  86. {
  87. Debug.LogError("hp seg len==0");
  88. }
  89. thp2.t = t;
  90. thp2.t_oya = t_oya;
  91. thp2.defQ = t.localRotation;
  92. thp2.invQ = Quaternion.Inverse(t.localRotation);
  93. thp2.vec_up = thp2.t.up;
  94. thp2.rotRev = 90f;
  95. if (t.transform.right.y < 0f)
  96. {
  97. this.boXREV = true;
  98. }
  99. thp2.PrevSeg = prevSeg;
  100. if (k % this.HairDiv == 0)
  101. {
  102. prevSeg = thp2;
  103. }
  104. this.hplist.Add(thp2);
  105. b = thp2.v;
  106. }
  107. t_oya = t;
  108. t = child;
  109. }
  110. if (this.boDBL)
  111. {
  112. this.SoftG = p1.SoftG;
  113. for (int l = 1; l < this.hplist.Count; l++)
  114. {
  115. this.hplist[l].SoftPer = p1.hplist[l].SoftPer;
  116. this.hplist[l].SoftTgtG = p1.hplist[l].SoftTgtG;
  117. }
  118. }
  119. this.pointCount = this.hplist.Count / this.HairDiv;
  120. }
  121. public void SetPair(THair1 tp, THair1 tp2)
  122. {
  123. this.pair = tp;
  124. this.pair2 = tp2;
  125. for (int i = 0; i < this.hplist.Count; i++)
  126. {
  127. this.hplist[i].PairLength = (this.hplist[i].v - tp.hplist[i].v).magnitude * 0.5f;
  128. }
  129. }
  130. public void CheckPair(int i)
  131. {
  132. if (this.pair == null)
  133. {
  134. Debug.LogError("ERR CheckPair " + i.ToString());
  135. }
  136. if (this.pair2 == null)
  137. {
  138. Debug.LogError("ERR CheckPair2 " + i.ToString());
  139. }
  140. }
  141. public void SetUpDefTgt(bool boInit = false)
  142. {
  143. this.HitHeightY = this.bonehair.body.BoneHitHeightY + 0.03f;
  144. this.boWarpInitMode = boInit;
  145. if (this.hplist.Count < 2)
  146. {
  147. return;
  148. }
  149. for (int i = 0; i < this.hplist.Count; i++)
  150. {
  151. this.hplist[i].v_old = this.hplist[i].v;
  152. }
  153. for (int j = 1; j < this.hplist.Count; j++)
  154. {
  155. THp thp = this.hplist[j];
  156. if (this.pair != null)
  157. {
  158. THp thp2 = this.pair.hplist[j];
  159. thp.MST = (thp.v - thp2.v).sqrMagnitude / thp.PairLength * 2f;
  160. }
  161. }
  162. if (this.boDBL)
  163. {
  164. for (int k = 1; k < this.hplist.Count; k++)
  165. {
  166. THp thp3 = this.hplist[k];
  167. thp3.vTGT = (this.pair.hplist[k].vTGT + this.pair2.hplist[k].vTGT + this.pair.hplist[k - 1].vTGT + this.pair2.hplist[k - 1].vTGT) * 0.25f;
  168. if (this.boDebugLine)
  169. {
  170. Debug.DrawLine(thp3.vTGT, thp3.vTGT - Vector3.right * 0.005f, Color.yellow);
  171. }
  172. }
  173. this.hplist[0].vTGT = (this.pair.hplist[0].vTGT + this.pair2.hplist[0].vTGT) * 0.5f;
  174. this.hplist[0].v = this.hplist[0].vTGT;
  175. if (boInit)
  176. {
  177. for (int l = 0; l < this.hplist.Count; l++)
  178. {
  179. this.hplist[l].v = this.hplist[l].vTGT;
  180. this.hplist[l].v_old = this.hplist[l].vTGT;
  181. this.hplist[l].g = Vector3.zero;
  182. }
  183. }
  184. return;
  185. }
  186. Vector3 a = this.hplist[1].t.position;
  187. Quaternion quaternion = this.root_oya.rotation;
  188. for (int m = 1; m < this.hplist.Count; m++)
  189. {
  190. THp thp4 = this.hplist[m];
  191. if (m % this.HairDiv == 1)
  192. {
  193. quaternion *= thp4.defQ;
  194. if (this.boXREV)
  195. {
  196. quaternion *= Quaternion.Euler(0f, 180f, 0f);
  197. }
  198. }
  199. Vector3 vector = a + quaternion * thp4.defLclPos_child;
  200. if (m % this.HairDiv == 0)
  201. {
  202. a = vector;
  203. }
  204. if (this.boDebugLine)
  205. {
  206. Debug.DrawLine(vector, vector - Vector3.right * 0.005f, Color.red);
  207. }
  208. float num = (float)m * 0.05f + 0.5f;
  209. if (num > 1f)
  210. {
  211. }
  212. thp4.vTGT = vector;
  213. }
  214. this.hplist[0].vTGT = this.root.position;
  215. this.hplist[0].v = this.root.position;
  216. if (boInit)
  217. {
  218. for (int n = 0; n < this.hplist.Count; n++)
  219. {
  220. this.hplist[n].v = this.hplist[n].vTGT;
  221. this.hplist[n].v_old = this.hplist[n].vTGT;
  222. this.hplist[n].g = Vector3.zero;
  223. }
  224. }
  225. }
  226. public void Calc(TBodyHit bh)
  227. {
  228. if (this.hplist.Count < 2)
  229. {
  230. return;
  231. }
  232. if (this.bonehair.trsKusari[this.KusariIDX] != null)
  233. {
  234. if (this.bonehair.trsKusari[this.KusariIDX] != null)
  235. {
  236. this.hplist[this.hplist.Count - 1].v = this.bonehair.trsKusari[this.KusariIDX].position;
  237. }
  238. for (int i = 1; i < this.hplist.Count - 1; i++)
  239. {
  240. THp thp = this.hplist[i];
  241. thp.g += new Vector3(0f, -0.001f, 0f);
  242. thp.g *= 0.99f;
  243. thp.v += thp.g;
  244. }
  245. for (int j = this.hplist.Count - 1; j >= 2; j--)
  246. {
  247. THp thp2 = this.hplist[j];
  248. Vector3 a = this.hplist[j - 1].v - thp2.v;
  249. if (a.sqrMagnitude > thp2.lenxlen)
  250. {
  251. float magnitude = a.magnitude;
  252. Vector3 b = a / magnitude * thp2.len;
  253. this.hplist[j - 1].v = thp2.v + b;
  254. this.hplist[j - 1].g -= a * 0.01f;
  255. }
  256. if (this.bonehair.bodyskin.m_bHitFloorY && thp2.v.y < this.HitHeightY)
  257. {
  258. thp2.v.y = this.HitHeightY;
  259. thp2.g *= 0.9f;
  260. }
  261. }
  262. for (int k = 1; k < this.hplist.Count; k++)
  263. {
  264. THp thp3 = this.hplist[k];
  265. Vector3 a2 = thp3.v - this.hplist[k - 1].v;
  266. if (a2.sqrMagnitude > thp3.lenxlen)
  267. {
  268. float magnitude2 = a2.magnitude;
  269. Vector3 b2 = a2 / magnitude2 * thp3.len;
  270. thp3.v = this.hplist[k - 1].v + b2;
  271. thp3.g -= a2 * 0.01f;
  272. }
  273. thp3.Secchi = bh.SphereMove_hair2(ref thp3.v, ref thp3.g, thp3.v_old);
  274. if (this.bonehair.bodyskin.m_bHitFloorY && thp3.v.y < this.HitHeightY)
  275. {
  276. thp3.v.y = this.HitHeightY;
  277. thp3.g *= 0.9f;
  278. }
  279. }
  280. return;
  281. }
  282. for (int l = this.hplist.Count - 1; l >= 1; l--)
  283. {
  284. THp thp4 = this.hplist[l];
  285. float softPer = thp4.SoftPer;
  286. Vector3 a3 = (thp4.vTGT - this.hplist[l - 1].vTGT) * thp4.SoftTgtG;
  287. thp4.g += this.SoftG * softPer + a3 * (1f - softPer);
  288. thp4.g *= 0.99f;
  289. Vector3 vector = this.hplist[l - 1].v - thp4.v;
  290. thp4.v += thp4.g;
  291. if ((this.bonehair.bodyskin.SlotId != TBody.SlotID.hairR && this.bonehair.bodyskin.SlotId != TBody.SlotID.hairT) || this.bonehair.body.Mode_HairR == TBody.ModeHirR.NoFront)
  292. {
  293. }
  294. }
  295. for (int m = 1; m < this.hplist.Count; m++)
  296. {
  297. THp thp5 = this.hplist[m];
  298. Vector3 a4 = thp5.v - this.hplist[m - 1].v;
  299. if (a4.sqrMagnitude > thp5.lenxlen)
  300. {
  301. float magnitude3 = a4.magnitude;
  302. Vector3 vector2 = this.hplist[m - 1].v + a4 / magnitude3 * thp5.len;
  303. if (!thp5.Secchi)
  304. {
  305. thp5.g += (vector2 - thp5.v) * 0.05f;
  306. }
  307. thp5.v = vector2;
  308. }
  309. thp5.Secchi = bh.SphereMove_hair2(ref thp5.v, ref thp5.g, thp5.v_old);
  310. if (this.bonehair.bodyskin.m_bHitFloorY && thp5.v.y < this.HitHeightY)
  311. {
  312. thp5.v.y = this.HitHeightY;
  313. thp5.g *= 0.9f;
  314. }
  315. }
  316. }
  317. public void Calc_skirt2(int i)
  318. {
  319. THp thp = this.hplist[i];
  320. this.hplist[i].PairLength = (this.hplist[i].vTGT - this.pair.hplist[i].vTGT).magnitude * 0.5f;
  321. float softPer = thp.SoftPer;
  322. Vector3 a = (thp.vTGT - this.hplist[i - 1].vTGT) * thp.SoftTgtG;
  323. thp.g += this.SoftG * softPer + a * (1f - softPer);
  324. float d = (float)((this.hplist.Count - i) / this.HairDiv);
  325. thp.g += (this.hplist[0].v - this.hplist[0].v_old) * 0.2f * d;
  326. thp.g *= 0.999f;
  327. thp.v += thp.g;
  328. }
  329. public void Calc_skirt_WideCircle(int i)
  330. {
  331. THp thp = this.hplist[i];
  332. Vector3 a = thp.v - this.hplist[0].v;
  333. float num = thp.WideCircleLen * 0.5f;
  334. if (a.sqrMagnitude < num * num)
  335. {
  336. float magnitude = a.magnitude;
  337. Vector3 v = this.hplist[0].v + a / magnitude * num;
  338. thp.v = v;
  339. }
  340. thp.Secchi = this.BodyHit.SphereMove_skrt(ref thp.v, ref thp.g);
  341. }
  342. public void Calc_skirt_up(int i)
  343. {
  344. THp thp = this.hplist[i];
  345. Vector3 a = thp.v - this.hplist[i - 1].v;
  346. if (a.sqrMagnitude > thp.lenxlen)
  347. {
  348. float magnitude = a.magnitude;
  349. Vector3 vector = this.hplist[i - 1].v + a / magnitude * thp.len;
  350. thp.g += (vector - thp.v) * 0.5f;
  351. thp.v = vector;
  352. }
  353. thp.Secchi = this.BodyHit.SphereMove_skrt(ref thp.v, ref thp.g);
  354. }
  355. public void Calc_skirt_pair(int i)
  356. {
  357. THp thp = this.hplist[i];
  358. THp thp2 = this.pair.hplist[i];
  359. THp thp3 = this.pair2.hplist[i];
  360. float num = 0.5f;
  361. float num2 = thp3.MST + thp2.MST;
  362. if (num2 != 0f)
  363. {
  364. num = thp3.MST / num2;
  365. }
  366. Vector3 a = thp2.v - thp.v;
  367. Vector3 a2 = thp.v * num + thp2.v * (1f - num);
  368. float magnitude = a.magnitude;
  369. if (magnitude < thp.PairLength)
  370. {
  371. return;
  372. }
  373. a /= magnitude;
  374. a.Normalize();
  375. this.BodyHit.SphereMove_skrt(ref a2, ref thp.g);
  376. if (this.boDebugLine && this.BodyHit.MST > 0f)
  377. {
  378. Debug.DrawLine(thp.v, thp.v + this.BodyHit.MST_v * 10f, Color.white);
  379. }
  380. Vector3 a3 = a2 + a * num * this.hplist[i].PairLength;
  381. Vector3 a4 = a2 - a * (1f - num) * this.hplist[i].PairLength;
  382. float num3 = 0.5f;
  383. thp2.v = thp2.v * (1f - num3) + a3 * num3;
  384. thp.v = thp.v * (1f - num3) + a4 * num3;
  385. }
  386. public void Proc(TBodyHit bh)
  387. {
  388. if (this.hplist.Count < 2)
  389. {
  390. return;
  391. }
  392. if (this.boDebugLine)
  393. {
  394. for (int i = 0; i < this.hplist.Count; i++)
  395. {
  396. THp thp = this.hplist[i];
  397. Color color = new Color(1f, 1f - thp.mae, thp.mae);
  398. color = Color.red;
  399. if (this.boDBL)
  400. {
  401. color = Color.yellow;
  402. }
  403. if (i > 0)
  404. {
  405. Debug.DrawLine(thp.v, this.hplist[i - 1].v, color);
  406. }
  407. color = Color.white;
  408. if (thp.Secchi)
  409. {
  410. color = Color.yellow;
  411. }
  412. }
  413. }
  414. if (this.boDBL)
  415. {
  416. return;
  417. }
  418. float num = 1f;
  419. Transform transform = this.root;
  420. int num2 = this.hplist.Count / this.HairDiv;
  421. for (int j = 0; j < num2; j++)
  422. {
  423. if (transform.childCount == 0)
  424. {
  425. break;
  426. }
  427. Transform child = transform.GetChild(0);
  428. if (child == null)
  429. {
  430. break;
  431. }
  432. Quaternion quaternion = default(Quaternion);
  433. Vector3 vector = this.hplist[j * this.HairDiv + this.HairDiv].v - this.hplist[j * this.HairDiv].v;
  434. float magnitude = vector.magnitude;
  435. if (magnitude != 0f)
  436. {
  437. float num3 = magnitude / this.hplist[j * this.HairDiv + this.HairDiv].SegLength;
  438. num = num3 / num;
  439. if (num <= 0f)
  440. {
  441. Debug.LogError("scl<=0");
  442. }
  443. if (num < 0.1f)
  444. {
  445. num = 0.1f;
  446. }
  447. if (num > 10f)
  448. {
  449. num = 10f;
  450. }
  451. float num4 = 1f;
  452. transform.localScale = new Vector3(num * num4, num * num4, num * num4);
  453. Vector3 vec_up = this.hplist[j * this.HairDiv + 1].vec_up;
  454. if (vector != Vector3.zero)
  455. {
  456. quaternion.SetLookRotation(vector, vec_up);
  457. }
  458. quaternion *= Quaternion.Euler(0f, this.hplist[j * this.HairDiv + 1].rotRev, 0f);
  459. Vector3 eulerAngles = this.root_oya.eulerAngles;
  460. if (this.pointCount > 1)
  461. {
  462. quaternion *= Quaternion.Euler(eulerAngles.y + bh.RotOffset, 0f, 0f);
  463. }
  464. transform.rotation = quaternion;
  465. transform.localRotation = this.hplist[j * this.HairDiv + 1].defQ;
  466. Vector3 fromDirection = child.position - transform.position;
  467. Vector3 toDirection = this.hplist[j * this.HairDiv + this.HairDiv].v - this.hplist[j * this.HairDiv].v;
  468. transform.rotation = Quaternion.FromToRotation(fromDirection, toDirection) * transform.rotation;
  469. transform = child;
  470. }
  471. }
  472. }
  473. public bool boWarpInitMode;
  474. public TBoneHair_ bonehair;
  475. public TBodyHit BodyHit;
  476. public bool boDebugLine;
  477. public HairMode Mode = HairMode.hair;
  478. public Vector3 SoftG;
  479. public bool boXREV;
  480. public List<THp> hplist;
  481. public int pointCount;
  482. public Transform root;
  483. public Transform root_oya;
  484. private THair1 pair;
  485. private THair1 pair2;
  486. public int HairDiv = 2;
  487. public Vector3 root_oya_eulerAngles;
  488. public Vector3 Calf_L_pos_old;
  489. public Vector3 Calf_R_pos_old;
  490. public Vector3 Thigh_L_pos_old;
  491. public Vector3 Thigh_R_pos_old;
  492. public int KusariIDX;
  493. public int SkirtIDX;
  494. public bool boHard;
  495. public float HitHeightY;
  496. public bool boDBL;
  497. }