123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class ThighTwist : ATwistCtrl
- {
- public ThighTwist(bool is_left, TBody body) : base((!is_left) ? Maid.AutoTwist.ThighR : Maid.AutoTwist.ThighL, body)
- {
- string str;
- if (body.IsCrcBody)
- {
- str = "Bip01";
- }
- else
- {
- str = (body.boMAN ? "ManBip" : "Bip01");
- }
- string str2 = (!is_left) ? " R Thigh" : " L Thigh";
- base.bone = body.GetBone(str + str2);
- base.mrBone = base.GetMRBone(str + str2);
- this.Pelvis = body.GetBone(str + " Pelvis");
- if (body.IsCrcBody)
- {
- for (int i = 0; i < 5; i++)
- {
- string name = (!is_left) ? string.Format("ThighTwist{0}_R", i + 1) : string.Format("ThighTwist{0}_L", i + 1);
- Transform transform = base.bone.Find(name);
- if (transform)
- {
- Transform transform2 = base.mrBone.Find(name);
- if (transform2)
- {
- base.twistBones.Add(new KeyValuePair<Transform, Transform>(transform2, transform));
- }
- }
- }
- string text = (!is_left) ? "Hip_R" : "Hip_L";
- Transform bone = body.GetBone(text);
- Transform mrbone = base.GetMRBone(text);
- if (bone && mrbone)
- {
- this.HipPair = new KeyValuePair<Transform, Transform>(mrbone, bone);
- }
- }
- }
- public override void ApplyTwist()
- {
- Quaternion quaternion = base.bone.parent.rotation * base.mrBone.localRotation;
- quaternion = Quaternion.FromToRotation(quaternion * Vector3.right, base.bone.right) * quaternion;
- for (int i = 0; i < base.twistBones.Count; i++)
- {
- KeyValuePair<Transform, Transform> keyValuePair = base.twistBones[i];
- float t = (float)(i + 1) / (float)base.twistBones.Count;
- keyValuePair.Value.rotation = Quaternion.Lerp(quaternion, base.bone.rotation, t);
- }
- if (base.twistBones.Count > 0 && this.HipPair.Key && this.HipPair.Value)
- {
- this.HipPair.Value.localRotation = this.HipPair.Key.localRotation;
- this.HipPair.Value.rotation = Quaternion.Lerp(this.HipPair.Value.rotation, base.twistBones[0].Value.rotation, 0.67f);
- }
- }
- private KeyValuePair<Transform, Transform> HipPair;
- private const float HIP_BLEND_VAL = 0.67f;
- private Transform Pelvis;
- }
|