浏览代码

Merge pull request #3 from Unity-Technologies/fix-editor-pause

Fix editor pause
/main
GitHub 4 年前
当前提交
0ffef165
共有 21 个文件被更改,包括 305 次插入69 次删除
  1. 8
      TestProjects/PerceptionHDRP/Packages/manifest.json
  2. 5
      TestProjects/PerceptionHDRP/ProjectSettings/HDRPProjectSettings.asset
  3. 4
      TestProjects/PerceptionHDRP/ProjectSettings/ProjectVersion.txt
  4. 8
      TestProjects/PerceptionHDRP/ProjectSettings/VFXManager.asset
  5. 6
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  6. 14
      com.unity.perception/Tests/Editor/Unity.Perception.Editor.Tests.asmdef
  7. 36
      com.unity.perception/Tests/Runtime/GroundTruthTests/BoundingBox2DTests.cs
  8. 6
      com.unity.perception/Tests/Runtime/GroundTruthTests/Main Camera.prefab
  9. 4
      com.unity.perception/Tests/Runtime/GroundTruthTests/ObjectCountTests.cs
  10. 12
      com.unity.perception/Tests/Runtime/GroundTruthTests/SimulationManagerTests.cs
  11. 6
      com.unity.perception/Tests/Runtime/GroundTruthTests/SimulationManager_SensorSchedulingTests.cs
  12. 2
      com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs
  13. 77
      com.unity.perception/Tests/Editor/PerceptionCameraEditorTests.cs
  14. 3
      com.unity.perception/Tests/Editor/PerceptionCameraEditorTests.cs.meta
  15. 37
      com.unity.perception/Tests/Runtime/GroundTruthTests/GroundTruthTestBase.cs
  16. 112
      com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs
  17. 3
      com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs.meta
  18. 31
      com.unity.perception/Tests/Runtime/GroundTruthTests/PassTestBase.cs
  19. 0
      /com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs.meta
  20. 0
      /com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs
  21. 0
      /com.unity.perception/Tests/Runtime/GroundTruthTests/GroundTruthTestBase.cs.meta

8
TestProjects/PerceptionHDRP/Packages/manifest.json


"com.unity.ext.nunit": "1.0.0",
"com.unity.ide.rider": "1.1.4",
"com.unity.ide.vscode": "1.1.4",
"com.unity.render-pipelines.core": "7.1.8",
"com.unity.render-pipelines.high-definition": "7.1.8",
"com.unity.perception": "file:../../../com.unity.perception",
"com.unity.render-pipelines.core": "7.3.1",
"com.unity.render-pipelines.high-definition": "7.3.1",
"com.unity.perception": "file:../../../com.unity.perception",
"com.unity.test-framework": "1.1.11",
"com.unity.test-framework": "1.1.13",
"com.unity.testtools.codecoverage": "0.2.2-preview",
"com.unity.textmeshpro": "2.0.1",
"com.unity.ugui": "1.0.0",

5
TestProjects/PerceptionHDRP/ProjectSettings/HDRPProjectSettings.asset


m_DefaultDXRScenePrefabSaved: {fileID: 0}
m_ProjectSettingFolderPath: HDRPDefaultResources
m_WizardPopupAtStart: 0
m_WizardPopupAlreadyShownOnce: 0
m_PackageVersionForMaterials: 7.1.8
m_WizardNeedRestartAfterChangingToDX12: 0
m_WizardNeedToRunFixAllAgainAfterDomainReload: 0
m_LastMaterialVersion: 2

4
TestProjects/PerceptionHDRP/ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2019.3.6f1
m_EditorVersionWithRevision: 2019.3.6f1 (5c3fb0a11183)
m_EditorVersion: 2019.3.9f1
m_EditorVersionWithRevision: 2019.3.9f1 (e6e740a1c473)

8
TestProjects/PerceptionHDRP/ProjectSettings/VFXManager.asset


--- !u!937362698 &1
VFXManager:
m_ObjectHideFlags: 0
m_IndirectShader: {fileID: 0}
m_CopyBufferShader: {fileID: 0}
m_SortShader: {fileID: 0}
m_StripUpdateShader: {fileID: 0}
m_IndirectShader: {fileID: 7200000, guid: 84a17cfa13e40ae4082ef42714f0a81c, type: 3}
m_CopyBufferShader: {fileID: 7200000, guid: 23c51f21a3503f6428b527b01f8a2f4e, type: 3}
m_SortShader: {fileID: 7200000, guid: ea257ca3cfb12a642a5025e612af6b2a, type: 3}
m_StripUpdateShader: {fileID: 7200000, guid: 8fa6c4009fe2a4d4486c62736fc30ad8, type: 3}
m_RenderPipeSettingsPath:
m_FixedTimeStep: 0.016666668
m_MaxDeltaTime: 0.05

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


{
if (camera != GetComponent<Camera>())
return;
#if UNITY_EDITOR
if (UnityEditor.EditorApplication.isPaused)
return;
#endif
ReportAsyncAnnotations();
CaptureRgbData(camera);
}

if (m_RenderedObjectInfoGenerator != null)
{
World.DefaultGameObjectInjectionWorld.GetExistingSystem<GroundTruthLabelSetupSystem>().Deactivate(m_RenderedObjectInfoGenerator);
World.DefaultGameObjectInjectionWorld?.GetExistingSystem<GroundTruthLabelSetupSystem>()?.Deactivate(m_RenderedObjectInfoGenerator);
m_RenderedObjectInfoGenerator?.Dispose();
m_RenderedObjectInfoGenerator = null;
}

14
com.unity.perception/Tests/Editor/Unity.Perception.Editor.Tests.asmdef


"Unity.Mathematics",
"Unity.Perception.Editor",
"Unity.Collections",
"Unity.Entities"
"Unity.Entities",
"Unity.Simulation.Core",
"Unity.RenderPipelines.HighDefinition.Runtime"
],
"includePlatforms": [
"Editor"

"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"versionDefines": [
{
"name": "com.unity.render-pipelines.high-definition",
"expression": "",
"define": "HDRP_PRESENT"
}
],
}
}

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


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Perception;
using UnityEngine.Perception.Sensors;
using UnityEngine.TestTools;

[TestFixture]
public class BoundingBox2DTests : PassTestBase
public class BoundingBox2DTests : GroundTruthTestBase
{
public class ProducesCorrectBoundingBoxesData
{

public BoundingBoxOrigin boundingBoxOrigin;
public ProducesCorrectBoundingBoxesData(uint[] data, RenderedObjectInfo[] boundingBoxesExpected, uint[] classCountsExpected, int stride, string name)
public ProducesCorrectBoundingBoxesData(uint[] data, RenderedObjectInfo[] boundingBoxesExpected, uint[] classCountsExpected, int stride, BoundingBoxOrigin boundingBoxOrigin, string name)
{
this.data = data;
this.boundingBoxesExpected = boundingBoxesExpected;

this.boundingBoxOrigin = boundingBoxOrigin;
}
public override string ToString()

0
},
2,
BoundingBoxOrigin.BottomLeft,
"SimpleBox");
yield return new ProducesCorrectBoundingBoxesData(
new uint[]

1
},
3,
BoundingBoxOrigin.BottomLeft,
"WithGaps");
yield return new ProducesCorrectBoundingBoxesData(
new uint[]

1
},
3,
BoundingBoxOrigin.BottomLeft,
yield return new ProducesCorrectBoundingBoxesData(
new uint[]
{
0, 0,
0, 0,
0, 1
}, new[]
{
new RenderedObjectInfo()
{
boundingBox = new Rect(1, 0, 1, 1),
instanceId = 1,
labelId = 0,
pixelCount = 1
},
}, new uint[]
{
1,
0
},
2,
BoundingBoxOrigin.TopLeft,
"TopLeft");
}
[UnityTest]

var dataNativeArray = new NativeArray<uint>(producesCorrectBoundingBoxesData.data, Allocator.Persistent);
renderedObjectInfoGenerator.Compute(dataNativeArray, producesCorrectBoundingBoxesData.stride, BoundingBoxOrigin.BottomLeft, out var boundingBoxes, out var classCounts, Allocator.Temp);
renderedObjectInfoGenerator.Compute(dataNativeArray, producesCorrectBoundingBoxesData.stride, producesCorrectBoundingBoxesData.boundingBoxOrigin, out var boundingBoxes, out var classCounts, Allocator.Temp);
CollectionAssert.AreEqual(producesCorrectBoundingBoxesData.boundingBoxesExpected, boundingBoxes.ToArray());
CollectionAssert.AreEqual(producesCorrectBoundingBoxesData.classCountsExpected, classCounts.ToArray());

6
com.unity.perception/Tests/Runtime/GroundTruthTests/Main Camera.prefab


references:
version: 1
00000000:
type: {class: InstanceSegmentationPass, ns: UnityEngine.Perception.Sensors, asm: Unity.Perception.GroundTruth}
type: {class: InstanceSegmentationPass, ns: UnityEngine.SimViz.Sensors, asm: Unity.SimViz.GroundTruth}
data:
name: Custom Pass
enabled: 1

idStart: 1
idStep: 1
00000001:
type: {class: SemanticSegmentationPass, ns: UnityEngine.Perception.Sensors, asm: Unity.Perception.GroundTruth}
type: {class: SemanticSegmentationPass, ns: UnityEngine.SimViz.Sensors, asm: Unity.SimViz.GroundTruth}
data:
name: Custom Pass
enabled: 1

labelingConfiguration: {fileID: 11400000, guid: 16a81d3f01f4f4345b113509e93fdab6,
type: 2}
00000002:
type: {class: LabelHistogramPass, ns: UnityEngine.Perception.Sensors, asm: Unity.Perception.GroundTruth}
type: {class: LabelHistogramPass, ns: UnityEngine.SimViz.Sensors, asm: Unity.SimViz.GroundTruth}
data:
name: Custom Pass
enabled: 1

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


//Graphics issues with OpenGL Linux Editor. https://jira.unity3d.com/browse/AISV-422
[UnityPlatform(exclude = new[] {RuntimePlatform.LinuxEditor, RuntimePlatform.LinuxPlayer})]
[TestFixture]
class ObjectCountTests : PassTestBase
class ObjectCountTests : GroundTruthTestBase
public IEnumerator LabeledObjectHistogramPassProducesCorrectValuesWithChangingObjects()
public IEnumerator ProducesCorrectValuesWithChangingObjects()
{
var label = "label";
var labelingConfiguration = ScriptableObject.CreateInstance<LabelingConfiguration>();

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


[TestFixture]
public class SimulationManagerTests
{
[TearDown]
public void TearDown()
{
SimulationManager.ResetSimulation();
Time.timeScale = 1;
//Manager.Instance.Shutdown();
if (Directory.Exists(SimulationManager.OutputDirectory))
Directory.Delete(SimulationManager.OutputDirectory, true);
//Manager.Instance.Start();
}
[Test]
public void RegisterSensor_ReportsProperJson()
{

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


timeScale * period,
timeScale * period
};
for (int i = 0; i < deltaTimeSamplesExpected.Length; i++)
float[] deltaTimeSamples = new float[deltaTimeSamplesExpected.Length];
for (int i = 0; i < deltaTimeSamples.Length; i++)
{
yield return null;
Assert.AreEqual(deltaTimeSamplesExpected[i], Time.deltaTime, 0.0001f);

period,
period
};
for (int i = 0; i < deltaTimeSamplesExpected.Length; i++)
float[] deltaTimeSamples = new float[deltaTimeSamplesExpected.Length];
for (int i = 0; i < deltaTimeSamples.Length; i++)
{
Time.timeScale = newTimeScalesPerFrame[i];
yield return null;

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


//Graphics issues with OpenGL Linux Editor. https://jira.unity3d.com/browse/AISV-422
[UnityPlatform(exclude = new[] {RuntimePlatform.LinuxEditor, RuntimePlatform.LinuxPlayer})]
public class SegmentationPassTests : PassTestBase
public class SegmentationPassTests : GroundTruthTestBase
{
// A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
// `yield return null;` to skip a frame.

77
com.unity.perception/Tests/Editor/PerceptionCameraEditorTests.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Unity.Collections;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.Perception;
using UnityEngine.Perception.Sensors;
using UnityEngine.TestTools;
namespace EditorTests
{
[TestFixture]
public class PerceptionCameraEditorTests
{
[UnityTest]
public IEnumerator EditorPause_DoesNotLogErrors()
{
int sceneCount = EditorSceneManager.sceneCount;
for (int i = sceneCount - 1; i >= 0; i--)
{
EditorSceneManager.CloseScene(EditorSceneManager.GetSceneAt(i), true);
}
EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
SetupCamera(ScriptableObject.CreateInstance<LabelingConfiguration>());
yield return new EnterPlayMode();
var expectedFirstFrame = Time.frameCount;
yield return null;
EditorApplication.isPaused = true;
//Wait a few editor frames to ensure the issue has a chance to trigger.
yield return null;
yield return null;
yield return null;
yield return null;
EditorApplication.isPaused = false;
var expectedLastFrame = Time.frameCount;
yield return null;
SimulationManager.ResetSimulation();
var capturesPath = Path.Combine(SimulationManager.OutputDirectory, "captures_000.json");
var capturesJson = File.ReadAllText(capturesPath);
for (int iFrameCount = expectedFirstFrame; iFrameCount <= expectedLastFrame; iFrameCount++)
{
var imagePath = Path.Combine(PerceptionCamera.RgbDirectory, $"rgb_{iFrameCount}").Replace(@"\", @"\\");
StringAssert.Contains(imagePath, capturesJson);
}
yield return new ExitPlayMode();
}
static GameObject SetupCamera(LabelingConfiguration labelingConfiguration)
{
var cameraObject = new GameObject();
cameraObject.SetActive(false);
var camera = cameraObject.AddComponent<Camera>();
camera.orthographic = true;
camera.orthographicSize = 1;
#if HDRP_PRESENT
cameraObject.AddComponent<UnityEngine.Rendering.HighDefinition.HDAdditionalCameraData>();
#endif
var perceptionCamera = cameraObject.AddComponent<PerceptionCamera>();
perceptionCamera.LabelingConfiguration = labelingConfiguration;
perceptionCamera.captureRgbImages = true;
perceptionCamera.produceBoundingBoxAnnotations = true;
perceptionCamera.produceObjectCountAnnotations = true;
cameraObject.SetActive(true);
return cameraObject;
}
}
}

3
com.unity.perception/Tests/Editor/PerceptionCameraEditorTests.cs.meta


fileFormatVersion: 2
guid: 6efa744f46fc41e8aa4296d99f4c66c9
timeCreated: 1587395248

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


using System;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Unity.Simulation;
using UnityEngine;
using UnityEngine.Perception;
using Object = UnityEngine.Object;
namespace GroundTruthTests
{
public class GroundTruthTestBase
{
List<GameObject> objectsToDestroy = new List<GameObject>();
[TearDown]
public void TearDown()
{
foreach (var o in objectsToDestroy)
Object.DestroyImmediate(o);
objectsToDestroy.Clear();
SimulationManager.ResetSimulation();
Time.timeScale = 1;
if (Directory.Exists(SimulationManager.OutputDirectory))
Directory.Delete(SimulationManager.OutputDirectory, true);
}
public void AddTestObjectForCleanup(GameObject @object) => objectsToDestroy.Add(@object);
public void DestroyTestObject(GameObject @object)
{
Object.DestroyImmediate(@object);
objectsToDestroy.Remove(@object);
}
}
}

112
com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Unity.Collections;
using UnityEngine;
using UnityEngine.Perception;
using UnityEngine.Perception.Sensors;
using UnityEngine.TestTools;
using Object = UnityEngine.Object;
namespace GroundTruthTests
{
#if HDRP_PRESENT
[Ignore("Ignoring in HDRP because of a rendering issue in the first frame. See issue AISV-455.")]
#endif
public class PerceptionCameraIntegrationTests : GroundTruthTestBase
{
[UnityTest]
[UnityPlatform(RuntimePlatform.LinuxPlayer, RuntimePlatform.WindowsPlayer)]
public IEnumerator EnableBoundingBoxes_GeneratesCorrectDataset()
{
//set resolution to ensure we don't have rounding in rendering leading to bounding boxes to change height/width
Screen.SetResolution(400, 400, false);
//give the screen a chance to resize
yield return null;
var jsonExpected = $@" {{
""label_id"": 0,
""label_name"": ""label"",
""instance_id"": 1,
""x"": 0.0,
""y"": {Screen.height / 4:F1},
""width"": {Screen.width:F1},
""height"": {Screen.height / 2:F1}
}}";
var labelingConfiguration = CreateLabelingConfiguration();
var camera = SetupCamera(labelingConfiguration, pc =>
{
pc.produceBoundingBoxAnnotations = true;
});
var plane = TestHelper.CreateLabeledPlane();
AddTestObjectForCleanup(plane);
//a plane is 10x10 by default, so scale it down to be 10x1 to cover the center half of the image
plane.transform.localScale = new Vector3(10f, -1f, .1f);
yield return null;
SimulationManager.ResetSimulation();
var capturesPath = Path.Combine(SimulationManager.OutputDirectory, "captures_000.json");
var capturesJson = File.ReadAllText(capturesPath);
StringAssert.Contains(jsonExpected, capturesJson);
}
[UnityTest]
public IEnumerator EnableSemanticSegmentation_GeneratesCorrectDataset()
{
var labelingConfiguration = CreateLabelingConfiguration();
SetupCamera(labelingConfiguration, pc => pc.produceSegmentationImages = true);
string expectedImageFilename = $"segmentation_{Time.frameCount}.png";
this.AddTestObjectForCleanup(TestHelper.CreateLabeledPlane());
yield return null;
SimulationManager.ResetSimulation();
var capturesPath = Path.Combine(SimulationManager.OutputDirectory, "captures_000.json");
var capturesJson = File.ReadAllText(capturesPath);
var imagePath = Path.Combine("SemanticSegmentation", expectedImageFilename).Replace(@"\", @"\\");
StringAssert.Contains(imagePath, capturesJson);
}
static LabelingConfiguration CreateLabelingConfiguration()
{
var label = "label";
var labelingConfiguration = ScriptableObject.CreateInstance<LabelingConfiguration>();
labelingConfiguration.LabelingConfigurations = new List<LabelingConfigurationEntry>
{
new LabelingConfigurationEntry
{
label = label,
value = 500
}
};
return labelingConfiguration;
}
GameObject SetupCamera(LabelingConfiguration labelingConfiguration, Action<PerceptionCamera> initPerceptionCamera)
{
var cameraObject = new GameObject();
cameraObject.SetActive(false);
var camera = cameraObject.AddComponent<Camera>();
camera.orthographic = true;
camera.orthographicSize = 1;
var perceptionCamera = cameraObject.AddComponent<PerceptionCamera>();
perceptionCamera.produceSegmentationImages = false;
perceptionCamera.produceVisiblePixelsMetric = false;
perceptionCamera.produceBoundingBoxAnnotations = false;
perceptionCamera.produceObjectCountAnnotations = false;
perceptionCamera.captureRgbImages = false;
perceptionCamera.LabelingConfiguration = labelingConfiguration;
initPerceptionCamera(perceptionCamera);
cameraObject.SetActive(true);
AddTestObjectForCleanup(cameraObject);
return cameraObject;
}
}
}

3
com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs.meta


fileFormatVersion: 2
guid: f83408fe81fd4168a740139c98a38cfe
timeCreated: 1586791038

31
com.unity.perception/Tests/Runtime/GroundTruthTests/PassTestBase.cs


using System;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Perception;
using Object = UnityEngine.Object;
namespace GroundTruthTests
{
public class PassTestBase
{
List<GameObject> objectsToDestroy = new List<GameObject>();
[TearDown]
public void TearDown()
{
foreach (var o in objectsToDestroy)
Object.DestroyImmediate(o);
objectsToDestroy.Clear();
SimulationManager.ResetSimulation();
}
public void AddTestObjectForCleanup(GameObject @object) => objectsToDestroy.Add(@object);
public void DestroyTestObject(GameObject @object)
{
Object.DestroyImmediate(@object);
objectsToDestroy.Remove(@object);
}
}
}

/com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationPassTests.cs.meta → /com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs.meta

/com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationPassTests.cs → /com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs

/com.unity.perception/Tests/Runtime/GroundTruthTests/PassTestBase.cs.meta → /com.unity.perception/Tests/Runtime/GroundTruthTests/GroundTruthTestBase.cs.meta

正在加载...
取消
保存