public void SetComponentParameters( string[] detectableTags = null, float cellScaleX = 1f, float cellScaleZ = 1f, int gridSizeX = 10, int gridSizeY = 1, int gridSizeZ = 10, int colliderMaskInt = -1, SensorCompressionType compression = SensorCompressionType.None, bool rotateWithAgent = false, bool useOneHotTag = false, bool countColliders = false, bool useTestingGridSensor = false, bool useGridSensorBase = false ) { DetectableTags = detectableTags; CellScale = new Vector3(cellScaleX, 0.01f, cellScaleZ); GridSize = new Vector3Int(gridSizeX, gridSizeY, gridSizeZ); ColliderMask = colliderMaskInt < 0 ? LayerMask.GetMask("Default") : colliderMaskInt; RotateWithAgent = rotateWithAgent; CompressionType = compression; UseOneHotTag = useOneHotTag; CountColliders = countColliders; m_UseGridSensorBase = useGridSensorBase; m_UseTestingGridSensor = useTestingGridSensor; }
/// <summary> /// Create a GridSensorBase with the specified configuration. /// </summary> /// <param name="name">The sensor name</param> /// <param name="cellScale">The scale of each cell in the grid</param> /// <param name="gridSize">Number of cells on each side of the grid</param> /// <param name="detectableTags">Tags to be detected by the sensor</param> /// <param name="compression">Compression type</param> public GridSensorBase( string name, Vector3 cellScale, Vector3Int gridSize, string[] detectableTags, SensorCompressionType compression ) { m_Name = name; m_CellScale = cellScale; m_GridSize = gridSize; m_DetectableTags = detectableTags; CompressionType = compression; if (m_GridSize.y != 1) { throw new UnityAgentsException("GridSensor only supports 2D grids."); } m_NumCells = m_GridSize.x * m_GridSize.z; m_CellObservationSize = GetCellObservationSize(); m_ObservationSpec = ObservationSpec.Visual(m_GridSize.x, m_GridSize.z, m_CellObservationSize); m_PerceptionTexture = new Texture2D(m_GridSize.x, m_GridSize.z, TextureFormat.RGB24, false); ResetPerceptionBuffer(); }
public SimpleTestGridSensor( string name, Vector3 cellScale, Vector3Int gridNumSide, bool rotateWithAgent, int[] channelDepth, string[] detectableObjects, LayerMask observeMask, GridDepthType depthType, GameObject root, SensorCompressionType compression, int maxColliderBufferSize, int initialColliderBufferSize ) : base( name, cellScale, gridNumSide, rotateWithAgent, channelDepth, detectableObjects, observeMask, depthType, root, compression, maxColliderBufferSize, initialColliderBufferSize) { }
/// <summary> /// Initializes the sensor. /// </summary> /// <param name="grid">The <see cref="PixelGrid"/> instance to wrap.</param> /// <param name="compression">The compression to apply to the generated image.</param> /// <param name="name">Name of the sensor.</param> public GridSensor(PixelGrid grid, SensorCompressionType compression, string name) { m_SensorName = name; m_PixelGrid = grid; m_Compression = compression; Allocate(); }
/// <summary> /// Create a OneHotGridSensor with the specified configuration. /// </summary> /// <param name="name">The sensor name</param> /// <param name="cellScale">The scale of each cell in the grid</param> /// <param name="gridNum">Number of cells on each side of the grid</param> /// <param name="detectableTags">Tags to be detected by the sensor</param> /// <param name="compression">Compression type</param> public OneHotGridSensor( string name, Vector3 cellScale, Vector3Int gridNum, string[] detectableTags, SensorCompressionType compression ) : base(name, cellScale, gridNum, detectableTags, compression) { }
/// <summary> /// Create a CountingGridSensor with the specified configuration. /// </summary> /// <param name="name">The sensor name</param> /// <param name="cellScale">The scale of each cell in the grid</param> /// <param name="gridNum">Number of cells on each side of the grid</param> /// <param name="detectableTags">Tags to be detected by the sensor</param> /// <param name="compression">Compression type</param> public CountingGridSensor( string name, Vector3 cellScale, Vector3Int gridNum, string[] detectableTags, SensorCompressionType compression ) : base(name, cellScale, gridNum, detectableTags, compression) { CompressionType = SensorCompressionType.None; }
public CameraSensor(Camera camera, int width, int height, bool grayscale, string name, SensorCompressionType compression) { m_Camera = camera; m_Width = width; m_Height = height; m_Grayscale = grayscale; m_Name = name; m_Shape = new[] { height, width, grayscale ? 1 : 3 }; m_CompressionType = compression; }
/// <summary> /// Creates and returns the camera sensor. /// </summary> /// <param name="camera">Camera object to capture images from.</param> /// <param name="width">The width of the generated visual observation.</param> /// <param name="height">The height of the generated visual observation.</param> /// <param name="grayscale">Whether to convert the generated image to grayscale or keep color.</param> /// <param name="name">The name of the camera sensor.</param> /// <param name="compression">The compression to apply to the generated image.</param> public CameraSensor( Camera camera, int width, int height, bool grayscale, string name, SensorCompressionType compression) { m_Camera = camera; m_Width = width; m_Height = height; m_Grayscale = grayscale; m_Name = name; m_Shape = GenerateShape(width, height, grayscale); m_CompressionType = compression; }
public TestTextureSensor( Texture2D texture, string name, SensorCompressionType compressionType) { m_Texture = texture; var width = texture.width; var height = texture.height; m_Name = name; m_Shape = new[] { height, width, 3 }; m_CompressionType = compressionType; }
public TestTextureSensor( Texture2D texture, string name, SensorCompressionType compressionType) { m_Texture = texture; var width = texture.width; var height = texture.height; m_Name = name; m_ObservationSpec = ObservationSpec.Visual(height, width, 3); m_CompressionType = compressionType; }
/// <summary> /// Initializes the sensor. /// </summary> /// <param name="renderTexture">The <see cref="RenderTexture"/> instance to wrap.</param> /// <param name="grayscale">Whether to convert it to grayscale or not.</param> /// <param name="name">Name of the sensor.</param> /// <param name="compressionType">Compression method for the render texture.</param> public RenderTextureSensor( RenderTexture renderTexture, bool grayscale, string name, SensorCompressionType compressionType) { m_RenderTexture = renderTexture; var width = renderTexture != null ? renderTexture.width : 0; var height = renderTexture != null ? renderTexture.height : 0; m_Grayscale = grayscale; m_Name = name; m_Shape = new[] { height, width, grayscale ? 1 : 3 }; m_CompressionType = compressionType; }
/// <summary> /// Initializes the sensor. /// </summary> /// <param name="renderTexture">The [RenderTexture](https://docs.unity3d.com/ScriptReference/RenderTexture.html) /// instance to wrap.</param> /// <param name="grayscale">Whether to convert it to grayscale or not.</param> /// <param name="name">Name of the sensor.</param> /// <param name="compressionType">Compression method for the render texture.</param> /// [GameObject]: https://docs.unity3d.com/Manual/GameObjects.html public RenderTextureSensor( RenderTexture renderTexture, bool grayscale, string name, SensorCompressionType compressionType) { m_RenderTexture = renderTexture; var width = renderTexture != null ? renderTexture.width : 0; var height = renderTexture != null ? renderTexture.height : 0; m_Grayscale = grayscale; m_Name = name; m_ObservationSpec = ObservationSpec.Visual(height, width, grayscale ? 1 : 3); m_CompressionType = compressionType; }
/// <summary> /// Creates and returns the camera sensor. /// </summary> /// <param name="camera">Camera object to capture images from.</param> /// <param name="width">The width of the generated visual observation.</param> /// <param name="height">The height of the generated visual observation.</param> /// <param name="grayscale">Whether to convert the generated image to grayscale or keep color.</param> /// <param name="name">The name of the camera sensor.</param> /// <param name="compression">The compression to apply to the generated image.</param> /// <param name="observationType">The type of observation.</param> public CameraSensor( Camera camera, int width, int height, bool grayscale, string name, SensorCompressionType compression, ObservationType observationType = ObservationType.Default) { m_Camera = camera; m_Width = width; m_Height = height; m_Grayscale = grayscale; m_Name = name; var channels = grayscale ? 1 : 3; m_ObservationSpec = ObservationSpec.Visual(height, width, channels, observationType); m_CompressionType = compression; }
public SimpleTestGridSensor( string name, Vector3 cellScale, Vector3Int gridSize, string[] detectableTags, SensorCompressionType compression ) : base( name, cellScale, gridSize, detectableTags, compression) { }
public GridSensor( string name, Vector3 cellScale, Vector3Int gridNum, bool rotateWithAgent, int[] channelDepths, string[] detectableObjects, LayerMask colliderMask, GridDepthType depthType, GameObject rootReference, SensorCompressionType compression, int maxColliderBufferSize, int initialColliderBufferSize ) { m_Name = name; m_CellScale = cellScale; m_GridSize = gridNum; m_RotateWithAgent = rotateWithAgent; m_RootReference = rootReference; m_MaxColliderBufferSize = maxColliderBufferSize; m_InitialColliderBufferSize = initialColliderBufferSize; m_ColliderMask = colliderMask; m_GridDepthType = depthType; m_ChannelDepths = channelDepths; m_DetectableObjects = detectableObjects; m_CompressionType = compression; if (m_GridSize.y != 1) { throw new UnityAgentsException("GridSensor only supports 2D grids."); } if (m_GridDepthType == GridDepthType.Counting && m_DetectableObjects.Length != m_ChannelDepths.Length) { throw new UnityAgentsException("The channels of a CountingGridSensor is equal to the number of detectableObjects"); } InitGridParameters(); InitDepthType(); InitCellPoints(); ResetPerceptionBuffer(); m_ObservationSpec = ObservationSpec.Visual(m_GridSize.x, m_GridSize.z, m_CellObservationSize); m_PerceptionTexture = new Texture2D(m_GridSize.x, m_GridSize.z, TextureFormat.RGB24, false); m_ColliderBuffer = new Collider[Math.Min(m_MaxColliderBufferSize, m_InitialColliderBufferSize)]; }
/// <summary> /// Creates a <see cref="GridSensor"/> instance. /// </summary> /// <param name="buffer">The <see cref="GridBuffer"/> instance to wrap</param> /// <param name="compressionType">The <see cref="SensorCompressionType"/> /// to apply to the generated image</param> /// <param name="observationType">The <see cref="ObservationType"/> /// (default or goal signal) of the sensor</param> /// <param name="name">Name of the sensor</param> public GridSensor( string name, GridBuffer buffer, SensorCompressionType compressionType, ObservationType observationType) { m_Name = name; buffer.GetShape().Validate(); m_GridBuffer = buffer; m_CompressionType = compressionType; HandleCompressionType(); m_ObservationSpec = ObservationSpec.Visual( m_GridBuffer.Height, m_GridBuffer.Width, m_GridBuffer.NumChannels, observationType); }