2 using System.Collections.Generic;
10 namespace droid.Runtime.Prototyping.Sensors.Camera {
11 [AddComponentMenu(SensorComponentMenuPath._ComponentMenuPath
13 + SensorComponentMenuPath._Postfix)]
16 [Header(
"Specific", order = 102)]
25 [SerializeField] Texture2D _texture = null;
27 const TextureCreationFlags _flags = TextureCreationFlags.None;
33 if (this._manager == null) {
34 this._manager = FindObjectOfType<AbstractNeodroidManager>();
37 if (this._camera == null) {
38 this._camera = this.GetComponent<
UnityEngine.Camera>();
41 var target_texture = this._camera.targetTexture;
42 if (!target_texture) {
44 Debug.LogWarning(
"Texture not available!");
46 this._texture =
new Texture2D(NeodroidConstants._Default_Width,
47 NeodroidConstants._Default_Height,
48 NeodroidConstants._Default_TextureFormat,
53 this._texture =
new Texture2D(target_texture.width,
54 target_texture.height,
55 target_texture.graphicsFormat,
73 if (this._camera.targetTexture) {
78 Graphics.DrawTexture(
new Rect(
new Vector2(0, 0),
new Vector2(0, 0)), this._texture);
94 var current_render_texture = RenderTexture.active;
95 var texture = this._camera.targetTexture;
97 RenderTexture.active = texture;
99 this._texture.ReadPixels(
new Rect(0, 0, this._texture.width,
this._texture.height),
102 recalculateMipMaps :
false);
106 this.Bytes = this._texture.GetRawTextureData();
109 RenderTexture.active = current_render_texture;
111 Debug.LogWarning($
"No camera found on {this}");
115 public override String PrototypingTypeName {
get {
return ""; } }
117 public override IEnumerable<float> FloatEnumerable {
125 Debug.Log($
"{this._manager?.SimulatorConfiguration?.SimulationType}");
127 if (Application.isPlaying) {
128 this._camera.Render();
140 var rep = $
"Byte Array (Length: {this.Bytes.Length}), " 141 + $
"Sample [{this.Bytes[0]}.." 142 + $
"{this.Bytes[this.Bytes.Length - 1]}]";
150 public Byte[] Bytes {
get;
private set; }
155 public Int32[] Shape {
158 switch (this._texture.graphicsFormat) {
159 case GraphicsFormat.R8_UNorm:
160 case GraphicsFormat.R16_SFloat:
161 case GraphicsFormat.R32_SFloat:
172 return new[] {this._texture.width, this._texture.height, channels};
179 public String ArrayEncoding {
182 switch (this._texture.graphicsFormat) {
183 case GraphicsFormat.R8G8B8A8_UNorm:
184 case GraphicsFormat.R8_UInt:
187 case GraphicsFormat.R16_SFloat:
188 case GraphicsFormat.R16G16B16A16_SFloat:
191 case GraphicsFormat.R32_SFloat:
192 case GraphicsFormat.R32G32B32A32_SFloat:
override string ToString()
override void UpdateObservation()
virtual void UpdateArray()
virtual void OnPostRender()
SimulationType
Determines the discrete timesteps of the simulation environment.