Skip to content

Commit

Permalink
Merge pull request #409 from hiroj/fix_argument_textureitem
Browse files Browse the repository at this point in the history
Fix argument textureitem
  • Loading branch information
hiroj authored May 22, 2020
2 parents dde0f1d + 0bba060 commit 12ff8e9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
13 changes: 11 additions & 2 deletions Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,16 @@ public void Load(string path, byte[] bytes)
Root.name = Path.GetFileNameWithoutExtension(path);
}

public virtual void CreateTextureItems(UnityPath imageBaseDir = default(UnityPath))
public virtual ITextureLoader CreateTextureLoader(int index)
{
#if UNIGLTF_USE_WEBREQUEST_TEXTURELOADER
return new UnityWebRequestTextureLoader(index);
#else
return new TextureLoader(index);
#endif
}

public void CreateTextureItems(UnityPath imageBaseDir = default(UnityPath))
{
if (m_textures.Any())
{
Expand Down Expand Up @@ -422,7 +431,7 @@ public void Load(string path, byte[] bytes)
else
#endif
{
item = new TextureItem(i);
item = new TextureItem(i, CreateTextureLoader(i));
}

AddTexture(item);
Expand Down
21 changes: 5 additions & 16 deletions Assets/VRM/UniGLTF/Scripts/IO/TextureItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,17 @@ public IEnumerable<Texture2D> GetTexturesForSaveAssets()
/// Texture from buffer
/// </summary>
/// <param name="index"></param>
public TextureItem(int index, ITextureLoader textureLoader = null)
public TextureItem(int index, ITextureLoader textureLoader)
{
m_textureIndex = index;
if(textureLoader == null)
{
m_textureLoader = CreateTextureLoader(index);
}
else
m_textureLoader = textureLoader;

if(m_textureLoader == null)
{
m_textureLoader = textureLoader;
throw new Exception("ITextureLoader is null.");
}
}

private static ITextureLoader CreateTextureLoader(int index)
{
#if UNIGLTF_USE_WEBREQUEST_TEXTURELOADER
return new UnityWebRequestTextureLoader(index);
#else
return new TextureLoader(index);
#endif
}

#if UNITY_EDITOR
/// <summary>
/// Texture from asset
Expand Down
2 changes: 1 addition & 1 deletion Assets/VRM/UniVRM/Scripts/Format/VRMImporterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public VRMMetaObject ReadMeta(bool createThumbnail = false)
// 作成する(先行ロード用)
if (gltfMeta.texture >= 0 && gltfMeta.texture < GLTF.textures.Count)
{
var t = new TextureItem(gltfMeta.texture);
var t = new TextureItem(gltfMeta.texture, CreateTextureLoader(gltfMeta.texture));
t.Process(GLTF, Storage);
meta.Thumbnail = t.Texture;
}
Expand Down

0 comments on commit 12ff8e9

Please sign in to comment.