Skip to content

Commit

Permalink
Add Bone Name to Could Not Reset Bone Error
Browse files Browse the repository at this point in the history
Since performance gets impacted heavily when these errors occur, it
would be nice to have more information
  • Loading branch information
davidosullivan committed Mar 29, 2016
1 parent dfad553 commit 0db81ca
Showing 1 changed file with 115 additions and 90 deletions.
205 changes: 115 additions & 90 deletions UMAProject/Assets/Standard Assets/UMA/Core/Scripts/UMAExpressionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,104 +10,129 @@

namespace UMA.PoseTools
{
/// <summary>
/// UMA expression set. Groups poses for expression player channels.
/// </summary>
[System.Serializable]
public class UMAExpressionSet : ScriptableObject
{
/// <summary>
/// Pair of mutually exclusive expressions which can share a curve.
/// </summary>
[System.Serializable]
public class PosePair
{
public UMABonePose primary = null;
public UMABonePose inverse = null;
}
/// <summary>
/// The pose pairs for each expression channel.
/// </summary>
public PosePair[] posePairs = new PosePair[UMAExpressionPlayer.PoseCount];
/// <summary>
/// UMA expression set. Groups poses for expression player channels.
/// </summary>
[System.Serializable]
public class UMAExpressionSet : ScriptableObject
{
/// <summary>
/// Pair of mutually exclusive expressions which can share a curve.
/// </summary>
[System.Serializable]
public class PosePair
{
public UMABonePose primary = null;
public UMABonePose inverse = null;
}
/// <summary>
/// The pose pairs for each expression channel.
/// </summary>
public PosePair[] posePairs = new PosePair[UMAExpressionPlayer.PoseCount];

[System.NonSerialized]
private int[] boneHashes = null;
[System.NonSerialized]
private int[] boneHashes = null;

private void ValidateBoneHashes()
{
if (boneHashes == null)
{
List<int> boneHashList = new List<int>();
foreach (PosePair pair in posePairs)
{
if (pair.primary != null)
{
foreach (UMABonePose.PoseBone bone in pair.primary.poses)
{
if (!boneHashList.Contains(bone.hash))
{
boneHashList.Add(bone.hash);
}
}
}
if (pair.inverse != null)
{
foreach (UMABonePose.PoseBone bone in pair.inverse.poses)
{
if (!boneHashList.Contains(bone.hash))
{
boneHashList.Add(bone.hash);
}
}
}
}
private void ValidateBoneHashes()
{
if (boneHashes == null)
{
List<int> boneHashList = new List<int>();
foreach (PosePair pair in posePairs)
{
if (pair.primary != null)
{
foreach (UMABonePose.PoseBone bone in pair.primary.poses)
{
if (!boneHashList.Contains(bone.hash))
{
boneHashList.Add(bone.hash);
}
}
}
if (pair.inverse != null)
{
foreach (UMABonePose.PoseBone bone in pair.inverse.poses)
{
if (!boneHashList.Contains(bone.hash))
{
boneHashList.Add(bone.hash);
}
}
}
}

boneHashes = boneHashList.ToArray();
}
}
boneHashes = boneHashList.ToArray();
}
}

/// <summary>
/// Resets all the bones used by poses in the set to default position.
/// </summary>
/// <param name="umaSkeleton">Skeleton to be reset.</param>
public void ResetBones(UMASkeleton umaSkeleton)
{
if (umaSkeleton == null) return;
/// <summary>
/// Resets all the bones used by poses in the set to default position.
/// </summary>
/// <param name="umaSkeleton">Skeleton to be reset.</param>
public void ResetBones(UMASkeleton umaSkeleton)
{
if (umaSkeleton == null) return;

ValidateBoneHashes();
ValidateBoneHashes();

foreach (int hash in boneHashes)
{
if (!umaSkeleton.Reset(hash))
{
Debug.LogWarning("Couldn't reset bone!");
}
}
}
foreach (int hash in boneHashes)
{
if (!umaSkeleton.Reset(hash))
{
//Since this generally logs like crazy which screws everything anyway, it might be nice to provide some useful information?
string boneName = "";
foreach (PosePair pair in posePairs)
{
if (pair.primary != null)
{
foreach (UMABonePose.PoseBone bone in pair.primary.poses)
{
if (bone.hash == hash)
{
boneName = bone.bone;
}
}
}
if (pair.inverse != null)
{
foreach (UMABonePose.PoseBone bone in pair.inverse.poses)
{
if (bone.hash == hash)
{
boneName = bone.bone;
}
}
}
}
Debug.LogWarning("Couldn't reset bone! " + boneName);
}
}
}

public int[] GetAnimatedBoneHashes()
{
ValidateBoneHashes();
return boneHashes;
}
public int[] GetAnimatedBoneHashes()
{
ValidateBoneHashes();
return boneHashes;
}

/// <summary>
/// Gets the transforms for all animated bones.
/// </summary>
/// <returns>Array of transforms.</returns>
/// <param name="umaSkeleton">Skeleton containing transforms.</param>
public Transform[] GetAnimatedBones(UMASkeleton umaSkeleton)
{
if (umaSkeleton == null) return null;
/// <summary>
/// Gets the transforms for all animated bones.
/// </summary>
/// <returns>Array of transforms.</returns>
/// <param name="umaSkeleton">Skeleton containing transforms.</param>
public Transform[] GetAnimatedBones(UMASkeleton umaSkeleton)
{
if (umaSkeleton == null) return null;

ValidateBoneHashes();
ValidateBoneHashes();

var res = new Transform[boneHashes.Length];
for(int i = 0; i < boneHashes.Length; i++ )
{
res[i] = umaSkeleton.GetBoneGameObject(boneHashes[i]).transform;
}
return res;
}
}
var res = new Transform[boneHashes.Length];
for (int i = 0; i < boneHashes.Length; i++)
{
res[i] = umaSkeleton.GetBoneGameObject(boneHashes[i]).transform;
}
return res;
}
}
}

0 comments on commit 0db81ca

Please sign in to comment.