Merge model related chunks from gam file
This commit is contained in:
parent
db293791e0
commit
c48eb018f5
|
@ -5,6 +5,7 @@ using KeepersCompound.TMV.UI;
|
|||
using RectpackSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace KeepersCompound.TMV;
|
||||
|
||||
|
@ -95,13 +96,45 @@ public partial class Mission : Node3D
|
|||
UseChunk<TxList>("TXLIST", LoadTextures);
|
||||
UseChunk<WorldRep>("WREXT", BuildWrMeshes);
|
||||
if (
|
||||
_file.Chunks.TryGetValue("BRLIST", out var brList) &&
|
||||
_file.Chunks.TryGetValue("P$ModelName", out var modelNames) &&
|
||||
_file.Chunks.TryGetValue("L$MetaProp", out var metaPropLinks) &&
|
||||
_file.Chunks.TryGetValue("LD$MetaProp", out var metaPropLinkData)
|
||||
_file.Chunks.TryGetValue("BRLIST", out var brListRaw) &&
|
||||
_file.Chunks.TryGetValue("P$ModelName", out var modelNamesRaw) &&
|
||||
_file.Chunks.TryGetValue("L$MetaProp", out var metaPropLinksRaw) &&
|
||||
_file.Chunks.TryGetValue("LD$MetaProp", out var metaPropLinkDataRaw)
|
||||
)
|
||||
{
|
||||
PlaceObjects((BrList)brList, (PropertyModelName)modelNames, (LinkChunk)metaPropLinks, (LinkDataMetaProp)metaPropLinkData);
|
||||
var brList = (BrList)brListRaw;
|
||||
var modelNames = (PropertyModelName)modelNamesRaw;
|
||||
var metaPropLinks = (LinkChunk)metaPropLinksRaw;
|
||||
var metaPropLinkData = (LinkDataMetaProp)metaPropLinkDataRaw;
|
||||
|
||||
// TODO: Do this somewhere else lol
|
||||
if (_file.Chunks.TryGetValue("GAM_FILE", out var gamFileChunk))
|
||||
{
|
||||
GD.Print("GAM_FILE detected");
|
||||
|
||||
var options = new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive };
|
||||
var name = ((GamFile)gamFileChunk).fileName;
|
||||
GD.Print($"Searching for GAM: {FileName.GetBaseDir()}/{name}");
|
||||
var paths = Directory.GetFiles(FileName.GetBaseDir(), name, options);
|
||||
GD.Print($"Found paths: {paths.Length}");
|
||||
if (!paths.IsEmpty())
|
||||
{
|
||||
GD.Print($"Attempting to load GAM at: {paths[0]}");
|
||||
var gamFile = new DbFile(paths[0]);
|
||||
if (gamFile.Chunks.TryGetValue("P$ModelName", out var gamChunk1) &&
|
||||
gamFile.Chunks.TryGetValue("L$MetaProp", out var gamChunk2) &&
|
||||
gamFile.Chunks.TryGetValue("LD$MetaProp", out var gamChunk3))
|
||||
{
|
||||
GD.Print($"Pre-Merged chunks: {modelNames.properties.Count} {metaPropLinks.links.Count} {metaPropLinkData.linkData.Count}");
|
||||
modelNames.properties.AddRange(((PropertyModelName)gamChunk1).properties);
|
||||
metaPropLinks.links.AddRange(((LinkChunk)gamChunk2).links);
|
||||
metaPropLinkData.linkData.AddRange(((LinkDataMetaProp)gamChunk3).linkData);
|
||||
GD.Print($"Post-Merged chunks: {modelNames.properties.Count} {metaPropLinks.links.Count} {metaPropLinkData.linkData.Count}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PlaceObjects(brList, modelNames, metaPropLinks, metaPropLinkData);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue