TMorph.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  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_fFaceShapeRate = 0f;
  129. if (this.hash.ContainsKey("shape"))
  130. {
  131. this.m_BlendDataIdx_FaceShape = (int)this.hash["shape"];
  132. }
  133. this.m_fEyeCloseRate = 0f;
  134. this.BlendDataIdx_EyeClose = new int[10];
  135. if (this.hash.ContainsKey("eyeclose"))
  136. {
  137. this.BlendDataIdx_EyeClose[0] = (int)this.hash["eyeclose"];
  138. }
  139. for (int k = 1; k < 10; k++)
  140. {
  141. if (this.hash.ContainsKey("eyeclose" + k.ToString()))
  142. {
  143. this.BlendDataIdx_EyeClose[k] = (int)this.hash["eyeclose" + k.ToString()];
  144. }
  145. }
  146. if (!this.bodyskin.body.boMAN && this.Category == "head" && this.BlendDataIdx_EyeClose[0] == 0)
  147. {
  148. Debug.LogError("Face[eyeclose]");
  149. }
  150. if (this.hash.ContainsKey("toothoff"))
  151. {
  152. this.BlendDataIdx_LipSyncTh = (int)this.hash["toothoff"];
  153. }
  154. if (this.hash.ContainsKey("moutha"))
  155. {
  156. this.BlendDataIdx_LipSync_A = (int)this.hash["moutha"];
  157. }
  158. if (this.hash.ContainsKey("mouths"))
  159. {
  160. this.BlendDataIdx_LipSync_S = (int)this.hash["mouths"];
  161. }
  162. if (this.hash.ContainsKey("mouthc"))
  163. {
  164. this.BlendDataIdx_LipSync_C = (int)this.hash["mouthc"];
  165. }
  166. if (this.hash.ContainsKey("toothoff"))
  167. {
  168. this.BlendDataIdx_LipSync_ToothOFF = (int)this.hash["toothoff"];
  169. }
  170. if (this.hash.ContainsKey("mouthdw"))
  171. {
  172. this.BlendDataIdx_LipSync_W = (int)this.hash["mouthdw"];
  173. }
  174. if (this.hash.ContainsKey("tear1"))
  175. {
  176. this.BlendDataIdx_Tear1 = (int)this.hash["tear1"];
  177. }
  178. if (this.hash.ContainsKey("tear2"))
  179. {
  180. this.BlendDataIdx_Tear2 = (int)this.hash["tear2"];
  181. }
  182. if (this.hash.ContainsKey("tear3"))
  183. {
  184. this.BlendDataIdx_Tear3 = (int)this.hash["tear3"];
  185. }
  186. if (this.hash.ContainsKey("nosefook"))
  187. {
  188. this.BlendDataIdx_NoseFook = (int)this.hash["nosefook"];
  189. }
  190. if (this.hash.ContainsKey("eyeclose"))
  191. {
  192. int count = this.BlendDatas.Count;
  193. this.hash["uru-uru"] = count;
  194. this.BlendDatas.Add(null);
  195. this.MorphCount++;
  196. }
  197. if (this.hash.ContainsKey("regfat"))
  198. {
  199. this.BlendDataIdx_RegFat = (int)this.hash["regfat"];
  200. }
  201. if (this.hash.ContainsKey("regmeet"))
  202. {
  203. this.BlendDataIdx_RegMeet = (int)this.hash["regmeet"];
  204. }
  205. this.ScrnV = new Vector3[this.VCount];
  206. this.WorldV = new Vector3[this.VCount];
  207. this.BindVert = new Vector3[this.VCount];
  208. this.DefVert = new Vector3[this.VCount];
  209. this.BindBone = new int[this.VCount];
  210. this.m_bindposes = this.m_mesh.bindposes;
  211. this.m_bws = this.bodyskin.m_OriVert.bwWeight;
  212. fixed (BoneWeight* ptr = &this.m_bws[0])
  213. {
  214. BoneWeight* ptr2 = ptr;
  215. for (int l = 0; l < this.VCount; l++)
  216. {
  217. int num = ptr2->boneIndex0;
  218. float num2 = ptr2->weight0;
  219. if (ptr2->weight1 > num2)
  220. {
  221. num2 = ptr2->weight1;
  222. num = ptr2->boneIndex1;
  223. }
  224. if (ptr2->weight2 > num2)
  225. {
  226. num2 = ptr2->weight2;
  227. num = ptr2->boneIndex2;
  228. }
  229. if (ptr2->weight3 > num2)
  230. {
  231. num2 = ptr2->weight3;
  232. num = ptr2->boneIndex3;
  233. }
  234. this.BindBone[l] = num;
  235. Vector3 vector = this.m_bindposes[num].MultiplyPoint3x4(this.m_vOriVert[l]);
  236. this.BindVert[l] = vector;
  237. this.DefVert[l] = this.m_bones[num].TransformPoint(vector);
  238. this.m_AtrVert[l] = 0;
  239. for (int m = 0; m < TMorph.AtrVertChk.Length; m++)
  240. {
  241. if (this.BoneNames[ptr2->boneIndex0].Contains(TMorph.AtrVertChk[m]))
  242. {
  243. this.m_AtrVert[l] |= 1 << m;
  244. }
  245. if (ptr2->weight1 > 0f && this.BoneNames[ptr2->boneIndex1].Contains(TMorph.AtrVertChk[m]))
  246. {
  247. this.m_AtrVert[l] |= 1 << m;
  248. }
  249. if (ptr2->weight2 > 0f && this.BoneNames[ptr2->boneIndex2].Contains(TMorph.AtrVertChk[m]))
  250. {
  251. this.m_AtrVert[l] |= 1 << m;
  252. }
  253. if (ptr2->weight3 > 0f && this.BoneNames[ptr2->boneIndex3].Contains(TMorph.AtrVertChk[m]))
  254. {
  255. this.m_AtrVert[l] |= 1 << m;
  256. }
  257. }
  258. ptr2++;
  259. }
  260. }
  261. }
  262. private void initlp(Transform t)
  263. {
  264. for (int i = 0; i < this.BoneCount; i++)
  265. {
  266. if (this.m_bones[i] != null)
  267. {
  268. this.BoneNames.Add(this.m_bones[i].name);
  269. this.BoneVisible.Add(true);
  270. }
  271. else
  272. {
  273. this.BoneNames.Add(string.Empty);
  274. this.BoneVisible.Add(false);
  275. }
  276. }
  277. this.m_bDut = false;
  278. }
  279. public void ClearAllVisibleFlag(bool boSetFlag)
  280. {
  281. for (int i = 0; i < this.BoneCount; i++)
  282. {
  283. if (this.BoneVisible[i] != boSetFlag)
  284. {
  285. this.BoneVisible[i] = boSetFlag;
  286. this.m_bDut = true;
  287. }
  288. }
  289. }
  290. public void SetVisibleFlag1(int idx, bool flag)
  291. {
  292. if (this.BoneVisible[idx] != flag)
  293. {
  294. this.BoneVisible[idx] = flag;
  295. this.m_bDut = true;
  296. }
  297. }
  298. public void SetVisibleFlag(bool boSetFlag, string name, Transform t = null, bool boTgt = false, int cnt = -1)
  299. {
  300. cnt++;
  301. if (t == null)
  302. {
  303. t = this.tRoot;
  304. }
  305. if (t.name.IndexOf(name) >= 0)
  306. {
  307. boTgt = true;
  308. }
  309. if (name == "_ALL_")
  310. {
  311. boTgt = true;
  312. }
  313. if (boTgt)
  314. {
  315. for (int i = 0; i < this.BoneCount; i++)
  316. {
  317. if (t.name == this.BoneNames[i])
  318. {
  319. this.SetVisibleFlag1(i, boSetFlag);
  320. break;
  321. }
  322. }
  323. }
  324. for (int j = 0; j < t.childCount; j++)
  325. {
  326. this.SetVisibleFlag(boSetFlag, name, t.GetChild(j), boTgt, cnt);
  327. }
  328. }
  329. public void FixVisibleFlag()
  330. {
  331. if (this.smr_src == null)
  332. {
  333. return;
  334. }
  335. if (this.m_mesh == null)
  336. {
  337. return;
  338. }
  339. if (!this.m_bDut)
  340. {
  341. return;
  342. }
  343. for (int i = 0; i < this.m_nSubMeshCount; i++)
  344. {
  345. this.m_nSubMeshOriTri[i].CopyTo(this.m_nSubMeshTmpTri[i], 0);
  346. int[] array = this.m_nSubMeshTmpTri[i];
  347. for (int j = 0; j < array.Length / 3; j++)
  348. {
  349. int num = 3;
  350. for (int k = 0; k < 3; k++)
  351. {
  352. int num2 = array[j * 3 + k];
  353. BoneWeight boneWeight = this.m_bws[num2];
  354. if (!this.BoneVisible[boneWeight.boneIndex0])
  355. {
  356. num--;
  357. break;
  358. }
  359. if (!this.BoneVisible[boneWeight.boneIndex1] && boneWeight.weight1 > 0f)
  360. {
  361. num--;
  362. break;
  363. }
  364. if (!this.BoneVisible[boneWeight.boneIndex2] && boneWeight.weight2 > 0f)
  365. {
  366. num--;
  367. break;
  368. }
  369. if (!this.BoneVisible[boneWeight.boneIndex3] && boneWeight.weight3 > 0f)
  370. {
  371. num--;
  372. break;
  373. }
  374. }
  375. if (num != 3)
  376. {
  377. for (int l = 0; l < 3; l++)
  378. {
  379. array[j * 3 + l] = 0;
  380. }
  381. }
  382. }
  383. this.m_mesh.SetTriangles(array, i);
  384. }
  385. this.m_bDut = false;
  386. }
  387. public void LoadMoprhData2(BinaryReader r)
  388. {
  389. string text = r.ReadString();
  390. int count = this.BlendDatas.Count;
  391. this.hash[text] = count;
  392. BlendData blendData = new BlendData();
  393. blendData.name = text;
  394. int num = r.ReadInt32();
  395. blendData.vert = new Vector3[num];
  396. blendData.norm = new Vector3[num];
  397. blendData.v_index = new int[num];
  398. for (int i = 0; i < num; i++)
  399. {
  400. blendData.v_index[i] = (int)r.ReadUInt16();
  401. blendData.vert[i].x = r.ReadSingle();
  402. blendData.vert[i].y = r.ReadSingle();
  403. blendData.vert[i].z = r.ReadSingle();
  404. blendData.norm[i].x = r.ReadSingle();
  405. blendData.norm[i].y = r.ReadSingle();
  406. blendData.norm[i].z = r.ReadSingle();
  407. }
  408. this.MorphCount++;
  409. this.BlendDatas.Add(blendData);
  410. this.BlendValues = new float[this.MorphCount + 1];
  411. this.BlendValuesTemp = new float[this.MorphCount + 1];
  412. this.BlendValuesBackup = new float[this.MorphCount + 1];
  413. this.BlendValuesCHK = new float[this.MorphCount + 1];
  414. }
  415. public void NewBlendSet(string BlendSetName)
  416. {
  417. float[] array = new float[this.hash.Count];
  418. for (int i = 0; i < array.Length; i++)
  419. {
  420. array[i] = 0f;
  421. }
  422. if (this.dicBlendSet.ContainsKey(BlendSetName))
  423. {
  424. Debug.LogError("\u0093ブレンドセット" + BlendSetName);
  425. }
  426. this.dicBlendSet[BlendSetName] = array;
  427. this.dicBlendAtr[BlendSetName] = 0;
  428. if (!this.dicBlendSet.ContainsKey("オリジナル"))
  429. {
  430. float[] array2 = new float[this.hash.Count];
  431. for (int j = 0; j < array2.Length; j++)
  432. {
  433. array2[j] = 0f;
  434. }
  435. this.dicBlendSet["オリジナル"] = array2;
  436. }
  437. }
  438. public void SetValueOriginalBlendSet(TMorph.AddBlendType add_blend_type_flag)
  439. {
  440. float[] array = this.dicBlendSet["オリジナル"];
  441. array[(int)this.hash["hohol"]] = (array[(int)this.hash["hoho"]] = (array[(int)this.hash["hohos"]] = 0f));
  442. if ((add_blend_type_flag & TMorph.AddBlendType.Cheek3) == TMorph.AddBlendType.Cheek3)
  443. {
  444. array[(int)this.hash["hohol"]] = 1f;
  445. }
  446. else if ((add_blend_type_flag & TMorph.AddBlendType.Cheek2) == TMorph.AddBlendType.Cheek2)
  447. {
  448. array[(int)this.hash["hoho"]] = 1f;
  449. }
  450. else if ((add_blend_type_flag & TMorph.AddBlendType.Cheek1) == TMorph.AddBlendType.Cheek1)
  451. {
  452. array[(int)this.hash["hohos"]] = 1f;
  453. }
  454. array[(int)this.hash["tear3"]] = (array[(int)this.hash["tear2"]] = (array[(int)this.hash["tear1"]] = 0f));
  455. if ((add_blend_type_flag & TMorph.AddBlendType.Tear3) == TMorph.AddBlendType.Tear3)
  456. {
  457. array[(int)this.hash["tear3"]] = 1f;
  458. }
  459. else if ((add_blend_type_flag & TMorph.AddBlendType.Tear2) == TMorph.AddBlendType.Tear2)
  460. {
  461. array[(int)this.hash["tear2"]] = 1f;
  462. }
  463. else if ((add_blend_type_flag & TMorph.AddBlendType.Tear1) == TMorph.AddBlendType.Tear1)
  464. {
  465. array[(int)this.hash["tear1"]] = 1f;
  466. }
  467. array[(int)this.hash["hoho2"]] = (float)(((add_blend_type_flag & TMorph.AddBlendType.Blush) != TMorph.AddBlendType.Blush) ? 0 : 1);
  468. array[(int)this.hash["namida"]] = (float)(((add_blend_type_flag & TMorph.AddBlendType.TearBig) != TMorph.AddBlendType.TearBig) ? 0 : 1);
  469. array[(int)this.hash["yodare"]] = (float)(((add_blend_type_flag & TMorph.AddBlendType.Yodare) != TMorph.AddBlendType.Yodare) ? 0 : 1);
  470. array[(int)this.hash["shock"]] = (float)(((add_blend_type_flag & TMorph.AddBlendType.Shock) != TMorph.AddBlendType.Shock) ? 0 : 1);
  471. }
  472. public void SetValueBlendSet(string BlendSetName, string tag, float val)
  473. {
  474. if (tag == "hoho2")
  475. {
  476. Dictionary<string, int> dictionary = this.dicBlendAtr;
  477. int value = (this.dicBlendAtr[BlendSetName] & -4) | 2;
  478. this.dicBlendAtr[BlendSetName] = value;
  479. dictionary[BlendSetName] = value;
  480. }
  481. if (tag == "hoho" && (this.dicBlendAtr[BlendSetName] & 3) != 1)
  482. {
  483. this.dicBlendAtr[BlendSetName] = ((this.dicBlendAtr[BlendSetName] & -4) | 1);
  484. }
  485. if (!this.dicBlendSet.ContainsKey(BlendSetName))
  486. {
  487. Debug.LogError("表情がありません。" + BlendSetName);
  488. return;
  489. }
  490. if (!this.hash.Contains(tag))
  491. {
  492. Debug.LogError("表情がありません。tag=" + tag);
  493. return;
  494. }
  495. int num = (int)this.hash[tag];
  496. if (tag == "hoho2")
  497. {
  498. this.IdxHOHO2 = num;
  499. }
  500. if (tag == "hoho")
  501. {
  502. this.IdxHOHO = num;
  503. }
  504. this.dicBlendSet[BlendSetName][num] = val * 0.01f;
  505. }
  506. public void ClearBlendValues()
  507. {
  508. for (int i = 0; i < this.MorphCount; i++)
  509. {
  510. this.BlendValuesBackup[i] = (this.BlendValues[i] = 0f);
  511. }
  512. }
  513. public void MulBlendValues(string BlendSetName, float mul = 1f)
  514. {
  515. if (this.dicBlendSet.ContainsKey(BlendSetName))
  516. {
  517. float[] array = this.dicBlendSet[BlendSetName];
  518. for (int i = 0; i < this.MorphCount; i++)
  519. {
  520. this.BlendValuesBackup[i] = (this.BlendValues[i] = this.BlendValues[i] * (1f - mul) + array[i] * mul);
  521. }
  522. return;
  523. }
  524. if (BlendSetName == "頬0涙0")
  525. {
  526. return;
  527. }
  528. Debug.LogError("表情がありません。" + BlendSetName);
  529. }
  530. public void AddBlendValues(string BlendSetName, float add = 1f)
  531. {
  532. if (this.dicBlendSet.ContainsKey(BlendSetName))
  533. {
  534. float[] array = this.dicBlendSet[BlendSetName];
  535. for (int i = 0; i < this.MorphCount; i++)
  536. {
  537. this.BlendValues[i] += array[i] * add;
  538. if (this.BlendValues[i] > 1f)
  539. {
  540. this.BlendValues[i] = 1f;
  541. }
  542. this.BlendValuesBackup[i] = this.BlendValues[i];
  543. }
  544. return;
  545. }
  546. if (BlendSetName == "頬0涙0")
  547. {
  548. return;
  549. }
  550. Debug.LogError("表情がありません。" + BlendSetName);
  551. }
  552. public void FixBlendValues_Face()
  553. {
  554. this.BlendValuesTemp[this.BlendDataIdx_EyeClose[0]] = this.m_fEyeCloseRate + this.BlendValuesBackup[this.BlendDataIdx_EyeClose[0]] * (1f - this.m_fEyeCloseRate);
  555. for (int i = 1; i < 10; i++)
  556. {
  557. if (this.BlendDataIdx_EyeClose[i] != 0)
  558. {
  559. this.BlendValuesTemp[this.BlendDataIdx_EyeClose[i]] = this.BlendValuesBackup[this.BlendDataIdx_EyeClose[i]] * (1f - this.m_fEyeCloseRate);
  560. }
  561. }
  562. if (0f < this.EyeMabataki)
  563. {
  564. float num = 0f;
  565. for (int j = 0; j < 10; j++)
  566. {
  567. if (this.BlendDataIdx_EyeClose[j] != 0)
  568. {
  569. num += this.BlendValuesTemp[this.BlendDataIdx_EyeClose[j]];
  570. }
  571. }
  572. if (num > 1f)
  573. {
  574. num = 1f;
  575. }
  576. float num2 = 1f - num;
  577. float num3 = this.BlendValuesTemp[this.BlendDataIdx_EyeClose[0]] + num2 * this.EyeMabataki;
  578. if (num3 > 0f)
  579. {
  580. this.BlendValuesTemp[this.BlendDataIdx_EyeClose[0]] = num3;
  581. }
  582. }
  583. for (int k = 0; k < 10; k++)
  584. {
  585. if (this.BlendDataIdx_EyeClose[k] != 0)
  586. {
  587. this.BlendValues[this.BlendDataIdx_EyeClose[k]] = this.BlendValuesTemp[this.BlendDataIdx_EyeClose[k]];
  588. }
  589. }
  590. if (this.m_BlendDataIdx_FaceShape != -1)
  591. {
  592. this.BlendValues[this.m_BlendDataIdx_FaceShape] = this.m_fFaceShapeRate;
  593. }
  594. if (this.boLipSync)
  595. {
  596. this.BlendValues[this.BlendDataIdx_LipSync_A] = this.LipSync1 * 0.8f;
  597. this.BlendValues[this.BlendDataIdx_LipSync_C] = this.LipSync3 * 0.7f;
  598. this.BlendValues[this.BlendDataIdx_LipSync_ToothOFF] = this.LipSync3;
  599. this.BlendValues[this.BlendDataIdx_LipSync_S] = this.LipSync2 * (1f - this.LipSync1) * 0.5f;
  600. this.BlendValues[this.BlendDataIdx_LipSync_W] = this.LipSync2 * 0.3f;
  601. this.BlendValues[this.BlendDataIdx_LipSyncTh] = 0.5f;
  602. }
  603. if (this.boLookTooth)
  604. {
  605. this.BlendValues[this.BlendDataIdx_LipSync_A] = 0f;
  606. this.BlendValues[this.BlendDataIdx_LipSync_S] = 0.7f;
  607. this.BlendValues[this.BlendDataIdx_LipSync_C] = 0f;
  608. this.BlendValues[this.BlendDataIdx_LipSyncTh] = 0f;
  609. }
  610. if (this.boBallGAG)
  611. {
  612. this.BlendValues[this.BlendDataIdx_LipSync_A] = 1f;
  613. this.BlendValues[this.BlendDataIdx_LipSync_S] = 0f;
  614. this.BlendValues[this.BlendDataIdx_LipSync_C] = 0f;
  615. this.BlendValues[this.BlendDataIdx_LipSyncTh] = 0f;
  616. }
  617. float num4 = this.BlendValues[this.BlendDataIdx_Tear3];
  618. if (this.BlendValues[this.BlendDataIdx_Tear2] + num4 > 1f)
  619. {
  620. this.BlendValues[this.BlendDataIdx_Tear2] = 1f - num4;
  621. num4 = 1f;
  622. }
  623. else
  624. {
  625. num4 += this.BlendValues[this.BlendDataIdx_Tear2];
  626. }
  627. if (this.BlendValues[this.BlendDataIdx_Tear1] + num4 > 1f)
  628. {
  629. this.BlendValues[this.BlendDataIdx_Tear1] = 1f - num4;
  630. }
  631. if (this.boNoseFook)
  632. {
  633. this.BlendValues[this.BlendDataIdx_NoseFook] = 1f;
  634. }
  635. else
  636. {
  637. this.BlendValues[this.BlendDataIdx_NoseFook] = 0f;
  638. }
  639. int num5 = 0;
  640. for (int l = 0; l < this.MorphCount; l++)
  641. {
  642. if (this.BlendValuesCHK[l] != this.BlendValues[l])
  643. {
  644. num5++;
  645. this.BlendValuesCHK[l] = this.BlendValues[l];
  646. }
  647. }
  648. if (num5 == 0)
  649. {
  650. return;
  651. }
  652. this.m_vOriVert.CopyTo(this.m_vTmpVert, 0);
  653. this.m_bMorph = true;
  654. if (this.BlendValues[this.IdxHOHO] < 0.5f)
  655. {
  656. this.BlendValues[this.IdxHOHO] = 0f;
  657. }
  658. else
  659. {
  660. this.BlendValues[this.IdxHOHO] = 1f;
  661. }
  662. if (this.BlendValues[this.IdxHOHO2] < 0.5f)
  663. {
  664. this.BlendValues[this.IdxHOHO2] = 0f;
  665. }
  666. else
  667. {
  668. this.BlendValues[this.IdxHOHO2] = 1f;
  669. }
  670. for (int m = 0; m < this.MorphCount; m++)
  671. {
  672. if (this.BlendDatas[m] == null)
  673. {
  674. this.UruUruScaleX = this.BlendValues[m];
  675. }
  676. else
  677. {
  678. float num6 = this.BlendValues[m];
  679. if (num6 >= 0.01f)
  680. {
  681. int num7 = this.BlendDatas[m].v_index.Length;
  682. for (int n = 0; n < num7; n++)
  683. {
  684. int num8 = this.BlendDatas[m].v_index[n];
  685. this.m_vTmpVert[num8] += this.BlendDatas[m].vert[n] * num6;
  686. }
  687. }
  688. }
  689. }
  690. this.m_mesh.vertices = this.m_vTmpVert;
  691. foreach (TAttachPoint tattachPoint in this.dicAttachPoint.Values)
  692. {
  693. int vidx = tattachPoint.vidx;
  694. Vector3 vector = Vector3.zero;
  695. vector += this.m_bindposes[tattachPoint.bw.boneIndex0].MultiplyPoint3x4(this.m_vTmpVert[vidx]) * tattachPoint.bw.weight0;
  696. vector += this.m_bindposes[tattachPoint.bw.boneIndex1].MultiplyPoint3x4(this.m_vTmpVert[vidx]) * tattachPoint.bw.weight1;
  697. vector += this.m_bindposes[tattachPoint.bw.boneIndex2].MultiplyPoint3x4(this.m_vTmpVert[vidx]) * tattachPoint.bw.weight2;
  698. vector += this.m_bindposes[tattachPoint.bw.boneIndex3].MultiplyPoint3x4(this.m_vTmpVert[vidx]) * tattachPoint.bw.weight3;
  699. this.BindVert[vidx] = vector;
  700. }
  701. }
  702. public void FixFixBlendValues()
  703. {
  704. IEnumerator enumerator = this.hash.Keys.GetEnumerator();
  705. try
  706. {
  707. while (enumerator.MoveNext())
  708. {
  709. object obj = enumerator.Current;
  710. string text = (string)obj;
  711. int num = (int)this.hash[text];
  712. MaidProp propLower = this.bodyskin.body.maid.GetPropLower(text);
  713. if (propLower != null)
  714. {
  715. this.BlendValues[num] = (float)propLower.value / 100f;
  716. this.FixBlendValues();
  717. }
  718. }
  719. }
  720. finally
  721. {
  722. IDisposable disposable;
  723. if ((disposable = (enumerator as IDisposable)) != null)
  724. {
  725. disposable.Dispose();
  726. }
  727. }
  728. }
  729. public void FixBlendValues()
  730. {
  731. int num = 0;
  732. for (int i = 0; i < this.MorphCount; i++)
  733. {
  734. if (this.BlendValuesCHK[i] != this.BlendValues[i])
  735. {
  736. num++;
  737. this.BlendValuesCHK[i] = this.BlendValues[i];
  738. }
  739. }
  740. if (num == 0)
  741. {
  742. return;
  743. }
  744. this.m_vOriVert.CopyTo(this.m_vTmpVert, 0);
  745. this.m_vOriNorm.CopyTo(this.m_vTmpNorm, 0);
  746. this.m_bMorph = true;
  747. for (int j = 0; j < this.MorphCount; j++)
  748. {
  749. if (this.BlendDatas[j] == null)
  750. {
  751. this.UruUruScaleX = this.BlendValues[j];
  752. }
  753. else
  754. {
  755. float num2 = this.BlendValues[j];
  756. if (num2 >= 0.01f)
  757. {
  758. int num3 = this.BlendDatas[j].v_index.Length;
  759. for (int k = 0; k < num3; k++)
  760. {
  761. int num4 = this.BlendDatas[j].v_index[k];
  762. this.m_vTmpVert[num4] += this.BlendDatas[j].vert[k] * num2;
  763. this.m_vTmpNorm[num4] += this.BlendDatas[j].norm[k] * num2;
  764. }
  765. }
  766. }
  767. }
  768. this.m_mesh.vertices = this.m_vTmpVert;
  769. this.m_mesh.normals = this.m_vTmpNorm;
  770. foreach (TAttachPoint tattachPoint in this.dicAttachPoint.Values)
  771. {
  772. int vidx = tattachPoint.vidx;
  773. this.BindVert[vidx] = this.m_bindposes[tattachPoint.bw.boneIndex0].MultiplyPoint3x4(this.m_vTmpVert[vidx]);
  774. }
  775. }
  776. public void ResetBlendValues()
  777. {
  778. if (this.m_bMorph)
  779. {
  780. this.m_mesh.vertices = this.m_vTmpVert;
  781. this.m_mesh.normals = this.m_vTmpNorm;
  782. }
  783. }
  784. public void SetEnableAttachPointEdit(bool f_bEnable, string f_strApName)
  785. {
  786. TAttachPoint tattachPoint = this.dicAttachPoint[f_strApName];
  787. if (tattachPoint.bEditable == f_bEnable)
  788. {
  789. return;
  790. }
  791. int num = tattachPoint.srcvidx;
  792. Vector3 vector = Vector3.zero;
  793. Vector3 vector2 = Vector3.one;
  794. Quaternion quaternion = tattachPoint.qSrc;
  795. VtxAttachPos attachPointPos = this.bodyskin.body.maid.GetAttachPointPos(this.bodyskin.m_ParentMPN, this.bodyskin.SlotId, this.m_vOriVert.Length, f_strApName);
  796. if (attachPointPos != null)
  797. {
  798. num = attachPointPos.vidx;
  799. vector = attachPointPos.prs.position;
  800. quaternion = attachPointPos.prs.rotation;
  801. vector2 = attachPointPos.prs.scale;
  802. }
  803. if (f_bEnable)
  804. {
  805. tattachPoint.vidx = num;
  806. tattachPoint.vOffsLocal = vector;
  807. tattachPoint.qNow = quaternion;
  808. tattachPoint.vScaleRate = vector2;
  809. tattachPoint.bw = this.m_bws[tattachPoint.vidx];
  810. }
  811. else
  812. {
  813. tattachPoint.vidx = tattachPoint.srcvidx;
  814. tattachPoint.vOffsLocal = Vector3.zero;
  815. tattachPoint.qNow = tattachPoint.qSrc;
  816. tattachPoint.vScaleRate = Vector3.one;
  817. tattachPoint.bw = this.m_bws[tattachPoint.vidx];
  818. }
  819. tattachPoint.bEditable = f_bEnable;
  820. this.bodyskin.body.maid.SetAttachPointPos(this.bodyskin.m_ParentMPN, this.bodyskin.SlotId, this.m_vOriVert.Length, f_strApName, num, vector, quaternion, vector2, tattachPoint.bEditable);
  821. }
  822. public bool GetEnableAttachPointEdit(string f_strApName)
  823. {
  824. return this.dicAttachPoint[f_strApName].bEditable;
  825. }
  826. public void SetAttachPoint(string apname, Vector3 vc, Quaternion q, bool f_bTemp)
  827. {
  828. TAttachPoint tattachPoint = new TAttachPoint();
  829. float num = (vc - this.DefVert[0]).sqrMagnitude;
  830. int num2 = 0;
  831. for (int i = 0; i < this.m_vOriVert.Length; i++)
  832. {
  833. float sqrMagnitude = (vc - this.DefVert[i]).sqrMagnitude;
  834. if (num > sqrMagnitude)
  835. {
  836. num = sqrMagnitude;
  837. num2 = i;
  838. }
  839. }
  840. tattachPoint.srcvidx = (tattachPoint.vidx = num2);
  841. tattachPoint.vOffsLocal = Vector3.zero;
  842. TAttachPoint tattachPoint2 = tattachPoint;
  843. tattachPoint.qNow = q;
  844. tattachPoint2.qSrc = q;
  845. tattachPoint.vScaleRate = Vector3.one;
  846. tattachPoint.bw = this.m_bws[num2];
  847. this.dicAttachPoint[apname] = tattachPoint;
  848. if (!f_bTemp)
  849. {
  850. VtxAttachPos attachPointPos = this.bodyskin.body.maid.GetAttachPointPos(this.bodyskin.m_ParentMPN, this.bodyskin.SlotId, this.m_vOriVert.Length, apname);
  851. if (attachPointPos != null && attachPointPos.bEnable)
  852. {
  853. tattachPoint.vidx = attachPointPos.vidx;
  854. tattachPoint.vOffsLocal = attachPointPos.prs.position;
  855. tattachPoint.qNow = attachPointPos.prs.rotation;
  856. tattachPoint.vScaleRate = attachPointPos.prs.scale;
  857. tattachPoint.bEditable = true;
  858. tattachPoint.bw = this.m_bws[tattachPoint.vidx];
  859. }
  860. }
  861. }
  862. public void SetAttachPointOffsetLocal(string apname, VtxAttachPos f_vap)
  863. {
  864. TAttachPoint tattachPoint = this.dicAttachPoint[apname];
  865. tattachPoint.vidx = f_vap.vidx;
  866. tattachPoint.vOffsLocal = f_vap.prs.position;
  867. tattachPoint.qNow = f_vap.prs.rotation;
  868. tattachPoint.vScaleRate = f_vap.prs.scale;
  869. tattachPoint.bEditable = true;
  870. tattachPoint.bw = this.m_bws[tattachPoint.vidx];
  871. }
  872. public bool CopyAttachObjPoint(string apname)
  873. {
  874. TAttachPoint tattachPoint = this.dicAttachPoint[apname];
  875. TMorph.TempAttachPos tempAttachPos = new TMorph.TempAttachPos();
  876. tempAttachPos.m_nVidx = tattachPoint.vidx;
  877. tempAttachPos.m_vPos = tattachPoint.vOffsLocal;
  878. tempAttachPos.m_qRot = tattachPoint.qNow;
  879. tempAttachPos.m_vScale = tattachPoint.vScaleRate;
  880. this.bodyskin.m_dicTempAttachPoint[apname] = tempAttachPos;
  881. return true;
  882. }
  883. public bool PastAttachObjPoint(string apname)
  884. {
  885. TAttachPoint tattachPoint = this.dicAttachPoint[apname];
  886. TMorph.TempAttachPos tempAttachPos = null;
  887. if (this.bodyskin.m_dicTempAttachPoint.TryGetValue(apname, out tempAttachPos))
  888. {
  889. tattachPoint.bEditable = true;
  890. tattachPoint.vidx = tempAttachPos.m_nVidx;
  891. tattachPoint.vOffsLocal = tempAttachPos.m_vPos;
  892. tattachPoint.qNow = tempAttachPos.m_qRot;
  893. tattachPoint.vScaleRate = tempAttachPos.m_vScale;
  894. tattachPoint.bw = this.m_bws[tattachPoint.vidx];
  895. }
  896. 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);
  897. return true;
  898. }
  899. public void SetAttachPointWorld(string apname, Vector3 vWorldPos, Quaternion qWorldRot, Vector3 vScaleRate)
  900. {
  901. TAttachPoint tattachPoint = this.dicAttachPoint[apname];
  902. if (!tattachPoint.bEditable)
  903. {
  904. return;
  905. }
  906. this.ReclucPointWorldAndScreen(null);
  907. int vidx = tattachPoint.vidx;
  908. float num = (this.WorldV[vidx] - vWorldPos).sqrMagnitude;
  909. int num2 = vidx;
  910. for (int i = 0; i < this.m_vOriVert.Length; i++)
  911. {
  912. float sqrMagnitude = (this.WorldV[i] - vWorldPos).sqrMagnitude;
  913. if (sqrMagnitude < num)
  914. {
  915. num = sqrMagnitude;
  916. num2 = i;
  917. }
  918. }
  919. tattachPoint.vidx = num2;
  920. tattachPoint.bw = this.m_bws[num2];
  921. int num3 = this.BindBone[num2];
  922. Transform transform = this.m_bones[num3].transform;
  923. Vector3 vector = Vector3.zero;
  924. if (this.SlotId == TBody.SlotID.body)
  925. {
  926. this.CalcVertexPoint(ref vector, num2, ref tattachPoint.bw);
  927. }
  928. else
  929. {
  930. vector = this.BindVert[num2];
  931. vector = transform.TransformPoint(vector);
  932. tattachPoint.vOffsLocal = transform.InverseTransformPoint(vWorldPos) - transform.InverseTransformPoint(vector);
  933. }
  934. tattachPoint.qNow = Quaternion.Inverse(transform.transform.rotation) * qWorldRot;
  935. tattachPoint.vScaleRate = vScaleRate;
  936. this.dicAttachPoint[apname] = tattachPoint;
  937. 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);
  938. Debug.DrawLine(vector, vWorldPos, Color.cyan);
  939. }
  940. public bool GetAttachPoint(string apname, out Vector3 vWorldPos, out Quaternion qWorldRot, out Vector3 vScaleRate, bool f_bTemp = false)
  941. {
  942. if (!this.dicAttachPoint.ContainsKey(apname))
  943. {
  944. vWorldPos = Vector3.zero;
  945. qWorldRot = Quaternion.identity;
  946. vScaleRate = Vector3.one;
  947. return false;
  948. }
  949. TAttachPoint tattachPoint = this.dicAttachPoint[apname];
  950. Vector3 vector = Vector3.zero;
  951. int num = tattachPoint.vidx;
  952. if (f_bTemp)
  953. {
  954. num = tattachPoint.srcvidx;
  955. }
  956. Transform transform = this.m_bones[this.BindBone[num]].transform;
  957. if (this.SlotId == TBody.SlotID.body)
  958. {
  959. this.CalcVertexPoint(ref vector, num, ref tattachPoint.bw);
  960. }
  961. else
  962. {
  963. if (!f_bTemp)
  964. {
  965. vector = tattachPoint.vOffsLocal;
  966. }
  967. vector += this.BindVert[num];
  968. vector = transform.TransformPoint(vector);
  969. }
  970. vWorldPos = vector;
  971. if (f_bTemp)
  972. {
  973. qWorldRot = transform.rotation * tattachPoint.qSrc;
  974. vScaleRate = Vector3.one;
  975. }
  976. else
  977. {
  978. qWorldRot = transform.rotation * tattachPoint.qNow;
  979. vScaleRate = tattachPoint.vScaleRate;
  980. }
  981. return true;
  982. }
  983. public bool ResetAttachPoint(string apname)
  984. {
  985. if (!this.dicAttachPoint.ContainsKey(apname))
  986. {
  987. Debug.LogError("アタッチポイント " + apname + " はありません。");
  988. return false;
  989. }
  990. TAttachPoint tattachPoint = this.dicAttachPoint[apname];
  991. tattachPoint.vidx = tattachPoint.srcvidx;
  992. tattachPoint.vOffsLocal = Vector3.zero;
  993. tattachPoint.qNow = tattachPoint.qSrc;
  994. tattachPoint.vScaleRate = Vector3.one;
  995. tattachPoint.bw = this.m_bws[tattachPoint.vidx];
  996. this.bodyskin.body.maid.ClearAttachPointPos(this.bodyskin.m_ParentMPN, this.bodyskin.SlotId, apname);
  997. return true;
  998. }
  999. public void ReclucPointWorldAndScreen(Camera cam = null)
  1000. {
  1001. bool flag = cam != null;
  1002. for (int i = 0; i < this.VCount; i++)
  1003. {
  1004. BoneWeight boneWeight = this.m_bws[i];
  1005. Vector3 zero = Vector3.zero;
  1006. this.CalcVertexPoint(ref zero, i, ref boneWeight);
  1007. this.WorldV[i] = zero;
  1008. if (flag)
  1009. {
  1010. this.ScrnV[i] = cam.WorldToScreenPoint(zero);
  1011. }
  1012. }
  1013. }
  1014. private void CalcVertexPoint(ref Vector3 vPosLocalToWorld, int nVtx, ref BoneWeight bw)
  1015. {
  1016. vPosLocalToWorld += this.m_bones[bw.boneIndex0].transform.TransformPoint(this.m_bindposes[bw.boneIndex0].MultiplyPoint(this.m_vTmpVert[nVtx])) * bw.weight0;
  1017. if (bw.weight1 != 0f)
  1018. {
  1019. vPosLocalToWorld += this.m_bones[bw.boneIndex1].TransformPoint(this.m_bindposes[bw.boneIndex1].MultiplyPoint(this.m_vTmpVert[nVtx])) * bw.weight1;
  1020. }
  1021. if (bw.weight2 != 0f)
  1022. {
  1023. vPosLocalToWorld += this.m_bones[bw.boneIndex2].TransformPoint(this.m_bindposes[bw.boneIndex2].MultiplyPoint(this.m_vTmpVert[nVtx])) * bw.weight2;
  1024. }
  1025. if (bw.weight3 != 0f)
  1026. {
  1027. vPosLocalToWorld += this.m_bones[bw.boneIndex3].TransformPoint(this.m_bindposes[bw.boneIndex3].MultiplyPoint(this.m_vTmpVert[nVtx])) * bw.weight3;
  1028. }
  1029. }
  1030. private Vector3 CalcVertexPointWorldToLocal(Vector3 vWorld, int nVtx, ref BoneWeight bw)
  1031. {
  1032. Vector3 vector = Vector3.zero;
  1033. vector += this.m_bones[bw.boneIndex0].transform.InverseTransformPoint(vWorld) * bw.weight0;
  1034. if (bw.weight1 != 0f)
  1035. {
  1036. vector += this.m_bones[bw.boneIndex1].InverseTransformPoint(vWorld) * bw.weight1;
  1037. }
  1038. if (bw.weight2 != 0f)
  1039. {
  1040. vector += this.m_bones[bw.boneIndex2].InverseTransformPoint(vWorld) * bw.weight2;
  1041. }
  1042. if (bw.weight3 != 0f)
  1043. {
  1044. vector += this.m_bones[bw.boneIndex3].InverseTransformPoint(vWorld) * bw.weight3;
  1045. }
  1046. return vector;
  1047. }
  1048. private Vector3 CalcVertexPointLocalToWorld(Vector3 vLocal, int nVtx, ref BoneWeight bw)
  1049. {
  1050. Vector3 vector = Vector3.zero;
  1051. vector += this.m_bones[bw.boneIndex0].transform.TransformPoint(vLocal) * bw.weight0;
  1052. if (bw.weight1 != 0f)
  1053. {
  1054. vector += this.m_bones[bw.boneIndex1].TransformPoint(vLocal) * bw.weight1;
  1055. }
  1056. if (bw.weight2 != 0f)
  1057. {
  1058. vector += this.m_bones[bw.boneIndex2].TransformPoint(vLocal) * bw.weight2;
  1059. }
  1060. if (bw.weight3 != 0f)
  1061. {
  1062. vector += this.m_bones[bw.boneIndex3].TransformPoint(vLocal) * bw.weight3;
  1063. }
  1064. return vector;
  1065. }
  1066. public int VHitChk(Camera cam, Vector3 msv, out Vector3 vHitWorld)
  1067. {
  1068. if (this.m_nOriTri == null || this.m_nOriTri.Length == 0)
  1069. {
  1070. this.m_nOriTri = this.m_mesh.triangles;
  1071. this.TriCount = this.m_nOriTri.Length;
  1072. }
  1073. int num = -1;
  1074. float num2 = float.PositiveInfinity;
  1075. for (int i = 0; i < this.TriCount; i += 3)
  1076. {
  1077. int num3 = this.m_nOriTri[i];
  1078. int num4 = this.m_nOriTri[i + 1];
  1079. int num5 = this.m_nOriTri[i + 2];
  1080. Vector3 vector = this.ScrnV[num3];
  1081. Vector3 vector2 = this.ScrnV[num4];
  1082. Vector3 vector3 = this.ScrnV[num5];
  1083. float z = vector.z;
  1084. vector.z = 0f;
  1085. float z2 = vector2.z;
  1086. vector2.z = 0f;
  1087. float z3 = vector3.z;
  1088. vector3.z = 0f;
  1089. if (Vector3.Cross(vector2 - vector, vector3 - vector2).z <= 0f)
  1090. {
  1091. 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)
  1092. {
  1093. if (z < num2)
  1094. {
  1095. num2 = z;
  1096. num = i;
  1097. }
  1098. }
  1099. }
  1100. }
  1101. if (num != -1)
  1102. {
  1103. Debug.DrawLine(this.WorldV[this.m_nOriTri[num]], this.WorldV[this.m_nOriTri[num + 1]], Color.cyan);
  1104. Debug.DrawLine(this.WorldV[this.m_nOriTri[num + 1]], this.WorldV[this.m_nOriTri[num + 2]], Color.cyan);
  1105. Debug.DrawLine(this.WorldV[this.m_nOriTri[num]], this.WorldV[this.m_nOriTri[num + 2]], Color.cyan);
  1106. }
  1107. vHitWorld = Vector3.zero;
  1108. if (num != -1)
  1109. {
  1110. float d = 0f;
  1111. Plane plane = new Plane(this.WorldV[this.m_nOriTri[num]], this.WorldV[this.m_nOriTri[num + 1]], this.WorldV[this.m_nOriTri[num + 2]]);
  1112. Ray ray = cam.ScreenPointToRay(msv);
  1113. if (plane.Raycast(ray, out d))
  1114. {
  1115. vHitWorld = ray.origin + ray.direction * d;
  1116. }
  1117. else
  1118. {
  1119. Debug.LogWarning("当たって居ない");
  1120. }
  1121. }
  1122. return num;
  1123. }
  1124. public void Test(Vector3 vc)
  1125. {
  1126. float num = (vc - this.DefVert[0]).sqrMagnitude;
  1127. int num2 = 0;
  1128. for (int i = 0; i < this.m_vOriVert.Length; i++)
  1129. {
  1130. float sqrMagnitude = (vc - this.DefVert[i]).sqrMagnitude;
  1131. if (num > sqrMagnitude)
  1132. {
  1133. num = sqrMagnitude;
  1134. num2 = i;
  1135. }
  1136. }
  1137. this.attach_FaceHana = num2;
  1138. }
  1139. public float ChkHit(Camera cam)
  1140. {
  1141. Ray ray = cam.ScreenPointToRay(Input.mousePosition);
  1142. float num = 0f;
  1143. float num2 = 0f;
  1144. int num3 = -1;
  1145. float num4 = 0f;
  1146. for (int i = 0; i < this.TriCount / 3; i++)
  1147. {
  1148. float num5 = this.TriangleIntersect(ray, i);
  1149. if (num5 > 0f && (num4 > num5 || num4 == 0f))
  1150. {
  1151. num3 = i;
  1152. num4 = num5;
  1153. this.vHitPos = ray.origin + ray.direction * num5;
  1154. num = this.HitUV.x;
  1155. num2 = this.HitUV.y;
  1156. }
  1157. }
  1158. this.HitAtr = 0;
  1159. if (num3 >= 0)
  1160. {
  1161. Vector2[] uv = this.m_mesh.uv;
  1162. float d = 1f - num - num2;
  1163. Vector2 vector = uv[this.m_nOriTri[num3 * 3]] * d;
  1164. vector += uv[this.m_nOriTri[num3 * 3 + 1]] * num;
  1165. vector += uv[this.m_nOriTri[num3 * 3 + 2]] * num2;
  1166. this.HitTextureUV = vector;
  1167. 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]]);
  1168. }
  1169. return num4;
  1170. }
  1171. private float TriangleIntersect(Ray ray, int triidx)
  1172. {
  1173. Vector3 origin = ray.origin;
  1174. Vector3 normalized = ray.direction.normalized;
  1175. Vector3 b = this.WorldV[this.m_nOriTri[triidx * 3]];
  1176. Vector3 a = this.WorldV[this.m_nOriTri[triidx * 3 + 1]];
  1177. Vector3 a2 = this.WorldV[this.m_nOriTri[triidx * 3 + 2]];
  1178. Vector3 lhs = a - b;
  1179. Vector3 lhs2 = a2 - b;
  1180. Vector3 rhs = Vector3.Cross(lhs2, normalized);
  1181. float num = Vector3.Dot(lhs, rhs);
  1182. if (num >= -1E-08f)
  1183. {
  1184. return 0f;
  1185. }
  1186. Vector3 vector = origin - b;
  1187. float num2 = Vector3.Dot(vector, rhs);
  1188. if ((double)num2 > 0.0 || num2 < num)
  1189. {
  1190. return 0f;
  1191. }
  1192. Vector3 rhs2 = Vector3.Cross(lhs, vector);
  1193. float num3 = Vector3.Dot(normalized, rhs2);
  1194. if ((double)num3 > 0.0 || num2 + num3 < num)
  1195. {
  1196. return 0f;
  1197. }
  1198. float num4 = 1f / num;
  1199. float num5 = Vector3.Dot(lhs2, rhs2);
  1200. num5 *= num4;
  1201. num2 *= num4;
  1202. num3 *= num4;
  1203. this.HitUV.x = num2;
  1204. this.HitUV.y = num3;
  1205. return num5;
  1206. }
  1207. public void OnApplicationQuit()
  1208. {
  1209. Debug.LogError("TMorph OnApplicationQuit");
  1210. this.m_mesh.vertices = this.m_vOriVert;
  1211. this.m_mesh.normals = this.m_vOriNorm;
  1212. }
  1213. public int MorphCount;
  1214. public Hashtable hash;
  1215. public Dictionary<string, float[]> dicBlendSet = new Dictionary<string, float[]>();
  1216. public Dictionary<string, int> dicBlendAtr = new Dictionary<string, int>();
  1217. public int IdxHOHO = -1;
  1218. public int IdxHOHO2 = -1;
  1219. public Dictionary<string, TAttachPoint> dicAttachPoint = new Dictionary<string, TAttachPoint>();
  1220. public int VCount;
  1221. private int TriCount;
  1222. private int BoneCount;
  1223. private int m_nSubMeshCount;
  1224. public Vector3[] BindVert;
  1225. public Vector3[] ScrnV;
  1226. public Vector3[] WorldV;
  1227. public int[] BindBone;
  1228. public Vector3[] DefVert;
  1229. public Vector3[] m_vOriVert;
  1230. public Vector3[] m_vOriNorm;
  1231. public int[] m_nOriTri;
  1232. public int[][] m_nSubMeshOriTri;
  1233. private Vector3[] m_vTmpVert;
  1234. private Vector3[] m_vTmpNorm;
  1235. public int[][] m_nSubMeshTmpTri;
  1236. private int[] m_AtrVert;
  1237. public List<BlendData> BlendDatas;
  1238. public int[] BlendDataIdx_EyeClose;
  1239. public float m_fEyeCloseRate;
  1240. public float EyeMabataki;
  1241. public int m_BlendDataIdx_FaceShape = -1;
  1242. public float m_fFaceShapeRate;
  1243. public int BlendDataIdx_LipSyncTh;
  1244. public int BlendDataIdx_LipSync_A;
  1245. public int BlendDataIdx_LipSync_S;
  1246. public int BlendDataIdx_LipSync_C;
  1247. public int BlendDataIdx_LipSync_W;
  1248. public int BlendDataIdx_LipSync_ToothOFF;
  1249. public int BlendDataIdx_Tear1;
  1250. public int BlendDataIdx_Tear2;
  1251. public int BlendDataIdx_Tear3;
  1252. private float m_LipSync1;
  1253. private float m_LipSync2;
  1254. private float m_LipSync3;
  1255. public bool boLipSync;
  1256. public bool boLookTooth;
  1257. public bool boBallGAG;
  1258. public bool boNoseFook;
  1259. public int BlendDataIdx_NoseFook;
  1260. public int BlendDataIdx_RegFat;
  1261. public int BlendDataIdx_RegMeet;
  1262. private SkinnedMeshRenderer smr_src;
  1263. private Transform[] m_bones;
  1264. private Transform tRoot;
  1265. private Mesh m_mesh;
  1266. private BoneWeight[] m_bws;
  1267. private Matrix4x4[] m_bindposes;
  1268. private float[] BlendValues;
  1269. private float[] BlendValuesTemp;
  1270. private float[] BlendValuesBackup;
  1271. private float[] BlendValuesCHK;
  1272. public float UruUruScaleX;
  1273. public List<string> BoneNames;
  1274. public List<bool> BoneVisible;
  1275. public TBodySkin bodyskin;
  1276. public int attach_FaceHana;
  1277. private string Category;
  1278. private TBody.SlotID SlotId;
  1279. private bool m_bIsBody;
  1280. private bool m_bMorph;
  1281. private static string[] AtrVertChk = new string[]
  1282. {
  1283. "Mune",
  1284. "Hip"
  1285. };
  1286. private bool m_bDut;
  1287. public Vector3 vHitPos;
  1288. public Vector2 HitTextureUV;
  1289. public Vector2 HitUV;
  1290. public int HitAtr;
  1291. [Flags]
  1292. public enum AddBlendType
  1293. {
  1294. None = 0,
  1295. Cheek1 = 1,
  1296. Cheek2 = 2,
  1297. Cheek3 = 4,
  1298. Blush = 8,
  1299. Tear1 = 16,
  1300. Tear2 = 32,
  1301. Tear3 = 64,
  1302. TearBig = 128,
  1303. Yodare = 256,
  1304. Shock = 512
  1305. }
  1306. public class TempAttachPos
  1307. {
  1308. public int m_nVidx;
  1309. public Vector3 m_vPos;
  1310. public Vector3 m_vScale;
  1311. public Quaternion m_qRot;
  1312. }
  1313. }