Skip to content

Commit

Permalink
Added the CameraAdjuster.
Browse files Browse the repository at this point in the history
 Added a number of fields to the DockingCameraModule
  • Loading branch information
linuxgurugamer committed Mar 2, 2022
1 parent 2becdf3 commit 5c4f283
Show file tree
Hide file tree
Showing 22 changed files with 411 additions and 159 deletions.
29 changes: 28 additions & 1 deletion ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,31 @@
1.3.8.2
Fixed OnboardCamera to work in orbit
Added Assemblyfileversion
Updated project info
Updated project info

1.3.8.3

Added the CameraAdjuster. It is available when you set the field :
devMode = true

in a ModuleCameraModule. Add the following to the part you want to put the camera on, then select "Camera Adjuster" when right-clicking on the part. It will show an arrow showing where the camera origin is and where it's pointing to.

MODULE
{
name = DockingCameraModule
devMode = true
}

Added following fields to the DockingCameraModule

public bool canTakePicture = false; // Can this camera take a picture
public int cameraHorizontalResolution = 256; // Horizontal res for picture taking
public int cameraVerticalResolution = 256; // Vertical res for picture taking
public string deployAnimationName = null; // If there is a deploy animation needed to be open before the camera is available
public bool openBeforePic = false; // Does the deploy animation need to be open to take a picture
public bool openIsOne = true; // relative to the deploy animation, indicates which way is open
public string cameraTransformName = "";
public float cameraCustomNearClipPlane = 0f; // Used for clipping the near camera.
public bool isDockingNode = true; // Is this a docking node
public bool photoDir = "DockingCamera"; // This specifies the name of the directory where any photos taken are saved, inside the Screenshots folder, in a top level directory with the name of the game save

2 changes: 1 addition & 1 deletion DockingCamera.version
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"MAJOR": 1,
"MINOR": 3,
"PATCH": 8,
"BUILD": 2
"BUILD": 3
},
"KSP_VERSION": {
"MAJOR": 1,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions GameData/DockingCamKURS/DockingCamera.version
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"VERSION": {
"MAJOR": 1,
"MINOR": 3,
"PATCH": 7,
"BUILD": 11
"PATCH": 8,
"BUILD": 3
},
"KSP_VERSION": {
"MAJOR": 1,
"MINOR": 9,
"PATCH": 1
"MINOR": 12,
"PATCH": 0
},
"KSP_VERSION_MIN": {
"MAJOR": 1,
Expand Down
1 change: 1 addition & 0 deletions GameData/DockingCamKURS/MM_Scripts/MM_KSPCamera.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
MODULE
{
name = DockingCameraModule
isDockingNode = true
noise = false
}
}
5 changes: 5 additions & 0 deletions GameData/DockingCamKURS/Parts/OnboardCamera.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ PART
windowSize = 300 // initial camera window size
allowedScanDistance = 1000 //max allowed distance for scanning experiment
resourceScanning = ElectricCharge.50 //(resourseName/resourceUsage) for scanning

electricchargeCost = 0.02

photoDir = OnboardCamera

}

MODULE
Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions Parts/OnboardCamera.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ PART
allowedScanDistance = 1000 //max allowed distance for scanning experiment
resourceScanning = ElectricCharge.50 //(resourseName/resourceUsage) for scanning
electricchargeCost = 0.02

photoDir = OnboardCamera
}

MODULE
Expand Down
4 changes: 2 additions & 2 deletions Source/AssemblyVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

using System.Reflection;

[assembly: AssemblyVersion("1.3.8.2")]
[assembly: AssemblyFileVersion("1.3.8.2")]
[assembly: AssemblyVersion("1.3.8.3")]
[assembly: AssemblyFileVersion("1.3.8.3")]
96 changes: 94 additions & 2 deletions Source/Camera/BaseCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ public abstract class BaseCamera

internal ShaderInfo availableShaders = null;

Modules.DockingCameraModule dcm;
public string photoDir = "DockingCam";

public void SetDCM(Modules.DockingCameraModule dcm)
{
this.dcm = dcm;
}

public void SetPhotoDir(string dir)
{
Log.Info("SetPhotoDir: " + dir);
photoDir = dir;
}
protected BaseCamera(Part thisPart, float windowSizeInit, string windowLabel = "Camera")
{
InitBaseCamera(thisPart, windowSizeInit, windowLabel);
Expand Down Expand Up @@ -199,6 +212,8 @@ protected virtual void InitCameras()
camera.CopyFrom(cameraExample);
camera.name = string.Format("{1} copy of {0}", CameraNames[i], WindowCount);
camera.targetTexture = RenderTexture;
if (i == 2 && dcm != null && dcm.cameraCustomNearClipPlane > 0)
camera.nearClipPlane = dcm.cameraCustomNearClipPlane;
}
return camera;
}).ToList();
Expand All @@ -210,6 +225,7 @@ protected virtual void DestroyCameras()
AllCameras.Clear();
}


/// <summary>
/// Create and activate cameras
/// </summary>
Expand Down Expand Up @@ -275,6 +291,70 @@ private void DrawWindow(int id)
WindowSettings.SaveCameraWinSettings(WindowPosition);
}



internal bool takePic = false;

RenderTexture _renderTextureColor;
RenderTexture _renderTextureDepth;

public Texture2D GetPic()
{
RenderTexture CurrentRT = RenderTexture.active;

Texture2D imageTexture = new Texture2D(dcm.cameraHorizontalResolution, dcm.cameraVerticalResolution, TextureFormat.RGB24, false);

if (_renderTextureColor == null)
{
_renderTextureColor = new RenderTexture(dcm.cameraHorizontalResolution, dcm.cameraVerticalResolution, 0);
_renderTextureDepth = new RenderTexture(dcm.cameraHorizontalResolution, dcm.cameraVerticalResolution, 24);
_renderTextureColor.Create();
_renderTextureDepth.Create();
}
RenderTexture.active = _renderTextureColor;


foreach (var a in AllCameras)
{
a.SetTargetBuffers(_renderTextureColor.colorBuffer, _renderTextureDepth.depthBuffer);
a.Render();
}

imageTexture.ReadPixels(new Rect(0, 0, dcm.cameraHorizontalResolution, dcm.cameraVerticalResolution), 0, 0);
imageTexture.Apply();

_renderTextureColor.Release();
_renderTextureDepth.Release();
_renderTextureColor = null;
_renderTextureDepth = null;

foreach (var a in AllCameras)
a.targetTexture = RenderTexture;

RenderTexture.active = CurrentRT;


return imageTexture;
}

/* ************************************************************************************************
* Function Name: WriteTextureToDrive
* Input: The texture object that will be written to the hard drive.
* Output: None
* Purpose: This function will take an input texture and then convert it to a png file in the
* DockingCam subfolder of the Screenshot folder.
* This currently has some bugs.
* If Linux users complain about screenshots not saving to the disk, then this is the first place
* to look.
* ************************************************************************************************/
private void WriteTextureToDrive(Texture2D Input)
{
Util.WritePng(Input, photoDir, ThisPart.vessel.vesselName);
}




/// <summary>
/// drawing method, first layer, for cameras
/// </summary>
Expand All @@ -292,7 +372,7 @@ protected virtual void ExtendedDrawWindowL1()
{
GUI.Label(new Rect(widthOffset, 22, 80, 20), "Zoom: " + CalculatedZoom, Styles.Label13B);

if (FlightGlobals.ActiveVessel == ThisPart.vessel)
if (dcm != null && dcm.isDockingNode && FlightGlobals.ActiveVessel == ThisPart.vessel)
_isTargetPoint = GUI.Toggle(new Rect(widthOffset - 2, 233, 88, 20), _isTargetPoint, "Target Mark");
}
//GUI.DrawTexture(TexturePosition, _textureBackGroundCamera);
Expand All @@ -302,7 +382,19 @@ protected virtual void ExtendedDrawWindowL1()
_currentShaderName = CurrentShader == null ? "none" : CurrentShader.name;

if (Event.current.type.Equals(EventType.Repaint))
{
Graphics.DrawTexture(TexturePosition, Render(), CurrentShader);
if (takePic)
{
//RenderTexture.SavePng(ThisPart.vessel.vesselName);
//takePic = false;
//return;
WriteTextureToDrive(GetPic());

takePic = false;
}
}

}

/// <summary>
Expand Down Expand Up @@ -436,7 +528,7 @@ void LoadWinSettings()
}
DoResizeWindow(WindowSizeCoef);
}
#endregion DRAW LAYERS
#endregion DRAW LAYERS

private float GetX(float x, float z)
{
Expand Down
Loading

0 comments on commit 5c4f283

Please sign in to comment.