From 7207629094866ade08583df8c39841f73fa2e3a4 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 7 Mar 2022 16:08:17 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[1.0][exporter]=E6=9C=AA=E7=9F=A5=E3=81=AEM?= =?UTF-8?q?aterial(Shader)=E3=81=8C=E5=90=AB=E3=81=BE=E3=82=8C=E3=82=8B?= =?UTF-8?q?=E3=81=93=E3=81=A8=E3=82=92=E6=A4=9C=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UniGLTF/ExportDialog/MaterialValidator.cs | 3 ++ .../ExportDialog/MeshExportValidator.cs | 2 +- Assets/VRM/Editor/Format/VRMExporterWizard.cs | 36 ---------------- .../VRM/Editor/Format/VRMMaterialValidator.cs | 43 +++++++++++++++++++ .../Format/VRMMaterialValidator.cs.meta | 11 +++++ Assets/VRM10/Editor/VRM10MaterialValidator.cs | 41 ++++++++++++++++++ .../Editor/VRM10MaterialValidator.cs.meta | 11 +++++ Assets/VRM10/Editor/Vrm10ExportDialog.cs | 4 ++ 8 files changed, 114 insertions(+), 37 deletions(-) create mode 100644 Assets/VRM/Editor/Format/VRMMaterialValidator.cs create mode 100644 Assets/VRM/Editor/Format/VRMMaterialValidator.cs.meta create mode 100644 Assets/VRM10/Editor/VRM10MaterialValidator.cs create mode 100644 Assets/VRM10/Editor/VRM10MaterialValidator.cs.meta diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MaterialValidator.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MaterialValidator.cs index bf6d15af4..b1c9f32a5 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MaterialValidator.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MaterialValidator.cs @@ -3,6 +3,9 @@ using UnityEngine; namespace UniGLTF { + /// + /// MeshExportValidator から使われる + /// public interface IMaterialValidator { /// diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs index 976a39ff4..5ab9e55a8 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs @@ -85,7 +85,7 @@ namespace UniGLTF var gltfMaterial = MaterialValidator.GetGltfMaterialTypeFromUnityShaderName(m.shader.name); if (string.IsNullOrEmpty(gltfMaterial)) { - yield return Validation.Warning($"{m}: unknown shader: {m.shader.name} => export as gltf default"); + yield return Validation.Warning($"{m}: unknown shader: {m.shader.name} => export as gltf default", ValidationContext.Create(m)); } var used = new HashSet(); diff --git a/Assets/VRM/Editor/Format/VRMExporterWizard.cs b/Assets/VRM/Editor/Format/VRMExporterWizard.cs index 171533f06..be621b52f 100644 --- a/Assets/VRM/Editor/Format/VRMExporterWizard.cs +++ b/Assets/VRM/Editor/Format/VRMExporterWizard.cs @@ -121,42 +121,6 @@ namespace VRM m_meshes = null; } - /// - /// VRM0 - /// - class VRMMaterialValidator : DefaultMaterialValidator - { - public override string GetGltfMaterialTypeFromUnityShaderName(string shaderName) - { - var name = VRMMaterialExporter.VrmMaterialName(shaderName); - if (!string.IsNullOrEmpty(name)) - { - return name; - } - return base.GetGltfMaterialTypeFromUnityShaderName(shaderName); - } - - public override IEnumerable<(string propertyName, Texture texture)> EnumerateTextureProperties(Material m) - { - if (m.shader.name != "VRM/MToon") - { - foreach (var x in base.EnumerateTextureProperties(m)) - { - yield return x; - } - } - - var prop = UniGLTF.ShaderPropExporter.PreShaderPropExporter.GetPropsForSupportedShader(m.shader.name); - foreach (var kv in prop.Properties) - { - if (kv.ShaderPropertyType == UniGLTF.ShaderPropExporter.ShaderPropertyType.TexEnv) - { - yield return (kv.Key, m.GetTexture(kv.Key)); - } - } - } - } - protected override IEnumerable ValidatorFactory() { // ヒエラルキー のチェック diff --git a/Assets/VRM/Editor/Format/VRMMaterialValidator.cs b/Assets/VRM/Editor/Format/VRMMaterialValidator.cs new file mode 100644 index 000000000..7ff0b6656 --- /dev/null +++ b/Assets/VRM/Editor/Format/VRMMaterialValidator.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace VRM +{ + /// + /// VRM0 + /// + class VRMMaterialValidator : UniGLTF.DefaultMaterialValidator + { + public override string GetGltfMaterialTypeFromUnityShaderName(string shaderName) + { + var name = VRMMaterialExporter.VrmMaterialName(shaderName); + if (!string.IsNullOrEmpty(name)) + { + return name; + } + return base.GetGltfMaterialTypeFromUnityShaderName(shaderName); + } + + public override IEnumerable<(string propertyName, Texture texture)> EnumerateTextureProperties(Material m) + { + if (m.shader.name != "VRM/MToon") + { + // PBR, Unlit + foreach (var x in base.EnumerateTextureProperties(m)) + { + yield return x; + } + } + + // all + var prop = UniGLTF.ShaderPropExporter.PreShaderPropExporter.GetPropsForSupportedShader(m.shader.name); + foreach (var kv in prop.Properties) + { + if (kv.ShaderPropertyType == UniGLTF.ShaderPropExporter.ShaderPropertyType.TexEnv) + { + yield return (kv.Key, m.GetTexture(kv.Key)); + } + } + } + } +} diff --git a/Assets/VRM/Editor/Format/VRMMaterialValidator.cs.meta b/Assets/VRM/Editor/Format/VRMMaterialValidator.cs.meta new file mode 100644 index 000000000..375a03af3 --- /dev/null +++ b/Assets/VRM/Editor/Format/VRMMaterialValidator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 43a9939275e36534797e9be6fb83c71e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Editor/VRM10MaterialValidator.cs b/Assets/VRM10/Editor/VRM10MaterialValidator.cs new file mode 100644 index 000000000..083557e46 --- /dev/null +++ b/Assets/VRM10/Editor/VRM10MaterialValidator.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace UniVRM10 +{ + /// + /// VRM0 + /// + class VRM10MaterialValidator : UniGLTF.DefaultMaterialValidator + { + const string MTOON_SHADER_NAME = "VRM10/MToon10"; + + public override string GetGltfMaterialTypeFromUnityShaderName(string shaderName) + { + switch (shaderName) + { + case MTOON_SHADER_NAME: + return "VRMC_materials_mtoon"; + } + + // TODO: VRM-0.X + + return base.GetGltfMaterialTypeFromUnityShaderName(shaderName); + } + + public override IEnumerable<(string propertyName, Texture texture)> EnumerateTextureProperties(Material m) + { + if (m.shader.name == MTOON_SHADER_NAME) + { + // TODO + } + else + { + foreach (var x in base.EnumerateTextureProperties(m)) + { + yield return x; + } + } + } + } +} diff --git a/Assets/VRM10/Editor/VRM10MaterialValidator.cs.meta b/Assets/VRM10/Editor/VRM10MaterialValidator.cs.meta new file mode 100644 index 000000000..8d92b1cf7 --- /dev/null +++ b/Assets/VRM10/Editor/VRM10MaterialValidator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 77bcf6c00ae8990488aaea60f0ec9173 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Editor/Vrm10ExportDialog.cs b/Assets/VRM10/Editor/Vrm10ExportDialog.cs index b2518cd9c..b49e234fd 100644 --- a/Assets/VRM10/Editor/Vrm10ExportDialog.cs +++ b/Assets/VRM10/Editor/Vrm10ExportDialog.cs @@ -136,6 +136,10 @@ namespace UniVRM10 yield break; } + // Mesh/Renderer のチェック + m_meshes.MaterialValidator = new VRM10MaterialValidator(); + yield return m_meshes.Validate; + yield return HumanoidValidator.Validate_TPose; // MeshUtility.Validators.HumanoidValidator.EnableFreeze = false; From e22bacb94e7d2ef0da3d76c0944bf9df66806a9a Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 7 Mar 2022 16:34:48 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Vrm10TopMenu=20=E3=81=AB=20`MenuItem`=20?= =?UTF-8?q?=E3=82=92=E9=9B=86=E7=B4=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/VRM10/Editor/Components/VRM10Window.cs | 5 +--- Assets/VRM10/Editor/GeneratorMenu.cs | 18 ++----------- Assets/VRM10/Editor/Vrm10ExportDialog.cs | 5 +--- Assets/VRM10/Editor/Vrm10TopMenu.cs | 25 +++++++++++++++++++ Assets/VRM10/Editor/Vrm10TopMenu.cs.meta | 11 ++++++++ 5 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 Assets/VRM10/Editor/Vrm10TopMenu.cs create mode 100644 Assets/VRM10/Editor/Vrm10TopMenu.cs.meta diff --git a/Assets/VRM10/Editor/Components/VRM10Window.cs b/Assets/VRM10/Editor/Components/VRM10Window.cs index 588d262d8..3612409eb 100644 --- a/Assets/VRM10/Editor/Components/VRM10Window.cs +++ b/Assets/VRM10/Editor/Components/VRM10Window.cs @@ -10,11 +10,8 @@ namespace UniVRM10 /// public class VRM10Window : EditorWindow { - const string MENU_KEY = VRMVersion.MENU + "/VRM1 Window"; const string WINDOW_TITLE = "VRM1 Window"; - - [MenuItem(MENU_KEY, false, 1)] - private static void ExportFromMenu() + public static void Open() { var window = (VRM10Window)GetWindow(typeof(VRM10Window)); window.titleContent = new GUIContent(WINDOW_TITLE); diff --git a/Assets/VRM10/Editor/GeneratorMenu.cs b/Assets/VRM10/Editor/GeneratorMenu.cs index 1b4294680..f82349a1f 100644 --- a/Assets/VRM10/Editor/GeneratorMenu.cs +++ b/Assets/VRM10/Editor/GeneratorMenu.cs @@ -13,22 +13,8 @@ namespace UniVRM10 /// は SubModuleになった。 `$ git submodule update --init` しておくこと。 /// /// - public static class Menu + public static class GeneratorMenu { -#if VRM_DEVELOP - [MenuItem(UniVRM10.VRMVersion.MENU + "/Generate from JsonSchema")] - public static void Generate() - { - Run(false); - } - - [MenuItem(UniVRM10.VRMVersion.MENU + "/Generate from JsonSchema(debug)")] - public static void Parse() - { - Run(true); - } -#endif - struct GenerateInfo { public string JsonSchema; @@ -49,7 +35,7 @@ namespace UniVRM10 const string SPEC_DIR = "vrm-specification/specification"; - static void Run(bool debug) + public static void Run(bool debug) { var projectRoot = new DirectoryInfo(Path.GetFullPath(Path.Combine(Application.dataPath, "../"))); diff --git a/Assets/VRM10/Editor/Vrm10ExportDialog.cs b/Assets/VRM10/Editor/Vrm10ExportDialog.cs index b49e234fd..2650292df 100644 --- a/Assets/VRM10/Editor/Vrm10ExportDialog.cs +++ b/Assets/VRM10/Editor/Vrm10ExportDialog.cs @@ -13,10 +13,7 @@ namespace UniVRM10 { public class VRM10ExportDialog : ExportDialogBase { - const string CONVERT_HUMANOID_KEY = VRMVersion.MENU + "/Export VRM-1.0"; - - [MenuItem(CONVERT_HUMANOID_KEY, false, 0)] - private static void ExportFromMenu() + public static void Open() { var window = (VRM10ExportDialog)GetWindow(typeof(VRM10ExportDialog)); window.titleContent = new GUIContent("VRM-1.0 Exporter"); diff --git a/Assets/VRM10/Editor/Vrm10TopMenu.cs b/Assets/VRM10/Editor/Vrm10TopMenu.cs new file mode 100644 index 000000000..8bb1a54c9 --- /dev/null +++ b/Assets/VRM10/Editor/Vrm10TopMenu.cs @@ -0,0 +1,25 @@ +using UnityEditor; + +namespace UniVRM10 +{ + public static class Vrm10TopMenu + { + private const string UserMenuPrefix = VRMVersion.MENU; + private const string DevelopmentMenuPrefix = VRMVersion.MENU + "/Development"; + + const string CONVERT_HUMANOID_KEY = VRMVersion.MENU + "/Export VRM-1.0"; + [MenuItem(UserMenuPrefix + "/Export VRM-1.0", priority = 1)] + static void OpenExportDialog() => VRM10ExportDialog.Open(); + +#if VRM_DEVELOP + [MenuItem(UserMenuPrefix + "/VRM1 Window", false, 2)] + static void OpenWindow() => VRM10Window.Open(); + + [MenuItem(DevelopmentMenuPrefix + "/Generate from JsonSchema")] + public static void Generate() => GeneratorMenu.Run(false); + + [MenuItem(DevelopmentMenuPrefix + "/Generate from JsonSchema(debug)")] + public static void Parse() => GeneratorMenu.Run(true); +#endif + } +} diff --git a/Assets/VRM10/Editor/Vrm10TopMenu.cs.meta b/Assets/VRM10/Editor/Vrm10TopMenu.cs.meta new file mode 100644 index 000000000..9750afd3e --- /dev/null +++ b/Assets/VRM10/Editor/Vrm10TopMenu.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 935fd2eb9940f5d48933733f69a96113 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 11dbe661cc99b0a9c4888d72f2d428aa5a1e9333 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 14 Mar 2022 17:53:23 +0900 Subject: [PATCH 3/4] rename --- .../Editor/{GeneratorMenu.cs => Vrm10SerializerGenerator.cs} | 2 +- ...GeneratorMenu.cs.meta => Vrm10SerializerGenerator.cs.meta} | 2 +- Assets/VRM10/Editor/Vrm10TopMenu.cs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename Assets/VRM10/Editor/{GeneratorMenu.cs => Vrm10SerializerGenerator.cs} (98%) rename Assets/VRM10/Editor/{GeneratorMenu.cs.meta => Vrm10SerializerGenerator.cs.meta} (83%) diff --git a/Assets/VRM10/Editor/GeneratorMenu.cs b/Assets/VRM10/Editor/Vrm10SerializerGenerator.cs similarity index 98% rename from Assets/VRM10/Editor/GeneratorMenu.cs rename to Assets/VRM10/Editor/Vrm10SerializerGenerator.cs index f82349a1f..e1c22f856 100644 --- a/Assets/VRM10/Editor/GeneratorMenu.cs +++ b/Assets/VRM10/Editor/Vrm10SerializerGenerator.cs @@ -13,7 +13,7 @@ namespace UniVRM10 /// は SubModuleになった。 `$ git submodule update --init` しておくこと。 /// /// - public static class GeneratorMenu + public static class Vrm10SerializerGenerator { struct GenerateInfo { diff --git a/Assets/VRM10/Editor/GeneratorMenu.cs.meta b/Assets/VRM10/Editor/Vrm10SerializerGenerator.cs.meta similarity index 83% rename from Assets/VRM10/Editor/GeneratorMenu.cs.meta rename to Assets/VRM10/Editor/Vrm10SerializerGenerator.cs.meta index da8113e9c..1b098ddea 100644 --- a/Assets/VRM10/Editor/GeneratorMenu.cs.meta +++ b/Assets/VRM10/Editor/Vrm10SerializerGenerator.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7f8755f9d806837408cd04ebb587489c +guid: 7e5497454373c2a458526799422de3ad MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/VRM10/Editor/Vrm10TopMenu.cs b/Assets/VRM10/Editor/Vrm10TopMenu.cs index 8bb1a54c9..426024e81 100644 --- a/Assets/VRM10/Editor/Vrm10TopMenu.cs +++ b/Assets/VRM10/Editor/Vrm10TopMenu.cs @@ -16,10 +16,10 @@ namespace UniVRM10 static void OpenWindow() => VRM10Window.Open(); [MenuItem(DevelopmentMenuPrefix + "/Generate from JsonSchema")] - public static void Generate() => GeneratorMenu.Run(false); + public static void Generate() => Vrm10SerializerGenerator.Run(false); [MenuItem(DevelopmentMenuPrefix + "/Generate from JsonSchema(debug)")] - public static void Parse() => GeneratorMenu.Run(true); + public static void Parse() => Vrm10SerializerGenerator.Run(true); #endif } } From 143175b8687f12317c4a2aea0129b393c51b483f Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 14 Mar 2022 18:07:16 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E5=A4=89=E6=95=B0=E5=90=8D=E3=80=81if?= =?UTF-8?q?=E6=96=87=E3=80=81=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VRM/Editor/Format/VRMMaterialValidator.cs | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/Assets/VRM/Editor/Format/VRMMaterialValidator.cs b/Assets/VRM/Editor/Format/VRMMaterialValidator.cs index 7ff0b6656..941e59038 100644 --- a/Assets/VRM/Editor/Format/VRMMaterialValidator.cs +++ b/Assets/VRM/Editor/Format/VRMMaterialValidator.cs @@ -20,22 +20,37 @@ namespace VRM public override IEnumerable<(string propertyName, Texture texture)> EnumerateTextureProperties(Material m) { - if (m.shader.name != "VRM/MToon") + /// 歴史的経緯により処理ロジックが2種類ある + if (m.shader.name == "VRM/MToon") { - // PBR, Unlit - foreach (var x in base.EnumerateTextureProperties(m)) + // [Unity列挙] + // * UnityEditor.ShaderUtil により Shader の Property を列挙する。Editor専用。 + // * あらかじめEditorで実行して property 一覧をハードコーディングしてある `Assets\VRMShaders\VRM\IO\Runtime\VRM\PreExportShaders_VRM.cs` 界隈。 + // * 今は "VRM/MToon" のみ + // + // extensions.VRM.materialProperties に記録する + // + var prop = UniGLTF.ShaderPropExporter.PreShaderPropExporter.GetPropsForSupportedShader(m.shader.name); + foreach (var kv in prop.Properties) { - yield return x; + if (kv.ShaderPropertyType == UniGLTF.ShaderPropExporter.ShaderPropertyType.TexEnv) + { + yield return (kv.Key, m.GetTexture(kv.Key)); + } } } - - // all - var prop = UniGLTF.ShaderPropExporter.PreShaderPropExporter.GetPropsForSupportedShader(m.shader.name); - foreach (var kv in prop.Properties) + else { - if (kv.ShaderPropertyType == UniGLTF.ShaderPropExporter.ShaderPropertyType.TexEnv) + // [Shaderの定義から手で記述] + // + // PBR, Unlit + // * DefaultMaterialValidator.EnumerateTextureProperties + // + // glTF.materials に記録する + // + foreach (var textureProperty in base.EnumerateTextureProperties(m)) { - yield return (kv.Key, m.GetTexture(kv.Key)); + yield return textureProperty; } } }