Parcourir la source

Add rotating head

Closes #4
habeebweeb il y a 3 ans
Parent
commit
656dd1af4a

+ 19 - 4
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/IK/DragPointSpine.cs

@@ -7,12 +7,20 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private Quaternion spineRotation;
         private bool isHip = false;
         private bool isThigh = false;
+        private bool isHead = false;
+
+        public override void AddGizmo(float scale = 0.25f, CustomGizmo.GizmoMode mode = CustomGizmo.GizmoMode.Local)
+        {
+            base.AddGizmo(scale, mode);
+            if (isHead) this.Gizmo.GizmoDrag += (s, a) => meido.HeadToCam = false;
+        }
 
         public override void Set(Transform spine)
         {
             base.Set(spine);
             isHip = spine.name == "Bip01";
             isThigh = spine.name.EndsWith("Thigh");
+            isHead = spine.name.EndsWith("Head");
         }
 
         protected override void ApplyDragType()
@@ -20,10 +28,14 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             DragType current = CurrentDragType;
             if (IsBone && current != DragType.Ignore)
             {
-                if (current == DragType.RotLocalXZ) ApplyProperties(false, false, isThigh);
+                if (!isHead && current == DragType.RotLocalXZ) ApplyProperties(false, false, isThigh);
                 else if (!isThigh && (current == DragType.MoveY)) ApplyProperties(isHip, isHip, !isHip);
-                else if (!isThigh && (current == DragType.RotLocalY)) ApplyProperties(!isHip, !isHip, isHip);
-                else ApplyProperties(!isThigh, !isThigh, false);
+                else if (!(isThigh || isHead) && (current == DragType.RotLocalY)) ApplyProperties(!isHip, !isHip, isHip);
+                else
+                {
+                    bool active = !isThigh;
+                    ApplyProperties(active, active, false);
+                }
             }
             else ApplyProperties(false, false, false);
         }
@@ -32,6 +44,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             bool shift = Utility.GetModKey(Utility.ModKey.Shift);
             bool alt = Utility.GetModKey(Utility.ModKey.Alt);
+            bool ctrl = Utility.GetModKey(Utility.ModKey.Control);
 
             if (Input.GetKey(KeyCode.Space) || OtherDragType())
             {
@@ -50,7 +63,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             {
                 CurrentDragType = DragType.RotLocalY;
             }
-            else if (Utility.GetModKey(Utility.ModKey.Control))
+            else if (ctrl)
             {
                 // hip y transform and spine gizmo rotation
                 CurrentDragType = DragType.MoveY;
@@ -73,6 +86,8 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             if (CurrentDragType == DragType.None)
             {
+                if (isHead) meido.HeadToCam = false;
+
                 Vector3 mouseDelta = MouseDelta();
 
                 MyObject.rotation = spineRotation;

+ 16 - 6
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/MeidoDragPointManager.cs

@@ -375,11 +375,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             dragBody.Select += OnSelectBody;
             dragBody.EndScale += OnSetDragPointScale;
 
-            // Head Dragpoint
-            DragPointHead dragHead = DragPoint.Make<DragPointHead>(
+            // Neck Dragpoint
+            DragPointHead dragNeck = DragPoint.Make<DragPointHead>(
                 PrimitiveType.Sphere, new Vector3(0.2f, 0.24f, 0.2f), DragPoint.LightBlue
             );
-            dragHead.Initialize(meido,
+            dragNeck.Initialize(meido,
                 () => new Vector3(
                     BoneTransform[Bone.Head].position.x,
                     (BoneTransform[Bone.Head].position.y * 1.2f + BoneTransform[Bone.HeadNub].position.y * 0.8f) / 2f,
@@ -391,10 +391,20 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                     BoneTransform[Bone.Head].eulerAngles.z + 90f
                 )
             );
-            dragHead.Set(BoneTransform[Bone.Neck]);
-            dragHead.Select += OnSelectFace;
+            dragNeck.Set(BoneTransform[Bone.Neck]);
+            dragNeck.Select += OnSelectFace;
+
+            DragPoints[Bone.Head] = dragNeck;
+
+            // Head Dragpoint
+            DragPointSpine dragHead = DragPoint.Make<DragPointSpine>(
+                PrimitiveType.Sphere, Vector3.one * 0.045f, DragPoint.LightBlue
+            );
+            dragHead.Initialize(meido, () => BoneTransform[Bone.Head].position, () => Vector3.zero);
+            dragHead.Set(BoneTransform[Bone.Head]);
+            dragHead.AddGizmo();
 
-            DragPoints[Bone.Head] = dragHead;
+            DragPoints[Bone.HeadNub] = dragHead;
 
             // Torso Dragpoint
             Transform spineTrans1 = BoneTransform[Bone.Spine1];