Browse Source

Fix IK for COM3D2.5

2 days of researching by following call chains and emulating kag
scripts only to add a single line of code to fix IK.
habeebweeb 2 năm trước cách đây
mục cha
commit
823d273599

+ 0 - 3
src/MeidoPhotoStudio.Plugin/DragPoint/DragPointMeido.cs

@@ -34,8 +34,6 @@ public abstract class DragPointMeido : DragPoint
         }
     }
 
-    // TODO: Come up with an intermediary fix for this until I can rewrite the IK system.
-    // WARN: This does NOT work and is only done so the compiler does not complain
     protected
 #if COM25
         AIKCtrl IkCtrlData => meido.Body.fullBodyIK.GetIKCtrl(IkDataTag);
@@ -73,7 +71,6 @@ public abstract class DragPointMeido : DragPoint
     protected void InitializeIK(TBody.IKCMO iKCmo, Transform upper, Transform middle, Transform lower) =>
         iKCmo.Init(upper, middle, lower, maid.body0);
 
-    // WARN: This does NOT work and is only done so the compiler does not complain
     protected void Porc(
         TBody.IKCMO ikCmo,
 #if COM25

+ 0 - 1
src/MeidoPhotoStudio.Plugin/Meido/IK/DragPointFinger.cs

@@ -11,7 +11,6 @@ public class DragPointFinger : DragPointMeido
     private readonly TBody.IKCMO ik = new();
     private readonly Quaternion[] jointRotation = new Quaternion[2];
 
-    // WARN: This does NOT work and is only done so the compiler does not complain
     private
 #if COM25
             AIKCtrl

+ 0 - 1
src/MeidoPhotoStudio.Plugin/Meido/IK/IK Chain/DragPointChain.cs

@@ -7,7 +7,6 @@ public abstract class DragPointChain : DragPointMeido
     protected readonly TBody.IKCMO IK = new();
     protected readonly Quaternion[] jointRotation = new Quaternion[3];
 
-    // WARN: This does NOT work and is only done so the compiler does not complain
     protected
 #if COM25
     AIKCtrl

+ 76 - 10
src/MeidoPhotoStudio.Plugin/Meido/Meido.cs

@@ -246,6 +246,70 @@ public class Meido
         }
     }
 
+    private bool MuneLEnabled
+    {
+        set
+        {
+            if (!Body.isLoadedBody)
+                return;
+
+            MonoBehaviour mune = Body.jbMuneL;
+
+#if COM25
+            if (Body.IsCrcBody)
+                mune = Body.dbMuneL;
+#endif
+
+            if (mune)
+                mune.enabled = value;
+        }
+    }
+
+    private bool MuneREnabled
+    {
+        set
+        {
+            if (!Body.isLoadedBody)
+                return;
+
+            MonoBehaviour mune = Body.jbMuneR;
+
+#if COM25
+            if (Body.IsCrcBody)
+                mune = Body.dbMuneR;
+#endif
+
+            if (mune)
+                mune.enabled = value;
+        }
+    }
+
+    private bool MuneYureLEnabled
+    {
+        set
+        {
+#if COM25
+            Body.SetMuneYureL(value);
+#else
+            if (Body.jbMuneL)
+                Body.jbMuneL.BlendValueON = Convert.ToSingle(value);
+#endif
+        }
+    }
+
+    private bool MuneYureREnabled
+    {
+        set
+        {
+#if COM25
+            Body.SetMuneYureR(value);
+#else
+            if (Body.jbMuneR)
+                Body.jbMuneR.BlendValueON = Convert.ToSingle(value);
+#endif
+        }
+    }
+
     public void Load(int slot)
     {
         if (Busy)
@@ -277,8 +341,8 @@ public class Meido
         {
             DetachAllMpnAttach();
 
-            Body.jbMuneL.enabled = true;
-            Body.jbMuneR.enabled = true;
+            MuneLEnabled = true;
+            MuneREnabled = true;
 
             Body.quaDefEyeL = DefaultEyeRotL;
             Body.quaDefEyeR = DefaultEyeRotR;
@@ -303,8 +367,8 @@ public class Meido
 
         AllProcPropSeqStartPatcher.SequenceStart -= ReinitializeBody;
 
-        Body.MuneYureL(1f);
-        Body.MuneYureR(1f);
+        MuneYureLEnabled = true;
+        MuneYureREnabled = true;
 
         Body.SetMaskMode(MaskMode.None);
         Body.SetBoneHitHeightY(0f);
@@ -434,17 +498,15 @@ public class Meido
 
     public void SetMune(bool enabled, bool left = false)
     {
-        var value = enabled ? 1f : 0f;
-
         if (left)
         {
-            Body.MuneYureL(value);
-            Body.jbMuneL.enabled = enabled;
+            MuneLEnabled = enabled;
+            MuneYureLEnabled = enabled;
         }
         else
         {
-            Body.MuneYureR(value);
-            Body.jbMuneR.enabled = enabled;
+            MuneREnabled = enabled;
+            MuneYureREnabled = enabled;
         }
     }
 
@@ -792,6 +854,10 @@ public class Meido
         if (MeidoPhotoStudio.EditMode)
             AllProcPropSeqStartPatcher.SequenceStart += ReinitializeBody;
 
+#if COM25
+        // NOTE: This is required for IK to work in COM3D2.5
+        Body.motionBlendTime = 0f;
+#endif
         IKManager.Initialize();
 
         SetFaceBlendSet(DefaultFaceBlendSet);