From 27fa5dbc60ff5723c9322abe2d79ae25944f7562 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 2 Apr 2021 18:35:02 +0900 Subject: [PATCH] VRMShaders.TextureExporter, AssetTextureUtil --- Assets/UniGLTF/Editor/UniGLTF.Editor.asmdef | 3 ++- .../Editor/UniGLTF/GltfExportWindow.cs | 1 + Assets/UniGLTF/Tests/UniGLTF.Tests.asmdef | 3 ++- Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs | 23 ------------------- Assets/UniGLTF/Tests/UniGLTF/UniGLTFTests.cs | 2 +- .../Tests/VRM.Samples.Editor.Tests.asmdef | 2 +- .../Editor/Tests/VRMImportExportTests.cs | 1 + Assets/VRM/Editor/Format/VRMEditorExporter.cs | 1 + Assets/VRM/Editor/VRM.Editor.asmdef | 3 ++- Assets/VRM/Tests/VRM.Tests.asmdef | 2 +- Assets/VRM/Tests/VRMLoadTests.cs | 1 + Assets/VRMShaders/Editor.meta | 8 +++++++ .../Editor}/AssetTextureUtil.cs | 5 ++-- .../Editor}/AssetTextureUtil.cs.meta | 0 .../Editor/VRMShaders.Editor.asmdef | 3 +++ .../Editor/VRMShaders.Editor.asmdef.meta | 7 ++++++ .../Runtime}/TextureExporter.cs | 0 .../Runtime}/TextureExporter.cs.meta | 0 .../Tests/MetallicRoughnessConverterTests.cs | 23 +++++++++++++++++++ .../VRMShaders/Tests/VRMShaders.Tests.asmdef | 3 ++- 20 files changed, 59 insertions(+), 32 deletions(-) create mode 100644 Assets/VRMShaders/Editor.meta rename Assets/{UniGLTF/Editor/UniGLTF => VRMShaders/Editor}/AssetTextureUtil.cs (92%) rename Assets/{UniGLTF/Editor/UniGLTF => VRMShaders/Editor}/AssetTextureUtil.cs.meta (100%) create mode 100644 Assets/VRMShaders/Editor/VRMShaders.Editor.asmdef create mode 100644 Assets/VRMShaders/Editor/VRMShaders.Editor.asmdef.meta rename Assets/{UniGLTF/Runtime/UniGLTF/IO/TextureIO => VRMShaders/Runtime}/TextureExporter.cs (100%) rename Assets/{UniGLTF/Runtime/UniGLTF/IO/TextureIO => VRMShaders/Runtime}/TextureExporter.cs.meta (100%) diff --git a/Assets/UniGLTF/Editor/UniGLTF.Editor.asmdef b/Assets/UniGLTF/Editor/UniGLTF.Editor.asmdef index 60c094749..403b405c9 100644 --- a/Assets/UniGLTF/Editor/UniGLTF.Editor.asmdef +++ b/Assets/UniGLTF/Editor/UniGLTF.Editor.asmdef @@ -4,7 +4,8 @@ "UniGLTF", "MeshUtility", "MeshUtility.Editor", - "VRMShaders" + "VRMShaders", + "VRMShaders.Editor" ], "optionalUnityReferences": [], "includePlatforms": [ diff --git a/Assets/UniGLTF/Editor/UniGLTF/GltfExportWindow.cs b/Assets/UniGLTF/Editor/UniGLTF/GltfExportWindow.cs index 6ed78c1b1..da1bdea89 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/GltfExportWindow.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/GltfExportWindow.cs @@ -5,6 +5,7 @@ using System.Reflection; using UniGLTF.Animation; using UnityEditor; using UnityEngine; +using VRMShaders; namespace UniGLTF { diff --git a/Assets/UniGLTF/Tests/UniGLTF.Tests.asmdef b/Assets/UniGLTF/Tests/UniGLTF.Tests.asmdef index 71ff882a1..bb5646ef0 100644 --- a/Assets/UniGLTF/Tests/UniGLTF.Tests.asmdef +++ b/Assets/UniGLTF/Tests/UniGLTF.Tests.asmdef @@ -3,7 +3,8 @@ "references": [ "UniGLTF", "UniGLTF.Editor", - "VRMShaders" + "VRMShaders", + "VRMShaders.Editor" ], "optionalUnityReferences": [ "TestAssemblies" diff --git a/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs b/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs index 4371fcdd7..f18311fa1 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs @@ -50,28 +50,5 @@ namespace UniGLTF var (bytes, mime) = GltfTextureExporter.GetBytesWithMime(readonlyTexture); Assert.NotNull(bytes); } - - [Test] - public void ExportMetallicSmoothnessOcclusion_Test() - { - var metallic = new Texture2D(4, 4, TextureFormat.ARGB32, false, true); - var occlusion = new Texture2D(4, 4, TextureFormat.ARGB32, false, true); - - { - var exporter = new TextureExporter(AssetTextureUtil.UseAsset); - Assert.AreEqual(-1, exporter.ExportMetallicSmoothnessOcclusion(null, 0, null)); - } - { - var exporter = new TextureExporter(AssetTextureUtil.UseAsset); - Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(null, 0, occlusion)); - Assert.AreEqual(1, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, null)); - } - { - var exporter = new TextureExporter(AssetTextureUtil.UseAsset); - Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, occlusion)); - Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(null, 0, occlusion)); - Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, null)); - } - } } } diff --git a/Assets/UniGLTF/Tests/UniGLTF/UniGLTFTests.cs b/Assets/UniGLTF/Tests/UniGLTF/UniGLTFTests.cs index cd73aa0c3..f50eb2131 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/UniGLTFTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/UniGLTFTests.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Linq; using UniJSON; using UnityEngine; - +using VRMShaders; namespace UniGLTF { diff --git a/Assets/VRM.Samples/Editor/Tests/VRM.Samples.Editor.Tests.asmdef b/Assets/VRM.Samples/Editor/Tests/VRM.Samples.Editor.Tests.asmdef index fad13ad55..813b970b4 100644 --- a/Assets/VRM.Samples/Editor/Tests/VRM.Samples.Editor.Tests.asmdef +++ b/Assets/VRM.Samples/Editor/Tests/VRM.Samples.Editor.Tests.asmdef @@ -8,7 +8,7 @@ "UniVRM.Editor", "VRM.Tests", "VRMShaders", - "UniGLTF.Editor" + "VRMShaders.Editor" ], "optionalUnityReferences": [ "TestAssemblies" diff --git a/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs b/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs index ee23d0e99..adb843443 100644 --- a/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs +++ b/Assets/VRM.Samples/Editor/Tests/VRMImportExportTests.cs @@ -5,6 +5,7 @@ using UniJSON; using UnityEngine; using MeshUtility; using System; +using VRMShaders; namespace VRM.Samples { diff --git a/Assets/VRM/Editor/Format/VRMEditorExporter.cs b/Assets/VRM/Editor/Format/VRMEditorExporter.cs index 40c5e8cdc..4f4e02c46 100644 --- a/Assets/VRM/Editor/Format/VRMEditorExporter.cs +++ b/Assets/VRM/Editor/Format/VRMEditorExporter.cs @@ -6,6 +6,7 @@ using System.Text; using UniGLTF; using UnityEditor; using UnityEngine; +using VRMShaders; namespace VRM { diff --git a/Assets/VRM/Editor/VRM.Editor.asmdef b/Assets/VRM/Editor/VRM.Editor.asmdef index e9422cc38..0cdfce423 100644 --- a/Assets/VRM/Editor/VRM.Editor.asmdef +++ b/Assets/VRM/Editor/VRM.Editor.asmdef @@ -8,7 +8,8 @@ "UniUnlit", "UniGLTF", "UniGLTF.Editor", - "VRMShaders" + "VRMShaders", + "VRMShaders.Editor" ], "optionalUnityReferences": [], "includePlatforms": [ diff --git a/Assets/VRM/Tests/VRM.Tests.asmdef b/Assets/VRM/Tests/VRM.Tests.asmdef index 36d8d3e11..de7e2bdab 100644 --- a/Assets/VRM/Tests/VRM.Tests.asmdef +++ b/Assets/VRM/Tests/VRM.Tests.asmdef @@ -6,7 +6,7 @@ "MeshUtility", "MeshUtility.Editor", "VRMShaders", - "UniGLTF.Editor" + "VRMShaders.Editor" ], "optionalUnityReferences": [ "TestAssemblies" diff --git a/Assets/VRM/Tests/VRMLoadTests.cs b/Assets/VRM/Tests/VRMLoadTests.cs index ce4d2fce5..e1704c2cf 100644 --- a/Assets/VRM/Tests/VRMLoadTests.cs +++ b/Assets/VRM/Tests/VRMLoadTests.cs @@ -4,6 +4,7 @@ using System.IO; using NUnit.Framework; using UniGLTF; using UnityEngine; +using VRMShaders; namespace VRM { diff --git a/Assets/VRMShaders/Editor.meta b/Assets/VRMShaders/Editor.meta new file mode 100644 index 000000000..ac317874a --- /dev/null +++ b/Assets/VRMShaders/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 58204522f08a6fe4f846a5817a37f902 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Editor/UniGLTF/AssetTextureUtil.cs b/Assets/VRMShaders/Editor/AssetTextureUtil.cs similarity index 92% rename from Assets/UniGLTF/Editor/UniGLTF/AssetTextureUtil.cs rename to Assets/VRMShaders/Editor/AssetTextureUtil.cs index d22efde76..2a608107b 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/AssetTextureUtil.cs +++ b/Assets/VRMShaders/Editor/AssetTextureUtil.cs @@ -2,7 +2,7 @@ using System.Reflection; using UnityEditor; using UnityEngine; -namespace UniGLTF +namespace VRMShaders { public static class AssetTextureUtil { @@ -13,7 +13,8 @@ namespace UniGLTF /// public static bool CopyIfMaxTextureSizeIsSmaller(Texture src) { - var textureImporter = AssetImporter.GetAtPath(UnityPath.FromAsset(src).Value) as TextureImporter; + var path = AssetDatabase.GetAssetPath(src); + var textureImporter = AssetImporter.GetAtPath(path) as TextureImporter; // private メソッド TextureImporter.GetWidthAndHeight を無理やり呼ぶ var getSizeMethod = typeof(TextureImporter).GetMethod("GetWidthAndHeight", BindingFlags.NonPublic | BindingFlags.Instance); diff --git a/Assets/UniGLTF/Editor/UniGLTF/AssetTextureUtil.cs.meta b/Assets/VRMShaders/Editor/AssetTextureUtil.cs.meta similarity index 100% rename from Assets/UniGLTF/Editor/UniGLTF/AssetTextureUtil.cs.meta rename to Assets/VRMShaders/Editor/AssetTextureUtil.cs.meta diff --git a/Assets/VRMShaders/Editor/VRMShaders.Editor.asmdef b/Assets/VRMShaders/Editor/VRMShaders.Editor.asmdef new file mode 100644 index 000000000..9f771ac30 --- /dev/null +++ b/Assets/VRMShaders/Editor/VRMShaders.Editor.asmdef @@ -0,0 +1,3 @@ +{ + "name": "VRMShaders.Editor" +} diff --git a/Assets/VRMShaders/Editor/VRMShaders.Editor.asmdef.meta b/Assets/VRMShaders/Editor/VRMShaders.Editor.asmdef.meta new file mode 100644 index 000000000..8c9bfda5c --- /dev/null +++ b/Assets/VRMShaders/Editor/VRMShaders.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 7da8a75dcade2144aab699032d7d7987 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/TextureExporter.cs b/Assets/VRMShaders/Runtime/TextureExporter.cs similarity index 100% rename from Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/TextureExporter.cs rename to Assets/VRMShaders/Runtime/TextureExporter.cs diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/TextureExporter.cs.meta b/Assets/VRMShaders/Runtime/TextureExporter.cs.meta similarity index 100% rename from Assets/UniGLTF/Runtime/UniGLTF/IO/TextureIO/TextureExporter.cs.meta rename to Assets/VRMShaders/Runtime/TextureExporter.cs.meta diff --git a/Assets/VRMShaders/Tests/MetallicRoughnessConverterTests.cs b/Assets/VRMShaders/Tests/MetallicRoughnessConverterTests.cs index 1f79152f9..caef40d25 100644 --- a/Assets/VRMShaders/Tests/MetallicRoughnessConverterTests.cs +++ b/Assets/VRMShaders/Tests/MetallicRoughnessConverterTests.cs @@ -89,5 +89,28 @@ namespace VRMShaders Is.EqualTo(new Color32(255, 0, 0, 255))); } } + + [Test] + public void ExportMetallicSmoothnessOcclusion_Test() + { + var metallic = new Texture2D(4, 4, TextureFormat.ARGB32, false, true); + var occlusion = new Texture2D(4, 4, TextureFormat.ARGB32, false, true); + + { + var exporter = new TextureExporter(AssetTextureUtil.UseAsset); + Assert.AreEqual(-1, exporter.ExportMetallicSmoothnessOcclusion(null, 0, null)); + } + { + var exporter = new TextureExporter(AssetTextureUtil.UseAsset); + Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(null, 0, occlusion)); + Assert.AreEqual(1, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, null)); + } + { + var exporter = new TextureExporter(AssetTextureUtil.UseAsset); + Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, occlusion)); + Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(null, 0, occlusion)); + Assert.AreEqual(0, exporter.ExportMetallicSmoothnessOcclusion(metallic, 0, null)); + } + } } } diff --git a/Assets/VRMShaders/Tests/VRMShaders.Tests.asmdef b/Assets/VRMShaders/Tests/VRMShaders.Tests.asmdef index 18b3c3304..a2a91ba59 100644 --- a/Assets/VRMShaders/Tests/VRMShaders.Tests.asmdef +++ b/Assets/VRMShaders/Tests/VRMShaders.Tests.asmdef @@ -1,7 +1,8 @@ { "name": "VRMShaders.Tests", "references": [ - "VRMShaders" + "VRMShaders", + "VRMShaders.Editor" ], "optionalUnityReferences": [ "TestAssemblies"