Skip to content

Commit 9579d5a

Browse files
Export mtrlCachePath value if mtrls are cached
1 parent c8477c2 commit 9579d5a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Meddle/Meddle.Plugin/Models/Composer/ComposerCache.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class ComposerCache
1919
private readonly PbdFile defaultPbdFile;
2020
private readonly ConcurrentDictionary<string, ShaderPackage> shpkCache = new();
2121
private readonly ConcurrentDictionary<string, RefCounter<MtrlFile>> mtrlCache = new();
22+
private readonly ConcurrentDictionary<string, string> mtrlPathCache = new();
2223
private readonly ConcurrentDictionary<string, PbdFile> pbdCache = new();
2324
private readonly ConcurrentDictionary<string, RefCounter<MdlFile>> mdlCache = new();
2425

@@ -104,7 +105,7 @@ public MdlFile GetMdlFile(string path)
104105
return item.Object;
105106
}
106107

107-
public MtrlFile GetMtrlFile(string path)
108+
public MtrlFile GetMtrlFile(string path, out string? cachePath)
108109
{
109110
var item = mtrlCache.GetOrAdd(path, key =>
110111
{
@@ -114,7 +115,8 @@ public MtrlFile GetMtrlFile(string path)
114115

115116
if (exportConfig.CacheFileTypes.HasFlag(CacheFileType.Mtrl))
116117
{
117-
CacheFile(path);
118+
var cachePath = CacheFile(path);
119+
mtrlPathCache.TryAdd(path, cachePath);
118120
}
119121

120122
if (mtrlCache.Count > 100)
@@ -128,6 +130,8 @@ public MtrlFile GetMtrlFile(string path)
128130
return new RefCounter<MtrlFile>(mtrlFile);
129131
});
130132

133+
cachePath = mtrlPathCache.GetValueOrDefault(path);
134+
131135
item.LastAccess = DateTime.UtcNow;
132136
return item.Object;
133137
}
@@ -239,14 +243,19 @@ public MaterialBuilder ComposeMaterial(string mtrlPath,
239243
ParsedCharacterInfo? characterInfo = null,
240244
IColorTableSet? colorTableSet = null)
241245
{
242-
var mtrlFile = GetMtrlFile(mtrlPath);
246+
var mtrlFile = GetMtrlFile(mtrlPath, out var mtrlCachePath);
243247
var shaderPackage = GetShaderPackage(mtrlFile.GetShaderPackageName());
244248
var material = new MaterialComposer(mtrlFile, mtrlPath, shaderPackage);
245249
if (instance != null)
246250
{
247251
material.SetPropertiesFromInstance(instance);
248252
}
249253

254+
if (mtrlCachePath != null)
255+
{
256+
material.SetProperty("MtrlCachePath", Path.GetRelativePath(cacheDir, mtrlCachePath));
257+
}
258+
250259
if (characterInfo != null)
251260
{
252261
material.SetPropertiesFromCharacterInfo(characterInfo);

0 commit comments

Comments
 (0)