|
|
|
|
|
|
AnnotationDefinition m_AnnotationDefinition; |
|
|
|
Texture2D m_MissingTexture; |
|
|
|
|
|
|
|
Dictionary<int, (AsyncAnnotation annotation, Dictionary<uint, KeypointEntry> keypoints)> m_AsyncAnnotations; |
|
|
|
Dictionary<int, (AsyncAnnotation annotation, List<KeypointEntry> keypoints, List<float> zValues)> m_AsyncAnnotations; |
|
|
|
List<KeypointEntry> m_KeypointEntriesToReport; |
|
|
|
|
|
|
|
int m_CurrentFrame; |
|
|
|
|
|
|
|
|
|
|
var dimensions = (renderTexture.width, renderTexture.height); |
|
|
|
|
|
|
|
foreach (var keypointSet in asyncAnnotation.keypoints) |
|
|
|
foreach (var keypointEntry in asyncAnnotation.keypoints) |
|
|
|
if (InstanceIdToColorMapping.TryGetColorFromInstanceId(keypointSet.Key, out var idColor)) |
|
|
|
if (InstanceIdToColorMapping.TryGetColorFromInstanceId(keypointEntry.instance_id, out var idColor)) |
|
|
|
foreach (var keypoint in keypointSet.Value.keypoints) |
|
|
|
foreach (var keypoint in keypointEntry.keypoints) |
|
|
|
{ |
|
|
|
keypoint.state = DetermineKeypointState(keypoint, idColor, dimensions, data); |
|
|
|
|
|
|
|
|
|
|
m_KeypointEntriesToReport.Clear(); |
|
|
|
|
|
|
|
//filter out objects that are not visible
|
|
|
|
foreach (var keypointSet in asyncAnnotation.keypoints) |
|
|
|
foreach (var entry in asyncAnnotation.keypoints) |
|
|
|
var entry = keypointSet.Value; |
|
|
|
|
|
|
|
var include = false; |
|
|
|
if (objectFilter == KeypointObjectFilter.All) |
|
|
|
include = true; |
|
|
|
|
|
|
{ |
|
|
|
include = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
include = keypointSet.Value.keypoints.Any(k => k.state == 1); |
|
|
|
} |
|
|
|
include = entry.keypoints.Any(k => k.state == 1); |
|
|
|
} |
|
|
|
if (include) |
|
|
|
m_KeypointEntriesToReport.Add(entry); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
struct KeypointDepthCheckData |
|
|
|
{ |
|
|
|
private float3 position; |
|
|
|
public float3 position; |
|
|
|
} |
|
|
|
|
|
|
|
/// <param name="scriptableRenderContext"></param>
|
|
|
|
|
|
|
m_CurrentFrame = Time.frameCount; |
|
|
|
|
|
|
|
var annotation = perceptionCamera.SensorHandle.ReportAnnotationAsync(m_AnnotationDefinition); |
|
|
|
var keypoints = new Dictionary<uint, KeypointEntry>(); |
|
|
|
var keypointEntries = new List<KeypointEntry>(); |
|
|
|
m_AsyncAnnotations[m_CurrentFrame] = (annotation, keypoints); |
|
|
|
m_AsyncAnnotations[m_CurrentFrame] = (annotation, keypointEntries); |
|
|
|
var keypointCount = keypoints.Count * activeTemplate.keypoints.Length; |
|
|
|
var keypointCount = keypointEntries.Count * activeTemplate.keypoints.Length; |
|
|
|
commandBuffer.SetComputeTextureParam(m_KeypointDepthTestShader, 0, "depth", depthTexture); |
|
|
|
commandBuffer.SetComputeTextureParam(m_KeypointDepthTestShader, 0, "DepthBuffer", depthTexture); |
|
|
|
int index = 0; |
|
|
|
foreach (var keypointEntry in keypointEntries) |
|
|
|
{ |
|
|
|
foreach (var keypoint in keypointEntry.keypoints) |
|
|
|
{ |
|
|
|
keypointDepthCheckData[index++] = new KeypointDepthCheckData() |
|
|
|
{ |
|
|
|
position = new float3(keypoint.x, keypoint.y) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
commandBuffer.SetComputeBufferParam(m_KeypointDepthTestShader, 0, "keypoints", keypointDataComputeBuffer); |
|
|
|
commandBuffer.SetComputeBufferParam(m_KeypointDepthTestShader, 0, "CheckPositions", keypointDataComputeBuffer); |
|
|
|
commandBuffer.SetComputeBufferParam(m_KeypointDepthTestShader, 0, "CheckResults", resultsComputeBuffer); |
|
|
|
|
|
|
|
commandBuffer.RequestAsyncReadback(resultsComputeBuffer, OnDepthCheckReadback); |
|
|
|
private void OnDepthCheckReadback(AsyncGPUReadbackRequest obj) |
|
|
|
{ |
|
|
|
var data = obj.GetData<uint>(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
// ReSharper disable NotAccessedField.Global
|
|
|
|
// ReSharper disable NotAccessedField.Local
|
|
|
|
|
|
|
/// The values of a specific keypoint
|
|
|
|
/// </summary>
|
|
|
|
[Serializable] |
|
|
|
public class Keypoint |
|
|
|
public struct Keypoint |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// The index of the keypoint in the template file
|
|
|
|
|
|
|
public bool status; |
|
|
|
public Animator animator; |
|
|
|
public KeypointEntry keypoints; |
|
|
|
public List<float> zValues; |
|
|
|
public List<(JointLabel, int)> overrides; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
status = false, |
|
|
|
animator = null, |
|
|
|
keypoints = new KeypointEntry(), |
|
|
|
overrides = new List<(JointLabel, int)>() |
|
|
|
overrides = new List<(JointLabel, int)>(), |
|
|
|
zValues = new List<float>(activeTemplate.keypoints.Length) |
|
|
|
}; |
|
|
|
|
|
|
|
var entityGameObject = labeledEntity.gameObject; |
|
|
|
|
|
|
var bone = animator.GetBoneTransform(pt.rigLabel); |
|
|
|
if (bone != null) |
|
|
|
{ |
|
|
|
InitKeypoint(bone.position, keypoints, i); |
|
|
|
InitKeypoint(bone.position, cachedData, i); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
foreach (var (joint, idx) in cachedData.overrides) |
|
|
|
{ |
|
|
|
InitKeypoint(joint.transform.position, keypoints, idx); |
|
|
|
InitKeypoint(joint.transform.position, cachedData, idx); |
|
|
|
} |
|
|
|
|
|
|
|
cachedData.keypoints.pose = "unset"; |
|
|
|
|
|
|
cachedData.keypoints.pose = GetPose(cachedData.animator); |
|
|
|
} |
|
|
|
|
|
|
|
m_AsyncAnnotations[m_CurrentFrame].keypoints[labeledEntity.instanceId] = cachedData.keypoints; |
|
|
|
m_AsyncAnnotations[m_CurrentFrame].keypoints.Add(cachedData.keypoints); |
|
|
|
private void InitKeypoint(Vector3 position, Keypoint[] keypoints, int idx) |
|
|
|
private void InitKeypoint(Vector3 position, CachedData cachedData, int idx) |
|
|
|
cachedData.zValues[idx] = position.z; |
|
|
|
var keypoints = cachedData.keypoints.keypoints; |
|
|
|
keypoints[idx].index = idx; |
|
|
|
if (loc.z < 0) |
|
|
|
{ |
|
|
|