浏览代码
Merge pull request #218 from Unity-Technologies/scenario-lifecycle-hooks-refactor
Merge pull request #218 from Unity-Technologies/scenario-lifecycle-hooks-refactor
Scenario lifecycle hooks refactor/main
GitHub
4 年前
当前提交
31093061
共有 23 个文件被更改,包括 945 次插入 和 282 次删除
-
4com.unity.perception/CHANGELOG.md
-
108com.unity.perception/Documentation~/Randomization/Scenarios.md
-
2com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs
-
26com.unity.perception/Editor/Randomization/Utilities/StaticData.cs
-
6com.unity.perception/Editor/Randomization/Utilities/UIElementsEditorUtilities.cs
-
2com.unity.perception/Editor/Randomization/VisualElements/Randomizer/RandomizerElement.cs
-
3com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
-
103com.unity.perception/Runtime/Randomization/Randomizers/Randomizer.cs
-
2com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/BackgroundObjectPlacementRandomizer.cs
-
2com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/ForegroundObjectPlacementRandomizer.cs
-
2com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs
-
281com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
-
6com.unity.perception/Runtime/Randomization/Scenarios/Serialization/ScenarioSerializer.cs
-
41com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs
-
2com.unity.perception/Tests/Editor/RandomizerEditorTests.cs
-
2com.unity.perception/Tests/Runtime/Randomization/RandomizerTests/ExampleTransformRandomizer.cs
-
16com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ScenarioTests.cs
-
88com.unity.perception/Runtime/Randomization/Scenarios/PerceptionScenario.cs
-
3com.unity.perception/Runtime/Randomization/Scenarios/PerceptionScenario.cs.meta
-
14com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/TestFixedLengthScenario.cs
-
3com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/TestFixedLengthScenario.cs.meta
-
511com.unity.perception/Documentation~/Randomization/Images/scenario-lifecycle-diagram.png
|
|||
using System; |
|||
using Unity.Simulation; |
|||
using UnityEngine.Perception.GroundTruth; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Scenarios |
|||
{ |
|||
/// <summary>
|
|||
/// Derive this class to configure perception data capture while coordinating a scenario
|
|||
/// </summary>
|
|||
/// <typeparam name="T">The type of scenario constants to serialize</typeparam>
|
|||
public abstract class PerceptionScenario<T> : Scenario<T> where T : ScenarioConstants, new() |
|||
{ |
|||
/// <summary>
|
|||
/// The guid used to identify this scenario's Iteration Metric Definition
|
|||
/// </summary>
|
|||
const string k_ScenarioIterationMetricDefinitionId = "DB1B258E-D1D0-41B6-8751-16F601A2E230"; |
|||
|
|||
/// <summary>
|
|||
/// The metric definition used to report the current scenario iteration
|
|||
/// </summary>
|
|||
MetricDefinition m_IterationMetricDefinition; |
|||
|
|||
/// <summary>
|
|||
/// The scriptable render pipeline hook used to capture perception data skips the first frame of the simulation
|
|||
/// when running locally, so this flag is used to track whether the first frame has been skipped yet.
|
|||
/// </summary>
|
|||
protected bool m_SkippedFirstFrame; |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override bool isScenarioReadyToStart |
|||
{ |
|||
get |
|||
{ |
|||
if (!m_SkippedFirstFrame) |
|||
{ |
|||
m_SkippedFirstFrame = true; |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void OnAwake() |
|||
{ |
|||
m_IterationMetricDefinition = DatasetCapture.RegisterMetricDefinition( |
|||
"scenario_iteration", "Iteration information for dataset sequences", |
|||
Guid.Parse(k_ScenarioIterationMetricDefinitionId)); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void OnStart() |
|||
{ |
|||
var randomSeedMetricDefinition = DatasetCapture.RegisterMetricDefinition( |
|||
"random-seed", |
|||
"The random seed used to initialize the random state of the simulation. Only triggered once per simulation.", |
|||
Guid.Parse("14adb394-46c0-47e8-a3f0-99e754483b76")); |
|||
DatasetCapture.ReportMetric(randomSeedMetricDefinition, new[] { genericConstants.randomSeed }); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void OnIterationStart() |
|||
{ |
|||
DatasetCapture.StartNewSequence(); |
|||
DatasetCapture.ReportMetric(m_IterationMetricDefinition, new[] |
|||
{ |
|||
new IterationMetricData { iteration = currentIteration } |
|||
}); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void OnComplete() |
|||
{ |
|||
DatasetCapture.ResetSimulation(); |
|||
Manager.Instance.Shutdown(); |
|||
Quit(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Used to report a scenario iteration as a perception metric
|
|||
/// </summary>
|
|||
struct IterationMetricData |
|||
{ |
|||
// ReSharper disable once NotAccessedField.Local
|
|||
public int iteration; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 78c9b59045074d7aa47e4911ba0e86fb |
|||
timeCreated: 1613367040 |
|
|||
using System; |
|||
using UnityEngine.Perception.GroundTruth; |
|||
using UnityEngine.Perception.Randomization.Scenarios; |
|||
|
|||
namespace RandomizationTests.ScenarioTests |
|||
{ |
|||
class TestFixedLengthScenario : FixedLengthScenario |
|||
{ |
|||
protected override void OnComplete() |
|||
{ |
|||
DatasetCapture.ResetSimulation(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7e4a918b4c1442898a54ab08a83af01a |
|||
timeCreated: 1614016112 |
撰写
预览
正在加载...
取消
保存
Reference in new issue