diff --git a/project/code/TMV/Mission.cs b/project/code/TMV/Mission.cs index d83d182..2202c95 100644 --- a/project/code/TMV/Mission.cs +++ b/project/code/TMV/Mission.cs @@ -94,7 +94,15 @@ public partial class Mission : Node3D _file = new(FileName); UseChunk("TXLIST", LoadTextures); UseChunk("WREXT", BuildWrMeshes); - UseChunk("BRLIST", PlaceObjects); + 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) + ) + { + PlaceObjects((BrList)brList, (PropertyModelName)modelNames, (LinkChunk)metaPropLinks, (LinkDataMetaProp)metaPropLinkData); + } } private void UseChunk(string name, Action action) @@ -109,7 +117,11 @@ public partial class Mission : Node3D } } - private void PlaceObjects(BrList brList) + private void PlaceObjects( + BrList brList, + PropertyModelName modelNames, + LinkChunk metapropLink, + LinkDataMetaProp metaPropLinkData) { foreach (var brush in brList.Brushes) { @@ -118,6 +130,48 @@ public partial class Mission : Node3D continue; } + // TODO: Build an actual hierarchy and such :) + // TODO: We need to load the gamesys :) + // Determine if we have a model name :)) + var id = (int)brush.brushInfo; + var modelName = ""; + while (true) + { + // See if there's a modelname property + foreach (var prop in modelNames.properties) + { + if (prop.objectId == id) + { + modelName = prop.modelName; + break; + } + } + if (modelName != "") break; + + // No modelname so check for a parent + var length = metapropLink.links.Count; + var prevId = id; + for (var i = 0; i < length; i++) + { + var link = metapropLink.links[i]; + var linkData = metaPropLinkData.linkData[i]; + if (link.source == id && linkData.priority == 0) + { + id = link.destination; + break; + } + } + // No parent found + if (id == prevId) + { + break; + } + } + if (modelName == "") + { + continue; + } + var pos = brush.position.ToGodotVec3(); var cube = new CsgBox3D {