From 5453d486667ea321dce712e04cc523c03c05fe45 Mon Sep 17 00:00:00 2001 From: DeltaDesigns <50308149+DeltaDesigns@users.noreply.github.com> Date: Thu, 9 Nov 2023 23:35:34 -0500 Subject: [PATCH] Load Entity children Attempts to load any children entities a parent entity might have. Mainly just heads for npcs/vendors from what I've seen Only doing for the activity entities at the moment --- Charm/ActivityMapEntityView.xaml.cs | 14 ++++++--- Charm/MapView.xaml.cs | 33 ++++++++++++--------- Tiger/Schema/Activity/Activity.cs | 4 --- Tiger/Schema/Entity/Entity.cs | 43 ++++++++++++++++++++++++++++ Tiger/Schema/Entity/EntityStructs.cs | 1 + 5 files changed, 73 insertions(+), 22 deletions(-) diff --git a/Charm/ActivityMapEntityView.xaml.cs b/Charm/ActivityMapEntityView.xaml.cs index 7aba2873..61a05d1c 100644 --- a/Charm/ActivityMapEntityView.xaml.cs +++ b/Charm/ActivityMapEntityView.xaml.cs @@ -591,11 +591,13 @@ await Task.Run(() => } else { - FileHash tagHash = new FileHash(dc.Hash); - MainWindow.Progress.SetProgressStages(new List { $"Loading Entity to UI: {tagHash}" }); + Entity entity = FileResourcer.Get().GetFile(dc.Hash); + MainWindow.Progress.SetProgressStages(new List { $"Loading Entity to UI: {entity.Hash}" }); + List entities = new List { entity }; + entities.AddRange(entity.GetEntityChildren()); await Task.Run(() => { - MapControl.LoadEntity(tagHash, _globalFbxHandler); + MapControl.LoadEntity(entities, _globalFbxHandler); MainWindow.Progress.CompleteStage(); }); } @@ -630,7 +632,11 @@ await Task.Run(() => { Entity entity = FileResourcer.Get().GetFile(entry.GetEntityHash()); if(entity.HasGeometry()) - EntityView.Export(new List { entity }, entity.Hash, ExportTypeFlag.Full); + { + List entities = new List { entity }; + entities.AddRange(entity.GetEntityChildren()); + EntityView.Export(entities, entity.Hash, ExportTypeFlag.Full); + } } MainWindow.Progress.CompleteStage(); } diff --git a/Charm/MapView.xaml.cs b/Charm/MapView.xaml.cs index de5c447b..73c76c31 100644 --- a/Charm/MapView.xaml.cs +++ b/Charm/MapView.xaml.cs @@ -89,16 +89,16 @@ private void SetEntityMapUI(Tag dataentry, ExportDetailLevel deta displayParts.Clear(); } - public bool LoadEntity(FileHash entityHash, FbxHandler fbxHandler) + public bool LoadEntity(List entities, FbxHandler fbxHandler) { fbxHandler.Clear(); - AddEntity(entityHash, ExportDetailLevel.MostDetailed, fbxHandler); + foreach(var entity in entities) + AddEntity(entity, ExportDetailLevel.MostDetailed, fbxHandler); return LoadUI(fbxHandler); } - private void AddEntity(FileHash entityHash, ExportDetailLevel detailLevel, FbxHandler fbxHandler) + private void AddEntity(Entity entity, ExportDetailLevel detailLevel, FbxHandler fbxHandler) { - Entity entity = FileResourcer.Get().GetFile(typeof(Entity), entityHash); var dynamicParts = entity.Load(detailLevel); //ModelView.SetGroupIndices(new HashSet(dynamicParts.Select(x => x.GroupIndex))); //dynamicParts = dynamicParts.Where(x => x.GroupIndex == ModelView.GetSelectedGroupIndex()).ToList(); @@ -298,18 +298,23 @@ private static void ExportStatics(string savePath, Tag map) Parallel.ForEach(dataentry.TagData.DataEntries, entry => { Entity entity = FileResourcer.Get().GetFile(typeof(Entity), entry.GetEntityHash()); - if (entity.HasGeometry()) + List entities = new List { entity }; + entities.AddRange(entity.GetEntityChildren()); + foreach(var ent in entities) { - var parts = entity.Load(ExportDetailLevel.MostDetailed); - - foreach (var part in parts) + if (ent.HasGeometry()) { - MainViewModel.DisplayPart displayPart = new MainViewModel.DisplayPart(); - displayPart.BasePart = part; - displayPart.Translations.Add(entry.Translation.ToVec3()); - displayPart.Rotations.Add(entry.Rotation); - displayPart.Scales.Add(new Tiger.Schema.Vector3(entry.Translation.W, entry.Translation.W, entry.Translation.W)); - displayParts.Add(displayPart); + var parts = ent.Load(ExportDetailLevel.MostDetailed); + + foreach (var part in parts) + { + MainViewModel.DisplayPart displayPart = new MainViewModel.DisplayPart(); + displayPart.BasePart = part; + displayPart.Translations.Add(entry.Translation.ToVec3()); + displayPart.Rotations.Add(entry.Rotation); + displayPart.Scales.Add(new Tiger.Schema.Vector3(entry.Translation.W, entry.Translation.W, entry.Translation.W)); + displayParts.Add(displayPart); + } } } }); diff --git a/Tiger/Schema/Activity/Activity.cs b/Tiger/Schema/Activity/Activity.cs index 47ffc867..17d05042 100644 --- a/Tiger/Schema/Activity/Activity.cs +++ b/Tiger/Schema/Activity/Activity.cs @@ -333,10 +333,6 @@ private Dictionary> GetWorldIDs(FileHash hash) } break; default: - if (resource.EntityResourceParent.TagData.EntityResource.TagData.UnkHash80 != null) - { - Console.WriteLine($"{resource.EntityResourceParent.TagData.EntityResource.Hash}"); - } break; } } diff --git a/Tiger/Schema/Entity/Entity.cs b/Tiger/Schema/Entity/Entity.cs index ddfd7aa0..6fcf5829 100644 --- a/Tiger/Schema/Entity/Entity.cs +++ b/Tiger/Schema/Entity/Entity.cs @@ -120,4 +120,47 @@ public bool HasGeometry() } return Model != null; } + + public List GetEntityChildren() + { + lock (_lock) + { + if (!_loaded) + { + Load(); + } + } + + List entities = new List(); + foreach (var resource in _tag.EntityResources.Select(GetReader(), r => r.Resource)) + { + //Weird to have to get Unk10 first to be able to get Unk18 + //Trying to get Unk18 directly just crashes + switch (resource.TagData.Unk10.GetValue(resource.GetReader())) + { + case D2Class_12848080: + foreach (var entry in ((D2Class_0E848080)resource.TagData.Unk18.GetValue(resource.GetReader())).Unk88) + { + foreach (var entry2 in entry.Unk08) + { + if (entry2.Unk08 is null) + continue; + + Entity entity = FileResourcer.Get().GetFile(entry2.Unk08.Hash); + if(entity.HasGeometry()) + { + entities.Add(entity); + //Just in case + foreach (var child in entity.GetEntityChildren()) + { + entities.Add(child); + } + } + } + } + break; + } + } + return entities; + } } diff --git a/Tiger/Schema/Entity/EntityStructs.cs b/Tiger/Schema/Entity/EntityStructs.cs index 17fb3944..1602ead7 100644 --- a/Tiger/Schema/Entity/EntityStructs.cs +++ b/Tiger/Schema/Entity/EntityStructs.cs @@ -821,6 +821,7 @@ public struct D2Class_1D848080 { public int Unk00; public int Unk04; + [Tag64] public Tag Unk08; public int Unk0C; public int Unk10;