浏览代码

fixed an issue where an arbitrary limit on frame delta time was causing incorrect behavior

/main
Mohsen Kamalzadeh 4 年前
当前提交
a5a9e9cf
共有 3 个文件被更改,包括 45 次插入6 次删除
  1. 9
      com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs
  2. 7
      com.unity.perception/Runtime/GroundTruth/SimulationState.cs
  3. 35
      com.unity.perception/Tests/Runtime/GroundTruthTests/DatasetCaptureSensorSchedulingTests.cs

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


}
const string k_FrametimeTitle = "Simulation Delta Time";
const float k_DeltaTimeTooLarge = 200;
public override void OnInspectorGUI()
{
using(new EditorGUI.DisabledScope(EditorApplication.isPlaying))

GUILayout.BeginVertical("TextArea");
EditorGUILayout.LabelField("Scheduled Capture Properties", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.simulationDeltaTime)),new GUIContent(k_FrametimeTitle, $"Sets Unity's Time.{nameof(Time.captureDeltaTime)} to the specified number, causing a fixed number of frames to be simulated for each second of elapsed simulation time regardless of the capabilities of the underlying hardware. Thus, simulation time and real time will not be synchronized."));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.simulationDeltaTime)),new GUIContent(k_FrametimeTitle, $"Sets Unity's Time.{nameof(Time.captureDeltaTime)} to the specified number, causing a fixed number of frames to be simulated for each second of elapsed simulation time regardless of the capabilities of the underlying hardware. Thus, simulation time and real time will not be synchronized. Note that large {k_FrametimeTitle} values will lead to lower performance as the engine will need to simulate longer periods of elapsed time for each rendered frame."));
if (perceptionCamera.simulationDeltaTime > k_DeltaTimeTooLarge)
{
EditorGUILayout.HelpBox($"Large {k_FrametimeTitle} values can lead to significantly lower performance due to the processing time needed for simulating a larger period of time for each rendered frame. ", MessageType.Warning);
}
var interval = (perceptionCamera.framesBetweenCaptures + 1) * perceptionCamera.simulationDeltaTime;
var startTime = perceptionCamera.simulationDeltaTime * perceptionCamera.firstCaptureFrame;

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


const float k_SimulationTimingAccuracy = 0.01f;
const int k_MinPendingCapturesBeforeWrite = 150;
const int k_MinPendingMetricsBeforeWrite = 150;
const float k_MaxDeltaTime = 100f;
public SimulationState(string outputDirectory)
{

}
//find the deltatime required to land on the next active sensor that needs simulation
float nextFrameDt = k_MaxDeltaTime;
var nextFrameDt = float.PositiveInfinity;
foreach (var activeSensor in m_ActiveSensors)
{
float thisSensorNextFrameDt = -1;

}
if (thisSensorNextFrameDt > 0f && thisSensorNextFrameDt < nextFrameDt)
{
}
if (Math.Abs(nextFrameDt - k_MaxDeltaTime) < 0.0001)
if (float.IsPositiveInfinity(nextFrameDt))
{
//means no sensor is controlling simulation timing, so we set Time.captureDeltaTime to 0 (default) which means the setting does not do anything
nextFrameDt = 0;

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


{
var ego = DatasetCapture.RegisterEgo("ego");
var firstCaptureFrame = 2f;
var simulationDeltaTime = .4f;
var simulationDeltaTime = 105f;
var sensorHandle = DatasetCapture.RegisterSensor(ego, "cam", "", firstCaptureFrame, CaptureTriggerMode.Scheduled, simulationDeltaTime, 0);
var startTime = firstCaptureFrame * simulationDeltaTime;

}
CollectionAssert.AreEqual(samplesExpected, samplesActual);
}
[UnityTest]
[TestCase(1, 0, 0, 1, 2, 3, ExpectedResult = (IEnumerator)null)]
[TestCase(10, 5, 50, 60, 70, 80, ExpectedResult = (IEnumerator)null)]
[TestCase(55, 0, 0, 55, 110, 165, ExpectedResult = (IEnumerator)null)]
[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)
{
var ego = DatasetCapture.RegisterEgo("ego");
var sensorHandle = DatasetCapture.RegisterSensor(ego, "cam", "", firstCaptureFrame, CaptureTriggerMode.Scheduled, simulationDeltaTime, 0);
float[] sequenceTimesExpected =
{
firstCaptureTime,
secondCaptureTime,
thirdCaptureTime,
fourthCaptureTime
};
for (var i = 0; i < firstCaptureFrame; i++)
{
//render the non-captured frames before firstCaptureFrame
yield return null;
}
for (var i = 0; i < sequenceTimesExpected.Length; i++)
{
var sensorData = m_TestHelper.GetSensorData(sensorHandle);
var sequenceTimeActual = m_TestHelper.CallSequenceTimeOfNextCapture(sensorData);
Assert.AreEqual(sequenceTimesExpected[i], sequenceTimeActual, 0.0001f);
yield return null;
}
}
[UnityTest]

正在加载...
取消
保存