|
@@ -2,62 +2,13 @@ using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
+
|
|
|
using UnityEngine;
|
|
|
|
|
|
namespace MeidoPhotoStudio.Plugin;
|
|
|
|
|
|
-public enum AttachPoint
|
|
|
-{
|
|
|
- None, Head, Neck, UpperArmL, UpperArmR, ForearmL, ForearmR, MuneL, MuneR, HandL, HandR, Pelvis, ThighL, ThighR,
|
|
|
- CalfL, CalfR, FootL, FootR, Spine1a, Spine1, Spine0a, Spine0,
|
|
|
-}
|
|
|
-
|
|
|
public class MeidoDragPointManager
|
|
|
{
|
|
|
- private enum Bone
|
|
|
- {
|
|
|
- // Head
|
|
|
- Head, HeadNub, ClavicleL, ClavicleR,
|
|
|
-
|
|
|
- // Arms
|
|
|
- UpperArmL, UpperArmR, ForearmL, ForearmR, HandL, HandR, /*IKHandL, IKHandR,*/
|
|
|
-
|
|
|
- // Mune
|
|
|
- MuneL, MuneSubL, MuneR, MuneSubR,
|
|
|
-
|
|
|
- // Spine
|
|
|
- Neck, Spine, Spine0a, Spine1, Spine1a, ThighL, ThighR,
|
|
|
-
|
|
|
- // Hip
|
|
|
- Pelvis, Hip,
|
|
|
-
|
|
|
- // Legs
|
|
|
- CalfL, CalfR, FootL, FootR,
|
|
|
-
|
|
|
- // Dragpoint specific
|
|
|
- Cube, Body, Torso,
|
|
|
-
|
|
|
- // Fingers
|
|
|
- Finger0L, Finger01L, Finger02L, Finger0NubL,
|
|
|
- Finger1L, Finger11L, Finger12L, Finger1NubL,
|
|
|
- Finger2L, Finger21L, Finger22L, Finger2NubL,
|
|
|
- Finger3L, Finger31L, Finger32L, Finger3NubL,
|
|
|
- Finger4L, Finger41L, Finger42L, Finger4NubL,
|
|
|
- Finger0R, Finger01R, Finger02R, Finger0NubR,
|
|
|
- Finger1R, Finger11R, Finger12R, Finger1NubR,
|
|
|
- Finger2R, Finger21R, Finger22R, Finger2NubR,
|
|
|
- Finger3R, Finger31R, Finger32R, Finger3NubR,
|
|
|
- Finger4R, Finger41R, Finger42R, Finger4NubR,
|
|
|
-
|
|
|
- // Toes
|
|
|
- Toe0L, Toe01L, Toe0NubL,
|
|
|
- Toe1L, Toe11L, Toe1NubL,
|
|
|
- Toe2L, Toe21L, Toe2NubL,
|
|
|
- Toe0R, Toe01R, Toe0NubR,
|
|
|
- Toe1R, Toe11R, Toe1NubR,
|
|
|
- Toe2R, Toe21R, Toe2NubR,
|
|
|
- }
|
|
|
-
|
|
|
private static readonly Dictionary<AttachPoint, Bone> PointToBone = new()
|
|
|
{
|
|
|
[AttachPoint.Head] = Bone.Head,
|
|
@@ -90,8 +41,136 @@ public class MeidoDragPointManager
|
|
|
|
|
|
private static bool cubeActive;
|
|
|
private static bool cubeSmall;
|
|
|
- private static EventHandler CubeActiveChange;
|
|
|
- private static EventHandler CubeSmallChange;
|
|
|
+
|
|
|
+ private static EventHandler cubeActiveChange;
|
|
|
+
|
|
|
+ private static EventHandler cubeSmallChange;
|
|
|
+
|
|
|
+ private readonly Meido meido;
|
|
|
+ private readonly Dictionary<Bone, DragPointMeido> dragPoints = new();
|
|
|
+
|
|
|
+ private Dictionary<Bone, Transform> boneTransform = new();
|
|
|
+ private DragPointBody dragBody;
|
|
|
+ private DragPointBody dragCube;
|
|
|
+ private bool initialized;
|
|
|
+ private bool isBone;
|
|
|
+ private bool active = true;
|
|
|
+
|
|
|
+ public MeidoDragPointManager(Meido meido) =>
|
|
|
+ this.meido = meido;
|
|
|
+
|
|
|
+ public event EventHandler<MeidoUpdateEventArgs> SelectMaid;
|
|
|
+
|
|
|
+ private enum Bone
|
|
|
+ {
|
|
|
+ // Head
|
|
|
+ Head,
|
|
|
+ HeadNub,
|
|
|
+ ClavicleL,
|
|
|
+ ClavicleR,
|
|
|
+
|
|
|
+ // Arms
|
|
|
+ UpperArmL,
|
|
|
+ UpperArmR,
|
|
|
+ ForearmL,
|
|
|
+ ForearmR,
|
|
|
+
|
|
|
+ // IKHandL and IKHandR
|
|
|
+ HandL,
|
|
|
+ HandR,
|
|
|
+
|
|
|
+ // Mune
|
|
|
+ MuneL,
|
|
|
+ MuneSubL,
|
|
|
+ MuneR,
|
|
|
+ MuneSubR,
|
|
|
+
|
|
|
+ // Spine
|
|
|
+ Neck,
|
|
|
+ Spine,
|
|
|
+ Spine0a,
|
|
|
+ Spine1,
|
|
|
+ Spine1a,
|
|
|
+ ThighL,
|
|
|
+ ThighR,
|
|
|
+
|
|
|
+ // Hip
|
|
|
+ Pelvis,
|
|
|
+ Hip,
|
|
|
+
|
|
|
+ // Legs
|
|
|
+ CalfL,
|
|
|
+ CalfR,
|
|
|
+ FootL,
|
|
|
+ FootR,
|
|
|
+
|
|
|
+ // Dragpoint specific
|
|
|
+ Cube,
|
|
|
+ Body,
|
|
|
+ Torso,
|
|
|
+
|
|
|
+ // Fingers
|
|
|
+ Finger0L,
|
|
|
+ Finger01L,
|
|
|
+ Finger02L,
|
|
|
+ Finger0NubL,
|
|
|
+ Finger1L,
|
|
|
+ Finger11L,
|
|
|
+ Finger12L,
|
|
|
+ Finger1NubL,
|
|
|
+ Finger2L,
|
|
|
+ Finger21L,
|
|
|
+ Finger22L,
|
|
|
+ Finger2NubL,
|
|
|
+ Finger3L,
|
|
|
+ Finger31L,
|
|
|
+ Finger32L,
|
|
|
+ Finger3NubL,
|
|
|
+ Finger4L,
|
|
|
+ Finger41L,
|
|
|
+ Finger42L,
|
|
|
+ Finger4NubL,
|
|
|
+ Finger0R,
|
|
|
+ Finger01R,
|
|
|
+ Finger02R,
|
|
|
+ Finger0NubR,
|
|
|
+ Finger1R,
|
|
|
+ Finger11R,
|
|
|
+ Finger12R,
|
|
|
+ Finger1NubR,
|
|
|
+ Finger2R,
|
|
|
+ Finger21R,
|
|
|
+ Finger22R,
|
|
|
+ Finger2NubR,
|
|
|
+ Finger3R,
|
|
|
+ Finger31R,
|
|
|
+ Finger32R,
|
|
|
+ Finger3NubR,
|
|
|
+ Finger4R,
|
|
|
+ Finger41R,
|
|
|
+ Finger42R,
|
|
|
+ Finger4NubR,
|
|
|
+
|
|
|
+ // Toes
|
|
|
+ Toe0L,
|
|
|
+ Toe01L,
|
|
|
+ Toe0NubL,
|
|
|
+ Toe1L,
|
|
|
+ Toe11L,
|
|
|
+ Toe1NubL,
|
|
|
+ Toe2L,
|
|
|
+ Toe21L,
|
|
|
+ Toe2NubL,
|
|
|
+ Toe0R,
|
|
|
+ Toe01R,
|
|
|
+ Toe0NubR,
|
|
|
+ Toe1R,
|
|
|
+ Toe11R,
|
|
|
+ Toe1NubR,
|
|
|
+ Toe2R,
|
|
|
+ Toe21R,
|
|
|
+ Toe2NubR,
|
|
|
+ }
|
|
|
|
|
|
public static bool CubeActive
|
|
|
{
|
|
@@ -102,7 +181,7 @@ public class MeidoDragPointManager
|
|
|
return;
|
|
|
|
|
|
cubeActive = value;
|
|
|
- CubeActiveChange?.Invoke(null, EventArgs.Empty);
|
|
|
+ cubeActiveChange?.Invoke(null, EventArgs.Empty);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -115,22 +194,10 @@ public class MeidoDragPointManager
|
|
|
return;
|
|
|
|
|
|
cubeSmall = value;
|
|
|
- CubeSmallChange?.Invoke(null, EventArgs.Empty);
|
|
|
+ cubeSmallChange?.Invoke(null, EventArgs.Empty);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private readonly Meido meido;
|
|
|
- private readonly Dictionary<Bone, DragPointMeido> DragPoints = new();
|
|
|
-
|
|
|
- public event EventHandler<MeidoUpdateEventArgs> SelectMaid;
|
|
|
-
|
|
|
- private Dictionary<Bone, Transform> BoneTransform = new();
|
|
|
- private DragPointBody dragBody;
|
|
|
- private DragPointBody dragCube;
|
|
|
- private bool initialized;
|
|
|
- private bool isBone;
|
|
|
- private bool active = true;
|
|
|
-
|
|
|
public bool IsBone
|
|
|
{
|
|
|
get => isBone;
|
|
@@ -144,11 +211,11 @@ public class MeidoDragPointManager
|
|
|
|
|
|
isBone = value;
|
|
|
|
|
|
- foreach (var dragPoint in DragPoints.Values)
|
|
|
+ foreach (var dragPoint in dragPoints.Values)
|
|
|
dragPoint.IsBone = isBone;
|
|
|
|
|
|
foreach (var bone in SpineBones)
|
|
|
- DragPoints[bone].gameObject.SetActive(isBone);
|
|
|
+ dragPoints[bone].gameObject.SetActive(isBone);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -165,13 +232,13 @@ public class MeidoDragPointManager
|
|
|
|
|
|
active = value;
|
|
|
|
|
|
- foreach (var dragPoint in DragPoints.Values)
|
|
|
+ foreach (var dragPoint in dragPoints.Values)
|
|
|
dragPoint.gameObject.SetActive(active);
|
|
|
|
|
|
foreach (var bone in SpineBones)
|
|
|
- DragPoints[bone].gameObject.SetActive(active && IsBone);
|
|
|
+ dragPoints[bone].gameObject.SetActive(active && IsBone);
|
|
|
|
|
|
- var head = (DragPointHead)DragPoints[Bone.Head];
|
|
|
+ var head = (DragPointHead)dragPoints[Bone.Head];
|
|
|
|
|
|
head.gameObject.SetActive(true);
|
|
|
head.IsIK = !active;
|
|
@@ -179,59 +246,6 @@ public class MeidoDragPointManager
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static DragPointLimb[] MakeArmChain(Transform lower, Meido meido)
|
|
|
- {
|
|
|
- var limbDragPointSize = Vector3.one * 0.12f;
|
|
|
-
|
|
|
- var realLower = CMT.SearchObjName(meido.Body.goSlot[0].obj_tr, lower.name, false);
|
|
|
-
|
|
|
- var dragPoints = new DragPointLimb[3];
|
|
|
-
|
|
|
- for (var i = dragPoints.Length - 1; i >= 0; i--)
|
|
|
- {
|
|
|
- var joint = lower;
|
|
|
- var positionJoint = realLower;
|
|
|
-
|
|
|
- dragPoints[i] = DragPoint.Make<DragPointLimb>(PrimitiveType.Sphere, limbDragPointSize);
|
|
|
- dragPoints[i].Initialize(meido, () => positionJoint.position, () => Vector3.zero);
|
|
|
- dragPoints[i].Set(joint);
|
|
|
- dragPoints[i].AddGizmo();
|
|
|
- dragPoints[i].Gizmo.SetAlternateTarget(positionJoint);
|
|
|
-
|
|
|
- lower = lower.parent;
|
|
|
- realLower = realLower.parent;
|
|
|
- }
|
|
|
-
|
|
|
- return dragPoints;
|
|
|
- }
|
|
|
-
|
|
|
- private static DragPointFinger[] MakeFingerChain(Transform lower, Meido meido)
|
|
|
- {
|
|
|
- var fingerDragPointSize = Vector3.one * 0.01f;
|
|
|
-
|
|
|
- var dragPoints = new DragPointFinger[3];
|
|
|
-
|
|
|
- var realLower = CMT.SearchObjName(meido.Body.goSlot[0].obj_tr, lower.parent.name, false);
|
|
|
-
|
|
|
- for (var i = dragPoints.Length - 1; i >= 0; i--)
|
|
|
- {
|
|
|
- var joint = lower;
|
|
|
- var positionJoint = realLower;
|
|
|
-
|
|
|
- dragPoints[i] = DragPoint.Make<DragPointFinger>(PrimitiveType.Sphere, fingerDragPointSize);
|
|
|
- dragPoints[i].Initialize(meido, () => positionJoint.position, () => Vector3.zero);
|
|
|
- dragPoints[i].Set(joint);
|
|
|
-
|
|
|
- lower = lower.parent;
|
|
|
- realLower = realLower.parent;
|
|
|
- }
|
|
|
-
|
|
|
- return dragPoints;
|
|
|
- }
|
|
|
-
|
|
|
- public MeidoDragPointManager(Meido meido) =>
|
|
|
- this.meido = meido;
|
|
|
-
|
|
|
public void Deserialize(BinaryReader reader)
|
|
|
{
|
|
|
var sixtyFourFlag = reader.ReadBoolean();
|
|
@@ -239,7 +253,7 @@ public class MeidoDragPointManager
|
|
|
|
|
|
// finger rotations. Toe rotations as well if sixtyFourFlag is false
|
|
|
for (var bone = Bone.Finger0L; bone <= upperBone; ++bone)
|
|
|
- BoneTransform[bone].localRotation = reader.ReadQuaternion();
|
|
|
+ boneTransform[bone].localRotation = reader.ReadQuaternion();
|
|
|
|
|
|
var bones = sixtyFourFlag
|
|
|
? new[]
|
|
@@ -267,7 +281,7 @@ public class MeidoDragPointManager
|
|
|
/*
|
|
|
* Versions of MM possibly serialized ClavicleL improperly.
|
|
|
* At least I think that's what happened otherwise why would they make this check at all.
|
|
|
- * https://git.coder.horse/meidomustard/modifiedMM/src/master/MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.Update.cs#L4355
|
|
|
+ * https://git.coder.horse/meidomustard/modifiedMM/src/master/MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.Update.cs#L4355
|
|
|
*
|
|
|
* Just look at the way MM serializes rotations.
|
|
|
* https://git.coder.horse/meidomustard/modifiedMM/src/master/MultipleMaids/CM3D2/MultipleMaids/Plugin/MultipleMaids.Update.cs#L2364
|
|
@@ -287,9 +301,9 @@ public class MeidoDragPointManager
|
|
|
var rotation = reader.ReadQuaternion();
|
|
|
|
|
|
if (sixtyFourFlag || i > localRotationIndex)
|
|
|
- BoneTransform[bone].localRotation = rotation;
|
|
|
+ boneTransform[bone].localRotation = rotation;
|
|
|
else
|
|
|
- BoneTransform[bone].rotation = rotation;
|
|
|
+ boneTransform[bone].rotation = rotation;
|
|
|
}
|
|
|
|
|
|
// WHY????
|
|
@@ -307,10 +321,10 @@ public class MeidoDragPointManager
|
|
|
Bone.ThighL, Bone.ThighR, Bone.CalfL, Bone.CalfR, Bone.HandL, Bone.HandR, Bone.FootL, Bone.FootR,
|
|
|
};
|
|
|
|
|
|
- var singleRotations = single.Select(bone => BoneTransform[bone].eulerAngles).ToList();
|
|
|
- var pairRotations = pair.Select(bone => BoneTransform[bone].eulerAngles).ToList();
|
|
|
+ var singleRotations = single.Select(bone => boneTransform[bone].eulerAngles).ToList();
|
|
|
+ var pairRotations = pair.Select(bone => boneTransform[bone].eulerAngles).ToList();
|
|
|
|
|
|
- var hip = BoneTransform[Bone.Hip];
|
|
|
+ var hip = boneTransform[Bone.Hip];
|
|
|
var vecHip = hip.eulerAngles;
|
|
|
|
|
|
var hipL = meido.Maid.body0.GetBone("Hip_L");
|
|
@@ -329,7 +343,7 @@ public class MeidoDragPointManager
|
|
|
{
|
|
|
var bone = single[i];
|
|
|
|
|
|
- BoneTransform[bone].rotation = FlipRotation(singleRotations[i]);
|
|
|
+ boneTransform[bone].rotation = FlipRotation(singleRotations[i]);
|
|
|
}
|
|
|
|
|
|
for (var i = 0; i < pair.Length; i += 2)
|
|
@@ -337,8 +351,8 @@ public class MeidoDragPointManager
|
|
|
var boneA = pair[i];
|
|
|
var boneB = pair[i + 1];
|
|
|
|
|
|
- BoneTransform[boneA].rotation = FlipRotation(pairRotations[i + 1]);
|
|
|
- BoneTransform[boneB].rotation = FlipRotation(pairRotations[i]);
|
|
|
+ boneTransform[boneA].rotation = FlipRotation(pairRotations[i + 1]);
|
|
|
+ boneTransform[boneB].rotation = FlipRotation(pairRotations[i]);
|
|
|
}
|
|
|
|
|
|
var leftHand = SerializeHand(right: false);
|
|
@@ -355,7 +369,7 @@ public class MeidoDragPointManager
|
|
|
}
|
|
|
|
|
|
public Transform GetAttachPointTransform(AttachPoint point) =>
|
|
|
- point is AttachPoint.None ? null : BoneTransform[PointToBone[point]];
|
|
|
+ point is AttachPoint.None ? null : boneTransform[PointToBone[point]];
|
|
|
|
|
|
public byte[] SerializeHand(bool right)
|
|
|
{
|
|
@@ -391,7 +405,7 @@ public class MeidoDragPointManager
|
|
|
|
|
|
public void Destroy()
|
|
|
{
|
|
|
- foreach (var dragPoint in DragPoints.Values)
|
|
|
+ foreach (var dragPoint in dragPoints.Values)
|
|
|
if (dragPoint)
|
|
|
UnityEngine.Object.Destroy(dragPoint.gameObject);
|
|
|
|
|
@@ -401,10 +415,10 @@ public class MeidoDragPointManager
|
|
|
if (dragBody)
|
|
|
UnityEngine.Object.Destroy(dragBody.gameObject);
|
|
|
|
|
|
- BoneTransform.Clear();
|
|
|
- DragPoints.Clear();
|
|
|
- CubeActiveChange -= OnCubeActive;
|
|
|
- CubeSmallChange -= OnCubeSmall;
|
|
|
+ boneTransform.Clear();
|
|
|
+ dragPoints.Clear();
|
|
|
+ cubeActiveChange -= OnCubeActive;
|
|
|
+ cubeSmallChange -= OnCubeSmall;
|
|
|
initialized = false;
|
|
|
}
|
|
|
|
|
@@ -414,8 +428,8 @@ public class MeidoDragPointManager
|
|
|
return;
|
|
|
|
|
|
initialized = true;
|
|
|
- CubeActiveChange += OnCubeActive;
|
|
|
- CubeSmallChange += OnCubeSmall;
|
|
|
+ cubeActiveChange += OnCubeActive;
|
|
|
+ cubeSmallChange += OnCubeSmall;
|
|
|
|
|
|
InitializeBones();
|
|
|
InitializeDragPoints();
|
|
@@ -424,27 +438,77 @@ public class MeidoDragPointManager
|
|
|
|
|
|
public void SetDragPointScale(float scale)
|
|
|
{
|
|
|
- foreach (var dragPoint in DragPoints.Values)
|
|
|
+ foreach (var dragPoint in dragPoints.Values)
|
|
|
dragPoint.DragPointScale = scale;
|
|
|
|
|
|
dragBody.DragPointScale = scale;
|
|
|
}
|
|
|
|
|
|
+ private static DragPointLimb[] MakeArmChain(Transform lower, Meido meido)
|
|
|
+ {
|
|
|
+ var limbDragPointSize = Vector3.one * 0.12f;
|
|
|
+
|
|
|
+ var realLower = CMT.SearchObjName(meido.Body.goSlot[0].obj_tr, lower.name, false);
|
|
|
+
|
|
|
+ var dragPoints = new DragPointLimb[3];
|
|
|
+
|
|
|
+ for (var i = dragPoints.Length - 1; i >= 0; i--)
|
|
|
+ {
|
|
|
+ var joint = lower;
|
|
|
+ var positionJoint = realLower;
|
|
|
+
|
|
|
+ dragPoints[i] = DragPoint.Make<DragPointLimb>(PrimitiveType.Sphere, limbDragPointSize);
|
|
|
+ dragPoints[i].Initialize(meido, () => positionJoint.position, () => Vector3.zero);
|
|
|
+ dragPoints[i].Set(joint);
|
|
|
+ dragPoints[i].AddGizmo();
|
|
|
+ dragPoints[i].Gizmo.SetAlternateTarget(positionJoint);
|
|
|
+
|
|
|
+ lower = lower.parent;
|
|
|
+ realLower = realLower.parent;
|
|
|
+ }
|
|
|
+
|
|
|
+ return dragPoints;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static DragPointFinger[] MakeFingerChain(Transform lower, Meido meido)
|
|
|
+ {
|
|
|
+ var fingerDragPointSize = Vector3.one * 0.01f;
|
|
|
+
|
|
|
+ var dragPoints = new DragPointFinger[3];
|
|
|
+
|
|
|
+ var realLower = CMT.SearchObjName(meido.Body.goSlot[0].obj_tr, lower.parent.name, false);
|
|
|
+
|
|
|
+ for (var i = dragPoints.Length - 1; i >= 0; i--)
|
|
|
+ {
|
|
|
+ var joint = lower;
|
|
|
+ var positionJoint = realLower;
|
|
|
+
|
|
|
+ dragPoints[i] = DragPoint.Make<DragPointFinger>(PrimitiveType.Sphere, fingerDragPointSize);
|
|
|
+ dragPoints[i].Initialize(meido, () => positionJoint.position, () => Vector3.zero);
|
|
|
+ dragPoints[i].Set(joint);
|
|
|
+
|
|
|
+ lower = lower.parent;
|
|
|
+ realLower = realLower.parent;
|
|
|
+ }
|
|
|
+
|
|
|
+ return dragPoints;
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
Somebody smarter than me please help me find a way to do this better T_T
|
|
|
inb4 for loop.
|
|
|
*/
|
|
|
private System.Collections.IEnumerator ApplyHipPosition(Vector3 hipPosition)
|
|
|
{
|
|
|
- BoneTransform[Bone.Hip].position = hipPosition;
|
|
|
+ boneTransform[Bone.Hip].position = hipPosition;
|
|
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
|
|
- BoneTransform[Bone.Hip].position = hipPosition;
|
|
|
+ boneTransform[Bone.Hip].position = hipPosition;
|
|
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
|
|
- BoneTransform[Bone.Hip].position = hipPosition;
|
|
|
+ boneTransform[Bone.Hip].position = hipPosition;
|
|
|
}
|
|
|
|
|
|
private Quaternion FlipRotation(Vector3 rotation) =>
|
|
@@ -452,7 +516,7 @@ public class MeidoDragPointManager
|
|
|
|
|
|
private byte[] SerializeFinger(Bone start, Bone end)
|
|
|
{
|
|
|
- var joints = BoneTransform[start].name.Split(' ')[2].StartsWith("Finger") ? 4 : 3;
|
|
|
+ var joints = boneTransform[start].name.Split(' ')[2].StartsWith("Finger") ? 4 : 3;
|
|
|
|
|
|
byte[] buf;
|
|
|
|
|
@@ -461,7 +525,7 @@ public class MeidoDragPointManager
|
|
|
|
|
|
for (var bone = start; bone <= end; bone += joints)
|
|
|
for (var i = 0; i < joints - 1; i++)
|
|
|
- binaryWriter.WriteQuaternion(BoneTransform[bone + i].localRotation);
|
|
|
+ binaryWriter.WriteQuaternion(boneTransform[bone + i].localRotation);
|
|
|
|
|
|
buf = memoryStream.ToArray();
|
|
|
|
|
@@ -470,7 +534,7 @@ public class MeidoDragPointManager
|
|
|
|
|
|
private void DeserializeFinger(Bone start, Bone end, byte[] fingerBinary, bool mirroring = false)
|
|
|
{
|
|
|
- var joints = BoneTransform[start].name.Split(' ')[2].StartsWith("Finger") ? 4 : 3;
|
|
|
+ var joints = boneTransform[start].name.Split(' ')[2].StartsWith("Finger") ? 4 : 3;
|
|
|
var mirror = mirroring ? -1 : 1;
|
|
|
|
|
|
using var memoryStream = new MemoryStream(fingerBinary);
|
|
@@ -478,10 +542,11 @@ public class MeidoDragPointManager
|
|
|
|
|
|
for (var bone = start; bone <= end; bone += joints)
|
|
|
for (var i = 0; i < joints - 1; i++)
|
|
|
- BoneTransform[bone + i].localRotation = new(
|
|
|
- binaryReader.ReadSingle() * mirror, binaryReader.ReadSingle() * mirror,
|
|
|
- binaryReader.ReadSingle(), binaryReader.ReadSingle()
|
|
|
- );
|
|
|
+ boneTransform[bone + i].localRotation = new(
|
|
|
+ binaryReader.ReadSingle() * mirror,
|
|
|
+ binaryReader.ReadSingle() * mirror,
|
|
|
+ binaryReader.ReadSingle(),
|
|
|
+ binaryReader.ReadSingle());
|
|
|
}
|
|
|
|
|
|
private void InitializeDragPoints()
|
|
@@ -500,15 +565,13 @@ public class MeidoDragPointManager
|
|
|
|
|
|
dragBody.Initialize(
|
|
|
() => new(
|
|
|
- (BoneTransform[Bone.Hip].position.x + BoneTransform[Bone.Spine0a].position.x) / 2f,
|
|
|
- (BoneTransform[Bone.Spine1].position.y + BoneTransform[Bone.Spine0a].position.y) / 2f,
|
|
|
- (BoneTransform[Bone.Spine0a].position.z + BoneTransform[Bone.Hip].position.z) / 2f
|
|
|
- ),
|
|
|
+ (boneTransform[Bone.Hip].position.x + boneTransform[Bone.Spine0a].position.x) / 2f,
|
|
|
+ (boneTransform[Bone.Spine1].position.y + boneTransform[Bone.Spine0a].position.y) / 2f,
|
|
|
+ (boneTransform[Bone.Spine0a].position.z + boneTransform[Bone.Hip].position.z) / 2f),
|
|
|
() => new(
|
|
|
- BoneTransform[Bone.Spine0a].eulerAngles.x, BoneTransform[Bone.Spine0a].eulerAngles.y,
|
|
|
- BoneTransform[Bone.Spine0a].eulerAngles.z + 90f
|
|
|
- )
|
|
|
- );
|
|
|
+ boneTransform[Bone.Spine0a].eulerAngles.x,
|
|
|
+ boneTransform[Bone.Spine0a].eulerAngles.y,
|
|
|
+ boneTransform[Bone.Spine0a].eulerAngles.z + 90f));
|
|
|
|
|
|
dragBody.Set(meido.Maid.transform);
|
|
|
dragBody.Select += OnSelectBody;
|
|
@@ -517,102 +580,97 @@ public class MeidoDragPointManager
|
|
|
// Neck Dragpoint
|
|
|
var dragNeck = DragPoint.Make<DragPointHead>(PrimitiveType.Sphere, new(0.2f, 0.24f, 0.2f));
|
|
|
|
|
|
- dragNeck.Initialize(meido,
|
|
|
+ dragNeck.Initialize(
|
|
|
+ meido,
|
|
|
() => new(
|
|
|
- BoneTransform[Bone.Head].position.x,
|
|
|
- (BoneTransform[Bone.Head].position.y * 1.2f + BoneTransform[Bone.HeadNub].position.y * 0.8f) / 2f,
|
|
|
- BoneTransform[Bone.Head].position.z
|
|
|
- ),
|
|
|
+ boneTransform[Bone.Head].position.x,
|
|
|
+ (boneTransform[Bone.Head].position.y * 1.2f + boneTransform[Bone.HeadNub].position.y * 0.8f) / 2f,
|
|
|
+ boneTransform[Bone.Head].position.z),
|
|
|
() => new(
|
|
|
- BoneTransform[Bone.Head].eulerAngles.x, BoneTransform[Bone.Head].eulerAngles.y,
|
|
|
- BoneTransform[Bone.Head].eulerAngles.z + 90f
|
|
|
- )
|
|
|
- );
|
|
|
+ boneTransform[Bone.Head].eulerAngles.x,
|
|
|
+ boneTransform[Bone.Head].eulerAngles.y,
|
|
|
+ boneTransform[Bone.Head].eulerAngles.z + 90f));
|
|
|
|
|
|
- dragNeck.Set(BoneTransform[Bone.Neck]);
|
|
|
+ dragNeck.Set(boneTransform[Bone.Neck]);
|
|
|
dragNeck.Select += OnSelectFace;
|
|
|
|
|
|
- DragPoints[Bone.Head] = dragNeck;
|
|
|
+ dragPoints[Bone.Head] = dragNeck;
|
|
|
|
|
|
// Head Dragpoint
|
|
|
var dragHead = DragPoint.Make<DragPointSpine>(PrimitiveType.Sphere, Vector3.one * 0.045f);
|
|
|
|
|
|
- dragHead.Initialize(meido, () => BoneTransform[Bone.Head].position, () => Vector3.zero);
|
|
|
- dragHead.Set(BoneTransform[Bone.Head]);
|
|
|
+ dragHead.Initialize(meido, () => boneTransform[Bone.Head].position, () => Vector3.zero);
|
|
|
+ dragHead.Set(boneTransform[Bone.Head]);
|
|
|
dragHead.AddGizmo();
|
|
|
|
|
|
- DragPoints[Bone.HeadNub] = dragHead;
|
|
|
+ dragPoints[Bone.HeadNub] = dragHead;
|
|
|
|
|
|
// Torso Dragpoint
|
|
|
- var spineTrans1 = BoneTransform[Bone.Spine1];
|
|
|
- var spineTrans2 = BoneTransform[Bone.Spine1a];
|
|
|
+ var spineTrans1 = boneTransform[Bone.Spine1];
|
|
|
+ var spineTrans2 = boneTransform[Bone.Spine1a];
|
|
|
|
|
|
var dragTorso = DragPoint.Make<DragPointTorso>(PrimitiveType.Capsule, new Vector3(0.2f, 0.19f, 0.24f));
|
|
|
|
|
|
dragTorso.Initialize(
|
|
|
meido,
|
|
|
() => new(spineTrans1.position.x, spineTrans2.position.y, spineTrans1.position.z - 0.05f),
|
|
|
- () => new(spineTrans1.eulerAngles.x, spineTrans1.eulerAngles.y, spineTrans1.eulerAngles.z + 90f)
|
|
|
- );
|
|
|
+ () => new(spineTrans1.eulerAngles.x, spineTrans1.eulerAngles.y, spineTrans1.eulerAngles.z + 90f));
|
|
|
|
|
|
- dragTorso.Set(BoneTransform[Bone.Spine1a]);
|
|
|
+ dragTorso.Set(boneTransform[Bone.Spine1a]);
|
|
|
|
|
|
- DragPoints[Bone.Torso] = dragTorso;
|
|
|
+ dragPoints[Bone.Torso] = dragTorso;
|
|
|
|
|
|
// Pelvis Dragpoint
|
|
|
- var pelvisTrans = BoneTransform[Bone.Pelvis];
|
|
|
- var spineTrans = BoneTransform[Bone.Spine];
|
|
|
+ var pelvisTrans = boneTransform[Bone.Pelvis];
|
|
|
+ var spineTrans = boneTransform[Bone.Spine];
|
|
|
|
|
|
var dragPelvis = DragPoint.Make<DragPointPelvis>(PrimitiveType.Capsule, new(0.2f, 0.15f, 0.24f));
|
|
|
|
|
|
dragPelvis.Initialize(
|
|
|
meido,
|
|
|
() => new(
|
|
|
- pelvisTrans.position.x, (pelvisTrans.position.y + spineTrans.position.y) / 2f,
|
|
|
- pelvisTrans.position.z
|
|
|
- ),
|
|
|
- () => new(pelvisTrans.eulerAngles.x + 90f, pelvisTrans.eulerAngles.y + 90f, pelvisTrans.eulerAngles.z)
|
|
|
- );
|
|
|
+ pelvisTrans.position.x, (pelvisTrans.position.y + spineTrans.position.y) / 2f, pelvisTrans.position.z),
|
|
|
+ () => new(pelvisTrans.eulerAngles.x + 90f, pelvisTrans.eulerAngles.y + 90f, pelvisTrans.eulerAngles.z));
|
|
|
|
|
|
- dragPelvis.Set(BoneTransform[Bone.Pelvis]);
|
|
|
+ dragPelvis.Set(boneTransform[Bone.Pelvis]);
|
|
|
|
|
|
- DragPoints[Bone.Pelvis] = dragPelvis;
|
|
|
+ dragPoints[Bone.Pelvis] = dragPelvis;
|
|
|
|
|
|
InitializeMuneDragPoint(left: true);
|
|
|
InitializeMuneDragPoint(left: false);
|
|
|
|
|
|
- var armDragPointL = MakeArmChain(BoneTransform[Bone.HandL], meido);
|
|
|
+ var armDragPointL = MakeArmChain(boneTransform[Bone.HandL], meido);
|
|
|
|
|
|
- DragPoints[Bone.UpperArmL] = armDragPointL[0];
|
|
|
- DragPoints[Bone.ForearmL] = armDragPointL[1];
|
|
|
- DragPoints[Bone.HandL] = armDragPointL[2];
|
|
|
+ dragPoints[Bone.UpperArmL] = armDragPointL[0];
|
|
|
+ dragPoints[Bone.ForearmL] = armDragPointL[1];
|
|
|
+ dragPoints[Bone.HandL] = armDragPointL[2];
|
|
|
|
|
|
- var armDragPointR = MakeArmChain(BoneTransform[Bone.HandR], meido);
|
|
|
+ var armDragPointR = MakeArmChain(boneTransform[Bone.HandR], meido);
|
|
|
|
|
|
- DragPoints[Bone.UpperArmR] = armDragPointR[0];
|
|
|
- DragPoints[Bone.ForearmR] = armDragPointR[1];
|
|
|
- DragPoints[Bone.HandR] = armDragPointR[2];
|
|
|
+ dragPoints[Bone.UpperArmR] = armDragPointR[0];
|
|
|
+ dragPoints[Bone.ForearmR] = armDragPointR[1];
|
|
|
+ dragPoints[Bone.HandR] = armDragPointR[2];
|
|
|
|
|
|
- var legDragPointL = MakeLegChain(BoneTransform[Bone.FootL]);
|
|
|
+ var legDragPointL = MakeLegChain(boneTransform[Bone.FootL]);
|
|
|
|
|
|
- DragPoints[Bone.CalfL] = legDragPointL[0];
|
|
|
- DragPoints[Bone.FootL] = legDragPointL[1];
|
|
|
+ dragPoints[Bone.CalfL] = legDragPointL[0];
|
|
|
+ dragPoints[Bone.FootL] = legDragPointL[1];
|
|
|
|
|
|
- var legDragPointR = MakeLegChain(BoneTransform[Bone.FootR]);
|
|
|
+ var legDragPointR = MakeLegChain(boneTransform[Bone.FootR]);
|
|
|
|
|
|
- DragPoints[Bone.CalfR] = legDragPointR[0];
|
|
|
- DragPoints[Bone.FootR] = legDragPointR[1];
|
|
|
+ dragPoints[Bone.CalfR] = legDragPointR[0];
|
|
|
+ dragPoints[Bone.FootR] = legDragPointR[1];
|
|
|
|
|
|
InitializeSpineDragPoint(SpineBones);
|
|
|
|
|
|
for (var bone = Bone.Finger4NubR; bone >= Bone.Finger0L; bone -= 4)
|
|
|
{
|
|
|
- var chain = MakeFingerChain(BoneTransform[bone], meido);
|
|
|
+ var chain = MakeFingerChain(boneTransform[bone], meido);
|
|
|
var i = 2;
|
|
|
|
|
|
for (var joint = bone - 1; joint > bone - 4; joint--)
|
|
|
{
|
|
|
- DragPoints[joint] = chain[i];
|
|
|
+ dragPoints[joint] = chain[i];
|
|
|
i--;
|
|
|
}
|
|
|
}
|
|
@@ -628,12 +686,11 @@ public class MeidoDragPointManager
|
|
|
|
|
|
muneDragPoint.Initialize(
|
|
|
meido,
|
|
|
- () => (BoneTransform[mune].position + BoneTransform[sub].position) / 2f,
|
|
|
- () => Vector3.zero
|
|
|
- );
|
|
|
+ () => (boneTransform[mune].position + boneTransform[sub].position) / 2f,
|
|
|
+ () => Vector3.zero);
|
|
|
|
|
|
- muneDragPoint.Set(BoneTransform[sub]);
|
|
|
- DragPoints[mune] = muneDragPoint;
|
|
|
+ muneDragPoint.Set(boneTransform[sub]);
|
|
|
+ dragPoints[mune] = muneDragPoint;
|
|
|
}
|
|
|
|
|
|
private DragPointLimb[] MakeLegChain(Transform lower)
|
|
@@ -666,23 +723,23 @@ public class MeidoDragPointManager
|
|
|
{
|
|
|
for (var i = 1; i < joints; i++)
|
|
|
{
|
|
|
- var trans = BoneTransform[bone + i];
|
|
|
+ var trans = boneTransform[bone + i];
|
|
|
var chain = DragPoint.Make<DragPointFinger>(PrimitiveType.Sphere, fingerDragPointSize);
|
|
|
|
|
|
chain.Initialize(meido, () => trans.position, () => Vector3.zero);
|
|
|
chain.Set(trans);
|
|
|
- DragPoints[bone + i] = chain;
|
|
|
+ dragPoints[bone + i] = chain;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void InitializeSpineDragPoint(params Bone[] bones)
|
|
|
{
|
|
|
- var spineDragPointSize = DragPointMeido.boneScale;
|
|
|
+ var spineDragPointSize = DragPointMeido.BoneScale;
|
|
|
|
|
|
foreach (var bone in bones)
|
|
|
{
|
|
|
- var spine = BoneTransform[bone];
|
|
|
+ var spine = boneTransform[bone];
|
|
|
var primitive = bone is Bone.Hip ? PrimitiveType.Cube : PrimitiveType.Sphere;
|
|
|
var dragPoint = DragPoint.Make<DragPointSpine>(primitive, spineDragPointSize);
|
|
|
|
|
@@ -690,8 +747,8 @@ public class MeidoDragPointManager
|
|
|
|
|
|
dragPoint.Set(spine);
|
|
|
dragPoint.AddGizmo();
|
|
|
- DragPoints[bone] = dragPoint;
|
|
|
- DragPoints[bone].gameObject.SetActive(false);
|
|
|
+ dragPoints[bone] = dragPoint;
|
|
|
+ dragPoints[bone].gameObject.SetActive(false);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -699,7 +756,7 @@ public class MeidoDragPointManager
|
|
|
dragCube.gameObject.SetActive(CubeActive);
|
|
|
|
|
|
private void OnCubeSmall(object sender, EventArgs args) =>
|
|
|
- dragCube.DragPointScale = CubeSmall ? DragPointGeneral.smallCube : 1f;
|
|
|
+ dragCube.DragPointScale = CubeSmall ? DragPointGeneral.SmallCube : 1f;
|
|
|
|
|
|
private void OnSetDragPointScale(object sender, EventArgs args) =>
|
|
|
SetDragPointScale(meido.Maid.transform.localScale.x);
|
|
@@ -715,7 +772,7 @@ public class MeidoDragPointManager
|
|
|
// TODO: Move to external file somehow
|
|
|
var transform = meido.Body.m_Bones.transform;
|
|
|
|
|
|
- BoneTransform = new()
|
|
|
+ boneTransform = new()
|
|
|
{
|
|
|
[Bone.Head] = CMT.SearchObjName(transform, "Bip01 Head"),
|
|
|
[Bone.Neck] = CMT.SearchObjName(transform, "Bip01 Neck"),
|
|
@@ -809,29 +866,3 @@ public class MeidoDragPointManager
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-public readonly struct AttachPointInfo
|
|
|
-{
|
|
|
- private static readonly AttachPointInfo empty = new(AttachPoint.None, string.Empty, -1);
|
|
|
-
|
|
|
- public AttachPoint AttachPoint { get; }
|
|
|
- public string MaidGuid { get; }
|
|
|
- public int MaidIndex { get; }
|
|
|
-
|
|
|
- public static ref readonly AttachPointInfo Empty =>
|
|
|
- ref empty;
|
|
|
-
|
|
|
- public AttachPointInfo(AttachPoint attachPoint, Meido meido)
|
|
|
- {
|
|
|
- AttachPoint = attachPoint;
|
|
|
- MaidGuid = meido.Maid.status.guid;
|
|
|
- MaidIndex = meido.Slot;
|
|
|
- }
|
|
|
-
|
|
|
- public AttachPointInfo(AttachPoint attachPoint, string maidGuid, int maidIndex)
|
|
|
- {
|
|
|
- AttachPoint = attachPoint;
|
|
|
- MaidGuid = maidGuid;
|
|
|
- MaidIndex = maidIndex;
|
|
|
- }
|
|
|
-}
|