DynamicSkirtBone.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Runtime.InteropServices;
  5. using UnityEngine;
  6. public class DynamicSkirtBone : MonoBehaviour
  7. {
  8. [DllImport("kernel32.dll")]
  9. private static extern IntPtr LoadLibraryW(byte[] dllToLoad);
  10. [DllImport("kernel32.dll")]
  11. private static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
  12. [DllImport("kernel32.dll")]
  13. private static extern bool FreeLibrary(IntPtr hModule);
  14. public bool SerializeWrite(BinaryWriter f_bw)
  15. {
  16. f_bw.Write("CM3D21_PSK");
  17. f_bw.Write(1130);
  18. f_bw.Write(this.m_fPanierRadius);
  19. this.SerializeWriteAnimationCurve(f_bw, this.m_PanierRadiusDistrib);
  20. int num = (this.m_PanierRadiusDistribGroup == null) ? 0 : this.m_PanierRadiusDistribGroup.Length;
  21. f_bw.Write(num);
  22. for (int i = 0; i < num; i++)
  23. {
  24. DynamicSkirtBone.PanierRadiusGroup panierRadiusGroup = this.m_PanierRadiusDistribGroup[i];
  25. f_bw.Write(panierRadiusGroup.strBoneName);
  26. f_bw.Write(panierRadiusGroup.fRadius);
  27. this.SerializeWriteAnimationCurve(f_bw, panierRadiusGroup.Curve);
  28. }
  29. f_bw.Write(this.m_fPanierForce);
  30. this.SerializeWriteAnimationCurve(f_bw, this.m_PanierForceDistrib);
  31. f_bw.Write(this.m_fPanierStressForce);
  32. f_bw.Write(this.m_fStressDgreeMin);
  33. f_bw.Write(this.m_fStressDgreeMax);
  34. f_bw.Write(this.m_fStressMinScale);
  35. f_bw.Write(this.m_fScaleEaseSpeed);
  36. f_bw.Write(this.m_fPanierForceDistanceThreshold);
  37. f_bw.Write(this.m_nCalcTime);
  38. f_bw.Write(this.m_fVelocityForceRate);
  39. this.SerializeWriteAnimationCurve(f_bw, this.m_VelocityForceRateDistrib);
  40. f_bw.Write(this.m_vGravity.x);
  41. f_bw.Write(this.m_vGravity.y);
  42. f_bw.Write(this.m_vGravity.z);
  43. this.SerializeWriteAnimationCurve(f_bw, this.m_GravityDistrib);
  44. f_bw.Write(this.m_aryHard[0]);
  45. f_bw.Write(this.m_aryHard[1]);
  46. f_bw.Write(this.m_aryHard[2]);
  47. f_bw.Write(this.m_aryHard[3]);
  48. return true;
  49. }
  50. private void SerializeWriteAnimationCurve(BinaryWriter f_bw, AnimationCurve f_ac)
  51. {
  52. Keyframe[] keys = f_ac.keys;
  53. f_bw.Write(keys.Length);
  54. for (int i = 0; i < keys.Length; i++)
  55. {
  56. f_bw.Write(keys[i].time);
  57. f_bw.Write(keys[i].value);
  58. f_bw.Write(keys[i].inTangent);
  59. f_bw.Write(keys[i].outTangent);
  60. }
  61. }
  62. public void SerializeRead(BinaryReader f_br)
  63. {
  64. string a = f_br.ReadString();
  65. if (a != "CM3D21_PSK")
  66. {
  67. NDebug.Assert("物理スカート定義ヘッダー不正", false);
  68. }
  69. int num = f_br.ReadInt32();
  70. this.m_fPanierRadius = f_br.ReadSingle();
  71. this.SerializeReadAnimationCurve(f_br, out this.m_PanierRadiusDistrib);
  72. if (217 <= num)
  73. {
  74. int num2 = f_br.ReadInt32();
  75. if (num2 != 0)
  76. {
  77. this.m_PanierRadiusDistribGroup = new DynamicSkirtBone.PanierRadiusGroup[num2];
  78. }
  79. for (int i = 0; i < num2; i++)
  80. {
  81. DynamicSkirtBone.PanierRadiusGroup panierRadiusGroup = new DynamicSkirtBone.PanierRadiusGroup();
  82. panierRadiusGroup.strBoneName = f_br.ReadString();
  83. panierRadiusGroup.fRadius = f_br.ReadSingle();
  84. this.SerializeReadAnimationCurve(f_br, out panierRadiusGroup.Curve);
  85. this.m_PanierRadiusDistribGroup[i] = panierRadiusGroup;
  86. }
  87. }
  88. this.m_fPanierForce = f_br.ReadSingle();
  89. this.SerializeReadAnimationCurve(f_br, out this.m_PanierForceDistrib);
  90. this.m_fPanierStressForce = f_br.ReadSingle();
  91. this.m_fStressDgreeMin = f_br.ReadSingle();
  92. this.m_fStressDgreeMax = f_br.ReadSingle();
  93. this.m_fStressMinScale = f_br.ReadSingle();
  94. this.m_fScaleEaseSpeed = f_br.ReadSingle();
  95. this.m_fPanierForceDistanceThreshold = f_br.ReadSingle();
  96. this.m_nCalcTime = f_br.ReadInt32();
  97. this.m_fVelocityForceRate = f_br.ReadSingle();
  98. this.SerializeReadAnimationCurve(f_br, out this.m_VelocityForceRateDistrib);
  99. this.m_vGravity.x = f_br.ReadSingle();
  100. this.m_vGravity.y = f_br.ReadSingle();
  101. this.m_vGravity.z = f_br.ReadSingle();
  102. this.SerializeReadAnimationCurve(f_br, out this.m_GravityDistrib);
  103. this.m_aryHard[0] = f_br.ReadSingle();
  104. this.m_aryHard[1] = f_br.ReadSingle();
  105. this.m_aryHard[2] = f_br.ReadSingle();
  106. this.m_aryHard[3] = f_br.ReadSingle();
  107. this.UpdateParameters();
  108. }
  109. private void SerializeReadAnimationCurve(BinaryReader f_br, out AnimationCurve f_ac)
  110. {
  111. int num = f_br.ReadInt32();
  112. f_ac = null;
  113. if (num != 0)
  114. {
  115. Keyframe[] array = new Keyframe[num];
  116. for (int i = 0; i < num; i++)
  117. {
  118. array[i] = new Keyframe
  119. {
  120. time = f_br.ReadSingle(),
  121. value = f_br.ReadSingle(),
  122. inTangent = f_br.ReadSingle(),
  123. outTangent = f_br.ReadSingle()
  124. };
  125. }
  126. f_ac = new AnimationCurve(array);
  127. }
  128. }
  129. public bool InitGameObject(GameObject f_objRoot, TBodySkin bodyskin, Transform f_trSkirtRoot)
  130. {
  131. this.m_BodySkin = bodyskin;
  132. this.m_Body = bodyskin.body;
  133. if (DynamicSkirtBone.m_PluginDll == IntPtr.Zero)
  134. {
  135. string text = Application.dataPath + '/' + "Plugins/clothpp.dll";
  136. Debug.Log("Application.dataPath is " + text);
  137. DynamicSkirtBone.m_PluginDll = DynamicSkirtBone.LoadLibraryW(NUty.ConvStringToByte(text, NUty.ENCO.UTF_16));
  138. IntPtr procAddress = DynamicSkirtBone.GetProcAddress(DynamicSkirtBone.m_PluginDll, "Export_PhysicsCreate");
  139. DynamicSkirtBone.m_dgExport_PhysicsCreate = (DynamicSkirtBone.Export_PhysicsCreate)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(DynamicSkirtBone.Export_PhysicsCreate));
  140. IntPtr procAddress2 = DynamicSkirtBone.GetProcAddress(DynamicSkirtBone.m_PluginDll, "Export_PhysicsDelete");
  141. DynamicSkirtBone.m_dgExport_PhysicsDelete = (DynamicSkirtBone.Export_PhysicsDelete)Marshal.GetDelegateForFunctionPointer(procAddress2, typeof(DynamicSkirtBone.Export_PhysicsDelete));
  142. IntPtr procAddress3 = DynamicSkirtBone.GetProcAddress(DynamicSkirtBone.m_PluginDll, "Export_InitSkirt");
  143. DynamicSkirtBone.m_dgExport_InitSkirt = (DynamicSkirtBone.Export_InitSkirt)Marshal.GetDelegateForFunctionPointer(procAddress3, typeof(DynamicSkirtBone.Export_InitSkirt));
  144. IntPtr procAddress4 = DynamicSkirtBone.GetProcAddress(DynamicSkirtBone.m_PluginDll, "Export_GetBonePos");
  145. DynamicSkirtBone.m_dgExport_GetBonePos = (DynamicSkirtBone.Export_GetBonePos)Marshal.GetDelegateForFunctionPointer(procAddress4, typeof(DynamicSkirtBone.Export_GetBonePos));
  146. }
  147. NDebug.Assert(this.m_nDllPhysicsInstanceID == -1, () => "Skirt DLL多重ロード。");
  148. this.m_nDllPhysicsInstanceID = DynamicSkirtBone.m_dgExport_PhysicsCreate();
  149. this.m_nBoneCount = 0;
  150. this.m_listBoneScaleDef.Clear();
  151. this.m_listHookBoneTrs = new List<Transform>();
  152. int num = -1;
  153. int num2 = f_trSkirtRoot.childCount - 1;
  154. while (0 <= num2)
  155. {
  156. Transform child = f_trSkirtRoot.GetChild(num2);
  157. if (child.name.Contains("Skirt") && child.name.Contains("_A_"))
  158. {
  159. int num3 = int.Parse(child.name.Substring(5, 2)) - 1;
  160. if (num == -1)
  161. {
  162. num = num3;
  163. }
  164. num3 = num - num3;
  165. Vector3 position = child.position;
  166. this.m_aryBonePos[num3 * 3] = position.x;
  167. this.m_aryBonePos[num3 * 3 + 1] = position.y;
  168. this.m_aryBonePos[num3 * 3 + 2] = position.z;
  169. this.m_aryBoneTrs[num3] = child;
  170. this.m_listHookBoneTrs.Add(child);
  171. }
  172. num2--;
  173. }
  174. this.m_nHookBoneCount = this.m_listHookBoneTrs.Count;
  175. this.m_nBoneCount = this.m_nHookBoneCount;
  176. this.m_bOldBone = (this.m_nHookBoneCount <= 12);
  177. float num4 = 0f;
  178. for (int i = 0; i < this.m_nHookBoneCount; i++)
  179. {
  180. int num5 = 0;
  181. Transform transform = this.m_listHookBoneTrs[i];
  182. if (transform.localScale.x < 0.999f || 1.001f < transform.localScale.x || transform.localScale.y < 0.999f || 1.001f < transform.localScale.y || transform.localScale.z < 0.999f || 1.001f < transform.localScale.z)
  183. {
  184. this.m_listBoneScaleDef.Add(new BoneScaleDef(transform, transform.localPosition, transform.localRotation, transform.localScale));
  185. }
  186. this.m_aryBoneLength[i] = 0f;
  187. float num6 = 0f;
  188. while (transform.childCount > 0)
  189. {
  190. Vector3 position2 = transform.position;
  191. transform = transform.GetChild(0);
  192. if (transform.localScale.x < 0.999f || 1.001f < transform.localScale.x || transform.localScale.y < 0.999f || 1.001f < transform.localScale.y || transform.localScale.z < 0.999f || 1.001f < transform.localScale.z)
  193. {
  194. this.m_listBoneScaleDef.Add(new BoneScaleDef(transform, transform.localPosition, transform.localRotation, transform.localScale));
  195. }
  196. num6 += (position2 - transform.position).magnitude;
  197. Vector3 position3 = transform.position;
  198. this.m_aryBonePos[(num5 + 1) * (this.m_nHookBoneCount * 3) + i * 3] = position3.x;
  199. this.m_aryBonePos[(num5 + 1) * (this.m_nHookBoneCount * 3) + i * 3 + 1] = position3.y;
  200. this.m_aryBonePos[(num5 + 1) * (this.m_nHookBoneCount * 3) + i * 3 + 2] = position3.z;
  201. this.m_aryBoneTrs[(num5 + 1) * this.m_nHookBoneCount + i] = transform;
  202. this.m_aryBoneLength[(num5 + 1) * this.m_nHookBoneCount + i] = num6;
  203. this.m_nBoneCount++;
  204. num5++;
  205. }
  206. if (num4 < num6)
  207. {
  208. num4 = num6;
  209. }
  210. }
  211. this.m_fMaxLenght = num4;
  212. for (int j = 0; j < this.m_nBoneCount; j++)
  213. {
  214. this.m_aryBoneLengthRate[j] = this.m_aryBoneLength[j] / this.m_fMaxLenght;
  215. }
  216. this.m_aryVelocityForceRate = new float[this.m_nBoneCount];
  217. this.m_aryGravity = new float[this.m_nBoneCount * 3];
  218. this.m_trPanierParent = new GameObject("Skirt_P").transform;
  219. this.m_trPanierParent.SetParent(f_trSkirtRoot, false);
  220. this.m_trPanierParent.position = f_trSkirtRoot.position;
  221. this.m_trPanierParent.rotation = f_trSkirtRoot.rotation;
  222. this.m_aryPanierBoneTrs = new Transform[this.m_nBoneCount];
  223. this.m_aryPanierForce = new float[this.m_nBoneCount];
  224. this.m_aryPanierRadius = new float[this.m_nBoneCount];
  225. this.m_aryPanierBoneToLegSegRate = new float[this.m_nBoneCount];
  226. this.m_aryPanierBoneBeforeRotAngle = new float[this.m_nBoneCount];
  227. this.m_fPanierStress = new float[this.m_nHookBoneCount];
  228. this.m_fPanierVecAngle = new float[this.m_nHookBoneCount];
  229. this.m_aryPanierLastChildDef = new Transform[this.m_nHookBoneCount];
  230. Dictionary<string, ImportCM.OldSkirtBoneRev> dictionary = null;
  231. if (this.m_bOldBone)
  232. {
  233. dictionary = ImportCM.LoadOldSkirtBoneRev(f_objRoot.name);
  234. this.m_bPanierOldBoneRotRev = new bool[this.m_nBoneCount];
  235. this.m_vPanierOldBoneRotRevInit = new Vector3[this.m_nBoneCount];
  236. this.m_vPanierOldBoneRotRevAfter = new Vector3[this.m_nBoneCount];
  237. }
  238. int num7 = 0;
  239. for (int k = 0; k < this.m_nHookBoneCount; k++)
  240. {
  241. GameObject gameObject = new GameObject("Skirt_P_" + k + "_0");
  242. gameObject.transform.SetParent(this.m_trPanierParent, false);
  243. Transform transform2 = this.m_listHookBoneTrs[k];
  244. gameObject.transform.position = transform2.position;
  245. gameObject.transform.rotation = transform2.rotation;
  246. bool flag = false;
  247. Vector3 vector = Vector3.zero;
  248. Vector3 vector2 = Vector3.zero;
  249. if (this.m_bOldBone)
  250. {
  251. ImportCM.OldSkirtBoneRev oldSkirtBoneRev;
  252. if (dictionary != null && dictionary.TryGetValue(transform2.name, out oldSkirtBoneRev))
  253. {
  254. this.m_bPanierOldBoneRotRev[k] = true;
  255. this.m_vPanierOldBoneRotRevInit[k] = oldSkirtBoneRev.vRotRevInit;
  256. this.m_vPanierOldBoneRotRevAfter[k] = oldSkirtBoneRev.vRotRevAfter;
  257. flag = oldSkirtBoneRev.bRecursiv;
  258. if (flag)
  259. {
  260. vector = oldSkirtBoneRev.vRotRevInit;
  261. vector2 = oldSkirtBoneRev.vRotRevAfter;
  262. }
  263. }
  264. else
  265. {
  266. Vector3 normalized = (this.m_listHookBoneTrs[(k + 1 >= this.m_nHookBoneCount) ? 0 : (k + 1)].position - this.m_listHookBoneTrs[k].position).normalized;
  267. float num8 = Vector3.Dot(normalized, -this.m_listHookBoneTrs[k].forward);
  268. if (num8 < 0.1f)
  269. {
  270. this.m_bPanierOldBoneRotRev[k] = true;
  271. flag = true;
  272. float num9 = Vector3.Dot(normalized, this.m_listHookBoneTrs[k].forward);
  273. if (-0.1 < (double)num9 && num9 < 0.5f)
  274. {
  275. Vector3[] vPanierOldBoneRotRevInit = this.m_vPanierOldBoneRotRevInit;
  276. int num10 = k;
  277. vector = new Vector3(90f, 0f, 0f);
  278. vPanierOldBoneRotRevInit[num10] = vector;
  279. Vector3[] vPanierOldBoneRotRevAfter = this.m_vPanierOldBoneRotRevAfter;
  280. int num11 = k;
  281. vector2 = new Vector3(-90f, 0f, 0f);
  282. vPanierOldBoneRotRevAfter[num11] = vector2;
  283. }
  284. else
  285. {
  286. Vector3[] vPanierOldBoneRotRevInit2 = this.m_vPanierOldBoneRotRevInit;
  287. int num12 = k;
  288. vector = new Vector3(180f, 0f, 0f);
  289. vPanierOldBoneRotRevInit2[num12] = vector;
  290. Vector3[] vPanierOldBoneRotRevAfter2 = this.m_vPanierOldBoneRotRevAfter;
  291. int num13 = k;
  292. vector2 = new Vector3(-180f, 0f, 0f);
  293. vPanierOldBoneRotRevAfter2[num13] = vector2;
  294. }
  295. }
  296. }
  297. if (this.m_bPanierOldBoneRotRev[k])
  298. {
  299. gameObject.transform.Rotate(this.m_vPanierOldBoneRotRevInit[k], Space.Self);
  300. }
  301. }
  302. this.m_aryPanierBoneTrs[k] = gameObject.transform;
  303. int num14 = 0;
  304. int num15 = 0;
  305. Transform transform3 = this.m_listHookBoneTrs[k];
  306. while (transform3.childCount > 0)
  307. {
  308. transform3 = transform3.GetChild(0);
  309. int num16 = num15 * this.m_nHookBoneCount + k;
  310. int num17 = (num15 + 1) * this.m_nHookBoneCount + k;
  311. GameObject gameObject2 = new GameObject(string.Concat(new object[]
  312. {
  313. "Skirt_P_",
  314. k,
  315. "_",
  316. 1 + num15
  317. }));
  318. gameObject2.transform.SetParent(this.m_aryPanierBoneTrs[num16], false);
  319. gameObject2.transform.position = transform3.position;
  320. gameObject2.transform.rotation = transform3.rotation;
  321. if (this.m_bOldBone)
  322. {
  323. ImportCM.OldSkirtBoneRev oldSkirtBoneRev2;
  324. if (flag)
  325. {
  326. this.m_bPanierOldBoneRotRev[num17] = true;
  327. this.m_vPanierOldBoneRotRevInit[num17] = vector;
  328. this.m_vPanierOldBoneRotRevAfter[num17] = vector2;
  329. }
  330. else if (!flag && dictionary != null && dictionary.TryGetValue(transform2.name, out oldSkirtBoneRev2))
  331. {
  332. this.m_bPanierOldBoneRotRev[num17] = true;
  333. this.m_vPanierOldBoneRotRevInit[num17] = oldSkirtBoneRev2.vRotRevInit;
  334. this.m_vPanierOldBoneRotRevAfter[num17] = oldSkirtBoneRev2.vRotRevAfter;
  335. flag = oldSkirtBoneRev2.bRecursiv;
  336. if (flag)
  337. {
  338. vector = oldSkirtBoneRev2.vRotRevInit;
  339. vector2 = oldSkirtBoneRev2.vRotRevAfter;
  340. }
  341. }
  342. if (this.m_bPanierOldBoneRotRev[num17])
  343. {
  344. gameObject2.transform.Rotate(this.m_vPanierOldBoneRotRevInit[num17], Space.Self);
  345. }
  346. }
  347. this.m_aryPanierBoneTrs[num17] = gameObject2.transform;
  348. num15++;
  349. num14++;
  350. }
  351. if (num7 < num14)
  352. {
  353. num7 = num14;
  354. }
  355. }
  356. this.m_aryPanierBoneDefRot = new Quaternion[this.m_nBoneCount];
  357. for (int l = 0; l < this.m_nHookBoneCount; l++)
  358. {
  359. Transform transform4 = this.m_aryPanierBoneTrs[l];
  360. this.m_aryPanierBoneDefRot[l] = transform4.localRotation;
  361. int num18 = 0;
  362. while (transform4.childCount > 0)
  363. {
  364. transform4 = transform4.GetChild(0);
  365. this.m_aryPanierBoneDefRot[(num18 + 1) * this.m_nHookBoneCount + l] = transform4.localRotation;
  366. num18++;
  367. }
  368. }
  369. this.m_aryLegSeqRadius[0] = 0.1630143f;
  370. this.m_aryLegSeqRadius[1] = 0.2130143f;
  371. this.m_aryLegSeqRadius[2] = 0.5f;
  372. this.m_aryLegSeqRadius[3] = 0.5f;
  373. this.m_aryLegSeqRadius[4] = 0.5f;
  374. this.m_aryLegSeqRadius[5] = 0.5f;
  375. this.m_nPanierBoneCount = this.m_nBoneCount;
  376. for (int m = 0; m < this.m_nBoneCount * 3; m++)
  377. {
  378. this.m_aryPanierBonePos[m] = this.m_aryBonePos[m];
  379. }
  380. this.m_nBodyBallCount = 2;
  381. Transform pelvis = this.m_Body.Pelvis;
  382. int num19 = 0;
  383. GameObject gameObject3 = new GameObject("Hit_HipL");
  384. gameObject3.transform.SetParent(pelvis);
  385. this.m_listBodyBallPos.Add(gameObject3.transform);
  386. DynamicBoneCollider dynamicBoneCollider;
  387. this.m_listBodyBall.Add(dynamicBoneCollider = gameObject3.AddComponent<DynamicBoneCollider>());
  388. dynamicBoneCollider.m_Radius = 0.09f;
  389. gameObject3.transform.localPosition = new Vector3(-0.0181f, -0.0319f, 0.0573f);
  390. gameObject3.transform.localScale = new Vector3(1f, 1f, 1f);
  391. this.m_aryBodyBallPos[3 * num19] = gameObject3.transform.position.x;
  392. this.m_aryBodyBallPos[3 * num19 + 1] = gameObject3.transform.position.y;
  393. this.m_aryBodyBallPos[3 * num19 + 2] = gameObject3.transform.position.z;
  394. this.m_aryBodyBallRadius[num19] = dynamicBoneCollider.GetLossyScale();
  395. num19 = 1;
  396. GameObject gameObject4 = new GameObject("Hit_HipR");
  397. gameObject4.transform.SetParent(pelvis);
  398. this.m_listBodyBallPos.Add(gameObject4.transform);
  399. this.m_listBodyBall.Add(dynamicBoneCollider = gameObject4.AddComponent<DynamicBoneCollider>());
  400. dynamicBoneCollider.m_Radius = 0.09f;
  401. gameObject4.transform.localPosition = new Vector3(-0.0181f, -0.0319f, -0.0573f);
  402. gameObject4.transform.localScale = new Vector3(1f, 1f, 1f);
  403. this.m_aryBodyBallPos[3 * num19] = gameObject4.transform.position.x;
  404. this.m_aryBodyBallPos[3 * num19 + 1] = gameObject4.transform.position.y;
  405. this.m_aryBodyBallPos[3 * num19 + 2] = gameObject4.transform.position.z;
  406. this.m_aryBodyBallRadius[num19] = dynamicBoneCollider.GetLossyScale();
  407. GameObject gameObject5 = new GameObject("Hit_Vag");
  408. gameObject5.transform.SetParent(pelvis);
  409. this.m_listBodyBallPos.Add(gameObject5.transform);
  410. this.m_listBodyBall.Add(dynamicBoneCollider = gameObject5.AddComponent<DynamicBoneCollider>());
  411. dynamicBoneCollider.m_Radius = 0.09f;
  412. gameObject5.transform.localPosition = new Vector3(-0.022f, 0.023f, 0f);
  413. gameObject5.transform.localScale = new Vector3(1f, 1f, 1f);
  414. this.m_nBodyCapsuleCount = 4;
  415. this.m_aryCapsuleBoneTrs = new Transform[this.m_nBodyCapsuleCount * 2];
  416. this.m_aryCapsuleBoneTrs[0] = CMT.SearchObjName(this.m_Body.m_Bones.transform, "Bip01 L Thigh", true);
  417. this.m_aryCapsuleBoneTrs[1] = CMT.SearchObjName(this.m_Body.m_Bones.transform, "Bip01 L Calf", true);
  418. this.m_aryCapsuleBoneTrs[2] = this.m_aryCapsuleBoneTrs[1];
  419. this.m_aryCapsuleBoneTrs[3] = CMT.SearchObjName(this.m_Body.m_Bones.transform, "Bip01 L Foot", true);
  420. this.m_aryCapsuleBoneTrs[4] = CMT.SearchObjName(this.m_Body.m_Bones.transform, "Bip01 R Thigh", true);
  421. this.m_aryCapsuleBoneTrs[5] = CMT.SearchObjName(this.m_Body.m_Bones.transform, "Bip01 R Calf", true);
  422. this.m_aryCapsuleBoneTrs[6] = this.m_aryCapsuleBoneTrs[5];
  423. this.m_aryCapsuleBoneTrs[7] = CMT.SearchObjName(this.m_Body.m_Bones.transform, "Bip01 R Foot", true);
  424. this.m_aryTestCapsule = new Transform[this.m_nBodyCapsuleCount * 2];
  425. for (int n = 0; n < this.m_nBodyCapsuleCount; n++)
  426. {
  427. this.m_aryBodyCapsulePos[6 * n] = this.m_aryCapsuleBoneTrs[2 * n].position.x;
  428. this.m_aryBodyCapsulePos[6 * n + 1] = this.m_aryCapsuleBoneTrs[2 * n].position.y;
  429. this.m_aryBodyCapsulePos[6 * n + 2] = this.m_aryCapsuleBoneTrs[2 * n].position.z;
  430. this.m_aryBodyCapsulePos[6 * n + 3] = this.m_aryCapsuleBoneTrs[2 * n + 1].position.x;
  431. this.m_aryBodyCapsulePos[6 * n + 4] = this.m_aryCapsuleBoneTrs[2 * n + 1].position.y;
  432. this.m_aryBodyCapsulePos[6 * n + 5] = this.m_aryCapsuleBoneTrs[2 * n + 1].position.z;
  433. this.m_aryBodyCapsuleRadius[n] = this.m_fRegDefaultRadius;
  434. }
  435. Vector3 vector3 = this.m_Body.Pelvis.TransformPoint(new Vector3(-1f, 0f, 0f));
  436. this.m_vLegPelvisToSpine[0] = vector3.x;
  437. this.m_vLegPelvisToSpine[1] = vector3.y;
  438. this.m_vLegPelvisToSpine[2] = vector3.z;
  439. Vector3 vector4 = this.m_Body.Pelvis.TransformPoint(new Vector3(0f, 1f, 0f)) - this.m_Body.Pelvis.position;
  440. this.m_vLegPelvisToSpine[3] = vector4.x;
  441. this.m_vLegPelvisToSpine[4] = vector4.y;
  442. this.m_vLegPelvisToSpine[5] = vector4.z;
  443. this.m_aryLegSeqRadius[0] = this.m_fLegSeqRad0;
  444. this.m_aryLegSeqRadius[1] = this.m_fLegSeqRad1;
  445. this.m_aryLegSeqRadius[2] = this.m_fLegSeqRad1;
  446. this.m_aryLegSeqRadius[3] = this.m_fLegSeqRad2;
  447. this.m_aryLegSeqRadius[4] = this.m_fLegSeqRad2;
  448. this.m_aryLegSeqRadius[5] = this.m_fLegSeqRad3;
  449. this.UpdateParameters();
  450. this.m_listGcHandle.Add(GCHandle.Alloc(this.m_aryBonePos, GCHandleType.Pinned));
  451. this.m_listGcHandle.Add(GCHandle.Alloc(this.m_aryPanierBonePos, GCHandleType.Pinned));
  452. this.m_listGcHandle.Add(GCHandle.Alloc(this.m_aryHookBonePos, GCHandleType.Pinned));
  453. this.m_listGcHandle.Add(GCHandle.Alloc(this.m_aryBodyBallPos, GCHandleType.Pinned));
  454. this.m_listGcHandle.Add(GCHandle.Alloc(this.m_aryBodyBallRadius, GCHandleType.Pinned));
  455. this.m_listGcHandle.Add(GCHandle.Alloc(this.m_aryBodyCapsulePos, GCHandleType.Pinned));
  456. this.m_listGcHandle.Add(GCHandle.Alloc(this.m_aryBodyCapsuleRadius, GCHandleType.Pinned));
  457. this.m_listGcHandle.Add(GCHandle.Alloc(this.m_aryDebugLegSeqPos, GCHandleType.Pinned));
  458. this.m_listGcHandle.Add(GCHandle.Alloc(this.m_aryLegSeqRadius, GCHandleType.Pinned));
  459. this.m_listGcHandle.Add(GCHandle.Alloc(this.m_vLegPelvisToSpine, GCHandleType.Pinned));
  460. this.m_listGcHandle.Add(GCHandle.Alloc(this.m_aryBoneParam, GCHandleType.Pinned));
  461. this.m_listGcHandle.Add(GCHandle.Alloc(this.m_aryPanierForce, GCHandleType.Pinned));
  462. this.m_listGcHandle.Add(GCHandle.Alloc(this.m_aryVelocityForceRate, GCHandleType.Pinned));
  463. this.m_listGcHandle.Add(GCHandle.Alloc(this.m_aryGravity, GCHandleType.Pinned));
  464. DynamicSkirtBone.m_dgExport_InitSkirt(this.m_nDllPhysicsInstanceID, this.m_aryHard[0], this.m_aryHard[1], this.m_aryHard[2], this.m_aryHard[3], this.m_aryBonePos, this.m_nBoneCount, this.m_nHookBoneCount, this.m_nBodyBallCount, this.m_aryBodyBallPos, this.m_aryBodyBallRadius, this.m_nBodyCapsuleCount, this.m_aryBodyCapsulePos, this.m_aryBodyCapsuleRadius, this.m_vLegPelvisToSpine, this.m_aryLegSeqRadius);
  465. return true;
  466. }
  467. public void OnPreFinalize()
  468. {
  469. if (DynamicSkirtBone.m_PluginDll != IntPtr.Zero)
  470. {
  471. if (this.m_nDllPhysicsInstanceID != -1)
  472. {
  473. DynamicSkirtBone.m_dgExport_PhysicsDelete(this.m_nDllPhysicsInstanceID);
  474. this.m_nDllPhysicsInstanceID = -1;
  475. }
  476. DynamicSkirtBone.FreeLibrary(DynamicSkirtBone.m_PluginDll);
  477. DynamicSkirtBone.m_PluginDll = IntPtr.Zero;
  478. }
  479. DynamicSkirtBone.m_dgExport_PhysicsCreate = null;
  480. DynamicSkirtBone.m_dgExport_PhysicsDelete = null;
  481. DynamicSkirtBone.m_dgExport_InitSkirt = null;
  482. DynamicSkirtBone.m_dgExport_GetBonePos = null;
  483. }
  484. private void OnDestroy()
  485. {
  486. this.Uninit();
  487. }
  488. private void OnValidate()
  489. {
  490. this.UpdateParameters();
  491. }
  492. public void Uninit()
  493. {
  494. if (this.m_nDllPhysicsInstanceID != -1)
  495. {
  496. if (DynamicSkirtBone.m_dgExport_PhysicsDelete != null)
  497. {
  498. DynamicSkirtBone.m_dgExport_PhysicsDelete(this.m_nDllPhysicsInstanceID);
  499. }
  500. this.m_nDllPhysicsInstanceID = -1;
  501. }
  502. foreach (Transform transform in this.m_listBodyBallPos)
  503. {
  504. UnityEngine.Object.Destroy(transform.gameObject);
  505. }
  506. this.m_listBodyBallPos.Clear();
  507. this.m_listBodyBall.Clear();
  508. for (int i = 0; i < this.m_listGcHandle.Count; i++)
  509. {
  510. GCHandle gchandle = this.m_listGcHandle[i];
  511. if (gchandle.IsAllocated)
  512. {
  513. gchandle.Free();
  514. }
  515. }
  516. this.m_listGcHandle.Clear();
  517. if (this.m_aryTestCapsule != null)
  518. {
  519. foreach (Transform transform2 in this.m_aryTestCapsule)
  520. {
  521. if (transform2 != null && transform2.gameObject != null)
  522. {
  523. UnityEngine.Object.DestroyImmediate(transform2.gameObject);
  524. }
  525. }
  526. this.m_aryTestCapsule = null;
  527. }
  528. }
  529. private void UpdateParameters()
  530. {
  531. bool flag = this.m_PanierRadiusDistrib != null && this.m_PanierRadiusDistrib.length != 0;
  532. bool flag2 = this.m_PanierForceDistrib != null && this.m_PanierForceDistrib.length != 0;
  533. bool flag3 = this.m_VelocityForceRateDistrib != null && this.m_VelocityForceRateDistrib.length != 0;
  534. bool flag4 = this.m_GravityDistrib != null && this.m_GravityDistrib.length != 0;
  535. int nH;
  536. for (nH = 0; nH < this.m_nHookBoneCount; nH++)
  537. {
  538. DynamicSkirtBone.PanierRadiusGroup panierRadiusGroup = null;
  539. if (this.m_PanierRadiusDistribGroup != null)
  540. {
  541. panierRadiusGroup = Array.Find<DynamicSkirtBone.PanierRadiusGroup>(this.m_PanierRadiusDistribGroup, (DynamicSkirtBone.PanierRadiusGroup a) => a.strBoneName == this.m_aryBoneTrs[nH].name);
  542. }
  543. int num = this.m_nBoneCount / this.m_nHookBoneCount;
  544. for (int i = 0; i < num; i++)
  545. {
  546. int num2 = i * this.m_nHookBoneCount + nH;
  547. float time = this.m_aryBoneLength[num2];
  548. if (panierRadiusGroup == null)
  549. {
  550. float num3 = this.m_fPanierRadius;
  551. if (flag)
  552. {
  553. num3 *= this.m_PanierRadiusDistrib.Evaluate(time);
  554. }
  555. this.m_aryPanierRadius[num2] = num3;
  556. }
  557. else
  558. {
  559. float num4 = panierRadiusGroup.fRadius;
  560. if (panierRadiusGroup.Curve != null && panierRadiusGroup.Curve.length != 0)
  561. {
  562. num4 *= panierRadiusGroup.Curve.Evaluate(time);
  563. }
  564. this.m_aryPanierRadius[num2] = num4;
  565. }
  566. float num5 = this.m_fPanierForce;
  567. if (flag2)
  568. {
  569. num5 *= this.m_PanierForceDistrib.Evaluate(time);
  570. }
  571. this.m_aryPanierForce[num2] = num5;
  572. float num6 = this.m_fVelocityForceRate;
  573. if (flag3)
  574. {
  575. num6 *= this.m_VelocityForceRateDistrib.Evaluate(time);
  576. }
  577. this.m_aryVelocityForceRate[num2] = num6;
  578. Vector3 a2 = this.m_vGravity;
  579. if (flag4)
  580. {
  581. a2 *= this.m_GravityDistrib.Evaluate(time);
  582. }
  583. this.m_aryGravity[num2 * 3] = a2.x;
  584. this.m_aryGravity[num2 * 3 + 1] = a2.y;
  585. this.m_aryGravity[num2 * 3 + 2] = a2.z;
  586. }
  587. }
  588. }
  589. public void UpdateSelf()
  590. {
  591. if (DynamicSkirtBone.m_dgExport_GetBonePos == null)
  592. {
  593. return;
  594. }
  595. if (this.m_listBoneScaleDef.Count != 0)
  596. {
  597. for (int i = 0; i < this.m_listBoneScaleDef.Count; i++)
  598. {
  599. BoneScaleDef boneScaleDef = this.m_listBoneScaleDef[i];
  600. boneScaleDef.trTarget.localScale = Vector3.one;
  601. }
  602. }
  603. Transform transform = this.m_aryCapsuleBoneTrs[0];
  604. Transform transform2 = this.m_aryCapsuleBoneTrs[1];
  605. Transform transform3 = this.m_aryCapsuleBoneTrs[4];
  606. Transform transform4 = this.m_aryCapsuleBoneTrs[5];
  607. Vector3 vector = transform.position;
  608. Vector3 vector2 = transform3.position;
  609. Vector3 position = transform2.position;
  610. Vector3 position2 = transform4.position;
  611. Plane plane = new Plane(vector, position2, position);
  612. bool flag;
  613. if (!plane.GetSide(vector2))
  614. {
  615. flag = false;
  616. float distanceToPoint = plane.GetDistanceToPoint(vector2);
  617. Vector3 vector3 = vector2 - plane.normal.normalized * distanceToPoint;
  618. vector2 = vector3;
  619. }
  620. else
  621. {
  622. Plane plane2 = new Plane(vector2, position2, position);
  623. flag = true;
  624. float distanceToPoint2 = plane2.GetDistanceToPoint(vector);
  625. Vector3 vector4 = vector - plane2.normal.normalized * distanceToPoint2;
  626. vector = vector4;
  627. }
  628. Vector3 a = transform2.position - vector;
  629. Vector3 a2 = transform4.position - vector2;
  630. int num = 1;
  631. int num2 = num * 2;
  632. Vector3 a3 = a * (1f / (float)num);
  633. Vector3 a4 = a2 * (1f / (float)num);
  634. if (this.m_aryLegSegPory == null || this.m_aryLegSegPory.Length != num2 * 3)
  635. {
  636. this.m_aryLegSegPory = new Vector3[num2 * 3];
  637. this.m_aryLegSegPoryVec = new Vector3[num2 * 2];
  638. this.m_aryLegSegPlane = new Plane[num2];
  639. }
  640. for (int j = 0; j < num; j++)
  641. {
  642. Vector3 vector5 = vector + a3 * (float)j;
  643. Vector3 vector6 = vector2 + a4 * (float)j;
  644. Vector3 vector7 = vector + a3 * (float)(j + 1);
  645. Vector3 vector8 = vector2 + a4 * (float)(j + 1);
  646. if (flag)
  647. {
  648. this.m_aryLegSegPory[6 * j] = vector5;
  649. this.m_aryLegSegPory[6 * j + 1] = vector6;
  650. this.m_aryLegSegPory[6 * j + 2] = vector7;
  651. this.m_aryLegSegPoryVec[4 * j] = vector6 - vector5;
  652. this.m_aryLegSegPoryVec[4 * j + 1] = vector7 - vector5;
  653. this.m_aryLegSegPlane[2 * j].Set3Points(vector7, vector6, vector5);
  654. this.m_aryLegSegPory[6 * j + 3] = vector6;
  655. this.m_aryLegSegPory[6 * j + 4] = vector8;
  656. this.m_aryLegSegPory[6 * j + 5] = vector7;
  657. this.m_aryLegSegPoryVec[4 * j + 2] = vector8 - vector6;
  658. this.m_aryLegSegPoryVec[4 * j + 3] = vector7 - vector6;
  659. this.m_aryLegSegPlane[2 * j + 1].Set3Points(vector7, vector8, vector6);
  660. }
  661. else
  662. {
  663. this.m_aryLegSegPory[6 * j] = vector5;
  664. this.m_aryLegSegPory[6 * j + 1] = vector6;
  665. this.m_aryLegSegPory[6 * j + 2] = vector8;
  666. this.m_aryLegSegPoryVec[4 * j] = vector6 - vector5;
  667. this.m_aryLegSegPoryVec[4 * j + 1] = vector8 - vector5;
  668. this.m_aryLegSegPlane[2 * j].Set3Points(vector8, vector6, vector5);
  669. this.m_aryLegSegPory[6 * j + 3] = vector5;
  670. this.m_aryLegSegPory[6 * j + 4] = vector8;
  671. this.m_aryLegSegPory[6 * j + 5] = vector7;
  672. this.m_aryLegSegPoryVec[4 * j + 2] = vector8 - vector5;
  673. this.m_aryLegSegPoryVec[4 * j + 3] = vector7 - vector5;
  674. this.m_aryLegSegPlane[2 * j + 1].Set3Points(vector7, vector8, vector5);
  675. }
  676. }
  677. float num3 = this.m_fRegDefaultRadius;
  678. TMorph morph = this.m_Body.goSlot[0].morph;
  679. float blendValues = morph.GetBlendValues(morph.BlendDataIdx_RegFat);
  680. float blendValues2 = morph.GetBlendValues(morph.BlendDataIdx_RegMeet);
  681. float num4 = (blendValues + blendValues2) * 0.5f;
  682. if (this.m_fRegFatThrethold <= num4)
  683. {
  684. num3 *= this.m_fRegFatRateMin + (this.m_fRegFatRateMax - this.m_fRegFatRateMin) * (num4 - this.m_fRegFatThrethold);
  685. }
  686. float num5 = 0f;
  687. this.m_fEasingScale = Mathf.SmoothDamp(this.m_fEasingScale, this.m_fScaleTo, ref num5, this.m_fScaleEaseSpeed);
  688. float num6 = 0f;
  689. for (int k = 0; k < this.m_nHookBoneCount; k++)
  690. {
  691. float num7 = 0f;
  692. float num8 = 0f;
  693. Transform transform5 = this.m_aryPanierBoneTrs[k];
  694. Transform transform6 = transform5;
  695. Vector3 position3 = transform6.position;
  696. Vector3 up = transform6.up;
  697. Transform transform7 = transform5;
  698. transform5.localRotation = this.m_aryPanierBoneDefRot[k];
  699. int num9 = k;
  700. int num10 = 0;
  701. Transform transform8 = transform5;
  702. while (transform8.childCount != 0)
  703. {
  704. int num11 = (num10 + 1) * this.m_nHookBoneCount + k;
  705. Transform transform9 = this.m_aryPanierBoneTrs[num11];
  706. transform9.localRotation = this.m_aryPanierBoneDefRot[num11];
  707. transform8 = (transform7 = transform9);
  708. num10++;
  709. }
  710. if (this.m_bEnableStressScale)
  711. {
  712. transform5.localScale = new Vector3(this.m_fEasingScale, this.m_fEasingScale, this.m_fEasingScale);
  713. this.m_aryBoneTrs[k].localScale = new Vector3(this.m_fEasingScale, this.m_fEasingScale, this.m_fEasingScale);
  714. }
  715. else
  716. {
  717. transform5.localScale = Vector3.one;
  718. this.m_aryBoneTrs[k].localScale = Vector3.one;
  719. }
  720. Vector3 vector9 = transform6.position + transform6.TransformVector(Vector3.right);
  721. this.m_fPanierVecAngle[k] = 0f;
  722. for (int l = 0; l < num2; l++)
  723. {
  724. float d = 0f;
  725. float distanceToPoint3 = this.m_aryLegSegPlane[l].GetDistanceToPoint(position3);
  726. if (-this.m_fAdjustRegSegPoly < distanceToPoint3 && distanceToPoint3 < this.m_fAdjustRegSegPoly)
  727. {
  728. Vector3 b;
  729. if (distanceToPoint3 < 0f)
  730. {
  731. b = this.m_aryLegSegPlane[l].normal * this.m_fAdjustRegSegPoly;
  732. }
  733. else
  734. {
  735. b = this.m_aryLegSegPlane[l].normal * -this.m_fAdjustRegSegPoly;
  736. }
  737. if (flag)
  738. {
  739. this.m_aryLegSegPory[l * 3] += b;
  740. this.m_aryLegSegPory[l * 3 + 1] += b;
  741. this.m_aryLegSegPory[l * 3 + 2] += b;
  742. this.m_aryLegSegPlane[l].Set3Points(this.m_aryLegSegPory[l * 3 + 2], this.m_aryLegSegPory[l * 3 + 1], this.m_aryLegSegPory[l * 3]);
  743. }
  744. else
  745. {
  746. this.m_aryLegSegPory[l * 3] += b;
  747. this.m_aryLegSegPory[l * 3 + 1] += b;
  748. this.m_aryLegSegPory[l * 3 + 2] += b;
  749. this.m_aryLegSegPlane[l].Set3Points(this.m_aryLegSegPory[l * 3 + 2], this.m_aryLegSegPory[l * 3 + 1], this.m_aryLegSegPory[l * 3]);
  750. }
  751. }
  752. Vector3 tvec = position3 - this.m_aryLegSegPory[l * 3];
  753. if (MathCM.TriangleLineIntersect(position3, vector9, tvec, this.m_aryLegSegPory[l * 3], this.m_aryLegSegPoryVec[l * 2], this.m_aryLegSegPoryVec[l * 2 + 1], ref d))
  754. {
  755. this.m_fPanierVecAngle[k] = 1f;
  756. Vector3 a5 = vector9;
  757. Vector3 b2 = (a5 - position3).normalized * d;
  758. Vector3 a6 = position3 + b2;
  759. transform6.Rotate(-Vector3.forward, 1f, Space.Self);
  760. float d2 = 0f;
  761. Vector3 a7 = position3 + transform6.TransformVector(Vector3.right);
  762. Vector3 direction = a7 - position3;
  763. if (this.m_aryLegSegPlane[l].Raycast(new Ray(position3, direction), out d2))
  764. {
  765. this.m_fPanierVecAngle[k] = 2f;
  766. Vector3 vector10 = position3 + direction.normalized * d2;
  767. Vector3 vector11 = a6 - vector10;
  768. Vector3 zero = Vector3.zero;
  769. if (MathCM.SphireRayIntersect(vector10 + vector11.normalized * 10f, -vector11.normalized, position3, (position3 - transform7.position).magnitude, ref zero))
  770. {
  771. this.m_fPanierVecAngle[k] = 3f;
  772. float num12 = Vector3.Angle(zero - position3, transform7.position - position3);
  773. transform6.Rotate(-Vector3.forward, num12 + 1f);
  774. num8 += num12 + 1f;
  775. break;
  776. }
  777. }
  778. }
  779. }
  780. num10 = 0;
  781. while (transform5.childCount != 0)
  782. {
  783. int num13 = (num10 + 1) * this.m_nHookBoneCount + k;
  784. Transform transform9 = this.m_aryPanierBoneTrs[num13];
  785. bool flag2 = false;
  786. float num14 = 10f;
  787. for (int m = 0; m < this.m_listBodyBall.Count; m++)
  788. {
  789. DynamicBoneCollider dynamicBoneCollider = this.m_listBodyBall[m] as DynamicBoneCollider;
  790. Transform transform10 = dynamicBoneCollider.transform;
  791. float lossyScale = dynamicBoneCollider.GetLossyScale();
  792. float num15 = this.m_aryPanierRadius[num13];
  793. Vector3 position4 = transform9.position;
  794. float magnitude = (transform10.position - transform9.position).magnitude;
  795. if (dynamicBoneCollider.Collide(ref position4, num15))
  796. {
  797. flag2 = true;
  798. for (float num16 = 0f; num16 < 360f; num16 += 1f)
  799. {
  800. transform5.Rotate(-Vector3.forward, 1f, Space.Self);
  801. position4 = transform9.position;
  802. num8 += 1f;
  803. magnitude = (transform10.position - transform9.position).magnitude;
  804. if (!dynamicBoneCollider.Collide(ref position4, num15))
  805. {
  806. break;
  807. }
  808. }
  809. }
  810. if (magnitude - (lossyScale + num15) < num14)
  811. {
  812. num14 = magnitude - (lossyScale + num15);
  813. }
  814. }
  815. bool flag3 = false;
  816. for (int n = 0; n < this.m_nBodyCapsuleCount; n++)
  817. {
  818. float num17 = this.m_fRegDefaultRadius;
  819. if (n == 0 || n == 2)
  820. {
  821. num17 = num3;
  822. }
  823. this.m_aryBodyCapsuleRadius[n] = num17;
  824. Transform transform11 = this.m_aryCapsuleBoneTrs[2 * n];
  825. Transform transform12 = this.m_aryCapsuleBoneTrs[2 * n + 1];
  826. MathCM.Segment segment = new MathCM.Segment(transform11.position, transform12.position);
  827. float num18 = this.m_aryPanierRadius[num13];
  828. Vector3 position5 = transform9.position;
  829. Vector3 vector12;
  830. float num20;
  831. float num19 = MathCM.calcPointSegmentDist(ref position5, ref segment, out vector12, out num20);
  832. if (num19 < num17 + num18)
  833. {
  834. flag2 = (flag3 = true);
  835. Vector3 position6 = transform5.position;
  836. float num21 = 0f;
  837. float num22;
  838. for (num22 = 0f; num22 < 360f; num22 += 1f)
  839. {
  840. transform5.Rotate(-Vector3.forward, 1f, Space.Self);
  841. position5 = transform9.position;
  842. num21 += 1f;
  843. num8 += 1f;
  844. if (MathCM.calcPointSegmentDist(ref position5, ref segment, out vector12, out num20) > num17 + num18)
  845. {
  846. this.m_aryPanierBoneBeforeRotAngle[num9] = num21;
  847. break;
  848. }
  849. }
  850. if (358f <= num22)
  851. {
  852. if (this.m_bGizmoDraw)
  853. {
  854. Debug.DrawLine(transform5.position, transform9.position, Color.red);
  855. }
  856. transform5.Rotate(-Vector3.forward, this.m_aryPanierBoneBeforeRotAngle[num9], Space.Self);
  857. }
  858. }
  859. if (num19 - (num17 + num18) < num14)
  860. {
  861. num14 = num19 - (num17 + num18);
  862. }
  863. }
  864. if (!flag3)
  865. {
  866. this.m_aryPanierBoneBeforeRotAngle[num9] = 0f;
  867. }
  868. if (!flag2)
  869. {
  870. float num23 = this.m_fPanierForce;
  871. if (this.m_PanierForceDistrib != null && this.m_PanierForceDistrib.length != 0)
  872. {
  873. num23 *= this.m_PanierForceDistrib.Evaluate(this.m_aryBoneLengthRate[num13]);
  874. }
  875. this.m_aryPanierForce[num13] = num23;
  876. if (0f < this.m_fPanierForceDistanceThreshold && num14 <= this.m_fPanierForceDistanceThreshold)
  877. {
  878. this.m_aryPanierForce[num13] += (1f - num23) * (1f - num14 / this.m_fPanierForceDistanceThreshold) * this.m_fPanierStressForce;
  879. }
  880. }
  881. else
  882. {
  883. this.m_aryPanierForce[num13] = 1f * this.m_fPanierStressForce;
  884. }
  885. num7 += num8;
  886. num8 = 0f;
  887. Quaternion quaternion = this.m_aryPanierBoneDefRot[num13];
  888. num9 = num13;
  889. transform5 = transform9;
  890. num10++;
  891. }
  892. if (this.m_bEnableLegSegHit)
  893. {
  894. for (int num24 = 0; num24 < num2; num24++)
  895. {
  896. float d3 = 0f;
  897. Vector3 tvec2 = position3 - this.m_aryLegSegPory[num24 * 3];
  898. if (MathCM.TriangleLineIntersect(position3, transform7.position, tvec2, this.m_aryLegSegPory[num24 * 3], this.m_aryLegSegPoryVec[num24 * 2], this.m_aryLegSegPoryVec[num24 * 2 + 1], ref d3))
  899. {
  900. Vector3 position7 = transform7.position;
  901. Vector3 b3 = (position7 - position3).normalized * d3;
  902. Vector3 a8 = position3 + b3;
  903. transform6.Rotate(-Vector3.forward, 1f, Space.Self);
  904. float d4 = 0f;
  905. Vector3 direction2 = transform7.position - position3;
  906. if (this.m_aryLegSegPlane[num24].Raycast(new Ray(position3, direction2), out d4))
  907. {
  908. Vector3 vector13 = position3 + direction2.normalized * d4;
  909. Vector3 vector14 = a8 - vector13;
  910. Vector3 zero2 = Vector3.zero;
  911. if (MathCM.SphireRayIntersect(vector13 - vector14.normalized * 10f, vector14.normalized, position3, (position3 - position7).magnitude, ref zero2))
  912. {
  913. float num25 = Vector3.Angle(zero2 - position3, position7 - position3);
  914. transform6.Rotate(-Vector3.forward, num25 + 1f);
  915. num7 += num25 + 1f;
  916. break;
  917. }
  918. }
  919. }
  920. }
  921. }
  922. this.m_fPanierStress[k] = num7;
  923. if (num6 < num7)
  924. {
  925. num6 = num7;
  926. }
  927. }
  928. if (this.m_fStressDgreeMin < num6)
  929. {
  930. float num26 = Mathf.Clamp(num6, this.m_fStressDgreeMin, this.m_fStressDgreeMax);
  931. this.m_fScaleTo = 1f - (1f - this.m_fStressMinScale) * ((num26 - this.m_fStressDgreeMin) / (this.m_fStressDgreeMax - this.m_fStressDgreeMin));
  932. }
  933. else
  934. {
  935. this.m_fScaleTo = 1f;
  936. }
  937. for (int num27 = 0; num27 < this.m_nHookBoneCount; num27++)
  938. {
  939. Vector3 position8 = this.m_listHookBoneTrs[num27].position;
  940. this.m_aryHookBonePos[3 * num27] = position8.x;
  941. this.m_aryHookBonePos[3 * num27 + 1] = position8.y;
  942. this.m_aryHookBonePos[3 * num27 + 2] = position8.z;
  943. }
  944. for (int num28 = 0; num28 < this.m_aryPanierBoneTrs.Length; num28++)
  945. {
  946. Transform transform13 = this.m_aryPanierBoneTrs[num28].transform;
  947. this.m_aryPanierBonePos[3 * num28] = transform13.position.x;
  948. this.m_aryPanierBonePos[3 * num28 + 1] = transform13.position.y;
  949. this.m_aryPanierBonePos[3 * num28 + 2] = transform13.position.z;
  950. }
  951. for (int num29 = 0; num29 < this.m_nBodyBallCount; num29++)
  952. {
  953. Transform transform14 = this.m_listBodyBallPos[num29];
  954. this.m_aryBodyBallPos[3 * num29] = transform14.position.x;
  955. this.m_aryBodyBallPos[3 * num29 + 1] = transform14.position.y;
  956. this.m_aryBodyBallPos[3 * num29 + 2] = transform14.position.z;
  957. }
  958. for (int num30 = 0; num30 < this.m_nBodyCapsuleCount; num30++)
  959. {
  960. this.m_aryBodyCapsulePos[6 * num30] = this.m_aryCapsuleBoneTrs[2 * num30].position.x;
  961. this.m_aryBodyCapsulePos[6 * num30 + 1] = this.m_aryCapsuleBoneTrs[2 * num30].position.y;
  962. this.m_aryBodyCapsulePos[6 * num30 + 2] = this.m_aryCapsuleBoneTrs[2 * num30].position.z;
  963. this.m_aryBodyCapsulePos[6 * num30 + 3] = this.m_aryCapsuleBoneTrs[2 * num30 + 1].position.x;
  964. this.m_aryBodyCapsulePos[6 * num30 + 4] = this.m_aryCapsuleBoneTrs[2 * num30 + 1].position.y;
  965. this.m_aryBodyCapsulePos[6 * num30 + 5] = this.m_aryCapsuleBoneTrs[2 * num30 + 1].position.z;
  966. }
  967. Vector3 vector15 = this.m_Body.Pelvis.TransformPoint(new Vector3(-1f, 0f, 0f));
  968. this.m_vLegPelvisToSpine[0] = vector15.x;
  969. this.m_vLegPelvisToSpine[1] = vector15.y;
  970. this.m_vLegPelvisToSpine[2] = vector15.z;
  971. Vector3 vector16 = this.m_Body.Pelvis.TransformPoint(new Vector3(0f, 1f, 0f)) - this.m_Body.Pelvis.position;
  972. this.m_vLegPelvisToSpine[3] = vector16.x;
  973. this.m_vLegPelvisToSpine[4] = vector16.y;
  974. this.m_vLegPelvisToSpine[5] = vector16.z;
  975. this.m_aryLegSeqRadius[0] = this.m_fLegSeqRad0;
  976. this.m_aryLegSeqRadius[1] = this.m_fLegSeqRad1;
  977. this.m_aryLegSeqRadius[2] = this.m_fLegSeqRad1;
  978. this.m_aryLegSeqRadius[3] = this.m_fLegSeqRad2;
  979. this.m_aryLegSeqRadius[4] = this.m_fLegSeqRad2;
  980. this.m_aryLegSeqRadius[5] = this.m_fLegSeqRad3;
  981. DynamicSkirtBone.m_dgExport_GetBonePos(this.m_nDllPhysicsInstanceID, this.m_nCalcTime, this.m_aryHookBonePos, this.m_nHookBoneCount, this.m_aryPanierBonePos, this.m_nPanierBoneCount, this.m_aryBonePos, this.m_nBoneCount, this.m_aryPanierForce, this.m_nBodyBallCount, this.m_aryBodyBallPos, this.m_nBodyCapsuleCount, this.m_aryBodyCapsulePos, this.m_aryBoneNormal, this.m_aryDebugLegSeqPos, this.m_aryLegSeqRadius, this.m_vLegPelvisToSpine, this.m_aryBoneParam, this.m_aryVelocityForceRate, this.m_aryGravity, this.m_aryHard, (!this.m_bResetPos) ? 0 : 1, this.m_Body.BoneHitHeightY + this.m_fFloorOffsetY);
  982. for (int num31 = 0; num31 < this.m_nHookBoneCount; num31++)
  983. {
  984. int num32 = this.m_nBoneCount / this.m_nHookBoneCount;
  985. for (int num33 = 0; num33 < num32; num33++)
  986. {
  987. int num34 = num31 + num33 * this.m_nHookBoneCount;
  988. Vector3 vector17 = new Vector3(this.m_aryBonePos[3 * num34], this.m_aryBonePos[3 * num34 + 1], this.m_aryBonePos[3 * num34 + 2]);
  989. Transform transform15 = this.m_aryBoneTrs[num34];
  990. transform15.position = vector17;
  991. if (num33 < num32 - 1)
  992. {
  993. int num35 = num31 + (num33 + 1) * this.m_nHookBoneCount;
  994. Vector3 a9 = new Vector3(this.m_aryBonePos[3 * num35], this.m_aryBonePos[3 * num35 + 1], this.m_aryBonePos[3 * num35 + 2]);
  995. Vector3 lhs = new Vector3(this.m_aryBoneNormal[3 * num34], this.m_aryBoneNormal[3 * num34 + 1], this.m_aryBoneNormal[3 * num34 + 2]);
  996. Vector3 vector18 = a9 - vector17;
  997. Vector3 vector19 = Vector3.Cross(lhs, vector18);
  998. Quaternion rotation = Quaternion.AngleAxis(-90f, vector19);
  999. vector18 = rotation * vector18;
  1000. transform15.rotation = Quaternion.LookRotation(vector19, vector18);
  1001. }
  1002. if (this.m_bOldBone && this.m_bPanierOldBoneRotRev[num34])
  1003. {
  1004. transform15.Rotate(this.m_vPanierOldBoneRotRevAfter[num34], Space.Self);
  1005. }
  1006. }
  1007. }
  1008. if (this.m_listBoneScaleDef.Count != 0)
  1009. {
  1010. for (int num36 = 0; num36 < this.m_listBoneScaleDef.Count; num36++)
  1011. {
  1012. BoneScaleDef boneScaleDef2 = this.m_listBoneScaleDef[num36];
  1013. boneScaleDef2.trTarget.localScale = boneScaleDef2.vDefScale;
  1014. }
  1015. }
  1016. this.m_bResetPos = false;
  1017. }
  1018. [Header("■パニエ ノードサイズ")]
  1019. public float m_fPanierRadius = 0.025f;
  1020. public AnimationCurve m_PanierRadiusDistrib;
  1021. public bool m_bPanierNodeGizmoDraw;
  1022. [Header("■パニエ ノードサイズの上書き")]
  1023. [SerializeField]
  1024. public DynamicSkirtBone.PanierRadiusGroup[] m_PanierRadiusDistribGroup;
  1025. [Header("■パニエ 力")]
  1026. [Range(0f, 1f)]
  1027. public float m_fPanierForce = 0.134f;
  1028. public AnimationCurve m_PanierForceDistrib;
  1029. public bool m_bPanierLineGizmoDraw;
  1030. [Header("■パニエ 重力適応割合(初期パニエノード回転から重力方向への力の割合)")]
  1031. [Range(0f, 1f)]
  1032. public float m_fPanierGravityRate;
  1033. [Header("■パニエ 当たっていない場合の戻る力")]
  1034. [Range(0f, 2f)]
  1035. public float m_fPanierStiffnessRate;
  1036. [Header("■パニエ 足に当っていた場合の強制パニエ力")]
  1037. [Range(0f, 1f)]
  1038. public float m_fPanierStressForce = 0.4f;
  1039. [Header("■パニエ 足との距離によるパニエ力")]
  1040. public float m_fPanierForceDistanceThreshold = 0.1f;
  1041. [Header("■パニエ 角度による全体のスケーリング")]
  1042. [Tooltip("水平方向に伸びて見えるのを防ぐ。")]
  1043. public bool m_bEnableStressScale = true;
  1044. public float m_fStressDgreeMin = 45f;
  1045. public float m_fStressDgreeMax = 90f;
  1046. public float m_fStressMinScale = 0.75f;
  1047. [ReadOnly]
  1048. public float m_fScaleTo = 1f;
  1049. [ReadOnly]
  1050. public float m_fEasingScale = 1f;
  1051. public float m_fScaleEaseSpeed = 5f;
  1052. [ReadOnly]
  1053. public float[] m_fPanierStress;
  1054. [ReadOnly]
  1055. public float[] m_fPanierVecAngle;
  1056. [Header("■パニエ 足の間の当たり判定")]
  1057. public bool m_bEnableLegSegHit = true;
  1058. public float m_fLegSegHitDgree = 45f;
  1059. [Header("■パニエ 足側カプセル初期半径")]
  1060. public float m_fRegDefaultRadius = 0.1f;
  1061. [Header("■パニエ 腿判定の足の太さによる補正 掛け算")]
  1062. public bool m_bEnableRegFatAndMeetAdjust = true;
  1063. public float m_fRegFatThrethold = 0.5f;
  1064. public float m_fRegFatRateMin = 1f;
  1065. public float m_fRegFatRateMax = 1.3f;
  1066. [Header("■パニエ 股間ポリゴン判定 親自体がポリゴンに近接している場合のポリゴン位置補正")]
  1067. public float m_fAdjustRegSegPoly = 0.005f;
  1068. [Header("■物理 計算回数")]
  1069. public int m_nCalcTime = 16;
  1070. [Header("■物理 惰性割合")]
  1071. public float m_fVelocityForceRate = 0.8f;
  1072. public AnimationCurve m_VelocityForceRateDistrib;
  1073. [Header("■物理 重力")]
  1074. public Vector3 m_vGravity = new Vector3(0f, -0.005f, 0f);
  1075. public AnimationCurve m_GravityDistrib;
  1076. [Header("■物理 繋がり力(横縮,横伸,縦縮,縦伸)(物理計算回数に依存)")]
  1077. public float[] m_aryHard = new float[]
  1078. {
  1079. 0f,
  1080. 0.01f,
  1081. 0f,
  1082. 0.7f
  1083. };
  1084. [Header("■物理 床判定オフセット")]
  1085. public float m_fFloorOffsetY = -0.03f;
  1086. public bool m_RealBoneAndNormalGizmoDraw = true;
  1087. [Header("")]
  1088. public float m_fLegSeqRad0 = 0.1f;
  1089. public float m_fLegSeqRad1 = 0.1f;
  1090. public float m_fLegSeqRad2 = 0.1f;
  1091. public float m_fLegSeqRad3 = 0.1f;
  1092. [Header("")]
  1093. public bool m_bGizmoDraw = true;
  1094. public bool m_bResetPos;
  1095. public const int SKIRT_W_MAX = 24;
  1096. public const int SKIRT_H_MAX = 48;
  1097. private Transform[] m_aryBoneTrs = new Transform[1152];
  1098. private float[] m_aryBonePos = new float[6144];
  1099. private int m_nBoneCount;
  1100. private int[] m_aryBoneParam = new int[2048];
  1101. private float[] m_aryBoneLength = new float[1152];
  1102. private float[] m_aryBoneLengthRate = new float[1152];
  1103. private float[] m_aryBoneNormal = new float[6144];
  1104. private Transform m_trPanierParent;
  1105. private float[] m_aryPanierBonePos = new float[6144];
  1106. private int m_nPanierBoneCount;
  1107. private Transform[] m_aryPanierBoneTrs;
  1108. private Transform[] m_aryPanierPanierBoneTrs;
  1109. private float[] m_aryPanierForce;
  1110. private Quaternion[] m_aryPanierBoneDefRot;
  1111. private float[] m_aryPanierBoneToLegSegRate;
  1112. private float[] m_aryPanierBoneBeforeRotAngle;
  1113. private bool[] m_bPanierOldBoneRotRev;
  1114. private Vector3[] m_vPanierOldBoneRotRevInit;
  1115. private Vector3[] m_vPanierOldBoneRotRevAfter;
  1116. private Transform[] m_aryPanierLastChildDef;
  1117. private float[] m_aryPanierRadius;
  1118. private float[] m_aryVelocityForceRate;
  1119. private float[] m_aryGravity;
  1120. private List<Transform> m_listHookBoneTrs;
  1121. private float[] m_aryHookBonePos = new float[6144];
  1122. private int m_nHookBoneCount;
  1123. private List<Transform> m_listBodyBallPos = new List<Transform>();
  1124. private float[] m_aryBodyBallPos = new float[6144];
  1125. private float[] m_aryBodyBallRadius = new float[2048];
  1126. private int m_nBodyBallCount;
  1127. public List<DynamicBoneColliderBase> m_listBodyBall = new List<DynamicBoneColliderBase>();
  1128. private Transform[] m_aryCapsuleBoneTrs;
  1129. private float[] m_aryBodyCapsulePos = new float[12288];
  1130. private float[] m_aryBodyCapsuleRadius = new float[2048];
  1131. private int m_nBodyCapsuleCount;
  1132. private float[] m_aryDebugLegSeqPos = new float[120];
  1133. private float[] m_vLegPelvisToSpine = new float[6];
  1134. private float[] m_aryLegSeqRadius = new float[20];
  1135. private TBody m_Body;
  1136. private TBodySkin m_BodySkin;
  1137. private Transform[] m_aryTestCapsule;
  1138. private List<BoneScaleDef> m_listBoneScaleDef = new List<BoneScaleDef>();
  1139. private bool m_bOldBone;
  1140. private const string kUseDllPath_x64 = "Plugins/";
  1141. private static IntPtr m_PluginDll = IntPtr.Zero;
  1142. private List<GCHandle> m_listGcHandle = new List<GCHandle>();
  1143. private int m_nDllPhysicsInstanceID = -1;
  1144. private static DynamicSkirtBone.Export_PhysicsCreate m_dgExport_PhysicsCreate = null;
  1145. private static DynamicSkirtBone.Export_PhysicsDelete m_dgExport_PhysicsDelete = null;
  1146. private static DynamicSkirtBone.Export_InitSkirt m_dgExport_InitSkirt = null;
  1147. private static DynamicSkirtBone.Export_GetBonePos m_dgExport_GetBonePos = null;
  1148. private GameObject m_point;
  1149. private GameObject m_capsule;
  1150. private float m_fMaxLenght;
  1151. private Vector3 m_testLineA;
  1152. private Transform m_testGoRay;
  1153. private Transform m_testGoTriA;
  1154. private Transform m_testGoTriB;
  1155. private Transform m_testGoTriC;
  1156. private Vector3[] m_aryLegSegPory;
  1157. private Vector3[] m_aryLegSegPoryVec;
  1158. private Plane[] m_aryLegSegPlane;
  1159. [Serializable]
  1160. public class PanierRadiusGroup
  1161. {
  1162. [SerializeField]
  1163. public string strBoneName;
  1164. [SerializeField]
  1165. public float fRadius;
  1166. [SerializeField]
  1167. public AnimationCurve Curve;
  1168. }
  1169. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  1170. private delegate int Export_PhysicsCreate();
  1171. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  1172. private delegate void Export_PhysicsDelete(int f_nID);
  1173. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  1174. private delegate void Export_InitSkirt(int f_nID, float f_fHardHShort, float f_fHardHLong, float f_HardVShort, float f_HardVLong, float[] f_aryBonePos, int f_nBoneCount, int f_nSWidth, int f_nBallCount, float[] f_aryBallPos, float[] f_aryBallRadius, int f_nCapsuleCount, float[] f_aryCapsulePos, float[] f_aryCapsuleRadius, float[] f_vLegPelvisToSpine, float[] f_aryLegSeqRadius);
  1175. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  1176. private delegate void Export_GetBonePos(int f_nID, int f_nCalcTime, float[] f_aryHookBonePos, int f_nHookBoneCount, float[] f_aryPanierBonePos, int f_nPanierBoneCount, float[] f_aryBonePos, int f_nBoneCount, float[] f_aryPanierForce, int f_nBallCount, float[] f_aryBallPos, int f_nCapsuleCount, float[] f_aryCapsulePos, float[] f_aryNodeNormal, float[] f_aryDebugLegSeqPos, float[] f_aryLegSeqRadius, float[] f_aryLegPelvisToSpine, int[] f_aryBoneParam, float[] f_aryVelocityForceRate, float[] f_aryGravity, float[] f_aryHard, int f_bReset, float f_fFloorY);
  1177. }