public IEnumerator ProcessOnMainThread(bool isLinear, glTFTextureSampler sampler) { // tmp file var tmp = Path.GetTempFileName(); using (var f = new FileStream(tmp, FileMode.Create)) { f.Write(m_segments.Array, m_segments.Offset, m_segments.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); } }
public static void Serialize_gltf_samplers_ITEM(JsonFormatter f, glTFTextureSampler value) { f.BeginMap(); if (true) { f.Key("magFilter"); f.Value((int)value.magFilter); } if (true) { f.Key("minFilter"); f.Value((int)value.minFilter); } if (true) { f.Key("wrapS"); f.Value((int)value.wrapS); } if (true) { f.Key("wrapT"); f.Value((int)value.wrapT); } if (value.extensions != null) { f.Key("extensions"); value.extensions.Serialize(f); } if (value.extras != null) { f.Key("extras"); value.extras.Serialize(f); } if (!string.IsNullOrEmpty(value.name)) { f.Key("name"); f.Value(value.name); } f.EndMap(); }
public IEnumerator ProcessOnMainThread(bool isLinear, glTFTextureSampler sampler) { // // texture from assets // m_assetPath.ImportAsset(); var importer = m_assetPath.GetImporter <TextureImporter>(); if (importer == null) { Debug.LogWarningFormat("fail to get TextureImporter: {0}", m_assetPath); } importer.maxTextureSize = 8192; importer.sRGBTexture = !isLinear; importer.SaveAndReimport(); Texture = m_assetPath.LoadAsset <Texture2D>(); //Texture.name = m_textureName; if (Texture == null) { Debug.LogWarningFormat("fail to Load Texture2D: {0}", m_assetPath); } else { var maxSize = Mathf.Max(Texture.width, Texture.height); importer.maxTextureSize = maxSize > 4096 ? 8192 : maxSize > 2048 ? 4096 : maxSize > 1024 ? 2048 : maxSize > 512 ? 1024 : 512; importer.SaveAndReimport(); } if (sampler != null) { TextureSamplerUtil.SetSampler(Texture, sampler); } yield break; }
public IEnumerator ProcessOnMainThread(bool isLinear, glTFTextureSampler sampler) { // // texture from image(png etc) bytes // Texture = new Texture2D(2, 2, TextureFormat.ARGB32, false, isLinear); Texture.name = m_textureName; if (m_imageBytes != null) { Texture.LoadImage(m_imageBytes); } if (sampler != null) { TextureSamplerUtil.SetSampler(Texture, sampler); } yield break; }
public static Task <Texture2D> LoadTaskAsync(UnityPath m_assetPath, bool isLinear, glTFTextureSampler sampler) { // // texture from assets // m_assetPath.ImportAsset(); var importer = m_assetPath.GetImporter <UnityEditor.TextureImporter>(); if (importer == null) { Debug.LogWarningFormat("fail to get TextureImporter: {0}", m_assetPath); } importer.maxTextureSize = 8192; importer.sRGBTexture = !isLinear; importer.SaveAndReimport(); var Texture = m_assetPath.LoadAsset <Texture2D>(); if (Texture == null) { Debug.LogWarningFormat("fail to Load Texture2D: {0}", m_assetPath); } else { var maxSize = Mathf.Max(Texture.width, Texture.height); importer.maxTextureSize = maxSize > 4096 ? 8192 : maxSize > 2048 ? 4096 : maxSize > 1024 ? 2048 : maxSize > 512 ? 1024 : 512; importer.SaveAndReimport(); } if (sampler != null) { TextureSamplerUtil.SetSampler(Texture, sampler); } return(Task.FromResult(Texture)); }
public static void SetSampler(Texture2D texture, glTFTextureSampler sampler) { if (texture == null) { return; } foreach (var kv in GetUnityWrapMode(sampler)) { switch (kv.Key) { case TextureWrapType.All: texture.wrapMode = kv.Value; break; #if UNITY_2017_1_OR_NEWER case TextureWrapType.U: texture.wrapModeU = kv.Value; break; case TextureWrapType.V: texture.wrapModeV = kv.Value; break; case TextureWrapType.W: texture.wrapModeW = kv.Value; break; #endif default: throw new NotImplementedException(); } } texture.filterMode = ImportFilterMode(sampler.minFilter); }
public static IEnumerable <KeyValuePair <TextureWrapType, TextureWrapMode> > GetUnityWrapMode(glTFTextureSampler sampler) { #if UNITY_2017_1_OR_NEWER if (sampler.wrapS == sampler.wrapT) { switch (sampler.wrapS) { case glWrap.NONE: // default yield return(TypeWithMode(TextureWrapType.All, TextureWrapMode.Repeat)); break; case glWrap.CLAMP_TO_EDGE: yield return(TypeWithMode(TextureWrapType.All, TextureWrapMode.Clamp)); break; case glWrap.REPEAT: yield return(TypeWithMode(TextureWrapType.All, TextureWrapMode.Repeat)); break; case glWrap.MIRRORED_REPEAT: yield return(TypeWithMode(TextureWrapType.All, TextureWrapMode.Mirror)); break; default: throw new NotImplementedException(); } } else { switch (sampler.wrapS) { case glWrap.NONE: // default yield return(TypeWithMode(TextureWrapType.U, TextureWrapMode.Repeat)); break; case glWrap.CLAMP_TO_EDGE: yield return(TypeWithMode(TextureWrapType.U, TextureWrapMode.Clamp)); break; case glWrap.REPEAT: yield return(TypeWithMode(TextureWrapType.U, TextureWrapMode.Repeat)); break; case glWrap.MIRRORED_REPEAT: yield return(TypeWithMode(TextureWrapType.U, TextureWrapMode.Mirror)); break; default: throw new NotImplementedException(); } switch (sampler.wrapT) { case glWrap.NONE: // default yield return(TypeWithMode(TextureWrapType.V, TextureWrapMode.Repeat)); break; case glWrap.CLAMP_TO_EDGE: yield return(TypeWithMode(TextureWrapType.V, TextureWrapMode.Clamp)); break; case glWrap.REPEAT: yield return(TypeWithMode(TextureWrapType.V, TextureWrapMode.Repeat)); break; case glWrap.MIRRORED_REPEAT: yield return(TypeWithMode(TextureWrapType.V, TextureWrapMode.Mirror)); break; default: throw new NotImplementedException(); } #else // Unity2017.1より前 // * wrapSとwrapTの区別が無くてwrapしかない // * Mirrorが無い switch (sampler.wrapS) { case glWrap.NONE: // default yield return(TypeWithMode(TextureWrapType.All, TextureWrapMode.Repeat)); break; case glWrap.CLAMP_TO_EDGE: case glWrap.MIRRORED_REPEAT: yield return(TypeWithMode(TextureWrapType.All, TextureWrapMode.Clamp)); break; case glWrap.REPEAT: yield return(TypeWithMode(TextureWrapType.All, TextureWrapMode.Repeat)); break; default: throw new NotImplementedException(); #endif } }
static void SetSampler(Texture2D texture, glTFTextureSampler sampler) { if (texture == null) { return; } switch (sampler.wrapS) { #if UNITY_2017_OR_NEWER case glWrap.CLAMP_TO_EDGE: texture.wrapModeU = TextureWrapMode.Clamp; break; case glWrap.REPEAT: texture.wrapModeU = TextureWrapMode.Repeat; break; case glWrap.MIRRORED_REPEAT: texture.wrapModeU = TextureWrapMode.Mirror; break; #else case glWrap.CLAMP_TO_EDGE: case glWrap.MIRRORED_REPEAT: texture.wrapMode = TextureWrapMode.Clamp; break; case glWrap.REPEAT: texture.wrapMode = TextureWrapMode.Repeat; break; #endif default: throw new NotImplementedException(); } #if UNITY_2017_OR_NEWER switch (sampler.wrapT) { case glWrap.CLAMP_TO_EDGE: texture.wrapModeV = TextureWrapMode.Clamp; break; case glWrap.REPEAT: texture.wrapModeV = TextureWrapMode.Repeat; break; case glWrap.MIRRORED_REPEAT: texture.wrapModeV = TextureWrapMode.Mirror; break; default: throw new NotImplementedException(); } #endif switch (sampler.magFilter) { case glFilter.NEAREST: texture.filterMode = FilterMode.Point; break; case glFilter.LINEAR: texture.filterMode = FilterMode.Bilinear; break; default: throw new NotImplementedException(); } }