GitHub
5 年前
当前提交
85de0241
共有 53 个文件被更改,包括 666 次插入 和 749 次删除
-
4TestProjects/PerceptionHDRP/Assets/Rotator.cs
-
1TestProjects/PerceptionHDRP/Packages/manifest.json
-
4TestProjects/PerceptionURP/Assets/Rotator.cs
-
1TestProjects/PerceptionURP/Packages/manifest.json
-
6com.unity.perception/Editor/GroundTruth/BaseCustomPassDrawer.cs
-
7com.unity.perception/Editor/GroundTruth/InstanceSegmentationPassEditor.cs
-
111com.unity.perception/Editor/GroundTruth/LabelingConfigurationEditor.cs
-
76com.unity.perception/Editor/GroundTruth/LabelingEditor.cs
-
5com.unity.perception/Editor/GroundTruth/ObjectCountPassEditor.cs
-
7com.unity.perception/Editor/GroundTruth/SemanticSegmentationPassEditor.cs
-
3com.unity.perception/Runtime/GroundTruth/BoundingBoxOrigin.cs
-
2com.unity.perception/Runtime/GroundTruth/DatasetJsonUtility.cs
-
156com.unity.perception/Runtime/GroundTruth/GroundTruthCrossPipelinePass.cs
-
8com.unity.perception/Runtime/GroundTruth/GroundTruthInfo.cs
-
25com.unity.perception/Runtime/GroundTruth/GroundTruthLabelSetupSystem.cs
-
3com.unity.perception/Runtime/GroundTruth/GroundTruthPass.cs
-
89com.unity.perception/Runtime/GroundTruth/GroundTruthRendererFeature.cs
-
17com.unity.perception/Runtime/GroundTruth/IGroundTruthGenerator.cs
-
109com.unity.perception/Runtime/GroundTruth/InstanceSegmentationCrossPipelinePass.cs
-
7com.unity.perception/Runtime/GroundTruth/InstanceSegmentationPass.cs
-
22com.unity.perception/Runtime/GroundTruth/Labeling/Labeling.cs
-
33com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration.cs
-
29com.unity.perception/Runtime/GroundTruth/ObjectCountPass.cs
-
105com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
-
19com.unity.perception/Runtime/GroundTruth/RenderTextureReader.cs
-
22com.unity.perception/Runtime/GroundTruth/RenderedObjectInfo.cs
-
12com.unity.perception/Runtime/GroundTruth/RenderedObjectInfoGenerator.cs
-
6com.unity.perception/Runtime/GroundTruth/SemanticSegmentationCrossPipelinePass.cs
-
2com.unity.perception/Runtime/GroundTruth/SemanticSegmentationPass.cs
-
2com.unity.perception/Runtime/GroundTruth/SimulationManagementComponentSystem.cs
-
105com.unity.perception/Runtime/GroundTruth/SimulationManager.cs
-
18com.unity.perception/Runtime/GroundTruth/SimulationState.cs
-
10com.unity.perception/Runtime/GroundTruth/SimulationState_Json.cs
-
59com.unity.perception/Tests/Editor/BuildPerceptionPlayer.cs
-
13com.unity.perception/Tests/Editor/PerceptionCameraEditorTests.cs
-
5com.unity.perception/Tests/Runtime/GroundTruthTests/BoundingBox2DTests.cs
-
2com.unity.perception/Tests/Runtime/GroundTruthTests/DatasetJsonUtilityTests.cs
-
13com.unity.perception/Tests/Runtime/GroundTruthTests/GroundTruthTestBase.cs
-
39com.unity.perception/Tests/Runtime/GroundTruthTests/ObjectCountTests.cs
-
7com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs
-
19com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs
-
3com.unity.perception/Tests/Runtime/GroundTruthTests/SimulationManagerTests.cs
-
2com.unity.perception/Tests/Runtime/GroundTruthTests/TestHelper.cs
-
12com.unity.perception/Tests/Runtime/GroundTruthTests/SimulationManagerSensorSchedulingTests.cs
-
38com.unity.perception/Runtime/GroundTruth/Ego.cs
-
31com.unity.perception/Runtime/GroundTruth/EgoMarker.cs
-
135com.unity.perception/Runtime/GroundTruth/MetricData.cs
-
11com.unity.perception/Runtime/GroundTruth/MetricData.cs.meta
-
0/com.unity.perception/Editor/GroundTruth/SemanticSegmentationPassEditor.cs.meta
-
0/com.unity.perception/Editor/GroundTruth/SemanticSegmentationPassEditor.cs
-
0/com.unity.perception/Runtime/GroundTruth/Ego.cs.meta
-
0/com.unity.perception/Tests/Runtime/GroundTruthTests/SimulationManagerSensorSchedulingTests.cs.meta
-
0/com.unity.perception/Tests/Runtime/GroundTruthTests/SimulationManagerSensorSchedulingTests.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(); |
|||
} |
|||
} |
|
|||
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.labels)), 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.labels.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.labels.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.labels[index]); |
|||
if (change.changed) |
|||
{ |
|||
Labeling.labels[index] = value; |
|||
} |
|||
} |
|||
public override void OnInspectorGUI() |
|||
{ |
|||
m_LabelsList.DoLayoutList(); |
|||
public override void OnInspectorGUI() |
|||
{ |
|||
m_LabelsList.DoLayoutList(); |
|||
} |
|||
} |
|||
} |
|
|||
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; |
|||
} |
|||
} |
|
|||
#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
|
|
|||
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); |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections; |
|||
using UnityEngine.Serialization; |
|||
/// Defines a set of classes associated with the object and its descendants. Classes can be overwritten
|
|||
/// Defines a set of labels associated with the object and its descendants. A Labeling component will override any Labeling components on the object's ancestors.
|
|||
public List<string> classes = new List<string>(); |
|||
|
|||
Entity entity; |
|||
/// <summary>
|
|||
/// The label names to associate with the GameObject.
|
|||
/// </summary>
|
|||
[FormerlySerializedAs("classes")] |
|||
public List<string> labels = new List<string>(); |
|||
// 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); |
|||
} |
|||
} |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
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] |
|||
}; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 21e0b364c4d364d4a8d36cd1b2648bb0 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue