diff --git a/project/code/LGS/ResourcePathManager.cs b/project/code/LGS/ResourcePathManager.cs index 14ae529..e78b6fc 100644 --- a/project/code/LGS/ResourcePathManager.cs +++ b/project/code/LGS/ResourcePathManager.cs @@ -17,6 +17,7 @@ public class ResourcePathManager private bool _initialised = false; private readonly string _extractionPath; + private string _fmsDir; private CampaignResources _omResources; private Dictionary _fmResources; @@ -74,6 +75,7 @@ public class ResourcePathManager objectPathMap = objectPathMap, }; _fmResources.Add(campaign, resource); + _fmsDir = fmsDir; } } @@ -188,6 +190,42 @@ public class ResourcePathManager return null; } + // TODO: Store these as part of the resources + public string GetObjectTexturePath(string campaignName, string textureName) + { + var options = new EnumerationOptions + { + MatchCasing = MatchCasing.CaseInsensitive, + RecurseSubdirectories = true, + }; + + textureName = textureName.ToLower(); + var omDir = Path.Join(_extractionPath, "obj"); + var omPaths = Directory.GetFiles(omDir, textureName, options); + if (campaignName == null || campaignName == "") + { + if (omPaths.Length > 0) + { + return omPaths[0]; + } + } + else if (_fmResources.TryGetValue(campaignName, out var campaign)) + { + var fmDir = Path.Join(_fmsDir, campaignName); + var fmPaths = Directory.GetFiles(Path.Join(fmDir, "obj"), textureName, options); + if (fmPaths.Length > 0) + { + return fmPaths[0]; + } + else if (omPaths.Length > 0) + { + return omPaths[0]; + } + } + + return null; + } + // TODO: Handle object textures? private static Dictionary GetTexturePaths(string root) { diff --git a/project/code/TMV/ModelLoader.cs b/project/code/TMV/ModelLoader.cs index c01e1ff..afa880c 100644 --- a/project/code/TMV/ModelLoader.cs +++ b/project/code/TMV/ModelLoader.cs @@ -21,24 +21,21 @@ public static class ModelLoader return null; } - // TODO: Remove this disgusting hack. Not only is it a hack, it doesn't support custom models - var baseDir = Path.GetDirectoryName(modelPath); - var options = new EnumerationOptions - { - MatchCasing = MatchCasing.CaseInsensitive, - RecurseSubdirectories = true, - }; var materials = new List(); foreach (var material in modelFile.Materials) { if (material.Type == 0) { - var paths = Directory.GetFiles(baseDir, material.Name, options); - if (paths.IsEmpty()) continue; + var path = pathManager.GetObjectTexturePath(campaignName, material.Name); + if (path == null) + { + GD.Print($"Failed to load model texture: {material.Name}"); + continue; + } materials.Add(new StandardMaterial3D { - AlbedoTexture = TextureLoader.LoadTexture(paths[0]) + AlbedoTexture = TextureLoader.LoadTexture(path) }); } else