diff --git a/Assets/UniGLTF/Editor/UniGLTF/GltfExportWindow.cs b/Assets/UniGLTF/Editor/UniGLTF/GltfExportWindow.cs index da1bdea89..4842878dc 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/GltfExportWindow.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/GltfExportWindow.cs @@ -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 ); } diff --git a/Assets/UniGLTF/Tests/UniGLTF/MaterialTests.cs b/Assets/UniGLTF/Tests/UniGLTF/MaterialTests.cs index 039c67c9c..9592d923b 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/MaterialTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/MaterialTests.cs @@ -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 }); diff --git a/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs b/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs index f18311fa1..9911887c2 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs @@ -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; diff --git a/Assets/UniGLTF/Tests/UniGLTF/UniGLTFTests.cs b/Assets/UniGLTF/Tests/UniGLTF/UniGLTFTests.cs index f50eb2131..e4d38cde1 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/UniGLTFTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/UniGLTFTests.cs @@ -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(); } diff --git a/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs b/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs index adb843443..e3e25f9a1 100644 --- a/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs +++ b/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs @@ -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 = */ diff --git a/Assets/VRM.Samples/Editor/Tests/VRMMaterialTests.cs b/Assets/VRM.Samples/Editor/Tests/VRMMaterialTests.cs index 7c98c6829..2f2a63438 100644 --- a/Assets/VRM.Samples/Editor/Tests/VRMMaterialTests.cs +++ b/Assets/VRM.Samples/Editor/Tests/VRMMaterialTests.cs @@ -11,7 +11,7 @@ namespace VRM.Samples { var material = Resources.Load(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 diff --git a/Assets/VRM/Editor/Format/VRMEditorExporter.cs b/Assets/VRM/Editor/Format/VRMEditorExporter.cs index 4f4e02c46..14756193c 100644 --- a/Assets/VRM/Editor/Format/VRMEditorExporter.cs +++ b/Assets/VRM/Editor/Format/VRMEditorExporter.cs @@ -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); diff --git a/Assets/VRM/Tests/MToonTest.cs b/Assets/VRM/Tests/MToonTest.cs index 86d79422d..747e624b5 100644 --- a/Assets/VRM/Tests/MToonTest.cs +++ b/Assets/VRM/Tests/MToonTest.cs @@ -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); diff --git a/Assets/VRM/Tests/VRMLoadTests.cs b/Assets/VRM/Tests/VRMLoadTests.cs index e1704c2cf..dbec0820a 100644 --- a/Assets/VRM/Tests/VRMLoadTests.cs +++ b/Assets/VRM/Tests/VRMLoadTests.cs @@ -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) diff --git a/Assets/VRMShaders/Editor/AssetTextureUtil.cs b/Assets/VRMShaders/Editor/AssetTextureUtil.cs index 2a608107b..a4423e84f 100644 --- a/Assets/VRMShaders/Editor/AssetTextureUtil.cs +++ b/Assets/VRMShaders/Editor/AssetTextureUtil.cs @@ -7,11 +7,11 @@ namespace VRMShaders public static class AssetTextureUtil { /// - /// TextureImporter.maxTextureSize が元のテクスチャーより小さいか否かの判定 + /// TextureImporter.maxTextureSize が オリジナルの画像Sizeより小さいか /// /// /// - 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 } /// - /// 元の Asset が存在して、 TextureImporter に設定された画像サイズが小さくない + /// Export するときに オリジナルのテクスチャーアセット(png/jpg)を使用するか否か。 + /// 条件は、 + /// + /// * TextureAsset が存在する + /// * TextureImporter の maxSize + /// /// /// /// /// - 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; } } diff --git a/Assets/VRMShaders/Tests/MetallicRoughnessConverterTests.cs b/Assets/VRMShaders/Tests/MetallicRoughnessConverterTests.cs index caef40d25..a0cca736a 100644 --- a/Assets/VRMShaders/Tests/MetallicRoughnessConverterTests.cs +++ b/Assets/VRMShaders/Tests/MetallicRoughnessConverterTests.cs @@ -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));