Add IK Control For Pose Mode
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fd35cb16d5e64408eb3f5b252bc0c154
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c0d8b3c418dba4ac2a3443e7fcfe727c
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -11,8 +11,9 @@ public class HandleManager : MonoBehaviour
|
|||||||
|
|
||||||
public Material LineRendererMaterial;
|
public Material LineRendererMaterial;
|
||||||
|
|
||||||
public List<BoneTags> EnabledHandles = new List<BoneTags>() { BoneTags.Humanoid };
|
public List<BoneTags> EnabledHandles { get => IKMode ? IKHandles : enabledHandles; }
|
||||||
public bool EnabledLines = true;
|
public bool EnabledLines = true;
|
||||||
|
public bool IKMode = false;
|
||||||
|
|
||||||
public static bool InteractionInProgress;
|
public static bool InteractionInProgress;
|
||||||
|
|
||||||
@@ -21,6 +22,9 @@ public class HandleManager : MonoBehaviour
|
|||||||
public static System.Action<RuntimeGizmoUndoData> RegisterRuntimeGizmoUndoAction;
|
public static System.Action<RuntimeGizmoUndoData> RegisterRuntimeGizmoUndoAction;
|
||||||
public static System.Action<List<RuntimeGizmoUndoData>> RegisterRuntimeGizmoUndoActions;
|
public static System.Action<List<RuntimeGizmoUndoData>> RegisterRuntimeGizmoUndoActions;
|
||||||
|
|
||||||
|
private List<BoneTags> enabledHandles = new List<BoneTags>() { BoneTags.Humanoid };
|
||||||
|
private List<BoneTags> IKHandles = new List<BoneTags>() { BoneTags.IK };
|
||||||
|
|
||||||
public struct RuntimeGizmoUndoData
|
public struct RuntimeGizmoUndoData
|
||||||
{
|
{
|
||||||
public Transform NewPosition;
|
public Transform NewPosition;
|
||||||
@@ -32,10 +36,40 @@ public class HandleManager : MonoBehaviour
|
|||||||
var camera = Camera.main;
|
var camera = Camera.main;
|
||||||
var poseModeOn = UmaViewerUI.Instance.PoseManager.PoseModeOn;
|
var poseModeOn = UmaViewerUI.Instance.PoseManager.PoseModeOn;
|
||||||
|
|
||||||
foreach(var handle in AllHandles)
|
if (Input.GetKeyDown(KeyCode.Space))
|
||||||
|
{
|
||||||
|
IKMode = !IKMode;
|
||||||
|
if (IKMode)
|
||||||
|
{
|
||||||
|
var ik = UmaViewerUI.Instance.PoseManager.PoseIK;
|
||||||
|
if (ik)
|
||||||
|
{
|
||||||
|
foreach (var effector in ik.solver.effectors)
|
||||||
|
{
|
||||||
|
if (effector.target)
|
||||||
|
{
|
||||||
|
effector.target.localPosition = Vector3.zero;
|
||||||
|
effector.target.localRotation = Quaternion.identity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ik.solver.StoreDefaultLocalState();
|
||||||
|
ik.enabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var ik = UmaViewerUI.Instance.PoseManager.PoseIK;
|
||||||
|
if (ik)
|
||||||
|
{
|
||||||
|
ik.enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var handle in AllHandles)
|
||||||
{
|
{
|
||||||
handle.ForceDisplayOff(!poseModeOn);
|
handle.ForceDisplayOff(!poseModeOn);
|
||||||
handle.UpdateManual(camera, EnabledLines);
|
handle.UpdateManual(camera, EnabledLines && !IKMode);
|
||||||
|
|
||||||
if (handle.Popup.gameObject.activeInHierarchy)
|
if (handle.Popup.gameObject.activeInHierarchy)
|
||||||
{
|
{
|
||||||
@@ -85,13 +119,13 @@ public class HandleManager : MonoBehaviour
|
|||||||
public void ToggleBonesVisible(string tag)
|
public void ToggleBonesVisible(string tag)
|
||||||
{
|
{
|
||||||
var enumTag = (BoneTags)System.Enum.Parse(typeof(BoneTags), tag);
|
var enumTag = (BoneTags)System.Enum.Parse(typeof(BoneTags), tag);
|
||||||
if (EnabledHandles.Contains(enumTag))
|
if (enabledHandles.Contains(enumTag))
|
||||||
{
|
{
|
||||||
EnabledHandles.Remove(enumTag);
|
enabledHandles.Remove(enumTag);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EnabledHandles.Add(enumTag);
|
enabledHandles.Add(enumTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using RootMotion;
|
||||||
|
using RootMotion.Dynamics;
|
||||||
|
using RootMotion.FinalIK;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -35,6 +38,8 @@ public class PoseManager : MonoBehaviour
|
|||||||
public GameObject HandleCanvas;
|
public GameObject HandleCanvas;
|
||||||
public GameObject HelpPanel;
|
public GameObject HelpPanel;
|
||||||
|
|
||||||
|
public FullBodyBipedIK PoseIK;
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (Input.GetKeyDown(KeyCode.H))
|
if (Input.GetKeyDown(KeyCode.H))
|
||||||
@@ -115,8 +120,9 @@ public class PoseManager : MonoBehaviour
|
|||||||
ui.SetDynamicBoneEnable(false);
|
ui.SetDynamicBoneEnable(false);
|
||||||
HandleCanvas.SetActive(true);
|
HandleCanvas.SetActive(true);
|
||||||
|
|
||||||
if (builder.CurrentUMAContainer != null && builder.CurrentUMAContainer.UmaAnimator != null)
|
if (builder.CurrentUMAContainer && builder.CurrentUMAContainer.UmaAnimator)
|
||||||
{
|
{
|
||||||
|
PoseIK = builder.CurrentUMAContainer.CreatePoseIK();
|
||||||
builder.CurrentUMAContainer.UmaAnimator.enabled = false;
|
builder.CurrentUMAContainer.UmaAnimator.enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,6 +146,11 @@ public class PoseManager : MonoBehaviour
|
|||||||
builder.CurrentUMAContainer.UmaAnimator.enabled = true;
|
builder.CurrentUMAContainer.UmaAnimator.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PoseIK)
|
||||||
|
{
|
||||||
|
Destroy(PoseIK);
|
||||||
|
}
|
||||||
|
|
||||||
PoseModeOn = false;
|
PoseModeOn = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,7 +157,7 @@ namespace RuntimeGizmos
|
|||||||
UndoRedoManager.Insert(commandGroup);
|
UndoRedoManager.Insert(commandGroup);
|
||||||
};
|
};
|
||||||
|
|
||||||
PoseManager.SetTooltip(0, $"H - show/hide this\r\n\r\nUndo:\t\t{ActionKey} + {UndoAction}\r\nRedo:\t\t{ActionKey} + {RedoAction}\r\n\r\nMove only: \t{changeModeHotkey} + {SetMoveType}\r\nRotate only: {changeModeHotkey} + {SetRotateType}\r\nScale only: \t{changeModeHotkey} + {SetScaleType}\r\nAll:\t \t{changeModeHotkey} + {SetAllTransformType}");
|
PoseManager.SetTooltip(0, $"H - show/hide this\r\n\r\nUndo:\t\t{ActionKey} + {UndoAction}\r\nRedo:\t\t{ActionKey} + {RedoAction}\r\n\r\nIK Mode: \t{KeyCode.Space}\r\nMove only: \t{changeModeHotkey} + {SetMoveType}\r\nRotate only: {changeModeHotkey} + {SetRotateType}\r\nScale only: \t{changeModeHotkey} + {SetScaleType}\r\nAll:\t \t{changeModeHotkey} + {SetAllTransformType}");
|
||||||
PoseManager.SetTooltip(1, $"\r\n\r\nSpace Toggle:\t{changeModeHotkey} + {SetSpaceToggle}\r\nPivot Toggle:\t{changeModeHotkey} + {SetPivotModeToggle}\r\nScale type toggle: \t{changeModeHotkey} + {SetScaleTypeToggle}\r\nCenter type toggle:{changeModeHotkey} + {SetCenterTypeToggle}");
|
PoseManager.SetTooltip(1, $"\r\n\r\nSpace Toggle:\t{changeModeHotkey} + {SetSpaceToggle}\r\nPivot Toggle:\t{changeModeHotkey} + {SetPivotModeToggle}\r\nScale type toggle: \t{changeModeHotkey} + {SetScaleTypeToggle}\r\nCenter type toggle:{changeModeHotkey} + {SetCenterTypeToggle}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public class SerializableBone
|
|||||||
Dynamic,
|
Dynamic,
|
||||||
Humanoid,
|
Humanoid,
|
||||||
Finger,
|
Finger,
|
||||||
Face
|
Face,
|
||||||
|
IK,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Gallop;
|
using Gallop;
|
||||||
|
using RootMotion;
|
||||||
using RootMotion.Dynamics;
|
using RootMotion.Dynamics;
|
||||||
using RootMotion.FinalIK;
|
using RootMotion.FinalIK;
|
||||||
using System;
|
using System;
|
||||||
@@ -85,6 +86,7 @@ public class UmaContainerCharacter : UmaContainer
|
|||||||
private BipedIK IK;
|
private BipedIK IK;
|
||||||
private PuppetMaster PuppetMaster;
|
private PuppetMaster PuppetMaster;
|
||||||
private List<Transform> _humanoidBones;
|
private List<Transform> _humanoidBones;
|
||||||
|
private UIHandleCharacterRoot handleRoot;
|
||||||
|
|
||||||
public void Initialize(bool smile)
|
public void Initialize(bool smile)
|
||||||
{
|
{
|
||||||
@@ -479,6 +481,46 @@ public class UmaContainerCharacter : UmaContainer
|
|||||||
PuppetMaster.FlattenHierarchy();
|
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)
|
public void LoadTextures(UmaDatabaseEntry entry)
|
||||||
{
|
{
|
||||||
foreach(Texture2D tex2D in entry.GetAll<Texture2D>())
|
foreach(Texture2D tex2D in entry.GetAll<Texture2D>())
|
||||||
@@ -1380,13 +1422,25 @@ public class UmaContainerCharacter : UmaContainer
|
|||||||
UIHandleCharacterRoot rootHandle = UIHandleCharacterRoot.CreateAsChild(this);
|
UIHandleCharacterRoot rootHandle = UIHandleCharacterRoot.CreateAsChild(this);
|
||||||
|
|
||||||
var humanBones = GetHumanBones();
|
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 };
|
List<BoneTags> tags = new List<BoneTags>() { BoneTags.Humanoid };
|
||||||
if (bone.name.EndsWith("_L")) tags.Add(BoneTags.Left);
|
if (bone.name.EndsWith("_L")) tags.Add(BoneTags.Left);
|
||||||
if (bone.name.EndsWith("_R")) tags.Add(BoneTags.Right);
|
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();
|
var handle = UIHandleBone.CreateAsChild(bone, tags).WithLineRenderer();
|
||||||
rootHandle.ChildHandles.Add(handle);
|
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();
|
var handle = UIHandleBone.CreateAsChild(bone.Bone, bone.Tags).SetColor(Color.gray).SetScale(0.15f).WithLineRenderer();
|
||||||
rootHandle.ChildHandles.Add(handle);
|
rootHandle.ChildHandles.Add(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleRoot = rootHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SerializableBone> SaveBones()
|
public List<SerializableBone> SaveBones()
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
m_EditorVersion: 2020.3.48f1
|
m_EditorVersion: 2020.3.24f1
|
||||||
m_EditorVersionWithRevision: 2020.3.48f1 (b805b124c6b7)
|
m_EditorVersionWithRevision: 2020.3.24f1 (79c78de19888)
|
||||||
|
|||||||
Reference in New Issue
Block a user