DragPointLimb.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using UnityEngine;
  2. namespace MeidoPhotoStudio.Plugin
  3. {
  4. using Input = InputManager;
  5. public class DragPointLimb : DragPointChain
  6. {
  7. private int foot = 1;
  8. private bool isLower;
  9. private bool isMiddle;
  10. private bool isUpper;
  11. public override bool IsBone
  12. {
  13. set
  14. {
  15. base.IsBone = value;
  16. BaseScale = isBone ? boneScale : OriginalScale;
  17. }
  18. }
  19. public override void Set(Transform myObject)
  20. {
  21. base.Set(myObject);
  22. string name = myObject.name;
  23. foot = name.EndsWith("Foot") ? -1 : 1;
  24. isLower = name.EndsWith("Hand") || foot == -1;
  25. isMiddle = name.EndsWith("Calf") || name.EndsWith("Forearm");
  26. isUpper = !isMiddle && !isLower;
  27. if (isLower) ikChain[0] = ikChain[0].parent;
  28. }
  29. protected override void ApplyDragType()
  30. {
  31. DragType current = CurrentDragType;
  32. bool isBone = IsBone;
  33. if (CurrentDragType == DragType.Ignore) ApplyProperties();
  34. else if (current == DragType.RotLocalXZ)
  35. {
  36. if (isLower) ApplyProperties(!isBone, false, isBone);
  37. else ApplyProperties();
  38. }
  39. else if (current == DragType.RotLocalY)
  40. {
  41. if (isLower || isMiddle) ApplyProperties(!isBone, false, false);
  42. else if (isUpper) ApplyProperties(false, false, isBone);
  43. else ApplyProperties();
  44. }
  45. else if (current == DragType.RotY)
  46. {
  47. if (isMiddle) ApplyProperties(false, false, isBone);
  48. else ApplyProperties();
  49. }
  50. else if (current == DragType.MoveXZ)
  51. {
  52. if (isLower) ApplyProperties(true, isBone, false);
  53. else ApplyProperties();
  54. }
  55. else ApplyProperties(true, isBone, false);
  56. }
  57. protected override void UpdateDragType()
  58. {
  59. bool control = Input.Control;
  60. bool alt = Input.Alt;
  61. // Check for DragMove so that hand dragpoint is not in the way
  62. if (OtherDragType()) CurrentDragType = DragType.Ignore;
  63. else if (control && !Input.GetKey(MpsKey.DragMove))
  64. {
  65. if (alt) CurrentDragType = DragType.RotY;
  66. else CurrentDragType = DragType.MoveXZ;
  67. }
  68. else if (alt) CurrentDragType = Input.Shift ? DragType.RotLocalY : DragType.RotLocalXZ;
  69. else CurrentDragType = Input.Shift ? DragType.Ignore : DragType.None;
  70. }
  71. protected override void Drag()
  72. {
  73. if (isPlaying) meido.Stop = true;
  74. bool altRotation = CurrentDragType == DragType.MoveXZ || CurrentDragType == DragType.RotY;
  75. if (CurrentDragType == DragType.None || altRotation)
  76. {
  77. int upperJoint = altRotation ? jointMiddle : jointUpper;
  78. Porc(IK, ikCtrlData, ikChain[upperJoint], ikChain[jointMiddle], ikChain[jointLower]);
  79. InitializeRotation();
  80. }
  81. Vector3 mouseDelta = MouseDelta();
  82. if (CurrentDragType == DragType.RotLocalY)
  83. {
  84. int joint = isMiddle ? jointUpper : jointLower;
  85. ikChain[joint].localRotation = jointRotation[joint];
  86. ikChain[joint].Rotate(Vector3.right * (-mouseDelta.x / 1.5f));
  87. }
  88. if (CurrentDragType == DragType.RotLocalXZ)
  89. {
  90. ikChain[jointLower].localRotation = jointRotation[jointLower];
  91. ikChain[jointLower].Rotate(Vector3.up * (foot * mouseDelta.x / 1.5f));
  92. ikChain[jointLower].Rotate(Vector3.forward * (foot * mouseDelta.y / 1.5f));
  93. }
  94. }
  95. }
  96. }