TMorph.cs 45 KB

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