11using System ;
22using System . Collections . Generic ;
33using System . Linq ;
4+ using Unity . Collections . LowLevel . Unsafe ;
45
56namespace 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}
0 commit comments