浏览代码

[MLA-16] add filter mask to ray perception (#3111)

* add filter mask to ray perception

* use LayerMask type
/asymm-envs
GitHub 5 年前
当前提交
7ed81dbe
共有 4 个文件被更改,包括 26 次插入8 次删除
  1. 6
      UnitySDK/Assets/ML-Agents/Editor/Tests/RayPerceptionTests.cs
  2. 20
      UnitySDK/Assets/ML-Agents/Scripts/Sensor/RayPerceptionSensor.cs
  3. 6
      UnitySDK/Assets/ML-Agents/Scripts/Sensor/RayPerceptionSensorComponentBase.cs
  4. 2
      UnitySDK/ProjectSettings/ProjectVersion.txt

6
UnitySDK/Assets/ML-Agents/Editor/Tests/RayPerceptionTests.cs


tags);
Assert.IsTrue(result.Count == angles.Length * (tags.Length + 2));
}
[Test]
public void TestConstants()
{
Assert.AreEqual(Physics.DefaultRaycastLayers, Physics2D.DefaultRaycastLayers);
}
}
}

20
UnitySDK/Assets/ML-Agents/Scripts/Sensor/RayPerceptionSensor.cs


float m_CastRadius;
CastType m_CastType;
Transform m_Transform;
int m_LayerMask;
/// <summary>
/// Debug information for the raycast hits. This is used by the RayPerceptionSensorComponent.

}
public RayPerceptionSensor(string name, float rayDistance, List<string> detectableObjects, float[] angles,
Transform transform, float startOffset, float endOffset, float castRadius, CastType castType)
Transform transform, float startOffset, float endOffset, float castRadius, CastType castType,
int rayLayerMask)
{
var numObservations = (detectableObjects.Count + 2) * angles.Length;
m_Shape = new[] { numObservations };

m_EndOffset = endOffset;
m_CastRadius = castRadius;
m_CastType = castType;
m_LayerMask = rayLayerMask;
if (Application.isEditor)
{

{
PerceiveStatic(
m_RayDistance, m_Angles, m_DetectableObjects, m_StartOffset, m_EndOffset,
m_CastRadius, m_Transform, m_CastType, m_Observations, false, m_DebugDisplayInfo
m_CastRadius, m_Transform, m_CastType, m_Observations, false, m_LayerMask,
m_DebugDisplayInfo
);
adapter.AddRange(m_Observations);
}

float startOffset, float endOffset, float castRadius,
Transform transform, CastType castType, float[] perceptionBuffer,
bool legacyHitFractionBehavior = false,
int layerMask = Physics.DefaultRaycastLayers,
DebugDisplayInfo debugInfo = null)
{
Array.Clear(perceptionBuffer, 0, perceptionBuffer.Length);

RaycastHit rayHit;
if (castRadius > 0f)
{
castHit = Physics.SphereCast(startPositionWorld, castRadius, rayDirection, out rayHit, rayLength);
castHit = Physics.SphereCast(startPositionWorld, castRadius, rayDirection, out rayHit,
rayLength, layerMask);
castHit = Physics.Raycast(startPositionWorld, rayDirection, out rayHit, rayLength);
castHit = Physics.Raycast(startPositionWorld, rayDirection, out rayHit,
rayLength, layerMask);
}
hitFraction = castHit ? rayHit.distance / rayLength : 1.0f;

RaycastHit2D rayHit;
if (castRadius > 0f)
{
rayHit = Physics2D.CircleCast(startPositionWorld, castRadius, rayDirection, rayLength);
rayHit = Physics2D.CircleCast(startPositionWorld, castRadius, rayDirection,
rayLength, layerMask);
rayHit = Physics2D.Raycast(startPositionWorld, rayDirection, rayLength);
rayHit = Physics2D.Raycast(startPositionWorld, rayDirection, rayLength, layerMask);
}
castHit = rayHit;

6
UnitySDK/Assets/ML-Agents/Scripts/Sensor/RayPerceptionSensorComponentBase.cs


[Tooltip("Length of the rays to cast.")]
public float rayLength = 20f;
[Tooltip("Controls which layers the rays can hit.")]
public LayerMask rayLayerMask = Physics.DefaultRaycastLayers;
[Range(1, 50)]
[Tooltip("Whether to stack previous observations. Using 1 means no previous observations.")]
public int observationStacks = 1;

{
var rayAngles = GetRayAngles(raysPerDirection, maxRayDegrees);
m_RaySensor = new RayPerceptionSensor(sensorName, rayLength, detectableTags, rayAngles,
transform, GetStartVerticalOffset(), GetEndVerticalOffset(), sphereCastRadius, GetCastType()
transform, GetStartVerticalOffset(), GetEndVerticalOffset(), sphereCastRadius, GetCastType(),
rayLayerMask
);
if (observationStacks != 1)

2
UnitySDK/ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2017.4.32f1
m_EditorVersion: 2017.4.33f1
正在加载...
取消
保存