internal void UpdateCallBack(GrassColorPresetUI2.ColorPreset2 preset) { if (KKGraphics.GetTexture(preset.nearGrassTexture) != null) { //Log.Normal("Updating Texture to: " + newTexture); nearGrassTextureName = preset.nearGrassTexture; } if (KKGraphics.GetTexture(preset.farGrassTexture) != null) { //Log.Normal("Updating Texture to: " + newTexture); farGrassTextureName = preset.farGrassTexture; } if (KKGraphics.GetTexture(preset.tarmacTexture) != null) { //Log.Normal("Updating Texture to: " + newTexture); tarmacTextureName = preset.tarmacTexture; } grassColor = preset.grassColor; tarmacColor = preset.tarmacColor; ApplySettings(); }
/// <summary> /// Sets the texture in all transforms of the right name /// </summary> internal void SetTexture() { if (staticInstance.GrasColor == Color.clear) { return; } //Log.Normal("FlagDeclal: setTexture called"); if (!isInitialized) { Initialize(); } grasTextureName = staticInstance.GrasTexture; if (string.IsNullOrEmpty(grasTextureName)) { //Log.Normal("String was emtpy"); grasTextureName = GrasTextureImage; } grasColor = GetColor(); grasTexture = KKGraphics.GetTexture(grasTextureName, false, 0, true); foreach (Material material in grasMaterials) { material.SetColor("_Color", grasColor); if (grasTexture != null) { //Log.Normal("GC: Setting Texture to: " + grasTextureName); material.mainTexture = grasTexture; } } }
public void Start() { //Log.Normal("AdvTexture called on " + staticInstance.model.name); if (!int.TryParse(BuiltinIndex, out textureIndex)) { Log.UserError("AdvancedTexture: could not parse BuiltinIndex " + BuiltinIndex); } targetTransforms = transforms.Split(seperators, StringSplitOptions.RemoveEmptyEntries).ToList(); //foreach (var bla in targetTransforms) //{ // Log.Normal("AdvancedTexture: Found Transform: " + bla); //} foreach (MeshRenderer renderer in gameObject.GetComponentsInChildren <MeshRenderer>(true)) { if (!transforms.Equals("Any", StringComparison.CurrentCultureIgnoreCase) && !targetTransforms.Contains(renderer.transform.name)) { continue; } // Log.Normal("Processing Transform: " + renderer.transform.name); if (newMaterial != "") { ReplaceMaterial(renderer, newMaterial); continue; } if (!string.IsNullOrEmpty(newShader)) { ReplaceShader(renderer, newShader); } var myFields = this.GetType().GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); foreach (var texturemap in myFields) { if (texturemap.Name.Contains("_") && (texturemap.GetValue(this) != null)) { // Log.Normal(" Advanced texture" + texturemap.Name + " : " + (string)texturemap.GetValue(this)); Texture2D newTexture = KKGraphics.GetTexture((string)texturemap.GetValue(this), (texturemap.Name.Equals("_BumpMap", StringComparison.CurrentCultureIgnoreCase)), textureIndex); renderer.material.SetTexture(texturemap.Name, newTexture); } } } }
/// <summary> /// Uses the PQS System to query the color of the undergound /// </summary> /// <param name="body"></param> /// <param name="lat"></param> /// <param name="lon"></param> /// <returns></returns> public void FindModelGrasMaterials() { Transform[] allTransforms = gameObject.transform.GetComponentsInChildren <Transform>(true).Where(x => x.name == GrasMeshName).ToArray(); foreach (var transform in allTransforms) { transform.name = "KKGrass"; Renderer grasRenderer = transform.GetComponent <Renderer>(); grasMaterials.Add(grasRenderer.material); //grasRenderer.material.mainTexture = KKGraphics.GetTexture(GrasTextureImage); grasRenderer.material.mainTexture = KKGraphics.GetTexture(GrasTextureImage, false, 0, true); //grasRenderer.material.shader = Shader.Find("KSP/Scenery/Diffuse Multiply"); grasRenderer.material.shader = KKGraphics.GetShader("KK/Diffuse_Multiply_Random"); } }
private void SetTexture(MeshRenderer renderer, string texturename, string targetname, bool isNormal = false) { if (!String.IsNullOrEmpty(texturename)) { Texture2D newTexture = KKGraphics.GetTexture(texturename, isNormal, textureIndex); if (newTexture != null) { renderer.material.SetTexture(targetname, newTexture); if (doTileing) { tileing.StaticObjectUpdate(); } } else { Log.UserWarning("cannot set Texture: " + texturename + " as " + targetname + " on: " + staticInstance.model.name); } } }
public void findModelGrasMaterials() { Transform[] allTransforms = gameObject.transform.GetComponentsInChildren <Transform>(true).Where(x => x.name == GrasMeshName).ToArray(); foreach (var transform in allTransforms) { Renderer grasRenderer = transform.GetComponent <Renderer>(); grasMaterials.Add(grasRenderer.material); grasRenderer.material.mainTexture = KKGraphics.GetTexture(GrasTextureImage); grasRenderer.material.shader = Shader.Find("KSP/Scenery/Diffuse Multiply"); if (useNormalMap) { //grasRenderer.material.shader = Shader.Find("Legacy Shaders/Bumped Diffuse"); //grasRenderer.material.shader = Shader.Find("KSP/Scenery/Diffuse Multiply"); if ((String.IsNullOrEmpty(GrasTextureNormalMap) == false) && grasRenderer.material.HasProperty("_BumpMap")) { grasRenderer.material.shader = Shader.Find("Legacy Shaders/Bumped Diffuse"); grasRenderer.material.SetTexture("_BumpMap", KKGraphics.GetTexture(GrasTextureNormalMap, true)); } } } }
public void FindModelGrasMaterials() { Transform[] allTransforms = gameObject.transform.GetComponentsInChildren <Transform>(true).Where(x => x.name == GrassMeshName).ToArray(); foreach (var transform in allTransforms) { Renderer grassRenderer = transform.GetComponent <Renderer>(); grassRenderers.Add(grassRenderer); //grassRenderer.material.shader = Shader.Find("KSP/Scenery/Diffuse"); //grassRenderer.material.SetTexture("_MainTex", KKGraphics.GetTexture(GrasTextureImage,false,0)); grassRenderer.material.shader = Shader.Find("KSP/Scenery/Diffuse Ground KSC"); grassRenderer.material.SetTexture("_NearGrassTexture", KKGraphics.GetTexture(DefaultNearGrassTexture)); grassRenderer.material.SetTexture("_FarGrassTexture", KKGraphics.GetTexture(DefaultFarGrassTexture)); grassRenderer.material.SetTexture("_TarmacTexture", KKGraphics.GetTexture(DefaultTarmacTexture)); grassRenderer.material.SetTexture("_BlendMaskTexture", KKGraphics.GetTexture(DefaultBlendMaskTexture)); grassRenderer.material.SetFloat("_FarGrassBlendDistance", 100f); //Log.Normal("Scale: " + grassRenderer.material.GetTextureScale("_NearGrassTexture")); } }
/// <summary> /// Sets the texture in all transforms of the right name /// </summary> internal void ApplySettings() { if (!isInitialized) { Initialize(); } if (grassColor == Color.clear) { return; } nearGrassTexture = KKGraphics.GetTexture(nearGrassTextureName); farGrassTexture = KKGraphics.GetTexture(farGrassTextureName); tarmacTexture = KKGraphics.GetTexture(tarmacTextureName); blendMaskTexture = KKGraphics.GetTexture(blendMaskTextureName); //grassColor = GetColor(); foreach (Renderer renderer in grassRenderers) { //if (useLegacy && renderer.material.shader.name.StartsWith("KSP/Scenery/Diffuse Ground KSC")) //{ // Material grassMaterial = new Material(KKGraphics.GetShader("KK/legacy_Ground_KSC")); // grassMaterial.CopyPropertiesFromMaterial(renderer.material); // renderer.SetPropertyBlock(null); // Log.Normal("found localscale: " + renderer.transform.localScale); // Vector2 blendmaskTiling = renderer.material.GetTextureScale("_BlendMaskTexture"); // tarmacTiling = renderer.material.GetTextureScale("_TarmacTexture"); // //renderer.material.shader = KKGraphics.GetShader("KK/legacy_Ground_KSC"); // renderer.material = grassMaterial; // renderer.material.SetTextureScale("_TarmacTexture", tarmacTiling); // renderer.material.SetTextureScale("_BlendMaskTexture", new Vector2(1,1)); // nearGrassTiling = 20; // farGrassTiling = 80; // //if (staticInstance.model.name == "KSC_SpaceplaneHangar_level_3") // //{ // // nearGrassTiling = 5; // // farGrassTiling = 10; // // renderer.material.SetTextureScale("_BlendMaskTexture", (new Vector2(1, 1)*(1f/16f))); // // renderer.material.SetTextureOffset("_BlendMaskTexture", (new Vector2(0.5f, 0.5f))); // //} // //renderer.material.SetFloat("_TilingOffset", 10f); //} //if (!useLegacy && !renderer.material.shader.name.StartsWith("KSP/Scenery/Diffuse Ground KSC")) //{ // Vector2 blendmaskTiling = renderer.material.GetTextureScale("_BlendMaskTexture"); // tarmacTiling = renderer.material.GetTextureScale("_TarmacTexture"); // renderer.material.shader = KKGraphics.GetShader("KSP/Scenery/Diffuse Ground KSC"); // renderer.material.SetTextureScale("_TarmacTexture", tarmacTiling); //} //if (useLegacy) //{ // renderer.material.SetFloat("_TilingOffset", tilingOffset); //} renderer.material.SetColor("_GrassColor", grassColor); renderer.material.SetColor("_TarmacColor", tarmacColor); //if (!staticInstance.model.isSquad) //{ renderer.material.SetFloat("_NearGrassTiling", nearGrassTiling); renderer.material.SetFloat("_FarGrassTiling", farGrassTiling); //renderer.material.SetTextureScale("_TarmacTexture", tarmacTiling); //} //Log.Normal("tiling near: " + nearGrassTiling + " isSquad: " + staticInstance.model.isSquad.ToString()); //Log.Normal("tiling far: " + farGrassTiling + " isSquad: " + staticInstance.model.isSquad.ToString()); renderer.material.SetFloat("_FarGrassBlendDistance", farGrassBlendDistance); if (nearGrassTexture != null) { //Log.Normal("GC: Setting Texture to: " + grasTextureName); renderer.material.SetTexture("_NearGrassTexture", nearGrassTexture); } if (farGrassTexture != null) { //Log.Normal("GC: Setting Texture to: " + grasTextureName); renderer.material.SetTexture("_FarGrassTexture", farGrassTexture); } if (tarmacTexture != null) { //Log.Normal("GC: Setting Texture to: " + grasTextureName); renderer.material.SetTexture("_TarmacTexture", tarmacTexture); } if (blendMaskTexture != null) { //Log.Normal("GC: Setting Texture to: " + grasTextureName); renderer.material.SetTexture("_BlendMaskTexture", blendMaskTexture); } } }
/// <summary> /// Sets the texture in all transforms of the right name /// </summary> internal void ApplySettings() { if (!isInitialized) { Initialize(); } if (grassColor == Color.clear) { return; } nearGrassTexture = KKGraphics.GetTexture(nearGrassTextureName); farGrassTexture = KKGraphics.GetTexture(farGrassTextureName); tarmacTexture = KKGraphics.GetTexture(tarmacTextureName); blendMaskTexture = KKGraphics.GetTexture(blendMaskTextureName); if (!string.IsNullOrEmpty(thirdTextureName)) { thirdTexture = KKGraphics.GetTexture(thirdTextureName); } if (!string.IsNullOrEmpty(fourthTextureName)) { fourthTexture = KKGraphics.GetTexture(fourthTextureName); } //Material material = grassMaterials.ElementAt(matOffset); foreach (Material material in grassMaterials) { //if (useLegacy) //{ // renderer.material.SetFloat("_TilingOffset", tilingOffset); //} material.SetColor("_GrassColor", grassColor); material.SetColor("_TarmacColor", tarmacColor); //if (!staticInstance.model.isSquad) //{ material.SetFloat("_NearGrassTiling", nearGrassTiling); material.SetFloat("_FarGrassTiling", farGrassTiling); material.SetFloat("_FarGrassBlendDistance", farGrassBlendDistance); //Log.Normal("GC: Setting Texture to: " + grasTextureName); material.SetTexture("_NearGrassTexture", nearGrassTexture); //Log.Normal("GC: Setting Texture to: " + grasTextureName); material.SetTexture("_FarGrassTexture", farGrassTexture); //if (farGrassTexture != null) //{ // material.SetTexture("_FarGrassNormalTexture", KKGraphics.GetNormalMap(farGrassTexture)); //} //else //{ // material.SetTexture("_FarGrassNormalTexture", null); //} //Log.Normal("GC: Setting Texture to: " + grasTextureName); material.SetTexture("_TarmacTexture", tarmacTexture); if (tarmacTexture != null) { //material.SetTexture("_TarmacNormalTexture", KKGraphics.GetNormalMap(tarmacTexture)); material.SetTextureScale("_TarmacTexture", tarmacTiling); material.SetFloat("_TarmacTileRandom", tarmacTileRandom ? 1f : 0); } else { //material.SetTexture("_TarmacNormalTexture", null); material.SetFloat("_TarmacTileRandom", 0); } material.SetColor("_TarmacColor", tarmacColor); //Log.Normal("GC: Setting Texture to: " + grasTextureName); material.SetTexture("_BlendMaskTexture", blendMaskTexture); // third Texture (green) material.SetTexture("_ThirdTexture", thirdTexture); if (thirdTexture != null) { //material.SetTexture("_ThirdNormalTexture", KKGraphics.GetNormalMap(thirdTexture)); material.SetFloat("_ThirdTextureTileRandom", thirdTextureTileRandom ? 1f : 0); } else { //material.SetTexture("_ThirdNormalTexture", null); material.SetFloat("_ThirdTextureTileRandom", 0); } material.SetColor("_ThirdTextureColor", thirdTextureColor); material.SetFloat("_ThirdTextureTiling", thirdTextureTiling); // Fourth Texture (blue) material.SetTexture("_FourthTexture", fourthTexture); if (fourthTexture != null) { material.SetFloat("_FourthTextureTileRandom", fourthTextureTileRandom ? 1f : 0f); //material.SetTexture("_FourthNormalTexture", KKGraphics.GetNormalMap(fourthTexture)); } else { material.SetFloat("_FourthTextureTileRandom", 0); //material.SetTexture("_FourthNormalTexture", null); } material.SetColor("_FourthTextureColor", fourthTextureColor); material.SetFloat("_FourthTextureTiling", fourthTextureTiling); material.SetFloat("_NearGrassGrayScale", nearGrassTextureGray ? 1f : 0); material.SetFloat("_FarGrassGrayScale", farGrassTextureGray ? 1f : 0); material.SetFloat("_TarmacGrayScale", tarmacTextureGray ? 1f : 0); material.SetFloat("_ThirdTextureGrayScale", thirdTextureGray ? 1f : 0); material.SetFloat("_FourthTextureGrayScale", fourthTextureGray ? 1f : 0); } }