private static void LoadMapMeshes() { LoadMapTerrainInfo(); _modelMeshes = new Dictionary <int, Mesh[]>(); string objectsFolder = FFXIVHSPaths.GetTerritoryObjectsDirectory(territory); foreach (MapModel model in _map.models.Values) { if (DebugCustomLoad) { if (!debugCustomLoadList.Contains(model.id)) { continue; } } Mesh[] modelMeshes = new Mesh[model.numMeshes]; for (int i = 0; i < model.numMeshes; i++) { string meshFileName = string.Format("{0}{1}_{2}.obj", objectsFolder, model.modelName, i); modelMeshes[i] = FastObjImporter.Instance.ImportFile(meshFileName); } _modelMeshes.Add(model.id, modelMeshes); } Debug.Log("_modelMeshes loaded."); }
public static void WriteMap(ARealmReversed realm, TerritoryType teriType, SaintCoinach.Graphics.Territory teri = null) { string name = teri != null ? teri.Name : teriType.Name; //Plot.Ward ward = Plot.StringToWard(teriType.Name); string outdir = Path.Combine(FFXIVHSPaths.GetRootDirectory(), name + "\\"); string outpath = Path.Combine(outdir, name + ".json"); //string outpath = FFXIVHSPaths.GetWardJson(ward); if (!Directory.Exists(outdir)) { Directory.CreateDirectory(outdir); } if (File.Exists(outpath)) { WriteMapModels(realm, teriType, teri); return; } Map map = ReadTerritory(teriType, teri); string json = JsonConvert.SerializeObject(map, Formatting.Indented); File.WriteAllText(outpath, json); }
public static void WriteMapModels(ARealmReversed realm, TerritoryType teriType) { Territory territory = Plot.StringToWard(teriType.Name); string inpath = FFXIVHSPaths.GetTerritoryJson(territory); if (!File.Exists(inpath)) { throw new FileNotFoundException(); } string outpath = FFXIVHSPaths.GetTerritoryObjectsDirectory(territory); string json = File.ReadAllText(inpath); Map map = JsonConvert.DeserializeObject <Map>(json); foreach (MapModel model in map.models.Values) { if (realm.Packs.TryGetFile(model.modelPath, out SaintCoinach.IO.File f)) { ObjectFileWriter.WriteObjectFile(outpath, (ModelFile)f); } } }
public static void WriteOutHousingExteriorModels(ARealmReversed realm) { string inpath = FFXIVHSPaths.GetHousingExteriorJson(); if (!File.Exists(inpath)) { throw new FileNotFoundException(); } string outpath = FFXIVHSPaths.GetHousingExteriorObjectsDirectory(); string jsonText = File.ReadAllText(inpath); Dictionary <int, HousingExteriorFixture> fixtures = JsonConvert.DeserializeObject <Dictionary <int, HousingExteriorFixture> >(jsonText); foreach (HousingExteriorFixture fixture in fixtures.Values) { foreach (HousingExteriorFixtureVariant variant in fixture.variants) { foreach (HousingExteriorFixtureModel model in variant.models) { if (realm.Packs.TryGetFile(model.modelPath, out SaintCoinach.IO.File f)) { ObjectFileWriter.WriteObjectFile(outpath, (ModelFile)f); } } } } }
private static void LoadMapTerrainInfo() { string jsonText = File.ReadAllText(FFXIVHSPaths.GetTerritoryJson(territory)); _map = JsonConvert.DeserializeObject <Map>(jsonText); Debug.Log("_map loaded."); }
public static void WriteMapModels(ARealmReversed realm, TerritoryType teriType, SaintCoinach.Graphics.Territory teri = null) { string name = teri != null ? teri.Name : teriType.Name; //Plot.Ward ward = Plot.StringToWard(teriType.Name); string outpath = Path.Combine(FFXIVHSPaths.GetRootDirectory(), name, "objects\\"); string inpath = Path.Combine(FFXIVHSPaths.GetRootDirectory(), name + "\\", name + ".json"); if (!Directory.Exists(outpath)) { Directory.CreateDirectory(outpath); } //string inpath = FFXIVHSPaths.GetWardJson(ward); if (!File.Exists(inpath)) { throw new FileNotFoundException(); } //string outpath = FFXIVHSPaths.GetWardObjectsDirectory(ward); string json = File.ReadAllText(inpath); Map map = JsonConvert.DeserializeObject <Map>(json); foreach (MapModel model in map.models.Values) { if (realm.Packs.TryGetFile(model.modelPath, out SaintCoinach.IO.File f)) { ObjectFileWriter.WriteObjectFile(outpath, (ModelFile)f); } } }
private static Mesh[][][] GetMeshesForExteriorFixture(int fixtureId, ref FFXIVHSLib.Transform[][] transformsPerModel) { //A little different this time! if (_exteriorFixtureMeshes == null) { _exteriorFixtureMeshes = new Dictionary <int, Mesh[][][]>(); } if (_exteriorFixtureMeshTransforms == null) { _exteriorFixtureMeshTransforms = new Dictionary <int, FFXIVHSLib.Transform[][]>(); } Mesh[][][] modelMeshes; if (!_exteriorFixtureMeshes.TryGetValue(fixtureId, out modelMeshes)) { string exteriorHousingObjectsFolder = FFXIVHSPaths.GetHousingExteriorObjectsDirectory(); //Load the meshes if not found HousingExteriorFixture fixture = _exteriorFixtures[fixtureId]; //Initialize variants dimensions int numVariants = HousingExteriorFixture.GetVariants(fixture.fixtureType); modelMeshes = new Mesh[numVariants][][]; transformsPerModel = new FFXIVHSLib.Transform[numVariants][]; int i = 0; foreach (HousingExteriorFixtureVariant variant in fixture.variants) { //Initialize model dimensions for this variant int numModels = variant.models.Length; modelMeshes[i] = new Mesh[numModels][]; transformsPerModel[i] = new FFXIVHSLib.Transform[numModels]; int j = 0; foreach (HousingExteriorFixtureModel model in variant.models) { modelMeshes[i][j] = new Mesh[model.numMeshes]; transformsPerModel[i][j] = model.transform; for (int k = 0; k < model.numMeshes; k++) { string meshFileName = string.Format("{0}{1}_{2}.obj", exteriorHousingObjectsFolder, model.modelName, k); modelMeshes[i][j][k] = FastObjImporter.Instance.ImportFile(meshFileName); } j++; } i++; } _exteriorFixtureMeshes.Add(fixtureId, modelMeshes); _exteriorFixtureMeshTransforms.Add(fixtureId, transformsPerModel); } else { //If the meshes are in the dictionary, so are the transforms :p transformsPerModel = _exteriorFixtureMeshTransforms[fixtureId]; } return(modelMeshes); }
public static void WriteBlueprints(ARealmReversed realm) { HousingExteriorBlueprintSet blueprintSet = ReadExteriorBlueprintSet(realm); string outpath = FFXIVHSPaths.GetHousingExteriorBlueprintSetJson(); if (File.Exists(outpath)) { File.Delete(outpath); } string json = JsonConvert.SerializeObject(blueprintSet, Formatting.Indented); File.WriteAllText(outpath, json); }
public static void WriteOutHousingExteriorInfo(ARealmReversed realm) { string outpath = FFXIVHSPaths.GetHousingExteriorJson(); if (File.Exists(outpath)) { WriteOutHousingExteriorModels(realm); return; } Dictionary <int, HousingExteriorFixture> fixtures = ReadHousingExteriorSheet(realm); AddDefaultFences(realm, ref fixtures); string json = JsonConvert.SerializeObject(fixtures, Formatting.Indented); File.WriteAllText(outpath, json); }
public static void WriteOutWardInfo(ARealmReversed realm) { List <Plot> plots = new List <Plot>(); ReadLandSetSheet(realm, ref plots); ReadTerritoryPlots(realm, ref plots); string outpath = FFXIVHSPaths.GetWardInfoJson(); if (File.Exists(outpath)) { File.Delete(outpath); } string json = JsonConvert.SerializeObject(plots, Formatting.Indented); File.WriteAllText(outpath, json); }
public static void WriteMap(ARealmReversed realm, TerritoryType teriType) { Territory territory = Plot.StringToWard(teriType.Name); string outpath = FFXIVHSPaths.GetTerritoryJson(territory); if (File.Exists(outpath)) { WriteMapModels(realm, teriType); return; } Map map = ReadTerritory(teriType); string json = JsonConvert.SerializeObject(map, Formatting.Indented); File.WriteAllText(outpath, json); }
public MainWindow() { InitializeComponent(); realm = new ARealmReversed(FFXIVHSPaths.GetGameDirectory(), SaintCoinach.Ex.Language.English); if (!realm.IsCurrentVersion) { /* * MessageBox.Show("Game ver: " + realm.GameVersion + Environment.NewLine + * "Def ver: " + realm.DefinitionVersion + Environment.NewLine + * "Updating..."); * //realm.Update(true); * realm.Update(false); */ } TerritoryType[] territoryTypes = realm.GameData.GetSheet <TerritoryType>().ToArray(); foreach (TerritoryType t in territoryTypes) { if (!String.IsNullOrEmpty(t.PlaceName.ToString())) { byte intendedUse = (byte)t.GetRaw("TerritoryIntendedUse"); //Housing intended use column value is 13 //if (intendedUse == 13)// || intendedUse == 16 || intendedUse == 17) { relevantTerritories.Add(t); } //else if (intendedUse == 14) { //if (t.PlaceName.ToString().Contains("Private") || t.PlaceName.ToString().Contains("Apartment")) // relevantTerritories.Add(t); } } } amountLabel.Content = (String)amountLabel.Content + relevantTerritories.Count; placeBox.ItemsSource = relevantTerritories; placeBox.DisplayMemberPath = "PlaceName"; placeBox.SelectedValuePath = "."; }
private static void LoadExteriorBlueprints() { string jsonText = File.ReadAllText(FFXIVHSPaths.GetHousingExteriorBlueprintSetJson()); _blueprints = JsonConvert.DeserializeObject <HousingExteriorBlueprintSet>(jsonText); }
private static void LoadExteriorFixtures() { string jsonText = File.ReadAllText(FFXIVHSPaths.GetHousingExteriorJson()); _exteriorFixtures = JsonConvert.DeserializeObject <Dictionary <int, HousingExteriorFixture> >(jsonText); }
private static void LoadWardInfo() { string jsonText = File.ReadAllText(FFXIVHSPaths.GetWardInfoJson()); _wardInfo = JsonConvert.DeserializeObject <List <Plot> >(jsonText); }
/// <summary> /// Occurs second in the ward data output flow and reads all housing territories for their appropriate /// plot placeholders and calculates plot locations from them.<br /> /// /// This <i>would</i> be read from HousingMapMarkerInfo but the height values are incorrect there, /// and would mess up camera movement. X coordinates are negated due to the map reflection in Unity.<br /> /// /// This method takes a very long time due to Territory instantiation. /// </summary> private static void ReadTerritoryPlots(ARealmReversed realm, ref List <Plot> plots) { List <TerritoryType> housingTeriTypes = GetHousingTerritoryTypes(realm); WardSetting[] settings = JsonConvert.DeserializeObject <WardSetting[]>(File.ReadAllText(FFXIVHSPaths.GetWardSettingsJson())); foreach (TerritoryType tType in housingTeriTypes) { SaintCoinach.Graphics.Territory t = new SaintCoinach.Graphics.Territory(tType); LgbFile bg = null; //Get the ward's information from the wardsettings.json string groupName = "", plotName = "", subdivisionName = ""; foreach (WardSetting ws in settings) { if (ws.Territory.ToString() == t.Name.ToUpper()) { plotName = ws.plotName; groupName = ws.group; subdivisionName = ws.subdivisionSuffix + groupName; } } //We only care about bg.lgb for this territory foreach (LgbFile lgbFile in t.LgbFiles) { if (lgbFile.File.Path.EndsWith("bg.lgb")) { bg = lgbFile; } } if (bg != null) { //Define main and subdiv groups var mainGroup = bg.Groups .Where(_ => _.Name == groupName) .Select(_ => _); var subDivGroup = bg.Groups .Where(_ => _.Name == subdivisionName) .Select(_ => _); //Get main and subdiv plot lists and sort by index var mainPlotList = plots.Where(_ => _.ward.ToString() == t.Name.ToUpper()) .Where(_ => _.subdiv == false) .Select(_ => _).ToList(); var subdivPlotList = plots.Where(_ => _.ward.ToString() == t.Name.ToUpper()) .Where(_ => _.subdiv == true) .Select(_ => _).ToList(); mainPlotList.Sort((p1, p2) => p1.index.CompareTo(p2.index)); subdivPlotList.Sort((p1, p2) => p1.index.CompareTo(p2.index)); int plotIndex = 0; foreach (var lgbGroup in mainGroup.ToArray()) { foreach (var lgbGimmickEntry in lgbGroup.Entries.OfType <LgbGimmickEntry>()) { foreach (var sgbGroup in lgbGimmickEntry.Gimmick.Data.OfType <SgbGroup>()) { foreach (var modelEntry in sgbGroup.Entries.OfType <SgbModelEntry>()) { if (modelEntry.Model.Model.File.Path.Contains(plotName)) { //Position is in gimmick header, not transformedmodel SaintCoinach.Graphics.Vector3 position = lgbGimmickEntry.Header.Translation; SaintCoinach.Graphics.Vector3 rotation = lgbGimmickEntry.Header.Rotation; Vector3 pos = new Vector3(position.X * -1, position.Y, position.Z); Quaternion rot = new Vector3(rotation.X, rotation.Y, rotation.Z).ToQuaternion(); mainPlotList[plotIndex].position = pos; mainPlotList[plotIndex].rotation = rot; plotIndex++; } } } } } plotIndex = 0; foreach (var lgbGroup in subDivGroup.ToArray()) { foreach (var lgbGimmickEntry in lgbGroup.Entries.OfType <LgbGimmickEntry>()) { foreach (var sgbGroup in lgbGimmickEntry.Gimmick.Data.OfType <SgbGroup>()) { foreach (var modelEntry in sgbGroup.Entries.OfType <SgbModelEntry>()) { if (modelEntry.Model.Model.File.Path.Contains(plotName)) { //Position is in gimmick header, not transformedmodel SaintCoinach.Graphics.Vector3 position = lgbGimmickEntry.Header.Translation; SaintCoinach.Graphics.Vector3 rotation = lgbGimmickEntry.Header.Rotation; Vector3 pos = new Vector3(position.X * -1, position.Y, position.Z); Quaternion rot = new Vector3(rotation.X, rotation.Y, rotation.Z).ToQuaternion(); subdivPlotList[plotIndex].position = pos; subdivPlotList[plotIndex].rotation = rot; plotIndex++; } } } } } } } }
private static void LoadLandset() { if (!DebugLoadExteriors) { return; } if (_exteriorFixtures == null) { LoadExteriorFixtures(); } if (_blueprints == null) { LoadExteriorBlueprints(); } string landSetPath = FFXIVHSPaths.GetWardLandsetJson(territory); if (!File.Exists(landSetPath)) { //Main and subdivision, 60 plots _landSet = new HousingExteriorStructure[60]; for (int i = 0; i < _landSet.Length; i++) { _landSet[i] = new HousingExteriorStructure(); int numFixtureTypes = Enum.GetValues(typeof(FixtureType)).Length; _landSet[i].fixtures = new int[numFixtureTypes]; } string jsonText = JsonConvert.SerializeObject(_landSet, Formatting.Indented); File.WriteAllText(landSetPath, jsonText); } else { string jsonText = File.ReadAllText(landSetPath); _landSet = JsonConvert.DeserializeObject <HousingExteriorStructure[]>(jsonText); } //TODO: move this, rewrite this ? for (int plotIndex = 0; plotIndex < _landSet.Length; plotIndex++) { Plot plotAt = GetPlot(_territory, plotIndex % 30 + 1, plotIndex > 29); if (_landSet[plotIndex].size == Size.s) { //Verify possibly unset size _landSet[plotIndex].size = plotAt.size; } if (_landSet[plotIndex].fixtures[(int)FixtureType.fnc - 1] == 0) { _landSet[plotIndex].fixtures[(int)FixtureType.fnc - 1] = DefaultFences.fnc[(int)_territory]; } HousingExteriorBlueprint blueprint = _blueprints.set[(int)_landSet[plotIndex].size]; //TODO: If you ever figure out how to tell which transforms are for which house size, fix this string groupName = "{0}_{1:D2}_{2}_house"; string fixedWardName = _territory.ToString().ToLower().Substring(0, _territory.ToString().Length - 1) + '0'; string strSize = _landSet[plotIndex].size.ToString(); groupName = string.Format(groupName, fixedWardName, plotIndex + 1, strSize); Debug.Log(groupName); GameObject parentPlotObject = GameObject.Find(groupName); //For each fixture in our landset element for (int fixtureIndex = 0; fixtureIndex < _landSet[plotIndex].fixtures.Length; fixtureIndex++) { if (_landSet[plotIndex].fixtures[fixtureIndex] == 0) { continue; } FixtureType fixtureType = (FixtureType)fixtureIndex + 1; FFXIVHSLib.Transform[][] transformsForModels = null; Mesh[][][] meshes = GetMeshesForExteriorFixture(_landSet[plotIndex].fixtures[fixtureIndex], ref transformsForModels); //For each variant for (int variantIndex = 0; variantIndex < meshes.Length; variantIndex++) { if (blueprint.fixtureTransforms[fixtureType][variantIndex] == null || meshes[variantIndex] == null) { continue; } //The set of gameobjects for this variant, 1 gameobject per model GameObject[] objects = new GameObject[meshes[variantIndex].Length]; for (int modelIndex = 0; modelIndex < objects.Length; modelIndex++) { objects[modelIndex] = AddMeshToNewGameObject(meshes[variantIndex][modelIndex]); } foreach (FFXIVHSLib.Transform t in blueprint.fixtureTransforms[fixtureType][variantIndex]) { GameObject variantBaseObject = new GameObject(); variantBaseObject.GetComponent <Transform>().SetParent(parentPlotObject.transform); variantBaseObject.GetComponent <Transform>().localPosition = t.translation; variantBaseObject.GetComponent <Transform>().localRotation = t.rotation; variantBaseObject.GetComponent <Transform>().localScale = t.scale; variantBaseObject.name = string.Format("bp{0}_ft{1}_v{2}", _landSet[plotIndex].size, fixtureType, variantIndex); for (int modelIndex = 0; modelIndex < objects.Length; modelIndex++) { if (objects[modelIndex] == null) { continue; } FFXIVHSLib.Transform modelTransform = transformsForModels[variantIndex][modelIndex]; GameObject addedModel = UnityEngine.Object.Instantiate(objects[modelIndex]); addedModel.GetComponent <Transform>().SetParent(variantBaseObject.GetComponent <Transform>()); addedModel.GetComponent <Transform>().localPosition = modelTransform.translation; addedModel.GetComponent <Transform>().localRotation = modelTransform.rotation; addedModel.GetComponent <Transform>().localScale = modelTransform.scale; addedModel.name = addedModel.name.Replace("(Clone)", "_") + string.Format("{0}_{1}_{2}", fixtureIndex, variantIndex, modelIndex); addedModel.SetActive(true); UnityEngine.Object.Destroy(objects[modelIndex]); } } } } } }