浏览代码

Renames, namespace updates, docs, and misc cleanup

/main
Jon Hogins 5 年前
当前提交
5eac8e47
共有 37 个文件被更改,包括 424 次插入536 次删除
  1. 1
      TestProjects/PerceptionURP/Packages/manifest.json
  2. 111
      com.unity.perception/Editor/GroundTruth/LabelingConfigurationEditor.cs
  3. 76
      com.unity.perception/Editor/GroundTruth/LabelingEditor.cs
  4. 2
      com.unity.perception/Editor/GroundTruth/ObjectCountPassEditor.cs
  5. 4
      com.unity.perception/Editor/GroundTruth/SemanticSegmentationPassEditor.cs
  6. 3
      com.unity.perception/Runtime/GroundTruth/BoundingBoxOrigin.cs
  7. 2
      com.unity.perception/Runtime/GroundTruth/DatasetJsonUtility.cs
  8. 156
      com.unity.perception/Runtime/GroundTruth/GroundTruthCrossPipelinePass.cs
  9. 8
      com.unity.perception/Runtime/GroundTruth/GroundTruthInfo.cs
  10. 25
      com.unity.perception/Runtime/GroundTruth/GroundTruthLabelSetupSystem.cs
  11. 89
      com.unity.perception/Runtime/GroundTruth/GroundTruthRendererFeature.cs
  12. 17
      com.unity.perception/Runtime/GroundTruth/IGroundTruthGenerator.cs
  13. 109
      com.unity.perception/Runtime/GroundTruth/InstanceSegmentationCrossPipelinePass.cs
  14. 18
      com.unity.perception/Runtime/GroundTruth/Labeling/Labeling.cs
  15. 2
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration.cs
  16. 8
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  17. 1
      com.unity.perception/Runtime/GroundTruth/RenderTextureReader.cs
  18. 10
      com.unity.perception/Runtime/GroundTruth/RenderedObjectInfoGenerator.cs
  19. 4
      com.unity.perception/Runtime/GroundTruth/SemanticSegmentationCrossPipelinePass.cs
  20. 2
      com.unity.perception/Runtime/GroundTruth/SimulationManagementComponentSystem.cs
  21. 45
      com.unity.perception/Runtime/GroundTruth/SimulationManager.cs
  22. 18
      com.unity.perception/Runtime/GroundTruth/SimulationState.cs
  23. 10
      com.unity.perception/Runtime/GroundTruth/SimulationState_Json.cs
  24. 2
      com.unity.perception/Tests/Runtime/GroundTruthTests/BoundingBox2DTests.cs
  25. 2
      com.unity.perception/Tests/Runtime/GroundTruthTests/DatasetJsonUtilityTests.cs
  26. 2
      com.unity.perception/Tests/Runtime/GroundTruthTests/GroundTruthTestBase.cs
  27. 6
      com.unity.perception/Tests/Runtime/GroundTruthTests/ObjectCountTests.cs
  28. 6
      com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs
  29. 3
      com.unity.perception/Tests/Runtime/GroundTruthTests/SimulationManagerTests.cs
  30. 3
      com.unity.perception/Tests/Runtime/GroundTruthTests/SimulationManager_SensorSchedulingTests.cs
  31. 38
      com.unity.perception/Runtime/GroundTruth/Ego.cs
  32. 31
      com.unity.perception/Runtime/GroundTruth/EgoMarker.cs
  33. 135
      com.unity.perception/Runtime/GroundTruth/MetricData.cs
  34. 11
      com.unity.perception/Runtime/GroundTruth/MetricData.cs.meta
  35. 0
      /com.unity.perception/Editor/GroundTruth/SemanticSegmentationPassEditor.cs.meta
  36. 0
      /com.unity.perception/Editor/GroundTruth/SemanticSegmentationPassEditor.cs
  37. 0
      /com.unity.perception/Runtime/GroundTruth/Ego.cs.meta

1
TestProjects/PerceptionURP/Packages/manifest.json


"com.unity.collab-proxy": "1.2.16",
"com.unity.ide.rider": "1.1.4",
"com.unity.ide.vscode": "1.1.4",
"com.unity.package-validation-suite": "0.9.1-preview",
"com.unity.perception": "file:../../../com.unity.perception",
"com.unity.render-pipelines.universal": "7.3.1",
"com.unity.simulation.capture": "0.0.10-preview.6",

111
com.unity.perception/Editor/GroundTruth/LabelingConfigurationEditor.cs


using UnityEditor;
using UnityEditorInternal;
using UnityEditorInternal;
using UnityEngine.Perception.Sensors;
using UnityEngine.Perception.GroundTruth;
[CustomEditor(typeof(LabelingConfiguration))]
public class LabelingConfigurationEditor : Editor
namespace UnityEditor.Perception.GroundTruth
ReorderableList m_LabelsList;
public void OnEnable()
[CustomEditor(typeof(LabelingConfiguration))]
class LabelingConfigurationEditor : Editor
m_LabelsList = new ReorderableList(this.serializedObject, this.serializedObject.FindProperty(nameof(LabelingConfiguration.LabelingConfigurations)), true, false, true, true);
m_LabelsList.elementHeight = EditorGUIUtility.singleLineHeight * 2;
m_LabelsList.drawElementCallback = DrawElement;
m_LabelsList.onAddCallback += OnAdd;
m_LabelsList.onRemoveCallback += OnRemove;
}
ReorderableList m_LabelsList;
void OnRemove(ReorderableList list)
{
if (list.index != -1)
list.serializedProperty.DeleteArrayElementAtIndex(list.index);
public void OnEnable()
{
m_LabelsList = new ReorderableList(this.serializedObject, this.serializedObject.FindProperty(nameof(LabelingConfiguration.LabelingConfigurations)), true, false, true, true);
m_LabelsList.elementHeight = EditorGUIUtility.singleLineHeight * 2;
m_LabelsList.drawElementCallback = DrawElement;
m_LabelsList.onAddCallback += OnAdd;
m_LabelsList.onRemoveCallback += OnRemove;
}
this.serializedObject.ApplyModifiedProperties();
EditorUtility.SetDirty(target);
}
void OnRemove(ReorderableList list)
{
if (list.index != -1)
list.serializedProperty.DeleteArrayElementAtIndex(list.index);
LabelingConfiguration config => (LabelingConfiguration)this.target;
this.serializedObject.ApplyModifiedProperties();
EditorUtility.SetDirty(target);
}
void OnAdd(ReorderableList list)
{
var index = list.serializedProperty.arraySize;
list.serializedProperty.InsertArrayElementAtIndex(index);
var element = list.serializedProperty.GetArrayElementAtIndex(index);
var labelProperty = element.FindPropertyRelative(nameof(LabelingConfigurationEntry.label));
labelProperty.stringValue = "";
var valueProperty = element.FindPropertyRelative(nameof(LabelingConfigurationEntry.value));
valueProperty.intValue = 0;
serializedObject.ApplyModifiedProperties();
EditorUtility.SetDirty(target);
}
void OnAdd(ReorderableList list)
{
var index = list.serializedProperty.arraySize;
list.serializedProperty.InsertArrayElementAtIndex(index);
var element = list.serializedProperty.GetArrayElementAtIndex(index);
var labelProperty = element.FindPropertyRelative(nameof(LabelingConfigurationEntry.label));
labelProperty.stringValue = "";
var valueProperty = element.FindPropertyRelative(nameof(LabelingConfigurationEntry.value));
valueProperty.intValue = 0;
serializedObject.ApplyModifiedProperties();
EditorUtility.SetDirty(target);
}
void DrawElement(Rect rect, int index, bool isactive, bool isfocused)
{
var element = m_LabelsList.serializedProperty.GetArrayElementAtIndex(index);
var labelProperty = element.FindPropertyRelative(nameof(LabelingConfigurationEntry.label));
var valueProperty = element.FindPropertyRelative(nameof(LabelingConfigurationEntry.value));
using (var change = new EditorGUI.ChangeCheckScope())
void DrawElement(Rect rect, int index, bool isactive, bool isfocused)
var contentRect = new Rect(rect.position, new Vector2(rect.width, EditorGUIUtility.singleLineHeight));
var newLabel = EditorGUI.TextField(contentRect, nameof(LabelingConfigurationEntry.label), labelProperty.stringValue);
if (change.changed)
labelProperty.stringValue = newLabel;
var element = m_LabelsList.serializedProperty.GetArrayElementAtIndex(index);
var labelProperty = element.FindPropertyRelative(nameof(LabelingConfigurationEntry.label));
var valueProperty = element.FindPropertyRelative(nameof(LabelingConfigurationEntry.value));
using (var change = new EditorGUI.ChangeCheckScope())
{
var contentRect = new Rect(rect.position, new Vector2(rect.width, EditorGUIUtility.singleLineHeight));
var newLabel = EditorGUI.TextField(contentRect, nameof(LabelingConfigurationEntry.label), labelProperty.stringValue);
if (change.changed)
labelProperty.stringValue = newLabel;
}
using (var change = new EditorGUI.ChangeCheckScope())
{
var contentRect = new Rect(rect.position + new Vector2(0, EditorGUIUtility.singleLineHeight), new Vector2(rect.width, EditorGUIUtility.singleLineHeight));
var newValue = EditorGUI.IntField(contentRect, nameof(LabelingConfigurationEntry.value), valueProperty.intValue);
if (change.changed)
valueProperty.intValue = newValue;
}
using (var change = new EditorGUI.ChangeCheckScope())
public override void OnInspectorGUI()
var contentRect = new Rect(rect.position + new Vector2(0, EditorGUIUtility.singleLineHeight), new Vector2(rect.width, EditorGUIUtility.singleLineHeight));
var newValue = EditorGUI.IntField(contentRect, nameof(LabelingConfigurationEntry.value), valueProperty.intValue);
if (change.changed)
valueProperty.intValue = newValue;
m_LabelsList.DoLayoutList();
this.serializedObject.ApplyModifiedProperties();
}
public override void OnInspectorGUI()
{
m_LabelsList.DoLayoutList();
this.serializedObject.ApplyModifiedProperties();
}
}

76
com.unity.perception/Editor/GroundTruth/LabelingEditor.cs


using UnityEditor;
using UnityEditorInternal;
using UnityEditorInternal;
[CustomEditor(typeof(Labeling))]
public class LabelingEditor : Editor
namespace UnityEditor.Perception.GroundTruth
const int k_Indent = 7;
ReorderableList m_LabelsList;
public void OnEnable()
[CustomEditor(typeof(Labeling))]
class LabelingEditor : Editor
m_LabelsList = new ReorderableList(this.serializedObject, this.serializedObject.FindProperty(nameof(Labeling.classes)), true, false, true, true);
m_LabelsList.drawElementCallback = DrawElement;
m_LabelsList.onAddCallback += OnAdd;
m_LabelsList.onRemoveCallback += OnRemove;
}
const int k_Indent = 7;
ReorderableList m_LabelsList;
void OnRemove(ReorderableList list)
{
if (list.index != -1)
labeling.classes.RemoveAt(list.index);
}
public void OnEnable()
{
m_LabelsList = new ReorderableList(serializedObject, serializedObject.FindProperty(nameof(global::Labeling.classes)), true, false, true, true);
m_LabelsList.drawElementCallback = DrawElement;
m_LabelsList.onAddCallback += OnAdd;
m_LabelsList.onRemoveCallback += OnRemove;
}
Labeling labeling => (Labeling)this.target;
void OnRemove(ReorderableList list)
{
if (list.index != -1)
Labeling.classes.RemoveAt(list.index);
}
void OnAdd(ReorderableList list)
{
labeling.classes.Add("");
}
Labeling Labeling => (Labeling)target;
void DrawElement(Rect rect, int index, bool isactive, bool isfocused)
{
using (var change = new EditorGUI.ChangeCheckScope())
void OnAdd(ReorderableList list)
var indent = k_Indent * index;
if (indent >= rect.width)
return;
Labeling.classes.Add("");
}
var contentRect = new Rect(rect.x + indent, rect.y, rect.width - indent, rect.height);
var value = EditorGUI.TextField(contentRect, labeling.classes[index]);
if (change.changed)
void DrawElement(Rect rect, int index, bool isactive, bool isfocused)
{
using (var change = new EditorGUI.ChangeCheckScope())
labeling.classes[index] = value;
var indent = k_Indent * index;
if (indent >= rect.width)
return;
var contentRect = new Rect(rect.x + indent, rect.y, rect.width - indent, rect.height);
var value = EditorGUI.TextField(contentRect, Labeling.classes[index]);
if (change.changed)
{
Labeling.classes[index] = value;
}
}
public override void OnInspectorGUI()
{
m_LabelsList.DoLayoutList();
public override void OnInspectorGUI()
{
m_LabelsList.DoLayoutList();
}
}
}

2
com.unity.perception/Editor/GroundTruth/ObjectCountPassEditor.cs


using UnityEditor;
using UnityEditor.Rendering.HighDefinition;
namespace UnityEngine.Perception.Sensors.Editor
namespace UnityEditor.Perception.GroundTruth
{
[CustomPassDrawer(typeof(ObjectCountPass))]
public class ObjectCountPassEditor : BaseCustomPassDrawer

4
com.unity.perception/Editor/GroundTruth/SemanticSegmentationPassEditor.cs


using UnityEditor;
using UnityEditor.Rendering.HighDefinition;
namespace UnityEngine.Perception.Sensors.Editor
namespace UnityEditor.Perception.GroundTruth
public class SemanticSegmentationPassEditor : BaseCustomPassDrawer
class SemanticSegmentationPassEditor : BaseCustomPassDrawer
{
protected override void Initialize(SerializedProperty customPass)
{

3
com.unity.perception/Runtime/GroundTruth/BoundingBoxOrigin.cs


using System;
namespace UnityEngine.Perception {
namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
/// The origin to use for bounding box calculation
/// </summary>

2
com.unity.perception/Runtime/GroundTruth/DatasetJsonUtility.cs


using Newtonsoft.Json.Linq;
using Unity.Mathematics;
namespace UnityEngine.Perception.Sensors
namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
/// Utilities for producing Json for datasets.

156
com.unity.perception/Runtime/GroundTruth/GroundTruthCrossPipelinePass.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
using UnityEngine.Perception.Sensors;
public abstract class GroundTruthCrossPipelinePass : IGroundTruthGenerator
namespace UnityEngine.Perception.GroundTruth
public Camera targetCamera;
bool m_IsActivated;
protected GroundTruthCrossPipelinePass(Camera targetCamera)
abstract class GroundTruthCrossPipelinePass : IGroundTruthGenerator
this.targetCamera = targetCamera;
}
public Camera targetCamera;
public virtual void Setup()
{
if (targetCamera == null)
throw new InvalidOperationException("targetCamera may not be null");
bool m_IsActivated;
// If we are forced to activate here we will get zeroes in the first frame.
EnsureActivated();
}
protected GroundTruthCrossPipelinePass(Camera targetCamera)
{
this.targetCamera = targetCamera;
}
public void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult)
{
// CustomPasses are executed for each camera. We only want to run for the target camera
if (camera != targetCamera)
return;
public virtual void Setup()
{
if (targetCamera == null)
throw new InvalidOperationException("targetCamera may not be null");
ExecutePass(renderContext, cmd, camera, cullingResult);
}
protected abstract void ExecutePass(ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult);
// If we are forced to activate here we will get zeroes in the first frame.
EnsureActivated();
}
public void EnsureActivated()
{
if (!m_IsActivated)
public void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult)
var labelSetupSystem = World.DefaultGameObjectInjectionWorld?.GetExistingSystem<GroundTruthLabelSetupSystem>();
labelSetupSystem?.Activate(this);
m_IsActivated = true;
// CustomPasses are executed for each camera. We only want to run for the target camera
if (camera != targetCamera)
return;
ExecutePass(renderContext, cmd, camera, cullingResult);
}
public void Cleanup()
{
var labelSetupSystem = World.DefaultGameObjectInjectionWorld?.GetExistingSystem<GroundTruthLabelSetupSystem>();
labelSetupSystem?.Deactivate(this);
}
protected abstract void ExecutePass(ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult);
protected RendererListDesc CreateRendererListDesc(Camera camera, CullingResults cullingResult, string overrideMaterialPassName, int overrideMaterialPassIndex, Material overrideMaterial, LayerMask layerMask/*, PerObjectData perObjectData*/)
{
var shaderPasses = new[]
public void EnsureActivated()
new ShaderTagId("Forward"), // HD Lit shader
new ShaderTagId("ForwardOnly"), // HD Unlit shader
new ShaderTagId("SRPDefaultUnlit"), // Cross SRP Unlit shader
new ShaderTagId("UniversalForward"), // URP Forward
new ShaderTagId("LightweightForward"), // LWRP Forward
new ShaderTagId(overrideMaterialPassName), // The override material shader
};
if (!m_IsActivated)
{
var labelSetupSystem = World.DefaultGameObjectInjectionWorld?.GetExistingSystem<GroundTruthLabelSetupSystem>();
labelSetupSystem?.Activate(this);
m_IsActivated = true;
}
}
var stateBlock = new RenderStateBlock(0)
public void Cleanup()
depthState = new DepthState(true, CompareFunction.LessEqual),
};
var labelSetupSystem = World.DefaultGameObjectInjectionWorld?.GetExistingSystem<GroundTruthLabelSetupSystem>();
labelSetupSystem?.Deactivate(this);
}
var result = new RendererListDesc(shaderPasses, cullingResult, camera)
protected RendererListDesc CreateRendererListDesc(Camera camera, CullingResults cullingResult, string overrideMaterialPassName, int overrideMaterialPassIndex, Material overrideMaterial, LayerMask layerMask/*, PerObjectData perObjectData*/)
rendererConfiguration = PerObjectData.None,
renderQueueRange = new RenderQueueRange { lowerBound = 0, upperBound = 5000 },
sortingCriteria = SortingCriteria.CommonOpaque,
excludeObjectMotionVectors = false,
overrideMaterial = overrideMaterial,
overrideMaterialPassIndex = overrideMaterialPassIndex,
stateBlock = stateBlock,
layerMask = layerMask,
};
return result;
}
var shaderPasses = new[]
{
new ShaderTagId("Forward"), // HD Lit shader
new ShaderTagId("ForwardOnly"), // HD Unlit shader
new ShaderTagId("SRPDefaultUnlit"), // Cross SRP Unlit shader
new ShaderTagId("UniversalForward"), // URP Forward
new ShaderTagId("LightweightForward"), // LWRP Forward
new ShaderTagId(overrideMaterialPassName), // The override material shader
};
var stateBlock = new RenderStateBlock(0)
{
depthState = new DepthState(true, CompareFunction.LessEqual),
};
public static void DrawRendererList(ScriptableRenderContext renderContext, CommandBuffer cmd, RendererList rendererList)
{
if (!rendererList.isValid)
throw new ArgumentException("Invalid renderer list provided to DrawRendererList");
var result = new RendererListDesc(shaderPasses, cullingResult, camera)
{
rendererConfiguration = PerObjectData.None,
renderQueueRange = new RenderQueueRange { lowerBound = 0, upperBound = 5000 },
sortingCriteria = SortingCriteria.CommonOpaque,
excludeObjectMotionVectors = false,
overrideMaterial = overrideMaterial,
overrideMaterialPassIndex = overrideMaterialPassIndex,
stateBlock = stateBlock,
layerMask = layerMask,
};
return result;
}
// This is done here because DrawRenderers API lives outside command buffers so we need to make call this before doing any DrawRenders or things will be executed out of order
renderContext.ExecuteCommandBuffer(cmd);
cmd.Clear();
if (rendererList.stateBlock == null)
renderContext.DrawRenderers(rendererList.cullingResult, ref rendererList.drawSettings, ref rendererList.filteringSettings);
else
public static void DrawRendererList(ScriptableRenderContext renderContext, CommandBuffer cmd, RendererList rendererList)
var renderStateBlock = rendererList.stateBlock.Value;
renderContext.DrawRenderers(rendererList.cullingResult, ref rendererList.drawSettings, ref rendererList.filteringSettings, ref renderStateBlock);
if (!rendererList.isValid)
throw new ArgumentException("Invalid renderer list provided to DrawRendererList");
// This is done here because DrawRenderers API lives outside command buffers so we need to make call this before doing any DrawRenders or things will be executed out of order
renderContext.ExecuteCommandBuffer(cmd);
cmd.Clear();
if (rendererList.stateBlock == null)
renderContext.DrawRenderers(rendererList.cullingResult, ref rendererList.drawSettings, ref rendererList.filteringSettings);
else
{
var renderStateBlock = rendererList.stateBlock.Value;
renderContext.DrawRenderers(rendererList.cullingResult, ref rendererList.drawSettings, ref rendererList.filteringSettings, ref renderStateBlock);
}
}
public abstract void SetupMaterialProperties(MaterialPropertyBlock mpb, MeshRenderer meshRenderer, Labeling labeling, uint instanceId);
public abstract void SetupMaterialProperties(MaterialPropertyBlock mpb, MeshRenderer meshRenderer, Labeling labeling, uint instanceId);
}
}

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


using Unity.Entities;
namespace UnityEngine.Perception.Sensors
namespace UnityEngine.Perception.GroundTruth
/// <summary>
/// Information regarding a Labeling instance. Generated by <see cref="GroundTruthLabelSetupSystem"/>
/// </summary>
/// <summary>
/// The instanceId assigned to the <see cref="Labeling"/>
/// </summary>
public uint instanceId;
}
}

25
com.unity.perception/Runtime/GroundTruth/GroundTruthLabelSetupSystem.cs


using System.Threading;
using Unity.Entities;
namespace UnityEngine.Perception.Sensors
namespace UnityEngine.Perception.GroundTruth
{
struct IdAssignmentParameters : IComponentData
{

/// <summary>
/// System which notifies the registered <see cref="IGroundTruthGenerator"/> about <see cref="Labeling"/> additions.
/// </summary>
public class GroundTruthLabelSetupSystem : ComponentSystem
{
List<IGroundTruthGenerator> m_ActiveGenerators = new List<IGroundTruthGenerator>();

/// <inheritdoc/>
protected override void OnCreate()
{
//These are here to inform the system runner the queries we are interested in. Without these calls, OnUpdate() might not be called

/// <inheritdoc/>
protected override void OnUpdate()
{
var entityQuery = Entities.WithAll<IdAssignmentParameters>().ToEntityQuery();

}
}
public void Activate(IGroundTruthGenerator pass)
/// <summary>
/// Activates the given <see cref="IGroundTruthGenerator"/>. <see cref="IGroundTruthGenerator.SetupMaterialProperties"/>
/// will be called for all <see cref="MeshRenderer"/> instances under each object containing a <see cref="Labeling"/> component.
/// </summary>
/// <param name="generator">The generator to register</param>
public void Activate(IGroundTruthGenerator generator)
m_ActiveGenerators.Add(pass);
m_ActiveGenerators.Add(generator);
Entities.ForEach((Labeling labeling, ref GroundTruthInfo info) =>
{
var gameObject = labeling.gameObject;

}
public void Deactivate(IGroundTruthGenerator pass)
/// <summary>
/// Deactivates the given <see cref="IGroundTruthGenerator"/>. It will no longer receive calls when <see cref="Labeling"/> instances are created.
/// </summary>
/// <param name="generator">The generator to deactivate</param>
/// <returns>True if the <see cref="generator"/> was successfully removed. False if <see cref="generator"/> was not active.</returns>
public bool Deactivate(IGroundTruthGenerator generator)
m_ActiveGenerators.Remove(pass);
return m_ActiveGenerators.Remove(generator);
}
}
}

89
com.unity.perception/Runtime/GroundTruth/GroundTruthRendererFeature.cs


#if URP_PRESENT
using System;
using System.Collections.Generic;
using UnityEngine.Perception;
using UnityEngine.Perception.Sensors;
class InstanceSegmentationUrpPass : ScriptableRenderPass
namespace UnityEngine.Perception.GroundTruth
InstanceSegmentationCrossPipelinePass m_InstanceSegmentationPass;
class InstanceSegmentationUrpPass : ScriptableRenderPass
{
InstanceSegmentationCrossPipelinePass m_InstanceSegmentationPass;
public InstanceSegmentationUrpPass(Camera camera, RenderTexture targetTexture)
{
m_InstanceSegmentationPass = new InstanceSegmentationCrossPipelinePass(camera);
ConfigureTarget(targetTexture, targetTexture.depthBuffer);
m_InstanceSegmentationPass.Setup();
}
public InstanceSegmentationUrpPass(Camera camera, RenderTexture targetTexture)
{
m_InstanceSegmentationPass = new InstanceSegmentationCrossPipelinePass(camera);
ConfigureTarget(targetTexture, targetTexture.depthBuffer);
m_InstanceSegmentationPass.Setup();
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var commandBuffer = CommandBufferPool.Get(nameof(InstanceSegmentationUrpPass));
m_InstanceSegmentationPass.Execute(context, commandBuffer, renderingData.cameraData.camera, renderingData.cullResults);
CommandBufferPool.Release(commandBuffer);
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
class SemanticSegmentationUrpPass : ScriptableRenderPass
var commandBuffer = CommandBufferPool.Get(nameof(InstanceSegmentationUrpPass));
m_InstanceSegmentationPass.Execute(context, commandBuffer, renderingData.cameraData.camera, renderingData.cullResults);
CommandBufferPool.Release(commandBuffer);
}
}
class SemanticSegmentationUrpPass : ScriptableRenderPass
{
SemanticSegmentationCrossPipelinePass m_SemanticSegmentationCrossPipelinePass;
SemanticSegmentationCrossPipelinePass m_SemanticSegmentationCrossPipelinePass;
public SemanticSegmentationUrpPass(Camera camera, RenderTexture targetTexture, LabelingConfiguration labelingConfiguration)
{
m_SemanticSegmentationCrossPipelinePass = new SemanticSegmentationCrossPipelinePass(camera, labelingConfiguration);
ConfigureTarget(targetTexture, targetTexture.depthBuffer);
m_SemanticSegmentationCrossPipelinePass.Setup();
}
public SemanticSegmentationUrpPass(Camera camera, RenderTexture targetTexture, LabelingConfiguration labelingConfiguration)
{
m_SemanticSegmentationCrossPipelinePass = new SemanticSegmentationCrossPipelinePass(camera, labelingConfiguration);
ConfigureTarget(targetTexture, targetTexture.depthBuffer);
m_SemanticSegmentationCrossPipelinePass.Setup();
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var commandBuffer = CommandBufferPool.Get(nameof(SemanticSegmentationUrpPass));
m_SemanticSegmentationCrossPipelinePass.Execute(context, commandBuffer, renderingData.cameraData.camera, renderingData.cullResults);
CommandBufferPool.Release(commandBuffer);
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var commandBuffer = CommandBufferPool.Get(nameof(SemanticSegmentationUrpPass));
m_SemanticSegmentationCrossPipelinePass.Execute(context, commandBuffer, renderingData.cameraData.camera, renderingData.cullResults);
CommandBufferPool.Release(commandBuffer);
}
}
public class GroundTruthRendererFeature : ScriptableRendererFeature
{
public override void Create()
public class GroundTruthRendererFeature : ScriptableRendererFeature
}
public override void Create() { }
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
var cameraObject = renderingData.cameraData.camera.gameObject;
var perceptionCamera = cameraObject.GetComponent<PerceptionCamera>();
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
var cameraObject = renderingData.cameraData.camera.gameObject;
var perceptionCamera = cameraObject.GetComponent<PerceptionCamera>();
if (perceptionCamera == null)
return;
if (perceptionCamera == null)
return;
if (!EditorApplication.isPlaying)
return;
if (!EditorApplication.isPlaying)
return;
renderer.EnqueuePass(perceptionCamera.instanceSegmentationUrpPass);
renderer.EnqueuePass(perceptionCamera.semanticSegmentationUrpPass);
renderer.EnqueuePass(perceptionCamera.instanceSegmentationUrpPass);
renderer.EnqueuePass(perceptionCamera.semanticSegmentationUrpPass);
}
}
}
#endif

17
com.unity.perception/Runtime/GroundTruth/IGroundTruthGenerator.cs


using UnityEngine;
public interface IGroundTruthGenerator
namespace UnityEngine.Perception.GroundTruth
void SetupMaterialProperties(MaterialPropertyBlock mpb, MeshRenderer meshRenderer, Labeling labeling, uint instanceId);
/// <summary>
/// Interface for setting up MeshRenderers for ground truth generation via <see cref="GroundTruthLabelSetupSystem"/>.
/// </summary>
public interface IGroundTruthGenerator
{
/// <summary>
/// Called by <see cref="GroundTruthLabelSetupSystem"/> when first registered or when a Labeling is created at runtime.
/// </summary>
/// <param name="mpb">The MaterialPropertyBlock for the given meshRenderer. Can be used to set properties for custom rendering.</param>
/// <param name="meshRenderer">The MeshRenderer which exists under the given Labeling.</param>
/// <param name="labeling">The Labeling component created</param>
/// <param name="instanceId">The instanceId assigned to the given Labeling instance.</param>
void SetupMaterialProperties(MaterialPropertyBlock mpb, MeshRenderer meshRenderer, Labeling labeling, uint instanceId);
}
}

109
com.unity.perception/Runtime/GroundTruth/InstanceSegmentationCrossPipelinePass.cs


using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
public class InstanceSegmentationCrossPipelinePass : GroundTruthCrossPipelinePass
namespace UnityEngine.Perception.GroundTruth
public static readonly int SegmentationIdProperty = Shader.PropertyToID("_SegmentationId");
const string k_SegmentationPassShaderName = "Perception/InstanceSegmentation";
class InstanceSegmentationCrossPipelinePass : GroundTruthCrossPipelinePass
{
static readonly int k_SegmentationIdProperty = Shader.PropertyToID("_SegmentationId");
const string k_SegmentationPassShaderName = "Perception/InstanceSegmentation";
static ProfilerMarker s_ExecuteMarker = new ProfilerMarker("SegmentationPass_Execute");
static ProfilerMarker s_ExecuteMarker = new ProfilerMarker("SegmentationPass_Execute");
//Filter settings
public LayerMask layerMask = -1;
/// <summary>
/// The LayerMask to apply when rendering objects.
/// </summary>
public LayerMask layerMask = -1;
Shader m_SegmentationShader;
Material m_OverrideMaterial;
public bool reassignIds = false;
public uint idStart = 1;
public uint idStep = 1;
int m_NextObjectIndex;
Shader m_SegmentationShader;
Material m_OverrideMaterial;
int m_NextObjectIndex;
Dictionary<uint, uint> m_Ids;
Dictionary<uint, uint> m_Ids;
public InstanceSegmentationCrossPipelinePass(Camera targetCamera, uint idStart = 1, uint idStep = 1)
:base(targetCamera)
{
if (targetCamera == null)
throw new ArgumentNullException(nameof(targetCamera));
/// <summary>
/// Create a new <see cref="InstanceSegmentationCrossPipelinePass"/> referencing the given
/// </summary>
/// <param name="targetCamera"></param>
/// <exception cref="ArgumentNullException"></exception>
public InstanceSegmentationCrossPipelinePass(Camera targetCamera)
:base(targetCamera)
{
if (targetCamera == null)
throw new ArgumentNullException(nameof(targetCamera));
//Activating in the constructor allows us to get correct labeling in the first frame.
EnsureActivated();
//Activating in the constructor allows us to get correct labeling in the first frame.
EnsureActivated();
}
this.idStart = idStart;
this.idStep = idStep;
}
public override void Setup()
{
base.Setup();
m_SegmentationShader = Shader.Find(k_SegmentationPassShaderName);
var shaderVariantCollection = new ShaderVariantCollection();
shaderVariantCollection.Add(new ShaderVariantCollection.ShaderVariant(m_SegmentationShader, PassType.ScriptableRenderPipeline));
shaderVariantCollection.WarmUp();
m_OverrideMaterial = new Material(m_SegmentationShader);
}
//Render all objects to our target RenderTexture using `overrideMaterial` to use our shader
protected override void ExecutePass(ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult)
{
using (s_ExecuteMarker.Auto())
public override void Setup()
cmd.ClearRenderTarget(true, true, Color.clear);
var result = CreateRendererListDesc(camera, cullingResult, "FirstPass", 0, m_OverrideMaterial, layerMask);
base.Setup();
m_SegmentationShader = Shader.Find(k_SegmentationPassShaderName);
var shaderVariantCollection = new ShaderVariantCollection();
shaderVariantCollection.Add(new ShaderVariantCollection.ShaderVariant(m_SegmentationShader, PassType.ScriptableRenderPipeline));
shaderVariantCollection.WarmUp();
DrawRendererList(renderContext, cmd, RendererList.Create(result));
m_OverrideMaterial = new Material(m_SegmentationShader);
}
public override void SetupMaterialProperties(MaterialPropertyBlock mpb, MeshRenderer meshRenderer, Labeling labeling, uint instanceId)
{
if (reassignIds)
//Render all objects to our target RenderTexture using `overrideMaterial` to use our shader
protected override void ExecutePass(ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, CullingResults cullingResult)
//Almost all the code here interacts with shared state, so just use a simple lock for now.
lock (this)
using (s_ExecuteMarker.Auto())
if (m_Ids == null)
m_Ids = new Dictionary<uint, uint>();
cmd.ClearRenderTarget(true, true, Color.clear);
var result = CreateRendererListDesc(camera, cullingResult, "FirstPass", 0, m_OverrideMaterial, layerMask);
if (!m_Ids.TryGetValue(instanceId, out var actualId))
{
actualId = (uint)m_NextObjectIndex * idStep + idStart;
m_Ids.Add(instanceId, actualId);
instanceId = actualId;
m_NextObjectIndex++;
}
DrawRendererList(renderContext, cmd, RendererList.Create(result));
mpb.SetInt(SegmentationIdProperty, (int)instanceId);
#if PERCEPTION_DEBUG
Debug.Log($"Assigning id. Frame {Time.frameCount} id {id}");
#endif
public override void SetupMaterialProperties(MaterialPropertyBlock mpb, MeshRenderer meshRenderer, Labeling labeling, uint instanceId)
{
mpb.SetInt(k_SegmentationIdProperty, (int)instanceId);
#if PERCEPTION_DEBUG
Debug.Log($"Assigning id. Frame {Time.frameCount} id {id}");
#endif
}
}
}

18
com.unity.perception/Runtime/GroundTruth/Labeling/Labeling.cs


using System;
using System.Collections;
/// Defines a set of classes associated with the object and its descendants. Classes can be overwritten
/// Defines a set of classes associated with the object and its descendants. Classes can be overwritten
/// <summary>
/// The class names to associate with the GameObject.
/// </summary>
Entity entity;
// Start is called before the first frame update
Entity m_Entity;
entity = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity();
World.DefaultGameObjectInjectionWorld.EntityManager.AddComponentObject(entity, this);
m_Entity = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity();
World.DefaultGameObjectInjectionWorld.EntityManager.AddComponentObject(m_Entity, this);
private void OnDestroy()
void OnDestroy()
World.DefaultGameObjectInjectionWorld.EntityManager.DestroyEntity(entity);
World.DefaultGameObjectInjectionWorld.EntityManager.DestroyEntity(m_Entity);
}
}

2
com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration.cs


using System;
using System.Collections.Generic;
namespace UnityEngine.Perception.Sensors
namespace UnityEngine.Perception.GroundTruth
{
[CreateAssetMenu(fileName = "LabelingConfiguration", menuName = "Perception/Labeling Configuration", order = 1)]
public class LabelingConfiguration : ScriptableObject

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


#endif
using UnityEngine.Perception.Sensors;
namespace UnityEngine.Perception
namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
/// Captures ground truth from the associated Camera.

bool m_CapturedLastFrame;
EgoMarker m_EgoMarker;
Ego m_EgoMarker;
/// <summary>
/// The <see cref="SensorHandle"/> associated with this camera. Use this to report additional annotations and metrics at runtime.

{
//CaptureOptions.useAsyncReadbackIfSupported = false;
m_EgoMarker = this.GetComponentInParent<EgoMarker>();
var ego = m_EgoMarker == null ? SimulationManager.RegisterEgo("") : m_EgoMarker.Ego;
m_EgoMarker = this.GetComponentInParent<Ego>();
var ego = m_EgoMarker == null ? SimulationManager.RegisterEgo("") : m_EgoMarker.EgoHandle;
SensorHandle = SimulationManager.RegisterSensor(ego, "camera", description, period, startTime);
var myCamera = GetComponent<Camera>();

1
com.unity.perception/Runtime/GroundTruth/RenderTextureReader.cs


using Unity.Collections;
using Unity.Profiling;
using Unity.Simulation;
using UnityEngine.Assertions;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;

10
com.unity.perception/Runtime/GroundTruth/RenderedObjectInfoGenerator.cs


using Unity.Jobs;
using Unity.Mathematics;
using Unity.Profiling;
using UnityEngine.Rendering;
using UnityEngine.Perception.Sensors;
namespace UnityEngine.Perception
namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
/// A CPU-based pass which computes bounding box and pixel counts per-object from instance segmentation images

/// Create a new CpuRenderedObjectInfoPass with the given LabelingConfiguration.
/// </summary>
/// <param name="labelingConfiguration">The LabelingConfiguration to use to determine labelId. Should match the
/// one used by the <seealso cref="InstanceSegmentationPass"/> generating the input image. See <see cref="Compute"/></param>
/// one used by the <seealso cref="InstanceSegmentationUrpPass"/> generating the input image. See <see cref="Compute"/></param>
public RenderedObjectInfoGenerator(LabelingConfiguration labelingConfiguration)
{
m_LabelingConfiguration = labelingConfiguration;

}
}
// ReSharper disable once InvalidXmlDocComment
/// InstanceSegmentationRawData should be the raw data from a texture filled by <see cref="InstanceSegmentationPass"/>
/// InstanceSegmentationRawData should be the raw data from a texture filled by <see cref="InstanceSegmentationUrpPass"/> or <see cref="InstanceSegmentationPass"/>
/// using the same LabelingConfiguration that was passed into this object.
/// </summary>
/// <param name="instanceSegmentationRawData"></param>

4
com.unity.perception/Runtime/GroundTruth/SemanticSegmentationCrossPipelinePass.cs


using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
namespace UnityEngine.Perception.Sensors
namespace UnityEngine.Perception.GroundTruth
public class SemanticSegmentationCrossPipelinePass : GroundTruthCrossPipelinePass
class SemanticSegmentationCrossPipelinePass : GroundTruthCrossPipelinePass
{
const string k_ShaderName = "Perception/SemanticSegmentation";
static readonly int k_LabelingId = Shader.PropertyToID("LabelingId");

2
com.unity.perception/Runtime/GroundTruth/SimulationManagementComponentSystem.cs


using System;
using Unity.Entities;
namespace UnityEngine.Perception
namespace UnityEngine.Perception.GroundTruth
{
class SimulationManagementComponentSystem : ComponentSystem
{

45
com.unity.perception/Runtime/GroundTruth/SimulationManager.cs


using UnityEngine;
#pragma warning disable 649
namespace UnityEngine.Perception
namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
/// Global manager for frame scheduling and output capture for simulations.

/// </summary>
public static string SchemaVersion => "0.0.1";
/// <summary>
/// Called when the simulation ends. The simulation ends on playmode exit, application exit, or when <see cref="ResetSimulation"/> is called.
/// </summary>
public static event Action SimulationEnding;
/// <summary>

/// <returns>An <see cref="Ego"/>, which can be used to organize sensors under a common ego.</returns>
public static Ego RegisterEgo(string description)
/// <returns>An <see cref="EgoHandle"/>, which can be used to organize sensors under a common ego.</returns>
public static EgoHandle RegisterEgo(string description)
var ego = new Ego(Guid.NewGuid(), description);
var ego = new EgoHandle(Guid.NewGuid(), description);
SimulationState.AddEgo(ego);
return ego;
}

/// </summary>
/// <param name="ego">The ego container for the sensor. Sensor orientation will be reported in the context of the given ego.</param>
/// <param name="egoHandle">The ego container for the sensor. Sensor orientation will be reported in the context of the given ego.</param>
/// <param name="modality">The kind of the sensor (ex. "camera", "lidar")</param>
/// <param name="description">A human-readable description of the sensor (ex. "front-left rgb camera")</param>
/// <param name="period">The period, in seconds, on which the sensor should capture. Frames will be scheduled in the simulation such that each sensor is triggered every _period_ seconds.</param>

/// <exception cref="ArgumentException">Thrown if ego is invalid.</exception>
public static SensorHandle RegisterSensor(Ego ego, string modality, string description, float period, float firstCaptureTime)
public static SensorHandle RegisterSensor(EgoHandle egoHandle, string modality, string description, float period, float firstCaptureTime)
if (!SimulationState.Contains(ego.Id))
throw new ArgumentException("Supplied ego is not part of the simulation.", nameof(ego));
if (!SimulationState.Contains(egoHandle.Id))
throw new ArgumentException("Supplied ego is not part of the simulation.", nameof(egoHandle));
SimulationState.AddSensor(ego, modality, description, period, firstCaptureTime, sensor);
SimulationState.AddSensor(egoHandle, modality, description, period, firstCaptureTime, sensor);
return sensor;
}

Manager.Instance.ShutdownNotification += ResetSimulation;
}
internal static void ResetSimulation()
/// <summary>
/// Stop the current simulation and start a new one. All pending data is written to disk before returning.
/// </summary>
public static void ResetSimulation()
{
//this order ensures that exceptions thrown by End() do not prevent the state from being reset
SimulationEnding?.Invoke();

/// </summary>
/// <param name="metricDefinition">The <see cref="MetricDefinition"/> of the metric.</param>
/// <param name="valuesJsonArray">A string-based JSON array to be placed in the "values" field of the metric</param>
/// <typeparam name="T">The value type</typeparam>
/// <exception cref="ArgumentNullException">Thrown if values is null</exception>
/// <exception cref="InvalidOperationException">Thrown if <see cref="ShouldCaptureThisFrame"/> is false.</exception>
public void ReportMetric(MetricDefinition metricDefinition, [NotNull] string valuesJsonArray)

/// ReportValues may only be called once per AsyncMetric.
/// </summary>
/// <param name="valuesJsonArray">A JSON array in string form.</param>
/// <typeparam name="T">The type of the values</typeparam>
/// <exception cref="ArgumentNullException">Thrown if values is null</exception>
public void ReportValues(string valuesJsonArray)
{

/// <param name="values"></param>
/// <typeparam name="T"></typeparam>
/// <exception cref="ArgumentNullException">Thrown if values is null</exception>
/// <exception cref="InvalidOperationException">Thrown if <see cref="Annotation.SensorHandle"/> reports false for <see cref="UnityEngine.Perception.SensorHandle.ShouldCaptureThisFrame"/>.</exception>
/// <exception cref="InvalidOperationException">Thrown if <see cref="Annotation.SensorHandle"/> reports false for <see cref="UnityEngine.Perception.GroundTruth.SensorHandle.ShouldCaptureThisFrame"/>.</exception>
public void ReportMetric<T>(MetricDefinition metricDefinition, [NotNull] T[] values)
{
if (values == null)

/// <param name="metricDefinition"></param>
/// <param name="valuesJsonArray">A string-based JSON array to be placed in the "values" field of the metric</param>
/// <exception cref="ArgumentNullException">Thrown if values is null</exception>
/// <exception cref="InvalidOperationException">Thrown if <see cref="Annotation.SensorHandle"/> reports false for <see cref="SensorHandle.ShouldCaptureThisFrame"/>.</exception>
/// <exception cref="InvalidOperationException">Thrown if <see cref="Annotation.SensorHandle"/> reports false for
/// <see cref="UnityEngine.Perception.GroundTruth.SensorHandle.ShouldCaptureThisFrame"/>.</exception>
public void ReportMetric(MetricDefinition metricDefinition, [NotNull] string valuesJsonArray)
{
if (valuesJsonArray == null)

/// <summary>
/// An ego, which is used to group multiple sensors under a single frame of reference.
/// </summary>
public struct Ego : IEquatable<Ego>
public struct EgoHandle : IEquatable<EgoHandle>
{
/// <summary>
/// The ID for this ego. This ID will be used to refer to this ego in the json metadata.

/// </summary>
public readonly string Description;
internal Ego(Guid id, string description)
internal EgoHandle(Guid id, string description)
public bool Equals(Ego other)
public bool Equals(EgoHandle other)
{
return Id.Equals(other.Id);
}

return obj is Ego other && Equals(other);
return obj is EgoHandle other && Equals(other);
}
public override int GetHashCode()

public static bool operator ==(Ego left, Ego right)
public static bool operator ==(EgoHandle left, EgoHandle right)
public static bool operator !=(Ego left, Ego right)
public static bool operator !=(EgoHandle left, EgoHandle right)
{
return !left.Equals(right);
}

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


using Newtonsoft.Json.Linq;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Perception.Sensors;
namespace UnityEngine.Perception
namespace UnityEngine.Perception.GroundTruth
{
partial class SimulationState
{

Dictionary<SensorHandle, SensorData> m_Sensors = new Dictionary<SensorHandle, SensorData>();
HashSet<Ego> m_Egos = new HashSet<Ego>();
HashSet<EgoHandle> m_Egos = new HashSet<EgoHandle>();
HashSet<Guid> m_Ids = new HashSet<Guid>();
Guid m_SequenceId = Guid.NewGuid();

public float sequenceTimeNextCapture;
public int lastCaptureFrameCount;
public Ego ego;
public EgoHandle egoHandle;
}
struct AnnotationData

m_LastTimeScale = Time.timeScale;
}
public void AddSensor(Ego ego, string modality, string description, float period, float firstCaptureTime, SensorHandle sensor)
public void AddSensor(EgoHandle egoHandle, string modality, string description, float period, float firstCaptureTime, SensorHandle sensor)
{
var sensorData = new SensorData()
{

firstCaptureTime = firstCaptureTime,
ego = ego,
egoHandle = egoHandle,
lastCaptureFrameCount = -1
};
sensorData.sequenceTimeNextCapture = SequenceTimeOfNextCapture(sensorData);

public bool Contains(Guid id) => m_Ids.Contains(id);
public void AddEgo(Ego ego)
public void AddEgo(EgoHandle egoHandle)
m_Egos.Add(ego);
m_Ids.Add(ego.Id);
m_Egos.Add(egoHandle);
m_Ids.Add(egoHandle.Id);
}
public bool IsEnabled(SensorHandle sensorHandle) => m_ActiveSensors.Contains(sensorHandle);

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


using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Unity.Simulation;
using UnityEngine.Perception.Sensors;
namespace UnityEngine.Perception
namespace UnityEngine.Perception.GroundTruth
{
partial class SimulationState
{

{
var sensorReference = new JObject();
sensorReference["id"] = kvp.Key.Id.ToString();
sensorReference["ego_id"] = kvp.Value.ego.Id.ToString();
sensorReference["ego_id"] = kvp.Value.egoHandle.Id.ToString();
sensorReference["modality"] = kvp.Value.modality;
if (kvp.Value.description != null)
sensorReference["description"] = kvp.Value.description;

{
var sensorJObject = new JObject();//new SensorCaptureJson
sensorJObject["sensor_id"] = pendingCapture.SensorHandle.Id.ToString();
sensorJObject["ego_id"] = pendingCapture.SensorData.ego.Id.ToString();
sensorJObject["ego_id"] = pendingCapture.SensorData.egoHandle.Id.ToString();
sensorJObject["modality"] = pendingCapture.SensorData.modality;
sensorJObject["translation"] = DatasetJsonUtility.ToJToken(pendingCapture.SensorSpatialData.SensorPose.position);
sensorJObject["rotation"] = DatasetJsonUtility.ToJToken(pendingCapture.SensorSpatialData.SensorPose.rotation);

}
var egoCaptureJson = new JObject();
egoCaptureJson["ego_id"] = pendingCapture.SensorData.ego.Id.ToString();
egoCaptureJson["ego_id"] = pendingCapture.SensorData.egoHandle.Id.ToString();
egoCaptureJson["translation"] = DatasetJsonUtility.ToJToken(pendingCapture.SensorSpatialData.EgoPose.position);
egoCaptureJson["rotation"] = DatasetJsonUtility.ToJToken(pendingCapture.SensorSpatialData.EgoPose.rotation);
egoCaptureJson["velocity"] = pendingCapture.SensorSpatialData.EgoVelocity.HasValue ? DatasetJsonUtility.ToJToken(pendingCapture.SensorSpatialData.EgoVelocity.Value) : null;

2
com.unity.perception/Tests/Runtime/GroundTruthTests/BoundingBox2DTests.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Perception;
using UnityEngine.Perception.Sensors;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.TestTools;
namespace GroundTruthTests

2
com.unity.perception/Tests/Runtime/GroundTruthTests/DatasetJsonUtilityTests.cs


using NUnit.Framework;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Perception.Sensors;
using UnityEngine.Perception.GroundTruth;
namespace GroundTruthTests
{

2
com.unity.perception/Tests/Runtime/GroundTruthTests/GroundTruthTestBase.cs


using NUnit.Framework;
using Unity.Simulation;
using UnityEngine;
using UnityEngine.Perception;
using UnityEngine.Perception.GroundTruth;
using Object = UnityEngine.Object;
namespace GroundTruthTests

6
com.unity.perception/Tests/Runtime/GroundTruthTests/ObjectCountTests.cs


using NUnit.Framework;
using Unity.Collections;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditorInternal;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Perception;
using UnityEngine.Perception.Sensors;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.TestTools;
#if HDRP_PRESENT

6
com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs


using NUnit.Framework;
using Unity.Collections;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
#if HDRP_PRESENT
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Experimental.Rendering;

{
CollectionAssert.AreEqual(Enumerable.Repeat(expectedLabelAtFrame[frameCount], data.Length), data);
}
catch (Exception e)
// ReSharper disable once RedundantCatchClause
catch (Exception)
{
//uncomment to get RenderDoc captures while this check is failing
//RenderDoc.EndCaptureRenderDoc(gameView);

#endif
#if URP_PRESENT
var labelingConfiguration = ScriptableObject.CreateInstance<LabelingConfiguration>();
var perceptionCamera = cameraObject.AddComponent<UnityEngine.Perception.PerceptionCamera>();
var perceptionCamera = cameraObject.AddComponent<PerceptionCamera>();
perceptionCamera.LabelingConfiguration = labelingConfiguration;
perceptionCamera.captureRgbImages = false;
perceptionCamera.produceBoundingBoxAnnotations = false;

3
com.unity.perception/Tests/Runtime/GroundTruthTests/SimulationManagerTests.cs


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

3
com.unity.perception/Tests/Runtime/GroundTruthTests/SimulationManager_SensorSchedulingTests.cs


using System.Text.RegularExpressions;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Assertions.Comparers;
using UnityEngine.Perception;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.TestTools;
namespace GroundTruthTests

38
com.unity.perception/Runtime/GroundTruth/Ego.cs


using System;
using UnityEngine;
namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
/// Marker indicating the GameObject is the root of the ego for a set of sensors. Works with <see cref="PerceptionCamera"/>.
/// Custom sensors can use the <see cref="EgoHandle"/> property to register themselves under this ego.
/// </summary>
public class Ego : MonoBehaviour
{
/// <summary>
/// A human-readable description for this Ego to be included in the dataset.
/// </summary>
public string Description;
EgoHandle m_EgoHandle;
public EgoHandle EgoHandle
{
get
{
EnsureEgoInitialized();
return m_EgoHandle;
}
}
void Start()
{
EnsureEgoInitialized();
}
void EnsureEgoInitialized()
{
if (m_EgoHandle == default)
m_EgoHandle = SimulationManager.RegisterEgo(Description);
}
}
}

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


using System;
using UnityEngine;
namespace UnityEngine.Perception
{
public class EgoMarker : MonoBehaviour
{
public string Description;
Ego m_Ego;
public Ego Ego
{
get
{
EnsureEgoInitialized();
return m_Ego;
}
}
void Start()
{
EnsureEgoInitialized();
}
void EnsureEgoInitialized()
{
if (m_Ego == default)
m_Ego = SimulationManager.RegisterEgo(Description);
}
}
}

135
com.unity.perception/Runtime/GroundTruth/MetricData.cs


using System;
using System.Collections.Generic;
using UnityEngine;
using USim = Unity.Simulation;
namespace UnityEngine.Perception.Sensors
{
class MetricData<T>
{
public string Name;
public SimulationInfo SimulationInfo;
public CurrentContext CurrentContext;
public T Metric;
public MetricData(string name, T metric)
{
if(string.IsNullOrEmpty(name)) {
throw new ArgumentException("Arg name is null or empty");
}
this.Name = name;
this.Metric = metric;
this.SimulationInfo = SimulationInfo.GetInstance();
this.CurrentContext = CurrentContext.NewCurrentContext();
}
}
[Serializable]
class SensorMetric
{
public string SensorId;
public int FrameId;
public List<ObjectCountEntry> SegmentedHistogram = new List<ObjectCountEntry>();
}
[Serializable]
struct ObjectCountEntry
{
public string Label;
public uint Count;
}
[Serializable]
struct CurrentContext
{
static USim.Manager s_Manager;
public double SimulationElapsedTime;
public double SimulationElapsedTimeUnscaled;
public static CurrentContext NewCurrentContext()
{
if(s_Manager == null) {
s_Manager = USim.Manager.Instance;
}
return new CurrentContext() {
SimulationElapsedTime = s_Manager.SimulationElapsedTime,
SimulationElapsedTimeUnscaled = s_Manager.SimulationElapsedTimeUnscaled,
};
}
}
/// <summary> SimulationInfo - Context that is unchanged for this entire simulation </summary>
[Serializable]
class SimulationInfo
{
public string ProjectId;
public string RunId;
public string ExecutionId;
public string AppParamId;
public string RunInstanceId;
public string AttemptId;
public override string ToString()
{
return string.Format("{0}/{1}/{2}/{3}/{4}/{5}",
this.ProjectId,
this.RunId,
this.ExecutionId,
this.AppParamId,
this.RunInstanceId,
this.AttemptId);
}
static SimulationInfo s_Context;
public static SimulationInfo GetInstance()
{
if(s_Context != null) {
return s_Context;
}
var config = USim.Configuration.Instance;
if(config.IsSimulationRunningInCloud()) {
s_Context = GetInstance(config.GetStoragePath());
} else {
s_Context = new SimulationInfo() {
ProjectId = Guid.NewGuid().ToString(),
AppParamId = "urn:app_param_id:app_param_id",
ExecutionId = "urn:app_param_id:exn_id",
RunId = "urn:app_param_id:run_id",
RunInstanceId = "0",
AttemptId = "0"
};
}
return s_Context;
}
static SimulationInfo GetInstance(string storagePath)
{
if(string.IsNullOrEmpty(storagePath)) {
throw new ArgumentException("Arg storagePath is null or empty");
}
const int expectedTokenCount = 8;
var tokens = storagePath.Split('/');
if (tokens.Length < expectedTokenCount) {
var msg = "Storage path not in the expected format";
Debug.LogError(msg);
throw new ArgumentException(msg);
}
return new SimulationInfo()
{
ProjectId = tokens[1],
RunId = tokens[3],
ExecutionId = tokens[4],
AppParamId = tokens[5],
RunInstanceId = tokens[6],
AttemptId = tokens[7]
};
}
}
}

11
com.unity.perception/Runtime/GroundTruth/MetricData.cs.meta


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

/com.unity.perception/Editor/GroundTruth/LabelingPassEditor.cs.meta → /com.unity.perception/Editor/GroundTruth/SemanticSegmentationPassEditor.cs.meta

/com.unity.perception/Editor/GroundTruth/LabelingPassEditor.cs → /com.unity.perception/Editor/GroundTruth/SemanticSegmentationPassEditor.cs

/com.unity.perception/Runtime/GroundTruth/EgoMarker.cs.meta → /com.unity.perception/Runtime/GroundTruth/Ego.cs.meta

正在加载...
取消
保存