浏览代码

Merge pull request #189 from Unity-Technologies/usim-app-param-fix

App-params now deserialize from the correct location in USim
/main
GitHub 4 年前
当前提交
0f9d783e
共有 6 个文件被更改,包括 44 次插入51 次删除
  1. 25
      com.unity.perception/Editor/Randomization/Editors/RandomizerTagEditor.cs
  2. 16
      com.unity.perception/Editor/Randomization/Utilities/UIElementsEditorUtilities.cs
  3. 1
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBox3DLabeler.cs
  4. 19
      com.unity.perception/Runtime/Randomization/Scenarios/Scenario.cs
  5. 20
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
  6. 14
      com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs

25
com.unity.perception/Editor/Randomization/Editors/RandomizerTagEditor.cs


using UnityEditor;
using UnityEditor.Perception.Randomization;
using UnityEditor.UIElements;
using UnityEngine.Perception.Randomization.Randomizers;
using UnityEngine.UIElements;

[CustomEditor(typeof(RandomizerTag), true)]
public class RandomizerTagEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
var rootElement = new VisualElement();
CreatePropertyFields(rootElement);
return rootElement;
}
void CreatePropertyFields(VisualElement rootElement)
{
var iterator = serializedObject.GetIterator();
iterator.NextVisible(true);
do
{
if (iterator.name == "m_Script")
continue;
var propertyField = new PropertyField(iterator.Copy());
propertyField.Bind(serializedObject);
rootElement.Add(propertyField);
} while (iterator.NextVisible(false));
}
}
class RandomizerTagEditor : ParameterUIElementsEditor { }
}

16
com.unity.perception/Editor/Randomization/Utilities/UIElementsEditorUtilities.cs


var fieldType = serializedObj.targetObject.GetType();
var iterator = serializedObj.GetIterator();
iterator.NextVisible(true);
iterator.NextVisible(false);
do
if (iterator.NextVisible(false))
var propertyField = CreatePropertyField(iterator, fieldType);
containerElement.Add(propertyField);
} while (iterator.NextVisible(false));
do
{
var propertyField = CreatePropertyField(iterator, fieldType);
containerElement.Add(propertyField);
} while (iterator.NextVisible(false));
}
}
/// <summary>

public static void CreatePropertyFields(SerializedProperty property, VisualElement containerElement)
{
var fieldType = StaticData.GetManagedReferenceValue(property).GetType();
{
do
{
if (SerializedProperty.EqualContents(iterator, nextSiblingProperty))

} while (iterator.NextVisible(false));
}
}
/// <summary>

1
com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBox3DLabeler.cs


return VisualizationHelper.ConvertToScreenSpace(cam, worldPoint);
}
/// <inheritdoc/>
protected override void OnVisualize()
{
if (m_ToReport == null) return;

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


/// <inheritdoc/>
public override void DeserializeFromFile(string configFilePath)
{
if (string.IsNullOrEmpty(configFilePath))
throw new ArgumentNullException();
if (!File.Exists(configFilePath))
throw new FileNotFoundException($"A scenario configuration file does not exist at path {configFilePath}");
if (string.IsNullOrEmpty(configFilePath) || !File.Exists(configFilePath))
Debug.Log($"No configuration file found at {defaultConfigFilePath}");
else
{
Debug.Log($"Deserialized scenario configuration from <a href=\"file:///${configFilePath}\">{configFilePath}</a>. " +
"Using undo in the editor will revert these changes to your scenario.");
Debug.Log($"Deserialized scenario configuration from <a href=\"file:///${configFilePath}\">{configFilePath}</a>. " +
"Using undo in the editor will revert these changes to your scenario.");
Debug.Log($"Deserialized scenario configuration from <a href=\"file:///${configFilePath}\">{configFilePath}</a>");
Debug.Log($"Deserialized scenario configuration from <a href=\"file:///${configFilePath}\">{configFilePath}</a>");
var jsonText = File.ReadAllText(configFilePath);
DeserializeFromJson(jsonText);
var jsonText = File.ReadAllText(configFilePath);
DeserializeFromJson(jsonText);
}
}
/// <inheritdoc/>

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


/// <summary>
/// Returns the absolute file path of the JSON serialized configuration
/// </summary>
public string defaultConfigFilePath =>
public virtual string defaultConfigFilePath =>
Application.dataPath + "/StreamingAssets/" + configFileName + ".json";
/// <summary>

}
/// <summary>
/// Resets SamplerState.randomState with a new seed value generated by hashing this Scenario's randomSeed
/// with its currentIteration
/// </summary>
protected virtual void ResetRandomStateOnIteration()
{
SamplerState.randomState = SamplerUtility.IterateSeed((uint)currentIteration, genericConstants.randomSeed);
}
/// <summary>
/// This method executed directly after this scenario has been registered and initialized
/// </summary>
protected virtual void OnAwake() { }

Guid.Parse("14adb394-46c0-47e8-a3f0-99e754483b76"));
DatasetCapture.ReportMetric(randomSeedMetricDefinition, new[] { genericConstants.randomSeed });
#if !UNITY_EDITOR
if (File.Exists(defaultConfigFilePath))
DeserializeFromFile();
else
Debug.Log($"No configuration file found at {defaultConfigFilePath}. " +
"Proceeding with built in scenario constants and randomizer settings.");
DeserializeFromFile();
#endif
}

if (currentIterationFrame == 0)
{
DatasetCapture.StartNewSequence();
SamplerState.randomState = SamplerUtility.IterateSeed((uint)currentIteration, genericConstants.randomSeed);
ResetRandomStateOnIteration();
DatasetCapture.ReportMetric(m_IterationMetricDefinition, new[]
{
new IterationMetricData()

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


using System;
using System.IO;
using UnityEngine.Perception.Randomization.Samplers;
namespace UnityEngine.Perception.Randomization.Scenarios
{

public sealed override bool isScenarioComplete => currentIteration >= constants.totalIterations;
/// <inheritdoc/>
public override string defaultConfigFilePath =>
Configuration.Instance.IsSimulationRunningInCloud()
? new Uri(Configuration.Instance.SimulationConfig.app_param_uri).LocalPath
: base.defaultConfigFilePath;
/// <inheritdoc/>
protected sealed override void IncrementIteration()
{
currentIteration += constants.instanceCount;

public sealed override void DeserializeFromFile(string configFilePath)
{
base.DeserializeFromFile(Configuration.Instance.IsSimulationRunningInCloud()
? new Uri(Configuration.Instance.SimulationConfig.app_param_uri).LocalPath
: configFilePath);
currentIteration = constants.instanceIndex;
base.DeserializeFromFile(configFilePath);
currentIteration = constants.instanceIndex * constants.instanceCount;
}
}
}
正在加载...
取消
保存