Add jank object texture path gathering
This commit is contained in:
parent
b6a65fc10b
commit
05e90c1a30
|
@ -17,6 +17,7 @@ public class ResourcePathManager
|
|||
|
||||
private bool _initialised = false;
|
||||
private readonly string _extractionPath;
|
||||
private string _fmsDir;
|
||||
private CampaignResources _omResources;
|
||||
private Dictionary<string, CampaignResources> _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<string, string> GetTexturePaths(string root)
|
||||
{
|
||||
|
|
|
@ -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<StandardMaterial3D>();
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue