internal static void LoadAllMapDecalMaps() { UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("KK_DecalsMap"); foreach (UrlDir.UrlConfig conf in configs) { //create new Instance and Register in Database MapDecalsMap newMapDecalInstance = ScriptableObject.CreateInstance <MapDecalsMap>(); // Load Settings into instance ParseDecalsMapConfig(newMapDecalInstance, conf.config); newMapDecalInstance.path = Path.GetDirectoryName(Path.GetDirectoryName(conf.url)); newMapDecalInstance.mapTexture = KKGraphics.GetTexture(newMapDecalInstance.path + "/" + newMapDecalInstance.Image, false); if (newMapDecalInstance.mapTexture == null) { Log.UserError("Image File " + newMapDecalInstance.path + "/" + newMapDecalInstance.Image + " could not be loaded"); continue; } if (newMapDecalInstance.UseAsHeighMap) { newMapDecalInstance.CreateMap(MapSO.MapDepth.Greyscale, newMapDecalInstance.mapTexture); newMapDecalInstance.isHeightMap = true; } else { newMapDecalInstance.CreateMap(MapSO.MapDepth.RGBA, newMapDecalInstance.mapTexture); } //Log.Normal("DecalsMap " + newMapDecalInstance.Name + " imported: " + (newMapDecalInstance.isHeightMap? "as HeighMap" : "as ColorMap")); newMapDecalInstance.map = newMapDecalInstance as MapSO; DecalsDatabase.RegisterMap(newMapDecalInstance); } }
/// <summary> /// constructor /// </summary> internal MapDecalInstance() { gameObject = new GameObject(); mapDecal = gameObject.AddComponent <PQSMod_MapDecal>(); Name = "KK_MapDecal_" + DecalsDatabase.allMapDecalInstances.Length.ToString(); mapDecal.radius = 0; DecalsDatabase.RegisterMapDecalInstance(this); }
// /// <summary> /// Updates the static instance with new settings /// </summary> public void Update(bool doUpdate = true) { mapDecal.heightMap = DecalsDatabase.GetHeightMapByName(HeightMapName).map; mapDecal.colorMap = DecalsDatabase.GetColorMapByName(ColorMapName).map; if (mapDecal.heightMap == null && mapDecal.colorMap == null) { //DecalsDatabase.DeleteMapDecalInstance(this); return; } mapDecal.modEnabled = true; mapDecal.requirements = PQS.ModiferRequirements.MeshColorChannel | PQS.ModiferRequirements.MeshCustomNormals; mapDecal.order = Order; mapDecal.sphere = CelestialBody.pqsController; mapDecal.transform.parent = CelestialBody.pqsController.transform; mapDecal.position = CelestialBody.GetRelSurfaceNVector(Latitude, Longitude).normalized *CelestialBody.Radius; mapDecal.absolute = UseAbsolut; mapDecal.absoluteOffset = AbsolutOffset; mapDecal.radius = Radius; mapDecal.angle = Angle; mapDecal.removeScatter = RemoveScatter; mapDecal.smoothHeight = SmoothHeight; mapDecal.heightMapDeformity = HeightMapDeformity; mapDecal.useAlphaHeightSmoothing = UseAlphaHeightSmoothing; mapDecal.cullBlack = CullBlack; mapDecal.smoothColor = SmoothColor; //Log.Normal("MapDecal: heightmap: " + mapDecal.heightMap.name); //Log.Normal("MapDecal: Radius: " + Radius.ToString()); //Log.Normal("MapDecal: Vector: " + mapDecal.position.ToString()); //Log.Normal("MapDecal: Offset: " + AbsolutOffset); //Log.Normal("MapDecal: UseABS: " + UseAbsolut.ToString()); mapDecal.OnSetup(); // only rebuild the sphere when we use the editor if (doUpdate) { mapDecal.sphere.ForceStart(); } }
/// <summary> /// Loads all KK_MAPDecals and places them on the planets /// </summary> internal static void LoadAllMapDecals() { UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("KK_MapDecal"); foreach (UrlDir.UrlConfig conf in configs) { //create new Instance and Register in Database MapDecalInstance newMapDecalInstance = new MapDecalInstance(); // Load Settings into instance ConfigParser.ParseMapDecalConfig(newMapDecalInstance, conf.config); // set the configpath for saving newMapDecalInstance.configPath = conf.url.Substring(0, conf.url.LastIndexOf('/')) + ".cfg"; } HashSet <CelestialBody> bodies2Update = new HashSet <CelestialBody>(); // remove all instances where no planet was assigned foreach (MapDecalInstance instance in DecalsDatabase.allMapDecalInstances) { if (instance.CelestialBody == null) { Log.Normal("No valid CelestialBody found: removing MapDecal instance " + instance.configPath); DecalsDatabase.DeleteMapDecalInstance(instance); continue; } else { //Log.Normal("Loaded MapDecal instance " + instance.Name); if (!bodies2Update.Contains(instance.CelestialBody)) { bodies2Update.Add(instance.CelestialBody); } instance.mapDecal.transform.position = instance.CelestialBody.GetWorldSurfacePosition(instance.Latitude, instance.Longitude, instance.AbsolutOffset); instance.mapDecal.transform.up = instance.CelestialBody.GetSurfaceNVector(instance.Latitude, instance.Longitude); instance.Update(false); instance.Group = DecalsDatabase.GetCloesedCenter(instance.mapDecal.transform.position).Group; } } // Rebuild spheres on all plants with new MapDecals foreach (CelestialBody body in bodies2Update) { Log.Normal("Rebuilding PQS sphere on: " + body.name); body.pqsController.RebuildSphere(); } }
internal static void ExportPQSMapDecals() { string basePath = KSPUtil.ApplicationRootPath + "GameData/KerbalKonstructs/ExportedInstances/" + exportTime; foreach (MapDecalInstance mapDecalInstance in DecalsDatabase.allMapDecalInstances) { mapDecalInstance.Group = DecalsDatabase.GetCloesedCenter(mapDecalInstance.gameObject.transform.position).Group; if (!System.IO.Directory.Exists(basePath + mapDecalInstance.Group)) { System.IO.Directory.CreateDirectory(basePath + mapDecalInstance.Group); } ConfigNode masterNode = new ConfigNode(""); ConfigNode instanceNode = new ConfigNode("KK_MapDecal"); WriteMapDecalConfig(mapDecalInstance, instanceNode); masterNode.AddNode(instanceNode); masterNode.Save(basePath + mapDecalInstance.Group + "/" + mapDecalInstance.Name + "_PQSDecal.cfg", "Generated by Kerbal Konstructs"); } }
internal static void GetSquadMaps() { MapDecalsMap noHeighmap = ScriptableObject.CreateInstance <MapDecalsMap>(); noHeighmap.map = null; noHeighmap.isHeightMap = true; noHeighmap.Name = "None"; MapDecalsMap noColormap = ScriptableObject.CreateInstance <MapDecalsMap>(); noColormap.map = null; noColormap.isHeightMap = false; noColormap.Name = "None"; DecalsDatabase.RegisterMap(noHeighmap); DecalsDatabase.RegisterMap(noColormap); PQSMod_MapDecal[] allMapDecals = Resources.FindObjectsOfTypeAll <PQSMod_MapDecal>(); foreach (var mapDecal in allMapDecals) { //Log.Normal(""); // Log.Normal("Stats for: " + mapDecal.name); if (mapDecal.heightMap != null) { MapDecalsMap heightMap = ScriptableObject.CreateInstance <MapDecalsMap>(); heightMap.isHeightMap = true; heightMap.map = mapDecal.heightMap; heightMap.Name = "height_" + mapDecal.name; DecalsDatabase.RegisterMap(heightMap); // Log.Normal("MapDecal: heightmap: " + mapDecal.heightMap.name); } if (mapDecal.colorMap != null) { MapDecalsMap colorMap = ScriptableObject.CreateInstance <MapDecalsMap>(); colorMap.isHeightMap = false; colorMap.map = mapDecal.colorMap; colorMap.Name = "color_" + mapDecal.name; DecalsDatabase.RegisterMap(colorMap); // Log.Normal("MapDecal: colormap: " + mapDecal.colorMap.name); } //Log.Normal("MapDecal: Radius: " + mapDecal.radius.ToString()); //Log.Normal("MapDecal: Vector: " + mapDecal.position.ToString()); //Log.Normal("MapDecal: Offset: " + mapDecal.absoluteOffset); //Log.Normal("MapDecal: UseABS: " + mapDecal.absolute.ToString()); //Log.Normal("MapDecal: Heightmapdeformity: " + mapDecal.heightMapDeformity.ToString()); //Log.Normal("MapDecal: modisenabled " + mapDecal.modEnabled.ToString()); //Log.Normal("MapDecal: order: " + mapDecal.order.ToString()); //Log.Normal("MapDecal: requirement: " + mapDecal.requirements.ToString()); //Log.Normal("MapDecal: smoothcolor: " + mapDecal.smoothColor.ToString()); //Log.Normal("MapDecal: smoothhheight: " + mapDecal.smoothHeight.ToString()); //if (mapDecal.sphere != null ) // Log.Normal("MapDecal: sphere: " + mapDecal.sphere.name.ToString()); //Log.Normal("MapDecal: Alphaheight: " + mapDecal.useAlphaHeightSmoothing.ToString()); //Log.Normal("MapDecal: Cullblack: " + mapDecal.cullBlack.ToString()); } PQSMod_MapDecalTangent[] allMapDecalTangents = Resources.FindObjectsOfTypeAll <PQSMod_MapDecalTangent>(); foreach (var mapDecal in allMapDecalTangents) { //Log.Normal(""); //Log.Normal("Stats for: " + mapDecal.name); if (mapDecal.heightMap != null) { MapDecalsMap heightMap = ScriptableObject.CreateInstance <MapDecalsMap>(); heightMap.isHeightMap = true; heightMap.map = mapDecal.heightMap; heightMap.Name = "height_" + mapDecal.name; DecalsDatabase.RegisterMap(heightMap); //Log.Normal("MapDecalTGT: heightmap: " + mapDecal.heightMap.name); } if (mapDecal.colorMap != null) { MapDecalsMap colorMap = ScriptableObject.CreateInstance <MapDecalsMap>(); colorMap.isHeightMap = false; colorMap.map = mapDecal.colorMap; colorMap.Name = "color_" + mapDecal.name; DecalsDatabase.RegisterMap(colorMap); //Log.Normal("MapDecalTGT: colormap: " + mapDecal.colorMap.name); } //Log.Normal("MapDecalTGT: Radius: " + mapDecal.radius.ToString()); //Log.Normal("MapDecalTGT: Vector: " + mapDecal.position.ToString()); //Log.Normal("MapDecalTGT: Offset: " + mapDecal.absoluteOffset); //Log.Normal("MapDecalTGT: UseABS: " + mapDecal.absolute.ToString()); //Log.Normal("MapDecalTGT: Heightmapdeformity: " + mapDecal.heightMapDeformity.ToString()); //Log.Normal("MapDecalTGT: modisenabled: " + mapDecal.modEnabled.ToString()); //Log.Normal("MapDecalTGT: order: " + mapDecal.order.ToString()); //Log.Normal("MapDecalTGT: requirement: " + mapDecal.requirements.ToString()); //Log.Normal("MapDecalTGT: smoothcolor: " + mapDecal.smoothColor.ToString()); //Log.Normal("MapDecalTGT: smoothhheight: " + mapDecal.smoothHeight.ToString()); //if (mapDecal.sphere != null) // Log.Normal("MapDecalTGT: sphere: " + mapDecal.sphere.name.ToString()); //Log.Normal("MapDecalTGT: Alphaheight: " + mapDecal.useAlphaHeightSmoothing.ToString()); //Log.Normal("MapDecalTGT: Cullblack: " + mapDecal.cullBlack.ToString()); } Log.Normal("Imported " + (DecalsDatabase.allHeightMaps.Count + DecalsDatabase.allColorMaps.Count) + " Maps from around the universe"); //foreach (var map in DecalsDatabase.allDecalMaps) //{ // Log.Normal("DecalMap: " + map.name); //} }