Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Unity.Collections.LowLevel.Unsafe;

namespace UnityEngine.Perception.GroundTruth
{
Expand All @@ -22,14 +23,11 @@ public class PoseTimestampRecord
}

/// <summary>
/// The animation pose label is a mapping that file that maps a time range in an animation clip to a ground truth
/// pose. The timestamp record is defined by a pose label and a duration. The timestamp records are order dependent
/// and build on the previous entries. This means that if the first record has a duration of 5, then it will be the label
/// for all points in the clip from 0 (the beginning) to the five second mark. The next record will then go from the end
/// of the previous clip to its duration. If there is time left over in the flip, the final entry will be used.
/// The animation pose config is a configuration file that maps a time range in an animation clip to a ground truth
/// pose. The timestamp record is defined by a pose label and a start time. The timestamp records are order dependent.
/// </summary>
[CreateAssetMenu(fileName = "AnimationPoseTimestamp", menuName = "Perception/Animation Pose Timestamps")]
public class AnimationPoseLabel : ScriptableObject
[CreateAssetMenu(fileName = "AnimationPoseConfig", menuName = "Perception/Animation Pose Config")]
public class AnimationPoseConfig : ScriptableObject
{
/// <summary>
/// The animation clip used for all of the timestamps
Expand All @@ -40,22 +38,40 @@ public class AnimationPoseLabel : ScriptableObject
/// </summary>
public List<PoseTimestampRecord> timestamps;

SortedList<float, string> sortedTimestamps;
void OnEnable()
{
sortedTimestamps = new SortedList<float, string>(timestamps.Count);
foreach (var ts in timestamps)
{
sortedTimestamps.Add(ts.startOffsetPercent, ts.poseLabel);
}
}

const string k_Unset = "unset";

/// <summary>
/// Retrieves the pose for the clip at the current time.
/// </summary>
/// <param name="time">The time in question</param>
/// <returns>The pose for the passed in time</returns>
public string GetPoseAtTime(float time)
{
if (time < 0 || time > 1) return "unset";
if (time < 0 || time > 1) return k_Unset;
if (timestamps == null || !timestamps.Any()) return k_Unset;

// Special case code if there is only 1 timestamp in the config
if (sortedTimestamps.Keys.Count == 1)
{
return time > sortedTimestamps.Keys[0] ? sortedTimestamps.Values[0] : k_Unset;
}

var i = 1;
for (i = 1; i < timestamps.Count; i++)
for (var i = 0; i < sortedTimestamps.Keys.Count - 1; i++)
{
if (timestamps[i].startOffsetPercent > time) break;
if (time >= sortedTimestamps.Keys[i] && time <= sortedTimestamps.Keys[i + 1]) return sortedTimestamps.Values[i];
}

return timestamps[i - 1].poseLabel;
return time < sortedTimestamps.Keys.Last() ? k_Unset : sortedTimestamps.Values.Last();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using Unity.Collections;
using Unity.Entities;
using UnityEngine.Serialization;

namespace UnityEngine.Perception.GroundTruth
{
Expand Down Expand Up @@ -72,7 +73,7 @@ public KeyPointLabeler(IdLabelConfig config, KeyPointTemplate template)
/// <summary>
/// Array of animation pose labels which map animation clip times to ground truth pose labels.
/// </summary>
public AnimationPoseLabel[] poseStateConfigs;
public List<AnimationPoseConfig> animationPoseConfigs;

/// <inheritdoc/>
protected override void Setup()
Expand Down Expand Up @@ -331,11 +332,11 @@ string GetPose(Animator animator)
var clip = info[0].clip;
var timeOffset = animator.GetCurrentAnimatorStateInfo(0).normalizedTime;

if (poseStateConfigs != null)
if (animationPoseConfigs != null)
{
foreach (var p in poseStateConfigs)
foreach (var p in animationPoseConfigs)
{
if (p.animationClip == clip)
if (p != null && p.animationClip == clip)
{
var time = timeOffset;
var label = p.GetPoseAtTime(time);
Expand Down