浏览代码

Merge branch 'generic-asset-sources' of https://github.com/Unity-Technologies/com.unity.perception into generic-asset-sources

/generic-asset-sources
Jon Hogins 3 年前
当前提交
d6bc212c
共有 31 个文件被更改,包括 1539 次插入213 次删除
  1. 2
      com.unity.perception/CHANGELOG.md
  2. 35
      com.unity.perception/Documentation~/GroundTruthLabeling.md
  3. 7
      com.unity.perception/Documentation~/Randomization/Index.md
  4. 7
      com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs
  5. 4
      com.unity.perception/Editor/Randomization/Utilities/StaticData.cs
  6. 6
      com.unity.perception/Editor/Randomization/Uxml/AssetSource/AssetSourceElement.uxml
  7. 7
      com.unity.perception/Editor/Randomization/Uxml/ScenarioBaseElement.uxml
  8. 50
      com.unity.perception/Editor/Randomization/VisualElements/AssetSource/AssetSourceElement.cs
  9. 39
      com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs
  10. 43
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetSource.cs
  11. 6
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetSourceLocation.cs
  12. 4
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/LocalAssetSourceLocation.cs
  13. 79
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
  14. 38
      com.unity.perception/Runtime/Randomization/Scenarios/Serialization/ScenarioSerializer.cs
  15. 16
      com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs
  16. 1
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/Resources/SampleScenarioConfiguration.json
  17. 4
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ScenarioTests.cs
  18. 994
      com.unity.perception/Documentation~/Randomization/Images/randomization_uml.png
  19. 250
      com.unity.perception/Documentation~/images/labeling_uml.png
  20. 16
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetRole.cs
  21. 11
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetRole.cs.meta
  22. 15
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetRoleBase.cs
  23. 11
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetRoleBase.cs.meta
  24. 8
      com.unity.perception/Tests/Runtime/Randomization/AssetSourceTests.meta
  25. 51
      com.unity.perception/Tests/Runtime/Randomization/AssetSourceTests/LocalAssetSourceTests.cs
  26. 11
      com.unity.perception/Tests/Runtime/Randomization/AssetSourceTests/LocalAssetSourceTests.cs.meta
  27. 16
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/Archetype.cs
  28. 3
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/Archetype.cs.meta
  29. 15
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/ArchetypeBase.cs
  30. 3
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/ArchetypeBase.cs.meta

2
com.unity.perception/CHANGELOG.md


The PoissonDiskSampling utility now samples a larger region of points to then crop to size of the intended region to prevent edge case bias.
Upgraded capture package dependency to 0.0.10-preview.21
Upgraded capture package dependency to 0.0.10-preview.22 to fix an issue with URP where post processing effects were not included when capturing images.
### Deprecated

35
com.unity.perception/Documentation~/GroundTruthLabeling.md


# Labeling
Many labelers require mapping the objects in the view to the values recorded in the dataset. As an example, Semantic Segmentation needs to determine the color to draw each object in the segmentation image.
# Ground Truth Generation
The Perception package includes a set of Labelers which capture ground truth information along with each captured frame. The built-in Labelers support a variety of common computer vision tasks, including 2D and 3D bounding boxes, instance and semantic segmentation, and keypoint labeling (labeled points on 3D objects). The package also includes extensible components for building new Labelers to support additional tasks. Labelers derive ground truth data from labels specified on the GameObjects present in the Scene.
<p align="center">
<img src="images/labeling_uml.png" width="800"/>
<br><i>Class diagram for the ground truth generation system of the Perception package</i>
</p>
## Camera Labeler
A set of Camera Labelers are added to the Perception Camera, each tasked with generating a specific type of ground truth. For instance, the Semantic Segmentation Labeler outputs segmentation images in which each labeled object is rendered in a unique user-definable color and non-labeled objects and the background are rendered black.
## Label Config
The Label Config acts as a mapping between string labels and object classes (currently colors or integers), deciding which labels in the Scene (and thus which objects) should be tracked by the Labeler, and what color (or integer id) they should have in the captured frames.
## Labeling Component
The Labeling component associates a list of string-based labels with a GameObject and its descendants. A Labeling component on a descendant overrides its parent's labels.
## Label Resolution
The Labeling component added to the GameObjects in the Scene works in conjunction with each active Labeler's Label Config, in order to map each labeled GameObject to an object class in the output.
## Labeling component
The Labeling component associates a list of string-based labels with a GameObject and its descendants. A Labeling component on a descendant overrides its parent's labels.
### Limitations
## Limitations
## Label Config
Many labelers require a Label Config asset. This asset specifies a list of all labels to be captured in the dataset along with extra information used by the various labelers.
For example, you could label an asset representing a box of Rice Krispies as `food\cereal\kellogs\ricekrispies`
For example, you can assign four different labels to an asset representing a box of Rice Krispies so as to define an inherent hierarchy:
* "food": type
* "cereal": subtype

If the goal of the algorithm is to identify all objects in a Scene that are "food", that label is available and can be used. Conversely if the goal is to identify only Rice Krispies cereal within a Scene that label is also available. Depending on the goal of the algorithm, you can use any mix of labels in the hierarchy.
This way, you can have Label Configs that include labels from different levels of this hierarchy so that you can easily switch an object's label in the output by switching to a different Label Config. If the goal of the algorithm is to identify all objects in a Scene that are "food", that label is available and can be used if the Label Config only contains "food" and not the other labels of the object. Conversely if the goal is to identify only Rice Krispies cereal within a Scene, that label is also available. Depending on the goal of the algorithm, you can use any mix of labels in the hierarchy.

7
com.unity.perception/Documentation~/Randomization/Index.md


4. Parameters
5. Samplers
<br>
<p align="center">
<img src="Images/randomization_uml.png" width="900"/>
<br><i>Class diagram for the randomization framework included in the Perception package</i>
</p>
## Scenarios

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


if (string.IsNullOrEmpty(filePath))
return;
Undo.RecordObject(m_Scenario, "Deserialized scenario configuration");
m_Scenario.DeserializeFromFile(filePath);
var originalConfig = m_Scenario.configuration;
m_Scenario.LoadConfigurationFromFile(filePath);
m_Scenario.DeserializeConfiguration();
m_Scenario.configuration = originalConfig;
Debug.Log($"Deserialized scenario configuration from {Path.GetFullPath(filePath)}. " +
"Using undo in the editor will revert these changes to your scenario.");
PlayerPrefs.SetString(k_ConfigFilePlayerPrefKey, filePath);

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

4
com.unity.perception/Editor/Randomization/Utilities/StaticData.cs


internal static Type[] randomizerTypes;
internal static Type[] samplerTypes;
internal static Type[] assetSourceLocationTypes;
internal static Type[] archetypeTypes;
internal static Type[] assetRoleTypes;
static StaticData()
{

archetypeTypes = GetConstructableDerivedTypes<ArchetypeBase>();
assetRoleTypes = GetConstructableDerivedTypes<AssetRoleBase>();
}
static Type[] GetConstructableDerivedTypes<T>()

6
com.unity.perception/Editor/Randomization/Uxml/AssetSource/AssetSourceElement.uxml


</VisualElement>
<VisualElement style="flex-direction: row; align-items: center;">
<Label
text="Archetype"
text="Asset Role"
tooltip="Archetypes preprocess assets loaded from the selected asset source location"/>
<editor:ToolbarMenu name="archetype-dropdown" text="Type" class="sampler__type-menu"/>
tooltip="Asset Roles preprocess assets loaded from the selected asset source location"/>
<editor:ToolbarMenu name="asset-role-dropdown" text="Type" class="sampler__type-menu"/>
</VisualElement>
</VisualElement>
</VisualElement>

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


class="scenario__info-box"
text="Scenarios control the execution flow of your simulation by applying randomization parameters. Make sure to always have only one scenario active within your scene."/>
<VisualElement name="constants-container">
<editor:PropertyField
name="configuration-asset"
label="Configuration"
binding-path="configuration"
style="margin-left: 13 px;"
tooltip="References a JSON configuration text asset to load at runtime before the scenario starts executing. Scenario configuration files can be created using the Generate JSON Config button below."/>
<editor:PropertyField name="configuration-file-name" label="Constants File Name" binding-path="serializedConstantsFileName"/>
<VisualElement style="flex-direction: row;">
<Button name="generate-json-config" text="Generate JSON Config" style="flex-grow: 1;"
tooltip="Serializes scenario constants and randomizer settings to a JSON configuration file"/>

50
com.unity.perception/Editor/Randomization/VisualElements/AssetSource/AssetSourceElement.cs


{
class AssetSourceElement : VisualElement
{
SerializedProperty m_ArchetypeProperty;
SerializedProperty m_AssetRoleProperty;
ToolbarMenu m_ArchetypeToolbarMenu;
ToolbarMenu m_AssetRoleToolbarMenu;
ArchetypeBase archetype =>
(ArchetypeBase)StaticData.GetManagedReferenceValue(m_ArchetypeProperty);
AssetRoleBase assetRole =>
(AssetRoleBase)StaticData.GetManagedReferenceValue(m_AssetRoleProperty);
AssetSourceLocation assetSourceLocation =>
(AssetSourceLocation)StaticData.GetManagedReferenceValue(m_LocationProperty);

m_ArchetypeProperty = property.FindPropertyRelative("m_ArchetypeBase");
m_AssetRoleProperty = property.FindPropertyRelative("m_AssetRoleBase");
m_LocationProperty = property.FindPropertyRelative(nameof(AssetSource<GameObject>.assetSourceLocation));
var template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
$"{StaticData.uxmlDir}/AssetSource/AssetSourceElement.uxml");

m_FieldsContainer = this.Q<VisualElement>("fields-container");
m_ArchetypeToolbarMenu = this.Q<ToolbarMenu>("archetype-dropdown");
var storedArchetype = archetype;
m_ArchetypeToolbarMenu.text = storedArchetype != null
? GetArchetypeDisplayName(archetype.GetType()) : "None";
m_AssetRoleToolbarMenu = this.Q<ToolbarMenu>("asset-role-dropdown");
var storedAssetRole = assetRole;
m_AssetRoleToolbarMenu.text = storedAssetRole != null
? GetAssetRoleDisplayName(assetRole.GetType()) : "None";
var baseType = fieldInfo.FieldType.GetProperty("archetype").PropertyType;
m_ArchetypeToolbarMenu.menu.AppendAction(
var baseType = fieldInfo.FieldType.GetProperty("assetRole").PropertyType;
m_AssetRoleToolbarMenu.menu.AppendAction(
a => ReplaceArchetype(null),
a => ReplaceAssetRole(null),
foreach (var type in StaticData.archetypeTypes)
foreach (var type in StaticData.assetRoleTypes)
m_ArchetypeToolbarMenu.menu.AppendAction(
GetArchetypeDisplayName(type),
a => ReplaceArchetype(type),
m_AssetRoleToolbarMenu.menu.AppendAction(
GetAssetRoleDisplayName(type),
a => ReplaceAssetRole(type),
a => DropdownMenuAction.Status.Normal);
}

UpdateLocationUI(assetSourceLocation.GetType());
}
void ReplaceArchetype(Type type)
void ReplaceAssetRole(Type type)
m_ArchetypeToolbarMenu.text = "None";
m_ArchetypeProperty.managedReferenceValue = null;
m_AssetRoleToolbarMenu.text = "None";
m_AssetRoleProperty.managedReferenceValue = null;
m_ArchetypeToolbarMenu.text = GetDisplayName(type);
var newArchetype = (ArchetypeBase)Activator.CreateInstance(type);
m_ArchetypeProperty.managedReferenceValue = newArchetype;
m_AssetRoleToolbarMenu.text = GetDisplayName(type);
var newAssetRole = (AssetRoleBase)Activator.CreateInstance(type);
m_AssetRoleProperty.managedReferenceValue = newAssetRole;
m_ArchetypeProperty.serializedObject.ApplyModifiedProperties();
m_AssetRoleProperty.serializedObject.ApplyModifiedProperties();
}
void CreateAssetSourceLocation(Type type)

return attribute != null ? attribute.DisplayName : type.Name;
}
static string GetArchetypeDisplayName(Type type)
static string GetAssetRoleDisplayName(Type type)
return type.Name.Replace("Archetype", string.Empty);
return type.Name.Replace("AssetRole", string.Empty);
}
}
}

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


/// </summary>
protected virtual void Cleanup() {}
/// <summary>
/// Initializes labeler with the target perception camera
/// </summary>
/// <param name="camera">The target perception camera</param>
public void Init(PerceptionCamera camera)
{
try
{
perceptionCamera = camera;
sensorHandle = camera.SensorHandle;
Setup();
isInitialized = true;
m_ShowVisualizations = supportsVisualization && perceptionCamera.showVisualizations;
}
catch (Exception)
{
enabled = false;
throw;
}
}
internal void InternalSetup() => Setup();
internal bool InternalVisualizationEnabled

internal void Visualize()
{
if (visualizationEnabled) OnVisualize();
}
internal void Init(PerceptionCamera newPerceptionCamera)
{
try
{
this.perceptionCamera = newPerceptionCamera;
sensorHandle = newPerceptionCamera.SensorHandle;
Setup();
isInitialized = true;
m_ShowVisualizations = supportsVisualization && perceptionCamera.showVisualizations;
}
catch (Exception)
{
this.enabled = false;
throw;
}
}
}
}

43
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetSource.cs


[Serializable]
public sealed class AssetSource<T> where T : Object
{
[SerializeReference] ArchetypeBase m_ArchetypeBase;
[SerializeReference] AssetRoleBase m_AssetRoleBase;
/// <summary>
/// The location to load assets from

UniformSampler m_Sampler = new UniformSampler();
/// <summary>
/// The archetype used to preprocess assets from this source
/// The asset role used to preprocess assets from this source
public Archetype<T> archetype
public AssetRole<T> assetRole
get => (Archetype<T>)m_ArchetypeBase;
set => m_ArchetypeBase = value;
get => (AssetRole<T>)m_AssetRoleBase;
set => m_AssetRoleBase = value;
public int Count => assetSourceLocation.Count;
public int count => assetSourceLocation.count;
/// Execute setup steps for this AssetSource
/// Execute setup steps for this AssetSource. It is often unnecessary to call this API directly since all other
/// relevant APIs in this class will Initialize() this AssetSource if it hasn't been already.
assetSourceLocation.Initialize(archetype);
m_Initialized = true;
if (!m_Initialized)
{
assetSourceLocation.Initialize(assetRole);
m_Initialized = true;
}
}
/// <summary>

/// <returns>All assets that can be loaded from this AssetSource</returns>
public T[] LoadAllRawAssets()
{
var array = new T[Count];
for (var i = 0; i < Count; i++)
CheckIfInitialized();
var array = new T[count];
for (var i = 0; i < count; i++)
/// Creates an instance of the asset loaded from the provided index and preprocesses it using the archetype
/// Creates an instance of the asset loaded from the provided index and preprocesses it using the asset role
/// assigned to this asset source
/// </summary>
/// <param name="index">The index of the asset to load</param>

/// <returns>Instantiated instances from every loadable asset</returns>
public T[] CreateProcessedInstances()
{
var array = new T[Count];
for (var i = 0; i < Count; i++)
CheckIfInitialized();
var array = new T[count];
for (var i = 0; i < count; i++)
array[i] = CreateProcessedInstance(i);
return array;
}

public T SampleAsset()
{
CheckIfInitialized();
if (Count == 0)
return null;
return assetSourceLocation.LoadAsset<T>((int)(m_Sampler.Sample() * Count));
return assetSourceLocation.LoadAsset<T>((int)(m_Sampler.Sample() * count));
}
/// <summary>

return null;
var instance = Object.Instantiate(asset);
if (archetype != null)
archetype.Preprocess(instance);
if (assetRole != null)
assetRole.Preprocess(instance);
return instance;
}
}

6
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetSourceLocation.cs


/// <summary>
/// The number of assets available at this location
/// </summary>
public abstract int Count { get; }
public abstract int count { get; }
/// <param name="archetype">The archetype that will be used to preprocess assets from this location</param>
/// <param name="assetRole">The asset role that will be used to preprocess assets from this location</param>
public abstract void Initialize<T>(Archetype<T> archetype) where T : Object;
public abstract void Initialize<T>(AssetRole<T> assetRole) where T : Object;
/// <summary>
/// Unload all assets loaded from this location

4
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/LocalAssetSourceLocation.cs


[SerializeField] public List<Object> assets;
/// <inheritdoc/>
public override int Count => assets.Count;
public override int count => assets.Count;
public override void Initialize<T>(Archetype<T> archetype) { }
public override void Initialize<T>(AssetRole<T> assetRole) { }
/// <inheritdoc/>
public override void ReleaseAssets() { }

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


[SerializeReference] List<Randomizer> m_Randomizers = new List<Randomizer>();
/// <summary>
/// An external text asset that is loaded when the scenario starts to configure scenario settings
/// </summary>
public TextAsset configuration;
/// <summary>
/// Enumerates over all enabled randomizers
/// </summary>
public IEnumerable<Randomizer> activeRandomizers

}
/// <summary>
/// Overwrites this scenario's randomizer settings and scenario constants from a JSON serialized configuration
/// Loads a scenario configuration from a file located at the given file path
/// <param name="json">The JSON string to deserialize</param>
public virtual void DeserializeFromJson(string json)
/// <param name="filePath">The file path of the scenario configuration file</param>
/// <exception cref="FileNotFoundException"></exception>
public void LoadConfigurationFromFile(string filePath)
ScenarioSerializer.Deserialize(this, json);
}
/// <summary>
/// Overwrites this scenario's randomizer settings and scenario constants using a configuration file located at
/// the provided file path
/// </summary>
/// <param name="configFilePath">The file path to the configuration file to deserialize</param>
public virtual void DeserializeFromFile(string configFilePath)
{
if (string.IsNullOrEmpty(configFilePath))
throw new ArgumentException($"{nameof(configFilePath)} is null or empty");
if (!File.Exists(configFilePath))
throw new ArgumentException($"No configuration file found at {configFilePath}");
var jsonText = File.ReadAllText(configFilePath);
DeserializeFromJson(jsonText);
#if !UNITY_EDITOR
Debug.Log($"Deserialized scenario configuration from {Path.GetFullPath(configFilePath)}");
#endif
if (!File.Exists(filePath))
throw new FileNotFoundException($"No configuration file found at {filePath}");
var jsonText = File.ReadAllText(filePath);
configuration = new TextAsset(jsonText);
}
/// <summary>

protected virtual void DeserializeFromCommandLine(string commandLineArg="--scenario-config-file")
protected void LoadConfigurationFromCommandLine(string commandLineArg="--scenario-config-file")
{
var args = Environment.GetCommandLineArgs();
var filePath = string.Empty;

return;
}
try { DeserializeFromFile(filePath); }
catch (Exception exception)
{
Debug.LogException(exception);
Debug.LogError("An exception was caught while attempting to parse a " +
$"scenario configuration file at {filePath}. Cleaning up and exiting simulation.");
}
LoadConfigurationFromFile(filePath);
}
/// <summary>
/// Loads and stores a JSON scenario settings configuration file before the scenario starts
/// </summary>
protected virtual void LoadConfigurationAsset()
{
LoadConfigurationFromCommandLine();
}
/// <summary>
/// Overwrites this scenario's randomizer settings and scenario constants from a JSON serialized configuration
/// </summary>
public virtual void DeserializeConfiguration()
{
if (configuration != null)
ScenarioSerializer.Deserialize(this, configuration.text);
}
/// <summary>

/// OnAwake is called when this scenario MonoBehaviour is created or instantiated
/// </summary>
protected virtual void OnAwake() { }
/// <summary>
/// OnConfigurationImport is called before OnStart in the same frame. This method by default loads a scenario
/// settings from a file before the scenario begins.
/// </summary>
protected virtual void OnConfigurationImport()
{
#if !UNITY_EDITOR
DeserializeFromCommandLine();
#endif
}
/// <summary>
/// OnStart is called when the scenario first begins playing

case State.Initializing:
if (isScenarioReadyToStart)
{
OnConfigurationImport();
#if !UNITY_EDITOR
LoadConfigurationAsset();
#endif
DeserializeConfiguration();
state = State.Playing;
OnStart();
foreach (var randomizer in m_Randomizers)

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


{
return new JObject
{
["archetypes"] = SerializeArchetypes(scenario.randomizers),
}
static JArray SerializeArchetypes(IReadOnlyList<Randomizer> randomizers)
{
var archetypesObj = new JArray();
var archetypeLabels = new HashSet<string>();
foreach (var randomizer in randomizers)
{
var assetSourceFields = randomizer.GetType().GetFields();
foreach (var field in assetSourceFields)
{
if (!IsSubclassOfRawGeneric(typeof(AssetSource<>), field.FieldType))
continue;
var assetSource = field.GetValue(randomizer);
if (assetSource == null)
continue;
var archetypeField = assetSource.GetType().GetField(
"m_ArchetypeBase", BindingFlags.NonPublic | BindingFlags.Instance);
var archetype = (ArchetypeBase)archetypeField.GetValue(assetSource);
if (archetype == null || archetypeLabels.Contains(archetype.label))
continue;
archetypeLabels.Add(archetype.label);
}
}
var labelsList = archetypeLabels.ToList();
labelsList.Sort();
foreach (var label in labelsList)
{
var archetypeObj = new JObject
{
new JProperty("name", label),
new JProperty("description", string.Empty)
};
archetypesObj.Add(archetypeObj);
}
return archetypesObj;
}
static JObject SerializeConstants(ScenarioConstants constants)

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


protected sealed override bool isScenarioComplete => currentIteration >= constants.totalIterations;
/// <inheritdoc/>
protected override void OnConfigurationImport()
protected override void LoadConfigurationAsset()
DeserializeFromFile(new Uri(Configuration.Instance.SimulationConfig.app_param_uri).LocalPath);
constants.instanceIndex = int.Parse(Configuration.Instance.GetInstanceId()) - 1;
var filePath = new Uri(Configuration.Instance.SimulationConfig.app_param_uri).LocalPath;
LoadConfigurationFromFile(filePath);
base.OnConfigurationImport();
base.LoadConfigurationAsset();
}
/// <inheritdoc/>
public override void DeserializeConfiguration()
{
base.DeserializeConfiguration();
if (Configuration.Instance.IsSimulationRunningInCloud())
constants.instanceIndex = int.Parse(Configuration.Instance.GetInstanceId()) - 1;
currentIteration = constants.instanceIndex;
}

1
com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/Resources/SampleScenarioConfiguration.json


{
"archetypes": [],
"constants": {
"framesPerIteration": 1,
"totalIterations": 100,

4
com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ScenarioTests.cs


// Serialize some values
m_Scenario.constants = constants;
var serializedConfig = m_Scenario.SerializeToJson();
m_Scenario.configuration = new TextAsset(m_Scenario.SerializeToJson());
m_Scenario.DeserializeFromJson(serializedConfig);
m_Scenario.DeserializeConfiguration();
// Check if the values reverted correctly
Assert.AreEqual(m_Scenario.constants.framesPerIteration, constants.framesPerIteration);

994
com.unity.perception/Documentation~/Randomization/Images/randomization_uml.png

之前 之后
宽度: 3124  |  高度: 1304  |  大小: 254 KiB

250
com.unity.perception/Documentation~/images/labeling_uml.png
文件差异内容过多而无法显示
查看文件

16
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetRole.cs


namespace UnityEngine.Perception.Randomization
{
/// <summary>
/// Derive this class to create a typed asset role.
/// Typed asset roles are used to apply preprocessing steps to assets loaded from an <see cref="AssetSource{T}"/>.
/// </summary>
/// <typeparam name="T">The type of asset to preprocess</typeparam>
public abstract class AssetRole<T> : AssetRoleBase where T : Object
{
/// <summary>
/// Perform preprocessing operations on an asset loaded from an <see cref="AssetSource{T}"/>.
/// </summary>
/// <param name="asset">The asset to preprocess</param>
public abstract void Preprocess(T asset);
}
}

11
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetRole.cs.meta


fileFormatVersion: 2
guid: 3fce529b432e45f45bee917a2c4205b6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

15
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetRoleBase.cs


using UnityEngine;
namespace UnityEngine.Perception.Randomization
{
/// <summary>
/// The base asset role class. Derive from <see cref="AssetRole{T}"/> instead to create a new asset role.
/// </summary>
public abstract class AssetRoleBase
{
/// <summary>
/// The string label uniquely associated with this asset role
/// </summary>
public abstract string label { get; }
}
}

11
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetRoleBase.cs.meta


fileFormatVersion: 2
guid: 1af66eeef6ffa514a8307a228b8e85f9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
com.unity.perception/Tests/Runtime/Randomization/AssetSourceTests.meta


fileFormatVersion: 2
guid: ea8713402c0e1a946ac6af555b908641
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

51
com.unity.perception/Tests/Runtime/Randomization/AssetSourceTests/LocalAssetSourceTests.cs


using NUnit.Framework;
using UnityEngine;
using UnityEngine.Perception.Randomization;
namespace RandomizationTests.AssetSourceTests
{
[TestFixture]
public class LocalAssetSourceTests
{
GameObject m_TestObject;
TestBehaviour m_Behaviour;
class TestAssetRole : AssetRole<GameObject>
{
public override string label => "test";
public override void Preprocess(GameObject asset)
{
throw new System.NotImplementedException();
}
}
class TestBehaviour : MonoBehaviour
{
public AssetSource<GameObject> gameObjectSource = new AssetSource<GameObject>
{
assetRole = null,
assetSourceLocation = new LocalAssetSourceLocation()
};
public AssetSource<Material> materialSource = new AssetSource<Material>
{
assetRole = null,
assetSourceLocation = new LocalAssetSourceLocation()
};
}
[SetUp]
public void Setup()
{
m_TestObject = new GameObject();
m_Behaviour = m_TestObject.AddComponent<TestBehaviour>();
}
[TearDown]
public void TearDown()
{
Object.DestroyImmediate(m_TestObject);
}
}
}

11
com.unity.perception/Tests/Runtime/Randomization/AssetSourceTests/LocalAssetSourceTests.cs.meta


fileFormatVersion: 2
guid: c7b5bdabb856bb5469fd4033fb6bda01
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

16
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/Archetype.cs


namespace UnityEngine.Perception.Randomization
{
/// <summary>
/// Derive this class to create a typed Archetype.
/// Typed Archetypes are used to apply preprocessing steps to assets loaded from an <see cref="AssetSource{T}"/>.
/// </summary>
/// <typeparam name="T">The type of asset to preprocess</typeparam>
public abstract class Archetype<T> : ArchetypeBase where T : Object
{
/// <summary>
/// Perform preprocessing operations on an asset loaded from an <see cref="AssetSource{T}"/>.
/// </summary>
/// <param name="asset">The asset to preprocess</param>
public abstract void Preprocess(T asset);
}
}

3
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/Archetype.cs.meta


fileFormatVersion: 2
guid: ffdc828eccff45728455a572d1f2b0e3
timeCreated: 1618978426

15
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/ArchetypeBase.cs


using UnityEngine;
namespace UnityEngine.Perception.Randomization
{
/// <summary>
/// The base Archetype class. Derive from <see cref="AssetSource{T}"/> instead to create a new archetype.
/// </summary>
public abstract class ArchetypeBase
{
/// <summary>
/// The string label uniquely associated with this archetype
/// </summary>
public abstract string label { get; }
}
}

3
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/ArchetypeBase.cs.meta


fileFormatVersion: 2
guid: 88c34672b8a649439c1fd55bc201acde
timeCreated: 1619731337
正在加载...
取消
保存