Skip to content

Commit

Permalink
Load Entity children
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DeltaDesigns committed Nov 10, 2023
1 parent 5f8b291 commit 5453d48
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 22 deletions.
14 changes: 10 additions & 4 deletions Charm/ActivityMapEntityView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,13 @@ await Task.Run(() =>
}
else
{
FileHash tagHash = new FileHash(dc.Hash);
MainWindow.Progress.SetProgressStages(new List<string> { $"Loading Entity to UI: {tagHash}" });
Entity entity = FileResourcer.Get().GetFile<Entity>(dc.Hash);
MainWindow.Progress.SetProgressStages(new List<string> { $"Loading Entity to UI: {entity.Hash}" });
List<Entity> entities = new List<Entity> { entity };
entities.AddRange(entity.GetEntityChildren());
await Task.Run(() =>
{
MapControl.LoadEntity(tagHash, _globalFbxHandler);
MapControl.LoadEntity(entities, _globalFbxHandler);
MainWindow.Progress.CompleteStage();
});
}
Expand Down Expand Up @@ -630,7 +632,11 @@ await Task.Run(() =>
{
Entity entity = FileResourcer.Get().GetFile<Entity>(entry.GetEntityHash());
if(entity.HasGeometry())
EntityView.Export(new List<Entity> { entity }, entity.Hash, ExportTypeFlag.Full);
{
List<Entity> entities = new List<Entity> { entity };
entities.AddRange(entity.GetEntityChildren());
EntityView.Export(entities, entity.Hash, ExportTypeFlag.Full);
}
}
MainWindow.Progress.CompleteStage();
}
Expand Down
33 changes: 19 additions & 14 deletions Charm/MapView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ private void SetEntityMapUI(Tag<SMapDataTable> dataentry, ExportDetailLevel deta
displayParts.Clear();
}

public bool LoadEntity(FileHash entityHash, FbxHandler fbxHandler)
public bool LoadEntity(List<Entity> 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<int>(dynamicParts.Select(x => x.GroupIndex)));
//dynamicParts = dynamicParts.Where(x => x.GroupIndex == ModelView.GetSelectedGroupIndex()).ToList();
Expand Down Expand Up @@ -298,18 +298,23 @@ private static void ExportStatics(string savePath, Tag<SMapContainer> map)
Parallel.ForEach(dataentry.TagData.DataEntries, entry =>
{
Entity entity = FileResourcer.Get().GetFile(typeof(Entity), entry.GetEntityHash());
if (entity.HasGeometry())
List<Entity> entities = new List<Entity> { 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);
}
}
}
});
Expand Down
4 changes: 0 additions & 4 deletions Tiger/Schema/Activity/Activity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,6 @@ private Dictionary<ulong, Dictionary<string, string>> GetWorldIDs(FileHash hash)
}
break;
default:
if (resource.EntityResourceParent.TagData.EntityResource.TagData.UnkHash80 != null)
{
Console.WriteLine($"{resource.EntityResourceParent.TagData.EntityResource.Hash}");
}
break;
}
}
Expand Down
43 changes: 43 additions & 0 deletions Tiger/Schema/Entity/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,47 @@ public bool HasGeometry()
}
return Model != null;
}

public List<Entity> GetEntityChildren()
{
lock (_lock)
{
if (!_loaded)
{
Load();
}
}

List<Entity> entities = new List<Entity>();
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<Entity>(entry2.Unk08.Hash);
if(entity.HasGeometry())
{
entities.Add(entity);
//Just in case
foreach (var child in entity.GetEntityChildren())
{
entities.Add(child);
}
}
}
}
break;
}
}
return entities;
}
}
1 change: 1 addition & 0 deletions Tiger/Schema/Entity/EntityStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ public struct D2Class_1D848080
{
public int Unk00;
public int Unk04;
[Tag64]
public Tag Unk08;
public int Unk0C;
public int Unk10;
Expand Down

0 comments on commit 5453d48

Please sign in to comment.