MeidoDragPointManager.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. namespace COM3D2.MeidoPhotoStudio.Plugin
  7. {
  8. internal enum AttachPoint
  9. {
  10. None, Head, Neck, UpperArmL, UpperArmR, ForearmL, ForearmR, MuneL, MuneR, HandL, HandR,
  11. Pelvis, ThighL, ThighR, CalfL, CalfR, FootL, FootR
  12. }
  13. internal class MeidoDragPointManager
  14. {
  15. private enum Bone
  16. {
  17. Head, HeadNub, ClavicleL, ClavicleR,
  18. UpperArmL, UpperArmR, ForearmL, ForearmR,
  19. HandL, HandR, /*IKHandL, IKHandR,*/
  20. MuneL, MuneSubL, MuneR, MuneSubR,
  21. Neck, Spine, Spine0a, Spine1, Spine1a, ThighL, ThighR,
  22. Pelvis, Hip,
  23. CalfL, CalfR, FootL, FootR,
  24. // Dragpoint specific
  25. Cube, Body, Torso,
  26. // Fingers
  27. Finger0L, Finger01L, Finger02L, Finger0NubL,
  28. Finger1L, Finger11L, Finger12L, Finger1NubL,
  29. Finger2L, Finger21L, Finger22L, Finger2NubL,
  30. Finger3L, Finger31L, Finger32L, Finger3NubL,
  31. Finger4L, Finger41L, Finger42L, Finger4NubL,
  32. Finger0R, Finger01R, Finger02R, Finger0NubR,
  33. Finger1R, Finger11R, Finger12R, Finger1NubR,
  34. Finger2R, Finger21R, Finger22R, Finger2NubR,
  35. Finger3R, Finger31R, Finger32R, Finger3NubR,
  36. Finger4R, Finger41R, Finger42R, Finger4NubR,
  37. // Toes
  38. Toe0L, Toe01L, Toe0NubL,
  39. Toe1L, Toe11L, Toe1NubL,
  40. Toe2L, Toe21L, Toe2NubL,
  41. Toe0R, Toe01R, Toe0NubR,
  42. Toe1R, Toe11R, Toe1NubR,
  43. Toe2R, Toe21R, Toe2NubR
  44. }
  45. private static readonly Dictionary<AttachPoint, Bone> PointToBone = new Dictionary<AttachPoint, Bone>()
  46. {
  47. [AttachPoint.Head] = Bone.Head,
  48. [AttachPoint.Neck] = Bone.HeadNub,
  49. [AttachPoint.UpperArmL] = Bone.UpperArmL,
  50. [AttachPoint.UpperArmR] = Bone.UpperArmR,
  51. [AttachPoint.ForearmL] = Bone.ForearmL,
  52. [AttachPoint.ForearmR] = Bone.ForearmR,
  53. [AttachPoint.MuneL] = Bone.MuneL,
  54. [AttachPoint.MuneR] = Bone.MuneR,
  55. [AttachPoint.HandL] = Bone.HandL,
  56. [AttachPoint.HandR] = Bone.HandR,
  57. [AttachPoint.Pelvis] = Bone.Pelvis,
  58. [AttachPoint.ThighL] = Bone.ThighL,
  59. [AttachPoint.ThighR] = Bone.ThighR,
  60. [AttachPoint.CalfL] = Bone.CalfL,
  61. [AttachPoint.CalfR] = Bone.CalfR,
  62. [AttachPoint.FootL] = Bone.FootL,
  63. [AttachPoint.FootR] = Bone.FootR,
  64. };
  65. private static bool cubeActive;
  66. public static bool CubeActive
  67. {
  68. get => cubeActive;
  69. set
  70. {
  71. if (value != cubeActive)
  72. {
  73. cubeActive = value;
  74. CubeActiveChange?.Invoke(null, EventArgs.Empty);
  75. }
  76. }
  77. }
  78. private static bool cubeSmall = false;
  79. public static bool CubeSmall
  80. {
  81. get => cubeSmall;
  82. set
  83. {
  84. if (value != cubeSmall)
  85. {
  86. cubeSmall = value;
  87. CubeSmallChange?.Invoke(null, EventArgs.Empty);
  88. }
  89. }
  90. }
  91. private static EventHandler CubeActiveChange;
  92. private static EventHandler CubeSmallChange;
  93. private bool initialized = false;
  94. private Meido meido;
  95. private Dictionary<Bone, Transform> BoneTransform = new Dictionary<Bone, Transform>();
  96. private Dictionary<Bone, DragPointMeido> DragPoints = new Dictionary<Bone, DragPointMeido>();
  97. private DragPointBody dragBody;
  98. private DragPointBody dragCube;
  99. public event EventHandler<MeidoUpdateEventArgs> SelectMaid;
  100. private bool isBone = false;
  101. public bool IsBone
  102. {
  103. get => isBone;
  104. set
  105. {
  106. if (isBone != value)
  107. {
  108. isBone = value;
  109. foreach (DragPointMeido dragPoint in DragPoints.Values)
  110. {
  111. dragPoint.IsBone = isBone;
  112. }
  113. }
  114. }
  115. }
  116. private bool active = true;
  117. public bool Active
  118. {
  119. get => active;
  120. set
  121. {
  122. if (active != value)
  123. {
  124. active = value;
  125. foreach (DragPointMeido dragPoint in DragPoints.Values)
  126. {
  127. dragPoint.gameObject.SetActive(active);
  128. }
  129. DragPointHead head = (DragPointHead)DragPoints[Bone.Head];
  130. head.gameObject.SetActive(true);
  131. head.IsIK = !active;
  132. }
  133. }
  134. }
  135. public MeidoDragPointManager(Meido meido) => this.meido = meido;
  136. public Transform GetAttachPointTransform(AttachPoint point)
  137. {
  138. if (point == AttachPoint.None) return null;
  139. return BoneTransform[PointToBone[point]];
  140. }
  141. public void Flip()
  142. {
  143. Bone[] single = new[] { Bone.Pelvis, Bone.Spine, Bone.Spine0a, Bone.Spine1, Bone.Spine1a, Bone.Neck };
  144. Bone[] pair = new[] {
  145. Bone.ClavicleL, Bone.ClavicleR, Bone.UpperArmL, Bone.UpperArmR, Bone.ForearmL, Bone.ForearmR,
  146. Bone.ForearmL, Bone.ForearmR, Bone.ThighL, Bone.ThighR, Bone.CalfL, Bone.CalfR,
  147. Bone.HandL, Bone.HandR, Bone.FootL, Bone.FootR
  148. };
  149. List<Vector3> singleRotations = single.Select(bone => BoneTransform[bone].eulerAngles).ToList();
  150. List<Vector3> pairRotations = pair.Select(bone => BoneTransform[bone].eulerAngles).ToList();
  151. Transform hip = BoneTransform[Bone.Hip];
  152. Vector3 vecHip = hip.eulerAngles;
  153. Transform hipL = meido.Maid.body0.GetBone("Hip_L");
  154. Vector3 vecHipL = hipL.eulerAngles;
  155. Transform hipR = meido.Maid.body0.GetBone("Hip_R");
  156. Vector3 vecHipR = hipR.eulerAngles;
  157. hip.rotation = Quaternion.Euler(
  158. 360f - (vecHip.x + 270f) - 270f, 360f - (vecHip.y + 90f) - 90f, 360f - vecHip.z
  159. );
  160. hipL.rotation = FlipRotation(vecHipR);
  161. hipR.rotation = FlipRotation(vecHipL);
  162. for (int i = 0; i < single.Length; i++)
  163. {
  164. Bone bone = single[i];
  165. BoneTransform[bone].rotation = FlipRotation(singleRotations[i]);
  166. }
  167. for (int i = 0; i < pair.Length; i += 2)
  168. {
  169. Bone boneA = pair[i];
  170. Bone boneB = pair[i + 1];
  171. BoneTransform[boneA].rotation = FlipRotation(pairRotations[i + 1]);
  172. BoneTransform[boneB].rotation = FlipRotation(pairRotations[i]);
  173. }
  174. byte[] leftHand = SerializeHand(right: false);
  175. byte[] rightHand = SerializeHand(right: true);
  176. DeserializeHand(leftHand, right: true, true);
  177. DeserializeHand(rightHand, right: false, true);
  178. leftHand = SerializeFoot(right: false);
  179. rightHand = SerializeFoot(right: true);
  180. DeserializeFoot(leftHand, right: true, true);
  181. DeserializeFoot(rightHand, right: false, true);
  182. }
  183. private Quaternion FlipRotation(Vector3 rotation)
  184. {
  185. return Quaternion.Euler(360f - rotation.x, 360f - (rotation.y + 90f) - 90f, rotation.z);
  186. }
  187. public byte[] SerializeHand(bool right)
  188. {
  189. Bone start = right ? Bone.Finger0R : Bone.Finger0L;
  190. Bone end = right ? Bone.Finger4R : Bone.Finger4L;
  191. return SerializeFinger(start, end, right);
  192. }
  193. public void DeserializeHand(byte[] handBinary, bool right, bool mirroring = false)
  194. {
  195. Bone start = right ? Bone.Finger0R : Bone.Finger0L;
  196. Bone end = right ? Bone.Finger4R : Bone.Finger4L;
  197. DeserializeFinger(start, end, handBinary, right, mirroring);
  198. }
  199. public byte[] SerializeFoot(bool right)
  200. {
  201. Bone start = right ? Bone.Toe0R : Bone.Toe0L;
  202. Bone end = right ? Bone.Toe2R : Bone.Toe2L;
  203. return SerializeFinger(start, end, right);
  204. }
  205. public void DeserializeFoot(byte[] footBinary, bool right, bool mirroring = false)
  206. {
  207. Bone start = right ? Bone.Toe0R : Bone.Toe0L;
  208. Bone end = right ? Bone.Toe2R : Bone.Toe2L;
  209. DeserializeFinger(start, end, footBinary, right, mirroring);
  210. }
  211. private byte[] SerializeFinger(Bone start, Bone end, bool right)
  212. {
  213. int joints = BoneTransform[start].name.Split(' ')[2].StartsWith("Finger") ? 4 : 3;
  214. byte[] buf;
  215. using (MemoryStream memoryStream = new MemoryStream())
  216. using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
  217. {
  218. for (Bone bone = start; bone <= end; bone += joints)
  219. {
  220. for (int i = 0; i < joints - 1; i++)
  221. {
  222. Quaternion localRotation = BoneTransform[bone + i].localRotation;
  223. binaryWriter.Write(localRotation.x);
  224. binaryWriter.Write(localRotation.y);
  225. binaryWriter.Write(localRotation.z);
  226. binaryWriter.Write(localRotation.w);
  227. }
  228. }
  229. buf = memoryStream.ToArray();
  230. }
  231. return buf;
  232. }
  233. private void DeserializeFinger(Bone start, Bone end, byte[] fingerBinary, bool right, bool mirroring = false)
  234. {
  235. int joints = BoneTransform[start].name.Split(' ')[2].StartsWith("Finger") ? 4 : 3;
  236. int mirror = mirroring ? -1 : 1;
  237. using (MemoryStream memoryStream = new MemoryStream(fingerBinary))
  238. using (BinaryReader binaryReader = new BinaryReader(memoryStream))
  239. {
  240. for (Bone bone = start; bone <= end; bone += joints)
  241. {
  242. for (int i = 0; i < joints - 1; i++)
  243. {
  244. Vector4 vec4;
  245. vec4.x = binaryReader.ReadSingle() * mirror;
  246. vec4.y = binaryReader.ReadSingle() * mirror;
  247. vec4.z = binaryReader.ReadSingle();
  248. vec4.w = binaryReader.ReadSingle();
  249. BoneTransform[bone + i].localRotation = new Quaternion(vec4.x, vec4.y, vec4.z, vec4.w);
  250. }
  251. }
  252. }
  253. }
  254. public void Destroy()
  255. {
  256. foreach (DragPointMeido dragPoint in DragPoints.Values)
  257. {
  258. if (dragPoint != null)
  259. {
  260. GameObject.Destroy(dragPoint.gameObject);
  261. }
  262. }
  263. if (dragCube != null) GameObject.Destroy(dragCube.gameObject);
  264. if (dragBody != null) GameObject.Destroy(dragBody.gameObject);
  265. BoneTransform.Clear();
  266. DragPoints.Clear();
  267. CubeActiveChange -= OnCubeActive;
  268. CubeSmallChange -= OnCubeSmall;
  269. initialized = false;
  270. }
  271. public void Initialize()
  272. {
  273. if (initialized) return;
  274. initialized = true;
  275. CubeActiveChange += OnCubeActive;
  276. CubeSmallChange += OnCubeSmall;
  277. InitializeBones();
  278. InitializeDragPoints();
  279. }
  280. private void InitializeDragPoints()
  281. {
  282. dragCube = DragPoint.Make<DragPointBody>(
  283. PrimitiveType.Cube, Vector3.one * 0.12f, DragPoint.Blue
  284. );
  285. dragCube.Initialize(() => meido.Maid.transform.position, () => Vector3.zero);
  286. dragCube.Set(meido.Maid.transform);
  287. dragCube.IsCube = true;
  288. dragCube.ConstantScale = true;
  289. dragCube.Select += OnSelectBody;
  290. dragCube.EndScale += OnSetDragPointScale;
  291. dragCube.gameObject.SetActive(CubeActive);
  292. dragBody = DragPoint.Make<DragPointBody>(
  293. PrimitiveType.Capsule, new Vector3(0.2f, 0.3f, 0.24f), DragPoint.LightBlue
  294. );
  295. dragBody.Initialize(
  296. () => new Vector3(
  297. (BoneTransform[Bone.Hip].position.x + BoneTransform[Bone.Spine0a].position.x) / 2f,
  298. (BoneTransform[Bone.Spine1].position.y + BoneTransform[Bone.Spine0a].position.y) / 2f,
  299. (BoneTransform[Bone.Spine0a].position.z + BoneTransform[Bone.Hip].position.z) / 2f
  300. ),
  301. () => new Vector3(
  302. BoneTransform[Bone.Spine0a].eulerAngles.x,
  303. BoneTransform[Bone.Spine0a].eulerAngles.y,
  304. BoneTransform[Bone.Spine0a].eulerAngles.z + 90f
  305. )
  306. );
  307. dragBody.Set(meido.Maid.transform);
  308. dragBody.Select += OnSelectBody;
  309. dragBody.EndScale += OnSetDragPointScale;
  310. // Head Dragpoint
  311. DragPointHead dragHead = DragPoint.Make<DragPointHead>(
  312. PrimitiveType.Sphere, new Vector3(0.2f, 0.24f, 0.2f), DragPoint.LightBlue
  313. );
  314. dragHead.Initialize(meido,
  315. () => new Vector3(
  316. BoneTransform[Bone.Head].position.x,
  317. (BoneTransform[Bone.Head].position.y * 1.2f + BoneTransform[Bone.HeadNub].position.y * 0.8f) / 2f,
  318. BoneTransform[Bone.Head].position.z
  319. ),
  320. () => new Vector3(
  321. BoneTransform[Bone.Head].eulerAngles.x,
  322. BoneTransform[Bone.Head].eulerAngles.y,
  323. BoneTransform[Bone.Head].eulerAngles.z + 90f
  324. )
  325. );
  326. dragHead.Set(BoneTransform[Bone.Neck]);
  327. dragHead.Select += OnSelectFace;
  328. DragPoints[Bone.Head] = dragHead;
  329. // Torso Dragpoint
  330. Transform spineTrans1 = BoneTransform[Bone.Spine1];
  331. Transform spineTrans2 = BoneTransform[Bone.Spine1a];
  332. DragPointTorso dragTorso = DragPoint.Make<DragPointTorso>(
  333. PrimitiveType.Capsule, new Vector3(0.2f, 0.19f, 0.24f), DragPoint.LightBlue
  334. );
  335. dragTorso.Initialize(meido,
  336. () => new Vector3(
  337. spineTrans1.position.x,
  338. spineTrans2.position.y,
  339. spineTrans1.position.z - 0.05f
  340. ),
  341. () => new Vector3(
  342. spineTrans1.eulerAngles.x,
  343. spineTrans1.eulerAngles.y,
  344. spineTrans1.eulerAngles.z + 90f
  345. )
  346. );
  347. dragTorso.Set(BoneTransform[Bone.Spine1a]);
  348. DragPoints[Bone.Torso] = dragTorso;
  349. // Pelvis Dragpoint
  350. Transform pelvisTrans = BoneTransform[Bone.Pelvis];
  351. Transform spineTrans = BoneTransform[Bone.Spine];
  352. DragPointPelvis dragPelvis = DragPoint.Make<DragPointPelvis>(
  353. PrimitiveType.Capsule, new Vector3(0.2f, 0.15f, 0.24f), DragPoint.LightBlue
  354. );
  355. dragPelvis.Initialize(meido,
  356. () => new Vector3(
  357. pelvisTrans.position.x,
  358. (pelvisTrans.position.y + spineTrans.position.y) / 2f,
  359. pelvisTrans.position.z
  360. ),
  361. () => new Vector3(
  362. pelvisTrans.eulerAngles.x + 90f,
  363. pelvisTrans.eulerAngles.y + 90f,
  364. pelvisTrans.eulerAngles.z
  365. )
  366. );
  367. dragPelvis.Set(BoneTransform[Bone.Pelvis]);
  368. DragPoints[Bone.Pelvis] = dragPelvis;
  369. InitializeMuneDragPoint(left: true);
  370. InitializeMuneDragPoint(left: false);
  371. DragPointChain[] armDragPointL = MakeIKChain(BoneTransform[Bone.HandL]);
  372. DragPoints[Bone.UpperArmL] = armDragPointL[0];
  373. DragPoints[Bone.ForearmL] = armDragPointL[1];
  374. DragPoints[Bone.HandL] = armDragPointL[2];
  375. DragPointChain[] armDragPointR = MakeIKChain(BoneTransform[Bone.HandR]);
  376. DragPoints[Bone.UpperArmR] = armDragPointR[0];
  377. DragPoints[Bone.ForearmR] = armDragPointR[1];
  378. DragPoints[Bone.HandR] = armDragPointR[2];
  379. DragPointChain[] legDragPointL = MakeIKChain(BoneTransform[Bone.FootL]);
  380. DragPoints[Bone.CalfL] = legDragPointL[0];
  381. DragPoints[Bone.FootL] = legDragPointL[1];
  382. DragPointChain[] legDragPointR = MakeIKChain(BoneTransform[Bone.FootR]);
  383. DragPoints[Bone.CalfR] = legDragPointR[0];
  384. DragPoints[Bone.FootR] = legDragPointR[1];
  385. InitializeSpineDragPoint(
  386. Bone.Neck, Bone.Spine, Bone.Spine0a, Bone.Spine1, Bone.Spine1a, Bone.Hip, Bone.ThighL, Bone.ThighR
  387. );
  388. InitializeFingerDragPoint(Bone.Finger0L, Bone.Finger4R);
  389. InitializeFingerDragPoint(Bone.Toe0L, Bone.Toe2R);
  390. }
  391. private void InitializeMuneDragPoint(bool left)
  392. {
  393. Bone mune = left ? Bone.MuneL : Bone.MuneR;
  394. Bone sub = left ? Bone.MuneSubL : Bone.MuneSubR;
  395. DragPointChain muneDragPoint = DragPoint.Make<DragPointChain>(
  396. PrimitiveType.Sphere, Vector3.one * 0.12f, DragPoint.LightBlue
  397. );
  398. muneDragPoint.Initialize(meido,
  399. () => (BoneTransform[mune].position + BoneTransform[sub].position) / 2f,
  400. () => Vector3.zero
  401. );
  402. muneDragPoint.Set(BoneTransform[sub]);
  403. DragPoints[mune] = muneDragPoint;
  404. }
  405. private DragPointChain[] MakeIKChain(Transform lower)
  406. {
  407. Vector3 limbDragPointSize = Vector3.one * 0.12f;
  408. // Ignore Thigh transform when making a leg IK chain
  409. bool isLeg = lower.name.EndsWith("Foot");
  410. DragPointChain[] dragPoints = new DragPointChain[isLeg ? 2 : 3];
  411. for (int i = dragPoints.Length - 1; i >= 0; i--)
  412. {
  413. Transform joint = lower;
  414. dragPoints[i] = DragPoint.Make<DragPointChain>(
  415. PrimitiveType.Sphere, limbDragPointSize, DragPoint.LightBlue
  416. );
  417. dragPoints[i].Initialize(meido, () => joint.position, () => Vector3.zero);
  418. dragPoints[i].Set(joint);
  419. dragPoints[i].AddGizmo();
  420. lower = lower.parent;
  421. }
  422. return dragPoints;
  423. }
  424. private void InitializeFingerDragPoint(Bone start, Bone end)
  425. {
  426. Vector3 fingerDragPointSize = Vector3.one * 0.015f;
  427. int joints = BoneTransform[start].name.Split(' ')[2].StartsWith("Finger") ? 4 : 3;
  428. for (Bone bone = start; bone <= end; bone += joints)
  429. {
  430. for (int i = 1; i < joints; i++)
  431. {
  432. Transform trans = BoneTransform[bone + i];
  433. DragPointFinger chain = DragPoint.Make<DragPointFinger>(
  434. PrimitiveType.Sphere, fingerDragPointSize, DragPoint.Blue
  435. );
  436. chain.Initialize(meido, () => trans.position, () => Vector3.zero);
  437. chain.Set(trans);
  438. DragPoints[bone + i] = chain;
  439. }
  440. }
  441. }
  442. private void InitializeSpineDragPoint(params Bone[] bones)
  443. {
  444. Vector3 spineDragPointSize = Vector3.one * 0.045f;
  445. foreach (Bone bone in bones)
  446. {
  447. Transform spine = BoneTransform[bone];
  448. PrimitiveType primitive = bone == Bone.Hip ? PrimitiveType.Cube : PrimitiveType.Sphere;
  449. DragPointSpine dragPoint = DragPoint.Make<DragPointSpine>(
  450. primitive, spineDragPointSize, DragPoint.LightBlue
  451. );
  452. dragPoint.Initialize(meido,
  453. () => spine.position,
  454. () => Vector3.zero
  455. );
  456. dragPoint.Set(spine);
  457. dragPoint.AddGizmo();
  458. DragPoints[bone] = dragPoint;
  459. }
  460. }
  461. private void OnCubeActive(object sender, EventArgs args)
  462. {
  463. dragCube.gameObject.SetActive(CubeActive);
  464. }
  465. private void OnCubeSmall(object sender, EventArgs args)
  466. {
  467. dragCube.DragPointScale = CubeSmall ? DragPointGeneral.smallCube : 1f;
  468. }
  469. private void OnSetDragPointScale(object sender, EventArgs args)
  470. {
  471. this.SetDragPointScale(meido.Maid.transform.localScale.x);
  472. }
  473. private void OnSelectBody(object sender, EventArgs args)
  474. {
  475. SelectMaid?.Invoke(this, new MeidoUpdateEventArgs(meido.Slot, fromMaid: true, isBody: true));
  476. }
  477. private void OnSelectFace(object sender, EventArgs args)
  478. {
  479. SelectMaid?.Invoke(this, new MeidoUpdateEventArgs(meido.Slot, fromMaid: true, isBody: false));
  480. }
  481. private void SetDragPointScale(float scale)
  482. {
  483. foreach (DragPointMeido dragPoint in DragPoints.Values)
  484. {
  485. dragPoint.DragPointScale = scale;
  486. }
  487. dragBody.DragPointScale = scale;
  488. }
  489. private void InitializeBones()
  490. {
  491. // TODO: Move to external file somehow
  492. Transform transform = meido.Body.m_Bones.transform;
  493. BoneTransform = new Dictionary<Bone, Transform>()
  494. {
  495. [Bone.Head] = CMT.SearchObjName(transform, "Bip01 Head"),
  496. [Bone.Neck] = CMT.SearchObjName(transform, "Bip01 Neck"),
  497. [Bone.HeadNub] = CMT.SearchObjName(transform, "Bip01 HeadNub"),
  498. /*[Bone.IKHandL] = CMT.SearchObjName(transform, "_IK_handL"),
  499. [Bone.IKHandR] = CMT.SearchObjName(transform, "_IK_handR"),*/
  500. [Bone.MuneL] = CMT.SearchObjName(transform, "Mune_L"),
  501. [Bone.MuneSubL] = CMT.SearchObjName(transform, "Mune_L_sub"),
  502. [Bone.MuneR] = CMT.SearchObjName(transform, "Mune_R"),
  503. [Bone.MuneSubR] = CMT.SearchObjName(transform, "Mune_R_sub"),
  504. [Bone.Pelvis] = CMT.SearchObjName(transform, "Bip01 Pelvis"),
  505. [Bone.Hip] = CMT.SearchObjName(transform, "Bip01"),
  506. [Bone.Spine] = CMT.SearchObjName(transform, "Bip01 Spine"),
  507. [Bone.Spine0a] = CMT.SearchObjName(transform, "Bip01 Spine0a"),
  508. [Bone.Spine1] = CMT.SearchObjName(transform, "Bip01 Spine1"),
  509. [Bone.Spine1a] = CMT.SearchObjName(transform, "Bip01 Spine1a"),
  510. [Bone.ClavicleL] = CMT.SearchObjName(transform, "Bip01 L Clavicle"),
  511. [Bone.ClavicleR] = CMT.SearchObjName(transform, "Bip01 R Clavicle"),
  512. [Bone.UpperArmL] = CMT.SearchObjName(transform, "Bip01 L UpperArm"),
  513. [Bone.ForearmL] = CMT.SearchObjName(transform, "Bip01 L Forearm"),
  514. [Bone.HandL] = CMT.SearchObjName(transform, "Bip01 L Hand"),
  515. [Bone.UpperArmR] = CMT.SearchObjName(transform, "Bip01 R UpperArm"),
  516. [Bone.ForearmR] = CMT.SearchObjName(transform, "Bip01 R Forearm"),
  517. [Bone.HandR] = CMT.SearchObjName(transform, "Bip01 R Hand"),
  518. [Bone.ThighL] = CMT.SearchObjName(transform, "Bip01 L Thigh"),
  519. [Bone.CalfL] = CMT.SearchObjName(transform, "Bip01 L Calf"),
  520. [Bone.FootL] = CMT.SearchObjName(transform, "Bip01 L Foot"),
  521. [Bone.ThighR] = CMT.SearchObjName(transform, "Bip01 R Thigh"),
  522. [Bone.CalfR] = CMT.SearchObjName(transform, "Bip01 R Calf"),
  523. [Bone.FootR] = CMT.SearchObjName(transform, "Bip01 R Foot"),
  524. // fingers
  525. [Bone.Finger0L] = CMT.SearchObjName(transform, "Bip01 L Finger0"),
  526. [Bone.Finger01L] = CMT.SearchObjName(transform, "Bip01 L Finger01"),
  527. [Bone.Finger02L] = CMT.SearchObjName(transform, "Bip01 L Finger02"),
  528. [Bone.Finger0NubL] = CMT.SearchObjName(transform, "Bip01 L Finger0Nub"),
  529. [Bone.Finger1L] = CMT.SearchObjName(transform, "Bip01 L Finger1"),
  530. [Bone.Finger11L] = CMT.SearchObjName(transform, "Bip01 L Finger11"),
  531. [Bone.Finger12L] = CMT.SearchObjName(transform, "Bip01 L Finger12"),
  532. [Bone.Finger1NubL] = CMT.SearchObjName(transform, "Bip01 L Finger1Nub"),
  533. [Bone.Finger2L] = CMT.SearchObjName(transform, "Bip01 L Finger2"),
  534. [Bone.Finger21L] = CMT.SearchObjName(transform, "Bip01 L Finger21"),
  535. [Bone.Finger22L] = CMT.SearchObjName(transform, "Bip01 L Finger22"),
  536. [Bone.Finger2NubL] = CMT.SearchObjName(transform, "Bip01 L Finger2Nub"),
  537. [Bone.Finger3L] = CMT.SearchObjName(transform, "Bip01 L Finger3"),
  538. [Bone.Finger31L] = CMT.SearchObjName(transform, "Bip01 L Finger31"),
  539. [Bone.Finger32L] = CMT.SearchObjName(transform, "Bip01 L Finger32"),
  540. [Bone.Finger3NubL] = CMT.SearchObjName(transform, "Bip01 L Finger3Nub"),
  541. [Bone.Finger4L] = CMT.SearchObjName(transform, "Bip01 L Finger4"),
  542. [Bone.Finger41L] = CMT.SearchObjName(transform, "Bip01 L Finger41"),
  543. [Bone.Finger42L] = CMT.SearchObjName(transform, "Bip01 L Finger42"),
  544. [Bone.Finger4NubL] = CMT.SearchObjName(transform, "Bip01 L Finger4Nub"),
  545. [Bone.Finger0R] = CMT.SearchObjName(transform, "Bip01 R Finger0"),
  546. [Bone.Finger01R] = CMT.SearchObjName(transform, "Bip01 R Finger01"),
  547. [Bone.Finger02R] = CMT.SearchObjName(transform, "Bip01 R Finger02"),
  548. [Bone.Finger0NubR] = CMT.SearchObjName(transform, "Bip01 R Finger0Nub"),
  549. [Bone.Finger1R] = CMT.SearchObjName(transform, "Bip01 R Finger1"),
  550. [Bone.Finger11R] = CMT.SearchObjName(transform, "Bip01 R Finger11"),
  551. [Bone.Finger12R] = CMT.SearchObjName(transform, "Bip01 R Finger12"),
  552. [Bone.Finger1NubR] = CMT.SearchObjName(transform, "Bip01 R Finger1Nub"),
  553. [Bone.Finger2R] = CMT.SearchObjName(transform, "Bip01 R Finger2"),
  554. [Bone.Finger21R] = CMT.SearchObjName(transform, "Bip01 R Finger21"),
  555. [Bone.Finger22R] = CMT.SearchObjName(transform, "Bip01 R Finger22"),
  556. [Bone.Finger2NubR] = CMT.SearchObjName(transform, "Bip01 R Finger2Nub"),
  557. [Bone.Finger3R] = CMT.SearchObjName(transform, "Bip01 R Finger3"),
  558. [Bone.Finger31R] = CMT.SearchObjName(transform, "Bip01 R Finger31"),
  559. [Bone.Finger32R] = CMT.SearchObjName(transform, "Bip01 R Finger32"),
  560. [Bone.Finger3NubR] = CMT.SearchObjName(transform, "Bip01 R Finger3Nub"),
  561. [Bone.Finger4R] = CMT.SearchObjName(transform, "Bip01 R Finger4"),
  562. [Bone.Finger41R] = CMT.SearchObjName(transform, "Bip01 R Finger41"),
  563. [Bone.Finger42R] = CMT.SearchObjName(transform, "Bip01 R Finger42"),
  564. [Bone.Finger4NubR] = CMT.SearchObjName(transform, "Bip01 R Finger4Nub"),
  565. // Toes
  566. [Bone.Toe0L] = CMT.SearchObjName(transform, "Bip01 L Toe0"),
  567. [Bone.Toe01L] = CMT.SearchObjName(transform, "Bip01 L Toe01"),
  568. [Bone.Toe0NubL] = CMT.SearchObjName(transform, "Bip01 L Toe0Nub"),
  569. [Bone.Toe1L] = CMT.SearchObjName(transform, "Bip01 L Toe1"),
  570. [Bone.Toe11L] = CMT.SearchObjName(transform, "Bip01 L Toe11"),
  571. [Bone.Toe1NubL] = CMT.SearchObjName(transform, "Bip01 L Toe1Nub"),
  572. [Bone.Toe2L] = CMT.SearchObjName(transform, "Bip01 L Toe2"),
  573. [Bone.Toe21L] = CMT.SearchObjName(transform, "Bip01 L Toe21"),
  574. [Bone.Toe2NubL] = CMT.SearchObjName(transform, "Bip01 L Toe2Nub"),
  575. [Bone.Toe0R] = CMT.SearchObjName(transform, "Bip01 R Toe0"),
  576. [Bone.Toe01R] = CMT.SearchObjName(transform, "Bip01 R Toe01"),
  577. [Bone.Toe0NubR] = CMT.SearchObjName(transform, "Bip01 R Toe0Nub"),
  578. [Bone.Toe1R] = CMT.SearchObjName(transform, "Bip01 R Toe1"),
  579. [Bone.Toe11R] = CMT.SearchObjName(transform, "Bip01 R Toe11"),
  580. [Bone.Toe1NubR] = CMT.SearchObjName(transform, "Bip01 R Toe1Nub"),
  581. [Bone.Toe2R] = CMT.SearchObjName(transform, "Bip01 R Toe2"),
  582. [Bone.Toe21R] = CMT.SearchObjName(transform, "Bip01 R Toe21"),
  583. [Bone.Toe2NubR] = CMT.SearchObjName(transform, "Bip01 R Toe2Nub")
  584. };
  585. }
  586. }
  587. internal struct AttachPointInfo
  588. {
  589. public AttachPoint AttachPoint { get; }
  590. public string MaidGuid { get; }
  591. public int MaidIndex { get; }
  592. public static AttachPointInfo Empty => new AttachPointInfo(AttachPoint.None, String.Empty, -1);
  593. public AttachPointInfo(AttachPoint attachPoint, string maidGuid, int maidIndex)
  594. {
  595. this.AttachPoint = attachPoint;
  596. this.MaidGuid = maidGuid;
  597. this.MaidIndex = maidIndex;
  598. }
  599. }
  600. }