/// <summary> /// Normal のテクスチャを変換し index を確定させる /// </summary> /// <param name="normalTexture"></param> /// <returns></returns> public int ExportNormal(Texture src) { if (src == null) { return(-1); } // cache if (m_exportMap.TryGetValue(new ExportKey(src, glTFTextureTypes.Normal), out var index)) { return(index); } // get Texture2D index = Exported.Count; var texture2D = src as Texture2D; if (UseAsset(texture2D)) { // EditorAsset を使うので変換不要 } else { // 後で Bitmap を使うために変換する texture2D = NormalConverter.Export(src); } Exported.Add(texture2D); m_exportMap.Add(new ExportKey(src, glTFTextureTypes.Normal), index); return(index); }
/// <summary> /// /// </summary> /// <param name="prop"></param> /// <param name="smoothness">used only when converting MetallicRoughness maps</param> /// <returns></returns> public Texture2D ConvertTexture(string prop, float smoothnessOrRoughness = 1.0f) { var convertedTexture = Converts.FirstOrDefault(x => x.Key == prop); if (convertedTexture.Value != null) { return(convertedTexture.Value); } if (prop == "_BumpMap") { if (Application.isPlaying) { var converted = new NormalConverter().GetImportTexture(Texture); m_converts.Add(prop, converted); return(converted); } else { #if UNITY_EDITOR var textureAssetPath = AssetDatabase.GetAssetPath(Texture); if (!string.IsNullOrEmpty(textureAssetPath)) { TextureIO.MarkTextureAssetAsNormalMap(textureAssetPath); } else { Debug.LogWarningFormat("no asset for {0}", Texture); } #endif return(Texture); } } if (prop == "_MetallicGlossMap") { var converted = new MetallicRoughnessConverter(smoothnessOrRoughness).GetImportTexture(Texture); m_converts.Add(prop, converted); return(converted); } if (prop == "_OcclusionMap") { var converted = new OcclusionConverter().GetImportTexture(Texture); m_converts.Add(prop, converted); return(converted); } return(null); }