TMorph.cs 39 KB

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