rename AssetTextureUtil.UseAsset to AssetTextureUtil.IsTextureEditorAsset

This commit is contained in:
ousttrue
2021-04-05 13:11:27 +09:00
parent 27fa5dbc60
commit 002e8c6060
11 changed files with 36 additions and 21 deletions

View File

@@ -36,7 +36,7 @@ namespace UniGLTF
using (var exporter = new gltfExporter(gltf, inverseAxis))
{
exporter.Prepare(go);
exporter.Export(settings, AssetTextureUtil.UseAsset);
exporter.Export(settings, AssetTextureUtil.IsTextureEditorAsset );
}

View File

@@ -18,7 +18,7 @@ namespace UniGLTF
filterMode = FilterMode.Bilinear,
};
var textureManager = new TextureExporter(AssetTextureUtil.UseAsset);
var textureManager = new TextureExporter(AssetTextureUtil.IsTextureEditorAsset );
var srcMaterial = new Material(Shader.Find("Standard"));
var offset = new Vector2(0.3f, 0.2f);
@@ -242,7 +242,7 @@ namespace UniGLTF
material.SetColor("_EmissionColor", new Color(0, 1, 2, 1));
material.EnableKeyword("_EMISSION");
var materialExporter = new MaterialExporter();
var textureExportManager = new TextureExporter(AssetTextureUtil.UseAsset);
var textureExportManager = new TextureExporter(AssetTextureUtil.IsTextureEditorAsset );
var gltfMaterial = materialExporter.ExportMaterial(material, textureExportManager);
Assert.AreEqual(gltfMaterial.emissiveFactor, new float[] { 0, 0.5f, 1 });

View File

@@ -15,7 +15,7 @@ namespace UniGLTF
wrapMode = TextureWrapMode.Clamp,
filterMode = FilterMode.Trilinear,
};
var textureManager = new TextureExporter(AssetTextureUtil.UseAsset);
var textureManager = new TextureExporter(AssetTextureUtil.IsTextureEditorAsset );
var material = new Material(Shader.Find("Standard"));
material.mainTexture = tex0;

View File

@@ -106,7 +106,7 @@ namespace UniGLTF
using (var exporter = new gltfExporter(gltf))
{
exporter.Prepare(go);
exporter.Export(MeshExportSettings.Default, AssetTextureUtil.UseAsset);
exporter.Export(MeshExportSettings.Default, AssetTextureUtil.IsTextureEditorAsset );
// remove empty buffer
gltf.buffers.Clear();
@@ -298,7 +298,7 @@ namespace UniGLTF
using (var exporter = new gltfExporter(gltf))
{
exporter.Prepare(CreateSimpleScene());
exporter.Export(MeshExportSettings.Default, AssetTextureUtil.UseAsset);
exporter.Export(MeshExportSettings.Default, AssetTextureUtil.IsTextureEditorAsset );
}
var expected = gltf.ToJson().ParseAsJson();
@@ -534,7 +534,7 @@ namespace UniGLTF
using (var exporter = new gltfExporter(gltf))
{
exporter.Prepare(go);
exporter.Export(UniGLTF.MeshExportSettings.Default, AssetTextureUtil.UseAsset);
exporter.Export(UniGLTF.MeshExportSettings.Default, AssetTextureUtil.IsTextureEditorAsset );
json = gltf.ToJson();
}

View File

@@ -170,7 +170,7 @@ namespace VRM.Samples
*/
importedJson.RemoveValue(Utf8String.From("/bufferViews/*/byteStride"));
var vrm = VRMExporter.Export(UniGLTF.MeshExportSettings.Default, context.Root, AssetTextureUtil.UseAsset);
var vrm = VRMExporter.Export(UniGLTF.MeshExportSettings.Default, context.Root, AssetTextureUtil.IsTextureEditorAsset );
// TODO: Check contents in JSON
/*var exportJson = */

View File

@@ -11,7 +11,7 @@ namespace VRM.Samples
{
var material = Resources.Load<Material>(resourceName);
var exporter = new VRMMaterialExporter();
var textureManager = new TextureExporter(AssetTextureUtil.UseAsset);
var textureManager = new TextureExporter(AssetTextureUtil.IsTextureEditorAsset );
var exported = exporter.ExportMaterial(material, textureManager);
// parse glTFExtensionExport to glTFExtensionImport

View File

@@ -225,7 +225,7 @@ namespace VRM
using (var exporter = new VRMExporter(gltf))
{
exporter.Prepare(target);
exporter.Export(settings.MeshExportSettings, AssetTextureUtil.UseAsset);
exporter.Export(settings.MeshExportSettings, AssetTextureUtil.IsTextureEditorAsset );
}
var bytes = gltf.ToGlbBytes();
File.WriteAllBytes(path, bytes);

View File

@@ -16,7 +16,7 @@ namespace VRM
filterMode = FilterMode.Bilinear,
};
var textureManager = new TextureExporter(AssetTextureUtil.UseAsset);
var textureManager = new TextureExporter(AssetTextureUtil.IsTextureEditorAsset );
var srcMaterial = new Material(Shader.Find("VRM/MToon"));
var offset = new Vector2(0.3f, 0.2f);

View File

@@ -106,7 +106,7 @@ namespace VRM
try
{
// export
var vrm = VRMExporter.Export(UniGLTF.MeshExportSettings.Default, go, AssetTextureUtil.UseAsset);
var vrm = VRMExporter.Export(UniGLTF.MeshExportSettings.Default, go, AssetTextureUtil.IsTextureEditorAsset );
// re import
if (vrm != null)

View File

@@ -7,11 +7,11 @@ namespace VRMShaders
public static class AssetTextureUtil
{
/// <summary>
/// TextureImporter.maxTextureSize が元のテクスチャーより小さいか否かの判定
/// TextureImporter.maxTextureSize が オリジナルの画像Sizeより小さいか
/// </summary>
/// <param name="src"></param>
/// <returns></returns>
public static bool CopyIfMaxTextureSizeIsSmaller(Texture src)
public static bool IsMaxTextureSizeSmallerThanOriginalTextureSize(Texture2D src)
{
var path = AssetDatabase.GetAssetPath(src);
var textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
@@ -35,21 +35,36 @@ namespace VRMShaders
}
/// <summary>
/// 元の Asset が存在して、 TextureImporter に設定された画像サイズが小さくない
/// Export するときに オリジナルのテクスチャーアセット(png/jpg)を使用するか否か。
/// 条件は、
///
/// * TextureAsset が存在する
/// * TextureImporter の maxSize
///
/// </summary>
/// <param name="src"></param>
/// <param name="texture2D"></param>
/// <returns></returns>
public static bool UseAsset(Texture texture)
public static bool IsTextureEditorAsset(Texture texture)
{
if (texture != null && !string.IsNullOrEmpty(UnityEditor.AssetDatabase.GetAssetPath(texture)))
if (texture is Texture2D texture2D && !string.IsNullOrEmpty(UnityEditor.AssetDatabase.GetAssetPath(texture2D)))
{
if (CopyIfMaxTextureSizeIsSmaller(texture))
// exists Texture2D asset
if (IsMaxTextureSizeSmallerThanOriginalTextureSize(texture2D))
{
// Texture Inspector の MaxSize 設定で、テクスチャをオリジナルサイズよりも小さいサイズで Texture 化する指示を行っているため
// glTF Exporter もそれにしたがって、解釈をする
//
// 4096x4096 のような巨大なテクスチャーがそのまま出力されることを、Unityの TextureImporter.maxSize により防止する
//
return false;
}
// use Texture2D asset. EncodeToPng
return true;
}
// not Texture2D or not exists Texture2D asset. EncodeToPng
return false;
}
}

View File

@@ -97,16 +97,16 @@ namespace VRMShaders
var occlusion = new Texture2D(4, 4, TextureFormat.ARGB32, false, true);
{
var exporter = new TextureExporter(AssetTextureUtil.UseAsset);
var exporter = new TextureExporter(AssetTextureUtil.IsTextureEditorAsset );
Assert.AreEqual(-1, exporter.ExportMetallicSmoothnessOcclusion(null, 0, null));
}
{
var exporter = new TextureExporter(AssetTextureUtil.UseAsset);
var exporter = new TextureExporter(AssetTextureUtil.IsTextureEditorAsset );
Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(null, 0, occlusion));
Assert.AreEqual(1, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, null));
}
{
var exporter = new TextureExporter(AssetTextureUtil.UseAsset);
var exporter = new TextureExporter(AssetTextureUtil.IsTextureEditorAsset );
Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, occlusion));
Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(null, 0, occlusion));
Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, null));