public void Extract(TextureImportParam param) { if (Textures.Values.Contains(param)) { return; } UnityPath targetPath = default; if (!string.IsNullOrEmpty(param.Uri) && !param.ExtractConverted) { targetPath = m_textureDirectory.Child(param.GltfFileName); } else { switch (param.TextureType) { case TextureImportTypes.StandardMap: { // write converted texture var subAsset = m_subAssets.FirstOrDefault(x => x.name == param.ConvertedName); targetPath = m_textureDirectory.Child(param.ConvertedFileName); File.WriteAllBytes(targetPath.FullPath, subAsset.EncodeToPNG().ToArray()); targetPath.ImportAsset(); break; } default: { // write original bytes targetPath = m_textureDirectory.Child(param.GltfFileName); File.WriteAllBytes(targetPath.FullPath, param.Index0().Result.ToArray()); targetPath.ImportAsset(); break; } } } Textures.Add(targetPath, param); }
public bool TryGetExternal(TextureImportParam param, bool used, out Texture2D external) { if (param.Index0 != null && ExternalMap != null) { var cacheName = param.ConvertedName; if (param.TextureType == TextureImportTypes.NormalMap) { cacheName = param.GltfName; if (m_textureCache.TryGetValue(cacheName, out TextureLoadInfo normalInfo)) { external = normalInfo.Texture; return(true); } } if (ExternalMap.TryGetValue(cacheName, out external)) { m_textureCache.Add(cacheName, new TextureLoadInfo(external, used, true)); return(true); } } external = default; return(false); }
public static void Configure(TextureImportParam textureInfo, IDictionary <string, Texture2D> ExternalMap) { switch (textureInfo.TextureType) { case TextureImportTypes.NormalMap: { if (ExternalMap.TryGetValue(textureInfo.GltfName, out Texture2D external)) { ConfigureSize(external); ConfigureNormalMap(external); } } break; case TextureImportTypes.StandardMap: { if (ExternalMap.TryGetValue(textureInfo.ConvertedName, out Texture2D external)) { ConfigureSize(external); ConfigureLinear(external); } } break; case TextureImportTypes.sRGB: { if (ExternalMap.TryGetValue(textureInfo.GltfName, out Texture2D external)) { ConfigureSize(external); } } break; default: throw new NotImplementedException(); } }
/// <summary> /// VRM-1 の thumbnail テクスチャー。gltf.textures ではなく gltf.images の参照であることに注意(sampler等の設定が無い) /// /// MToonとは無関係だがとりあえずここに /// </summary> /// <param name="parser"></param> /// <param name="vrm"></param> /// <param name="value"></param> /// <returns></returns> public static bool TryGetMetaThumbnailTextureImportParam(GltfParser parser, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm, out TextureImportParam value) { if (!vrm.Meta.ThumbnailImage.HasValue) { value = default; return(false); } // thumbnail var imageIndex = vrm.Meta.ThumbnailImage.Value; var gltfImage = parser.GLTF.images[imageIndex]; var name = new TextureImportName(TextureImportTypes.sRGB, gltfImage.name, gltfImage.GetExt(), ""); GetTextureBytesAsync getBytesAsync = () => { var bytes = parser.GLTF.GetImageBytes(parser.Storage, imageIndex); return(Task.FromResult(GltfTextureImporter.ToArray(bytes))); }; value = new TextureImportParam(name, Vector2.zero, Vector2.one, default, TextureImportTypes.sRGB, default, default,
/// <summary> /// VRM-1 の thumbnail テクスチャー。gltf.textures ではなく gltf.images の参照であることに注意(sampler等の設定が無い) /// </summary> public static bool TryGetMetaThumbnailTextureImportParam(GltfParser parser, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm, out (SubAssetKey, TextureImportParam) value) { if (vrm?.Meta?.ThumbnailImage == null) { value = default; return(false); } var imageIndex = vrm.Meta.ThumbnailImage.Value; var gltfImage = parser.GLTF.images[imageIndex]; var name = TextureImportName.GetUnityObjectName(TextureImportTypes.sRGB, gltfImage.name, gltfImage.uri); GetTextureBytesAsync getThumbnailImageBytesAsync = () => { var bytes = parser.GLTF.GetImageBytes(parser.Storage, imageIndex); return(Task.FromResult(GltfTextureImporter.ToArray(bytes))); }; var param = new TextureImportParam(name, gltfImage.GetExt(), gltfImage.uri, Vector2.zero, Vector2.one, default, TextureImportTypes.sRGB, default, default,
private static bool TryGetNormalTexture(GltfParser parser, glTFMaterial src, out (SubAssetKey, TextureImportParam) pair) { try { pair = GltfPBRMaterial.NormalTexture(parser, src); return(true); } catch (NullReferenceException) { pair = default; return(false); } catch (ArgumentOutOfRangeException) { pair = default; return(false); } }
private static bool TryGetLinearTexture(GltfParser parser, Vrm10TextureInfo info, out (SubAssetKey, TextureImportParam) pair) { try { var(offset, scale) = GetTextureOffsetAndScale(info); pair = GltfTextureImporter.CreateLinear(parser, info.index, offset, scale); return(true); } catch (NullReferenceException) { pair = default; return(false); } catch (ArgumentOutOfRangeException) { pair = default; return(false); } }
private static bool TryGetUvAnimationMaskTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair) { return(TryGetLinearTexture(parser, new Vrm10TextureInfo(mToon.UvAnimationMaskTexture), out pair)); }
private static bool TryGetOutlineWidthMultiplyTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair) { return(TryGetLinearTexture(parser, new Vrm10TextureInfo(mToon.OutlineWidthMultiplyTexture), out pair)); }
private static bool TryGetRimMultiplyTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair) { return(TryGetSRGBTexture(parser, new Vrm10TextureInfo(mToon.RimMultiplyTexture), out pair)); }
private static bool TryGetMatcapTexture(GltfParser parser, VRMC_materials_mtoon mToon, out (SubAssetKey, TextureImportParam) pair) { return(TryGetSRGBTexture(parser, new Vrm10TextureInfo(mToon.ShadingShiftTexture), out pair)); }