mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-08 20:08:53 -05:00
remove UnityWebRequestTextureLoader
This commit is contained in:
@@ -39,7 +39,7 @@ namespace UniGLTF
|
||||
|
||||
var externalTextures = EnumerateTexturesFromUri(externalObjectMap, parser, UnityPath.FromUnityPath(scriptedImporter.assetPath).Parent).ToArray();
|
||||
|
||||
using (var loaded = new ImporterContext(parser, null, externalObjectMap.Concat(externalTextures)))
|
||||
using (var loaded = new ImporterContext(parser, externalObjectMap.Concat(externalTextures)))
|
||||
{
|
||||
// settings TextureImporters
|
||||
foreach (var textureInfo in GltfTextureEnumerator.Enumerate(parser.GLTF))
|
||||
@@ -96,7 +96,6 @@ namespace UniGLTF
|
||||
if (exclude != null && exclude.Any(kv => kv.Item2.name == asset.name))
|
||||
{
|
||||
// exclude. skip
|
||||
var a = 0;
|
||||
}
|
||||
else{
|
||||
if(used.Add(asset)){
|
||||
|
||||
@@ -41,24 +41,10 @@ namespace UniGLTF
|
||||
IAwaitCaller m_awaitCaller;
|
||||
|
||||
public ImporterContext(GltfParser parser,
|
||||
LoadTextureAsyncFunc loadTextureAsync = null,
|
||||
IEnumerable<(string, UnityEngine.Object)> externalObjectMap = null)
|
||||
{
|
||||
m_parser = parser;
|
||||
if (loadTextureAsync == null)
|
||||
{
|
||||
#if UNIGLTF_USE_WEBREQUEST_TEXTURELOADER
|
||||
loadTextureAsync = (awaitCaller, index, used) => UnityWebRequestTextureLoader.LoadTextureAsync(index);
|
||||
#else
|
||||
loadTextureAsync = async (awaitCaller, index, used) =>
|
||||
{
|
||||
var texture = await GltfTextureLoader.LoadTextureAsync(awaitCaller, GLTF, Storage, index);
|
||||
return new TextureLoadInfo(texture, used, false);
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
m_textureFactory = new TextureFactory(loadTextureAsync, externalObjectMap);
|
||||
m_textureFactory = new TextureFactory(GLTF, Storage, externalObjectMap);
|
||||
m_materialFactory = new MaterialFactory(GLTF, Storage, externalObjectMap);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,10 +42,12 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
|
||||
public delegate Task<TextureLoadInfo> LoadTextureAsyncFunc(IAwaitCaller awaitCaller, int index, bool used);
|
||||
public delegate Task<Texture2D> GetTextureAsyncFunc(IAwaitCaller awaitCaller, glTF gltf, GetTextureParam param);
|
||||
public class TextureFactory : IDisposable
|
||||
{
|
||||
glTF m_gltf;
|
||||
IStorage m_storage;
|
||||
|
||||
public readonly Dictionary<string, Texture2D> ExternalMap;
|
||||
|
||||
public bool TryGetExternal(GetTextureParam param, bool used, out Texture2D external)
|
||||
@@ -72,12 +74,11 @@ namespace UniGLTF
|
||||
return false;
|
||||
}
|
||||
|
||||
public UnityPath ImageBaseDir { get; set; }
|
||||
|
||||
public TextureFactory(LoadTextureAsyncFunc loadTextureAsync,
|
||||
IEnumerable<(string, UnityEngine.Object)> externalMap)
|
||||
public TextureFactory(glTF gltf, IStorage storage, IEnumerable<(string, UnityEngine.Object)> externalMap)
|
||||
{
|
||||
LoadTextureAsync = loadTextureAsync;
|
||||
m_gltf = gltf;
|
||||
m_storage = storage;
|
||||
|
||||
if (externalMap != null)
|
||||
{
|
||||
ExternalMap = externalMap
|
||||
@@ -132,14 +133,13 @@ namespace UniGLTF
|
||||
|
||||
public IEnumerable<TextureLoadInfo> Textures => m_textureCache.Values;
|
||||
|
||||
public LoadTextureAsyncFunc LoadTextureAsync;
|
||||
|
||||
async Task<TextureLoadInfo> GetOrCreateBaseTexture(IAwaitCaller awaitCaller, glTF gltf, int textureIndex, bool used)
|
||||
{
|
||||
var name = gltf.textures[textureIndex].name;
|
||||
if (!m_textureCache.TryGetValue(name, out TextureLoadInfo cacheInfo))
|
||||
{
|
||||
cacheInfo = await LoadTextureAsync(awaitCaller, textureIndex, used);
|
||||
var texture = await GltfTextureLoader.LoadTextureAsync(awaitCaller, m_gltf, m_storage, textureIndex);
|
||||
cacheInfo = new TextureLoadInfo(texture, used, false);
|
||||
m_textureCache.Add(name, cacheInfo);
|
||||
}
|
||||
return cacheInfo;
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public class UnityWebRequestTextureLoader
|
||||
{
|
||||
public Texture2D Texture
|
||||
{
|
||||
private set;
|
||||
get;
|
||||
}
|
||||
|
||||
int m_textureIndex;
|
||||
|
||||
public UnityWebRequestTextureLoader(int textureIndex)
|
||||
{
|
||||
m_textureIndex = textureIndex;
|
||||
}
|
||||
|
||||
UnityWebRequest m_uwr;
|
||||
public void Dispose()
|
||||
{
|
||||
if (m_uwr != null)
|
||||
{
|
||||
m_uwr.Dispose();
|
||||
m_uwr = null;
|
||||
}
|
||||
}
|
||||
|
||||
string m_textureName = default;
|
||||
public void ProcessOnAnyThread()
|
||||
{
|
||||
}
|
||||
|
||||
class Deleter : IDisposable
|
||||
{
|
||||
string m_path;
|
||||
public Deleter(string path)
|
||||
{
|
||||
m_path = path;
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
if (File.Exists(m_path))
|
||||
{
|
||||
File.Delete(m_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator ProcessOnMainThread(glTF gltf, IStorage storage, bool isLinear, glTFTextureSampler sampler)
|
||||
{
|
||||
var gltfTexture = gltf.textures[m_textureIndex];
|
||||
var bytes = gltf.GetImageBytes(storage, gltfTexture.source);
|
||||
|
||||
// tmp file
|
||||
var tmp = Path.GetTempFileName();
|
||||
using (var f = new FileStream(tmp, FileMode.Create))
|
||||
{
|
||||
f.Write(bytes.Array, bytes.Offset, bytes.Count);
|
||||
}
|
||||
|
||||
using (var d = new Deleter(tmp))
|
||||
{
|
||||
var url = "file:///" + tmp.Replace("\\", "/");
|
||||
Debug.LogFormat("UnityWebRequest: {0}", url);
|
||||
#if UNITY_2017_1_OR_NEWER
|
||||
using (var m_uwr = UnityWebRequestTexture.GetTexture(url, true))
|
||||
{
|
||||
yield return m_uwr.SendWebRequest();
|
||||
|
||||
if (m_uwr.isNetworkError || m_uwr.isHttpError)
|
||||
{
|
||||
Debug.LogWarning(m_uwr.error);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get downloaded asset bundle
|
||||
Texture = ((DownloadHandlerTexture)m_uwr.downloadHandler).texture;
|
||||
Texture.name = m_textureName;
|
||||
}
|
||||
}
|
||||
#elif UNITY_5
|
||||
using (var m_uwr = new WWW(url))
|
||||
{
|
||||
yield return m_uwr;
|
||||
|
||||
// wait for request
|
||||
while (!m_uwr.isDone)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(m_uwr.error))
|
||||
{
|
||||
Debug.Log(m_uwr.error);
|
||||
yield break;
|
||||
}
|
||||
|
||||
// Get downloaded asset bundle
|
||||
Texture = m_uwr.textureNonReadable;
|
||||
Texture.name = m_textureName;
|
||||
}
|
||||
#else
|
||||
#error Unsupported Unity version
|
||||
#endif
|
||||
}
|
||||
if (sampler != null)
|
||||
{
|
||||
TextureSamplerUtil.SetSampler(Texture, sampler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b91b7b42ddfd6284a9303a0901fccaa3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -80,7 +80,7 @@ namespace VRM
|
||||
return (texture.name, texture);
|
||||
}).ToArray();
|
||||
|
||||
using (var context = new VRMImporterContext(parser, null, map))
|
||||
using (var context = new VRMImporterContext(parser, map))
|
||||
{
|
||||
var editor = new VRMEditorImporterContext(context, prefabPath);
|
||||
foreach (var textureInfo in new VRMTextureEnumerator(context.VRM).Enumerate(parser.GLTF))
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace VRM
|
||||
return (texture.name, texture: texture as UnityEngine.Object);
|
||||
}).ToArray();
|
||||
|
||||
using (var context = new VRMImporterContext(parser, null, map))
|
||||
using (var context = new VRMImporterContext(parser, map))
|
||||
{
|
||||
var editor = new VRMEditorImporterContext(context, prefabPath);
|
||||
foreach (var textureInfo in new VRMTextureEnumerator(context.VRM).Enumerate(parser.GLTF))
|
||||
|
||||
@@ -19,8 +19,7 @@ namespace VRM
|
||||
public VRM.glTF_VRM_extensions VRM { get; private set; }
|
||||
|
||||
public VRMImporterContext(GltfParser parser,
|
||||
UniGLTF.LoadTextureAsyncFunc asyncTextureLoader = null,
|
||||
IEnumerable<(string, UnityEngine.Object)> externalObjectMap = null) : base(parser, asyncTextureLoader, externalObjectMap)
|
||||
IEnumerable<(string, UnityEngine.Object)> externalObjectMap = null) : base(parser, externalObjectMap)
|
||||
{
|
||||
// parse VRM part
|
||||
if (glTF_VRM_extensions.TryDeserialize(GLTF.extensions, out glTF_VRM_extensions vrm))
|
||||
|
||||
Reference in New Issue
Block a user