比较提交

...
此合并请求有变更与目标分支冲突。
/com.unity.perception/Editor/Randomization/Uxml/ScenarioBaseElement.uxml
/com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs
/com.unity.perception/Runtime/Randomization/Scenarios/Serialization/ScenarioSerializer.cs
/com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs
/com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
/com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
/com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs

1 次代码提交

作者 SHA1 备注 提交日期
Mohsen Kamalzadeh 15d578d5 switched to scheduled capture 4 年前
共有 9 个文件被更改,包括 137 次插入62 次删除
  1. 6
      com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs
  2. 3
      com.unity.perception/Editor/Randomization/Uxml/ScenarioBaseElement.uxml
  3. 2
      com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs
  4. 7
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  5. 100
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
  6. 14
      com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs
  7. 19
      com.unity.perception/Runtime/Randomization/Scenarios/Serialization/ScenarioSerializer.cs
  8. 20
      com.unity.perception/Runtime/Randomization/Scenarios/PerceptionScenario.cs
  9. 28
      com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs

6
com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs


using System.IO;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.Perception.Randomization.Scenarios;
using UnityEngine.UIElements;

CreatePropertyFields();
CheckIfConstantsExist();
var appParamField = m_Root.Q<ObjectField>("test-app-param");
appParamField.objectType = typeof(TextAsset);
var generateConfigButton = m_Root.Q<Button>("generate-json-config");
generateConfigButton.clicked += () =>

case "constants":
m_HasConstantsField = true;
UIElementsEditorUtilities.CreatePropertyFields(iterator.Copy(), m_ConstantsListVisualContainer);
break;
case nameof(ScenarioBase.testAppParam):
break;
default:
{

3
com.unity.perception/Editor/Randomization/Uxml/ScenarioBaseElement.uxml


<VisualElement>
<Style src="../Uss/Styles.uss"/>
<VisualElement name="inspector-properties" style="margin-bottom: 4px;"/>
<VisualElement class="scenario__dark-viewport" >
<VisualElement name="scenario-properties-container" class="scenario__dark-viewport" >
<editor:ObjectField name="test-app-param" label="Test App Param" binding-path="testAppParam"/>
<VisualElement name="constants-container">
<Foldout style="padding-left: 16px" text="Constants" name="constants-list" tooltip="A list of parameters for this scenario that will be JSON serialized in the configuration file."/>
<editor:PropertyField name="configuration-file-name" label="Constants File Name" binding-path="serializedConstantsFileName"/>

2
com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs


if (visualizationEnabled) OnVisualize();
}
internal void Init(PerceptionCamera newPerceptionCamera)
public void Init(PerceptionCamera newPerceptionCamera)
{
try
{

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


using Unity.Simulation;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Perception.Randomization.Scenarios;
using UnityEngine.Profiling;
using UnityEngine.Rendering;
#if HDRP_PRESENT

continue;
if (!labeler.isInitialized)
labeler.Init(this);
continue;
labeler.InternalOnUpdate();
}

void OnBeginCameraRendering(ScriptableRenderContext scriptableRenderContext, Camera cam)
{
if (!ShouldCallLabelers(cam, m_LastFrameCaptured))
if (!ShouldCallLabelers(cam, m_LastFrameCaptured) || ScenarioBase.activeScenario.state != ScenarioBase.State.Playing)
return;
m_LastFrameCaptured = Time.frameCount;

continue;
if (!labeler.isInitialized)
labeler.Init(this);
continue;
action(labeler);
}

100
com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;

s_ActiveScenario = value;
}
}
/// <summary>
/// A list of the addressable bundle catalog URLs to load before the scenario starts
/// </summary>
protected List<string> m_CatalogUrls = new List<string>();
/// <summary>
/// Maps bundle primary keys (the name of the bundle file) to the bundle's URL. Enables the addressable asset
/// system to use signed URLs for remote asset bundles.
/// </summary>
protected Dictionary<string, string> m_BundleToUrlMap = new Dictionary<string, string>();
#if UNITY_EDITOR
/// <summary>
/// A reference to a test app-param json file to enable app-param testing in the editor
/// </summary>
public TextAsset testAppParam;
#endif
/// <summary>
/// The current activity state of the scenario

/// The scenario will begin on the frame this property first returns true
/// </summary>
/// <returns>Whether the scenario should start this frame</returns>
protected abstract bool isScenarioReadyToStart { get; }
protected virtual bool isScenarioReadyToStart => true;
/// <summary>
/// Returns whether the current scenario iteration has completed

/// </summary>
protected virtual void OnConfigurationImport()
{
#if !UNITY_EDITOR
#if UNITY_EDITOR
if (testAppParam != null)
{
DeserializeFromFile(AssetDatabase.GetAssetPath(testAppParam));
}
#else
DeserializeFromCommandLine();
#endif
}

void Awake()
{
activeScenario = this;
OnAwake();
OnConfigurationImport();
OnAwake();
}
/// <summary>

void Update()
{
// There are two known issues with the starting simulations on the first frame: rendered frames cannot be
// captured and the WaitForEndOfFrame will not function properly on the first frame.
if (Time.frameCount == 1)
return;
OnConfigurationImport();
state = State.Playing;
OnStart();
foreach (var randomizer in m_Randomizers)

void IterationLoop()
{
// Perform new iteration tasks
if (currentIterationFrame == 0)
{
ResetRandomStateOnIteration();
OnIterationStart();
foreach (var randomizer in activeRandomizers)
randomizer.IterationStart();
}
// Perform new frame tasks
OnUpdate();
foreach (var randomizer in activeRandomizers)
randomizer.Update();
StartCoroutine(EndOfFrameIterationLoop());
}
IEnumerator EndOfFrameIterationLoop()
{
yield return new WaitForEndOfFrame();
// Iterate scenario frame count
currentIterationFrame++;
framesSinceInitialization++;
// Increment iteration and cleanup last iteration
if (isIterationComplete)
{

OnComplete();
state = State.Idle;
OnIdle();
return;
// Perform new iteration tasks
if (currentIterationFrame == 0)
{
ResetRandomStateOnIteration();
OnIterationStart();
foreach (var randomizer in activeRandomizers)
randomizer.IterationStart();
}
// Perform new frame tasks
OnUpdate();
foreach (var randomizer in activeRandomizers)
randomizer.Update();
// Iterate scenario frame count
currentIterationFrame++;
framesSinceInitialization++;
}
/// <summary>

if (randomizer is T typedRandomizer)
return typedRandomizer;
throw new ScenarioException($"A Randomizer of type {typeof(T).Name} was not added to this scenario");
}
/// <summary>
/// Maps a bundle primary key to a specific URL
/// </summary>
/// <param name="bundle">The bundle's primary key (file name)</param>
/// <param name="url">The bundle's URL</param>
internal void AddBundleUrl(string bundle, string url)
{
m_BundleToUrlMap.Add(bundle, url);
}
/// <summary>
/// Specifies a catalog URL to load before starting the simulation
/// </summary>
/// <param name="url"></param>
internal void AddCatalogUrl(string url)
{
m_CatalogUrls.Add(url);
}
void ValidateParameters()

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


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;
/// <inheritdoc/>

19
com.unity.perception/Runtime/Randomization/Scenarios/Serialization/ScenarioSerializer.cs


public static void Deserialize(ScenarioBase scenario, string json)
{
var jsonData = JObject.Parse(json);
if (jsonData.ContainsKey("contents"))
DeserializeContents(scenario, (JObject)jsonData["contents"]);
}
static void DeserializeContents(ScenarioBase scenario, JObject contentsData)
{
var catalogs = (JArray)contentsData["catalogs"];
foreach (var catalogToken in catalogs)
{
var catalog = (JObject)catalogToken;
scenario.AddCatalogUrl(catalog["catalogUrl"].Value<string>());
var bundles = (JArray) catalog["bundles"];
foreach (var bundleToken in bundles)
{
var bundle = (JObject) bundleToken;
scenario.AddBundleUrl(bundle["name"].Value<string>(), bundle["url"].Value<string>());
}
}
}
static void DeserializeConstants(ScenarioConstants constants, JObject constantsData)

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

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


using System;
using System.Collections.Generic;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.Perception.Randomization.Parameters;
using UnityEngine.Perception.Randomization.Samplers;
namespace UnityEngine.Perception.Randomization.Scenarios
{

[AddComponentMenu("Perception/Scenarios/Fixed Length Scenario")]
public class FixedLengthScenario: UnitySimulationScenario<FixedLengthScenario.Constants>
{
protected PerceptionCamera m_PerceptionCamera;
/// <summary>
/// Constants describing the execution of this scenario
/// </summary>

/// Returns whether the current scenario iteration has completed
/// </summary>
protected override bool isIterationComplete => currentIterationFrame >= constants.framesPerIteration;
/// <inheritdoc/>
protected override void OnAwake()
{
base.OnAwake();
m_PerceptionCamera = FindObjectOfType<PerceptionCamera>();
// if (m_PerceptionCamera != null && m_PerceptionCamera.captureTriggerMode != CaptureTriggerMode.Manual)
// {
// Debug.LogError("The perception camera must be set to manual capture mode", m_PerceptionCamera);
// m_PerceptionCamera.enabled = false;
// enabled = false;
// }
}
/// <inheritdoc/>
protected override void OnUpdate()
{
// if (m_PerceptionCamera && currentIterationFrame == constants.framesPerIteration - 1)
// {
// m_PerceptionCamera.RequestCapture();
// }
}
}
}
正在加载...
取消
保存