浏览代码

added more parameter docs

/usim-randomization
Steven Leal 4 年前
当前提交
aac3570e
共有 14 个文件被更改,包括 146 次插入36 次删除
  1. 21
      com.unity.perception/Editor/Randomization/ParameterElement.cs
  2. 4
      com.unity.perception/Editor/Randomization/SamplerElement.cs
  3. 3
      com.unity.perception/Runtime/Randomization/Parameters/CategoricalParameter.cs
  4. 9
      com.unity.perception/Runtime/Randomization/Parameters/Parameter.cs
  5. 18
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/BooleanParameter.cs
  6. 13
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorHsvaParameter.cs
  7. 13
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/FloatParameter.cs
  8. 3
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/GameObjectParameter.cs
  9. 23
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/IntegerParameter.cs
  10. 3
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/MaterialParameter.cs
  11. 3
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/StringParameter.cs
  12. 21
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector2Parameter.cs
  13. 23
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector3Parameter.cs
  14. 25
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector4Parameter.cs

21
com.unity.perception/Editor/Randomization/ParameterElement.cs


VisualElement m_TargetContainer;
ToolbarMenu m_TargetPropertyMenu;
SerializedProperty m_SerializedProperty;
SerializedProperty m_TargetGameObjectProperty;
const string k_CollapsedParameterClass = "collapsed-parameter";

parameterNameField.BindProperty(m_SerializedProperty.FindPropertyRelative("name"));
m_TargetContainer = this.Q<VisualElement>("target-container");
m_TargetPropertyMenu = this.Q<ToolbarMenu>("property-select-menu");
m_TargetGameObjectProperty = m_SerializedProperty.FindPropertyRelative("target.gameObject");
m_TargetPropertyMenu = this.Q<ToolbarMenu>("property-select-menu");
var targetObjectProperty = m_SerializedProperty.FindPropertyRelative("target.gameObject");
targetField.BindProperty(targetObjectProperty);
targetField.BindProperty(m_TargetGameObjectProperty);
if (evt.newValue == targetObjectProperty.objectReferenceValue)
return;
targetObjectProperty.objectReferenceValue = (GameObject)evt.newValue;
m_TargetGameObjectProperty.objectReferenceValue = (GameObject)evt.newValue;
m_SerializedProperty.serializedObject.ApplyModifiedProperties();
ToggleTargetContainer();
FillPropertySelectMenu();

void ToggleTargetContainer()
{
m_TargetContainer.style.display = parameter.hasTarget
? new StyleEnum<DisplayStyle>(DisplayStyle.Flex)
: new StyleEnum<DisplayStyle>(DisplayStyle.None);
m_TargetContainer.style.display = m_TargetGameObjectProperty.objectReferenceValue == null
? new StyleEnum<DisplayStyle>(DisplayStyle.None)
: new StyleEnum<DisplayStyle>(DisplayStyle.Flex);
}
void ClearTarget()

var nextSiblingProperty = m_SerializedProperty.Copy();
nextSiblingProperty.Next(false);
if (currentProperty.Next(true))
if (currentProperty.NextVisible(true))
if (currentProperty.name == "name")
continue;
if (currentProperty.type.Contains("managedReference") &&
currentProperty.managedReferenceFieldTypename == StaticData.samplerSerializedFieldType)
m_ExtraProperties.Add(new SamplerElement(currentProperty.Copy(), parameter));

4
com.unity.perception/Editor/Randomization/SamplerElement.cs


var nextSiblingProperty = m_Property.Copy();
nextSiblingProperty.Next(false);
if (currentProperty.Next(true))
if (currentProperty.NextVisible(true))
{
do
{

m_Properties.Add(propertyField);
}
}
while (currentProperty.Next(false));
while (currentProperty.NextVisible(false));
}
}

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


/// <returns>The probability value stored at the specified index</returns>
public float GetProbability(int index) => probabilities[index];
/// <summary>
/// Constructs a new categorical parameter
/// </summary>
protected CategoricalParameter() { }
/// <summary>

9
com.unity.perception/Runtime/Randomization/Parameters/Parameter.cs


[Serializable]
public abstract class Parameter
{
[SerializeField] internal bool collapsed;
[HideInInspector, SerializeField] internal bool collapsed;
public string name = "Parameter";
[HideInInspector] public string name = "Parameter";
[SerializeField] internal ParameterTarget target = new ParameterTarget();
[HideInInspector, SerializeField] internal ParameterTarget target = new ParameterTarget();
/// <summary>
/// Indicates whether this parameter has a target GameObject

/// </summary>
public abstract ISampler[] samplers { get; }
/// <summary>
/// Constructs a new parameter
/// </summary>
protected Parameter()
{
InitializeSamplers();

18
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/BooleanParameter.cs


[ParameterMetaData("Bool")]
public class BooleanParameter : NumericParameter<bool>
{
[SerializeReference] public ISampler value = new UniformSampler(0f, 1f);
/// <summary>
/// The sampler used as a source of random values for this parameter
/// </summary>
[HideInInspector, SerializeReference] public ISampler value = new UniformSampler(0f, 1f);
/// <summary>
/// Returns the sampler employed by this parameter
/// </summary>
/// <summary>
/// Generates a boolean sample
/// </summary>
/// <returns>The generated sample</returns>
/// <summary>
/// Schedules a job to generate an array of samples
/// </summary>
/// <param name="sampleCount">The number of samples to generate</param>
/// <param name="jobHandle">The handle of the scheduled job</param>
/// <returns>A NativeArray of samples</returns>
public override NativeArray<bool> Samples(int sampleCount, out JobHandle jobHandle)
{
var samples = new NativeArray<bool>(sampleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

13
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorHsvaParameter.cs


[SerializeReference] public ISampler value = new UniformSampler(0f, 1f);
[SerializeReference] public ISampler alpha = new ConstantSampler(1f);
/// <summary>
/// Returns the samplers employed by this parameter
/// </summary>
/// <summary>
/// Generates a color sample
/// </summary>
/// <returns>The generated sample</returns>
public override Color Sample()
{
var color = Color.HSVToRGB(hue.Sample(), saturation.Sample(), value.Sample());

/// <summary>
/// Schedules a job to generate an array of samples
/// </summary>
/// <param name="sampleCount">The number of samples to generate</param>
/// <param name="jobHandle">The handle of the scheduled job</param>
/// <returns>A NativeArray of samples</returns>
public override NativeArray<Color> Samples(int sampleCount, out JobHandle jobHandle)
{
var samples = new NativeArray<Color>(sampleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

13
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/FloatParameter.cs


{
[SerializeReference] public ISampler value = new UniformSampler(0f, 1f);
/// <summary>
/// Returns the sampler employed by this parameter
/// </summary>
/// <summary>
/// Generates a float sample
/// </summary>
/// <returns>The generated sample</returns>
/// <summary>
/// Schedules a job to generate an array of samples
/// </summary>
/// <param name="sampleCount">The number of samples to generate</param>
/// <param name="jobHandle">The handle of the scheduled job</param>
/// <returns>A NativeArray of samples</returns>
public override NativeArray<float> Samples(int sampleCount, out JobHandle jobHandle)
{
return value.Samples(sampleCount, out jobHandle);

3
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/GameObjectParameter.cs


namespace UnityEngine.Perception.Randomization.Parameters
{
/// <summary>
/// A categorical parameter for generating GameObject samples
/// </summary>
[Serializable]
[ParameterMetaData("GameObject")]
public class GameObjectParameter : CategoricalParameter<GameObject> { }

23
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/IntegerParameter.cs


[ParameterMetaData("Int")]
public class IntegerParameter : NumericParameter<int>
{
/// <summary>
/// The sampler used as a source of random values for this parameter
/// </summary>
/// <summary>
/// Returns the sampler employed by this parameter
/// </summary>
/// <summary>
/// Generates an integer sample
/// </summary>
/// <returns>The generated sample</returns>
public override NativeArray<int> Samples(int totalSamples, out JobHandle jobHandle)
/// <summary>
/// Schedules a job to generate an array of samples
/// </summary>
/// <param name="sampleCount">The number of samples to generate</param>
/// <param name="jobHandle">The handle of the scheduled job</param>
/// <returns>A NativeArray of samples</returns>
public override NativeArray<int> Samples(int sampleCount, out JobHandle jobHandle)
var samples = new NativeArray<int>(totalSamples, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
var rngSamples = value.Samples(totalSamples, out jobHandle);
var samples = new NativeArray<int>(sampleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
var rngSamples = value.Samples(sampleCount, out jobHandle);
jobHandle = new SamplesJob
{
rngSamples = rngSamples,

3
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/MaterialParameter.cs


namespace UnityEngine.Perception.Randomization.Parameters
{
/// <summary>
/// A categorical parameter for generating Material samples
/// </summary>
[Serializable]
[ParameterMetaData("Material")]
public class MaterialParameter : CategoricalParameter<Material> {}

3
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/StringParameter.cs


namespace UnityEngine.Perception.Randomization.Parameters
{
/// <summary>
/// A categorical parameter for generating string samples
/// </summary>
[Serializable]
[ParameterMetaData("String")]
public class StringParameter : CategoricalParameter<string> {}

21
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector2Parameter.cs


[SerializeReference] public ISampler x = new UniformSampler(0f, 1f);
[SerializeReference] public ISampler y = new UniformSampler(0f, 1f);
/// <summary>
/// Returns the samplers employed by this parameter
/// </summary>
/// <summary>
/// Generates a Vector2 sample
/// </summary>
/// <returns>The generated sample</returns>
public override NativeArray<Vector2> Samples(int totalSamples, out JobHandle jobHandle)
/// <summary>
/// Schedules a job to generate an array of samples
/// </summary>
/// <param name="sampleCount">The number of samples to generate</param>
/// <param name="jobHandle">The handle of the scheduled job</param>
/// <returns>A NativeArray of samples</returns>
public override NativeArray<Vector2> Samples(int sampleCount, out JobHandle jobHandle)
var samples = new NativeArray<Vector2>(totalSamples, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
var xRng = x.Samples(totalSamples, out var xHandle);
var yRng = y.Samples(totalSamples, out var yHandle);
var samples = new NativeArray<Vector2>(sampleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
var xRng = x.Samples(sampleCount, out var xHandle);
var yRng = y.Samples(sampleCount, out var yHandle);
var combinedJobHandles = JobHandle.CombineDependencies(xHandle, yHandle);
jobHandle = new SamplesJob
{

23
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector3Parameter.cs


[SerializeReference] public ISampler y = new UniformSampler(0f, 1f);
[SerializeReference] public ISampler z = new UniformSampler(0f, 1f);
/// <summary>
/// Returns the samplers employed by this parameter
/// </summary>
/// <summary>
/// Generates a Vector3 sample
/// </summary>
/// <returns>The generated sample</returns>
public override NativeArray<Vector3> Samples(int totalSamples, out JobHandle jobHandle)
/// <summary>
/// Schedules a job to generate an array of samples
/// </summary>
/// <param name="sampleCount">The number of samples to generate</param>
/// <param name="jobHandle">The handle of the scheduled job</param>
/// <returns>A NativeArray of samples</returns>
public override NativeArray<Vector3> Samples(int sampleCount, out JobHandle jobHandle)
var samples = new NativeArray<Vector3>(totalSamples, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
var xRng = x.Samples(totalSamples, out var xHandle);
var yRng = y.Samples(totalSamples, out var yHandle);
var zRng = z.Samples(totalSamples, out var zHandle);
var samples = new NativeArray<Vector3>(sampleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
var xRng = x.Samples(sampleCount, out var xHandle);
var yRng = y.Samples(sampleCount, out var yHandle);
var zRng = z.Samples(sampleCount, out var zHandle);
var combinedJobHandles = JobHandle.CombineDependencies(xHandle, yHandle, zHandle);
jobHandle = new SamplesJob
{

25
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector4Parameter.cs


[SerializeReference] public ISampler z = new UniformSampler(0f, 1f);
[SerializeReference] public ISampler w = new UniformSampler(0f, 1f);
/// <summary>
/// Returns the samplers employed by this parameter
/// </summary>
/// <summary>
/// Generates a Vector4 sample
/// </summary>
/// <returns>The generated sample</returns>
public override NativeArray<Vector4> Samples(int totalSamples, out JobHandle jobHandle)
/// <summary>
/// Schedules a job to generate an array of samples
/// </summary>
/// <param name="sampleCount">The number of samples to generate</param>
/// <param name="jobHandle">The handle of the scheduled job</param>
/// <returns>A NativeArray of samples</returns>
public override NativeArray<Vector4> Samples(int sampleCount, out JobHandle jobHandle)
var samples = new NativeArray<Vector4>(totalSamples, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
var xRng = x.Samples(totalSamples, out var xHandle);
var yRng = y.Samples(totalSamples, out var yHandle);
var zRng = z.Samples(totalSamples, out var zHandle);
var wRng = w.Samples(totalSamples, out var wHandle);
var samples = new NativeArray<Vector4>(sampleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
var xRng = x.Samples(sampleCount, out var xHandle);
var yRng = y.Samples(sampleCount, out var yHandle);
var zRng = z.Samples(sampleCount, out var zHandle);
var wRng = w.Samples(sampleCount, out var wHandle);
var handles = new NativeArray<JobHandle>(4, Allocator.Temp)
{

正在加载...
取消
保存