浏览代码

I think I have the timings working now

/solo_support
Steve Borkman 3 年前
当前提交
0fce16c7
共有 49 个文件被更改,包括 1632 次插入365 次删除
  1. 11
      TestProjects/PerceptionURP/Assets/ExampleScripts/CustomAnnotationAndMetricReporter.cs
  2. 1
      com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs
  3. 26
      com.unity.perception/Editor/GroundTruth/Uss/Styles.uss
  4. 19
      com.unity.perception/Runtime/GroundTruth/ConsumerEndpoint.cs
  5. 4
      com.unity.perception/Runtime/GroundTruth/Consumers/OldPerceptionConsumer.cs
  6. 46
      com.unity.perception/Runtime/GroundTruth/Consumers/SoloConsumer.cs
  7. 8
      com.unity.perception/Runtime/GroundTruth/Consumers/SoloMessageBuilder.cs
  8. 31
      com.unity.perception/Runtime/GroundTruth/DataModel.cs
  9. 328
      com.unity.perception/Runtime/GroundTruth/DatasetCapture.cs
  10. 2
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBox3DLabeler.cs
  11. 19
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs
  12. 3
      com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs
  13. 2
      com.unity.perception/Runtime/GroundTruth/Labelers/KeypointLabeler.cs
  14. 2
      com.unity.perception/Runtime/GroundTruth/Labelers/ObjectCountLabeler.cs
  15. 2
      com.unity.perception/Runtime/GroundTruth/Labelers/SemanticSegmentationLabeler.cs
  16. 49
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  17. 8
      com.unity.perception/Runtime/GroundTruth/PerceptionUpdater.cs
  18. 268
      com.unity.perception/Runtime/GroundTruth/SimulationState.cs
  19. 23
      com.unity.perception/Runtime/GroundTruth/SimulationState_Json.cs
  20. 2
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/AnimationRandomizer.cs
  21. 46
      com.unity.perception/Runtime/Randomization/Scenarios/PerceptionScenario.cs
  22. 14
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
  23. 127
      com.unity.perception/Tests/Runtime/GroundTruthTests/DatasetCaptureSensorSchedulingTests.cs
  24. 178
      com.unity.perception/Tests/Runtime/GroundTruthTests/DatasetCaptureTests.cs
  25. 9
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/TestFixedLengthScenario.cs
  26. 8
      com.unity.perception/Editor/GroundTruth/DatasetConsumer.meta
  27. 27
      com.unity.perception/Runtime/GroundTruth/Consumers/NoOpConsumer.cs
  28. 11
      com.unity.perception/Runtime/GroundTruth/Consumers/NoOpConsumer.cs.meta
  29. 253
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/AddConsumerEndpointMenu.cs
  30. 11
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/AddConsumerEndpointMenu.cs.meta
  31. 14
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/AddConsumerEndpointMenuAttribute.cs
  32. 11
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/AddConsumerEndpointMenuAttribute.cs.meta
  33. 79
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/ConsumerEndpointElement.cs
  34. 11
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/ConsumerEndpointElement.cs.meta
  35. 31
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/DatasetCaptureEditor.cs
  36. 11
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/DatasetCaptureEditor.cs.meta
  37. 111
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/EndpointList.cs
  38. 11
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/EndpointList.cs.meta
  39. 93
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/StaticData.cs
  40. 11
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/StaticData.cs.meta
  41. 8
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/Uxml.meta
  42. 16
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/Uxml/ConsumerEndpointElement.uxml
  43. 10
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/Uxml/ConsumerEndpointElement.uxml.meta
  44. 6
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/Uxml/DatasetCaptureElement.uxml
  45. 10
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/Uxml/DatasetCaptureElement.uxml.meta
  46. 16
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/Uxml/EndpointList.uxml
  47. 10
      com.unity.perception/Editor/GroundTruth/DatasetConsumer/Uxml/EndpointList.uxml.meta

11
TestProjects/PerceptionURP/Assets/ExampleScripts/CustomAnnotationAndMetricReporter.cs


[RequireComponent(typeof(PerceptionCamera))]
public class CustomAnnotationAndMetricReporter : MonoBehaviour
{
DatasetCapture _DatasetCapture;
internal DatasetCapture DatasetCapture
{
get
{
if (_DatasetCapture == null) _DatasetCapture = GameObject.Find("DatasetCapture").GetComponent<DatasetCapture>();
return _DatasetCapture;
}
}
public GameObject targetLight;
public GameObject target;

1
com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs


using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.Perception.GroundTruth.DataModel;
using UnityEngine.Perception.GroundTruth.Exporters;
namespace UnityEditor.Perception.GroundTruth

26
com.unity.perception/Editor/GroundTruth/Uss/Styles.uss


margin-top: 4px;
margin-bottom: 4px;
}
/* Dataset capture and endpoints */
.dataset-capture__info-box {
border-width: 1px;
border-color: #808080;
padding: 7px;
border-radius: 4px;
white-space: normal;
margin: 3px 3px 3px 3px;
}
.dataset-capture__error-box {
color: #FF4040;
}
.dataset-capture__dark-viewport {
border-radius: 5px;
background-color: #191919;
padding: 2px;
}
.dataset-capture__title-label {
-unity-font-style: bold;
margin: 3px 3px 3px 3px;
color: #CACACA;
}

19
com.unity.perception/Runtime/GroundTruth/ConsumerEndpoint.cs


using UnityEngine.Perception.GroundTruth.DataModel;
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Simulation;
using UnityEngine.Perception.GroundTruth.DataModel;
public abstract class ConsumerEndpoint : MonoBehaviour
public abstract class ConsumerEndpoint
IEnumerator WaitForComplete()
{
yield return new WaitUntil(IsComplete);
}
#if false
public virtual bool IsComplete => true;
#else
protected abstract bool IsComplete();
#endif
/// <summary>
/// Called when the simulation begins. Provides simulation wide metadata to
/// the consumer.

4
com.unity.perception/Runtime/GroundTruth/Consumers/OldPerceptionConsumer.cs


Dictionary<int, Guid> m_SequenceToGuidMap = new Dictionary<int, Guid>();
List<PerceptionCapture> m_CurrentCaptures = new List<PerceptionCapture>();
void Start()
protected override bool IsComplete()
// Only here to get the check mark to show up in Unity Editor
return true;
}
internal string VerifyDirectoryWithGuidExists(string directoryPrefix, bool appendGuid = true)

46
com.unity.perception/Runtime/GroundTruth/Consumers/SoloConsumer.cs


{
public string _baseDirectory = "D:/PerceptionOutput/SoloConsumer";
public string soloDatasetName = "solo";
static string currentDirectory = "";
static string currentDirectory = "";
void Start()
bool m_IsComplete = false;
protected override bool IsComplete()
// Only here to get the check mark to show up in Unity Editor
return m_IsComplete;
}
public override void OnSimulationStarted(SimulationMetadata metadata)

path = Path.Combine(path, $"step{frame.step}.frame_data.json");
WriteJTokenToFile(path, ToFrame(frame));
Debug.Log("SC - On Frame Generated");
Debug.Log("SC - On Simulation Completed");
var path = Path.Combine(currentDirectory, "metadata.json");
WriteJTokenToFile(path, ToMetadata(metadata));
m_IsComplete = true;
}
static JToken ToMetadata(CompletionMetadata metadata)
{
var sequences = new JArray();
if (metadata.sequences != null)
{
foreach (var sequence in metadata.sequences)
{
sequences.Add(new JObject
{
["id"] = sequence.id,
["number_of_steps"] = sequence.numberOfSteps
});
}
sequences.Add(new JObject());
}
var json = new JObject
{
["unity_version"] = metadata.unityVersion,
["perception_version"] = metadata.perceptionVersion,
["render_pipeline"] = metadata.renderPipeline,
["total_frames"] = metadata.totalFrames,
["sequences"] = sequences
};
return json;
}
static JToken ToFrame(Frame frame)

var path = GetSequenceDirectoryPath(frame);
path = Path.Combine(path, $"step{frame.step}.{sensor.sensorType}.{sensor.imageFormat}");
#if true
#endif
var outRgb = ToSensorHeader(frame, sensor);
outRgb["fileName"] = path;
outRgb["imageFormat"] = sensor.imageFormat;

8
com.unity.perception/Runtime/GroundTruth/Consumers/SoloMessageBuilder.cs


public string soloDatasetName = "solo_mb";
static string currentDirectory = "";
SimulationMetadata m_CurrentMetadata;
void Start()
protected override bool IsComplete()
// Only here to get the check mark to show up in Unity Editor
return true;
SimulationMetadata m_CurrentMetadata;
public override void OnSimulationStarted(SimulationMetadata metadata)
{

31
com.unity.perception/Runtime/GroundTruth/DataModel.cs


void ToMessage(IMessageBuilder builder);
}
/// <summary>
/// Capture trigger modes for sensors.
/// </summary>
public enum CaptureTriggerMode
{
/// <summary>
/// Captures happen automatically based on a start frame and frame delta time.
/// </summary>
Scheduled,
/// <summary>
/// Captures should be triggered manually through calling the manual capture method of the sensor using this trigger mode.
/// </summary>
Manual
}
[Serializable]
public class SensorDefinition : IMessageProducer
{

this.modality = modality;
this.definition = definition;
this.firstCaptureFrame = 0;
this.captureTriggerMode = string.Empty;
this.simulationDeltaTime = 0.0f;
this.framesBetweenCaptures = 0;
this.manualSensorsAffectTiming = false;
firstCaptureFrame = 0;
captureTriggerMode = CaptureTriggerMode.Scheduled;
simulationDeltaTime = 0.0f;
framesBetweenCaptures = 0;
manualSensorsAffectTiming = false;
}
public virtual bool IsValid()

public string modality;
public string definition;
public float firstCaptureFrame;
public string captureTriggerMode;
public CaptureTriggerMode captureTriggerMode;
public float simulationDeltaTime;
public int framesBetweenCaptures;
public bool manualSensorsAffectTiming;

builder.AddString("modality", modality);
builder.AddString("definition", definition);
builder.AddFloat("first_capture_frame", firstCaptureFrame);
builder.AddString("capture_trigger_mode", captureTriggerMode);
builder.AddString("capture_trigger_mode", captureTriggerMode.ToString());
builder.AddFloat("simulation_delta_time", simulationDeltaTime);
builder.AddInt("frames_between_captures", framesBetweenCaptures);
builder.AddBoolean("manual_sensors_affect_timing", manualSensorsAffectTiming);

{
public SimulationMetadata()
{
unityVersion = "figure out how to do unity version";
unityVersion = "not_set";
perceptionVersion = "0.8.0-preview.4";
#if HDRP_PRESENT
renderPipeline = "HDRP";

328
com.unity.perception/Runtime/GroundTruth/DatasetCapture.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine.Perception.GroundTruth.Consumers;
using UnityEngine.Rendering;
#if UNITY_EDITOR
[InitializeOnLoad]
public static class EditModePlayStateController
{
public static bool s_Done = false;
public static bool Done
{
get => s_Done;
set
{
if (value)
{
s_Done = true;
EditorApplication.isPlaying = false;
}
}
}
static bool toggle = true;
static EditModePlayStateController()
{
EditorApplication.playModeStateChanged += state =>
{
if (state == PlayModeStateChange.ExitingPlayMode)
{
EditorApplication.isPlaying = toggle;
toggle = !toggle;
// EditorApplication.isPlaying = !Done;
}
};
}
}
#endif
public class DatasetCapture : MonoBehaviour
public class DatasetCapture
public static DatasetCapture Instance { get; protected set; }
public ConsumerEndpoint activeConsumer;
#if false
public static DatasetCapture Instance { get; private set; }
#else
static DatasetCapture s_Instance;
public static DatasetCapture Instance
{
get { return s_Instance ?? (s_Instance = new DatasetCapture()); }
}
#endif
ConsumerEndpoint m_ActiveConsumer;
List<ConsumerEndpoint> m_Endpoints = new List<ConsumerEndpoint>();
public IEnumerable<ConsumerEndpoint> consumerEndpoints => m_Endpoints.AsReadOnly();
public bool ReadyToShutdown => m_ReadyToShutdown && !m_OldSimStates.Any();
class ShutdownCondition : ICondition
{
public bool HasConditionBeenMet()
{
if (DatasetCapture.Instance.ReadyToShutdown)
{
Debug.Log("Triggered dc ready");
}
return DatasetCapture.Instance.ReadyToShutdown;
}
}
DatasetCapture()
{
Manager.Instance.ShutdownCondition = new ShutdownCondition();
//Manager.Instance.ShutdownCondition = new ShutdownCondition();
Manager.Instance.ShutdownNotification += OnApplicationShutdown;
}
List<SimulationState> m_OldSimStates = new List<SimulationState>();
internal SimulationState simulationState
{
get
{
if (m_SimulationState == null)
{
m_SimulationState = CreateSimulationData();
m_SimulationState.consumerEndpoint = CreateConsumerEndpoint(typeof(SoloConsumer));
}
return m_SimulationState;
}
private set { m_SimulationState = value; }
}
public bool RegisterConsumer(ConsumerEndpoint endpoint)
{
// TODO error detection about active consumer already set...
m_ActiveConsumer = endpoint;
return true;
}
public bool UnregisterConsumer(ConsumerEndpoint endpoint)
{
m_ActiveConsumer = null;
return true;
}
public ConsumerEndpoint ActiveConsumer => m_ActiveConsumer;
internal void AddConsumerEndpoint(ConsumerEndpoint endpoint)
{
m_ActiveConsumer = endpoint;
}
internal void RemoveConsumerEndpointAt(int index)
{
Debug.Log("RemoveConsumerEndpointAt has not been implemented yet");
}
internal ConsumerEndpoint GetConsumerEndpoint(int index)
{
Debug.Log("RemoveConsumerEndpointAt has not been implemented yet");
return m_ActiveConsumer;
}
internal void InsertConsumerEndpoint(int index, ConsumerEndpoint endpoint)
{
Debug.Log("InsertConsumerEndpoint has not been implemented yet");
}
internal ConsumerEndpoint CreateConsumerEndpoint(Type endpointType)
{
if (!endpointType.IsSubclassOf(typeof(ConsumerEndpoint)))
throw new InvalidOperationException($"Cannot add non-endpoint type {endpointType.Name} to consumer endpoint list");
var newEndpoint = (ConsumerEndpoint)Activator.CreateInstance(endpointType);
AddConsumerEndpoint(newEndpoint);
return newEndpoint;
}
#if false
void Awake()
{
if (Instance != null && Instance != this)

else
{
Instance = this;
}
}
internal SimulationState simulationState
{
get { return m_SimulationState ?? (m_SimulationState = CreateSimulationData()); }
private set => m_SimulationState = value;
}
#if UNITY_EDITOR
EditorApplication.playModeStateChanged += (x) =>
{
Debug.Log("On playmode changed");
};
Manager.Instance.ShutdownNotification += OnApplicationShutdown;
EditorApplication.wantsToQuit += () =>
{
if (m_HijackQuit)
{
// StartCoroutine(ResetSimulation());
m_HijackQuit = false;
return false;
}
return true;
};
#else
Application.wantsToQuit += () =>
{
if (m_HijackQuit)
{
StartCoroutine(ResetSimulation());
m_HijackQuit = false;
return false;
}
return true;
};
#endif
}
}
#endif
public static string PerceptionVersion => "0.8.0-preview.4";
public event Action SimulationEnding;
public event Action SimulationEnding;
public SensorHandle RegisterSensor(SensorDefinition sensor)
{

/// <summary>
/// Starts a new sequence in the capture.
/// </summary>
public void StartNewSequence() => simulationState.StartNewSequence();
public void StartNewSequence() => simulationState.StartNewSequence();
internal bool IsValid(string id) => simulationState.Contains(id);

}
[RuntimeInitializeOnLoadMethod]
void OnInitializeOnLoad()
void OnInitializeOnLoad()
Manager.Instance.ShutdownNotification += ResetSimulation;
Manager.Instance.ShutdownNotification += OnApplicationShutdown;
}
void OnApplicationQuit()
{
ResetSimulation();
// StartCoroutine(ResetSimulation());
void OnDisable()
{
// StartCoroutine(ResetSimulation());
}
void OnDestroy()
{
Debug.Log("ON Destroy");
}
bool m_ReadyToShutdown = false;
void OnApplicationShutdown()
{
Debug.Log("On application Quit");
ResetSimulation();
m_ReadyToShutdown = true;
// Manager.Instance.ShutdownAfterFrames(5);
// Manager.Instance.Shutdown();
// StartCoroutine(ResetSimulation());
}
#if false
public void ResetSimulation()
public IEnumerator ResetSimulation()
oldSimulationState.End();
simulationState.consumerEndpoint = CreateConsumerEndpoint(typeof(SoloConsumer));
yield return StartCoroutine(oldSimulationState.End());
if (!m_HijackQuit) Application.Quit();
}
/// <summary>
/// Capture trigger modes for sensors.
/// </summary>
public enum CaptureTriggerMode
{
/// <summary>
/// Captures happen automatically based on a start frame and frame delta time.
/// </summary>
Scheduled,
/// <summary>
/// Captures should be triggered manually through calling the manual capture method of the sensor using this trigger mode.
/// </summary>
Manual
#else
public void Update()
{
simulationState.Update();
List<SimulationState> toClear = new List<SimulationState>();
foreach (var oldie in m_OldSimStates)
{
oldie.TryToClearOut();
}
m_OldSimStates.RemoveAll(oldie => oldie.ReadyToShutdown);
if (m_ReadyToShutdown)
{
Debug.Log("stop here");
}
EditModePlayStateController.Done = m_ReadyToShutdown && !m_OldSimStates.Any();
}
public void ResetSimulation()
{
// Manager.Instance.Shutdown();
SimulationEnding?.Invoke();
var oldState = simulationState;
simulationState = CreateSimulationData();
simulationState.consumerEndpoint = CreateConsumerEndpoint(typeof(SoloConsumer));
m_OldSimStates.Add(oldState);
oldState.End();
m_ReadyToShutdown = true;
}
#endif
}
public enum FutureType

bool IsPending();
}
public struct AsyncSensorFuture : IAsyncFuture<SimulationState.SPendingSensorId>
public struct AsyncSensorFuture : IAsyncFuture<SimulationState.PendingSensorId>
public AsyncSensorFuture(SimulationState.SPendingSensorId id, SimulationState simulationState)
public AsyncSensorFuture(SimulationState.PendingSensorId id, SimulationState simulationState)
SimulationState.SPendingSensorId m_Id;
SimulationState.PendingSensorId m_Id;
public SimulationState.SPendingSensorId GetId()
public SimulationState.PendingSensorId GetId()
{
return m_Id;
}

}
}
public struct AsyncAnnotationFuture : IAsyncFuture<SimulationState.SPendingCaptureId>
public struct AsyncAnnotationFuture : IAsyncFuture<SimulationState.PendingCaptureId>
public AsyncAnnotationFuture(SimulationState.SPendingCaptureId id, SimulationState simulationState)
public AsyncAnnotationFuture(SimulationState.PendingCaptureId id, SimulationState simulationState)
SimulationState.SPendingCaptureId m_Id;
SimulationState.PendingCaptureId m_Id;
public SimulationState.SPendingCaptureId GetId()
public SimulationState.PendingCaptureId GetId()
{
return m_Id;
}

}
}
public struct AsyncMetricFuture : IAsyncFuture<SimulationState.SPendingCaptureId>
public struct AsyncMetricFuture : IAsyncFuture<SimulationState.PendingCaptureId>
public AsyncMetricFuture(SimulationState.SPendingCaptureId id, SimulationState simulationState)
public AsyncMetricFuture(SimulationState.PendingCaptureId id, SimulationState simulationState)
SimulationState.SPendingCaptureId m_Id;
SimulationState.PendingCaptureId m_Id;
public SimulationState.SPendingCaptureId GetId()
public SimulationState.PendingCaptureId GetId()
{
return m_Id;
}

return DatasetCapture.Instance.simulationState.ReportAnnotationAsync(annotationDefinition, this);
}
public AsyncSensorFuture ReportSensorAsync(SensorDefinition sensorDefinition)
public AsyncSensorFuture ReportSensorAsync()
if (!sensorDefinition.IsValid())
throw new ArgumentException("The given annotationDefinition is invalid", nameof(sensorDefinition));
if (!IsValid)
throw new ArgumentException($"The given annotationDefinition is invalid {Id}");
return DatasetCapture.Instance.simulationState.ReportSensorAsync(sensorDefinition);
return DatasetCapture.Instance.simulationState.ReportSensorAsync(this);
public void ReportSensor(SensorDefinition definition, Sensor sensor)
public void ReportSensor(Sensor sensor)
if (!definition.IsValid())
throw new ArgumentException("The given annotationDefinition is invalid", nameof(definition));
if (!IsValid)
throw new ArgumentException("The given annotationDefinition is invalid", Id);
DatasetCapture.Instance.simulationState.ReportSensor(definition, sensor);
DatasetCapture.Instance.simulationState.ReportSensor(this, sensor);
}
/// <summary>

2
com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBox3DLabeler.cs


var spec = idLabelConfig.GetAnnotationSpecification().Select(i => new BoundingBox3DAnnotationDefinition.DefinitionEntry { labelId = i.label_id, labelName = i.label_name });
m_AnnotationDefinition = new BoundingBox3DAnnotationDefinition(spec);
DatasetCapture.RegisterAnnotationDefinition(m_AnnotationDefinition);
DatasetCapture.Instance.RegisterAnnotationDefinition(m_AnnotationDefinition);
perceptionCamera.RenderedObjectInfosCalculated += OnRenderObjectInfosCalculated;

19
com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs


public IdLabelConfig idLabelConfig;
Dictionary<int, (AsyncAnnotationFuture annotation, LabelEntryMatchCache labelEntryMatchCache)> m_AsyncData;
List<BoundingBoxAnnotation.Entry> m_BoundingBoxValues;
List<BoundingBoxAnnotation.Entry> m_ToVisualize;
Vector2 m_OriginalScreenSize = Vector2.zero;

throw new InvalidOperationException("BoundingBox2DLabeler's idLabelConfig field must be assigned");
m_AsyncData = new Dictionary<int, (AsyncAnnotationFuture annotation, LabelEntryMatchCache labelEntryMatchCache)>();
m_BoundingBoxValues = new List<BoundingBoxAnnotation.Entry>();
DatasetCapture.RegisterAnnotationDefinition(m_AnnotationDefinition);
DatasetCapture.Instance.RegisterAnnotationDefinition(m_AnnotationDefinition);
#if false
m_BoundingBoxAnnotationDefinition = DatasetCapture.RegisterAnnotationDefinition("bounding box", idLabelConfig.GetAnnotationSpecification(),
"Bounding box for each labeled object visible to the sensor", id: new Guid(annotationId));

m_AsyncData.Remove(frameCount);
using (s_BoundingBoxCallback.Auto())
{
m_BoundingBoxValues.Clear();
var bbValues = new List<BoundingBoxAnnotation.Entry>();
for (var i = 0; i < renderedObjectInfos.Length; i++)
{
var objectInfo = renderedObjectInfos[i];

m_BoundingBoxValues.Add(new BoundingBoxAnnotation.Entry
bbValues.Add(new BoundingBoxAnnotation.Entry
{
labelId = labelEntry.id,
labelName = labelEntry.label,

if (!CaptureOptions.useAsyncReadbackIfSupported && frameCount != Time.frameCount)
Debug.LogWarning("Not on current frame: " + frameCount + "(" + Time.frameCount + ")");
m_ToVisualize = bbValues;
data = m_BoundingBoxValues,
data = bbValues,
frameCount = frameCount
});
#if true

Id = m_AnnotationDefinition.id,
annotationType = m_AnnotationDefinition.annotationType,
description = m_AnnotationDefinition.description,
boxes = m_BoundingBoxValues
boxes = bbValues
};
asyncData.annotation.Report(toReport);

/// <inheritdoc/>
protected override void OnVisualize()
{
if (m_BoundingBoxValues == null) return;
if (m_ToVisualize == null) return;
GUI.depth = 5;

var screenRatioHeight = Screen.height / m_OriginalScreenSize.y;
foreach (var box in m_BoundingBoxValues)
foreach (var box in m_ToVisualize)
{
var x = box.origin.x * screenRatioWidth;
var y = box.origin.y * screenRatioHeight;

3
com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs


[Serializable]
public abstract class CameraLabeler
{
// TODO protect from null
internal DatasetCapture DatasetCapture => DatasetCapture.Instance;
/// <summary>
/// A human-readable description of the labeler
/// </summary>

2
com.unity.perception/Runtime/GroundTruth/Labelers/KeypointLabeler.cs


throw new InvalidOperationException($"{nameof(KeypointLabeler)}'s idLabelConfig field must be assigned");
m_AnnotationDefinition = new Definition(TemplateToJson(activeTemplate, idLabelConfig));
DatasetCapture.RegisterAnnotationDefinition(m_AnnotationDefinition);
DatasetCapture.Instance.RegisterAnnotationDefinition(m_AnnotationDefinition);
// Texture to use in case the template does not contain a texture for the joints or the skeletal connections
m_MissingTexture = new Texture2D(1, 1);

2
com.unity.perception/Runtime/GroundTruth/Labelers/ObjectCountLabeler.cs


description = k_Description
};
DatasetCapture.RegisterMetric(m_Definition);
DatasetCapture.Instance.RegisterMetric(m_Definition);
visualizationEnabled = supportsVisualization;
}

2
com.unity.perception/Runtime/GroundTruth/Labelers/SemanticSegmentationLabeler.cs


}
m_AnnotationDefinition = new SemanticSegmentationDefinition(specs);
DatasetCapture.RegisterAnnotationDefinition(m_AnnotationDefinition);
DatasetCapture.Instance.RegisterAnnotationDefinition(m_AnnotationDefinition);
m_SemanticSegmentationTextureReader = new RenderTextureReader<Color32>(targetTexture);
visualizationEnabled = supportsVisualization;

49
com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs


using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using Unity.Mathematics;

SetupVisualizationCamera();
DatasetCapture.Instance.SimulationEnding += OnSimulationEnding;
Manager.Instance.ShutdownNotification += OnSimulationEnding;
}
void OnEnable()

void OnDisable()
{
RenderPipelineManager.beginCameraRendering -= OnBeginCameraRendering;
RenderPipelineManager.endFrameRendering -= OnEndFrameRendering;
RenderPipelineManager.endCameraRendering -= CheckForRendererFeature;

m_SensorDefinition = new SensorDefinition(ID, "camera", description)
{
firstCaptureFrame = firstCaptureFrame,
captureTriggerMode = captureTriggerMode.ToString(),
captureTriggerMode = captureTriggerMode,
simulationDeltaTime = simulationDeltaTime,
framesBetweenCaptures = framesBetweenCaptures,
manualSensorsAffectTiming = manualSensorAffectSimulationTiming

void CaptureRgbData(Camera cam)
{
if (!captureRgbImages)
return;
Profiler.BeginSample("CaptureDataFromLastFrame");
var capture = new RgbSensor
{
Id = "perception_camera",

acceleration = Vector3.zero,
imageFormat = ".png",
dimension = new Vector2(cam.pixelWidth, cam.pixelHeight),
buffer = null
buffer = new byte[0]
if (!captureRgbImages)
{
SensorHandle.ReportSensor(capture);
return;
}
Profiler.BeginSample("CaptureDataFromLastFrame");
//var width = cam.pixelWidth;
//var height = cam.pixelHeight;

SetPersistentSensorData("camera_intrinsic", ToProjectionMatrix3x3(cam.projectionMatrix));
SetPersistentSensorData("projection", cam.orthographic ? "orthographic" : "perspective");
var asyncSensor = SensorHandle.ReportSensorAsync(m_SensorDefinition);
var asyncSensor = SensorHandle.ReportSensorAsync();
#if false
SensorHandle.ReportCapture(dxRootPath, SensorSpatialData.FromGameObjects(

Func<AsyncRequest<CaptureCamera.CaptureState>, AsyncRequest.Result> colorFunctor;
colorFunctor = r =>

var dataColorBuffer = (byte[])r.data.colorBuffer;
#if true
byte[] encodedData;
using (s_EncodeAndSave.Auto())
{

#if false
SetPersistentSensorData("buffer", encodedData);
return !FileProducer.Write(captureFilename, encodedData)
? AsyncRequest.Result.Error
: AsyncRequest.Result.Completed;
capture.buffer = encodedData;
#else
capture.buffer = dataColorBuffer;
capture.buffer = encodedData;
asyncSensor.Report(capture);
return AsyncRequest.Result.Completed;

void OnSimulationEnding()
{
m_Done = true;
CleanUpInstanceSegmentation();
foreach (var labeler in m_Labelers)
{

}
}
void OnBeginCameraRendering(ScriptableRenderContext scriptableRenderContext, Camera cam)
{

}
}
bool m_Done = false;
if (m_Done) return false;
if (cam != attachedCamera)
return false;
if (!SensorHandle.ShouldCaptureThisFrame)

8
com.unity.perception/Runtime/GroundTruth/PerceptionUpdater.cs


namespace UnityEngine.Perception.GroundTruth
using Unity.Simulation;
namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
/// PerceptionUpdater is automatically spawned when the player starts and is used to coordinate and maintain

DontDestroyOnLoad(updaterObject);
}
// TODO - all of this can be rolled into dataset capture
DatasetCapture.Instance.simulationState?.Update();
DatasetCapture.Instance.Update();
}
}
}

268
com.unity.perception/Runtime/GroundTruth/SimulationState.cs


using System;
using System.Collections;
using System.Threading;
using Unity.Simulation;
using UnityEngine.Rendering;
namespace UnityEngine.Perception.GroundTruth
{

Dictionary<SensorHandle, SensorData> m_Sensors = new Dictionary<SensorHandle, SensorData>();
// ConsumerEndpoint _Consumer;
int m_SequenceId = -1;
internal ConsumerEndpoint consumerEndpoint { get; set; }
int m_SequenceId = 0;
HashSet<string> _Ids = new HashSet<string>();

float m_UnscaledSequenceTimeDoNotUse;
int m_FrameCountLastStepIncremented = -1;
int m_TotalFrames = 0;
int m_Step = -1;
bool m_HasStarted;

Dictionary<SPendingFrameId, int> m_PendingIdToFrameMap = new Dictionary<SPendingFrameId, int>();
Dictionary<SPendingFrameId, PendingFrame> m_PendingFrames = new Dictionary<SPendingFrameId, PendingFrame>();
Dictionary<PendingFrameId, int> m_PendingIdToFrameMap = new Dictionary<PendingFrameId, int>();
Dictionary<PendingFrameId, PendingFrame> m_PendingFrames = new Dictionary<PendingFrameId, PendingFrame>();
CustomSampler m_SerializeCapturesSampler = CustomSampler.Create("SerializeCaptures");
CustomSampler m_SerializeCapturesAsyncSampler = CustomSampler.Create("SerializeCapturesAsync");

IsRunning = true;
}
static ConsumerEndpoint GetActiveConsumer()
{
return DatasetCapture.Instance.activeConsumer;
}
public bool ReadyToShutdown => !m_PendingFrames.Any();
SPendingFrameId AsFrameId();
SPendingSensorId AsSensorId();
PendingFrameId AsFrameId();
PendingSensorId AsSensorId();
public readonly struct SPendingFrameId : IPendingId, IEquatable<SPendingFrameId>, IEquatable<SPendingSensorId>, IEquatable<SPendingCaptureId>
public readonly struct PendingFrameId : IPendingId, IEquatable<PendingFrameId>, IEquatable<PendingSensorId>, IEquatable<PendingCaptureId>
public SPendingFrameId(int sequence, int step)
public PendingFrameId(int sequence, int step)
{
Sequence = sequence;
Step = step;

public int Sequence { get; }
public int Step { get; }
public SPendingFrameId AsFrameId()
public PendingFrameId AsFrameId()
public SPendingSensorId AsSensorId()
public PendingSensorId AsSensorId()
return new SPendingSensorId(string.Empty,this);
return new PendingSensorId(string.Empty,this);
public bool Equals(SPendingFrameId other)
public bool Equals(PendingFrameId other)
public bool Equals(SPendingSensorId other)
public bool Equals(PendingSensorId other)
public bool Equals(SPendingCaptureId other)
public bool Equals(PendingCaptureId other)
{
var otherId = other.AsFrameId();
return Sequence == otherId.Sequence && Step == otherId.Step;

{
return obj is SPendingFrameId other && Equals(other);
return obj is PendingFrameId other && Equals(other);
}
public override int GetHashCode()

}
}
public readonly struct SPendingSensorId : IPendingId, IEquatable<SPendingSensorId>, IEquatable<SPendingFrameId>, IEquatable<SPendingCaptureId>
public readonly struct PendingSensorId : IPendingId, IEquatable<PendingSensorId>, IEquatable<PendingFrameId>, IEquatable<PendingCaptureId>
public SPendingSensorId(string sensorId, int sequence, int step)
public PendingSensorId(string sensorId, int sequence, int step)
m_FrameId = new SPendingFrameId(sequence, step);
m_FrameId = new PendingFrameId(sequence, step);
public SPendingSensorId(string sensorId, SPendingFrameId frameId)
public PendingSensorId(string sensorId, PendingFrameId frameId)
{
SensorId = sensorId;
m_FrameId = frameId;

public string SensorId { get; }
readonly SPendingFrameId m_FrameId;
public SPendingFrameId AsFrameId()
readonly PendingFrameId m_FrameId;
public PendingFrameId AsFrameId()
public SPendingSensorId AsSensorId()
public PendingSensorId AsSensorId()
public bool Equals(SPendingSensorId other)
public bool Equals(PendingSensorId other)
public bool Equals(SPendingFrameId other)
public bool Equals(PendingFrameId other)
public bool Equals(SPendingCaptureId other)
public bool Equals(PendingCaptureId other)
{
return Equals(other.SensorId);
}

return obj is SPendingSensorId other && Equals(other);
return obj is PendingSensorId other && Equals(other);
}
public override int GetHashCode()

}
}
public readonly struct SPendingCaptureId : IPendingId, IEquatable<SPendingCaptureId>, IEquatable<SPendingSensorId>, IEquatable<SPendingFrameId>
public readonly struct PendingCaptureId : IPendingId, IEquatable<PendingCaptureId>, IEquatable<PendingSensorId>, IEquatable<PendingFrameId>
public SPendingCaptureId(string sensorId, string captureId, int sequence, int step)
public PendingCaptureId(string sensorId, string captureId, int sequence, int step)
SensorId = new SPendingSensorId(sensorId, sequence, step);
SensorId = new PendingSensorId(sensorId, sequence, step);
public SPendingCaptureId(string captureId, SPendingSensorId frameId)
public PendingCaptureId(string captureId, PendingSensorId frameId)
{
CaptureId = captureId;
SensorId = frameId;

public SPendingSensorId SensorId { get; }
public PendingSensorId SensorId { get; }
public SPendingFrameId AsFrameId()
public PendingFrameId AsFrameId()
public SPendingSensorId AsSensorId()
public PendingSensorId AsSensorId()
{
return SensorId;
}

return SensorId.IsValid() && !string.IsNullOrEmpty(CaptureId);
}
public bool Equals(SPendingCaptureId other)
public bool Equals(PendingCaptureId other)
public bool Equals(SPendingSensorId other)
public bool Equals(PendingSensorId other)
public bool Equals(SPendingFrameId other)
public bool Equals(PendingFrameId other)
{
return SensorId.AsFrameId().Equals(other);
}

return obj is SPendingCaptureId other && Equals(other);
return obj is PendingCaptureId other && Equals(other);
}
public override int GetHashCode()

public class PendingSensor
{
public PendingSensor(SPendingSensorId id)
public PendingSensor(PendingSensorId id)
Annotations = new Dictionary<SPendingCaptureId, Annotation>();
Metrics = new Dictionary<SPendingCaptureId, Metric>();
Annotations = new Dictionary<PendingCaptureId, Annotation>();
Metrics = new Dictionary<PendingCaptureId, Metric>();
public PendingSensor(SPendingSensorId id, Sensor sensorData) : this(id)
public PendingSensor(PendingSensorId id, Sensor sensorData) : this(id)
{
m_SensorData = sensorData;
}

return m_SensorData;
}
SPendingSensorId m_Id;
PendingSensorId m_Id;
public Dictionary<SPendingCaptureId, Annotation> Annotations { get; private set; }
public Dictionary<SPendingCaptureId, Metric> Metrics { get; private set; }
public Dictionary<PendingCaptureId, Annotation> Annotations { get; private set; }
public Dictionary<PendingCaptureId, Metric> Metrics { get; private set; }
public bool IsPending<T>(IAsyncFuture<T> asyncFuture) where T : IPendingId
{

return m_SensorData == null;
case FutureType.Annotation:
{
return asyncFuture.GetId() is SPendingCaptureId captureId && Annotations.ContainsKey(captureId) && Annotations[captureId] == null;
return asyncFuture.GetId() is PendingCaptureId captureId && Annotations.ContainsKey(captureId) && Annotations[captureId] == null;
return asyncFuture.GetId() is SPendingCaptureId captureId && Metrics.ContainsKey(captureId) && Metrics[captureId] == null;
return asyncFuture.GetId() is PendingCaptureId captureId && Metrics.ContainsKey(captureId) && Metrics[captureId] == null;
}
default:
throw new ArgumentOutOfRangeException();

return false;
case FutureType.Annotation:
{
if (result is Annotation annotation && asyncFuture.GetId() is SPendingCaptureId capId)
if (result is Annotation annotation && asyncFuture.GetId() is PendingCaptureId capId)
{
Annotations[capId] = annotation;
return true;

}
case FutureType.Metric:
{
if (result is Metric metric && asyncFuture.GetId() is SPendingCaptureId capId)
if (result is Metric metric && asyncFuture.GetId() is PendingCaptureId capId)
{
Metrics[capId] = metric;
return true;

public class PendingFrame
{
public SPendingFrameId PendingId { get; }
SimulationState m_SimulationState;
public PendingFrameId PendingId { get; }
internal Dictionary<SPendingSensorId, PendingSensor> sensors = new Dictionary<SPendingSensorId, PendingSensor>();
internal Dictionary<PendingSensorId, PendingSensor> sensors = new Dictionary<PendingSensorId, PendingSensor>();
public PendingFrame(SPendingFrameId pendingFrameId, float timestamp)
public PendingFrame(PendingFrameId pendingFrameId, float timestamp, SimulationState simState)
m_SimulationState = simState;
}
public bool IsReadyToReport()

public PendingSensor GetOrCreatePendingSensor(SPendingSensorId sensorId)
public PendingSensor GetOrCreatePendingSensor(PendingSensorId sensorId)
public PendingSensor GetOrCreatePendingSensor(SPendingSensorId sensorId, out bool created)
public PendingSensor GetOrCreatePendingSensor(PendingSensorId sensorId, out bool created)
{
created = false;

if (!sensorId.IsValid()) return false;
var sensor = GetOrCreatePendingSensor(sensorId);
return sensor.ReportAsyncResult(asyncFuture, result);
sensor.ReportAsyncResult(asyncFuture, result);
return true;
}
}

}
}
bool m_FirstNewSequence = true;
public void StartNewSequence()
{
ResetTimings();

m_Sensors[kvp.Key] = sensorData;
}
m_SequenceId++;
if (m_FirstNewSequence)
m_FirstNewSequence = false;
else
m_SequenceId++;
}
void ResetTimings()

m_ActiveSensors.Add(sensorHandle);
m_Sensors.Add(sensorHandle, sensorData);
GetActiveConsumer()?.OnSensorRegistered(sensor);
consumerEndpoint.OnSensorRegistered(sensor);
return sensorHandle;
}

throw new InvalidOperationException("Dataset generation is only supported in play mode.");
}
}
SimulationMetadata m_SimulationMetadata;
public void Update()
{

if (!m_HasStarted)
{
GetActiveConsumer()?.OnSimulationStarted(new SimulationMetadata());
m_SimulationMetadata = new SimulationMetadata()
{
unityVersion = Application.unityVersion,
perceptionVersion = DatasetCapture.PerceptionVersion,
};
consumerEndpoint.OnSimulationStarted(m_SimulationMetadata);
//simulation starts now
m_FrameCountLastUpdatedSequenceTime = Time.frameCount;

}
WritePendingCaptures();
// WritePendingMetrics();
Time.captureDeltaTime = nextFrameDt;

return data.sequenceTimeOfNextCapture - UnscaledSequenceTime < k_SimulationTimingAccuracy;
}
#if false
public IEnumerator End()
{
if (_Ids.Count == 0)
yield break;
while (m_PendingFrames.Count > 0)
{
WritePendingCaptures(true, true);
yield return null;
}
if (m_PendingFrames.Count > 0)
Debug.LogError($"Simulation ended with pending annotations: {string.Join(", ", m_PendingFrames.Select(c => $"id:{c.Key}"))}");
#if false
WritePendingMetrics(true);
if (m_PendingMetrics.Count > 0)
Debug.LogError($"Simulation ended with pending metrics: {string.Join(", ", m_PendingMetrics.Select(c => $"id:{c.MetricId} step:{c.Step}"))}");
#endif
if (m_AdditionalInfoTypeData.Any())
{
List<IdLabelConfig.LabelEntrySpec> labels = new List<IdLabelConfig.LabelEntrySpec>();
foreach (var infoTypeData in m_AdditionalInfoTypeData)
{
if (infoTypeData.specValues == null) continue;
foreach (var spec in infoTypeData.specValues)
{
if (spec is IdLabelConfig.LabelEntrySpec entrySpec)
{
labels.Add(entrySpec);
}
}
// Debug.Log($"adt: {infoTypeData}");
}
}
// WriteReferences();
Time.captureDeltaTime = 0;
IsRunning = false;
var metadata = new CompletionMetadata()
{
unityVersion = m_SimulationMetadata.unityVersion,
perceptionVersion = m_SimulationMetadata.perceptionVersion,
renderPipeline = m_SimulationMetadata.renderPipeline,
totalFrames = m_TotalFrames
};
consumerEndpoint.OnSimulationCompleted(metadata);
}
#else
internal bool CapturesLeft()
{
return m_PendingFrames.Count > 0;
}
internal void TryToClearOut()
{
if (ReadyToShutdown) return;
WritePendingCaptures(true, true);
if (ReadyToShutdown)
{
var metadata = new CompletionMetadata()
{
unityVersion = m_SimulationMetadata.unityVersion,
perceptionVersion = m_SimulationMetadata.perceptionVersion,
renderPipeline = m_SimulationMetadata.renderPipeline,
totalFrames = m_TotalFrames
};
consumerEndpoint.OnSimulationCompleted(metadata);
}
}
public void End()
{

WritePendingCaptures(true, true);
// while (m_PendingFrames.Count > 0)
// {
WritePendingCaptures(true, true);
// }
Debug.LogError($"Simulation ended with pending annotations: {string.Join(", ", m_PendingFrames.Select(c => $"id:{c.Key}"))}");
Debug.LogError($"Simulation ended with {m_PendingFrames.Count} pending annotations, final one is: ({m_PendingFrames.Last().Key.Sequence},{m_PendingFrames.Last().Key.Step})");
#if false
WritePendingMetrics(true);
if (m_PendingMetrics.Count > 0)

Time.captureDeltaTime = 0;
IsRunning = false;
var metadata = new CompletionMetadata();
GetActiveConsumer()?.OnSimulationCompleted(metadata);
#endif
GetActiveConsumer()?.OnAnnotationRegistered(definition);
consumerEndpoint.OnAnnotationRegistered(definition);
GetActiveConsumer()?.OnMetricRegistered(definition);
consumerEndpoint.OnMetricRegistered(definition);
}
void RegisterAdditionalInfoType<TSpec>(string name, TSpec[] specValues, string description, string format, Guid id, AdditionalInfoKind additionalInfoKind)

m_AdditionalInfoTypeData.Add(annotationDefinitionInfo);
}
public SPendingSensorId ReportSensor(SensorDefinition definition, Sensor sensor)
public PendingSensorId ReportSensor(SensorHandle handle, Sensor sensor)
var pendingSensorId = new SPendingSensorId(definition.id, m_SequenceId, step);
var pendingSensorId = new PendingSensorId(handle.Id, m_SequenceId, step);
public SPendingCaptureId ReportAnnotation(SensorHandle sensorHandle, AnnotationDefinition definition, Annotation annotation)
public PendingCaptureId ReportAnnotation(SensorHandle sensorHandle, AnnotationDefinition definition, Annotation annotation)
var sensorId = new SPendingCaptureId(sensorHandle.Id, definition.id, m_SequenceId, step);
var sensorId = new PendingCaptureId(sensorHandle.Id, definition.id, m_SequenceId, step);
var annotationId = new SPendingCaptureId(sensorHandle.Id, definition.id, m_SequenceId, step);
var annotationId = new PendingCaptureId(sensorHandle.Id, definition.id, m_SequenceId, step);
PendingFrame GetOrCreatePendingFrame(SPendingFrameId pendingId)
PendingFrame GetOrCreatePendingFrame(PendingFrameId pendingId)
PendingFrame GetOrCreatePendingFrame(SPendingFrameId pendingId, out bool created)
PendingFrame GetOrCreatePendingFrame(PendingFrameId pendingId, out bool created)
{
created = false;
m_GetOrCreatePendingCaptureForThisFrameSampler.Begin();

{
pendingFrame = new PendingFrame(pendingId, SequenceTime);
pendingFrame = new PendingFrame(pendingId, SequenceTime, this);
m_PendingFrames[pendingId] = pendingFrame;
m_PendingIdToFrameMap[pendingId] = Time.frameCount;
created = true;

return new AsyncAnnotationFuture(ReportAnnotation(sensorHandle, annotationDefinition, null), this);
}
public AsyncSensorFuture ReportSensorAsync(SensorDefinition sensorDefinition)
public AsyncSensorFuture ReportSensorAsync(SensorHandle handle)
return new AsyncSensorFuture(ReportSensor(sensorDefinition, null), this);
return new AsyncSensorFuture(ReportSensor(handle, null), this);
}
public bool IsPending<T>(IAsyncFuture<T> asyncFuture) where T : IPendingId

return GetPendingFrame(future.GetId().AsFrameId());
}
PendingFrame GetPendingFrame(SPendingFrameId id)
PendingFrame GetPendingFrame(PendingFrameId id)
{
return m_PendingFrames[id];
}

return new AsyncMetricFuture(pendingId, this);
}
public SPendingCaptureId ReportMetric(SensorHandle sensor, MetricDefinition definition, Metric metric, AnnotationHandle annotation)
public PendingCaptureId ReportMetric(SensorHandle sensor, MetricDefinition definition, Metric metric, AnnotationHandle annotation)
var pendingId = new SPendingCaptureId(sensor.Id, definition.id, m_SequenceId, AcquireStep());
var pendingId = new PendingCaptureId(sensor.Id, definition.id, m_SequenceId, AcquireStep());
var pendingFrame = GetOrCreatePendingFrame(pendingId.AsFrameId());
if (pendingFrame == null)

23
com.unity.perception/Runtime/GroundTruth/SimulationState_Json.cs


{
m_SerializeCapturesSampler.Begin();
var pendingFramesToWrite = new List<KeyValuePair<SPendingFrameId,PendingFrame>>(m_PendingFrames.Count);
var pendingFramesToWrite = new List<KeyValuePair<PendingFrameId,PendingFrame>>(m_PendingFrames.Count);
var currentFrame = Time.frameCount;
foreach (var frame in m_PendingFrames)

return frame;
}
void Write(List<KeyValuePair<SPendingFrameId, PendingFrame>> frames, SimulationState simulationState)
void Write(List<KeyValuePair<PendingFrameId, PendingFrame>> frames, SimulationState simulationState)
#if true
// TODO this needs to be done properly, we need to wait on all of the frames to come back so we
// can report them, right now we are just going to jam up this thread waiting for them, also could
// result in an endless loop if the frame never comes back
while (frames.Any())
{
var frame = frames.First();
if (frame.Value.IsReadyToReport())
{
frames.Remove(frame);
var converted = ConvertToFrameData(frame.Value, simulationState);
m_TotalFrames++;
consumerEndpoint.OnFrameGenerated(converted);
}
}
#else
#endif
}
if (flush)

struct WritePendingCaptureRequestData
{
public List<KeyValuePair<SPendingFrameId, PendingFrame>> PendingFrames;
public List<KeyValuePair<PendingFrameId, PendingFrame>> PendingFrames;
public SimulationState SimulationState;
}
}

2
com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/AnimationRandomizer.cs


[AddRandomizerMenu("Perception/Animation Randomizer")]
public class AnimationRandomizer : Randomizer
{
FloatParameter m_FloatParameter = new FloatParameter{ value = new UniformSampler(0, 1) };
FloatParameter m_FloatParameter = new FloatParameter{ value = new ConstantSampler(0) };
const string k_ClipName = "PlayerIdle";
const string k_StateName = "Base Layer.RandomState";

46
com.unity.perception/Runtime/Randomization/Scenarios/PerceptionScenario.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Rendering;
namespace UnityEngine.Perception.Randomization.Scenarios
{

return true;
}
}
#if false
class ShutdownCondition : ICondition
{
public bool HasConditionBeenMet()
{
if (DatasetCapture.Instance.ReadyToShutdown)
{
Debug.Log("Triggered dc ready");
}
return DatasetCapture.Instance.ReadyToShutdown;
}
}
#endif
/// <inheritdoc/>
protected override void OnStart()
{

// Manager.Instance.ShutdownCondition = new ShutdownCondition();
Manager.Instance.ShutdownNotification += () =>
{
// DatasetCapture.Instance.ResetSimulation();
Quit();
};
m_IterationMetricDefinition = DatasetCapture.Instance.RegisterMetricDefinition(
m_IterationMetricDefinition = DatasetCapture.RegisterMetricDefinition(
var randomSeedMetricDefinition = DatasetCapture.Instance.RegisterMetricDefinition(
var randomSeedMetricDefinition = DatasetCapture.RegisterMetricDefinition(
DatasetCapture.Instance.ReportMetric(randomSeedMetricDefinition, new[] { genericConstants.randomSeed });
DatasetCapture.ReportMetric(randomSeedMetricDefinition, new[] { genericConstants.randomSeed });
#endif
}

DatasetCapture.Instance.StartNewSequence();
#if false
DatasetCapture.Instance.ReportMetric(m_IterationMetricDefinition, new[]
DatasetCapture.ReportMetric(m_IterationMetricDefinition, new[]
{
new IterationMetricData { iteration = currentIteration }
});

/// <inheritdoc/>
#if false
protected override IEnumerator OnComplete()
{
yield return StartCoroutine(DatasetCapture.Instance.ResetSimulation());
#else
Manager.Instance.Shutdown();
Quit();
//Manager.Instance.ShutdownAfterFrames(105);
//Manager.Instance.Shutdown();
//DatasetCapture.Instance.ResetSimulation();
#endif
// Quit();
}
#if false
/// <summary>

14
com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;

/// OnComplete is called when this scenario's isScenarioComplete property
/// returns true during its main update loop
/// </summary>
#if false
protected virtual IEnumerator OnComplete()
{
yield break;
}
#else
#endif
/// <summary>
/// OnIdle is called each frame after the scenario has completed
/// </summary>

{
foreach (var randomizer in activeRandomizers)
randomizer.ScenarioComplete();
#if false
StartCoroutine(OnComplete());
#else
#endif
state = State.Idle;
OnIdle();
return;

127
com.unity.perception/Tests/Runtime/GroundTruthTests/DatasetCaptureSensorSchedulingTests.cs


using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.Perception.GroundTruth.DataModel;
using UnityEngine.TestTools;
using Random = UnityEngine.Random;

// due to protection level - use only when testing protected logic is critical
class SimulationStateTestHelper
{
#if false
SimulationState m_State => DatasetCapture.SimulationState;
#endif
SimulationState m_State;
#if false
m_State = DatasetCapture.Instance.simulationState;
var bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance;
m_SequenceTimeOfNextCaptureMethod = m_State.GetType().GetMethod("GetSequenceTimeOfNextCapture", bindingFlags);
Debug.Assert(m_SequenceTimeOfNextCaptureMethod != null, "Couldn't find sequence time method.");

Debug.Assert(m_SensorsReference != null, "Couldn't cast sensor field to dictionary");
#endif
// return (float)m_SequenceTimeOfNextCaptureMethod.Invoke(m_State, new object[] { sensorData });
return 0;
return (float)m_SequenceTimeOfNextCaptureMethod.Invoke(m_State, new object[] { sensorData });
// return m_SensorsReference[sensorHandle];
return new SimulationState.SensorData();
return m_SensorsReference[sensorHandle];
}
}

public void TearDown()
{
Time.timeScale = 1;
// DatasetCapture.ResetSimulation();
DatasetCapture.Instance.ResetSimulation();
}
SensorDefinition CreateSensorDefinition(string id, string modality, string def, int firstFrame, CaptureTriggerMode mode, float deltaTime, int framesBetween)
{
return new SensorDefinition(id, modality, def)
{
firstCaptureFrame = firstFrame,
captureTriggerMode = mode,
simulationDeltaTime = deltaTime,
framesBetweenCaptures = framesBetween
};
#if false
var ego = DatasetCapture.RegisterEgo("ego");
var firstCaptureFrame = 2f;
var firstCaptureFrame = 2;
var sensorHandle = DatasetCapture.RegisterSensor(ego, "cam", "", firstCaptureFrame, CaptureTriggerMode.Scheduled, simulationDeltaTime, 0);
var sensorHandle = DatasetCapture.Instance.RegisterSensor(
CreateSensorDefinition("cam", "", "", firstCaptureFrame, CaptureTriggerMode.Scheduled, simulationDeltaTime, 0));
var startTime = firstCaptureFrame * simulationDeltaTime;
float[] sequenceTimesExpected =

Assert.AreEqual(sequenceTimesExpected[i], sequenceTimeActual, 0.0001f);
yield return null;
}
#endif
yield return null;
#if false
var ego = DatasetCapture.RegisterEgo("ego");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "cam", "", firstCaptureFrame, CaptureTriggerMode.Scheduled, simulationDeltaTime, framesBetweenCaptures);
var sensorHandle = DatasetCapture.Instance.RegisterSensor(
CreateSensorDefinition("cam", "", "", firstCaptureFrame, CaptureTriggerMode.Scheduled, simulationDeltaTime, framesBetweenCaptures));
var startingFrame = Time.frameCount;
var startTime = firstCaptureFrame * simulationDeltaTime;

yield return null;
}
}
#endif
yield return null;
#if false
var ego = DatasetCapture.RegisterEgo("ego");
var firstCaptureFrame = 2f;
var firstCaptureFrame = 2;
DatasetCapture.RegisterSensor(ego, "cam", "", firstCaptureFrame, CaptureTriggerMode.Scheduled, simulationDeltaTime, 0);
DatasetCapture.Instance.RegisterSensor(
CreateSensorDefinition("cam", "", "", firstCaptureFrame, CaptureTriggerMode.Scheduled, simulationDeltaTime, 0));
float[] deltaTimeSamplesExpected =
{

yield return null;
Assert.AreEqual(deltaTimeSamplesExpected[i], Time.deltaTime, 0.0001f);
}
#endif
yield return null;
#if false
var ego = DatasetCapture.RegisterEgo("ego");
var firstCaptureFrame = 2f;
var firstCaptureFrame = 2;
DatasetCapture.RegisterSensor(ego, "cam", "", firstCaptureFrame, CaptureTriggerMode.Scheduled, simulationDeltaTime, 0);
DatasetCapture.Instance.RegisterSensor(
CreateSensorDefinition("cam", "", "", firstCaptureFrame, CaptureTriggerMode.Scheduled, simulationDeltaTime, 0));
float[] deltaTimeSamplesExpected =
{

yield return null;
Assert.AreEqual(deltaTimeSamplesExpected[i], Time.deltaTime, 0.0001f);
}
#endif
yield return null;
#if false
var ego = DatasetCapture.RegisterEgo("ego");
DatasetCapture.RegisterSensor(ego, "cam", "", 2f, CaptureTriggerMode.Scheduled, 1, 0);
DatasetCapture.Instance.RegisterSensor(CreateSensorDefinition("cam", "", "", 2, CaptureTriggerMode.Scheduled, 1, 0));
#endif
yield return null;
#if false
var ego = DatasetCapture.RegisterEgo("ego");
DatasetCapture.RegisterSensor(ego, "cam", "", 2f, CaptureTriggerMode.Scheduled, 1, 0);
DatasetCapture.Instance.RegisterSensor(CreateSensorDefinition("cam", "", "", 2, CaptureTriggerMode.Scheduled, 1, 0));
DatasetCapture.StartNewSequence();
yield return null;
#endif
DatasetCapture.Instance.StartNewSequence();
yield return null;
}

{
#if false
var ego = DatasetCapture.RegisterEgo("ego");
var firstCaptureFrame = 2f;
var firstCaptureFrame = 2;
var simulationDeltaTime = 1f;
float[] newTimeScalesPerFrame =
{

1f
};
DatasetCapture.RegisterSensor(ego, "cam", "", firstCaptureFrame, CaptureTriggerMode.Scheduled, 1, 0);
DatasetCapture.Instance.RegisterSensor(CreateSensorDefinition("cam", "", "", firstCaptureFrame, CaptureTriggerMode.Scheduled, 1, 0));
float[] deltaTimeSamplesExpected =
{

yield return null;
Assert.AreEqual(deltaTimeSamplesExpected[i], Time.deltaTime, 0.0001f);
}
#endif
yield return null;
#if false
var ego = DatasetCapture.RegisterEgo("ego");
DatasetCapture.RegisterSensor(ego, "cam", "", 0, CaptureTriggerMode.Scheduled, 5, 0);
DatasetCapture.Instance.RegisterSensor(CreateSensorDefinition("cam", "", "", 0, CaptureTriggerMode.Scheduled, 5, 0));
DatasetCapture.ResetSimulation();
DatasetCapture.Instance.ResetSimulation();
#endif
yield return null;
#if false
var ego = DatasetCapture.RegisterEgo("ego");
var sensor1 = DatasetCapture.RegisterSensor(ego, "cam", "1", firstCaptureFrame1, CaptureTriggerMode.Scheduled, simDeltaTime1, framesBetweenCaptures1);
var sensor1 = DatasetCapture.Instance.RegisterSensor(CreateSensorDefinition("cam1", "", "", firstCaptureFrame1, CaptureTriggerMode.Scheduled, simDeltaTime1, framesBetweenCaptures1));
var sensor2 = DatasetCapture.RegisterSensor(ego, "cam", "2", firstCaptureFrame2, CaptureTriggerMode.Scheduled, simDeltaTime2, framesBetweenCaptures2);
var sensor2 = DatasetCapture.Instance.RegisterSensor(CreateSensorDefinition("cam2", "", "", firstCaptureFrame2, CaptureTriggerMode.Scheduled, simDeltaTime2, framesBetweenCaptures2));
var sensor3 = DatasetCapture.RegisterSensor(ego, "cam", "3", 0, CaptureTriggerMode.Manual, simDeltaTime3, 0, true);
var sensor3 = DatasetCapture.Instance.RegisterSensor(CreateSensorDefinition("cam3", "", "", 0, CaptureTriggerMode.Manual, simDeltaTime3, 0)); // why is there a true on this one
(float deltaTime, bool sensor1ShouldCapture, bool sensor2ShouldCapture, bool sensor3ShouldCapture)[] samplesExpected =
{

}
CollectionAssert.AreEqual(samplesExpected, samplesActual);
#endif
yield return null;
}
[UnityTest]

[TestCase(235, 10, 2350, 2585, 2820, 3055, ExpectedResult = (IEnumerator)null)]
public IEnumerator SequenceTimeOfNextCapture_ReportsCorrectTime_VariedDeltaTimesAndStartFrames(float simulationDeltaTime, int firstCaptureFrame, float firstCaptureTime, float secondCaptureTime, float thirdCaptureTime, float fourthCaptureTime)
{
#if false
var ego = DatasetCapture.RegisterEgo("ego");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "cam", "", firstCaptureFrame, CaptureTriggerMode.Scheduled, simulationDeltaTime, 0);
var sensorHandle = DatasetCapture.Instance.RegisterSensor(CreateSensorDefinition("cam", "", "", firstCaptureFrame, CaptureTriggerMode.Scheduled, simulationDeltaTime, 0));
float[] sequenceTimesExpected =
{

Assert.AreEqual(sequenceTimesExpected[i], sequenceTimeActual, 0.0001f);
yield return null;
}
#endif
yield return null;
#if false
var ego = DatasetCapture.RegisterEgo("ego");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "cam", "", 0, CaptureTriggerMode.Manual, 0, 0, false);
var sensorHandle = DatasetCapture.Instance.RegisterSensor(CreateSensorDefinition("cam", "", "", 0, CaptureTriggerMode.Manual, 0, 0)); // why is there supposed to be a falise at the end of this
var framesToCaptureOn = new List<int>();

}
Assert.AreEqual(frameIndex, framesToCaptureOn.Count, 0.0001f);
#endif
yield return null;
#if false
var ego = DatasetCapture.RegisterEgo("ego");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "cam", "", 0, CaptureTriggerMode.Manual, simulationDeltaTime, 0, true);
var sensorHandle = DatasetCapture.Instance.RegisterSensor(CreateSensorDefinition("cam", "", "", 0, CaptureTriggerMode.Manual, simulationDeltaTime, 0)); // why was there a true here...
var framesToCaptureOn = new List<int>();

yield return null;
}
Assert.AreEqual(frameIndex, framesToCaptureOn.Count, 0.0001f);
#endif
yield return null;
}
}
}

178
com.unity.perception/Tests/Runtime/GroundTruthTests/DatasetCaptureTests.cs


using Newtonsoft.Json.Linq;
using NUnit.Framework;
using Unity.Mathematics;
using Unity.Simulation;
using UnityEngine.Perception.GroundTruth.Consumers;
using UnityEngine.Perception.GroundTruth.DataModel;
using UnityEngine.TestTools;
// ReSharper disable InconsistentNaming
// ReSharper disable NotAccessedField.Local

static SensorHandle RegisterSensor(string id, string modality, string sensorDescription, int firstCaptureFrame, CaptureTriggerMode captureTriggerMode, float simDeltaTime, int framesBetween, bool affectTiming = false)
{
var sensorDefinition = new SensorDefinition(id, modality, sensorDescription)
{
firstCaptureFrame = firstCaptureFrame,
captureTriggerMode = captureTriggerMode,
simulationDeltaTime = simDeltaTime,
framesBetweenCaptures = framesBetween,
manualSensorsAffectTiming = affectTiming
};
return DatasetCapture.Instance.RegisterSensor(sensorDefinition);
}
[Test]
public void RegisterSensor_ReportsProperJson()
{

}}
]
}}";
#if false
//var ego = DatasetCapture.RegisterEgo(egoDescription);
var ego = new EgoHandle();
var sensorHandle = DatasetCapture.RegisterSensor(ego, modality, sensorDescription, 1, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = RegisterSensor("camera", modality, sensorDescription, 1, CaptureTriggerMode.Scheduled, 1, 0);
DatasetCapture.ResetSimulation();
DatasetCapture.Instance.ResetSimulation();
var sensorsPath = Path.Combine(DatasetCapture.OutputDirectory, "sensors.json");
var egosPath = Path.Combine(DatasetCapture.OutputDirectory, "egos.json");
FileAssert.Exists(egosPath);
var path = Configuration.Instance.GetStorageBasePath();
var sensorsPath = Path.Combine(path, "sensors.json");
AssertJsonFileEquals(egoJsonExpected, egosPath);
#endif
#if false
[Test]
public void ReportCapture_ReportsProperJson()
{

}}
]
}}";
#if false
var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "camera", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = RegisterSensor("camera", "camera", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensorSpatialData = new SensorSpatialData(new Pose(egoPosition, egoRotation), new Pose(position, rotation), egoVelocity, null);
sensorHandle.ReportCapture(filename, sensorSpatialData, ("camera_intrinsic", intrinsics));

FileAssert.Exists(capturesPath);
AssertJsonFileEquals(capturesJsonExpected, capturesPath);
#endif
#endif
#if false
var go = new GameObject("DatasetCapture");
var solo = go.AddComponent<SoloConsumer>();
solo._baseDirectory = "D:/PerceptionOutput/SoloConsumer";
solo.soloDatasetName = "go_test_go";
var timingsExpected = new(int step, int timestamp, bool expectNewSequence)[]
{
(0, 0, true),

};
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 2, 0);
var sensor = new RgbSensor();
Assert.IsTrue(sensorHandle.ShouldCaptureThisFrame);
sensorHandle.ReportSensor(sensor);
yield return null;
Assert.IsTrue(sensorHandle.ShouldCaptureThisFrame);
sensorHandle.ReportSensor(sensor);
yield return null;
DatasetCapture.Instance.StartNewSequence();
Assert.IsTrue(sensorHandle.ShouldCaptureThisFrame);
sensorHandle.ReportSensor(sensor);
yield return null;
Assert.IsTrue(sensorHandle.ShouldCaptureThisFrame);
sensorHandle.ReportSensor(sensor);
DatasetCapture.Instance.ResetSimulation();
Assert.IsFalse(sensorHandle.IsValid);
var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 0, CaptureTriggerMode.Scheduled, 2, 0);
//read all captures from the output directory
List<JObject> captures = new List<JObject>();
foreach (var capturesPath in Directory.EnumerateFiles(DatasetCapture.OutputDirectory, "captures_*.json"))
{
var capturesText = File.ReadAllText(capturesPath);
var jObject = JToken.ReadFrom(new JsonTextReader(new StringReader(capturesText)));
var captureJArray = (JArray)jObject["captures"];
captures.AddRange(captureJArray.Cast<JObject>());
}
Assert.AreEqual(timingsExpected.Length, captures.Count);
var currentSequenceId = "00";
for (int i = 0; i < timingsExpected.Length; i++)
{
var timingExpected = timingsExpected[i];
var text = captures[i];
Assert.AreEqual(timingExpected.step, text["step"].Value<int>());
Assert.AreEqual(timingExpected.timestamp, text["timestamp"].Value<int>());
var newSequenceId = text["sequence_id"].ToString();
if (timingExpected.expectNewSequence)
Assert.AreNotEqual(newSequenceId, currentSequenceId, $"Expected new sequence in frame {i}, but was same");
else
Assert.AreEqual(newSequenceId, currentSequenceId, $"Expected same sequence in frame {i}, but was new");
currentSequenceId = newSequenceId;
}
#endif
#if false
var sensorSpatialData = new SensorSpatialData(default, default, null, null);
Assert.IsTrue(sensorHandle.ShouldCaptureThisFrame);
sensorHandle.ReportCapture("f", sensorSpatialData);

currentSequenceId = newSequenceId;
}
#endif
yield return null;
#endif
//Format a float to match Newtonsoft.Json formatting
string Format(float value)
{

return result;
}
#if false
#if false
var filename = "my/file.png";
var annotationDefinitionGuid = Guid.NewGuid();

}}
]";
var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
sensorHandle.ReportCapture(filename, default);
var annotationDefinition = DatasetCapture.RegisterAnnotationDefinition("semantic segmentation", "pixel-wise semantic segmentation label", "PNG", annotationDefinitionGuid);
sensorHandle.ReportAnnotationFile(annotationDefinition, "annotations/semantic_segmentation_000.png");

FileAssert.Exists(capturesPath);
StringAssert.Contains(TestHelper.NormalizeJson(annotationsJsonExpected), EscapeGuids(File.ReadAllText(capturesPath)));
#endif
#if false
var values = new[]
{
new TestValues()

}}
]";
var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
sensorHandle.ReportAnnotationValues(annotationDefinition, values);
DatasetCapture.ResetSimulation();

FileAssert.Exists(capturesPath);
StringAssert.Contains(TestHelper.NormalizeJson(expectedAnnotation), EscapeGuids(File.ReadAllText(capturesPath)));
#endif
#if false
var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 100, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = RegisterSensor("camera", "", "", 100, CaptureTriggerMode.Scheduled, 1, 0);
#endif
#if false
var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 100, CaptureTriggerMode.Scheduled, 1, 0);
Assert.Thows<InvalidOperationException>(() => sensorHandle.ReportAnnotationValues(annotationDefinition, new int[0]));
#endif
var sensorHandle = DatasetCapture.RegisterSensor("camera", "", "", 100, CaptureTriggerMode.Scheduled, 1, 0);
Assert.Throws<InvalidOperationException>(() => sensorHandle.ReportAnnotationValues(annotationDefinition, new int[0]));
#if false
var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 100, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = RegisterSensor("camera", "", "", 100, CaptureTriggerMode.Scheduled, 1, 0);
#endif
#if false
var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
#endif
#if false
[Test]
public void ResetSimulation_CallsSimulationEnding()
{

{
LogAssert.ignoreFailingMessages = true; //we aren't worried about "Simulation ended with pending..."
var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var asyncAnnotation = sensorHandle.ReportAnnotationAsync(annotationDefinition);
Assert.IsTrue(asyncAnnotation.IsValid);

}}
]";
var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var asyncAnnotation = sensorHandle.ReportAnnotationAsync(annotationDefinition);
Assert.IsTrue(asyncAnnotation.IsPending);

}}
]";
var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var asyncAnnotation = sensorHandle.ReportAnnotationAsync(annotationDefinition);
Assert.IsTrue(asyncAnnotation.IsPending);

}
};
var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = DatasetCapture.RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
// Record one capture for this frame
sensorHandle.ReportCapture(fileName, default);

[Test]
public void ReportMetricValues_WhenCaptureNotExpected_Throws()
{
var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 100, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = RegisterSensor("camera", "", "", 100, CaptureTriggerMode.Scheduled, 1, 0);
Assert.Throws<InvalidOperationException>(() => sensorHandle.ReportMetric(metricDefinition, new int[0]));
}

var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 100, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = RegisterSensor("camera", "", "", 100, CaptureTriggerMode.Scheduled, 1, 0);
Assert.Throws<InvalidOperationException>(() => sensorHandle.ReportMetricAsync(metricDefinition));
}

var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
sensorHandle.ReportMetricAsync(metricDefinition);
DatasetCapture.ResetSimulation();
LogAssert.Expect(LogType.Error, new Regex("Simulation ended with pending .*"));

{
LogAssert.ignoreFailingMessages = true; //we aren't worried about "Simulation ended with pending..."
var ego = DatasetCapture.RegisterEgo("");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensorHandle = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var asyncMetric = sensorHandle.ReportMetricAsync(metricDefinition);
Assert.IsTrue(asyncMetric.IsValid);

var expectedLine = @"""step"": 0";
var metricDefinition = DatasetCapture.RegisterMetricDefinition("");
DatasetCapture.RegisterSensor(DatasetCapture.RegisterEgo(""), "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
yield return null;
yield return null;

var expectedLine = @"""step"": 0";
var metricDefinition = DatasetCapture.RegisterMetricDefinition("");
var sensor = DatasetCapture.RegisterSensor(DatasetCapture.RegisterEgo(""), "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensor = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
yield return null;
sensor.ReportMetric(metricDefinition, values);

}}";
var metricDefinition = DatasetCapture.RegisterMetricDefinition("");
var sensor = DatasetCapture.RegisterSensor(DatasetCapture.RegisterEgo(""), "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var sensor = RegisterSensor("camera", "", "", 0, CaptureTriggerMode.Scheduled, 1, 0);
var annotation = sensor.ReportAnnotationFile(DatasetCapture.RegisterAnnotationDefinition(""), "");
var valuesJsonArray = JArray.FromObject(values).ToString(Formatting.Indented);
if (async)

AssertJsonFileEquals(annotationDefinitionsJsonExpected, annotationDefinitionsPath);
}
#endif
static void AssertJsonFileEquals(string jsonExpected, string jsonPath, bool escapeGuids = true, bool ignoreFormatting = false)
{
FileAssert.Exists(jsonPath);

result = TestHelper.NormalizeJson(result);
return result;
}
#endif
}

9
com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/TestFixedLengthScenario.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.Perception.Randomization.Scenarios;

[AddComponentMenu("")]
class TestFixedLengthScenario : FixedLengthScenario
{
#if false
protected override IEnumerator OnComplete()
{
yield return StartCoroutine(DatasetCapture.Instance.ResetSimulation());
}
#else
#endif
}
}

8
com.unity.perception/Editor/GroundTruth/DatasetConsumer.meta


fileFormatVersion: 2
guid: 3cc809492ae10b840963071dbc2e6e39
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

27
com.unity.perception/Runtime/GroundTruth/Consumers/NoOpConsumer.cs


using UnityEngine.Perception.GroundTruth.DataModel;
namespace UnityEngine.Perception.GroundTruth.Consumers
{
public class NoOpConsumer : ConsumerEndpoint
{
protected override bool IsComplete()
{
return true;
}
public override void OnSimulationStarted(SimulationMetadata metadata)
{
// Do nothing, drop everything on the floor
}
public override void OnFrameGenerated(Frame frame)
{
// Do nothing, drop everything on the floor
}
public override void OnSimulationCompleted(CompletionMetadata metadata)
{
// Do nothing, drop everything on the floor
}
}
}

11
com.unity.perception/Runtime/GroundTruth/Consumers/NoOpConsumer.cs.meta


fileFormatVersion: 2
guid: 47182fdcdec0dc74fa26fcd45504eb3d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

253
com.unity.perception/Editor/GroundTruth/DatasetConsumer/AddConsumerEndpointMenu.cs


using System;
using System.Collections.Generic;
using NUnit.Framework;
using Unity.Mathematics;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.UIElements;
namespace UnityEditor.Perception.GroundTruth.DatasetConsumer
{
public class AddConsumerEndpointMenu : VisualElement
{
const string k_DefaultDirectoryText = "ConsumerEndpoints";
string m_CurrentPath = string.Empty;
VisualElement m_DirectoryChevron;
TextElement m_DirectoryLabelText;
Dictionary<string, HashSet<string>> m_MenuDirectories = new Dictionary<string, HashSet<string>>();
VisualElement m_MenuElements;
List<MenuItem> m_MenuItems = new List<MenuItem>();
Dictionary<string, List<MenuItem>> m_MenuItemsMap = new Dictionary<string, List<MenuItem>>();
EndpointList m_EndpointList;
string m_SearchString = string.Empty;
public AddConsumerEndpointMenu(VisualElement parentElement, VisualElement button, EndpointList endpointList)
{
m_EndpointList = endpointList;
var template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
$"{StaticData.uxmlDir}/ConsumerEndpoints/AddConsumerEndpointMenu.uxml");
template.CloneTree(this);
style.position = new StyleEnum<Position>(Position.Absolute);
var buttonPosition = button.worldBound.position;
var top = math.min(buttonPosition.y, parentElement.worldBound.height - 300);
style.top = top;
style.left = buttonPosition.x;
focusable = true;
RegisterCallback<FocusOutEvent>(evt =>
{
if (evt.relatedTarget == null || ((VisualElement)evt.relatedTarget).FindCommonAncestor(this) != this)
ExitMenu();
});
var directoryLabel = this.Q<VisualElement>("directory-label");
directoryLabel.RegisterCallback<MouseUpEvent>(evt => { AscendDirectory(); });
m_DirectoryLabelText = this.Q<TextElement>("directory-label-text");
m_DirectoryChevron = this.Q<VisualElement>("directory-chevron");
var searchBar = this.Q<TextField>("search-bar");
searchBar.schedule.Execute(() => searchBar.ElementAt(0).Focus());
searchBar.RegisterValueChangedCallback(evt => searchString = evt.newValue);
m_MenuElements = this.Q<VisualElement>("menu-options");
CreateMenuItems();
DrawDirectoryItems();
}
string currentPath
{
get => m_CurrentPath;
set
{
m_CurrentPath = value;
DrawDirectoryItems();
}
}
string currentPathName
{
get
{
if (m_CurrentPath == string.Empty)
return k_DefaultDirectoryText;
var pathItems = m_CurrentPath.Split('/');
return pathItems[pathItems.Length - 1];
}
}
string searchString
{
get => m_SearchString;
set
{
m_SearchString = value;
if (m_SearchString == string.Empty)
DrawDirectoryItems();
else
DrawSearchItems();
}
}
string directoryText
{
set
{
m_DirectoryLabelText.text = value;
m_DirectoryChevron.style.visibility = value == k_DefaultDirectoryText
? new StyleEnum<Visibility>(Visibility.Hidden)
: new StyleEnum<Visibility>(Visibility.Visible);
}
}
void ExitMenu()
{
parent.Remove(this);
}
void AddEndpoint(Type endpointType)
{
#if false
m_EndpointList.AddEndpoint(endpointType);
ExitMenu();
#endif
}
void AscendDirectory()
{
var pathItems = m_CurrentPath.Split('/');
var path = pathItems[0];
for (var i = 1; i < pathItems.Length - 1; i++)
path = $"{path}/{pathItems[i]}";
currentPath = path;
}
void DrawDirectoryItems()
{
directoryText = currentPathName;
m_MenuElements.Clear();
if (m_MenuDirectories.ContainsKey(currentPath))
{
var directories = m_MenuDirectories[currentPath];
foreach (var directory in directories)
m_MenuElements.Add(new MenuDirectoryElement(directory, this));
}
if (m_MenuItemsMap.ContainsKey(currentPath))
{
var menuItems = m_MenuItemsMap[currentPath];
foreach (var menuItem in menuItems)
m_MenuElements.Add(new MenuItemElement(menuItem, this));
}
}
void DrawSearchItems()
{
directoryText = k_DefaultDirectoryText;
m_MenuElements.Clear();
var upperSearchString = searchString.ToUpper();
foreach (var menuItem in m_MenuItems)
if (menuItem.itemName.ToUpper().Contains(upperSearchString))
m_MenuElements.Add(new MenuItemElement(menuItem, this));
}
void CreateMenuItems()
{
var rootList = new List<MenuItem>();
m_MenuItemsMap.Add(string.Empty, rootList);
var endpointTypeSet = new HashSet<Type>();
#if false
foreach (var endpoint in m_EndpointList.datasetCapture.consumerEndpoints)
endpointTypeSet.Add(endpoint.GetType());
#endif
foreach (var endpointType in StaticData.endpointTypes)
{
if (endpointTypeSet.Contains(endpointType))
continue;
var menuAttribute = (AddConsumerEndpointMenuAttribute)Attribute.GetCustomAttribute(
endpointType, typeof(AddConsumerEndpointMenuAttribute));
if (menuAttribute != null)
{
var pathItems = menuAttribute.menuPath.Split('/');
if (pathItems.Length > 1)
{
var path = string.Empty;
var itemName = pathItems[pathItems.Length - 1];
for (var i = 0; i < pathItems.Length - 1; i++)
{
var childPath = $"{path}/{pathItems[i]}";
if (i < pathItems.Length - 1)
{
if (!m_MenuDirectories.ContainsKey(path))
m_MenuDirectories.Add(path, new HashSet<string>());
m_MenuDirectories[path].Add(childPath);
}
path = childPath;
}
if (!m_MenuItemsMap.ContainsKey(path))
m_MenuItemsMap.Add(path, new List<MenuItem>());
var item = new MenuItem(endpointType, itemName);
m_MenuItems.Add(item);
m_MenuItemsMap[path].Add(item);
}
else
{
if (pathItems.Length == 0)
throw new AssertionException("Empty consumer endpoint menu path");
var item = new MenuItem(endpointType, pathItems[0]);
m_MenuItems.Add(item);
rootList.Add(item);
}
}
else
{
rootList.Add(new MenuItem(endpointType, endpointType.Name));
}
}
m_MenuItems.Sort((item1, item2) => item1.itemName.CompareTo(item2.itemName));
}
class MenuItem
{
public string itemName;
public Type endpointType;
public MenuItem(Type endpointType, string itemName)
{
this.endpointType = endpointType;
this.itemName = itemName;
}
}
sealed class MenuItemElement : TextElement
{
public MenuItemElement(MenuItem menuItem, AddConsumerEndpointMenu menu)
{
text = menuItem.itemName;
AddToClassList("consumer-endpoint__add-menu-directory-item");
RegisterCallback<MouseUpEvent>(evt => menu.AddEndpoint(menuItem.endpointType));
}
}
sealed class MenuDirectoryElement : VisualElement
{
public MenuDirectoryElement(string directory, AddConsumerEndpointMenu menu)
{
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
$"{StaticData.uxmlDir}/ConsumerEndpoint/MenuDirectoryElement.uxml").CloneTree(this);
var pathItems = directory.Split('/');
this.Q<TextElement>("directory").text = pathItems[pathItems.Length - 1];
RegisterCallback<MouseUpEvent>(evt => menu.currentPath = directory);
}
}
}
}

11
com.unity.perception/Editor/GroundTruth/DatasetConsumer/AddConsumerEndpointMenu.cs.meta


fileFormatVersion: 2
guid: 544559f30bb964a4fa67eb732cc7b47a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

14
com.unity.perception/Editor/GroundTruth/DatasetConsumer/AddConsumerEndpointMenuAttribute.cs


using System;
namespace UnityEditor.Perception.GroundTruth.DatasetConsumer
{
public class AddConsumerEndpointMenuAttribute : Attribute
{
public string menuPath;
public AddConsumerEndpointMenuAttribute(string menuPath)
{
this.menuPath = menuPath;
}
}
}

11
com.unity.perception/Editor/GroundTruth/DatasetConsumer/AddConsumerEndpointMenuAttribute.cs.meta


fileFormatVersion: 2
guid: 3ad70a0ee31b79c449e1363a0b01c487
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

79
com.unity.perception/Editor/GroundTruth/DatasetConsumer/ConsumerEndpointElement.cs


using System;
using UnityEditor.Perception.Randomization;
using UnityEditor.UIElements;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.UIElements;
namespace UnityEditor.Perception.GroundTruth.DatasetConsumer
{
public class ConsumerEndpointElement : VisualElement
{
const string k_CollapsedParameterClass = "collapsed";
SerializedProperty m_Collapsed;
VisualElement m_PropertiesContainer;
SerializedProperty m_Property;
public ConsumerEndpointElement(SerializedProperty property, EndpointList endpointList)
{
m_Property = property;
this.endpointList = endpointList;
m_Collapsed = property.FindPropertyRelative("collapsed");
collapsed = m_Collapsed.boolValue;
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
$"{StaticData.uxmlDir}/ConsumerEndpoint/ConsumerEndpointElement.uxml").CloneTree(this);
var classNameLabel = this.Q<TextElement>("class-name");
var splitType = property.managedReferenceFullTypename.Split(' ', '.');
classNameLabel.text = splitType[splitType.Length - 1];
m_PropertiesContainer = this.Q<VisualElement>("properties");
var collapseToggle = this.Q<VisualElement>("collapse");
collapseToggle.RegisterCallback<MouseUpEvent>(evt => collapsed = !collapsed);
var enabledToggle = this.Q<Toggle>("enabled");
enabledToggle.BindProperty(property.FindPropertyRelative("m_Enabled"));
var removeButton = this.Q<Button>("remove");
// removeButton.clicked += () => endpointList.RemoveEndpoint(this);
// this.AddManipulator(new DragToReorderManipulator());
FillPropertiesContainer();
}
ConsumerEndpoint endpoint => (ConsumerEndpoint)StaticData.GetManagedReferenceValue(m_Property);
public Type endpointType => endpoint.GetType();
public EndpointList endpointList { get; }
public bool collapsed
{
get => m_Collapsed?.boolValue ?? true;
set
{
if (m_Collapsed == null)
return;
m_Collapsed.boolValue = value;
m_Property.serializedObject.ApplyModifiedPropertiesWithoutUndo();
if (value)
AddToClassList(k_CollapsedParameterClass);
else
RemoveFromClassList(k_CollapsedParameterClass);
}
}
void FillPropertiesContainer()
{
m_PropertiesContainer.Clear();
UIElementsEditorUtilities.CreatePropertyFields(m_Property, m_PropertiesContainer);
if (m_PropertiesContainer.childCount == 0)
m_PropertiesContainer.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None);
}
}
}

11
com.unity.perception/Editor/GroundTruth/DatasetConsumer/ConsumerEndpointElement.cs.meta


fileFormatVersion: 2
guid: 1c2bdd53b35277e4c8f7ba95c6bffedd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

31
com.unity.perception/Editor/GroundTruth/DatasetConsumer/DatasetCaptureEditor.cs


using UnityEngine.Perception.GroundTruth;
using UnityEngine.UIElements;
namespace UnityEditor.Perception.GroundTruth.DatasetConsumer
{
[CustomEditor(typeof(DatasetCapture), true)]
public class DatasetCaptureEditor : Editor
{
DatasetCapture m_DatasetCapture;
SerializedObject m_SerializedObject;
VisualElement m_EndpointsPlaceholder;
VisualElement m_Root;
public override VisualElement CreateInspectorGUI()
{
#if false
m_DatasetCapture = (DatasetCapture)target;
m_SerializedObject = new SerializedObject(m_DatasetCapture);
m_Root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
$"{StaticData.uxmlDir}/DatasetCaptureElement.uxml").CloneTree();
m_EndpointsPlaceholder = m_Root.Q<VisualElement>("endpoint-list-placeholder");
// m_EndpointsPlaceholder.Add(new EndpointList());
return m_Root;
#endif
return null;
}
}
}

11
com.unity.perception/Editor/GroundTruth/DatasetConsumer/DatasetCaptureEditor.cs.meta


fileFormatVersion: 2
guid: e029f41d3f1427e4ba7db2d06efee341
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

111
com.unity.perception/Editor/GroundTruth/DatasetConsumer/EndpointList.cs


using System;
using System.Net;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.UIElements;
namespace UnityEditor.Perception.GroundTruth.DatasetConsumer
{
public class EndpointList : VisualElement
{
VisualElement m_Container;
SerializedProperty m_Property;
public EndpointList(SerializedProperty property)
{
m_Property = property;
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
$"{StaticData.uxmlDir}/EndpointList.uxml").CloneTree(this);
m_Container = this.Q<VisualElement>("consumer-endpoint-container");
var addEndpointButton = this.Q<Button>("add-consumer-endpoint-button");
addEndpointButton.clicked += () =>
{
inspectorContainer.Add(new AddConsumerEndpointMenu(inspectorContainer, addEndpointButton, this));
};
#if false
var expandAllButton = this.Q<Button>("expand-all");
expandAllButton.clicked += () => CollapseEndpoints(false);
var collapseAllButton = this.Q<Button>("collapse-all");
collapseAllButton.clicked += () => CollapseEndpoints(true);
#endif
RefreshList();
Undo.undoRedoPerformed += () =>
{
m_Property.serializedObject.Update();
RefreshList();
};
}
#if false
public DatasetCapture datasetCapture => (DatasetCapture)m_Property.serializedObject.targetObject;
#endif
VisualElement inspectorContainer
{
get
{
var viewport = parent;
while (!viewport.ClassListContains("unity-inspector-main-container"))
viewport = viewport.parent;
return viewport;
}
}
void RefreshList()
{
m_Container.Clear();
if (m_Property.arraySize > 0 &&
string.IsNullOrEmpty(m_Property.GetArrayElementAtIndex(0).managedReferenceFullTypename))
{
var textElement = new TextElement()
{
text = "One or more endpoints have missing scripts. See console for more info."
};
textElement.AddToClassList("dataset_capture__info-box");
textElement.AddToClassList("dataset_capture__error-box");
m_Container.Add(textElement);
return;
}
for (var i = 0; i < m_Property.arraySize; i++)
m_Container.Add(new ConsumerEndpointElement(m_Property.GetArrayElementAtIndex(i), this));
}
#if false
public void AddEndpoint(Type endpointType)
{
Undo.RegisterCompleteObjectUndo(m_Property.serializedObject.targetObject, "Add Consumer Endpoint");
datasetCapture.CreateConsumerEndpoint(endpointType);
m_Property.serializedObject.Update();
RefreshList();
}
public void RemoveEndpoint(ConsumerEndpointElement element)
{
Undo.RegisterCompleteObjectUndo(m_Property.serializedObject.targetObject, "Remove Consumer Endpoint");
datasetCapture.RemoveConsumerEndpointAt(element.parent.IndexOf(element));
m_Property.serializedObject.Update();
RefreshList();
}
public void ReorderEndpoints(int currentIndex, int nextIndex)
{
if (currentIndex == nextIndex)
return;
if (nextIndex > currentIndex)
nextIndex--;
Undo.RegisterCompleteObjectUndo(m_Property.serializedObject.targetObject, "Reorder Consumer Endpoint");
var endpoint = datasetCapture.GetConsumerEndpoint(currentIndex);
datasetCapture.RemoveConsumerEndpointAt(currentIndex);
datasetCapture.InsertConsumerEndpoint(nextIndex, endpoint);
m_Property.serializedObject.Update();
RefreshList();
}
void CollapseEndpoints(bool collapsed)
{
foreach (var child in m_Container.Children())
((ConsumerEndpointElement)child).collapsed = collapsed;
}
#endif
}
}

11
com.unity.perception/Editor/GroundTruth/DatasetConsumer/EndpointList.cs.meta


fileFormatVersion: 2
guid: ffff1c74e2a357f458147ff9be9e6071
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

93
com.unity.perception/Editor/GroundTruth/DatasetConsumer/StaticData.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine.Perception.GroundTruth;
namespace UnityEditor.Perception.GroundTruth.DatasetConsumer
{
public static class StaticData
{
const string k_ConsumerEndpointDir = "Packages/com.unity.perception/Editor/GroundTruth/DatasetConsumer";
internal const string uxmlDir = k_ConsumerEndpointDir + "/Uxml";
internal static Type[] endpointTypes;
static StaticData()
{
endpointTypes = GetConstructableDerivedTypes<ConsumerEndpoint>();
}
static Type[] GetConstructableDerivedTypes<T>()
{
var collection = TypeCache.GetTypesDerivedFrom<T>();
var types = new List<Type>();
foreach (var type in collection)
if (!type.IsAbstract && !type.IsInterface)
types.Add(type);
return types.ToArray();
}
public static FieldInfo GetField(Type type, string fieldName)
{
if (type == null)
return null;
const BindingFlags flags =
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance |BindingFlags.DeclaredOnly;
var fields = type.GetFields(flags);
foreach (var field in fields)
if (field.Name == fieldName)
return field;
return GetField(type.BaseType, fieldName);
}
static object GetValue(object source, string name)
{
if (source == null)
return null;
var type = source.GetType();
var field = GetField(type, name);
if (field == null)
{
var property = type.GetProperty(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
return property == null ? null : property.GetValue(source, null);
}
return field.GetValue(source);
}
static object GetArrayValue(object source, string name, int index)
{
var value = GetValue(source, name);
if (!(value is IEnumerable enumerable))
return null;
var enumerator = enumerable.GetEnumerator();
while (index-- >= 0)
enumerator.MoveNext();
return enumerator.Current;
}
public static object GetManagedReferenceValue(SerializedProperty prop, bool parent = false)
{
var path = prop.propertyPath.Replace(".Array.data[", "[");
object obj = prop.serializedObject.targetObject;
var elements = path.Split('.');
if (parent)
elements = elements.Take(elements.Length - 1).ToArray();
foreach (var element in elements)
if (element.Contains("["))
{
var elementName = element.Substring(0, element.IndexOf("["));
var index = Convert.ToInt32(element.Substring(element.IndexOf("[")).Replace("[", "").Replace("]", ""));
obj = GetArrayValue(obj, elementName, index);
}
else
{
obj = GetValue(obj, element);
}
return obj;
}
}
}

11
com.unity.perception/Editor/GroundTruth/DatasetConsumer/StaticData.cs.meta


fileFormatVersion: 2
guid: ef7a918bf9607df47814d7a7041454a8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
com.unity.perception/Editor/GroundTruth/DatasetConsumer/Uxml.meta


fileFormatVersion: 2
guid: a9e1dad40ca390d42a0dcb2b136042d9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

16
com.unity.perception/Editor/GroundTruth/DatasetConsumer/Uxml/ConsumerEndpointElement.uxml


<UXML xmlns="UnityEngine.UIElements">
<VisualElement class="consumer-endpoint__element">
<VisualElement name="drag-handle" class="consumer-endpoint__drag-handle"/>
<VisualElement style="flex-grow: 1;">
<VisualElement style="flex-direction: row; justify-content: space-between;">
<VisualElement style="flex-direction: row; align-items: center;">
<VisualElement name="collapse" class="randomization__collapse-toggle foldout-open"/>
<Toggle name="enabled"/>
<TextElement name="class-name" text="Consumer Endpoint Class Name"/>
</VisualElement>
<Button name="remove" class="randomization__remove-item-button"/>
</VisualElement>
<VisualElement name="properties" class="randomization__collapsible-container" style="padding-left: 16px;"/>
</VisualElement>
</VisualElement>
</UXML>

10
com.unity.perception/Editor/GroundTruth/DatasetConsumer/Uxml/ConsumerEndpointElement.uxml.meta


fileFormatVersion: 2
guid: 18ab57ec859168e4db7287a0dcc1206f
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

6
com.unity.perception/Editor/GroundTruth/DatasetConsumer/Uxml/DatasetCaptureElement.uxml


<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements">
<VisualElement>
<Style src="../../Uss/Styles.uss"/>
<VisualElement name="endpoint-list-placeholder" style = "margin-top: 10px"/>
</VisualElement>
</UXML>

10
com.unity.perception/Editor/GroundTruth/DatasetConsumer/Uxml/DatasetCaptureElement.uxml.meta


fileFormatVersion: 2
guid: d55dcb751c632144ca061bf5bc90f892
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

16
com.unity.perception/Editor/GroundTruth/DatasetConsumer/Uxml/EndpointList.uxml


<UXML xmlns="UnityEngine.UIElements">
<VisualElement style="min-height: 132px;">
<VisualElement class="dataset-capture__dark-viewport">
<TextElement text="Consumer Endpoints" class="scenario__title-label"/>
<TextElement
class="dataset-capture__info-box"
text="Need to say a bunch of stuff here."/>
<VisualElement name="consumer-endpoints-container" style="margin-top: 3px; min-height: 100px;"/>
<VisualElement style="flex-direction: row; align-items: center; justify-content: center; margin-top: 2px;">
<Button name="add-consumer-endpoint-button" text="Add Endpoint"/>
<Button name="expand-all" text="Expand All"/>
<Button name="collapse-all" text="Collapse All"/>
</VisualElement>
</VisualElement>
</VisualElement>
</UXML>

10
com.unity.perception/Editor/GroundTruth/DatasetConsumer/Uxml/EndpointList.uxml.meta


fileFormatVersion: 2
guid: c1b51a431ff3c334b8d57dba2acf2ee2
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
正在加载...
取消
保存