MASCamera - MOARdV/AvionicsSystems GitHub Wiki

The MASCamera module represents a camera installed on a part. The camera may be accessed in a CAMERA node of a MASMonitor page. The MASCamera is similar to the JSIExternalCameraSelector, but there are important differences to be aware of:

  • Camera parameters (zoom limits, pan and tilt limits) are part of MASCamera. In RPM, they were part of the page definition, allowing different pages to use different values for the same camera. Putting the limits in the part config better duplicates a physical camera, and it allows the part maker to specify limits based on what the part is emulating.
  • Likewise, post-processing shaders belong to the MASCamera module, not the monitor. This allows cameras to be designed for specific applications. Cameras may have more than one post-processing configuration, such as a simple color mode and a highly-gained green monochrome (to represent a night vision setting), or a camera may be designed as a monochrome, low-resolution, noisy camera to represent early television.
  • Camera names are user-configurable in the VAB/SPH (or in flight) using a text input box. RPM used a named prefix (traditionally, "ExtCam"), and it allowed the user to increment or decrement a number that was added to the prefix. Default names for a camera may be set in the config file, but a user is always allowed to edit it.
  • Multiple cameras may be specified on the same part, and each camera may have unique settings.
  • A part may have transforms specified for pan and tilt within a MASCameraMount part module, allowing the part to move in response to camera steering.

When MAS loads during flight, if it finds duplicate names, it will automatically number those cameras. For example, if several cameras were named "ExtCam" in the VAB, MAS will name them "ExtCam 1", "ExtCam 2", etc. Which cameras receive which number is arbitrary, and it cannot be specified. If cameras are unnamed, MAS will name them either "Camera #" or "Dock #", depending on whether the camera is on a regular part or on a docking port.

Cameras are attached to transforms. The camera lens points along the Z+ axis (the blue axis in Unity), with the right side of the camera field of view aligned with the X+ axis (red axis in Unity). The camera moves with the transform, so if the transform is animated (such as with the MASDeployableCamera, below), the camera will move with the transform.

The MASCamera is configured with the following values. All user-configurable values and their defaults are included.

MODULE
{
   name = MASCamera

   fovRange = 50, 50
   fovRate = 0

   panRange = 0, 0
   panRate = 0

   tiltRange = 0, 0
   tiltRate = 0

   cameraTransformName = ""

   refreshRate = 1

   translation = 0, 0, 0
   rotation = 0, 0, 0

   cameraName = ""

   MODE
   {
      (see below)
   }
   MODE
   {
      ...
   }
}
  • fovRange - Defines the minimum and maximum field of view for the camera, in degrees.
  • fovRate - The maximum number of degrees per second that the field of view can change. If 0, field of view changes are instantaneous.
  • panRange - Defines the maximum left and right rotation of the camera, in degrees.
  • panRate - The maximum number of degrees per second that the camera can pan. If 0, pan changes are instantaneous.
  • tiltRange - Defines the maximum up and down rotation of the camera, in degrees.
  • tiltRate - The maximum number of degrees per second that the camera can tilt. If 0, tilt changes are instantaneous.
  • cameraTransformName - Required. Specifies the transform in the prop where the camera is attached. The following two fields allow the camera to be moved and rotated from that location.
  • refreshRate - Optional. Defaults to 1. Controls how frequently the camera's render texture is updated. Camera render textures are updated with every Unity update, typically 60 frames a second. A refreshRate of 1 means the camera's view updates every Update, while a 2 means every other update, a 3 means every 3rd update, etc.
  • translation - Specifies the offset from cameraTransformName where the camera should be created.
  • rotation - Specifies the rotation (in degrees) that the camera should be rotated from cameraTransformName's forward (blue) axis.
  • cameraName - A user-configurable field naming the camera. An initial default name may be provided in the config.

Note that additional fields are used by the MASCamera to keep track of changes during flight, but these fields should not be added to the MASCamera config under normal circumstances.

If tiltRange and panRange are both set to 0, 0 (or omitted from the config), but the part also has a MASCameraMount (see below), then when MAS tells the camera to pan or tilt, the MASCameraMount will pan or tilt instead. If either panRange or tiltRange is not zero, then pan and tilt affects only the current camera, not the camera mount.

Camera Modes

Each MASCamera may include one or more MODE configuration nodes. These nodes allow configuring a camera with different post-processing shaders, resolutions, etc. If no MODEs are included, the camera is configured with no post-processing effects, a mode name of "Default", and a 256 x 256 pixel resolution.

If more than one MODE is included, the first one is the default. MODE selection persists, and it applies to all monitors that display that camera.

MODE
{
  name = anonymous
  cameraResolution = 256
  shader = ""
  properties = ""
  texture = ""
}
  • name: Optional, but highly recommended. Defaults to "anonymous". This is the name of the camera mode. This name may be displayed using fc.GetCameraModeName() (see).
  • cameraResolution: Optional. Defaults to 256. Controls the resolution of the camera, in pixels. The resolution is always adjusted to the largest power-of-two that is less than or equal to the provided resolution (for instance, a setting of 320 will automatically be adjusted to 256). Values larger than 2048 are clamped to 2048, and values smaller than 64 are clamped to 64.
  • shader: Optional. If present, and set to one of the included Shaders, this camera mode will apply a post-processing shader effect to the image before showing it. If the 'shader' is not included, the camera mode will display a color image with no effects applied.
  • properties: Optional. Ignored if 'shader' is absent. The 'properties' field is a semi-colon (;) separated list of name:value pairs that controls various tunable parameters in the shader. Refer to the Shaders page for more information.
  • texture: Optional. Ignored if 'shader' is absent. The texture field provides the name of a texture that is used in the shader (where applicable, such as the noise shaders).

MASCameraMount

The MASCameraMount is used to control transforms on a part to control the pan and tilt position of the camera. This functionality allows a part to physically move as the camera's view is adjusted. Putting this pan and tilt control in a separate module also allows multiple cameras to share the same camera mount and be updated at the same time.

A MASCamera automatically controls the MASCameraMount when the MASCamera has panRange = 0, 0 and tiltRange = 0, 0. If either of those ranges are not zero, the MASCamera will change its own facing instead of moving the part. NOTE: It is possible to have multiple cameras installed on the same MASCameraMount. As long as all of them use a panRange and tiltRange of 0, 0, all cameras will pan and tilt when any of them are changed. A MASCamera that has a non-zero panRange or tiltRange will update itself, but not the MASCameraMount.

The fields to configure a MASCameraMount are very similar to the MASCamera:

MODULE
{
   name = MASCameraMount

   panRange = 0, 0
   panRate = 0

   tiltRange = 0, 0
   tiltRate = 0

   panTransformName = ""
   tiltTransformName = ""
}
  • panRange - Defines the maximum left and right rotation of the camera mount, in degrees.
  • panRate - The maximum number of degrees per second that the camera mount can pan. If 0, pan changes are instantaneous.
  • tiltRange - Defines the maximum up and down rotation of the camera mount, in degrees.
  • tiltRate - The maximum number of degrees per second that the camera mount can tilt. If 0, tilt changes are instantaneous.
  • panTransformName - Optional. When present, specifies a transform in the model that will be rotated to correspond with the current pan value. Using the pan transform allows the camera model to rotate physically when it is rotated. The pan rotation takes place around the Y axis of the transform.
  • tiltTransformName - Optional. When present, specifies a transform in the model that will be rotated to correspond with the current tilt value. Using the tilt transform allows the camera model to tilt physically when it is tilted. The tilt rotation takes place around the X axis of the transform.

MASDeployableCamera

The MASDeployableCamera part module may be added to any MASCamera part. When configured properly, the MASDeployableCamera controls an animation that can be used to deploy the camera, similar to the way some solar panels, radiators, and antennae may be deployed. This could allow, for instance, a camera that is mounted on a long boom that can be deployed once the vessel is on orbit.

Similar to the other deployable parts, the deployable camera is subject to aerodynamic forces (configurable in the module's config node, of course).

NOTE: The fields below are primarily from the stock KSP ModuleDeployablePart. I have guessed in some cases what values are appropriate. If I am not sure about a field, I will include (?) after the description.

MODULE
{
	name = MASDeployableCamera

	animationName = rtg
	pivotName = Cylinder_002
	raycastTransformName = Cylinder

	isBreakable = true
	//isTracking = false

	showStatus = true
	retractable = true

		// kPa * sin(AoA)
	windResistance = 2.5

	extendActionName = Extend Camera
	retractActionName = Retract Camera
	extendpanelsActionName = Extend Panels Action
}
  • animationName: Required. The deployment animation.
  • pivotName: Required. The transform that is the anchor of the animation. If the camera is damaged because of excessive wind or g-forces, the part will break at this transform. (?)
  • raycastTransformName: Required. A transform on the part of the camera that is extended. This transform appears to be involved with sun / target tracking. In the test design, I used the same transform that I used for the camera. (?)
  • isBreakable: Boolean, Optional. Default true. Controls whether the deployed camera can be broken by aerodynamic forces.
  • isTracking: Boolean, Optional. Default false. Setting this to true will cause the camera to behave like a sun-tracking solar panel. I recommend leaving it at false for now - future updates may allow for automatic tracking.
  • showStatus: Boolean, Optional. Default true. Controls whether the deployment status (RETRACTED, DEPLOYED, BROKEN, MOVING) shows in the right-click menu for the part during flight.
  • retractable: Boolean, Optional. Default true. Controls whether the camera may be retracted after it has been deployed.
  • windResistance: Optional. Default 3.0. Determines the maximum aero-forces that the part can survive. KSP documentation says that this value is Q-alpha (that is, dynamic pressure in kPa times sin(angle of attack)).
  • extendActionName, retractActionName, extendpanelsActionName: Required. Recommend using the values provided here. This is the text that is displayed in the right-click menu for the part, as well as during action group assignment in the VAB/SPH.