浏览代码

improved parameter doc

/usim-randomization
Steven Leal 4 年前
当前提交
410cab0f
共有 2 个文件被更改,包括 45 次插入7 次删除
  1. 51
      com.unity.perception/Documentation~/Randomization/Parameters.md
  2. 1
      com.unity.perception/Runtime/Randomization/Parameters/CategoricalParameter.cs

51
com.unity.perception/Documentation~/Randomization/Parameters.md


# Custom Parameters
# Parameters
## Lookup Parameters
To obtain a parameter from a paramter configuration, use the GetParameter() method:
```
// Get a reference to the parameter configuration attached to this GameObject
var parameterConfiguration = GetComponent<ParameterConfiguration>();
// Lookup the parameter "ObjectWidth" by name
var parameter = GetComponent<FloatParameter>("ObjectWidth");
```
## Creating and Sampling Parameters
Parameters are typically managed by `ParameterConfigurations` in the Unity Editor. However, parameters can be instanced independently like a regular class too:
```
// Create a color parameter
var colorParameter = new HsvaColorParameter();
// Generate one color sample
var color = colorParameter.Sample();
```
Note that parameters, like samplers, generate new random values for each call to the Sample() method:
```
var color1 = colorParameter.Sample();
var color2 = colorParameter.Sample();
Assert.AreNotEqual(color1, color2);
```
## Defining Custom Parameters
All parameters derive from the Parameter abstract class, but all included perception package parameter types derive from two specialized Parameter base classes:
All parameters derive from the `Parameter` abstract class, but all included perception package parameter types derive from two specialized Parameter base classes:
1. `CategoricalParameter`
2. `NumericParameter`

Numeric parameters use samplers to generate randomized structs. Take a look at the [ColorHsvaParameter]() class included in the perception package for an example on how to implement a numeric parameter.
## Performance
## Improving Sampling Performance
// Get a reference to the parameter configuration attached to this GameObject
var parameterConfiguration = GetComponent<ParameterConfiguration>();
// Lookup parameters
var cubeColorParameter = parameterConfiguration.GetParameter<HsvaColorParameter>("CubeColor");
var cubePositionParameter = parameterConfiguration.GetParameter<Vector3Parameter>("CubePosition");
var currentIteration = ScenarioBase.ActiveScenario.currentIteration
var cubeColors = ObjectColor.Samples(constants.objectCount, out var colorHandle);
var cubePositions = ObjectPosition.Samples(constants.objectCount, out var positionHandle);
var cubeColors = cubeColorParameter.Samples(constants.cubeCount, out var colorHandle);
var cubePositions = cubePositionParameter.Samples(constants.cubeCount, out var positionHandle);
// Combine job handles
var handles = JobHandle.CombineDependencies(colorHandle, positionHandle);

// Use the created samples
for (var i = 0; i < constants.objectCount; i++)
for (var i = 0; i < constants.cubeCount; i++)
{
m_ObjectMaterials[i].SetColor(k_BaseColorProperty, cubeColors[i]);
m_Objects[i].transform.position = cubePositions[i];

1
com.unity.perception/Runtime/Randomization/Parameters/CategoricalParameter.cs


using System;
using System.Collections.Generic;
using Unity.Assertions;
using UnityEngine.Perception.Randomization.Samplers;
namespace UnityEngine.Perception.Randomization.Parameters

正在加载...
取消
保存