DragPointLimb.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using UnityEngine;
  2. namespace COM3D2.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 (control && !Input.GetKey(MpsKey.DragMove))
  63. {
  64. if (alt) CurrentDragType = DragType.RotY;
  65. else CurrentDragType = DragType.MoveXZ;
  66. }
  67. else if (alt) CurrentDragType = Input.Shift ? DragType.RotLocalY : DragType.RotLocalXZ;
  68. else CurrentDragType = OtherDragType() ? DragType.Ignore : DragType.None;
  69. }
  70. protected override void Drag()
  71. {
  72. if (isPlaying) meido.Stop = true;
  73. bool altRotation = CurrentDragType == DragType.MoveXZ || CurrentDragType == DragType.RotY;
  74. if (CurrentDragType == DragType.None || altRotation)
  75. {
  76. int upperJoint = altRotation ? jointMiddle : jointUpper;
  77. Porc(IK, ikCtrlData, ikChain[upperJoint], ikChain[jointMiddle], ikChain[jointLower]);
  78. InitializeRotation();
  79. }
  80. Vector3 mouseDelta = MouseDelta();
  81. if (CurrentDragType == DragType.RotLocalY)
  82. {
  83. int joint = isMiddle ? jointUpper : jointLower;
  84. ikChain[joint].localRotation = jointRotation[joint];
  85. ikChain[joint].Rotate(Vector3.right * (-mouseDelta.x / 1.5f));
  86. }
  87. if (CurrentDragType == DragType.RotLocalXZ)
  88. {
  89. ikChain[jointLower].localRotation = jointRotation[jointLower];
  90. ikChain[jointLower].Rotate(Vector3.up * (foot * mouseDelta.x / 1.5f));
  91. ikChain[jointLower].Rotate(Vector3.forward * (foot * mouseDelta.y / 1.5f));
  92. }
  93. }
  94. }
  95. }