Skip to content

Commit

Permalink
Upgrade Dialog, improved bonepose editor, various bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaimi committed Dec 10, 2020
1 parent 6953536 commit 3d80d4e
Show file tree
Hide file tree
Showing 19 changed files with 189,184 additions and 18,227 deletions.
17 changes: 17 additions & 0 deletions UMAProject/Assets/UMA/Core/Editor/Scripts/GUIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ private static GUIStyle inspectStyle
}
}

public static void BeginVerticalPadded()
{
if (EditorGUIUtility.isProSkin)
{
GUIHelper.BeginVerticalPadded(10, new Color(1.3f, 1.4f, 1.5f));
}
else
{
GUIHelper.BeginVerticalPadded(10, new Color(0.75f, 0.875f, 1f));
}
}

public static void EndVerticalPadded()
{
GUIHelper.EndVerticalPadded(10);
}

public static void BeginVerticalPadded(float padding, Color backgroundColor, GUIStyle theStyle = null)
{
if (theStyle == null)
Expand Down
150 changes: 125 additions & 25 deletions UMAProject/Assets/UMA/Core/Editor/Scripts/UMABonePoseEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public class UMABonePoseEditor : Editor
//The property drawer makes sure there is only ever one of these open at any one time, so you know if you change
//any fields on the editor defined here you are changing them for that instance of the editor
private static UMABonePoseEditor _livePopupEditor = null;

public static int MirrorAxis = 1;
public static string[] MirrorAxises = {"X Axis (raw)","Y Axis (UMA Internal)", "Z Axis" };
public static UMAData saveUMAData;
// HACK for testing
public UMAData sourceUMA;
TreeViewState treeState;
Expand Down Expand Up @@ -195,6 +197,9 @@ public static void SetLivePopupEditor(UMABonePoseEditor liveUBPEditor)

public void OnEnable()
{
if (saveUMAData != null)
sourceUMA = saveUMAData;

if (treeState == null)
treeState = new TreeViewState();

Expand Down Expand Up @@ -333,22 +338,39 @@ private void DrawSkeletonBones()
var Hips = Position.Find("Hips");
if (Hips != null)
{
DrawSkeletonBonesRecursive(Hips);
DrawSkeletonBonesRecursive(Hips,Color.white);
}
}
}
}
Handles.color = prevHandlesColor;
}

private void DrawSkeletonBonesRecursive(Transform parentBone)
private void DrawSkeletonBonesRecursive(Transform parentBone, Color col)
{
float leaflen = 0.01f;

for (int i = 0; i < parentBone.childCount; i++)
{
Handles.color = parentBone.GetChild(i) == context.activeTransform ? Color.green : (parentBone.GetChild(i) == context.mirrorTransform ? new Color(0,0.5f,1) : Color.white);
Transform child = parentBone.GetChild(i);
Color NextColor = child == context.activeTransform ? Color.green : (parentBone.GetChild(i) == context.mirrorTransform ? new Color(0, 0.5f, 1) : Color.white);

Handles.color = col;
Handles.DrawLine(parentBone.position, parentBone.GetChild(i).position);
if (parentBone.GetChild(i).childCount > 0)
DrawSkeletonBonesRecursive(parentBone.GetChild(i));
{
DrawSkeletonBonesRecursive(parentBone.GetChild(i),NextColor);
}
else
{
if (!child.gameObject.name.Contains("Adjust"))
{
Vector3 leafpos = child.rotation * (Vector3.one * leaflen);
Vector3 ends = child.position + leafpos;
// draw terminator bone
//Handles.DrawLine(child.position, ends); ?? Not working
}
}
}
}

Expand Down Expand Up @@ -527,22 +549,6 @@ public override void OnInspectorGUI()
AddABone(poses,addBoneName);
}

/*
int addedIndex = poses.arraySize;
poses.InsertArrayElementAtIndex(addedIndex);
var pose = poses.GetArrayElementAtIndex(addedIndex);
SerializedProperty bone = pose.FindPropertyRelative("bone");
bone.stringValue = addBoneName;
SerializedProperty hash = pose.FindPropertyRelative("hash");
hash.intValue = UMASkeleton.StringToHash(addBoneName);
SerializedProperty position = pose.FindPropertyRelative("position");
position.vector3Value = Vector3.zero;
SerializedProperty rotation = pose.FindPropertyRelative("rotation");
rotation.quaternionValue = Quaternion.identity;
SerializedProperty scale = pose.FindPropertyRelative("scale");
scale.vector3Value = Vector3.one;
*/

activeBoneIndex = BAD_INDEX;
editBoneIndex = BAD_INDEX;
mirrorBoneIndex = BAD_INDEX;
Expand All @@ -565,8 +571,9 @@ public override void OnInspectorGUI()
// HACK
if (!dynamicDNAConverterMode)
{
EditorGUILayout.HelpBox("Select a UMA at runtime (DynamicCharacterAvatar, DynamicAvatar, UMAData) to enable editing and addition of new bones.", MessageType.Info);
EditorGUILayout.HelpBox("Select a built UMA (DynamicCharacterAvatar, DynamicAvatar, UMAData) to enable editing and addition of new bones.", MessageType.Info);
sourceUMA = EditorGUILayout.ObjectField("Source UMA", sourceUMA, typeof(UMAData), true) as UMAData;
saveUMAData = sourceUMA;
}
else
{
Expand Down Expand Up @@ -604,6 +611,49 @@ public override void OnInspectorGUI()

GUILayout.Space(EditorGUIUtility.singleLineHeight / 2f);

// Toolbar
GUIHelper.BeginVerticalPadded();
MirrorAxis = EditorGUILayout.Popup("Mirror Axis",MirrorAxis, MirrorAxises);
GUILayout.BeginHorizontal();

if (GUILayout.Button("Find UMA in scene"))
{
UMAData data = GameObject.FindObjectOfType<UMAData>();
if (data != null)
{
sourceUMA = data;
saveUMAData = data;

var active = Selection.activeObject;

Selection.activeGameObject = data.gameObject;
SceneView.FrameLastActiveSceneView();

Selection.activeObject = active;
}
}

GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
if (GUILayout.Button("Convert all Left/Right"))
{
for (int i = 0; i < poses.arraySize; i++)
{
FlipBone(poses, i);
}
}
if (GUILayout.Button("Mirror to opposite"))
{
// find the opposite bone.
// Copy the parms
// flip it with FlipBone
}
GUILayout.EndHorizontal();
highlight = EditorGUILayout.TextField("Highlight bones containing: ", highlight);

GUIHelper.EndVerticalPadded();

// string controlName = GUI.GetNameOfFocusedControl();
// if ((controlName != null) && (controlName.Length > 0))
// Debug.Log(controlName);
Expand Down Expand Up @@ -631,7 +681,8 @@ public override void OnInspectorGUI()
if (editBoneIndex != BAD_INDEX)
{
SerializedProperty editBone = poses.GetArrayElementAtIndex(editBoneIndex);
string boneName = editBone.stringValue;
SerializedProperty bone = editBone.FindPropertyRelative("bone");
string boneName = bone.stringValue;
string mirrorBoneName = "";
if (boneName.StartsWith("Left"))
{
Expand All @@ -649,7 +700,6 @@ public override void OnInspectorGUI()
poses.isExpanded = EditorGUILayout.Foldout(poses.isExpanded, "Pose Bones ("+poses.arraySize+")");
if (poses.isExpanded)
{
highlight = EditorGUILayout.TextField("Highlight bones containing: ", highlight);
for (int i = 0; i < poses.arraySize; i++)
{
SerializedProperty pose = poses.GetArrayElementAtIndex(i);
Expand Down Expand Up @@ -775,7 +825,57 @@ public override void OnInspectorGUI()
serializedObject.ApplyModifiedProperties();
}

private void ReloadFilteredTree()
private static void FlipBone(SerializedProperty poses, int i)
{
SerializedProperty pose = poses.GetArrayElementAtIndex(i);
SerializedProperty bone = pose.FindPropertyRelative("bone");
SerializedProperty position = pose.FindPropertyRelative("position");
SerializedProperty rotation = pose.FindPropertyRelative("rotation");
SerializedProperty scale = pose.FindPropertyRelative("scale");
SerializedProperty hash = pose.FindPropertyRelative("hash");
if (bone.stringValue.Contains("Left"))
{
bone.stringValue = bone.stringValue.Replace("Left", "Right");
hash.intValue = UMASkeleton.StringToHash(bone.stringValue);
FlipSingleBone(position, rotation);
}
else if (bone.stringValue.Contains("Right"))
{
bone.stringValue = bone.stringValue.Replace("Right", "Left");
hash.intValue = UMASkeleton.StringToHash(bone.stringValue);
FlipSingleBone(position, rotation);
}
}

private static void FlipSingleBone(SerializedProperty position, SerializedProperty rotation)
{
Quaternion localRot = rotation.quaternionValue;
Vector3 localPos = position.vector3Value;

switch (MirrorAxis)
{
case 0: // X (all others)
localRot.x *= -1;
localRot.w *= -1;
localPos.x *= -1;
break;
case 1: // Y (UMA/Blender models)
localRot.y *= -1;
localRot.w *= -1;
localPos.y *= -1;
break;
case 2: // Z - Who knows
localRot.z *= -1;
localRot.w *= -1;
localPos.z *= -1;
break;
}

rotation.quaternionValue = localRot;
position.vector3Value = localPos;
}

private void ReloadFilteredTree()
{
filtered = true;
lastFilter = filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ public void Awake()
ud.umaRoot = null;
}
}

#else
UMAData ud = GetComponent<UMAData>();

Expand Down Expand Up @@ -429,6 +430,21 @@ public void Awake()
cacheStates = new Dictionary<string, string>();
this.context = UMAContextBase.Instance;
}

#if UNITY_EDITOR
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnScriptsReloaded()
{
DynamicCharacterAvatar[] dcas = GameObject.FindObjectsOfType<DynamicCharacterAvatar>();
foreach (var dca in dcas)
{
if (dca.editorTimeGeneration)
{
dca.GenerateSingleUMA();
}
}
}
#endif
// Use this for initialization
public override void Start()
{
Expand Down
Loading

0 comments on commit 3d80d4e

Please sign in to comment.