2 using System.Collections.Generic;
10 namespace droid.Runtime.Prototyping.Sensors.Camera.Deprecated {
38 [AddComponentMenu(SensorComponentMenuPath._ComponentMenuPath +
"Camera" + SensorComponentMenuPath._Postfix)]
40 [DisallowMultipleComponent]
46 [Header(
"Specific", order = 102)]
52 protected bool _Grab =
true;
69 public override String PrototypingTypeName {
get {
return ""; } }
73 Texture2D _texture = null;
75 [SerializeField]
bool disable_encoding =
false;
80 [field : Header(
"Observation", order = 103)]
81 public byte[] Bytes {
get;
private set; } = { };
83 public GraphicsFormat DataType {
85 return GraphicsFormat.None;
96 return new[] {this._texture.width, this._texture.height, channels};
100 public string ArrayEncoding {
102 switch (this.imageFormat) {
113 default:
throw new ArgumentOutOfRangeException();
122 if (this._Manager == null) {
123 this._Manager = FindObjectOfType<AbstractNeodroidManager>();
126 if (this._Camera == null) {
127 this._Camera = this.GetComponent<
UnityEngine.Camera>();
131 var target_texture = this._Camera.targetTexture;
132 if (!target_texture) {
133 Debug.LogWarning($
"No targetTexture defaulting to a texture of size ({NeodroidConstants._Default_Width}, {NeodroidConstants._Default_Height})");
135 this._texture =
new Texture2D(NeodroidConstants._Default_Width, NeodroidConstants._Default_Height);
137 var texture_format_str = target_texture.format.ToString();
138 if (Enum.TryParse(texture_format_str, out TextureFormat texture_format)) {
139 this._texture =
new Texture2D(target_texture.width,
140 target_texture.height,
142 target_texture.useMipMap,
143 !target_texture.sRGB);
146 Debug.LogWarning($
"Texture format {texture_format_str} is not a valid TextureFormat for Texture2D for observer {this.Identifier}");
152 if (this._Manager?.SimulatorConfiguration != null) {
154 && Application.isEditor) {
176 var current_render_texture = RenderTexture.active;
177 RenderTexture.active = this._Camera.targetTexture;
180 this._texture.ReadPixels(
new Rect(0, 0, this._texture.width,
this._texture.height), 0, 0);
181 this._texture.Apply();
184 Debug.LogWarning(
"Texture not available!");
186 var target_texture = this._Camera.targetTexture;
187 this._texture =
new Texture2D(target_texture.width,
188 target_texture.height,
189 NeodroidConstants._Default_TextureFormat,
193 if (!this.disable_encoding) {
194 switch (this.imageFormat) {
196 this.Bytes = this._texture.EncodeToJPG(this.jpegQuality);
199 this.Bytes = this._texture.EncodeToPNG();
202 this.Bytes = this._texture.EncodeToEXR();
205 this.Bytes = this._texture.EncodeToTGA();
208 this.Bytes = this._texture.GetRawTextureData();
226 default:
throw new ArgumentOutOfRangeException();
230 RenderTexture.active = current_render_texture;
232 Debug.LogWarning($
"No camera found on {this}");
239 public override IEnumerable<float> FloatEnumerable {
get {
return null; } }
247 if (Application.isPlaying) {
248 this._Camera.Render();
259 public override string ToString() {
return $
"Rendered {this.imageFormat} image"; }
ISimulatorConfiguration SimulatorConfiguration
virtual void OnPostRender()
override void UpdateObservation()
UnityEngine.Camera _Camera
override string ToString()
SimulationType SimulationType
SimulationType
Determines the discrete timesteps of the simulation environment.