Add IK Control For Pose Mode
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Gallop;
|
||||
using RootMotion;
|
||||
using RootMotion.Dynamics;
|
||||
using RootMotion.FinalIK;
|
||||
using System;
|
||||
@@ -85,6 +86,7 @@ public class UmaContainerCharacter : UmaContainer
|
||||
private BipedIK IK;
|
||||
private PuppetMaster PuppetMaster;
|
||||
private List<Transform> _humanoidBones;
|
||||
private UIHandleCharacterRoot handleRoot;
|
||||
|
||||
public void Initialize(bool smile)
|
||||
{
|
||||
@@ -479,6 +481,46 @@ public class UmaContainerCharacter : UmaContainer
|
||||
PuppetMaster.FlattenHierarchy();
|
||||
}
|
||||
|
||||
public FullBodyBipedIK CreatePoseIK()
|
||||
{
|
||||
var container = this;
|
||||
BipedRagdollReferences r = BipedRagdollReferences.FromAvatar(UmaAnimator);
|
||||
BipedReferences pr = new BipedReferences();
|
||||
var ik = container.gameObject.AddComponent<FullBodyBipedIK>();
|
||||
|
||||
pr.root = r.root;
|
||||
pr.pelvis = r.hips;
|
||||
pr.spine = new Transform[] { r.spine, r.chest };
|
||||
pr.leftThigh = r.leftUpperLeg;
|
||||
pr.leftCalf = r.leftLowerLeg;
|
||||
pr.leftFoot = r.leftFoot;
|
||||
pr.rightThigh = r.rightUpperLeg;
|
||||
pr.rightCalf = r.rightLowerLeg;
|
||||
pr.rightFoot = r.rightFoot;
|
||||
pr.leftUpperArm = r.leftUpperArm;
|
||||
pr.leftForearm = r.leftLowerArm;
|
||||
pr.leftHand = r.leftHand;
|
||||
pr.rightUpperArm = r.rightUpperArm;
|
||||
pr.rightForearm = r.rightLowerArm;
|
||||
pr.rightHand = r.rightHand;
|
||||
pr.head = r.head;
|
||||
ik.SetReferences(pr, r.hips);
|
||||
|
||||
foreach (var effector in ik.solver.effectors)
|
||||
{
|
||||
var handle = handleRoot.ChildHandles.Find(h => h.Owner.transform.parent == effector.bone && (h as UIHandleBone).Tags.Contains(BoneTags.IK));
|
||||
if (handle)
|
||||
{
|
||||
effector.target = handle.Owner.transform;
|
||||
effector.positionWeight = 1;
|
||||
effector.rotationWeight = 1;
|
||||
}
|
||||
}
|
||||
|
||||
ik.enabled = false;
|
||||
return ik;
|
||||
}
|
||||
|
||||
public void LoadTextures(UmaDatabaseEntry entry)
|
||||
{
|
||||
foreach(Texture2D tex2D in entry.GetAll<Texture2D>())
|
||||
@@ -1380,13 +1422,25 @@ public class UmaContainerCharacter : UmaContainer
|
||||
UIHandleCharacterRoot rootHandle = UIHandleCharacterRoot.CreateAsChild(this);
|
||||
|
||||
var humanBones = GetHumanBones();
|
||||
foreach(var bone in humanBones)
|
||||
var ikNames = new[] { "Hip", "Wrist_L", "Wrist_R", "Ankle_L", "Ankle_R" };
|
||||
foreach (var bone in humanBones)
|
||||
{
|
||||
List<BoneTags> tags = new List<BoneTags>() { BoneTags.Humanoid };
|
||||
if (bone.name.EndsWith("_L")) tags.Add(BoneTags.Left);
|
||||
if (bone.name.EndsWith("_R")) tags.Add(BoneTags.Right);
|
||||
|
||||
if(bone.name != "Hip")
|
||||
if (ikNames.Any(x => x == bone.name))
|
||||
{
|
||||
var go = new GameObject(bone.name + "_IK_Handle");
|
||||
go.transform.parent = bone.transform;
|
||||
go.transform.localPosition = Vector3.zero;
|
||||
go.transform.rotation = bone.transform.rotation;
|
||||
go.transform.localScale = Vector3.one;
|
||||
var handle = UIHandleBone.CreateAsChild(go, new List<BoneTags>() { BoneTags.IK });
|
||||
rootHandle.ChildHandles.Add(handle);
|
||||
}
|
||||
|
||||
if (bone.name != "Hip")
|
||||
{
|
||||
var handle = UIHandleBone.CreateAsChild(bone, tags).WithLineRenderer();
|
||||
rootHandle.ChildHandles.Add(handle);
|
||||
@@ -1428,6 +1482,8 @@ public class UmaContainerCharacter : UmaContainer
|
||||
var handle = UIHandleBone.CreateAsChild(bone.Bone, bone.Tags).SetColor(Color.gray).SetScale(0.15f).WithLineRenderer();
|
||||
rootHandle.ChildHandles.Add(handle);
|
||||
}
|
||||
|
||||
handleRoot = rootHandle;
|
||||
}
|
||||
|
||||
public List<SerializableBone> SaveBones()
|
||||
|
||||
Reference in New Issue
Block a user