Skip to content

Commit

Permalink
0.90.0 Update. Includes @fingerboxes pull request e3eb1cc. Cleaned up…
Browse files Browse the repository at this point in the history
… other comments in master commit.
  • Loading branch information
bigorangemachine committed Dec 20, 2014
1 parent c5f29d0 commit 7d28b8f
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 77 deletions.
Binary file modified GameData.zip
Binary file not shown.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ Developers who wish to contribute should [branch dev-master](https://github.com/

### Bigorangemachine's Fork

#### v0.0.4 - 0.90.0 Patch
* Includes [Git fingerboxes](https://github.com/fingerboxes) patch for in-game rendering glitches & other weirdness (unconfirmed bug)
* Thanks to KSP-IRC: TaranisElsu for helping me find the solution to the VAB/SPH facitilty detection
* Thanks to [Git m4v](https://github.com/m4v) (RCS Build Assist) again for keeping their code public so I could reference the click through code
* To Install:
* Replace all Existing <KSP ROOT>GameData/KronalUtils/ files (only .DLL changed but be sure replace everything)
* No Dependancies
* To Build/Compile:
* Normal KSP Modding (Build with required KSP DLLs)
* Download and Build with [KAS.dll](https://github.com/KospY/KAS)
* Download and Build with [ProceduralFairings.dll](https://github.com/e-dog/ProceduralFairings)

#### v0.0.4 - Pitch Perfect
* Added 'Auto-Preview' checkbox (for slower computers)
* [HOT FIX] Fixed Bug where parts would not 'Offset' (Formerly Explode View) unless Procedural Fairings was installed
Expand Down
112 changes: 77 additions & 35 deletions src/KRSVesselShot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ class KRSVesselShot
public ShaderMaterial MaterialBluePrint = new ShaderMaterial(KSP.IO.File.ReadAllText<KRSVesselShot>("blueprint"));
private List<string> Shaders = new List<string>() { "edn", "cutoff", "diffuse", "bumped", "bumpedspecular", "specular", "unlit", "emissivespecular", "emissivebumpedspecular" };
private Dictionary<string, Material> Materials;
public string editorOrientation = "";
public readonly IDictionary<string, ShaderMaterial> Effects;
public int calculatedWidth = 1;
public int calculatedHeight = 1;
public Dictionary<string, float> uiFloatVals = new Dictionary<string, float> {
{ "shadowVal", 0f }, { "shadowValPercent", 0f },
{"imgPercent",4f},
{"bgR",1f},{"bgG",1f},{"bgB",1f},{"bgA",1f},//RGBA
{"bgR_",0f},{"bgG_",0.07f},{"bgB_",0.11f},{"bgA_",1f}//RGBA defaults //00406E 0,64,110 -> reduced due to color adjust shader
{"bgR",1f},{"bgG",1f},{"bgB",1f},{"bgA",1f},
{"bgR_",0f},{"bgG_",0.07f},{"bgB_",0.11f},{"bgA_",1f}
};
public Dictionary<string, bool> uiBoolVals = new Dictionary<string, bool> {
{"canPreview",true},{"saveTextureEvent",false}
Expand All @@ -37,17 +38,17 @@ class KRSVesselShot
internal Camera Camera { get; private set; }
internal Vector3 direction;
internal Vector3 position;
internal float storedShadowDistance; // keeps original shadow distance. Used to toggle shadows off during rendering.
internal bool EffectsAntiAliasing { get; set; }//consider obsolete?
internal float storedShadowDistance;
internal bool EffectsAntiAliasing { get; set; }
internal bool Orthographic
{
get
{
return this.Camera == this.cameras[0];//if this currently selected camera is the first camera then Orthographic is true
return this.Camera == this.cameras[0];
}
set
{
this.Camera = this.cameras[value ? 0 : 1];//if setting to true use the first camera (which is ortho camera). if false use the non-ortho
this.Camera = this.cameras[value ? 0 : 1];
}
}
internal VesselViewConfig Config { get; private set; }
Expand Down Expand Up @@ -101,14 +102,19 @@ public KRSVesselShot()
LoadShaders();
UpdateShipBounds();

GameEvents.onPartAttach.Add(PartAttached);
GameEvents.onPartRemove.Add(PartRemoved);

GameEvents.onPartAttach.Add(PartModified);
GameEvents.onPartRemove.Add(PartModified);
}

~KRSVesselShot()
{
GameEvents.onPartAttach.Remove(PartAttached);
GameEvents.onPartRemove.Remove(PartRemoved);
GameEvents.onPartAttach.Remove(PartModified);
GameEvents.onPartRemove.Remove(PartModified);
}
public void setFacility()
{
editorOrientation = (EditorLogic.fetch.ship.shipFacility == EditorFacility.SPH ? "SPH" : "VAB");
}

private void SetupCameras()
Expand All @@ -130,16 +136,17 @@ private void SetupCameras()
public void RotateShip(float degrees)
{
Vector3 rotateAxis;
if (editorOrientation != "SPH" && editorOrientation != "VAB") { setFacility(); }

if (HighLogic.LoadedScene == GameScenes.SPH)
if (editorOrientation == "SPH")
{
Debug.Log(string.Format("Rotating in SPH: {0}", degrees));
rotateAxis = EditorLogic.startPod.transform.forward;
rotateAxis = EditorLogic.RootPart.transform.forward;
}
else
{
Debug.Log(string.Format("Rotating in VAB: {0}", degrees));
rotateAxis = EditorLogic.startPod.transform.up;
rotateAxis = EditorLogic.RootPart.transform.up;
}

this.direction = Quaternion.AngleAxis(degrees, rotateAxis) * this.direction;
Expand All @@ -166,28 +173,52 @@ private void ReplacePartShaders(Part part)
var model = part.transform.Find("model");
if (!model) return;

foreach (var r in model.GetComponentsInChildren<MeshRenderer>())
Dictionary<MeshRenderer, Shader> MeshRendererLibrary = new Dictionary<MeshRenderer,Shader>();

foreach (MeshRenderer mr in model.GetComponentsInChildren<MeshRenderer>())
{
Material mat;
if (Materials.TryGetValue(r.material.shader.name, out mat))
if (Materials.TryGetValue(mr.material.shader.name, out mat))
{
r.material.shader = mat.shader;
if (!MeshRendererLibrary.ContainsKey(mr))
{
MeshRendererLibrary.Add(mr, mr.material.shader);
}
mr.material.shader = mat.shader;
}
else
{
MonoBehaviour.print("[Warning] " + this.GetType().Name + "No replacement for " + r.material.shader + " in " + part + "/*/" + r);
MonoBehaviour.print("[Warning] " + this.GetType().Name + "No replacement for " + mr.material.shader + " in " + part + "/*/" + mr);
}
}
if (!PartShaderLibrary.ContainsKey(part))
{
PartShaderLibrary.Add(part, MeshRendererLibrary);
}
}

private void PartAttached(GameEvents.HostTargetAction<Part, Part> data)
Dictionary<Part,Dictionary<MeshRenderer, Shader>> PartShaderLibrary = new Dictionary<Part,Dictionary<MeshRenderer,Shader>>();

private void RestorePartShaders(Part part)
{
ReplacePartShaders(data.host);
ReplacePartShaders(data.target);
UpdateShipBounds();
var model = part.transform.Find("model");
if (!model) return;

Dictionary<MeshRenderer,Shader> MeshRendererLibrary;
if (PartShaderLibrary.TryGetValue(part, out MeshRendererLibrary))
{
foreach (MeshRenderer mr in model.GetComponentsInChildren<MeshRenderer>())
{
Shader OldShader;
if (MeshRendererLibrary.TryGetValue(mr, out OldShader))
{
mr.material.shader = OldShader;
}
}
}
}

private void PartRemoved(GameEvents.HostTargetAction<Part, Part> data)
private void PartModified(GameEvents.HostTargetAction<Part, Part> data)
{
UpdateShipBounds();
}
Expand Down Expand Up @@ -225,6 +256,11 @@ public Vector3 GetShipSize()

public void GenTexture(Vector3 direction, int imageWidth = -1, int imageHeight = -1)
{
foreach (Part p in EditorLogic.fetch.ship)
{
ReplacePartShaders(p);
}

var minusDir = -direction;
this.Camera.clearFlags = CameraClearFlags.SolidColor;
if(this.Effects["Blue Print"].Enabled){
Expand All @@ -235,7 +271,8 @@ public void GenTexture(Vector3 direction, int imageWidth = -1, int imageHeight =

this.Camera.transform.position = this.shipBounds.center;

if (HighLogic.LoadedScene == GameScenes.SPH)
//if (HighLogic.LoadedScene == GameScenes.SPH)
if (editorOrientation == "SPH")
{
this.Camera.transform.rotation = Quaternion.AngleAxis(90, Vector3.right);
}
Expand All @@ -244,7 +281,6 @@ public void GenTexture(Vector3 direction, int imageWidth = -1, int imageHeight =
this.Camera.transform.rotation = Quaternion.AngleAxis(0f, Vector3.right);
}

// Apply angle Vector to camera.
this.Camera.transform.Translate(minusDir * this.Camera.nearClipPlane);

// Face camera to vehicle.
Expand All @@ -256,10 +292,9 @@ public void GenTexture(Vector3 direction, int imageWidth = -1, int imageHeight =
var width = Vector3.Scale(binormal, this.shipBounds.size).magnitude;
var depth = Vector3.Scale(minusDir, this.shipBounds.size).magnitude;

width += this.Config.procFairingOffset; // get the distance of fairing offset
depth += this.Config.procFairingOffset; // for the farClipPlane
width += this.Config.procFairingOffset;
depth += this.Config.procFairingOffset;

// Find distance from vehicle.
float positionOffset = (this.shipBounds.size.magnitude - this.position.z) / (2f * Mathf.Tan(Mathf.Deg2Rad * this.Camera.fieldOfView / 2f));

this.Camera.transform.Translate(new Vector3(this.position.x, this.position.y, -positionOffset));
Expand Down Expand Up @@ -310,13 +345,10 @@ public void GenTexture(Vector3 direction, int imageWidth = -1, int imageHeight =
if (uiBoolVals["canPreview"] || uiBoolVals["saveTextureEvent"])
{
this.rt = RenderTexture.GetTemporary(fileWidth, fileHeight, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
//this.rt = RenderTexture.GetTemporary(imageWidth, imageHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
this.Camera.targetTexture = this.rt;
this.Camera.depthTextureMode = DepthTextureMode.DepthNormals;
this.Camera.Render();
this.Camera.targetTexture = null;
//Graphics.Blit(this.rt, this.rt, MaterialColorAdjust.Material);
//Graphics.Blit(this.rt, this.rt, MaterialEdgeDetect.Material);
foreach (var fx in Effects)
{
if (fx.Value.Enabled)
Expand All @@ -325,13 +357,20 @@ public void GenTexture(Vector3 direction, int imageWidth = -1, int imageHeight =
}
}
}

foreach (Part p in EditorLogic.fetch.ship)
{
RestorePartShaders(p);
}
}

private void SaveTexture(String fileName)
{
int fileWidth = this.rt.width;
int fileHeight = this.rt.height;
#if DEBUG
Debug.Log(string.Format("KVV: SIZE: {0} x {1}", fileWidth, fileHeight));
#endif

Texture2D screenShot = new Texture2D(fileWidth, fileHeight, TextureFormat.ARGB32, false);

Expand Down Expand Up @@ -362,7 +401,8 @@ private static string MakeValidFileName(string name)
return System.Text.RegularExpressions.Regex.Replace(name, invalidRegStr, "_");
}
public void Execute() {
if (!((EditorLogic.startPod) && (this.Ship != null)))
//if (!((EditorLogic.startPod) && (this.Ship != null)))
if (!((EditorLogic.RootPart) && (this.Ship != null)))
{
return;
}
Expand All @@ -372,7 +412,8 @@ public void Execute() {

public void Explode()
{
if (!EditorLogic.startPod || this.Ship == null)
//if (!EditorLogic.startPod || this.Ship == null)
if (!EditorLogic.RootPart || this.Ship == null)
{
return;
}
Expand All @@ -383,12 +424,13 @@ public void Explode()

public void Update(int width = -1, int height = -1)
{
if (!EditorLogic.startPod || this.Ship == null)
//if (!EditorLogic.startPod || this.Ship == null)
if (!EditorLogic.RootPart || this.Ship == null)
{
return;
}

var dir = EditorLogic.startPod.transform.TransformDirection(this.direction);
var dir = EditorLogic.RootPart.transform.TransformDirection(this.direction);

storedShadowDistance = QualitySettings.shadowDistance;
QualitySettings.shadowDistance = (this.uiFloatVals["shadowVal"] < 0f ? 0f : this.uiFloatVals["shadowVal"]);
Expand All @@ -401,7 +443,7 @@ public void Update(int width = -1, int height = -1)

internal Texture Texture()
{
if (!((EditorLogic.startPod) && (this.Ship != null)))
if (!((EditorLogic.RootPart) && (this.Ship != null)))
{
return null;
}
Expand Down
27 changes: 11 additions & 16 deletions src/KRSVesselShotUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class KRSVesselShotUI : MonoBehaviour
private KRSEditorAxis axis;
private bool IsOnEditor()
{
return (HighLogic.LoadedScene == GameScenes.EDITOR || HighLogic.LoadedScene == GameScenes.SPH);
return (HighLogic.LoadedScene == GameScenes.EDITOR || HighLogic.LoadedSceneIsEditor);
}

public void Awake()
Expand Down Expand Up @@ -90,9 +90,7 @@ bool isMouseOver()//https://github.com/m4v/RCSBuildAid/blob/master/Plugin/GUI/Ma
Screen.height - Input.mousePosition.y);
return this.windowSize.Contains(position);
}
/* Whenever we mouseover our window, we need to lock the editor so we don't pick up
* parts while dragging the window around */
void setEditorLock()//https://github.com/m4v/RCSBuildAid/blob/master/Plugin/GUI/MainWindow.cs#L296
void setEditorLock()//https://github.com/m4v/RCSBuildAid/blob/master/Plugin/GUI/MainWindow.cs
{
if (visible)
{
Expand All @@ -106,8 +104,8 @@ void setEditorLock()//https://github.com/m4v/RCSBuildAid/blob/master/Plugin/GUI/
| ControlTypes.EDITOR_PAD_PICK_PLACE
| ControlTypes.EDITOR_PAD_PICK_COPY
| ControlTypes.EDITOR_EDIT_STAGES
| ControlTypes.EDITOR_ROTATE_PARTS
| ControlTypes.EDITOR_OVERLAYS;
| ControlTypes.EDITOR_GIZMO_TOOLS
| ControlTypes.EDITOR_ROOT_REFLOW;

InputLockManager.SetControlLock(controlTypes, this.inputLockIdent);
}
Expand All @@ -127,16 +125,13 @@ public void OnGUI()
{
switch (HighLogic.LoadedScene) {//https://github.com/m4v/RCSBuildAid/blob/master/Plugin/GUI/MainWindow.cs
case GameScenes.EDITOR:
case GameScenes.SPH:
break;
default:
/* don't show window during scene changes */
return;
}
if (visible)
{
this.windowSize = GUILayout.Window(GetInstanceID(), this.windowSize, GUIWindow, "Kronal Vessel Viewer", HighLogic.Skin.window);
EditorLogic.softLock = this.windowSize.Contains(Event.current.mousePosition);//EditorLogic.softLock not supported anymore? this.windowSize is static not dynamic with drag & drop? what does this do?
}

if (Event.current.type == EventType.Repaint)
Expand Down Expand Up @@ -202,7 +197,7 @@ private void GUIButtons()
{
this.control.position.y -= 0.1f;
}
if (GUILayout.RepeatButton("ᴐ", GUILayout.Width(34) , GUILayout.Height(34))) //↶
if (GUILayout.RepeatButton("ᴐ", GUILayout.Width(34) , GUILayout.Height(34)))
{
this.control.RotateShip(1f);
}
Expand Down Expand Up @@ -248,8 +243,8 @@ private void GUIButtons()
GUILayout.Space(3f);
this.control.uiFloatVals["shadowValPercent"] = GUILayout.HorizontalSlider(this.control.uiFloatVals["shadowValPercent"], 0f, 300f, GUILayout.Width(153f));
GUILayout.Space(1f);
GUILayout.Label(this.control.uiFloatVals["shadowValPercent"].ToString("F"), GUILayout.Width(50f));//GUILayout.Width(50f),
this.control.uiFloatVals["shadowVal"] = this.control.uiFloatVals["shadowValPercent"] * 1000f;//1000 is the max shadow val. Looks like it takes a float so thats the max?
GUILayout.Label(this.control.uiFloatVals["shadowValPercent"].ToString("F"), GUILayout.Width(50f));
this.control.uiFloatVals["shadowVal"] = this.control.uiFloatVals["shadowValPercent"] * 1000f;
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("File Quality", GUILayout.Width(68f));
Expand All @@ -258,7 +253,7 @@ private void GUIButtons()
GUILayout.Space(1f);
String disW = Math.Floor((control.uiFloatVals["imgPercent"] +1) * control.calculatedWidth).ToString();
String disH = Math.Floor((control.uiFloatVals["imgPercent"] + 1) * control.calculatedHeight).ToString();
GUILayout.Label(String.Format("{0:0.#}", this.control.uiFloatVals["imgPercent"].ToString("F")) + "\n" + disW + " x " + disH, GUILayout.Width(110f));//GUILayout.Width(50f),
GUILayout.Label(String.Format("{0:0.#}", this.control.uiFloatVals["imgPercent"].ToString("F")) + "\n" + disW + " x " + disH, GUILayout.Width(110f));
control.uiFloatVals["imgPercent"] = control.uiFloatVals["imgPercent"] + 1;
GUILayout.EndHorizontal();
GUILayout.EndVertical();
Expand All @@ -268,8 +263,7 @@ private void GUIButtons()
this.shaderTabCurrent = GUILayout.Toolbar(this.shaderTabCurrent, this.shaderTabsNames);
GUILayout.EndHorizontal();

this.tabCurrent = 0;//used only in Update() be 0. This will be removed later
//GUILayout.EndHorizontal();
this.tabCurrent = 0;
}
private void GUITabShader(string name)
{
Expand Down Expand Up @@ -394,7 +388,7 @@ private void GUITabView()
var texture = this.control.Texture();
if (texture)
{
GUI.DrawTexture(this.orthoViewRect, texture, ScaleMode.ScaleToFit, false); // ALPHA BLENDING?! HEY HEY
GUI.DrawTexture(this.orthoViewRect, texture, ScaleMode.ScaleToFit, false);
}
}

Expand Down Expand Up @@ -447,6 +441,7 @@ void OnGUIAppLauncherReady()
DummyVoid,
ApplicationLauncher.AppScenes.SPH | ApplicationLauncher.AppScenes.VAB,
(Texture)GameDatabase.Instance.GetTexture("KronalUtils/Textures/icon_button", false));
control.setFacility();

}
}
Expand Down
Loading

0 comments on commit 7d28b8f

Please sign in to comment.