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); }
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]); } } } } } }