TMorph.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using UnityEngine;
  6. public class TMorph
  7. {
  8. public TMorph(TBodySkin bs)
  9. {
  10. this.bodyskin = bs;
  11. this.Category = bs.Category;
  12. this.SlotId = bs.SlotId;
  13. this.hash = new Hashtable();
  14. this.MorphCount = 0;
  15. this.BlendDatas = new List<BlendData>(20);
  16. this.BoneNames = new List<string>(200);
  17. this.BoneVisible = new List<bool>(200);
  18. }
  19. public float LipSync1
  20. {
  21. get
  22. {
  23. return this.m_LipSync1;
  24. }
  25. set
  26. {
  27. this.m_LipSync1 = Mathf.Clamp01(value);
  28. }
  29. }
  30. public float LipSync2
  31. {
  32. get
  33. {
  34. return this.m_LipSync2;
  35. }
  36. set
  37. {
  38. this.m_LipSync2 = Mathf.Clamp01(value);
  39. }
  40. }
  41. public float LipSync3
  42. {
  43. get
  44. {
  45. return this.m_LipSync3;
  46. }
  47. set
  48. {
  49. this.m_LipSync3 = Mathf.Clamp01(value);
  50. }
  51. }
  52. ~TMorph()
  53. {
  54. this.DeleteObj();
  55. }
  56. public BlendData this[string tag]
  57. {
  58. get
  59. {
  60. int index = (int)this.hash[tag];
  61. return this.BlendDatas[index];
  62. }
  63. }
  64. public bool Contains(string name)
  65. {
  66. return this.hash.ContainsKey(name);
  67. }
  68. public float GetBlendValues(int f_nIdx)
  69. {
  70. return this.BlendValues[f_nIdx];
  71. }
  72. public void SetBlendValues(int f_nIdx, float f_fValue)
  73. {
  74. float[] blendValuesBackup = this.BlendValuesBackup;
  75. this.BlendValues[f_nIdx] = f_fValue;
  76. blendValuesBackup[f_nIdx] = f_fValue;
  77. }
  78. public void DeleteObj()
  79. {
  80. this.bodyskin = null;
  81. this.m_mesh = null;
  82. this.smr_src = null;
  83. this.m_bones = null;
  84. this.m_vOriVert = null;
  85. this.m_vOriNorm = null;
  86. this.m_nSubMeshOriTri = null;
  87. this.m_bws = null;
  88. }
  89. public unsafe void InitGameObject(GameObject o)
  90. {
  91. SkinnedMeshRenderer skinnedMeshRenderer = null;
  92. List<SkinnedMeshRenderer> list = new List<SkinnedMeshRenderer>(3);
  93. o.GetComponentsInChildren<SkinnedMeshRenderer>(true, list);
  94. for (int i = 0; i < list.Count; i++)
  95. {
  96. skinnedMeshRenderer = list[i];
  97. }
  98. Transform[] bones = skinnedMeshRenderer.bones;
  99. Transform transform = o.transform;
  100. this.tRoot = transform;
  101. if (skinnedMeshRenderer == null)
  102. {
  103. Debug.LogError("err init morph " + o.name);
  104. this.initlp(this.tRoot);
  105. return;
  106. }
  107. this.smr_src = skinnedMeshRenderer;
  108. this.m_bones = bones;
  109. this.m_mesh = this.smr_src.sharedMesh;
  110. this.VCount = this.bodyskin.m_OriVert.VCount;
  111. this.m_vOriVert = this.bodyskin.m_OriVert.vOriVert;
  112. this.m_vOriNorm = this.bodyskin.m_OriVert.vOriNorm;
  113. this.m_vTmpVert = new Vector3[this.VCount];
  114. this.m_vTmpNorm = new Vector3[this.VCount];
  115. this.m_AtrVert = new int[this.VCount];
  116. this.m_vOriVert.CopyTo(this.m_vTmpVert, 0);
  117. this.m_vOriNorm.CopyTo(this.m_vTmpNorm, 0);
  118. this.m_nSubMeshCount = this.bodyskin.m_OriVert.nSubMeshCount;
  119. this.m_nSubMeshOriTri = this.bodyskin.m_OriVert.nSubMeshOriTri;
  120. this.m_nSubMeshTmpTri = new int[this.m_nSubMeshCount][];
  121. for (int j = 0; j < this.m_nSubMeshCount; j++)
  122. {
  123. int[] array = this.m_nSubMeshOriTri[j];
  124. this.m_nSubMeshTmpTri[j] = new int[array.Length];
  125. }
  126. this.BoneCount = this.m_bones.Length;
  127. this.initlp(this.tRoot);
  128. this.m_EarNoneData.rate = false;
  129. this.m_EarNoneData.idx = ((!this.hash.ContainsKey("earnone")) ? -1 : ((int)this.hash["earnone"]));
  130. this.m_EarElfData.rate = 0f;
  131. this.m_EarElfData.idx = ((!this.hash.ContainsKey("earelf")) ? -1 : ((int)this.hash["earelf"]));
  132. this.m_FaceShapeData.rate = 0f;
  133. this.m_FaceShapeData.idx = ((!this.hash.ContainsKey("shape")) ? -1 : ((int)this.hash["shape"]));
  134. this.m_FaceShapeSlimData.rate = 0f;
  135. this.m_FaceShapeSlimData.idx = ((!this.hash.ContainsKey("shapeslim")) ? -1 : ((int)this.hash["shapeslim"]));
  136. this.m_MayuShapeIn.rate = (this.m_MayuShapeOut.rate = 0f);
  137. this.m_MayuShapeIn.idx = ((!this.hash.ContainsKey("mayueditin")) ? -1 : ((int)this.hash["mayueditin"]));
  138. this.m_MayuShapeOut.idx = ((!this.hash.ContainsKey("mayueditout")) ? -1 : ((int)this.hash["mayueditout"]));
  139. if (120 <= this.bodyskin.PartsVersion)
  140. {
  141. Action<string, TMorph.IdxMinMaxRatePair> action = delegate(string no, TMorph.IdxMinMaxRatePair idx)
  142. {
  143. bool flag = false;
  144. flag |= ((idx.idxDwL = ((!this.hash.ContainsKey("eyeeditl" + no + "_dw")) ? -1 : ((int)this.hash["eyeeditl" + no + "_dw"]))) == -1);
  145. flag |= ((idx.idxUpL = ((!this.hash.ContainsKey("eyeeditl" + no + "_up")) ? -1 : ((int)this.hash["eyeeditl" + no + "_up"]))) == -1);
  146. flag |= ((idx.idxDwR = ((!this.hash.ContainsKey("eyeeditr" + no + "_dw")) ? -1 : ((int)this.hash["eyeeditr" + no + "_dw"]))) == -1);
  147. flag |= ((idx.idxUpR = ((!this.hash.ContainsKey("eyeeditr" + no + "_up")) ? -1 : ((int)this.hash["eyeeditr" + no + "_up"]))) == -1);
  148. if (flag)
  149. {
  150. Debug.LogError("not fund shape key name");
  151. return;
  152. }
  153. idx.exec = delegate(float rateL, float rateR)
  154. {
  155. float num4 = Mathf.Clamp01((idx.rate - 0.5f) / -0.5f);
  156. float num5 = Mathf.Clamp01((idx.rate - 0.5f) / 0.5f);
  157. this.BlendValues[idx.idxDwL] = num4 * rateL;
  158. this.BlendValues[idx.idxDwR] = num4 * rateR;
  159. this.BlendValues[idx.idxUpL] = num5 * rateL;
  160. this.BlendValues[idx.idxUpR] = num5 * rateR;
  161. };
  162. if (this.m_IdxMinMaxList == null)
  163. {
  164. this.m_IdxMinMaxList = new List<TMorph.IdxMinMaxRatePair>();
  165. }
  166. this.m_IdxMinMaxList.Add(idx);
  167. };
  168. action("1", this.m_MabutaUpIn);
  169. action("2", this.m_MabutaUpIn2);
  170. action("3", this.m_MabutaUpMiddle);
  171. action("4", this.m_MabutaUpOut);
  172. action("5", this.m_MabutaUpOut2);
  173. action("6", this.m_MabutaLowUpOut);
  174. action("7", this.m_MabutaLowUpMiddle);
  175. action("8", this.m_MabutaLowIn);
  176. }
  177. this.m_fEyeCloseRate = 0f;
  178. this.BlendDataIdx_EyeClose = new int[][]
  179. {
  180. new int[10],
  181. new int[10],
  182. new int[10]
  183. };
  184. if (this.bodyskin.PartsVersion < 120)
  185. {
  186. if (this.hash.ContainsKey("eyeclose"))
  187. {
  188. this.BlendDataIdx_EyeClose[0][0] = (int)this.hash["eyeclose"];
  189. }
  190. for (int k = 1; k < 10; k++)
  191. {
  192. if (this.hash.ContainsKey("eyeclose" + k.ToString()))
  193. {
  194. this.BlendDataIdx_EyeClose[0][k] = (int)this.hash["eyeclose" + k.ToString()];
  195. }
  196. }
  197. if (!this.bodyskin.body.boMAN && this.Category == "head" && this.BlendDataIdx_EyeClose[0][0] == 0)
  198. {
  199. Debug.LogError("Face[eyeclose]");
  200. }
  201. }
  202. else
  203. {
  204. for (int l = 0; l < 3; l++)
  205. {
  206. for (int m = 0; m < 10; m++)
  207. {
  208. if (this.hash.ContainsKey("eyeclose" + (m + 1).ToString() + TMorph.crcFaceTypesStr[l]))
  209. {
  210. this.BlendDataIdx_EyeClose[l][m] = (int)this.hash["eyeclose" + (m + 1).ToString() + TMorph.crcFaceTypesStr[l]];
  211. }
  212. }
  213. }
  214. }
  215. if (this.hash.ContainsKey("toothoff"))
  216. {
  217. this.BlendDataIdx_LipSyncTh = (int)this.hash["toothoff"];
  218. }
  219. if (this.hash.ContainsKey("moutha"))
  220. {
  221. this.BlendDataIdx_LipSync_A = (int)this.hash["moutha"];
  222. }
  223. if (this.hash.ContainsKey("mouths"))
  224. {
  225. this.BlendDataIdx_LipSync_S = (int)this.hash["mouths"];
  226. }
  227. if (this.hash.ContainsKey("mouthc"))
  228. {
  229. this.BlendDataIdx_LipSync_C = (int)this.hash["mouthc"];
  230. }
  231. if (this.hash.ContainsKey("toothoff"))
  232. {
  233. this.BlendDataIdx_LipSync_ToothOFF = (int)this.hash["toothoff"];
  234. }
  235. if (this.hash.ContainsKey("mouthdw"))
  236. {
  237. this.BlendDataIdx_LipSync_W = (int)this.hash["mouthdw"];
  238. }
  239. if (this.hash.ContainsKey("tear1"))
  240. {
  241. this.BlendDataIdx_Tear1 = (int)this.hash["tear1"];
  242. }
  243. if (this.hash.ContainsKey("tear2"))
  244. {
  245. this.BlendDataIdx_Tear2 = (int)this.hash["tear2"];
  246. }
  247. if (this.hash.ContainsKey("tear3"))
  248. {
  249. this.BlendDataIdx_Tear3 = (int)this.hash["tear3"];
  250. }
  251. if (this.hash.ContainsKey("nosefook"))
  252. {
  253. this.BlendDataIdx_NoseFook = (int)this.hash["nosefook"];
  254. }
  255. if (this.hash.ContainsKey("eyeclose"))
  256. {
  257. int count = this.BlendDatas.Count;
  258. this.hash["uru-uru"] = count;
  259. this.BlendDatas.Add(null);
  260. this.MorphCount++;
  261. }
  262. if (this.hash.ContainsKey("regfat"))
  263. {
  264. this.BlendDataIdx_RegFat = (int)this.hash["regfat"];
  265. }
  266. if (this.hash.ContainsKey("regmeet"))
  267. {
  268. this.BlendDataIdx_RegMeet = (int)this.hash["regmeet"];
  269. }
  270. this.ScrnV = new Vector3[this.VCount];
  271. this.WorldV = new Vector3[this.VCount];
  272. this.BindVert = new Vector3[this.VCount];
  273. this.DefVert = new Vector3[this.VCount];
  274. this.BindBone = new int[this.VCount];
  275. this.m_bindposes = this.m_mesh.bindposes;
  276. this.m_bws = this.bodyskin.m_OriVert.bwWeight;
  277. fixed (BoneWeight* ptr = &this.m_bws[0])
  278. {
  279. BoneWeight* ptr2 = ptr;
  280. for (int n = 0; n < this.VCount; n++)
  281. {
  282. int num = ptr2->boneIndex0;
  283. float num2 = ptr2->weight0;
  284. if (ptr2->weight1 > num2)
  285. {
  286. num2 = ptr2->weight1;
  287. num = ptr2->boneIndex1;
  288. }
  289. if (ptr2->weight2 > num2)
  290. {
  291. num2 = ptr2->weight2;
  292. num = ptr2->boneIndex2;
  293. }
  294. if (ptr2->weight3 > num2)
  295. {
  296. num2 = ptr2->weight3;
  297. num = ptr2->boneIndex3;
  298. }
  299. this.BindBone[n] = num;
  300. Vector3 vector = this.m_bindposes[num].MultiplyPoint3x4(this.m_vOriVert[n]);
  301. this.BindVert[n] = vector;
  302. this.DefVert[n] = this.m_bones[num].TransformPoint(vector);
  303. this.m_AtrVert[n] = 0;
  304. for (int num3 = 0; num3 < TMorph.AtrVertChk.Length; num3++)
  305. {
  306. if (this.BoneNames[ptr2->boneIndex0].Contains(TMorph.AtrVertChk[num3]))
  307. {
  308. this.m_AtrVert[n] |= 1 << num3;
  309. }
  310. if (ptr2->weight1 > 0f && this.BoneNames[ptr2->boneIndex1].Contains(TMorph.AtrVertChk[num3]))
  311. {
  312. this.m_AtrVert[n] |= 1 << num3;
  313. }
  314. if (ptr2->weight2 > 0f && this.BoneNames[ptr2->boneIndex2].Contains(TMorph.AtrVertChk[num3]))
  315. {
  316. this.m_AtrVert[n] |= 1 << num3;
  317. }
  318. if (ptr2->weight3 > 0f && this.BoneNames[ptr2->boneIndex3].Contains(TMorph.AtrVertChk[num3]))
  319. {
  320. this.m_AtrVert[n] |= 1 << num3;
  321. }
  322. }
  323. ptr2++;
  324. }
  325. }
  326. }
  327. private void initlp(Transform t)
  328. {
  329. for (int i = 0; i < this.BoneCount; i++)
  330. {
  331. if (this.m_bones[i] != null)
  332. {
  333. this.BoneNames.Add(this.m_bones[i].name);
  334. this.BoneVisible.Add(true);
  335. }
  336. else
  337. {
  338. this.BoneNames.Add(string.Empty);
  339. this.BoneVisible.Add(false);
  340. }
  341. }
  342. this.m_bDut = false;
  343. }
  344. public void ClearAllVisibleFlag(bool boSetFlag)
  345. {
  346. for (int i = 0; i < this.BoneCount; i++)
  347. {
  348. if (this.BoneVisible[i] != boSetFlag)
  349. {
  350. this.BoneVisible[i] = boSetFlag;
  351. this.m_bDut = true;
  352. }
  353. }
  354. }
  355. public void SetVisibleFlag1(int idx, bool flag)
  356. {
  357. if (this.BoneVisible[idx] != flag)
  358. {
  359. this.BoneVisible[idx] = flag;
  360. this.m_bDut = true;
  361. }
  362. }
  363. public void SetVisibleFlag(bool boSetFlag, string name, Transform t = null, bool boTgt = false, int cnt = -1)
  364. {
  365. cnt++;
  366. if (t == null)
  367. {
  368. t = this.tRoot;
  369. }
  370. if (t.name.IndexOf(name) >= 0)
  371. {
  372. boTgt = true;
  373. }
  374. if (name == "_ALL_")
  375. {
  376. boTgt = true;
  377. }
  378. if (boTgt)
  379. {
  380. for (int i = 0; i < this.BoneCount; i++)
  381. {
  382. if (t.name == this.BoneNames[i])
  383. {
  384. this.SetVisibleFlag1(i, boSetFlag);
  385. break;
  386. }
  387. }
  388. }
  389. for (int j = 0; j < t.childCount; j++)
  390. {
  391. this.SetVisibleFlag(boSetFlag, name, t.GetChild(j), boTgt, cnt);
  392. }
  393. }
  394. public void FixVisibleFlag()
  395. {
  396. if (this.smr_src == null)
  397. {
  398. return;
  399. }
  400. if (this.m_mesh == null)
  401. {
  402. return;
  403. }
  404. if (!this.m_bDut)
  405. {
  406. return;
  407. }
  408. for (int i = 0; i < this.m_nSubMeshCount; i++)
  409. {
  410. this.m_nSubMeshOriTri[i].CopyTo(this.m_nSubMeshTmpTri[i], 0);
  411. int[] array = this.m_nSubMeshTmpTri[i];
  412. for (int j = 0; j < array.Length / 3; j++)
  413. {
  414. int num = 3;
  415. for (int k = 0; k < 3; k++)
  416. {
  417. int num2 = array[j * 3 + k];
  418. BoneWeight boneWeight = this.m_bws[num2];
  419. if (!this.BoneVisible[boneWeight.boneIndex0])
  420. {
  421. num--;
  422. break;
  423. }
  424. if (!this.BoneVisible[boneWeight.boneIndex1] && boneWeight.weight1 > 0f)
  425. {
  426. num--;
  427. break;
  428. }
  429. if (!this.BoneVisible[boneWeight.boneIndex2] && boneWeight.weight2 > 0f)
  430. {
  431. num--;
  432. break;
  433. }
  434. if (!this.BoneVisible[boneWeight.boneIndex3] && boneWeight.weight3 > 0f)
  435. {
  436. num--;
  437. break;
  438. }
  439. }
  440. if (num != 3)
  441. {
  442. for (int l = 0; l < 3; l++)
  443. {
  444. array[j * 3 + l] = 0;
  445. }
  446. }
  447. }
  448. this.m_mesh.SetTriangles(array, i);
  449. }
  450. this.m_bDut = false;
  451. }
  452. public void LoadMoprhData2(BinaryReader r)
  453. {
  454. string text = r.ReadString();
  455. int count = this.BlendDatas.Count;
  456. this.hash[text] = count;
  457. BlendData blendData = new BlendData();
  458. blendData.name = text;
  459. int num = r.ReadInt32();
  460. blendData.vert = new Vector3[num];
  461. blendData.norm = new Vector3[num];
  462. blendData.v_index = new int[num];
  463. for (int i = 0; i < num; i++)
  464. {
  465. blendData.v_index[i] = (int)r.ReadUInt16();
  466. blendData.vert[i].x = r.ReadSingle();
  467. blendData.vert[i].y = r.ReadSingle();
  468. blendData.vert[i].z = r.ReadSingle();
  469. blendData.norm[i].x = r.ReadSingle();
  470. blendData.norm[i].y = r.ReadSingle();
  471. blendData.norm[i].z = r.ReadSingle();
  472. }
  473. this.MorphCount++;
  474. this.BlendDatas.Add(blendData);
  475. this.BlendValues = new float[this.MorphCount + 1];
  476. this.BlendValuesTemp = new float[this.MorphCount + 1];
  477. this.BlendValuesBackup = new float[this.MorphCount + 1];
  478. this.BlendValuesCHK = new float[this.MorphCount + 1];
  479. }
  480. public void NewBlendSet(string BlendSetName)
  481. {
  482. float[] array = new float[this.hash.Count];
  483. for (int i = 0; i < array.Length; i++)
  484. {
  485. array[i] = 0f;
  486. }
  487. if (this.dicBlendSet.ContainsKey(BlendSetName))
  488. {
  489. Debug.LogError("\u0093ブレンドセット" + BlendSetName);
  490. }
  491. this.dicBlendSet[BlendSetName] = array;
  492. this.dicBlendAtr[BlendSetName] = 0;
  493. if (!this.dicBlendSet.ContainsKey("オリジナル"))
  494. {
  495. float[] array2 = new float[this.hash.Count];
  496. for (int j = 0; j < array2.Length; j++)
  497. {
  498. array2[j] = 0f;
  499. }
  500. this.dicBlendSet["オリジナル"] = array2;
  501. }
  502. }
  503. public void SetValueOriginalBlendSet(TMorph.AddBlendType add_blend_type_flag)
  504. {
  505. float[] array = this.dicBlendSet["オリジナル"];
  506. array[(int)this.hash["hohol"]] = (array[(int)this.hash["hoho"]] = (array[(int)this.hash["hohos"]] = 0f));
  507. if ((add_blend_type_flag & TMorph.AddBlendType.Cheek3) == TMorph.AddBlendType.Cheek3)
  508. {
  509. array[(int)this.hash["hohol"]] = 1f;
  510. }
  511. else if ((add_blend_type_flag & TMorph.AddBlendType.Cheek2) == TMorph.AddBlendType.Cheek2)
  512. {
  513. array[(int)this.hash["hoho"]] = 1f;
  514. }
  515. else if ((add_blend_type_flag & TMorph.AddBlendType.Cheek1) == TMorph.AddBlendType.Cheek1)
  516. {
  517. array[(int)this.hash["hohos"]] = 1f;
  518. }
  519. array[(int)this.hash["tear3"]] = (array[(int)this.hash["tear2"]] = (array[(int)this.hash["tear1"]] = 0f));
  520. if ((add_blend_type_flag & TMorph.AddBlendType.Tear3) == TMorph.AddBlendType.Tear3)
  521. {
  522. array[(int)this.hash["tear3"]] = 1f;
  523. }
  524. else if ((add_blend_type_flag & TMorph.AddBlendType.Tear2) == TMorph.AddBlendType.Tear2)
  525. {
  526. array[(int)this.hash["tear2"]] = 1f;
  527. }
  528. else if ((add_blend_type_flag & TMorph.AddBlendType.Tear1) == TMorph.AddBlendType.Tear1)
  529. {
  530. array[(int)this.hash["tear1"]] = 1f;
  531. }
  532. array[(int)this.hash["hoho2"]] = (float)(((add_blend_type_flag & TMorph.AddBlendType.Blush) != TMorph.AddBlendType.Blush) ? 0 : 1);
  533. array[(int)this.hash["namida"]] = (float)(((add_blend_type_flag & TMorph.AddBlendType.TearBig) != TMorph.AddBlendType.TearBig) ? 0 : 1);
  534. array[(int)this.hash["yodare"]] = (float)(((add_blend_type_flag & TMorph.AddBlendType.Yodare) != TMorph.AddBlendType.Yodare) ? 0 : 1);
  535. array[(int)this.hash["shock"]] = (float)(((add_blend_type_flag & TMorph.AddBlendType.Shock) != TMorph.AddBlendType.Shock) ? 0 : 1);
  536. }
  537. public void SetValueBlendSet(string BlendSetName, string tag, float val)
  538. {
  539. if (tag == "hoho2")
  540. {
  541. Dictionary<string, int> dictionary = this.dicBlendAtr;
  542. int value = (this.dicBlendAtr[BlendSetName] & -4) | 2;
  543. this.dicBlendAtr[BlendSetName] = value;
  544. dictionary[BlendSetName] = value;
  545. }
  546. if (tag == "hoho" && (this.dicBlendAtr[BlendSetName] & 3) != 1)
  547. {
  548. this.dicBlendAtr[BlendSetName] = ((this.dicBlendAtr[BlendSetName] & -4) | 1);
  549. }
  550. if (!this.dicBlendSet.ContainsKey(BlendSetName))
  551. {
  552. Debug.LogError("表情がありません。" + BlendSetName);
  553. return;
  554. }
  555. if (tag.Contains("*"))
  556. {
  557. for (int i = 0; i < 3; i++)
  558. {
  559. string text = tag.Replace("*", TMorph.crcFaceTypesStr[i]);
  560. if (!this.hash.Contains(text))
  561. {
  562. Debug.LogError("表情がありません。tag=" + text);
  563. }
  564. else
  565. {
  566. int num = (int)this.hash[text];
  567. if (text == "hoho2")
  568. {
  569. this.IdxHOHO2 = num;
  570. }
  571. if (text == "hoho")
  572. {
  573. this.IdxHOHO = num;
  574. }
  575. this.dicBlendSet[BlendSetName][num] = val * 0.01f;
  576. }
  577. }
  578. }
  579. else
  580. {
  581. if (!this.hash.Contains(tag))
  582. {
  583. Debug.LogError("表情がありません。tag=" + tag);
  584. return;
  585. }
  586. int num2 = (int)this.hash[tag];
  587. if (tag == "hoho2")
  588. {
  589. this.IdxHOHO2 = num2;
  590. }
  591. if (tag == "hoho")
  592. {
  593. this.IdxHOHO = num2;
  594. }
  595. this.dicBlendSet[BlendSetName][num2] = val * 0.01f;
  596. }
  597. }
  598. public void ClearBlendValues()
  599. {
  600. for (int i = 0; i < this.MorphCount; i++)
  601. {
  602. this.BlendValuesBackup[i] = (this.BlendValues[i] = 0f);
  603. }
  604. }
  605. public void MulBlendValues(string BlendSetName, float mul = 1f)
  606. {
  607. if (this.dicBlendSet.ContainsKey(BlendSetName))
  608. {
  609. float[] array = this.dicBlendSet[BlendSetName];
  610. for (int i = 0; i < this.MorphCount; i++)
  611. {
  612. this.BlendValuesBackup[i] = (this.BlendValues[i] = this.BlendValues[i] * (1f - mul) + array[i] * mul);
  613. }
  614. return;
  615. }
  616. if (BlendSetName == "頬0涙0")
  617. {
  618. return;
  619. }
  620. Debug.LogError("表情がありません。" + BlendSetName);
  621. }
  622. public void AddBlendValues(string BlendSetName, float add = 1f)
  623. {
  624. if (this.dicBlendSet.ContainsKey(BlendSetName))
  625. {
  626. float[] array = this.dicBlendSet[BlendSetName];
  627. for (int i = 0; i < this.MorphCount; i++)
  628. {
  629. this.BlendValues[i] += array[i] * add;
  630. if (this.BlendValues[i] > 1f)
  631. {
  632. this.BlendValues[i] = 1f;
  633. }
  634. this.BlendValuesBackup[i] = this.BlendValues[i];
  635. }
  636. return;
  637. }
  638. if (BlendSetName == "頬0涙0")
  639. {
  640. return;
  641. }
  642. Debug.LogError("表情がありません。" + BlendSetName);
  643. }
  644. public TMorph.GP01FB_FACE_TYPE GetFaceTypeGP01FB()
  645. {
  646. float num = this.m_MabutaUpOut2.rate - 0.5f;
  647. float num2 = Mathf.Clamp01(num / -0.5f);
  648. float num3 = Mathf.Clamp01(num / 0.5f);
  649. if (num2 < 0.35f && num3 < 0.35f)
  650. {
  651. return TMorph.GP01FB_FACE_TYPE.NORMAL;
  652. }
  653. if (0.35f <= num2)
  654. {
  655. return TMorph.GP01FB_FACE_TYPE.TARE;
  656. }
  657. if (0.35f <= num3)
  658. {
  659. return TMorph.GP01FB_FACE_TYPE.TSURI;
  660. }
  661. return TMorph.GP01FB_FACE_TYPE.MAX;
  662. }
  663. public void FixBlendValues_Face()
  664. {
  665. if (120 <= this.bodyskin.PartsVersion)
  666. {
  667. this.m_crcFaceTypeNow = this.GetFaceTypeGP01FB();
  668. for (int i = 0; i < 3; i++)
  669. {
  670. if (i != (int)this.m_crcFaceTypeNow)
  671. {
  672. int[] array = this.BlendDataIdx_EyeClose[i];
  673. for (int j = 0; j < array.Length; j++)
  674. {
  675. this.BlendValues[array[j]] = 0f;
  676. }
  677. }
  678. }
  679. }
  680. int[] array2 = this.BlendDataIdx_EyeClose[(int)this.m_crcFaceTypeNow];
  681. this.BlendValuesTemp[array2[0]] = this.m_fEyeCloseRate + this.BlendValuesBackup[array2[0]] * (1f - this.m_fEyeCloseRate);
  682. for (int k = 1; k < 10; k++)
  683. {
  684. if (array2[k] != 0)
  685. {
  686. this.BlendValuesTemp[array2[k]] = this.BlendValuesBackup[array2[k]] * (1f - this.m_fEyeCloseRate);
  687. }
  688. }
  689. if (0f < this.EyeMabataki)
  690. {
  691. float num = 0f;
  692. for (int l = 0; l < 10; l++)
  693. {
  694. if (array2[l] != 0)
  695. {
  696. num += this.BlendValuesTemp[array2[l]];
  697. }
  698. }
  699. if (num > 1f)
  700. {
  701. num = 1f;
  702. }
  703. float num2 = 1f - num;
  704. float num3 = this.BlendValuesTemp[array2[0]] + num2 * this.EyeMabataki;
  705. if (num3 > 0f)
  706. {
  707. this.BlendValuesTemp[array2[0]] = num3;
  708. }
  709. }
  710. for (int m = 0; m < 10; m++)
  711. {
  712. if (array2[m] != 0)
  713. {
  714. this.BlendValues[array2[m]] = this.BlendValuesTemp[array2[m]];
  715. }
  716. }
  717. if (this.m_EarNoneData.idx != -1)
  718. {
  719. this.BlendValues[this.m_EarNoneData.idx] = (float)((!this.m_EarNoneData.rate) ? 0 : 1);
  720. }
  721. if (this.m_EarElfData.idx != -1 && !this.m_EarNoneData.rate)
  722. {
  723. this.BlendValues[this.m_EarElfData.idx] = this.m_EarElfData.rate;
  724. }
  725. if (this.m_FaceShapeData.idx != -1)
  726. {
  727. this.BlendValues[this.m_FaceShapeData.idx] = this.m_FaceShapeData.rate;
  728. }
  729. if (this.m_FaceShapeSlimData.idx != -1)
  730. {
  731. this.BlendValues[this.m_FaceShapeSlimData.idx] = this.m_FaceShapeSlimData.rate;
  732. }
  733. if (this.m_MayuShapeIn.idx != -1)
  734. {
  735. this.BlendValues[this.m_MayuShapeIn.idx] = this.m_MayuShapeIn.rate;
  736. }
  737. if (this.m_MayuShapeOut.idx != -1)
  738. {
  739. this.BlendValues[this.m_MayuShapeOut.idx] = this.m_MayuShapeOut.rate;
  740. }
  741. if (120 <= this.bodyskin.PartsVersion && this.m_IdxMinMaxList != null)
  742. {
  743. float arg = 1f - Mathf.Clamp01(this.BlendValues[array2[0]] + this.BlendValues[array2[1]] + this.BlendValues[array2[4]] + this.BlendValues[array2[5]]);
  744. float arg2 = 1f - Mathf.Clamp01(this.BlendValues[array2[0]] + this.BlendValues[array2[1]] + this.BlendValues[array2[6]] + this.BlendValues[array2[7]]);
  745. foreach (TMorph.IdxMinMaxRatePair idxMinMaxRatePair in this.m_IdxMinMaxList)
  746. {
  747. if (idxMinMaxRatePair.exec != null)
  748. {
  749. idxMinMaxRatePair.exec(arg, arg2);
  750. }
  751. }
  752. }
  753. if (this.boLipSync)
  754. {
  755. this.BlendValues[this.BlendDataIdx_LipSync_A] = this.LipSync1 * 0.8f;
  756. this.BlendValues[this.BlendDataIdx_LipSync_C] = this.LipSync3 * 0.7f;
  757. this.BlendValues[this.BlendDataIdx_LipSync_ToothOFF] = this.LipSync3;
  758. this.BlendValues[this.BlendDataIdx_LipSync_S] = this.LipSync2 * (1f - this.LipSync1) * 0.5f;
  759. this.BlendValues[this.BlendDataIdx_LipSync_W] = this.LipSync2 * 0.3f;
  760. this.BlendValues[this.BlendDataIdx_LipSyncTh] = 0.5f;
  761. }
  762. if (this.boLookTooth)
  763. {
  764. this.BlendValues[this.BlendDataIdx_LipSync_A] = 0f;
  765. this.BlendValues[this.BlendDataIdx_LipSync_S] = 0.7f;
  766. this.BlendValues[this.BlendDataIdx_LipSync_C] = 0f;
  767. this.BlendValues[this.BlendDataIdx_LipSyncTh] = 0f;
  768. }
  769. if (this.boBallGAG)
  770. {
  771. this.BlendValues[this.BlendDataIdx_LipSync_A] = 1f;
  772. this.BlendValues[this.BlendDataIdx_LipSync_S] = 0f;
  773. this.BlendValues[this.BlendDataIdx_LipSync_C] = 0f;
  774. this.BlendValues[this.BlendDataIdx_LipSyncTh] = 0f;
  775. }
  776. float num4 = this.BlendValues[this.BlendDataIdx_Tear3];
  777. if (this.BlendValues[this.BlendDataIdx_Tear2] + num4 > 1f)
  778. {
  779. this.BlendValues[this.BlendDataIdx_Tear2] = 1f - num4;
  780. num4 = 1f;
  781. }
  782. else
  783. {
  784. num4 += this.BlendValues[this.BlendDataIdx_Tear2];
  785. }
  786. if (this.BlendValues[this.BlendDataIdx_Tear1] + num4 > 1f)
  787. {
  788. this.BlendValues[this.BlendDataIdx_Tear1] = 1f - num4;
  789. }
  790. if (this.boNoseFook)
  791. {
  792. this.BlendValues[this.BlendDataIdx_NoseFook] = 1f;
  793. }
  794. else
  795. {
  796. this.BlendValues[this.BlendDataIdx_NoseFook] = 0f;
  797. }
  798. int num5 = 0;
  799. for (int n = 0; n < this.MorphCount; n++)
  800. {
  801. if (this.BlendValuesCHK[n] != this.BlendValues[n])
  802. {
  803. num5++;
  804. this.BlendValuesCHK[n] = this.BlendValues[n];
  805. }
  806. }
  807. if (num5 == 0)
  808. {
  809. return;
  810. }
  811. this.m_vOriVert.CopyTo(this.m_vTmpVert, 0);
  812. this.m_bMorph = true;
  813. if (this.BlendValues[this.IdxHOHO] < 0.5f)
  814. {
  815. this.BlendValues[this.IdxHOHO] = 0f;
  816. }
  817. else
  818. {
  819. this.BlendValues[this.IdxHOHO] = 1f;
  820. }
  821. if (this.BlendValues[this.IdxHOHO2] < 0.5f)
  822. {
  823. this.BlendValues[this.IdxHOHO2] = 0f;
  824. }
  825. else
  826. {
  827. this.BlendValues[this.IdxHOHO2] = 1f;
  828. }
  829. for (int num6 = 0; num6 < this.MorphCount; num6++)
  830. {
  831. if (this.BlendDatas[num6] == null)
  832. {
  833. this.UruUruScaleX = this.BlendValues[num6];
  834. }
  835. else
  836. {
  837. float num7 = this.BlendValues[num6];
  838. if (num7 >= 0.01f || num6 == this.m_MayuShapeIn.idx || num6 == this.m_MayuShapeOut.idx)
  839. {
  840. int num8 = this.BlendDatas[num6].v_index.Length;
  841. for (int num9 = 0; num9 < num8; num9++)
  842. {
  843. int num10 = this.BlendDatas[num6].v_index[num9];
  844. this.m_vTmpVert[num10] += this.BlendDatas[num6].vert[num9] * num7;
  845. }
  846. }
  847. }
  848. }
  849. this.m_mesh.vertices = this.m_vTmpVert;
  850. foreach (TAttachPoint tattachPoint in this.dicAttachPoint.Values)
  851. {
  852. int vidx = tattachPoint.vidx;
  853. Vector3 vector = Vector3.zero;
  854. vector += this.m_bindposes[tattachPoint.bw.boneIndex0].MultiplyPoint3x4(this.m_vTmpVert[vidx]) * tattachPoint.bw.weight0;
  855. vector += this.m_bindposes[tattachPoint.bw.boneIndex1].MultiplyPoint3x4(this.m_vTmpVert[vidx]) * tattachPoint.bw.weight1;
  856. vector += this.m_bindposes[tattachPoint.bw.boneIndex2].MultiplyPoint3x4(this.m_vTmpVert[vidx]) * tattachPoint.bw.weight2;
  857. vector += this.m_bindposes[tattachPoint.bw.boneIndex3].MultiplyPoint3x4(this.m_vTmpVert[vidx]) * tattachPoint.bw.weight3;
  858. this.BindVert[vidx] = vector;
  859. }
  860. }
  861. public void FixFixBlendValues()
  862. {
  863. IEnumerator enumerator = this.hash.Keys.GetEnumerator();
  864. try
  865. {
  866. while (enumerator.MoveNext())
  867. {
  868. object obj = enumerator.Current;
  869. string text = (string)obj;
  870. int num = (int)this.hash[text];
  871. MaidProp propLower = this.bodyskin.body.maid.GetPropLower(text);
  872. if (propLower != null)
  873. {
  874. this.BlendValues[num] = (float)propLower.value / 100f;
  875. this.FixBlendValues();
  876. }
  877. }
  878. }
  879. finally
  880. {
  881. IDisposable disposable;
  882. if ((disposable = (enumerator as IDisposable)) != null)
  883. {
  884. disposable.Dispose();
  885. }
  886. }
  887. }
  888. public void FixBlendValues()
  889. {
  890. int num = 0;
  891. for (int i = 0; i < this.MorphCount; i++)
  892. {
  893. if (this.BlendValuesCHK[i] != this.BlendValues[i])
  894. {
  895. num++;
  896. this.BlendValuesCHK[i] = this.BlendValues[i];
  897. }
  898. }
  899. if (num == 0)
  900. {
  901. return;
  902. }
  903. this.m_vOriVert.CopyTo(this.m_vTmpVert, 0);
  904. this.m_vOriNorm.CopyTo(this.m_vTmpNorm, 0);
  905. this.m_bMorph = true;
  906. for (int j = 0; j < this.MorphCount; j++)
  907. {
  908. if (this.BlendDatas[j] == null)
  909. {
  910. this.UruUruScaleX = this.BlendValues[j];
  911. }
  912. else
  913. {
  914. float num2 = this.BlendValues[j];
  915. if (num2 >= 0.01f || j == this.m_MayuShapeIn.idx || j == this.m_MayuShapeOut.idx)
  916. {
  917. int num3 = this.BlendDatas[j].v_index.Length;
  918. for (int k = 0; k < num3; k++)
  919. {
  920. int num4 = this.BlendDatas[j].v_index[k];
  921. this.m_vTmpVert[num4] += this.BlendDatas[j].vert[k] * num2;
  922. this.m_vTmpNorm[num4] += this.BlendDatas[j].norm[k] * num2;
  923. }
  924. }
  925. }
  926. }
  927. this.m_mesh.vertices = this.m_vTmpVert;
  928. this.m_mesh.normals = this.m_vTmpNorm;
  929. foreach (TAttachPoint tattachPoint in this.dicAttachPoint.Values)
  930. {
  931. int vidx = tattachPoint.vidx;
  932. this.BindVert[vidx] = this.m_bindposes[tattachPoint.bw.boneIndex0].MultiplyPoint3x4(this.m_vTmpVert[vidx]);
  933. }
  934. }
  935. public void ResetBlendValues()
  936. {
  937. if (this.m_bMorph)
  938. {
  939. this.m_mesh.vertices = this.m_vTmpVert;
  940. this.m_mesh.normals = this.m_vTmpNorm;
  941. }
  942. }
  943. public void SetEnableAttachPointEdit(bool f_bEnable, string f_strApName)
  944. {
  945. TAttachPoint tattachPoint = this.dicAttachPoint[f_strApName];
  946. if (tattachPoint.bEditable == f_bEnable)
  947. {
  948. return;
  949. }
  950. int num = tattachPoint.srcvidx;
  951. Vector3 vector = Vector3.zero;
  952. Vector3 vector2 = Vector3.one;
  953. Quaternion quaternion = tattachPoint.qSrc;
  954. VtxAttachPos attachPointPos = this.bodyskin.body.maid.GetAttachPointPos(this.bodyskin.m_ParentMPN, this.bodyskin.SlotId, this.m_vOriVert.Length, f_strApName);
  955. if (attachPointPos != null)
  956. {
  957. num = attachPointPos.vidx;
  958. vector = attachPointPos.prs.position;
  959. quaternion = attachPointPos.prs.rotation;
  960. vector2 = attachPointPos.prs.scale;
  961. }
  962. if (f_bEnable)
  963. {
  964. tattachPoint.vidx = num;
  965. tattachPoint.vOffsLocal = vector;
  966. tattachPoint.qNow = quaternion;
  967. tattachPoint.vScaleRate = vector2;
  968. tattachPoint.bw = this.m_bws[tattachPoint.vidx];
  969. }
  970. else
  971. {
  972. tattachPoint.vidx = tattachPoint.srcvidx;
  973. tattachPoint.vOffsLocal = Vector3.zero;
  974. tattachPoint.qNow = tattachPoint.qSrc;
  975. tattachPoint.vScaleRate = Vector3.one;
  976. tattachPoint.bw = this.m_bws[tattachPoint.vidx];
  977. }
  978. tattachPoint.bEditable = f_bEnable;
  979. this.bodyskin.body.maid.SetAttachPointPos(this.bodyskin.m_ParentMPN, this.bodyskin.SlotId, this.m_vOriVert.Length, f_strApName, num, vector, quaternion, vector2, tattachPoint.bEditable);
  980. }
  981. public bool GetEnableAttachPointEdit(string f_strApName)
  982. {
  983. return this.dicAttachPoint[f_strApName].bEditable;
  984. }
  985. public void SetAttachPoint(string apname, Vector3 vc, Quaternion q, bool f_bTemp)
  986. {
  987. TAttachPoint tattachPoint = new TAttachPoint();
  988. float num = (vc - this.DefVert[0]).sqrMagnitude;
  989. int num2 = 0;
  990. for (int i = 0; i < this.m_vOriVert.Length; i++)
  991. {
  992. float sqrMagnitude = (vc - this.DefVert[i]).sqrMagnitude;
  993. if (num > sqrMagnitude)
  994. {
  995. num = sqrMagnitude;
  996. num2 = i;
  997. }
  998. }
  999. tattachPoint.srcvidx = (tattachPoint.vidx = num2);
  1000. tattachPoint.vOffsLocal = Vector3.zero;
  1001. TAttachPoint tattachPoint2 = tattachPoint;
  1002. tattachPoint.qNow = q;
  1003. tattachPoint2.qSrc = q;
  1004. tattachPoint.vScaleRate = Vector3.one;
  1005. tattachPoint.bw = this.m_bws[num2];
  1006. this.dicAttachPoint[apname] = tattachPoint;
  1007. if (!f_bTemp)
  1008. {
  1009. VtxAttachPos attachPointPos = this.bodyskin.body.maid.GetAttachPointPos(this.bodyskin.m_ParentMPN, this.bodyskin.SlotId, this.m_vOriVert.Length, apname);
  1010. if (attachPointPos != null && attachPointPos.bEnable)
  1011. {
  1012. tattachPoint.vidx = attachPointPos.vidx;
  1013. tattachPoint.vOffsLocal = attachPointPos.prs.position;
  1014. tattachPoint.qNow = attachPointPos.prs.rotation;
  1015. tattachPoint.vScaleRate = attachPointPos.prs.scale;
  1016. tattachPoint.bEditable = true;
  1017. tattachPoint.bw = this.m_bws[tattachPoint.vidx];
  1018. }
  1019. }
  1020. }
  1021. public void SetAttachPointOffsetLocal(string apname, VtxAttachPos f_vap)
  1022. {
  1023. TAttachPoint tattachPoint = this.dicAttachPoint[apname];
  1024. tattachPoint.vidx = f_vap.vidx;
  1025. tattachPoint.vOffsLocal = f_vap.prs.position;
  1026. tattachPoint.qNow = f_vap.prs.rotation;
  1027. tattachPoint.vScaleRate = f_vap.prs.scale;
  1028. tattachPoint.bEditable = true;
  1029. tattachPoint.bw = this.m_bws[tattachPoint.vidx];
  1030. }
  1031. public bool CopyAttachObjPoint(string apname)
  1032. {
  1033. TAttachPoint tattachPoint = this.dicAttachPoint[apname];
  1034. TMorph.TempAttachPos tempAttachPos = new TMorph.TempAttachPos();
  1035. tempAttachPos.m_nVidx = tattachPoint.vidx;
  1036. tempAttachPos.m_vPos = tattachPoint.vOffsLocal;
  1037. tempAttachPos.m_qRot = tattachPoint.qNow;
  1038. tempAttachPos.m_vScale = tattachPoint.vScaleRate;
  1039. this.bodyskin.m_dicTempAttachPoint[apname] = tempAttachPos;
  1040. return true;
  1041. }
  1042. public bool PastAttachObjPoint(string apname)
  1043. {
  1044. TAttachPoint tattachPoint = this.dicAttachPoint[apname];
  1045. TMorph.TempAttachPos tempAttachPos = null;
  1046. if (this.bodyskin.m_dicTempAttachPoint.TryGetValue(apname, out tempAttachPos))
  1047. {
  1048. tattachPoint.bEditable = true;
  1049. tattachPoint.vidx = tempAttachPos.m_nVidx;
  1050. tattachPoint.vOffsLocal = tempAttachPos.m_vPos;
  1051. tattachPoint.qNow = tempAttachPos.m_qRot;
  1052. tattachPoint.vScaleRate = tempAttachPos.m_vScale;
  1053. tattachPoint.bw = this.m_bws[tattachPoint.vidx];
  1054. }
  1055. this.bodyskin.body.maid.SetAttachPointPos(this.bodyskin.m_ParentMPN, this.bodyskin.SlotId, this.m_vOriVert.Length, apname, tattachPoint.vidx, tattachPoint.vOffsLocal, tattachPoint.qNow, tattachPoint.vScaleRate, tattachPoint.bEditable);
  1056. return true;
  1057. }
  1058. public void SetAttachPointWorld(string apname, Vector3 vWorldPos, Quaternion qWorldRot, Vector3 vScaleRate)
  1059. {
  1060. TAttachPoint tattachPoint = this.dicAttachPoint[apname];
  1061. if (!tattachPoint.bEditable)
  1062. {
  1063. return;
  1064. }
  1065. this.ReclucPointWorldAndScreen(null);
  1066. int vidx = tattachPoint.vidx;
  1067. float num = (this.WorldV[vidx] - vWorldPos).sqrMagnitude;
  1068. int num2 = vidx;
  1069. for (int i = 0; i < this.m_vOriVert.Length; i++)
  1070. {
  1071. float sqrMagnitude = (this.WorldV[i] - vWorldPos).sqrMagnitude;
  1072. if (sqrMagnitude < num)
  1073. {
  1074. num = sqrMagnitude;
  1075. num2 = i;
  1076. }
  1077. }
  1078. tattachPoint.vidx = num2;
  1079. tattachPoint.bw = this.m_bws[num2];
  1080. int num3 = this.BindBone[num2];
  1081. Transform transform = this.m_bones[num3].transform;
  1082. Vector3 vector = Vector3.zero;
  1083. if (this.SlotId == TBody.SlotID.body)
  1084. {
  1085. this.CalcVertexPoint(ref vector, num2, ref tattachPoint.bw);
  1086. }
  1087. else
  1088. {
  1089. vector = this.BindVert[num2];
  1090. vector = transform.TransformPoint(vector);
  1091. tattachPoint.vOffsLocal = transform.InverseTransformPoint(vWorldPos) - transform.InverseTransformPoint(vector);
  1092. }
  1093. tattachPoint.qNow = Quaternion.Inverse(transform.transform.rotation) * qWorldRot;
  1094. tattachPoint.vScaleRate = vScaleRate;
  1095. this.dicAttachPoint[apname] = tattachPoint;
  1096. this.bodyskin.body.maid.SetAttachPointPos(this.bodyskin.m_ParentMPN, this.bodyskin.SlotId, this.m_vOriVert.Length, apname, tattachPoint.vidx, tattachPoint.vOffsLocal, tattachPoint.qNow, tattachPoint.vScaleRate, tattachPoint.bEditable);
  1097. Debug.DrawLine(vector, vWorldPos, Color.cyan);
  1098. }
  1099. public bool GetAttachPoint(string apname, out Vector3 vWorldPos, out Quaternion qWorldRot, out Vector3 vScaleRate, bool f_bTemp = false)
  1100. {
  1101. if (!this.dicAttachPoint.ContainsKey(apname))
  1102. {
  1103. vWorldPos = Vector3.zero;
  1104. qWorldRot = Quaternion.identity;
  1105. vScaleRate = Vector3.one;
  1106. return false;
  1107. }
  1108. TAttachPoint tattachPoint = this.dicAttachPoint[apname];
  1109. Vector3 vector = Vector3.zero;
  1110. int num = tattachPoint.vidx;
  1111. if (f_bTemp)
  1112. {
  1113. num = tattachPoint.srcvidx;
  1114. }
  1115. Transform transform = this.m_bones[this.BindBone[num]].transform;
  1116. if (this.SlotId == TBody.SlotID.body)
  1117. {
  1118. this.CalcVertexPoint(ref vector, num, ref tattachPoint.bw);
  1119. }
  1120. else
  1121. {
  1122. if (!f_bTemp)
  1123. {
  1124. vector = tattachPoint.vOffsLocal;
  1125. }
  1126. vector += this.BindVert[num];
  1127. vector = transform.TransformPoint(vector);
  1128. }
  1129. vWorldPos = vector;
  1130. if (f_bTemp)
  1131. {
  1132. qWorldRot = transform.rotation * tattachPoint.qSrc;
  1133. vScaleRate = Vector3.one;
  1134. }
  1135. else
  1136. {
  1137. qWorldRot = transform.rotation * tattachPoint.qNow;
  1138. vScaleRate = tattachPoint.vScaleRate;
  1139. }
  1140. return true;
  1141. }
  1142. public bool ResetAttachPoint(string apname)
  1143. {
  1144. if (!this.dicAttachPoint.ContainsKey(apname))
  1145. {
  1146. Debug.LogError("アタッチポイント " + apname + " はありません。");
  1147. return false;
  1148. }
  1149. TAttachPoint tattachPoint = this.dicAttachPoint[apname];
  1150. tattachPoint.vidx = tattachPoint.srcvidx;
  1151. tattachPoint.vOffsLocal = Vector3.zero;
  1152. tattachPoint.qNow = tattachPoint.qSrc;
  1153. tattachPoint.vScaleRate = Vector3.one;
  1154. tattachPoint.bw = this.m_bws[tattachPoint.vidx];
  1155. this.bodyskin.body.maid.ClearAttachPointPos(this.bodyskin.m_ParentMPN, this.bodyskin.SlotId, apname);
  1156. return true;
  1157. }
  1158. public void ReclucPointWorldAndScreen(Camera cam = null)
  1159. {
  1160. bool flag = cam != null;
  1161. for (int i = 0; i < this.VCount; i++)
  1162. {
  1163. BoneWeight boneWeight = this.m_bws[i];
  1164. Vector3 zero = Vector3.zero;
  1165. this.CalcVertexPoint(ref zero, i, ref boneWeight);
  1166. this.WorldV[i] = zero;
  1167. if (flag)
  1168. {
  1169. this.ScrnV[i] = cam.WorldToScreenPoint(zero);
  1170. }
  1171. }
  1172. }
  1173. private void CalcVertexPoint(ref Vector3 vPosLocalToWorld, int nVtx, ref BoneWeight bw)
  1174. {
  1175. vPosLocalToWorld += this.m_bones[bw.boneIndex0].transform.TransformPoint(this.m_bindposes[bw.boneIndex0].MultiplyPoint(this.m_vTmpVert[nVtx])) * bw.weight0;
  1176. if (bw.weight1 != 0f)
  1177. {
  1178. vPosLocalToWorld += this.m_bones[bw.boneIndex1].TransformPoint(this.m_bindposes[bw.boneIndex1].MultiplyPoint(this.m_vTmpVert[nVtx])) * bw.weight1;
  1179. }
  1180. if (bw.weight2 != 0f)
  1181. {
  1182. vPosLocalToWorld += this.m_bones[bw.boneIndex2].TransformPoint(this.m_bindposes[bw.boneIndex2].MultiplyPoint(this.m_vTmpVert[nVtx])) * bw.weight2;
  1183. }
  1184. if (bw.weight3 != 0f)
  1185. {
  1186. vPosLocalToWorld += this.m_bones[bw.boneIndex3].TransformPoint(this.m_bindposes[bw.boneIndex3].MultiplyPoint(this.m_vTmpVert[nVtx])) * bw.weight3;
  1187. }
  1188. }
  1189. private Vector3 CalcVertexPointWorldToLocal(Vector3 vWorld, int nVtx, ref BoneWeight bw)
  1190. {
  1191. Vector3 vector = Vector3.zero;
  1192. vector += this.m_bones[bw.boneIndex0].transform.InverseTransformPoint(vWorld) * bw.weight0;
  1193. if (bw.weight1 != 0f)
  1194. {
  1195. vector += this.m_bones[bw.boneIndex1].InverseTransformPoint(vWorld) * bw.weight1;
  1196. }
  1197. if (bw.weight2 != 0f)
  1198. {
  1199. vector += this.m_bones[bw.boneIndex2].InverseTransformPoint(vWorld) * bw.weight2;
  1200. }
  1201. if (bw.weight3 != 0f)
  1202. {
  1203. vector += this.m_bones[bw.boneIndex3].InverseTransformPoint(vWorld) * bw.weight3;
  1204. }
  1205. return vector;
  1206. }
  1207. private Vector3 CalcVertexPointLocalToWorld(Vector3 vLocal, int nVtx, ref BoneWeight bw)
  1208. {
  1209. Vector3 vector = Vector3.zero;
  1210. vector += this.m_bones[bw.boneIndex0].transform.TransformPoint(vLocal) * bw.weight0;
  1211. if (bw.weight1 != 0f)
  1212. {
  1213. vector += this.m_bones[bw.boneIndex1].TransformPoint(vLocal) * bw.weight1;
  1214. }
  1215. if (bw.weight2 != 0f)
  1216. {
  1217. vector += this.m_bones[bw.boneIndex2].TransformPoint(vLocal) * bw.weight2;
  1218. }
  1219. if (bw.weight3 != 0f)
  1220. {
  1221. vector += this.m_bones[bw.boneIndex3].TransformPoint(vLocal) * bw.weight3;
  1222. }
  1223. return vector;
  1224. }
  1225. public int VHitChk(Camera cam, Vector3 msv, out Vector3 vHitWorld)
  1226. {
  1227. if (this.m_nOriTri == null || this.m_nOriTri.Length == 0)
  1228. {
  1229. this.m_nOriTri = this.m_mesh.triangles;
  1230. this.TriCount = this.m_nOriTri.Length;
  1231. }
  1232. int num = -1;
  1233. float num2 = float.PositiveInfinity;
  1234. for (int i = 0; i < this.TriCount; i += 3)
  1235. {
  1236. int num3 = this.m_nOriTri[i];
  1237. int num4 = this.m_nOriTri[i + 1];
  1238. int num5 = this.m_nOriTri[i + 2];
  1239. Vector3 vector = this.ScrnV[num3];
  1240. Vector3 vector2 = this.ScrnV[num4];
  1241. Vector3 vector3 = this.ScrnV[num5];
  1242. float z = vector.z;
  1243. vector.z = 0f;
  1244. float z2 = vector2.z;
  1245. vector2.z = 0f;
  1246. float z3 = vector3.z;
  1247. vector3.z = 0f;
  1248. if (Vector3.Cross(vector2 - vector, vector3 - vector2).z <= 0f)
  1249. {
  1250. if ((double)Vector3.Cross(msv - vector, vector2 - vector).z >= 0.0 && (double)Vector3.Cross(msv - vector2, vector3 - vector2).z >= 0.0 && (double)Vector3.Cross(msv - vector3, vector - vector3).z >= 0.0)
  1251. {
  1252. if (z < num2)
  1253. {
  1254. num2 = z;
  1255. num = i;
  1256. }
  1257. }
  1258. }
  1259. }
  1260. if (num != -1)
  1261. {
  1262. Debug.DrawLine(this.WorldV[this.m_nOriTri[num]], this.WorldV[this.m_nOriTri[num + 1]], Color.cyan);
  1263. Debug.DrawLine(this.WorldV[this.m_nOriTri[num + 1]], this.WorldV[this.m_nOriTri[num + 2]], Color.cyan);
  1264. Debug.DrawLine(this.WorldV[this.m_nOriTri[num]], this.WorldV[this.m_nOriTri[num + 2]], Color.cyan);
  1265. }
  1266. vHitWorld = Vector3.zero;
  1267. if (num != -1)
  1268. {
  1269. float d = 0f;
  1270. Plane plane = new Plane(this.WorldV[this.m_nOriTri[num]], this.WorldV[this.m_nOriTri[num + 1]], this.WorldV[this.m_nOriTri[num + 2]]);
  1271. Ray ray = cam.ScreenPointToRay(msv);
  1272. if (plane.Raycast(ray, out d))
  1273. {
  1274. vHitWorld = ray.origin + ray.direction * d;
  1275. }
  1276. else
  1277. {
  1278. Debug.LogWarning("当たって居ない");
  1279. }
  1280. }
  1281. return num;
  1282. }
  1283. public void Test(Vector3 vc)
  1284. {
  1285. float num = (vc - this.DefVert[0]).sqrMagnitude;
  1286. int num2 = 0;
  1287. for (int i = 0; i < this.m_vOriVert.Length; i++)
  1288. {
  1289. float sqrMagnitude = (vc - this.DefVert[i]).sqrMagnitude;
  1290. if (num > sqrMagnitude)
  1291. {
  1292. num = sqrMagnitude;
  1293. num2 = i;
  1294. }
  1295. }
  1296. this.attach_FaceHana = num2;
  1297. }
  1298. public float ChkHit(Camera cam)
  1299. {
  1300. Ray ray = cam.ScreenPointToRay(Input.mousePosition);
  1301. float num = 0f;
  1302. float num2 = 0f;
  1303. int num3 = -1;
  1304. float num4 = 0f;
  1305. for (int i = 0; i < this.TriCount / 3; i++)
  1306. {
  1307. float num5 = this.TriangleIntersect(ray, i);
  1308. if (num5 > 0f && (num4 > num5 || num4 == 0f))
  1309. {
  1310. num3 = i;
  1311. num4 = num5;
  1312. this.vHitPos = ray.origin + ray.direction * num5;
  1313. num = this.HitUV.x;
  1314. num2 = this.HitUV.y;
  1315. }
  1316. }
  1317. this.HitAtr = 0;
  1318. if (num3 >= 0)
  1319. {
  1320. Vector2[] uv = this.m_mesh.uv;
  1321. float d = 1f - num - num2;
  1322. Vector2 vector = uv[this.m_nOriTri[num3 * 3]] * d;
  1323. vector += uv[this.m_nOriTri[num3 * 3 + 1]] * num;
  1324. vector += uv[this.m_nOriTri[num3 * 3 + 2]] * num2;
  1325. this.HitTextureUV = vector;
  1326. this.HitAtr = (this.m_AtrVert[this.m_nOriTri[num3 * 3]] | this.m_AtrVert[this.m_nOriTri[num3 * 3 + 1]] | this.m_AtrVert[this.m_nOriTri[num3 * 3 + 2]]);
  1327. }
  1328. return num4;
  1329. }
  1330. private float TriangleIntersect(Ray ray, int triidx)
  1331. {
  1332. Vector3 origin = ray.origin;
  1333. Vector3 normalized = ray.direction.normalized;
  1334. Vector3 b = this.WorldV[this.m_nOriTri[triidx * 3]];
  1335. Vector3 a = this.WorldV[this.m_nOriTri[triidx * 3 + 1]];
  1336. Vector3 a2 = this.WorldV[this.m_nOriTri[triidx * 3 + 2]];
  1337. Vector3 lhs = a - b;
  1338. Vector3 lhs2 = a2 - b;
  1339. Vector3 rhs = Vector3.Cross(lhs2, normalized);
  1340. float num = Vector3.Dot(lhs, rhs);
  1341. if (num >= -1E-08f)
  1342. {
  1343. return 0f;
  1344. }
  1345. Vector3 vector = origin - b;
  1346. float num2 = Vector3.Dot(vector, rhs);
  1347. if ((double)num2 > 0.0 || num2 < num)
  1348. {
  1349. return 0f;
  1350. }
  1351. Vector3 rhs2 = Vector3.Cross(lhs, vector);
  1352. float num3 = Vector3.Dot(normalized, rhs2);
  1353. if ((double)num3 > 0.0 || num2 + num3 < num)
  1354. {
  1355. return 0f;
  1356. }
  1357. float num4 = 1f / num;
  1358. float num5 = Vector3.Dot(lhs2, rhs2);
  1359. num5 *= num4;
  1360. num2 *= num4;
  1361. num3 *= num4;
  1362. this.HitUV.x = num2;
  1363. this.HitUV.y = num3;
  1364. return num5;
  1365. }
  1366. public void OnApplicationQuit()
  1367. {
  1368. Debug.LogError("TMorph OnApplicationQuit");
  1369. this.m_mesh.vertices = this.m_vOriVert;
  1370. this.m_mesh.normals = this.m_vOriNorm;
  1371. }
  1372. public int MorphCount;
  1373. public Hashtable hash;
  1374. public Dictionary<string, float[]> dicBlendSet = new Dictionary<string, float[]>();
  1375. public Dictionary<string, int> dicBlendAtr = new Dictionary<string, int>();
  1376. public int IdxHOHO = -1;
  1377. public int IdxHOHO2 = -1;
  1378. public Dictionary<string, TAttachPoint> dicAttachPoint = new Dictionary<string, TAttachPoint>();
  1379. public int VCount;
  1380. private int TriCount;
  1381. private int BoneCount;
  1382. private int m_nSubMeshCount;
  1383. public Vector3[] BindVert;
  1384. public Vector3[] ScrnV;
  1385. public Vector3[] WorldV;
  1386. public int[] BindBone;
  1387. public Vector3[] DefVert;
  1388. public Vector3[] m_vOriVert;
  1389. public Vector3[] m_vOriNorm;
  1390. public int[] m_nOriTri;
  1391. public int[][] m_nSubMeshOriTri;
  1392. private Vector3[] m_vTmpVert;
  1393. private Vector3[] m_vTmpNorm;
  1394. public int[][] m_nSubMeshTmpTri;
  1395. private int[] m_AtrVert;
  1396. public List<BlendData> BlendDatas;
  1397. public static readonly string[] crcFaceTypesStr = new string[]
  1398. {
  1399. "_normal",
  1400. "_tare",
  1401. "_tsuri"
  1402. };
  1403. private TMorph.GP01FB_FACE_TYPE m_crcFaceTypeNow;
  1404. public int[][] BlendDataIdx_EyeClose;
  1405. public float m_fEyeCloseRate;
  1406. public float EyeMabataki;
  1407. public TMorph.IdxRatePair<bool> m_EarNoneData;
  1408. public TMorph.IdxRatePair<float> m_EarElfData;
  1409. public TMorph.IdxRatePair<float> m_FaceShapeData;
  1410. public TMorph.IdxRatePair<float> m_FaceShapeSlimData;
  1411. public TMorph.IdxRatePair<float> m_MayuShapeIn;
  1412. public TMorph.IdxRatePair<float> m_MayuShapeOut;
  1413. public TMorph.IdxMinMaxRatePair m_MabutaUpIn = new TMorph.IdxMinMaxRatePair();
  1414. public TMorph.IdxMinMaxRatePair m_MabutaUpIn2 = new TMorph.IdxMinMaxRatePair();
  1415. public TMorph.IdxMinMaxRatePair m_MabutaUpMiddle = new TMorph.IdxMinMaxRatePair();
  1416. public TMorph.IdxMinMaxRatePair m_MabutaUpOut = new TMorph.IdxMinMaxRatePair();
  1417. public TMorph.IdxMinMaxRatePair m_MabutaUpOut2 = new TMorph.IdxMinMaxRatePair();
  1418. public TMorph.IdxMinMaxRatePair m_MabutaLowIn = new TMorph.IdxMinMaxRatePair();
  1419. public TMorph.IdxMinMaxRatePair m_MabutaLowUpMiddle = new TMorph.IdxMinMaxRatePair();
  1420. public TMorph.IdxMinMaxRatePair m_MabutaLowUpOut = new TMorph.IdxMinMaxRatePair();
  1421. private List<TMorph.IdxMinMaxRatePair> m_IdxMinMaxList;
  1422. public int BlendDataIdx_LipSyncTh;
  1423. public int BlendDataIdx_LipSync_A;
  1424. public int BlendDataIdx_LipSync_S;
  1425. public int BlendDataIdx_LipSync_C;
  1426. public int BlendDataIdx_LipSync_W;
  1427. public int BlendDataIdx_LipSync_ToothOFF;
  1428. public int BlendDataIdx_Tear1;
  1429. public int BlendDataIdx_Tear2;
  1430. public int BlendDataIdx_Tear3;
  1431. private float m_LipSync1;
  1432. private float m_LipSync2;
  1433. private float m_LipSync3;
  1434. public bool boLipSync;
  1435. public bool boLookTooth;
  1436. public bool boBallGAG;
  1437. public bool boNoseFook;
  1438. public int BlendDataIdx_NoseFook;
  1439. public int BlendDataIdx_RegFat;
  1440. public int BlendDataIdx_RegMeet;
  1441. private SkinnedMeshRenderer smr_src;
  1442. private Transform[] m_bones;
  1443. private Transform tRoot;
  1444. private Mesh m_mesh;
  1445. private BoneWeight[] m_bws;
  1446. private Matrix4x4[] m_bindposes;
  1447. private float[] BlendValues;
  1448. private float[] BlendValuesTemp;
  1449. private float[] BlendValuesBackup;
  1450. private float[] BlendValuesCHK;
  1451. public float UruUruScaleX;
  1452. public List<string> BoneNames;
  1453. public List<bool> BoneVisible;
  1454. public TBodySkin bodyskin;
  1455. public int attach_FaceHana;
  1456. private string Category;
  1457. private TBody.SlotID SlotId;
  1458. private bool m_bIsBody;
  1459. private bool m_bMorph;
  1460. private static string[] AtrVertChk = new string[]
  1461. {
  1462. "Mune",
  1463. "Hip"
  1464. };
  1465. private bool m_bDut;
  1466. public Vector3 vHitPos;
  1467. public Vector2 HitTextureUV;
  1468. public Vector2 HitUV;
  1469. public int HitAtr;
  1470. [Flags]
  1471. public enum AddBlendType
  1472. {
  1473. None = 0,
  1474. Cheek1 = 1,
  1475. Cheek2 = 2,
  1476. Cheek3 = 4,
  1477. Blush = 8,
  1478. Tear1 = 16,
  1479. Tear2 = 32,
  1480. Tear3 = 64,
  1481. TearBig = 128,
  1482. Yodare = 256,
  1483. Shock = 512
  1484. }
  1485. public struct IdxRatePair<T> where T : struct
  1486. {
  1487. public int idx;
  1488. public T rate;
  1489. }
  1490. public class IdxMinMaxRatePair
  1491. {
  1492. public int idxDwL;
  1493. public int idxUpL;
  1494. public int idxDwR;
  1495. public int idxUpR;
  1496. public float rate;
  1497. public Action<float, float> exec;
  1498. }
  1499. public enum GP01FB_FACE_TYPE
  1500. {
  1501. NORMAL,
  1502. TARE,
  1503. TSURI,
  1504. MAX
  1505. }
  1506. public class TempAttachPos
  1507. {
  1508. public int m_nVidx;
  1509. public Vector3 m_vPos;
  1510. public Vector3 m_vScale;
  1511. public Quaternion m_qRot;
  1512. }
  1513. }