浏览代码

not training well. not sure why

/hh-develop-gridsensor-tests/static
HH 4 年前
当前提交
583dd767
共有 4 个文件被更改,包括 149 次插入147 次删除
  1. 128
      Project/Assets/ML-Agents/Examples/PushBlock/Prefabs/PushBlockHard.prefab
  2. 132
      Project/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockGridSensorTests.unity
  3. 4
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentGrid.cs
  4. 32
      com.unity.ml-agents.extensions/Runtime/Sensors/GridSensor.cs

128
Project/Assets/ML-Agents/Examples/PushBlock/Prefabs/PushBlockHard.prefab


- component: {fileID: 89552374}
- component: {fileID: 89552373}
- component: {fileID: 89552372}
- component: {fileID: 89552371}
- component: {fileID: 3071652823701304804}
m_Layer: 0
m_Name: AgentCOMBO
m_TagString: agent

rayMissColor: {r: 1, g: 1, b: 1, a: 1}
m_StartVerticalOffset: 0
m_EndVerticalOffset: 0
--- !u!114 &89552371
--- !u!114 &3071652823701304804
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}

m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!1 &1215672705
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1215672706}
- component: {fileID: 1215672710}
- component: {fileID: 1215672709}
- component: {fileID: 1215672708}
- component: {fileID: 1215672707}
m_Layer: 0
m_Name: Cube
m_TagString: stone
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!4 &1215672706
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1215672705}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 2, y: 0.52, z: 6.18}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 5956721712675605120}
m_RootOrder: 15
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &1215672710
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1215672705}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!65 &1215672709
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1215672705}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1215672708
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1215672705}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: eaad04b0e0dec42229c9cb00a981d7ac, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!54 &1215672707
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1215672705}
serializedVersion: 2
m_Mass: 10
m_Drag: 0.5
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &1420080868
GameObject:
m_ObjectHideFlags: 0

GridNumSideZ: 20
CellScaleY: 1.1
RotateToAgent: 1
TranslateToAgent: 0
collidersToIgnore:
- {fileID: 89552376}
ChannelDepth: 06000000
DetectableObjects:
- agent

serializedVersion: 2
m_Bits: 257
gridDepthType: 1
rootReference: {fileID: 89552369}
rootReference: {fileID: 1514411054}
- {r: 0.5283019, g: 0.5283019, b: 0.5283019, a: 1}
- {r: 1, g: 1, b: 1, a: 1}
DebugDefaultColor: {r: 1, g: 1, b: 1, a: 0.09803922}
--- !u!1 &1907827094
GameObject:
m_ObjectHideFlags: 0

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2365449668380784399}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 2, y: 0.52, z: -1.43}
m_LocalScale: {x: 2, y: 1, z: 2}
m_LocalPosition: {x: 1.81, y: 0.52, z: -1.43}
m_LocalScale: {x: 1.5, y: 1, z: 1.5}
m_Children: []
m_Father: {fileID: 5956721712675605120}
m_RootOrder: 14

GridNumSideZ: 80
CellScaleY: 1.1
RotateToAgent: 1
TranslateToAgent: 0
collidersToIgnore: []
ChannelDepth: 06000000
DetectableObjects:
- agent

- {r: 1, g: 0.07976162, b: 0, a: 1}
GizmoYOffset: 0
ShowGizmos: 0
DebugDefaultColor: {r: 1, g: 1, b: 1, a: 0.55}
--- !u!1 &5954386630694887120
GameObject:
m_ObjectHideFlags: 0

- {fileID: 142039848}
- {fileID: 89552370}
- {fileID: 2741929382500039756}
- {fileID: 1215672706}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

132
Project/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockGridSensorTests.unity


objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 9f61863318eba452baefa644fe4ddf1e, type: 3}
--- !u!1 &1215672705
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1215672706}
- component: {fileID: 1215672710}
- component: {fileID: 1215672709}
- component: {fileID: 1215672708}
- component: {fileID: 1215672707}
m_Layer: 0
m_Name: Cube
m_TagString: stone
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1215672706
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1215672705}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 2, y: 0.52, z: 6.18}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1804219581}
m_RootOrder: 15
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!54 &1215672707
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1215672705}
serializedVersion: 2
m_Mass: 10
m_Drag: 0.5
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!23 &1215672708
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1215672705}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: eaad04b0e0dec42229c9cb00a981d7ac, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!65 &1215672709
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1215672705}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &1215672710
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1215672705}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &1257687048
GameObject:
m_ObjectHideFlags: 0

objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 9f61863318eba452baefa644fe4ddf1e, type: 3}
--- !u!4 &1804219581 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 5956721712675605120, guid: 9f61863318eba452baefa644fe4ddf1e,
type: 3}
m_PrefabInstance: {fileID: 5955089666562024894}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &1900462655
PrefabInstance:
m_ObjectHideFlags: 0

m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5955089667059465107, guid: 9f61863318eba452baefa644fe4ddf1e,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5955089667383748315, guid: 9f61863318eba452baefa644fe4ddf1e,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5955089668141999361, guid: 9f61863318eba452baefa644fe4ddf1e,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5955804999460259248, guid: 9f61863318eba452baefa644fe4ddf1e,
type: 3}
propertyPath: m_Name

propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 89552371, guid: 9f61863318eba452baefa644fe4ddf1e, type: 3}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 9f61863318eba452baefa644fe4ddf1e, type: 3}

4
Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentGrid.cs


var localVelocity = transform.InverseTransformDirection(m_AgentRb.velocity);
sensor.AddObservation(localVelocity.x);
sensor.AddObservation(localVelocity.z);
// sensor.AddObservation(transform.localRotation);
// sensor.AddObservation(transform.localPosition);
}
}

public void SetBlockProperties()
{
var scale = m_ResetParams.GetWithDefault("block_scale", 2);
var scale = m_ResetParams.GetWithDefault("block_scale", 1.5f);
//Set the scale of the block
m_BlockRb.transform.localScale = new Vector3(scale, 0.75f, scale);

32
com.unity.ml-agents.extensions/Runtime/Sensors/GridSensor.cs


[Tooltip("Rotate the grid based on the direction the agent is facing")]
public bool RotateToAgent;
public bool TranslateToAgent; //should the grid move with the agent
// public bool MapThisAgent = false; //should this agent be mapped
public List<Collider> collidersToIgnore;
/// <summary>
/// Array holding the depth of each channel.
/// </summary>

/// </summary>
private List<byte[]> byteSizesBytesList;
private Color DebugDefaultColor = new Color(1f, 1f, 1f, 0.55f);
public Color DebugDefaultColor = new Color(1f, 1f, 1f, 0.55f);
/// <inheritdoc/>
public override ISensor CreateSensor()

{
if (RotateToAgent)
{
cellCenter = transform.TransformPoint(CellPoints[cellIndex]);
foundColliders = Physics.OverlapBox(cellCenter, halfCellScale, transform.rotation, ObserveMask);
// cellCenter = transform.TransformPoint(CellPoints[cellIndex]);
cellCenter = rootReference.transform.TransformPoint(CellPoints[cellIndex]);
// foundColliders = Physics.OverlapBox(cellCenter, halfCellScale, transform.rotation, ObserveMask);
foundColliders = Physics.OverlapBox(cellCenter, halfCellScale, rootReference.transform.rotation, ObserveMask);
cellCenter = transform.position + CellPoints[cellIndex];
cellCenter = rootReference.transform.position + CellPoints[cellIndex];
// cellCenter = transform.position + CellPoints[cellIndex];
foundColliders = Physics.OverlapBox(cellCenter, halfCellScale, Quaternion.identity, ObserveMask);
}

currentColliderGo = foundColliders[i].gameObject;
// Continue if the current collider go is the root reference
if (currentColliderGo == rootReference)
if (collidersToIgnore.Contains(foundColliders[i]))
// if (currentColliderGo == rootReference && !MapThisAgent)
// if (!MapThisAgent)
continue;
closestColliderPoint = foundColliders[i].ClosestPointOnBounds(cellCenter);

float z = (cell / GridNumSideZ - OffsetGridNumSide) * CellScaleZ - DiffNumSideZX;
if (shouldTransformPoint)
return transform.TransformPoint(new Vector3(x, 0, z));
// return transform.TransformPoint(new Vector3(x, 0, z));
return rootReference.transform.TransformPoint(new Vector3(x, 0, z));
return new Vector3(x, 0, z);
}

/// <param name="globalPoint">The 3D point in global space</param>
public int PointToCell(Vector3 globalPoint)
{
Vector3 point = transform.InverseTransformPoint(globalPoint);
// Vector3 point = transform.InverseTransformPoint(globalPoint);
Vector3 point = rootReference.transform.InverseTransformPoint(globalPoint);
if (point.x < -HalfOfGridX || point.x > HalfOfGridX || point.z < -HalfOfGridZ || point.z > HalfOfGridZ)
return -1;

Vector3 offset = new Vector3(0, GizmoYOffset, 0);
Matrix4x4 oldGizmoMatrix = Gizmos.matrix;
Matrix4x4 cubeTransform = Gizmos.matrix;
// Matrix4x4 cubeTransform = rootReference.transform.localToWorldMatrix;
cubeTransform = Matrix4x4.TRS(CellToPoint(i) + offset, transform.rotation, scale);
// cubeTransform = Matrix4x4.TRS(CellToPoint(i) + offset, transform.rotation, scale);
cubeTransform = Matrix4x4.TRS(CellToPoint(i) + offset, rootReference.transform.rotation, scale);
cubeTransform = Matrix4x4.TRS(CellToPoint(i, false) + transform.position + offset, Quaternion.identity, scale);
// cubeTransform = Matrix4x4.TRS(CellToPoint(i, false) + transform.position + offset, Quaternion.identity, scale);
cubeTransform = Matrix4x4.TRS(CellToPoint(i, false) + rootReference.transform.position + offset, Quaternion.identity, scale);
// cubeTransform = Matrix4x4.TRS(CellToPoint(i, false) + offset, Quaternion.identity, scale);
}
Gizmos.matrix = oldGizmoMatrix * cubeTransform;

正在加载...
取消
保存