diff --git a/Charm/ActivityMapEntityView.xaml.cs b/Charm/ActivityMapEntityView.xaml.cs index 3fe3ad99..204fea7f 100644 --- a/Charm/ActivityMapEntityView.xaml.cs +++ b/Charm/ActivityMapEntityView.xaml.cs @@ -350,10 +350,9 @@ public static void ExportFull(List dataTables, string hash) private static void ExtractDataTables(List dataTables, string hash, string savePath) { // todo these scenes can be combined - ExporterScene dynamicPointScene = Exporter.Get().CreateScene($"{hash}_EntityPoints", ExportType.EntityPoints); - ExporterScene dynamicScene = Exporter.Get().CreateScene($"{hash}_Entities", ExportType.Map); - ExporterScene skyScene = Exporter.Get().CreateScene($"{hash}_SkyEnts", ExportType.Map); - ExporterScene terrainScene = Exporter.Get().CreateScene($"{hash}_Terrain", ExportType.Terrain); + ExporterScene dynamicScene = Exporter.Get().CreateScene($"{hash}_Entities", ExportType.MapResource); + ExporterScene skyScene = Exporter.Get().CreateScene($"{hash}_SkyEnts", ExportType.MapResource); + ExporterScene terrainScene = Exporter.Get().CreateScene($"{hash}_Terrain", ExportType.MapResource); Parallel.ForEach(dataTables, data => { @@ -366,8 +365,6 @@ private static void ExtractDataTables(List dataTables, string hash, st dynamicScene.AddMapEntity(entry, entity); entity.SaveMaterialsFromParts(dynamicScene, entity.Load(ExportDetailLevel.MostDetailed)); } - else - dynamicPointScene.AddEntityPoints(entry); switch (entry.DataResource.GetValue(dataTable.GetReader())) { @@ -428,7 +425,7 @@ private static void ExtractDataTables(List dataTables, string hash, st } break; case SMapTerrainResource terrain: - terrain.Terrain.LoadIntoExporter(terrainScene, savePath, _config.GetSBoxShaderExportEnabled()); + terrain.Terrain.LoadIntoExporter(terrainScene, savePath); break; default: break; @@ -451,10 +448,7 @@ private static void ExportIndividual(List dataTables, string hash, str dynamicScene.AddEntity(entry.GetEntityHash(), entity.Load(ExportDetailLevel.MostDetailed), entity.Skeleton?.GetBoneNodes()); entity.SaveMaterialsFromParts(dynamicScene, entity.Load(ExportDetailLevel.MostDetailed)); - if (_config.GetSBoxModelExportEnabled()) - { - SBoxHandler.SaveEntityVMDL($"{savePath}/Entities", entity); - } + SBoxHandler.SaveEntityVMDL($"{savePath}/Entities", entity); } if (entry.DataResource.GetValue(dataTable.GetReader()) is SMapSkyEntResource skyResource) { @@ -466,16 +460,13 @@ private static void ExportIndividual(List dataTables, string hash, str ExporterScene skyScene = Exporter.Get().CreateScene(element.Unk60.TagData.Unk08.Hash, ExportType.EntityInMap); skyScene.AddModel(element.Unk60.TagData.Unk08); - if (_config.GetSBoxModelExportEnabled()) - { - SBoxHandler.SaveEntityVMDL($"{savePath}/Entities", element.Unk60.TagData.Unk08.Hash, element.Unk60.TagData.Unk08.Load(ExportDetailLevel.MostDetailed, null)); - } + SBoxHandler.SaveEntityVMDL($"{savePath}/Entities", element.Unk60.TagData.Unk08.Hash, element.Unk60.TagData.Unk08.Load(ExportDetailLevel.MostDetailed, null)); } } if (entry.DataResource.GetValue(dataTable.GetReader()) is SMapTerrainResource terrainArrangement) { ExporterScene staticScene = Exporter.Get().CreateScene($"{terrainArrangement.Terrain.Hash}_Terrain", ExportType.StaticInMap); - terrainArrangement.Terrain.LoadIntoExporter(staticScene, savePath, _config.GetSBoxShaderExportEnabled(), true); + terrainArrangement.Terrain.LoadIntoExporter(staticScene, savePath, true); } }); }); diff --git a/Charm/ActivityMapView.xaml.cs b/Charm/ActivityMapView.xaml.cs index 42b2330f..491c4214 100644 --- a/Charm/ActivityMapView.xaml.cs +++ b/Charm/ActivityMapView.xaml.cs @@ -42,20 +42,6 @@ private ObservableCollection GetMapList(IActivity activity) displayMap.Hash = bubble.MapReference.TagData.ChildMapReference.Hash; maps.Add(displayMap); } - // foreach (var mapEntry in activity.TagData.Unk50) - // { - // foreach (var mapReferences in mapEntry.MapReferences) - // { - // // idk why this can happen but it can, some weird stuff with h64 - // // for the child map reference, ive only seen it once so far but the hash for it was just FFFFFFFF in the map reference file - // if (mapReferences.MapReference is null || mapReferences.MapReference.TagData.ChildMapReference == null) - // continue; - // DisplayBubble displayMap = new DisplayBubble(); - // displayMap.Name = $"{mapEntry.BubbleName} ({mapEntry.LocationName})"; // assuming Unk10 is 0F978080 or 0B978080 - // displayMap.Hash = mapReferences.MapReference.TagData.ChildMapReference.Hash; - // maps.Add(displayMap); - // } - // } return maps; } diff --git a/Charm/MapView.xaml.cs b/Charm/MapView.xaml.cs index 297b3d81..7e99bbc1 100644 --- a/Charm/MapView.xaml.cs +++ b/Charm/MapView.xaml.cs @@ -131,7 +131,7 @@ public void Dispose() public static void ExportFullMap(Tag map, ExportTypeFlag exportTypeFlag) { - ExporterScene scene = Exporter.Get().CreateScene(map.Hash.ToString(), ExportType.Map); + ExporterScene scene = Exporter.Get().CreateScene(map.Hash.ToString(), ExportType.MapResource); string meshName = map.Hash.ToString(); string savePath = _config.GetExportSavePath() + $"/{meshName}"; @@ -141,11 +141,8 @@ public static void ExportFullMap(Tag map, ExportTypeFlag exportTy } Directory.CreateDirectory(savePath); - if(exportStatics) - { - Directory.CreateDirectory(savePath + "/Statics"); - ExportStatics(savePath, map); - } + Directory.CreateDirectory(savePath + "/Statics"); + ExportStatics(savePath, map); ExtractDataTables(map, savePath, scene, ExportTypeFlag.Full); } @@ -173,7 +170,7 @@ public static void ExportTerrainMap(Tag map) if (exportStatics) { ExporterScene staticScene = Exporter.Get().CreateScene($"{terrainArrangement.Terrain.Hash}_Terrain", ExportType.StaticInMap); - terrainArrangement.Terrain.LoadIntoExporter(staticScene, savePath, _config.GetSBoxShaderExportEnabled(), true); + terrainArrangement.Terrain.LoadIntoExporter(staticScene, savePath, true); } } }); @@ -188,14 +185,7 @@ private static void ExtractDataTables(Tag map, string savePath, E { if (entry.DataResource.GetValue(data.MapDataTable.GetReader()) is SMapDataResource staticMapResource) // Static map { - if (exportTypeFlag == ExportTypeFlag.ArrangedMap) - { - staticMapResource.StaticMapParent.TagData.StaticMap.LoadArrangedIntoExporterScene(); //Arranged because...arranged - } - else if (exportTypeFlag == ExportTypeFlag.Full) - { - staticMapResource.StaticMapParent.TagData.StaticMap.LoadIntoExporterScene(scene, savePath, _config.GetSBoxShaderExportEnabled()); - } + staticMapResource.StaticMapParent.TagData.StaticMap.LoadIntoExporterScene(scene, savePath, _config.GetSBoxShaderExportEnabled()); } }); }); @@ -218,11 +208,7 @@ private static void ExportStatics(string savePath, Tag map) ExporterScene staticScene = Exporter.Get().CreateScene(staticMeshName, ExportType.StaticInMap); var staticmesh = part.Static.Load(ExportDetailLevel.MostDetailed); staticScene.AddStatic(part.Static.Hash, staticmesh); - - if (sboxModels) - { - SBoxHandler.SaveStaticVMDL($"{savePath}/Statics", staticMeshName, staticmesh); - } + SBoxHandler.SaveStaticVMDL($"{savePath}/Statics", staticMeshName, staticmesh); } } }); diff --git a/Tiger/Exporters/Exporter.cs b/Tiger/Exporters/Exporter.cs index 61e7c0a9..484ef0e4 100644 --- a/Tiger/Exporters/Exporter.cs +++ b/Tiger/Exporters/Exporter.cs @@ -196,25 +196,28 @@ public void AddEntity(FileHash entityHash, List parts, List>(); - _config["Instances"][_config["MeshName"]] = instance; - } - _config["Parts"] = new ConcurrentDictionary(); - _config["Parts"][_config["MeshName"]] = part; - } + //// If theres only 1 part, we need to rename it + the instance to the name of the mesh (unreal imports to fbx name if only 1 mesh inside) + //if (_config["Parts"].Count == 1) + //{ + // var part = _config["Parts"][_config["Parts"].Keys[0]]; + // //I'm not sure what to do if it's 0, so I guess I'll leave that to fix it in the future if something breakes. + // if (_config["Instances"].Count != 0) + // { + // var instance = _config["Instances"][_config["Instances"].Keys[0]]; + // _config["Instances"] = new ConcurrentDictionary>(); + // _config["Instances"][_config["MeshName"]] = instance; + // } + // _config["Parts"] = new ConcurrentDictionary(); + // _config["Parts"][_config["MeshName"]] = part; + //} //this just sorts the "instances" part of the cfg so its ordered by scale diff --git a/Tiger/Schema/Static/StaticMapData.cs b/Tiger/Schema/Static/StaticMapData.cs index c30714ff..2caadd6c 100644 --- a/Tiger/Schema/Static/StaticMapData.cs +++ b/Tiger/Schema/Static/StaticMapData.cs @@ -33,12 +33,13 @@ public void LoadArrangedIntoExporterScene() public void LoadIntoExporterScene(ExporterScene scene, string savePath, bool bSaveShaders) { List extractedStatics = _tag.Statics.DistinctBy(x => x.Static.Hash).ToList(); - // todo this loads statics twice Parallel.ForEach(extractedStatics, s => { var parts = s.Static.Load(ExportDetailLevel.MostDetailed); - scene.AddStatic(s.Static.Hash, parts); + if (scene.Type != ExportType.MapResource) + scene.AddStatic(s.Static.Hash, parts); + s.Static.SaveMaterialsFromParts(scene, parts); }); diff --git a/Tiger/Schema/Static/StaticMesh.cs b/Tiger/Schema/Static/StaticMesh.cs index 4142b0dd..983fc851 100644 --- a/Tiger/Schema/Static/StaticMesh.cs +++ b/Tiger/Schema/Static/StaticMesh.cs @@ -65,9 +65,7 @@ public void SaveMaterialsFromParts(ExporterScene scene, List parts) foreach (var part in parts) { if (part.Material == null) - { continue; - } scene.Materials.Add(new ExportMaterial(part.Material)); } } diff --git a/Tiger/Schema/Static/Terrain.cs b/Tiger/Schema/Static/Terrain.cs index f335bf8e..3597b2fc 100644 --- a/Tiger/Schema/Static/Terrain.cs +++ b/Tiger/Schema/Static/Terrain.cs @@ -16,28 +16,11 @@ public Terrain(FileHash hash) : base(hash) } // To test use edz.strike_hmyn and alleys_a adf6ae80 - public void LoadIntoExporter(ExporterScene scene, string saveDirectory, bool bSaveShaders, bool exportStatic = false) + public void LoadIntoExporter(ExporterScene scene, string saveDirectory, bool exportStatic = false) { // Uses triangle strip + only using first set of vertices and indices Dictionary parts = new Dictionary(); List dyeMaps = new List(); - foreach (var partEntry in _tag.StaticParts) - { - if (partEntry.DetailLevel == 0) - { - if (partEntry.Material is null || partEntry.Material.VertexShader is null) - continue; - - var part = MakePart(partEntry); - parts.TryAdd(part, partEntry.Material); - - scene.Materials.Add(new ExportMaterial(partEntry.Material, true)); - part.Material = partEntry.Material; - - if (exportStatic) //Need access to material early, before scene system exports - partEntry.Material.SaveShaders($"{saveDirectory}", true); - } - } int terrainTextureIndex = 14; for (int i = 0; i < _tag.MeshGroups.Count; i++) @@ -61,23 +44,43 @@ public void LoadIntoExporter(ExporterScene scene, string saveDirectory, bool bSa } } - foreach (var part in parts) - { - TransformPositions(part.Key); - TransformTexcoords(part.Key); - TransformVertexColors(part.Key); - } - - scene.AddStatic(Hash, parts.Keys.ToList()); - // For now we pre-transform it - if (!exportStatic) + if (scene.Type == ExportType.MapResource) { scene.AddStaticInstance(Hash, 1, Vector4.Zero, Vector3.Zero); - for (int i = 0; i < dyeMaps.Count; i++) { scene.AddTerrainDyemap(Hash, dyeMaps[i].Hash); } + return; + } + else + { + scene.AddStatic(Hash, parts.Keys.ToList()); + } + + foreach (var partEntry in _tag.StaticParts) + { + if (partEntry.DetailLevel == 0) + { + if (partEntry.Material is null || partEntry.Material.VertexShader is null) + continue; + + var part = MakePart(partEntry); + parts.TryAdd(part, partEntry.Material); + + scene.Materials.Add(new ExportMaterial(partEntry.Material, true)); + part.Material = partEntry.Material; + + if (exportStatic) //Need access to material early, before scene system exports + partEntry.Material.SaveShaders($"{saveDirectory}", true); + } + } + + foreach (var part in parts) + { + TransformPositions(part.Key); + TransformTexcoords(part.Key); + TransformVertexColors(part.Key); } // We need to add these textures after the static is initialised