浏览代码

Merge pull request #32 from unity/fix-standalone-first-extra-frame

standalone player scenario start rendering from frame 1
/0.9.0.preview.1_staging
GitHub Enterprise 3 年前
当前提交
7f24359c
共有 5 个文件被更改,包括 36 次插入39 次删除
  1. 9
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  2. 19
      com.unity.perception/Runtime/Randomization/Scenarios/PerceptionScenario.cs
  3. 13
      com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs
  4. 28
      com.unity.perception/Tests/Runtime/Randomization/RandomizerTests/RandomizerTests.cs
  5. 6
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ScenarioTests.cs

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


static PerceptionCamera s_VisualizedPerceptionCamera;
/// <summary>
/// The number of capture-able frames that have been generated
/// </summary>
#if UNITY_EDITOR
public static int captureFrameCount => Time.frameCount - 2;
#else
public static int captureFrameCount => Time.frameCount - 1;
#endif
//TODO: Remove the Guid path when we have proper dataset merging in Unity Simulation and Thea
internal string rgbDirectory { get; } = $"RGB{Guid.NewGuid()}";
internal HUDPanel hudPanel;

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


/// </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;
protected override bool isScenarioReadyToStart
{
get
{
if (!m_SkippedFirstFrame)
{
m_SkippedFirstFrame = true;
return false;
}
return true;
}
}
protected override bool isScenarioReadyToStart => PerceptionCamera.captureFrameCount >= 0;
/// <inheritdoc/>
protected override void OnAwake()

13
com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs


public abstract class UnitySimulationScenario<T> : PerceptionScenario<T>
where T : UnitySimulationScenarioConstants, new()
{
/// <inheritdoc/>
protected override bool isScenarioReadyToStart
{
get
{
if (!Configuration.Instance.IsSimulationRunningInCloud() && !m_SkippedFirstFrame)
{
m_SkippedFirstFrame = true;
return false;
}
return true;
}
}
/// <inheritdoc/>
protected sealed override bool isScenarioComplete => currentIteration >= constants.totalIterations;

28
com.unity.perception/Tests/Runtime/Randomization/RandomizerTests/RandomizerTests.cs


using System.Collections;
using NUnit.Framework;
using RandomizationTests.ScenarioTests;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.Perception.Randomization.Randomizers;
using UnityEngine.Perception.Randomization.Scenarios;
using UnityEngine.TestTools;

}
// TODO: update this function once the perception camera doesn't skip the first frame
IEnumerator CreateNewScenario(int totalIterations, int framesPerIteration)
IEnumerator CreateNewScenario(int totalIterations, int framesPerIteration, Randomizer[] randomizers = null)
yield return null; // Skip first frame
if (randomizers != null)
{
foreach (var rnd in randomizers)
{
m_Scenario.AddRandomizer(rnd);
}
}
if (PerceptionCamera.captureFrameCount < 0)
{
yield return null;
}
}
[Test]

[UnityTest]
public IEnumerator OnUpdateExecutesEveryFrame()
{
yield return CreateNewScenario(10, 1);
m_Scenario.AddRandomizer(new ExampleTransformRandomizer());
yield return CreateNewScenario(10, 1, new Randomizer[] { new ExampleTransformRandomizer() });
var transform = m_TestObject.transform;
var initialPosition = Vector3.zero;
transform.position = initialPosition;

[UnityTest]
public IEnumerator OnIterationStartExecutesEveryIteration()
{
yield return CreateNewScenario(10, 2);
m_Scenario.AddRandomizer(new ExampleTransformRandomizer());
yield return CreateNewScenario(10, 2, new Randomizer[] { new ExampleTransformRandomizer() });
// Wait one frame so the next iteration can begin
yield return null;
yield return null;
Assert.AreNotEqual(initialRotation, transform.rotation);

6
com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ScenarioTests.cs


}
}
yield return null; // Skip first frame
yield return null; // Skip first Update() frame
if (PerceptionCamera.captureFrameCount < 0)
{
yield return null;
}
}
[Test]

正在加载...
取消
保存