@@ -19,6 +19,7 @@ public class ComposerCache
19
19
private readonly PbdFile defaultPbdFile ;
20
20
private readonly ConcurrentDictionary < string , ShaderPackage > shpkCache = new ( ) ;
21
21
private readonly ConcurrentDictionary < string , RefCounter < MtrlFile > > mtrlCache = new ( ) ;
22
+ private readonly ConcurrentDictionary < string , string > mtrlPathCache = new ( ) ;
22
23
private readonly ConcurrentDictionary < string , PbdFile > pbdCache = new ( ) ;
23
24
private readonly ConcurrentDictionary < string , RefCounter < MdlFile > > mdlCache = new ( ) ;
24
25
@@ -104,7 +105,7 @@ public MdlFile GetMdlFile(string path)
104
105
return item . Object ;
105
106
}
106
107
107
- public MtrlFile GetMtrlFile ( string path )
108
+ public MtrlFile GetMtrlFile ( string path , out string ? cachePath )
108
109
{
109
110
var item = mtrlCache . GetOrAdd ( path , key =>
110
111
{
@@ -114,7 +115,8 @@ public MtrlFile GetMtrlFile(string path)
114
115
115
116
if ( exportConfig . CacheFileTypes . HasFlag ( CacheFileType . Mtrl ) )
116
117
{
117
- CacheFile ( path ) ;
118
+ var cachePath = CacheFile ( path ) ;
119
+ mtrlPathCache . TryAdd ( path , cachePath ) ;
118
120
}
119
121
120
122
if ( mtrlCache . Count > 100 )
@@ -128,6 +130,8 @@ public MtrlFile GetMtrlFile(string path)
128
130
return new RefCounter < MtrlFile > ( mtrlFile ) ;
129
131
} ) ;
130
132
133
+ cachePath = mtrlPathCache . GetValueOrDefault ( path ) ;
134
+
131
135
item . LastAccess = DateTime . UtcNow ;
132
136
return item . Object ;
133
137
}
@@ -239,14 +243,19 @@ public MaterialBuilder ComposeMaterial(string mtrlPath,
239
243
ParsedCharacterInfo ? characterInfo = null ,
240
244
IColorTableSet ? colorTableSet = null )
241
245
{
242
- var mtrlFile = GetMtrlFile ( mtrlPath ) ;
246
+ var mtrlFile = GetMtrlFile ( mtrlPath , out var mtrlCachePath ) ;
243
247
var shaderPackage = GetShaderPackage ( mtrlFile . GetShaderPackageName ( ) ) ;
244
248
var material = new MaterialComposer ( mtrlFile , mtrlPath , shaderPackage ) ;
245
249
if ( instance != null )
246
250
{
247
251
material . SetPropertiesFromInstance ( instance ) ;
248
252
}
249
253
254
+ if ( mtrlCachePath != null )
255
+ {
256
+ material . SetProperty ( "MtrlCachePath" , Path . GetRelativePath ( cacheDir , mtrlCachePath ) ) ;
257
+ }
258
+
250
259
if ( characterInfo != null )
251
260
{
252
261
material . SetPropertiesFromCharacterInfo ( characterInfo ) ;
0 commit comments