浏览代码
Pose config rename (#184)
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 <steven.leal@unity3d.com>/main
GitHub
4 年前
当前提交
ed1b1a8e
共有 4 个文件被更改,包括 82 次插入 和 65 次删除
-
9com.unity.perception/Runtime/GroundTruth/Labelers/KeyPointLabeler.cs
-
77com.unity.perception/Runtime/GroundTruth/Labelers/AnimationPoseConfig.cs
-
61com.unity.perception/Runtime/GroundTruth/Labelers/AnimationPoseLabel.cs
-
0/com.unity.perception/Runtime/GroundTruth/Labelers/AnimationPoseConfig.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Unity.Collections.LowLevel.Unsafe; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
/// <summary>
|
|||
/// Record that maps a pose to a timestamp
|
|||
/// </summary>
|
|||
[Serializable] |
|||
public class PoseTimestampRecord |
|||
{ |
|||
/// <summary>
|
|||
/// The percentage within the clip that the pose starts, a value from 0 (beginning) to 1 (end)
|
|||
/// </summary>
|
|||
[Tooltip("The percentage within the clip that the pose starts, a value from 0 (beginning) to 1 (end)")] |
|||
public float startOffsetPercent; |
|||
/// <summary>
|
|||
/// The label to use for any captures inside of this time period
|
|||
/// </summary>
|
|||
public string poseLabel; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 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 = "AnimationPoseConfig", menuName = "Perception/Animation Pose Config")] |
|||
public class AnimationPoseConfig : ScriptableObject |
|||
{ |
|||
/// <summary>
|
|||
/// The animation clip used for all of the timestamps
|
|||
/// </summary>
|
|||
public AnimationClip animationClip; |
|||
/// <summary>
|
|||
/// The list of timestamps, order dependent
|
|||
/// </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 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; |
|||
} |
|||
|
|||
for (var i = 0; i < sortedTimestamps.Keys.Count - 1; i++) |
|||
{ |
|||
if (time >= sortedTimestamps.Keys[i] && time <= sortedTimestamps.Keys[i + 1]) return sortedTimestamps.Values[i]; |
|||
} |
|||
|
|||
return time < sortedTimestamps.Keys.Last() ? k_Unset : sortedTimestamps.Values.Last(); |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
/// <summary>
|
|||
/// Record that maps a pose to a timestamp
|
|||
/// </summary>
|
|||
[Serializable] |
|||
public class PoseTimestampRecord |
|||
{ |
|||
/// <summary>
|
|||
/// The percentage within the clip that the pose starts, a value from 0 (beginning) to 1 (end)
|
|||
/// </summary>
|
|||
[Tooltip("The percentage within the clip that the pose starts, a value from 0 (beginning) to 1 (end)")] |
|||
public float startOffsetPercent; |
|||
/// <summary>
|
|||
/// The label to use for any captures inside of this time period
|
|||
/// </summary>
|
|||
public string poseLabel; |
|||
} |
|||
|
|||
/// <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.
|
|||
/// </summary>
|
|||
[CreateAssetMenu(fileName = "AnimationPoseTimestamp", menuName = "Perception/Animation Pose Timestamps")] |
|||
public class AnimationPoseLabel : ScriptableObject |
|||
{ |
|||
/// <summary>
|
|||
/// The animation clip used for all of the timestamps
|
|||
/// </summary>
|
|||
public AnimationClip animationClip; |
|||
/// <summary>
|
|||
/// The list of timestamps, order dependent
|
|||
/// </summary>
|
|||
public List<PoseTimestampRecord> timestamps; |
|||
|
|||
/// <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"; |
|||
|
|||
var i = 1; |
|||
for (i = 1; i < timestamps.Count; i++) |
|||
{ |
|||
if (timestamps[i].startOffsetPercent > time) break; |
|||
} |
|||
|
|||
return timestamps[i - 1].poseLabel; |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue