AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
AirControl.AC_Airplane_CameraController Class Reference

Camera switching and capture functionality More...

Inheritance diagram for AirControl.AC_Airplane_CameraController:
Collaboration diagram for AirControl.AC_Airplane_CameraController:

Classes

struct  CapturePass
 

Public Types

enum  ReplacementMode {
  ObjectId = 0, CatergoryId = 1, DepthCompressed = 2, DepthMultichannel = 3,
  Normals = 4
}
 

Public Member Functions

void CreateCamera ()
 Create hidden capture camera for each schene camera More...
 
void ScreenToBytes (Camera cam, Camera mainCamera, int width, int height, bool supportsAntialiasing, bool needsRescale, ref byte[] screencapture)
 Capture and return the screen as byte array More...
 
void selectCamera (int cameraId)
 select scene cameras More...
 
void OnSceneChange ()
 Deprecated Not used with API This fucntion was used to switch the screen manually More...
 
void OnCameraChange (Camera activeCamera)
 Refresh capture camera when active scene camera switch happens More...
 

Public Attributes

AC_BaseAirplane_Input input
 
List< CapturePassCapturePassList = new List<CapturePass>()
 
int startCameraIndex =1
 
Shader uberReplacementShader
 
Shader opticalFlowShader
 
float opticalFlowSensitivity = 1.0f
 
bool saveImage = true
 
bool saveIdSegmentation = true
 
bool saveLayerSegmentation = true
 
bool saveDepth = true
 
bool saveNormals = true
 
bool saveOpticalFlow =true
 
CapturePass[] capturePasses
 

Protected Member Functions

virtual void SwitchCamera ()
 Switch camera More...
 

Detailed Description

Camera switching and capture functionality

Definition at line 14 of file AC_Airplane_CameraController.cs.

Member Function Documentation

◆ CreateCamera()

void AirControl.AC_Airplane_CameraController.CreateCamera ( )
inline

Create hidden capture camera for each schene camera

Definition at line 99 of file AC_Airplane_CameraController.cs.

100  {
101  for (int q = 0; q < capturePasses.Length; q++)
102  {
103  capturePasses[q].camera = CreateHiddenCamera(capturePasses[q].name, cameras[currentCaprtureCamera].transform);
104  CapturePassList.Add(capturePasses[q]);
105  }
106 
107  }

◆ OnCameraChange()

void AirControl.AC_Airplane_CameraController.OnCameraChange ( Camera  activeCamera)
inline

Refresh capture camera when active scene camera switch happens

Parameters
activeCameraActive scene camera

Definition at line 416 of file AC_Airplane_CameraController.cs.

417  {
418  int targetDisplay = 1;
419  foreach (var pass in capturePasses)
420  {
421  if (pass.camera == activeCamera)
422  continue;
423 
424  // cleanup capturing camera
425  pass.camera.RemoveAllCommandBuffers();
426 
427  // copy all "main" camera parameters into capturing camera
428  pass.camera.CopyFrom(activeCamera);
429 
430  // set targetDisplay here since it gets overriden by CopyFrom()
431  pass.camera.targetDisplay = targetDisplay++;
432  }
433 
434  // cache materials and setup material properties
435  if (!opticalFlowMaterial || opticalFlowMaterial.shader != opticalFlowShader)
436  opticalFlowMaterial = new Material(opticalFlowShader);
437  opticalFlowMaterial.SetFloat("_Sensitivity", opticalFlowSensitivity);
438 
439  // setup command buffers and replacement shaders
440  SetupCameraWithReplacementShader(capturePasses[1].camera, uberReplacementShader, ReplacementMode.ObjectId, Color.black);
441  SetupCameraWithReplacementShader(capturePasses[2].camera, uberReplacementShader, ReplacementMode.CatergoryId, Color.black);
442  SetupCameraWithReplacementShader(capturePasses[3].camera, uberReplacementShader, ReplacementMode.DepthCompressed, Color.white);
443  SetupCameraWithReplacementShader(capturePasses[4].camera, uberReplacementShader, ReplacementMode.Normals, Color.black);
444  SetupCameraWithPostShader(capturePasses[5].camera, opticalFlowMaterial, DepthTextureMode.Depth | DepthTextureMode.MotionVectors);
445  }

◆ OnSceneChange()

void AirControl.AC_Airplane_CameraController.OnSceneChange ( )
inline

Deprecated Not used with API This fucntion was used to switch the screen manually

Definition at line 397 of file AC_Airplane_CameraController.cs.

398  {
399  var renderers = Object.FindObjectsOfType<Renderer>();
400  var mpb = new MaterialPropertyBlock();
401  foreach (var r in renderers)
402  {
403  var id = r.gameObject.GetInstanceID();
404  var layer = r.gameObject.layer;
405  var tag = r.gameObject.tag;
406 
407  mpb.SetColor("_ObjectColor", ColorEncoding.EncodeIDAsColor(id));
408  mpb.SetColor("_CategoryColor", ColorEncoding.EncodeLayerAsColor(layer));
409  r.SetPropertyBlock(mpb);
410  }
411  }

◆ ScreenToBytes()

void AirControl.AC_Airplane_CameraController.ScreenToBytes ( Camera  cam,
Camera  mainCamera,
int  width,
int  height,
bool  supportsAntialiasing,
bool  needsRescale,
ref byte[]  screencapture 
)
inline

Capture and return the screen as byte array

Parameters
camHidden capture camera
mainCameraAny of scene camera
widthWidth of the capture
heightheight of the capture
supportsAntialiasingAntialiasing Property
needsRescaleRescale property
screencapturereference screencapture

Definition at line 226 of file AC_Airplane_CameraController.cs.

227  {
228  if (width <= 0 || height <= 0)
229  {
230  width = Screen.width;
231  height = Screen.height;
232  }
233 
234  var depth = 8;
235  var format = RenderTextureFormat.Default;
236  var readWrite = RenderTextureReadWrite.Default;
237  var antiAliasing = (supportsAntialiasing) ? Mathf.Max(1, QualitySettings.antiAliasing) : 1;
238 
239  var finalRT =
240  RenderTexture.GetTemporary(width, height, depth, format, readWrite, antiAliasing);
241  var renderRT = (!needsRescale) ? finalRT :
242  RenderTexture.GetTemporary(mainCamera.pixelWidth, mainCamera.pixelHeight, depth, format, readWrite, antiAliasing);
243  var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
244 
245  var prevActiveRT = RenderTexture.active;
246  var prevCameraRT = cam.targetTexture;
247 
248  // render to offscreen texture (readonly from CPU side)
249  RenderTexture.active = renderRT;
250  cam.targetTexture = renderRT;
251 
252  cam.Render();
253 
254  if (needsRescale)
255  {
256  // blit to rescale (see issue with Motion Vectors in @KNOWN ISSUES)
257  RenderTexture.active = finalRT;
258  Graphics.Blit(renderRT, finalRT);
259  RenderTexture.ReleaseTemporary(renderRT);
260  }
261 
262  // read offsreen texture contents into the CPU readable texture
263  tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
264  tex.Apply();
265 
266  // encode texture into PNG
267  screencapture = tex.EncodeToPNG();
268 
269  }

◆ selectCamera()

void AirControl.AC_Airplane_CameraController.selectCamera ( int  cameraId)
inline

select scene cameras

Parameters
cameraId

Definition at line 348 of file AC_Airplane_CameraController.cs.

349  {
350  DisableAllCameras();
351 
352  if (cameraId <= cameras.Count){
353  cameras[cameraId].enabled = true;
354  cameras[cameraId].GetComponent<AudioListener>().enabled = true;
355  curentCameraIndex = cameraId;
356  }
357  }

◆ SwitchCamera()

virtual void AirControl.AC_Airplane_CameraController.SwitchCamera ( )
inlineprotectedvirtual

Switch camera

Definition at line 331 of file AC_Airplane_CameraController.cs.

332  {
333  // chnage the camera index as we chaneg the camera
334  DisableAllCameras();
335  curentCameraIndex++;
336  //circular index
337  if (curentCameraIndex >= cameras.Count){
338  curentCameraIndex = 0;
339  }
340  cameras[curentCameraIndex].enabled = true;
341  cameras[curentCameraIndex].GetComponent<AudioListener>().enabled = true;
342  }

Member Data Documentation

◆ capturePasses

CapturePass [] AirControl.AC_Airplane_CameraController.capturePasses
Initial value:
= new CapturePass[] {
new CapturePass() { name = "_img" },
new CapturePass() { name = "_id", supportsAntialiasing = false },
new CapturePass() { name = "_layer", supportsAntialiasing = false },
new CapturePass() { name = "_depth" },
new CapturePass() { name = "_normals" },
new CapturePass() { name = "_flow", supportsAntialiasing = false, needsRescale = true }
}

Definition at line 39 of file AC_Airplane_CameraController.cs.


The documentation for this class was generated from the following file:
XCharts.SerieSymbolType.Rect
@ Rect
正方形。可通过设置itemStyle的cornerRadius变成圆角矩形。