public static List <Texture2D> GetTextureList(Coocoo3DMain appBody, StorageFolder storageFolder, PMXFormat pmx) { List <Texture2D> textures = new List <Texture2D>(); List <string> paths = new List <string>(); List <string> relativePaths = new List <string>(); foreach (var vTex in pmx.Textures) { string relativePath = vTex.TexturePath.Replace("//", "\\").Replace('/', '\\'); string texPath = Path.Combine(storageFolder.Path, relativePath); paths.Add(texPath); relativePaths.Add(relativePath); } lock (appBody.mainCaches.TextureCaches) { for (int i = 0; i < pmx.Textures.Count; i++) { Texture2DPack tex = appBody.mainCaches.TextureCaches.GetOrCreate(paths[i]); if (tex.Status != GraphicsObjectStatus.loaded) { tex.Mark(GraphicsObjectStatus.loading); } tex.relativePath = relativePaths[i]; tex.folder = storageFolder; textures.Add(tex.texture2D); } } return(textures); }
public void ReloadTextures(ProcessingList processingList, Action _RequireRender) { if (textureTaskLocker.GetLocker()) { List <Texture2DPack> packs = new List <Texture2DPack>(); lock (TextureCaches) foreach (var texturePack in TextureCaches.Values) { packs.Add(texturePack); } for (int i = 0; i < packs.Count; i++) { var tex = packs[i]; if (tex.loadLocker.GetLocker()) { Task.Factory.StartNew(async(object a) => { Texture2DPack texturePack1 = (Texture2DPack)a; try { var file = await texturePack1.folder.GetFileAsync(texturePack1.relativePath); var attr = await file.GetBasicPropertiesAsync(); if (attr.DateModified != texturePack1.lastModifiedTime || texturePack1.texture2D.Status != GraphicsObjectStatus.loaded) { Uploader uploader = new Uploader(); if (await texturePack1.ReloadTexture(file, uploader)) { processingList.AddObject(new Texture2DUploadPack(texturePack1.texture2D, uploader)); } _RequireRender(); texturePack1.lastModifiedTime = attr.DateModified; } } catch { texturePack1.Mark(GraphicsObjectStatus.error); _RequireRender(); } finally { texturePack1.loadLocker.FreeLocker(); } }, tex); } } textureTaskLocker.FreeLocker(); } }