Forráskód Böngészése

Split DragPointChain into mune and limb classes

Make DragPointChain an abstract class that mune and limb (arms and legs)
drag points derive from.
habeebweeb 4 éve
szülő
commit
72ffa6df92

+ 39 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/IK/IK Chain/DragPointChain.cs

@@ -0,0 +1,39 @@
+using UnityEngine;
+
+namespace COM3D2.MeidoPhotoStudio.Plugin
+{
+    public abstract class DragPointChain : DragPointMeido
+    {
+        protected readonly TBody.IKCMO IK = new TBody.IKCMO();
+        protected readonly Quaternion[] jointRotation = new Quaternion[3];
+        protected IKCtrlData ikCtrlData;
+        protected Transform[] ikChain;
+
+        public override void Set(Transform myObject)
+        {
+            base.Set(myObject);
+
+            ikChain = new Transform[] {
+                myObject.parent,
+                myObject.parent,
+                myObject
+            };
+
+            ikCtrlData = IkCtrlData;
+        }
+
+        protected void InitializeRotation()
+        {
+            for (int i = 0; i < jointRotation.Length; i++) jointRotation[i] = ikChain[i].localRotation;
+        }
+
+        protected override void OnMouseDown()
+        {
+            base.OnMouseDown();
+
+            InitializeRotation();
+
+            InitializeIK(IK, ikChain[jointUpper], ikChain[jointMiddle], ikChain[jointLower]);
+        }
+    }
+}

+ 13 - 60
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/IK/DragPointChain.cs

@@ -3,24 +3,18 @@ using UnityEngine;
 namespace COM3D2.MeidoPhotoStudio.Plugin
 {
     using Input = InputManager;
-    public class DragPointChain : DragPointMeido
+    public class DragPointLimb : DragPointChain
     {
-        private readonly TBody.IKCMO IK = new TBody.IKCMO();
-        private readonly Quaternion[] jointRotation = new Quaternion[3];
-        private IKCtrlData ikCtrlData;
-        private Transform[] ikChain;
         private int foot = 1;
         private bool isLower;
         private bool isMiddle;
         private bool isUpper;
-        private bool isMune;
-        private bool isMuneL;
         public override bool IsBone
         {
             set
             {
                 base.IsBone = value;
-                if (!isMune) BaseScale = isBone ? boneScale : OriginalScale;
+                BaseScale = isBone ? boneScale : OriginalScale;
             }
         }
 
@@ -30,27 +24,12 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             string name = myObject.name;
 
-            isMune = name.StartsWith("Mune");
-            isMuneL = isMune && name[5] == 'L'; // Mune_L_Sub
             foot = name.EndsWith("Foot") ? -1 : 1;
             isLower = name.EndsWith("Hand") || foot == -1;
             isMiddle = name.EndsWith("Calf") || name.EndsWith("Forearm");
-            isUpper = !(isMiddle || isLower) && !isMune;
-
-            ikChain = new Transform[] {
-                myObject.parent,
-                myObject.parent,
-                myObject
-            };
+            isUpper = !isMiddle && !isLower;
 
             if (isLower) ikChain[0] = ikChain[0].parent;
-
-            ikCtrlData = IkCtrlData;
-        }
-
-        private void InitializeRotation()
-        {
-            for (int i = 0; i < jointRotation.Length; i++) jointRotation[i] = ikChain[i].localRotation;
         }
 
         protected override void ApplyDragType()
@@ -71,8 +50,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             }
             else if (current == DragType.RotY)
             {
-                if (isMune) ApplyProperties(true, false, false);
-                else if (isMiddle) ApplyProperties(false, false, isBone);
+                if (isMiddle) ApplyProperties(false, false, isBone);
                 else ApplyProperties();
             }
             else if (current == DragType.MoveXZ)
@@ -80,47 +58,21 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 if (isLower) ApplyProperties(true, isBone, false);
                 else ApplyProperties();
             }
-            else ApplyProperties(!isMune, isBone && !isMune, false);
+            else ApplyProperties(true, isBone, false);
         }
 
         protected override void UpdateDragType()
         {
             bool control = Input.Control;
             bool alt = Input.Alt;
-
-            if (control && alt)
-            {
-                // mune
-                CurrentDragType = DragType.RotY;
-            }
-            else if (control)
-            {
-                CurrentDragType = DragType.MoveXZ;
-            }
-            else if (alt)
-            {
-                CurrentDragType = Input.Shift ? DragType.RotLocalY : DragType.RotLocalXZ;
-            }
-            else
+            // Check for DragMove so that hand dragpoint is not in the way
+            if (control && !Input.GetKey(MpsKey.DragMove))
             {
-                CurrentDragType = OtherDragType() ? DragType.Ignore : DragType.None;
+                if (alt) CurrentDragType = DragType.RotY;
+                else CurrentDragType = DragType.MoveXZ;
             }
-        }
-
-        protected override void OnMouseDown()
-        {
-            base.OnMouseDown();
-
-            if (isMune) meido.SetMune(false, isMuneL);
-
-            InitializeRotation();
-
-            InitializeIK(IK, ikChain[jointUpper], ikChain[jointMiddle], ikChain[jointLower]);
-        }
-
-        protected override void OnDoubleClick()
-        {
-            if (isMune && CurrentDragType == DragType.RotY) meido.SetMune(true, isMuneL);
+            else if (alt) CurrentDragType = Input.Shift ? DragType.RotLocalY : DragType.RotLocalXZ;
+            else CurrentDragType = OtherDragType() ? DragType.Ignore : DragType.None;
         }
 
         protected override void Drag()
@@ -129,7 +81,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             bool altRotation = CurrentDragType == DragType.MoveXZ || CurrentDragType == DragType.RotY;
 
-            if ((CurrentDragType == DragType.None) || altRotation)
+            if (CurrentDragType == DragType.None || altRotation)
             {
                 int upperJoint = altRotation ? jointMiddle : jointUpper;
 
@@ -146,6 +98,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 ikChain[joint].localRotation = jointRotation[joint];
                 ikChain[joint].Rotate(Vector3.right * (-mouseDelta.x / 1.5f));
             }
+
             if (CurrentDragType == DragType.RotLocalXZ)
             {
                 ikChain[jointLower].localRotation = jointRotation[jointLower];

+ 47 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/IK/IK Chain/DragPointMune.cs

@@ -0,0 +1,47 @@
+using UnityEngine;
+
+namespace COM3D2.MeidoPhotoStudio.Plugin
+{
+    using Input = InputManager;
+    public class DragPointMune : DragPointChain
+    {
+        private bool isMuneL;
+
+        public override void Set(Transform myObject)
+        {
+            base.Set(myObject);
+            isMuneL = myObject.name[5] == 'L'; // Mune_L_Sub
+        }
+
+        protected override void ApplyDragType() => ApplyProperties(CurrentDragType != DragType.None, false, false);
+
+        protected override void OnMouseDown()
+        {
+            base.OnMouseDown();
+
+            meido.SetMune(false, isMuneL);
+        }
+
+        protected override void OnDoubleClick()
+        {
+            if (CurrentDragType != DragType.None) meido.SetMune(true, isMuneL);
+        }
+
+        protected override void UpdateDragType()
+        {
+            if (Input.Control && Input.Alt) CurrentDragType = DragType.RotLocalXZ;
+            else CurrentDragType = DragType.None;
+        }
+
+        protected override void Drag()
+        {
+            if (isPlaying) meido.Stop = true;
+
+            if (CurrentDragType == DragType.RotLocalXZ)
+            {
+                Porc(IK, ikCtrlData, ikChain[jointUpper], ikChain[jointMiddle], ikChain[jointLower]);
+                InitializeRotation();
+            }
+        }
+    }
+}

+ 8 - 8
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/MeidoDragPointManager.cs

@@ -449,21 +449,21 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             InitializeMuneDragPoint(left: true);
             InitializeMuneDragPoint(left: false);
 
-            DragPointChain[] armDragPointL = MakeIKChain(BoneTransform[Bone.HandL]);
+            DragPointLimb[] armDragPointL = MakeIKChain(BoneTransform[Bone.HandL]);
             DragPoints[Bone.UpperArmL] = armDragPointL[0];
             DragPoints[Bone.ForearmL] = armDragPointL[1];
             DragPoints[Bone.HandL] = armDragPointL[2];
 
-            DragPointChain[] armDragPointR = MakeIKChain(BoneTransform[Bone.HandR]);
+            DragPointLimb[] armDragPointR = MakeIKChain(BoneTransform[Bone.HandR]);
             DragPoints[Bone.UpperArmR] = armDragPointR[0];
             DragPoints[Bone.ForearmR] = armDragPointR[1];
             DragPoints[Bone.HandR] = armDragPointR[2];
 
-            DragPointChain[] legDragPointL = MakeIKChain(BoneTransform[Bone.FootL]);
+            DragPointLimb[] legDragPointL = MakeIKChain(BoneTransform[Bone.FootL]);
             DragPoints[Bone.CalfL] = legDragPointL[0];
             DragPoints[Bone.FootL] = legDragPointL[1];
 
-            DragPointChain[] legDragPointR = MakeIKChain(BoneTransform[Bone.FootR]);
+            DragPointLimb[] legDragPointR = MakeIKChain(BoneTransform[Bone.FootR]);
             DragPoints[Bone.CalfR] = legDragPointR[0];
             DragPoints[Bone.FootR] = legDragPointR[1];
 
@@ -477,7 +477,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             Bone mune = left ? Bone.MuneL : Bone.MuneR;
             Bone sub = left ? Bone.MuneSubL : Bone.MuneSubR;
-            DragPointChain muneDragPoint = DragPoint.Make<DragPointChain>(PrimitiveType.Sphere, Vector3.one * 0.12f);
+            DragPointMune muneDragPoint = DragPoint.Make<DragPointMune>(PrimitiveType.Sphere, Vector3.one * 0.12f);
             muneDragPoint.Initialize(meido,
                 () => (BoneTransform[mune].position + BoneTransform[sub].position) / 2f,
                 () => Vector3.zero
@@ -486,16 +486,16 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             DragPoints[mune] = muneDragPoint;
         }
 
-        private DragPointChain[] MakeIKChain(Transform lower)
+        private DragPointLimb[] MakeIKChain(Transform lower)
         {
             Vector3 limbDragPointSize = Vector3.one * 0.12f;
             // Ignore Thigh transform when making a leg IK chain
             bool isLeg = lower.name.EndsWith("Foot");
-            DragPointChain[] dragPoints = new DragPointChain[isLeg ? 2 : 3];
+            DragPointLimb[] dragPoints = new DragPointLimb[isLeg ? 2 : 3];
             for (int i = dragPoints.Length - 1; i >= 0; i--)
             {
                 Transform joint = lower;
-                dragPoints[i] = DragPoint.Make<DragPointChain>(PrimitiveType.Sphere, limbDragPointSize);
+                dragPoints[i] = DragPoint.Make<DragPointLimb>(PrimitiveType.Sphere, limbDragPointSize);
                 dragPoints[i].Initialize(meido, () => joint.position, () => Vector3.zero);
                 dragPoints[i].Set(joint);
                 dragPoints[i].AddGizmo();