浏览代码

Merge branch 'master' into fix-notebook-tutorial

/main
Mohsen Kamalzadeh 4 年前
当前提交
b694fb11
共有 14 个文件被更改,包括 83 次插入81 次删除
  1. 4
      com.unity.perception/CHANGELOG.md
  2. 4
      com.unity.perception/Documentation~/Tutorial/Phase1.md
  3. 28
      com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs
  4. 2
      com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml
  5. 2
      com.unity.perception/Runtime/GroundTruth/DatasetCapture.cs
  6. 2
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  7. 4
      com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs
  8. 59
      com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs
  9. 59
      com.unity.perception/Runtime/Randomization/Scenarios/USimScenario.cs
  10. 0
      /com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs.meta
  11. 0
      /com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs
  12. 0
      /com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml.meta
  13. 0
      /com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml
  14. 0
      /com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs.meta

4
com.unity.perception/CHANGELOG.md


### Changed
Expanded all Unity Simulation references from USim to Unity Simulation
### Deprecated
### Removed

USimScenario now correctly deserializes app-params before offsetting the current scenario iteration when executing on Unity Simulation
UnitySimulationScenario now correctly deserializes app-params before offsetting the current scenario iteration when executing on Unity Simulation
Fixed Unity Simulation nodes generating one extra empty image before generating their share of the randomization scenario iterations

4
com.unity.perception/Documentation~/Tutorial/Phase1.md


An alternative approach is to first install [_**Unity Hub**_](https://unity3d.com/get-unity/download), which will allow you to have multiple versions of Unity on your computer, and make it easier to manage your Unity projects and the versions of Unity they will use.
During the installation of Unity, you will be asked to choose which modules you would like to include. This will depend on the types of applications you eventually intend to build with your Unity installation; however, for the purposes of this tutorial, we need to make make sure _**Linux Build Support**_ is checked. In addition, if you do not already have _**Visual Studio**_ on your computer, the wizard will give you an option to install it. Go ahead and check this option, as we will need _**Visual Studio**_ for writing some simple scripts in Phase 2 of the tutorial.
During the installation of Unity, you will be asked to choose which modules you would like to include. This will depend on the types of applications you eventually intend to build with your Unity installation; however, for the purposes of this tutorial, we need to make sure _**Linux Build Support**_ is checked. In addition, if you do not already have _**Visual Studio**_ on your computer, the wizard will give you an option to install it. Go ahead and check this option, as we will need _**Visual Studio**_ for writing some simple scripts in Phase 2 of the tutorial.
* **Action**: Make sure the _**Linux Build Support**_ and _**Visual Studio**_ installation options are checked when selecting modules during installation.

This step prepares your project to render tailor-made images that will be later used for labeling the generated synthetic data.
### <a name="step-3">Step 3: Setup a Scene for Your Perception Simulation</a>
Simply put, in Unity, Scenes contain any object that exists in the world. This world can be a game, or in this case, a perception-oriented simulation. Every new project contains a Scene named `SampleScene`, which is automatically openned when the project is created. This Scenes comes with several objects and settings that we do not need, so let's create a new one.
Simply put, in Unity, Scenes contain any object that exists in the world. This world can be a game, or in this case, a perception-oriented simulation. Every new project contains a Scene named `SampleScene`, which is automatically opened when the project is created. This Scene comes with several objects and settings that we do not need, so let's create a new one.
* **Action**: In the _**Project**_ tab, right-click on the `Assets/Scenes` folder and click _**Create -> Scene**_. Name this new Scene `TutorialScene` and double-click on it to open it.

28
com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs


using Unity.Simulation.Client;
using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEditor.SceneManagement;
using UnityEditor.UIElements;
using UnityEngine.Experimental.Perception.Randomization.Editor;
using UnityEngine.Experimental.Perception.Randomization.Scenarios;

namespace UnityEngine.Perception.Randomization.Editor
{
class RunInUSimWindow : EditorWindow
class RunInUnitySimulationWindow : EditorWindow
{
string m_BuildDirectory;

[MenuItem("Window/Run in Unity Simulation")]
static void ShowWindow()
{
var window = GetWindow<RunInUSimWindow>();
var window = GetWindow<RunInUnitySimulationWindow>();
window.titleContent = new GUIContent("Run In Unity Simulation");
window.minSize = new Vector2(250, 50);
window.Show();

}
else
{
CreateRunInUSimUI();
CreateRunInUnitySimulationUI();
}
}

/// <param name="element">The visual element to enable view data for</param>
static void SetViewDataKey(VisualElement element)
{
element.viewDataKey = $"RunInUSim_{element.name}";
element.viewDataKey = $"RunInUnitySimulation_{element.name}";
void CreateRunInUSimUI()
void CreateRunInUnitySimulationUI()
$"{StaticData.uxmlDir}/RunInUSimWindow.uxml").CloneTree(root);
$"{StaticData.uxmlDir}/RunInUnitySimulationWindow.uxml").CloneTree(root);
m_RunNameField = root.Q<TextField>("run-name");
SetViewDataKey(m_RunNameField);

m_SysParam = sysParamDefinitions[0];
m_RunButton = root.Q<Button>("run-button");
m_RunButton.clicked += RunInUSim;
m_RunButton.clicked += RunInUnitySimulation;
async void RunInUSim()
async void RunInUnitySimulation()
await StartUSimRun();
await StartUnitySimulationRun();
}
void ValidateSettings()

if (m_ScenarioField.value == null)
throw new MissingFieldException("Scenario unselected");
var scenario = (ScenarioBase)m_ScenarioField.value;
if (!StaticData.IsSubclassOfRawGeneric(typeof(USimScenario<>), scenario.GetType()))
throw new NotSupportedException("Scenario class must be derived from USimScenario to run in USim");
if (!StaticData.IsSubclassOfRawGeneric(typeof(UnitySimulationScenario<>), scenario.GetType()))
throw new NotSupportedException(
"Scenario class must be derived from UnitySimulationScenario to run in Unity Simulation");
}
void CreateLinuxBuildAndZip()

if (token.IsCancellationRequested)
return null;
var appParamName = $"{m_RunNameField.value}_{i}";
var appParamId = API.UploadAppParam(appParamName, new USimConstants
var appParamId = API.UploadAppParam(appParamName, new UnitySimulationConstants
{
totalIterations = m_TotalIterationsField.value,
instanceCount = m_InstanceCountField.value,

return appParamIds;
}
async Task StartUSimRun()
async Task StartUnitySimulationRun()
{
m_RunButton.SetEnabled(false);
var cancellationTokenSource = new CancellationTokenSource();

2
com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml


<editor:ObjectField name="main-scene" label="Main Scene" allow-scene-objects="false"/>
<editor:ObjectField name="scenario" label="Scenario"/>
<VisualElement class="unity-base-field">
<Label text="USim worker config" class="unity-base-field__label"/>
<Label text="Sys-Param" class="unity-base-field__label"/>
<editor:ToolbarMenu name="sys-param" class="unity-base-field__input" style="border-width: 1px;"/>
</VisualElement>
<VisualElement style="align-items: center;">

2
com.unity.perception/Runtime/GroundTruth/DatasetCapture.cs


static SimulationState CreateSimulationData()
{
//TODO: Remove the Guid path when we have proper dataset merging in USim/Thea
//TODO: Remove the Guid path when we have proper dataset merging in Unity Simulation and Thea
return new SimulationState($"Dataset{k_DatasetGuid}");
}

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


[RequireComponent(typeof(Camera))]
public partial class PerceptionCamera : MonoBehaviour
{
//TODO: Remove the Guid path when we have proper dataset merging in USim/Thea
//TODO: Remove the Guid path when we have proper dataset merging in Unity Simulation and Thea
internal static string RgbDirectory { get; } = $"RGB{Guid.NewGuid()}";
static string s_RgbFilePrefix = "rgb_";

4
com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs


/// A scenario that runs for a fixed number of frames during each iteration
/// </summary>
[AddComponentMenu("Perception/Randomization/Scenarios/Fixed Length Scenario")]
public class FixedLengthScenario: USimScenario<FixedLengthScenario.Constants>
public class FixedLengthScenario: UnitySimulationScenario<FixedLengthScenario.Constants>
public class Constants : USimConstants
public class Constants : UnitySimulationConstants
{
/// <summary>
/// The number of frames to generate per iteration

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


using System;
using Unity.Simulation;
namespace UnityEngine.Experimental.Perception.Randomization.Scenarios
{
/// <summary>
/// Defines a scenario that is compatible with the Run in Unity Simulation window
/// </summary>
/// <typeparam name="T">The type of constants to serialize</typeparam>
public abstract class UnitySimulationScenario<T> : Scenario<T> where T : UnitySimulationConstants, new()
{
/// <summary>
/// Returns whether the entire scenario has completed
/// </summary>
public sealed override bool isScenarioComplete => currentIteration >= constants.totalIterations;
/// <summary>
/// Progresses the current scenario iteration
/// </summary>
protected sealed override void IncrementIteration()
{
currentIteration += constants.instanceCount;
}
/// <summary>
/// Deserializes this scenario's constants from the Unity Simulation AppParams Json file
/// </summary>
public sealed override void Deserialize()
{
if (Configuration.Instance.IsSimulationRunningInCloud())
constants = Configuration.Instance.GetAppParams<T>();
else
base.Deserialize();
currentIteration = constants.instanceIndex;
}
}
/// <summary>
/// A class encapsulating the scenario constants fields required for Unity Simulation cloud execution
/// </summary>
[Serializable]
public class UnitySimulationConstants
{
/// <summary>
/// The total number of iterations to run a scenario for
/// </summary>
public int totalIterations = 100;
/// <summary>
/// The number of Unity Simulation instances assigned to executed this scenario
/// </summary>
public int instanceCount = 1;
/// <summary>
/// The Unity Simulation instance index of the currently executing worker
/// </summary>
public int instanceIndex;
}
}

59
com.unity.perception/Runtime/Randomization/Scenarios/USimScenario.cs


using System;
using Unity.Simulation;
namespace UnityEngine.Experimental.Perception.Randomization.Scenarios
{
/// <summary>
/// Defines a scenario that is compatible with the Run in USim window
/// </summary>
/// <typeparam name="T">The type of constants to serialize</typeparam>
public abstract class USimScenario<T> : Scenario<T> where T : USimConstants, new()
{
/// <summary>
/// Returns whether the entire scenario has completed
/// </summary>
public sealed override bool isScenarioComplete => currentIteration >= constants.totalIterations;
/// <summary>
/// Progresses the current scenario iteration
/// </summary>
protected sealed override void IncrementIteration()
{
currentIteration += constants.instanceCount;
}
/// <summary>
/// Deserializes this scenario's constants from the USim AppParams Json file
/// </summary>
public sealed override void Deserialize()
{
if (Configuration.Instance.IsSimulationRunningInCloud())
constants = Configuration.Instance.GetAppParams<T>();
else
base.Deserialize();
currentIteration = constants.instanceIndex;
}
}
/// <summary>
/// A class encapsulating the scenario constants fields required for USim cloud execution
/// </summary>
[Serializable]
public class USimConstants
{
/// <summary>
/// The total number of iterations to run a scenario for
/// </summary>
public int totalIterations = 100;
/// <summary>
/// The number of USim instances assigned to executed this scenario
/// </summary>
public int instanceCount = 1;
/// <summary>
/// The USim instance index of the currently executing worker
/// </summary>
public int instanceIndex;
}
}

/com.unity.perception/Editor/Randomization/Editors/RunInUSimWindow.cs.meta → /com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs.meta

/com.unity.perception/Editor/Randomization/Editors/RunInUSimWindow.cs → /com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs

/com.unity.perception/Editor/Randomization/Uxml/RunInUSimWindow.uxml.meta → /com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml.meta

/com.unity.perception/Editor/Randomization/Uxml/RunInUSimWindow.uxml → /com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml

/com.unity.perception/Runtime/Randomization/Scenarios/USimScenario.cs.meta → /com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs.meta

正在加载...
取消
保存