Skip to content

Commit d822a32

Browse files
Pose config rename (#184)
* Converge on a single name for animation pose config * Assorted fixes for pose label config stability * Updated for PR comments Co-authored-by: Steven Leal <[email protected]>
1 parent 29b3d32 commit d822a32

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

com.unity.perception/Runtime/GroundTruth/Labelers/AnimationPoseLabel.cs renamed to com.unity.perception/Runtime/GroundTruth/Labelers/AnimationPoseConfig.cs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using Unity.Collections.LowLevel.Unsafe;
45

56
namespace UnityEngine.Perception.GroundTruth
67
{
@@ -22,14 +23,11 @@ public class PoseTimestampRecord
2223
}
2324

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

41+
SortedList<float, string> sortedTimestamps;
42+
void OnEnable()
43+
{
44+
sortedTimestamps = new SortedList<float, string>(timestamps.Count);
45+
foreach (var ts in timestamps)
46+
{
47+
sortedTimestamps.Add(ts.startOffsetPercent, ts.poseLabel);
48+
}
49+
}
50+
51+
const string k_Unset = "unset";
52+
4353
/// <summary>
4454
/// Retrieves the pose for the clip at the current time.
4555
/// </summary>
4656
/// <param name="time">The time in question</param>
4757
/// <returns>The pose for the passed in time</returns>
4858
public string GetPoseAtTime(float time)
4959
{
50-
if (time < 0 || time > 1) return "unset";
60+
if (time < 0 || time > 1) return k_Unset;
61+
if (timestamps == null || !timestamps.Any()) return k_Unset;
62+
63+
// Special case code if there is only 1 timestamp in the config
64+
if (sortedTimestamps.Keys.Count == 1)
65+
{
66+
return time > sortedTimestamps.Keys[0] ? sortedTimestamps.Values[0] : k_Unset;
67+
}
5168

52-
var i = 1;
53-
for (i = 1; i < timestamps.Count; i++)
69+
for (var i = 0; i < sortedTimestamps.Keys.Count - 1; i++)
5470
{
55-
if (timestamps[i].startOffsetPercent > time) break;
71+
if (time >= sortedTimestamps.Keys[i] && time <= sortedTimestamps.Keys[i + 1]) return sortedTimestamps.Values[i];
5672
}
5773

58-
return timestamps[i - 1].poseLabel;
74+
return time < sortedTimestamps.Keys.Last() ? k_Unset : sortedTimestamps.Values.Last();
5975
}
6076
}
6177
}

com.unity.perception/Runtime/GroundTruth/Labelers/AnimationPoseLabel.cs.meta renamed to com.unity.perception/Runtime/GroundTruth/Labelers/AnimationPoseConfig.cs.meta

File renamed without changes.

com.unity.perception/Runtime/GroundTruth/Labelers/KeyPointLabeler.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using Unity.Collections;
55
using Unity.Entities;
6+
using UnityEngine.Serialization;
67

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

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

334-
if (poseStateConfigs != null)
335+
if (animationPoseConfigs != null)
335336
{
336-
foreach (var p in poseStateConfigs)
337+
foreach (var p in animationPoseConfigs)
337338
{
338-
if (p.animationClip == clip)
339+
if (p != null && p.animationClip == clip)
339340
{
340341
var time = timeOffset;
341342
var label = p.GetPoseAtTime(time);

0 commit comments

Comments
 (0)