Add IK Control For Pose Mode
This commit is contained in:
@@ -11,8 +11,9 @@ public class HandleManager : MonoBehaviour
|
||||
|
||||
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 IKMode = false;
|
||||
|
||||
public static bool InteractionInProgress;
|
||||
|
||||
@@ -21,6 +22,9 @@ public class HandleManager : MonoBehaviour
|
||||
public static System.Action<RuntimeGizmoUndoData> RegisterRuntimeGizmoUndoAction;
|
||||
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 Transform NewPosition;
|
||||
@@ -32,10 +36,40 @@ public class HandleManager : MonoBehaviour
|
||||
var camera = Camera.main;
|
||||
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.UpdateManual(camera, EnabledLines);
|
||||
handle.UpdateManual(camera, EnabledLines && !IKMode);
|
||||
|
||||
if (handle.Popup.gameObject.activeInHierarchy)
|
||||
{
|
||||
@@ -85,13 +119,13 @@ public class HandleManager : MonoBehaviour
|
||||
public void ToggleBonesVisible(string 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
|
||||
{
|
||||
EnabledHandles.Add(enumTag);
|
||||
enabledHandles.Add(enumTag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using RootMotion;
|
||||
using RootMotion.Dynamics;
|
||||
using RootMotion.FinalIK;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -35,6 +38,8 @@ public class PoseManager : MonoBehaviour
|
||||
public GameObject HandleCanvas;
|
||||
public GameObject HelpPanel;
|
||||
|
||||
public FullBodyBipedIK PoseIK;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.H))
|
||||
@@ -115,8 +120,9 @@ public class PoseManager : MonoBehaviour
|
||||
ui.SetDynamicBoneEnable(false);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -140,6 +146,11 @@ public class PoseManager : MonoBehaviour
|
||||
builder.CurrentUMAContainer.UmaAnimator.enabled = true;
|
||||
}
|
||||
|
||||
if (PoseIK)
|
||||
{
|
||||
Destroy(PoseIK);
|
||||
}
|
||||
|
||||
PoseModeOn = false;
|
||||
}
|
||||
}
|
||||
@@ -157,7 +157,7 @@ namespace RuntimeGizmos
|
||||
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}");
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ public class SerializableBone
|
||||
Dynamic,
|
||||
Humanoid,
|
||||
Finger,
|
||||
Face
|
||||
Face,
|
||||
IK,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user