Skip to content

Commit

Permalink
Only export individual fbxs, no more one big fbx
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaDesigns committed Dec 19, 2023
1 parent 2e93163 commit 8efd941
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 125 deletions.
23 changes: 7 additions & 16 deletions Charm/ActivityMapEntityView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,9 @@ public static void ExportFull(List<FileHash> dataTables, string hash)
private static void ExtractDataTables(List<FileHash> 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 =>
{
Expand All @@ -366,8 +365,6 @@ private static void ExtractDataTables(List<FileHash> 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()))
{
Expand Down Expand Up @@ -428,7 +425,7 @@ private static void ExtractDataTables(List<FileHash> dataTables, string hash, st
}
break;
case SMapTerrainResource terrain:
terrain.Terrain.LoadIntoExporter(terrainScene, savePath, _config.GetSBoxShaderExportEnabled());
terrain.Terrain.LoadIntoExporter(terrainScene, savePath);
break;
default:
break;
Expand All @@ -451,10 +448,7 @@ private static void ExportIndividual(List<FileHash> 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)
{
Expand All @@ -466,16 +460,13 @@ private static void ExportIndividual(List<FileHash> 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);
}
});
});
Expand Down
14 changes: 0 additions & 14 deletions Charm/ActivityMapView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@ private ObservableCollection<DisplayBubble> 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;
}

Expand Down
26 changes: 6 additions & 20 deletions Charm/MapView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void Dispose()

public static void ExportFullMap(Tag<SMapContainer> 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}";
Expand All @@ -141,11 +141,8 @@ public static void ExportFullMap(Tag<SMapContainer> 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);
}
Expand Down Expand Up @@ -173,7 +170,7 @@ public static void ExportTerrainMap(Tag<SMapContainer> 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);
}
}
});
Expand All @@ -188,14 +185,7 @@ private static void ExtractDataTables(Tag<SMapContainer> 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());
}
});
});
Expand All @@ -218,11 +208,7 @@ private static void ExportStatics(string savePath, Tag<SMapContainer> 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);
}
}
});
Expand Down
57 changes: 31 additions & 26 deletions Tiger/Exporters/Exporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,28 @@ public void AddEntity(FileHash entityHash, List<DynamicMeshPart> parts, List<Bon

public void AddMapEntity(SMapDataEntry dynamicResource, Entity entity)
{
if (!_addedEntities.Contains(entity.Hash)) //Dont want duplicate entities being added
if(Type != ExportType.MapResource)
{
ExporterMesh mesh = new(dynamicResource.GetEntityHash());

_addedEntities.Add(entity.Hash);
var parts = entity.Model.Load(ExportDetailLevel.MostDetailed, entity.ModelParentResource);
for (int i = 0; i < parts.Count; i++)
if (!_addedEntities.Contains(entity.Hash)) //Dont want duplicate entities being added
{
DynamicMeshPart part = parts[i];
if (part.Material == null)
continue;
if (part.Material.EnumeratePSTextures().Any()) //Dont know if this will 100% "fix" the duplicate meshs that come with entities
ExporterMesh mesh = new(dynamicResource.GetEntityHash());

_addedEntities.Add(entity.Hash);
var parts = entity.Model.Load(ExportDetailLevel.MostDetailed, entity.ModelParentResource);
for (int i = 0; i < parts.Count; i++)
{
mesh.AddPart(dynamicResource.GetEntityHash(), part, i);
DynamicMeshPart part = parts[i];
if (part.Material == null)
continue;
if (part.Material.EnumeratePSTextures().Any()) //Dont know if this will 100% "fix" the duplicate meshs that come with entities
{
mesh.AddPart(dynamicResource.GetEntityHash(), part, i);
}
}
Entities.Add(new ExporterEntity { Mesh = mesh, BoneNodes = entity.Skeleton?.GetBoneNodes() });
}
Entities.Add(new ExporterEntity { Mesh = mesh, BoneNodes = entity.Skeleton?.GetBoneNodes() });
}

if (!EntityInstances.ContainsKey(dynamicResource.GetEntityHash()))
{
EntityInstances.TryAdd(dynamicResource.GetEntityHash(), new());
Expand All @@ -231,24 +234,26 @@ public void AddMapEntity(SMapDataEntry dynamicResource, Entity entity)

public void AddMapModel(EntityModel model, Vector4 translation, Vector4 rotation, Vector3 scale)
{
ExporterMesh mesh = new(model.Hash);

if (!_addedEntities.Contains(model.Hash)) //Dont want duplicate entities being added
if (Type != ExportType.MapResource)
{
_addedEntities.Add(model.Hash);
var parts = model.Load(ExportDetailLevel.MostDetailed, null);
for (int i = 0; i < parts.Count; i++)
ExporterMesh mesh = new(model.Hash);
if (!_addedEntities.Contains(model.Hash)) //Dont want duplicate entities being added
{
DynamicMeshPart part = parts[i];

if (part.Material != null && !part.Material.EnumeratePSTextures().Any()) //Dont know if this will 100% "fix" the duplicate meshs that come with entities
_addedEntities.Add(model.Hash);
var parts = model.Load(ExportDetailLevel.MostDetailed, null);
for (int i = 0; i < parts.Count; i++)
{
continue;
}
DynamicMeshPart part = parts[i];

mesh.AddPart(model.Hash, part, i);
if (part.Material != null && !part.Material.EnumeratePSTextures().Any()) //Dont know if this will 100% "fix" the duplicate meshs that come with entities
{
continue;
}

mesh.AddPart(model.Hash, part, i);
}
Entities.Add(new ExporterEntity { Mesh = mesh, BoneNodes = null });
}
Entities.Add(new ExporterEntity { Mesh = mesh, BoneNodes = null });
}

if (!EntityInstances.ContainsKey(model.Hash))
Expand Down
2 changes: 1 addition & 1 deletion Tiger/Exporters/FbxExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override void Export(Exporter.ExportEventArgs args)
{
outputDirectory = Path.Join(outputDirectory, scene.Name);
}
else if (scene.Type is ExportType.Map or ExportType.Terrain or ExportType.EntityPoints)
else if (scene.Type is ExportType.Map or ExportType.Terrain or ExportType.EntityPoints or ExportType.MapResource)
{
outputDirectory = Path.Join(outputDirectory, "Maps");
}
Expand Down
30 changes: 15 additions & 15 deletions Tiger/Exporters/MetadataExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public void WriteToFile(string path)
{
path = Path.Join(path, _config["MeshName"]);
}
else if (_exportType is ExportType.Map or ExportType.Terrain or ExportType.EntityPoints)
else if (_exportType is ExportType.Map or ExportType.Terrain or ExportType.EntityPoints or ExportType.MapResource)
{
path = Path.Join(path, "Maps");
}
Expand All @@ -310,20 +310,20 @@ public void WriteToFile(string path)
return;
}

// 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<string, ConcurrentBag<JsonInstance>>();
_config["Instances"][_config["MeshName"]] = instance;
}
_config["Parts"] = new ConcurrentDictionary<string, string>();
_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<string, ConcurrentBag<JsonInstance>>();
// _config["Instances"][_config["MeshName"]] = instance;
// }
// _config["Parts"] = new ConcurrentDictionary<string, string>();
// _config["Parts"][_config["MeshName"]] = part;
//}


//this just sorts the "instances" part of the cfg so its ordered by scale
Expand Down
5 changes: 3 additions & 2 deletions Tiger/Schema/Static/StaticMapData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ public void LoadArrangedIntoExporterScene()
public void LoadIntoExporterScene(ExporterScene scene, string savePath, bool bSaveShaders)
{
List<SStaticMeshHash> 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);
});

Expand Down
2 changes: 0 additions & 2 deletions Tiger/Schema/Static/StaticMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ public void SaveMaterialsFromParts(ExporterScene scene, List<StaticPart> parts)
foreach (var part in parts)
{
if (part.Material == null)
{
continue;
}
scene.Materials.Add(new ExportMaterial(part.Material));
}
}
Expand Down
61 changes: 32 additions & 29 deletions Tiger/Schema/Static/Terrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<StaticPart, IMaterial> parts = new Dictionary<StaticPart, IMaterial>();
List<Texture> dyeMaps = new List<Texture>();
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++)
Expand All @@ -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
Expand Down

0 comments on commit 8efd941

Please sign in to comment.