ソースを参照

Serialize/deserialize mune properly

Mune seemed to be distorted when loading the frame binary saved from a
different maid.
habeebweeb 4 年 前
コミット
e04f334feb

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

@@ -14,20 +14,27 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private bool isMiddle;
         private bool isUpper;
         private bool isMune;
+        private bool isMuneL;
 
         public override void Set(Transform myObject)
         {
             base.Set(myObject);
-            isMune = myObject.name.StartsWith("Mune");
-            foot = myObject.name.EndsWith("Foot") ? -1 : 1;
-            isLower = myObject.name.EndsWith("Hand") || foot == -1;
-            isMiddle = myObject.name.EndsWith("Calf") || myObject.name.EndsWith("Forearm");
+
+            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
             };
+
             if (isLower) ikChain[0] = ikChain[0].parent;
 
             ikCtrlData = IkCtrlData;
@@ -96,7 +103,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         {
             base.OnMouseDown();
 
-            if (isMune) meido.SetMune(true);
+            if (isMune) meido.SetMune(false, isMuneL);
 
             InitializeRotation();
 
@@ -105,7 +112,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         protected override void OnDoubleClick()
         {
-            if (isMune && CurrentDragType == DragType.RotY) meido.SetMune();
+            if (isMune && CurrentDragType == DragType.RotY) meido.SetMune(true, isMuneL);
         }
 
         protected override void Drag()

+ 28 - 14
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Meido/Meido.cs

@@ -322,7 +322,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             }
 
             Maid.SetAutoTwistAll(true);
-            SetMune();
+            SetPoseMune();
         }
 
         public void CopyPose(Meido fromMeido)
@@ -332,17 +332,29 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             Body.CrossFade(tag, poseBinary, false, true, false, 0f);
             Maid.SetAutoTwistAll(true);
             Maid.transform.rotation = fromMeido.Maid.transform.rotation;
-            SetMune();
+            SetPoseMune();
         }
 
-        public void SetMune(bool drag = false)
+        public void SetMune(bool enabled, bool left = false)
+        {
+            float value = enabled ? 1f : 0f;
+            if (left)
+            {
+                Body.MuneYureL(value);
+                Body.jbMuneL.enabled = enabled;
+            }
+            else
+            {
+                Body.MuneYureR(value);
+                Body.jbMuneR.enabled = enabled;
+            }
+        }
+
+        private void SetPoseMune()
         {
             bool momiOrPaizuri = CachedPose.Pose.Contains("_momi") || CachedPose.Pose.Contains("paizuri_");
-            float onL = (drag || momiOrPaizuri) ? 0f : 1f;
-            Body.MuneYureL(onL);
-            Body.MuneYureR(onL);
-            Body.jbMuneL.enabled = !drag;
-            Body.jbMuneR.enabled = !drag;
+            SetMune(!momiOrPaizuri, left: true);
+            SetMune(!momiOrPaizuri, left: false);
         }
 
         public void SetHandPreset(string filename, bool right)
@@ -386,7 +398,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public byte[] SerializePose(bool frameBinary = false)
         {
             CacheBoneDataArray cache = GetCacheBoneData();
-            return frameBinary ? cache.GetFrameBinary(true, true) : cache.GetAnmBinary(true, true);
+            bool muneL = Body.GetMuneYureL() == 0f;
+            bool muneR = Body.GetMuneYureR() == 0f;
+            return frameBinary ? cache.GetFrameBinary(muneL, muneR) : cache.GetAnmBinary(true, true);
         }
 
         public Dictionary<string, float> SerializeFace()
@@ -742,18 +756,18 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             Maid.transform.rotation = binaryReader.ReadQuaternion();
             Maid.transform.localScale = binaryReader.ReadVector3();
             // pose
+
+            KeyValuePair<bool, bool> muneSetting = new KeyValuePair<bool, bool>(true, true);
             if (mmScene) IKManager.Deserialize(binaryReader);
             else
             {
                 int poseBufferLength = binaryReader.ReadInt32();
                 byte[] poseBuffer = binaryReader.ReadBytes(poseBufferLength);
-                GetCacheBoneData().SetFrameBinary(poseBuffer);
+                muneSetting = GetCacheBoneData().SetFrameBinary(poseBuffer);
             }
 
-            Body.MuneYureL(0f);
-            Body.MuneYureR(0f);
-            Body.jbMuneL.enabled = true;
-            Body.jbMuneR.enabled = true;
+            SetMune(!muneSetting.Key, left: true);
+            SetMune(!muneSetting.Value, left: false);
 
             CachedPose = PoseInfo.Deserialize(binaryReader);
             // eye direction