Super scuffed initial object model detection

This commit is contained in:
Jarrod Doyle 2024-08-24 11:33:55 +01:00
parent 0eb918d863
commit acc3add512
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 56 additions and 2 deletions

View File

@ -94,7 +94,15 @@ public partial class Mission : Node3D
_file = new(FileName); _file = new(FileName);
UseChunk<TxList>("TXLIST", LoadTextures); UseChunk<TxList>("TXLIST", LoadTextures);
UseChunk<WorldRep>("WREXT", BuildWrMeshes); UseChunk<WorldRep>("WREXT", BuildWrMeshes);
UseChunk<BrList>("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<T>(string name, Action<T> action) private void UseChunk<T>(string name, Action<T> 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) foreach (var brush in brList.Brushes)
{ {
@ -118,6 +130,48 @@ public partial class Mission : Node3D
continue; 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 pos = brush.position.ToGodotVec3();
var cube = new CsgBox3D var cube = new CsgBox3D
{ {