public static void Merge(Ytyp[] ytypfiles, Ymap[] ymapfiles) { if (ytypfiles != null && ytypfiles.Length != 0) { Ytyp.Merge(ytypfiles).WriteXML().Save("merged.ytyp.xml"); Console.WriteLine("Exported merged.ytyp.xml"); } if (ymapfiles != null && ymapfiles.Length != 0) { Ymap.Merge(ymapfiles).WriteXML().Save("merged.ymap.xml"); Console.WriteLine("Exported merged.ymap.xml"); } }
public static void RemoveFromList(Ytyp[] ytypfiles, Ymap[] ymapfiles) { List <string> removelist = new List <string>(); Console.WriteLine("Insert the file to load names from: (ex. list.txt)"); string filename = Console.ReadLine(); using (StreamReader reader = new StreamReader(filename)) { string line; while ((line = reader.ReadLine()) != null) { removelist.Add(line.Trim().ToLower()); } } if (ytypfiles != null && ytypfiles.Length != 0) { for (int i = 0; i < ytypfiles.Length; i++) { List <CBaseArchetypeDef> removed_archetypes = ytypfiles[i].RemoveArchetypesByNames(removelist); ytypfiles[i].WriteXML().Save(ytypfiles[i].filename); Console.WriteLine("Updated " + (ytypfiles[i].filename)); Ytyp removedytyp = ytypfiles[i]; removedytyp.CMapTypes.archetypes = removed_archetypes; removedytyp.WriteXML().Save(ytypfiles[i].filename.Split('.')[0] + "_removed.ytyp.xml"); Console.WriteLine("Exported {0}_removed.ytyp.xml", ytypfiles[i].filename.Split('.')[0]); } } if (ymapfiles != null && ymapfiles.Length != 0) { for (int i = 0; i < ymapfiles.Length; i++) { List <CEntityDef> removed_entities = ymapfiles[i].RemoveEntitiesByNames(removelist); ymapfiles[i].WriteXML().Save(ymapfiles[i].filename); Console.WriteLine("Updated " + (ymapfiles[i].filename)); Ymap removedymap = ymapfiles[i]; removedymap.CMapData.entities = removed_entities; removedymap.WriteXML().Save(ymapfiles[i].filename.Split('.')[0] + "_removed.ymap.xml"); Console.WriteLine("Exported {0}_removed.ymap.xml", ymapfiles[i].filename.Split('.')[0]); } } }
//TEMP public static void GenerateMLO(string ytyppath, string ymappath) { Console.WriteLine("Insert the name for the MLO:"); string mloname = Console.ReadLine(); Ytyp theytyp = new Ytyp(XDocument.Load(ytyppath), mloname); Ymap theymap = new Ymap(XDocument.Load(ymappath), mloname); if (theytyp != null && theymap != null) { CMloInstanceDef mloent = new CMloInstanceDef(mloname); CMloArchetypeDef mloarc = new CMloArchetypeDef(mloname); //COPY VALUES mloarc.entities = theymap.CMapData.entities; mloarc.lodDist = theytyp.CMapTypes.archetypes.Max(arc => arc.lodDist); mloarc.hdTextureDist = theytyp.CMapTypes.archetypes.Max(arc => arc.hdTextureDist); mloent.lodDist = theymap.CMapData.entities.Max(ent => ent.lodDist); //GET CENTROID OF ENTITIES AND USE IT AS MLO POSITION foreach (CEntityDef ent in theymap.CMapData.entities) { mloent.position += ent.position; } mloent.position = mloent.position / theymap.CMapData.entities.Count; //CHANGE COORDSYSTEM TO PARENT'S ONE foreach (CEntityDef ent in mloarc.entities) { ent.position = ent.position - mloent.position; } //WEIRD WAY OF SAVING BECAUSE I'M ACTUALLY TOO BORED TO FIX ALL THE CODE TO SUPPORT MLO :DDDDDDDDDDD theytyp.CMapTypes.name = mloname; XDocument doc = theytyp.WriteXML(); doc.Element("CMapTypes").Element("archetypes").Add(mloarc.WriteXML()); doc.Save(mloname + ".ytyp.xml"); Console.WriteLine(mloname + ".ytyp.xml"); theymap.CMapData.name = mloname; theymap.CMapData.entities = new List <CEntityDef>(); doc = theymap.WriteXML(); doc.Element("CMapData").Element("entities").Add(mloent.WriteXML()); doc.Save(mloname + ".ymap.xml"); Console.WriteLine(mloname + ".ymap.xml"); } }
public static Ymap[] CollectYmaps(DirectoryInfo dir) { Ymap[] ymaps = null; FileInfo[] files = dir.GetFiles("*.ymap.xml"); if (files.Length == 0) { Console.WriteLine("No .ymap.xml file found."); } else { ymaps = new Ymap[files.Length]; for (int i = 0; i < files.Length; i++) { ymaps[i] = new Ymap(XDocument.Load(files[i].Name), files[i].Name); } } return(ymaps); }
public static void BatchesFromParticles() { List <float[]> particlesInfo = new List <float[]>(); Console.WriteLine("Insert the name of the file to load"); string filepath = Console.ReadLine(); float posXmax = float.MinValue; float posXmin = float.MaxValue; float posYmax = float.MinValue; float posYmin = float.MaxValue; float posZmax = float.MinValue; float posZmin = float.MaxValue; BinaryReader reader = new BinaryReader(File.OpenRead(filepath)); while (reader.BaseStream.Position != reader.BaseStream.Length) { float posx = reader.ReadSingle(); float posy = reader.ReadSingle(); float posz = reader.ReadSingle(); float dirx = reader.ReadSingle(); float diry = reader.ReadSingle(); float[] pInfo = new float[5] { posx, posy, posz, dirx, diry }; //Console.WriteLine("POS: {0},{1},{2} DIR:{3},{4}", posx, posy, posz, dirx, diry); particlesInfo.Add(pInfo); posXmax = Math.Max(posXmax, posx); posXmin = Math.Min(posXmin, posx); posYmax = Math.Max(posYmax, posy); posYmin = Math.Min(posYmin, posy); posZmax = Math.Max(posZmax, posz); posZmin = Math.Min(posZmin, posz); } reader.Close(); if (particlesInfo == null || !particlesInfo.Any()) { return; } Random rnd = new Random(); List <string> archetypes = new List <string>() { "proc_brittlebush_01", "proc_desert_sage_01", "proc_drygrasses01", "proc_drygrasses01b", "proc_drygrassfronds01", "proc_dryplantsgrass_01", "proc_dryplantsgrass_02", "proc_dry_plants_01", "proc_forest_grass01", "proc_forest_ivy_01", "proc_grassdandelion01", "proc_grasses01", "proc_grasses01b", "proc_grassfronds01", "proc_grassplantmix_01", "proc_grassplantmix_02", "proc_indian_pbrush_01", "proc_leafybush_01", "proc_leafyplant_01", "proc_lizardtail_01", "proc_lupins_01", "proc_meadowmix_01", "proc_meadowpoppy_01", "proc_sage_01", "proc_scrub_bush01", "proc_sml_reeds_01", "proc_sml_reeds_01b", "proc_sml_reeds_01c", "proc_stones_01", "proc_stones_02", "proc_stones_03", "proc_stones_04", "proc_stones_05", "proc_stones_06", "proc_wildquinine", "prop_dandy_b", "prop_dryweed_001_a", "prop_dryweed_002_a", "prop_fernba", "prop_fernbb", "prop_flowerweed_005_a", "prop_grass_001_a", "prop_grass_ca", "prop_grass_da", "prop_log_aa", "prop_log_ab", "prop_log_ac", "prop_log_ad", "prop_log_ae", "prop_log_af", "prop_saplin_001_b", "prop_saplin_001_c", "prop_saplin_002_b", "prop_saplin_002_c", "prop_small_bushyba", "prop_tall_drygrass_aa", "prop_tall_grass_ba", "prop_thindesertfiller_aa", "prop_weed_001_aa", "prop_weed_002_ba", "urbandryfrnds_01", "urbandrygrass_01", "urbangrnfrnds_01", "urbangrngrass_01", "urbanweeds01", "urbanweeds01_l1", "urbanweeds02", "urbanweeds02_l1" }; string archetype = archetypes[rnd.Next(0, archetypes.Count() - 1)]; Vector3 batchSize = new Vector3(100, 100, 75); Vector3 bbmax = new Vector3(posXmax, posYmax, posZmax); Vector3 bbmin = new Vector3(posXmin, posYmin, posZmin); Vector3 numblocks = (bbmax - bbmin) / batchSize; //Console.WriteLine("{0},{1},{2}",numblocks.X,numblocks.Y,numblocks.Z); int blockX = (int)(numblocks.X + 1); int blockY = (int)(numblocks.Y + 1); int blockZ = (int)(numblocks.Z + 1); Ymap map = new Ymap("instancedData"); map.CMapData.contentFlags = 1088; map.CMapData.physicsDictionaries.Add("v_proc1"); for (int x = -blockX; x <= blockX; x++) { for (int y = -blockY; y <= blockY; y++) { for (int z = -blockZ; z <= blockZ; z++) { IEnumerable <float[]> currentBatch = Enumerable.Empty <float[]>(); float maxX = (x + 1) * batchSize.X; float minX = x * batchSize.X; float maxY = (y + 1) * batchSize.Y; float minY = y * batchSize.Y; float maxZ = (z + 1) * batchSize.Z; float minZ = z * batchSize.Z; ///Console.WriteLine("maxX:{0},minX{1},maxY{2},minY{3},maxZ{4},minZ{5}",maxX,minX,maxY,minY,maxZ,minZ); currentBatch = particlesInfo.Where(a => a[0] < maxX && a[0] >= minX && a[1] < maxY && a[1] >= minY && a[2] < maxZ && a[2] >= minZ).ToList(); // Console.WriteLine(currentBatch.Count()); if (currentBatch?.Any() ?? false) { BatchAABB aabb = new BatchAABB(new Vector4(minX, minY, minZ, 0), new Vector4(maxX, maxY, maxZ, 0)); GrassInstance grassBatch = new GrassInstance(archetype); grassBatch.BatchAABB = aabb; foreach (float[] inst in currentBatch) { Vector4 worldPos = new Vector4(inst[0], inst[1], inst[2], 0); Vector4 batchPos = (worldPos - aabb.min) / (aabb.max - aabb.min) * 65535; byte NormalX = (byte)((inst[3] + 1) * 0.5 * 255); byte NormalY = (byte)((inst[4] + 1) * 0.5 * 255); byte[] color = new byte[3] { 150, 150, 150 }; byte scale = (byte)rnd.Next(0, 255);; Instance i = new Instance(new ushort[] { (ushort)batchPos.X, (ushort)batchPos.Y, (ushort)batchPos.Z }, NormalX, NormalY, color, scale); grassBatch.InstanceList.Add(i); } map.CMapData.instancedData.GrassInstanceList.Add(grassBatch); } } } } map.UpdateExtents(new List <CBaseArchetypeDef>()); Console.WriteLine("Total batches: {0}", map.CMapData.instancedData.GrassInstanceList.Count); Console.WriteLine("Total instances: {0}", particlesInfo.Count); map.WriteXML().Save("grass.ymap.xml"); Console.WriteLine("Exported grass.ymap.xml"); }
public static void ConvertJson(FivemJson[] jsonfiles) { if (jsonfiles == null || jsonfiles.Length <= 0) { return; } Ytyp[] ytypfiles = new Ytyp[jsonfiles.Length]; Ymap[] ymapfiles = new Ymap[jsonfiles.Length]; for (int i = 0; i < jsonfiles.Length; i++) { ytypfiles[i] = new Ytyp(jsonfiles[i].filename.Replace(".json", ".ytyp.xml")); ytypfiles[i].CMapTypes.name = jsonfiles[i].filename.Replace(".json", ""); List <CBaseArchetypeDef> unresolved_arc = new List <CBaseArchetypeDef>(); foreach (FivemArchetype a in jsonfiles[i].archetypes) { CBaseArchetypeDef arc = new CBaseArchetypeDef(); //arc.lodDist = 0; arc.flags = 0; arc.specialAttribute = 0; arc.bbMin = a.aabbMin; arc.bbMax = a.aabbMax; arc.bsCentre = a.centroid; arc.bsRadius = a.radius; //arc.hdTextureDist = 0; arc.name = a.archetypeName; arc.textureDictionary = a.txdName; arc.clipDictionary = null; arc.drawableDictionary = null; arc.physicsDictionary = a.archetypeName; arc.assetType = assetType.ASSET_TYPE_DRAWABLE; arc.assetName = a.archetypeName; arc.extensions = null; arc.lodDist = 100 + (1.5f * arc.bsRadius); arc.hdTextureDist = 0.75f * arc.lodDist; if (a.archetypeName.StartsWith("0x") || a.txdName.StartsWith("0x")) { unresolved_arc.Add(arc); } else { ytypfiles[i].CMapTypes.archetypes.Add(arc); } } ymapfiles[i] = new Ymap(jsonfiles[i].filename.Replace(".json", ".ymap.xml")); ymapfiles[i].CMapData.name = jsonfiles[i].filename.Replace(".json", ""); Random rnd = new Random(); List <CEntityDef> unresolved_ent = new List <CEntityDef>(); foreach (FivemEntity e in jsonfiles[i].entities) { CEntityDef ent = new CEntityDef(); ent.archetypeName = e.archetypeName; ent.flags = 0; ent.guid = (uint)rnd.Next(); ent.position = e.position; ent.rotation = e.rotation; ent.scaleXY = 1; ent.scaleZ = 1; ent.parentIndex = -1; ent.lodDist = 100; ent.childLodDist = 0; ent.lodLevel = lodLevel.LODTYPES_DEPTH_ORPHANHD; ent.numChildren = 0; ent.priorityLevel = priorityLevel.PRI_REQUIRED; ent.extensions = null; ent.ambientOcclusionMultiplier = 255; ent.artificialAmbientOcclusion = 255; ent.tintValue = 0; if (e.archetypeName.StartsWith("0x")) { unresolved_ent.Add(ent); } else { ymapfiles[i].CMapData.entities.Add(ent); } } ymapfiles[i].UpdatelodDist(ytypfiles[i].CMapTypes.archetypes); ymapfiles[i].UpdateExtents(ytypfiles[i].CMapTypes.archetypes); ytypfiles[i].WriteXML().Save(ytypfiles[i].filename); Console.WriteLine("Saved " + ytypfiles[i].filename); ymapfiles[i].WriteXML().Save(ymapfiles[i].filename); Console.WriteLine("Saved " + ymapfiles[i].filename); if (unresolved_arc?.Any() ?? false) { string unresolvedname = ytypfiles[i].CMapTypes.name + "_unresolved"; ytypfiles[i].CMapTypes.archetypes = unresolved_arc; ytypfiles[i].CMapTypes.name = unresolvedname; ytypfiles[i].WriteXML().Save(unresolvedname + ".ymap.xml"); Console.WriteLine("Saved " + unresolvedname + ".ymap.xml"); } if (unresolved_ent?.Any() ?? false) { string unresolvedname = ymapfiles[i].CMapData.name + "_unresolved"; ymapfiles[i].CMapData.entities = unresolved_ent; ymapfiles[i].CMapData.name = unresolvedname; ymapfiles[i].WriteXML().Save(unresolvedname + ".ymap.xml"); Console.WriteLine("Saved " + unresolvedname + ".ymap.xml"); } } }