123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665 |
- #define IKO132
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using static ExtensionMethods.MyExtensions;
- using CM3D2.XtMasterSlave.Plugin;
- using UnityEngine;
- using System.Reflection;
- namespace XtMasterSlave_IK_XDLL
- {
- #if IKO132
- public class IkpInst : IkInst
- {
- public const string INFO = "Fixed by @ghorsington on Twitter";
- public static bool boAnime = false; //?
- public static bool IKBend = false; //
- public override bool IsNewPointIK(Maid m, string hand = "右手")
- {
- var ikP = m.body0.IKCtrl.GetIKData(hand, IKBend).GetIKSettingData(IKCtrlData.IKAttachType.Point);
- return (ikP.MyType == IKCtrlData.IKAttachType.NewPoint);
- }
- public override object GetIkPoint(TBody body, string hand = "右手")
- {
- #if DEBUG
- if (Input.GetKey(KeyCode.Space))
- {
- IKBend = true;
- Console.WriteLine("IKBend: ON");
- }
- else
- {
- IKBend = false;
- }
- #endif
- var obj = body.IKCtrl.GetIKData(hand, IKBend).GetIKSettingData(IKCtrlData.IKAttachType.Point);
- if (obj == null)
- obj = body.IKCtrl.GetIKData(hand, IKBend).GetIKSettingData(IKCtrlData.IKAttachType.NewPoint);
- return obj;
- }
- public override object GetIkCtrl(Maid maid)
- {
- return maid.IKCtrl;
- }
- public override object GetIkCtrlPoint(TBody body, string hand = "右手")
- {
- #if DEBUG
- if (Input.GetKey(KeyCode.Space))
- {
- IKBend = true;
- Console.WriteLine("IKBend: ON");
- }
- else
- {
- IKBend = false;
- }
- #endif
- var obj = body.IKCtrl.GetIKData(hand, IKBend);
- return obj;
- }
- private IKCtrlData.IKAttachType GetDefType(XtMasterSlave.MsLinkConfig mscfg)
- {
- if (mscfg.doIK159NewPointToDef)
- {
- return IKCtrlData.IKAttachType.NewPoint;
- }
- else
- {
- return IKCtrlData.IKAttachType.Point;
- }
- }
- public override void IkClear(Maid tgt, XtMasterSlave.MsLinkConfig mscfg)
- {
- List<string> listHand = new List<string> { "右手", "左手" };
- IkClear(tgt, listHand, mscfg);
- }
- //public override void IkClear(Maid tgt, List<string> listHand, XtMasterSlave.MsLinkConfig mscfg, IKCtrlData.IKAttachType IkType = (IKCtrlData.IKAttachType)(-1))
- public override void IkClear(Maid tgt, List<string> listHand, XtMasterSlave.MsLinkConfig mscfg, int IkType = (-1))
- {
- List<IKCtrlData.IKAttachType> listTypes = new List<IKCtrlData.IKAttachType>
- { IKCtrlData.IKAttachType.NewPoint, IKCtrlData.IKAttachType.Rotate };
- listHand.ToList().ForEach(h =>
- {
- var ctrl = tgt.body0.IKCtrl.GetIKData(h, IKBend);
- listTypes.ForEach(t =>
- {
- var iks = ctrl.GetIKSettingData(t);
- if (IkXT.IsIkCtrlO117)
- {
- ctrl.SetIKSetting(t, IKCtrlData.IKExecTiming.Normal, null, string.Empty, null, Vector3.zero);
- ctrl.Detach(t);
- //ctrl.SetIKSetting(t, false, null, -1, string.Empty, null, null, Vector3.zero, false, 0f);
- //iks.SetIKSetting(null, -1, string.Empty, null, null, Vector3.zero, false, 0f);
- //ctrl.Detach(t, 0f);
- }
- else
- {
- //iks.TgtMaid = null;
- //iks.Tgt_AttachSlot = -1;
- //iks.Tgt_AttachName = string.Empty;
- //iks.Target = null;
- //iks.AxisTgt = null;
- //iks.TgtOffset = Vector3.zero;
- //iks.IsTgtAxis
- }
- if (iks.MyType != IKCtrlData.IKAttachType.Rotate)
- {
- if (IkType >= 0 && IkType != (int)IKCtrlData.IKAttachType.Rotate
- && Enum.IsDefined(typeof(IKCtrlData.IKAttachType), IkType))
- {
- iks.ChangeIKType((IKCtrlData.IKAttachType)IkType);
- }
- else
- {
- if (mscfg != null)
- iks.ChangeIKType(GetDefType(mscfg));/*fix v5.0
- else
- iks.ChangePointType(IKCtrlData.IKAttachType.NewPoint);*/
- }
- }
- });
- });
- }
- public override void CopyHandIK(Maid master, Maid slave, XtMasterSlave.v3Offsets[] v3ofs, int num_)
- {
- List<string> listHand = new List<string> { "右手", "左手" };
- List<IKCtrlData.IKAttachType> listTypes = new List<IKCtrlData.IKAttachType>
- { IKCtrlData.IKAttachType.NewPoint, IKCtrlData.IKAttachType.Rotate };
- listHand.ToList().ForEach(h =>
- {
- var ikcm = master.body0.IKCtrl.GetIKData(h, IKBend);
- var ikcs = slave.body0.IKCtrl.GetIKData(h, IKBend);
- listTypes.ForEach(t =>
- {
- var ikm = ikcm.GetIKSettingData(t);
- var iks = ikcs.GetIKSettingData(t);
- if (!(string.IsNullOrEmpty(ikm.curTargetData.Tgt_AttachName) && ikm.curTargetData.Target == null))
- {
- //Console.WriteLine("{0} {1} -> {2} {3} {4}", h, t, ikm.MyType, ikm.Tgt_AttachName, ikm.Target);
- if (iks.MyType != IKCtrlData.IKAttachType.Rotate)
- {
- if (ikm.MyType != IKCtrlData.IKAttachType.Rotate)
- {
- iks.ChangeIKType(ikm.MyType);
- }
- }
- float fixAngle(float angle)
- {
- while (Mathf.Abs(angle) > 360f)
- {
- angle = ((!(angle < 0f)) ? (angle - 360f) : (angle + 360f));
- }
- return angle;
- }
- if (IkXT.IsIkCtrlO117)
- {
- ikcs.SetIKSetting(t, IKCtrlData.IKExecTiming.Normal, ikm.curTargetData.TgtChara, ikm.curTargetData.Tgt_AttachSlot, ikm.curTargetData.Tgt_AttachName, ikm.curTargetData.AxisTgt, ikm.curTargetData.Target, ikm.curTargetData.TgtOffset, ikm.DoAnimation);
- //ikcs.SetIKSetting(t, false, ikm.TgtMaid, ikm.Tgt_AttachSlot, ikm.Tgt_AttachName, ikm.AxisTgt, ikm.Target, ikm.TgtOffset, ikm.DoAnimation, ikm.BlendTime);
- //iks.SetIKSetting(ikm.TgtMaid, ikm.Tgt_AttachSlot, ikm.Tgt_AttachName, ikm.AxisTgt, ikm.Target, ikm.TgtOffset, ikm.DoAnimation, ikm.BlendTime);
- }
- else
- {
- //iks.TgtMaid = ikm.TgtMaid;
- //iks.Tgt_AttachSlot = ikm.Tgt_AttachSlot;
- //iks.Tgt_AttachName = ikm.Tgt_AttachName;
- //iks.Target = ikm.Target;
- //iks.AxisTgt = ikm.AxisTgt;
- }
- if (iks.IsPointAttach)
- {
- iks.curTargetData.TgtOffset = ikm.curTargetData.TgtOffset;
- if (h == "右手")
- iks.curTargetData.TgtOffset += v3ofs[num_].v3HandROffset;
- else
- iks.curTargetData.TgtOffset += v3ofs[num_].v3HandLOffset;
- }
- else
- {
- Vector3 v3rot = Vector3.zero;
- if (h == "右手")
- v3rot = v3ofs[num_].v3HandROffsetRot;
- else
- v3rot = v3ofs[num_].v3HandLOffsetRot;
- iks.curTargetData.TgtOffset.x = fixAngle(ikm.curTargetData.TgtOffset.x + v3rot.x);
- iks.curTargetData.TgtOffset.y = fixAngle(ikm.curTargetData.TgtOffset.y + v3rot.y);
- iks.curTargetData.TgtOffset.z = fixAngle(ikm.curTargetData.TgtOffset.z + v3rot.z);
- }
- }
- });
- });
- //needInit = true;
- }
-
- public override void SetHandIKRotate(string handName, Maid master, Maid slave, string boneTgtname, Vector3 v3HandLOffsetRot)
- {
- slave.IKTargetToBone(handName, master, boneTgtname, v3HandLOffsetRot, IKCtrlData.IKAttachType.Rotate, false, boAnime, IKCtrlData.IKExecTiming.Normal);
- //slave.IKTargetToBone(handName, master, boneTgtname, v3HandLOffsetRot, IKCtrlData.IKAttachType.Rotate, false, 0f, boAnime, false);
- }
- public override void SetHandIKTarget(XtMasterSlave.MsLinkConfig mscfg, string handName, Maid master, Maid slave, int slot_no, string attach_name, Transform target, Vector3 v3HandLOffset)
- {
- /*if (needInit)
- {
- needInit = false;
- if (mscfg.doIK159NewPointToDef)
- IKInit(slave, mscfg);
- #if DEBUG
- else
- IKInit4OldPoint(slave);
- #endif
- }*/
- slave.IKCtrl.GetIKData(handName, IKBend).SetIKSetting(GetDefType(mscfg), IKCtrlData.IKExecTiming.Normal, master, slot_no, attach_name, null, target, v3HandLOffset, boAnime);
- HandFootIKData ikdata = slave.IKCtrl.GetIKData<HandFootIKData>(handName);
- ikdata.CorrectType = HandFootIKData.BorderCorrectType.Bone;
- }
- bool needInit = true;
- static string bodytgt = "dummyBodyTgtXt";
- //RootMotion.FinalIK.FullBodyBipedIK m_FullbodyIK;
- #if DEBUG
- /*GameObject goBodyTgt = new GameObject("dummyBodyTgtXt");
- RootMotion.FinalIK.FullBodyBipedIK m_FullbodyIK;
- GameObject goTgtSR = new GameObject("xtTgtSR");
- GameObject goTgtSL = new GameObject("xtTgtSL");*/
- #endif
- Dictionary<Maid, string> lastAnimeFNs = new Dictionary<Maid, string>();
- private void IKInit(Maid slave, XtMasterSlave.MsLinks ms, XtMasterSlave.MsLinkConfig mscfg)
- {
- var fik = slave.body0.IKCtrl.GetNonPublicField<RootMotion.FinalIK.FullBodyBipedIK>("m_FullbodyIK");
- RootMotion.FinalIK.FullBodyBipedIK FullbodyIK = fik;
- var solver = FullbodyIK.solver;
- string[] tgtlist = new string[] { "IKTarget", "BendBone", "ChainRootBone" };
- bool animStop = true; //モーション停止中
- if (ms.doMasterSlave && !mscfg.doStackSlave_PosSyncMode)
- {
- animStop = false;
- }
- else
- {
- Animation anim = slave.body0.m_Bones.GetComponent<Animation>();
- animStop = !anim.isPlaying;
- }
- if (!lastAnimeFNs.ContainsKey(slave) || slave.body0.LastAnimeFN != lastAnimeFNs[slave])
- {
- lastAnimeFNs[slave] = slave.body0.LastAnimeFN;
- animStop = false;
- }
- solver.spineStiffness = 1f; //背骨の硬さ
- solver.pullBodyVertical = 0.5f; //ボディエフェクター位置補正
- solver.pullBodyHorizontal = 0f;
- solver.spineMapping.twistWeight = 0f;
- foreach (var e in solver.effectors)
- {
- if (animStop)
- {
- e.positionWeight = 1f;
- e.rotationWeight = 0f;
- }
- else
- {
- e.PinToBone(1f, 0f);
- }
- var tgtname = e.target.gameObject.name;
- if (tgtlist.Contains(tgtname))
- {
- // COM3D2標準ターゲット
- e.target.transform.position = e.bone.position;
- e.target.transform.rotation = e.bone.rotation;
- }
- }
- solver.rightShoulderEffector.positionWeight = 0.95f;
- solver.leftShoulderEffector.positionWeight = 0.95f;
- solver.bodyEffector.rotationWeight = 1f;
- solver.rightThighEffector.positionWeight = 0.95f;
- solver.leftThighEffector.positionWeight = 0.95f;
- if (mscfg != null && mscfg.doFinalIKShoulderMove)
- {
- solver.rightShoulderEffector.positionWeight = 0f;
- solver.leftShoulderEffector.positionWeight = 0f;
- }
- if (mscfg != null && mscfg.doFinalIKThighMove)
- {
- solver.bodyEffector.rotationWeight = 0f;
- solver.rightThighEffector.positionWeight = 0f;
- solver.leftThighEffector.positionWeight = 0f;
- }
- foreach (var m in solver.limbMappings)
- {
- m.weight = 1f;
- m.maintainRotationWeight = 0f;
- }
- if (mscfg != null)
- {
- solver.rightLegMapping.weight = mscfg.fFinalIKLegWeight; //0.5f;
- solver.leftLegMapping.weight = mscfg.fFinalIKLegWeight; //0.5f;
- }
- solver.rightLegMapping.maintainRotationWeight = 1f;
- solver.leftLegMapping.maintainRotationWeight = 1f;
- }
- #region for TEST
- #if DEBUG
- private void IKInit4OldPoint(Maid slave)
- {
- var fik = slave.body0.IKCtrl.GetNonPublicField<RootMotion.FinalIK.FullBodyBipedIK>("m_FullbodyIK");
- RootMotion.FinalIK.FullBodyBipedIK FullbodyIK = fik;
- var solver = FullbodyIK.solver;
- string[] tgtlist = new string[] { "IKTarget", "BendBone", "ChainRootBone" };
- solver.spineStiffness = 1f; //背骨の硬さ
- solver.pullBodyVertical = 0f; //ボディエフェクター位置補正
- solver.pullBodyHorizontal = 0f;
- solver.spineMapping.twistWeight = 0f;
- foreach (var e in solver.effectors)
- {
- e.PinToBone(1f, 1f);
- var tgtname = e.target.gameObject.name;
- if (tgtlist.Contains(tgtname))
- {
- // COM3D2標準ターゲット
- e.target.transform.position = e.bone.position;
- e.target.transform.rotation = e.bone.rotation;
- }
- }
-
- foreach(var m in solver.limbMappings)
- {
- m.weight = 0f;
- m.maintainRotationWeight = 1f;
- }
- }
- private void IKInit2(Maid slave)
- {
- var fik = slave.body0.IKCtrl.GetNonPublicField<RootMotion.FinalIK.FullBodyBipedIK>("m_FullbodyIK");
- RootMotion.FinalIK.FullBodyBipedIK FullbodyIK = fik;
- var solver = FullbodyIK.solver;
- string[] tgtlist = new string[] { "IKTarget", "BendBone", "ChainRootBone" };
- string[] bendlist = new string[] { "BendBone", };
- /*
- #if DEBUG
- solver.spineStiffness = 1f; //背骨の硬さ
- //solver.rightLegMapping.weight = 0f;
- //solver.leftLegMapping.weight = 0f;
- if (!solver.bodyEffector.target || solver.bodyEffector.target.gameObject.name != bodytgt)
- solver.bodyEffector.target = new GameObject(bodytgt).transform;
- solver.bodyEffector.positionWeight = 1f;
- solver.bodyEffector.rotationWeight = 1f;
- solver.rightShoulderEffector.positionWeight = 0.95f;
- solver.leftShoulderEffector.positionWeight = 0.95f;
- solver.rightShoulderEffector.rotationWeight = 0.5f;
- solver.leftShoulderEffector.rotationWeight = 0.5f;
- solver.leftThighEffector.positionWeight = 1f;
- solver.leftThighEffector.rotationWeight = 0.5f;
- solver.rightThighEffector.positionWeight = 1f;
- solver.rightThighEffector.rotationWeight = 0.5f;
- solver.leftFootEffector.positionWeight = 1.0f;
- solver.rightFootEffector.positionWeight = 1.0f;
- if (!solver.rightThighEffector.target || solver.rightThighEffector.target.gameObject.name != bodytgt)
- solver.rightThighEffector.target = new GameObject(bodytgt).transform;
- if (!solver.leftThighEffector.target || solver.leftThighEffector.target.gameObject.name != bodytgt)
- solver.leftThighEffector.target = new GameObject(bodytgt).transform;
- if (!solver.rightFootEffector.target || solver.rightFootEffector.target.gameObject.name != bodytgt)
- solver.rightFootEffector.target = new GameObject(bodytgt).transform;
- if (!solver.leftFootEffector.target || solver.leftFootEffector.target.gameObject.name != bodytgt)
- solver.leftFootEffector.target = new GameObject(bodytgt).transform;
- solver.rightLegMapping.weight = 0.2f;
- solver.leftLegMapping.weight = 0.2f;
- //Sync(solver.leftArmChain.bendConstraint.bendGoal.transform, solver.leftArmMapping.bone2);
- //Sync(solver.rightArmChain.bendConstraint.bendGoal.transform, solver.rightArmMapping.bone2);
- foreach (var e in solver.effectors)
- {
- Sync(e);
- var tgtname = e.target.gameObject.name;
- if (tgtlist.Contains(tgtname) || tgtname == bodytgt)
- {
- // COM3D2標準ターゲット
- e.target.transform.position = e.bone.position;
- e.target.transform.rotation = e.bone.rotation;
- }
- else if (bendlist.Contains(tgtname))
- {
- // COM3D2標準ターゲット
- e.target.transform.position = e.bone.position;
- e.target.transform.rotation = e.bone.rotation;
- }
- }
- return;
- #endif
- */
- solver.spineStiffness = 1f; //背骨の硬さ
- solver.pullBodyVertical = 0.5f; //ボディエフェクター位置補正
- solver.pullBodyHorizontal = 0f;
- foreach (var e in solver.effectors)
- {
- e.PinToBone(1f, 0f);
- #if DEBUG
- e.PinToBone(1f, 1f);
- #endif
- var tgtname = e.target.gameObject.name;
- if (tgtlist.Contains(tgtname))
- {
- // COM3D2標準ターゲット
- e.target.transform.position = e.bone.position;
- e.target.transform.rotation = e.bone.rotation;
- }
- }
- solver.rightShoulderEffector.positionWeight = 0.95f;
- solver.leftShoulderEffector.positionWeight = 0.95f;
- solver.bodyEffector.rotationWeight = 1f;
- solver.rightLegMapping.maintainRotationWeight = 0f;
- solver.leftLegMapping.maintainRotationWeight = 0f;
- solver.rightLegMapping.weight = 0f;
- solver.leftLegMapping.weight = 0f;
- solver.rightArmMapping.maintainRotationWeight = 0f;
- solver.leftArmMapping.maintainRotationWeight = 0f;
- solver.rightArmMapping.weight = 1f;
- solver.leftArmMapping.weight = 1f;
- }
- private void IKInitTest(Maid slave, string handName)
- {
- var fik = slave.body0.IKCtrl.GetNonPublicField<RootMotion.FinalIK.FullBodyBipedIK>("m_FullbodyIK");
- RootMotion.FinalIK.FullBodyBipedIK FullbodyIK = fik;
- var solver = FullbodyIK.solver;
- if (handName.Contains("右"))
- {
- //solver.rightLegMapping.weight = 0f;
- //solver.spineMapping.twistWeight = 0f;
- //m_FullbodyIK.references.root = slave.gameObject.transform;
- //solver.SetToReferences(FullbodyIK.references, null);
- solver.spineStiffness = 1f;
- solver.pullBodyVertical = 0f;
- solver.pullBodyHorizontal = 0f;
- if (Input.GetKey(KeyCode.LeftAlt))
- {
- solver.spineStiffness = 0f;
- solver.pullBodyVertical = 1f;
- }
- foreach (var e in solver.effectors)
- {
- if (Input.GetKey(KeyCode.RightAlt))
- e.PinToBone(0.25f, 1f);
- else if (Input.GetKey(KeyCode.RightShift))
- e.PinToBone(0.5f, 0f);
- else if (Input.GetKey(KeyCode.RightControl))
- e.PinToBone(0f, 1f);
- else
- e.PinToBone(1f, 1f);
- }
- solver.rightLegMapping.maintainRotationWeight = 1f;
- solver.leftLegMapping.maintainRotationWeight = 1f;
- if (Input.GetKey(KeyCode.Space))
- solver.rightLegMapping.weight = 1f;
- else if (Input.GetKey(KeyCode.Keypad0))
- solver.rightLegMapping.weight = 0f;
- else
- solver.rightLegMapping.weight = 0.5f;
- /*Sync(solver.bodyEffector);
- Sync(solver.rightFootEffector);
- Sync(solver.rightThighEffector);
- Sync(solver.rightShoulderEffector);
- WeightZero(solver.rightFootEffector);
- WeightZero(solver.rightThighEffector);
- WeightZero(solver.rightShoulderEffector);*/
- }
- else
- {
- solver.leftLegMapping.maintainRotationWeight = 1f;
- if (Input.GetKey(KeyCode.Space))
- solver.leftLegMapping.weight = 1f;
- else if (Input.GetKey(KeyCode.Keypad0))
- solver.leftLegMapping.weight = 0f;
- else
- solver.leftLegMapping.weight = 0.5f;
- /*Sync(solver.leftFootEffector);
- Sync(solver.leftThighEffector);
- Sync(solver.leftShoulderEffector);
- WeightZero(solver.leftFootEffector);
- WeightZero(solver.leftThighEffector);
- WeightZero(solver.leftShoulderEffector);*/
- }
- }
- #endif
- #endregion
- private static void Sync(Transform tr1, Transform tr2)
- {
- tr1.position = tr2.position;
- tr1.rotation = tr2.rotation;
- }
- private static void Sync(RootMotion.FinalIK.IKEffector eff)
- {
- eff.position = eff.bone.position;
- eff.rotation = eff.bone.rotation;
- /*eff.target.position = eff.bone.position;
- eff.target.rotation = eff.bone.rotation;
- eff.PinToBone(1f, 1f);*/
- }
- private static void WeightZero(RootMotion.FinalIK.IKEffector eff)
- {
- eff.positionWeight = 0f;
- eff.rotationWeight = 0f;
- }
- public override object GetIKCmo(TBody body, string hand = "右手")
- {
- return body.IKCtrl.GetIKData(hand, IKBend).IKCmo;
- /*
- if (hand == "右手")
- return body.IKCtrl.GetIKData("右手").IKCmo;
- else
- return body.IKCtrl.GetIKData("左手").IKCmo;
- */
- }
- public override bool IKUpdate(TBody body)
- {
- body.IKCtrl.IKUpdate();
- return true;
- }
- public override bool GetIKCmoPosRot(TBody body, out Vector3 pos, out Quaternion rot, string hand = "右手")
- {
- var ctrl = body.IKCtrl.GetIKData(hand, IKBend);
- bool proc = false;
- pos = Vector3.zero;
- rot = Quaternion.identity;
- var data = ctrl.GetIKSettingData(IKCtrlData.IKAttachType.Point);
- if (data.curTargetData.Target != null)
- {
- pos = data.curTargetData.Target.position;
- rot = data.curTargetData.Target.rotation;
- proc = true;
- }
- else if (data.curTargetData.Tgt_AttachName != string.Empty)
- {
- if (data.curTargetData.TgtChara != null && data.curTargetData.TgtChara.body0 != null && data.curTargetData.Tgt_AttachSlot >= 0 && data.curTargetData.TgtChara.body0.goSlot[data.curTargetData.Tgt_AttachSlot].morph != null)
- {
- Vector3 vector;
- data.curTargetData.TgtChara.body0.goSlot[data.curTargetData.Tgt_AttachSlot].morph.GetAttachPoint(data.curTargetData.Tgt_AttachName, out pos, out rot, out vector, false);
- proc = true;
- }
- else
- {
- data.curTargetData.Tgt_AttachName = string.Empty;
- }
- }
- return proc;
- }
- public override bool IKCmoUpdate(TBody body, Transform trh, Vector3 offset, string hand = "右手")
- {
- var ctrl = body.IKCtrl.GetIKData(hand, IKBend);
- /*ctrl.MyIKCtrl.GetType().GetProperty("IsUpdateEnd").SetValue(ctrl.MyIKCtrl, true, null);
- ctrl.MyIKCtrl.IsUpdateLate = false;
- ctrl.ApplyIKSetting();
- */
- Vector3 pos = Vector3.zero;
- Quaternion rot = Quaternion.identity;
- bool proc = GetIKCmoPosRot(body, out pos, out rot, hand);
- if (proc)
- {
- ctrl.IKCmo.Porc(trh.parent.parent, trh.parent, trh, pos, rot * offset, ctrl);
- return true;
- }
- return false;
- }
- public override bool UpdateFinalIK(Maid maid, XtMasterSlave.MsLinks ms, XtMasterSlave.MsLinkConfig mscfg)
- {
- if (!maid || !maid.body0)
- return false;
- needInit = false;
- if (mscfg.doIK159NewPointToDef)
- IKInit(maid, ms, mscfg);
- #if DEBUG
- else
- IKInit4OldPoint(maid);
- #endif
- return true; // 実行できたか
- }
- }
- #endif
- }
- public static class Extentions
- {
- public static T GetNonPublicField<T>(this object obj, string name)
- {
- var ret = obj.GetType().GetField(name, BindingFlags.Instance | BindingFlags.NonPublic).GetValue(obj);
-
- if (ret is T)
- return (T)ret;
- return default(T);
- }
- }
|