/// <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(); }
/// <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; }