This commit is contained in:
ousttrue
2021-02-12 22:01:58 +09:00
parent 6f3d3e3f2b
commit 56772ff03d
3 changed files with 18 additions and 6 deletions

View File

@@ -58,8 +58,15 @@ namespace UniGLTF
return texture;
}
texture = await LoadTextureAsync(param.Index0.Value);
m_textureCache.Add(GetTextureParam.Create(param.Index0.Value), texture);
{
var defaultParam = GetTextureParam.Create(param.Index0.Value);
if (!m_textureCache.TryGetValue(defaultParam, out texture))
{
texture = await LoadTextureAsync(param.Index0.Value);
m_textureCache.Add(defaultParam, texture);
}
}
switch (param.TextureType)
{
case GetTextureParam.NORMAL_PROP:

View File

@@ -71,7 +71,12 @@ namespace UniGLTF
/// <returns></returns>
public static Material CreateMaterialForTest(int i, glTFMaterial material)
{
throw new System.NotImplementedException();
var gltf = new glTF
{
materials = new System.Collections.Generic.List<glTFMaterial> { material },
};
var task = DefaultCreateMaterialAsync(gltf, i, null);
return task.Result;
}
}
}

View File

@@ -24,10 +24,10 @@ namespace UniGLTF
}
}
public static async Task<Texture2D> LoadTextureAsync(glTF gltf, IStorage storage, int index)
public static Task<Texture2D> LoadTextureAsync(glTF gltf, IStorage storage, int index)
{
string m_textureName = default;
var imageIndex = gltf.GetImageIndexFromTextureIndex(index);
var segments = gltf.GetImageBytes(storage, imageIndex, out m_textureName);
var imageBytes = ToArray(segments);
@@ -50,7 +50,7 @@ namespace UniGLTF
{
TextureSamplerUtil.SetSampler(texture, sampler);
}
return texture;
return Task.FromResult(texture);
}
}
}