浏览代码

address comments

/develop/custom-raycast
Ruo-Ping Dong 4 年前
当前提交
b71a2c06
共有 1 个文件被更改,包括 12 次插入16 次删除
  1. 28
      com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs

28
com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs


public class RayPerceptionSensor : ISensor, IBuiltInSensor
{
float[] m_Observations;
float[] m_SingleRayObservations;
ObservationSpec m_ObservationSpec;
string m_Name;

return RayPerceptionInput.Angles.Count;
}
void SetNumObservations(int observationsSize, int numRays)
void SetNumObservations(int observationsSizePerRay, int numRays)
m_ObservationSpec = ObservationSpec.Vector(observationsSize * numRays);
m_Observations = new float[observationsSize * numRays];
m_SingleRayObservations = new float[observationsSize];
m_ObservationSpec = ObservationSpec.Vector(observationsSizePerRay * numRays);
m_Observations = new float[observationsSizePerRay * numRays];
}
internal void SetRayPerceptionInput(RayPerceptionInput rayInput)

var oldObservationSize = GetObservationSizePerRay();
var oldObservationSize = GetObservationSizePerRay() * GetNumberOfRays();
if (GetObservationSizePerRay() != oldObservationSize)
if (GetObservationSizePerRay() * GetNumberOfRays() != oldObservationSize)
{
Debug.Log(
"Changing the number of tags or rays at runtime is not " +

{
using (TimerStack.Instance.Scoped("RayPerceptionSensor.Perceive"))
{
Array.Clear(m_Observations, 0, m_Observations.Length);
var numRays = m_RayPerceptionInput.Angles.Count;
var bufferOffset = 0;
for (var rayIndex = 0; rayIndex < numRays; rayIndex++)
for (var rayIndex = 0; rayIndex < GetNumberOfRays(); rayIndex++)
Array.Clear(m_SingleRayObservations, 0, rayObservartionSize);
RayOutputToArray(m_RayPerceptionOutput.RayOutputs[rayIndex], rayIndex, m_SingleRayObservations);
Array.Copy(m_SingleRayObservations, 0, m_Observations, rayObservartionSize * rayIndex, rayObservartionSize);
}
Array.Clear(m_Observations, 0, rayObservartionSize);
RayOutputToArray(m_RayPerceptionOutput.RayOutputs[rayIndex], rayIndex, m_Observations);
// Finally, add the observations to the ObservationWriter
writer.AddList(m_Observations);
writer.AddList(m_Observations, bufferOffset);
bufferOffset += rayObservartionSize;
}
}
return m_Observations.Length;
}

正在加载...
取消
保存